@sparkvault/sdk-js 2.0.4 → 2.1.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.
@@ -5869,7 +5869,7 @@ class IdentityRenderer {
5869
5869
  return new MethodSelectView({
5870
5870
  email: state.email,
5871
5871
  methods: state.methods,
5872
- onSelectMethod: (method) => this.handleMethodSelect(method),
5872
+ onSelectMethod: (method) => this.handleMethodSelect(method, true),
5873
5873
  onBack: state.email ? () => this.showIdentityInput() : undefined,
5874
5874
  });
5875
5875
  case 'totp-verify':
@@ -6048,7 +6048,13 @@ class IdentityRenderer {
6048
6048
  getAllowedIdentityTypes() {
6049
6049
  return this.verificationState.getAllowedIdentityTypes();
6050
6050
  }
6051
- async handleMethodSelect(method) {
6051
+ /**
6052
+ * @param userInitiated True when called from a live click on the picker, so
6053
+ * a popup may be opened synchronously within that gesture. False when
6054
+ * auto-selected after an async step (e.g. the single enabled method), where
6055
+ * opening a popup would be blocked.
6056
+ */
6057
+ async handleMethodSelect(method, userInitiated = false) {
6052
6058
  try {
6053
6059
  switch (method.type) {
6054
6060
  case 'totp': {
@@ -6076,11 +6082,21 @@ class IdentityRenderer {
6076
6082
  break;
6077
6083
  }
6078
6084
  case 'passkey': {
6079
- this.setState({
6080
- view: 'passkey',
6081
- recipient: this.recipient,
6082
- mode: 'verify',
6083
- });
6085
+ if (userInitiated) {
6086
+ // Live picker tap: open the passkey popup directly within this
6087
+ // gesture (window.open in verify() runs before the first await),
6088
+ // skipping the redundant in-widget passkey screen.
6089
+ await this.launchPasskeyVerify();
6090
+ }
6091
+ else {
6092
+ // Auto-selected without a fresh gesture: a popup would be blocked,
6093
+ // so land on the passkey view whose button supplies the gesture.
6094
+ this.setState({
6095
+ view: 'passkey',
6096
+ recipient: this.recipient,
6097
+ mode: 'verify',
6098
+ });
6099
+ }
6084
6100
  break;
6085
6101
  }
6086
6102
  case 'sparklink': {
@@ -6269,6 +6285,24 @@ class IdentityRenderer {
6269
6285
  const result = currentMode === 'register'
6270
6286
  ? await this.passkeyHandler.register()
6271
6287
  : await this.passkeyHandler.verify();
6288
+ this.applyPasskeyResult(result, currentMode);
6289
+ }
6290
+ /**
6291
+ * Open the verify popup straight from a live picker gesture, showing a
6292
+ * loading state while the ceremony runs. window.open inside verify() fires
6293
+ * synchronously (before the first await), so it stays within the gesture.
6294
+ */
6295
+ async launchPasskeyVerify() {
6296
+ this.setState({ view: 'loading' });
6297
+ const result = await this.passkeyHandler.verify();
6298
+ this.applyPasskeyResult(result, 'verify');
6299
+ }
6300
+ /**
6301
+ * Apply a passkey ceremony result: complete on success, or route to the
6302
+ * matching recovery state. Shared by the passkey view and the direct
6303
+ * picker launch so both behave identically.
6304
+ */
6305
+ applyPasskeyResult(result, currentMode) {
6272
6306
  if (result.success && result.result) {
6273
6307
  this.close();
6274
6308
  this.safeOnSuccess(result.result);
@@ -6284,24 +6318,22 @@ class IdentityRenderer {
6284
6318
  message: 'This SparkVault Identity is locked. Visit auth.sv to manage it.',
6285
6319
  });
6286
6320
  }
6321
+ else if (result.errorType === 'not_found') {
6322
+ // No passkey yet — pivot the same screen to registration.
6323
+ this.setState({
6324
+ view: 'passkey',
6325
+ recipient: this.recipient,
6326
+ mode: 'register',
6327
+ error: result.error,
6328
+ });
6329
+ }
6287
6330
  else {
6288
- // Handle different error types
6289
- if (result.errorType === 'not_found') {
6290
- this.setState({
6291
- view: 'passkey',
6292
- recipient: this.recipient,
6293
- mode: 'register',
6294
- error: result.error,
6295
- });
6296
- }
6297
- else {
6298
- this.setState({
6299
- view: 'passkey',
6300
- recipient: this.recipient,
6301
- mode: currentMode,
6302
- error: result.error,
6303
- });
6304
- }
6331
+ this.setState({
6332
+ view: 'passkey',
6333
+ recipient: this.recipient,
6334
+ mode: currentMode,
6335
+ error: result.error,
6336
+ });
6305
6337
  }
6306
6338
  }
6307
6339
  /**