@sparkvault/sdk-js 4.0.0 → 5.0.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.
@@ -945,19 +945,22 @@ class IdentityApi extends SparkVaultApi {
945
945
  });
946
946
  }
947
947
  /**
948
- * Start discoverable passkey verification. Legacy identity parameters are
949
- * intentionally ignored; the credential userHandle routes completion to the
950
- * SVID.
948
+ * Start passkey verification. An optional identifier scopes the ceremony to
949
+ * that person's credentials (`allowCredentials`) so the authenticator offers
950
+ * only the matching passkey; omit it for a discoverable ceremony. Completion
951
+ * always routes via the credential userHandle, so scoping is purely a hint.
951
952
  */
952
- async startPasskeyVerify(_identity, _identityType = 'email', authContext) {
953
+ async startPasskeyVerify(identity, identityType = 'email', authContext) {
954
+ const identityParam = identity ? { [identityType]: identity } : {};
953
955
  // Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
954
956
  // Extract and flatten to match PasskeyChallengeResponse
955
- const response = await this.request('POST', '/passkey/verify', this.buildAuthContextParams(authContext));
957
+ const response = await this.request('POST', '/passkey/verify', { ...identityParam, ...this.buildAuthContextParams(authContext) });
956
958
  return {
957
959
  challenge: response.options.challenge,
958
960
  rpId: response.options.rpId,
959
961
  rpName: 'SparkVault Identity', // Not returned by verify endpoint
960
962
  timeout: response.options.timeout,
963
+ ...(response.options.allowCredentials ? { allowCredentials: response.options.allowCredentials } : {}),
961
964
  session: response.session,
962
965
  };
963
966
  }
@@ -1423,13 +1426,24 @@ class PasskeyHandler {
1423
1426
  */
1424
1427
  async verifyInline() {
1425
1428
  try {
1426
- const challenge = await this.api.startPasskeyVerify(undefined, 'email', this.state.authContext);
1429
+ // When the widget has an identifier, scope the ceremony to that person's
1430
+ // passkeys so the authenticator offers only the matching credential;
1431
+ // without one it falls back to a discoverable ceremony.
1432
+ const identityType = this.state.identityType === 'phone' ? 'phone' : 'email';
1433
+ const challenge = await this.api.startPasskeyVerify(this.state.recipient, identityType, this.state.authContext);
1427
1434
  const credential = await navigator.credentials.get({
1428
1435
  publicKey: {
1429
1436
  challenge: base64urlToArrayBuffer(challenge.challenge),
1430
1437
  rpId: challenge.rpId,
1431
1438
  timeout: challenge.timeout,
1432
1439
  userVerification: 'required',
1440
+ ...(challenge.allowCredentials ? {
1441
+ allowCredentials: challenge.allowCredentials.map((c) => ({
1442
+ type: c.type,
1443
+ id: base64urlToArrayBuffer(c.id),
1444
+ ...(c.transports ? { transports: c.transports } : {}),
1445
+ })),
1446
+ } : {}),
1433
1447
  },
1434
1448
  });
1435
1449
  if (!credential) {
@@ -1506,14 +1520,15 @@ class PasskeyHandler {
1506
1520
  */
1507
1521
  async openPasskeyPopup(mode, registrationToken) {
1508
1522
  return new Promise((resolve) => {
1509
- // Registration carries the freshly verified identifier so the backend
1510
- // can attach the credential to that SVID. Verification is discoverable:
1511
- // the credential userHandle routes completion to the SVID.
1523
+ // Registration carries the freshly verified identifier so the backend can
1524
+ // attach the credential to that SVID. Verification carries it too when
1525
+ // known, to scope the ceremony to that person's passkeys; the credential
1526
+ // userHandle still routes completion to the SVID.
1512
1527
  const params = new URLSearchParams({
1513
1528
  mode,
1514
1529
  origin: window.location.origin,
1515
1530
  });
1516
- if (mode === 'register' && this.state.recipient) {
1531
+ if (this.state.recipient) {
1517
1532
  const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
1518
1533
  params.set(identityParam, this.state.recipient);
1519
1534
  }