@tinfoilsh/passkey-kit 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +138 -81
  2. package/dist/crypto.d.ts +11 -54
  3. package/dist/crypto.d.ts.map +1 -1
  4. package/dist/crypto.js +146 -97
  5. package/dist/crypto.js.map +1 -1
  6. package/dist/errors.d.ts +11 -21
  7. package/dist/errors.d.ts.map +1 -1
  8. package/dist/errors.js +10 -27
  9. package/dist/errors.js.map +1 -1
  10. package/dist/index.d.ts +7 -10
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +4 -7
  13. package/dist/index.js.map +1 -1
  14. package/dist/kit.d.ts +2 -62
  15. package/dist/kit.d.ts.map +1 -1
  16. package/dist/kit.js +305 -159
  17. package/dist/kit.js.map +1 -1
  18. package/dist/storage.d.ts +15 -29
  19. package/dist/storage.d.ts.map +1 -1
  20. package/dist/storage.js +113 -62
  21. package/dist/storage.js.map +1 -1
  22. package/dist/support.d.ts +2 -14
  23. package/dist/support.d.ts.map +1 -1
  24. package/dist/support.js +32 -47
  25. package/dist/support.js.map +1 -1
  26. package/dist/types.d.ts +85 -89
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/webauthn.d.ts +10 -33
  29. package/dist/webauthn.d.ts.map +1 -1
  30. package/dist/webauthn.js +89 -177
  31. package/dist/webauthn.js.map +1 -1
  32. package/dist/wrapped-key-record-codec.d.ts +4 -0
  33. package/dist/wrapped-key-record-codec.d.ts.map +1 -0
  34. package/dist/wrapped-key-record-codec.js +89 -0
  35. package/dist/wrapped-key-record-codec.js.map +1 -0
  36. package/package.json +4 -2
  37. package/src/crypto.ts +171 -137
  38. package/src/errors.ts +29 -33
  39. package/src/index.ts +26 -41
  40. package/src/kit.ts +405 -263
  41. package/src/storage.ts +126 -60
  42. package/src/support.ts +36 -50
  43. package/src/types.ts +99 -99
  44. package/src/webauthn.ts +121 -237
  45. package/src/wrapped-key-record-codec.ts +93 -0
  46. package/dist/protocol.d.ts +0 -13
  47. package/dist/protocol.d.ts.map +0 -1
  48. package/dist/protocol.js +0 -13
  49. package/dist/protocol.js.map +0 -1
  50. package/src/protocol.ts +0 -15
package/dist/kit.js CHANGED
@@ -1,198 +1,344 @@
1
- /**
2
- * The main SDK entry point. `createPasskeyKit(config)` binds relying-party
3
- * configuration, protocol constants, and local persistence into a single
4
- * object exposing both high-level flows (enroll / unlock / rewrap) and the
5
- * lower-level ceremony + crypto building blocks.
6
- */
7
- import { base64ToBytes, bytesToBase64 } from "./codec.js";
8
- import { deriveKeyEncryptionKey as deriveKekFromPrf, unwrapCek, wrapCek, } from "./crypto.js";
9
- import { TINFOIL_HKDF_INFO_V1, TINFOIL_PRF_SALT_INPUT_V1 } from "./protocol.js";
10
- import { browserLocalStorageAdapter } from "./storage.js";
11
- import { detectPrfSupport } from "./support.js";
12
- import { authenticatePrfPasskey, createPrfPasskey, } from "./webauthn.js";
13
- const DEFAULT_STORAGE_KEYS = {
14
- prfResult: "tinfoil-secret-passkey-prf-output",
15
- localCredentialId: "tinfoil-local-passkey-credential-id",
16
- };
17
- const DEFAULT_WEBAUTHN_TIMEOUT_MS = 30000;
18
- // Internal hard timeout to guard against providers (e.g. some
19
- // password-manager browser extensions) that never resolve the
20
- // credentials.create/get promise. Kept tight so users aren't left staring
21
- // at an indefinite spinner; the WebAuthn flow itself should complete well
22
- // within this window once the provider actually prompts.
23
- const DEFAULT_STUCK_TIMEOUT_MS = 60000;
24
- export function createPasskeyKit(config) {
25
- const logger = config.logger ?? {};
26
- const storage = config.storage === undefined ? browserLocalStorageAdapter : config.storage;
27
- const storageKeys = {
28
- ...DEFAULT_STORAGE_KEYS,
29
- ...config.storageKeys,
1
+ import { copyAndValidateProfile, profilesEqual, unwrapKey, validateCredentialId, validateKey, validateWrappedKey, wrapKey, } from "./crypto.js";
2
+ import { invalidInput, PasskeyKeyError } from "./errors.js";
3
+ import { capability as detectCapability } from "./support.js";
4
+ import { createPrfCredential, evaluatePrfCredential, } from "./webauthn.js";
5
+ const DEFAULT_TIMEOUT_MS = 60000;
6
+ const MIN_TIMEOUT_MS = 1;
7
+ const MAX_TIMEOUT_MS = 2147483647;
8
+ function mapCeremonyError(error, operation) {
9
+ if (error instanceof PasskeyKeyError) {
10
+ if (error.operation)
11
+ return error;
12
+ return new PasskeyKeyError(error.category, error.message, {
13
+ cause: error.cause,
14
+ operation,
15
+ });
16
+ }
17
+ if (error instanceof DOMException && error.name === "NotAllowedError") {
18
+ return new PasskeyKeyError("cancelled", "the prompt was dismissed or no eligible credential was available", { cause: error, operation });
19
+ }
20
+ if (error instanceof DOMException && error.name === "AbortError") {
21
+ return new PasskeyKeyError("cancelled", "the passkey operation was cancelled", {
22
+ cause: error,
23
+ operation,
24
+ });
25
+ }
26
+ return new PasskeyKeyError("operation_failed", "the passkey operation failed", {
27
+ cause: error,
28
+ operation,
29
+ });
30
+ }
31
+ function context(profile, relyingPartyName, timeoutMs) {
32
+ return {
33
+ rpId: profile.relyingPartyId,
34
+ rpName: relyingPartyName,
35
+ prfInput: profile.prfSalt,
36
+ timeoutMs,
30
37
  };
31
- // Byte inputs are snapshotted so later caller-side buffer reuse cannot
32
- // silently change the PRF domain or KEK derivation between ceremonies.
33
- const prfSalt = typeof config.prfSaltInput === "string" || config.prfSaltInput === undefined
34
- ? new TextEncoder().encode(config.prfSaltInput ?? TINFOIL_PRF_SALT_INPUT_V1)
35
- : config.prfSaltInput.slice();
36
- const hkdfInfo = config.hkdfInfo === undefined
37
- ? TINFOIL_HKDF_INFO_V1
38
- : typeof config.hkdfInfo === "string"
39
- ? config.hkdfInfo
40
- : config.hkdfInfo.slice();
41
- let prfSupportCache = null;
42
- function cachePrfResult(result) {
43
- if (!storage)
44
- return;
45
- const entry = {
46
- credentialId: result.credentialId,
47
- prfOutput: bytesToBase64(new Uint8Array(result.prfOutput)),
38
+ }
39
+ function copyUser(user) {
40
+ if (!user || typeof user !== "object")
41
+ throw invalidInput("user is required");
42
+ return {
43
+ id: user.id instanceof Uint8Array ? user.id.slice() : user.id,
44
+ name: user.name,
45
+ displayName: user.displayName,
46
+ };
47
+ }
48
+ function copyWrappedKeys(wrappedKeys) {
49
+ if (!Array.isArray(wrappedKeys) || wrappedKeys.length === 0) {
50
+ throw invalidInput("at least one wrapped key is required");
51
+ }
52
+ return wrappedKeys.map((wrapped) => {
53
+ if (!wrapped || typeof wrapped !== "object") {
54
+ throw invalidInput("wrapped key is required");
55
+ }
56
+ return {
57
+ ...wrapped,
58
+ profile: copyAndValidateProfile(wrapped.profile),
59
+ };
60
+ });
61
+ }
62
+ export function createPasskeyKeyManager(config) {
63
+ if (!config || typeof config !== "object")
64
+ throw invalidInput("manager config is required");
65
+ const profile = copyAndValidateProfile(config.profile);
66
+ if (typeof config.relyingPartyName !== "string" ||
67
+ config.relyingPartyName.length === 0) {
68
+ throw invalidInput("relyingPartyName must be a non-empty string");
69
+ }
70
+ const relyingPartyName = config.relyingPartyName;
71
+ if (config.timeoutMs !== undefined &&
72
+ (!Number.isFinite(config.timeoutMs) ||
73
+ config.timeoutMs < MIN_TIMEOUT_MS ||
74
+ config.timeoutMs > MAX_TIMEOUT_MS)) {
75
+ throw invalidInput(`timeoutMs must be between ${MIN_TIMEOUT_MS} and ${MAX_TIMEOUT_MS}`);
76
+ }
77
+ const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
78
+ let activeCeremony = null;
79
+ async function runCeremony(operation, callerSignal, perform) {
80
+ if (activeCeremony) {
81
+ throw new PasskeyKeyError("operation_in_progress", "another passkey ceremony is in progress", { operation });
82
+ }
83
+ if (callerSignal?.aborted) {
84
+ throw new PasskeyKeyError("cancelled", "the passkey operation was cancelled", {
85
+ cause: callerSignal.reason,
86
+ operation,
87
+ });
88
+ }
89
+ const token = Symbol(operation);
90
+ const controller = new AbortController();
91
+ let rejectInterruption;
92
+ const interrupted = new Promise((_, reject) => {
93
+ rejectInterruption = reject;
94
+ });
95
+ const cancel = (error) => {
96
+ rejectInterruption?.(error);
97
+ controller.abort(error);
48
98
  };
99
+ activeCeremony = { token, operation, cancel };
100
+ const cancelFromCaller = () => cancel(new PasskeyKeyError("cancelled", "the passkey operation was cancelled", {
101
+ cause: callerSignal?.reason,
102
+ operation,
103
+ }));
104
+ callerSignal?.addEventListener("abort", cancelFromCaller, { once: true });
105
+ const timeout = setTimeout(() => cancel(new PasskeyKeyError("timeout", "the passkey operation timed out", {
106
+ operation,
107
+ })), timeoutMs);
108
+ try {
109
+ return await Promise.race([perform(controller.signal), interrupted]);
110
+ }
111
+ catch (error) {
112
+ throw mapCeremonyError(error, operation);
113
+ }
114
+ finally {
115
+ clearTimeout(timeout);
116
+ callerSignal?.removeEventListener("abort", cancelFromCaller);
117
+ if (activeCeremony?.token === token)
118
+ activeCeremony = null;
119
+ }
120
+ }
121
+ function recordSuccessfulCredential(result) {
49
122
  try {
50
- storage.setItem(storageKeys.prfResult, JSON.stringify(entry));
123
+ config.storage?.saveCachedPRFResult({
124
+ profile: copyAndValidateProfile(profile),
125
+ credentialId: result.credentialId,
126
+ prfOutput: result.prfOutput.slice(),
127
+ });
51
128
  }
52
129
  catch {
53
- // best-effort
130
+ // Storage is best-effort and cannot invalidate a successful ceremony.
131
+ }
132
+ if (result.isPlatformAuthenticator) {
133
+ try {
134
+ config.storage?.saveLocalCredentialId(result.credentialId);
135
+ }
136
+ catch {
137
+ // Storage is best-effort and cannot invalidate a successful ceremony.
138
+ }
54
139
  }
55
140
  }
56
- function getCachedPrfResult() {
57
- if (!storage)
141
+ function loadCachedResult() {
142
+ let result;
143
+ try {
144
+ result = config.storage?.loadCachedPRFResult() ?? null;
145
+ }
146
+ catch {
58
147
  return null;
148
+ }
149
+ if (!result)
150
+ return null;
151
+ let cachedProfile;
59
152
  try {
60
- const raw = storage.getItem(storageKeys.prfResult);
61
- if (!raw)
62
- return null;
63
- const entry = JSON.parse(raw);
64
- return {
65
- credentialId: entry.credentialId,
66
- prfOutput: base64ToBytes(entry.prfOutput).buffer,
67
- };
153
+ cachedProfile = copyAndValidateProfile(result.profile);
154
+ validateCredentialId(result.credentialId);
68
155
  }
69
156
  catch {
70
157
  return null;
71
158
  }
159
+ if (!profilesEqual(cachedProfile, profile) ||
160
+ !(result.prfOutput instanceof Uint8Array) ||
161
+ result.prfOutput.length !== 32)
162
+ return null;
163
+ return {
164
+ profile: cachedProfile,
165
+ credentialId: result.credentialId,
166
+ prfOutput: result.prfOutput.slice(),
167
+ };
72
168
  }
73
- function setLocalCredentialId(credentialId) {
74
- storage?.setItem(storageKeys.localCredentialId, credentialId);
169
+ function loadPreferredCredentialId() {
170
+ try {
171
+ return config.storage?.loadLocalCredentialId() ?? null;
172
+ }
173
+ catch {
174
+ return null;
175
+ }
75
176
  }
76
- // Cross-device hybrid (QR-paired phone, etc.) reports
77
- // `authenticatorAttachment === 'cross-platform'` on the resulting
78
- // credential. Caching the cred id in that case would make this
79
- // device look like it has its own passkey when in reality the user
80
- // just borrowed another device's passkey for a one-shot unlock.
81
- // Per WebAuthn L3 §5.2.1, we only treat `authenticatorAttachment`
82
- // of `'platform'` as "this device truly owns this credential".
83
- function onPrfResult(result, credential) {
84
- cachePrfResult(result);
85
- if (credential.authenticatorAttachment === "platform") {
86
- try {
87
- setLocalCredentialId(result.credentialId);
88
- }
89
- catch {
90
- // best-effort: a throwing custom adapter must not discard the
91
- // ceremony result
92
- }
177
+ function orderedCredentialIds(credentialIds, preferredCredentialId) {
178
+ if (!Array.isArray(credentialIds) || credentialIds.length === 0) {
179
+ throw invalidInput("at least one credentialId is required");
93
180
  }
181
+ const unique = [...new Set(credentialIds)];
182
+ for (const credentialId of unique) {
183
+ validateCredentialId(credentialId);
184
+ }
185
+ const preferred = preferredCredentialId ?? loadPreferredCredentialId();
186
+ if (!preferred || !unique.includes(preferred))
187
+ return unique;
188
+ return [preferred, ...unique.filter((credentialId) => credentialId !== preferred)];
94
189
  }
95
- const ceremonyContext = {
96
- rpId: config.rpId,
97
- rpName: config.rpName,
98
- prfSalt,
99
- webauthnTimeoutMs: config.webauthnTimeoutMs ?? DEFAULT_WEBAUTHN_TIMEOUT_MS,
100
- stuckTimeoutMs: config.stuckTimeoutMs ?? DEFAULT_STUCK_TIMEOUT_MS,
101
- errorMessages: config.errorMessages,
102
- logger,
103
- onPrfResult,
104
- };
105
- const deriveKek = (prfOutput) => deriveKekFromPrf(prfOutput, hkdfInfo);
106
- async function wrapWithPrfResult(prfResult, cek) {
107
- const kek = await deriveKek(prfResult.prfOutput);
108
- return wrapCek({ credentialId: prfResult.credentialId, kek, cek });
190
+ function copyPRFOutput(prfResult, operation) {
191
+ if (!prfResult ||
192
+ typeof prfResult !== "object" ||
193
+ !(prfResult.output instanceof Uint8Array) ||
194
+ prfResult.output.length !== 32) {
195
+ throw invalidInput("prfResult.output must be exactly 32 bytes", operation);
196
+ }
197
+ return prfResult.output.slice();
198
+ }
199
+ async function wrapKeyWithPRFResult(input, operation = "wrapKeyWithPRFResult") {
200
+ if (!input || typeof input !== "object")
201
+ throw invalidInput("input is required", operation);
202
+ validateKey(input.keyMaterial, operation);
203
+ validateCredentialId(input.credentialId);
204
+ const keyMaterial = input.keyMaterial.slice();
205
+ const prfOutput = copyPRFOutput(input.prfResult, operation);
206
+ return wrapKey(profile, input.credentialId, prfOutput, keyMaterial, operation);
207
+ }
208
+ async function unwrapKeyWithPRFResult(input, operation = "unwrapKeyWithPRFResult") {
209
+ if (!input || typeof input !== "object")
210
+ throw invalidInput("input is required", operation);
211
+ const wrappedKey = {
212
+ ...input.wrappedKey,
213
+ profile: copyAndValidateProfile(input.wrappedKey?.profile),
214
+ };
215
+ validateWrappedKey(wrappedKey, profile);
216
+ const prfOutput = copyPRFOutput(input.prfResult, operation);
217
+ return unwrapKey(profile, prfOutput, wrappedKey, operation);
218
+ }
219
+ async function createAndWrapKey(input) {
220
+ if (!input || typeof input !== "object")
221
+ throw invalidInput("input is required");
222
+ validateKey(input.key, "createAndWrapKey");
223
+ const key = input.key.slice();
224
+ const user = copyUser(input.user);
225
+ const result = await runCeremony("createAndWrapKey", input.signal, (signal) => createPrfCredential(context(profile, relyingPartyName, timeoutMs), user, signal));
226
+ recordSuccessfulCredential(result);
227
+ const wrappedKey = await wrapKeyWithPRFResult({
228
+ keyMaterial: key,
229
+ credentialId: result.credentialId,
230
+ prfResult: { output: result.prfOutput },
231
+ }, "createAndWrapKey");
232
+ return { credentialId: result.credentialId, wrappedKey };
233
+ }
234
+ function prepareRecovery(input) {
235
+ if (!input || typeof input !== "object")
236
+ throw invalidInput("input is required");
237
+ const wrappedKeys = copyWrappedKeys(input.wrappedKeys);
238
+ for (const wrapped of wrappedKeys)
239
+ validateWrappedKey(wrapped, profile);
240
+ return wrappedKeys;
241
+ }
242
+ async function evaluateCredential(input, operation = "evaluateCredential") {
243
+ if (!input || typeof input !== "object")
244
+ throw invalidInput("input is required");
245
+ const interaction = input.interaction ?? "interactive";
246
+ if (interaction !== "interactive" && interaction !== "immediatelyAvailable") {
247
+ throw invalidInput("interaction must be interactive or immediatelyAvailable", operation);
248
+ }
249
+ if (interaction === "immediatelyAvailable") {
250
+ throw new PasskeyKeyError("unsupported", "immediatelyAvailable credential evaluation is not supported in browsers", { operation });
251
+ }
252
+ const credentialIds = orderedCredentialIds(input.credentialIds, input.preferredCredentialId);
253
+ const result = await runCeremony(operation, input.signal, (signal) => evaluatePrfCredential(context(profile, relyingPartyName, timeoutMs), credentialIds, signal));
254
+ recordSuccessfulCredential(result);
255
+ return {
256
+ credentialId: result.credentialId,
257
+ prfResult: { output: result.prfOutput.slice() },
258
+ };
109
259
  }
110
260
  return {
111
- async isPrfSupported() {
112
- if (prfSupportCache !== null)
113
- return prfSupportCache;
114
- prfSupportCache = await detectPrfSupport();
115
- return prfSupportCache;
116
- },
117
- resetPrfSupportCache() {
118
- prfSupportCache = null;
261
+ async capability(input) {
262
+ if (!input ||
263
+ typeof input !== "object" ||
264
+ (input.operation !== "enroll" && input.operation !== "recover")) {
265
+ throw invalidInput("operation must be enroll or recover", "capability");
266
+ }
267
+ return detectCapability(input.operation);
119
268
  },
120
- createPasskey(user) {
121
- return createPrfPasskey(ceremonyContext, user);
269
+ createAndWrapKey,
270
+ evaluateCredential(input) {
271
+ return evaluateCredential(input);
122
272
  },
123
- async authenticate(credentialIds, options = {}) {
124
- // An empty allowCredentials list would start a discoverable-passkey
125
- // ceremony against ANY credential, breaking the "only the supplied
126
- // ids" contract.
127
- if (credentialIds.length === 0)
128
- return null;
129
- return authenticatePrfPasskey(ceremonyContext, credentialIds, options);
273
+ wrapKeyWithPRFResult(input) {
274
+ return wrapKeyWithPRFResult(input);
130
275
  },
131
- deriveKek,
132
- async enroll(opts) {
133
- const prfResult = await createPrfPasskey(ceremonyContext, opts.user);
134
- if (!prfResult)
135
- return null;
136
- const wrappedCek = await wrapWithPrfResult(prfResult, opts.cek);
137
- return { credentialId: prfResult.credentialId, wrappedCek, prfResult };
276
+ unwrapKeyWithPRFResult(input) {
277
+ return unwrapKeyWithPRFResult(input);
138
278
  },
139
- async unlock(wrappedCeks) {
140
- if (wrappedCeks.length === 0)
141
- return null;
142
- const prfResult = await authenticatePrfPasskey(ceremonyContext, wrappedCeks.map((w) => w.credentialId));
143
- if (!prfResult)
144
- return null;
145
- const match = wrappedCeks.find((w) => w.credentialId === prfResult.credentialId);
146
- if (!match) {
147
- logger.error?.("assertion matched a credential with no wrapped CEK", undefined, { action: "unlock", credentialId: prfResult.credentialId });
148
- return null;
149
- }
150
- const kek = await deriveKek(prfResult.prfOutput);
151
- const cek = await unwrapCek(kek, match);
152
- return { credentialId: prfResult.credentialId, cek };
279
+ async recoverKey(input) {
280
+ const wrappedKeys = prepareRecovery(input);
281
+ const result = await evaluateCredential({
282
+ credentialIds: wrappedKeys.map((wrapped) => wrapped.credentialId),
283
+ preferredCredentialId: input.preferredCredentialId,
284
+ signal: input.signal,
285
+ interaction: input.interaction,
286
+ }, "recoverKey");
287
+ const wrapped = wrappedKeys.find((candidate) => candidate.credentialId === result.credentialId);
288
+ if (!wrapped)
289
+ throw invalidInput("credential has no matching wrapped key", "recoverKey");
290
+ return {
291
+ credentialId: result.credentialId,
292
+ key: await unwrapKeyWithPRFResult({ wrappedKey: wrapped, prfResult: result.prfResult }, "recoverKey"),
293
+ };
153
294
  },
154
- async unlockWithCachedPrf(wrappedCeks) {
155
- const cached = getCachedPrfResult();
295
+ async recoverKeyFromCache(input) {
296
+ const wrappedKeys = prepareRecovery(input);
297
+ const cached = loadCachedResult();
156
298
  if (!cached)
157
299
  return null;
158
- const match = wrappedCeks.find((w) => w.credentialId === cached.credentialId);
159
- if (!match)
300
+ const wrapped = wrappedKeys.find((candidate) => candidate.credentialId === cached.credentialId);
301
+ if (!wrapped)
160
302
  return null;
161
303
  try {
162
- const kek = await deriveKek(cached.prfOutput);
163
- const cek = await unwrapCek(kek, match);
164
- return { credentialId: cached.credentialId, cek };
165
- }
166
- catch (error) {
167
- logger.error?.("failed to unwrap CEK with cached PRF output", error, {
168
- action: "unlockWithCachedPrf",
304
+ return {
169
305
  credentialId: cached.credentialId,
170
- });
306
+ key: await unwrapKeyWithPRFResult({
307
+ wrappedKey: wrapped,
308
+ prfResult: { output: cached.prfOutput },
309
+ }, "recoverKeyFromCache"),
310
+ };
311
+ }
312
+ catch {
171
313
  return null;
172
314
  }
173
315
  },
174
- async rewrapWithCachedPrf(cek) {
175
- const cached = getCachedPrfResult();
316
+ async rewrapKeyFromCache(input) {
317
+ if (!input || typeof input !== "object")
318
+ throw invalidInput("input is required");
319
+ validateKey(input.key, "rewrapKeyFromCache");
320
+ const cached = loadCachedResult();
176
321
  if (!cached)
177
322
  return null;
178
- return wrapWithPrfResult(cached, cek);
179
- },
180
- wrapWithPrfResult,
181
- async unwrapWithPrfResult(prfResult, wrapped) {
182
- const kek = await deriveKek(prfResult.prfOutput);
183
- return unwrapCek(kek, wrapped);
184
- },
185
- getCachedPrfResult,
186
- clearCachedPrfResult() {
187
- storage?.removeItem(storageKeys.prfResult);
188
- },
189
- getLocalCredentialId() {
190
- return storage?.getItem(storageKeys.localCredentialId) ?? null;
323
+ return wrapKeyWithPRFResult({
324
+ keyMaterial: input.key,
325
+ credentialId: cached.credentialId,
326
+ prfResult: { output: cached.prfOutput },
327
+ }, "rewrapKeyFromCache");
191
328
  },
192
- setLocalCredentialId,
193
329
  clearLocalState() {
194
- storage?.removeItem(storageKeys.prfResult);
195
- storage?.removeItem(storageKeys.localCredentialId);
330
+ try {
331
+ config.storage?.clear();
332
+ }
333
+ catch {
334
+ // Storage is best-effort.
335
+ }
336
+ },
337
+ cancelActiveCeremony() {
338
+ const operation = activeCeremony?.operation;
339
+ activeCeremony?.cancel(new PasskeyKeyError("cancelled", "the passkey operation was cancelled", {
340
+ operation,
341
+ }));
196
342
  },
197
343
  };
198
344
  }
package/dist/kit.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"kit.js","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EACL,sBAAsB,IAAI,gBAAgB,EAC1C,SAAS,EACT,OAAO,GACR,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,0BAA0B,EAAuB,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUhD,OAAO,EACL,sBAAsB,EACtB,gBAAgB,GAEjB,MAAM,eAAe,CAAC;AAEvB,MAAM,oBAAoB,GAA0B;IAClD,SAAS,EAAE,mCAAmC;IAC9C,iBAAiB,EAAE,qCAAqC;CACzD,CAAC;AAEF,MAAM,2BAA2B,GAAG,KAAM,CAAC;AAE3C,8DAA8D;AAC9D,8DAA8D;AAC9D,0EAA0E;AAC1E,0EAA0E;AAC1E,yDAAyD;AACzD,MAAM,wBAAwB,GAAG,KAAM,CAAC;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AAC;YAC1B,CAAC;YAAC,MAAM,CAAC;gBACP,0BAA0B;YAC5B,CAAC;QACH,CAAC;QAED,oBAAoB;YAClB,MAAM,SAAS,GAAG,cAAc,EAAE,SAAS,CAAC;YAC5C,cAAc,EAAE,MAAM,CACpB,IAAI,eAAe,CAAC,WAAW,EAAE,qCAAqC,EAAE;gBACtE,SAAS;aACV,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/storage.d.ts CHANGED
@@ -1,31 +1,17 @@
1
- /**
2
- * Pluggable local persistence for the SDK's device-side state: the cached
3
- * PRF output and the credential id this device owns. Adapters are
4
- * synchronous by design (mirroring the Web Storage API) so callers can
5
- * read cached state without awaiting.
6
- *
7
- * SECURITY: the PRF output cached through an adapter is raw key material —
8
- * anyone who can read it can re-derive the KEK and unwrap the CEK. The
9
- * default `localStorage` adapter stores it in plaintext, which is only as
10
- * strong as the origin's script-injection defenses (an XSS attacker could
11
- * equally just run the ceremony or exfiltrate decrypted data). Hosts with
12
- * stricter requirements should supply their own adapter with at-rest
13
- * protection, or pass `storage: null` to disable caching and re-prompt
14
- * biometrics instead.
15
- */
16
- export interface StorageAdapter {
17
- getItem(key: string): string | null;
18
- setItem(key: string, value: string): void;
19
- removeItem(key: string): void;
1
+ import type { PasskeyKeyProfile } from "./types.js";
2
+ export interface CachedPRFResult {
3
+ profile: PasskeyKeyProfile;
4
+ credentialId: string;
5
+ prfOutput: Uint8Array;
20
6
  }
21
- /**
22
- * Default adapter backed by `window.localStorage`. Every operation is
23
- * best-effort: quota errors, privacy-mode failures, blocked-storage
24
- * contexts (e.g. sandboxed frames, where even touching `localStorage`
25
- * throws), and SSR (no window) all degrade to no-ops so storage problems
26
- * never interrupt a passkey ceremony.
27
- */
28
- export declare const browserLocalStorageAdapter: StorageAdapter;
29
- /** In-memory adapter for tests and non-browser environments. */
30
- export declare function createMemoryStorageAdapter(): StorageAdapter;
7
+ export interface PasskeyKeyStorage {
8
+ loadCachedPRFResult(): CachedPRFResult | null;
9
+ saveCachedPRFResult(result: CachedPRFResult): void;
10
+ loadLocalCredentialId(): string | null;
11
+ saveLocalCredentialId(credentialId: string): void;
12
+ clear(): void;
13
+ }
14
+ export declare function createMemoryPasskeyKeyStorage(): PasskeyKeyStorage;
15
+ /** Stores raw PRF output unencrypted in localStorage under an explicit namespace. */
16
+ export declare function createInsecureBrowserLocalStoragePasskeyKeyStorage(namespace: string): PasskeyKeyStorage;
31
17
  //# sourceMappingURL=storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IACnC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACzC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,EAAE,cAyBxC,CAAA;AAED,gEAAgE;AAChE,wBAAgB,0BAA0B,IAAI,cAAc,CAW3D"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,UAAU,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,IAAI,eAAe,GAAG,IAAI,CAAC;IAC9C,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IACnD,qBAAqB,IAAI,MAAM,GAAG,IAAI,CAAC;IACvC,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,KAAK,IAAI,IAAI,CAAC;CACf;AAkBD,wBAAgB,6BAA6B,IAAI,iBAAiB,CAqBjE;AAWD,qFAAqF;AACrF,wBAAgB,kDAAkD,CAChE,SAAS,EAAE,MAAM,GAChB,iBAAiB,CAkEnB"}