Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(vaults): stabilize passkey PRF setup output (#727)
Call Whitec7a1dc8d74f7
diff --git a/ui/src/lib/useProtectedVault.test.ts b/ui/src/lib/useProtectedVault.test.tsnew file mode 100644index 000000000..b57da9eae--- /dev/null+++ b/ui/src/lib/useProtectedVault.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from 'vitest';++import { readPasskeyPrfResult } from './useProtectedVault';++function passkeyCredential(first?: ArrayBuffer | ArrayBufferView | number[]): PublicKeyCredential {+ return {+ getClientExtensionResults: () => ({+ prf: {+ results: first ? { first } : {},+ },+ }),+ } as unknown as PublicKeyCredential;+}++describe('protected vault WebAuthn PRF result handling', () => {+ it('copies the PRF output before handing it to the VMK wrap chain', () => {+ const source = new Uint8Array(32).fill(0x22);+ const backing = source.buffer as ArrayBuffer;+ const result = readPasskeyPrfResult(passkeyCredential(backing));++ structuredClone(backing, { transfer: [backing] });++ expect(result.byteLength).toBe(32);+ expect(result).toEqual(new Uint8Array(32).fill(0x22));+ });++ it('accepts a plain Array PRF output from browser extension passkey providers', () => {+ const source = Array.from({ length: 32 }, (_, index) => index + 1);++ expect(readPasskeyPrfResult(passkeyCredential(source))).toEqual(Uint8Array.from(source));+ });++ it('rejects a present but empty PRF output at the WebAuthn boundary', () => {+ expect(() => readPasskeyPrfResult(passkeyCredential(new ArrayBuffer(0)))).toThrow(/passkey-prf-unavailable/);+ });+});diff --git a/ui/src/lib/useProtectedVault.ts b/ui/src/lib/useProtectedVault.tsindex 31596071d..68f11e2cb 100644--- a/ui/src/lib/useProtectedVault.ts+++ b/ui/src/lib/useProtectedVault.ts@@ -105,15 +105,23 @@ function withRpId(wrapMeta: string, rpId: string): string {return JSON.stringify(meta);}-function toUint8(buffer: ArrayBuffer | ArrayBufferView): Uint8Array {- return buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);+function toUint8(buffer: ArrayBuffer | ArrayBufferView | ArrayLike<number>): Uint8Array {+ if (buffer instanceof ArrayBuffer) return new Uint8Array(buffer);+ if (ArrayBuffer.isView(buffer)) return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);+ return Uint8Array.from(buffer);}-function passkeyResult(credential: PublicKeyCredential | null): Uint8Array {- const ext = credential?.getClientExtensionResults() as { prf?: { results?: { first?: ArrayBuffer } } } | undefined;+function copyUint8(buffer: ArrayBuffer | ArrayBufferView | ArrayLike<number>): Uint8Array {+ return new Uint8Array(toUint8(buffer));+}++export function readPasskeyPrfResult(credential: PublicKeyCredential | null): Uint8Array {+ const ext = credential?.getClientExtensionResults() as { prf?: { results?: { first?: ArrayBuffer | ArrayBufferView | ArrayLike<number> } } } | undefined;const first = ext?.prf?.results?.first;if (!first) throw new Error('passkey-prf-unavailable');- return toUint8(first);+ const prfOutput = copyUint8(first);+ if (prfOutput.byteLength === 0) throw new Error('passkey-prf-unavailable');+ return prfOutput;}type PasskeyEntry = { credentialId?: string; prfSalt: Uint8Array };@@ -144,7 +152,7 @@ async function assertPasskeyPrf(entries: PasskeyEntry[]): Promise<{ prfOutput: U},})) as PublicKeyCredential | null;if (!assertion) throw new Error('passkey-cancelled');- const prfOutput = passkeyResult(assertion);+ const prfOutput = readPasskeyPrfResult(assertion);const usedId = bytesToBase64(toUint8(assertion.rawId));const used = entries.find((entry) => entry.credentialId === usedId);return { prfOutput, prfSalt: used?.prfSalt ?? entries[0].prfSalt };diff --git a/ui/src/lib/vaultCrypto.test.ts b/ui/src/lib/vaultCrypto.test.tsindex 09d68b6d1..6e047081d 100644--- a/ui/src/lib/vaultCrypto.test.ts+++ b/ui/src/lib/vaultCrypto.test.ts@@ -338,6 +338,19 @@ describe('vaultCrypto protected hierarchy', () => {expect(copies.at(-1)?.kdf).toBe('argon2id');});+ it('keeps setup passkey PRF bytes and credential id intact through wrap_meta', async () => {+ const vmk = newVmk();+ const prfSalt = new Uint8Array(32).fill(0x11);+ const prfOutput = new Uint8Array(32).fill(0x22);+ const credentialId = '/Wz4YbtaoR9NBzQH1amGZagS0BmEdIh2dS8OIbpdN2WftQMJlny4PP4I';++ const wrapMeta = await buildWrapMeta(vmk, [{ kind: 'passkey', prfOutput, prfSalt, credentialId }]);++ await expect(unwrapVmk(wrapMeta, { kind: 'passkey', prfOutput })).resolves.toEqual(vmk);+ expect(passkeyPrfSaltEntries(wrapMeta)).toEqual([{ prfSalt, credentialId }]);+ expect(prfOutput).toEqual(new Uint8Array(32).fill(0x22));+ });+it('skips malformed authenticated VMK copies and tries the next valid copy', async () => {const vmk = newVmk();const password = 'less-secure-fallback';