@paystage/channel 0.0.0-stage → 0.1.0-canary.88
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 +78 -2
- package/dist/channel.d.ts +66 -0
- package/dist/channel.js +101 -0
- package/dist/constants.d.ts +49 -0
- package/dist/constants.js +40 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3 -0
- package/dist/rpc.d.ts +18 -0
- package/dist/rpc.js +58 -0
- package/package.json +49 -4
package/README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@paystage/channel`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read-only inspection of an **x402 batch-settlement deposit channel** on Base.
|
|
4
|
+
Two `eth_call` view calls, no keys, no signing, no transaction.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { readChannel } from "@paystage/channel";
|
|
8
|
+
|
|
9
|
+
const channel = await readChannel({
|
|
10
|
+
channelId: "0x…", // bytes32, from the deposit tx / 402 extra
|
|
11
|
+
chain: "eip155:8453", // Base mainnet, or eip155:84532 for Sepolia
|
|
12
|
+
withdrawDelay: 86400, // ChannelConfig.withdrawDelay, optional
|
|
13
|
+
signedMaxClaimable: "25000000" // from the voucher you hold, optional
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
|
|
19
|
+
| field | source | notes |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `balance` | `channels(bytes32)` | deposited, unclaimed balance in token base units |
|
|
22
|
+
| `signedMaxClaimable` | **signed voucher, off chain** | cumulative ceiling, not remaining balance; `null` unless you pass it, because there is no contract storage for it |
|
|
23
|
+
| `withdrawRequestedAt` | `pendingWithdrawals(bytes32)` → `initiatedAt` | unix seconds, `0` when no withdrawal is pending |
|
|
24
|
+
| `expiry` | derived | `withdrawRequestedAt + withdrawDelay`; `null` when no request or delay unknown |
|
|
25
|
+
|
|
26
|
+
`raw.channels` and `raw.pendingWithdrawals` carry the exact hex responses, and
|
|
27
|
+
`unavailable` says which field(s) could not be resolved and why.
|
|
28
|
+
|
|
29
|
+
## What this reads
|
|
30
|
+
|
|
31
|
+
- Contract: `0x4020074e9dF2ce1deE5A9C1b5c3f541D02a10003` — the x402
|
|
32
|
+
batch-settlement contract (from `BATCH_SETTLEMENT_ADDRESS` in `@x402/evm`).
|
|
33
|
+
Verified present with `eth_getCode` on Base mainnet (`0x2105`) and Base
|
|
34
|
+
Sepolia (`0x14a34`) on 2026-11-20.
|
|
35
|
+
- Network: Base mainnet / Base Sepolia. One contract holds many channels, keyed
|
|
36
|
+
by `bytes32 channelId`; there is no per-channel contract address.
|
|
37
|
+
- ABI: `channels(bytes32) returns (uint128 balance, uint128 totalClaimed)` and
|
|
38
|
+
`pendingWithdrawals(bytes32) returns (uint128 amount, uint40 initiatedAt)`.
|
|
39
|
+
|
|
40
|
+
The `channelId` is `computeChannelId(ChannelConfig)` from `@x402/evm`
|
|
41
|
+
(EIP-712 hash of payer, payerAuthorizer, receiver, receiverAuthorizer, token,
|
|
42
|
+
withdrawDelay, salt). It can also be read from the contract with
|
|
43
|
+
`getChannelId(config)`.
|
|
44
|
+
|
|
45
|
+
## What it deliberately does not do
|
|
46
|
+
|
|
47
|
+
It has no wallet client, no `writeContract`, no `sendTransaction`, no private-key
|
|
48
|
+
input, and no runtime dependency. The test suite scans `src/` for those
|
|
49
|
+
identifiers and asserts `dependencies` is empty. Only `eth_call` is sent.
|
|
50
|
+
|
|
51
|
+
## Live read
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm run build -w @paystage/channel
|
|
55
|
+
node packages/channel/scripts/read-live.mjs \
|
|
56
|
+
0x1dc6371a716991c8eb1cd8fdff2c21ad56a3c2ca835c0a83b480c7cf7f88da93
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Recorded 2026-11-20 on Base mainnet at block 59,972,547 for that real channel:
|
|
60
|
+
`balance 20001600`, `totalClaimed 19958880`, `withdrawRequestedAt 0`,
|
|
61
|
+
`expiry null`. `signedMaxClaimable` is `unassessed`: it is not on chain, and no
|
|
62
|
+
signed voucher for that channel was available to this read.
|
|
63
|
+
|
|
64
|
+
## Publishing is blocked
|
|
65
|
+
|
|
66
|
+
`package.json` sets `"private": true` so `scripts/check-manifest-packages.mjs`
|
|
67
|
+
skips it and no release attempts to publish the name.
|
|
68
|
+
|
|
69
|
+
When an npm Trusted Publisher exists for `@paystage/channel`, do **all** of:
|
|
70
|
+
|
|
71
|
+
1. set `"private": false` in `packages/channel/package.json`;
|
|
72
|
+
2. add `"@paystage/channel"` to `PACKAGE_VERSIONS` in
|
|
73
|
+
`apps/console/src/lib/agent-manifest.ts`;
|
|
74
|
+
3. add the name to `PKGS` in `.github/workflows/release.yml` (the lists near
|
|
75
|
+
lines 85 and 165);
|
|
76
|
+
4. add it to `cadence.yml` around line 105;
|
|
77
|
+
5. add it to the root `build`/`test` lists if it is not already there.
|
|
78
|
+
|
|
79
|
+
Nothing in this package pushes, publishes or tags.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type ChainLike, type JsonRpcClient } from "./rpc.js";
|
|
2
|
+
export interface ReadChannelOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The batch-settlement contract. Defaults to the x402 address verified on
|
|
5
|
+
* Base and Base Sepolia. This is **not** a per-channel address: one contract
|
|
6
|
+
* stores every channel under a bytes32 `channelId`.
|
|
7
|
+
*/
|
|
8
|
+
address?: string;
|
|
9
|
+
/** Channel id (`bytes32`), e.g. from a deposit transaction or the 402 extra. */
|
|
10
|
+
channelId: string;
|
|
11
|
+
/** `eip155:8453` / 8453 / `base`, or `eip155:84532` / 84532 / `base-sepolia`. */
|
|
12
|
+
chain: ChainLike;
|
|
13
|
+
/** Injected JSON-RPC client (tests, or a custom transport). */
|
|
14
|
+
client?: JsonRpcClient;
|
|
15
|
+
/** Explicit RPC URL; ignored when `client` is given. */
|
|
16
|
+
rpcUrl?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Cumulative ceiling from the latest signed voucher. This value is **not**
|
|
19
|
+
* on chain — it only exists in the voucher signature held by the payer or
|
|
20
|
+
* server — so it cannot be recovered by `eth_call`. Omit it and the field is
|
|
21
|
+
* returned as `null` with a note; supply it from the voucher you already hold.
|
|
22
|
+
*/
|
|
23
|
+
signedMaxClaimable?: bigint | string | number;
|
|
24
|
+
/**
|
|
25
|
+
* `ChannelConfig.withdrawDelay` in seconds. Needed only to turn
|
|
26
|
+
* `withdrawRequestedAt` into the unlock time; omit it and `expiry` is `null`
|
|
27
|
+
* while a withdrawal is pending.
|
|
28
|
+
*/
|
|
29
|
+
withdrawDelay?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface ChannelReading {
|
|
32
|
+
channelId: string;
|
|
33
|
+
network: string;
|
|
34
|
+
contract: string;
|
|
35
|
+
/** Deposited, not-yet-claimed balance, in token base units. */
|
|
36
|
+
balance: bigint;
|
|
37
|
+
/** From a signed voucher, when supplied. Never read from the chain. */
|
|
38
|
+
signedMaxClaimable: bigint | null;
|
|
39
|
+
/** `pendingWithdrawals(channelId).initiatedAt`, unix seconds; 0 when none. */
|
|
40
|
+
withdrawRequestedAt: number;
|
|
41
|
+
/**
|
|
42
|
+
* `withdrawRequestedAt + withdrawDelay` when a withdrawal is pending and the
|
|
43
|
+
* delay is known; otherwise `null`.
|
|
44
|
+
*/
|
|
45
|
+
expiry: number | null;
|
|
46
|
+
/** Informational: total already claimed from this channel. */
|
|
47
|
+
totalClaimed: bigint;
|
|
48
|
+
/** Amount queued by `initiateWithdraw`, in token base units. */
|
|
49
|
+
pendingWithdrawalAmount: bigint;
|
|
50
|
+
/** Raw `eth_call` results, hex, for debugging and reproduction. */
|
|
51
|
+
raw: {
|
|
52
|
+
channels: string;
|
|
53
|
+
pendingWithdrawals: string;
|
|
54
|
+
};
|
|
55
|
+
/** Values this read could not obtain, and why. Empty means all four fields resolved. */
|
|
56
|
+
unavailable: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Reads one x402 deposit channel. Two view calls, no signing, no sending.
|
|
60
|
+
*
|
|
61
|
+
* `balance` and `withdrawRequestedAt` come from the batch-settlement contract.
|
|
62
|
+
* `signedMaxClaimable` cannot: it is the cumulative ceiling in an off-chain
|
|
63
|
+
* voucher signature. `expiry` is derived from the on-chain withdrawal request
|
|
64
|
+
* plus the caller-supplied `withdrawDelay`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function readChannel(options: ReadChannelOptions): Promise<ChannelReading>;
|
package/dist/channel.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { BATCH_SETTLEMENT_ADDRESS, CHANNELS_SELECTOR, PENDING_WITHDRAWALS_SELECTOR, } from "./constants.js";
|
|
2
|
+
import { createRpcClient, resolveChain, resolveRpcUrl, } from "./rpc.js";
|
|
3
|
+
const BYTES32 = /^0x[0-9a-fA-F]{64}$/;
|
|
4
|
+
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
5
|
+
const WORD = /^[0-9a-fA-F]{64}$/;
|
|
6
|
+
function requireBytes32(value, label) {
|
|
7
|
+
if (!BYTES32.test(value)) {
|
|
8
|
+
throw new Error(`${label} must be a 0x-prefixed 32-byte hex string`);
|
|
9
|
+
}
|
|
10
|
+
return value.toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
function requireAddress(value, label) {
|
|
13
|
+
if (!ADDRESS.test(value)) {
|
|
14
|
+
throw new Error(`${label} must be a 0x-prefixed 20-byte hex string`);
|
|
15
|
+
}
|
|
16
|
+
return value.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
function wordAt(hex, index) {
|
|
19
|
+
const body = hex.slice(2);
|
|
20
|
+
const word = body.slice(index * 64, (index + 1) * 64);
|
|
21
|
+
if (!WORD.test(word)) {
|
|
22
|
+
throw new Error(`Malformed eth_call response: expected at least ${index + 1} 32-byte word(s)`);
|
|
23
|
+
}
|
|
24
|
+
return word;
|
|
25
|
+
}
|
|
26
|
+
function parseUintWord(hex, index) {
|
|
27
|
+
return BigInt(`0x${wordAt(hex, index)}`);
|
|
28
|
+
}
|
|
29
|
+
function parseOptionalBigInt(value, label) {
|
|
30
|
+
if (value === undefined)
|
|
31
|
+
return null;
|
|
32
|
+
const parsed = typeof value === "bigint" ? value : BigInt(value);
|
|
33
|
+
if (parsed < 0n)
|
|
34
|
+
throw new Error(`${label} must be non-negative`);
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
function callData(selector, channelId) {
|
|
38
|
+
return `${selector}${channelId.slice(2)}`;
|
|
39
|
+
}
|
|
40
|
+
async function ethCall(client, to, data) {
|
|
41
|
+
const result = await client.request("eth_call", [{ to, data }, "latest"]);
|
|
42
|
+
if (typeof result !== "string" || !result.startsWith("0x")) {
|
|
43
|
+
throw new Error("eth_call returned a non-hex result");
|
|
44
|
+
}
|
|
45
|
+
if (result === "0x") {
|
|
46
|
+
throw new Error("eth_call returned empty data; wrong contract or channel id?");
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Reads one x402 deposit channel. Two view calls, no signing, no sending.
|
|
52
|
+
*
|
|
53
|
+
* `balance` and `withdrawRequestedAt` come from the batch-settlement contract.
|
|
54
|
+
* `signedMaxClaimable` cannot: it is the cumulative ceiling in an off-chain
|
|
55
|
+
* voucher signature. `expiry` is derived from the on-chain withdrawal request
|
|
56
|
+
* plus the caller-supplied `withdrawDelay`.
|
|
57
|
+
*/
|
|
58
|
+
export async function readChannel(options) {
|
|
59
|
+
const chain = resolveChain(options.chain);
|
|
60
|
+
const contract = requireAddress(options.address ?? BATCH_SETTLEMENT_ADDRESS, "address");
|
|
61
|
+
const channelId = requireBytes32(options.channelId, "channelId");
|
|
62
|
+
const signedMaxClaimable = parseOptionalBigInt(options.signedMaxClaimable, "signedMaxClaimable");
|
|
63
|
+
if (options.withdrawDelay !== undefined &&
|
|
64
|
+
(!Number.isFinite(options.withdrawDelay) || options.withdrawDelay < 0)) {
|
|
65
|
+
throw new Error("withdrawDelay must be a non-negative number of seconds");
|
|
66
|
+
}
|
|
67
|
+
const client = options.client ?? createRpcClient(options.rpcUrl ?? resolveRpcUrl(chain.network));
|
|
68
|
+
const channelsRaw = await ethCall(client, contract, callData(CHANNELS_SELECTOR, channelId));
|
|
69
|
+
const pendingRaw = await ethCall(client, contract, callData(PENDING_WITHDRAWALS_SELECTOR, channelId));
|
|
70
|
+
const balance = parseUintWord(channelsRaw, 0);
|
|
71
|
+
const totalClaimed = parseUintWord(channelsRaw, 1);
|
|
72
|
+
const pendingWithdrawalAmount = parseUintWord(pendingRaw, 0);
|
|
73
|
+
const initiatedAtRaw = parseUintWord(pendingRaw, 1);
|
|
74
|
+
const withdrawRequestedAt = Number(initiatedAtRaw);
|
|
75
|
+
const unavailable = [];
|
|
76
|
+
if (signedMaxClaimable === null) {
|
|
77
|
+
unavailable.push("signedMaxClaimable is in an off-chain cumulative voucher signature, not in contract storage; pass it from the voucher you hold");
|
|
78
|
+
}
|
|
79
|
+
let expiry = null;
|
|
80
|
+
if (withdrawRequestedAt > 0) {
|
|
81
|
+
if (options.withdrawDelay === undefined) {
|
|
82
|
+
unavailable.push("expiry needs ChannelConfig.withdrawDelay; pass withdrawDelay (seconds) to compute it");
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
expiry = withdrawRequestedAt + options.withdrawDelay;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
channelId,
|
|
90
|
+
network: chain.network,
|
|
91
|
+
contract,
|
|
92
|
+
balance,
|
|
93
|
+
signedMaxClaimable,
|
|
94
|
+
withdrawRequestedAt,
|
|
95
|
+
expiry,
|
|
96
|
+
totalClaimed,
|
|
97
|
+
pendingWithdrawalAmount,
|
|
98
|
+
raw: { channels: channelsRaw, pendingWithdrawals: pendingRaw },
|
|
99
|
+
unavailable,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The x402 batch-settlement contract the channel records live in.
|
|
3
|
+
*
|
|
4
|
+
* Verified with `eth_getCode` on 2026-11-20: code present on Base mainnet
|
|
5
|
+
* (chain id 8453) and Base Sepolia (84532), same deterministic address on both.
|
|
6
|
+
* The contract was found from the deployed `@x402/evm` package
|
|
7
|
+
* (`BATCH_SETTLEMENT_ADDRESS`), not from a project deployment.
|
|
8
|
+
*/
|
|
9
|
+
export declare const BATCH_SETTLEMENT_ADDRESS: "0x4020074e9dF2ce1deE5A9C1b5c3f541D02a10003";
|
|
10
|
+
/**
|
|
11
|
+
* Only the two view functions this package calls are declared. There is
|
|
12
|
+
* deliberately no write fragment, no `deposit`, `claim`, `settle`,
|
|
13
|
+
* `initiateWithdraw`, `finalizeWithdraw` or `refund` here.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CHANNEL_READ_ABI: readonly [{
|
|
16
|
+
readonly type: "function";
|
|
17
|
+
readonly name: "channels";
|
|
18
|
+
readonly stateMutability: "view";
|
|
19
|
+
readonly inputs: readonly [{
|
|
20
|
+
readonly name: "channelId";
|
|
21
|
+
readonly type: "bytes32";
|
|
22
|
+
}];
|
|
23
|
+
readonly outputs: readonly [{
|
|
24
|
+
readonly name: "balance";
|
|
25
|
+
readonly type: "uint128";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "totalClaimed";
|
|
28
|
+
readonly type: "uint128";
|
|
29
|
+
}];
|
|
30
|
+
}, {
|
|
31
|
+
readonly type: "function";
|
|
32
|
+
readonly name: "pendingWithdrawals";
|
|
33
|
+
readonly stateMutability: "view";
|
|
34
|
+
readonly inputs: readonly [{
|
|
35
|
+
readonly name: "channelId";
|
|
36
|
+
readonly type: "bytes32";
|
|
37
|
+
}];
|
|
38
|
+
readonly outputs: readonly [{
|
|
39
|
+
readonly name: "amount";
|
|
40
|
+
readonly type: "uint128";
|
|
41
|
+
}, {
|
|
42
|
+
readonly name: "initiatedAt";
|
|
43
|
+
readonly type: "uint40";
|
|
44
|
+
}];
|
|
45
|
+
}];
|
|
46
|
+
/** `channels(bytes32)` */
|
|
47
|
+
export declare const CHANNELS_SELECTOR: "0x7a7ebd7b";
|
|
48
|
+
/** `pendingWithdrawals(bytes32)` */
|
|
49
|
+
export declare const PENDING_WITHDRAWALS_SELECTOR: "0xb7f06ebe";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The x402 batch-settlement contract the channel records live in.
|
|
3
|
+
*
|
|
4
|
+
* Verified with `eth_getCode` on 2026-11-20: code present on Base mainnet
|
|
5
|
+
* (chain id 8453) and Base Sepolia (84532), same deterministic address on both.
|
|
6
|
+
* The contract was found from the deployed `@x402/evm` package
|
|
7
|
+
* (`BATCH_SETTLEMENT_ADDRESS`), not from a project deployment.
|
|
8
|
+
*/
|
|
9
|
+
export const BATCH_SETTLEMENT_ADDRESS = "0x4020074e9dF2ce1deE5A9C1b5c3f541D02a10003";
|
|
10
|
+
/**
|
|
11
|
+
* Only the two view functions this package calls are declared. There is
|
|
12
|
+
* deliberately no write fragment, no `deposit`, `claim`, `settle`,
|
|
13
|
+
* `initiateWithdraw`, `finalizeWithdraw` or `refund` here.
|
|
14
|
+
*/
|
|
15
|
+
export const CHANNEL_READ_ABI = [
|
|
16
|
+
{
|
|
17
|
+
type: "function",
|
|
18
|
+
name: "channels",
|
|
19
|
+
stateMutability: "view",
|
|
20
|
+
inputs: [{ name: "channelId", type: "bytes32" }],
|
|
21
|
+
outputs: [
|
|
22
|
+
{ name: "balance", type: "uint128" },
|
|
23
|
+
{ name: "totalClaimed", type: "uint128" },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "function",
|
|
28
|
+
name: "pendingWithdrawals",
|
|
29
|
+
stateMutability: "view",
|
|
30
|
+
inputs: [{ name: "channelId", type: "bytes32" }],
|
|
31
|
+
outputs: [
|
|
32
|
+
{ name: "amount", type: "uint128" },
|
|
33
|
+
{ name: "initiatedAt", type: "uint40" },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
/** `channels(bytes32)` */
|
|
38
|
+
export const CHANNELS_SELECTOR = "0x7a7ebd7b";
|
|
39
|
+
/** `pendingWithdrawals(bytes32)` */
|
|
40
|
+
export const PENDING_WITHDRAWALS_SELECTOR = "0xb7f06ebe";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { readChannel } from "./channel.js";
|
|
2
|
+
export type { ChannelReading, ReadChannelOptions } from "./channel.js";
|
|
3
|
+
export { BATCH_SETTLEMENT_ADDRESS, CHANNELS_SELECTOR, CHANNEL_READ_ABI, PENDING_WITHDRAWALS_SELECTOR, } from "./constants.js";
|
|
4
|
+
export { createRpcClient, resolveChain, resolveRpcUrl, } from "./rpc.js";
|
|
5
|
+
export type { ChainLike, JsonRpcClient, ResolvedChain } from "./rpc.js";
|
package/dist/index.js
ADDED
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal JSON-RPC client. Nothing here can sign: the only method this package
|
|
3
|
+
* ever sends is `eth_call`.
|
|
4
|
+
*/
|
|
5
|
+
export interface JsonRpcClient {
|
|
6
|
+
request(method: string, params: unknown[]): Promise<unknown>;
|
|
7
|
+
}
|
|
8
|
+
export type ChainLike = string | number;
|
|
9
|
+
export interface ResolvedChain {
|
|
10
|
+
/** CAIP-2 identifier, e.g. `eip155:8453`. */
|
|
11
|
+
network: string;
|
|
12
|
+
chainId: number;
|
|
13
|
+
/** Default public RPC used when no client or rpcUrl is supplied. */
|
|
14
|
+
defaultRpcUrl: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function resolveChain(chain: ChainLike): ResolvedChain;
|
|
17
|
+
export declare function createRpcClient(url: string): JsonRpcClient;
|
|
18
|
+
export declare function resolveRpcUrl(network: string, env?: NodeJS.ProcessEnv): string;
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function resolveChain(chain) {
|
|
2
|
+
const raw = typeof chain === "number" ? String(chain) : chain.trim().toLowerCase();
|
|
3
|
+
switch (raw) {
|
|
4
|
+
case "8453":
|
|
5
|
+
case "eip155:8453":
|
|
6
|
+
case "base":
|
|
7
|
+
return {
|
|
8
|
+
network: "eip155:8453",
|
|
9
|
+
chainId: 8453,
|
|
10
|
+
defaultRpcUrl: "https://mainnet.base.org",
|
|
11
|
+
};
|
|
12
|
+
case "84532":
|
|
13
|
+
case "eip155:84532":
|
|
14
|
+
case "base-sepolia":
|
|
15
|
+
case "base_sepolia":
|
|
16
|
+
case "basesepolia":
|
|
17
|
+
return {
|
|
18
|
+
network: "eip155:84532",
|
|
19
|
+
chainId: 84532,
|
|
20
|
+
defaultRpcUrl: "https://sepolia.base.org",
|
|
21
|
+
};
|
|
22
|
+
default:
|
|
23
|
+
throw new Error(`Unsupported chain ${JSON.stringify(chain)}; this package reads Base (eip155:8453) and Base Sepolia (eip155:84532) only`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function createRpcClient(url) {
|
|
27
|
+
let id = 0;
|
|
28
|
+
return {
|
|
29
|
+
async request(method, params) {
|
|
30
|
+
const res = await fetch(url, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: { "content-type": "application/json" },
|
|
33
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: ++id, method, params }),
|
|
34
|
+
});
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
throw new Error(`RPC HTTP ${res.status} ${res.statusText} for ${method}`);
|
|
37
|
+
}
|
|
38
|
+
const json = (await res.json());
|
|
39
|
+
if (json.error) {
|
|
40
|
+
throw new Error(`RPC error ${json.error.code}: ${json.error.message}`);
|
|
41
|
+
}
|
|
42
|
+
return json.result;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function resolveRpcUrl(network, env = process.env) {
|
|
47
|
+
const override = env.PAYSTAGE_RPC_URL;
|
|
48
|
+
if (override && override.trim().length > 0)
|
|
49
|
+
return override.trim();
|
|
50
|
+
switch (network) {
|
|
51
|
+
case "eip155:8453":
|
|
52
|
+
return "https://mainnet.base.org";
|
|
53
|
+
case "eip155:84532":
|
|
54
|
+
return "https://sepolia.base.org";
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`No default RPC URL for network ${network}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paystage/channel",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-canary.88",
|
|
4
|
+
"description": "Read-only inspection of x402 batch-settlement deposit channels on Base (balance, withdraw request, expiry)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"!dist/**/*.map"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=20"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"mcp",
|
|
26
|
+
"x402",
|
|
27
|
+
"agent-payments",
|
|
28
|
+
"base",
|
|
29
|
+
"deposit-channel",
|
|
30
|
+
"batch-settlement"
|
|
31
|
+
],
|
|
32
|
+
"homepage": "https://paystage.xyz",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/base-buzz/paystage.git",
|
|
36
|
+
"directory": "packages/channel"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/base-buzz/paystage/issues"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^20.14.0",
|
|
48
|
+
"typescript": "^5.5.4",
|
|
49
|
+
"vitest": "^4.1.12"
|
|
50
|
+
}
|
|
51
|
+
}
|