From 4be457a48dd57b25454a9cb746b054b9e52eb8ff Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 18 Jul 2026 23:25:59 -0700 Subject: [PATCH] Wrap prf output in Uint8Array Non-standard passkey implementations (e.g., 1Password) return `Array` instead of `BufferSource`. --- index.html | 2 +- script.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index b6c3b4b..fa592dc 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@ - + static-encrypt-passkey diff --git a/script.js b/script.js index 093f5d6..29850fb 100644 --- a/script.js +++ b/script.js @@ -93,7 +93,9 @@ export async function encrypt(plaintext) { paddedPlaintext.set([p]); // Offset to discard on decode paddedPlaintext.set(encodedPlaintext, p); // Gap filled with zero bytes, e.g. [3, 0, 0, ...encodedPlaintext] - const prf = await createPrf(); + // As per the specification, the PRF extension *should* already return a BufferSource which can be directly + // passed to Web Crypto API, however non-standard passkey implementations (e.g., 1Password) return Array. + const prf = new Uint8Array(await createPrf()); const key = await getKey(prf, salt, info); const ciphertext = new Uint8Array(await crypto.subtle.encrypt( { name: 'AES-GCM', iv }, @@ -126,7 +128,9 @@ export async function decrypt(content) { // Prepare non-crypto inputs const info = new TextEncoder().encode('https://github.com/ardislu/static-encrypt-passkey'); - const prf = await getPrf(); + // As per the specification, the PRF extension *should* already return a BufferSource which can be directly + // passed to Web Crypto API, however non-standard passkey implementations (e.g., 1Password) return Array. + const prf = new Uint8Array(await getPrf()); const key = await getKey(prf, salt, info); const encodedPlaintext = new Uint8Array(await crypto.subtle.decrypt( { name: 'AES-GCM', iv }, -- 2.47.3