agentaos 0.2.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/LICENSE +199 -0
- package/README.md +249 -0
- package/dist/cli/commands/admin.command.d.ts +3 -0
- package/dist/cli/commands/admin.command.d.ts.map +1 -0
- package/dist/cli/commands/admin.command.js +415 -0
- package/dist/cli/commands/admin.command.js.map +1 -0
- package/dist/cli/commands/balance.command.d.ts +3 -0
- package/dist/cli/commands/balance.command.d.ts.map +1 -0
- package/dist/cli/commands/balance.command.js +65 -0
- package/dist/cli/commands/balance.command.js.map +1 -0
- package/dist/cli/commands/deploy.command.d.ts +3 -0
- package/dist/cli/commands/deploy.command.d.ts.map +1 -0
- package/dist/cli/commands/deploy.command.js +101 -0
- package/dist/cli/commands/deploy.command.js.map +1 -0
- package/dist/cli/commands/info.command.d.ts +3 -0
- package/dist/cli/commands/info.command.d.ts.map +1 -0
- package/dist/cli/commands/info.command.js +30 -0
- package/dist/cli/commands/info.command.js.map +1 -0
- package/dist/cli/commands/init.command.d.ts +3 -0
- package/dist/cli/commands/init.command.d.ts.map +1 -0
- package/dist/cli/commands/init.command.js +364 -0
- package/dist/cli/commands/init.command.js.map +1 -0
- package/dist/cli/commands/link.command.d.ts +3 -0
- package/dist/cli/commands/link.command.d.ts.map +1 -0
- package/dist/cli/commands/link.command.js +111 -0
- package/dist/cli/commands/link.command.js.map +1 -0
- package/dist/cli/commands/login.command.d.ts +4 -0
- package/dist/cli/commands/login.command.d.ts.map +1 -0
- package/dist/cli/commands/login.command.js +149 -0
- package/dist/cli/commands/login.command.js.map +1 -0
- package/dist/cli/commands/network.command.d.ts +3 -0
- package/dist/cli/commands/network.command.d.ts.map +1 -0
- package/dist/cli/commands/network.command.js +206 -0
- package/dist/cli/commands/network.command.js.map +1 -0
- package/dist/cli/commands/proxy.command.d.ts +3 -0
- package/dist/cli/commands/proxy.command.d.ts.map +1 -0
- package/dist/cli/commands/proxy.command.js +248 -0
- package/dist/cli/commands/proxy.command.js.map +1 -0
- package/dist/cli/commands/receive.command.d.ts +3 -0
- package/dist/cli/commands/receive.command.d.ts.map +1 -0
- package/dist/cli/commands/receive.command.js +360 -0
- package/dist/cli/commands/receive.command.js.map +1 -0
- package/dist/cli/commands/send.command.d.ts +3 -0
- package/dist/cli/commands/send.command.d.ts.map +1 -0
- package/dist/cli/commands/send.command.js +83 -0
- package/dist/cli/commands/send.command.js.map +1 -0
- package/dist/cli/commands/sign.command.d.ts +3 -0
- package/dist/cli/commands/sign.command.d.ts.map +1 -0
- package/dist/cli/commands/sign.command.js +53 -0
- package/dist/cli/commands/sign.command.js.map +1 -0
- package/dist/cli/commands/status.command.d.ts +3 -0
- package/dist/cli/commands/status.command.d.ts.map +1 -0
- package/dist/cli/commands/status.command.js +109 -0
- package/dist/cli/commands/status.command.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +50 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/theme.d.ts +35 -0
- package/dist/cli/theme.d.ts.map +1 -0
- package/dist/cli/theme.js +96 -0
- package/dist/cli/theme.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/__tests__/transfer-crypto.test.d.ts +2 -0
- package/dist/lib/__tests__/transfer-crypto.test.d.ts.map +1 -0
- package/dist/lib/__tests__/transfer-crypto.test.js +151 -0
- package/dist/lib/__tests__/transfer-crypto.test.js.map +1 -0
- package/dist/lib/authenticated-fetch.d.ts +6 -0
- package/dist/lib/authenticated-fetch.d.ts.map +1 -0
- package/dist/lib/authenticated-fetch.js +74 -0
- package/dist/lib/authenticated-fetch.js.map +1 -0
- package/dist/lib/config.d.ts +42 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +163 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/erc20-abi.d.ts +43 -0
- package/dist/lib/erc20-abi.d.ts.map +1 -0
- package/dist/lib/erc20-abi.js +34 -0
- package/dist/lib/erc20-abi.js.map +1 -0
- package/dist/lib/errors.d.ts +12 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +23 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/keychain.d.ts +11 -0
- package/dist/lib/keychain.d.ts.map +1 -0
- package/dist/lib/keychain.js +216 -0
- package/dist/lib/keychain.js.map +1 -0
- package/dist/lib/policy-conversions.d.ts +19 -0
- package/dist/lib/policy-conversions.d.ts.map +1 -0
- package/dist/lib/policy-conversions.js +62 -0
- package/dist/lib/policy-conversions.js.map +1 -0
- package/dist/lib/signer-manager.d.ts +17 -0
- package/dist/lib/signer-manager.d.ts.map +1 -0
- package/dist/lib/signer-manager.js +80 -0
- package/dist/lib/signer-manager.js.map +1 -0
- package/dist/lib/transfer-crypto.d.ts +36 -0
- package/dist/lib/transfer-crypto.d.ts.map +1 -0
- package/dist/lib/transfer-crypto.js +109 -0
- package/dist/lib/transfer-crypto.js.map +1 -0
- package/dist/lib/x402-client.d.ts +63 -0
- package/dist/lib/x402-client.d.ts.map +1 -0
- package/dist/lib/x402-client.js +236 -0
- package/dist/lib/x402-client.js.map +1 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +73 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/tools/call-contract.d.ts +4 -0
- package/dist/mcp/tools/call-contract.d.ts.map +1 -0
- package/dist/mcp/tools/call-contract.js +68 -0
- package/dist/mcp/tools/call-contract.js.map +1 -0
- package/dist/mcp/tools/execute.d.ts +4 -0
- package/dist/mcp/tools/execute.d.ts.map +1 -0
- package/dist/mcp/tools/execute.js +59 -0
- package/dist/mcp/tools/execute.js.map +1 -0
- package/dist/mcp/tools/get-audit-log.d.ts +4 -0
- package/dist/mcp/tools/get-audit-log.d.ts.map +1 -0
- package/dist/mcp/tools/get-audit-log.js +85 -0
- package/dist/mcp/tools/get-audit-log.js.map +1 -0
- package/dist/mcp/tools/get-balances.d.ts +4 -0
- package/dist/mcp/tools/get-balances.d.ts.map +1 -0
- package/dist/mcp/tools/get-balances.js +84 -0
- package/dist/mcp/tools/get-balances.js.map +1 -0
- package/dist/mcp/tools/get-status.d.ts +4 -0
- package/dist/mcp/tools/get-status.d.ts.map +1 -0
- package/dist/mcp/tools/get-status.js +66 -0
- package/dist/mcp/tools/get-status.js.map +1 -0
- package/dist/mcp/tools/list-networks.d.ts +4 -0
- package/dist/mcp/tools/list-networks.d.ts.map +1 -0
- package/dist/mcp/tools/list-networks.js +36 -0
- package/dist/mcp/tools/list-networks.js.map +1 -0
- package/dist/mcp/tools/list-signers.d.ts +4 -0
- package/dist/mcp/tools/list-signers.d.ts.map +1 -0
- package/dist/mcp/tools/list-signers.js +36 -0
- package/dist/mcp/tools/list-signers.js.map +1 -0
- package/dist/mcp/tools/read-contract.d.ts +4 -0
- package/dist/mcp/tools/read-contract.d.ts.map +1 -0
- package/dist/mcp/tools/read-contract.js +62 -0
- package/dist/mcp/tools/read-contract.js.map +1 -0
- package/dist/mcp/tools/resolve-address.d.ts +4 -0
- package/dist/mcp/tools/resolve-address.d.ts.map +1 -0
- package/dist/mcp/tools/resolve-address.js +37 -0
- package/dist/mcp/tools/resolve-address.js.map +1 -0
- package/dist/mcp/tools/send-eth.d.ts +4 -0
- package/dist/mcp/tools/send-eth.d.ts.map +1 -0
- package/dist/mcp/tools/send-eth.js +52 -0
- package/dist/mcp/tools/send-eth.js.map +1 -0
- package/dist/mcp/tools/send-token.d.ts +4 -0
- package/dist/mcp/tools/send-token.d.ts.map +1 -0
- package/dist/mcp/tools/send-token.js +102 -0
- package/dist/mcp/tools/send-token.js.map +1 -0
- package/dist/mcp/tools/sign-message.d.ts +4 -0
- package/dist/mcp/tools/sign-message.d.ts.map +1 -0
- package/dist/mcp/tools/sign-message.js +33 -0
- package/dist/mcp/tools/sign-message.js.map +1 -0
- package/dist/mcp/tools/sign-typed-data.d.ts +4 -0
- package/dist/mcp/tools/sign-typed-data.d.ts.map +1 -0
- package/dist/mcp/tools/sign-typed-data.js +48 -0
- package/dist/mcp/tools/sign-typed-data.js.map +1 -0
- package/dist/mcp/tools/simulate.d.ts +4 -0
- package/dist/mcp/tools/simulate.d.ts.map +1 -0
- package/dist/mcp/tools/simulate.js +54 -0
- package/dist/mcp/tools/simulate.js.map +1 -0
- package/dist/mcp/tools/wallet-overview.d.ts +4 -0
- package/dist/mcp/tools/wallet-overview.d.ts.map +1 -0
- package/dist/mcp/tools/wallet-overview.js +109 -0
- package/dist/mcp/tools/wallet-overview.js.map +1 -0
- package/dist/mcp/tools/x402-check.d.ts +3 -0
- package/dist/mcp/tools/x402-check.d.ts.map +1 -0
- package/dist/mcp/tools/x402-check.js +44 -0
- package/dist/mcp/tools/x402-check.js.map +1 -0
- package/dist/mcp/tools/x402-discover.d.ts +3 -0
- package/dist/mcp/tools/x402-discover.d.ts.map +1 -0
- package/dist/mcp/tools/x402-discover.js +42 -0
- package/dist/mcp/tools/x402-discover.js.map +1 -0
- package/dist/mcp/tools/x402-fetch.d.ts +4 -0
- package/dist/mcp/tools/x402-fetch.d.ts.map +1 -0
- package/dist/mcp/tools/x402-fetch.js +45 -0
- package/dist/mcp/tools/x402-fetch.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy conversion utilities for the CLI.
|
|
3
|
+
* Mirrors the app's policy-builder/conversions.ts but for CLI use.
|
|
4
|
+
*/
|
|
5
|
+
import { CRITERION_CATALOG } from '@agentaos/core';
|
|
6
|
+
/**
|
|
7
|
+
* Convert form state → PolicyRule[] for the API.
|
|
8
|
+
* Reject rules first, then one accept rule with all AND'd criteria.
|
|
9
|
+
*/
|
|
10
|
+
export function buildRules(values, enabled) {
|
|
11
|
+
const rules = [];
|
|
12
|
+
const rejectCriteria = [];
|
|
13
|
+
const acceptCriteria = [];
|
|
14
|
+
for (const meta of CRITERION_CATALOG) {
|
|
15
|
+
if (meta.alwaysOn)
|
|
16
|
+
continue;
|
|
17
|
+
if (!enabled[meta.type])
|
|
18
|
+
continue;
|
|
19
|
+
const fieldValues = values[meta.type] ?? {};
|
|
20
|
+
const criterion = meta.toCriterion(fieldValues);
|
|
21
|
+
if (meta.type === 'evmAddressBlocked' || meta.type === 'blockInfiniteApprovals') {
|
|
22
|
+
rejectCriteria.push(criterion);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
acceptCriteria.push(criterion);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const c of rejectCriteria) {
|
|
29
|
+
rules.push({ action: 'reject', criteria: [c] });
|
|
30
|
+
}
|
|
31
|
+
if (acceptCriteria.length > 0) {
|
|
32
|
+
rules.push({ action: 'accept', criteria: acceptCriteria });
|
|
33
|
+
}
|
|
34
|
+
return rules;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse a PolicyRule[] back to form state.
|
|
38
|
+
*/
|
|
39
|
+
export function parseFormValues(rules) {
|
|
40
|
+
const values = {};
|
|
41
|
+
const enabled = {};
|
|
42
|
+
const metaByType = new Map();
|
|
43
|
+
for (const meta of CRITERION_CATALOG) {
|
|
44
|
+
metaByType.set(meta.type, meta);
|
|
45
|
+
}
|
|
46
|
+
for (const rule of rules) {
|
|
47
|
+
const criteria = rule.criteria ?? [];
|
|
48
|
+
for (const criterion of criteria) {
|
|
49
|
+
const type = criterion.type;
|
|
50
|
+
if (!type)
|
|
51
|
+
continue;
|
|
52
|
+
const resolvedType = type === 'evmAddress' && criterion.operator === 'not_in' ? 'evmAddressBlocked' : type;
|
|
53
|
+
const meta = metaByType.get(resolvedType);
|
|
54
|
+
if (!meta)
|
|
55
|
+
continue;
|
|
56
|
+
enabled[resolvedType] = true;
|
|
57
|
+
values[resolvedType] = meta.fromCriterion(criterion);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { values, enabled };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=policy-conversions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-conversions.js","sourceRoot":"","sources":["../../src/lib/policy-conversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAMnD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAkB,EAAE,OAAmB;IACjE,MAAM,KAAK,GAA8B,EAAE,CAAC;IAC5C,MAAM,cAAc,GAA8B,EAAE,CAAC;IACrD,MAAM,cAAc,GAA8B,EAAE,CAAC;IAErD,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,QAAQ;YAAE,SAAS;QAC5B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,SAAS;QAElC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAEhD,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,IAAI,IAAI,CAAC,IAAI,KAAK,wBAAwB,EAAE,CAAC;YACjF,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,cAAc,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,EAAE,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
|
3
|
+
private signer;
|
|
4
|
+
private signerPromise;
|
|
5
|
+
private httpClient;
|
|
6
|
+
private api;
|
|
7
|
+
private getConfig;
|
|
8
|
+
getSigner(): Promise<ThresholdSigner>;
|
|
9
|
+
getHttpClient(): HttpClient;
|
|
10
|
+
getApi(): AgentaApi;
|
|
11
|
+
/** AGENTA_NETWORK — network name matching server's GET /api/v1/networks (e.g. "base-sepolia", "mainnet"). */
|
|
12
|
+
getNetwork(): string | null;
|
|
13
|
+
requireNetwork(networkParam?: string): string;
|
|
14
|
+
getSignerAddress(): string | undefined;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=signer-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer-manager.d.ts","sourceRoot":"","sources":["../../src/lib/signer-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEvE,qBAAa,aAAa;IACzB,OAAO,CAAC,MAAM,CAAgC;IAC9C,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,GAAG,CAA0B;IAErC,OAAO,CAAC,SAAS;IAWX,SAAS,IAAI,OAAO,CAAC,eAAe,CAAC;IA2B3C,aAAa,IAAI,UAAU;IAQ3B,MAAM,IAAI,SAAS;IAMnB,6GAA6G;IAC7G,UAAU,IAAI,MAAM,GAAG,IAAI;IAI3B,cAAc,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM;IAU7C,gBAAgB,IAAI,MAAM,GAAG,SAAS;IAItC,OAAO,IAAI,IAAI;CASf"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CGGMP24Scheme } from '@agentaos/engine';
|
|
2
|
+
import { AgentaApi, HttpClient, ThresholdSigner } from '@agentaos/sdk';
|
|
3
|
+
export class SignerManager {
|
|
4
|
+
signer = null;
|
|
5
|
+
signerPromise = null;
|
|
6
|
+
httpClient = null;
|
|
7
|
+
api = null;
|
|
8
|
+
getConfig() {
|
|
9
|
+
const apiSecret = process.env.AGENTA_API_SECRET;
|
|
10
|
+
const serverUrl = process.env.AGENTA_SERVER || 'https://api.agentaos.ai';
|
|
11
|
+
const apiKey = process.env.AGENTA_API_KEY;
|
|
12
|
+
if (!apiSecret)
|
|
13
|
+
throw new Error('AGENTA_API_SECRET is required');
|
|
14
|
+
if (!apiKey)
|
|
15
|
+
throw new Error('AGENTA_API_KEY is required');
|
|
16
|
+
return { apiSecret, serverUrl, apiKey };
|
|
17
|
+
}
|
|
18
|
+
async getSigner() {
|
|
19
|
+
if (this.signer && !this.signer.isDestroyed)
|
|
20
|
+
return this.signer;
|
|
21
|
+
// Prevent concurrent creation — reuse the in-flight promise
|
|
22
|
+
if (this.signerPromise)
|
|
23
|
+
return this.signerPromise;
|
|
24
|
+
this.signer = null;
|
|
25
|
+
const { apiSecret, serverUrl, apiKey } = this.getConfig();
|
|
26
|
+
this.signerPromise = ThresholdSigner.fromSecret({
|
|
27
|
+
apiSecret,
|
|
28
|
+
serverUrl,
|
|
29
|
+
apiKey,
|
|
30
|
+
scheme: new CGGMP24Scheme(),
|
|
31
|
+
})
|
|
32
|
+
.then((s) => {
|
|
33
|
+
this.signer = s;
|
|
34
|
+
this.signerPromise = null;
|
|
35
|
+
return s;
|
|
36
|
+
})
|
|
37
|
+
.catch((err) => {
|
|
38
|
+
this.signerPromise = null;
|
|
39
|
+
throw err;
|
|
40
|
+
});
|
|
41
|
+
return this.signerPromise;
|
|
42
|
+
}
|
|
43
|
+
getHttpClient() {
|
|
44
|
+
if (this.httpClient)
|
|
45
|
+
return this.httpClient;
|
|
46
|
+
const { serverUrl, apiKey } = this.getConfig();
|
|
47
|
+
this.httpClient = new HttpClient({ baseUrl: serverUrl, apiKey });
|
|
48
|
+
return this.httpClient;
|
|
49
|
+
}
|
|
50
|
+
getApi() {
|
|
51
|
+
if (this.api)
|
|
52
|
+
return this.api;
|
|
53
|
+
this.api = new AgentaApi(this.getHttpClient());
|
|
54
|
+
return this.api;
|
|
55
|
+
}
|
|
56
|
+
/** AGENTA_NETWORK — network name matching server's GET /api/v1/networks (e.g. "base-sepolia", "mainnet"). */
|
|
57
|
+
getNetwork() {
|
|
58
|
+
return process.env.AGENTA_NETWORK || null;
|
|
59
|
+
}
|
|
60
|
+
requireNetwork(networkParam) {
|
|
61
|
+
const network = networkParam || this.getNetwork();
|
|
62
|
+
if (!network) {
|
|
63
|
+
throw new Error('No network specified. Call agenta_list_networks first to see available networks, then pass the "network" parameter to this tool.');
|
|
64
|
+
}
|
|
65
|
+
return network;
|
|
66
|
+
}
|
|
67
|
+
getSignerAddress() {
|
|
68
|
+
return this.signer?.address;
|
|
69
|
+
}
|
|
70
|
+
destroy() {
|
|
71
|
+
if (this.signer && !this.signer.isDestroyed) {
|
|
72
|
+
this.signer.destroy();
|
|
73
|
+
}
|
|
74
|
+
this.signer = null;
|
|
75
|
+
this.signerPromise = null;
|
|
76
|
+
this.httpClient = null;
|
|
77
|
+
this.api = null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=signer-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer-manager.js","sourceRoot":"","sources":["../../src/lib/signer-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEvE,MAAM,OAAO,aAAa;IACjB,MAAM,GAA2B,IAAI,CAAC;IACtC,aAAa,GAAoC,IAAI,CAAC;IACtD,UAAU,GAAsB,IAAI,CAAC;IACrC,GAAG,GAAqB,IAAI,CAAC;IAE7B,SAAS;QAChB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAChD,MAAM,SAAS,GAAG,O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2
|
+
* Generate a 6-word BIP39 transfer code and derive the corresponding AES-256-GCM key.
|
|
3
|
+
*
|
|
4
|
+
* The words are randomly chosen from the BIP39 English wordlist (2048 words).
|
|
5
|
+
* 6 words = ~66 bits of entropy — sufficient for a 10-minute expiry window.
|
|
6
|
+
*
|
|
7
|
+
* The AES key is derived via HKDF-SHA256 with a fixed salt and transfer-specific info,
|
|
8
|
+
* binding the key to a specific transfer ID to prevent cross-transfer reuse.
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateTransferCode(transferId: string): {
|
|
11
|
+
words: string[];
|
|
12
|
+
transferKey: Uint8Array;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Derive the AES-256-GCM key from 6 BIP39 words and a transfer ID.
|
|
16
|
+
*
|
|
17
|
+
* Uses HKDF-SHA256 with:
|
|
18
|
+
* - IKM: space-joined lowercase words
|
|
19
|
+
* - Salt: 'agentaos-transfer-v1'
|
|
20
|
+
* - Info: 'aes-256-gcm:{transferId}'
|
|
21
|
+
*/
|
|
22
|
+
export declare function deriveTransferKey(words: string[], transferId: string): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Encrypt share bytes with AES-256-GCM using the transfer key.
|
|
25
|
+
*
|
|
26
|
+
* Returns base64-encoded ciphertext: IV (12 bytes) || ciphertext || tag (16 bytes).
|
|
27
|
+
*/
|
|
28
|
+
export declare function encryptShareForTransfer(shareBytes: Uint8Array, transferKey: Uint8Array): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Decrypt share bytes from AES-256-GCM ciphertext.
|
|
31
|
+
*
|
|
32
|
+
* Input: base64-encoded IV (12 bytes) || ciphertext || tag (16 bytes).
|
|
33
|
+
* Throws on wrong key (GCM tag verification failure).
|
|
34
|
+
*/
|
|
35
|
+
export declare function decryptShareFromTransfer(ciphertextBase64: string, transferKey: Uint8Array): Promise<Uint8Array>;
|
|
36
|
+
//# sourceMappingURL=transfer-crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-crypto.d.ts","sourceRoot":"","sources":["../../src/lib/transfer-crypto.ts"],"names":[],"mappings":"AAmBA;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG;IACzD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,UAAU,CAAC;CACxB,CAcA;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU,CAkBjF;AAeD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC5C,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAwBjB;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC7C,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,UAAU,GACrB,OAAO,CAAC,UAAU,CAAC,CA6BrB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { hkdf } from '@noble/hashes/hkdf';
|
|
3
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
4
|
+
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Constants
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
const HKDF_SALT = 'agentaos-transfer-v1';
|
|
9
|
+
const HKDF_INFO_PREFIX = 'aes-256-gcm:';
|
|
10
|
+
const WORD_COUNT = 6;
|
|
11
|
+
const AES_KEY_BYTES = 32;
|
|
12
|
+
const AES_IV_BYTES = 12;
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Transfer code generation & key derivation
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
/**
|
|
17
|
+
* Generate a 6-word BIP39 transfer code and derive the corresponding AES-256-GCM key.
|
|
18
|
+
*
|
|
19
|
+
* The words are randomly chosen from the BIP39 English wordlist (2048 words).
|
|
20
|
+
* 6 words = ~66 bits of entropy — sufficient for a 10-minute expiry window.
|
|
21
|
+
*
|
|
22
|
+
* The AES key is derived via HKDF-SHA256 with a fixed salt and transfer-specific info,
|
|
23
|
+
* binding the key to a specific transfer ID to prevent cross-transfer reuse.
|
|
24
|
+
*/
|
|
25
|
+
export function generateTransferCode(transferId) {
|
|
26
|
+
const entropy = randomBytes(WORD_COUNT * 2); // 2 bytes per word → 0..65535 mod 2048
|
|
27
|
+
const words = [];
|
|
28
|
+
for (let i = 0; i < WORD_COUNT; i++) {
|
|
29
|
+
const hi = entropy[i * 2];
|
|
30
|
+
const lo = entropy[i * 2 + 1];
|
|
31
|
+
const index = ((hi << 8) | lo) % wordlist.length;
|
|
32
|
+
words.push(wordlist[index]);
|
|
33
|
+
}
|
|
34
|
+
const transferKey = deriveTransferKey(words, transferId);
|
|
35
|
+
entropy.fill(0);
|
|
36
|
+
return { words, transferKey };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Derive the AES-256-GCM key from 6 BIP39 words and a transfer ID.
|
|
40
|
+
*
|
|
41
|
+
* Uses HKDF-SHA256 with:
|
|
42
|
+
* - IKM: space-joined lowercase words
|
|
43
|
+
* - Salt: 'agentaos-transfer-v1'
|
|
44
|
+
* - Info: 'aes-256-gcm:{transferId}'
|
|
45
|
+
*/
|
|
46
|
+
export function deriveTransferKey(words, transferId) {
|
|
47
|
+
if (words.length !== WORD_COUNT) {
|
|
48
|
+
throw new Error(`Expected ${WORD_COUNT} words, got ${words.length}`);
|
|
49
|
+
}
|
|
50
|
+
// Validate all words are in the BIP39 wordlist
|
|
51
|
+
const wordSet = new Set(wordlist);
|
|
52
|
+
for (const word of words) {
|
|
53
|
+
if (!wordSet.has(word.toLowerCase())) {
|
|
54
|
+
throw new Error(`Invalid word: "${word}". Must be a valid BIP39 word.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const ikm = new TextEncoder().encode(words.join(' ').toLowerCase());
|
|
58
|
+
const salt = new TextEncoder().encode(HKDF_SALT);
|
|
59
|
+
const info = new TextEncoder().encode(`${HKDF_INFO_PREFIX}${transferId}`);
|
|
60
|
+
return hkdf(sha256, ikm, salt, info, AES_KEY_BYTES);
|
|
61
|
+
}
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Internal helpers
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
/** Extract a plain ArrayBuffer from a Uint8Array (handles Buffer subarrays). */
|
|
66
|
+
function toArrayBuffer(buf) {
|
|
67
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
68
|
+
}
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// AES-256-GCM encrypt / decrypt
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
/**
|
|
73
|
+
* Encrypt share bytes with AES-256-GCM using the transfer key.
|
|
74
|
+
*
|
|
75
|
+
* Returns base64-encoded ciphertext: IV (12 bytes) || ciphertext || tag (16 bytes).
|
|
76
|
+
*/
|
|
77
|
+
export async function encryptShareForTransfer(shareBytes, transferKey) {
|
|
78
|
+
const iv = randomBytes(AES_IV_BYTES);
|
|
79
|
+
const key = await crypto.subtle.importKey('raw', toArrayBuffer(transferKey), { name: 'AES-GCM' }, false, ['encrypt']);
|
|
80
|
+
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({ name: 'AES-GCM', iv: toArrayBuffer(iv) }, key, toArrayBuffer(shareBytes)));
|
|
81
|
+
// Pack: IV || ciphertext (includes GCM tag)
|
|
82
|
+
const packed = new Uint8Array(iv.length + ciphertext.length);
|
|
83
|
+
packed.set(iv, 0);
|
|
84
|
+
packed.set(ciphertext, iv.length);
|
|
85
|
+
return Buffer.from(packed).toString('base64');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Decrypt share bytes from AES-256-GCM ciphertext.
|
|
89
|
+
*
|
|
90
|
+
* Input: base64-encoded IV (12 bytes) || ciphertext || tag (16 bytes).
|
|
91
|
+
* Throws on wrong key (GCM tag verification failure).
|
|
92
|
+
*/
|
|
93
|
+
export async function decryptShareFromTransfer(ciphertextBase64, transferKey) {
|
|
94
|
+
const packed = Buffer.from(ciphertextBase64, 'base64');
|
|
95
|
+
if (packed.length < AES_IV_BYTES + 16) {
|
|
96
|
+
throw new Error('Ciphertext too short — expected at least IV + GCM tag');
|
|
97
|
+
}
|
|
98
|
+
const iv = packed.subarray(0, AES_IV_BYTES);
|
|
99
|
+
const ciphertext = packed.subarray(AES_IV_BYTES);
|
|
100
|
+
const key = await crypto.subtle.importKey('raw', toArrayBuffer(transferKey), { name: 'AES-GCM' }, false, ['decrypt']);
|
|
101
|
+
try {
|
|
102
|
+
const plaintext = new Uint8Array(await crypto.subtle.decrypt({ name: 'AES-GCM', iv: toArrayBuffer(iv) }, key, toArrayBuffer(ciphertext)));
|
|
103
|
+
return plaintext;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new Error('Decryption failed — wrong transfer code or corrupted data');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=transfer-crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-crypto.js","sourceRoot":"","sources":["../../src/lib/transfer-crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAE7D,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,SAAS,GAAG,sBAAsB,CAAC;AACzC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AACxC,MAAM,UAAU,GAAG,CAAC,CAAC;AACr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AO,CAC1B,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,aAAa,CAAC,EAAE,CAAC,EAAE,EAC1C,GAAG,EACH,aAAa,CAAC,UAAU,CAAC,CACzB,CACD,CAAC;QACF,OAAO,SAAS,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC9E,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 Protocol Client for AgentaOS
|
|
3
|
+
*
|
|
4
|
+
* Supports the x402 **exact** payment scheme (ERC-3009 / Permit2) via @x402/evm.
|
|
5
|
+
* Both v2 (CAIP-2 networks, PAYMENT-REQUIRED/PAYMENT-SIGNATURE headers) and
|
|
6
|
+
* v1 (legacy network names, X-PAYMENT header) are supported.
|
|
7
|
+
*/
|
|
8
|
+
import type { ThresholdSigner } from '@agentaos/sdk';
|
|
9
|
+
import type { PaymentRequired } from '@x402/core/types';
|
|
10
|
+
export interface X402CheckResult {
|
|
11
|
+
requires402: boolean;
|
|
12
|
+
url: string;
|
|
13
|
+
paymentRequired?: PaymentRequired;
|
|
14
|
+
}
|
|
15
|
+
export interface X402FetchResult {
|
|
16
|
+
status: number;
|
|
17
|
+
url: string;
|
|
18
|
+
paid: boolean;
|
|
19
|
+
scheme?: string;
|
|
20
|
+
transaction?: string;
|
|
21
|
+
payer?: string;
|
|
22
|
+
contentType?: string;
|
|
23
|
+
body: string;
|
|
24
|
+
}
|
|
25
|
+
export interface X402DiscoverResult {
|
|
26
|
+
domain: string;
|
|
27
|
+
endpoints: Array<{
|
|
28
|
+
path: string;
|
|
29
|
+
method: string;
|
|
30
|
+
scheme?: string;
|
|
31
|
+
network?: string;
|
|
32
|
+
amount?: string;
|
|
33
|
+
asset?: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export interface X402FetchOptions {
|
|
38
|
+
/** Maximum amount willing to pay in atomic units (e.g., "1000000" = 1 USDC). */
|
|
39
|
+
maxAmount?: string;
|
|
40
|
+
/** Preferred token addresses in order. Reorders the accepts list. */
|
|
41
|
+
preferTokens?: string[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if a URL requires x402 payment. No signer needed.
|
|
45
|
+
*/
|
|
46
|
+
export declare function checkX402(url: string): Promise<X402CheckResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Discover x402-protected endpoints on a domain.
|
|
49
|
+
* Checks .well-known/x402 first, then probes common paths.
|
|
50
|
+
*/
|
|
51
|
+
export declare function discoverX402(domain: string): Promise<X402DiscoverResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Fetch a 402-protected resource, automatically paying via the x402 exact scheme.
|
|
54
|
+
*
|
|
55
|
+
* 1. GET → if not 402, return response
|
|
56
|
+
* 2. Parse PAYMENT-REQUIRED header → PaymentRequirements[]
|
|
57
|
+
* 3. Apply policies (maxAmount, preferTokens)
|
|
58
|
+
* 4. Sign EIP-712 payment payload via threshold signer
|
|
59
|
+
* 5. Retry with PAYMENT-SIGNATURE header
|
|
60
|
+
* 6. Parse settlement from PAYMENT-RESPONSE header
|
|
61
|
+
*/
|
|
62
|
+
export declare function fetchWithX402(url: string, signer: ThresholdSigner, opts?: X402FetchOptions): Promise<X402FetchResult>;
|
|
63
|
+
//# sourceMappingURL=x402-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-client.d.ts","sourceRoot":"","sources":["../../src/lib/x402-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAuB,MAAM,kBAAkB,CAAC;AAO7E,MAAM,WAAW,eAAe;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,CAAC,EAAE,eAAe,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|
+
* Supports the x402 **exact** payment scheme (ERC-3009 / Permit2) via @x402/evm.
|
|
5
|
+
* Both v2 (CAIP-2 networks, PAYMENT-REQUIRED/PAYMENT-SIGNATURE headers) and
|
|
6
|
+
* v1 (legacy network names, X-PAYMENT header) are supported.
|
|
7
|
+
*/
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Signer Bridge
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* Bridge ThresholdSigner → ClientEvmSigner for @x402/evm.
|
|
13
|
+
* ThresholdSigner.signMessage() detects EIP-712 typed data via `{ domain }`.
|
|
14
|
+
*/
|
|
15
|
+
function toX402Signer(signer) {
|
|
16
|
+
return {
|
|
17
|
+
address: signer.address,
|
|
18
|
+
async signTypedData(message) {
|
|
19
|
+
const result = await signer.signMessage(message);
|
|
20
|
+
return result.signature;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Header Parsing (for checkX402 / discoverX402 — no signer needed)
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
const PAYMENT_REQUIRED_HEADERS = ['payment-required', 'x-payment'];
|
|
28
|
+
const PAYMENT_RESPONSE_HEADERS = ['payment-response', 'x-payment-response'];
|
|
29
|
+
function decodeBase64Header(raw) {
|
|
30
|
+
return JSON.parse(Buffer.from(raw, 'base64').toString('utf-8'));
|
|
31
|
+
}
|
|
32
|
+
function readHeader(headers, names) {
|
|
33
|
+
for (const name of names) {
|
|
34
|
+
const val = headers.get(name);
|
|
35
|
+
if (val)
|
|
36
|
+
return val;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
async function parsePaymentRequired(response) {
|
|
41
|
+
const raw = readHeader(response.headers, PAYMENT_REQUIRED_HEADERS);
|
|
42
|
+
if (raw) {
|
|
43
|
+
try {
|
|
44
|
+
return decodeBase64Header(raw);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Malformed header — try body
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const ct = response.headers.get('content-type') || '';
|
|
51
|
+
if (ct.includes('json')) {
|
|
52
|
+
try {
|
|
53
|
+
const body = (await response.json());
|
|
54
|
+
if (Array.isArray(body.accepts))
|
|
55
|
+
return body;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Not JSON
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
function parseSettlement(headers) {
|
|
64
|
+
const raw = readHeader(headers, PAYMENT_RESPONSE_HEADERS);
|
|
65
|
+
if (!raw)
|
|
66
|
+
return null;
|
|
67
|
+
try {
|
|
68
|
+
return decodeBase64Header(raw);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Policies
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
function maxAmountPolicy(max) {
|
|
78
|
+
const limit = BigInt(max);
|
|
79
|
+
return (_v, reqs) => reqs.filter((r) => BigInt(r.amount) <= limit);
|
|
80
|
+
}
|
|
81
|
+
function preferTokensPolicy(tokens) {
|
|
82
|
+
const normalized = tokens.map((t) => t.toLowerCase());
|
|
83
|
+
return (_v, reqs) => {
|
|
84
|
+
const preferred = new Array(normalized.length);
|
|
85
|
+
const rest = [];
|
|
86
|
+
for (const r of reqs) {
|
|
87
|
+
const idx = normalized.indexOf(r.asset.toLowerCase());
|
|
88
|
+
if (idx >= 0)
|
|
89
|
+
preferred[idx] = r;
|
|
90
|
+
else
|
|
91
|
+
rest.push(r);
|
|
92
|
+
}
|
|
93
|
+
return [...preferred.filter(Boolean), ...rest];
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// x402 Client Factory
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
async function createHttpClient(signer, opts) {
|
|
100
|
+
const { x402Client, x402HTTPClient } = await import('@x402/core/client');
|
|
101
|
+
const { registerExactEvmScheme } = await import('@x402/evm/exact/client');
|
|
102
|
+
const client = new x402Client();
|
|
103
|
+
registerExactEvmScheme(client, { signer: toX402Signer(signer) });
|
|
104
|
+
if (opts?.maxAmount)
|
|
105
|
+
client.registerPolicy(maxAmountPolicy(opts.maxAmount));
|
|
106
|
+
if (opts?.preferTokens?.length)
|
|
107
|
+
client.registerPolicy(preferTokensPolicy(opts.preferTokens));
|
|
108
|
+
return new x402HTTPClient(client);
|
|
109
|
+
}
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Public API
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
/**
|
|
114
|
+
* Check if a URL requires x402 payment. No signer needed.
|
|
115
|
+
*/
|
|
116
|
+
export async function checkX402(url) {
|
|
117
|
+
const response = await fetch(url, {
|
|
118
|
+
method: 'GET',
|
|
119
|
+
signal: AbortSignal.timeout(15_000),
|
|
120
|
+
redirect: 'follow',
|
|
121
|
+
});
|
|
122
|
+
if (response.status !== 402) {
|
|
123
|
+
return { requires402: false, url };
|
|
124
|
+
}
|
|
125
|
+
const paymentRequired = await parsePaymentRequired(response);
|
|
126
|
+
return { requires402: true, url, paymentRequired: paymentRequired ?? undefined };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Discover x402-protected endpoints on a domain.
|
|
130
|
+
* Checks .well-known/x402 first, then probes common paths.
|
|
131
|
+
*/
|
|
132
|
+
export async function discoverX402(domain) {
|
|
133
|
+
const baseUrl = domain.startsWith('http') ? domain : `https://${domain}`;
|
|
134
|
+
const endpoints = [];
|
|
135
|
+
// 1. Try .well-known/x402 (returns endpoint manifest)
|
|
136
|
+
try {
|
|
137
|
+
const wellKnown = await fetch(`${baseUrl}/.well-known/x402`, {
|
|
138
|
+
signal: AbortSignal.timeout(10_000),
|
|
139
|
+
});
|
|
140
|
+
if (wellKnown.ok) {
|
|
141
|
+
const body = (await wellKnown.json());
|
|
142
|
+
if (body.endpoints) {
|
|
143
|
+
for (const ep of body.endpoints) {
|
|
144
|
+
endpoints.push({
|
|
145
|
+
path: String(ep.path || '/'),
|
|
146
|
+
method: String(ep.method || 'GET'),
|
|
147
|
+
scheme: ep.scheme ? String(ep.scheme) : undefined,
|
|
148
|
+
network: ep.network ? String(ep.network) : undefined,
|
|
149
|
+
amount: ep.amount ? String(ep.amount) : undefined,
|
|
150
|
+
asset: ep.asset ? String(ep.asset) : undefined,
|
|
151
|
+
description: ep.description ? String(ep.description) : undefined,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return { domain, endpoints };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// No well-known endpoint
|
|
160
|
+
}
|
|
161
|
+
// 2. Probe common paths (well-known not included — already checked above)
|
|
162
|
+
const probePaths = ['/', '/api', '/api/v1', '/data', '/premium', '/content'];
|
|
163
|
+
const probes = probePaths.map(async (path) => {
|
|
164
|
+
try {
|
|
165
|
+
const result = await checkX402(`${baseUrl}${path}`);
|
|
166
|
+
if (result.requires402 && result.paymentRequired) {
|
|
167
|
+
for (const req of result.paymentRequired.accepts) {
|
|
168
|
+
endpoints.push({
|
|
169
|
+
path,
|
|
170
|
+
method: 'GET',
|
|
171
|
+
scheme: req.scheme,
|
|
172
|
+
network: req.network,
|
|
173
|
+
amount: req.amount,
|
|
174
|
+
asset: req.asset,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// Unreachable
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
await Promise.allSettled(probes);
|
|
184
|
+
return { domain, endpoints };
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Fetch a 402-protected resource, automatically paying via the x402 exact scheme.
|
|
188
|
+
*
|
|
189
|
+
* 1. GET → if not 402, return response
|
|
190
|
+
* 2. Parse PAYMENT-REQUIRED header → PaymentRequirements[]
|
|
191
|
+
* 3. Apply policies (maxAmount, preferTokens)
|
|
192
|
+
* 4. Sign EIP-712 payment payload via threshold signer
|
|
193
|
+
* 5. Retry with PAYMENT-SIGNATURE header
|
|
194
|
+
* 6. Parse settlement from PAYMENT-RESPONSE header
|
|
195
|
+
*/
|
|
196
|
+
export async function fetchWithX402(url, signer, opts) {
|
|
197
|
+
const initial = await fetch(url, {
|
|
198
|
+
method: 'GET',
|
|
199
|
+
signal: AbortSignal.timeout(15_000),
|
|
200
|
+
redirect: 'follow',
|
|
201
|
+
});
|
|
202
|
+
if (initial.status !== 402) {
|
|
203
|
+
return {
|
|
204
|
+
status: initial.status,
|
|
205
|
+
url,
|
|
206
|
+
paid: false,
|
|
207
|
+
contentType: initial.headers.get('content-type') || undefined,
|
|
208
|
+
body: await initial.text(),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const paymentRequired = await parsePaymentRequired(initial);
|
|
212
|
+
if (!paymentRequired?.accepts?.length) {
|
|
213
|
+
throw new Error('402 response but could not parse payment requirements');
|
|
214
|
+
}
|
|
215
|
+
const httpClient = await createHttpClient(signer, opts);
|
|
216
|
+
const paymentPayload = await httpClient.createPaymentPayload(paymentRequired);
|
|
217
|
+
const paymentHeaders = httpClient.encodePaymentSignatureHeader(paymentPayload);
|
|
218
|
+
const paidResponse = await fetch(url, {
|
|
219
|
+
method: 'GET',
|
|
220
|
+
headers: paymentHeaders,
|
|
221
|
+
signal: AbortSignal.timeout(30_000),
|
|
222
|
+
redirect: 'follow',
|
|
223
|
+
});
|
|
224
|
+
const settlement = parseSettlement(paidResponse.headers);
|
|
225
|
+
return {
|
|
226
|
+
status: paidResponse.status,
|
|
227
|
+
url,
|
|
228
|
+
paid: true,
|
|
229
|
+
scheme: 'exact',
|
|
230
|
+
transaction: settlement?.transaction,
|
|
231
|
+
payer: settlement?.payer,
|
|
232
|
+
contentType: paidResponse.headers.get('content-type') || undefined,
|
|
233
|
+
body: await paidResponse.text(),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=x402-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-client.js","sourceRoot":"","sources":["../../src/lib/x402-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA+CH,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,YAAY,CAAC,MAAuB;IAC5C,OAAO;QACN,OAAO,EAAE,MAAM,CAAC,OAAwB;QACxC,KAAK,CAAC,aAAa,CAAC,OAKnB;YACA,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACjD,OAAO,MAAM,CAAC,SAA0B,CAAC;QAC1C,CAAC;KACD,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,mEAAmE;AACnE,8EAA8E;AAE9E,MAAM,wBAAwB,GAAG,CAAC,kBAAkB,EAAE,WAAW,CAAU,CAAC;AAC5E,MAAM,wBAAwB,GAAG,CAAC,kBAAkB,EAAE,oBAAoB,CAAU,CAAC;AAErF,SAAS,kBAAkB,CAAI,GAAW;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,UAAU,CAAC,OAAgB,EAAE,KAAwB;IAC7D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,KAAK,UAAU,oBAAoB,CAAC,QAAkB;IACrD,MA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