* Prototype methods and accessors used on a call path, captured once when this
* module is evaluated and called through a bound `Function.prototype.call`, so
* that code patching a prototype afterwards cannot change what is validated,
- * copied, scrubbed or decoded. The `%TypedArray%.prototype` getters also read
- * internal slots, which a caller's subclass cannot override, so use these
- * helpers on every typed array instead of its own properties. Use the captured
- * `allocate()` and `words()` instead of `Uint8Array` and `Uint32Array`. Other
- * global constructors and static functions are looked up at time-of-call, and
- * capturing them is out of scope.
+ * copied, scrubbed or decoded. Static functions are captured on load, and the
+ * bound functions are used instead. The `%TypedArray%.prototype` getters also
+ * read internal slots, which a caller's subclass cannot override, so use these
+ * helpers on every typed array instead of its own properties, and use
+ * `allocate(byteLength)` instead of `new Uint8Array(byteLength)` and
+ * `words(buffer)` instead of `new Uint32Array(buffer)`.
*/
/** Type aliases for legibility. */
}
const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt)
+const fromCharCode = String.fromCharCode
/** 0-9a-f for a valid hex digit 0..15 */
function hexcode (c: number): number {
let hex = ''
for (let i = 0; i < byteLength; i++) {
const byte = bytes[i]
- hex += String.fromCharCode(hexcode(byte >> 4), hexcode(byte & 15))
+ hex += fromCharCode(hexcode(byte >> 4), hexcode(byte & 15))
}
return hex
}
export function verify_blocks (pub: unknown, data: unknown): readonly boolean[] {
const blocks: unknown[] = isArray(data) ? data : [data]
const count: unknown = blocks.length
- if (typeof count !== 'number') {
+ if (typeof count !== 'number' || !count || count === Infinity || count === -Infinity) {
throw new Nano25519TypeError('Invalid blocks length', { cause: data })
}
if (count < 1) {