return str
}
-function toHex (n) {
- if (n < 16) return '0' + n.toString(16)
- return n.toString(16)
+function toHex (n: number) {
+ if (typeof n !== 'number')
+ throw new TypeError(`expected number to convert to hex, received convert ${typeof n}`)
+ if (n < 0 || n > 255)
+ throw new RangeError(`expected byte value 0-255, received ${n}`)
+ return n.toString(16).padStart(2, '0')
}
var Proto = Blake2b
throw new RangeError('key must be at most ' + KEYBYTES_MAX + ', was given ' + key.length)
}
if (salt != null) {
- if(!(salt instanceof Uint8Array))
+ if (!(salt instanceof Uint8Array))
throw new TypeError('salt must be Uint8Array or Buffer')
if (salt.length !== SALTBYTES)
throw new RangeError('salt must be exactly ' + SALTBYTES + ', was given ' + salt.length)
}
if (personal != null) {
- if(!(personal instanceof Uint8Array))
- throw new TypeError( 'personal must be Uint8Array or Buffer')
- if(personal.length !== PERSONALBYTES)
+ if (!(personal instanceof Uint8Array))
+ throw new TypeError('personal must be Uint8Array or Buffer')
+ if (personal.length !== PERSONALBYTES)
throw new RangeError('personal must be exactly ' + PERSONALBYTES + ', was given ' + personal.length)
}
}