From bf70ba977621ec34a84458e3f639715b776613fa Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Thu, 22 Jun 2023 07:12:37 +0700 Subject: [PATCH] fix: validate hash_to_field DST as stringOrUint8Array (closes #57) --- src/abstract/hash-to-curve.ts | 2 +- src/abstract/utils.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/abstract/hash-to-curve.ts b/src/abstract/hash-to-curve.ts index 38d31d4..24d472b 100644 --- a/src/abstract/hash-to-curve.ts +++ b/src/abstract/hash-to-curve.ts @@ -127,7 +127,7 @@ export function expand_message_xof( */ export function hash_to_field(msg: Uint8Array, count: number, options: Opts): bigint[][] { validateObject(options, { - DST: 'string', + DST: 'stringOrUint8Array', p: 'bigint', m: 'isSafeInteger', k: 'isSafeInteger', diff --git a/src/abstract/utils.ts b/src/abstract/utils.ts index 00fc18f..fa3b6bc 100644 --- a/src/abstract/utils.ts +++ b/src/abstract/utils.ts @@ -246,6 +246,7 @@ const validatorFns = { function: (val: any) => typeof val === 'function', boolean: (val: any) => typeof val === 'boolean', string: (val: any) => typeof val === 'string', + stringOrUint8Array: (val: any) => typeof val === 'string' || val instanceof Uint8Array, isSafeInteger: (val: any) => Number.isSafeInteger(val), array: (val: any) => Array.isArray(val), field: (val: any, object: any) => (object as any).Fp.isValid(val),