fix: validate hash_to_field DST as stringOrUint8Array (closes #57)

This commit is contained in:
Nicholas Dudfield 2023-06-22 07:12:37 +07:00
parent 62e806cfaf
commit bf70ba9776
2 changed files with 2 additions and 1 deletions

@ -127,7 +127,7 @@ export function expand_message_xof(
*/ */
export function hash_to_field(msg: Uint8Array, count: number, options: Opts): bigint[][] { export function hash_to_field(msg: Uint8Array, count: number, options: Opts): bigint[][] {
validateObject(options, { validateObject(options, {
DST: 'string', DST: 'stringOrUint8Array',
p: 'bigint', p: 'bigint',
m: 'isSafeInteger', m: 'isSafeInteger',
k: 'isSafeInteger', k: 'isSafeInteger',

@ -246,6 +246,7 @@ const validatorFns = {
function: (val: any) => typeof val === 'function', function: (val: any) => typeof val === 'function',
boolean: (val: any) => typeof val === 'boolean', boolean: (val: any) => typeof val === 'boolean',
string: (val: any) => typeof val === 'string', string: (val: any) => typeof val === 'string',
stringOrUint8Array: (val: any) => typeof val === 'string' || val instanceof Uint8Array,
isSafeInteger: (val: any) => Number.isSafeInteger(val), isSafeInteger: (val: any) => Number.isSafeInteger(val),
array: (val: any) => Array.isArray(val), array: (val: any) => Array.isArray(val),
field: (val: any, object: any) => (object as any).Fp.isValid(val), field: (val: any, object: any) => (object as any).Fp.isValid(val),