@absol-labs/agent 0.11.0 → 0.12.0-rc.2
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 +43 -51
- package/dist/capability/invocation-capability.d.ts +2 -2
- 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 +32 -0
- package/dist/cli/commands/claim.d.ts.map +1 -1
- package/dist/cli/commands/claim.js +116 -28
- 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 +35 -3
- 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 +2 -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 +58 -4
- package/dist/cli/commands/open.js.map +1 -1
- package/dist/cli/commands/pay.d.ts +34 -0
- package/dist/cli/commands/pay.d.ts.map +1 -0
- package/dist/cli/commands/pay.js +479 -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 +3 -2
- 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 +204 -20
- package/dist/cli/commands/reclaim.js.map +1 -1
- package/dist/cli/commands/refund.d.ts +31 -0
- package/dist/cli/commands/refund.d.ts.map +1 -0
- package/dist/cli/commands/refund.js +397 -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 +21 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/streams.js +8 -12
- 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 +4 -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/context.d.ts +19 -0
- package/dist/cli/context.d.ts.map +1 -1
- package/dist/cli/deps.d.ts +53 -0
- package/dist/cli/deps.d.ts.map +1 -1
- package/dist/cli/deps.js +51 -1
- 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.map +1 -1
- package/dist/cli/privy.js +4 -2
- package/dist/cli/privy.js.map +1 -1
- package/dist/cli/progress.d.ts +13 -1
- package/dist/cli/progress.d.ts.map +1 -1
- package/dist/cli/progress.js +7 -1
- package/dist/cli/progress.js.map +1 -1
- 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 +62 -21
- 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/status.d.ts +106 -1
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +325 -44
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/wallet.d.ts +2 -2
- package/dist/cli/wallet.d.ts.map +1 -1
- package/dist/cli/wallet.js +29 -5
- 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 +83 -31
- package/dist/gateway/caller-auth-gateway.d.ts.map +1 -1
- package/dist/gateway/caller-auth-gateway.js +180 -27
- package/dist/gateway/caller-auth-gateway.js.map +1 -1
- package/dist/gateway/http-server.d.ts +128 -44
- package/dist/gateway/http-server.d.ts.map +1 -1
- package/dist/gateway/http-server.js +506 -155
- 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 +252 -0
- package/dist/gateway/x402-opener-mode.d.ts.map +1 -0
- package/dist/gateway/x402-opener-mode.js +772 -0
- package/dist/gateway/x402-opener-mode.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts +64 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +247 -37
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/x402-tools.d.ts +109 -0
- package/dist/mcp/x402-tools.d.ts.map +1 -0
- package/dist/mcp/x402-tools.js +554 -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/client.d.ts +13 -0
- package/dist/sdk/client.d.ts.map +1 -1
- package/dist/sdk/client.js +15 -0
- package/dist/sdk/client.js.map +1 -1
- package/dist/sdk/invoke.d.ts +4 -0
- package/dist/sdk/invoke.d.ts.map +1 -1
- package/dist/sdk/invoke.js +2 -5
- 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 +3 -30
- package/dist/x402/facilitator.d.ts.map +1 -1
- package/dist/x402/facilitator.js +0 -27
- 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 +157 -0
- package/dist/x402-buyer/pay.d.ts.map +1 -0
- package/dist/x402-buyer/pay.js +366 -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 +40 -0
- package/dist/x402-opener/facilitator-entry.js.map +1 -0
- package/dist/x402-opener/facilitator-server.d.ts +209 -0
- package/dist/x402-opener/facilitator-server.d.ts.map +1 -0
- package/dist/x402-opener/facilitator-server.js +762 -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 +266 -0
- package/dist/x402-opener/refund-relay.d.ts.map +1 -0
- package/dist/x402-opener/refund-relay.js +1341 -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 +296 -0
- package/dist/x402-opener/scheme.d.ts.map +1 -0
- package/dist/x402-opener/scheme.js +1035 -0
- package/dist/x402-opener/scheme.js.map +1 -0
- package/dist/x402-opener/terms.d.ts +165 -0
- package/dist/x402-opener/terms.d.ts.map +1 -0
- package/dist/x402-opener/terms.js +304 -0
- package/dist/x402-opener/terms.js.map +1 -0
- package/dist/zktls/reclaim.d.ts +2 -2
- package/dist/zktls/t2-delivery-proof.d.ts +6 -6
- package/docs/agent-layer.md +3 -2
- package/docs/autonomous-privy-wallet.md +188 -0
- package/docs/cli.md +265 -34
- package/docs/langchain.md +5 -0
- package/docs/mcp-reference.md +91 -5
- package/docs/probe-capability.md +191 -0
- package/docs/quickstart.md +39 -4
- package/docs/threat-model.md +20 -0
- package/docs/x402.md +766 -593
- package/package.json +19 -17
- package/src/capability/probe-capability.ts +355 -0
- package/src/cli/args.ts +29 -0
- package/src/cli/commands/claim.ts +168 -33
- package/src/cli/commands/close.ts +36 -3
- package/src/cli/commands/invoke.ts +5 -2
- package/src/cli/commands/mcp.ts +18 -2
- package/src/cli/commands/open.ts +75 -4
- package/src/cli/commands/pay.ts +584 -0
- package/src/cli/commands/reclaim-unverified.ts +8 -2
- package/src/cli/commands/reclaim.ts +277 -19
- package/src/cli/commands/refund.ts +475 -0
- package/src/cli/commands/status.ts +28 -2
- package/src/cli/commands/streams.ts +10 -14
- package/src/cli/commands/watch.ts +11 -1
- package/src/cli/config.ts +139 -52
- package/src/cli/context.ts +16 -0
- package/src/cli/deps.ts +111 -1
- 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 +4 -2
- package/src/cli/progress.ts +21 -2
- package/src/cli/reclaimability.ts +154 -0
- package/src/cli/run.ts +77 -21
- package/src/cli/scan-range.ts +2 -2
- package/src/cli/status.ts +454 -44
- package/src/cli/wallet.ts +45 -8
- 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 +320 -68
- package/src/gateway/http-server.ts +717 -220
- package/src/gateway/probe-auth.ts +191 -0
- package/src/gateway/signed-rate-bounds.ts +164 -0
- package/src/gateway/x402-opener-mode.ts +1171 -0
- package/src/index.ts +82 -19
- package/src/mcp/server.ts +351 -42
- package/src/mcp/x402-tools.ts +785 -0
- package/src/network.ts +302 -0
- package/src/sdk/client.ts +25 -0
- package/src/sdk/invoke.ts +6 -5
- 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 +3 -43
- package/src/x402-buyer/guarded-fetch.ts +213 -0
- package/src/x402-buyer/index.ts +9 -0
- package/src/x402-buyer/pay.ts +555 -0
- package/src/x402-opener/abi.ts +881 -0
- package/src/x402-opener/facilitator-entry.ts +48 -0
- package/src/x402-opener/facilitator-server.ts +1114 -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 +1873 -0
- package/src/x402-opener/relayer-queue.ts +18 -0
- package/src/x402-opener/scheme.ts +1551 -0
- package/src/x402-opener/terms.ts +453 -0
- package/dist/gateway/x402-mode.d.ts +0 -123
- package/dist/gateway/x402-mode.d.ts.map +0 -1
- package/dist/gateway/x402-mode.js +0 -212
- package/dist/gateway/x402-mode.js.map +0 -1
- package/dist/x402/delivery-oracle.d.ts +0 -108
- package/dist/x402/delivery-oracle.d.ts.map +0 -1
- package/dist/x402/delivery-oracle.js +0 -174
- package/dist/x402/delivery-oracle.js.map +0 -1
- package/dist/x402/facilitator-server-entry.d.ts +0 -3
- package/dist/x402/facilitator-server-entry.d.ts.map +0 -1
- package/dist/x402/facilitator-server-entry.js +0 -27
- package/dist/x402/facilitator-server-entry.js.map +0 -1
- package/dist/x402/facilitator-server.d.ts +0 -73
- package/dist/x402/facilitator-server.d.ts.map +0 -1
- package/dist/x402/facilitator-server.js +0 -305
- package/dist/x402/facilitator-server.js.map +0 -1
- package/dist/x402/payment-requirements.d.ts +0 -106
- package/dist/x402/payment-requirements.d.ts.map +0 -1
- package/dist/x402/payment-requirements.js +0 -138
- package/dist/x402/payment-requirements.js.map +0 -1
- package/dist/x402/relayer.d.ts +0 -41
- package/dist/x402/relayer.d.ts.map +0 -1
- package/dist/x402/relayer.js +0 -64
- package/dist/x402/relayer.js.map +0 -1
- package/dist/x402/resource-index.d.ts +0 -75
- package/dist/x402/resource-index.d.ts.map +0 -1
- package/dist/x402/resource-index.js +0 -126
- package/dist/x402/resource-index.js.map +0 -1
- package/dist/x402/verified-delivery-facilitator.d.ts +0 -285
- package/dist/x402/verified-delivery-facilitator.d.ts.map +0 -1
- package/dist/x402/verified-delivery-facilitator.js +0 -423
- package/dist/x402/verified-delivery-facilitator.js.map +0 -1
- package/src/gateway/x402-mode.ts +0 -350
- package/src/x402/delivery-oracle.ts +0 -285
- package/src/x402/facilitator-server-entry.ts +0 -35
- package/src/x402/facilitator-server.ts +0 -445
- package/src/x402/payment-requirements.ts +0 -231
- package/src/x402/relayer.ts +0 -122
- package/src/x402/resource-index.ts +0 -228
- package/src/x402/verified-delivery-facilitator.ts +0 -744
package/src/wallet/lifecycle.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { networkForChainId } from "@absol-labs/sdk";
|
|
1
2
|
import { erc20Abi, type Address } from "viem";
|
|
2
3
|
|
|
4
|
+
import {
|
|
5
|
+
defaultNetwork,
|
|
6
|
+
describeAllowedNetworks,
|
|
7
|
+
networkFunding,
|
|
8
|
+
} from "../network.js";
|
|
9
|
+
|
|
3
10
|
/**
|
|
4
11
|
* Agent wallet lifecycle helpers (metrik-agent#65).
|
|
5
12
|
*
|
|
@@ -21,7 +28,7 @@ import { erc20Abi, type Address } from "viem";
|
|
|
21
28
|
|
|
22
29
|
/** Native gas balance + USDC balance for one address. */
|
|
23
30
|
export interface WalletBalances {
|
|
24
|
-
/** Native token balance
|
|
31
|
+
/** Native gas-token balance, in its smallest unit (the network's `gasToken.decimals`). */
|
|
25
32
|
readonly nativeWei: bigint;
|
|
26
33
|
/** USDC balance, in atomic units (6 decimals). */
|
|
27
34
|
readonly usdcAtomic: bigint;
|
|
@@ -63,10 +70,21 @@ export async function getWalletBalances(
|
|
|
63
70
|
|
|
64
71
|
/** Human-facing pointers to fund a freshly created/restored testnet wallet. */
|
|
65
72
|
export interface FaucetHint {
|
|
73
|
+
/** The Coinbase CDP faucet's name for the network (e.g. what `requestCdpFaucet` sends). */
|
|
66
74
|
readonly network: string;
|
|
67
|
-
/**
|
|
75
|
+
/** The registry id of the network the hint is for. */
|
|
76
|
+
readonly networkId: string;
|
|
77
|
+
/**
|
|
78
|
+
* The network's gas token, from the registry's gas-token metadata. NOT always
|
|
79
|
+
* ETH: where gas is the settlement token, it is USDC and
|
|
80
|
+
* {@link FaucetHint.gasIsSettlementToken} is `true`.
|
|
81
|
+
*/
|
|
82
|
+
readonly gasToken: string;
|
|
83
|
+
/** Whether gas is paid in the same token streams settle in (one balance to fund). */
|
|
84
|
+
readonly gasIsSettlementToken: boolean;
|
|
85
|
+
/** Coinbase CDP faucet — funds the gas token (and, on some networks, USDC) for a CDP-managed address. */
|
|
68
86
|
readonly cdpFaucetUrl: string;
|
|
69
|
-
/** Circle's
|
|
87
|
+
/** Circle's USDC faucet for the network — a USDC source that doesn't require a CDP account. */
|
|
70
88
|
readonly usdcFaucetUrl: string;
|
|
71
89
|
/** How to request the same funds programmatically from a CDP wallet — see {@link requestCdpFaucet}. */
|
|
72
90
|
readonly programmaticHint: string;
|
|
@@ -75,28 +93,42 @@ export interface FaucetHint {
|
|
|
75
93
|
export class UnsupportedFaucetChainError extends Error {
|
|
76
94
|
constructor(chainId: number) {
|
|
77
95
|
super(
|
|
78
|
-
`no known testnet faucet for chainId ${chainId} (
|
|
96
|
+
`no known testnet faucet for chainId ${chainId} (registered testnets: ${describeAllowedNetworks({ testnetOnly: true })})`,
|
|
79
97
|
);
|
|
80
98
|
this.name = "UnsupportedFaucetChainError";
|
|
81
99
|
}
|
|
82
100
|
}
|
|
83
101
|
|
|
84
|
-
const
|
|
102
|
+
const CDP_FAUCET_URL = "https://portal.cdp.coinbase.com/products/faucet";
|
|
85
103
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/** A faucet hint for the given chain. Only Base Sepolia (84532) is supported — Metrik is testnet-only, single-chain. */
|
|
104
|
+
/**
|
|
105
|
+
* A faucet hint for the given chain, read from the network registry (gas token)
|
|
106
|
+
* plus the agent's funding catalogue (faucet URLs). Only a registered TESTNET
|
|
107
|
+
* with a known CDP faucet has one; anything else throws
|
|
108
|
+
* {@link UnsupportedFaucetChainError}.
|
|
109
|
+
*/
|
|
95
110
|
export function faucetHint(chainId: number): FaucetHint {
|
|
96
|
-
|
|
111
|
+
const network = networkForChainId(chainId);
|
|
112
|
+
if (network === undefined || !network.testnet) {
|
|
113
|
+
throw new UnsupportedFaucetChainError(chainId);
|
|
114
|
+
}
|
|
115
|
+
const funding = networkFunding(network);
|
|
116
|
+
if (funding.cdpNetwork === null || funding.usdcFaucetUrl === null) {
|
|
97
117
|
throw new UnsupportedFaucetChainError(chainId);
|
|
98
118
|
}
|
|
99
|
-
|
|
119
|
+
const gasToken = network.gasToken.symbol;
|
|
120
|
+
const tokens = network.gasToken.isSettlementToken
|
|
121
|
+
? "'usdc'"
|
|
122
|
+
: `'${gasToken.toLowerCase()}' | 'usdc'`;
|
|
123
|
+
return {
|
|
124
|
+
network: funding.cdpNetwork,
|
|
125
|
+
networkId: network.id,
|
|
126
|
+
gasToken,
|
|
127
|
+
gasIsSettlementToken: network.gasToken.isSettlementToken,
|
|
128
|
+
cdpFaucetUrl: CDP_FAUCET_URL,
|
|
129
|
+
usdcFaucetUrl: funding.usdcFaucetUrl,
|
|
130
|
+
programmaticHint: `requestCdpFaucet({ cdp, address, token: ${tokens} }) — subject to a 24h per-address rate limit`,
|
|
131
|
+
};
|
|
100
132
|
}
|
|
101
133
|
|
|
102
134
|
export type FaucetToken = "eth" | "usdc";
|
|
@@ -116,7 +148,7 @@ export interface RequestCdpFaucetOptions {
|
|
|
116
148
|
readonly cdp: CdpFaucetClientLike;
|
|
117
149
|
readonly address: Address;
|
|
118
150
|
readonly token: FaucetToken;
|
|
119
|
-
/** Default
|
|
151
|
+
/** CDP faucet network name. Default: the registry's default network's CDP name. */
|
|
120
152
|
readonly network?: string;
|
|
121
153
|
}
|
|
122
154
|
|
|
@@ -145,7 +177,10 @@ export async function requestCdpFaucet(
|
|
|
145
177
|
try {
|
|
146
178
|
const result = await options.cdp.evm.requestFaucet({
|
|
147
179
|
address: options.address,
|
|
148
|
-
network:
|
|
180
|
+
network:
|
|
181
|
+
options.network ??
|
|
182
|
+
networkFunding(defaultNetwork()).cdpNetwork ??
|
|
183
|
+
defaultNetwork().id,
|
|
149
184
|
token: options.token,
|
|
150
185
|
});
|
|
151
186
|
return { requested: true, txHash: result.transactionHash };
|
|
@@ -20,12 +20,15 @@ import {
|
|
|
20
20
|
type AutonomousWalletProvision,
|
|
21
21
|
} from "./autonomous-wallet-broker.js";
|
|
22
22
|
import {
|
|
23
|
+
PRIVY_BROKER_CAIP2,
|
|
24
|
+
PRIVY_BROKER_CHAIN_ID,
|
|
23
25
|
PrivySessionBroker,
|
|
24
26
|
PrivySessionBrokerError,
|
|
25
27
|
type PrivyBrokerProvider,
|
|
26
28
|
type PrivyBrokerSession,
|
|
27
29
|
type PrivyBrokerSessionStore,
|
|
28
30
|
} from "./privy-session-broker.js";
|
|
31
|
+
import { defaultNetwork } from "../network.js";
|
|
29
32
|
|
|
30
33
|
const serverEnvSchema = z.object({
|
|
31
34
|
PRIVY_APP_ID: z.string().min(1),
|
|
@@ -56,7 +59,7 @@ const rpcSchema = z.object({
|
|
|
56
59
|
const autonomousProofSchema = z.object({
|
|
57
60
|
version: z.literal(1),
|
|
58
61
|
appId: z.string().min(1).max(200),
|
|
59
|
-
chainId: z.literal(
|
|
62
|
+
chainId: z.literal(PRIVY_BROKER_CHAIN_ID),
|
|
60
63
|
publicKey: z.string().min(1).max(1_024),
|
|
61
64
|
nonce: z.string().min(16).max(256),
|
|
62
65
|
issuedAt: z.number().int().safe(),
|
|
@@ -64,7 +67,7 @@ const autonomousProofSchema = z.object({
|
|
|
64
67
|
});
|
|
65
68
|
const autonomousProvisionSchema = z.object({
|
|
66
69
|
appId: z.string().min(1).max(200),
|
|
67
|
-
chainId: z.literal(
|
|
70
|
+
chainId: z.literal(PRIVY_BROKER_CHAIN_ID),
|
|
68
71
|
publicKey: z.string().min(1).max(1_024),
|
|
69
72
|
proof: autonomousProofSchema,
|
|
70
73
|
idempotencyKey: z.string().min(16).max(256),
|
|
@@ -92,7 +95,32 @@ export async function startPrivyBrokerServer(
|
|
|
92
95
|
appId: config.PRIVY_APP_ID,
|
|
93
96
|
appSecret: config.PRIVY_APP_SECRET,
|
|
94
97
|
});
|
|
95
|
-
|
|
98
|
+
// One read-only client per escrow: the current one, and a legacy one when an
|
|
99
|
+
// exit targets it (V2 and V3 share the getStream tuple).
|
|
100
|
+
const network = defaultNetwork();
|
|
101
|
+
const clients = new Map<string, MetrikClient>();
|
|
102
|
+
const clientFor = (escrow?: `0x${string}`): MetrikClient => {
|
|
103
|
+
const key = (escrow ?? network.escrow.address).toLowerCase();
|
|
104
|
+
let client = clients.get(key);
|
|
105
|
+
if (client === undefined) {
|
|
106
|
+
client = MetrikClient.forNetwork(
|
|
107
|
+
network,
|
|
108
|
+
escrow === undefined ? {} : { escrow },
|
|
109
|
+
);
|
|
110
|
+
clients.set(key, client);
|
|
111
|
+
}
|
|
112
|
+
return client;
|
|
113
|
+
};
|
|
114
|
+
const brokerStreamReader = {
|
|
115
|
+
getStream: async (streamId: Hex, escrow?: `0x${string}`) => {
|
|
116
|
+
const stream = await clientFor(escrow).getStreamV2(streamId);
|
|
117
|
+
return {
|
|
118
|
+
buyer: stream.buyer,
|
|
119
|
+
serviceRef: stream.serviceRef,
|
|
120
|
+
status: stream.status,
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
};
|
|
96
124
|
const provider = createPrivyProvider(client);
|
|
97
125
|
const autonomousBroker = new AutonomousWalletBroker({
|
|
98
126
|
appId: config.PRIVY_APP_ID,
|
|
@@ -102,31 +130,13 @@ export async function startPrivyBrokerServer(
|
|
|
102
130
|
config.METRIK_PRIVY_AUTONOMOUS_STORE ??
|
|
103
131
|
`${config.METRIK_PRIVY_SESSION_STORE}.autonomous`,
|
|
104
132
|
),
|
|
105
|
-
streamReader:
|
|
106
|
-
getStream: async (streamId) => {
|
|
107
|
-
const stream = await metrik.getStreamV2(streamId);
|
|
108
|
-
return {
|
|
109
|
-
buyer: stream.buyer,
|
|
110
|
-
serviceRef: stream.serviceRef,
|
|
111
|
-
status: stream.status,
|
|
112
|
-
};
|
|
113
|
-
},
|
|
114
|
-
},
|
|
133
|
+
streamReader: brokerStreamReader,
|
|
115
134
|
});
|
|
116
135
|
const broker = new PrivySessionBroker({
|
|
117
136
|
provider,
|
|
118
137
|
store: new JsonPrivyBrokerSessionStore(config.METRIK_PRIVY_SESSION_STORE),
|
|
119
138
|
authorizationPrivateKey,
|
|
120
|
-
streamReader:
|
|
121
|
-
getStream: async (streamId) => {
|
|
122
|
-
const stream = await metrik.getStreamV2(streamId);
|
|
123
|
-
return {
|
|
124
|
-
buyer: stream.buyer,
|
|
125
|
-
serviceRef: stream.serviceRef,
|
|
126
|
-
status: stream.status,
|
|
127
|
-
};
|
|
128
|
-
},
|
|
129
|
-
},
|
|
139
|
+
streamReader: brokerStreamReader,
|
|
130
140
|
});
|
|
131
141
|
const allowedOrigins = new Set(
|
|
132
142
|
config.METRIK_PRIVY_ALLOWED_ORIGINS.split(",").map((value) => value.trim()),
|
|
@@ -150,7 +160,7 @@ export async function startPrivyBrokerServer(
|
|
|
150
160
|
appId: config.PRIVY_APP_ID,
|
|
151
161
|
keyQuorumId: config.PRIVY_KEY_QUORUM_ID,
|
|
152
162
|
policyId: config.PRIVY_POLICY_ID,
|
|
153
|
-
chainId:
|
|
163
|
+
chainId: PRIVY_BROKER_CHAIN_ID,
|
|
154
164
|
maxTotalUsdcAtomic: "1000000",
|
|
155
165
|
maxRatePerSecondAtomic: "1000",
|
|
156
166
|
maxDurationSeconds: 3600,
|
|
@@ -431,7 +441,7 @@ function createPrivyProvider(client: PrivyClient): PrivyBrokerProvider {
|
|
|
431
441
|
.wallets()
|
|
432
442
|
.ethereum()
|
|
433
443
|
.sendTransaction(input.walletId, {
|
|
434
|
-
caip2:
|
|
444
|
+
caip2: PRIVY_BROKER_CAIP2,
|
|
435
445
|
params: { transaction: input.transaction as never },
|
|
436
446
|
sponsor: input.sponsor,
|
|
437
447
|
authorization_context: {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
2
|
|
|
3
|
-
import { streamEscrowV2Abi } from "@absol-labs/shared";
|
|
4
3
|
import {
|
|
5
4
|
decodeFunctionData,
|
|
6
5
|
getAddress,
|
|
@@ -22,13 +21,25 @@ import {
|
|
|
22
21
|
invocationCapabilityDomainVersion,
|
|
23
22
|
invocationCapabilitySchema,
|
|
24
23
|
} from "../capability/invocation-capability.js";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
import { defaultNetwork } from "../network.js";
|
|
25
|
+
import {
|
|
26
|
+
BROKER_EXIT_METHODS,
|
|
27
|
+
brokerEscrowPolicy,
|
|
28
|
+
decodeEscrowCall,
|
|
29
|
+
escrowRole,
|
|
30
|
+
type BrokerEscrowPolicy,
|
|
31
|
+
} from "./broker-escrows.js";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The deployment a Privy broker polices: the registry's default network. Its
|
|
35
|
+
* Privy policy allowlists exactly this escrow and this USDC, so these are read
|
|
36
|
+
* once from the `@absol-labs/sdk` network registry, never written as literals.
|
|
37
|
+
*/
|
|
38
|
+
const BROKER_NETWORK = defaultNetwork();
|
|
39
|
+
export const PRIVY_BROKER_CHAIN_ID: number = BROKER_NETWORK.chain.id;
|
|
40
|
+
export const PRIVY_BROKER_CAIP2: `eip155:${number}` = BROKER_NETWORK.caip2;
|
|
41
|
+
export const PRIVY_BROKER_ESCROW: `0x${string}` = BROKER_NETWORK.escrow.address;
|
|
42
|
+
export const PRIVY_BROKER_USDC: `0x${string}` = BROKER_NETWORK.usdc.address;
|
|
32
43
|
export const PRIVY_POLICY_MAX_TOTAL_USDC = 1_000_000n;
|
|
33
44
|
export const PRIVY_POLICY_MAX_RATE_USDC = 1_000n;
|
|
34
45
|
export const PRIVY_POLICY_MAX_DURATION_SECONDS = 3_600;
|
|
@@ -83,7 +94,15 @@ export interface PrivyBrokerProvider {
|
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
export interface BrokerStreamReader {
|
|
86
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Read a stream. `escrow` names the escrow the transaction targets (the
|
|
99
|
+
* current one, or a legacy one for an exit); readers that serve only one
|
|
100
|
+
* escrow may ignore it.
|
|
101
|
+
*/
|
|
102
|
+
getStream(
|
|
103
|
+
streamId: Hex,
|
|
104
|
+
escrow?: Address,
|
|
105
|
+
): Promise<{
|
|
87
106
|
readonly buyer: Address;
|
|
88
107
|
readonly serviceRef: Hex;
|
|
89
108
|
readonly status: "active" | "closed";
|
|
@@ -151,8 +170,14 @@ export class PrivySessionBroker {
|
|
|
151
170
|
readonly streamReader: BrokerStreamReader;
|
|
152
171
|
readonly authorizationPrivateKey: string;
|
|
153
172
|
readonly nowSeconds?: () => number;
|
|
173
|
+
/** Current + legacy escrows. Default: from the registries (see `./broker-escrows.ts`). */
|
|
174
|
+
readonly escrows?: BrokerEscrowPolicy;
|
|
154
175
|
},
|
|
155
|
-
) {
|
|
176
|
+
) {
|
|
177
|
+
this.escrows = dependencies.escrows ?? brokerEscrowPolicy(BROKER_NETWORK);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private readonly escrows: BrokerEscrowPolicy;
|
|
156
181
|
|
|
157
182
|
async createSession(input: CreatePrivyBrokerSessionInput): Promise<{
|
|
158
183
|
readonly sessionId: string;
|
|
@@ -276,11 +301,13 @@ export class PrivySessionBroker {
|
|
|
276
301
|
const to = getAddress(transaction.to);
|
|
277
302
|
const data = transaction.data as Hex;
|
|
278
303
|
|
|
304
|
+
const role = escrowRole(this.escrows, to);
|
|
279
305
|
if (to.toLowerCase() === PRIVY_BROKER_USDC.toLowerCase()) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
306
|
+
// The approval spender must be the CURRENT escrow, never a legacy one.
|
|
307
|
+
assertBoundedApproval(data, session.signedMandate, this.escrows.current);
|
|
308
|
+
} else if (role !== null) {
|
|
309
|
+
const decoded = decodeEscrowCall(data);
|
|
310
|
+
if (decoded.functionName === "openStream" && role === "current") {
|
|
284
311
|
const [operator, , deposit, rate, duration] = decoded.args;
|
|
285
312
|
const decision = await checkMandate(
|
|
286
313
|
session.signedMandate,
|
|
@@ -307,14 +334,13 @@ export class PrivySessionBroker {
|
|
|
307
334
|
});
|
|
308
335
|
return hash;
|
|
309
336
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
decoded.functionName !== "reclaim" &&
|
|
313
|
-
decoded.functionName !== "reclaimUnverified"
|
|
314
|
-
) {
|
|
337
|
+
// A legacy escrow is exit-only: openStream falls through to here too.
|
|
338
|
+
if (!BROKER_EXIT_METHODS.has(decoded.functionName)) {
|
|
315
339
|
throw new PrivySessionBrokerError(
|
|
316
340
|
"policy-denied",
|
|
317
|
-
|
|
341
|
+
role === "legacy"
|
|
342
|
+
? "only close, reclaim and reclaimUnverified are allowed on a legacy escrow"
|
|
343
|
+
: "escrow method is not allowed for an agent session",
|
|
318
344
|
);
|
|
319
345
|
}
|
|
320
346
|
const owner = await verifyMandateOwnerSignature(session.signedMandate);
|
|
@@ -324,8 +350,11 @@ export class PrivySessionBroker {
|
|
|
324
350
|
"mandate owner signature is invalid",
|
|
325
351
|
);
|
|
326
352
|
}
|
|
327
|
-
const streamId = decoded.args[0];
|
|
328
|
-
const stream = await this.dependencies.streamReader.getStream(
|
|
353
|
+
const streamId = (decoded.args as readonly unknown[])[0] as Hex;
|
|
354
|
+
const stream = await this.dependencies.streamReader.getStream(
|
|
355
|
+
streamId,
|
|
356
|
+
to,
|
|
357
|
+
);
|
|
329
358
|
if (stream.buyer.toLowerCase() !== session.address.toLowerCase()) {
|
|
330
359
|
throw new PrivySessionBrokerError(
|
|
331
360
|
"policy-denied",
|
|
@@ -375,7 +404,7 @@ export class PrivySessionBroker {
|
|
|
375
404
|
Number(domain.chainId) !== PRIVY_BROKER_CHAIN_ID ||
|
|
376
405
|
typeof domain.verifyingContract !== "string" ||
|
|
377
406
|
domain.verifyingContract.toLowerCase() !==
|
|
378
|
-
|
|
407
|
+
this.escrows.current.toLowerCase() ||
|
|
379
408
|
typedDataRecord.primaryType !== "InvocationCapability"
|
|
380
409
|
) {
|
|
381
410
|
throw new PrivySessionBrokerError(
|
|
@@ -563,7 +592,11 @@ function assertMandateWithinPrivyPolicy(signed: SignedSpendMandate): void {
|
|
|
563
592
|
}
|
|
564
593
|
}
|
|
565
594
|
|
|
566
|
-
function assertBoundedApproval(
|
|
595
|
+
function assertBoundedApproval(
|
|
596
|
+
data: Hex,
|
|
597
|
+
signed: SignedSpendMandate,
|
|
598
|
+
currentEscrow: Address,
|
|
599
|
+
): void {
|
|
567
600
|
const decoded = decodeFunctionData({
|
|
568
601
|
abi: [
|
|
569
602
|
{
|
|
@@ -581,7 +614,7 @@ function assertBoundedApproval(data: Hex, signed: SignedSpendMandate): void {
|
|
|
581
614
|
});
|
|
582
615
|
const [spender, amount] = decoded.args;
|
|
583
616
|
if (
|
|
584
|
-
spender.toLowerCase() !==
|
|
617
|
+
spender.toLowerCase() !== currentEscrow.toLowerCase() ||
|
|
585
618
|
amount > signed.mandate.maxPerStreamUsdc
|
|
586
619
|
) {
|
|
587
620
|
throw new PrivySessionBrokerError(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getAddress, type Address, type Hex } from "viem";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
+
import { defaultNetwork } from "../network.js";
|
|
4
5
|
import type { PrivyEip1193Provider } from "./provider.js";
|
|
5
6
|
|
|
6
7
|
const jsonRpcResponseSchema = z.object({
|
|
@@ -21,6 +22,8 @@ export interface PrivySessionProviderConfig {
|
|
|
21
22
|
readonly sessionToken: string;
|
|
22
23
|
readonly address: Address;
|
|
23
24
|
readonly rpcUrl?: string;
|
|
25
|
+
/** Chain the session signs on. Default: the registry's default network. */
|
|
26
|
+
readonly chainId?: number;
|
|
24
27
|
readonly fetchImpl?: typeof fetch;
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -34,7 +37,7 @@ export class PrivySessionProviderError extends Error {
|
|
|
34
37
|
/**
|
|
35
38
|
* EIP-1193 provider for a policy-bound Metrik/Privy headless session.
|
|
36
39
|
* Signing and writes go only to the broker; public read RPCs go directly to
|
|
37
|
-
*
|
|
40
|
+
* the network's public RPC and never receive the session token.
|
|
38
41
|
*/
|
|
39
42
|
export function createPrivySessionProvider(
|
|
40
43
|
config: PrivySessionProviderConfig,
|
|
@@ -42,12 +45,13 @@ export function createPrivySessionProvider(
|
|
|
42
45
|
const fetchImpl = config.fetchImpl ?? fetch;
|
|
43
46
|
const address = getAddress(config.address);
|
|
44
47
|
const brokerUrl = new URL("/v1/rpc", requireHttpsBase(config.brokerUrl));
|
|
45
|
-
const rpcUrl = config.rpcUrl ??
|
|
48
|
+
const rpcUrl = config.rpcUrl ?? defaultNetwork().rpcUrls[0];
|
|
49
|
+
const chainIdHex = `0x${(config.chainId ?? defaultNetwork().chain.id).toString(16)}`;
|
|
46
50
|
let rpcId = 0;
|
|
47
51
|
|
|
48
52
|
return {
|
|
49
53
|
async request({ method, params = [] }) {
|
|
50
|
-
if (method === "eth_chainId") return
|
|
54
|
+
if (method === "eth_chainId") return chainIdHex;
|
|
51
55
|
if (method === "eth_accounts" || method === "eth_requestAccounts") {
|
|
52
56
|
return [address];
|
|
53
57
|
}
|
package/src/wallet/provider.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
networkForChainId,
|
|
3
|
+
type StreamProofClientConfig,
|
|
4
|
+
} from "@absol-labs/sdk";
|
|
2
5
|
// `@coinbase/cdp-sdk` is an OPTIONAL peer dependency: TYPES only here (erased at
|
|
3
6
|
// compile time), the runtime module via `loadCdpSdk()` at the point of first use.
|
|
4
7
|
// This module IS reachable from the package barrel, so a value import here would
|
|
@@ -26,6 +29,7 @@ import {
|
|
|
26
29
|
VerifiedStreamAgentClient,
|
|
27
30
|
type AgentSdkClientFactory,
|
|
28
31
|
} from "../sdk/client.js";
|
|
32
|
+
import { defaultNetwork, requireNetworkForChainId } from "../network.js";
|
|
29
33
|
|
|
30
34
|
const privateKeySchema = z
|
|
31
35
|
.string()
|
|
@@ -165,7 +169,7 @@ export async function resolveAgentWallet(
|
|
|
165
169
|
}
|
|
166
170
|
|
|
167
171
|
if ("privy" in input) {
|
|
168
|
-
const chainId = input.privy.chainId ??
|
|
172
|
+
const chainId = input.privy.chainId ?? defaultNetwork().chain.id;
|
|
169
173
|
const account = await createPrivyEmbeddedAccount(input.privy);
|
|
170
174
|
return {
|
|
171
175
|
source: "privy",
|
|
@@ -214,7 +218,7 @@ export async function createPrivyEmbeddedAccount(
|
|
|
214
218
|
config: PrivyEmbeddedWalletConfig,
|
|
215
219
|
): Promise<Account> {
|
|
216
220
|
validatePrivyConfig(config);
|
|
217
|
-
const chainId = config.chainId ??
|
|
221
|
+
const chainId = config.chainId ?? defaultNetwork().chain.id;
|
|
218
222
|
await assertPrivySession(config, chainId);
|
|
219
223
|
|
|
220
224
|
const account = {
|
|
@@ -357,8 +361,6 @@ async function defaultCdpClientFactory(
|
|
|
357
361
|
});
|
|
358
362
|
}
|
|
359
363
|
|
|
360
|
-
const BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
361
|
-
|
|
362
364
|
function validatePrivyConfig(config: PrivyEmbeddedWalletConfig): void {
|
|
363
365
|
if (config.appId.trim() === "") {
|
|
364
366
|
throw new PrivyEmbeddedWalletError(
|
|
@@ -372,14 +374,17 @@ function validatePrivyConfig(config: PrivyEmbeddedWalletConfig): void {
|
|
|
372
374
|
"Privy wallet address is invalid",
|
|
373
375
|
);
|
|
374
376
|
}
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
377
|
+
if (config.chainId !== undefined) {
|
|
378
|
+
// A registered TESTNET network only: the wallet signs with a key the
|
|
379
|
+
// browser holds and Metrik settles real value on a mainnet.
|
|
380
|
+
try {
|
|
381
|
+
requireNetworkForChainId(config.chainId, { testnetOnly: true });
|
|
382
|
+
} catch (error) {
|
|
383
|
+
throw new PrivyEmbeddedWalletError(
|
|
384
|
+
"invalid-config",
|
|
385
|
+
`Metrik Privy wallets support registered testnet networks only: ${error instanceof Error ? error.message : String(error)}`,
|
|
386
|
+
);
|
|
387
|
+
}
|
|
383
388
|
}
|
|
384
389
|
}
|
|
385
390
|
|
|
@@ -406,7 +411,7 @@ async function assertPrivySession(
|
|
|
406
411
|
if (chainId !== expectedChainId) {
|
|
407
412
|
throw new PrivyEmbeddedWalletError(
|
|
408
413
|
"chain-mismatch",
|
|
409
|
-
`Privy wallet chain ID ${chainId} is not
|
|
414
|
+
`Privy wallet chain ID ${chainId} is not ${networkForChainId(expectedChainId)?.name ?? "the configured network"} (${expectedChainId})`,
|
|
410
415
|
);
|
|
411
416
|
}
|
|
412
417
|
if (
|
|
@@ -441,7 +446,7 @@ async function requestPrivy(
|
|
|
441
446
|
function createCheckedPrivyProvider(
|
|
442
447
|
config: PrivyEmbeddedWalletConfig,
|
|
443
448
|
): PrivyEip1193Provider {
|
|
444
|
-
const expectedChainId = config.chainId ??
|
|
449
|
+
const expectedChainId = config.chainId ?? defaultNetwork().chain.id;
|
|
445
450
|
return {
|
|
446
451
|
request: async (args) => {
|
|
447
452
|
if (args.method === "eth_sendTransaction") {
|
package/src/x402/facilitator.ts
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* facilitator. See `docs/x402.md` for the full explanation of why Metrik's
|
|
9
9
|
* metered-stream settlement does not fit any shipped x402 scheme.
|
|
10
10
|
*
|
|
11
|
-
* The `X402*` / `x402*`
|
|
12
|
-
*
|
|
11
|
+
* The directory name is historical. The deprecated `X402*` / `x402*` alias
|
|
12
|
+
* exports that used to live here were removed with the x402 v1 integration
|
|
13
|
+
* (metrik-agent#115); only the canonical names below are exported.
|
|
13
14
|
*/
|
|
14
15
|
import type { StreamProofClientConfig } from "@absol-labs/sdk";
|
|
15
16
|
import { z } from "zod";
|
|
@@ -442,44 +443,3 @@ function reviveBigInts(value: unknown): unknown {
|
|
|
442
443
|
|
|
443
444
|
return value;
|
|
444
445
|
}
|
|
445
|
-
|
|
446
|
-
/* -------------------------------------------------------------------------- */
|
|
447
|
-
/* Deprecated `x402`-flavoured aliases. */
|
|
448
|
-
/* */
|
|
449
|
-
/* These names are misleading — this flow is Metrik-native and not x402 (see */
|
|
450
|
-
/* `docs/x402.md`). They are retained as aliases bound to the SAME values and */
|
|
451
|
-
/* class objects as the canonical exports above, so existing consumers and */
|
|
452
|
-
/* `instanceof` checks keep working. Prefer the canonical names. */
|
|
453
|
-
/* -------------------------------------------------------------------------- */
|
|
454
|
-
|
|
455
|
-
export {
|
|
456
|
-
/** @deprecated Use {@link METRIK_STREAM_SCHEME}. This flow is not x402. */
|
|
457
|
-
METRIK_STREAM_SCHEME as X402_SCHEME,
|
|
458
|
-
/** @deprecated Use {@link VerifiedStreamFacilitator}. This flow is not x402. */
|
|
459
|
-
VerifiedStreamFacilitator as VerifiedStreamX402Facilitator,
|
|
460
|
-
/** @deprecated Use {@link StreamPayloadError}. Same class object. */
|
|
461
|
-
StreamPayloadError as X402PayloadError,
|
|
462
|
-
/** @deprecated Use {@link SpendControlUnavailableError}. Same class object. */
|
|
463
|
-
SpendControlUnavailableError as X402SpendControlUnavailableError,
|
|
464
|
-
/** @deprecated Use {@link streamChallengeSchema}. */
|
|
465
|
-
streamChallengeSchema as x402StreamChallengeSchema,
|
|
466
|
-
/** @deprecated Use {@link streamOpenPayloadSchema}. */
|
|
467
|
-
streamOpenPayloadSchema as x402OpenPayloadSchema,
|
|
468
|
-
/** @deprecated Use {@link encodeStreamPayloadHeader}. */
|
|
469
|
-
encodeStreamPayloadHeader as encodeX402PayloadHeader,
|
|
470
|
-
/** @deprecated Use {@link parseStreamPayloadHeader}. */
|
|
471
|
-
parseStreamPayloadHeader as parseX402PayloadHeader,
|
|
472
|
-
/** @deprecated Use {@link parseStreamChallengeJson}. */
|
|
473
|
-
parseStreamChallengeJson as parseX402ChallengeJson,
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
export type {
|
|
477
|
-
/** @deprecated Use {@link StreamFacilitator}. This flow is not x402. */
|
|
478
|
-
StreamFacilitator as X402Facilitator,
|
|
479
|
-
/** @deprecated Use {@link StreamChallenge}. */
|
|
480
|
-
StreamChallenge as X402StreamChallenge,
|
|
481
|
-
/** @deprecated Use {@link StreamOpenPayload}. */
|
|
482
|
-
StreamOpenPayload as X402OpenPayload,
|
|
483
|
-
/** @deprecated Use {@link ConsumedHttpsResponseProofInput}. */
|
|
484
|
-
ConsumedHttpsResponseProofInput as X402ConsumedHttpsResponseProofInput,
|
|
485
|
-
};
|