@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/dist/cli/wallet.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { privateKeyToAccount } from "viem/accounts";
|
|
2
2
|
import { resolveAgentWallet } from "../wallet/provider.js";
|
|
3
3
|
import { configError } from "./errors.js";
|
|
4
|
+
import { PRIVY_ENV_VARS, PRIVY_SESSION_ENV_VARS, PRIVY_WALLET_KEY_ENV, resolvePrivyCliWallet, } from "./privy.js";
|
|
4
5
|
/**
|
|
5
6
|
* The ONLY place the CLI resolves a signing wallet.
|
|
6
7
|
*
|
|
@@ -12,35 +13,36 @@ import { configError } from "./errors.js";
|
|
|
12
13
|
*
|
|
13
14
|
* ## Resolution order (first match wins, checked in this order)
|
|
14
15
|
*
|
|
15
|
-
* 1. `METRIK_AGENT_PRIVATE_KEY` — a raw
|
|
16
|
+
* 1. `METRIK_AGENT_PRIVATE_KEY` — a raw testnet key.
|
|
16
17
|
* 2. The `CDP_*` / `METRIK_AGENT_CDP_*` quartet — a Coinbase CDP Server Wallet
|
|
17
18
|
* v2 account, resolved through this package's own `resolveAgentWallet()`.
|
|
19
|
+
* 3. The `METRIK_AGENT_PRIVY_*` variables — a Privy wallet reached through a
|
|
20
|
+
* broker, either agent-owned (`METRIK_AGENT_PRIVY_WALLET_KEY`) or a
|
|
21
|
+
* user-owned broker session. See `./privy.ts`.
|
|
18
22
|
*
|
|
19
|
-
* The
|
|
20
|
-
* one environment configures
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* The first two match `parseAgentWalletEnv()` (the MCP server's resolution), so
|
|
24
|
+
* one environment configures those surfaces the same way. The order is FIXED
|
|
25
|
+
* rather than "whichever is configured", because an environment carrying two is
|
|
26
|
+
* ambiguous about which address funds the stream — and that ambiguity is a
|
|
27
|
+
* fund-moving one. When more than one is present the earlier entry wins and
|
|
28
|
+
* `resolveCliWallet` says so on stderr rather than silently picking.
|
|
25
29
|
*
|
|
26
|
-
* ##
|
|
30
|
+
* ## What is different about Privy
|
|
27
31
|
*
|
|
28
|
-
*
|
|
29
|
-
* (`
|
|
30
|
-
*
|
|
31
|
-
* viem local account, so it drops straight into the CLI's existing
|
|
32
|
-
* `http(rpcUrl)` transport with no other change.
|
|
32
|
+
* A private key and a CDP account both sign LOCALLY: `privateKeyToAccount()`
|
|
33
|
+
* and `toAccount(cdpServerAccount)` are viem local accounts, so they drop
|
|
34
|
+
* straight into the CLI's `http(rpcUrl)` transport with no other change.
|
|
33
35
|
*
|
|
34
|
-
* Privy does not.
|
|
35
|
-
*
|
|
36
|
-
* `
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* `docs/cli.md` § Wallet.
|
|
36
|
+
* Privy does not. Its account is a JSON-RPC account with no `signTransaction`:
|
|
37
|
+
* it signs and broadcasts by sending `eth_sendTransaction` /
|
|
38
|
+
* `eth_signTypedData_v4` to a provider, so the wallet client's TRANSPORT must
|
|
39
|
+
* be that provider rather than a plain RPC. That is what {@link CliWallet.transport}
|
|
40
|
+
* carries, and the only reason this file knows Privy exists. The signer check
|
|
41
|
+
* below is therefore about CAPABILITY, not about locality: it refuses an
|
|
42
|
+
* account that genuinely cannot sign, and refuses a non-local account only on
|
|
43
|
+
* the paths that broadcast through `--rpc-url`.
|
|
44
|
+
*
|
|
45
|
+
* See `docs/cli.md` § Wallet.
|
|
44
46
|
*/
|
|
45
47
|
export const PRIVATE_KEY_ENV = "METRIK_AGENT_PRIVATE_KEY";
|
|
46
48
|
/** Every environment variable the CDP path reads. Named in errors, never printed. */
|
|
@@ -50,26 +52,41 @@ export const CDP_ENV_VARS = [
|
|
|
50
52
|
"CDP_WALLET_SECRET",
|
|
51
53
|
"METRIK_AGENT_CDP_OWNER_NAME",
|
|
52
54
|
];
|
|
55
|
+
export { PRIVY_ENV_VARS, PRIVY_SESSION_ENV_VARS, PRIVY_WALLET_KEY_ENV, } from "./privy.js";
|
|
53
56
|
const PURPOSE_TEXT = {
|
|
54
57
|
transaction: "signs a transaction",
|
|
55
58
|
capability: "signs an off-chain EIP-712 invocation capability (no transaction is broadcast)",
|
|
56
59
|
};
|
|
57
|
-
const WALLET_HINT = `export ${PRIVATE_KEY_ENV}=0x… (a funded
|
|
58
|
-
`${CDP_ENV_VARS.join(", ")}
|
|
60
|
+
const WALLET_HINT = `export ${PRIVATE_KEY_ENV}=0x… (a funded testnet key), configure a Coinbase CDP wallet with ` +
|
|
61
|
+
`${CDP_ENV_VARS.join(", ")}, or configure a Privy wallet with ${PRIVY_WALLET_KEY_ENV} (agent-owned) or ` +
|
|
62
|
+
`${PRIVY_SESSION_ENV_VARS.join(", ")} (broker session). All are read from the environment only — never pass a credential as a command-line flag.`;
|
|
59
63
|
/**
|
|
60
64
|
* Resolves the signing wallet, or throws an actionable configuration error.
|
|
61
65
|
*
|
|
62
|
-
* `note` receives one line when the environment is ambiguous (
|
|
63
|
-
*
|
|
64
|
-
* context with no printer; commands always pass `out.note`.
|
|
66
|
+
* `note` receives one line when the environment is ambiguous (more than one
|
|
67
|
+
* wallet source configured). It is optional so `resolveCliWallet` stays usable
|
|
68
|
+
* from a context with no printer; commands always pass `out.note`.
|
|
65
69
|
*/
|
|
66
70
|
export async function resolveCliWallet(env, options = {}) {
|
|
67
71
|
const wallet = await optionalCliWallet(env, options);
|
|
68
72
|
if (wallet === null) {
|
|
69
|
-
throw configError(`this command ${PURPOSE_TEXT[options.purpose ?? "transaction"]} and needs a wallet:
|
|
73
|
+
throw configError(`this command ${PURPOSE_TEXT[options.purpose ?? "transaction"]} and needs a wallet: none of ${PRIVATE_KEY_ENV}, the CDP variables or the Privy variables are set`, WALLET_HINT);
|
|
70
74
|
}
|
|
71
75
|
return wallet;
|
|
72
76
|
}
|
|
77
|
+
/** True for both Privy shapes, which reach their key through a broker. */
|
|
78
|
+
export function isPrivyWalletSource(source) {
|
|
79
|
+
return source === "privy-autonomous" || source === "privy-session";
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether this wallet's ceiling is enforced somewhere the CLI cannot reach.
|
|
83
|
+
*
|
|
84
|
+
* The one question every fund-moving command asks before deciding whether to
|
|
85
|
+
* self-sign a `SpendMandate`. See `./spend-policy.ts`.
|
|
86
|
+
*/
|
|
87
|
+
export function isPolicyEnforced(wallet) {
|
|
88
|
+
return wallet.readSpendPolicy !== undefined;
|
|
89
|
+
}
|
|
73
90
|
/**
|
|
74
91
|
* The same resolution, but "nothing configured" is not an error. Used by
|
|
75
92
|
* look-before-you-leap paths (`open --dry-run`, `streams --address`) that
|
|
@@ -79,14 +96,19 @@ export async function resolveCliWallet(env, options = {}) {
|
|
|
79
96
|
* A wallet that is PARTIALLY configured is still an error here: "you set three
|
|
80
97
|
* of the four CDP variables" and "you configured no wallet" are different
|
|
81
98
|
* facts, and rendering the first as the second sends the reader looking in the
|
|
82
|
-
* wrong place.
|
|
99
|
+
* wrong place. The same rule applies to a partial Privy setup.
|
|
83
100
|
*/
|
|
84
101
|
export async function optionalCliWallet(env, options = {}) {
|
|
85
102
|
const privateKeyAccount = optionalCliAccount(env);
|
|
86
103
|
const cdpConfigured = CDP_ENV_VARS.some((name) => isSet(env[name]));
|
|
104
|
+
const privyConfigured = PRIVY_ENV_VARS.some((name) => isSet(env[name]));
|
|
87
105
|
if (privateKeyAccount !== null) {
|
|
88
|
-
|
|
89
|
-
|
|
106
|
+
const shadowed = [
|
|
107
|
+
...(cdpConfigured ? ["CDP"] : []),
|
|
108
|
+
...(privyConfigured ? ["Privy"] : []),
|
|
109
|
+
];
|
|
110
|
+
if (shadowed.length > 0) {
|
|
111
|
+
options.note?.(`warning: both ${PRIVATE_KEY_ENV} and ${shadowed.join(" and ")} wallet variables are set; using ${PRIVATE_KEY_ENV} (${privateKeyAccount.address}). Unset it to sign with the ${shadowed[0]} wallet.`);
|
|
90
112
|
}
|
|
91
113
|
return {
|
|
92
114
|
source: "private-key",
|
|
@@ -94,8 +116,29 @@ export async function optionalCliWallet(env, options = {}) {
|
|
|
94
116
|
description: `${privateKeyAccount.address} (from ${PRIVATE_KEY_ENV})`,
|
|
95
117
|
};
|
|
96
118
|
}
|
|
97
|
-
if (
|
|
119
|
+
if (cdpConfigured) {
|
|
120
|
+
if (privyConfigured) {
|
|
121
|
+
options.note?.("warning: both CDP and Privy wallet variables are set; using the CDP wallet. Unset the CDP variables to sign with the Privy wallet.");
|
|
122
|
+
}
|
|
123
|
+
return await resolveCdpWallet(env);
|
|
124
|
+
}
|
|
125
|
+
if (!privyConfigured)
|
|
98
126
|
return null;
|
|
127
|
+
const privy = await resolvePrivyCliWallet(env, options);
|
|
128
|
+
// Unreachable: `privyConfigured` is exactly the condition under which
|
|
129
|
+
// `resolvePrivyCliWallet` returns non-null or throws. Kept so a future change
|
|
130
|
+
// to either predicate fails loudly here rather than as a null deref.
|
|
131
|
+
if (privy === null)
|
|
132
|
+
return null;
|
|
133
|
+
return {
|
|
134
|
+
source: privy.source,
|
|
135
|
+
account: assertCliSigner(privy.account, privy.source),
|
|
136
|
+
transport: privy.transport,
|
|
137
|
+
description: privy.description,
|
|
138
|
+
readSpendPolicy: privy.readSpendPolicy,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async function resolveCdpWallet(env) {
|
|
99
142
|
const missing = CDP_ENV_VARS.filter((name) => !isSet(env[name]));
|
|
100
143
|
if (missing.length > 0) {
|
|
101
144
|
throw configError(`the CDP wallet is partially configured: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not set`, `a CDP wallet needs all of ${CDP_ENV_VARS.join(", ")}. Set the missing one${missing.length === 1 ? "" : "s"}, or unset the others and use ${PRIVATE_KEY_ENV} instead.`);
|
|
@@ -130,7 +173,7 @@ export async function optionalCliWallet(env, options = {}) {
|
|
|
130
173
|
}
|
|
131
174
|
return {
|
|
132
175
|
source: "cdp",
|
|
133
|
-
account:
|
|
176
|
+
account: assertCliSigner(account, "cdp"),
|
|
134
177
|
description: `${account.address} (CDP account "${ownerName}")`,
|
|
135
178
|
};
|
|
136
179
|
}
|
|
@@ -148,17 +191,39 @@ export function optionalCliAccount(env) {
|
|
|
148
191
|
return privateKeyToAccount(raw);
|
|
149
192
|
}
|
|
150
193
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
194
|
+
* Whether this wallet source broadcasts through the CLI's own
|
|
195
|
+
* `http(--rpc-url)` transport, and therefore needs an account that can produce
|
|
196
|
+
* a signed raw transaction by itself.
|
|
197
|
+
*/
|
|
198
|
+
function broadcastsLocally(source) {
|
|
199
|
+
return source === "private-key" || source === "cdp";
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Refuses an account that genuinely cannot sign — and nothing else.
|
|
203
|
+
*
|
|
204
|
+
* Two distinct capabilities are checked, because two distinct things fail:
|
|
205
|
+
*
|
|
206
|
+
* - `signTypedData` is needed by EVERY command. Fund-moving commands self-sign
|
|
207
|
+
* an EIP-712 `SpendMandate`; `invoke` signs an EIP-712
|
|
208
|
+
* `InvocationCapability`. Without it the run dies at the first signature
|
|
209
|
+
* with a `TypeError` from inside viem.
|
|
210
|
+
* - A LOCAL account is needed only where the CLI broadcasts through
|
|
211
|
+
* `http(--rpc-url)`, which cannot sign. A Privy account is deliberately NOT
|
|
212
|
+
* local: its provider is the transport and performs `eth_sendTransaction`
|
|
213
|
+
* itself, so demanding locality there would reject a wallet that works.
|
|
214
|
+
*
|
|
215
|
+
* The earlier version of this guard collapsed both into "must be local", which
|
|
216
|
+
* is why Privy was refused. Deleting the guard outright was not the fix: it
|
|
217
|
+
* exists so a broken wallet fails here, named, instead of deep inside viem.
|
|
157
218
|
*/
|
|
158
|
-
function
|
|
159
|
-
if (account.
|
|
160
|
-
|
|
161
|
-
|
|
219
|
+
export function assertCliSigner(account, source) {
|
|
220
|
+
if (typeof account.signTypedData !== "function") {
|
|
221
|
+
throw configError(`the ${source} wallet (${account.address}) cannot sign EIP-712 typed data`, "every command signs typed data: fund-moving commands self-sign a spend mandate, and `invoke` signs an invocation capability.");
|
|
222
|
+
}
|
|
223
|
+
if (broadcastsLocally(source) && account.type !== "local") {
|
|
224
|
+
throw configError(`the ${source} wallet returned a ${account.type} account, which cannot sign locally`, "this wallet source broadcasts through --rpc-url, which cannot sign, so it needs a local signer.");
|
|
225
|
+
}
|
|
226
|
+
return account;
|
|
162
227
|
}
|
|
163
228
|
function isSet(value) {
|
|
164
229
|
return value !== undefined && value.length > 0;
|
package/dist/cli/wallet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/cli/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/cli/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,GAGtB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,0BAA0B,CAAC;AAE1D,qFAAqF;AACrF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,gBAAgB;IAChB,oBAAoB;IACpB,mBAAmB;IACnB,6BAA6B;CACrB,CAAC;AAEX,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AASpB,MAAM,YAAY,GAA+B;IAC/C,WAAW,EAAE,qBAAqB;IAClC,UAAU,EACR,gFAAgF;CACnF,CAAC;AAwCF,MAAM,WAAW,GACf,UAAU,eAAe,oEAAoE;IAC7F,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,sCAAsC,oBAAoB,oBAAoB;IACxG,GAAG,sBAAsB,CAAC,IAAI,CAAC,IAAI,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AW,CACf,OAAO,MAAM,sBAAsB,OAAO,CAAC,IAAI,qCAAqC,EACpF,iGAAiG,CAClG,CAAC;IACJ,CAAC;IACD,OAAO,OAA2B,CAAC;AACrC,CAAC;AAED,SAAS,KAAK,CAAC,KAAyB;IACtC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,QAAQ,CAAC,KAAyB;IACzC,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,GAAG,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SignedRateBoundsError, type SignedRateBounds } from "../gateway/signed-rate-bounds.js";
|
|
2
|
+
/**
|
|
3
|
+
* The buyer-side twin of the gateway's signed-rate check.
|
|
4
|
+
*
|
|
5
|
+
* `StreamEscrowV2.openStream` accepts any non-zero `ratePerSecond`; the band a
|
|
6
|
+
* seller will actually SERVE lives in its operator-signed descriptor
|
|
7
|
+
* (`commercial.minRatePerSecond` / `maxRatePerSecond`), and the seller's
|
|
8
|
+
* capability gateway answers every request on an out-of-band stream with
|
|
9
|
+
* `403 stream-rate-out-of-bounds`. Opening such a stream locks the buyer's
|
|
10
|
+
* deposit in a stream that can never be served, so every buyer surface that
|
|
11
|
+
* takes a caller-chosen rate checks it against the SAME band, with the SAME
|
|
12
|
+
* verification ({@link verifySignedRateBounds}), before anything is broadcast.
|
|
13
|
+
*
|
|
14
|
+
* Nothing here is a second signature implementation: the bounds come only out
|
|
15
|
+
* of `verifySignedRateBounds`, which re-derives the serviceRef from the signed
|
|
16
|
+
* content and recovers the operator's EIP-712 signature.
|
|
17
|
+
*/
|
|
18
|
+
/** A listing as discovery hands it over: the serviceRef and its signed record. */
|
|
19
|
+
export interface RateBandListing {
|
|
20
|
+
readonly serviceRef: string;
|
|
21
|
+
readonly signed: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The operator-signed rate band of a verified listing.
|
|
25
|
+
*
|
|
26
|
+
* - `null`: the listing is a legacy service BINDING, which carries no
|
|
27
|
+
* commercial terms, so the operator signed no band and there is nothing to
|
|
28
|
+
* enforce (the gateway enforces none either).
|
|
29
|
+
* - a {@link SignedRateBounds}: the descriptor verified. Either bound may still
|
|
30
|
+
* be `null` when the operator signed only one side, or none.
|
|
31
|
+
*
|
|
32
|
+
* Throws {@link SignedRateBoundsError} when the record IS a descriptor but does
|
|
33
|
+
* not verify, or verifies for a different serviceRef than the listing claims.
|
|
34
|
+
* Callers must treat that as a refusal: a band that cannot be verified is not a
|
|
35
|
+
* band that can be assumed absent.
|
|
36
|
+
*/
|
|
37
|
+
export declare function listingRateBand(listing: RateBandListing): Promise<SignedRateBounds | null>;
|
|
38
|
+
/**
|
|
39
|
+
* The signed band in both units, e.g. `100..10000 atomic/s (0.0001..0.01
|
|
40
|
+
* USDC/s)`. A one-sided band reads `at least 100 atomic/s (…)` /
|
|
41
|
+
* `at most 10000 atomic/s (…)`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function describeRateBand(bounds: SignedRateBounds): string;
|
|
44
|
+
/**
|
|
45
|
+
* `undefined` when `rate` is inside the operator-signed band (bounds are
|
|
46
|
+
* inclusive, exactly as the gateway applies them), otherwise an actionable
|
|
47
|
+
* refusal naming the band in atomic units and USDC. `rateLabel` is how the
|
|
48
|
+
* caller supplied the rate (`--rate`, `ratePerSecondUsdc`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function rateBandRefusal(rate: bigint, bounds: SignedRateBounds, rateLabel: string): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Outcome of {@link checkListedRateBand}: `ok: false` is a refusal, and its
|
|
53
|
+
* `message` is safe to hand straight back to the caller.
|
|
54
|
+
*/
|
|
55
|
+
export type ListedRateBandCheck = {
|
|
56
|
+
readonly ok: true;
|
|
57
|
+
/** `unlisted`: no verified listing, so no operator-signed band exists. */
|
|
58
|
+
readonly band: "in-band" | "no-band-signed" | "unlisted";
|
|
59
|
+
} | {
|
|
60
|
+
readonly ok: false;
|
|
61
|
+
readonly message: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Discover the serviceRef's verified listing(s) and check `rate` against every
|
|
65
|
+
* operator-signed band among them, for a surface that has no listing in hand.
|
|
66
|
+
*
|
|
67
|
+
* Fail closed: a registry that cannot be read means a signed band may exist and
|
|
68
|
+
* is unknown, so it is a refusal — never a pass. A serviceRef with no verified
|
|
69
|
+
* listing has no signed band to violate, and is allowed (these surfaces never
|
|
70
|
+
* required a listing to hire).
|
|
71
|
+
*/
|
|
72
|
+
export declare function checkListedRateBand(discover: () => Promise<readonly RateBandListing[]>, serviceRef: string, rate: bigint, rateLabel: string): Promise<ListedRateBandCheck>;
|
|
73
|
+
export { SignedRateBoundsError };
|
|
74
|
+
//# sourceMappingURL=rate-band.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-band.d.ts","sourceRoot":"","sources":["../../src/discovery/rate-band.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,qBAAqB,EAErB,KAAK,gBAAgB,EACtB,MAAM,kCAAkC,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AAEH,kFAAkF;AAClF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAgBlC;AAOD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAYjE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAIpB;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IACE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,gBAAgB,GAAG,UAAU,CAAC;CAC1D,GACD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC,EACnD,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,mBAAmB,CAAC,CAqC9B;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { formatUnits } from "viem";
|
|
2
|
+
import { rateOutsideBounds, SignedRateBoundsError, verifySignedRateBounds, } from "../gateway/signed-rate-bounds.js";
|
|
3
|
+
/**
|
|
4
|
+
* The operator-signed rate band of a verified listing.
|
|
5
|
+
*
|
|
6
|
+
* - `null`: the listing is a legacy service BINDING, which carries no
|
|
7
|
+
* commercial terms, so the operator signed no band and there is nothing to
|
|
8
|
+
* enforce (the gateway enforces none either).
|
|
9
|
+
* - a {@link SignedRateBounds}: the descriptor verified. Either bound may still
|
|
10
|
+
* be `null` when the operator signed only one side, or none.
|
|
11
|
+
*
|
|
12
|
+
* Throws {@link SignedRateBoundsError} when the record IS a descriptor but does
|
|
13
|
+
* not verify, or verifies for a different serviceRef than the listing claims.
|
|
14
|
+
* Callers must treat that as a refusal: a band that cannot be verified is not a
|
|
15
|
+
* band that can be assumed absent.
|
|
16
|
+
*/
|
|
17
|
+
export async function listingRateBand(listing) {
|
|
18
|
+
const signed = listing.signed;
|
|
19
|
+
if (typeof signed !== "object" ||
|
|
20
|
+
signed === null ||
|
|
21
|
+
!("descriptor" in signed)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const bounds = await verifySignedRateBounds(signed);
|
|
25
|
+
if (bounds.serviceRef !== listing.serviceRef.toLowerCase()) {
|
|
26
|
+
throw new SignedRateBoundsError(`the signed descriptor verifies for serviceRef ${bounds.serviceRef}, not the listed ${listing.serviceRef}`);
|
|
27
|
+
}
|
|
28
|
+
return bounds;
|
|
29
|
+
}
|
|
30
|
+
/** `0.0001` for `100n` — USDC has 6 decimals. */
|
|
31
|
+
function usdc(atomic) {
|
|
32
|
+
return formatUnits(atomic, 6);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The signed band in both units, e.g. `100..10000 atomic/s (0.0001..0.01
|
|
36
|
+
* USDC/s)`. A one-sided band reads `at least 100 atomic/s (…)` /
|
|
37
|
+
* `at most 10000 atomic/s (…)`.
|
|
38
|
+
*/
|
|
39
|
+
export function describeRateBand(bounds) {
|
|
40
|
+
const { minRatePerSecond: min, maxRatePerSecond: max } = bounds;
|
|
41
|
+
if (min !== null && max !== null) {
|
|
42
|
+
return `${min}..${max} atomic/s (${usdc(min)}..${usdc(max)} USDC/s)`;
|
|
43
|
+
}
|
|
44
|
+
if (min !== null) {
|
|
45
|
+
return `at least ${min} atomic/s (${usdc(min)} USDC/s)`;
|
|
46
|
+
}
|
|
47
|
+
if (max !== null) {
|
|
48
|
+
return `at most ${max} atomic/s (${usdc(max)} USDC/s)`;
|
|
49
|
+
}
|
|
50
|
+
return "any rate (the operator signed no bounds)";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `undefined` when `rate` is inside the operator-signed band (bounds are
|
|
54
|
+
* inclusive, exactly as the gateway applies them), otherwise an actionable
|
|
55
|
+
* refusal naming the band in atomic units and USDC. `rateLabel` is how the
|
|
56
|
+
* caller supplied the rate (`--rate`, `ratePerSecondUsdc`).
|
|
57
|
+
*/
|
|
58
|
+
export function rateBandRefusal(rate, bounds, rateLabel) {
|
|
59
|
+
const outside = rateOutsideBounds(rate, bounds);
|
|
60
|
+
if (outside === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
return `the operator signed rates ${describeRateBand(bounds)}; ${rateLabel} ${rate} (${usdc(rate)} USDC/s) would be refused by the service's gateway (${outside}), so the stream could never be served. Nothing was broadcast.`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Discover the serviceRef's verified listing(s) and check `rate` against every
|
|
66
|
+
* operator-signed band among them, for a surface that has no listing in hand.
|
|
67
|
+
*
|
|
68
|
+
* Fail closed: a registry that cannot be read means a signed band may exist and
|
|
69
|
+
* is unknown, so it is a refusal — never a pass. A serviceRef with no verified
|
|
70
|
+
* listing has no signed band to violate, and is allowed (these surfaces never
|
|
71
|
+
* required a listing to hire).
|
|
72
|
+
*/
|
|
73
|
+
export async function checkListedRateBand(discover, serviceRef, rate, rateLabel) {
|
|
74
|
+
let listings;
|
|
75
|
+
try {
|
|
76
|
+
listings = await discover();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
ok: false,
|
|
81
|
+
message: `refusing to hire: the service registry could not be read (${error instanceof Error ? error.message : String(error)}), so the operator-signed rate band for ${serviceRef} cannot be checked and the stream might never be served. Nothing was spent — retry when the registry answers.`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const wanted = serviceRef.toLowerCase();
|
|
85
|
+
const matches = listings.filter((listing) => listing.serviceRef.toLowerCase() === wanted);
|
|
86
|
+
if (matches.length === 0)
|
|
87
|
+
return { ok: true, band: "unlisted" };
|
|
88
|
+
let signedAny = false;
|
|
89
|
+
for (const listing of matches) {
|
|
90
|
+
let bounds;
|
|
91
|
+
try {
|
|
92
|
+
bounds = await listingRateBand(listing);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error instanceof SignedRateBoundsError) {
|
|
96
|
+
return {
|
|
97
|
+
ok: false,
|
|
98
|
+
message: `refusing to hire: the listing's operator-signed rate band could not be verified (${error.message}). Nothing was spent.`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
if (bounds === null)
|
|
104
|
+
continue;
|
|
105
|
+
signedAny = true;
|
|
106
|
+
const refusal = rateBandRefusal(rate, bounds, rateLabel);
|
|
107
|
+
if (refusal !== undefined) {
|
|
108
|
+
return { ok: false, message: `refusing to hire: ${refusal}` };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { ok: true, band: signedAny ? "in-band" : "no-band-signed" };
|
|
112
|
+
}
|
|
113
|
+
export { SignedRateBoundsError };
|
|
114
|
+
//# sourceMappingURL=rate-band.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-band.js","sourceRoot":"","sources":["../../src/discovery/rate-band.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,kCAAkC,CAAC;AAyB1C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAwB;IAExB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,IACE,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IAAI;QACf,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,EACzB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,MAAM,CAAC,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC;QAC3D,MAAM,IAAI,qBAAqB,CAC7B,iDAAiD,MAAM,CAAC,UAAU,oBAAoB,OAAO,CAAC,UAAU,EAAE,CAC3G,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB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K,EAAE,OAAO,EAAE,qBAAqB,OAAO,EAAE,EAAE,CAAC;QAChE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACtE,CAAC;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Escrow-generation-specific rules, driven by the SDK network registry's
|
|
4
|
+
* `escrow.generation` (metrik-agent#121).
|
|
5
|
+
*
|
|
6
|
+
* Today the registry knows only `v2` (`StreamEscrowV2`). `StreamEscrowV3`
|
|
7
|
+
* changes one rule the agent reasons about: the buyer's no-proof escape hatch.
|
|
8
|
+
*
|
|
9
|
+
* - **V2**: `reclaimUnverified` opens at `expiresAt + escapeGraceSeconds`.
|
|
10
|
+
* Closing early does NOT bring it forward.
|
|
11
|
+
* - **V3**: it opens at `min(expiresAt, closedAt) + escapeGraceSeconds`, and the
|
|
12
|
+
* escrow exposes `escapeHatchReadyAt(bytes32)` to read it directly. Where a
|
|
13
|
+
* chain read is available it is preferred over re-deriving the formula.
|
|
14
|
+
*
|
|
15
|
+
* An unknown generation is refused, never guessed: a wrong readiness answer
|
|
16
|
+
* either sends a buyer a guaranteed revert or tells them to wait when they need
|
|
17
|
+
* not. (V3 also restricts `recordProven` to the stream's operator or an active
|
|
18
|
+
* oracle signer; no agent or relay path calls it on a buyer's behalf.)
|
|
19
|
+
*/
|
|
20
|
+
/** Escrow generations whose escape-hatch rule this package implements. */
|
|
21
|
+
export type KnownEscrowGeneration = "v2" | "v3";
|
|
22
|
+
export declare class UnsupportedEscrowGenerationError extends Error {
|
|
23
|
+
readonly generation: string;
|
|
24
|
+
constructor(generation: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The generation of `escrow` on `chainId`, from the network registry. An escrow
|
|
28
|
+
* the registry does not record is treated as V2 — the generation every
|
|
29
|
+
* unregistered, explicitly configured Metrik deployment speaks today.
|
|
30
|
+
*/
|
|
31
|
+
export declare function escrowGenerationFor(chainId: number, escrow: Address): KnownEscrowGeneration;
|
|
32
|
+
/**
|
|
33
|
+
* The second the no-proof escape hatch opens, by formula. `closedAt` is `0`
|
|
34
|
+
* while the stream is open.
|
|
35
|
+
*/
|
|
36
|
+
export declare function escapeHatchReadyAtFormula(generation: string, stream: {
|
|
37
|
+
readonly expiresAt: bigint;
|
|
38
|
+
readonly closedAt: bigint;
|
|
39
|
+
}, graceSeconds: bigint): bigint;
|
|
40
|
+
/**
|
|
41
|
+
* `StreamEscrowV3.escapeHatchReadyAt(bytes32)`. A one-function fragment until
|
|
42
|
+
* the SDK ships the V3 ABI; replace it with the SDK's export then.
|
|
43
|
+
*/
|
|
44
|
+
export declare const streamEscrowV3EscapeHatchAbi: readonly [{
|
|
45
|
+
readonly type: "function";
|
|
46
|
+
readonly name: "escapeHatchReadyAt";
|
|
47
|
+
readonly stateMutability: "view";
|
|
48
|
+
readonly inputs: readonly [{
|
|
49
|
+
readonly name: "streamId";
|
|
50
|
+
readonly type: "bytes32";
|
|
51
|
+
}];
|
|
52
|
+
readonly outputs: readonly [{
|
|
53
|
+
readonly name: "";
|
|
54
|
+
readonly type: "uint256";
|
|
55
|
+
}];
|
|
56
|
+
}];
|
|
57
|
+
/** The minimal read surface {@link readEscapeHatchReadyAt} needs. */
|
|
58
|
+
export interface EscapeHatchReader {
|
|
59
|
+
readContract(args: {
|
|
60
|
+
readonly address: Address;
|
|
61
|
+
readonly abi: typeof streamEscrowV3EscapeHatchAbi;
|
|
62
|
+
readonly functionName: "escapeHatchReadyAt";
|
|
63
|
+
readonly args: readonly [Hex];
|
|
64
|
+
}): Promise<bigint>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The escape-hatch second for one stream: V3 reads the escrow's own view (and
|
|
68
|
+
* falls back to the V3 formula if that read fails); V2 uses its formula.
|
|
69
|
+
*/
|
|
70
|
+
export declare function readEscapeHatchReadyAt(input: {
|
|
71
|
+
readonly generation: string;
|
|
72
|
+
readonly reader: EscapeHatchReader;
|
|
73
|
+
readonly escrow: Address;
|
|
74
|
+
readonly streamId: Hex;
|
|
75
|
+
readonly stream: {
|
|
76
|
+
readonly expiresAt: bigint;
|
|
77
|
+
readonly closedAt: bigint;
|
|
78
|
+
};
|
|
79
|
+
readonly graceSeconds: bigint;
|
|
80
|
+
}): Promise<bigint>;
|
|
81
|
+
//# sourceMappingURL=escrow-generation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-generation.d.ts","sourceRoot":"","sources":["../src/escrow-generation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,qBAAqB,GAAG,IAAI,GAAG,IAAI,CAAC;AAEhD,qBAAa,gCAAiC,SAAQ,KAAK;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,UAAU,EAAE,MAAM;CAO/B;AAOD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,OAAO,GACd,qBAAqB,CAMvB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EACjE,YAAY,EAAE,MAAM,GACnB,MAAM,CAYR;AAED;;;GAGG;AACH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;EAQ/B,CAAC;AAEX,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,IAAI,EAAE;QACjB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAC1B,QAAQ,CAAC,GAAG,EAAE,OAAO,4BAA4B,CAAC;QAClD,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;QAC5C,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;KAC/B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBlB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { findDeployment } from "@absol-labs/sdk";
|
|
2
|
+
export class UnsupportedEscrowGenerationError extends Error {
|
|
3
|
+
generation;
|
|
4
|
+
constructor(generation) {
|
|
5
|
+
super(`escrow generation "${generation}" is not one this package knows the escape-hatch rule for (known: v2, v3)`);
|
|
6
|
+
this.name = "UnsupportedEscrowGenerationError";
|
|
7
|
+
this.generation = generation;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function known(generation) {
|
|
11
|
+
if (generation === "v2" || generation === "v3")
|
|
12
|
+
return generation;
|
|
13
|
+
throw new UnsupportedEscrowGenerationError(generation);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The generation of `escrow` on `chainId`, from the network registry. An escrow
|
|
17
|
+
* the registry does not record is treated as V2 — the generation every
|
|
18
|
+
* unregistered, explicitly configured Metrik deployment speaks today.
|
|
19
|
+
*/
|
|
20
|
+
export function escrowGenerationFor(chainId, escrow) {
|
|
21
|
+
return known(
|
|
22
|
+
// The generation of THIS deployment (current or legacy), not of the
|
|
23
|
+
// network's current escrow.
|
|
24
|
+
findDeployment(chainId, escrow)?.deployment.escrow.generation ?? "v2");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The second the no-proof escape hatch opens, by formula. `closedAt` is `0`
|
|
28
|
+
* while the stream is open.
|
|
29
|
+
*/
|
|
30
|
+
export function escapeHatchReadyAtFormula(generation, stream, graceSeconds) {
|
|
31
|
+
switch (known(generation)) {
|
|
32
|
+
case "v2":
|
|
33
|
+
return stream.expiresAt + graceSeconds;
|
|
34
|
+
case "v3": {
|
|
35
|
+
const stop = stream.closedAt > 0n && stream.closedAt < stream.expiresAt
|
|
36
|
+
? stream.closedAt
|
|
37
|
+
: stream.expiresAt;
|
|
38
|
+
return stop + graceSeconds;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `StreamEscrowV3.escapeHatchReadyAt(bytes32)`. A one-function fragment until
|
|
44
|
+
* the SDK ships the V3 ABI; replace it with the SDK's export then.
|
|
45
|
+
*/
|
|
46
|
+
export const streamEscrowV3EscapeHatchAbi = [
|
|
47
|
+
{
|
|
48
|
+
type: "function",
|
|
49
|
+
name: "escapeHatchReadyAt",
|
|
50
|
+
stateMutability: "view",
|
|
51
|
+
inputs: [{ name: "streamId", type: "bytes32" }],
|
|
52
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* The escape-hatch second for one stream: V3 reads the escrow's own view (and
|
|
57
|
+
* falls back to the V3 formula if that read fails); V2 uses its formula.
|
|
58
|
+
*/
|
|
59
|
+
export async function readEscapeHatchReadyAt(input) {
|
|
60
|
+
const generation = known(input.generation);
|
|
61
|
+
if (generation === "v3") {
|
|
62
|
+
try {
|
|
63
|
+
return await input.reader.readContract({
|
|
64
|
+
address: input.escrow,
|
|
65
|
+
abi: streamEscrowV3EscapeHatchAbi,
|
|
66
|
+
functionName: "escapeHatchReadyAt",
|
|
67
|
+
args: [input.streamId],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Fall through to the V3 formula: the same rule the view implements.
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return escapeHatchReadyAtFormula(generation, input.stream, input.graceSeconds);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=escrow-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-generation.js","sourceRoot":"","sources":["../src/escrow-generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAyBjD,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IAChD,UAAU,CAAS;IAE5B,YAAY,UAAkB;QAC5B,KAAK,CACH,sBAAsB,UAAU,2EAA2E,CAC5G,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,SAAS,KAAK,CAAC,UAAkB;IAC/B,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,UAAU,CAAC;IAClE,MAAM,IAAI,gCAAgC,CAAC,UAAU,CAAC,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAe,EACf,MAAe;IAEf,OAAO,KAAK;IACV,oEAAoE;IACpE,4BAA4B;IAC5B,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU,IAAI,IAAI,CACtE,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,UA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