@dexterai/connect 0.36.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 +19 -6
- package/dist/index.d.ts +74 -11
- package/dist/index.js +131 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,20 +97,33 @@ await sendFromAccount({ identity, send: { mint, amount: '2500000', to } });
|
|
|
97
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
98
|
|
|
99
99
|
```ts
|
|
100
|
-
import {
|
|
100
|
+
import {
|
|
101
|
+
getConnectionRequest, grantConnection, connectionClientLabel, listConnections, revokeConnection,
|
|
102
|
+
getConnectionApproval, approveConnectionPayment, declineConnectionPayment,
|
|
103
|
+
} from '@dexterai/connect';
|
|
101
104
|
|
|
102
|
-
const review = await getConnectionRequest({ identity, requestId }); // client, limits, payee
|
|
103
|
-
const
|
|
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
|
|
105
110
|
|
|
106
111
|
const connections = await listConnections({ identity });
|
|
107
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 });
|
|
108
118
|
```
|
|
109
119
|
|
|
110
|
-
- The
|
|
111
|
-
-
|
|
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.
|
|
112
124
|
- A connection is `pending` (an approval that didn't finish; stop it to abandon it), `active`, `stopped` or `revoked`.
|
|
113
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.
|
|
114
127
|
- A lost reply leaves the step unsettled with `flow: 'connection'`, the same as a send.
|
|
115
128
|
|
|
116
129
|
## Interrupted wallet setup
|
package/dist/index.d.ts
CHANGED
|
@@ -162,14 +162,25 @@ interface AccountAmount {
|
|
|
162
162
|
readonly decimals: number;
|
|
163
163
|
readonly symbol: string | null;
|
|
164
164
|
}
|
|
165
|
-
/**
|
|
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
|
+
*/
|
|
166
169
|
interface AccountConnectionLimits {
|
|
167
170
|
readonly perPayment: AccountAmount;
|
|
171
|
+
/** Refills: what the agent spent more than 30 days ago no longer counts. */
|
|
168
172
|
readonly per30Days: AccountAmount;
|
|
169
|
-
|
|
173
|
+
/** `null`: until the owner stops it. */
|
|
174
|
+
readonly endsAt: string | null;
|
|
170
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
|
+
*/
|
|
171
180
|
interface AccountConnectionClient {
|
|
172
|
-
readonly
|
|
181
|
+
readonly host: string;
|
|
182
|
+
readonly verified: boolean;
|
|
183
|
+
readonly name: string | null;
|
|
173
184
|
readonly kind: 'chatgpt' | 'claude' | 'other';
|
|
174
185
|
}
|
|
175
186
|
/** What a connection approval or stop is about, as the API prepared it. */
|
|
@@ -246,6 +257,8 @@ declare class AccountOperationUnsettledError extends ConnectError {
|
|
|
246
257
|
readonly step: string;
|
|
247
258
|
constructor(operationId: string, flow: AccountFlowName, step: string);
|
|
248
259
|
}
|
|
260
|
+
/** How a page names the app: the verified name, or else the host itself. */
|
|
261
|
+
declare function connectionClientLabel(client: AccountConnectionClient): string;
|
|
249
262
|
/** Read the signed-in owner's Account, or `null` when none is open yet. */
|
|
250
263
|
declare function getAccount(config: Pick<AccountOperationConfig, 'identity' | 'signal'>): Promise<DexterAccount | null>;
|
|
251
264
|
/**
|
|
@@ -281,10 +294,10 @@ declare function parseAccountAmount(input: string, decimals: number): string | n
|
|
|
281
294
|
/** An OAuth request for an agent connection, as the owner reviews it. */
|
|
282
295
|
interface AccountConnectionReview {
|
|
283
296
|
readonly requestId: string;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
};
|
|
297
|
+
/** `client.host` is where the person goes back to after approving. */
|
|
298
|
+
readonly client: AccountConnectionClient;
|
|
287
299
|
readonly scope: string;
|
|
300
|
+
/** The starting figures. The owner may change them; see grantConnection. */
|
|
288
301
|
readonly limits: AccountConnectionLimits;
|
|
289
302
|
readonly payee: AccountConnectionDetails['payee'];
|
|
290
303
|
readonly expiresAt: string | null;
|
|
@@ -314,13 +327,22 @@ declare function listConnections(config: Pick<AccountOperationConfig, 'identity'
|
|
|
314
327
|
declare function getConnection(config: Pick<AccountOperationConfig, 'identity' | 'signal'> & {
|
|
315
328
|
readonly connectionId: string;
|
|
316
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
|
+
}
|
|
317
337
|
/**
|
|
318
|
-
* Approve an agent's spending permission with the owner's passkey
|
|
319
|
-
*
|
|
320
|
-
*
|
|
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.
|
|
321
342
|
*/
|
|
322
343
|
declare function grantConnection(config: AccountOperationConfig & {
|
|
323
|
-
readonly request: Pick<AccountConnectionReview, 'requestId' | 'client'>;
|
|
344
|
+
readonly request: Pick<AccountConnectionReview, 'requestId' | 'client' | 'limits'>;
|
|
345
|
+
readonly terms?: AccountConnectionTerms;
|
|
324
346
|
}): Promise<AccountFlowResult & {
|
|
325
347
|
readonly connectionId: string;
|
|
326
348
|
readonly redirectUrl: string;
|
|
@@ -334,6 +356,47 @@ declare function revokeConnection(config: AccountOperationConfig & {
|
|
|
334
356
|
}): Promise<AccountFlowResult & {
|
|
335
357
|
readonly state: 'revoked';
|
|
336
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
|
+
}>;
|
|
337
400
|
|
|
338
401
|
/** One localStorage entry per Wallet keeps inactive Wallet proofs independent. */
|
|
339
402
|
declare const WALLET_PROOF_SESSION_STORAGE_PREFIX: "dexter:wallet-identity-proof-session:";
|
|
@@ -954,4 +1017,4 @@ type SignAccountChallengeResult = {
|
|
|
954
1017
|
};
|
|
955
1018
|
declare function signAccountChallenge(config: SignAccountChallengeConfig): Promise<SignAccountChallengeResult>;
|
|
956
1019
|
|
|
957
|
-
export { ACCOUNT_API_PATH, AGENT_AUTHORITY_NAMESPACE, AGENT_AUTHORITY_STATUS_NAMESPACE, type AccountAmount, type AccountBalances, type AccountChallengeAssertion, type AccountConnection, type AccountConnectionClient, type AccountConnectionDetails, type AccountConnectionLimits, type AccountConnectionRequest, type AccountConnectionReview, 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, assembleAgentSpendStatus, beginAgentAuthority, beginBoundedX402Authority, buildAgentAuthorityRequest, buildBoundedX402BootstrapRequest, buildX402PaymentRule, ceremonyPhaseLabel, createAnonServerPolicy, createDexterIdentityCoordinator, createPasskeySigner, createWalletProofSessionStore, describeAgentSpendError, enableAgentSpend, exactAgentAuthorityApprovalRedirect, exactBoundedX402ApprovalRedirect, formatAccountAmount, getAccount, getAccountBalances, getAccountOperation, getAccountOverview, getConnection, getConnectionRequest, grantConnection, listConnections, noCustomX402Limits, openAccount, parseAccountAmount, passkeySignalSupport, prunePasskey, readAgentAuthority, recoverMissingVaultForAccount, recoverWallet, renamePasskey, revokeAgentSpend, revokeConnection, 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
|
@@ -325,13 +325,26 @@ function amountFrom(value) {
|
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
function limitsFrom(value) {
|
|
328
|
-
if (!record(value)
|
|
329
|
-
|
|
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 });
|
|
330
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(".");
|
|
331
338
|
function clientFrom(value) {
|
|
332
|
-
if (!record(value) || !
|
|
333
|
-
const
|
|
334
|
-
|
|
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;
|
|
335
348
|
}
|
|
336
349
|
function payeeFrom(value) {
|
|
337
350
|
if (value === null || value === void 0) return null;
|
|
@@ -621,8 +634,6 @@ function parseAccountAmount(input, decimals) {
|
|
|
621
634
|
const value = BigInt(`${match[1] || "0"}${fraction.padEnd(decimals, "0")}`);
|
|
622
635
|
return value > 0n && value < 1n << 64n ? value.toString() : null;
|
|
623
636
|
}
|
|
624
|
-
var hostName = (value) => typeof value === "string" && /^[a-z0-9.-]{1,253}(:[0-9]{1,5})?$/i.test(value);
|
|
625
|
-
var time = (value) => text(value, 40) && !Number.isNaN(Date.parse(value)) ? value : null;
|
|
626
637
|
function connectionFrom(value) {
|
|
627
638
|
if (!record(value) || !connectionKey(value.connectionId)) malformed();
|
|
628
639
|
const state = connectionState(value.state);
|
|
@@ -641,10 +652,10 @@ function connectionFrom(value) {
|
|
|
641
652
|
async function getConnectionRequest(config) {
|
|
642
653
|
if (!connectionKey(config.requestId)) throw new ConnectError("invalid_connection_request");
|
|
643
654
|
const value = await call(config.identity, "GET", `/connections/requests/${config.requestId}`, void 0, false, config.signal);
|
|
644
|
-
if (!record(value) || value.requestId !== config.requestId || !
|
|
655
|
+
if (!record(value) || value.requestId !== config.requestId || !text(value.scope, 80)) malformed();
|
|
645
656
|
return Object.freeze({
|
|
646
657
|
requestId: value.requestId,
|
|
647
|
-
client:
|
|
658
|
+
client: clientFrom(value.client),
|
|
648
659
|
scope: value.scope,
|
|
649
660
|
limits: limitsFrom(value.limits),
|
|
650
661
|
payee: payeeFrom(value.payee),
|
|
@@ -662,20 +673,47 @@ async function getConnection(config) {
|
|
|
662
673
|
if (value.connectionId !== config.connectionId) malformed();
|
|
663
674
|
return value;
|
|
664
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);
|
|
665
689
|
async function grantConnection(config) {
|
|
666
690
|
const { request } = config;
|
|
667
|
-
if (!record(request) || !connectionKey(request.requestId) || !record(request.client) || !hostName(request.client.
|
|
691
|
+
if (!record(request) || !connectionKey(request.requestId) || !record(request.client) || !hostName(request.client.host) || !record(request.limits)) {
|
|
668
692
|
throw new ConnectError("invalid_connection_request");
|
|
669
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
|
+
});
|
|
670
700
|
let promised = null;
|
|
671
701
|
const result = await runFlow(
|
|
672
702
|
config,
|
|
673
703
|
{ flow: "connection", prepare: "/connections/grant/prepare", complete: "/connections/grant/complete" },
|
|
674
|
-
{ requestId: request.requestId
|
|
704
|
+
{ requestId: request.requestId, limits: {
|
|
705
|
+
perPayment: { amount: terms.perPayment },
|
|
706
|
+
per30Days: { amount: terms.per30Days },
|
|
707
|
+
endsAt: terms.endsAt
|
|
708
|
+
} },
|
|
675
709
|
(step, { connection }) => {
|
|
676
710
|
if (step !== "grant-permission" || connection === null || promised !== null && connection.connectionId !== promised) {
|
|
677
711
|
throw new ConnectError("account_operation_mismatch");
|
|
678
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
|
+
}
|
|
679
717
|
promised = connection.connectionId;
|
|
680
718
|
}
|
|
681
719
|
);
|
|
@@ -688,7 +726,7 @@ async function grantConnection(config) {
|
|
|
688
726
|
} catch {
|
|
689
727
|
throw new ConnectError("connection_redirect_refused");
|
|
690
728
|
}
|
|
691
|
-
if (target.protocol !== "https:" || target.host.toLowerCase() !== request.client.
|
|
729
|
+
if (target.protocol !== "https:" || target.host.toLowerCase() !== request.client.host.toLowerCase()) {
|
|
692
730
|
throw new ConnectError("connection_redirect_refused");
|
|
693
731
|
}
|
|
694
732
|
return Object.freeze({ ...result, connectionId, redirectUrl: target.toString() });
|
|
@@ -709,6 +747,83 @@ async function revokeConnection(config) {
|
|
|
709
747
|
if (result.outcome.connectionId !== connectionId || result.outcome.state !== "revoked") malformed();
|
|
710
748
|
return Object.freeze({ ...result, state: "revoked" });
|
|
711
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
|
+
}
|
|
712
827
|
|
|
713
828
|
// src/agentSpend.ts
|
|
714
829
|
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
@@ -1491,6 +1606,7 @@ export {
|
|
|
1491
1606
|
X402_PROTOCOL_ID,
|
|
1492
1607
|
X402_PROTOCOL_VERSION,
|
|
1493
1608
|
accountBindingCandidate,
|
|
1609
|
+
approveConnectionPayment,
|
|
1494
1610
|
assembleAgentSpendStatus,
|
|
1495
1611
|
authoredPolicy,
|
|
1496
1612
|
beginAgentAuthority,
|
|
@@ -1500,6 +1616,7 @@ export {
|
|
|
1500
1616
|
buildX402PaymentRule,
|
|
1501
1617
|
ceremonyPhaseLabel,
|
|
1502
1618
|
connectDexterIdentity,
|
|
1619
|
+
connectionClientLabel,
|
|
1503
1620
|
createAnonServerPolicy,
|
|
1504
1621
|
createDexterControlModel,
|
|
1505
1622
|
createDexterIdentityCoordinator,
|
|
@@ -1507,6 +1624,7 @@ export {
|
|
|
1507
1624
|
createWallet,
|
|
1508
1625
|
createWalletAccountBindingClient,
|
|
1509
1626
|
createWalletProofSessionStore,
|
|
1627
|
+
declineConnectionPayment,
|
|
1510
1628
|
describeAgentSpendError,
|
|
1511
1629
|
disconnectDexterIdentity,
|
|
1512
1630
|
enableAgentSpend,
|
|
@@ -1521,6 +1639,7 @@ export {
|
|
|
1521
1639
|
getAccountOperation,
|
|
1522
1640
|
getAccountOverview,
|
|
1523
1641
|
getConnection,
|
|
1642
|
+
getConnectionApproval,
|
|
1524
1643
|
getConnectionRequest,
|
|
1525
1644
|
grantConnection,
|
|
1526
1645
|
listConnections,
|
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",
|