@zkproofport-ai/sdk 0.3.0 → 0.4.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 +52 -134
- package/dist/action.js +1 -1
- package/dist/action.js.map +1 -1
- package/dist/actionApproval.js +1 -1
- package/dist/actionApproval.js.map +1 -1
- package/dist/attestation.d.ts +6 -1
- package/dist/attestation.d.ts.map +1 -1
- package/dist/attestation.js +41 -4
- package/dist/attestation.js.map +1 -1
- package/dist/cdp.d.ts +3 -3
- package/dist/circuits.d.ts +26 -105
- package/dist/circuits.d.ts.map +1 -1
- package/dist/circuits.js +18 -114
- package/dist/circuits.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -10
- package/dist/constants.js.map +1 -1
- package/dist/extract.d.ts +6 -3
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +11 -10
- package/dist/extract.js.map +1 -1
- package/dist/flow.d.ts.map +1 -1
- package/dist/flow.js +13 -14
- package/dist/flow.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -16
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +4 -3
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +4 -7
- package/dist/inputs.js.map +1 -1
- package/dist/payment.d.ts +7 -9
- package/dist/payment.d.ts.map +1 -1
- package/dist/payment.js +20 -43
- package/dist/payment.js.map +1 -1
- package/dist/types.d.ts +9 -28
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +1 -1
- package/dist/usdc.d.ts +6 -10
- package/dist/usdc.d.ts.map +1 -1
- package/dist/usdc.js +6 -11
- package/dist/usdc.js.map +1 -1
- package/dist/verify.d.ts +5 -1
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +15 -13
- package/dist/verify.js.map +1 -1
- package/dist/wallets.d.ts +8 -34
- package/dist/wallets.d.ts.map +1 -1
- package/dist/wallets.js +10 -87
- package/dist/wallets.js.map +1 -1
- package/package.json +3 -12
- package/dist/arcWallet.d.ts +0 -50
- package/dist/arcWallet.d.ts.map +0 -1
- package/dist/arcWallet.js +0 -161
- package/dist/arcWallet.js.map +0 -1
- package/dist/delegation.d.ts +0 -107
- package/dist/delegation.d.ts.map +0 -1
- package/dist/delegation.js +0 -126
- package/dist/delegation.js.map +0 -1
- package/dist/nanopayment.d.ts +0 -71
- package/dist/nanopayment.d.ts.map +0 -1
- package/dist/nanopayment.js +0 -77
- package/dist/nanopayment.js.map +0 -1
- package/dist/typedAction.d.ts +0 -3
- package/dist/typedAction.d.ts.map +0 -1
- package/dist/typedAction.js +0 -50
- package/dist/typedAction.js.map +0 -1
package/dist/arcWallet.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Paying from an Arc agent wallet, through Circle's CLI.
|
|
3
|
-
*
|
|
4
|
-
* ## Why the CLI and not an API
|
|
5
|
-
*
|
|
6
|
-
* An Arc agent wallet is not a key this process can hold. Circle keeps it, and
|
|
7
|
-
* everything that touches it — creating it, reading its balance, signing with
|
|
8
|
-
* it — goes through `@circle-fin/cli`, which authenticates with a login that a
|
|
9
|
-
* person does once. So the integration is a wrapper around that command, and
|
|
10
|
-
* the alternative would be reimplementing Circle's auth, which is both work and
|
|
11
|
-
* a second thing to get wrong.
|
|
12
|
-
*
|
|
13
|
-
* ## What this buys over a private key
|
|
14
|
-
*
|
|
15
|
-
* The wallet carries policies Circle enforces: spending limits per period,
|
|
16
|
-
* recipient allowlists, contract blocklists. A raw key has none of that — it
|
|
17
|
-
* signs whatever it is handed. That is the whole point of an agent holding
|
|
18
|
-
* money: the agent acts on its own, and the limits are not the agent's to
|
|
19
|
-
* ignore.
|
|
20
|
-
*
|
|
21
|
-
* ## What it costs
|
|
22
|
-
*
|
|
23
|
-
* A subprocess per signature, and the CLI must be installed and logged in. Both
|
|
24
|
-
* are checked before signing rather than discovered as a cryptic failure, and
|
|
25
|
-
* the errors here say which of the two is missing and what command fixes it.
|
|
26
|
-
*/
|
|
27
|
-
import { execFile } from 'node:child_process';
|
|
28
|
-
import { promisify } from 'node:util';
|
|
29
|
-
const run = promisify(execFile);
|
|
30
|
-
/** How Circle names Arc's chains. Not ours to choose. */
|
|
31
|
-
export const ARC_CLI_CHAINS = { testnet: 'ARC-TESTNET', mainnet: 'ARC' };
|
|
32
|
-
async function circle(args) {
|
|
33
|
-
try {
|
|
34
|
-
const { stdout } = await run('circle', [...args, '--output', 'json'], {
|
|
35
|
-
// Non-interactive: a script has no way to answer the terms prompt, and
|
|
36
|
-
// Circle documents this variable for exactly that.
|
|
37
|
-
env: { ...process.env, CIRCLE_ACCEPT_TERMS: '1' },
|
|
38
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
39
|
-
});
|
|
40
|
-
return JSON.parse(stdout);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
const err = error;
|
|
44
|
-
if (err.code === 'ENOENT') {
|
|
45
|
-
throw new Error('Circle CLI is not installed, so an Arc agent wallet cannot sign. Install it with ' +
|
|
46
|
-
'`npm install -g @circle-fin/cli@>=1.1.4`, then `circle wallet login <email> --testnet`.');
|
|
47
|
-
}
|
|
48
|
-
// The CLI prints a JSON error on stdout even when it exits non-zero.
|
|
49
|
-
let reason = err.stderr?.trim() || err.message || 'unknown error';
|
|
50
|
-
try {
|
|
51
|
-
const parsed = JSON.parse(err.stdout ?? '');
|
|
52
|
-
if (parsed.error?.message) {
|
|
53
|
-
reason = parsed.error.hint ? `${parsed.error.message} (${parsed.error.hint})` : parsed.error.message;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
// stdout was not JSON; the stderr text above is the best there is.
|
|
58
|
-
}
|
|
59
|
-
if (/no longer supported/i.test(reason)) {
|
|
60
|
-
throw new Error(`Circle CLI is too old: ${reason} Update it with \`circle update\` or ` +
|
|
61
|
-
'`npm install -g @circle-fin/cli@latest`. Circle disables wallet operations on ' +
|
|
62
|
-
'versions it has retired, so the pin cannot be held here — 1.0.0 stopped working ' +
|
|
63
|
-
'for wallet commands and 1.1.4 was current on 2026-09-22.');
|
|
64
|
-
}
|
|
65
|
-
if (/AUTH_REQUIRED|Not logged in/i.test(reason)) {
|
|
66
|
-
throw new Error(`Circle CLI is not logged in for this environment: ${reason}. ` +
|
|
67
|
-
'Testnet and mainnet are separate logins — `circle wallet login <email> --testnet` for Arc Testnet.');
|
|
68
|
-
}
|
|
69
|
-
throw new Error(`Circle CLI failed: ${reason}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/** The agent wallets Circle holds for this login on one chain. */
|
|
73
|
-
export async function listArcAgentWallets(chain = ARC_CLI_CHAINS.testnet) {
|
|
74
|
-
const answer = (await circle(['wallet', 'list', '--chain', chain, '--type', 'agent']));
|
|
75
|
-
return (answer.data?.wallets ?? []).map((w) => String(w.address)).filter(Boolean);
|
|
76
|
-
}
|
|
77
|
-
/** Create one. Circle caps an account at five. */
|
|
78
|
-
export async function createArcAgentWallet() {
|
|
79
|
-
const answer = (await circle(['wallet', 'create']));
|
|
80
|
-
const address = answer.data?.wallet?.address;
|
|
81
|
-
if (!address)
|
|
82
|
-
throw new Error('Circle CLI created a wallet but reported no address.');
|
|
83
|
-
return address;
|
|
84
|
-
}
|
|
85
|
-
/** The address that actually signs for an agent wallet, per Circle. */
|
|
86
|
-
async function backingEoa(wallet, chain) {
|
|
87
|
-
const answer = (await circle(['gateway', 'balance', '--address', wallet, '--chain', chain]));
|
|
88
|
-
const backer = answer.data?.backingEOA;
|
|
89
|
-
if (!backer) {
|
|
90
|
-
throw new Error(`Circle did not say which address signs for agent wallet ${wallet}. ` +
|
|
91
|
-
'Gateway holds the balance under that address, so paying without it would sign as nobody.');
|
|
92
|
-
}
|
|
93
|
-
return backer;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* A payment wallet backed by an Arc agent wallet.
|
|
97
|
-
*
|
|
98
|
-
* `address` may be omitted, in which case the single agent wallet on that chain
|
|
99
|
-
* is used — and having none, or several, is an error rather than a guess:
|
|
100
|
-
* paying from a wallet the caller did not name spends somebody's money
|
|
101
|
-
* somewhere they did not choose.
|
|
102
|
-
*/
|
|
103
|
-
export async function walletFromArcAgent(opts = {}) {
|
|
104
|
-
const chain = opts.chain ?? ARC_CLI_CHAINS.testnet;
|
|
105
|
-
let address = opts.address;
|
|
106
|
-
if (!address) {
|
|
107
|
-
const wallets = await listArcAgentWallets(chain);
|
|
108
|
-
if (wallets.length === 0) {
|
|
109
|
-
throw new Error(`No Arc agent wallet exists on ${chain}. Create one with \`circle wallet create\`, ` +
|
|
110
|
-
'or pass the address of one that does.');
|
|
111
|
-
}
|
|
112
|
-
if (wallets.length > 1) {
|
|
113
|
-
throw new Error(`${wallets.length} agent wallets exist on ${chain} (${wallets.join(', ')}). ` +
|
|
114
|
-
'Name the one to pay from — picking for you would spend from a wallet nobody chose.');
|
|
115
|
-
}
|
|
116
|
-
address = wallets[0];
|
|
117
|
-
}
|
|
118
|
-
// Circle uses the smart wallet for direct USDC authorizations (ERC-1271),
|
|
119
|
-
// but its backing EOA owns the Gateway deposit. Signing always goes through
|
|
120
|
-
// the same Circle agent wallet; signPayment chooses the authorization owner
|
|
121
|
-
// for the selected offer without changing this wallet's identity.
|
|
122
|
-
const signer = await backingEoa(address, chain);
|
|
123
|
-
return {
|
|
124
|
-
address: address,
|
|
125
|
-
gatewayAddress: signer,
|
|
126
|
-
signTypedData: async (message) => {
|
|
127
|
-
// EIP-712 amounts arrive as BigInt and `JSON.stringify` refuses them
|
|
128
|
-
// outright — "Do not know how to serialize a BigInt". They go over as
|
|
129
|
-
// decimal strings, which is what EIP-712 encoders take for a uint256
|
|
130
|
-
// anyway, so nothing is lost and nothing is rounded.
|
|
131
|
-
// `EIP712Domain` spelled out.
|
|
132
|
-
//
|
|
133
|
-
// viem infers it from the domain's own fields and most libraries follow,
|
|
134
|
-
// but Circle's CLI validates the typed data strictly and refuses a
|
|
135
|
-
// request whose `types` does not declare it: "there is extra data
|
|
136
|
-
// provided in the message (0 < 4)". Declared here to match the domain
|
|
137
|
-
// actually given, field for field.
|
|
138
|
-
const typed = message;
|
|
139
|
-
const domainFields = [
|
|
140
|
-
['name', 'string'],
|
|
141
|
-
['version', 'string'],
|
|
142
|
-
['chainId', 'uint256'],
|
|
143
|
-
['verifyingContract', 'address'],
|
|
144
|
-
].filter(([field]) => typed.domain && typed.domain[field] !== undefined)
|
|
145
|
-
.map(([name, type]) => ({ name, type }));
|
|
146
|
-
const asJson = JSON.stringify({ ...typed, types: { EIP712Domain: domainFields, ...(typed.types ?? {}) } }, (_key, value) => (typeof value === 'bigint' ? value.toString() : value));
|
|
147
|
-
if (process.env.ARC_WALLET_DEBUG)
|
|
148
|
-
console.error('[arc-wallet] 서명 요청 =', asJson);
|
|
149
|
-
const answer = (await circle([
|
|
150
|
-
'wallet', 'sign', 'typed-data', asJson,
|
|
151
|
-
'--address', address, '--chain', chain,
|
|
152
|
-
]));
|
|
153
|
-
const signature = answer.data?.signature;
|
|
154
|
-
if (!signature)
|
|
155
|
-
throw new Error('Circle CLI signed nothing: no signature in its answer.');
|
|
156
|
-
return signature;
|
|
157
|
-
},
|
|
158
|
-
describe: () => `Arc agent wallet ${address} on ${chain}, Gateway depositor ${signer}`,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
//# sourceMappingURL=arcWallet.js.map
|
package/dist/arcWallet.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"arcWallet.js","sourceRoot":"","sources":["../src/arcWallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEhC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CAAC,CAAC;YAChF,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC;gBAC3B,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;gBACtC,WAAW,EAAE,OAAQ,EAAE,SAAS,EAAE,KAAK;aACxC,CAAC,CAAsC,CAAC;YACzC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC;YACzC,IAAI,CAAC,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;YAC1F,OAAO,SAA0B,CAAC;QACpC,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC,oBAAoB,OAAO,OAAO,KAAK,uBAAuB,MAAM,EAAE;KACvF,CAAC;AACJ,CAAC"}
|
package/dist/delegation.d.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorizing an action by another wallet without transferring KYC or identity.
|
|
3
|
-
*
|
|
4
|
-
* ## The problem this solves
|
|
5
|
-
*
|
|
6
|
-
* A wallet holds a Coinbase KYC attestation — call it A. A service wants proof
|
|
7
|
-
* of that KYC before it will let anyone stake. But A is the wallet whose
|
|
8
|
-
* on-chain history is worth hiding: revealing it links the KYC to everything
|
|
9
|
-
* else A has ever done.
|
|
10
|
-
*
|
|
11
|
-
* So A never appears. A signs a statement naming a second wallet, B, and the
|
|
12
|
-
* proof carries the hash of that statement. The service checks the proof, reads
|
|
13
|
-
* B out of the statement, and lets B act — while A stays behind the proof.
|
|
14
|
-
*
|
|
15
|
-
* ## Why this is an ordinary action and not a new mechanism
|
|
16
|
-
*
|
|
17
|
-
* `arc_eligibility` already proves "the wallet holding this KYC authorised ONE
|
|
18
|
-
* EIP-712 action". A delegation IS such an action: its fields name who is being
|
|
19
|
-
* delegated to, what they may do, and until when. Nothing in the circuit
|
|
20
|
-
* changes — only the structure being signed.
|
|
21
|
-
*
|
|
22
|
-
* That also means the delegation is bound to the proof: a proof made for one
|
|
23
|
-
* delegation verifies for no other, because the action's hash is a public
|
|
24
|
-
* input. Lifting the proof onto a different B is not possible.
|
|
25
|
-
*
|
|
26
|
-
* ## What the verifier must do
|
|
27
|
-
*
|
|
28
|
-
* Reading B out of the action is not enough. The service MUST rebuild the
|
|
29
|
-
* action's hash from the delegation it was shown and compare it with the
|
|
30
|
-
* proof's public input — otherwise anyone could present a valid proof
|
|
31
|
-
* alongside a delegation naming a wallet of their choosing.
|
|
32
|
-
* `delegationMatchesProof` is that check.
|
|
33
|
-
*/
|
|
34
|
-
import type { TypedAction } from './types.js';
|
|
35
|
-
/** What a delegation says. Every field is signed and none may be inferred. */
|
|
36
|
-
export interface Delegation {
|
|
37
|
-
/** The operational wallet authorized by this action; it does not acquire KYC. */
|
|
38
|
-
delegate: string;
|
|
39
|
-
/** What the delegate may do, e.g. 'stake'. Free text the service defines. */
|
|
40
|
-
action: string;
|
|
41
|
-
/** Unix seconds. A delegation without an end is not offered. */
|
|
42
|
-
expiresAt: number;
|
|
43
|
-
/** Makes this delegation single-use, so it cannot be replayed. */
|
|
44
|
-
nonce: string;
|
|
45
|
-
}
|
|
46
|
-
/** The EIP-712 type of a delegation, and the name its wallet renders. */
|
|
47
|
-
export declare const DELEGATION_PRIMARY_TYPE = "CredentialDelegation";
|
|
48
|
-
export declare const DELEGATION_TYPES: {
|
|
49
|
-
readonly CredentialDelegation: readonly [{
|
|
50
|
-
readonly name: "delegate";
|
|
51
|
-
readonly type: "address";
|
|
52
|
-
}, {
|
|
53
|
-
readonly name: "action";
|
|
54
|
-
readonly type: "string";
|
|
55
|
-
}, {
|
|
56
|
-
readonly name: "expiresAt";
|
|
57
|
-
readonly type: "uint256";
|
|
58
|
-
}, {
|
|
59
|
-
readonly name: "nonce";
|
|
60
|
-
readonly type: "string";
|
|
61
|
-
}];
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Build the legacy generic action that A signs to authorize B.
|
|
65
|
-
*
|
|
66
|
-
* This four-field wire schema has no amount and is not compatible with the
|
|
67
|
-
* Ledger House staking Gate's five-field CredentialDelegation type. For that
|
|
68
|
-
* Gate, supply its exact TypedAction including amount; do not change this
|
|
69
|
-
* helper's established type hash or treat this as a transfer of identity.
|
|
70
|
-
*
|
|
71
|
-
* `domain` names the service the delegation is for, so a delegation issued to
|
|
72
|
-
* one service cannot be presented at another: the domain separator is part of
|
|
73
|
-
* what the proof binds.
|
|
74
|
-
*/
|
|
75
|
-
export declare function buildDelegationAction(params: {
|
|
76
|
-
delegation: Delegation;
|
|
77
|
-
domain: {
|
|
78
|
-
name: string;
|
|
79
|
-
version: string;
|
|
80
|
-
chainId: number;
|
|
81
|
-
verifyingContract: string;
|
|
82
|
-
};
|
|
83
|
-
}): TypedAction;
|
|
84
|
-
/** The 32 bytes a proof carries for this action: EIP-712's hashStruct. */
|
|
85
|
-
export declare function delegationActionHash(action: TypedAction): string;
|
|
86
|
-
/** The 32 bytes a proof carries for the service this delegation is for. */
|
|
87
|
-
export declare function delegationDomainSeparator(action: TypedAction): string;
|
|
88
|
-
/**
|
|
89
|
-
* Whether a proof was made for exactly this delegation.
|
|
90
|
-
*
|
|
91
|
-
* The reason to call this rather than trust the delegation shown alongside the
|
|
92
|
-
* proof: a proof is public once presented, and anything that reads the
|
|
93
|
-
* delegate out of an unverified structure can be handed a proof plus a
|
|
94
|
-
* delegation naming somebody else.
|
|
95
|
-
*/
|
|
96
|
-
export declare function delegationMatchesProof(params: {
|
|
97
|
-
action: TypedAction;
|
|
98
|
-
/** The proof's `domain_separator` public input. */
|
|
99
|
-
domainSeparator: string;
|
|
100
|
-
/** The proof's `action_hash` public input. */
|
|
101
|
-
actionHash: string;
|
|
102
|
-
/** Unix seconds. An expired delegation is refused even when the proof is sound. */
|
|
103
|
-
now?: number;
|
|
104
|
-
}): string | null;
|
|
105
|
-
/** The wallet a checked delegation names. Throws rather than return a guess. */
|
|
106
|
-
export declare function delegateOf(action: TypedAction): string;
|
|
107
|
-
//# sourceMappingURL=delegation.d.ts.map
|
package/dist/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MAAM,GAAG,IAAI,CAkBhB;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAMtD"}
|
package/dist/delegation.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorizing an action by another wallet without transferring KYC or identity.
|
|
3
|
-
*
|
|
4
|
-
* ## The problem this solves
|
|
5
|
-
*
|
|
6
|
-
* A wallet holds a Coinbase KYC attestation — call it A. A service wants proof
|
|
7
|
-
* of that KYC before it will let anyone stake. But A is the wallet whose
|
|
8
|
-
* on-chain history is worth hiding: revealing it links the KYC to everything
|
|
9
|
-
* else A has ever done.
|
|
10
|
-
*
|
|
11
|
-
* So A never appears. A signs a statement naming a second wallet, B, and the
|
|
12
|
-
* proof carries the hash of that statement. The service checks the proof, reads
|
|
13
|
-
* B out of the statement, and lets B act — while A stays behind the proof.
|
|
14
|
-
*
|
|
15
|
-
* ## Why this is an ordinary action and not a new mechanism
|
|
16
|
-
*
|
|
17
|
-
* `arc_eligibility` already proves "the wallet holding this KYC authorised ONE
|
|
18
|
-
* EIP-712 action". A delegation IS such an action: its fields name who is being
|
|
19
|
-
* delegated to, what they may do, and until when. Nothing in the circuit
|
|
20
|
-
* changes — only the structure being signed.
|
|
21
|
-
*
|
|
22
|
-
* That also means the delegation is bound to the proof: a proof made for one
|
|
23
|
-
* delegation verifies for no other, because the action's hash is a public
|
|
24
|
-
* input. Lifting the proof onto a different B is not possible.
|
|
25
|
-
*
|
|
26
|
-
* ## What the verifier must do
|
|
27
|
-
*
|
|
28
|
-
* Reading B out of the action is not enough. The service MUST rebuild the
|
|
29
|
-
* action's hash from the delegation it was shown and compare it with the
|
|
30
|
-
* proof's public input — otherwise anyone could present a valid proof
|
|
31
|
-
* alongside a delegation naming a wallet of their choosing.
|
|
32
|
-
* `delegationMatchesProof` is that check.
|
|
33
|
-
*/
|
|
34
|
-
import { ethers } from 'ethers';
|
|
35
|
-
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
36
|
-
/** The EIP-712 type of a delegation, and the name its wallet renders. */
|
|
37
|
-
export const DELEGATION_PRIMARY_TYPE = 'CredentialDelegation';
|
|
38
|
-
export const DELEGATION_TYPES = {
|
|
39
|
-
[DELEGATION_PRIMARY_TYPE]: [
|
|
40
|
-
{ name: 'delegate', type: 'address' },
|
|
41
|
-
{ name: 'action', type: 'string' },
|
|
42
|
-
{ name: 'expiresAt', type: 'uint256' },
|
|
43
|
-
{ name: 'nonce', type: 'string' },
|
|
44
|
-
],
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Build the legacy generic action that A signs to authorize B.
|
|
48
|
-
*
|
|
49
|
-
* This four-field wire schema has no amount and is not compatible with the
|
|
50
|
-
* Ledger House staking Gate's five-field CredentialDelegation type. For that
|
|
51
|
-
* Gate, supply its exact TypedAction including amount; do not change this
|
|
52
|
-
* helper's established type hash or treat this as a transfer of identity.
|
|
53
|
-
*
|
|
54
|
-
* `domain` names the service the delegation is for, so a delegation issued to
|
|
55
|
-
* one service cannot be presented at another: the domain separator is part of
|
|
56
|
-
* what the proof binds.
|
|
57
|
-
*/
|
|
58
|
-
export function buildDelegationAction(params) {
|
|
59
|
-
const { delegation, domain } = params;
|
|
60
|
-
if (!ADDRESS.test(delegation.delegate)) {
|
|
61
|
-
throw new Error(`delegate must be an address, got '${delegation.delegate}'.`);
|
|
62
|
-
}
|
|
63
|
-
if (!delegation.action.trim()) {
|
|
64
|
-
throw new Error('A delegation must say what the delegate may do; `action` was empty.');
|
|
65
|
-
}
|
|
66
|
-
if (!Number.isInteger(delegation.expiresAt) || delegation.expiresAt <= 0) {
|
|
67
|
-
throw new Error('expiresAt must be a Unix time in seconds. A delegation without an end is not offered.');
|
|
68
|
-
}
|
|
69
|
-
if (!delegation.nonce.trim()) {
|
|
70
|
-
throw new Error('A delegation needs a nonce, or the same signature can be replayed.');
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
domain,
|
|
74
|
-
types: DELEGATION_TYPES,
|
|
75
|
-
primaryType: DELEGATION_PRIMARY_TYPE,
|
|
76
|
-
message: {
|
|
77
|
-
delegate: delegation.delegate,
|
|
78
|
-
action: delegation.action,
|
|
79
|
-
expiresAt: delegation.expiresAt,
|
|
80
|
-
nonce: delegation.nonce,
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
/** The 32 bytes a proof carries for this action: EIP-712's hashStruct. */
|
|
85
|
-
export function delegationActionHash(action) {
|
|
86
|
-
return ethers.TypedDataEncoder.hashStruct(action.primaryType, action.types, action.message);
|
|
87
|
-
}
|
|
88
|
-
/** The 32 bytes a proof carries for the service this delegation is for. */
|
|
89
|
-
export function delegationDomainSeparator(action) {
|
|
90
|
-
return ethers.TypedDataEncoder.hashDomain(action.domain);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Whether a proof was made for exactly this delegation.
|
|
94
|
-
*
|
|
95
|
-
* The reason to call this rather than trust the delegation shown alongside the
|
|
96
|
-
* proof: a proof is public once presented, and anything that reads the
|
|
97
|
-
* delegate out of an unverified structure can be handed a proof plus a
|
|
98
|
-
* delegation naming somebody else.
|
|
99
|
-
*/
|
|
100
|
-
export function delegationMatchesProof(params) {
|
|
101
|
-
const { action, domainSeparator, actionHash } = params;
|
|
102
|
-
const now = params.now ?? Math.floor(Date.now() / 1000);
|
|
103
|
-
if (action.primaryType !== DELEGATION_PRIMARY_TYPE) {
|
|
104
|
-
return `This action is a '${action.primaryType}', not a ${DELEGATION_PRIMARY_TYPE}. It authorises something, but not a delegation.`;
|
|
105
|
-
}
|
|
106
|
-
if (delegationDomainSeparator(action).toLowerCase() !== domainSeparator.toLowerCase()) {
|
|
107
|
-
return 'The proof was made for a different service: its domain separator does not match this delegation.';
|
|
108
|
-
}
|
|
109
|
-
if (delegationActionHash(action).toLowerCase() !== actionHash.toLowerCase()) {
|
|
110
|
-
return 'The proof was made for a different delegation: its action hash does not match the one shown.';
|
|
111
|
-
}
|
|
112
|
-
const expiresAt = Number(action.message.expiresAt);
|
|
113
|
-
if (!Number.isFinite(expiresAt) || expiresAt <= now) {
|
|
114
|
-
return `This delegation expired at ${expiresAt}, and it is now ${now}.`;
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
/** The wallet a checked delegation names. Throws rather than return a guess. */
|
|
119
|
-
export function delegateOf(action) {
|
|
120
|
-
const delegate = action.message.delegate;
|
|
121
|
-
if (typeof delegate !== 'string' || !ADDRESS.test(delegate)) {
|
|
122
|
-
return (() => { throw new Error(`This action names no delegate address: got '${String(delegate)}'.`); })();
|
|
123
|
-
}
|
|
124
|
-
return delegate;
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=delegation.js.map
|
package/dist/delegation.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegation.js","sourceRoot":"","sources":["../src/delegation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAehC,MAAM,OAAO,GAAG,qBAAqB,CAAC;AAEtC,yEAAyE;AACzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,CAAC,uBAAuB,CAAC,EAAE;QACzB,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;QACrC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;QAClC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;KAClC;CACO,CAAC;AAEX;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAGrC;IACC,MAAM,EAAE,UAAU,EAAE,M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AC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7G,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/nanopayment.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Paying with Arc nanopayments: deposit once, then pay many times for free.
|
|
3
|
-
*
|
|
4
|
-
* ## What is different from the ordinary path
|
|
5
|
-
*
|
|
6
|
-
* An ordinary x402 payment puts one authorization on chain per purchase, and
|
|
7
|
-
* on Arc that costs gas in USDC — measured 2026-09-12 at 0.0035 USDC to settle
|
|
8
|
-
* a payment of 0.001, which is four times the price of the thing being bought.
|
|
9
|
-
* That is fine for a one-off and absurd for an agent buying thousands of
|
|
10
|
-
* proofs.
|
|
11
|
-
*
|
|
12
|
-
* Circle Gateway takes the same EIP-3009 authorization, verifies it off chain
|
|
13
|
-
* in under a second, and settles thousands of them in one transaction. The
|
|
14
|
-
* buyer's money moves into Gateway once, by depositing; after that each
|
|
15
|
-
* payment is a signature and nothing more.
|
|
16
|
-
*
|
|
17
|
-
* ## What the buyer has to do
|
|
18
|
-
*
|
|
19
|
-
* Deposit first. A signature drawn against a Gateway balance that is not there
|
|
20
|
-
* is refused, and the refusal names the balance rather than the signature, so
|
|
21
|
-
* `ensureGatewayBalance` checks before paying rather than after failing.
|
|
22
|
-
*/
|
|
23
|
-
/** Arc Testnet, as `@circle-fin/x402-batching` names it. */
|
|
24
|
-
export declare const ARC_GATEWAY_CHAIN: "arcTestnet";
|
|
25
|
-
export interface NanopaymentWallet {
|
|
26
|
-
/** The buyer's key. Gateway signs authorizations with it and never sends a transaction per payment. */
|
|
27
|
-
privateKey: `0x${string}`;
|
|
28
|
-
/** Arc's RPC. Required — the package's default is for Arc mainnet. */
|
|
29
|
-
rpcUrl: string;
|
|
30
|
-
}
|
|
31
|
-
/** What a buyer holds inside Gateway, in USDC's smallest units. */
|
|
32
|
-
export interface GatewayBalances {
|
|
33
|
-
/** Spendable right now. */
|
|
34
|
-
available: bigint;
|
|
35
|
-
/** On the way out, not spendable. */
|
|
36
|
-
withdrawing: bigint;
|
|
37
|
-
}
|
|
38
|
-
/** What the buyer currently has inside Gateway. */
|
|
39
|
-
export declare function gatewayBalance(wallet: NanopaymentWallet): Promise<GatewayBalances>;
|
|
40
|
-
/**
|
|
41
|
-
* Make sure the buyer can pay `atLeast`, depositing `topUp` if not.
|
|
42
|
-
*
|
|
43
|
-
* Deposits are the one on-chain step in this flow and they cost gas, so this
|
|
44
|
-
* is deliberately not called before every payment — an agent deposits once and
|
|
45
|
-
* spends against it.
|
|
46
|
-
*/
|
|
47
|
-
export declare function ensureGatewayBalance(wallet: NanopaymentWallet,
|
|
48
|
-
/** In USDC's smallest units. Undefined requests an unconditional deposit. */
|
|
49
|
-
atLeast: bigint | undefined,
|
|
50
|
-
/** In whole USDC, like everything the deposit call takes. */
|
|
51
|
-
topUp: string): Promise<{
|
|
52
|
-
deposited: boolean;
|
|
53
|
-
balance: GatewayBalances;
|
|
54
|
-
depositTxHash?: string;
|
|
55
|
-
}>;
|
|
56
|
-
/**
|
|
57
|
-
* Buy something priced in x402, paying through Gateway.
|
|
58
|
-
*
|
|
59
|
-
* The 402 answer must carry a batched offer; a service that offers only the
|
|
60
|
-
* ordinary on-chain options is not reachable this way, and saying so is better
|
|
61
|
-
* than silently paying the expensive way.
|
|
62
|
-
*/
|
|
63
|
-
export declare function payWithNanopayments<T = unknown>(wallet: NanopaymentWallet, url: string, options?: {
|
|
64
|
-
method?: string;
|
|
65
|
-
body?: unknown;
|
|
66
|
-
headers?: Record<string, string>;
|
|
67
|
-
}): Promise<{
|
|
68
|
-
data: T;
|
|
69
|
-
amount: string;
|
|
70
|
-
}>;
|
|
71
|
-
//# sourceMappingURL=nanopayment.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nanopayment.d.ts","sourceRoot":"","sources":["../src/nanopayment.ts"],"names":[],"mappings":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ments: deposit once, then pay many times for free.
|
|
3
|
-
*
|
|
4
|
-
* ## What is different from the ordinary path
|
|
5
|
-
*
|
|
6
|
-
* An ordinary x402 payment puts one authorization on chain per purchase, and
|
|
7
|
-
* on Arc that costs gas in USDC — measured 2026-09-12 at 0.0035 USDC to settle
|
|
8
|
-
* a payment of 0.001, which is four times the price of the thing being bought.
|
|
9
|
-
* That is fine for a one-off and absurd for an agent buying thousands of
|
|
10
|
-
* proofs.
|
|
11
|
-
*
|
|
12
|
-
* Circle Gateway takes the same EIP-3009 authorization, verifies it off chain
|
|
13
|
-
* in under a second, and settles thousands of them in one transaction. The
|
|
14
|
-
* buyer's money moves into Gateway once, by depositing; after that each
|
|
15
|
-
* payment is a signature and nothing more.
|
|
16
|
-
*
|
|
17
|
-
* ## What the buyer has to do
|
|
18
|
-
*
|
|
19
|
-
* Deposit first. A signature drawn against a Gateway balance that is not there
|
|
20
|
-
* is refused, and the refusal names the balance rather than the signature, so
|
|
21
|
-
* `ensureGatewayBalance` checks before paying rather than after failing.
|
|
22
|
-
*/
|
|
23
|
-
import { GatewayClient } from '@circle-fin/x402-batching/client';
|
|
24
|
-
/** Arc Testnet, as `@circle-fin/x402-batching` names it. */
|
|
25
|
-
export const ARC_GATEWAY_CHAIN = 'arcTestnet';
|
|
26
|
-
function client(wallet) {
|
|
27
|
-
return new GatewayClient({
|
|
28
|
-
chain: ARC_GATEWAY_CHAIN,
|
|
29
|
-
privateKey: wallet.privateKey,
|
|
30
|
-
rpcUrl: wallet.rpcUrl,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/** What the buyer currently has inside Gateway. */
|
|
34
|
-
export async function gatewayBalance(wallet) {
|
|
35
|
-
const balance = await client(wallet).getBalance();
|
|
36
|
-
return { available: balance.available, withdrawing: balance.withdrawing };
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Make sure the buyer can pay `atLeast`, depositing `topUp` if not.
|
|
40
|
-
*
|
|
41
|
-
* Deposits are the one on-chain step in this flow and they cost gas, so this
|
|
42
|
-
* is deliberately not called before every payment — an agent deposits once and
|
|
43
|
-
* spends against it.
|
|
44
|
-
*/
|
|
45
|
-
export async function ensureGatewayBalance(wallet,
|
|
46
|
-
/** In USDC's smallest units. Undefined requests an unconditional deposit. */
|
|
47
|
-
atLeast,
|
|
48
|
-
/** In whole USDC, like everything the deposit call takes. */
|
|
49
|
-
topUp) {
|
|
50
|
-
const before = await gatewayBalance(wallet);
|
|
51
|
-
if (atLeast !== undefined && before.available >= atLeast)
|
|
52
|
-
return { deposited: false, balance: before };
|
|
53
|
-
const result = await client(wallet).deposit(topUp);
|
|
54
|
-
return {
|
|
55
|
-
deposited: true,
|
|
56
|
-
balance: await gatewayBalance(wallet),
|
|
57
|
-
depositTxHash: result.depositTxHash,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Buy something priced in x402, paying through Gateway.
|
|
62
|
-
*
|
|
63
|
-
* The 402 answer must carry a batched offer; a service that offers only the
|
|
64
|
-
* ordinary on-chain options is not reachable this way, and saying so is better
|
|
65
|
-
* than silently paying the expensive way.
|
|
66
|
-
*/
|
|
67
|
-
export async function payWithNanopayments(wallet, url, options) {
|
|
68
|
-
const gateway = client(wallet);
|
|
69
|
-
const supported = await gateway.supports(url);
|
|
70
|
-
if (!supported.supported) {
|
|
71
|
-
throw new Error(`${url} offers no batched payment option, so it cannot be paid through Circle Gateway. ` +
|
|
72
|
-
`Pay it the ordinary way, or have the service offer arc-testnet-nano.`);
|
|
73
|
-
}
|
|
74
|
-
const paid = await gateway.pay(url, options);
|
|
75
|
-
return { data: paid.data, amount: String(paid.amount ?? '0') };
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=nanopayment.js.map
|
package/dist/nanopayment.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nanopayment.js","sourceRoot":"","sources":["../src/nanopayment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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/E,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,GAAG,GAAG,kFAAkF;YACxF,sEAAsE,CACvE,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAAI,GAAG,EAAE,OAAgB,CAAC,CAAC;IACzD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAS,EAAE,MAAM,EAAE,MAAM,CAAE,IAA6B,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC;AAChG,CAAC"}
|
package/dist/typedAction.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typedAction.d.ts","sourceRoot":"","sources":["../src/typedAction.ts"],"names":[],"mappings":"AAsBA,6EAA6E;AAC7E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAkDjE"}
|
package/dist/typedAction.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
2
|
-
/** The reason the value is not a usable action, or `null` when it is one. */
|
|
3
|
-
export function validateTypedAction(value) {
|
|
4
|
-
if (value === undefined || value === null) {
|
|
5
|
-
return 'action is required for arc_eligibility. The circuit proves that a wallet authorised ONE EIP-712 action; there is nothing to prove without it.';
|
|
6
|
-
}
|
|
7
|
-
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
8
|
-
return 'action must be an object.';
|
|
9
|
-
}
|
|
10
|
-
const a = value;
|
|
11
|
-
const d = a.domain;
|
|
12
|
-
if (!d || typeof d !== 'object') {
|
|
13
|
-
return 'action.domain is required.';
|
|
14
|
-
}
|
|
15
|
-
for (const k of ['name', 'version', 'verifyingContract']) {
|
|
16
|
-
if (typeof d[k] !== 'string' || !d[k]) {
|
|
17
|
-
return `action.domain.${k} must be a non-empty string.`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (typeof d.chainId !== 'number' || !Number.isInteger(d.chainId)) {
|
|
21
|
-
return 'action.domain.chainId must be an integer.';
|
|
22
|
-
}
|
|
23
|
-
if (!ADDRESS.test(d.verifyingContract)) {
|
|
24
|
-
return 'action.domain.verifyingContract must be a 20-byte hex address.';
|
|
25
|
-
}
|
|
26
|
-
if (!a.types || typeof a.types !== 'object' || Array.isArray(a.types)) {
|
|
27
|
-
return 'action.types is required.';
|
|
28
|
-
}
|
|
29
|
-
if (typeof a.primaryType !== 'string' || !a.primaryType) {
|
|
30
|
-
return 'action.primaryType is required.';
|
|
31
|
-
}
|
|
32
|
-
if (!(a.primaryType in a.types)) {
|
|
33
|
-
return `action.primaryType '${a.primaryType}' is not one of the structs in action.types.`;
|
|
34
|
-
}
|
|
35
|
-
if (!a.message || typeof a.message !== 'object' || Array.isArray(a.message)) {
|
|
36
|
-
return 'action.message is required.';
|
|
37
|
-
}
|
|
38
|
-
const fields = a.types[a.primaryType];
|
|
39
|
-
if (!Array.isArray(fields) || fields.length === 0) {
|
|
40
|
-
return `action.types.${a.primaryType} declares no fields.`;
|
|
41
|
-
}
|
|
42
|
-
const missing = fields
|
|
43
|
-
.map(f => f?.name)
|
|
44
|
-
.filter(n => typeof n === 'string' && !(n in a.message));
|
|
45
|
-
if (missing.length) {
|
|
46
|
-
return `action.message is missing: ${missing.join(', ')}`;
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=typedAction.js.map
|
package/dist/typedAction.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typedAction.js","sourceRoot":"","sources":["../src/typedAction.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,GAAG,qBAAqB,CAAC;AAEtC,6EAA6E;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