@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.
package/dist/react.js CHANGED
@@ -1,289 +1,76 @@
1
+ import {
2
+ ceremonyPhaseLabel,
3
+ connectDexterIdentity,
4
+ createDexterControlModel,
5
+ createDexterIdentityCoordinator,
6
+ disconnectDexterIdentity,
7
+ passkeySignalSupport,
8
+ prunePasskey,
9
+ renamePasskey
10
+ } from "./chunk-2BTS6DCR.js";
1
11
  import {
2
12
  ConnectError,
3
13
  authoredPolicy,
4
- ceremonyPhaseLabel,
5
- continueWithDexter,
6
- createPasskeySigner,
7
14
  createWallet,
15
+ disconnectActiveWallet,
8
16
  ejectActiveWallet,
17
+ forgetWallet,
9
18
  getActiveHandle,
10
- getCredentialId,
11
19
  listWallets,
12
- passkeyLogin,
13
- passkeySignalSupport,
14
- prunePasskey,
15
- recoverWallet,
16
- renamePasskey,
17
- resolveIdentity,
20
+ removeWalletFromDeviceRoster,
18
21
  setActiveHandle,
22
+ setActiveWallet,
19
23
  shouldUsePopup,
20
24
  subscribe,
21
- switchWallet
22
- } from "./chunk-H3NXC4S5.js";
25
+ switchWallet,
26
+ walletProofSessionStore
27
+ } from "./chunk-CZL7NGVV.js";
23
28
  import {
24
29
  DexterButton,
25
30
  DexterMark,
26
31
  cx,
27
32
  ensureDexterButtonStyles
28
- } from "./chunk-TLCQSAE5.js";
33
+ } from "./chunk-T62F36N2.js";
34
+ import "./chunk-EMCGL64H.js";
29
35
 
30
- // src/useSignInWithDexter.ts
31
- import { useCallback, useEffect, useMemo, useState } from "react";
36
+ // src/useDexterConnection.ts
37
+ import { useCallback as useCallback2, useEffect as useEffect3, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
32
38
 
33
- // src/balance.ts
34
- async function fetchUsdcBalance(rpcUrl, usdcAta) {
35
- try {
36
- const res = await fetch(rpcUrl, {
37
- method: "POST",
38
- headers: { "content-type": "application/json" },
39
- body: JSON.stringify({
40
- jsonrpc: "2.0",
41
- id: 1,
42
- method: "getAccountInfo",
43
- params: [usdcAta, { encoding: "base64", commitment: "confirmed" }]
44
- })
45
- });
46
- if (!res.ok) return null;
47
- const json = await res.json();
48
- const value = json?.result?.value;
49
- if (!value || !value.data) return 0;
50
- const b64 = Array.isArray(value.data) ? value.data[0] : value.data;
51
- const bytes = base64ToBytes(b64);
52
- if (bytes.length < 72) return 0;
53
- return Number(readU64LE(bytes, 64)) / 1e6;
54
- } catch {
55
- return null;
56
- }
39
+ // src/identity.ts
40
+ function presentOrNull(value) {
41
+ return value && value.length > 0 ? value : null;
57
42
  }
58
- function readU64LE(bytes, offset) {
59
- let v = 0n;
60
- for (let i = 7; i >= 0; i -= 1) v = v << 8n | BigInt(bytes[offset + i]);
61
- return v;
62
- }
63
- function base64ToBytes(s) {
64
- const bin = atob(s);
65
- const out = new Uint8Array(bin.length);
66
- for (let i = 0; i < bin.length; i += 1) out[i] = bin.charCodeAt(i);
67
- return out;
68
- }
69
-
70
- // src/useSignInWithDexter.ts
71
- var DEFAULT_RPC = "https://api.dexter.cash/proxy/helius/rpc";
72
- function useSignInWithDexter(config = {}) {
73
- const { apiBase, rpcUrl = DEFAULT_RPC, transport, connectHost, preferImmediate } = config;
74
- const [status, setStatus] = useState("idle");
75
- const [phase, setPhase] = useState(null);
76
- const [session, setSession] = useState(null);
77
- const [vault, setVault] = useState(null);
78
- const [usdcBalance, setUsdcBalance] = useState(null);
79
- const [error, setError] = useState(null);
80
- const [recovered, setRecovered] = useState(null);
81
- const refreshBalance = useCallback(async () => {
82
- const ata = vault?.usdcAta;
83
- if (!ata) return;
84
- setUsdcBalance(await fetchUsdcBalance(rpcUrl, ata));
85
- }, [vault, rpcUrl]);
86
- const signIn = useCallback(async () => {
87
- setError(null);
88
- setPhase(null);
89
- setStatus("pending");
90
- try {
91
- const result = await passkeyLogin(
92
- {
93
- ...apiBase ? { apiBase } : {},
94
- ...transport ? { transport } : {},
95
- ...connectHost ? { connectHost } : {}
96
- },
97
- setPhase
98
- );
99
- setSession(result.session);
100
- setVault(result.vault ?? null);
101
- setStatus("done");
102
- setPhase(null);
103
- return result;
104
- } catch (err) {
105
- const e = err instanceof ConnectError ? err : new ConnectError("sign_in_failed", String(err));
106
- setError(e);
107
- setStatus("error");
108
- setPhase(null);
109
- throw e;
110
- }
111
- }, [apiBase, transport, connectHost]);
112
- const recover = useCallback(async () => {
113
- setError(null);
114
- setPhase(null);
115
- setStatus("pending");
116
- const outcome = await recoverWallet({
117
- ...apiBase ? { apiBase } : {},
118
- ...transport ? { transport } : {},
119
- ...connectHost ? { connectHost } : {},
120
- ...preferImmediate ? { preferImmediate } : {},
121
- onPhase: setPhase
122
- });
123
- setPhase(null);
124
- setRecovered(outcome);
125
- if (outcome.ok) {
126
- setStatus("done");
127
- } else if (outcome.reason === "error") {
128
- setError(outcome.error ?? new ConnectError("recover_failed"));
129
- setStatus("error");
130
- } else {
131
- setStatus("idle");
132
- }
133
- return outcome;
134
- }, [apiBase, transport, connectHost, preferImmediate]);
135
- const continueWith = useCallback(async () => {
136
- setError(null);
137
- setPhase(null);
138
- setStatus("pending");
139
- try {
140
- const result = await continueWithDexter(
141
- {
142
- ...apiBase ? { apiBase } : {},
143
- ...transport ? { transport } : {},
144
- ...connectHost ? { connectHost } : {}
145
- },
146
- setPhase
147
- );
148
- setPhase(null);
149
- if (result.kind === "signin") {
150
- setSession(result.session);
151
- setVault(result.vault ?? null);
152
- setStatus("done");
153
- } else if (result.kind === "create") {
154
- setVault(result.vault);
155
- setStatus("done");
156
- } else {
157
- setStatus("idle");
158
- }
159
- return result;
160
- } catch (err) {
161
- const e = err instanceof ConnectError ? err : new ConnectError("continue_failed", String(err));
162
- setError(e);
163
- setStatus("error");
164
- setPhase(null);
165
- throw e;
166
- }
167
- }, [apiBase, transport, connectHost]);
168
- const disconnect = useCallback(() => {
169
- setSession(null);
170
- setVault(null);
171
- setUsdcBalance(null);
172
- setError(null);
173
- setRecovered(null);
174
- setStatus("idle");
175
- }, []);
176
- const passkeySigner = useMemo(
177
- () => vault ? createPasskeySigner(vault, apiBase, {
178
- ...connectHost ? { connectHost } : {}
179
- }) : null,
180
- [vault, apiBase, connectHost]
181
- );
182
- useEffect(() => {
183
- void refreshBalance();
184
- }, [refreshBalance]);
43
+ function resolveIdentity(input) {
44
+ const hasPasskeyVault = input.relation.walletPresent;
45
+ const hasAccount = input.relation.accountPresent;
46
+ const userHandle = hasPasskeyVault ? presentOrNull(input.userHandle) : null;
47
+ const walletLabel = userHandle ? presentOrNull(input.walletLabel ?? null) : null;
48
+ const hasAccountAccess = input.relation.privateAccountAccess;
49
+ const accountToken = hasAccountAccess ? presentOrNull(input.accountToken) : null;
185
50
  return {
186
- status,
187
- phase,
188
- isVaultConnected: status === "done" && vault !== null,
189
- signIn,
190
- recover,
191
- continueWith,
192
- recovered,
193
- disconnect,
194
- session,
195
- vault,
196
- vaultAddress: vault?.swigAddress ?? null,
197
- vaultPda: vault?.vaultPda ?? null,
198
- credentialId: vault?.credentialId ?? null,
199
- passkeySigner,
200
- usdcBalance,
201
- refreshBalance,
202
- error
51
+ kind: input.relation.relation,
52
+ userHandle,
53
+ walletLabel,
54
+ accountToken,
55
+ hasPasskeyVault,
56
+ hasAccount,
57
+ hasWallet: hasPasskeyVault,
58
+ hasAccountAccess,
59
+ quarantined: input.relation.quarantined
203
60
  };
204
61
  }
205
62
 
206
- // src/SignInWithDexter.tsx
207
- import { useEffect as useEffect2 } from "react";
208
- import { jsx, jsxs } from "react/jsx-runtime";
209
- function shortAddress(addr) {
210
- return addr.length > 10 ? `${addr.slice(0, 4)}\u2026${addr.slice(-4)}` : addr;
211
- }
212
- function formatUsd(n) {
213
- return n.toLocaleString("en-US", { style: "currency", currency: "USD" });
214
- }
215
- function SignInWithDexter(props) {
216
- const {
217
- mode = "signin",
218
- onSuccess,
219
- onError,
220
- onRecovered,
221
- onContinue,
222
- label = "Sign in with Dexter",
223
- variant = "primary",
224
- block = false,
225
- size = "md",
226
- className,
227
- showConnectedChip = true,
228
- ...config
229
- } = props;
230
- useEffect2(ensureDexterButtonStyles, []);
231
- const c = useSignInWithDexter(config);
232
- const handleClick = async () => {
233
- if (mode === "recover") {
234
- onRecovered?.(await c.recover());
235
- return;
236
- }
237
- if (mode === "continue") {
238
- try {
239
- onContinue?.(await c.continueWith());
240
- } catch (err) {
241
- onError?.(err);
242
- }
243
- return;
244
- }
245
- try {
246
- onSuccess?.(await c.signIn());
247
- } catch (err) {
248
- onError?.(err);
249
- }
250
- };
251
- if (mode === "recover" && c.recovered?.ok) return null;
252
- if (c.isVaultConnected) {
253
- if (!showConnectedChip) return null;
254
- return /* @__PURE__ */ jsxs("span", { className: cx("dx-chip", className), children: [
255
- /* @__PURE__ */ jsx("span", { className: "dx-chip__dot", "aria-hidden": true }),
256
- /* @__PURE__ */ jsx("span", { children: c.vault?.walletLabel ?? (c.vaultAddress ? shortAddress(c.vaultAddress) : "Connected") }),
257
- c.usdcBalance !== null && /* @__PURE__ */ jsxs("span", { className: "dx-chip__bal", children: [
258
- formatUsd(c.usdcBalance),
259
- " available"
260
- ] }),
261
- /* @__PURE__ */ jsx("button", { type: "button", className: "dx-chip__x", onClick: c.disconnect, "aria-label": "Disconnect", children: "\xD7" })
262
- ] });
263
- }
264
- return /* @__PURE__ */ jsx(
265
- DexterButton,
266
- {
267
- loading: c.status === "pending",
268
- loadingLabel: c.phase ? ceremonyPhaseLabel(c.phase) : "Connecting\u2026",
269
- variant,
270
- block,
271
- size,
272
- className,
273
- onClick: handleClick,
274
- children: label
275
- }
276
- );
277
- }
63
+ // src/useDexterIdentity.ts
64
+ import { useEffect as useEffect2, useMemo, useRef, useState as useState2, useSyncExternalStore } from "react";
278
65
 
279
66
  // src/useDexterWallet.ts
280
- import { useCallback as useCallback2, useEffect as useEffect3, useState as useState2 } from "react";
67
+ import { useCallback, useEffect, useState } from "react";
281
68
  var NO_SUPPORT = { rename: false, prune: false, syncAccepted: false };
282
69
  function useDexterWallet() {
283
- const [activeHandle, setHandle] = useState2(() => getActiveHandle());
284
- const [wallets, setWallets] = useState2(() => listWallets());
285
- const [support, setSupport] = useState2(NO_SUPPORT);
286
- useEffect3(() => {
70
+ const [activeHandle, setHandle] = useState(() => getActiveHandle());
71
+ const [wallets, setWallets] = useState(() => listWallets());
72
+ const [support, setSupport] = useState(NO_SUPPORT);
73
+ useEffect(() => {
287
74
  const sync = () => {
288
75
  setHandle(getActiveHandle());
289
76
  setWallets(listWallets());
@@ -292,192 +79,461 @@ function useDexterWallet() {
292
79
  sync();
293
80
  return subscribe(sync);
294
81
  }, []);
295
- const eject = useCallback2((opts) => {
296
- const handle = getActiveHandle();
297
- const credentialId = handle ? getCredentialId(handle) : void 0;
298
- ejectActiveWallet(opts);
299
- if (credentialId) void prunePasskey({ credentialId });
300
- }, []);
301
- const rename = useCallback2(async (name, displayName) => {
82
+ const disconnect = useCallback(() => disconnectActiveWallet(), []);
83
+ const forget = useCallback((handle) => forgetWallet(handle), []);
84
+ const eject = useCallback((opts) => ejectActiveWallet(opts), []);
85
+ const removeFromDevice = useCallback(
86
+ async (handle, confirmation) => {
87
+ const removed = removeWalletFromDeviceRoster(handle, confirmation);
88
+ if (!removed) return { removedFromRoster: false, passkeyPruned: false };
89
+ walletProofSessionStore.handleLifecycle({
90
+ type: "wallet_removed_from_device",
91
+ handle
92
+ });
93
+ const passkeyPruned = removed.credentialId ? await prunePasskey({ credentialId: removed.credentialId }) : false;
94
+ return { removedFromRoster: true, passkeyPruned };
95
+ },
96
+ []
97
+ );
98
+ const rename = useCallback(async (name, displayName) => {
302
99
  const handle = getActiveHandle();
303
100
  if (!handle) return false;
304
101
  const ok = await renamePasskey({ userId: handle, name, displayName });
305
102
  if (ok) setActiveHandle(handle, name);
306
103
  return ok;
307
104
  }, []);
105
+ const switchTo = useCallback((handle) => switchWallet(handle), []);
106
+ const setActive = useCallback(
107
+ (handle, label, credentialId) => setActiveHandle(handle, label, credentialId),
108
+ []
109
+ );
110
+ const activate = useCallback((wallet) => setActiveWallet(wallet), []);
308
111
  return {
309
112
  activeHandle,
310
113
  activeWallet: activeHandle ? wallets.find((w) => w.handle === activeHandle) ?? null : null,
311
114
  wallets,
312
115
  support,
116
+ disconnect,
117
+ forget,
313
118
  eject,
314
- switchTo: useCallback2((handle) => switchWallet(handle), []),
315
- setActive: useCallback2(
316
- (handle, label, credentialId) => setActiveHandle(handle, label, credentialId),
317
- []
318
- ),
119
+ removeFromDevice,
120
+ switchTo,
121
+ setActive,
122
+ activate,
319
123
  rename
320
124
  };
321
125
  }
322
126
 
323
- // src/DexterWalletChip.tsx
324
- import { useEffect as useEffect4 } from "react";
325
-
326
- // src/walletKitStyles.ts
327
- var STYLE_ID = "dexter-connect-wallet-kit-styles";
328
- var WALLET_KIT_CSS = `
329
- .dx-wchip{
330
- display:inline-flex; align-items:center; gap:9px; max-width:240px;
331
- padding:6px 12px 6px 7px; font:inherit; font-weight:600; font-size:.74rem;
332
- letter-spacing:.1em; text-transform:uppercase; cursor:pointer; background:transparent;
333
- color:inherit; border:1px solid color-mix(in srgb,var(--dx-ember,#f26c18) 42%,transparent);
334
- border-radius:var(--dx-radius,0px); -webkit-tap-highlight-color:transparent;
335
- transition:filter .16s ease, box-shadow .16s ease, border-color .16s ease;
127
+ // src/useDexterIdentity.ts
128
+ function relationForPresence(walletPresent, accountPresent) {
129
+ if (walletPresent) return "wallet_only";
130
+ if (accountPresent) return "account_only";
131
+ return "none";
336
132
  }
337
- .dx-wchip:hover{ filter:brightness(1.08); box-shadow:0 8px 18px color-mix(in srgb,var(--dx-ember,#f26c18) 18%,transparent); }
338
- .dx-wchip:focus-visible{ outline:none; box-shadow:0 0 0 3px color-mix(in srgb,var(--dx-ember,#f26c18) 34%,transparent); }
339
- .dx-wchip--signedout{ border-color:color-mix(in srgb,currentColor 22%,transparent); padding-left:12px; }
340
- .dx-wchip__avatar{
341
- width:22px; height:22px; flex-shrink:0; display:inline-flex; align-items:center; justify-content:center;
342
- border-radius:50%; overflow:hidden; font-size:.72rem; font-weight:700; letter-spacing:0; line-height:1;
343
- background:linear-gradient(135deg,var(--dx-ember,#f26c18),var(--dx-ember-2,#ba3a00)); color:var(--dx-fg,#fff4ea);
344
- }
345
- .dx-wchip__avatar img{ width:100%; height:100%; object-fit:cover; }
346
- .dx-wchip__label{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
347
-
348
- .dx-wmenu{ display:flex; flex-direction:column; min-width:248px; }
349
- .dx-wmenu__id{ display:flex; align-items:center; gap:10px; padding:13px 15px; border-bottom:1px solid color-mix(in srgb,currentColor 12%,transparent); }
350
- .dx-wmenu__avatar{ width:32px; height:32px; flex-shrink:0; display:inline-flex; align-items:center; justify-content:center; border-radius:50%; font-weight:700; font-size:.85rem; line-height:1; background:linear-gradient(135deg,var(--dx-ember,#f26c18),var(--dx-ember-2,#ba3a00)); color:var(--dx-fg,#fff4ea); }
351
- .dx-wmenu__meta{ display:flex; flex-direction:column; gap:2px; min-width:0; }
352
- .dx-wmenu__name{ font-weight:700; font-size:.9rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
353
- .dx-wmenu__sub{ font-size:.66rem; letter-spacing:.12em; text-transform:uppercase; opacity:.55; }
354
- .dx-wmenu__list{ display:flex; flex-direction:column; padding:6px; }
355
- .dx-wmenu__item{ display:flex; align-items:center; justify-content:space-between; gap:10px; width:100%; padding:10px 12px; font:inherit; font-size:.82rem; font-weight:600; text-align:left; background:transparent; border:none; color:inherit; cursor:pointer; transition:background .12s ease; }
356
- .dx-wmenu__item:hover{ background:color-mix(in srgb,var(--dx-ember,#f26c18) 10%,transparent); }
357
- .dx-wmenu__item--danger{ color:var(--dx-danger,#e5552e); }
358
- .dx-wmenu__icon{ opacity:.45; font-size:.9rem; }
359
- .dx-wmenu__back{ border-bottom:1px solid color-mix(in srgb,currentColor 10%,transparent); opacity:.85; }
360
- .dx-wmenu__save{ display:flex; flex-direction:column; gap:9px; padding:13px 15px; }
361
- .dx-wmenu__savehint{ font-size:.78rem; line-height:1.4; opacity:.7; }
362
- `;
363
- function ensureWalletKitStyles() {
364
- if (typeof document === "undefined") return;
365
- if (document.getElementById(STYLE_ID)) return;
366
- const el = document.createElement("style");
367
- el.id = STYLE_ID;
368
- el.textContent = WALLET_KIT_CSS;
369
- document.head.appendChild(el);
133
+ function transitionSnapshot(current, accountSession, walletPresent, initial) {
134
+ const accountPresent = accountSession.status === "authenticated";
135
+ const runtime = initial || accountSession.status === "loading" ? { phase: "hydrating" } : walletPresent && accountPresent ? { phase: "checking", reason: "account_change" } : { phase: "ready" };
136
+ return Object.freeze({
137
+ relation: relationForPresence(walletPresent, accountPresent),
138
+ runtime: Object.freeze(runtime),
139
+ walletPresent,
140
+ accountPresent,
141
+ privateAccountAccess: false,
142
+ quarantined: false,
143
+ verifiedAt: null,
144
+ revision: current.revision
145
+ });
370
146
  }
371
- ensureWalletKitStyles();
372
-
373
- // src/DexterWalletChip.tsx
374
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
375
- function DexterWalletChip(props) {
376
- const { connected, label, avatarUrl, avatarInitial, onClick, className, ariaExpanded } = props;
377
- useEffect4(ensureWalletKitStyles, []);
378
- const initial = (avatarInitial ?? label.trim().charAt(0) ?? "D").toUpperCase();
379
- return /* @__PURE__ */ jsxs2(
380
- "button",
381
- {
382
- type: "button",
383
- className: cx("dx-wchip", !connected && "dx-wchip--signedout", className),
384
- onClick,
385
- "aria-expanded": ariaExpanded,
386
- children: [
387
- connected ? /* @__PURE__ */ jsx2("span", { className: "dx-wchip__avatar", "aria-hidden": "true", children: avatarUrl ? /* @__PURE__ */ jsx2("img", { src: avatarUrl, alt: "" }) : initial }) : null,
388
- /* @__PURE__ */ jsx2("span", { className: "dx-wchip__label", children: label })
389
- ]
147
+ function useDexterIdentity({
148
+ accountSession,
149
+ ...coordinatorOptions
150
+ }) {
151
+ const [coordinator] = useState2(
152
+ () => createDexterIdentityCoordinator(coordinatorOptions)
153
+ );
154
+ const relation = useSyncExternalStore(
155
+ coordinator.subscribe,
156
+ coordinator.getSnapshot,
157
+ coordinator.getSnapshot
158
+ );
159
+ const { activeHandle, activeWallet } = useDexterWallet();
160
+ const initialized = useRef(false);
161
+ const lifecycleGeneration = useRef(0);
162
+ const desired = useRef({
163
+ status: accountSession.status,
164
+ accessToken: accountSession.status === "authenticated" ? accountSession.accessToken : null,
165
+ marker: /* @__PURE__ */ Symbol("account-session")
166
+ });
167
+ const nextAccessToken = accountSession.status === "authenticated" ? accountSession.accessToken : null;
168
+ if (desired.current.status !== accountSession.status || desired.current.accessToken !== nextAccessToken) {
169
+ desired.current = {
170
+ status: accountSession.status,
171
+ accessToken: nextAccessToken,
172
+ marker: /* @__PURE__ */ Symbol("account-session")
173
+ };
174
+ }
175
+ const desiredMarker = desired.current.marker;
176
+ const [settledMarker, setSettledMarker] = useState2(null);
177
+ useEffect2(() => {
178
+ let cancelled = false;
179
+ const marker = desiredMarker;
180
+ if (accountSession.status === "loading") {
181
+ coordinator.setAccountLoading();
182
+ setSettledMarker(marker);
183
+ return () => {
184
+ cancelled = true;
185
+ };
390
186
  }
187
+ const accessToken = accountSession.status === "authenticated" ? accountSession.accessToken : null;
188
+ const pending = initialized.current ? coordinator.setAccountSession(accessToken) : coordinator.restore(accessToken);
189
+ initialized.current = true;
190
+ void pending.then(() => {
191
+ if (!cancelled) setSettledMarker(marker);
192
+ });
193
+ return () => {
194
+ cancelled = true;
195
+ };
196
+ }, [accountSession.status, coordinator, desiredMarker, nextAccessToken]);
197
+ useEffect2(() => {
198
+ const generation = lifecycleGeneration.current + 1;
199
+ lifecycleGeneration.current = generation;
200
+ return () => {
201
+ queueMicrotask(() => {
202
+ if (lifecycleGeneration.current === generation) {
203
+ coordinator.dispose();
204
+ }
205
+ });
206
+ };
207
+ }, [coordinator]);
208
+ const visibleRelation = settledMarker === desiredMarker ? relation : transitionSnapshot(
209
+ relation,
210
+ accountSession,
211
+ activeHandle !== null,
212
+ !initialized.current
213
+ );
214
+ const accountToken = accountSession.status === "authenticated" ? accountSession.accessToken : null;
215
+ const identity = useMemo(
216
+ () => resolveIdentity({
217
+ relation: visibleRelation,
218
+ accountToken,
219
+ userHandle: activeHandle,
220
+ walletLabel: activeWallet?.label ?? null
221
+ }),
222
+ [visibleRelation, accountToken, activeHandle, activeWallet?.label]
391
223
  );
224
+ return {
225
+ identity,
226
+ relation: visibleRelation,
227
+ retry: async () => {
228
+ await coordinator.retry();
229
+ },
230
+ reconcile: async () => {
231
+ if (accountSession.status === "loading") {
232
+ coordinator.setAccountLoading();
233
+ return;
234
+ }
235
+ await coordinator.restore(
236
+ accountSession.status === "authenticated" ? accountSession.accessToken : null
237
+ );
238
+ },
239
+ allowAccountSession: coordinator.allowAccountSession,
240
+ settleAccountSession: (accessToken) => coordinator.setAccountSession(accessToken)
241
+ };
392
242
  }
393
243
 
394
- // src/DexterWalletMenu.tsx
395
- import { useEffect as useEffect5, useState as useState3 } from "react";
396
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
397
- function DexterWalletMenu(props) {
244
+ // src/useDexterConnection.ts
245
+ var REMOVE_DEXTER_FROM_DEVICE_CONFIRMATION = "remove-dexter-from-device";
246
+ function checkingSnapshot(snapshot, reason) {
247
+ return Object.freeze({
248
+ ...snapshot,
249
+ relation: "none",
250
+ runtime: Object.freeze({ phase: "checking", reason }),
251
+ walletPresent: false,
252
+ accountPresent: false,
253
+ privateAccountAccess: false,
254
+ quarantined: false,
255
+ verifiedAt: null
256
+ });
257
+ }
258
+ function errorSnapshot(snapshot, error) {
259
+ return Object.freeze({
260
+ ...snapshot,
261
+ runtime: Object.freeze({ phase: "error", code: error.code }),
262
+ privateAccountAccess: false
263
+ });
264
+ }
265
+ function unsettledBindingError(snapshot) {
266
+ if (snapshot.relation === "bound" && snapshot.runtime.phase === "ready" && snapshot.privateAccountAccess) {
267
+ return null;
268
+ }
269
+ if (snapshot.relation === "conflict") {
270
+ return new ConnectError("identity_binding_conflict");
271
+ }
272
+ if (snapshot.runtime.phase === "offline") {
273
+ return new ConnectError("identity_binding_offline");
274
+ }
275
+ if (snapshot.runtime.phase === "expired") {
276
+ return new ConnectError(`identity_${snapshot.runtime.subject}_expired`);
277
+ }
278
+ if (snapshot.runtime.phase === "error") {
279
+ return new ConnectError(snapshot.runtime.code);
280
+ }
281
+ return new ConnectError("identity_binding_unverified");
282
+ }
283
+ function useDexterConnection(config) {
398
284
  const {
399
- walletLabel,
400
- avatarInitial,
401
- onManageWallet,
402
- onStartFresh,
403
- startFreshLabel = "Eject wallet",
404
- saveSlot,
405
- saveHint,
406
- className
407
- } = props;
408
- useEffect5(ensureWalletKitStyles, []);
409
- const [showSave, setShowSave] = useState3(false);
410
- const initial = (avatarInitial ?? walletLabel.trim().charAt(0) ?? "D").toUpperCase();
411
- if (showSave && saveSlot) {
412
- return /* @__PURE__ */ jsxs3("div", { className: cx("dx-wmenu", className), children: [
413
- /* @__PURE__ */ jsx3(
414
- "button",
415
- {
416
- type: "button",
417
- className: "dx-wmenu__item dx-wmenu__back",
418
- onClick: () => setShowSave(false),
419
- children: /* @__PURE__ */ jsx3("span", { children: "\u2190 Back to wallet" })
285
+ intent,
286
+ accountSession,
287
+ installAccountSession,
288
+ clearAccountSession,
289
+ passkey,
290
+ apiBase,
291
+ fetch
292
+ } = config;
293
+ const dexterIdentity = useDexterIdentity({
294
+ ...apiBase ? { apiBase } : {},
295
+ ...fetch ? { fetch } : {},
296
+ accountSession
297
+ });
298
+ const wallet = useDexterWallet();
299
+ const [operation, setOperation] = useState3("idle");
300
+ const [targetHandle, setTargetHandle] = useState3(null);
301
+ const [targetAccessToken, setTargetAccessToken] = useState3(null);
302
+ const [error, setError] = useState3(null);
303
+ const action = useRef2("idle");
304
+ const beginAction = useCallback2(
305
+ (next) => {
306
+ if (action.current !== "idle") {
307
+ throw new ConnectError("identity_operation_in_progress");
308
+ }
309
+ action.current = next;
310
+ if (next !== "retrying") setOperation(next);
311
+ },
312
+ []
313
+ );
314
+ const finishAction = useCallback2(
315
+ (expected) => {
316
+ if (action.current !== expected) return;
317
+ action.current = "idle";
318
+ if (expected !== "retrying") setOperation("idle");
319
+ },
320
+ []
321
+ );
322
+ useEffect3(() => {
323
+ if (operation === "connecting" && targetHandle !== null && targetAccessToken !== null && wallet.activeHandle === targetHandle && accountSession.status === "authenticated" && accountSession.accessToken === targetAccessToken && dexterIdentity.relation.relation === "bound" && dexterIdentity.relation.privateAccountAccess) {
324
+ finishAction("connecting");
325
+ setTargetHandle(null);
326
+ setTargetAccessToken(null);
327
+ }
328
+ if ((operation === "disconnecting" || operation === "removing") && dexterIdentity.relation.relation === "none") {
329
+ finishAction(operation);
330
+ }
331
+ }, [
332
+ dexterIdentity.relation,
333
+ operation,
334
+ targetHandle,
335
+ targetAccessToken,
336
+ wallet.activeHandle,
337
+ accountSession,
338
+ finishAction
339
+ ]);
340
+ const operationRelation = operation === "idle" ? dexterIdentity.relation : checkingSnapshot(
341
+ dexterIdentity.relation,
342
+ operation === "connecting" ? "wallet_change" : "account_change"
343
+ );
344
+ const modelRelation = error !== null && operation === "idle" ? errorSnapshot(operationRelation, error) : operationRelation;
345
+ const model = useMemo2(
346
+ () => createDexterControlModel(intent, modelRelation),
347
+ [intent, modelRelation]
348
+ );
349
+ const relation = modelRelation;
350
+ const accountToken = accountSession.status === "authenticated" ? accountSession.accessToken : null;
351
+ const identity = useMemo2(() => {
352
+ const resolved = resolveIdentity({
353
+ relation,
354
+ accountToken,
355
+ userHandle: wallet.activeHandle,
356
+ walletLabel: wallet.activeWallet?.label ?? null
357
+ });
358
+ return {
359
+ kind: resolved.kind,
360
+ userHandle: model.permissions.walletIdentityVisible ? resolved.userHandle : null,
361
+ walletLabel: model.permissions.walletIdentityVisible ? resolved.walletLabel : null,
362
+ hasPasskeyVault: resolved.hasPasskeyVault,
363
+ hasAccount: resolved.hasAccount,
364
+ hasWallet: resolved.hasWallet,
365
+ hasAccountAccess: model.permissions.accountContentVisible && resolved.hasAccountAccess,
366
+ quarantined: resolved.quarantined
367
+ };
368
+ }, [
369
+ accountToken,
370
+ relation,
371
+ model.permissions.accountContentVisible,
372
+ model.permissions.walletIdentityVisible,
373
+ wallet.activeHandle,
374
+ wallet.activeWallet?.label
375
+ ]);
376
+ const activeWallet = useMemo2(() => {
377
+ if (!model.permissions.walletIdentityVisible) return null;
378
+ const active = wallet.activeWallet;
379
+ if (!active) return null;
380
+ return {
381
+ userHandle: active.handle,
382
+ label: active.label ?? null,
383
+ vaultPda: active.vaultPda ?? null,
384
+ swigAddress: active.swigAddress ?? null,
385
+ walletAddress: active.walletAddress ?? null,
386
+ receiveAddress: active.receiveAddress ?? null,
387
+ network: active.network ?? null
388
+ };
389
+ }, [model.permissions.walletIdentityVisible, wallet.activeWallet]);
390
+ const connect = useCallback2(async () => {
391
+ beginAction("connecting");
392
+ setError(null);
393
+ setTargetHandle(null);
394
+ setTargetAccessToken(null);
395
+ try {
396
+ const result = await connectDexterIdentity({
397
+ ...passkey,
398
+ ...apiBase ? { apiBase } : {},
399
+ ...fetch ? { bindingFetch: fetch } : {},
400
+ installAccountSession: async (session) => {
401
+ dexterIdentity.allowAccountSession(session.accessToken);
402
+ await installAccountSession(session);
403
+ const settled = await dexterIdentity.settleAccountSession(
404
+ session.accessToken
405
+ );
406
+ const settleError = unsettledBindingError(settled);
407
+ if (settleError) {
408
+ try {
409
+ await clearAccountSession();
410
+ } catch (cause) {
411
+ throw new ConnectError(
412
+ "account_session_clear_failed",
413
+ cause instanceof Error ? cause.message : String(cause)
414
+ );
415
+ }
416
+ throw settleError;
417
+ }
420
418
  }
421
- ),
422
- /* @__PURE__ */ jsxs3("div", { className: "dx-wmenu__save", children: [
423
- saveHint ? /* @__PURE__ */ jsx3("span", { className: "dx-wmenu__savehint", children: saveHint }) : null,
424
- saveSlot
425
- ] })
426
- ] });
427
- }
428
- return /* @__PURE__ */ jsxs3("div", { className: cx("dx-wmenu", className), children: [
429
- /* @__PURE__ */ jsxs3("div", { className: "dx-wmenu__id", children: [
430
- /* @__PURE__ */ jsx3("span", { className: "dx-wmenu__avatar", "aria-hidden": "true", children: initial }),
431
- /* @__PURE__ */ jsxs3("span", { className: "dx-wmenu__meta", children: [
432
- /* @__PURE__ */ jsx3("span", { className: "dx-wmenu__name", children: walletLabel }),
433
- /* @__PURE__ */ jsx3("span", { className: "dx-wmenu__sub", children: "Your Dexter Wallet" })
434
- ] })
435
- ] }),
436
- /* @__PURE__ */ jsxs3("div", { className: "dx-wmenu__list", children: [
437
- onManageWallet ? /* @__PURE__ */ jsxs3("button", { type: "button", className: "dx-wmenu__item", onClick: onManageWallet, children: [
438
- /* @__PURE__ */ jsx3("span", { children: "Manage wallet" }),
439
- /* @__PURE__ */ jsx3("span", { className: "dx-wmenu__icon", "aria-hidden": "true", children: "\u2197" })
440
- ] }) : null,
441
- saveSlot ? /* @__PURE__ */ jsxs3("button", { type: "button", className: "dx-wmenu__item", onClick: () => setShowSave(true), children: [
442
- /* @__PURE__ */ jsx3("span", { children: "Save your wallet" }),
443
- /* @__PURE__ */ jsx3("span", { className: "dx-wmenu__icon", "aria-hidden": "true", children: "\u2197" })
444
- ] }) : null,
445
- onStartFresh ? /* @__PURE__ */ jsxs3(
446
- "button",
447
- {
448
- type: "button",
449
- className: "dx-wmenu__item dx-wmenu__item--danger",
450
- onClick: onStartFresh,
451
- children: [
452
- /* @__PURE__ */ jsx3("span", { children: startFreshLabel }),
453
- /* @__PURE__ */ jsx3("span", { className: "dx-wmenu__icon", "aria-hidden": "true", children: "\u27F5" })
454
- ]
419
+ });
420
+ setTargetHandle(result.vault.userHandle);
421
+ setTargetAccessToken(result.session.accessToken);
422
+ return result;
423
+ } catch (cause) {
424
+ await dexterIdentity.reconcile().catch(() => void 0);
425
+ const nextError = cause instanceof ConnectError ? cause : new ConnectError("identity_transition_failed", String(cause));
426
+ setError(nextError);
427
+ setTargetHandle(null);
428
+ setTargetAccessToken(null);
429
+ finishAction("connecting");
430
+ throw nextError;
431
+ }
432
+ }, [
433
+ dexterIdentity,
434
+ apiBase,
435
+ fetch,
436
+ installAccountSession,
437
+ clearAccountSession,
438
+ passkey,
439
+ beginAction,
440
+ finishAction
441
+ ]);
442
+ const disconnectDexter = useCallback2(async () => {
443
+ beginAction("disconnecting");
444
+ setError(null);
445
+ try {
446
+ const disconnected = await disconnectDexterIdentity({
447
+ clearAccountSession
448
+ });
449
+ if (!disconnected) finishAction("disconnecting");
450
+ return disconnected;
451
+ } catch (cause) {
452
+ await dexterIdentity.reconcile().catch(() => void 0);
453
+ const nextError = cause instanceof ConnectError ? cause : new ConnectError("identity_disconnect_failed", String(cause));
454
+ setError(nextError);
455
+ finishAction("disconnecting");
456
+ throw nextError;
457
+ }
458
+ }, [
459
+ beginAction,
460
+ clearAccountSession,
461
+ dexterIdentity,
462
+ finishAction
463
+ ]);
464
+ const removeFromThisDevice = useCallback2(
465
+ async (confirmation) => {
466
+ if (confirmation !== REMOVE_DEXTER_FROM_DEVICE_CONFIRMATION) {
467
+ return { removedFromRoster: false, passkeyPruned: false };
468
+ }
469
+ const handle = wallet.activeHandle;
470
+ if (!handle) {
471
+ return { removedFromRoster: false, passkeyPruned: false };
472
+ }
473
+ beginAction("removing");
474
+ setError(null);
475
+ try {
476
+ const result = await wallet.removeFromDevice(
477
+ handle,
478
+ "remove-wallet-from-device"
479
+ );
480
+ if (!result.removedFromRoster) {
481
+ throw new ConnectError("identity_device_removal_failed");
455
482
  }
456
- ) : null
457
- ] })
458
- ] });
459
- }
460
-
461
- // src/useIdentity.ts
462
- import { useMemo as useMemo2 } from "react";
463
- function useIdentity({ accountToken }) {
464
- const { activeHandle, activeWallet } = useDexterWallet();
465
- const walletLabel = activeWallet?.label ?? null;
466
- return useMemo2(
467
- () => resolveIdentity({
468
- accountToken: accountToken ?? null,
469
- userHandle: activeHandle ?? null,
470
- walletLabel
471
- }),
472
- [accountToken, activeHandle, walletLabel]
483
+ await clearAccountSession();
484
+ return result;
485
+ } catch (cause) {
486
+ await dexterIdentity.reconcile().catch(() => void 0);
487
+ const nextError = cause instanceof ConnectError ? cause : new ConnectError(
488
+ "identity_device_removal_failed",
489
+ String(cause)
490
+ );
491
+ setError(nextError);
492
+ finishAction("removing");
493
+ throw nextError;
494
+ }
495
+ },
496
+ [
497
+ beginAction,
498
+ clearAccountSession,
499
+ dexterIdentity,
500
+ finishAction,
501
+ wallet
502
+ ]
473
503
  );
504
+ const retry = useCallback2(async () => {
505
+ beginAction("retrying");
506
+ setError(null);
507
+ try {
508
+ await dexterIdentity.retry();
509
+ } catch (cause) {
510
+ const nextError = cause instanceof ConnectError ? cause : new ConnectError("identity_retry_failed", String(cause));
511
+ setError(nextError);
512
+ throw nextError;
513
+ } finally {
514
+ finishAction("retrying");
515
+ }
516
+ }, [beginAction, dexterIdentity, finishAction]);
517
+ return {
518
+ model,
519
+ identity,
520
+ relation,
521
+ operation,
522
+ activeWallet,
523
+ error,
524
+ connect,
525
+ useAnotherDexterWallet: connect,
526
+ disconnectDexter,
527
+ removeFromThisDevice,
528
+ retry
529
+ };
474
530
  }
475
531
 
476
532
  // src/AllowanceChips.tsx
477
- import { useEffect as useEffect6, useId, useState as useState4 } from "react";
533
+ import { useEffect as useEffect4, useId, useState as useState4 } from "react";
478
534
 
479
535
  // src/consentStyles.ts
480
- var STYLE_ID2 = "dexter-connect-consent-styles";
536
+ var STYLE_ID = "dexter-connect-consent-styles";
481
537
  var CONSENT_CSS = `
482
538
  .dx-allow{
483
539
  display:flex; flex-wrap:wrap; gap:8px; align-items:center; min-width:0;
@@ -529,7 +585,7 @@ var CONSENT_CSS = `
529
585
  display:flex; flex-direction:column; gap:16px; font:inherit;
530
586
  }
531
587
  .dx-cwp__field{ display:flex; flex-direction:column; gap:8px; }
532
- .dx-cwp__label{ font-size:.7rem; font-weight:700; letter-spacing:.14em; text-transform:uppercase; opacity:.62; }
588
+ .dx-cwp__label{ font-size:.8rem; font-weight:700; letter-spacing:.12em; text-transform:uppercase; opacity:.66; }
533
589
  .dx-cwp__name{
534
590
  min-height:48px; padding:10px 13px; font:inherit; font-size:1rem; color:inherit; background:transparent;
535
591
  border:1px solid color-mix(in srgb,currentColor 22%,transparent); border-radius:var(--dx-radius,0px);
@@ -540,10 +596,10 @@ var CONSENT_CSS = `
540
596
  box-shadow:0 0 0 3px color-mix(in srgb,var(--dx-ember,#f26c18) 26%,transparent);
541
597
  }
542
598
  .dx-cwp__name::placeholder{ color:currentColor; opacity:.42; }
543
- .dx-cwp__hosted{ margin:0; font-size:.9rem; line-height:1.55; opacity:.82; }
544
- .dx-cwp__fine{ font-size:.76rem; line-height:1.5; opacity:.66; }
545
- .dx-cwp__err{ font-size:.78rem; line-height:1.45; color:var(--dx-danger,#e5552e); }
546
- .dx-cwp__status{ min-height:1.25rem; margin:0; font-size:.78rem; line-height:1.45; opacity:.72; }
599
+ .dx-cwp__hosted{ margin:0; font-size:.95rem; line-height:1.55; opacity:.82; }
600
+ .dx-cwp__fine{ margin:0; font-size:.875rem; line-height:1.5; opacity:.68; }
601
+ .dx-cwp__err{ font-size:.875rem; line-height:1.45; color:var(--dx-danger,#e5552e); }
602
+ .dx-cwp__status{ margin:0; font-size:.875rem; line-height:1.45; opacity:.74; }
547
603
  @media (max-width:380px){
548
604
  .dx-allow__option{ flex:1 1 calc(50% - 4px); }
549
605
  .dx-allow__chip{ width:100%; }
@@ -556,16 +612,16 @@ var CONSENT_CSS = `
556
612
  `;
557
613
  function ensureConsentStyles() {
558
614
  if (typeof document === "undefined") return;
559
- if (document.getElementById(STYLE_ID2)) return;
615
+ if (document.getElementById(STYLE_ID)) return;
560
616
  const el = document.createElement("style");
561
- el.id = STYLE_ID2;
617
+ el.id = STYLE_ID;
562
618
  el.textContent = CONSENT_CSS;
563
619
  document.head.appendChild(el);
564
620
  }
565
621
  ensureConsentStyles();
566
622
 
567
623
  // src/AllowanceChips.tsx
568
- import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
624
+ import { jsx, jsxs } from "react/jsx-runtime";
569
625
  var PRESETS = [
570
626
  { label: "$5", num: "5" },
571
627
  { label: "$20", num: "20" },
@@ -575,7 +631,7 @@ var PRESET_NUMS = PRESETS.map((p) => p.num);
575
631
  var isPreset = (v) => v !== null && PRESET_NUMS.includes(v);
576
632
  function AllowanceChips(props) {
577
633
  const { value, onChange, className, disabled = false } = props;
578
- useEffect6(ensureConsentStyles, []);
634
+ useEffect4(ensureConsentStyles, []);
579
635
  const [customOpen, setCustomOpen] = useState4(false);
580
636
  const groupName = useId();
581
637
  const customActive = customOpen || value !== null && !isPreset(value);
@@ -589,12 +645,12 @@ function AllowanceChips(props) {
589
645
  setCustomOpen(true);
590
646
  onChange(isPreset(value) ? null : value);
591
647
  };
592
- return /* @__PURE__ */ jsxs4("fieldset", { className: cx("dx-allow", className), disabled, children: [
593
- /* @__PURE__ */ jsx4("legend", { className: "dx-sr-only", children: "Monthly agent allowance" }),
648
+ return /* @__PURE__ */ jsxs("fieldset", { className: cx("dx-allow", className), disabled, children: [
649
+ /* @__PURE__ */ jsx("legend", { className: "dx-sr-only", children: "Monthly agent allowance" }),
594
650
  PRESETS.map(({ label, num }) => {
595
651
  const checked = !customActive && value === num;
596
- return /* @__PURE__ */ jsxs4("label", { className: "dx-allow__option", children: [
597
- /* @__PURE__ */ jsx4(
652
+ return /* @__PURE__ */ jsxs("label", { className: "dx-allow__option", children: [
653
+ /* @__PURE__ */ jsx(
598
654
  "input",
599
655
  {
600
656
  className: "dx-allow__radio",
@@ -605,11 +661,11 @@ function AllowanceChips(props) {
605
661
  onChange: () => selectPreset(num)
606
662
  }
607
663
  ),
608
- /* @__PURE__ */ jsx4("span", { className: "dx-allow__chip", children: label })
664
+ /* @__PURE__ */ jsx("span", { className: "dx-allow__chip", children: label })
609
665
  ] }, num);
610
666
  }),
611
- /* @__PURE__ */ jsxs4("label", { className: "dx-allow__option", children: [
612
- /* @__PURE__ */ jsx4(
667
+ /* @__PURE__ */ jsxs("label", { className: "dx-allow__option", children: [
668
+ /* @__PURE__ */ jsx(
613
669
  "input",
614
670
  {
615
671
  className: "dx-allow__radio",
@@ -620,9 +676,9 @@ function AllowanceChips(props) {
620
676
  onChange: selectCustom
621
677
  }
622
678
  ),
623
- /* @__PURE__ */ jsx4("span", { className: "dx-allow__chip", children: "Custom" })
679
+ /* @__PURE__ */ jsx("span", { className: "dx-allow__chip", children: "Custom" })
624
680
  ] }),
625
- customActive && /* @__PURE__ */ jsx4(
681
+ customActive && /* @__PURE__ */ jsx(
626
682
  "input",
627
683
  {
628
684
  className: "dx-allow__input",
@@ -640,13 +696,21 @@ function AllowanceChips(props) {
640
696
  }
641
697
 
642
698
  // src/CreateWalletPanel.tsx
643
- import { useEffect as useEffect7, useId as useId2, useState as useState5 } from "react";
644
- import { Fragment, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
699
+ import { useEffect as useEffect5, useId as useId2, useState as useState5 } from "react";
700
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
645
701
  var FINE_PRINT = "This is the wallet-wide agent allowance. You can revoke it anytime. Starter credit, if available, is separate and never raises this limit.";
646
702
  function CreateWalletPanel(props) {
647
- const { onCreated, onError, apiBase, transport, showName = true, className } = props;
648
- useEffect7(ensureConsentStyles, []);
649
- useEffect7(ensureDexterButtonStyles, []);
703
+ const {
704
+ onCreated,
705
+ onError,
706
+ apiBase,
707
+ transport,
708
+ showName = true,
709
+ agentDelegation = "deferred",
710
+ className
711
+ } = props;
712
+ useEffect5(ensureConsentStyles, []);
713
+ useEffect5(ensureDexterButtonStyles, []);
650
714
  const nameInputId = useId2();
651
715
  const [name, setName] = useState5("");
652
716
  const [value, setValue] = useState5(null);
@@ -656,15 +720,17 @@ function CreateWalletPanel(props) {
656
720
  const [resolvedTransport, setResolvedTransport] = useState5(
657
721
  transport === "inline" ? "inline" : transport === "popup" ? "popup" : "unknown"
658
722
  );
659
- useEffect7(() => {
723
+ useEffect5(() => {
660
724
  setResolvedTransport(shouldUsePopup(transport) ? "popup" : "inline");
661
725
  }, [transport]);
662
726
  const hosted = resolvedTransport === "popup";
663
- const policy = resolvedTransport === "inline" ? authoredPolicy(value ?? "") : null;
664
- const canContinue = hosted || Boolean(policy);
727
+ const ownerOnly = agentDelegation === "deferred";
728
+ const policy = resolvedTransport === "inline" && !ownerOnly ? authoredPolicy(value ?? "") : null;
729
+ const canContinue = hosted || ownerOnly || Boolean(policy);
730
+ const statusText = running ? phase ? ceremonyPhaseLabel(phase) : "Starting your passkey\u2026" : resolvedTransport === "unknown" ? "Preparing wallet setup\u2026" : hosted ? "Wallet setup continues in Dexter Wallet." : ownerOnly ? "" : policy ? "Ready to create." : "Choose an agent allowance.";
665
731
  const handleCreate = async () => {
666
732
  if (running) return;
667
- if (resolvedTransport === "unknown" || !hosted && !policy) return;
733
+ if (resolvedTransport === "unknown" || !hosted && !ownerOnly && !policy) return;
668
734
  setError(null);
669
735
  setRunning(true);
670
736
  setPhase(null);
@@ -672,6 +738,7 @@ function CreateWalletPanel(props) {
672
738
  const result = await createWallet({
673
739
  name: hosted ? void 0 : name.trim() || "Dexter Wallet",
674
740
  spendPolicy: hosted ? void 0 : policy ?? void 0,
741
+ agentDelegation,
675
742
  apiBase,
676
743
  transport,
677
744
  onPhase: setPhase
@@ -686,10 +753,10 @@ function CreateWalletPanel(props) {
686
753
  setPhase(null);
687
754
  }
688
755
  };
689
- return /* @__PURE__ */ jsxs5("div", { className: cx("dx-cwp", className), children: [
690
- !hosted && resolvedTransport === "inline" && showName && /* @__PURE__ */ jsxs5("div", { className: "dx-cwp__field", children: [
691
- /* @__PURE__ */ jsx5("label", { className: "dx-cwp__label", htmlFor: nameInputId, children: "Name your wallet" }),
692
- /* @__PURE__ */ jsx5(
756
+ return /* @__PURE__ */ jsxs2("div", { className: cx("dx-cwp", className), children: [
757
+ !hosted && resolvedTransport === "inline" && showName && /* @__PURE__ */ jsxs2("div", { className: "dx-cwp__field", children: [
758
+ /* @__PURE__ */ jsx2("label", { className: "dx-cwp__label", htmlFor: nameInputId, children: "Name your wallet" }),
759
+ /* @__PURE__ */ jsx2(
693
760
  "input",
694
761
  {
695
762
  id: nameInputId,
@@ -703,16 +770,16 @@ function CreateWalletPanel(props) {
703
770
  }
704
771
  )
705
772
  ] }),
706
- hosted ? /* @__PURE__ */ jsx5("p", { className: "dx-cwp__hosted", children: "Dexter will open its secure wallet window. Choose the wallet name and agent allowance there before your passkey creates anything." }) : resolvedTransport === "inline" ? /* @__PURE__ */ jsxs5(Fragment, { children: [
707
- /* @__PURE__ */ jsxs5("div", { className: "dx-cwp__field", children: [
708
- /* @__PURE__ */ jsx5("span", { className: "dx-cwp__label", children: "What agents may spend automatically, per 30 days" }),
709
- /* @__PURE__ */ jsx5(AllowanceChips, { value, onChange: setValue, disabled: running })
773
+ hosted ? /* @__PURE__ */ jsx2("p", { className: "dx-cwp__hosted", children: ownerOnly ? "Finish setup in Dexter Wallet." : "Choose a name and agent allowance in Dexter Wallet." }) : resolvedTransport === "inline" ? !ownerOnly ? /* @__PURE__ */ jsxs2(Fragment, { children: [
774
+ /* @__PURE__ */ jsxs2("div", { className: "dx-cwp__field", children: [
775
+ /* @__PURE__ */ jsx2("span", { className: "dx-cwp__label", children: "What agents may spend automatically, per 30 days" }),
776
+ /* @__PURE__ */ jsx2(AllowanceChips, { value, onChange: setValue, disabled: running })
710
777
  ] }),
711
- /* @__PURE__ */ jsx5("p", { className: "dx-cwp__fine", children: FINE_PRINT })
712
- ] }) : null,
713
- error && /* @__PURE__ */ jsx5("div", { className: "dx-cwp__err", role: "alert", "aria-live": "assertive", children: error.message || error.code }),
714
- /* @__PURE__ */ jsx5("p", { className: "dx-cwp__status", role: "status", "aria-live": "polite", children: running ? phase ? ceremonyPhaseLabel(phase) : "Starting your passkey\u2026" : resolvedTransport === "unknown" ? "Preparing secure wallet setup\u2026" : hosted ? "Name, allowance, and passkey confirmation happen in the Dexter window." : policy ? "Allowance selected. Your passkey will create and secure the wallet." : "Choose an allowance to continue." }),
715
- /* @__PURE__ */ jsx5(
778
+ /* @__PURE__ */ jsx2("p", { className: "dx-cwp__fine", children: FINE_PRINT })
779
+ ] }) : null : null,
780
+ error && /* @__PURE__ */ jsx2("div", { className: "dx-cwp__err", role: "alert", "aria-live": "assertive", children: error.message || error.code }),
781
+ statusText && /* @__PURE__ */ jsx2("p", { className: "dx-cwp__status", role: "status", "aria-live": "polite", children: statusText }),
782
+ /* @__PURE__ */ jsx2(
716
783
  DexterButton,
717
784
  {
718
785
  block: true,
@@ -728,9 +795,9 @@ function CreateWalletPanel(props) {
728
795
  }
729
796
 
730
797
  // src/AppInstallButtons.tsx
731
- import { useEffect as useEffect8, useId as useId3, useState as useState6 } from "react";
732
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
733
- var STYLE_ID3 = "dexter-connect-appinstall-styles";
798
+ import { useEffect as useEffect6, useId as useId3, useState as useState6 } from "react";
799
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
800
+ var STYLE_ID2 = "dexter-connect-appinstall-styles";
734
801
  var APPINSTALL_CSS = `
735
802
  .dx-appinstall{ display:flex; flex-wrap:wrap; gap:10px; }
736
803
  .dx-appinstall--block{ flex-direction:column; }
@@ -803,9 +870,9 @@ var APPINSTALL_CSS = `
803
870
  `;
804
871
  function ensureAppInstallStyles() {
805
872
  if (typeof document === "undefined") return;
806
- if (document.getElementById(STYLE_ID3)) return;
873
+ if (document.getElementById(STYLE_ID2)) return;
807
874
  const el = document.createElement("style");
808
- el.id = STYLE_ID3;
875
+ el.id = STYLE_ID2;
809
876
  el.textContent = APPINSTALL_CSS;
810
877
  document.head.appendChild(el);
811
878
  }
@@ -870,7 +937,7 @@ function AppInstallButtons(props) {
870
937
  className,
871
938
  onAction
872
939
  } = props;
873
- useEffect8(ensureAppInstallStyles, []);
940
+ useEffect6(ensureAppInstallStyles, []);
874
941
  const statusId = useId3();
875
942
  const hermesCommand = hermesInstallCommand(serverName, mcpUrl);
876
943
  const claudeCommand = claudeCodeInstallCommand(serverName, mcpUrl);
@@ -879,7 +946,7 @@ function AppInstallButtons(props) {
879
946
  const hermesErrorId = `${statusId}-hermes-error`;
880
947
  const claudeErrorId = `${statusId}-claude-error`;
881
948
  const buttons = {
882
- claude: /* @__PURE__ */ jsxs6(
949
+ claude: /* @__PURE__ */ jsxs3(
883
950
  "a",
884
951
  {
885
952
  className: appCx(block),
@@ -888,13 +955,13 @@ function AppInstallButtons(props) {
888
955
  rel: "noopener noreferrer",
889
956
  onClick: () => onAction?.("claude", "deeplink"),
890
957
  children: [
891
- /* @__PURE__ */ jsx6("img", { className: "dx-appbtn__logo", src: CLAUDE_MARK, alt: "", "aria-hidden": true }),
958
+ /* @__PURE__ */ jsx3("img", { className: "dx-appbtn__logo", src: CLAUDE_MARK, alt: "", "aria-hidden": true }),
892
959
  "Open in Claude"
893
960
  ]
894
961
  },
895
962
  "claude"
896
963
  ),
897
- chatgpt: /* @__PURE__ */ jsxs6(
964
+ chatgpt: /* @__PURE__ */ jsxs3(
898
965
  "a",
899
966
  {
900
967
  className: appCx(block),
@@ -903,39 +970,39 @@ function AppInstallButtons(props) {
903
970
  rel: "noopener noreferrer",
904
971
  onClick: () => onAction?.("chatgpt", "deeplink"),
905
972
  children: [
906
- /* @__PURE__ */ jsx6("img", { className: "dx-appbtn__logo", src: CHATGPT_MARK, alt: "", "aria-hidden": true }),
973
+ /* @__PURE__ */ jsx3("img", { className: "dx-appbtn__logo", src: CHATGPT_MARK, alt: "", "aria-hidden": true }),
907
974
  "Open ChatGPT plugins"
908
975
  ]
909
976
  },
910
977
  "chatgpt"
911
978
  ),
912
- cursor: /* @__PURE__ */ jsxs6(
979
+ cursor: /* @__PURE__ */ jsxs3(
913
980
  "a",
914
981
  {
915
982
  className: appCx(block),
916
983
  href: cursorInstallUrl(serverName, mcpUrl),
917
984
  onClick: () => onAction?.("cursor", "deeplink"),
918
985
  children: [
919
- /* @__PURE__ */ jsx6("img", { className: "dx-appbtn__logo", src: CURSOR_MARK, alt: "", "aria-hidden": true }),
986
+ /* @__PURE__ */ jsx3("img", { className: "dx-appbtn__logo", src: CURSOR_MARK, alt: "", "aria-hidden": true }),
920
987
  "Add to Cursor"
921
988
  ]
922
989
  },
923
990
  "cursor"
924
991
  ),
925
- vscode: /* @__PURE__ */ jsxs6(
992
+ vscode: /* @__PURE__ */ jsxs3(
926
993
  "a",
927
994
  {
928
995
  className: appCx(block),
929
996
  href: vscodeInstallUrl(serverName, mcpUrl),
930
997
  onClick: () => onAction?.("vscode", "deeplink"),
931
998
  children: [
932
- /* @__PURE__ */ jsx6("img", { className: "dx-appbtn__logo", src: VSCODE_MARK, alt: "", "aria-hidden": true }),
999
+ /* @__PURE__ */ jsx3("img", { className: "dx-appbtn__logo", src: VSCODE_MARK, alt: "", "aria-hidden": true }),
933
1000
  "Add to VS Code"
934
1001
  ]
935
1002
  },
936
1003
  "vscode"
937
1004
  ),
938
- hermes: /* @__PURE__ */ jsxs6(
1005
+ hermes: /* @__PURE__ */ jsxs3(
939
1006
  "button",
940
1007
  {
941
1008
  type: "button",
@@ -953,13 +1020,13 @@ function AppInstallButtons(props) {
953
1020
  }
954
1021
  },
955
1022
  children: [
956
- /* @__PURE__ */ jsx6("img", { className: "dx-appbtn__logo", src: HERMES_MARK, alt: "", "aria-hidden": true }),
957
- hermesStatus === "copied" ? /* @__PURE__ */ jsx6("span", { className: "dx-appbtn__copied", children: "Copied. Run it in your terminal" }) : hermesStatus === "copying" ? "Copying OAuth setup\u2026" : hermesStatus === "failed" ? "Try copying for Hermes" : "Copy OAuth setup for Hermes"
1023
+ /* @__PURE__ */ jsx3("img", { className: "dx-appbtn__logo", src: HERMES_MARK, alt: "", "aria-hidden": true }),
1024
+ hermesStatus === "copied" ? /* @__PURE__ */ jsx3("span", { className: "dx-appbtn__copied", children: "Copied. Run it in your terminal" }) : hermesStatus === "copying" ? "Copying OAuth setup\u2026" : hermesStatus === "failed" ? "Try copying for Hermes" : "Copy OAuth setup for Hermes"
958
1025
  ]
959
1026
  },
960
1027
  "hermes"
961
1028
  ),
962
- "claude-code": /* @__PURE__ */ jsxs6(
1029
+ "claude-code": /* @__PURE__ */ jsxs3(
963
1030
  "button",
964
1031
  {
965
1032
  type: "button",
@@ -977,14 +1044,14 @@ function AppInstallButtons(props) {
977
1044
  }
978
1045
  },
979
1046
  children: [
980
- /* @__PURE__ */ jsx6("img", { className: "dx-appbtn__logo", src: CLAUDE_MARK, alt: "", "aria-hidden": true }),
981
- claudeStatus === "copied" ? /* @__PURE__ */ jsx6("span", { className: "dx-appbtn__copied", children: "Copied. Run it in your terminal" }) : claudeStatus === "copying" ? "Copying setup\u2026" : claudeStatus === "failed" ? "Try copying for Claude Code" : "Copy for Claude Code"
1047
+ /* @__PURE__ */ jsx3("img", { className: "dx-appbtn__logo", src: CLAUDE_MARK, alt: "", "aria-hidden": true }),
1048
+ claudeStatus === "copied" ? /* @__PURE__ */ jsx3("span", { className: "dx-appbtn__copied", children: "Copied. Run it in your terminal" }) : claudeStatus === "copying" ? "Copying setup\u2026" : claudeStatus === "failed" ? "Try copying for Claude Code" : "Copy for Claude Code"
982
1049
  ]
983
1050
  },
984
1051
  "claude-code"
985
1052
  )
986
1053
  };
987
- return /* @__PURE__ */ jsxs6(
1054
+ return /* @__PURE__ */ jsxs3(
988
1055
  "div",
989
1056
  {
990
1057
  className: ["dx-appinstall", block ? "dx-appinstall--block" : "", className ?? ""].filter(Boolean).join(" "),
@@ -992,13 +1059,13 @@ function AppInstallButtons(props) {
992
1059
  "aria-label": `Add ${displayName} to an agent app`,
993
1060
  children: [
994
1061
  apps.map((app) => buttons[app] ?? null),
995
- /* @__PURE__ */ jsx6("span", { className: "dx-appinstall__sr-only", "aria-live": "polite", "aria-atomic": "true", children: [
1062
+ /* @__PURE__ */ jsx3("span", { className: "dx-appinstall__sr-only", "aria-live": "polite", "aria-atomic": "true", children: [
996
1063
  hermesStatus === "copied" ? "Hermes OAuth setup command copied." : "",
997
1064
  claudeStatus === "copied" ? "Claude Code setup command copied." : ""
998
1065
  ].filter(Boolean).join(" ") }),
999
- hermesStatus === "copied" ? /* @__PURE__ */ jsxs6("div", { className: "dx-appinstall__notice", children: [
1000
- /* @__PURE__ */ jsx6("p", { children: "Run the command in your terminal. It adds the hosted MCP with OAuth." }),
1001
- /* @__PURE__ */ jsx6(
1066
+ hermesStatus === "copied" ? /* @__PURE__ */ jsxs3("div", { className: "dx-appinstall__notice", children: [
1067
+ /* @__PURE__ */ jsx3("p", { children: "Run the command in your terminal. It adds the hosted MCP with OAuth." }),
1068
+ /* @__PURE__ */ jsx3(
1002
1069
  "a",
1003
1070
  {
1004
1071
  className: "dx-appinstall__open",
@@ -1009,9 +1076,9 @@ function AppInstallButtons(props) {
1009
1076
  }
1010
1077
  )
1011
1078
  ] }) : null,
1012
- hermesStatus === "failed" ? /* @__PURE__ */ jsxs6("div", { id: hermesErrorId, className: "dx-appinstall__error", role: "alert", children: [
1013
- /* @__PURE__ */ jsx6("label", { htmlFor: `${hermesErrorId}-command`, children: "Couldn't copy. Select this Hermes command and run it in your terminal." }),
1014
- /* @__PURE__ */ jsx6(
1079
+ hermesStatus === "failed" ? /* @__PURE__ */ jsxs3("div", { id: hermesErrorId, className: "dx-appinstall__error", role: "alert", children: [
1080
+ /* @__PURE__ */ jsx3("label", { htmlFor: `${hermesErrorId}-command`, children: "Couldn't copy. Select this Hermes command and run it in your terminal." }),
1081
+ /* @__PURE__ */ jsx3(
1015
1082
  "input",
1016
1083
  {
1017
1084
  id: `${hermesErrorId}-command`,
@@ -1022,14 +1089,14 @@ function AppInstallButtons(props) {
1022
1089
  }
1023
1090
  )
1024
1091
  ] }) : null,
1025
- claudeStatus === "copied" ? /* @__PURE__ */ jsx6("div", { className: "dx-appinstall__notice", children: /* @__PURE__ */ jsxs6("p", { children: [
1092
+ claudeStatus === "copied" ? /* @__PURE__ */ jsx3("div", { className: "dx-appinstall__notice", children: /* @__PURE__ */ jsxs3("p", { children: [
1026
1093
  "Run the command in your terminal. If sign-in is required, finish it from Claude Code's ",
1027
- /* @__PURE__ */ jsx6("code", { children: "/mcp" }),
1094
+ /* @__PURE__ */ jsx3("code", { children: "/mcp" }),
1028
1095
  " menu."
1029
1096
  ] }) }) : null,
1030
- claudeStatus === "failed" ? /* @__PURE__ */ jsxs6("div", { id: claudeErrorId, className: "dx-appinstall__error", role: "alert", children: [
1031
- /* @__PURE__ */ jsx6("label", { htmlFor: `${claudeErrorId}-command`, children: "Couldn't copy. Select this Claude Code command and run it in your terminal." }),
1032
- /* @__PURE__ */ jsx6(
1097
+ claudeStatus === "failed" ? /* @__PURE__ */ jsxs3("div", { id: claudeErrorId, className: "dx-appinstall__error", role: "alert", children: [
1098
+ /* @__PURE__ */ jsx3("label", { htmlFor: `${claudeErrorId}-command`, children: "Couldn't copy. Select this Claude Code command and run it in your terminal." }),
1099
+ /* @__PURE__ */ jsx3(
1033
1100
  "input",
1034
1101
  {
1035
1102
  id: `${claudeErrorId}-command`,
@@ -1050,17 +1117,13 @@ export {
1050
1117
  CreateWalletPanel,
1051
1118
  DexterButton,
1052
1119
  DexterMark,
1053
- DexterWalletChip,
1054
- DexterWalletMenu,
1055
- SignInWithDexter,
1120
+ REMOVE_DEXTER_FROM_DEVICE_CONFIRMATION,
1056
1121
  chatgptPluginsUrl,
1057
1122
  claudeCodeInstallCommand,
1058
1123
  claudeWebConnectorUrl,
1059
1124
  cursorInstallUrl,
1060
1125
  hermesInstallCommand,
1061
1126
  hermesOpenUrl,
1062
- useDexterWallet,
1063
- useIdentity,
1064
- useSignInWithDexter,
1127
+ useDexterConnection,
1065
1128
  vscodeInstallUrl
1066
1129
  };