@dexterai/connect 0.35.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/index.d.ts +160 -5
- package/dist/index.js +292 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,40 @@ await sendFromAccount({ identity, send: { mint, amount: '2500000', to } });
|
|
|
92
92
|
- With lazy opening, sign-up's approvals are checked and held, not sent. Each setup step can be confirmed with `signature: null`, and the Account's status is then `held`: its address takes money at once and it opens on the chain by itself on the first money or the first action. Show a `held` Account exactly like a `ready` one; `openAccount` returns it without prompting. A send is never taken as confirmed without the signature of what it sent.
|
|
93
93
|
- The first action on a held Account finishes the opening inside that request, so it can take a minute. Connect sets no timeout of its own on these requests.
|
|
94
94
|
|
|
95
|
+
### Agent connections
|
|
96
|
+
|
|
97
|
+
An agent asks through OAuth to pay on the owner's behalf. The owner reviews the request and approves one exact spending permission with their passkey, through the same approval step as setup and send.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import {
|
|
101
|
+
getConnectionRequest, grantConnection, connectionClientLabel, listConnections, revokeConnection,
|
|
102
|
+
getConnectionApproval, approveConnectionPayment, declineConnectionPayment,
|
|
103
|
+
} from '@dexterai/connect';
|
|
104
|
+
|
|
105
|
+
const review = await getConnectionRequest({ identity, requestId }); // client, starting limits, payee
|
|
106
|
+
const label = connectionClientLabel(review.client); // "ChatGPT" if verified, else "chatgpt.example"
|
|
107
|
+
const terms = { perPayment: '200000000', per30Days: '2000000000', endsAt: null }; // what the owner chose
|
|
108
|
+
const { redirectUrl } = await grantConnection({ identity, request: review, terms, confirmStep, onStep });
|
|
109
|
+
window.location.assign(redirectUrl); // only ever on review.client.host
|
|
110
|
+
|
|
111
|
+
const connections = await listConnections({ identity });
|
|
112
|
+
await revokeConnection({ identity, connectionId, confirmStep, onStep });
|
|
113
|
+
|
|
114
|
+
// An agent went over a limit; its link opens /account/agents/{connectionId}/approve/{approvalId}.
|
|
115
|
+
const waiting = await getConnectionApproval({ identity, connectionId, approvalId });
|
|
116
|
+
await approveConnectionPayment({ identity, connectionId, approvalId, confirmStep, onStep }); // or per30Days for a budget
|
|
117
|
+
await declineConnectionPayment({ identity, connectionId, approvalId });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
- The request carries starting limits (per payment, per 30 days, and `endsAt`, which is `null` for "until stopped"). The owner may change them, with no maximum. Pass the owner's choice as `terms` in smallest units. Left out, the starting figures apply.
|
|
121
|
+
- The 30-day limit refills: what an agent spent more than 30 days ago no longer counts.
|
|
122
|
+
- `grantConnection` checks that the prepared grant has exactly the owner's limits, in the request's token, before any passkey prompt. It refuses any step but `grant-permission`, and any redirect to a host other than `client.host` (`connection_redirect_refused`). Limits that make no sense, such as zero, a per-payment limit above the 30-day limit, or an end in the past, are refused before any request (`invalid_connection_limits`).
|
|
123
|
+
- `client` is `{ host, verified, name, kind }`. `name` is set only when Dexter has verified the host, and an unverified app's claimed name is dropped. Use `connectionClientLabel` to name the app.
|
|
124
|
+
- A connection is `pending` (an approval that didn't finish; stop it to abandon it), `active`, `stopped` or `revoked`.
|
|
125
|
+
- `revokeConnection`: Dexter's servers stop signing for the connection when the stop is prepared (`connection.state` is `stopped` in the step view). The passkey approval then revokes the permission on chain, and the result's state is `revoked`.
|
|
126
|
+
- Over a limit: an approval is `payment` (this payment is over the per-payment limit) or `budget` (it would go over the 30-day budget, and `newBudget` is the API's proposal). One passkey approves it (`approve-payment` or `raise-budget`). A raise is checked against the owner's `per30Days` before the prompt.
|
|
127
|
+
- A lost reply leaves the step unsettled with `flow: 'connection'`, the same as a send.
|
|
128
|
+
|
|
95
129
|
## Interrupted wallet setup
|
|
96
130
|
|
|
97
131
|
`createWallet()` retains the original passkey when setup is interrupted. Calling
|
package/dist/index.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ interface AccountPasskey {
|
|
|
103
103
|
/** An operation whose last step was approved and whose outcome the API does not know yet. */
|
|
104
104
|
interface AccountUnsettled {
|
|
105
105
|
readonly operationId: string;
|
|
106
|
-
readonly flow:
|
|
106
|
+
readonly flow: AccountFlowName;
|
|
107
107
|
readonly step: string;
|
|
108
108
|
}
|
|
109
109
|
interface AccountOverview {
|
|
@@ -153,6 +153,47 @@ interface AccountOperationDetails {
|
|
|
153
153
|
readonly to: string | null;
|
|
154
154
|
}
|
|
155
155
|
type AccountStepPhase = 'preparing' | 'ready' | 'passkey' | 'sending' | 'confirmed';
|
|
156
|
+
/** The operations an Account approval belongs to. */
|
|
157
|
+
type AccountFlowName = 'setup' | 'send' | 'connection';
|
|
158
|
+
/** An amount in a token's smallest unit, with what it takes to show it. */
|
|
159
|
+
interface AccountAmount {
|
|
160
|
+
readonly amount: string;
|
|
161
|
+
readonly mint: string;
|
|
162
|
+
readonly decimals: number;
|
|
163
|
+
readonly symbol: string | null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* What an agent connection may spend. The API proposes starting figures; the
|
|
167
|
+
* owner may change them before approving, with no maximum.
|
|
168
|
+
*/
|
|
169
|
+
interface AccountConnectionLimits {
|
|
170
|
+
readonly perPayment: AccountAmount;
|
|
171
|
+
/** Refills: what the agent spent more than 30 days ago no longer counts. */
|
|
172
|
+
readonly per30Days: AccountAmount;
|
|
173
|
+
/** `null`: until the owner stops it. */
|
|
174
|
+
readonly endsAt: string | null;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The app asking, known by the host it returns to. `name` is set only when
|
|
178
|
+
* Dexter has verified that host; an app's own claim about its name never shows.
|
|
179
|
+
*/
|
|
180
|
+
interface AccountConnectionClient {
|
|
181
|
+
readonly host: string;
|
|
182
|
+
readonly verified: boolean;
|
|
183
|
+
readonly name: string | null;
|
|
184
|
+
readonly kind: 'chatgpt' | 'claude' | 'other';
|
|
185
|
+
}
|
|
186
|
+
/** What a connection approval or stop is about, as the API prepared it. */
|
|
187
|
+
interface AccountConnectionDetails {
|
|
188
|
+
readonly connectionId: string;
|
|
189
|
+
readonly limits: AccountConnectionLimits | null;
|
|
190
|
+
readonly payee: {
|
|
191
|
+
readonly name: string | null;
|
|
192
|
+
readonly address: string;
|
|
193
|
+
} | null;
|
|
194
|
+
readonly client: AccountConnectionClient | null;
|
|
195
|
+
readonly state: 'pending' | 'active' | 'stopped' | 'revoked' | null;
|
|
196
|
+
}
|
|
156
197
|
/** One approval, as the page should show it. */
|
|
157
198
|
interface AccountStepView {
|
|
158
199
|
/** The API's name for the step. The page words the steps it knows. */
|
|
@@ -163,6 +204,8 @@ interface AccountStepView {
|
|
|
163
204
|
readonly statement: string | null;
|
|
164
205
|
readonly stepsRemaining: number | null;
|
|
165
206
|
readonly details: AccountOperationDetails | null;
|
|
207
|
+
/** Set for a connection's approval or stop. */
|
|
208
|
+
readonly connection: AccountConnectionDetails | null;
|
|
166
209
|
readonly phase: AccountStepPhase;
|
|
167
210
|
/** Set once the step is confirmed. */
|
|
168
211
|
readonly signature: string | null;
|
|
@@ -183,6 +226,8 @@ interface AccountOperationConfig {
|
|
|
183
226
|
interface AccountFlowResult {
|
|
184
227
|
/** Signatures of the transactions the flow sent, in order. A held setup step sends none. */
|
|
185
228
|
readonly signatures: readonly string[];
|
|
229
|
+
/** The last step's own answer, for flows that return more than a signature. */
|
|
230
|
+
readonly outcome: Readonly<Record<string, string>>;
|
|
186
231
|
}
|
|
187
232
|
/**
|
|
188
233
|
* Where one operation stands, from the API's own record and the chain.
|
|
@@ -192,11 +237,13 @@ interface AccountFlowResult {
|
|
|
192
237
|
type AccountOperationStatus = 'prepared' | 'sending' | 'confirmed' | 'failed' | 'expired';
|
|
193
238
|
interface AccountOperationState {
|
|
194
239
|
readonly operationId: string;
|
|
195
|
-
readonly flow:
|
|
240
|
+
readonly flow: AccountFlowName;
|
|
196
241
|
readonly step: string;
|
|
197
242
|
readonly status: AccountOperationStatus;
|
|
198
243
|
readonly signature: string | null;
|
|
199
244
|
readonly next: string | null;
|
|
245
|
+
/** A connection's id, state or redirect, when the operation's answer carries them. */
|
|
246
|
+
readonly outcome: Readonly<Record<string, string>>;
|
|
200
247
|
}
|
|
201
248
|
/**
|
|
202
249
|
* An approved step whose outcome is not known: the reply was lost, slow, or
|
|
@@ -206,10 +253,12 @@ interface AccountOperationState {
|
|
|
206
253
|
*/
|
|
207
254
|
declare class AccountOperationUnsettledError extends ConnectError {
|
|
208
255
|
readonly operationId: string;
|
|
209
|
-
readonly flow:
|
|
256
|
+
readonly flow: AccountFlowName;
|
|
210
257
|
readonly step: string;
|
|
211
|
-
constructor(operationId: string, flow:
|
|
258
|
+
constructor(operationId: string, flow: AccountFlowName, step: string);
|
|
212
259
|
}
|
|
260
|
+
/** How a page names the app: the verified name, or else the host itself. */
|
|
261
|
+
declare function connectionClientLabel(client: AccountConnectionClient): string;
|
|
213
262
|
/** Read the signed-in owner's Account, or `null` when none is open yet. */
|
|
214
263
|
declare function getAccount(config: Pick<AccountOperationConfig, 'identity' | 'signal'>): Promise<DexterAccount | null>;
|
|
215
264
|
/**
|
|
@@ -242,6 +291,112 @@ declare function sendFromAccount(config: AccountOperationConfig & {
|
|
|
242
291
|
declare function formatAccountAmount(amount: string, decimals: number): string;
|
|
243
292
|
/** Turn what a person typed ("2.5") into a smallest-unit string, or `null` if it is not an amount. */
|
|
244
293
|
declare function parseAccountAmount(input: string, decimals: number): string | null;
|
|
294
|
+
/** An OAuth request for an agent connection, as the owner reviews it. */
|
|
295
|
+
interface AccountConnectionReview {
|
|
296
|
+
readonly requestId: string;
|
|
297
|
+
/** `client.host` is where the person goes back to after approving. */
|
|
298
|
+
readonly client: AccountConnectionClient;
|
|
299
|
+
readonly scope: string;
|
|
300
|
+
/** The starting figures. The owner may change them; see grantConnection. */
|
|
301
|
+
readonly limits: AccountConnectionLimits;
|
|
302
|
+
readonly payee: AccountConnectionDetails['payee'];
|
|
303
|
+
readonly expiresAt: string | null;
|
|
304
|
+
}
|
|
305
|
+
/** An agent connection on the owner's Account. */
|
|
306
|
+
interface AccountConnection {
|
|
307
|
+
readonly connectionId: string;
|
|
308
|
+
readonly client: AccountConnectionClient;
|
|
309
|
+
readonly limits: AccountConnectionLimits;
|
|
310
|
+
readonly spent30Days: AccountAmount | null;
|
|
311
|
+
/**
|
|
312
|
+
* `pending`: an approval that did not finish (stop it to abandon it); `stopped`: Dexter's servers no
|
|
313
|
+
* longer sign for it; `revoked`: the permission is gone on chain.
|
|
314
|
+
*/
|
|
315
|
+
readonly state: 'pending' | 'active' | 'stopped' | 'revoked';
|
|
316
|
+
readonly createdAt: string | null;
|
|
317
|
+
readonly stoppedAt: string | null;
|
|
318
|
+
readonly revokedAt: string | null;
|
|
319
|
+
}
|
|
320
|
+
/** Read an agent's OAuth request so the owner can review it before approving. */
|
|
321
|
+
declare function getConnectionRequest(config: Pick<AccountOperationConfig, 'identity' | 'signal'> & {
|
|
322
|
+
readonly requestId: string;
|
|
323
|
+
}): Promise<AccountConnectionReview>;
|
|
324
|
+
/** List the owner's agent connections. */
|
|
325
|
+
declare function listConnections(config: Pick<AccountOperationConfig, 'identity' | 'signal'>): Promise<readonly AccountConnection[]>;
|
|
326
|
+
/** Read one of the owner's agent connections. */
|
|
327
|
+
declare function getConnection(config: Pick<AccountOperationConfig, 'identity' | 'signal'> & {
|
|
328
|
+
readonly connectionId: string;
|
|
329
|
+
}): Promise<AccountConnection>;
|
|
330
|
+
/** The limits the owner approves: amounts in the request's smallest units, and an end or none. */
|
|
331
|
+
interface AccountConnectionTerms {
|
|
332
|
+
readonly perPayment: string;
|
|
333
|
+
readonly per30Days: string;
|
|
334
|
+
/** `null`: until the owner stops it. */
|
|
335
|
+
readonly endsAt: string | null;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Approve an agent's spending permission with the owner's passkey, at the
|
|
339
|
+
* limits the owner chose (the request's starting figures when `terms` is
|
|
340
|
+
* left out). Resolves with the new connection and the address to return the
|
|
341
|
+
* person to, which must be on the host the reviewed request named.
|
|
342
|
+
*/
|
|
343
|
+
declare function grantConnection(config: AccountOperationConfig & {
|
|
344
|
+
readonly request: Pick<AccountConnectionReview, 'requestId' | 'client' | 'limits'>;
|
|
345
|
+
readonly terms?: AccountConnectionTerms;
|
|
346
|
+
}): Promise<AccountFlowResult & {
|
|
347
|
+
readonly connectionId: string;
|
|
348
|
+
readonly redirectUrl: string;
|
|
349
|
+
}>;
|
|
350
|
+
/**
|
|
351
|
+
* Stop an agent connection. Dexter's servers stop signing for it when the stop
|
|
352
|
+
* is prepared; the owner's passkey then revokes the permission on chain.
|
|
353
|
+
*/
|
|
354
|
+
declare function revokeConnection(config: AccountOperationConfig & {
|
|
355
|
+
readonly connectionId: string;
|
|
356
|
+
}): Promise<AccountFlowResult & {
|
|
357
|
+
readonly state: 'revoked';
|
|
358
|
+
}>;
|
|
359
|
+
/** A payment an agent asked for that its limits don't cover. */
|
|
360
|
+
interface AccountConnectionApproval {
|
|
361
|
+
readonly approvalId: string;
|
|
362
|
+
readonly connectionId: string;
|
|
363
|
+
/** `payment`: this one payment is over the per-payment limit; `budget`: it would go over the 30-day budget. */
|
|
364
|
+
readonly kind: 'payment' | 'budget';
|
|
365
|
+
readonly amount: AccountAmount;
|
|
366
|
+
readonly payee: {
|
|
367
|
+
readonly host: string | null;
|
|
368
|
+
readonly name: string | null;
|
|
369
|
+
readonly address: string;
|
|
370
|
+
} | null;
|
|
371
|
+
/** For `budget`: the 30-day budget the API proposes so this payment fits. */
|
|
372
|
+
readonly newBudget: AccountAmount | null;
|
|
373
|
+
readonly expiresAt: string | null;
|
|
374
|
+
readonly state: 'waiting' | 'approved' | 'declined' | 'expired';
|
|
375
|
+
}
|
|
376
|
+
/** Read a payment waiting for the owner's approval. */
|
|
377
|
+
declare function getConnectionApproval(config: Pick<AccountOperationConfig, 'identity' | 'signal'> & {
|
|
378
|
+
readonly connectionId: string;
|
|
379
|
+
readonly approvalId: string;
|
|
380
|
+
}): Promise<AccountConnectionApproval>;
|
|
381
|
+
/**
|
|
382
|
+
* Approve a waiting payment with the owner's passkey. For a `budget` approval,
|
|
383
|
+
* `per30Days` (smallest units) sets the new 30-day budget; left out, the API's
|
|
384
|
+
* proposed budget applies.
|
|
385
|
+
*/
|
|
386
|
+
declare function approveConnectionPayment(config: AccountOperationConfig & {
|
|
387
|
+
readonly connectionId: string;
|
|
388
|
+
readonly approvalId: string;
|
|
389
|
+
readonly per30Days?: string;
|
|
390
|
+
}): Promise<AccountFlowResult & {
|
|
391
|
+
readonly approvalId: string;
|
|
392
|
+
}>;
|
|
393
|
+
/** Turn a waiting payment down. The agent is told it was declined. */
|
|
394
|
+
declare function declineConnectionPayment(config: Pick<AccountOperationConfig, 'identity' | 'signal'> & {
|
|
395
|
+
readonly connectionId: string;
|
|
396
|
+
readonly approvalId: string;
|
|
397
|
+
}): Promise<{
|
|
398
|
+
readonly state: 'declined';
|
|
399
|
+
}>;
|
|
245
400
|
|
|
246
401
|
/** One localStorage entry per Wallet keeps inactive Wallet proofs independent. */
|
|
247
402
|
declare const WALLET_PROOF_SESSION_STORAGE_PREFIX: "dexter:wallet-identity-proof-session:";
|
|
@@ -862,4 +1017,4 @@ type SignAccountChallengeResult = {
|
|
|
862
1017
|
};
|
|
863
1018
|
declare function signAccountChallenge(config: SignAccountChallengeConfig): Promise<SignAccountChallengeResult>;
|
|
864
1019
|
|
|
865
|
-
export { ACCOUNT_API_PATH, AGENT_AUTHORITY_NAMESPACE, AGENT_AUTHORITY_STATUS_NAMESPACE, type AccountBalances, type AccountChallengeAssertion, type AccountConnectionRequest, type AccountFlowResult, AccountIdentityResult, type AccountOperationConfig, type AccountOperationDetails, type AccountOperationState, type AccountOperationStatus, AccountOperationUnsettledError, type AccountOverview, type AccountPasskey, type AccountPrincipalContext, type AccountSendRequest, type AccountStepPhase, type AccountStepView, type AccountTokenBalance, type AccountUnsettled, type AgentAuthorityActiveRole, type AgentAuthorityApprovalMode, type AgentAuthorityAuthorization, type AgentAuthorityBootstrapRequest, type AgentAuthorityCapacity, AgentAuthorityError, type AgentAuthorityRule, type AgentAuthorityRuleBase, type AgentAuthorityStagedReceipt, type AgentAuthorityStatus, type AgentAuthorityTarget, AgentSpendError, type AgentSpendIdentity, type AgentSpendStatus, type AgentSpendTab, type AnonChallengeResult, type AnonServerPolicy, type AutomaticAgentSpend, BindingFetch, AgentAuthorityError as BoundedX402AuthorityError, type BoundedX402Authorization, type BoundedX402BootstrapRequest, type BoundedX402Draft, type BoundedX402Limits, type BoundedX402Rule, type BoundedX402StagedReceipt, type BoundedX402Validation, CeremonyPhase, ConnectError, ConnectVault, type CreatePasskeySignerOptions, type DexterAccount, type DexterIdentityCoordinator, type DexterIdentityCoordinatorOptions, type EnableAgentSpendResult, MAX_AUTHORITY_AMOUNT_ATOMIC, MissingVaultRecoveryConfig, MissingVaultRecoveryResult, type PasskeySignalSupport, type RawAgentSpendSession, type RawAgentSpendStatus, RecoverOutcome, RecoverWalletConfig, type RevokeAgentSpendResult, type SignAccountChallengeConfig, type SignAccountChallengeResult, type StagedAgentAuthorityRule, type TradeAuthorityRule, WALLET_PROOF_SESSION_STORAGE_PREFIX, WalletAccountBindingClient, WalletAccountRelationSnapshot, WalletBindingCandidate, WalletIdentityProof, type WalletProofLifecycleEvent, type WalletProofSession, type WalletProofSessionEvent, type WalletProofSessionOperation, type WalletProofSessionStorage, type WalletProofSessionStore, type WalletProofSessionStoreOptions, type WalletProofStorageEvent, type WalletProofStorageEventSource, type X402LimitDraft, type X402LimitValidation, type X402Limits, type X402PaymentAuthorityRule, X402_ALLOWED_SCHEMES, X402_ASSET, X402_COUNTERPARTY_SCOPE, X402_PROTOCOL_ID, X402_PROTOCOL_VERSION, assembleAgentSpendStatus, beginAgentAuthority, beginBoundedX402Authority, buildAgentAuthorityRequest, buildBoundedX402BootstrapRequest, buildX402PaymentRule, ceremonyPhaseLabel, createAnonServerPolicy, createDexterIdentityCoordinator, createPasskeySigner, createWalletProofSessionStore, describeAgentSpendError, enableAgentSpend, exactAgentAuthorityApprovalRedirect, exactBoundedX402ApprovalRedirect, formatAccountAmount, getAccount, getAccountBalances, getAccountOperation, getAccountOverview, noCustomX402Limits, openAccount, parseAccountAmount, passkeySignalSupport, prunePasskey, readAgentAuthority, recoverMissingVaultForAccount, recoverWallet, renamePasskey, revokeAgentSpend, sendFromAccount, signAccountChallenge, stageAgentAuthority, stageBoundedX402Authority, syncAcceptedPasskeys, validateBoundedX402Draft, walletProofSessionStore };
|
|
1020
|
+
export { ACCOUNT_API_PATH, AGENT_AUTHORITY_NAMESPACE, AGENT_AUTHORITY_STATUS_NAMESPACE, type AccountAmount, type AccountBalances, type AccountChallengeAssertion, type AccountConnection, type AccountConnectionApproval, type AccountConnectionClient, type AccountConnectionDetails, type AccountConnectionLimits, type AccountConnectionRequest, type AccountConnectionReview, type AccountConnectionTerms, type AccountFlowName, type AccountFlowResult, AccountIdentityResult, type AccountOperationConfig, type AccountOperationDetails, type AccountOperationState, type AccountOperationStatus, AccountOperationUnsettledError, type AccountOverview, type AccountPasskey, type AccountPrincipalContext, type AccountSendRequest, type AccountStepPhase, type AccountStepView, type AccountTokenBalance, type AccountUnsettled, type AgentAuthorityActiveRole, type AgentAuthorityApprovalMode, type AgentAuthorityAuthorization, type AgentAuthorityBootstrapRequest, type AgentAuthorityCapacity, AgentAuthorityError, type AgentAuthorityRule, type AgentAuthorityRuleBase, type AgentAuthorityStagedReceipt, type AgentAuthorityStatus, type AgentAuthorityTarget, AgentSpendError, type AgentSpendIdentity, type AgentSpendStatus, type AgentSpendTab, type AnonChallengeResult, type AnonServerPolicy, type AutomaticAgentSpend, BindingFetch, AgentAuthorityError as BoundedX402AuthorityError, type BoundedX402Authorization, type BoundedX402BootstrapRequest, type BoundedX402Draft, type BoundedX402Limits, type BoundedX402Rule, type BoundedX402StagedReceipt, type BoundedX402Validation, CeremonyPhase, ConnectError, ConnectVault, type CreatePasskeySignerOptions, type DexterAccount, type DexterIdentityCoordinator, type DexterIdentityCoordinatorOptions, type EnableAgentSpendResult, MAX_AUTHORITY_AMOUNT_ATOMIC, MissingVaultRecoveryConfig, MissingVaultRecoveryResult, type PasskeySignalSupport, type RawAgentSpendSession, type RawAgentSpendStatus, RecoverOutcome, RecoverWalletConfig, type RevokeAgentSpendResult, type SignAccountChallengeConfig, type SignAccountChallengeResult, type StagedAgentAuthorityRule, type TradeAuthorityRule, WALLET_PROOF_SESSION_STORAGE_PREFIX, WalletAccountBindingClient, WalletAccountRelationSnapshot, WalletBindingCandidate, WalletIdentityProof, type WalletProofLifecycleEvent, type WalletProofSession, type WalletProofSessionEvent, type WalletProofSessionOperation, type WalletProofSessionStorage, type WalletProofSessionStore, type WalletProofSessionStoreOptions, type WalletProofStorageEvent, type WalletProofStorageEventSource, type X402LimitDraft, type X402LimitValidation, type X402Limits, type X402PaymentAuthorityRule, X402_ALLOWED_SCHEMES, X402_ASSET, X402_COUNTERPARTY_SCOPE, X402_PROTOCOL_ID, X402_PROTOCOL_VERSION, approveConnectionPayment, assembleAgentSpendStatus, beginAgentAuthority, beginBoundedX402Authority, buildAgentAuthorityRequest, buildBoundedX402BootstrapRequest, buildX402PaymentRule, ceremonyPhaseLabel, connectionClientLabel, createAnonServerPolicy, createDexterIdentityCoordinator, createPasskeySigner, createWalletProofSessionStore, declineConnectionPayment, describeAgentSpendError, enableAgentSpend, exactAgentAuthorityApprovalRedirect, exactBoundedX402ApprovalRedirect, formatAccountAmount, getAccount, getAccountBalances, getAccountOperation, getAccountOverview, getConnection, getConnectionApproval, getConnectionRequest, grantConnection, listConnections, noCustomX402Limits, openAccount, parseAccountAmount, passkeySignalSupport, prunePasskey, readAgentAuthority, recoverMissingVaultForAccount, recoverWallet, renamePasskey, revokeAgentSpend, revokeConnection, sendFromAccount, signAccountChallenge, stageAgentAuthority, stageBoundedX402Authority, syncAcceptedPasskeys, validateBoundedX402Draft, walletProofSessionStore };
|
package/dist/index.js
CHANGED
|
@@ -233,6 +233,8 @@ var AccountOperationUnsettledError = class extends ConnectError {
|
|
|
233
233
|
this.step = step;
|
|
234
234
|
}
|
|
235
235
|
};
|
|
236
|
+
var SETUP_ROUTE = { flow: "setup", prepare: "/setup/prepare", complete: "/setup/complete" };
|
|
237
|
+
var SEND_ROUTE = { flow: "send", prepare: "/send/prepare", complete: "/send/complete" };
|
|
236
238
|
function record(value) {
|
|
237
239
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
238
240
|
}
|
|
@@ -311,7 +313,57 @@ function detailsFrom(value) {
|
|
|
311
313
|
to: value.to ?? null
|
|
312
314
|
});
|
|
313
315
|
}
|
|
314
|
-
|
|
316
|
+
var isFlowName = (value) => value === "setup" || value === "send" || value === "connection";
|
|
317
|
+
var connectionKey = (value) => typeof value === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(value);
|
|
318
|
+
function amountFrom(value) {
|
|
319
|
+
if (!record(value) || !units(value.amount) || !address(value.mint) || typeof value.decimals !== "number" || !Number.isInteger(value.decimals) || value.decimals < 0 || value.decimals > 18 || value.symbol !== null && value.symbol !== void 0 && !text(value.symbol, 20)) malformed();
|
|
320
|
+
return Object.freeze({
|
|
321
|
+
amount: value.amount,
|
|
322
|
+
mint: value.mint,
|
|
323
|
+
decimals: value.decimals,
|
|
324
|
+
symbol: value.symbol ?? null
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
function limitsFrom(value) {
|
|
328
|
+
if (!record(value)) malformed();
|
|
329
|
+
const endsAt = value.endsAt === null || value.endsAt === void 0 ? null : time(value.endsAt);
|
|
330
|
+
if (endsAt === null && value.endsAt !== null && value.endsAt !== void 0) malformed();
|
|
331
|
+
const perPayment = amountFrom(value.perPayment);
|
|
332
|
+
const per30Days = amountFrom(value.per30Days);
|
|
333
|
+
if (perPayment.mint !== per30Days.mint) malformed();
|
|
334
|
+
return Object.freeze({ perPayment, per30Days, endsAt });
|
|
335
|
+
}
|
|
336
|
+
var time = (value) => text(value, 40) && !Number.isNaN(Date.parse(value)) ? value : null;
|
|
337
|
+
var hostName = (value) => typeof value === "string" && /^[a-z0-9.-]{1,253}(:[0-9]{1,5})?$/i.test(value) && value.includes(".");
|
|
338
|
+
function clientFrom(value) {
|
|
339
|
+
if (!record(value) || !hostName(value.host) || typeof value.verified !== "boolean") malformed();
|
|
340
|
+
const verified = value.verified;
|
|
341
|
+
const name = verified && text(value.name, 80) ? value.name : null;
|
|
342
|
+
const host = value.host.toLowerCase();
|
|
343
|
+
const kind = !verified ? "other" : value.kind === "chatgpt" || value.kind === "claude" ? value.kind : host === "chatgpt.com" || host === "chat.openai.com" ? "chatgpt" : host === "claude.ai" || host === "claude.com" ? "claude" : "other";
|
|
344
|
+
return Object.freeze({ host, verified, name, kind });
|
|
345
|
+
}
|
|
346
|
+
function connectionClientLabel(client) {
|
|
347
|
+
return client.verified && client.name ? client.name : client.host;
|
|
348
|
+
}
|
|
349
|
+
function payeeFrom(value) {
|
|
350
|
+
if (value === null || value === void 0) return null;
|
|
351
|
+
if (!record(value) || !address(value.address) || value.name !== null && value.name !== void 0 && !text(value.name, 80)) malformed();
|
|
352
|
+
return Object.freeze({ name: value.name ?? null, address: value.address });
|
|
353
|
+
}
|
|
354
|
+
var CONNECTION_STATES = ["pending", "active", "stopped", "revoked"];
|
|
355
|
+
var connectionState = (value) => CONNECTION_STATES.includes(value) ? value : null;
|
|
356
|
+
function connectionDetailsFrom(value) {
|
|
357
|
+
if (!record(value) || !connectionKey(value.connectionId)) malformed();
|
|
358
|
+
return Object.freeze({
|
|
359
|
+
connectionId: value.connectionId,
|
|
360
|
+
limits: value.limits === void 0 || value.limits === null ? null : limitsFrom(value.limits),
|
|
361
|
+
payee: payeeFrom(value.payee),
|
|
362
|
+
client: value.client === void 0 || value.client === null ? null : clientFrom(value.client),
|
|
363
|
+
state: connectionState(value.state)
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function preparedFrom(value, identity, flow) {
|
|
315
367
|
if (record(value) && value.status === "complete" && (value.next === null || value.next === void 0)) return null;
|
|
316
368
|
if (!record(value) || !text(value.operationId) || !text(value.step, 80) || typeof value.summary !== "string" || value.summary.length > 300 || !record(value.publicKey)) malformed();
|
|
317
369
|
const options = value.publicKey;
|
|
@@ -333,7 +385,8 @@ function preparedFrom(value, identity) {
|
|
|
333
385
|
summary: value.summary,
|
|
334
386
|
statement: text(value.statement, 1e3) ? value.statement : null,
|
|
335
387
|
stepsRemaining: typeof remaining === "number" && Number.isInteger(remaining) && remaining >= 0 ? remaining : null,
|
|
336
|
-
details: detailsFrom(value.details),
|
|
388
|
+
details: flow === "connection" ? null : detailsFrom(value.details),
|
|
389
|
+
connection: flow === "connection" ? connectionDetailsFrom(value.details) : null,
|
|
337
390
|
publicKey: Object.freeze({
|
|
338
391
|
challenge: options.challenge,
|
|
339
392
|
rpId: DEXTER_RP_ID,
|
|
@@ -350,12 +403,13 @@ function assertApprovalContext() {
|
|
|
350
403
|
if (!browserSupportsWebAuthn()) throw new ConnectError("webauthn_unsupported");
|
|
351
404
|
}
|
|
352
405
|
var approvalInProgress = false;
|
|
353
|
-
async function prepare(config,
|
|
406
|
+
async function prepare(config, route, body) {
|
|
354
407
|
for (let attempt = 0; ; attempt += 1) {
|
|
355
408
|
try {
|
|
356
409
|
return preparedFrom(
|
|
357
|
-
await call(config.identity, "POST",
|
|
358
|
-
config.identity
|
|
410
|
+
await call(config.identity, "POST", route.prepare, body, false, config.signal),
|
|
411
|
+
config.identity,
|
|
412
|
+
route.flow
|
|
359
413
|
);
|
|
360
414
|
} catch (cause) {
|
|
361
415
|
if (!(cause instanceof ConnectError) || cause.code !== "chain_not_ready" || attempt >= NOT_READY_RETRIES) throw cause;
|
|
@@ -363,20 +417,31 @@ async function prepare(config, flow, body) {
|
|
|
363
417
|
}
|
|
364
418
|
}
|
|
365
419
|
}
|
|
366
|
-
async function complete(config,
|
|
420
|
+
async function complete(config, route, body) {
|
|
367
421
|
try {
|
|
368
|
-
return await call(config.identity, "POST",
|
|
422
|
+
return await call(config.identity, "POST", route.complete, body, true);
|
|
369
423
|
} catch (cause) {
|
|
370
424
|
if (!(cause instanceof ConnectError) || cause.code !== "account_operation_uncertain") throw cause;
|
|
371
|
-
return call(config.identity, "POST",
|
|
425
|
+
return call(config.identity, "POST", route.complete, body, true);
|
|
372
426
|
}
|
|
373
427
|
}
|
|
428
|
+
function outcomeFrom(value) {
|
|
429
|
+
const outcome = {};
|
|
430
|
+
for (const key of ["connectionId", "state", "redirectUrl"]) {
|
|
431
|
+
if (text(value[key], 2048)) outcome[key] = value[key];
|
|
432
|
+
}
|
|
433
|
+
return Object.freeze(outcome);
|
|
434
|
+
}
|
|
374
435
|
function confirmedFrom(value, flow) {
|
|
375
436
|
if (!record(value) || value.status !== "confirmed") malformed();
|
|
376
437
|
const held = flow === "setup" && (value.signature === null || value.signature === void 0);
|
|
377
438
|
if (!held && !text(value.signature)) malformed();
|
|
378
439
|
if (value.next !== null && value.next !== void 0 && !text(value.next, 80)) malformed();
|
|
379
|
-
return {
|
|
440
|
+
return {
|
|
441
|
+
signature: held ? null : value.signature,
|
|
442
|
+
next: value.next ?? null,
|
|
443
|
+
outcome: outcomeFrom(value)
|
|
444
|
+
};
|
|
380
445
|
}
|
|
381
446
|
async function settle(config, flow, step, operationId, cause) {
|
|
382
447
|
let state;
|
|
@@ -385,13 +450,16 @@ async function settle(config, flow, step, operationId, cause) {
|
|
|
385
450
|
} catch {
|
|
386
451
|
throw new AccountOperationUnsettledError(operationId, flow, step);
|
|
387
452
|
}
|
|
388
|
-
if (state.status === "confirmed" && (state.signature || flow === "setup"))
|
|
453
|
+
if (state.status === "confirmed" && (state.signature || flow === "setup")) {
|
|
454
|
+
return { signature: state.signature, next: state.next, outcome: state.outcome };
|
|
455
|
+
}
|
|
389
456
|
if (state.status === "failed" || state.status === "prepared" || state.status === "expired") {
|
|
390
457
|
throw cause instanceof ConnectError && cause.code !== "account_operation_uncertain" ? cause : new ConnectError("account_operation_failed");
|
|
391
458
|
}
|
|
392
459
|
throw new AccountOperationUnsettledError(operationId, flow, step);
|
|
393
460
|
}
|
|
394
|
-
async function runFlow(config,
|
|
461
|
+
async function runFlow(config, route, body, check) {
|
|
462
|
+
const { flow } = route;
|
|
395
463
|
assertApprovalContext();
|
|
396
464
|
if (approvalInProgress) throw new ConnectError("account_operation_in_progress");
|
|
397
465
|
approvalInProgress = true;
|
|
@@ -399,15 +467,16 @@ async function runFlow(config, flow, body, check) {
|
|
|
399
467
|
try {
|
|
400
468
|
for (let count = 0; count < MAX_STEPS; count += 1) {
|
|
401
469
|
cancelled(config.signal);
|
|
402
|
-
const prepared = await prepare(config,
|
|
403
|
-
if (prepared === null) return Object.freeze({ signatures: Object.freeze(signatures) });
|
|
404
|
-
check?.(prepared.step, prepared.details);
|
|
470
|
+
const prepared = await prepare(config, route, body);
|
|
471
|
+
if (prepared === null) return Object.freeze({ signatures: Object.freeze(signatures), outcome: Object.freeze({}) });
|
|
472
|
+
check?.(prepared.step, { details: prepared.details, connection: prepared.connection });
|
|
405
473
|
const view = {
|
|
406
474
|
step: prepared.step,
|
|
407
475
|
summary: prepared.summary,
|
|
408
476
|
statement: prepared.statement,
|
|
409
477
|
stepsRemaining: prepared.stepsRemaining,
|
|
410
478
|
details: prepared.details,
|
|
479
|
+
connection: prepared.connection,
|
|
411
480
|
signature: null
|
|
412
481
|
};
|
|
413
482
|
if (config.confirmStep) {
|
|
@@ -433,7 +502,7 @@ async function runFlow(config, flow, body, check) {
|
|
|
433
502
|
config.onStep?.({ ...view, phase: "sending" });
|
|
434
503
|
let result;
|
|
435
504
|
try {
|
|
436
|
-
result = confirmedFrom(await complete(config,
|
|
505
|
+
result = confirmedFrom(await complete(config, route, {
|
|
437
506
|
operationId: prepared.operationId,
|
|
438
507
|
assertion: {
|
|
439
508
|
credentialId: credential.id,
|
|
@@ -449,13 +518,14 @@ async function runFlow(config, flow, body, check) {
|
|
|
449
518
|
if (result.signature) signatures.push(result.signature);
|
|
450
519
|
config.onStep?.({ ...view, phase: "confirmed", signature: result.signature });
|
|
451
520
|
const next = result.next;
|
|
452
|
-
if (next === null) return Object.freeze({ signatures: Object.freeze(signatures) });
|
|
521
|
+
if (next === null) return Object.freeze({ signatures: Object.freeze(signatures), outcome: result.outcome });
|
|
453
522
|
config.onStep?.({
|
|
454
523
|
step: next,
|
|
455
524
|
summary: "",
|
|
456
525
|
statement: null,
|
|
457
526
|
stepsRemaining: null,
|
|
458
527
|
details: null,
|
|
528
|
+
connection: null,
|
|
459
529
|
signature: null,
|
|
460
530
|
phase: "preparing"
|
|
461
531
|
});
|
|
@@ -477,21 +547,22 @@ async function getAccountOverview(config) {
|
|
|
477
547
|
const created = record(raw) && text(raw.createdAt, 40) && !Number.isNaN(Date.parse(raw.createdAt)) ? raw.createdAt : null;
|
|
478
548
|
const passkey = record(raw) ? Object.freeze({ name: text(raw.name, 80) ? raw.name : null, createdAt: created }) : null;
|
|
479
549
|
const pending = body.unsettled;
|
|
480
|
-
const unsettled = record(pending) && text(pending.operationId) && (pending.flow
|
|
550
|
+
const unsettled = record(pending) && text(pending.operationId) && isFlowName(pending.flow) && text(pending.step, 80) ? Object.freeze({ operationId: pending.operationId, flow: pending.flow, step: pending.step }) : null;
|
|
481
551
|
return Object.freeze({ account, network, passkey, unsettled });
|
|
482
552
|
}
|
|
483
553
|
async function getAccountOperation(config) {
|
|
484
554
|
if (!text(config.operationId) || !/^[A-Za-z0-9_-]+$/.test(config.operationId)) throw new ConnectError("invalid_account_operation");
|
|
485
555
|
const value = await call(config.identity, "GET", `/operations/${config.operationId}`, void 0, false, config.signal);
|
|
486
556
|
const statuses = ["prepared", "sending", "confirmed", "failed", "expired"];
|
|
487
|
-
if (!record(value) || value.operationId !== config.operationId || value.flow
|
|
557
|
+
if (!record(value) || value.operationId !== config.operationId || !isFlowName(value.flow) || !text(value.step, 80) || typeof value.status !== "string" || !statuses.includes(value.status) || value.signature !== null && value.signature !== void 0 && !text(value.signature) || value.next !== null && value.next !== void 0 && !text(value.next, 80) || value.status === "confirmed" && value.flow !== "setup" && !text(value.signature)) malformed();
|
|
488
558
|
return Object.freeze({
|
|
489
559
|
operationId: value.operationId,
|
|
490
560
|
flow: value.flow,
|
|
491
561
|
step: value.step,
|
|
492
562
|
status: value.status,
|
|
493
563
|
signature: value.signature ?? null,
|
|
494
|
-
next: value.next ?? null
|
|
564
|
+
next: value.next ?? null,
|
|
565
|
+
outcome: outcomeFrom(value)
|
|
495
566
|
});
|
|
496
567
|
}
|
|
497
568
|
async function getAccountBalances(config) {
|
|
@@ -523,10 +594,11 @@ async function openAccount(config) {
|
|
|
523
594
|
statement: null,
|
|
524
595
|
stepsRemaining: null,
|
|
525
596
|
details: null,
|
|
597
|
+
connection: null,
|
|
526
598
|
signature: null,
|
|
527
599
|
phase: "preparing"
|
|
528
600
|
});
|
|
529
|
-
await runFlow(config,
|
|
601
|
+
await runFlow(config, SETUP_ROUTE, {});
|
|
530
602
|
const account = await getAccount(config);
|
|
531
603
|
if (!account) malformed();
|
|
532
604
|
return account;
|
|
@@ -537,7 +609,7 @@ async function sendFromAccount(config) {
|
|
|
537
609
|
throw new ConnectError("invalid_account_send");
|
|
538
610
|
}
|
|
539
611
|
const request = { mint: send.mint, amount: send.amount, to: send.to };
|
|
540
|
-
return runFlow(config,
|
|
612
|
+
return runFlow(config, SEND_ROUTE, request, (step, { details }) => {
|
|
541
613
|
const sameToken = details !== null && details.mint === request.mint;
|
|
542
614
|
if (step === "prepare-token" ? !sameToken || details.amount !== null || details.to !== null : !sameToken || details.amount !== request.amount || details.to !== request.to) {
|
|
543
615
|
throw new ConnectError("account_operation_mismatch");
|
|
@@ -562,6 +634,196 @@ function parseAccountAmount(input, decimals) {
|
|
|
562
634
|
const value = BigInt(`${match[1] || "0"}${fraction.padEnd(decimals, "0")}`);
|
|
563
635
|
return value > 0n && value < 1n << 64n ? value.toString() : null;
|
|
564
636
|
}
|
|
637
|
+
function connectionFrom(value) {
|
|
638
|
+
if (!record(value) || !connectionKey(value.connectionId)) malformed();
|
|
639
|
+
const state = connectionState(value.state);
|
|
640
|
+
if (state === null) malformed();
|
|
641
|
+
return Object.freeze({
|
|
642
|
+
connectionId: value.connectionId,
|
|
643
|
+
client: clientFrom(value.client),
|
|
644
|
+
limits: limitsFrom(value.limits),
|
|
645
|
+
spent30Days: value.spent30Days === null || value.spent30Days === void 0 ? null : amountFrom(value.spent30Days),
|
|
646
|
+
state,
|
|
647
|
+
createdAt: time(value.createdAt),
|
|
648
|
+
stoppedAt: time(value.stoppedAt),
|
|
649
|
+
revokedAt: time(value.revokedAt)
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
async function getConnectionRequest(config) {
|
|
653
|
+
if (!connectionKey(config.requestId)) throw new ConnectError("invalid_connection_request");
|
|
654
|
+
const value = await call(config.identity, "GET", `/connections/requests/${config.requestId}`, void 0, false, config.signal);
|
|
655
|
+
if (!record(value) || value.requestId !== config.requestId || !text(value.scope, 80)) malformed();
|
|
656
|
+
return Object.freeze({
|
|
657
|
+
requestId: value.requestId,
|
|
658
|
+
client: clientFrom(value.client),
|
|
659
|
+
scope: value.scope,
|
|
660
|
+
limits: limitsFrom(value.limits),
|
|
661
|
+
payee: payeeFrom(value.payee),
|
|
662
|
+
expiresAt: time(value.expiresAt)
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
async function listConnections(config) {
|
|
666
|
+
const value = await call(config.identity, "GET", "/connections", void 0, false, config.signal);
|
|
667
|
+
if (!record(value) || !Array.isArray(value.connections)) malformed();
|
|
668
|
+
return Object.freeze(value.connections.map(connectionFrom));
|
|
669
|
+
}
|
|
670
|
+
async function getConnection(config) {
|
|
671
|
+
if (!connectionKey(config.connectionId)) throw new ConnectError("invalid_connection");
|
|
672
|
+
const value = connectionFrom(await call(config.identity, "GET", `/connections/${config.connectionId}`, void 0, false, config.signal));
|
|
673
|
+
if (value.connectionId !== config.connectionId) malformed();
|
|
674
|
+
return value;
|
|
675
|
+
}
|
|
676
|
+
function termsFrom(terms) {
|
|
677
|
+
if (!record(terms) || !units(terms.perPayment) || !units(terms.per30Days) || BigInt(terms.perPayment) <= 0n || BigInt(terms.per30Days) <= 0n || BigInt(terms.perPayment) > BigInt(terms.per30Days)) {
|
|
678
|
+
throw new ConnectError("invalid_connection_limits");
|
|
679
|
+
}
|
|
680
|
+
let endsAt = null;
|
|
681
|
+
if (terms.endsAt !== null) {
|
|
682
|
+
const at = typeof terms.endsAt === "string" ? Date.parse(terms.endsAt) : Number.NaN;
|
|
683
|
+
if (Number.isNaN(at) || at <= Date.now()) throw new ConnectError("invalid_connection_limits");
|
|
684
|
+
endsAt = new Date(at).toISOString();
|
|
685
|
+
}
|
|
686
|
+
return Object.freeze({ perPayment: terms.perPayment, per30Days: terms.per30Days, endsAt });
|
|
687
|
+
}
|
|
688
|
+
var sameEnd = (a, b) => a === null || b === null ? a === b : Date.parse(a) === Date.parse(b);
|
|
689
|
+
async function grantConnection(config) {
|
|
690
|
+
const { request } = config;
|
|
691
|
+
if (!record(request) || !connectionKey(request.requestId) || !record(request.client) || !hostName(request.client.host) || !record(request.limits)) {
|
|
692
|
+
throw new ConnectError("invalid_connection_request");
|
|
693
|
+
}
|
|
694
|
+
const mint = request.limits.perPayment.mint;
|
|
695
|
+
const terms = termsFrom(config.terms ?? {
|
|
696
|
+
perPayment: request.limits.perPayment.amount,
|
|
697
|
+
per30Days: request.limits.per30Days.amount,
|
|
698
|
+
endsAt: request.limits.endsAt
|
|
699
|
+
});
|
|
700
|
+
let promised = null;
|
|
701
|
+
const result = await runFlow(
|
|
702
|
+
config,
|
|
703
|
+
{ flow: "connection", prepare: "/connections/grant/prepare", complete: "/connections/grant/complete" },
|
|
704
|
+
{ requestId: request.requestId, limits: {
|
|
705
|
+
perPayment: { amount: terms.perPayment },
|
|
706
|
+
per30Days: { amount: terms.per30Days },
|
|
707
|
+
endsAt: terms.endsAt
|
|
708
|
+
} },
|
|
709
|
+
(step, { connection }) => {
|
|
710
|
+
if (step !== "grant-permission" || connection === null || promised !== null && connection.connectionId !== promised) {
|
|
711
|
+
throw new ConnectError("account_operation_mismatch");
|
|
712
|
+
}
|
|
713
|
+
const limits = connection.limits;
|
|
714
|
+
if (limits === null || limits.perPayment.mint !== mint || limits.per30Days.mint !== mint || limits.perPayment.amount !== terms.perPayment || limits.per30Days.amount !== terms.per30Days || !sameEnd(limits.endsAt, terms.endsAt)) {
|
|
715
|
+
throw new ConnectError("account_operation_mismatch");
|
|
716
|
+
}
|
|
717
|
+
promised = connection.connectionId;
|
|
718
|
+
}
|
|
719
|
+
);
|
|
720
|
+
const connectionId = result.outcome.connectionId;
|
|
721
|
+
const redirectUrl = result.outcome.redirectUrl;
|
|
722
|
+
if (!connectionKey(connectionId) || promised !== null && connectionId !== promised || !text(redirectUrl, 2048)) malformed();
|
|
723
|
+
let target;
|
|
724
|
+
try {
|
|
725
|
+
target = new URL(redirectUrl);
|
|
726
|
+
} catch {
|
|
727
|
+
throw new ConnectError("connection_redirect_refused");
|
|
728
|
+
}
|
|
729
|
+
if (target.protocol !== "https:" || target.host.toLowerCase() !== request.client.host.toLowerCase()) {
|
|
730
|
+
throw new ConnectError("connection_redirect_refused");
|
|
731
|
+
}
|
|
732
|
+
return Object.freeze({ ...result, connectionId, redirectUrl: target.toString() });
|
|
733
|
+
}
|
|
734
|
+
async function revokeConnection(config) {
|
|
735
|
+
const { connectionId } = config;
|
|
736
|
+
if (!connectionKey(connectionId)) throw new ConnectError("invalid_connection");
|
|
737
|
+
const result = await runFlow(
|
|
738
|
+
config,
|
|
739
|
+
{ flow: "connection", prepare: `/connections/${connectionId}/revoke/prepare`, complete: "/connections/revoke/complete" },
|
|
740
|
+
{},
|
|
741
|
+
(step, { connection }) => {
|
|
742
|
+
if (step !== "revoke-permission" || connection?.connectionId !== connectionId) {
|
|
743
|
+
throw new ConnectError("account_operation_mismatch");
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
);
|
|
747
|
+
if (result.outcome.connectionId !== connectionId || result.outcome.state !== "revoked") malformed();
|
|
748
|
+
return Object.freeze({ ...result, state: "revoked" });
|
|
749
|
+
}
|
|
750
|
+
var APPROVAL_STATES = ["waiting", "approved", "declined", "expired"];
|
|
751
|
+
function approvalFrom(value, connectionId, approvalId) {
|
|
752
|
+
if (!record(value) || value.approvalId !== approvalId || value.connectionId !== void 0 && value.connectionId !== connectionId || value.kind !== "payment" && value.kind !== "budget" || !APPROVAL_STATES.includes(value.state)) malformed();
|
|
753
|
+
let payee = null;
|
|
754
|
+
if (value.payee !== null && value.payee !== void 0) {
|
|
755
|
+
const p = value.payee;
|
|
756
|
+
if (!record(p) || !address(p.address) || p.host !== null && p.host !== void 0 && !hostName(p.host) || p.name !== null && p.name !== void 0 && !text(p.name, 80)) malformed();
|
|
757
|
+
payee = Object.freeze({
|
|
758
|
+
host: p.host ? p.host.toLowerCase() : null,
|
|
759
|
+
name: p.name ?? null,
|
|
760
|
+
address: p.address
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
const amount = amountFrom(value.amount);
|
|
764
|
+
const newBudget = value.newBudget === null || value.newBudget === void 0 ? null : amountFrom(value.newBudget);
|
|
765
|
+
if (newBudget !== null && newBudget.mint !== amount.mint) malformed();
|
|
766
|
+
return Object.freeze({
|
|
767
|
+
approvalId,
|
|
768
|
+
connectionId,
|
|
769
|
+
kind: value.kind,
|
|
770
|
+
amount,
|
|
771
|
+
payee,
|
|
772
|
+
newBudget,
|
|
773
|
+
expiresAt: time(value.expiresAt),
|
|
774
|
+
state: value.state
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
async function getConnectionApproval(config) {
|
|
778
|
+
const { connectionId, approvalId } = config;
|
|
779
|
+
if (!connectionKey(connectionId) || !connectionKey(approvalId)) throw new ConnectError("invalid_connection_approval");
|
|
780
|
+
return approvalFrom(await call(
|
|
781
|
+
config.identity,
|
|
782
|
+
"GET",
|
|
783
|
+
`/connections/${connectionId}/approvals/${approvalId}`,
|
|
784
|
+
void 0,
|
|
785
|
+
false,
|
|
786
|
+
config.signal
|
|
787
|
+
), connectionId, approvalId);
|
|
788
|
+
}
|
|
789
|
+
async function approveConnectionPayment(config) {
|
|
790
|
+
const { connectionId, approvalId, per30Days } = config;
|
|
791
|
+
if (!connectionKey(connectionId) || !connectionKey(approvalId)) throw new ConnectError("invalid_connection_approval");
|
|
792
|
+
if (per30Days !== void 0 && (!units(per30Days) || BigInt(per30Days) <= 0n)) throw new ConnectError("invalid_connection_limits");
|
|
793
|
+
const result = await runFlow(
|
|
794
|
+
config,
|
|
795
|
+
{
|
|
796
|
+
flow: "connection",
|
|
797
|
+
prepare: `/connections/${connectionId}/approvals/${approvalId}/prepare`,
|
|
798
|
+
complete: "/connections/approvals/complete"
|
|
799
|
+
},
|
|
800
|
+
per30Days === void 0 ? { decision: "approve" } : { decision: "approve", per30Days: { amount: per30Days } },
|
|
801
|
+
(step, { connection }) => {
|
|
802
|
+
if (step !== "approve-payment" && step !== "raise-budget" || connection?.connectionId !== connectionId) {
|
|
803
|
+
throw new ConnectError("account_operation_mismatch");
|
|
804
|
+
}
|
|
805
|
+
if (step === "raise-budget" && per30Days !== void 0 && connection.limits?.per30Days.amount !== per30Days) {
|
|
806
|
+
throw new ConnectError("account_operation_mismatch");
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
);
|
|
810
|
+
if (result.outcome.connectionId !== void 0 && result.outcome.connectionId !== connectionId) malformed();
|
|
811
|
+
return Object.freeze({ ...result, approvalId });
|
|
812
|
+
}
|
|
813
|
+
async function declineConnectionPayment(config) {
|
|
814
|
+
const { connectionId, approvalId } = config;
|
|
815
|
+
if (!connectionKey(connectionId) || !connectionKey(approvalId)) throw new ConnectError("invalid_connection_approval");
|
|
816
|
+
const value = await call(
|
|
817
|
+
config.identity,
|
|
818
|
+
"POST",
|
|
819
|
+
`/connections/${connectionId}/approvals/${approvalId}/decline`,
|
|
820
|
+
{},
|
|
821
|
+
false,
|
|
822
|
+
config.signal
|
|
823
|
+
);
|
|
824
|
+
if (!record(value) || value.state !== "declined") malformed();
|
|
825
|
+
return Object.freeze({ state: "declined" });
|
|
826
|
+
}
|
|
565
827
|
|
|
566
828
|
// src/agentSpend.ts
|
|
567
829
|
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
@@ -1344,6 +1606,7 @@ export {
|
|
|
1344
1606
|
X402_PROTOCOL_ID,
|
|
1345
1607
|
X402_PROTOCOL_VERSION,
|
|
1346
1608
|
accountBindingCandidate,
|
|
1609
|
+
approveConnectionPayment,
|
|
1347
1610
|
assembleAgentSpendStatus,
|
|
1348
1611
|
authoredPolicy,
|
|
1349
1612
|
beginAgentAuthority,
|
|
@@ -1353,6 +1616,7 @@ export {
|
|
|
1353
1616
|
buildX402PaymentRule,
|
|
1354
1617
|
ceremonyPhaseLabel,
|
|
1355
1618
|
connectDexterIdentity,
|
|
1619
|
+
connectionClientLabel,
|
|
1356
1620
|
createAnonServerPolicy,
|
|
1357
1621
|
createDexterControlModel,
|
|
1358
1622
|
createDexterIdentityCoordinator,
|
|
@@ -1360,6 +1624,7 @@ export {
|
|
|
1360
1624
|
createWallet,
|
|
1361
1625
|
createWalletAccountBindingClient,
|
|
1362
1626
|
createWalletProofSessionStore,
|
|
1627
|
+
declineConnectionPayment,
|
|
1363
1628
|
describeAgentSpendError,
|
|
1364
1629
|
disconnectDexterIdentity,
|
|
1365
1630
|
enableAgentSpend,
|
|
@@ -1373,6 +1638,11 @@ export {
|
|
|
1373
1638
|
getAccountBalances,
|
|
1374
1639
|
getAccountOperation,
|
|
1375
1640
|
getAccountOverview,
|
|
1641
|
+
getConnection,
|
|
1642
|
+
getConnectionApproval,
|
|
1643
|
+
getConnectionRequest,
|
|
1644
|
+
grantConnection,
|
|
1645
|
+
listConnections,
|
|
1376
1646
|
noCustomX402Limits,
|
|
1377
1647
|
openAccount,
|
|
1378
1648
|
parseAccountAmount,
|
|
@@ -1383,6 +1653,7 @@ export {
|
|
|
1383
1653
|
recoverWallet,
|
|
1384
1654
|
renamePasskey,
|
|
1385
1655
|
revokeAgentSpend,
|
|
1656
|
+
revokeConnection,
|
|
1386
1657
|
sendFromAccount,
|
|
1387
1658
|
signAccountChallenge,
|
|
1388
1659
|
signInAccountAccess,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexterai/connect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Connect apps and agents to a self-custodial Dexter Wallet with passkey identity, governed authority, hosted signing, and verifiable sessions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|