@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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <h1 align="center">@dexterai/connect</h1>
6
6
 
7
7
  <p align="center">
8
- <strong>Sign in with Dexter. One passkey tap gives any website a non-custodial Dexter Wallet, and gives any server an offline-verifiable session.</strong>
8
+ <strong>Add Dexter identity, Wallet access, or governed agent authority to a web app.</strong>
9
9
  </p>
10
10
 
11
11
  <p align="center">
@@ -14,25 +14,19 @@
14
14
  <a href="https://www.w3.org/TR/webauthn-2/"><img src="https://img.shields.io/badge/auth-passkey-00FF88" alt="Passkey"></a>
15
15
  </p>
16
16
 
17
- ---
17
+ ## One Dexter identity
18
18
 
19
- ## What this is
19
+ Each signed-in person has one active Dexter identity and one canonical Dexter
20
+ Wallet. A full connection returns the Wallet and account session from the same
21
+ passkey ceremony. Connect asks the Dexter API to verify that exact pair before
22
+ the app receives account-owned data or actions.
20
23
 
21
- A `<SignInWithDexter/>` button runs a discoverable passkey ceremony. The user
22
- taps their face, and your app gets back a session plus their **Dexter
23
- Wallet**: address, live USD balance, and the rails for an agent to spend from
24
- it under on-chain limits. The user holds their own keys; only their passkey
25
- moves funds, enforced on-chain. Composes
26
- [`@dexterai/vault`](https://www.npmjs.com/package/@dexterai/vault).
24
+ The browser may remember earlier Wallet passkeys for recovery. That roster stays
25
+ inside Connect. The product action is **Use another Dexter Wallet**, which runs a
26
+ fresh passkey ceremony and replaces the active identity only after verification.
27
27
 
28
- Four entry points cover the whole flow:
29
-
30
- | Entry point | Runs in | What it gives you |
31
- |---|---|---|
32
- | `@dexterai/connect` | browser | framework-free core: `passkeyLogin`, `createWallet`, `continueWithDexter`, the wallet store, agent-spend controls |
33
- | `@dexterai/connect/react` | browser | `<SignInWithDexter/>`, the branded wallet kit, hooks |
34
- | `@dexterai/connect/server` | Node 18+, Workers, Vercel edge | `verifyDexterSession`: offline session verification |
35
- | `@dexterai/connect/worldid` | browser | `<VerifyPersonhood/>` World ID proof-of-personhood button |
28
+ Agent authority always requires a separate owner grant. Creating or connecting a
29
+ Wallet grants no agent spending authority.
36
30
 
37
31
  ## Install
38
32
 
@@ -40,161 +34,224 @@ Four entry points cover the whole flow:
40
34
  npm install @dexterai/connect @dexterai/vault react
41
35
  ```
42
36
 
43
- `@solana/web3.js` and `@worldcoin/idkit` are optional peers: the first for
44
- passkey and agent-spend signing, the second only if you use the World ID button.
37
+ `@solana/web3.js` is optional and supports signing paths.
38
+ `@worldcoin/idkit` is optional and supports the World ID entry point.
39
+
40
+ ## Entry points
41
+
42
+ | Import | Purpose |
43
+ |---|---|
44
+ | `@dexterai/connect` | Passkey ceremonies, hosted signing, lifecycle operations, and agent authority |
45
+ | `@dexterai/connect/react` | The canonical React control, hooks, and Dexter UI primitives |
46
+ | `@dexterai/connect/server` | Local verification of Dexter account sessions |
47
+ | `@dexterai/connect/worldid` | Optional World ID proof-of-personhood control |
48
+
49
+ ## Canonical React integration
45
50
 
46
- ## Quick start
51
+ `useDexterConnection` is the controlled integration for a product header,
52
+ account menu, or connection screen. The host owns its account-session storage.
53
+ Connect owns the Wallet ceremony, pair verification, and display permissions.
47
54
 
48
55
  ```tsx
49
- import { SignInWithDexter } from '@dexterai/connect/react';
50
-
51
- function Header() {
52
- return (
53
- <SignInWithDexter
54
- onSuccess={({ session, vault }) => {
55
- // session = auth tokens (camelCase); vault = the Dexter Wallet
56
- seatYourSession(session);
57
- }}
58
- />
59
- );
56
+ import { useDexterConnection } from '@dexterai/connect/react';
57
+
58
+ function DexterControl({ loading, session }: Props) {
59
+ const dexter = useDexterConnection({
60
+ intent: 'wallet',
61
+ accountSession: loading
62
+ ? { status: 'loading' }
63
+ : session
64
+ ? {
65
+ status: 'authenticated',
66
+ accessToken: session.access_token,
67
+ }
68
+ : { status: 'signed_out' },
69
+ installAccountSession: async (next) => {
70
+ await auth.setSession({
71
+ access_token: next.accessToken,
72
+ refresh_token: next.refreshToken,
73
+ });
74
+ },
75
+ clearAccountSession: async () => {
76
+ await auth.signOut();
77
+ },
78
+ });
79
+
80
+ if (dexter.model.stage === 'checking') return <Spinner />;
81
+ if (dexter.model.stage === 'connect') {
82
+ return <button onClick={() => void dexter.connect()}>Connect Dexter</button>;
83
+ }
84
+ if (dexter.model.stage === 'repair') {
85
+ return <button onClick={() => void dexter.connect()}>Reconnect Dexter</button>;
86
+ }
87
+ if (dexter.model.stage === 'offline' || dexter.model.stage === 'error') {
88
+ return <button onClick={() => void dexter.retry()}>Try again</button>;
89
+ }
90
+
91
+ return <WalletMenu dexter={dexter} />;
60
92
  }
61
93
  ```
62
94
 
63
- Signed out, it renders a **Sign in with Dexter** button. Connected, it becomes
64
- the wallet chip: address plus **"$X.XX available."**
65
-
66
- ## Works on any website
67
-
68
- The ceremony is not limited to dexter.cash. On a foreign origin, `passkeyLogin`
69
- opens a hosted popup on `dexter.cash/connect`, runs the ceremony there, and
70
- posts the result back to your page. A browser-stamped hello/ack binds the exact
71
- popup window, hosted origin, caller origin, request nonce, and requested
72
- operation; the caller-origin may be any HTTPS website and is not allowlisted.
73
- The default `transport: 'auto'` picks the right mode; `'popup'` and `'inline'`
74
- force it.
75
-
76
- The connected `passkeySigner.signOperation(rawOperation)` follows the same
77
- cross-origin rule. On an unrelated website it opens the pinned Dexter consent
78
- window and sends the raw operation plus the selected vault identity only after
79
- the exact hello/ack handshake. Those bytes are structured-cloned in a
80
- `sign-request`; they are never put in the URL. The Dexter window displays the
81
- requesting origin and operation-specific consent before returning the
82
- on-chain-ready assertion bytes.
83
-
84
- WebAuthn challenge and verification calls are pinned to
85
- `https://api.dexter.cash`. The legacy `apiBase` option remains source-compatible
86
- only for that exact value (an optional trailing slash is normalized); any other
87
- server fails before a popup, fetch, or authenticator call. `apiBase` is never
88
- placed in the hosted popup URL. The legacy `connectHost` option is likewise
89
- compatibility-only and may name only `https://dexter.cash/connect`; this pins
90
- the credential-handling window without restricting the embedding website.
95
+ The host callbacks are part of the identity transition:
96
+
97
+ - `installAccountSession` receives the session from the verified ceremony. The
98
+ callback should resolve only after the host store publishes that exact access
99
+ token.
100
+ - `clearAccountSession` removes that host session during **Disconnect Dexter**.
101
+ - `accountSession` maps the host store back into `loading`, `signed_out`, or
102
+ `authenticated` with an access token.
103
+
104
+ If account installation fails, Connect restores the previous active Wallet. The
105
+ new identity stays hidden until the host session is installed.
106
+
107
+ ## Integration intents
108
+
109
+ Choose one intent for each control.
110
+
111
+ | Intent | Capabilities requested | Ready state |
112
+ |---|---|---|
113
+ | `identity` | `identity` | Exact Wallet/account pair is bound |
114
+ | `wallet` | `identity`, `wallet.read`, `wallet.use` | Owner Wallet is present; account content still requires `bound` |
115
+ | `agent` | `identity`, `wallet.read`, `agent.authority` | Exact pair is bound; authority is granted in a separate owner flow |
116
+
117
+ `wallet.use` means the owner can use their own Wallet in the current app.
118
+ `agent.authority` means the app may offer a governed grant for an agent. The two
119
+ permissions are separate.
120
+
121
+ ## Stage and permission model
122
+
123
+ Render from `dexter.model`, rather than inferring connection from a cached Wallet
124
+ or account token.
125
+
126
+ | Stage | Product response |
127
+ |---|---|
128
+ | `connect` | Offer the configured Dexter connection action |
129
+ | `checking` | Keep private content closed while the exact pair is verified |
130
+ | `ready` | Render only the fields enabled in `model.permissions` |
131
+ | `repair` | Offer the fresh passkey reconnect path |
132
+ | `offline` | Keep private Wallet and account content closed; offer retry |
133
+ | `error` | Show a concise error and offer retry |
134
+
135
+ The permission fields are:
136
+
137
+ | Field | Meaning |
138
+ |---|---|
139
+ | `walletIdentityVisible` | The active Wallet identity may be shown |
140
+ | `walletDataVisible` | Wallet balances and related data may be shown |
141
+ | `ownerWalletUseEnabled` | The owner may use this Wallet in the current app |
142
+ | `accountContentVisible` | The API verified `bound`; account-owned content may be shown |
143
+ | `agentAuthorityVisible` | A bound `agent` integration may present agent-authority controls |
144
+
145
+ Only `bound` unlocks account profile, roles, credit, servers, or other
146
+ account-owned content. A conflict enters the repair stage with private account
147
+ access closed.
148
+
149
+ ## Lifecycle actions
150
+
151
+ The canonical control presents three identity actions:
152
+
153
+ | Action | Effect |
154
+ |---|---|
155
+ | **Use another Dexter Wallet** | Runs a fresh ceremony and keeps the replacement hidden until the API verifies the pair and the host installs the matching account session |
156
+ | **Disconnect Dexter** | Clears the host account session and active Wallet; the passkey remains on the device for a later sign-in |
157
+ | **Remove from this device** | Requires explicit confirmation, removes the local Wallet record, and asks the browser to remove its passkey |
158
+
159
+ Connect keeps the browser Wallet roster, raw switching methods, and partial
160
+ Wallet/account disconnects inside its recovery plumbing.
161
+
162
+ ## Framework-neutral transition
163
+
164
+ Apps without React can use the same full transition directly:
91
165
 
92
166
  ```ts
93
- import { passkeyLogin } from '@dexterai/connect';
167
+ import {
168
+ connectDexterIdentity,
169
+ disconnectDexterIdentity,
170
+ } from '@dexterai/connect';
94
171
 
95
- const { session, vault } = await passkeyLogin({ transport: 'auto' });
172
+ const result = await connectDexterIdentity({
173
+ transport: 'auto',
174
+ installAccountSession: (session) => auth.setSession(session),
175
+ });
176
+
177
+ await disconnectDexterIdentity({
178
+ clearAccountSession: () => auth.signOut(),
179
+ });
96
180
  ```
97
181
 
98
- By default, a successful sign-in immediately makes its wallet active in the
99
- browser wallet store, preserving existing behavior. A flow that must finish a
100
- separate account-level approval can instead keep the result provisional:
182
+ `connectDexterIdentity` keeps the passkey result provisional, verifies its exact
183
+ Wallet/account relation, then publishes the Wallet and asks the host to install
184
+ the matching account session.
185
+
186
+ ## Hosted ceremonies
187
+
188
+ On another HTTPS origin, Connect opens the ceremony on `dexter.cash/connect` and
189
+ returns the result to the calling app. The browser handshake binds the popup,
190
+ hosted origin, caller origin, nonce, and requested operation. The hosted window
191
+ also handles consent for Wallet signing.
192
+
193
+ WebAuthn challenge and verification calls use `https://api.dexter.cash`. The
194
+ default `transport: 'auto'` selects inline or popup transport. Integrators can
195
+ force `popup` or `inline` when their environment requires it.
196
+
197
+ The first-party page uses the guarded hosted entry instead of importing raw
198
+ login or Wallet-store functions:
101
199
 
102
200
  ```ts
103
- import { passkeyLogin, setActiveHandle } from '@dexterai/connect';
201
+ import { runHostedCeremony } from '@dexterai/connect/hosted';
104
202
 
105
- const result = await passkeyLogin({
106
- transport: 'auto',
203
+ const result = await runHostedCeremony({
204
+ operation: 'continue',
107
205
  walletStore: 'provisional',
108
206
  });
109
-
110
- // Only after your approval has bound this exact wallet to the account:
111
- if (result.vault) {
112
- setActiveHandle(
113
- result.vault.userHandle,
114
- result.vault.walletLabel ?? undefined,
115
- result.vault.credentialId,
116
- );
117
- }
118
207
  ```
119
208
 
120
- `provisional` suppresses both active-handle and wallet-roster writes on the
121
- hosted Dexter origin and the calling origin. It does not weaken passkey
122
- verification or persist a second identity. `recoverWallet`, `createWallet`, and
123
- every terminal sign-in/create branch of `continueWithDexter` accept the same
124
- option. A provisional creation still completes the passkey and Vault ceremony
125
- and returns the full `CreateWalletResult`; explicitly call
126
- `setActiveHandle(result.handle, result.label ?? undefined, result.credentialId)`
127
- only after the separate approval succeeds. The only supported modes are exact
128
- `commit` and `provisional`; omitted means `commit`.
209
+ This entry runs only on `https://dexter.cash`. It pins the inline transport and
210
+ Dexter API while preserving provisional Wallet results for the opener. The root
211
+ package continues to expose the complete identity transition rather than its
212
+ private login and browser-roster steps.
129
213
 
130
- ## Verify the session on your server
214
+ ## Server verification
131
215
 
132
216
  ```ts
133
217
  import { createDexterClient } from '@dexterai/connect/server';
134
218
 
135
- const dexter = createDexterClient(); // parameterized on (iss, jwksUrl); defaults to Dexter's issuer
219
+ const dexter = createDexterClient();
136
220
 
137
221
  export async function handler(req: Request) {
138
222
  const auth = await dexter.authenticateRequest(req);
139
223
  if (!auth.isSignedIn) return new Response('unauthorized', { status: 401 });
140
- auth.sub; // stable user id
141
- auth.vaultAddress; // the Dexter Wallet address, from the signed dexter claim
142
- auth.claims; // full verified JWT payload
224
+ if (!auth.userHandle) {
225
+ return new Response('wallet identity required', { status: 403 });
226
+ }
227
+
228
+ auth.userHandle; // stable Dexter Wallet principal
229
+ auth.vaultAddress; // Wallet capability
230
+ auth.sub; // account subject
231
+ auth.claims; // verified JWT payload
143
232
  }
144
233
  ```
145
234
 
146
- Verification is a local ES256 signature check against a cached JWKS. The first
147
- call fetches the key set; every later call is pure local crypto with zero
148
- network (measured at ~0.6ms). The algorithm list is pinned to ES256, and
149
- issuer plus audience are always checked. `verifyDexterSession(token, options)`
150
- does the same for a bare token string, and `jwtKey` accepts a public JWK for
151
- fully networkless deployments.
235
+ The server entry verifies ES256 signatures against Dexter's JWKS and checks the
236
+ issuer and audience. `verifyDexterSession` verifies a token directly.
152
237
 
153
- ## Hook (full control)
238
+ ## Wallet creation and recovery
154
239
 
155
- ```tsx
156
- import { useSignInWithDexter } from '@dexterai/connect/react';
157
-
158
- const c = useSignInWithDexter();
159
- await c.signIn(); // run the passkey ceremony
160
- c.status; // idle -> pending -> done -> error
161
- c.vaultAddress; // the Dexter Wallet address (base58)
162
- c.usdcBalance; // USD available (via Dexter's RPC), or null
163
- c.disconnect();
164
- ```
165
-
166
- | Field | What it is |
167
- |---|---|
168
- | `signIn()` / `disconnect()` | run the passkey ceremony / clear state |
169
- | `status` / `isVaultConnected` | `idle->pending->done->error` / connected flag |
170
- | `session` | auth session tokens (camelCase) |
171
- | `vaultAddress` / `vaultPda` | the Dexter Wallet address / PDA |
172
- | `usdcBalance` / `refreshBalance()` | USD available, best-effort via Dexter's RPC |
173
- | `vault` / `credentialId` / `error` | raw vault payload / credential id / typed error |
240
+ `createWallet` creates an owner Wallet and passkey. Agent authority remains a
241
+ later, explicit owner action. `recoverWallet` runs a fresh Wallet ceremony for a
242
+ device that already holds a Dexter passkey. Product integrations should route
243
+ full account connection through `useDexterConnection` or
244
+ `connectDexterIdentity`, so the account and Wallet are verified together.
174
245
 
175
- ## The wallet kit
246
+ ## Agent authority
176
247
 
177
- Branded, presentational pieces that share one implementation across every
178
- Dexter surface, themed with `--dx-*` CSS variables: `DexterButton` (and
179
- `DexterMark`) for any action that should look like Dexter, `DexterWalletChip`
180
- as the header trigger, `DexterWalletMenu` for manage / save / start-fresh, and
181
- the `useDexterWallet` + `useIdentity` hooks to drive them.
248
+ Agent integrations build, present, and stage a separate owner grant. The grant
249
+ can include x402 payment rules or other governed actions. It is bound to the
250
+ selected Wallet and remains revocable.
182
251
 
183
- ## Agent spend
184
-
185
- The control surface for letting an agent spend from the connected wallet:
186
-
187
- ```ts
188
- import {
189
- assembleAgentSpendStatus, // honest two-mode status read
190
- enableAgentSpend, // the on switch
191
- revokeAgentSpend, // the off switch
192
- createPasskeySigner, // @dexterai/vault guest signer for x402 / tab flows
193
- } from '@dexterai/connect';
194
- ```
195
-
196
- The verbs are framework-free and take `apiOrigin` as a parameter; the SDK
197
- reads no environment variables.
252
+ Key helpers include `buildAgentAuthorityRequest`, `beginAgentAuthority`,
253
+ `stageAgentAuthority`, and `readAgentAuthority`. The bounded x402 helpers provide
254
+ the equivalent hosted setup path for x402-only grants.
198
255
 
199
256
  ## World ID
200
257
 
@@ -204,66 +261,19 @@ import { VerifyPersonhood } from '@dexterai/connect/worldid';
204
261
  <VerifyPersonhood onSuccess={(proof) => sendToYourVerifier(proof)} />
205
262
  ```
206
263
 
207
- `useVerifyPersonhood` is the headless version. Requires the optional
264
+ `useVerifyPersonhood` is the headless form. This entry requires the optional
208
265
  `@worldcoin/idkit` peer.
209
266
 
210
- ## Wallet-only sign-in (no account session)
211
-
212
- `recoverWallet` re-points a browser at an existing Dexter Wallet — the wallet
213
- IS the sign-in; nothing else is minted. Use it when your surface treats the
214
- wallet as the identity (the dexter.cash header does exactly this):
215
-
216
- ```ts
217
- import { recoverWallet } from '@dexterai/connect';
218
-
219
- const outcome = await recoverWallet({ preferImmediate: true }); // fire on TAP, never on mount
220
- if (outcome.ok) {
221
- // outcome.vault.swigAddress, outcome.vault.walletLabel — the store + every
222
- // useIdentity/useDexterWallet surface is already updated.
223
- } else if (outcome.reason === 'no_credential') {
224
- // this device has no wallet passkey → offer your create flow
225
- } else if (outcome.reason === 'cancelled') {
226
- // the user dismissed the sheet → stay silent
227
- }
228
- ```
229
-
230
- It returns a discriminated outcome instead of throwing: user cancel is a
231
- normal result in WebAuthn, not an exception. `preferImmediate` uses Chrome
232
- 149+'s immediate UI mode to fast-fail instantly when the device holds no
233
- passkey (no empty account-picker sheet); everywhere else it falls back to the
234
- normal modal. Works from any website — off dexter.cash the ceremony runs in
235
- the hosted popup automatically.
236
-
237
- React: `<SignInWithDexter mode="recover" preferImmediate onRecovered={…} />`
238
- (after a successful recover the element renders null — show identity with
239
- `DexterWalletChip` over `useIdentity`), or `useSignInWithDexter().recover()`.
240
-
241
- ## Wallet lifecycle
242
-
243
- - `createWallet` mints a brand-new named passkey + vault; `passkeyLogin` signs
244
- an existing one in; `continueWithDexter` resumes a known wallet;
245
- `recoverWallet` restores the wallet with no account session.
246
- - The **wallet store** (`getActiveHandle`, `listWallets`, `switchWallet`,
247
- `ejectActiveWallet`, `forgetWallet`, `subscribeWallet`) is the canonical
248
- owner of the active-wallet handle. Read and write through it rather than
249
- touching localStorage.
250
- - The **WebAuthn Signal API** helpers (`renamePasskey`, `prunePasskey`,
251
- `syncAcceptedPasskeys`, `passkeySignalSupport`) keep the OS keychain in sync
252
- where the browser supports it.
253
- - `resolveIdentity` combines the wallet handle with whatever account token you
254
- pass in; `ceremonyPhaseLabel` gives shared copy for connecting-step UI;
255
- `createAnonServerPolicy` builds the anonymous server policy for the signer.
256
-
257
267
  ## Peer dependencies
258
268
 
259
- | Peer | Required | Why |
269
+ | Peer | Required | Purpose |
260
270
  |---|---|---|
261
- | `react` >=18 | yes | the `/react` and `/worldid` surfaces |
262
- | `@dexterai/vault` ^0.43 | yes | hardened signer envelope validation + agent-spend message builders |
263
- | `@solana/web3.js` | optional | passkey and agent-spend signing paths |
264
- | `@worldcoin/idkit` | optional | only for `/worldid` |
271
+ | `react` >=18 | yes | React and World ID entry points |
272
+ | `@dexterai/vault` ^0.43 | yes | Wallet signer and governed authority messages |
273
+ | `@solana/web3.js` | optional | Passkey and agent signing paths |
274
+ | `@worldcoin/idkit` | optional | World ID controls |
265
275
 
266
- The `/server` entry has none of these peers; it depends only on `jose`.
276
+ The server entry depends only on `jose`.
267
277
 
268
278
  ## License
269
279