From a062f75d38a9d4856b3a3a610c252c4025dbcdd5 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Tue, 17 Jul 2018 15:32:06 -0400 Subject: [PATCH] Made Signatures more flexible for input. --- src.ts/utils/bytes.ts | 3 +++ src.ts/utils/types.ts | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src.ts/utils/bytes.ts b/src.ts/utils/bytes.ts index 6fb17e7ec..7a494d727 100644 --- a/src.ts/utils/bytes.ts +++ b/src.ts/utils/bytes.ts @@ -248,6 +248,9 @@ export function splitSignature(signature: Arrayish | Signature): Signature { let r = '0x', s = '0x'; if (isSignature(signature)) { + if (signature.v == null && signature.recoveryParam == null) { + errors.throwError('at least on of recoveryParam or v must be specified', errors.INVALID_ARGUMENT, { argument: 'signature', value: signature }); + } r = hexZeroPad(signature.r, 32); s = hexZeroPad(signature.s, 32); diff --git a/src.ts/utils/types.ts b/src.ts/utils/types.ts index 8d4db88a3..7cbadf879 100644 --- a/src.ts/utils/types.ts +++ b/src.ts/utils/types.ts @@ -65,7 +65,9 @@ export type SupportedAlgorithms = 'sha256' | 'sha512'; export interface Signature { r: string; s: string; - recoveryParam: number; + + /* At least one of the following MUST be specified; the other will be derived */ + recoveryParam?: number; v?: number; }