@dexterai/connect 0.26.4 → 0.29.1

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.
@@ -0,0 +1,245 @@
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
+ /** Dexter-signed Wallet identity proof returned by a completed passkey ceremony. */
10
+ interface WalletIdentityProof {
11
+ token: string;
12
+ tokenType: 'Bearer';
13
+ /** Epoch seconds. */
14
+ expiresAt: number;
15
+ /** Lifetime in seconds. */
16
+ expiresIn: number;
17
+ }
18
+ /**
19
+ * Wallet identity returned alongside the account session by passkey login.
20
+ * `vaultPda` and `publicKey` are required by the passkey signer.
21
+ */
22
+ interface ConnectVault {
23
+ vaultPda: string;
24
+ /** Swig state address, base58 — the user-facing Dexter Wallet address. */
25
+ swigAddress: string;
26
+ /** v2 swig wallet PDA (deposit address); null until the swig is deployed. */
27
+ receiveAddress: string | null;
28
+ /** Swig wallet's USDC ATA, base58 (for the connected-chip balance read);
29
+ * null until the swig is deployed. Server-resolved (off-curve-safe). */
30
+ usdcAta: string | null;
31
+ /** base64 33-byte SEC1 compressed P-256 authority pubkey (for the signer). */
32
+ publicKey: string;
33
+ userHandle: string;
34
+ credentialId: string;
35
+ /** The wallet's cross-device display name (user-authored via rename), or
36
+ * null when never named. Identity is first-class: every sign-in carries
37
+ * the human name so no consumer ever falls back to a synthetic email.
38
+ * Optional for wire-compat with servers/popup pages predating 0.23. */
39
+ walletLabel?: string | null;
40
+ }
41
+ /** Result of a completed "Sign in with Dexter" ceremony. */
42
+ interface SignInResult {
43
+ session: PasskeyLoginTokens;
44
+ vault: ConnectVault;
45
+ walletIdentityProof: WalletIdentityProof;
46
+ }
47
+ /**
48
+ * Coarse ceremony phase, emitted as a sign-in/create ceremony progresses so the
49
+ * UI can show live "connecting steps" instead of one flat spinner:
50
+ * challenge → passkey (the OS prompt) → verifying → finalizing (create only).
51
+ */
52
+ type CeremonyPhase = 'challenge' | 'passkey' | 'verifying' | 'finalizing';
53
+ /**
54
+ * Controls whether a successful sign-in/recovery immediately changes the
55
+ * browser's active-wallet store.
56
+ *
57
+ * `commit` preserves the historical SDK behavior. `provisional` returns the
58
+ * verified session and Wallet without changing the browser's active Wallet.
59
+ * The canonical identity transition uses it until the exact Wallet/account
60
+ * pair has been verified.
61
+ */
62
+ type WalletStoreMode = 'commit' | 'provisional';
63
+ /**
64
+ * Controls whether wallet creation also asks the owner to configure an agent
65
+ * spending allowance.
66
+ *
67
+ * `deferred` creates the wallet for its owner. `configure-now` is the explicit
68
+ * compatibility path for a caller that has already collected an agent
69
+ * spending allowance.
70
+ */
71
+ type AgentDelegationMode = 'configure-now' | 'deferred';
72
+ /** Exact action the hosted Dexter consent window is being asked to perform. */
73
+ type CeremonyOperation = 'signin' | 'create' | 'continue' | 'recover' | 'sign';
74
+ /** Minimal vault identity transferred to Dexter's hosted signing window. */
75
+ interface HostedSignVaultIdentity {
76
+ vaultPda: string;
77
+ publicKey: string;
78
+ userHandle: string;
79
+ credentialId: string;
80
+ walletLabel?: string | null;
81
+ }
82
+ /**
83
+ * Sensitive signing input. This is structured-cloned to the pinned Dexter
84
+ * popup only after the browser-stamped hello/ack; it is never serialized into
85
+ * the popup URL.
86
+ */
87
+ interface HostedSignRequestPayload {
88
+ operationMessage: Uint8Array;
89
+ vault: HostedSignVaultIdentity;
90
+ }
91
+ /** On-chain-ready assertion bytes returned by the hosted Dexter popup. */
92
+ interface HostedSignResult {
93
+ signature: Uint8Array;
94
+ clientDataJSON: Uint8Array;
95
+ authenticatorData: Uint8Array;
96
+ }
97
+ /**
98
+ * Vault identity on the wallet-only recover leg, as reported by
99
+ * /api/passkey-vault-anon/status. Narrower than ConnectVault on purpose —
100
+ * the status endpoint carries no publicKey/usdcAta, so a recover cannot
101
+ * construct a passkey signer; it only restores the browser Wallet candidate.
102
+ */
103
+ interface RecoverVault {
104
+ vaultPda: string;
105
+ /** Swig state address, base58 — the user-facing Dexter Wallet address. */
106
+ swigAddress: string;
107
+ /** Deposit address; null until the swig is deployed. */
108
+ receiveAddress: string | null;
109
+ isActivated: boolean;
110
+ walletLabel: string | null;
111
+ }
112
+ /**
113
+ * Result of a wallet-only recover ceremony. A discriminated RESULT, not a
114
+ * throw: user-cancel is a normal outcome in WebAuthn, and consumers branch on
115
+ * `reason` (no_credential → offer create; cancelled → stay silent; error →
116
+ * retry copy). `no_credential` covers both the immediate-mode instant
117
+ * rejection (no passkey on this device) and a verify 404 (a passkey the
118
+ * server has no row for).
119
+ */
120
+ type RecoverOutcome = {
121
+ ok: true;
122
+ userHandle: string;
123
+ credentialId: string;
124
+ vault: RecoverVault;
125
+ walletIdentityProof: WalletIdentityProof;
126
+ } | {
127
+ ok: false;
128
+ reason: 'no_credential' | 'cancelled' | 'error';
129
+ error?: ConnectError;
130
+ };
131
+ interface RecoverWalletConfig extends DexterConnectConfig {
132
+ /** Chrome-149+ immediate UI mode: instant fast-fail when this device has no
133
+ * discoverable passkey (no empty account-picker sheet). Falls back to the
134
+ * normal modal wherever unsupported. */
135
+ preferImmediate?: boolean;
136
+ /** See `PasskeyLoginConfig.walletStore`. */
137
+ walletStore?: WalletStoreMode;
138
+ onPhase?: (phase: CeremonyPhase) => void;
139
+ }
140
+ /** Configuration for `passkeyLogin`. */
141
+ interface PasskeyLoginConfig extends DexterConnectConfig {
142
+ /**
143
+ * Wallet-store behavior after a successful passkey ceremony. Defaults to
144
+ * `commit` for backward compatibility. Use `provisional` when the returned
145
+ * wallet must pass a separate approval before becoming active.
146
+ */
147
+ walletStore?: WalletStoreMode;
148
+ }
149
+ interface DexterConnectConfig {
150
+ /**
151
+ * Compatibility-only Dexter API base. Omit it or pass exactly
152
+ * https://api.dexter.cash. Noncanonical values fail before WebAuthn and this
153
+ * value is never propagated into the hosted popup.
154
+ */
155
+ apiBase?: string;
156
+ /**
157
+ * Where the WebAuthn ceremony runs:
158
+ * - 'auto' (default): inline on the canonical Dexter origin (dexter.cash),
159
+ * popup on ANY other origin — so a third-party site works without the
160
+ * WebAuthn rpId-origin problem (in-page only works on dexter.cash).
161
+ * - 'popup': always via the hosted popup (works on any website).
162
+ * - 'inline': always in-page — only valid on a Dexter origin; this is what
163
+ * the hosted ceremony page itself uses.
164
+ */
165
+ transport?: 'auto' | 'popup' | 'inline';
166
+ /** Hosted ceremony page (popup transport). Default https://dexter.cash/connect. */
167
+ connectHost?: string;
168
+ }
169
+ /** Typed error whose `code` is the server's snake_case error string. */
170
+ declare class ConnectError extends Error {
171
+ readonly code: string;
172
+ constructor(code: string, message?: string);
173
+ }
174
+
175
+ /** Consent-at-birth allowance (Branch rulings 2026-07-02/03).
176
+ * The user authors the number; zero is not consent; TTL is fixed 30d and
177
+ * never user-editable; no caller may invent a default. */
178
+ declare const SESSION_TTL_30D = "2592000";
179
+ interface SpendPolicy {
180
+ /** Role-2 allowance, atomic USDC (6dp), decimal string. User-authored. */
181
+ spendLimitAtomic: string;
182
+ /** Fixed 30d. Present for wire compatibility; always SESSION_TTL_30D. */
183
+ sessionTtlSeconds: string;
184
+ }
185
+ /** Parse user-entered USD ("5", "$20", "1,000", "20.5") to atomic USDC.
186
+ * Null on anything invalid — callers must not invent a fallback. */
187
+ declare function usdToAtomic(input: string): bigint | null;
188
+ /** Null when invalid or zero (zero is not consent). */
189
+ declare function authoredPolicy(usdInput: string): SpendPolicy | null;
190
+
191
+ interface CreateWalletConfig extends DexterConnectConfig {
192
+ /**
193
+ * Wallet-store behavior after successful creation. Defaults to `commit` for
194
+ * backward compatibility. Use `provisional` when the created wallet must
195
+ * pass a separate approval before becoming active.
196
+ */
197
+ walletStore?: WalletStoreMode;
198
+ /** Label for the passkey in the OS keychain AND the wallet roster. Set at
199
+ * creation — the only moment naming is guaranteed to stick. Default "Dexter Wallet". */
200
+ name?: string;
201
+ /** RP id for the new credential. Default "dexter.cash". */
202
+ rpId?: string;
203
+ /** Consent-at-birth allowance the user authored at creation (chips $5/$20/$50
204
+ * or Custom; zero is not consent; build it with authoredPolicy()). When
205
+ * present it rides the /initialize body so the number becomes the server-side
206
+ * write-once consent record. The TTL is ruled fixed 30d — whatever the object
207
+ * carries, the wire always sends SESSION_TTL_30D. Absent → no policy authored
208
+ * (the vault initializes without one; nothing invents a default). */
209
+ spendPolicy?: SpendPolicy;
210
+ /**
211
+ * When agent authority is configured. The default, `deferred`, creates the
212
+ * wallet without an agent allowance. `configure-now` is an explicit
213
+ * compatibility path for callers that have already collected a
214
+ * `spendPolicy`. A deferred creation must not also carry a `spendPolicy`.
215
+ */
216
+ agentDelegation?: AgentDelegationMode;
217
+ /** Called as the ceremony progresses, for live "connecting steps" UI:
218
+ * challenge → passkey → verifying → finalizing. */
219
+ onPhase?: (phase: CeremonyPhase) => void;
220
+ }
221
+ interface CreateWalletResult {
222
+ /** Server-minted 16-byte user handle, base64url — the vault identity. */
223
+ handle: string;
224
+ /** base64url credential id of the new passkey. */
225
+ credentialId: string;
226
+ /** The freshly initialized vault (swig not yet deployed; deploys lazily). */
227
+ vault: ConnectVault;
228
+ /** Wallet name recorded at birth (server-confirmed via /initialize). Rides
229
+ * the result so a popup-typed name reaches the OPENER's wallet store —
230
+ * before 0.23.2 it lived only on the popup origin. null = unnamed. */
231
+ label: string | null;
232
+ /** Dexter-signed proof used to restore this Wallet's account relationship. */
233
+ walletIdentityProof: WalletIdentityProof;
234
+ }
235
+ /**
236
+ * Mint a brand-new Dexter wallet (passkey + vault). Commit mode (the default)
237
+ * makes it active immediately; provisional mode returns it without changing
238
+ * the active-wallet store.
239
+ *
240
+ * One passkey approval. Throws ConnectError on any failed leg (the `code` is the
241
+ * server's error string, or webauthn_failed / no_credential for the ceremony).
242
+ */
243
+ declare function createWallet(config?: CreateWalletConfig): Promise<CreateWalletResult>;
244
+
245
+ export { type AgentDelegationMode as A, type CreateWalletResult as C, type DexterConnectConfig as D, type HostedSignRequestPayload as H, 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 ConnectVault as c, type RecoverWalletConfig as d, type WalletIdentityProof as e, type CeremonyOperation as f, ConnectError as g, type CreateWalletConfig as h, type HostedSignResult as i, type HostedSignVaultIdentity as j, type RecoverVault as k, SESSION_TTL_30D as l, authoredPolicy as m, createWallet as n, type PasskeyLoginConfig as o, usdToAtomic as u };
@@ -0,0 +1,72 @@
1
+ import { S as SignInResult, C as CreateWalletResult, W as WalletStoreMode, a as CeremonyPhase, b as SpendPolicy, R as RecoverOutcome } from './enroll-DrgEW0X8.js';
2
+
3
+ type ContinueResult = ({
4
+ kind: 'signin';
5
+ } & SignInResult) | ({
6
+ kind: 'create';
7
+ } & CreateWalletResult)
8
+ /** This device has no passkey (proven by an immediate fast-fail) but the
9
+ * caller supplied neither an authored spendPolicy nor explicit deferred
10
+ * agent setup — collect name + allowance, then call createWallet. */
11
+ | {
12
+ kind: 'needs_create';
13
+ }
14
+ /** Cannot silently probe (no immediate support, no local handle): render an
15
+ * explicit "Sign in" / "I'm new" choice. Never guess. */
16
+ | {
17
+ kind: 'needs_choice';
18
+ }
19
+ /** The user dismissed the passkey sheet. Not an error — stay quiet. */
20
+ | {
21
+ kind: 'cancelled';
22
+ };
23
+
24
+ /** The only production browser origin allowed to run an inline Dexter ceremony. */
25
+ declare const DEXTER_HOSTED_CEREMONY_ORIGIN = "https://dexter.cash";
26
+ type HostedCeremonyOperation = 'signin' | 'continue' | 'create' | 'recover';
27
+ type HostedContinueResult = ContinueResult;
28
+ interface HostedCeremonyBase {
29
+ /** Commit to Dexter's host-side Wallet store, or return the Wallet provisionally. */
30
+ walletStore?: WalletStoreMode;
31
+ onPhase?: (phase: CeremonyPhase) => void;
32
+ }
33
+ interface HostedSignInCeremony extends HostedCeremonyBase {
34
+ operation: 'signin';
35
+ }
36
+ type HostedDelegationChoice = {
37
+ agentDelegation: 'configure-now';
38
+ spendPolicy: SpendPolicy;
39
+ } | {
40
+ agentDelegation: 'deferred';
41
+ spendPolicy?: never;
42
+ } | {
43
+ agentDelegation?: undefined;
44
+ spendPolicy?: SpendPolicy;
45
+ };
46
+ type HostedContinueCeremony = HostedCeremonyBase & HostedDelegationChoice & {
47
+ operation: 'continue';
48
+ name?: string;
49
+ };
50
+ type HostedCreateCeremony = HostedCeremonyBase & HostedDelegationChoice & {
51
+ operation: 'create';
52
+ name?: string;
53
+ };
54
+ interface HostedRecoverCeremony extends HostedCeremonyBase {
55
+ operation: 'recover';
56
+ preferImmediate?: boolean;
57
+ }
58
+ type HostedCeremonyRequest = HostedSignInCeremony | HostedContinueCeremony | HostedCreateCeremony | HostedRecoverCeremony;
59
+ type HostedCeremonyResult<O extends HostedCeremonyOperation> = O extends 'signin' ? SignInResult : O extends 'continue' ? HostedContinueResult : O extends 'create' ? CreateWalletResult : RecoverOutcome;
60
+ /**
61
+ * Run one first-party hosted Wallet ceremony.
62
+ *
63
+ * The caller chooses only the operation and host-side persistence behavior.
64
+ * API origin and transport are fixed here so a hosted route cannot drift into
65
+ * a second implementation or accept an opener-controlled credential server.
66
+ */
67
+ declare function runHostedCeremony(request: HostedSignInCeremony): Promise<SignInResult>;
68
+ declare function runHostedCeremony(request: HostedContinueCeremony): Promise<HostedContinueResult>;
69
+ declare function runHostedCeremony(request: HostedCreateCeremony): Promise<CreateWalletResult>;
70
+ declare function runHostedCeremony(request: HostedRecoverCeremony): Promise<RecoverOutcome>;
71
+
72
+ export { DEXTER_HOSTED_CEREMONY_ORIGIN, type HostedCeremonyOperation, type HostedCeremonyRequest, type HostedCeremonyResult, type HostedContinueCeremony, type HostedContinueResult, type HostedCreateCeremony, type HostedRecoverCeremony, type HostedSignInCeremony, runHostedCeremony };
package/dist/hosted.js ADDED
@@ -0,0 +1,95 @@
1
+ import {
2
+ recoverWallet
3
+ } from "./chunk-LHYU2EZQ.js";
4
+ import {
5
+ ConnectError,
6
+ DEXTER_API_BASE,
7
+ continueWithDexter,
8
+ createWallet,
9
+ passkeyLogin,
10
+ resolveAgentDelegationMode,
11
+ resolveWalletStoreMode
12
+ } from "./chunk-CZL7NGVV.js";
13
+ import "./chunk-EMCGL64H.js";
14
+
15
+ // src/hosted.ts
16
+ var DEXTER_HOSTED_CEREMONY_ORIGIN = "https://dexter.cash";
17
+ async function runHostedCeremony(request) {
18
+ assertHostedCeremonyOrigin();
19
+ const walletStore = resolveWalletStoreMode(request.walletStore);
20
+ assertHostedDelegationChoice(request);
21
+ const persistence = walletStore === "provisional" ? { walletStore } : {};
22
+ switch (request.operation) {
23
+ case "signin":
24
+ return await passkeyLogin(
25
+ {
26
+ apiBase: DEXTER_API_BASE,
27
+ transport: "inline",
28
+ ...persistence
29
+ },
30
+ request.onPhase
31
+ );
32
+ case "continue":
33
+ return await continueWithDexter(
34
+ {
35
+ apiBase: DEXTER_API_BASE,
36
+ transport: "inline",
37
+ ...persistence,
38
+ ...request.name !== void 0 ? { name: request.name } : {},
39
+ ...request.spendPolicy !== void 0 ? { spendPolicy: request.spendPolicy } : {},
40
+ ...request.agentDelegation !== void 0 ? { agentDelegation: request.agentDelegation } : {}
41
+ },
42
+ request.onPhase
43
+ );
44
+ case "create":
45
+ return await createWallet({
46
+ apiBase: DEXTER_API_BASE,
47
+ transport: "inline",
48
+ ...persistence,
49
+ ...request.name !== void 0 ? { name: request.name } : {},
50
+ ...request.spendPolicy !== void 0 ? { spendPolicy: request.spendPolicy } : {},
51
+ ...request.agentDelegation !== void 0 ? { agentDelegation: request.agentDelegation } : {},
52
+ ...request.onPhase !== void 0 ? { onPhase: request.onPhase } : {}
53
+ });
54
+ case "recover":
55
+ return await recoverWallet({
56
+ apiBase: DEXTER_API_BASE,
57
+ transport: "inline",
58
+ ...persistence,
59
+ ...request.preferImmediate !== void 0 ? { preferImmediate: request.preferImmediate } : {},
60
+ ...request.onPhase !== void 0 ? { onPhase: request.onPhase } : {}
61
+ });
62
+ default:
63
+ throw new ConnectError("unsupported_hosted_ceremony");
64
+ }
65
+ }
66
+ function assertHostedDelegationChoice(request) {
67
+ if (request.operation !== "continue" && request.operation !== "create") return;
68
+ const agentDelegation = resolveAgentDelegationMode(
69
+ request.agentDelegation ?? (request.spendPolicy ? "configure-now" : void 0)
70
+ );
71
+ if (agentDelegation === "configure-now" && !request.spendPolicy) {
72
+ throw new ConnectError(
73
+ "missing_spend_policy",
74
+ "agentDelegation configure-now requires a spendPolicy"
75
+ );
76
+ }
77
+ if (agentDelegation === "deferred" && request.spendPolicy) {
78
+ throw new ConnectError(
79
+ "conflicting_agent_delegation",
80
+ "agentDelegation deferred cannot include a spendPolicy"
81
+ );
82
+ }
83
+ }
84
+ function assertHostedCeremonyOrigin() {
85
+ if (typeof window === "undefined" || window.location.origin !== DEXTER_HOSTED_CEREMONY_ORIGIN) {
86
+ throw new ConnectError(
87
+ "hosted_ceremony_origin_required",
88
+ `Hosted Wallet ceremonies run only on ${DEXTER_HOSTED_CEREMONY_ORIGIN}`
89
+ );
90
+ }
91
+ }
92
+ export {
93
+ DEXTER_HOSTED_CEREMONY_ORIGIN,
94
+ runHostedCeremony
95
+ };