@sparkvault/sdk-js 8.4.0 → 8.6.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 +2 -2
- package/dist/products/identity/handlers/passkey-handler.d.ts +11 -1
- package/dist/products/identity/renderer.d.ts +29 -0
- package/dist/products/identity/types.d.ts +2 -0
- package/dist/products/identity/views/identity-input.d.ts +8 -0
- package/dist/products/identity/views/index.d.ts +1 -0
- package/dist/products/identity/views/passkey-auto.d.ts +22 -0
- package/dist/sparkvault.cjs.js +183 -11
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +183 -11
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +2 -2
package/dist/sparkvault.esm.js
CHANGED
|
@@ -1443,6 +1443,15 @@ class PopupLauncher {
|
|
|
1443
1443
|
/** Passkey popup window dimensions. */
|
|
1444
1444
|
const POPUP_WIDTH = 450;
|
|
1445
1445
|
const POPUP_HEIGHT = 500;
|
|
1446
|
+
/**
|
|
1447
|
+
* Device-level hint the Identity API sets on every completed passkey login
|
|
1448
|
+
* (products/product-identity/src/utils/passkey-hint-cookie.js — the cookie
|
|
1449
|
+
* NAME is the wire contract between the two). Host-locked to the Identity
|
|
1450
|
+
* origin and deliberately JS-readable, it means "a passkey login has completed
|
|
1451
|
+
* in this browser", which is what licenses auto-starting the discoverable
|
|
1452
|
+
* ceremony for returning people without ever prompting first-time visitors.
|
|
1453
|
+
*/
|
|
1454
|
+
const PASSKEY_HINT_COOKIE = '__Host-authsv_passkey';
|
|
1446
1455
|
/** `data.type` the passkey popup posts back. */
|
|
1447
1456
|
const PASSKEY_RESULT_TYPE = 'sparkvault-passkey-result';
|
|
1448
1457
|
/**
|
|
@@ -1503,9 +1512,9 @@ class PasskeyHandler {
|
|
|
1503
1512
|
* supported in cross-origin iframes, so the embedded widget uses the inline
|
|
1504
1513
|
* path.)
|
|
1505
1514
|
*/
|
|
1506
|
-
async verify() {
|
|
1515
|
+
async verify(signal) {
|
|
1507
1516
|
if (this.canRunCeremonyInline()) {
|
|
1508
|
-
return this.verifyInline();
|
|
1517
|
+
return this.verifyInline(signal);
|
|
1509
1518
|
}
|
|
1510
1519
|
return this.openPasskeyPopup('verify');
|
|
1511
1520
|
}
|
|
@@ -1519,11 +1528,27 @@ class PasskeyHandler {
|
|
|
1519
1528
|
&& !!navigator.credentials
|
|
1520
1529
|
&& window.location.origin === this.trustedOrigin;
|
|
1521
1530
|
}
|
|
1531
|
+
/**
|
|
1532
|
+
* True when the discoverable ceremony may be fired WITHOUT a user gesture:
|
|
1533
|
+
* the flow is running on the Identity origin (the inline ceremony needs no
|
|
1534
|
+
* popup, so no gesture) AND this browser carries the passkey-hint cookie —
|
|
1535
|
+
* a passkey login has completed here before. First visits never see an
|
|
1536
|
+
* unprompted system sheet.
|
|
1537
|
+
*/
|
|
1538
|
+
canAutoVerify() {
|
|
1539
|
+
if (!this.canRunCeremonyInline())
|
|
1540
|
+
return false;
|
|
1541
|
+
return document.cookie
|
|
1542
|
+
.split(';')
|
|
1543
|
+
.some((part) => part.trim().startsWith(`${PASSKEY_HINT_COOKIE}=1`));
|
|
1544
|
+
}
|
|
1522
1545
|
/**
|
|
1523
1546
|
* Run the discoverable verification ceremony directly in this document and
|
|
1524
1547
|
* map the outcome onto the same PasskeyResult shape the popup produces.
|
|
1548
|
+
* An optional AbortSignal cancels the pending system sheet (the auto-started
|
|
1549
|
+
* ceremony's "Use another method" escape hatch).
|
|
1525
1550
|
*/
|
|
1526
|
-
async verifyInline() {
|
|
1551
|
+
async verifyInline(signal) {
|
|
1527
1552
|
try {
|
|
1528
1553
|
// When the widget has an identifier, scope the ceremony to that person's
|
|
1529
1554
|
// passkeys so the authenticator offers only the matching credential;
|
|
@@ -1531,6 +1556,7 @@ class PasskeyHandler {
|
|
|
1531
1556
|
const identityType = this.state.identityType === 'phone' ? 'phone' : 'email';
|
|
1532
1557
|
const challenge = await this.api.startPasskeyVerify(this.state.recipient, identityType, this.state.authContext);
|
|
1533
1558
|
const credential = await navigator.credentials.get({
|
|
1559
|
+
...(signal ? { signal } : {}),
|
|
1534
1560
|
publicKey: {
|
|
1535
1561
|
challenge: base64urlToArrayBuffer(challenge.challenge),
|
|
1536
1562
|
rpId: challenge.rpId,
|
|
@@ -1576,8 +1602,10 @@ class PasskeyHandler {
|
|
|
1576
1602
|
* (cancelled, identity locked, no passkey → registration).
|
|
1577
1603
|
*/
|
|
1578
1604
|
mapInlineCeremonyError(error) {
|
|
1579
|
-
// User dismissed the system sheet
|
|
1580
|
-
|
|
1605
|
+
// User dismissed the system sheet or no credential was available
|
|
1606
|
+
// (NotAllowedError), or the caller aborted the pending ceremony via its
|
|
1607
|
+
// AbortSignal (AbortError). Both end the ceremony without a credential.
|
|
1608
|
+
if (error instanceof Error && (error.name === 'NotAllowedError' || error.name === 'AbortError')) {
|
|
1581
1609
|
return {
|
|
1582
1610
|
success: false,
|
|
1583
1611
|
error: 'Authentication was cancelled. Please try again.',
|
|
@@ -4184,6 +4212,7 @@ class IdentityInputView {
|
|
|
4184
4212
|
this.inputElement = null;
|
|
4185
4213
|
this.labelElement = null;
|
|
4186
4214
|
this.submitButton = null;
|
|
4215
|
+
this.passkeyLink = null;
|
|
4187
4216
|
this.errorContainer = null;
|
|
4188
4217
|
this.focusTimeoutId = null;
|
|
4189
4218
|
this.detectedType = 'email';
|
|
@@ -4196,6 +4225,7 @@ class IdentityInputView {
|
|
|
4196
4225
|
}
|
|
4197
4226
|
};
|
|
4198
4227
|
this.boundHandleSubmit = () => this.handleSubmit();
|
|
4228
|
+
this.boundHandlePasskey = props.onPasskey ? () => props.onPasskey() : null;
|
|
4199
4229
|
}
|
|
4200
4230
|
get allowsBoth() {
|
|
4201
4231
|
return this.props.allowedTypes.includes('email') && this.props.allowedTypes.includes('phone');
|
|
@@ -4251,6 +4281,13 @@ class IdentityInputView {
|
|
|
4251
4281
|
this.submitButton.addEventListener('click', this.boundHandleSubmit);
|
|
4252
4282
|
formSection.appendChild(this.submitButton);
|
|
4253
4283
|
container.appendChild(formSection);
|
|
4284
|
+
if (this.boundHandlePasskey) {
|
|
4285
|
+
this.passkeyLink = document.createElement('button');
|
|
4286
|
+
this.passkeyLink.className = 'sv-fallback-link';
|
|
4287
|
+
this.passkeyLink.textContent = 'Sign in with a passkey';
|
|
4288
|
+
this.passkeyLink.addEventListener('click', this.boundHandlePasskey);
|
|
4289
|
+
container.appendChild(this.passkeyLink);
|
|
4290
|
+
}
|
|
4254
4291
|
this.focusTimeoutId = setTimeout(() => this.inputElement?.focus(), 50);
|
|
4255
4292
|
return container;
|
|
4256
4293
|
}
|
|
@@ -4394,6 +4431,9 @@ class IdentityInputView {
|
|
|
4394
4431
|
if (this.submitButton) {
|
|
4395
4432
|
this.submitButton.removeEventListener('click', this.boundHandleSubmit);
|
|
4396
4433
|
}
|
|
4434
|
+
if (this.passkeyLink && this.boundHandlePasskey) {
|
|
4435
|
+
this.passkeyLink.removeEventListener('click', this.boundHandlePasskey);
|
|
4436
|
+
}
|
|
4397
4437
|
}
|
|
4398
4438
|
}
|
|
4399
4439
|
|
|
@@ -5061,6 +5101,55 @@ class PasskeyView {
|
|
|
5061
5101
|
}
|
|
5062
5102
|
}
|
|
5063
5103
|
|
|
5104
|
+
/**
|
|
5105
|
+
* Passkey Auto-Verify View
|
|
5106
|
+
*
|
|
5107
|
+
* Shown behind the browser's passkey sheet while an auto-started discoverable
|
|
5108
|
+
* ceremony runs (returning browsers carrying the passkey-hint cookie). The
|
|
5109
|
+
* ceremony was fired without a click, so this screen has no action button —
|
|
5110
|
+
* only a live status and an escape hatch to the identifier form for anyone
|
|
5111
|
+
* who wants a different method (or whose sheet hangs).
|
|
5112
|
+
*/
|
|
5113
|
+
class PasskeyAutoView {
|
|
5114
|
+
constructor(props) {
|
|
5115
|
+
this.fallbackLink = null;
|
|
5116
|
+
this.props = props;
|
|
5117
|
+
this.boundHandleFallback = () => this.props.onUseAnotherMethod();
|
|
5118
|
+
}
|
|
5119
|
+
render() {
|
|
5120
|
+
const container = div();
|
|
5121
|
+
const iconContainer = div();
|
|
5122
|
+
iconContainer.appendChild(createPasskeyIcon());
|
|
5123
|
+
const title = document.createElement('h3');
|
|
5124
|
+
title.className = 'sv-title';
|
|
5125
|
+
title.textContent = 'Signing you in';
|
|
5126
|
+
const subtitle = document.createElement('p');
|
|
5127
|
+
subtitle.className = 'sv-subtitle';
|
|
5128
|
+
subtitle.textContent = 'Use your passkey to continue';
|
|
5129
|
+
const spinner = document.createElement('div');
|
|
5130
|
+
spinner.className = 'sv-spinner';
|
|
5131
|
+
spinner.setAttribute('role', 'status');
|
|
5132
|
+
spinner.setAttribute('aria-label', 'Waiting for your passkey');
|
|
5133
|
+
const spinnerRow = div('sv-loading');
|
|
5134
|
+
spinnerRow.appendChild(spinner);
|
|
5135
|
+
this.fallbackLink = document.createElement('button');
|
|
5136
|
+
this.fallbackLink.className = 'sv-fallback-link';
|
|
5137
|
+
this.fallbackLink.textContent = 'Use another method';
|
|
5138
|
+
this.fallbackLink.addEventListener('click', this.boundHandleFallback);
|
|
5139
|
+
container.appendChild(iconContainer);
|
|
5140
|
+
container.appendChild(title);
|
|
5141
|
+
container.appendChild(subtitle);
|
|
5142
|
+
container.appendChild(spinnerRow);
|
|
5143
|
+
container.appendChild(this.fallbackLink);
|
|
5144
|
+
return container;
|
|
5145
|
+
}
|
|
5146
|
+
destroy() {
|
|
5147
|
+
if (this.fallbackLink) {
|
|
5148
|
+
this.fallbackLink.removeEventListener('click', this.boundHandleFallback);
|
|
5149
|
+
}
|
|
5150
|
+
}
|
|
5151
|
+
}
|
|
5152
|
+
|
|
5064
5153
|
/**
|
|
5065
5154
|
* Passkey Registration Prompt View
|
|
5066
5155
|
*
|
|
@@ -6036,6 +6125,9 @@ class IdentityRenderer {
|
|
|
6036
6125
|
this.currentView = null;
|
|
6037
6126
|
this.focusTimeoutId = null;
|
|
6038
6127
|
this.morphTimer = null;
|
|
6128
|
+
// Live discoverable (no-identifier) ceremony. The controller cancels the
|
|
6129
|
+
// pending browser sheet when the person escapes to the identifier form.
|
|
6130
|
+
this.discoverableVerifyAbort = null;
|
|
6039
6131
|
// Post-login recommendation pipeline: the verified result to finalize with,
|
|
6040
6132
|
// and the remaining server-recommended steps to walk before finalizing.
|
|
6041
6133
|
this.postLoginResult = null;
|
|
@@ -6247,6 +6339,10 @@ class IdentityRenderer {
|
|
|
6247
6339
|
close() {
|
|
6248
6340
|
// Cancel all pending API requests first
|
|
6249
6341
|
this.api.abort();
|
|
6342
|
+
// A pending discoverable ceremony would otherwise hold the browser sheet
|
|
6343
|
+
// open against a dialog that no longer exists.
|
|
6344
|
+
this.discoverableVerifyAbort?.abort();
|
|
6345
|
+
this.discoverableVerifyAbort = null;
|
|
6250
6346
|
if (this.focusTimeoutId !== null) {
|
|
6251
6347
|
clearTimeout(this.focusTimeoutId);
|
|
6252
6348
|
this.focusTimeoutId = null;
|
|
@@ -6275,6 +6371,58 @@ class IdentityRenderer {
|
|
|
6275
6371
|
await this.showMethodSelect();
|
|
6276
6372
|
return;
|
|
6277
6373
|
}
|
|
6374
|
+
// Returning browser on the Identity origin (passkey-hint cookie present):
|
|
6375
|
+
// auto-start the discoverable ceremony instead of asking for an identifier
|
|
6376
|
+
// — the Google-style one-touch return. A cancel lands on the identifier
|
|
6377
|
+
// form, which keeps a "Sign in with a passkey" way back in.
|
|
6378
|
+
if (this.canDiscoverableVerify()) {
|
|
6379
|
+
void this.launchDiscoverableVerify();
|
|
6380
|
+
return;
|
|
6381
|
+
}
|
|
6382
|
+
this.showIdentityInput();
|
|
6383
|
+
}
|
|
6384
|
+
/**
|
|
6385
|
+
* True when the discoverable ceremony may be started without a gesture and
|
|
6386
|
+
* this account actually offers passkey login: the flow runs on the Identity
|
|
6387
|
+
* origin, the browser carries the passkey hint, and `passkey` is among the
|
|
6388
|
+
* account's enabled methods.
|
|
6389
|
+
*/
|
|
6390
|
+
canDiscoverableVerify() {
|
|
6391
|
+
if (!this.passkeyHandler.canAutoVerify())
|
|
6392
|
+
return false;
|
|
6393
|
+
const methods = enrichMethods(this.sdkConfig?.methods ?? []);
|
|
6394
|
+
return methods.some((m) => m.type === 'passkey');
|
|
6395
|
+
}
|
|
6396
|
+
/**
|
|
6397
|
+
* Run the no-identifier discoverable ceremony behind the passkey-auto view.
|
|
6398
|
+
* Fired on open for returning browsers and from the identifier form's
|
|
6399
|
+
* "Sign in with a passkey" shortcut. Anything short of a terminal outcome
|
|
6400
|
+
* (dismissed sheet, no credential on the device, transient failure) falls
|
|
6401
|
+
* back to the identifier form with no error banner — the person simply
|
|
6402
|
+
* lands where a first-time visitor starts.
|
|
6403
|
+
*/
|
|
6404
|
+
async launchDiscoverableVerify() {
|
|
6405
|
+
this.discoverableVerifyAbort = new AbortController();
|
|
6406
|
+
const { signal } = this.discoverableVerifyAbort;
|
|
6407
|
+
this.setState({ view: 'passkey-auto' });
|
|
6408
|
+
const result = await this.passkeyHandler.verify(signal);
|
|
6409
|
+
if (signal.aborted) {
|
|
6410
|
+
// The person already escaped to the identifier form; the aborted
|
|
6411
|
+
// ceremony's result is stale.
|
|
6412
|
+
return;
|
|
6413
|
+
}
|
|
6414
|
+
this.discoverableVerifyAbort = null;
|
|
6415
|
+
if (this.applyTerminalPasskeyResult(result))
|
|
6416
|
+
return;
|
|
6417
|
+
this.showIdentityInput();
|
|
6418
|
+
}
|
|
6419
|
+
/**
|
|
6420
|
+
* Abort the pending discoverable ceremony (dismisses the browser sheet where
|
|
6421
|
+
* the platform allows) and land on the identifier form.
|
|
6422
|
+
*/
|
|
6423
|
+
cancelDiscoverableVerify() {
|
|
6424
|
+
this.discoverableVerifyAbort?.abort();
|
|
6425
|
+
this.discoverableVerifyAbort = null;
|
|
6278
6426
|
this.showIdentityInput();
|
|
6279
6427
|
}
|
|
6280
6428
|
render() {
|
|
@@ -6385,6 +6533,11 @@ class IdentityRenderer {
|
|
|
6385
6533
|
initialValue: this.recipient,
|
|
6386
6534
|
error: state.error,
|
|
6387
6535
|
onSubmit: (result) => this.handleIdentitySubmit(result),
|
|
6536
|
+
// Returning browsers keep a one-tap way back into the discoverable
|
|
6537
|
+
// ceremony (e.g. after dismissing the auto-started sheet).
|
|
6538
|
+
onPasskey: this.canDiscoverableVerify()
|
|
6539
|
+
? () => { void this.launchDiscoverableVerify(); }
|
|
6540
|
+
: undefined,
|
|
6388
6541
|
});
|
|
6389
6542
|
case 'method-select':
|
|
6390
6543
|
return new MethodSelectView({
|
|
@@ -6436,6 +6589,10 @@ class IdentityRenderer {
|
|
|
6436
6589
|
: undefined,
|
|
6437
6590
|
});
|
|
6438
6591
|
}
|
|
6592
|
+
case 'passkey-auto':
|
|
6593
|
+
return new PasskeyAutoView({
|
|
6594
|
+
onUseAnotherMethod: () => this.cancelDiscoverableVerify(),
|
|
6595
|
+
});
|
|
6439
6596
|
case 'passkey-prompt':
|
|
6440
6597
|
return new PasskeyPromptView({
|
|
6441
6598
|
identityLabel: state.recipient,
|
|
@@ -6868,27 +7025,42 @@ class IdentityRenderer {
|
|
|
6868
7025
|
this.applyPasskeyResult(result, 'verify', fallbackToList);
|
|
6869
7026
|
}
|
|
6870
7027
|
/**
|
|
6871
|
-
*
|
|
6872
|
-
*
|
|
6873
|
-
*
|
|
7028
|
+
* Handle the terminal passkey outcomes every entry point shares: a verified
|
|
7029
|
+
* login (close + onSuccess + redirect), a blocked-Identity interstitial, or
|
|
7030
|
+
* a locked identity. Returns false for the retryable failures each caller
|
|
7031
|
+
* routes according to its own flow.
|
|
6874
7032
|
*/
|
|
6875
|
-
|
|
7033
|
+
applyTerminalPasskeyResult(result) {
|
|
6876
7034
|
if (result.success && result.result) {
|
|
6877
7035
|
this.close();
|
|
6878
7036
|
this.safeOnSuccess(result.result);
|
|
6879
7037
|
if (typeof result.result.redirect === 'string' && result.result.redirect) {
|
|
6880
7038
|
window.location.href = result.result.redirect;
|
|
6881
7039
|
}
|
|
7040
|
+
return true;
|
|
6882
7041
|
}
|
|
6883
|
-
|
|
6884
|
-
|
|
7042
|
+
if (this.renderBlockedInterstitial(result.errorCode)) {
|
|
7043
|
+
// Terminal interstitial already rendered — the owner must subscribe.
|
|
7044
|
+
return true;
|
|
7045
|
+
}
|
|
7046
|
+
if (result.errorCode === 'identity_locked') {
|
|
6885
7047
|
// Dedicated state — retrying cannot unlock the identity.
|
|
6886
7048
|
this.setState({
|
|
6887
7049
|
view: 'error',
|
|
6888
7050
|
code: 'identity_locked',
|
|
6889
7051
|
message: 'This SparkVault Identity is locked. Visit auth.sv to manage it.',
|
|
6890
7052
|
});
|
|
7053
|
+
return true;
|
|
6891
7054
|
}
|
|
7055
|
+
return false;
|
|
7056
|
+
}
|
|
7057
|
+
/**
|
|
7058
|
+
* Apply a passkey ceremony result: complete on success, or route to the
|
|
7059
|
+
* matching recovery state. Shared by the passkey view and the direct
|
|
7060
|
+
* picker launch so both behave identically.
|
|
7061
|
+
*/
|
|
7062
|
+
applyPasskeyResult(result, currentMode, fallbackToList = false) {
|
|
7063
|
+
if (this.applyTerminalPasskeyResult(result)) ;
|
|
6892
7064
|
else if (fallbackToList && this.passkeyFallbackMethodsAvailable()) {
|
|
6893
7065
|
// Auto-launched passkey that the person cancelled or that failed: drop to
|
|
6894
7066
|
// the full method list (passkey still listed) rather than a passkey-only
|