@dexterai/connect 0.31.3 → 0.34.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 CHANGED
@@ -28,6 +28,70 @@ fresh passkey ceremony and replaces the active identity only after verification.
28
28
  Agent authority always requires a separate owner grant. Creating or connecting a
29
29
  Wallet grants no agent spending authority.
30
30
 
31
+ ## Account identity without wallet creation (unreleased)
32
+
33
+ The new Account integration can enroll or authenticate a passkey independently
34
+ of the existing Wallet flow:
35
+
36
+ ```ts
37
+ import { enrollAccountIdentity, signInAccountIdentity } from '@dexterai/connect';
38
+
39
+ const enrolled = await enrollAccountIdentity({ name: 'My Dexter passkey' });
40
+ // On a later visit, use the passkey picker. The application owns persistence.
41
+ const signedIn = await signInAccountIdentity();
42
+ ```
43
+
44
+ Both return `profile: 'account-identity-v1'`, `credential` (user handle,
45
+ credential ID and compressed P-256 public key), and an identity-only Bearer
46
+ `session`. They do not create a wallet, install a Supabase session, discover a
47
+ Principal or authorize money movement. The Account integration must establish
48
+ the current Principal/credential binding and obtain the required approvals.
49
+
50
+ Third-party sites use the origin-bound hosted popup. Inline ceremonies are
51
+ restricted to `https://dexter.cash`, with required user verification and a
52
+ discoverable P-256 credential. The hosted operation names are `account-signin`
53
+ and `account-enroll`. An uncertain enrollment submission must lead to sign-in
54
+ with the new passkey, not automatic creation of another credential.
55
+
56
+ Dexter’s own connection review at `/tabs/setup` uses `enrollAccountAccess`
57
+ or `signInAccountAccess` when the original request includes a refusal ticket.
58
+ Both pass the request ID and ticket to the passkey challenge and its completion.
59
+ The returned `refusalProof` belongs in the current review’s memory. The popup
60
+ returns only the ordinary identity result to the requesting app.
61
+
62
+ These exports need the matching API identity profile and hosted page. Source
63
+ checks do not establish package publication or production availability.
64
+
65
+ ## Dexter Account operations
66
+
67
+ An Account session opens and uses a Dexter Account through one approval step.
68
+ The API prepares one exact operation, the owner approves it with the passkey
69
+ the session is bound to, and the API sends the transaction. The page never
70
+ talks to a chain.
71
+
72
+ ```ts
73
+ import { getAccount, getAccountBalances, openAccount, sendFromAccount } from '@dexterai/connect';
74
+
75
+ const account = await openAccount({ identity, onStep: view => render(view) });
76
+ const balances = await getAccountBalances({ identity });
77
+ await sendFromAccount({ identity, send: { mint, amount: '2500000', to } });
78
+ ```
79
+
80
+ - `identity` is the result of `enrollAccountIdentity` or `signInAccountIdentity`. Its token is the only credential sent.
81
+ - A flow follows the API's `next` step until the API returns none. Don't write the number of approvals into a page.
82
+ - `onStep` receives each step with its phase: `preparing`, `ready`, `passkey`, `sending`, `confirmed`. Word the steps you know from `step`; show `summary` for one you don't.
83
+ - Pass `confirmStep` to hold each prepared step until the owner taps, and resolve it inside the tap handler. Browsers that want a user gesture for a passkey prompt need this when a flow has more than one approval.
84
+ - `getAccountOverview` returns the Account with the chain in use (`network`) and the owning passkey's name and creation time. Show any network other than `mainnet` as a test network, and show the passkey before the first approval.
85
+ - Amounts are smallest-unit strings. `parseAccountAmount` and `formatAccountAmount` convert with a token's `decimals`.
86
+ - A send is the step `approve-send`. The first send of a token is preceded by `prepare-token`, a one-time setup with its own approval. Before either prompt the prepared `details` must match what was asked (the token for setup; the token, amount and recipient for the send), or the call fails with `account_operation_mismatch`.
87
+ - Approvals run only at the top level of `https://dexter.cash`, for rpId `dexter.cash`, with user verification.
88
+ - A lost reply to `complete` is repeated once with the same operation; the API answers a repeat with the first result. `openAccount` can be called again after any interruption.
89
+ - Once an approval has gone out, the step may land even if the reply never comes. Any failure of `complete` is checked against the API's record of the operation. A confirmed step carries on. A step the API records as failed, still prepared or expired throws its error, and only then has nothing been sent. Anything else throws `AccountOperationUnsettledError`, which carries `operationId`. Don't say nothing was sent, and don't offer the same send again. Read the outcome with `getAccountOperation({ identity, operationId })`. `getAccountOverview` returns `unsettled` after a reload or a new sign-in.
90
+ - The caller's `signal` stops a flow up to the approval. After that the flow waits for the API's answer, so leaving the page can't turn an unknown outcome into a reported failure.
91
+ - `statement` is the kit's own text for what the passkey signs, when the API sends it.
92
+ - With lazy opening, sign-up's approvals are checked and held, not sent. Each setup step can be confirmed with `signature: null`, and the Account's status is then `held`: its address takes money at once and it opens on the chain by itself on the first money or the first action. Show a `held` Account exactly like a `ready` one; `openAccount` returns it without prompting. A send is never taken as confirmed without the signature of what it sent.
93
+ - The first action on a held Account finishes the opening inside that request, so it can take a minute. Connect sets no timeout of its own on these requests.
94
+
31
95
  ## Interrupted wallet setup
32
96
 
33
97
  `createWallet()` retains the original passkey when setup is interrupted. Calling
@@ -38,7 +38,7 @@ interface ConnectVault {
38
38
  * Optional for wire-compat with servers/popup pages predating 0.23. */
39
39
  walletLabel?: string | null;
40
40
  }
41
- /** Result of a completed "Sign in with Dexter" ceremony. */
41
+ /** Result of a completed Dexter Connect sign-in ceremony. */
42
42
  interface SignInResult {
43
43
  session: PasskeyLoginTokens;
44
44
  vault: ConnectVault;
@@ -70,7 +70,7 @@ type WalletStoreMode = 'commit' | 'provisional';
70
70
  */
71
71
  type AgentDelegationMode = 'configure-now' | 'deferred';
72
72
  /** Exact action the hosted Dexter consent window is being asked to perform. */
73
- type CeremonyOperation = 'signin' | 'create' | 'continue' | 'recover' | 'sign' | 'recover-missing-vault';
73
+ type CeremonyOperation = 'signin' | 'create' | 'continue' | 'recover' | 'sign' | 'recover-missing-vault' | 'account-signin' | 'account-enroll';
74
74
  /** Minimal vault identity transferred to Dexter's hosted signing window. */
75
75
  interface HostedSignVaultIdentity {
76
76
  vaultPda: string;
@@ -275,4 +275,58 @@ interface CreateWalletResult {
275
275
  */
276
276
  declare function createWallet(config?: CreateWalletConfig): Promise<CreateWalletResult>;
277
277
 
278
- export { type AgentDelegationMode as A, type CreateWalletResult as C, type DexterConnectConfig as D, type HostedSignRequestPayload as H, type MissingVaultRecoveryConfig as M, type PasskeyLoginTokens as P, type RecoverOutcome as R, type SignInResult as S, type WalletStoreMode as W, type CeremonyPhase as a, type SpendPolicy as b, type MissingVaultRecoveryResult as c, type ConnectVault as d, type RecoverWalletConfig as e, type WalletIdentityProof as f, type CeremonyOperation as g, ConnectError as h, type CreateWalletConfig as i, type HostedSignResult as j, type HostedSignVaultIdentity as k, type MissingVaultRecoveryAccount as l, type MissingVaultRecoveryVault as m, type RecoverVault as n, SESSION_TTL_30D as o, authoredPolicy as p, createWallet as q, type PasskeyLoginConfig as r, usdToAtomic as u };
278
+ declare const ACCOUNT_IDENTITY_API_PATH = "/api/connect/account-identity";
279
+ /** Application authentication. It does not authorize a Registry instruction. */
280
+ interface AccountIdentitySession {
281
+ readonly accessToken: string;
282
+ readonly expiresAt: number;
283
+ readonly expiresIn: number;
284
+ readonly tokenType: 'Bearer';
285
+ }
286
+ interface AccountIdentityCredential {
287
+ readonly userHandle: string;
288
+ readonly credentialId: string;
289
+ /** Standard base64, 33-byte compressed P-256 public key. */
290
+ readonly publicKey: string;
291
+ }
292
+ interface AccountIdentityResult {
293
+ readonly profile: 'account-identity-v1';
294
+ readonly session: AccountIdentitySession;
295
+ readonly credential: AccountIdentityCredential;
296
+ }
297
+ interface AccountRefusalRequest {
298
+ readonly request_id: string;
299
+ readonly decline_token: string;
300
+ }
301
+ interface AccountAccessResult extends AccountIdentityResult {
302
+ /** First-party proof valid only for refusing the original connection request. */
303
+ readonly refusalProof: AccountIdentitySession;
304
+ }
305
+ interface AccountIdentityConfig {
306
+ /** Compatibility options accept only the canonical Dexter origins. */
307
+ readonly apiBase?: string;
308
+ readonly connectHost?: string;
309
+ readonly transport?: 'auto' | 'popup' | 'inline';
310
+ readonly onPhase?: (phase: CeremonyPhase) => void;
311
+ }
312
+ interface SignInAccountIdentityConfig extends AccountIdentityConfig {
313
+ readonly targetUserHandle?: string;
314
+ }
315
+ interface EnrollAccountIdentityConfig extends AccountIdentityConfig {
316
+ /** Display label for the credential in the device's passkey picker. */
317
+ readonly name?: string;
318
+ }
319
+ /** Sign in with an existing credential. The caller owns session persistence. */
320
+ declare function signInAccountIdentity(config?: SignInAccountIdentityConfig): Promise<AccountIdentityResult>;
321
+ /** Authenticate the active first-party request with a fresh passkey assertion. */
322
+ declare function signInAccountAccess(config: Pick<SignInAccountIdentityConfig, 'targetUserHandle' | 'onPhase'> & {
323
+ readonly accountRequest: AccountRefusalRequest;
324
+ }): Promise<AccountAccessResult>;
325
+ /** Enroll a passkey and authenticate its identity without creating a wallet. */
326
+ declare function enrollAccountIdentity(config?: EnrollAccountIdentityConfig): Promise<AccountIdentityResult>;
327
+ /** Enroll on the original first-party request and obtain its distinct refusal proof. */
328
+ declare function enrollAccountAccess(config: Pick<EnrollAccountIdentityConfig, 'name' | 'onPhase'> & {
329
+ readonly accountRequest: AccountRefusalRequest;
330
+ }): Promise<AccountAccessResult>;
331
+
332
+ export { type AccountIdentityResult as A, signInAccountAccess as B, type CreateWalletResult as C, type DexterConnectConfig as D, type EnrollAccountIdentityConfig as E, signInAccountIdentity as F, usdToAtomic as G, type HostedSignRequestPayload as H, type PasskeyLoginConfig as I, type MissingVaultRecoveryConfig as M, type PasskeyLoginTokens as P, type RecoverOutcome as R, type SignInResult as S, type WalletStoreMode as W, type CeremonyPhase as a, type SpendPolicy as b, type MissingVaultRecoveryResult as c, type ConnectVault as d, type RecoverWalletConfig as e, ConnectError as f, type WalletIdentityProof as g, ACCOUNT_IDENTITY_API_PATH as h, type AccountAccessResult as i, type AccountIdentityCredential as j, type AccountIdentitySession as k, type AccountRefusalRequest as l, type AgentDelegationMode as m, type CeremonyOperation as n, type CreateWalletConfig as o, type HostedSignResult as p, type HostedSignVaultIdentity as q, type MissingVaultRecoveryAccount as r, type MissingVaultRecoveryVault as s, type RecoverVault as t, SESSION_TTL_30D as u, type SignInAccountIdentityConfig as v, authoredPolicy as w, createWallet as x, enrollAccountAccess as y, enrollAccountIdentity as z };
@@ -18,7 +18,7 @@ import {
18
18
  resolveWalletStoreMode,
19
19
  shouldUsePopup,
20
20
  validateMissingVaultRecoveryAssertion
21
- } from "./chunk-IPEINLMT.js";
21
+ } from "./chunk-Q7HTBUJF.js";
22
22
 
23
23
  // src/missingVaultRecovery.ts
24
24
  import {
@@ -1,5 +1,7 @@
1
1
  import {
2
+ base64ToBytes,
2
3
  base64urlToBytes,
4
+ bytesToBase64,
3
5
  bytesToBase64url
4
6
  } from "./chunk-EMCGL64H.js";
5
7
 
@@ -350,13 +352,13 @@ function parseStoredProofSession(raw) {
350
352
  return null;
351
353
  }
352
354
  }
353
- function sessionFromRecord(handle, record) {
355
+ function sessionFromRecord(handle, record2) {
354
356
  const session = Object.freeze({
355
357
  kind: "dexter_wallet_proof_session",
356
358
  handle,
357
- expiresAt: record.expiresAt
359
+ expiresAt: record2.expiresAt
358
360
  });
359
- proofBySession.set(session, record.proof);
361
+ proofBySession.set(session, record2.proof);
360
362
  return session;
361
363
  }
362
364
  function frozenEvent(operation, handle, session) {
@@ -396,18 +398,18 @@ function createWalletProofSessionStore(options = {}) {
396
398
  return null;
397
399
  }
398
400
  if (raw === null) return null;
399
- const record = parseStoredProofSession(raw);
400
- if (!record) {
401
+ const record2 = parseStoredProofSession(raw);
402
+ if (!record2) {
401
403
  safeRemove(key);
402
404
  publish(frozenEvent("corrupted", handle, null));
403
405
  return null;
404
406
  }
405
- if (record.expiresAt <= nowEpochSeconds()) {
407
+ if (record2.expiresAt <= nowEpochSeconds()) {
406
408
  safeRemove(key);
407
409
  publish(frozenEvent("expired", handle, null));
408
410
  return null;
409
411
  }
410
- return sessionFromRecord(handle, record);
412
+ return sessionFromRecord(handle, record2);
411
413
  };
412
414
  const clear = (handleValue) => {
413
415
  const handle = requireWalletHandle(handleValue);
@@ -430,17 +432,17 @@ function createWalletProofSessionStore(options = {}) {
430
432
  throw new ConnectError("wallet_identity_proof_expired");
431
433
  }
432
434
  if (!storage2) return null;
433
- const record = {
435
+ const record2 = {
434
436
  v: STORAGE_VERSION,
435
437
  proof: parsed.token,
436
438
  expiresAt: parsed.expiresAt
437
439
  };
438
440
  try {
439
- storage2.setItem(keyForHandle(handle), JSON.stringify(record));
441
+ storage2.setItem(keyForHandle(handle), JSON.stringify(record2));
440
442
  } catch {
441
443
  return null;
442
444
  }
443
- const session = sessionFromRecord(handle, record);
445
+ const session = sessionFromRecord(handle, record2);
444
446
  publish(frozenEvent("saved", handle, session));
445
447
  return session;
446
448
  };
@@ -467,8 +469,8 @@ function createWalletProofSessionStore(options = {}) {
467
469
  }
468
470
  const handle = handleFromKey(event.key);
469
471
  if (!handle) return;
470
- const record = event.newValue === null ? null : parseStoredProofSession(event.newValue);
471
- const session = record && record.expiresAt > nowEpochSeconds() ? sessionFromRecord(handle, record) : null;
472
+ const record2 = event.newValue === null ? null : parseStoredProofSession(event.newValue);
473
+ const session = record2 && record2.expiresAt > nowEpochSeconds() ? sessionFromRecord(handle, record2) : null;
472
474
  publish(frozenEvent("external", handle, session));
473
475
  };
474
476
  const subscribe2 = (listener) => {
@@ -1375,6 +1377,12 @@ async function createWalletOperation(config = {}) {
1375
1377
  throw new ConnectError("webauthn_unsupported", "WebAuthn unavailable in this environment");
1376
1378
  }
1377
1379
  const pending = readPendingCreation();
1380
+ if (pending && config.agentDelegation === "deferred" && pending.spendPolicy !== void 0) {
1381
+ throw new ConnectError(
1382
+ "pending_creation_has_spend_policy",
1383
+ "Finish the account setup that included a spending allowance before continuing."
1384
+ );
1385
+ }
1378
1386
  if (pending) return resumeCreation(apiBase, pending, walletStore, config.onPhase);
1379
1387
  const name = config.name && config.name.trim() || DEFAULT_WALLET_NAME;
1380
1388
  config.onPhase?.("challenge");
@@ -1556,8 +1564,273 @@ async function initializeVault(apiBase, userHandle, credentialId, spendPolicy, l
1556
1564
  return await res.json();
1557
1565
  }
1558
1566
 
1567
+ // src/accountIdentity.ts
1568
+ import {
1569
+ browserSupportsWebAuthn,
1570
+ startAuthentication as startAuthentication2,
1571
+ startRegistration as startRegistration2
1572
+ } from "@simplewebauthn/browser";
1573
+ var ACCOUNT_IDENTITY_API_PATH = "/api/connect/account-identity";
1574
+ function record(value) {
1575
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1576
+ }
1577
+ function canonicalBase64url2(value, exactLength) {
1578
+ if (typeof value !== "string" || !/^[A-Za-z0-9_-]+$/.test(value) || value.length > 1400) return false;
1579
+ try {
1580
+ const bytes = base64urlToBytes(value);
1581
+ return bytes.length > 0 && bytes.length <= 1024 && (exactLength === void 0 || bytes.length === exactLength) && bytesToBase64url(bytes) === value;
1582
+ } catch {
1583
+ return false;
1584
+ }
1585
+ }
1586
+ function validPublicKey(value) {
1587
+ if (typeof value !== "string" || value.length !== 44) return false;
1588
+ try {
1589
+ const bytes = base64ToBytes(value);
1590
+ return bytes.length === 33 && (bytes[0] === 2 || bytes[0] === 3) && bytesToBase64(bytes) === value;
1591
+ } catch {
1592
+ return false;
1593
+ }
1594
+ }
1595
+ function positiveInteger(value) {
1596
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
1597
+ }
1598
+ function normalizeSession(session) {
1599
+ if (!record(session) || typeof session.accessToken !== "string" || session.accessToken.length === 0 || /\s/.test(session.accessToken) || session.tokenType !== "Bearer" || !positiveInteger(session.expiresAt) || !positiveInteger(session.expiresIn) || session.expiresIn > 30 * 24 * 60 * 60) {
1600
+ throw new ConnectError("account_identity_result_malformed");
1601
+ }
1602
+ return Object.freeze({
1603
+ accessToken: session.accessToken,
1604
+ expiresAt: session.expiresAt,
1605
+ expiresIn: session.expiresIn,
1606
+ tokenType: "Bearer"
1607
+ });
1608
+ }
1609
+ function normalizeResult(value) {
1610
+ if (!record(value) || value.profile !== "account-identity-v1" || !record(value.credential)) {
1611
+ throw new ConnectError("account_identity_result_malformed");
1612
+ }
1613
+ const { credential } = value;
1614
+ if (!canonicalBase64url2(credential.userHandle, 16) || !canonicalBase64url2(credential.credentialId) || !validPublicKey(credential.publicKey)) {
1615
+ throw new ConnectError("account_identity_result_malformed");
1616
+ }
1617
+ return Object.freeze({
1618
+ profile: "account-identity-v1",
1619
+ session: normalizeSession(value.session),
1620
+ credential: Object.freeze({
1621
+ userHandle: credential.userHandle,
1622
+ credentialId: credential.credentialId,
1623
+ publicKey: credential.publicKey
1624
+ })
1625
+ });
1626
+ }
1627
+ function normalizeAccessResult(value) {
1628
+ const identity = normalizeResult(value);
1629
+ const refusalProof = normalizeSession(record(value) ? value.refusalProof : void 0);
1630
+ if (refusalProof.accessToken === identity.session.accessToken) {
1631
+ throw new ConnectError("account_identity_result_malformed");
1632
+ }
1633
+ return Object.freeze({ ...identity, refusalProof });
1634
+ }
1635
+ function bindRefusalRequest(request) {
1636
+ assertInlineOrigin();
1637
+ if (window.top !== window || window.location.pathname !== "/tabs/setup" || !record(request) || typeof request.request_id !== "string" || typeof request.decline_token !== "string" || !/^vpair_[a-f0-9]{1,80}$/.test(request.request_id) || !/^[a-f0-9]{64}$/.test(request.decline_token) || new URL(window.location.href).searchParams.get("request_id") !== request.request_id) {
1638
+ throw new ConnectError("account_request_mismatch");
1639
+ }
1640
+ return Object.freeze({ request_id: request.request_id, decline_token: request.decline_token });
1641
+ }
1642
+ async function post(apiBase, endpoint, body) {
1643
+ let response;
1644
+ try {
1645
+ response = await fetch(`${apiBase}${ACCOUNT_IDENTITY_API_PATH}/${endpoint}`, {
1646
+ method: "POST",
1647
+ headers: { "Content-Type": "application/json", Accept: "application/json" },
1648
+ body: JSON.stringify(body),
1649
+ credentials: "omit",
1650
+ cache: "no-store",
1651
+ redirect: "error"
1652
+ });
1653
+ } catch {
1654
+ throw new ConnectError(endpoint === "login" || endpoint === "enroll" ? "account_identity_request_uncertain" : "account_identity_unavailable");
1655
+ }
1656
+ if (!response.ok) {
1657
+ const code = await readErrorCode(response);
1658
+ if (endpoint === "enroll" && !(response.status === 400 && code === "account_identity_verification_failed" || response.status === 409 && ["challenge_unavailable", "credential_exists", "credential_changed"].includes(code))) {
1659
+ throw new ConnectError("account_identity_request_uncertain");
1660
+ }
1661
+ throw new ConnectError(code);
1662
+ }
1663
+ try {
1664
+ return await response.json();
1665
+ } catch {
1666
+ throw new ConnectError(endpoint === "enroll" ? "account_identity_request_uncertain" : "account_identity_result_malformed");
1667
+ }
1668
+ }
1669
+ function enrollmentResult(value, decode, expected) {
1670
+ try {
1671
+ const result = decode(value);
1672
+ if (expected && (result.credential.credentialId !== expected.credentialId || result.credential.userHandle !== expected.userHandle)) {
1673
+ throw new ConnectError("account_identity_credential_mismatch");
1674
+ }
1675
+ return result;
1676
+ } catch {
1677
+ throw new ConnectError("account_identity_request_uncertain");
1678
+ }
1679
+ }
1680
+ function assertInlineOrigin() {
1681
+ if (typeof window === "undefined" || window.location.origin !== "https://dexter.cash") {
1682
+ throw new ConnectError("hosted_ceremony_origin_required");
1683
+ }
1684
+ if (!browserSupportsWebAuthn()) throw new ConnectError("webauthn_unsupported");
1685
+ }
1686
+ function loginOptions(value) {
1687
+ if (!record(value) || !record(value.options)) throw new ConnectError("account_identity_challenge_malformed");
1688
+ const options = value.options;
1689
+ if (!canonicalBase64url2(options.challenge) || base64urlToBytes(options.challenge).length < 16 || options.rpId !== DEXTER_RP_ID || options.userVerification !== "required") {
1690
+ throw new ConnectError("account_identity_challenge_malformed");
1691
+ }
1692
+ return options;
1693
+ }
1694
+ function enrollmentOptions(value) {
1695
+ if (!record(value) || !record(value.options)) throw new ConnectError("account_identity_challenge_malformed");
1696
+ const options = value.options;
1697
+ if (!canonicalBase64url2(options.challenge) || base64urlToBytes(options.challenge).length < 16 || !record(options.rp) || options.rp.id !== DEXTER_RP_ID || !record(options.user) || !canonicalBase64url2(options.user.id, 16) || !record(options.authenticatorSelection) || options.authenticatorSelection.userVerification !== "required" || options.authenticatorSelection.residentKey !== "required" || !Array.isArray(options.pubKeyCredParams) || options.pubKeyCredParams.length !== 1 || !record(options.pubKeyCredParams[0]) || options.pubKeyCredParams[0].type !== "public-key" || options.pubKeyCredParams[0].alg !== -7) {
1698
+ throw new ConnectError("account_identity_challenge_malformed");
1699
+ }
1700
+ return options;
1701
+ }
1702
+ function ceremonyError(cause) {
1703
+ if (cause instanceof Error && (cause.name === "NotAllowedError" || cause.name === "AbortError")) {
1704
+ return new ConnectError("user_cancelled");
1705
+ }
1706
+ return new ConnectError("webauthn_failed");
1707
+ }
1708
+ var ceremonyInProgress = false;
1709
+ async function serializeCeremony(run) {
1710
+ if (ceremonyInProgress) throw new ConnectError("account_identity_ceremony_in_progress");
1711
+ ceremonyInProgress = true;
1712
+ try {
1713
+ return await run();
1714
+ } finally {
1715
+ ceremonyInProgress = false;
1716
+ }
1717
+ }
1718
+ async function signInAccountIdentity(config = {}) {
1719
+ return signIn(config, normalizeResult);
1720
+ }
1721
+ async function signInAccountAccess(config) {
1722
+ return signIn(
1723
+ { targetUserHandle: config.targetUserHandle, onPhase: config.onPhase, transport: "inline" },
1724
+ normalizeAccessResult,
1725
+ bindRefusalRequest(config.accountRequest)
1726
+ );
1727
+ }
1728
+ async function signIn(config, decode, accountRequest) {
1729
+ const context = accountRequest ? { accountRequest } : {};
1730
+ const { targetUserHandle, transport, onPhase } = config;
1731
+ const apiBase = resolveDexterApiBase(config.apiBase);
1732
+ const connectHost = resolveDexterConnectHost(config.connectHost);
1733
+ if (targetUserHandle !== void 0 && !canonicalBase64url2(targetUserHandle, 16)) {
1734
+ throw new ConnectError("invalid_target_account");
1735
+ }
1736
+ return serializeCeremony(async () => {
1737
+ let result;
1738
+ if (shouldUsePopup(transport)) {
1739
+ result = decode(await openCeremonyPopup("account-signin", {
1740
+ connectHost,
1741
+ ...targetUserHandle === void 0 ? {} : { targetUserHandle }
1742
+ }));
1743
+ } else {
1744
+ assertInlineOrigin();
1745
+ onPhase?.("challenge");
1746
+ const optionsJSON = loginOptions(await post(apiBase, "login-challenge", context));
1747
+ onPhase?.("passkey");
1748
+ let credential;
1749
+ try {
1750
+ credential = await startAuthentication2({ optionsJSON });
1751
+ } catch (cause) {
1752
+ throw ceremonyError(cause);
1753
+ }
1754
+ onPhase?.("verifying");
1755
+ result = decode(await post(apiBase, "login", { credential, ...context }));
1756
+ if (result.credential.credentialId !== credential.id || credential.response.userHandle && result.credential.userHandle !== credential.response.userHandle) {
1757
+ throw new ConnectError("account_identity_credential_mismatch");
1758
+ }
1759
+ }
1760
+ if (targetUserHandle !== void 0 && result.credential.userHandle !== targetUserHandle) {
1761
+ throw new ConnectError("target_account_mismatch");
1762
+ }
1763
+ return result;
1764
+ });
1765
+ }
1766
+ async function enrollAccountIdentity(config = {}) {
1767
+ return enroll(config, normalizeResult);
1768
+ }
1769
+ async function enrollAccountAccess(config) {
1770
+ return enroll(
1771
+ { name: config.name, onPhase: config.onPhase, transport: "inline" },
1772
+ normalizeAccessResult,
1773
+ bindRefusalRequest(config.accountRequest)
1774
+ );
1775
+ }
1776
+ async function enroll(config, decode, accountRequest) {
1777
+ const context = accountRequest ? { accountRequest } : {};
1778
+ const { transport, onPhase } = config;
1779
+ const apiBase = resolveDexterApiBase(config.apiBase);
1780
+ const connectHost = resolveDexterConnectHost(config.connectHost);
1781
+ if (config.name !== void 0 && (typeof config.name !== "string" || config.name.trim().length > 80)) {
1782
+ throw new ConnectError("invalid_account_identity_name");
1783
+ }
1784
+ const name = config.name?.trim() || "Dexter";
1785
+ return serializeCeremony(async () => {
1786
+ if (shouldUsePopup(transport)) {
1787
+ let value;
1788
+ try {
1789
+ value = await openCeremonyPopup("account-enroll", { connectHost, name });
1790
+ } catch (cause) {
1791
+ if (cause instanceof ConnectError && [
1792
+ "popup_blocked",
1793
+ "not_browser",
1794
+ "user_cancelled",
1795
+ "account_identity_verification_failed",
1796
+ "challenge_unavailable",
1797
+ "credential_exists",
1798
+ "credential_changed",
1799
+ "account_identity_unavailable",
1800
+ "account_identity_challenge_malformed",
1801
+ "webauthn_unsupported",
1802
+ "webauthn_failed"
1803
+ ].includes(cause.code)) throw cause;
1804
+ throw new ConnectError("account_identity_request_uncertain");
1805
+ }
1806
+ return enrollmentResult(value, decode);
1807
+ }
1808
+ assertInlineOrigin();
1809
+ onPhase?.("challenge");
1810
+ const options = enrollmentOptions(await post(apiBase, "enroll-challenge", context));
1811
+ const expectedUserHandle = options.user.id;
1812
+ const optionsJSON = {
1813
+ ...options,
1814
+ rp: { ...options.rp, name: "Dexter" },
1815
+ user: { ...options.user, name, displayName: name }
1816
+ };
1817
+ onPhase?.("passkey");
1818
+ let credential;
1819
+ try {
1820
+ credential = await startRegistration2({ optionsJSON });
1821
+ } catch (cause) {
1822
+ throw ceremonyError(cause);
1823
+ }
1824
+ onPhase?.("verifying");
1825
+ return enrollmentResult(await post(apiBase, "enroll", { credential, ...context }), decode, {
1826
+ credentialId: credential.id,
1827
+ userHandle: expectedUserHandle
1828
+ });
1829
+ });
1830
+ }
1831
+
1559
1832
  // src/relay.ts
1560
- import { startAuthentication as startAuthentication2, browserSupportsWebAuthn } from "@simplewebauthn/browser";
1833
+ import { startAuthentication as startAuthentication3, browserSupportsWebAuthn as browserSupportsWebAuthn2 } from "@simplewebauthn/browser";
1561
1834
 
1562
1835
  // src/immediate.ts
1563
1836
  var immediateCapPromise = null;
@@ -1640,7 +1913,7 @@ async function passkeyLogin(config = {}, onPhase) {
1640
1913
  }
1641
1914
  return result2;
1642
1915
  }
1643
- if (!browserSupportsWebAuthn()) {
1916
+ if (!browserSupportsWebAuthn2()) {
1644
1917
  throw new ConnectError("webauthn_unsupported", "WebAuthn unavailable in this environment");
1645
1918
  }
1646
1919
  onPhase?.("challenge");
@@ -1650,7 +1923,7 @@ async function passkeyLogin(config = {}, onPhase) {
1650
1923
  onPhase?.("passkey");
1651
1924
  let response;
1652
1925
  try {
1653
- response = await startAuthentication2({ optionsJSON: targetedOptions });
1926
+ response = await startAuthentication3({ optionsJSON: targetedOptions });
1654
1927
  } catch (err) {
1655
1928
  throw new ConnectError("webauthn_failed", err instanceof Error ? err.message : String(err));
1656
1929
  }
@@ -1802,6 +2075,7 @@ export {
1802
2075
  parseWalletIdentityProof,
1803
2076
  readErrorCode,
1804
2077
  DEXTER_API_BASE,
2078
+ DEXTER_RP_ID,
1805
2079
  resolveDexterApiBase,
1806
2080
  resolveDexterConnectHost,
1807
2081
  resolveDexterRpId,
@@ -1842,6 +2116,11 @@ export {
1842
2116
  primeImmediateSupport,
1843
2117
  immediateAuthentication,
1844
2118
  classifyWebAuthnRejection,
2119
+ ACCOUNT_IDENTITY_API_PATH,
2120
+ signInAccountIdentity,
2121
+ signInAccountAccess,
2122
+ enrollAccountIdentity,
2123
+ enrollAccountAccess,
1845
2124
  passkeyLogin,
1846
2125
  continueWithDexter
1847
2126
  };
@@ -10,7 +10,7 @@ import {
10
10
  subscribe,
11
11
  walletBindingCandidate,
12
12
  walletProofSessionStore
13
- } from "./chunk-IPEINLMT.js";
13
+ } from "./chunk-Q7HTBUJF.js";
14
14
 
15
15
  // src/relationController.ts
16
16
  function provisionalRelation(walletPresent, accountPresent) {
@@ -1,4 +1,4 @@
1
- import { P as PasskeyLoginTokens, r as PasskeyLoginConfig, a as CeremonyPhase, S as SignInResult } from './enroll-Cqou8Pbi.js';
1
+ import { P as PasskeyLoginTokens, I as PasskeyLoginConfig, a as CeremonyPhase, S as SignInResult } from './accountIdentity-DQ_C-WAi.js';
2
2
 
3
3
  /**
4
4
  * Framework-neutral Wallet/account relationship controller.
package/dist/hosted.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as SignInResult, C as CreateWalletResult, W as WalletStoreMode, a as CeremonyPhase, b as SpendPolicy, R as RecoverOutcome } from './enroll-Cqou8Pbi.js';
1
+ import { S as SignInResult, C as CreateWalletResult, a as CeremonyPhase, W as WalletStoreMode, b as SpendPolicy, A as AccountIdentityResult, R as RecoverOutcome } from './accountIdentity-DQ_C-WAi.js';
2
2
  import { AuthenticationResponseJSON } from '@simplewebauthn/browser';
3
3
 
4
4
  type ContinueResult = ({
@@ -24,7 +24,7 @@ type ContinueResult = ({
24
24
 
25
25
  /** The only production browser origin allowed to run an inline Dexter ceremony. */
26
26
  declare const DEXTER_HOSTED_CEREMONY_ORIGIN = "https://dexter.cash";
27
- type HostedCeremonyOperation = 'signin' | 'continue' | 'create' | 'recover';
27
+ type HostedCeremonyOperation = 'signin' | 'continue' | 'create' | 'recover' | 'account-signin' | 'account-enroll';
28
28
  type HostedContinueResult = ContinueResult;
29
29
  interface HostedCeremonyBase {
30
30
  /** Commit to Dexter's host-side Wallet store, or return the Wallet provisionally. */
@@ -57,8 +57,18 @@ interface HostedRecoverCeremony extends HostedCeremonyBase {
57
57
  operation: 'recover';
58
58
  preferImmediate?: boolean;
59
59
  }
60
- type HostedCeremonyRequest = HostedSignInCeremony | HostedContinueCeremony | HostedCreateCeremony | HostedRecoverCeremony;
61
- type HostedCeremonyResult<O extends HostedCeremonyOperation> = O extends 'signin' ? SignInResult : O extends 'continue' ? HostedContinueResult : O extends 'create' ? CreateWalletResult : RecoverOutcome;
60
+ interface HostedAccountSignInCeremony {
61
+ operation: 'account-signin';
62
+ targetUserHandle?: string;
63
+ onPhase?: (phase: CeremonyPhase) => void;
64
+ }
65
+ interface HostedAccountEnrollCeremony {
66
+ operation: 'account-enroll';
67
+ name?: string;
68
+ onPhase?: (phase: CeremonyPhase) => void;
69
+ }
70
+ type HostedCeremonyRequest = HostedSignInCeremony | HostedContinueCeremony | HostedCreateCeremony | HostedRecoverCeremony | HostedAccountSignInCeremony | HostedAccountEnrollCeremony;
71
+ type HostedCeremonyResult<O extends HostedCeremonyOperation> = O extends 'account-signin' | 'account-enroll' ? AccountIdentityResult : O extends 'signin' ? SignInResult : O extends 'continue' ? HostedContinueResult : O extends 'create' ? CreateWalletResult : RecoverOutcome;
62
72
  /**
63
73
  * Run one first-party hosted Wallet ceremony.
64
74
  *
@@ -70,6 +80,7 @@ declare function runHostedCeremony(request: HostedSignInCeremony): Promise<SignI
70
80
  declare function runHostedCeremony(request: HostedContinueCeremony): Promise<HostedContinueResult>;
71
81
  declare function runHostedCeremony(request: HostedCreateCeremony): Promise<CreateWalletResult>;
72
82
  declare function runHostedCeremony(request: HostedRecoverCeremony): Promise<RecoverOutcome>;
83
+ declare function runHostedCeremony(request: HostedAccountSignInCeremony | HostedAccountEnrollCeremony): Promise<AccountIdentityResult>;
73
84
  /**
74
85
  * Run only the account-bound missing-Vault proof supplied by an opener after
75
86
  * the exact popup handshake. API/session binding and completion stay in the
@@ -77,4 +88,4 @@ declare function runHostedCeremony(request: HostedRecoverCeremony): Promise<Reco
77
88
  */
78
89
  declare function runHostedMissingVaultRecoveryProof(options: unknown): Promise<AuthenticationResponseJSON>;
79
90
 
80
- export { DEXTER_HOSTED_CEREMONY_ORIGIN, type HostedCeremonyOperation, type HostedCeremonyRequest, type HostedCeremonyResult, type HostedContinueCeremony, type HostedContinueResult, type HostedCreateCeremony, type HostedRecoverCeremony, type HostedSignInCeremony, runHostedCeremony, runHostedMissingVaultRecoveryProof };
91
+ export { AccountIdentityResult, DEXTER_HOSTED_CEREMONY_ORIGIN, type HostedAccountEnrollCeremony, type HostedAccountSignInCeremony, type HostedCeremonyOperation, type HostedCeremonyRequest, type HostedCeremonyResult, type HostedContinueCeremony, type HostedContinueResult, type HostedCreateCeremony, type HostedRecoverCeremony, type HostedSignInCeremony, runHostedCeremony, runHostedMissingVaultRecoveryProof };