@vapi-network/core 0.2.3 → 0.5.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 +18 -5
- package/dist/accounts.d.ts.map +1 -1
- package/dist/agent-guard.d.ts +40 -0
- package/dist/agent-guard.d.ts.map +1 -0
- package/dist/agent-link.d.ts +98 -0
- package/dist/agent-link.d.ts.map +1 -0
- package/dist/agent-link.js +1715 -0
- package/dist/agent-link.js.map +6 -0
- package/dist/agent-profile.d.ts +27 -0
- package/dist/agent-profile.d.ts.map +1 -0
- package/dist/api-key.d.ts +99 -0
- package/dist/api-key.d.ts.map +1 -0
- package/dist/api-key.js +20084 -0
- package/dist/api-key.js.map +6 -0
- package/dist/audit.d.ts +44 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/authorization-state.d.ts +58 -0
- package/dist/authorization-state.d.ts.map +1 -0
- package/dist/call-contracts-wire.d.ts +151 -11
- package/dist/call-contracts-wire.d.ts.map +1 -1
- package/dist/config.d.ts +10 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/discovery.d.ts +20 -2
- package/dist/discovery.d.ts.map +1 -1
- package/dist/hd.d.ts +33 -0
- package/dist/hd.d.ts.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25354 -954
- package/dist/index.js.map +3 -3
- package/dist/keystore.d.ts +94 -4
- package/dist/keystore.d.ts.map +1 -1
- package/dist/marketplace-contracts.d.ts +448 -15
- package/dist/marketplace-contracts.d.ts.map +1 -1
- package/dist/networks.d.ts +16 -2
- package/dist/networks.d.ts.map +1 -1
- package/dist/onramp.d.ts +12 -28
- package/dist/onramp.d.ts.map +1 -1
- package/dist/passphrase.d.ts +47 -0
- package/dist/passphrase.d.ts.map +1 -0
- package/dist/policy.d.ts +6 -0
- package/dist/policy.d.ts.map +1 -1
- package/dist/receipts.d.ts +40 -4
- package/dist/receipts.d.ts.map +1 -1
- package/dist/router-client.d.ts +117 -0
- package/dist/router-client.d.ts.map +1 -0
- package/dist/router-client.js +27421 -0
- package/dist/router-client.js.map +6 -0
- package/dist/secret-store.d.ts +60 -0
- package/dist/secret-store.d.ts.map +1 -0
- package/dist/secrets.d.ts +14 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +47238 -0
- package/dist/secrets.js.map +6 -0
- package/dist/spend-policy.d.ts +13 -1
- package/dist/spend-policy.d.ts.map +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.d.ts.map +1 -1
- package/dist/support-report.d.ts +1 -1
- package/dist/sweep.d.ts +4 -0
- package/dist/sweep.d.ts.map +1 -1
- package/dist/wallet-name.d.ts +18 -0
- package/dist/wallet-name.d.ts.map +1 -0
- package/dist/wallet-store.d.ts +220 -0
- package/dist/wallet-store.d.ts.map +1 -0
- package/dist/wallet.d.ts +0 -5
- package/dist/wallet.d.ts.map +1 -1
- package/dist/x402-networks.d.ts +6 -9
- package/dist/x402-networks.d.ts.map +1 -1
- package/dist/x402-pay.d.ts +131 -0
- package/dist/x402-pay.d.ts.map +1 -0
- package/dist/x402.d.ts +20 -1
- package/dist/x402.d.ts.map +1 -1
- package/package.json +17 -1
package/dist/spend-policy.d.ts
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type SpendCaps } from "./config.js";
|
|
3
|
+
import { type WalletName } from "./wallet-name.js";
|
|
3
4
|
declare const ledgerSchema: z.ZodObject<{
|
|
4
5
|
date: z.ZodString;
|
|
5
6
|
spentAtomic: z.ZodString;
|
|
6
7
|
}, z.core.$strip>;
|
|
7
8
|
export type SpendLedger = z.infer<typeof ledgerSchema>;
|
|
9
|
+
export type SpendLedgerRow = SpendLedger & {
|
|
10
|
+
wallet: WalletName;
|
|
11
|
+
};
|
|
8
12
|
export declare class SpendCapError extends Error {
|
|
9
13
|
readonly code: "per_call_cap_exceeded" | "per_day_cap_exceeded";
|
|
10
14
|
constructor(code: "per_call_cap_exceeded" | "per_day_cap_exceeded", message: string);
|
|
11
15
|
}
|
|
12
16
|
export declare function utcDateKey(now?: Date): string;
|
|
13
|
-
|
|
17
|
+
/** Today's spend for one wallet. Other wallets and older days read as zero. */
|
|
18
|
+
export declare function readSpendLedger(path?: string, now?: Date, wallet?: WalletName): Promise<SpendLedger>;
|
|
19
|
+
/** Today's spend of every wallet that has spent today. */
|
|
20
|
+
export declare function readSpendLedgerRows(path?: string, now?: Date): Promise<SpendLedgerRow[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Reserves one payment against the caps of one wallet. Per-day totals are kept
|
|
23
|
+
* per wallet, so an agent wallet cannot spend the owner's daily allowance.
|
|
24
|
+
*/
|
|
14
25
|
export declare function reserveSpend(amountAtomic: bigint, caps: SpendCaps, options?: {
|
|
15
26
|
ledgerPath?: string;
|
|
16
27
|
now?: Date;
|
|
28
|
+
wallet?: WalletName;
|
|
17
29
|
}): Promise<SpendLedger>;
|
|
18
30
|
export {};
|
|
19
31
|
//# sourceMappingURL=spend-policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spend-policy.d.ts","sourceRoot":"","sources":["../src/spend-policy.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"spend-policy.d.ts","sourceRoot":"","sources":["../src/spend-policy.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAyC,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE1F,QAAA,MAAM,YAAY;;;iBAGhB,CAAC;AAkBH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAElE,qBAAa,aAAc,SAAQ,KAAK;aAEpB,IAAI,EAAE,uBAAuB,GAAG,sBAAsB;gBAAtD,IAAI,EAAE,uBAAuB,GAAG,sBAAsB,EACtE,OAAO,EAAE,MAAM;CAKlB;AAED,wBAAgB,UAAU,CAAC,GAAG,OAAa,GAAG,MAAM,CAEnD;AAED,+EAA+E;AAC/E,wBAAsB,eAAe,CACnC,IAAI,SAA6B,EACjC,GAAG,OAAa,EAChB,MAAM,GAAE,UAAgC,GACvC,OAAO,CAAC,WAAW,CAAC,CAItB;AAED,0DAA0D;AAC1D,wBAAsB,mBAAmB,CACvC,IAAI,SAA6B,EACjC,GAAG,OAAa,GACf,OAAO,CAAC,cAAc,EAAE,CAAC,CAkB3B;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,SAAS,EACf,OAAO,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,UAAU,CAAA;CAAE,GACjE,OAAO,CAAC,WAAW,CAAC,CAsCtB"}
|
package/dist/stats.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Receipt } from "./receipts.js";
|
|
2
2
|
import type { SearchEvent } from "./searches.js";
|
|
3
3
|
export declare const STATS_RANGES: readonly ["24h", "7d", "30d"];
|
|
4
4
|
export type StatsRange = (typeof STATS_RANGES)[number];
|
|
@@ -50,6 +50,7 @@ export declare function aggregateStats(args: {
|
|
|
50
50
|
range?: StatsRange;
|
|
51
51
|
now?: Date;
|
|
52
52
|
}): StatsReport;
|
|
53
|
-
|
|
53
|
+
/** Keeps the receipts of one range, and of one wallet when `wallet` is given. */
|
|
54
|
+
export declare function filterReceiptsByRange(receipts: readonly Receipt[], range: StatsRange, now?: Date, wallet?: string): Receipt[];
|
|
54
55
|
export declare function receiptsToCsv(receipts: readonly Receipt[]): string;
|
|
55
56
|
//# sourceMappingURL=stats.d.ts.map
|
package/dist/stats.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../src/stats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../src/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,eAAO,MAAM,YAAY,+BAAgC,CAAC;AAC1D,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAAC;AAC1F,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AAgB7D,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA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AAE,SAAS,OAAO,EAAE,EAC5B,KAAK,EAAE,UAAU,EACjB,GAAG,OAAa,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,EAAE,CAIX;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAqElE"}
|
package/dist/support-report.d.ts
CHANGED
package/dist/sweep.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ export type SweepResult = {
|
|
|
34
34
|
amountAtomic: string;
|
|
35
35
|
transaction: string;
|
|
36
36
|
};
|
|
37
|
+
export declare class SweepGasError extends Error {
|
|
38
|
+
readonly address: string;
|
|
39
|
+
constructor(address: string, cause: unknown);
|
|
40
|
+
}
|
|
37
41
|
export declare function calculateSweepAmount(balanceAtomic: bigint, gasHeadroomAtomic: bigint): bigint;
|
|
38
42
|
export declare function getArcGasHeadroomAtomic(): bigint;
|
|
39
43
|
export declare function readUsdcBalance(args: {
|
package/dist/sweep.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sweep.d.ts","sourceRoot":"","sources":["../src/sweep.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"sweep.d.ts","sourceRoot":"","sources":["../src/sweep.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAaxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBZ,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAQ5C;AAED,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAK7F;AAED,wBAAgB,uBAAuB,IAAI,MAAM,CAYhD;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBlB;AAED,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,GAAG,OAAO,CAAC,WAAW,CAAC,CA+FvB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The wallet a record belongs to when it predates named wallets. Receipts and
|
|
4
|
+
* spend-ledger rows written before 0.3.0 carry no wallet, and the 0.2.x
|
|
5
|
+
* keystore becomes this wallet during the layout migration.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_WALLET_NAME = "main";
|
|
8
|
+
/**
|
|
9
|
+
* A wallet name is also a file name under `~/.vapi/wallets/`, so it stays in
|
|
10
|
+
* the small set that is safe on every filesystem and unambiguous in a shell:
|
|
11
|
+
* lowercase letters, digits and dashes, 1 to 32 characters, never starting
|
|
12
|
+
* with a dash.
|
|
13
|
+
*/
|
|
14
|
+
export declare const WALLET_NAME_PATTERN: RegExp;
|
|
15
|
+
export type WalletName = string;
|
|
16
|
+
export declare const walletNameSchema: z.ZodString;
|
|
17
|
+
export declare function isWalletName(value: string): boolean;
|
|
18
|
+
//# sourceMappingURL=wallet-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-name.d.ts","sourceRoot":"","sources":["../src/wallet-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAA8B,CAAC;AAE/D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,eAAO,MAAM,gBAAgB,aAK1B,CAAC;AAEJ,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type SpendCaps } from "./config.js";
|
|
3
|
+
import { type VapiPaymentAccount } from "./keystore.js";
|
|
4
|
+
import type { SecretStore } from "./secret-store.js";
|
|
5
|
+
import { type WalletName } from "./wallet-name.js";
|
|
6
|
+
export { DEFAULT_WALLET_NAME, isWalletName, walletNameSchema, WALLET_NAME_PATTERN, type WalletName, } from "./wallet-name.js";
|
|
7
|
+
export type AgentLink = {
|
|
8
|
+
apiBase: string;
|
|
9
|
+
clientId: string;
|
|
10
|
+
owner: `0x${string}`;
|
|
11
|
+
label: string;
|
|
12
|
+
scopes: string[];
|
|
13
|
+
linkedAt: string;
|
|
14
|
+
routerBaseUrl?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const ROUTER_TOPUP_TIERS: readonly [1, 5, 20, 50];
|
|
17
|
+
export type RouterTopupTier = (typeof ROUTER_TOPUP_TIERS)[number];
|
|
18
|
+
export type RouterRefill = {
|
|
19
|
+
belowUsd: number;
|
|
20
|
+
tierUsd: RouterTopupTier;
|
|
21
|
+
};
|
|
22
|
+
/** What `wallets.json` records about one wallet. The keys live in its keystore. */
|
|
23
|
+
export declare const walletEntrySchema: z.ZodObject<{
|
|
24
|
+
createdAt: z.ZodISODateTime;
|
|
25
|
+
label: z.ZodOptional<z.ZodString>;
|
|
26
|
+
spendCaps: z.ZodObject<{
|
|
27
|
+
perCallAtomic: z.ZodString;
|
|
28
|
+
perDayAtomic: z.ZodString;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
routerRefill: z.ZodOptional<z.ZodType<RouterRefill, unknown, z.core.$ZodTypeInternals<RouterRefill, unknown>>>;
|
|
31
|
+
link: z.ZodOptional<z.ZodType<AgentLink, unknown, z.core.$ZodTypeInternals<AgentLink, unknown>>>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export declare const walletRegistrySchema: z.ZodObject<{
|
|
34
|
+
version: z.ZodLiteral<1>;
|
|
35
|
+
default: z.ZodOptional<z.ZodString>;
|
|
36
|
+
wallets: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
37
|
+
createdAt: z.ZodISODateTime;
|
|
38
|
+
label: z.ZodOptional<z.ZodString>;
|
|
39
|
+
spendCaps: z.ZodObject<{
|
|
40
|
+
perCallAtomic: z.ZodString;
|
|
41
|
+
perDayAtomic: z.ZodString;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
routerRefill: z.ZodOptional<z.ZodType<RouterRefill, unknown, z.core.$ZodTypeInternals<RouterRefill, unknown>>>;
|
|
44
|
+
link: z.ZodOptional<z.ZodType<AgentLink, unknown, z.core.$ZodTypeInternals<AgentLink, unknown>>>;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
export type WalletEntry = z.infer<typeof walletEntrySchema>;
|
|
48
|
+
export type WalletRegistry = z.infer<typeof walletRegistrySchema>;
|
|
49
|
+
/** How a caller names the wallet it wants; every field is optional. */
|
|
50
|
+
export type WalletSelection = {
|
|
51
|
+
/** An explicit name, from `--wallet` or an MCP argument. */
|
|
52
|
+
name?: string | undefined;
|
|
53
|
+
/** Environment to read `VAPI_WALLET` from. Defaults to `process.env`. */
|
|
54
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
55
|
+
};
|
|
56
|
+
export type ResolvedWallet = {
|
|
57
|
+
name: WalletName;
|
|
58
|
+
path: string;
|
|
59
|
+
entry: WalletEntry;
|
|
60
|
+
};
|
|
61
|
+
export type WalletInfo = ResolvedWallet & {
|
|
62
|
+
address?: string;
|
|
63
|
+
solanaAddress?: string;
|
|
64
|
+
keystoreVersion?: number;
|
|
65
|
+
isDefault: boolean;
|
|
66
|
+
spendCaps: SpendCaps;
|
|
67
|
+
label?: string;
|
|
68
|
+
createdAt: string;
|
|
69
|
+
};
|
|
70
|
+
export type CreatedWallet = ResolvedWallet & {
|
|
71
|
+
account: VapiPaymentAccount;
|
|
72
|
+
recoveryPhrase: string;
|
|
73
|
+
};
|
|
74
|
+
export type ImportedWallet = ResolvedWallet & {
|
|
75
|
+
account: VapiPaymentAccount;
|
|
76
|
+
};
|
|
77
|
+
export type TrashedWallet = {
|
|
78
|
+
name: WalletName;
|
|
79
|
+
removedAt: string;
|
|
80
|
+
path: string;
|
|
81
|
+
entry?: WalletEntry;
|
|
82
|
+
};
|
|
83
|
+
/** Reads the USDC balance of an address, so `remove` can refuse a funded wallet. */
|
|
84
|
+
export type WalletBalanceReader = (address: string) => Promise<bigint>;
|
|
85
|
+
export type WalletStoreOptions = {
|
|
86
|
+
/** Injected clock, so `createdAt` is deterministic in tests. */
|
|
87
|
+
now?: () => Date;
|
|
88
|
+
};
|
|
89
|
+
export type LayoutMigration = {
|
|
90
|
+
moved: boolean;
|
|
91
|
+
from?: string;
|
|
92
|
+
to?: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The wallets on this machine: one registry file, one keystore per wallet, and
|
|
96
|
+
* the rules for picking the wallet a command acts on. Keys never leave the
|
|
97
|
+
* keystore files; the store only moves, names and caps them.
|
|
98
|
+
*
|
|
99
|
+
* Layout under the config home (`~/.vapi`, or `VAPI_HOME`):
|
|
100
|
+
*
|
|
101
|
+
* ```
|
|
102
|
+
* wallets.json registry: default wallet, per-wallet caps and labels
|
|
103
|
+
* wallets/<name>.json one keystore per wallet, mode 0600
|
|
104
|
+
* wallets/.trash/ removed wallets, kept encrypted, never auto-deleted
|
|
105
|
+
* keystore.json symlink to wallets/main.json after the 0.2.x migration
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare class WalletStore {
|
|
109
|
+
/** The config home these wallets live under. */
|
|
110
|
+
readonly home: string;
|
|
111
|
+
private readonly options;
|
|
112
|
+
private registry;
|
|
113
|
+
private constructor();
|
|
114
|
+
/** Opens the store, migrating a 0.2.x single-keystore home on the way. */
|
|
115
|
+
static open(home?: string, options?: WalletStoreOptions): Promise<WalletStore>;
|
|
116
|
+
get registryPath(): string;
|
|
117
|
+
get walletsDirectory(): string;
|
|
118
|
+
get trashDirectory(): string;
|
|
119
|
+
/** The keystore path of a wallet, whether or not it exists yet. */
|
|
120
|
+
pathFor(name: string): string;
|
|
121
|
+
/** The names this machine knows, in registry order. */
|
|
122
|
+
names(): WalletName[];
|
|
123
|
+
/** The name a command uses when nothing selects another wallet. */
|
|
124
|
+
get defaultName(): WalletName | undefined;
|
|
125
|
+
/** True once `wallets.json` exists; false for an un-migrated 0.2.x home. */
|
|
126
|
+
hasRegistry(): boolean;
|
|
127
|
+
entry(name: string): WalletEntry | undefined;
|
|
128
|
+
has(name: string): boolean;
|
|
129
|
+
/** A copy of the registry as it was last read or written. */
|
|
130
|
+
snapshot(): WalletRegistry;
|
|
131
|
+
/** Re-reads `wallets.json` from disk. */
|
|
132
|
+
reload(): Promise<WalletRegistry>;
|
|
133
|
+
/**
|
|
134
|
+
* Picks the wallet a command acts on: an explicit name first, then
|
|
135
|
+
* `VAPI_WALLET`, then the registry default.
|
|
136
|
+
*/
|
|
137
|
+
resolve(selection?: WalletSelection): ResolvedWallet;
|
|
138
|
+
/** Every wallet with its addresses, read without a passphrase. */
|
|
139
|
+
list(): Promise<WalletInfo[]>;
|
|
140
|
+
/** The stored Base address of a wallet, without its passphrase. */
|
|
141
|
+
readAddress(name: string): Promise<string | undefined>;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a wallet from a fresh or supplied recovery phrase. The first wallet
|
|
144
|
+
* on a machine also becomes the default. The phrase is returned once and is
|
|
145
|
+
* never written anywhere but the encrypted keystore.
|
|
146
|
+
*/
|
|
147
|
+
create(name: string, passphrase: string, options?: {
|
|
148
|
+
phrase?: string;
|
|
149
|
+
enableSolana?: boolean;
|
|
150
|
+
label?: string;
|
|
151
|
+
spendCaps?: SpendCaps;
|
|
152
|
+
}): Promise<CreatedWallet>;
|
|
153
|
+
/** Wraps a private key the user already holds in a new named wallet. */
|
|
154
|
+
importKey(name: string, passphrase: string, privateKey: string, options?: {
|
|
155
|
+
label?: string;
|
|
156
|
+
spendCaps?: SpendCaps;
|
|
157
|
+
}): Promise<ImportedWallet>;
|
|
158
|
+
/** Opens one wallet's keystore with its passphrase. */
|
|
159
|
+
unlock(name: string, passphrase: string): Promise<VapiPaymentAccount>;
|
|
160
|
+
setDefault(name: string): Promise<WalletRegistry>;
|
|
161
|
+
setSpendCaps(name: string, caps: SpendCaps): Promise<WalletEntry>;
|
|
162
|
+
setRouterRefill(name: string, refill: RouterRefill | null): Promise<WalletEntry>;
|
|
163
|
+
/** Sets or, with `undefined`, clears the human label of a wallet. */
|
|
164
|
+
setLabel(name: string, label: string | undefined): Promise<WalletEntry>;
|
|
165
|
+
setLink(name: WalletName, link: AgentLink): Promise<WalletEntry>;
|
|
166
|
+
clearLink(name: WalletName): Promise<WalletEntry>;
|
|
167
|
+
/**
|
|
168
|
+
* Renames a wallet everywhere its name is recorded: the keystore file, the
|
|
169
|
+
* registry, and the wallet field of its receipts. The keystore contents are
|
|
170
|
+
* moved untouched.
|
|
171
|
+
*/
|
|
172
|
+
rename(oldName: string, newName: string, options?: {
|
|
173
|
+
secrets?: SecretStore;
|
|
174
|
+
}): Promise<ResolvedWallet>;
|
|
175
|
+
/**
|
|
176
|
+
* Moves a wallet's keystore to `wallets/.trash/`. Nothing is deleted: the
|
|
177
|
+
* encrypted file stays, and its passphrase still opens it. The default wallet
|
|
178
|
+
* and a wallet that still holds USDC are refused unless forced.
|
|
179
|
+
*
|
|
180
|
+
* `allowDefault` exists for one caller: `vapi import --replace`, which puts a
|
|
181
|
+
* new wallet under the same name back in place immediately afterwards, so the
|
|
182
|
+
* machine is never left without a default. `vapi wallet remove` never sets it.
|
|
183
|
+
*/
|
|
184
|
+
remove(name: string, options?: {
|
|
185
|
+
force?: boolean;
|
|
186
|
+
balanceReader?: WalletBalanceReader;
|
|
187
|
+
allowDefault?: boolean;
|
|
188
|
+
}): Promise<TrashedWallet>;
|
|
189
|
+
/** Brings the most recently removed wallet of that name back. */
|
|
190
|
+
restore(name: string): Promise<ResolvedWallet>;
|
|
191
|
+
/** Every removed wallet still in the trash, newest first. */
|
|
192
|
+
listTrash(): Promise<TrashedWallet[]>;
|
|
193
|
+
/**
|
|
194
|
+
* Moves a 0.2.x home into the wallet layout, once: `keystore.json` becomes
|
|
195
|
+
* `wallets/main.json` and `keystore.json` stays behind as a symlink for one
|
|
196
|
+
* release, so scripts and 0.2.x callers keep working. The keystore contents
|
|
197
|
+
* are never rewritten, and a home without a keystore migrates nothing.
|
|
198
|
+
*/
|
|
199
|
+
migrateLegacyLayout(): Promise<LayoutMigration>;
|
|
200
|
+
private now;
|
|
201
|
+
private newEntry;
|
|
202
|
+
private prepareNewWallet;
|
|
203
|
+
private registerWallet;
|
|
204
|
+
/**
|
|
205
|
+
* Keeps the compatibility symlink honest: when the wallet it points at moves,
|
|
206
|
+
* the link follows it, and when that wallet is removed, the link goes too.
|
|
207
|
+
*/
|
|
208
|
+
private retargetLegacyKeystoreLink;
|
|
209
|
+
private update;
|
|
210
|
+
private readRegistry;
|
|
211
|
+
private writeRegistry;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The caps that apply to one wallet: its own entry, or — in a home that has no
|
|
215
|
+
* registry yet — the legacy `config.spendCaps`, and otherwise the defaults.
|
|
216
|
+
*/
|
|
217
|
+
export declare function spendCapsForWallet(store: WalletStore, name?: WalletName): Promise<SpendCaps>;
|
|
218
|
+
/** Rejects anything that is not a wallet name, including path traversal. */
|
|
219
|
+
export declare function assertWalletName(value: string): WalletName;
|
|
220
|
+
//# sourceMappingURL=wallet-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-store.d.ts","sourceRoot":"","sources":["../src/wallet-store.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,KAAK,MAAM,EAAE,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,E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E,UAAgC,GACrC,OAAO,CAAC,SAAS,CAAC,CAIpB;AAED,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAa1D"}
|
package/dist/wallet.d.ts
CHANGED
|
@@ -23,9 +23,4 @@ export declare class LocalWallet implements Wallet {
|
|
|
23
23
|
signTypedData(typedData: X402TypedData): Promise<Hex>;
|
|
24
24
|
balance(network: string, configured: ConfiguredNetwork): Promise<bigint>;
|
|
25
25
|
}
|
|
26
|
-
export declare function openWallet(options: {
|
|
27
|
-
passphrase: string;
|
|
28
|
-
policy: Policy;
|
|
29
|
-
keystorePath?: string;
|
|
30
|
-
}): Promise<Wallet>;
|
|
31
26
|
//# sourceMappingURL=wallet.d.ts.map
|
package/dist/wallet.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,aAAa,CAAC,SAAS,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACvD;AAED,gFAAgF;AAChF,MAAM,WAAW,MAAO,SAAQ,MAAM;IACpC,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1E;AAED,qBAAa,WAAY,YAAW,MAAM;IAItC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;gBAGP,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAK3B,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,aAAa,CAAC,SAAS,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC;IAIrD,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;CAS/E"}
|
package/dist/x402-networks.d.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
2
|
export declare const BASE_MAINNET_CAIP2: "eip155:8453";
|
|
3
|
+
export declare const ARC_MAINNET_CAIP2: "eip155:5042";
|
|
3
4
|
export declare const ARC_TESTNET_CAIP2: "eip155:5042002";
|
|
4
|
-
/**
|
|
5
|
-
* Arc mainnet is not yet published by Arc or the x402 packages. Keep this
|
|
6
|
-
* non-routable placeholder so callers do not mistake viem's reserved chain ID
|
|
7
|
-
* for a usable x402 network.
|
|
8
|
-
*
|
|
9
|
-
* TODO: replace only after Arc publishes a mainnet RPC and canonical USDC.
|
|
10
|
-
*/
|
|
11
|
-
export declare const ARC_MAINNET_CAIP2_PLACEHOLDER: null;
|
|
12
5
|
/** Full Solana mainnet genesis hash requested by the persisted vAPI config. */
|
|
13
6
|
export declare const SOLANA_MAINNET_CAIP2: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
14
7
|
/** CAIP-2 identifier emitted by the x402 reference packages. */
|
|
15
8
|
export declare const X402_SOLANA_MAINNET_CAIP2: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
16
9
|
export declare const SOLANA_MAINNET_USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
17
|
-
export type CanonicalX402UsdcNetwork = typeof BASE_MAINNET_CAIP2 | typeof ARC_TESTNET_CAIP2;
|
|
10
|
+
export type CanonicalX402UsdcNetwork = typeof BASE_MAINNET_CAIP2 | typeof ARC_MAINNET_CAIP2 | typeof ARC_TESTNET_CAIP2;
|
|
18
11
|
export type X402TokenDomain = Readonly<{
|
|
19
12
|
name: string;
|
|
20
13
|
version: string;
|
|
@@ -35,6 +28,10 @@ export declare const CANONICAL_X402_USDC_NETWORKS: Readonly<{
|
|
|
35
28
|
usdc: Address;
|
|
36
29
|
eip712Domain: X402TokenDomain;
|
|
37
30
|
}>;
|
|
31
|
+
"eip155:5042": Readonly<{
|
|
32
|
+
usdc: Address;
|
|
33
|
+
eip712Domain: X402TokenDomain;
|
|
34
|
+
}>;
|
|
38
35
|
"eip155:5042002": Readonly<{
|
|
39
36
|
usdc: Address;
|
|
40
37
|
eip712Domain: X402TokenDomain;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x402-networks.d.ts","sourceRoot":"","sources":["../src/x402-networks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAEhD,eAAO,MAAM,kBAAkB,EAAG,aAAsB,CAAC;AACzD,eAAO,MAAM,iBAAiB,EAAG,
|
|
1
|
+
{"version":3,"file":"x402-networks.d.ts","sourceRoot":"","sources":["../src/x402-networks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,MAAM,CAA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Caps, VapiConfig } from "./config.js";
|
|
2
|
+
import type { VapiPaymentAccount } from "./keystore.js";
|
|
3
|
+
import { type LookupFn } from "./net-guard.js";
|
|
4
|
+
import { type Receipt } from "./receipts.js";
|
|
5
|
+
import type { WalletName } from "./wallet-name.js";
|
|
6
|
+
import { type X402Quote, type X402SettlementOutcome } from "./x402.js";
|
|
7
|
+
export type PayRequestArgs = {
|
|
8
|
+
url: string;
|
|
9
|
+
init: RequestInit;
|
|
10
|
+
account: VapiPaymentAccount;
|
|
11
|
+
wallet: WalletName;
|
|
12
|
+
caps: SpendCaps;
|
|
13
|
+
config: VapiConfig;
|
|
14
|
+
fetchImpl: typeof fetch;
|
|
15
|
+
paths?: {
|
|
16
|
+
ledgerPath?: string;
|
|
17
|
+
receiptsPath?: string;
|
|
18
|
+
};
|
|
19
|
+
maxAtomic?: bigint;
|
|
20
|
+
preferNetworks?: string[];
|
|
21
|
+
paymentId?: string;
|
|
22
|
+
now?: Date;
|
|
23
|
+
nowMs?: () => number;
|
|
24
|
+
source?: string;
|
|
25
|
+
lookup?: LookupFn;
|
|
26
|
+
};
|
|
27
|
+
export type PayRequestResult = {
|
|
28
|
+
response: Response;
|
|
29
|
+
receipt: Receipt;
|
|
30
|
+
};
|
|
31
|
+
export type X402PaymentAttempt = {
|
|
32
|
+
response: Response;
|
|
33
|
+
request: Request;
|
|
34
|
+
finish(): void;
|
|
35
|
+
waitFor<T>(operation: Promise<T>, response: Response): Promise<T>;
|
|
36
|
+
};
|
|
37
|
+
export type X402PossibleSettlement = {
|
|
38
|
+
network: string;
|
|
39
|
+
asset: string;
|
|
40
|
+
amountAtomic: string;
|
|
41
|
+
payTo: string;
|
|
42
|
+
payer: string;
|
|
43
|
+
paymentId?: string;
|
|
44
|
+
authorizationNonce?: string;
|
|
45
|
+
authorizationExpiresAt?: string;
|
|
46
|
+
authorizationTransaction?: string;
|
|
47
|
+
receipt: unknown | null;
|
|
48
|
+
};
|
|
49
|
+
export type X402PaymentTrace = {
|
|
50
|
+
phases: {
|
|
51
|
+
quoteMs?: number;
|
|
52
|
+
signMs?: number;
|
|
53
|
+
requestMs?: number;
|
|
54
|
+
settleMs?: number;
|
|
55
|
+
};
|
|
56
|
+
quote?: NonNullable<Receipt["quote"]>;
|
|
57
|
+
payer?: string;
|
|
58
|
+
paymentId?: string;
|
|
59
|
+
authorization?: NonNullable<Receipt["authorization"]>;
|
|
60
|
+
settlement?: NonNullable<Receipt["settlement"]>;
|
|
61
|
+
status?: number;
|
|
62
|
+
capsApplied: boolean;
|
|
63
|
+
};
|
|
64
|
+
export declare class X402PaymentError extends Error {
|
|
65
|
+
readonly code: "payment_rejected" | "response_unreadable" | "settlement_unknown";
|
|
66
|
+
readonly possibleSettlement?: X402PossibleSettlement | undefined;
|
|
67
|
+
readonly name = "X402PaymentError";
|
|
68
|
+
constructor(code: "payment_rejected" | "response_unreadable" | "settlement_unknown", message: string, possibleSettlement?: X402PossibleSettlement | undefined, options?: ErrorOptions & {
|
|
69
|
+
paymentRejection?: {
|
|
70
|
+
httpStatus: number;
|
|
71
|
+
receipt: unknown;
|
|
72
|
+
};
|
|
73
|
+
confirmedSettlement?: {
|
|
74
|
+
httpStatus: number;
|
|
75
|
+
receipt: unknown;
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
readonly paymentRejection?: {
|
|
79
|
+
httpStatus: number;
|
|
80
|
+
receipt: unknown;
|
|
81
|
+
};
|
|
82
|
+
readonly confirmedSettlement?: {
|
|
83
|
+
httpStatus: number;
|
|
84
|
+
receipt: unknown;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export type CompleteX402PaymentArgs<T = undefined> = {
|
|
88
|
+
challenge: X402PaymentAttempt;
|
|
89
|
+
account: VapiPaymentAccount;
|
|
90
|
+
caps: SpendCaps;
|
|
91
|
+
config: VapiConfig;
|
|
92
|
+
send(request: Request): Promise<X402PaymentAttempt>;
|
|
93
|
+
consumeResponse?: (response: Response) => Promise<T>;
|
|
94
|
+
fetchImpl?: typeof fetch;
|
|
95
|
+
ledgerPath?: string;
|
|
96
|
+
wallet?: WalletName;
|
|
97
|
+
maxAtomic?: bigint;
|
|
98
|
+
maxPriceUsd?: number | string;
|
|
99
|
+
preferNetworks?: string[];
|
|
100
|
+
requiredNetwork?: string;
|
|
101
|
+
expectedPayTo?: string;
|
|
102
|
+
paymentId?: string;
|
|
103
|
+
now?: Date;
|
|
104
|
+
nowMs?: () => number;
|
|
105
|
+
quoteStartedMs?: number;
|
|
106
|
+
trace?: X402PaymentTrace;
|
|
107
|
+
};
|
|
108
|
+
export type CompleteX402PaymentResult<T = undefined> = {
|
|
109
|
+
response: Response;
|
|
110
|
+
request: Request;
|
|
111
|
+
body: T | undefined;
|
|
112
|
+
quote: X402Quote;
|
|
113
|
+
payer: string;
|
|
114
|
+
paymentId?: string;
|
|
115
|
+
settlement: unknown | null;
|
|
116
|
+
settlementOutcome: X402SettlementOutcome;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Sends one request and, only when it receives HTTP 402, completes the exact
|
|
120
|
+
* x402 payment flow. A non-402 response is returned with a receipt that has no
|
|
121
|
+
* quote, payer, authorization, or settlement fields. The existing receipt
|
|
122
|
+
* vocabulary records a successful unpaid response as `paid`.
|
|
123
|
+
*/
|
|
124
|
+
export declare function payRequest(args: PayRequestArgs): Promise<PayRequestResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Completes an already-received HTTP 402 challenge. The transport seam keeps
|
|
127
|
+
* redirect validation and timeout ownership with the caller while this module
|
|
128
|
+
* owns quote selection, policy, signing, paid replay, and settlement handling.
|
|
129
|
+
*/
|
|
130
|
+
export declare function completeX402Payment<T = undefined>(args: CompleteX402PaymentArgs<T>): Promise<CompleteX402PaymentResult<T>>;
|
|
131
|
+
//# sourceMappingURL=x402-pay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-pay.d.ts","sourceRoot":"","sources":["../src/x402-pay.ts"],"names":[],"mappings":"AA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AAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,SAAS,IAAI;IACrD,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC;IACpB,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,iBAAiB,EAAE,qBAAqB,CAAC;CAC1C,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA2EhF;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,GAAG,SAAS,EACrD,IAAI,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAC/B,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAuMvC"}
|
package/dist/x402.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { type Address, type Hex } from "viem";
|
|
|
2
2
|
import { ExactSvmScheme } from "@x402/svm/exact/client";
|
|
3
3
|
import { type X402NetworkConfig } from "./x402-networks.js";
|
|
4
4
|
export type { Address, Hex } from "viem";
|
|
5
|
-
export {
|
|
5
|
+
export { ARC_MAINNET_CAIP2, ARC_TESTNET_CAIP2, BASE_MAINNET_CAIP2, BROWSER_ENABLED_X402_NETWORK_CONFIG, CANONICAL_X402_USDC_NETWORKS, SOLANA_MAINNET_CAIP2, SOLANA_MAINNET_USDC, X402_SOLANA_MAINNET_CAIP2, getCanonicalX402Usdc, type CanonicalX402UsdcIdentity, type CanonicalX402UsdcNetwork, type X402NetworkConfig, type X402TokenDomain, } from "./x402-networks.js";
|
|
6
|
+
export declare const VAPI_BUILDER_CODE = "vapi";
|
|
6
7
|
export declare const EIP3009_AUTHORIZATION_TYPES: {
|
|
7
8
|
readonly TransferWithAuthorization: readonly [{
|
|
8
9
|
readonly name: "from";
|
|
@@ -119,6 +120,18 @@ export declare class X402Error extends Error {
|
|
|
119
120
|
readonly code: "invalid_challenge" | "unsupported_challenge" | "max_price_exceeded";
|
|
120
121
|
constructor(code: "invalid_challenge" | "unsupported_challenge" | "max_price_exceeded", message: string, options?: ErrorOptions);
|
|
121
122
|
}
|
|
123
|
+
/** Returns whether a value is a valid x402 payment-identifier id. */
|
|
124
|
+
export declare function isValidPaymentId(value: unknown): value is string;
|
|
125
|
+
/** Creates a fresh x402 payment-identifier id from 16 random bytes. */
|
|
126
|
+
export declare function createPaymentId(randomBytes?: (bytes: Uint8Array<ArrayBuffer>) => void): string;
|
|
127
|
+
/**
|
|
128
|
+
* Builds the extensions sent in a payment payload without mutating the
|
|
129
|
+
* server-declared extensions. A payment id is required only when the server
|
|
130
|
+
* advertised payment-identifier.
|
|
131
|
+
*/
|
|
132
|
+
export declare function buildPaymentExtensions(serverExtensions: Readonly<Record<string, unknown>> | undefined, options?: Readonly<{
|
|
133
|
+
paymentId?: string;
|
|
134
|
+
}>): Record<string, unknown>;
|
|
122
135
|
export declare function parse402Challenge(challenge: unknown, configuredNetworks: X402NetworkConfig, fallbackResourceUrl?: string, requiredNetwork?: string, expectedPayTo?: string): X402Quote;
|
|
123
136
|
/**
|
|
124
137
|
* Drop a response body without waiting. Awaiting cancel() on a body that has
|
|
@@ -126,6 +139,8 @@ export declare function parse402Challenge(challenge: unknown, configuredNetworks
|
|
|
126
139
|
* callers that only want to discard the bytes must not block on it.
|
|
127
140
|
*/
|
|
128
141
|
export declare function discardBody(response: Response | null | undefined): void;
|
|
142
|
+
/** Decodes a `PAYMENT-REQUIRED` header: base64 of the JSON payment offer. Throws when it is not. */
|
|
143
|
+
export declare function decodePaymentRequiredHeader(value: string): unknown;
|
|
129
144
|
export declare function parse402Response(response: Response, configuredNetworks: X402NetworkConfig, requiredNetwork?: string, expectedPayTo?: string): Promise<X402Quote>;
|
|
130
145
|
export declare function buildEip3009TypedData(args: {
|
|
131
146
|
from: Address;
|
|
@@ -142,9 +157,11 @@ export declare function buildX402Payment(args: {
|
|
|
142
157
|
nowSeconds?: number;
|
|
143
158
|
nonce?: Hex;
|
|
144
159
|
fetchImpl?: typeof fetch;
|
|
160
|
+
paymentId?: string;
|
|
145
161
|
}): Promise<{
|
|
146
162
|
payload: X402PaymentPayload;
|
|
147
163
|
headers: X402PaymentHeaders;
|
|
164
|
+
paymentId?: string;
|
|
148
165
|
}>;
|
|
149
166
|
/** Adds the older X-PAYMENT header while keeping PAYMENT-SIGNATURE canonical. */
|
|
150
167
|
export declare function buildCompatibleX402Payment(args: {
|
|
@@ -153,9 +170,11 @@ export declare function buildCompatibleX402Payment(args: {
|
|
|
153
170
|
nowSeconds?: number;
|
|
154
171
|
nonce?: Hex;
|
|
155
172
|
fetchImpl?: typeof fetch;
|
|
173
|
+
paymentId?: string;
|
|
156
174
|
}): Promise<{
|
|
157
175
|
payload: X402PaymentPayload;
|
|
158
176
|
headers: X402CompatiblePaymentHeaders;
|
|
177
|
+
paymentId?: string;
|
|
159
178
|
}>;
|
|
160
179
|
export declare function assertMaxPrice(amountAtomic: bigint, maxPriceUsd: number | string | undefined): void;
|
|
161
180
|
export declare function usdToAtomic(value: number | string): bigint;
|
package/dist/x402.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../src/x402.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;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