@absol-labs/agent 0.10.0 → 0.12.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -30
- package/dist/capability/invocation-capability.d.ts +20 -8
- package/dist/capability/invocation-capability.d.ts.map +1 -1
- package/dist/capability/invocation-capability.js.map +1 -1
- package/dist/capability/probe-capability.d.ts +225 -0
- package/dist/capability/probe-capability.d.ts.map +1 -0
- package/dist/capability/probe-capability.js +248 -0
- package/dist/capability/probe-capability.js.map +1 -0
- package/dist/cli/args.d.ts +11 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +23 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/commands/claim.d.ts.map +1 -1
- package/dist/cli/commands/claim.js +21 -5
- package/dist/cli/commands/claim.js.map +1 -1
- package/dist/cli/commands/close.d.ts.map +1 -1
- package/dist/cli/commands/close.js +51 -7
- package/dist/cli/commands/close.js.map +1 -1
- package/dist/cli/commands/invoke.d.ts +2 -0
- package/dist/cli/commands/invoke.d.ts.map +1 -1
- package/dist/cli/commands/invoke.js +3 -2
- package/dist/cli/commands/invoke.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +15 -2
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/open.d.ts.map +1 -1
- package/dist/cli/commands/open.js +121 -15
- package/dist/cli/commands/open.js.map +1 -1
- package/dist/cli/commands/pay.d.ts +19 -0
- package/dist/cli/commands/pay.d.ts.map +1 -0
- package/dist/cli/commands/pay.js +355 -0
- package/dist/cli/commands/pay.js.map +1 -0
- package/dist/cli/commands/reclaim-unverified.d.ts.map +1 -1
- package/dist/cli/commands/reclaim-unverified.js +15 -6
- package/dist/cli/commands/reclaim-unverified.js.map +1 -1
- package/dist/cli/commands/reclaim.d.ts +23 -2
- package/dist/cli/commands/reclaim.d.ts.map +1 -1
- package/dist/cli/commands/reclaim.js +200 -21
- package/dist/cli/commands/reclaim.js.map +1 -1
- package/dist/cli/commands/refund.d.ts +13 -0
- package/dist/cli/commands/refund.d.ts.map +1 -0
- package/dist/cli/commands/refund.js +224 -0
- package/dist/cli/commands/refund.js.map +1 -0
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +10 -1
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/streams.js +9 -13
- package/dist/cli/commands/streams.js.map +1 -1
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +2 -1
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/config.d.ts +44 -26
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +88 -38
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/deps.d.ts +86 -7
- package/dist/cli/deps.d.ts.map +1 -1
- package/dist/cli/deps.js +102 -16
- package/dist/cli/deps.js.map +1 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/errors.js +21 -1
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/escape-hatch.d.ts +6 -4
- package/dist/cli/escape-hatch.d.ts.map +1 -1
- package/dist/cli/escape-hatch.js +6 -2
- package/dist/cli/escape-hatch.js.map +1 -1
- package/dist/cli/listings.d.ts +18 -0
- package/dist/cli/listings.d.ts.map +1 -1
- package/dist/cli/listings.js +22 -12
- package/dist/cli/listings.js.map +1 -1
- package/dist/cli/preflight.d.ts +20 -14
- package/dist/cli/preflight.d.ts.map +1 -1
- package/dist/cli/preflight.js +34 -20
- package/dist/cli/preflight.js.map +1 -1
- package/dist/cli/privy.d.ts +83 -0
- package/dist/cli/privy.d.ts.map +1 -0
- package/dist/cli/privy.js +232 -0
- package/dist/cli/privy.js.map +1 -0
- package/dist/cli/reclaimability.d.ts +82 -0
- package/dist/cli/reclaimability.d.ts.map +1 -0
- package/dist/cli/reclaimability.js +80 -0
- package/dist/cli/reclaimability.js.map +1 -0
- package/dist/cli/run.d.ts +2 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +40 -11
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/scan-range.d.ts +2 -2
- package/dist/cli/scan-range.js +2 -2
- package/dist/cli/spend-policy.d.ts +60 -0
- package/dist/cli/spend-policy.d.ts.map +1 -0
- package/dist/cli/spend-policy.js +65 -0
- package/dist/cli/spend-policy.js.map +1 -0
- package/dist/cli/status.d.ts +3 -1
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +15 -3
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/wallet.d.ts +109 -40
- package/dist/cli/wallet.d.ts.map +1 -1
- package/dist/cli/wallet.js +109 -44
- package/dist/cli/wallet.js.map +1 -1
- package/dist/discovery/rate-band.d.ts +74 -0
- package/dist/discovery/rate-band.d.ts.map +1 -0
- package/dist/discovery/rate-band.js +114 -0
- package/dist/discovery/rate-band.js.map +1 -0
- package/dist/escrow-generation.d.ts +81 -0
- package/dist/escrow-generation.d.ts.map +1 -0
- package/dist/escrow-generation.js +76 -0
- package/dist/escrow-generation.js.map +1 -0
- package/dist/frameworks/agentkit.d.ts +8 -4
- package/dist/frameworks/agentkit.d.ts.map +1 -1
- package/dist/frameworks/agentkit.js +27 -10
- package/dist/frameworks/agentkit.js.map +1 -1
- package/dist/frameworks/eliza.d.ts +3 -3
- package/dist/frameworks/eliza.d.ts.map +1 -1
- package/dist/frameworks/eliza.js +15 -6
- package/dist/frameworks/eliza.js.map +1 -1
- package/dist/frameworks/langchain.d.ts.map +1 -1
- package/dist/frameworks/langchain.js +8 -0
- package/dist/frameworks/langchain.js.map +1 -1
- package/dist/gateway/caller-auth-gateway.d.ts +91 -4
- package/dist/gateway/caller-auth-gateway.d.ts.map +1 -1
- package/dist/gateway/caller-auth-gateway.js +184 -7
- package/dist/gateway/caller-auth-gateway.js.map +1 -1
- package/dist/gateway/http-server.d.ts +121 -1
- package/dist/gateway/http-server.d.ts.map +1 -1
- package/dist/gateway/http-server.js +474 -5
- package/dist/gateway/http-server.js.map +1 -1
- package/dist/gateway/probe-auth.d.ts +112 -0
- package/dist/gateway/probe-auth.d.ts.map +1 -0
- package/dist/gateway/probe-auth.js +127 -0
- package/dist/gateway/probe-auth.js.map +1 -0
- package/dist/gateway/signed-rate-bounds.d.ts +51 -0
- package/dist/gateway/signed-rate-bounds.d.ts.map +1 -0
- package/dist/gateway/signed-rate-bounds.js +94 -0
- package/dist/gateway/signed-rate-bounds.js.map +1 -0
- package/dist/gateway/x402-opener-mode.d.ts +215 -0
- package/dist/gateway/x402-opener-mode.d.ts.map +1 -0
- package/dist/gateway/x402-opener-mode.js +639 -0
- package/dist/gateway/x402-opener-mode.js.map +1 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/mandates/env.d.ts +3 -2
- package/dist/mandates/env.d.ts.map +1 -1
- package/dist/mandates/env.js +3 -2
- package/dist/mandates/env.js.map +1 -1
- package/dist/mcp/server.d.ts +100 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +719 -39
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/service-invoker.d.ts +97 -0
- package/dist/mcp/service-invoker.d.ts.map +1 -0
- package/dist/mcp/service-invoker.js +167 -0
- package/dist/mcp/service-invoker.js.map +1 -0
- package/dist/mcp/x402-tools.d.ts +104 -0
- package/dist/mcp/x402-tools.d.ts.map +1 -0
- package/dist/mcp/x402-tools.js +434 -0
- package/dist/mcp/x402-tools.js.map +1 -0
- package/dist/network.d.ts +119 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +199 -0
- package/dist/network.js.map +1 -0
- package/dist/sdk/invoke.d.ts +23 -4
- package/dist/sdk/invoke.d.ts.map +1 -1
- package/dist/sdk/invoke.js +71 -10
- package/dist/sdk/invoke.js.map +1 -1
- package/dist/wallet/autonomous-wallet-broker.d.ts +3 -0
- package/dist/wallet/autonomous-wallet-broker.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet-broker.js +27 -23
- package/dist/wallet/autonomous-wallet-broker.js.map +1 -1
- package/dist/wallet/autonomous-wallet-protocol.d.ts +8 -2
- package/dist/wallet/autonomous-wallet-protocol.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet-protocol.js +9 -2
- package/dist/wallet/autonomous-wallet-protocol.js.map +1 -1
- package/dist/wallet/autonomous-wallet.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet.js +3 -2
- package/dist/wallet/autonomous-wallet.js.map +1 -1
- package/dist/wallet/broker-escrows.d.ts +222 -0
- package/dist/wallet/broker-escrows.d.ts.map +1 -0
- package/dist/wallet/broker-escrows.js +36 -0
- package/dist/wallet/broker-escrows.js.map +1 -0
- package/dist/wallet/lifecycle.d.ts +21 -5
- package/dist/wallet/lifecycle.d.ts.map +1 -1
- package/dist/wallet/lifecycle.js +32 -12
- package/dist/wallet/lifecycle.js.map +1 -1
- package/dist/wallet/privy-broker-server.d.ts.map +1 -1
- package/dist/wallet/privy-broker-server.js +31 -26
- package/dist/wallet/privy-broker-server.js.map +1 -1
- package/dist/wallet/privy-session-broker.d.ts +14 -5
- package/dist/wallet/privy-session-broker.d.ts.map +1 -1
- package/dist/wallet/privy-session-broker.js +29 -17
- package/dist/wallet/privy-session-broker.js.map +1 -1
- package/dist/wallet/privy-session-provider.d.ts +3 -1
- package/dist/wallet/privy-session-provider.d.ts.map +1 -1
- package/dist/wallet/privy-session-provider.js +5 -3
- package/dist/wallet/privy-session-provider.js.map +1 -1
- package/dist/wallet/provider.d.ts.map +1 -1
- package/dist/wallet/provider.js +15 -8
- package/dist/wallet/provider.js.map +1 -1
- package/dist/x402/facilitator.d.ts +42 -17
- package/dist/x402/facilitator.d.ts.map +1 -1
- package/dist/x402/facilitator.js +49 -33
- package/dist/x402/facilitator.js.map +1 -1
- package/dist/x402-buyer/guarded-fetch.d.ts +51 -0
- package/dist/x402-buyer/guarded-fetch.d.ts.map +1 -0
- package/dist/x402-buyer/guarded-fetch.js +147 -0
- package/dist/x402-buyer/guarded-fetch.js.map +1 -0
- package/dist/x402-buyer/index.d.ts +10 -0
- package/dist/x402-buyer/index.d.ts.map +1 -0
- package/dist/x402-buyer/index.js +10 -0
- package/dist/x402-buyer/index.js.map +1 -0
- package/dist/x402-buyer/pay.d.ts +135 -0
- package/dist/x402-buyer/pay.d.ts.map +1 -0
- package/dist/x402-buyer/pay.js +336 -0
- package/dist/x402-buyer/pay.js.map +1 -0
- package/dist/x402-opener/abi.d.ts +684 -0
- package/dist/x402-opener/abi.d.ts.map +1 -0
- package/dist/x402-opener/abi.js +880 -0
- package/dist/x402-opener/abi.js.map +1 -0
- package/dist/x402-opener/facilitator-entry.d.ts +3 -0
- package/dist/x402-opener/facilitator-entry.d.ts.map +1 -0
- package/dist/x402-opener/facilitator-entry.js +37 -0
- package/dist/x402-opener/facilitator-entry.js.map +1 -0
- package/dist/x402-opener/facilitator-server.d.ts +180 -0
- package/dist/x402-opener/facilitator-server.d.ts.map +1 -0
- package/dist/x402-opener/facilitator-server.js +696 -0
- package/dist/x402-opener/facilitator-server.js.map +1 -0
- package/dist/x402-opener/index.d.ts +14 -0
- package/dist/x402-opener/index.d.ts.map +1 -0
- package/dist/x402-opener/index.js +14 -0
- package/dist/x402-opener/index.js.map +1 -0
- package/dist/x402-opener/listing-resolver.d.ts +55 -0
- package/dist/x402-opener/listing-resolver.d.ts.map +1 -0
- package/dist/x402-opener/listing-resolver.js +125 -0
- package/dist/x402-opener/listing-resolver.js.map +1 -0
- package/dist/x402-opener/refund-relay.d.ts +240 -0
- package/dist/x402-opener/refund-relay.d.ts.map +1 -0
- package/dist/x402-opener/refund-relay.js +1240 -0
- package/dist/x402-opener/refund-relay.js.map +1 -0
- package/dist/x402-opener/relayer-queue.d.ts +14 -0
- package/dist/x402-opener/relayer-queue.d.ts.map +1 -0
- package/dist/x402-opener/relayer-queue.js +18 -0
- package/dist/x402-opener/relayer-queue.js.map +1 -0
- package/dist/x402-opener/scheme.d.ts +217 -0
- package/dist/x402-opener/scheme.d.ts.map +1 -0
- package/dist/x402-opener/scheme.js +749 -0
- package/dist/x402-opener/scheme.js.map +1 -0
- package/dist/x402-opener/terms.d.ts +105 -0
- package/dist/x402-opener/terms.d.ts.map +1 -0
- package/dist/x402-opener/terms.js +212 -0
- package/dist/x402-opener/terms.js.map +1 -0
- package/dist/zktls/reclaim.d.ts +2 -2
- package/docs/agent-layer.md +13 -8
- package/docs/autonomous-privy-wallet.md +188 -0
- package/docs/cli.md +342 -53
- package/docs/langchain.md +5 -0
- package/docs/mcp-hosted.md +4 -3
- package/docs/mcp-reference.md +245 -0
- package/docs/probe-capability.md +191 -0
- package/docs/quickstart.md +54 -5
- package/docs/threat-model.md +24 -3
- package/docs/x402.md +681 -0
- package/package.json +19 -6
- package/src/capability/invocation-capability.ts +17 -1
- package/src/capability/probe-capability.ts +355 -0
- package/src/cli/args.ts +29 -0
- package/src/cli/commands/claim.ts +31 -5
- package/src/cli/commands/close.ts +56 -7
- package/src/cli/commands/invoke.ts +6 -2
- package/src/cli/commands/mcp.ts +18 -2
- package/src/cli/commands/open.ts +151 -14
- package/src/cli/commands/pay.ts +442 -0
- package/src/cli/commands/reclaim-unverified.ts +24 -6
- package/src/cli/commands/reclaim.ts +274 -19
- package/src/cli/commands/refund.ts +277 -0
- package/src/cli/commands/status.ts +17 -1
- package/src/cli/commands/streams.ts +11 -15
- package/src/cli/commands/watch.ts +7 -1
- package/src/cli/config.ts +139 -52
- package/src/cli/deps.ts +189 -25
- package/src/cli/errors.ts +24 -1
- package/src/cli/escape-hatch.ts +19 -5
- package/src/cli/listings.ts +43 -10
- package/src/cli/preflight.ts +36 -21
- package/src/cli/privy.ts +398 -0
- package/src/cli/reclaimability.ts +154 -0
- package/src/cli/run.ts +54 -11
- package/src/cli/scan-range.ts +2 -2
- package/src/cli/spend-policy.ts +139 -0
- package/src/cli/status.ts +14 -1
- package/src/cli/wallet.ts +189 -58
- package/src/discovery/rate-band.ts +172 -0
- package/src/escrow-generation.ts +135 -0
- package/src/frameworks/agentkit.ts +45 -11
- package/src/frameworks/eliza.ts +27 -5
- package/src/frameworks/langchain.ts +14 -0
- package/src/gateway/caller-auth-gateway.ts +336 -13
- package/src/gateway/http-server.ts +690 -7
- package/src/gateway/probe-auth.ts +191 -0
- package/src/gateway/signed-rate-bounds.ts +164 -0
- package/src/gateway/x402-opener-mode.ts +974 -0
- package/src/index.ts +112 -14
- package/src/mandates/env.ts +3 -2
- package/src/mcp/server.ts +973 -44
- package/src/mcp/service-invoker.ts +285 -0
- package/src/mcp/x402-tools.ts +621 -0
- package/src/network.ts +302 -0
- package/src/sdk/invoke.ts +96 -17
- package/src/wallet/autonomous-wallet-broker.ts +46 -20
- package/src/wallet/autonomous-wallet-protocol.ts +11 -2
- package/src/wallet/autonomous-wallet.ts +4 -2
- package/src/wallet/broker-escrows.ts +66 -0
- package/src/wallet/lifecycle.ts +53 -18
- package/src/wallet/privy-broker-server.ts +35 -25
- package/src/wallet/privy-session-broker.ts +58 -25
- package/src/wallet/privy-session-provider.ts +7 -3
- package/src/wallet/provider.ts +20 -15
- package/src/x402/facilitator.ts +85 -46
- package/src/x402-buyer/guarded-fetch.ts +213 -0
- package/src/x402-buyer/index.ts +9 -0
- package/src/x402-buyer/pay.ts +517 -0
- package/src/x402-opener/abi.ts +881 -0
- package/src/x402-opener/facilitator-entry.ts +45 -0
- package/src/x402-opener/facilitator-server.ts +1014 -0
- package/src/x402-opener/index.ts +13 -0
- package/src/x402-opener/listing-resolver.ts +202 -0
- package/src/x402-opener/refund-relay.ts +1743 -0
- package/src/x402-opener/relayer-queue.ts +18 -0
- package/src/x402-opener/scheme.ts +1133 -0
- package/src/x402-opener/terms.ts +300 -0
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absol-labs/agent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Metrik agent layer:
|
|
3
|
+
"version": "0.12.0-rc.1",
|
|
4
|
+
"description": "Metrik agent layer: verified-streaming USDC payments metered by delivery, an MCP server, framework tools, and spend mandates so AI agents can hire and pay verified services safely.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Absol Labs",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"metrik",
|
|
9
|
-
"x402",
|
|
10
9
|
"mcp",
|
|
11
10
|
"ai-agents",
|
|
12
11
|
"spend-mandate",
|
|
@@ -21,7 +20,8 @@
|
|
|
21
20
|
"metrik": "dist/cli/bin.js",
|
|
22
21
|
"metrik-mcp": "dist/mcp/stdio.js",
|
|
23
22
|
"metrik-mcp-http": "dist/mcp/http-server.js",
|
|
24
|
-
"metrik-gateway": "dist/gateway/server-entry.js"
|
|
23
|
+
"metrik-gateway": "dist/gateway/server-entry.js",
|
|
24
|
+
"metrik-x402-opener-facilitator": "dist/x402-opener/facilitator-entry.js"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
@@ -48,6 +48,14 @@
|
|
|
48
48
|
"types": "./dist/frameworks/crewai.d.ts",
|
|
49
49
|
"import": "./dist/frameworks/crewai.js"
|
|
50
50
|
},
|
|
51
|
+
"./x402-opener": {
|
|
52
|
+
"types": "./dist/x402-opener/index.d.ts",
|
|
53
|
+
"import": "./dist/x402-opener/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./x402-buyer": {
|
|
56
|
+
"types": "./dist/x402-buyer/index.d.ts",
|
|
57
|
+
"import": "./dist/x402-buyer/index.js"
|
|
58
|
+
},
|
|
51
59
|
"./package.json": "./package.json",
|
|
52
60
|
"./*": {
|
|
53
61
|
"types": "./dist/*.d.ts",
|
|
@@ -77,11 +85,13 @@
|
|
|
77
85
|
"pnpm": "9.15.x"
|
|
78
86
|
},
|
|
79
87
|
"dependencies": {
|
|
80
|
-
"@absol-labs/sdk": "
|
|
81
|
-
"@absol-labs/shared": "
|
|
88
|
+
"@absol-labs/sdk": "0.10.0-rc.2",
|
|
89
|
+
"@absol-labs/shared": "0.14.0-rc.1",
|
|
82
90
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
83
91
|
"@napi-rs/keyring": "1.3.0",
|
|
84
92
|
"@privy-io/node": "0.33.0",
|
|
93
|
+
"@x402/core": "2.27.0",
|
|
94
|
+
"@x402/evm": "2.27.0",
|
|
85
95
|
"reflect-metadata": "^0.2.2",
|
|
86
96
|
"viem": "^2.21.0",
|
|
87
97
|
"zod": "^3.24.0"
|
|
@@ -123,6 +133,7 @@
|
|
|
123
133
|
"@reclaimprotocol/zk-fetch": "^1.0.0",
|
|
124
134
|
"@swc/core": "^1.10.0",
|
|
125
135
|
"@types/node": "^20.17.0",
|
|
136
|
+
"@x402/fetch": "2.27.0",
|
|
126
137
|
"prettier": "^3.4.0",
|
|
127
138
|
"tsx": "^4.19.0",
|
|
128
139
|
"typescript": "^5.7.0",
|
|
@@ -135,7 +146,9 @@
|
|
|
135
146
|
"mcp:stdio": "tsx src/mcp/stdio.ts",
|
|
136
147
|
"mcp:http": "tsx src/mcp/http-server.ts",
|
|
137
148
|
"gateway": "tsx src/gateway/server-entry.ts",
|
|
149
|
+
"x402-opener:facilitator": "tsx src/x402-opener/facilitator-entry.ts",
|
|
138
150
|
"e2e:cdp": "node dist-e2e/scripts/e2e-cdp.js",
|
|
151
|
+
"e2e:x402": "node dist-e2e/scripts/e2e-x402.js",
|
|
139
152
|
"e2e:hire": "tsx scripts/e2e-hire.ts",
|
|
140
153
|
"l2:proof": "node scripts/l2-proof.mjs",
|
|
141
154
|
"test": "vitest run",
|
|
@@ -172,11 +172,27 @@ export function buildInvocationCapabilityTypedData(
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
/**
|
|
176
|
+
* The minimum an account must expose to sign a capability: its address, and
|
|
177
|
+
* EIP-712 signing.
|
|
178
|
+
*
|
|
179
|
+
* Deliberately narrower than viem's `LocalAccount`. Every wallet this package
|
|
180
|
+
* resolves signs typed data — a raw key, a CDP server account via `toAccount()`,
|
|
181
|
+
* a Privy embedded EOA — but only the raw-key one is a `LocalAccount` by TYPE.
|
|
182
|
+
* Demanding the full interface would have meant the MCP server could only ever
|
|
183
|
+
* invoke with a raw key, which is the wallet an MCP host is least likely to be
|
|
184
|
+
* configured with. Widening a parameter type breaks no existing caller.
|
|
185
|
+
*/
|
|
186
|
+
export type InvocationCapabilitySigner = Pick<
|
|
187
|
+
LocalAccount,
|
|
188
|
+
"address" | "signTypedData"
|
|
189
|
+
>;
|
|
190
|
+
|
|
175
191
|
/** Signs an `InvocationCapability` with the buyer's own wallet. */
|
|
176
192
|
export async function signInvocationCapability(
|
|
177
193
|
capability: InvocationCapability,
|
|
178
194
|
domain: InvocationCapabilityDomainInput,
|
|
179
|
-
account:
|
|
195
|
+
account: InvocationCapabilitySigner,
|
|
180
196
|
): Promise<Hex> {
|
|
181
197
|
const typedData = buildInvocationCapabilityTypedData(capability, domain);
|
|
182
198
|
return account.signTypedData(typedData);
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getAddress,
|
|
5
|
+
isAddress,
|
|
6
|
+
isHex,
|
|
7
|
+
recoverTypedDataAddress,
|
|
8
|
+
type Address,
|
|
9
|
+
type Hex,
|
|
10
|
+
type LocalAccount,
|
|
11
|
+
} from "viem";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
hashInvocationPath,
|
|
16
|
+
httpMethodSchema,
|
|
17
|
+
normalizeInvocationPath,
|
|
18
|
+
} from "./invocation-capability.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `ProbeCapability` — the ORACLE-signed EIP-712 credential that lets the
|
|
22
|
+
* neutral verifier exercise the PAID route of a `gated` listing.
|
|
23
|
+
*
|
|
24
|
+
* ## The gap this closes
|
|
25
|
+
*
|
|
26
|
+
* A gated listing's paid route requires an `InvocationCapability` signed by the
|
|
27
|
+
* stream's BUYER (see `./invocation-capability.ts`). The oracle is not a buyer
|
|
28
|
+
* and holds no buyer key, so before this type existed the oracle could only
|
|
29
|
+
* probe a gated service's HEALTH route. "The seller earns only for intervals
|
|
30
|
+
* that verified" therefore meant "the health endpoint answered" — not "the paid
|
|
31
|
+
* route delivered". This capability is the missing credential.
|
|
32
|
+
*
|
|
33
|
+
* ## Why this is not just "give the workers a credential"
|
|
34
|
+
*
|
|
35
|
+
* Three properties, all load-bearing:
|
|
36
|
+
*
|
|
37
|
+
* 1. **No shared secret.** Authority is an EIP-712 signature by an address in
|
|
38
|
+
* the escrow's `getOracleSigners()`. That list is PUBLICLY READABLE on-chain,
|
|
39
|
+
* so a third-party seller performs the identical check with no credential
|
|
40
|
+
* distribution, no registration, and nothing for either side to leak.
|
|
41
|
+
* 2. **No signing key leaves the coordinator.** The oracle coordinator mints one
|
|
42
|
+
* fresh capability per probe and hands the encoded header to the regional
|
|
43
|
+
* worker. A worker holds a bearer token for the coordinator and nothing else;
|
|
44
|
+
* compromising every worker yields no ability to mint a capability.
|
|
45
|
+
* 3. **Not stream-bound.** Deliberately carries NO `streamId` and NO `buyer`.
|
|
46
|
+
* That is what makes the same mechanism usable to probe a listing that has no
|
|
47
|
+
* stream at all — and it is also the structural guarantee that a probe can
|
|
48
|
+
* never consume a buyer's budget: there is no stream for it to be billed
|
|
49
|
+
* against. Accrual is only ever produced by an oracle checkpoint keyed to a
|
|
50
|
+
* stream; a gateway call produces none.
|
|
51
|
+
*
|
|
52
|
+
* ## What a probe is NOT
|
|
53
|
+
*
|
|
54
|
+
* A probe is verification, not delivery to a buyer. A gateway authorizing one
|
|
55
|
+
* MUST NOT meter it, settle any payment for it, or count it as a paid call.
|
|
56
|
+
* The reference gateway enforces this structurally (see
|
|
57
|
+
* `../gateway/caller-auth-gateway.ts`) and marks the upstream request with
|
|
58
|
+
* {@link PROBE_MARKER_HEADER_NAME} so a seller's own metering can exclude it.
|
|
59
|
+
*
|
|
60
|
+
* ## Honest note for third-party sellers
|
|
61
|
+
*
|
|
62
|
+
* This CHANGES what a seller's gateway must implement to get paid-route
|
|
63
|
+
* verification. A gated listing fronted by a gateway that has not adopted
|
|
64
|
+
* `ProbeCapability` stays HEALTH-ROUTE-ONLY, and the oracle reports it as
|
|
65
|
+
* unverifiable rather than passing. Adoption is the seller's choice; silence
|
|
66
|
+
* about it is not the oracle's.
|
|
67
|
+
*
|
|
68
|
+
* Kept LOCAL to `@absol-labs/agent` for the same reason as
|
|
69
|
+
* `InvocationCapability`: no contract parses it, so there is no on-chain byte
|
|
70
|
+
* compatibility requirement. Cross-repo compatibility with the oracle's minter
|
|
71
|
+
* is pinned by a shared digest test vector — see
|
|
72
|
+
* `test/probe-capability.test.ts` and the oracle's mirror of the same constant.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
const addressSchema = z
|
|
76
|
+
.string()
|
|
77
|
+
.refine((value) => isAddress(value), "must be an EVM address");
|
|
78
|
+
const bytes32Schema = z
|
|
79
|
+
.string()
|
|
80
|
+
.refine(
|
|
81
|
+
(value) => isHex(value, { strict: true }) && value.length === 66,
|
|
82
|
+
"must be bytes32 hex",
|
|
83
|
+
);
|
|
84
|
+
const signatureSchema = z
|
|
85
|
+
.string()
|
|
86
|
+
.refine(
|
|
87
|
+
(value) => isHex(value, { strict: true }) && value.length === 132,
|
|
88
|
+
"must be a 65-byte signature",
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
export const probeCapabilitySchema = z.object({
|
|
92
|
+
/**
|
|
93
|
+
* The service being probed. Must match the target gateway's configured
|
|
94
|
+
* `serviceRef`. There is deliberately no `streamId` field — see the class
|
|
95
|
+
* docs.
|
|
96
|
+
*/
|
|
97
|
+
serviceRef: bytes32Schema,
|
|
98
|
+
/**
|
|
99
|
+
* The minting oracle signer. Must equal the EIP-712 signer AND be a member of
|
|
100
|
+
* the escrow's on-chain `getOracleSigners()` set at verification time.
|
|
101
|
+
*/
|
|
102
|
+
oracle: addressSchema,
|
|
103
|
+
/** The single HTTP method this capability authorizes. */
|
|
104
|
+
method: httpMethodSchema,
|
|
105
|
+
/** `keccak256` of the exact request path this capability authorizes. */
|
|
106
|
+
pathHash: bytes32Schema,
|
|
107
|
+
/** Single-use anti-replay nonce. */
|
|
108
|
+
nonce: bytes32Schema,
|
|
109
|
+
/** Unix seconds after which the capability is no longer valid. */
|
|
110
|
+
expiry: z.number().int().positive(),
|
|
111
|
+
});
|
|
112
|
+
export type ProbeCapability = z.infer<typeof probeCapabilitySchema>;
|
|
113
|
+
|
|
114
|
+
export const signedProbeCapabilitySchema = probeCapabilitySchema.extend({
|
|
115
|
+
signature: signatureSchema,
|
|
116
|
+
});
|
|
117
|
+
export type SignedProbeCapability = z.infer<typeof signedProbeCapabilitySchema>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Chain-bound domain. `verifyingContract` is the `StreamEscrowV2` whose
|
|
121
|
+
* `getOracleSigners()` defines who may mint — so a capability minted for one
|
|
122
|
+
* escrow can never authorize a probe against a gateway fronting another.
|
|
123
|
+
*/
|
|
124
|
+
export interface ProbeCapabilityDomainInput {
|
|
125
|
+
readonly chainId: number;
|
|
126
|
+
readonly verifyingContract: Address;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Distinct from `Metrik Invocation Capability`, so a buyer's invocation
|
|
131
|
+
* signature can never be replayed as a probe (or the reverse) even though both
|
|
132
|
+
* share a chainId and verifying contract.
|
|
133
|
+
*/
|
|
134
|
+
export const probeCapabilityDomainName = "Metrik Probe Capability" as const;
|
|
135
|
+
export const probeCapabilityDomainVersion = "1" as const;
|
|
136
|
+
|
|
137
|
+
export const probeCapabilityTypedData = {
|
|
138
|
+
ProbeCapability: [
|
|
139
|
+
{ name: "serviceRef", type: "bytes32" },
|
|
140
|
+
{ name: "oracle", type: "address" },
|
|
141
|
+
{ name: "method", type: "string" },
|
|
142
|
+
{ name: "pathHash", type: "bytes32" },
|
|
143
|
+
{ name: "nonce", type: "bytes32" },
|
|
144
|
+
{ name: "expiry", type: "uint64" },
|
|
145
|
+
],
|
|
146
|
+
} as const;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Default lifetime of a freshly-minted probe capability, in seconds.
|
|
150
|
+
*
|
|
151
|
+
* Shorter than the ~15-22s checkpoint cadence would race a slow upstream; much
|
|
152
|
+
* longer would widen the window in which a captured capability is replayable
|
|
153
|
+
* against a gateway with no nonce cache. 30s is one to two probe intervals.
|
|
154
|
+
*/
|
|
155
|
+
export const DEFAULT_PROBE_CAPABILITY_TTL_SECONDS = 30;
|
|
156
|
+
|
|
157
|
+
/** Header a probe request carries the signed capability in. */
|
|
158
|
+
export const PROBE_CAPABILITY_HEADER_NAME = "x-metrik-probe-capability";
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Header the gateway adds to the UPSTREAM request when it authorized a probe.
|
|
162
|
+
* Advisory: it exists so a seller's own metering/analytics can exclude
|
|
163
|
+
* verification traffic from billable usage.
|
|
164
|
+
*/
|
|
165
|
+
export const PROBE_MARKER_HEADER_NAME = "x-metrik-probe";
|
|
166
|
+
|
|
167
|
+
export function createProbeCapabilityEip712Domain(
|
|
168
|
+
domain: ProbeCapabilityDomainInput,
|
|
169
|
+
) {
|
|
170
|
+
return {
|
|
171
|
+
name: probeCapabilityDomainName,
|
|
172
|
+
version: probeCapabilityDomainVersion,
|
|
173
|
+
chainId: domain.chainId,
|
|
174
|
+
verifyingContract: getAddress(domain.verifyingContract),
|
|
175
|
+
} as const;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* `keccak256` of the exact request path this capability authorizes. Shares the
|
|
180
|
+
* canonical form with `InvocationCapability` so both sides of a gateway hash
|
|
181
|
+
* paths identically.
|
|
182
|
+
*/
|
|
183
|
+
export function hashProbePath(path: string): Hex {
|
|
184
|
+
return hashInvocationPath(path);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Re-exported for symmetry; identical canonicalization to the invocation path. */
|
|
188
|
+
export function normalizeProbePath(path: string): string {
|
|
189
|
+
return normalizeInvocationPath(path);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function probeCapabilityMessage(capability: ProbeCapability) {
|
|
193
|
+
const parsed = probeCapabilitySchema.parse(capability);
|
|
194
|
+
return {
|
|
195
|
+
serviceRef: parsed.serviceRef as Hex,
|
|
196
|
+
oracle: getAddress(parsed.oracle),
|
|
197
|
+
method: parsed.method,
|
|
198
|
+
pathHash: parsed.pathHash as Hex,
|
|
199
|
+
nonce: parsed.nonce as Hex,
|
|
200
|
+
expiry: BigInt(parsed.expiry),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function buildProbeCapabilityTypedData(
|
|
205
|
+
capability: ProbeCapability,
|
|
206
|
+
domain: ProbeCapabilityDomainInput,
|
|
207
|
+
) {
|
|
208
|
+
return {
|
|
209
|
+
domain: createProbeCapabilityEip712Domain(domain),
|
|
210
|
+
types: probeCapabilityTypedData,
|
|
211
|
+
primaryType: "ProbeCapability" as const,
|
|
212
|
+
message: probeCapabilityMessage(capability),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The minimum an oracle signer must expose to mint a probe capability. */
|
|
217
|
+
export type ProbeCapabilitySigner = Pick<
|
|
218
|
+
LocalAccount,
|
|
219
|
+
"address" | "signTypedData"
|
|
220
|
+
>;
|
|
221
|
+
|
|
222
|
+
/** Signs a `ProbeCapability` with an oracle signer's own key. */
|
|
223
|
+
export async function signProbeCapability(
|
|
224
|
+
capability: ProbeCapability,
|
|
225
|
+
domain: ProbeCapabilityDomainInput,
|
|
226
|
+
account: ProbeCapabilitySigner,
|
|
227
|
+
): Promise<Hex> {
|
|
228
|
+
const typedData = buildProbeCapabilityTypedData(capability, domain);
|
|
229
|
+
return account.signTypedData(typedData);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Recovers the EIP-712 signer of a probe capability. Throws on a malformed signature. */
|
|
233
|
+
export async function recoverProbeCapabilitySigner(
|
|
234
|
+
capability: ProbeCapability,
|
|
235
|
+
domain: ProbeCapabilityDomainInput,
|
|
236
|
+
signature: Hex,
|
|
237
|
+
): Promise<Address> {
|
|
238
|
+
const typedData = buildProbeCapabilityTypedData(capability, domain);
|
|
239
|
+
return recoverTypedDataAddress({ ...typedData, signature });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Cryptographically random 32-byte single-use nonce. */
|
|
243
|
+
export function generateProbeNonce(): Hex {
|
|
244
|
+
return `0x${randomBytes(32).toString("hex")}` as Hex;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export class InvalidProbeCapabilityHeaderError extends Error {
|
|
248
|
+
constructor(message: string, options?: { readonly cause?: unknown }) {
|
|
249
|
+
super(message, options);
|
|
250
|
+
this.name = "InvalidProbeCapabilityHeaderError";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Encodes a signed probe capability as an opaque, header-safe (base64url) string. */
|
|
255
|
+
export function encodeProbeCapabilityHeader(
|
|
256
|
+
signed: SignedProbeCapability,
|
|
257
|
+
): string {
|
|
258
|
+
const parsed = signedProbeCapabilitySchema.parse(signed);
|
|
259
|
+
const json = JSON.stringify({
|
|
260
|
+
serviceRef: parsed.serviceRef,
|
|
261
|
+
oracle: parsed.oracle,
|
|
262
|
+
method: parsed.method,
|
|
263
|
+
pathHash: parsed.pathHash,
|
|
264
|
+
nonce: parsed.nonce,
|
|
265
|
+
expiry: parsed.expiry,
|
|
266
|
+
signature: parsed.signature,
|
|
267
|
+
});
|
|
268
|
+
return Buffer.from(json, "utf8").toString("base64url");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Decodes and schema-validates a probe capability header. Fails closed on any malformation. */
|
|
272
|
+
export function decodeProbeCapabilityHeader(
|
|
273
|
+
headerValue: string,
|
|
274
|
+
): SignedProbeCapability {
|
|
275
|
+
let json: string;
|
|
276
|
+
try {
|
|
277
|
+
json = Buffer.from(headerValue, "base64url").toString("utf8");
|
|
278
|
+
} catch (cause) {
|
|
279
|
+
throw new InvalidProbeCapabilityHeaderError(
|
|
280
|
+
"malformed base64 probe capability header",
|
|
281
|
+
{ cause },
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let raw: unknown;
|
|
286
|
+
try {
|
|
287
|
+
raw = JSON.parse(json);
|
|
288
|
+
} catch (cause) {
|
|
289
|
+
throw new InvalidProbeCapabilityHeaderError(
|
|
290
|
+
"malformed JSON probe capability header",
|
|
291
|
+
{ cause },
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const result = signedProbeCapabilitySchema.safeParse(raw);
|
|
296
|
+
if (!result.success) {
|
|
297
|
+
throw new InvalidProbeCapabilityHeaderError(
|
|
298
|
+
`invalid probe capability shape: ${result.error.message}`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
return result.data;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface MintProbeCapabilityOptions {
|
|
305
|
+
readonly serviceRef: Hex;
|
|
306
|
+
readonly method: ProbeCapability["method"];
|
|
307
|
+
/** The exact request path to be probed (query/fragment are stripped). */
|
|
308
|
+
readonly path: string;
|
|
309
|
+
readonly domain: ProbeCapabilityDomainInput;
|
|
310
|
+
readonly account: ProbeCapabilitySigner;
|
|
311
|
+
readonly ttlSeconds?: number;
|
|
312
|
+
/** Injectable clock (unix seconds), for tests. */
|
|
313
|
+
readonly now?: () => number;
|
|
314
|
+
/** Injectable nonce source, for tests. */
|
|
315
|
+
readonly nonce?: () => Hex;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Mint one fresh, single-use, short-lived probe capability and return its
|
|
320
|
+
* encoded header value. Called once PER PROBE PER VANTAGE by the coordinator:
|
|
321
|
+
* the gateway's replay cache is single-use, so two vantages sharing one
|
|
322
|
+
* capability would see the second rejected as a replay.
|
|
323
|
+
*/
|
|
324
|
+
export async function mintProbeCapabilityHeader(
|
|
325
|
+
options: MintProbeCapabilityOptions,
|
|
326
|
+
): Promise<{
|
|
327
|
+
readonly headerName: string;
|
|
328
|
+
readonly headerValue: string;
|
|
329
|
+
readonly capability: SignedProbeCapability;
|
|
330
|
+
}> {
|
|
331
|
+
const nowSeconds = (options.now ?? (() => Math.floor(Date.now() / 1000)))();
|
|
332
|
+
const ttl = options.ttlSeconds ?? DEFAULT_PROBE_CAPABILITY_TTL_SECONDS;
|
|
333
|
+
if (!Number.isInteger(ttl) || ttl <= 0) {
|
|
334
|
+
throw new Error("probe capability ttlSeconds must be a positive integer");
|
|
335
|
+
}
|
|
336
|
+
const capability: ProbeCapability = {
|
|
337
|
+
serviceRef: options.serviceRef,
|
|
338
|
+
oracle: getAddress(options.account.address),
|
|
339
|
+
method: options.method,
|
|
340
|
+
pathHash: hashProbePath(options.path),
|
|
341
|
+
nonce: (options.nonce ?? generateProbeNonce)(),
|
|
342
|
+
expiry: nowSeconds + ttl,
|
|
343
|
+
};
|
|
344
|
+
const signature = await signProbeCapability(
|
|
345
|
+
capability,
|
|
346
|
+
options.domain,
|
|
347
|
+
options.account,
|
|
348
|
+
);
|
|
349
|
+
const signed: SignedProbeCapability = { ...capability, signature };
|
|
350
|
+
return {
|
|
351
|
+
headerName: PROBE_CAPABILITY_HEADER_NAME,
|
|
352
|
+
headerValue: encodeProbeCapabilityHeader(signed),
|
|
353
|
+
capability: signed,
|
|
354
|
+
};
|
|
355
|
+
}
|
package/src/cli/args.ts
CHANGED
|
@@ -117,6 +117,35 @@ export function booleanFlag(args: ParsedArgs, name: string): boolean {
|
|
|
117
117
|
throw usageError(`--${name} takes no value (got "${value}")`);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Commands whose `--json` may ALSO carry a value: a JSON request body, as in
|
|
122
|
+
* curl's `--json '<body>'`. For them a bare `--json` (or `--json=true`) still
|
|
123
|
+
* selects JSON output, and the two can be combined
|
|
124
|
+
* (`--json '{"a":1}' --json`). Every other command keeps `--json` boolean.
|
|
125
|
+
*/
|
|
126
|
+
export const JSON_BODY_COMMANDS: ReadonlySet<string> = new Set(["pay"]);
|
|
127
|
+
|
|
128
|
+
/** Whether `--json` OUTPUT was requested (see {@link JSON_BODY_COMMANDS}). */
|
|
129
|
+
export function jsonOutputRequested(args: ParsedArgs): boolean {
|
|
130
|
+
if (args.command === null || !JSON_BODY_COMMANDS.has(args.command)) {
|
|
131
|
+
return booleanFlag(args, "json");
|
|
132
|
+
}
|
|
133
|
+
const values = args.flags.get("json") ?? [];
|
|
134
|
+
return values.some((value) => value === true || value === "true");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The `--json <body>` value(s) of a JSON-body command, if any. */
|
|
138
|
+
export function jsonBodyFlag(args: ParsedArgs): string | undefined {
|
|
139
|
+
const values = (args.flags.get("json") ?? []).filter(
|
|
140
|
+
(value): value is string =>
|
|
141
|
+
typeof value === "string" && value !== "true" && value !== "false",
|
|
142
|
+
);
|
|
143
|
+
if (values.length > 1) {
|
|
144
|
+
throw usageError("--json <body> may be given only once");
|
|
145
|
+
}
|
|
146
|
+
return values[0];
|
|
147
|
+
}
|
|
148
|
+
|
|
120
149
|
export function integerFlag(
|
|
121
150
|
args: ParsedArgs,
|
|
122
151
|
name: string,
|
|
@@ -3,7 +3,12 @@ import { assertTestnetRpc, parseBytes32 } from "../config.js";
|
|
|
3
3
|
import { CliError, describeError, usageError } from "../errors.js";
|
|
4
4
|
import { signClaimMandate } from "../mandate.js";
|
|
5
5
|
import { assertCanPayGas } from "../preflight.js";
|
|
6
|
-
import {
|
|
6
|
+
import { writeClientOptions } from "../deps.js";
|
|
7
|
+
import {
|
|
8
|
+
isPolicyEnforced,
|
|
9
|
+
PRIVATE_KEY_ENV,
|
|
10
|
+
resolveCliWallet,
|
|
11
|
+
} from "../wallet.js";
|
|
7
12
|
import type { CommandContext, CommandSpec } from "../context.js";
|
|
8
13
|
|
|
9
14
|
/**
|
|
@@ -30,10 +35,24 @@ export const claimCommand: CommandSpec = {
|
|
|
30
35
|
}
|
|
31
36
|
const streamId = parseBytes32(streamIdArg, "<streamId>");
|
|
32
37
|
|
|
33
|
-
const
|
|
38
|
+
const wallet = await resolveCliWallet(env, {
|
|
39
|
+
note: out.note,
|
|
40
|
+
rpcUrl: config.rpcUrl,
|
|
41
|
+
});
|
|
42
|
+
const { account } = wallet;
|
|
43
|
+
if (isPolicyEnforced(wallet)) {
|
|
44
|
+
// Said plainly rather than discovered mid-command. `claim` is the
|
|
45
|
+
// OPERATOR's side, and a Privy broker policy allowlists the BUYER
|
|
46
|
+
// actions only (openStream, close, reclaim, reclaimUnverified, and a
|
|
47
|
+
// bounded USDC approval). That is a property of an operator using a
|
|
48
|
+
// buyer-scoped wallet, not a defect in this command.
|
|
49
|
+
out.note(
|
|
50
|
+
"warning: this wallet's broker policy allowlists buyer actions only, so it will refuse to sign an operator claim. Claim with the operator's own key.",
|
|
51
|
+
);
|
|
52
|
+
}
|
|
34
53
|
const read = deps.createReadClient(config);
|
|
35
54
|
await assertTestnetRpc(config, () => read.getChainId());
|
|
36
|
-
await assertCanPayGas(read, account.address);
|
|
55
|
+
await assertCanPayGas(read, account.address, config.network);
|
|
37
56
|
|
|
38
57
|
const stream = await read.getStreamV2(streamId);
|
|
39
58
|
if (stream.operator.toLowerCase() !== account.address.toLowerCase()) {
|
|
@@ -74,10 +93,17 @@ export const claimCommand: CommandSpec = {
|
|
|
74
93
|
});
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
const write = deps.createWriteClient(
|
|
96
|
+
const write = deps.createWriteClient(
|
|
97
|
+
config,
|
|
98
|
+
account,
|
|
99
|
+
writeClientOptions(wallet),
|
|
100
|
+
);
|
|
78
101
|
const result = await write.claimStream({
|
|
79
102
|
streamId,
|
|
80
|
-
|
|
103
|
+
// `null` for a policy-enforced wallet — see `../spend-policy.ts`.
|
|
104
|
+
signedMandate: isPolicyEnforced(wallet)
|
|
105
|
+
? null
|
|
106
|
+
: await signClaimMandate(account, config.chainId),
|
|
81
107
|
spentSoFarUsdc: 0n,
|
|
82
108
|
nowSeconds: deps.nowSeconds(),
|
|
83
109
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { assertTestnetRpc, parseBytes32 } from "../config.js";
|
|
2
|
-
import { usageError } from "../errors.js";
|
|
2
|
+
import { CliError, usageError } from "../errors.js";
|
|
3
3
|
import { signRecoveryMandate } from "../mandate.js";
|
|
4
4
|
import { assertCanPayGas } from "../preflight.js";
|
|
5
|
-
import {
|
|
5
|
+
import { writeClientOptions } from "../deps.js";
|
|
6
|
+
import { isPolicyEnforced, resolveCliWallet } from "../wallet.js";
|
|
6
7
|
import type { CommandContext, CommandSpec } from "../context.js";
|
|
7
8
|
|
|
8
9
|
export const closeCommand: CommandSpec = {
|
|
@@ -19,13 +20,49 @@ export const closeCommand: CommandSpec = {
|
|
|
19
20
|
}
|
|
20
21
|
const streamId = parseBytes32(streamIdArg, "<streamId>");
|
|
21
22
|
|
|
22
|
-
const
|
|
23
|
+
const wallet = await resolveCliWallet(env, {
|
|
24
|
+
note: out.note,
|
|
25
|
+
rpcUrl: config.rpcUrl,
|
|
26
|
+
});
|
|
27
|
+
const { account } = wallet;
|
|
23
28
|
const read = deps.createReadClient(config);
|
|
24
29
|
await assertTestnetRpc(config, () => read.getChainId());
|
|
25
|
-
|
|
30
|
+
// An x402 opener stream is closed through the opener, by its PAYER. Say so
|
|
31
|
+
// up front: the escrow would answer anyone else with NotBuyer, and the SDK
|
|
32
|
+
// refuses a non-payer before anything is sent.
|
|
33
|
+
const stream = await read.getStreamV2(streamId).catch(() => null);
|
|
34
|
+
const opener = stream?.opener ?? null;
|
|
35
|
+
if (opener !== null && stream !== null) {
|
|
36
|
+
out.note(
|
|
37
|
+
`x402 stream: closing through the opener ${opener}; only its payer ${stream.payer} may close it.`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await assertCanPayGas(read, account.address, config.network);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (opener !== null && error instanceof CliError) {
|
|
44
|
+
throw new CliError(error.message, {
|
|
45
|
+
exitCode: error.exitCode,
|
|
46
|
+
hint: `${error.hint ?? ""} This stream was bought over x402: a payer with no gas can close it through the seller's refund relay instead — \`metrik refund ${streamId} --refund-url <url> --close\`.`.trim(),
|
|
47
|
+
cause: error,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
26
52
|
|
|
27
|
-
|
|
28
|
-
|
|
53
|
+
// A policy-enforced wallet signs no mandate of its own: this is a
|
|
54
|
+
// buyer-recovery action, the escrow gates it on the buyer address and the
|
|
55
|
+
// broker gates it again on `stream.buyer == wallet`. A locally self-signed
|
|
56
|
+
// placeholder would add nothing and the broker would refuse to sign it.
|
|
57
|
+
// See `../spend-policy.ts`.
|
|
58
|
+
const signedMandate = isPolicyEnforced(wallet)
|
|
59
|
+
? null
|
|
60
|
+
: await signRecoveryMandate(account, config.chainId);
|
|
61
|
+
const write = deps.createWriteClient(
|
|
62
|
+
config,
|
|
63
|
+
account,
|
|
64
|
+
writeClientOptions(wallet),
|
|
65
|
+
);
|
|
29
66
|
const result = await write.closeStream({
|
|
30
67
|
streamId,
|
|
31
68
|
signedMandate,
|
|
@@ -33,11 +70,23 @@ export const closeCommand: CommandSpec = {
|
|
|
33
70
|
nowSeconds: deps.nowSeconds(),
|
|
34
71
|
});
|
|
35
72
|
|
|
36
|
-
out.result({
|
|
73
|
+
out.result({
|
|
74
|
+
streamId,
|
|
75
|
+
txHash: result.txHash,
|
|
76
|
+
closed: true,
|
|
77
|
+
opener,
|
|
78
|
+
payer: stream?.payer ?? null,
|
|
79
|
+
});
|
|
37
80
|
out.print("Stream closed.");
|
|
38
81
|
out.table([
|
|
39
82
|
["streamId", streamId],
|
|
40
83
|
["tx", result.txHash],
|
|
84
|
+
...(opener === null
|
|
85
|
+
? []
|
|
86
|
+
: ([
|
|
87
|
+
["via opener", opener],
|
|
88
|
+
["payer", stream?.payer ?? "-"],
|
|
89
|
+
] as const)),
|
|
41
90
|
]);
|
|
42
91
|
out.print("");
|
|
43
92
|
out.print(
|
|
@@ -61,6 +61,7 @@ export const invokeCommand: CommandSpec = {
|
|
|
61
61
|
const { account } = await resolveCliWallet(env, {
|
|
62
62
|
purpose: "capability",
|
|
63
63
|
note: out.note,
|
|
64
|
+
rpcUrl: config.rpcUrl,
|
|
64
65
|
});
|
|
65
66
|
const read = deps.createReadClient(config);
|
|
66
67
|
// No transaction is signed here — but the capability is bound to
|
|
@@ -156,7 +157,7 @@ function explainInvokeFailure(error: unknown, signer: string): unknown {
|
|
|
156
157
|
return error;
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
function parseHeaders(raw: readonly string[]): Record<string, string> {
|
|
160
|
+
export function parseHeaders(raw: readonly string[]): Record<string, string> {
|
|
160
161
|
const headers: Record<string, string> = {};
|
|
161
162
|
for (const entry of raw) {
|
|
162
163
|
const separator = entry.indexOf(":");
|
|
@@ -170,7 +171,10 @@ function parseHeaders(raw: readonly string[]): Record<string, string> {
|
|
|
170
171
|
return headers;
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
function hasHeader(
|
|
174
|
+
export function hasHeader(
|
|
175
|
+
headers: Record<string, string>,
|
|
176
|
+
name: string,
|
|
177
|
+
): boolean {
|
|
174
178
|
return Object.keys(headers).some(
|
|
175
179
|
(key) => key.toLowerCase() === name.toLowerCase(),
|
|
176
180
|
);
|