]> git.codecow.com Git - nano25519.git/commitdiff
Fix buffer slicing when normalizing.
authorChris Duncan <chris@zoso.dev>
Sat, 29 Aug 2026 06:33:32 +0000 (23:33 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 29 Aug 2026 06:33:32 +0000 (23:33 -0700)
src/lib/wasm.ts

index f08d3d1f61bdc058ec9f4c0f73c8de4ffe0a8d53..37bdbb438057814623862c668db77b41277c2440 100644 (file)
@@ -124,10 +124,13 @@ export function normalize (name: string, byteLengthMin: number, byteLengthMax: n
                return new Uint8Array(value.match(/[0-9a-f]{2}/gi)?.map(b => parseInt(b, 16)) || [])
        }
 
-       if (!(value instanceof ArrayBuffer || value instanceof Uint8Array)) {
+       if (value instanceof ArrayBuffer) {
+               value = new Uint8Array(value)
+       }
+       if (!(value instanceof Uint8Array)) {
                throw new TypeError(`${name} must be Uint8Array or ArrayBuffer`)
        }
-       const bytes = new Uint8Array(value.slice())
+       const bytes = value.slice()
        if (bytes.byteLength < byteLengthMin) {
                throw new TypeError(`${name} must be at least ${byteLengthMin} bytes`)
        }