@dexterai/connect 0.26.4 → 0.29.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.
@@ -1,383 +0,0 @@
1
- /** Supabase session tokens returned by dexter-api's passkey-login (camelCase). */
2
- interface PasskeyLoginTokens {
3
- accessToken: string;
4
- refreshToken: string;
5
- expiresAt: number;
6
- expiresIn: number;
7
- tokenType: string;
8
- }
9
- /**
10
- * Vault identity, returned ALONGSIDE the session by passkey-login once
11
- * vault-review ships the dexter-api change (ASK 1). Optional until then —
12
- * the connector degrades to session-only. Consumers that open x402 tabs
13
- * (dexter-agents) need `vaultPda` + `publicKey` to build a passkey signer.
14
- */
15
- interface ConnectVault {
16
- vaultPda: string;
17
- /** Swig state address, base58 — the user-facing Dexter Wallet address. */
18
- swigAddress: string;
19
- /** v2 swig wallet PDA (deposit address); null until the swig is deployed. */
20
- receiveAddress: string | null;
21
- /** Swig wallet's USDC ATA, base58 (for the connected-chip balance read);
22
- * null until the swig is deployed. Server-resolved (off-curve-safe). */
23
- usdcAta: string | null;
24
- /** base64 33-byte SEC1 compressed P-256 authority pubkey (for the signer). */
25
- publicKey: string;
26
- userHandle: string;
27
- credentialId: string;
28
- /** The wallet's cross-device display name (user-authored via rename), or
29
- * null when never named. Identity is first-class: every sign-in carries
30
- * the human name so no consumer ever falls back to a synthetic email.
31
- * Optional for wire-compat with servers/popup pages predating 0.23. */
32
- walletLabel?: string | null;
33
- }
34
- /** Result of a completed "Sign in with Dexter" ceremony. */
35
- interface SignInResult {
36
- session: PasskeyLoginTokens;
37
- /** Present once vault-review ships the vault-in-login change. */
38
- vault?: ConnectVault;
39
- }
40
- /**
41
- * Coarse ceremony phase, emitted as a sign-in/create ceremony progresses so the
42
- * UI can show live "connecting steps" instead of one flat spinner:
43
- * challenge → passkey (the OS prompt) → verifying → finalizing (create only).
44
- */
45
- type CeremonyPhase = 'challenge' | 'passkey' | 'verifying' | 'finalizing';
46
- /**
47
- * Controls whether a successful sign-in/recovery immediately changes the
48
- * browser's active-wallet store.
49
- *
50
- * `commit` preserves the historical SDK behavior. `provisional` returns the
51
- * verified session/vault without writing either the active handle or wallet
52
- * roster, so a caller can finish an account-level approval first and then
53
- * explicitly commit the approved wallet with `setActiveHandle`.
54
- */
55
- type WalletStoreMode = 'commit' | 'provisional';
56
- /** Exact action the hosted Dexter consent window is being asked to perform. */
57
- type CeremonyOperation = 'signin' | 'create' | 'continue' | 'recover' | 'sign';
58
- /** Minimal vault identity transferred to Dexter's hosted signing window. */
59
- interface HostedSignVaultIdentity {
60
- vaultPda: string;
61
- publicKey: string;
62
- userHandle: string;
63
- credentialId: string;
64
- walletLabel?: string | null;
65
- }
66
- /**
67
- * Sensitive signing input. This is structured-cloned to the pinned Dexter
68
- * popup only after the browser-stamped hello/ack; it is never serialized into
69
- * the popup URL.
70
- */
71
- interface HostedSignRequestPayload {
72
- operationMessage: Uint8Array;
73
- vault: HostedSignVaultIdentity;
74
- }
75
- /** On-chain-ready assertion bytes returned by the hosted Dexter popup. */
76
- interface HostedSignResult {
77
- signature: Uint8Array;
78
- clientDataJSON: Uint8Array;
79
- authenticatorData: Uint8Array;
80
- }
81
- /**
82
- * Vault identity on the wallet-only recover leg, as reported by
83
- * /api/passkey-vault-anon/status. Narrower than ConnectVault on purpose —
84
- * the status endpoint carries no publicKey/usdcAta, so a recover cannot
85
- * construct a passkey signer; it re-points this browser at the wallet and
86
- * lets useIdentity/useDexterWallet light the UI.
87
- */
88
- interface RecoverVault {
89
- vaultPda: string;
90
- /** Swig state address, base58 — the user-facing Dexter Wallet address. */
91
- swigAddress: string;
92
- /** Deposit address; null until the swig is deployed. */
93
- receiveAddress: string | null;
94
- isActivated: boolean;
95
- walletLabel: string | null;
96
- }
97
- /**
98
- * Result of a wallet-only recover ceremony. A discriminated RESULT, not a
99
- * throw: user-cancel is a normal outcome in WebAuthn, and consumers branch on
100
- * `reason` (no_credential → offer create; cancelled → stay silent; error →
101
- * retry copy). `no_credential` covers both the immediate-mode instant
102
- * rejection (no passkey on this device) and a verify 404 (a passkey the
103
- * server has no row for).
104
- */
105
- type RecoverOutcome = {
106
- ok: true;
107
- userHandle: string;
108
- credentialId: string;
109
- vault: RecoverVault;
110
- } | {
111
- ok: false;
112
- reason: 'no_credential' | 'cancelled' | 'error';
113
- error?: ConnectError;
114
- };
115
- interface RecoverWalletConfig extends DexterConnectConfig {
116
- /** Chrome-149+ immediate UI mode: instant fast-fail when this device has no
117
- * discoverable passkey (no empty account-picker sheet). Falls back to the
118
- * normal modal wherever unsupported. */
119
- preferImmediate?: boolean;
120
- /** See `PasskeyLoginConfig.walletStore`. */
121
- walletStore?: WalletStoreMode;
122
- onPhase?: (phase: CeremonyPhase) => void;
123
- }
124
- /** Configuration for `passkeyLogin`. */
125
- interface PasskeyLoginConfig extends DexterConnectConfig {
126
- /**
127
- * Wallet-store behavior after a successful passkey ceremony. Defaults to
128
- * `commit` for backward compatibility. Use `provisional` when the returned
129
- * wallet must pass a separate approval before becoming active.
130
- */
131
- walletStore?: WalletStoreMode;
132
- }
133
- interface DexterConnectConfig {
134
- /**
135
- * Compatibility-only Dexter API base. Omit it or pass exactly
136
- * https://api.dexter.cash. Noncanonical values fail before WebAuthn and this
137
- * value is never propagated into the hosted popup.
138
- */
139
- apiBase?: string;
140
- /**
141
- * Where the WebAuthn ceremony runs:
142
- * - 'auto' (default): inline on the canonical Dexter origin (dexter.cash),
143
- * popup on ANY other origin — so a third-party site works without the
144
- * WebAuthn rpId-origin problem (in-page only works on dexter.cash).
145
- * - 'popup': always via the hosted popup (works on any website).
146
- * - 'inline': always in-page — only valid on a Dexter origin; this is what
147
- * the hosted ceremony page itself uses.
148
- */
149
- transport?: 'auto' | 'popup' | 'inline';
150
- /** Hosted ceremony page (popup transport). Default https://dexter.cash/connect. */
151
- connectHost?: string;
152
- }
153
- /** Typed error whose `code` is the server's snake_case error string. */
154
- declare class ConnectError extends Error {
155
- readonly code: string;
156
- constructor(code: string, message?: string);
157
- }
158
-
159
- /** Consent-at-birth allowance (Branch rulings 2026-07-02/03).
160
- * The user authors the number; zero is not consent; TTL is fixed 30d and
161
- * never user-editable; no caller may invent a default. */
162
- declare const SESSION_TTL_30D = "2592000";
163
- interface SpendPolicy {
164
- /** Role-2 allowance, atomic USDC (6dp), decimal string. User-authored. */
165
- spendLimitAtomic: string;
166
- /** Fixed 30d. Present for wire compatibility; always SESSION_TTL_30D. */
167
- sessionTtlSeconds: string;
168
- }
169
- /** Parse user-entered USD ("5", "$20", "1,000", "20.5") to atomic USDC.
170
- * Null on anything invalid — callers must not invent a fallback. */
171
- declare function usdToAtomic(input: string): bigint | null;
172
- /** Null when invalid or zero (zero is not consent). */
173
- declare function authoredPolicy(usdInput: string): SpendPolicy | null;
174
-
175
- interface CreateWalletConfig extends DexterConnectConfig {
176
- /**
177
- * Wallet-store behavior after successful creation. Defaults to `commit` for
178
- * backward compatibility. Use `provisional` when the created wallet must
179
- * pass a separate approval before becoming active.
180
- */
181
- walletStore?: WalletStoreMode;
182
- /** Label for the passkey in the OS keychain AND the wallet roster. Set at
183
- * creation — the only moment naming is guaranteed to stick. Default "Dexter Wallet". */
184
- name?: string;
185
- /** RP id for the new credential. Default "dexter.cash". */
186
- rpId?: string;
187
- /** Consent-at-birth allowance the user authored at creation (chips $5/$20/$50
188
- * or Custom; zero is not consent; build it with authoredPolicy()). When
189
- * present it rides the /initialize body so the number becomes the server-side
190
- * write-once consent record. The TTL is ruled fixed 30d — whatever the object
191
- * carries, the wire always sends SESSION_TTL_30D. Absent → no policy authored
192
- * (the vault initializes without one; nothing invents a default). */
193
- spendPolicy?: SpendPolicy;
194
- /** Called as the ceremony progresses, for live "connecting steps" UI:
195
- * challenge → passkey → verifying → finalizing. */
196
- onPhase?: (phase: CeremonyPhase) => void;
197
- }
198
- interface CreateWalletResult {
199
- /** Server-minted 16-byte user handle, base64url — the vault identity. */
200
- handle: string;
201
- /** base64url credential id of the new passkey. */
202
- credentialId: string;
203
- /** The freshly initialized vault (swig not yet deployed; deploys lazily). */
204
- vault: ConnectVault;
205
- /** Wallet name recorded at birth (server-confirmed via /initialize). Rides
206
- * the result so a popup-typed name reaches the OPENER's wallet store —
207
- * before 0.23.2 it lived only on the popup origin. null = unnamed. */
208
- label: string | null;
209
- }
210
- /**
211
- * Mint a brand-new Dexter wallet (passkey + vault). Commit mode (the default)
212
- * makes it active immediately; provisional mode returns it without changing
213
- * the active-wallet store.
214
- *
215
- * One passkey approval. Throws ConnectError on any failed leg (the `code` is the
216
- * server's error string, or webauthn_failed / no_credential for the ceremony).
217
- */
218
- declare function createWallet(config?: CreateWalletConfig): Promise<CreateWalletResult>;
219
-
220
- /**
221
- * "Sign in with Dexter" — the discoverable-credential login ceremony.
222
- *
223
- * 1. POST /login-challenge → a server-issued challenge (no allow-list:
224
- * the resident passkey itself identifies the user)
225
- * 2. navigator.credentials.get over that challenge (no allowCredentials)
226
- * 3. POST /passkey-login → the server resolves the credential + vault,
227
- * verifies the assertion, and returns a Supabase session (+ the vault
228
- * payload once vault-review ships the dexter-api change — ASK 1)
229
- *
230
- * Relays to dexter-api's ANON router — a first-time third-party user has no
231
- * Supabase session, so the Supabase-gated router would 401.
232
- */
233
- declare function passkeyLogin(config?: PasskeyLoginConfig, onPhase?: (phase: CeremonyPhase) => void): Promise<SignInResult>;
234
- type ContinueResult = ({
235
- kind: 'signin';
236
- } & SignInResult) | ({
237
- kind: 'create';
238
- } & CreateWalletResult)
239
- /** This device has no passkey (proven by an immediate fast-fail) but the
240
- * caller supplied no authored spendPolicy — collect name + allowance,
241
- * then call createWallet. */
242
- | {
243
- kind: 'needs_create';
244
- }
245
- /** Cannot silently probe (no immediate support, no local handle): render an
246
- * explicit "Sign in" / "I'm new" choice. Never guess. */
247
- | {
248
- kind: 'needs_choice';
249
- }
250
- /** The user dismissed the passkey sheet. Not an error — stay quiet. */
251
- | {
252
- kind: 'cancelled';
253
- };
254
- declare function continueWithDexter(config?: CreateWalletConfig, onPhase?: (phase: CeremonyPhase) => void): Promise<ContinueResult>;
255
-
256
- type IdentityKind = 'passkey-vault' | 'account' | 'none';
257
- interface IdentityInput {
258
- /** An account session token (e.g. Supabase access_token) when present, else null. */
259
- accountToken: string | null;
260
- /** The passkey-vault user handle (the connect wallet store), else null. */
261
- userHandle: string | null;
262
- /** The active wallet's display name from the connect wallet store (persisted
263
- * at sign-in/recover/rename), else null. Browser-only input like the handle. */
264
- walletLabel?: string | null;
265
- }
266
- interface ResolvedIdentity {
267
- /** The primary identity axis, passkey-vault-first. */
268
- kind: IdentityKind;
269
- /** Passkey-vault identity (FIRST-CLASS): the wallet handle, or null. */
270
- userHandle: string | null;
271
- /** The wallet's human display name, or null when the wallet was never named
272
- * (or no wallet is active). Display surfaces prefer this over any synthetic
273
- * account identifier — a user should never be shown a generated email. */
274
- walletLabel: string | null;
275
- /** Account identity (secondary/legacy axis): bearer for account-scoped fetches, or null. */
276
- accountToken: string | null;
277
- /** A passkey vault is present on this device. */
278
- hasPasskeyVault: boolean;
279
- /** An account session is present. */
280
- hasAccount: boolean;
281
- /** Any identity at all — drives "show the wallet" vs "Sign in with Dexter". */
282
- hasWallet: boolean;
283
- }
284
- declare function resolveIdentity(input: IdentityInput): ResolvedIdentity;
285
-
286
- /** A wallet this browser knows about. `handle` is the identity; the rest is UX. */
287
- interface StoredWallet {
288
- /** base64url 16-byte user handle — the vault identity. */
289
- handle: string;
290
- /** Human label for switch UIs (e.g. an email, or "Dexter Wallet"). */
291
- label?: string;
292
- /** base64url credential id — enables the WebAuthn Signal API to prune this
293
- * passkey from the OS manager on eject (see ./signals). */
294
- credentialId?: string;
295
- /** Epoch ms of last activation — for ordering the switcher. */
296
- lastUsedAt?: number;
297
- }
298
- type Listener = () => void;
299
- /** The active wallet handle, or null if this browser has no active wallet. */
300
- declare function getActiveHandle(): string | null;
301
- /**
302
- * Set the active wallet handle (e.g. after enroll or recover), upserting it into
303
- * the roster with a fresh `lastUsedAt`. Idempotent. Fires subscribers.
304
- */
305
- declare function setActiveHandle(handle: string, label?: string, credentialId?: string): void;
306
- /** Look up a known wallet's stored credentialId (for Signal-API prune on eject). */
307
- declare function getCredentialId(handle: string): string | undefined;
308
- /**
309
- * EJECT — clear the active wallet so the browser is no longer bound to it. This
310
- * is "switch / start fresh / sign out of this wallet". The wallet stays in the
311
- * roster (so the user can switch back) unless `forget` is true. After eject,
312
- * `getActiveHandle()` is null and the next enroll/recover starts clean. Fires
313
- * subscribers. This is the function whose absence WAS the welded-wallet bug.
314
- */
315
- declare function ejectActiveWallet(opts?: {
316
- forget?: boolean;
317
- }): void;
318
- /** Every wallet this browser knows about, most-recently-used first. */
319
- declare function listWallets(): StoredWallet[];
320
- /**
321
- * Switch the active wallet to a handle ALREADY in the roster. Returns false (and
322
- * does nothing) if the handle is unknown — switching is only ever to a wallet
323
- * this browser has seen, never to an arbitrary string.
324
- */
325
- declare function switchWallet(handle: string): boolean;
326
- /** Remove a wallet from the roster entirely; clears active if it was active. */
327
- declare function forgetWallet(handle: string): void;
328
- /**
329
- * Subscribe to active-wallet/roster changes. Returns an unsubscribe fn. Also
330
- * wires the cross-tab `storage` event once, so ejecting in one tab updates the
331
- * others. The React hook (`useDexterWallet`) is a thin wrapper over this.
332
- */
333
- declare function subscribe(listener: Listener): () => void;
334
- /** Exposed for consumers that must reference the canonical key (migrations,
335
- * tests). Prefer the accessors above — do NOT read localStorage by hand. */
336
- declare const ACTIVE_WALLET_STORAGE_KEY = "dexter:passkey:userHandle";
337
-
338
- interface PasskeySignalSupport {
339
- /** signalCurrentUserDetails — rename a passkey post-creation. */
340
- rename: boolean;
341
- /** signalUnknownCredential — remove one stale passkey from the manager. */
342
- prune: boolean;
343
- /** signalAllAcceptedCredentials — reconcile the full valid set. */
344
- syncAccepted: boolean;
345
- }
346
- /**
347
- * What the CURRENT browser supports, by direct feature-detection. Instant, no
348
- * network, no UA sniffing — tells you exactly what will light up on THIS device
349
- * (e.g. call once on Branch's iPhone to learn its Safari's status).
350
- */
351
- declare function passkeySignalSupport(): PasskeySignalSupport;
352
- /**
353
- * Rename a passkey in the OS keychain AFTER creation. `userId` is the base64url
354
- * user handle; `rpId` defaults to the current host. Returns true if the signal
355
- * fired, false if unsupported/failed (caller treats false as "left as-is").
356
- */
357
- declare function renamePasskey(args: {
358
- userId: string;
359
- name: string;
360
- displayName?: string;
361
- rpId?: string;
362
- }): Promise<boolean>;
363
- /**
364
- * Tell the OS manager a credential is gone so it removes that passkey from the
365
- * user's list — the welded-old-wallet auto-cleanup. `credentialId` is base64url.
366
- * Returns true if fired, false if unsupported/failed.
367
- */
368
- declare function prunePasskey(args: {
369
- credentialId: string;
370
- rpId?: string;
371
- }): Promise<boolean>;
372
- /**
373
- * Declare the FULL set of still-valid credential IDs for a user; the manager
374
- * prunes anything not listed. Use after sign-in or eject to reconcile in one
375
- * shot (pass `[]` to clear all of a user's passkeys). Returns true if fired.
376
- */
377
- declare function syncAcceptedPasskeys(args: {
378
- userId: string;
379
- acceptedCredentialIds: string[];
380
- rpId?: string;
381
- }): Promise<boolean>;
382
-
383
- export { ACTIVE_WALLET_STORAGE_KEY as A, passkeySignalSupport as B, type ConnectVault as C, type DexterConnectConfig as D, prunePasskey as E, renamePasskey as F, resolveIdentity as G, type HostedSignRequestPayload as H, type IdentityKind as I, setActiveHandle as J, subscribe as K, switchWallet as L, syncAcceptedPasskeys as M, usdToAtomic as N, type PasskeyLoginConfig as P, type RecoverWalletConfig as R, SESSION_TTL_30D as S, type WalletStoreMode as W, type RecoverOutcome as a, type CeremonyPhase as b, type CeremonyOperation as c, ConnectError as d, type ContinueResult as e, type CreateWalletConfig as f, type CreateWalletResult as g, type HostedSignResult as h, type HostedSignVaultIdentity as i, type IdentityInput as j, type PasskeyLoginTokens as k, type PasskeySignalSupport as l, type RecoverVault as m, type ResolvedIdentity as n, type SignInResult as o, type SpendPolicy as p, type StoredWallet as q, authoredPolicy as r, continueWithDexter as s, createWallet as t, ejectActiveWallet as u, forgetWallet as v, getActiveHandle as w, getCredentialId as x, listWallets as y, passkeyLogin as z };