Merge pull request #58 from sublimator/nd-validate-dst-as-stringoruint8array-closes-57-2023-06-22

fix: validate hash_to_field DST as stringOrUint8Array (closes #57)
This commit is contained in:
Paul Miller 2023-06-23 00:27:24 +02:00 committed by GitHub
commit c2edc97868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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),