export type Bytes = Uint8Array<ArrayBuffer>
export type Words = Uint32Array<ArrayBuffer>
-const TypedArray = Object.getPrototypeOf(Uint8Array.prototype)
+const Bytes = Uint8Array
+const Words = Uint32Array
+const TypedArray = Object.getPrototypeOf(Bytes.prototype)
-const bytesSet = Function.prototype.call.bind(Uint8Array.prototype.set)
-const bytesFill = Function.prototype.call.bind(Uint8Array.prototype.fill)
+const bytesSet = Function.prototype.call.bind(Bytes.prototype.set)
+const bytesFill = Function.prototype.call.bind(Bytes.prototype.fill)
/** An accessor's getter, taking the object to read as its argument. */
function getter (target: object, key: PropertyKey): (self: unknown) => any {
}
/** True on little-endian system which aligns with WASM spec. */
-export const isLE = new Uint8Array(getBuffer(new Uint32Array([1])))[0] === 1
+export const isLE = new Bytes(getBuffer(new Words([1])))[0] === 1
/**
* Enables reading multiple bytes in a single load which is more efficient than
if (offset !== 0) {
throw new Nano25519RangeError('Unexpected byte offset', { cause: offset })
}
- return new Uint32Array(getBuffer(bytes) as ArrayBuffer, offset, getByteLength(bytes) >> 2)
+ return new Words(getBuffer(bytes) as ArrayBuffer, offset, getByteLength(bytes) >> 2)
}
const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt)
if (value.length < (byteLengthMin << 1) || value.length > (byteLengthMax << 1)) {
throw new Nano25519TypeError(`Invalid hexadecimal length ${value.length} for ${name}`)
}
- if (typeof out === 'undefined') out = new Uint8Array(value.length >> 1)
+ if (typeof out === 'undefined') out = new Bytes(value.length >> 1)
hexToBytes(out, value)
return out
}
if (byteLength > byteLengthMax) {
throw new Nano25519TypeError(`${name} must be no more than ${byteLengthMax} bytes`)
}
- if (typeof out === 'undefined') out = new Uint8Array(byteLength)
+ if (typeof out === 'undefined') out = new Bytes(byteLength)
copy(out, value)
return out
}