import { describe, it, expect } from 'vitest' import { b64urlToBuf, bufToB64url, toCreationOptions } from './passkey' describe('passkey base64url helpers', () => { it('roundtrips bytes', () => { const bytes = new Uint8Array([0, 1, 250, 255, 62, 63]) expect(new Uint8Array(b64urlToBuf(bufToB64url(bytes.buffer)))).toEqual(bytes) }) it('is url-safe (no +/=)', () => { const s = bufToB64url(new Uint8Array([251, 255, 191]).buffer) expect(s).not.toMatch(/[+/=]/) }) it('converts backend register options to ArrayBuffers', () => { const opts = toCreationOptions({ challenge: 'AAAA', user: { id: 'QUJD', name: 'a' }, rp: { name: 'x' } }) expect(opts.publicKey!.challenge).toBeInstanceOf(ArrayBuffer) expect((opts.publicKey!.user as { id: ArrayBuffer }).id).toBeInstanceOf(ArrayBuffer) }) })