@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.
- package/README.md +5 -5
- package/dist/products/identity/api.d.ts +5 -4
- package/dist/products/identity/types.d.ts +15 -0
- package/dist/sparkvault.cjs.js +25 -10
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +25 -10
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ yarn add @sparkvault/sdk-js
|
|
|
53
53
|
<button class="login-btn">Sign In</button>
|
|
54
54
|
|
|
55
55
|
<script>
|
|
56
|
-
SparkVault.identity.attach('.login-btn', {
|
|
56
|
+
SparkVault.products.identity.attach('.login-btn', {
|
|
57
57
|
onSuccess: async (result) => {
|
|
58
58
|
await fetch('/api/auth/verify', {
|
|
59
59
|
method: 'POST',
|
|
@@ -66,7 +66,7 @@ yarn add @sparkvault/sdk-js
|
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
The script auto-initializes `SparkVault` with your account ID. Use
|
|
69
|
-
`SparkVault.identity.attach()` or `SparkVault.identity.pop()` to open the
|
|
69
|
+
`SparkVault.products.identity.attach()` or `SparkVault.products.identity.pop()` to open the
|
|
70
70
|
verification UI and handle the result.
|
|
71
71
|
|
|
72
72
|
### Data Attributes
|
|
@@ -87,7 +87,7 @@ verification UI and handle the result.
|
|
|
87
87
|
></script>
|
|
88
88
|
|
|
89
89
|
<script>
|
|
90
|
-
SparkVault.identity.attach('.js-sparkvault-auth', {
|
|
90
|
+
SparkVault.products.identity.attach('.js-sparkvault-auth', {
|
|
91
91
|
onSuccess: async (result) => {
|
|
92
92
|
const response = await fetch('/api/auth/verify', {
|
|
93
93
|
method: 'POST',
|
|
@@ -110,8 +110,8 @@ verification UI and handle the result.
|
|
|
110
110
|
|
|
111
111
|
### Verification Result
|
|
112
112
|
|
|
113
|
-
The SDK returns this shape from `identity.pop()`, `identity.verify()`, and
|
|
114
|
-
`identity.attach()` callbacks:
|
|
113
|
+
The SDK returns this shape from `products.identity.pop()`, `products.identity.verify()`, and
|
|
114
|
+
`products.identity.attach()` callbacks:
|
|
115
115
|
|
|
116
116
|
```json
|
|
117
117
|
{
|
|
@@ -91,11 +91,12 @@ export declare class IdentityApi extends SparkVaultApi {
|
|
|
91
91
|
credential: PublicKeyCredential;
|
|
92
92
|
}): Promise<PasskeyVerifyResponse>;
|
|
93
93
|
/**
|
|
94
|
-
* Start
|
|
95
|
-
*
|
|
96
|
-
*
|
|
94
|
+
* Start passkey verification. An optional identifier scopes the ceremony to
|
|
95
|
+
* that person's credentials (`allowCredentials`) so the authenticator offers
|
|
96
|
+
* only the matching passkey; omit it for a discoverable ceremony. Completion
|
|
97
|
+
* always routes via the credential userHandle, so scoping is purely a hint.
|
|
97
98
|
*/
|
|
98
|
-
startPasskeyVerify(
|
|
99
|
+
startPasskeyVerify(identity?: string, identityType?: 'email' | 'phone', authContext?: AuthContext): Promise<PasskeyChallengeResponse>;
|
|
99
100
|
/**
|
|
100
101
|
* Complete passkey verification
|
|
101
102
|
*/
|
|
@@ -234,6 +234,16 @@ export interface BackupVerifyResponse {
|
|
|
234
234
|
type: 'email' | 'phone';
|
|
235
235
|
value: string;
|
|
236
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* WebAuthn credential descriptor. Scopes an authentication ceremony to a
|
|
239
|
+
* specific person's passkeys (`allowCredentials`) so the authenticator offers
|
|
240
|
+
* only the matching credential. `id` is base64url-encoded.
|
|
241
|
+
*/
|
|
242
|
+
export interface PasskeyCredentialDescriptor {
|
|
243
|
+
type: 'public-key';
|
|
244
|
+
id: string;
|
|
245
|
+
transports?: AuthenticatorTransport[];
|
|
246
|
+
}
|
|
237
247
|
export interface PasskeyChallengeResponse {
|
|
238
248
|
challenge: string;
|
|
239
249
|
rpId: string;
|
|
@@ -241,6 +251,11 @@ export interface PasskeyChallengeResponse {
|
|
|
241
251
|
userId?: string;
|
|
242
252
|
userName?: string;
|
|
243
253
|
timeout: number;
|
|
254
|
+
/**
|
|
255
|
+
* Present only for an identifier-scoped ceremony: restricts the authenticator
|
|
256
|
+
* to this person's credentials. Absent for a discoverable ceremony.
|
|
257
|
+
*/
|
|
258
|
+
allowCredentials?: PasskeyCredentialDescriptor[];
|
|
244
259
|
/** Session object to pass back in complete request */
|
|
245
260
|
session: Record<string, unknown>;
|
|
246
261
|
}
|
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -949,19 +949,22 @@ class IdentityApi extends SparkVaultApi {
|
|
|
949
949
|
});
|
|
950
950
|
}
|
|
951
951
|
/**
|
|
952
|
-
* Start
|
|
953
|
-
*
|
|
954
|
-
*
|
|
952
|
+
* Start passkey verification. An optional identifier scopes the ceremony to
|
|
953
|
+
* that person's credentials (`allowCredentials`) so the authenticator offers
|
|
954
|
+
* only the matching passkey; omit it for a discoverable ceremony. Completion
|
|
955
|
+
* always routes via the credential userHandle, so scoping is purely a hint.
|
|
955
956
|
*/
|
|
956
|
-
async startPasskeyVerify(
|
|
957
|
+
async startPasskeyVerify(identity, identityType = 'email', authContext) {
|
|
958
|
+
const identityParam = identity ? { [identityType]: identity } : {};
|
|
957
959
|
// Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
|
|
958
960
|
// Extract and flatten to match PasskeyChallengeResponse
|
|
959
|
-
const response = await this.request('POST', '/passkey/verify', this.buildAuthContextParams(authContext));
|
|
961
|
+
const response = await this.request('POST', '/passkey/verify', { ...identityParam, ...this.buildAuthContextParams(authContext) });
|
|
960
962
|
return {
|
|
961
963
|
challenge: response.options.challenge,
|
|
962
964
|
rpId: response.options.rpId,
|
|
963
965
|
rpName: 'SparkVault Identity', // Not returned by verify endpoint
|
|
964
966
|
timeout: response.options.timeout,
|
|
967
|
+
...(response.options.allowCredentials ? { allowCredentials: response.options.allowCredentials } : {}),
|
|
965
968
|
session: response.session,
|
|
966
969
|
};
|
|
967
970
|
}
|
|
@@ -1427,13 +1430,24 @@ class PasskeyHandler {
|
|
|
1427
1430
|
*/
|
|
1428
1431
|
async verifyInline() {
|
|
1429
1432
|
try {
|
|
1430
|
-
|
|
1433
|
+
// When the widget has an identifier, scope the ceremony to that person's
|
|
1434
|
+
// passkeys so the authenticator offers only the matching credential;
|
|
1435
|
+
// without one it falls back to a discoverable ceremony.
|
|
1436
|
+
const identityType = this.state.identityType === 'phone' ? 'phone' : 'email';
|
|
1437
|
+
const challenge = await this.api.startPasskeyVerify(this.state.recipient, identityType, this.state.authContext);
|
|
1431
1438
|
const credential = await navigator.credentials.get({
|
|
1432
1439
|
publicKey: {
|
|
1433
1440
|
challenge: base64urlToArrayBuffer(challenge.challenge),
|
|
1434
1441
|
rpId: challenge.rpId,
|
|
1435
1442
|
timeout: challenge.timeout,
|
|
1436
1443
|
userVerification: 'required',
|
|
1444
|
+
...(challenge.allowCredentials ? {
|
|
1445
|
+
allowCredentials: challenge.allowCredentials.map((c) => ({
|
|
1446
|
+
type: c.type,
|
|
1447
|
+
id: base64urlToArrayBuffer(c.id),
|
|
1448
|
+
...(c.transports ? { transports: c.transports } : {}),
|
|
1449
|
+
})),
|
|
1450
|
+
} : {}),
|
|
1437
1451
|
},
|
|
1438
1452
|
});
|
|
1439
1453
|
if (!credential) {
|
|
@@ -1510,14 +1524,15 @@ class PasskeyHandler {
|
|
|
1510
1524
|
*/
|
|
1511
1525
|
async openPasskeyPopup(mode, registrationToken) {
|
|
1512
1526
|
return new Promise((resolve) => {
|
|
1513
|
-
// Registration carries the freshly verified identifier so the backend
|
|
1514
|
-
//
|
|
1515
|
-
//
|
|
1527
|
+
// Registration carries the freshly verified identifier so the backend can
|
|
1528
|
+
// attach the credential to that SVID. Verification carries it too when
|
|
1529
|
+
// known, to scope the ceremony to that person's passkeys; the credential
|
|
1530
|
+
// userHandle still routes completion to the SVID.
|
|
1516
1531
|
const params = new URLSearchParams({
|
|
1517
1532
|
mode,
|
|
1518
1533
|
origin: window.location.origin,
|
|
1519
1534
|
});
|
|
1520
|
-
if (
|
|
1535
|
+
if (this.state.recipient) {
|
|
1521
1536
|
const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
|
|
1522
1537
|
params.set(identityParam, this.state.recipient);
|
|
1523
1538
|
}
|