UNPKG

@virtonetwork/authenticators-webauthn

Version:

An Authenticator compatible with KreivoPassSigner that uses the WebAuthn standard

46 lines (45 loc) 1.52 kB
export class InMemoryCredentialsHandler { static userCredentials = {}; static tryMutate(userId, f) { try { let map = this.userCredentials[userId] ?? {}; f(map); this.userCredentials[userId] = map; } catch { /* on error, no-op */ } } static credentialIds(userId) { const credentials = this.userCredentials[userId] ?? {}; return Object.entries(credentials).map(([, credential]) => new Uint8Array(credential.rawId)); } async onCreatedCredentials(userId, credential) { InMemoryCredentialsHandler.tryMutate(userId, (credentials) => { credentials[credential.id] = credential; }); } async publicKeyCreateOptions(challenge, user) { return { challenge, rp: { name: "Virto Passkeys" }, user, pubKeyCredParams: [{ type: "public-key", alg: -7 /* ES256 */ }], authenticatorSelection: { userVerification: "preferred" }, attestation: "none", timeout: 60_000, }; } async publicKeyRequestOptions(userId, challenge) { return { challenge, allowCredentials: InMemoryCredentialsHandler.credentialIds(userId).map((id) => ({ id, type: "public-key", transports: ["usb", "ble", "nfc", "internal"], })), userVerification: "preferred", timeout: 60_000, }; } }