@zkproofport-ai/sdk 0.2.10 → 0.2.11
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 +232 -18
- package/dist/arcWallet.d.ts +50 -0
- package/dist/arcWallet.d.ts.map +1 -0
- package/dist/arcWallet.js +158 -0
- package/dist/arcWallet.js.map +1 -0
- package/dist/attestation.d.ts +5 -1
- package/dist/attestation.d.ts.map +1 -1
- package/dist/attestation.js +21 -2
- package/dist/attestation.js.map +1 -1
- package/dist/cdp.d.ts +162 -0
- package/dist/cdp.d.ts.map +1 -0
- package/dist/cdp.js +78 -0
- package/dist/cdp.js.map +1 -0
- package/dist/circuits.d.ts +121 -0
- package/dist/circuits.d.ts.map +1 -0
- package/dist/circuits.js +129 -0
- package/dist/circuits.js.map +1 -0
- package/dist/constants.d.ts +8 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -4
- package/dist/constants.js.map +1 -1
- package/dist/delegation.d.ts +102 -0
- package/dist/delegation.d.ts.map +1 -0
- package/dist/delegation.js +121 -0
- package/dist/delegation.js.map +1 -0
- package/dist/extract.d.ts +46 -12
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +92 -30
- package/dist/extract.js.map +1 -1
- package/dist/flow.d.ts +13 -0
- package/dist/flow.d.ts.map +1 -1
- package/dist/flow.js +88 -3
- package/dist/flow.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +12 -0
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +13 -2
- package/dist/inputs.js.map +1 -1
- package/dist/nanopayment.d.ts +71 -0
- package/dist/nanopayment.d.ts.map +1 -0
- package/dist/nanopayment.js +77 -0
- package/dist/nanopayment.js.map +1 -0
- package/dist/payment.d.ts +73 -0
- package/dist/payment.d.ts.map +1 -0
- package/dist/payment.js +167 -0
- package/dist/payment.js.map +1 -0
- package/dist/prove.d.ts +7 -0
- package/dist/prove.d.ts.map +1 -1
- package/dist/prove.js +2 -0
- package/dist/prove.js.map +1 -1
- package/dist/typedAction.d.ts +3 -0
- package/dist/typedAction.d.ts.map +1 -0
- package/dist/typedAction.js +50 -0
- package/dist/typedAction.js.map +1 -0
- package/dist/types.d.ts +146 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -6
- package/dist/types.js.map +1 -1
- package/dist/usdc.d.ts +63 -0
- package/dist/usdc.d.ts.map +1 -0
- package/dist/usdc.js +78 -0
- package/dist/usdc.js.map +1 -0
- package/dist/wallets.d.ts +96 -0
- package/dist/wallets.d.ts.map +1 -0
- package/dist/wallets.js +214 -0
- package/dist/wallets.js.map +1 -0
- package/package.json +40 -3
package/dist/usdc.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The USDC contracts this SDK is willing to pay in.
|
|
3
|
+
*
|
|
4
|
+
* ## Why the client keeps its own list
|
|
5
|
+
*
|
|
6
|
+
* A 402 answer names the token it wants paid in. Signing whatever it names
|
|
7
|
+
* means a service can ask for any token at all -- including one it minted --
|
|
8
|
+
* and a wallet paying autonomously would sign it. `@x402/core` guards against
|
|
9
|
+
* exactly that: it refuses to sign for an asset outside its own default list
|
|
10
|
+
* unless told otherwise, and refusing is the correct behaviour.
|
|
11
|
+
*
|
|
12
|
+
* Arc's USDC is not in that default list, so paying on Arc needs this list
|
|
13
|
+
* rather than `spendControls: false`. The difference matters: turning the
|
|
14
|
+
* control off allows every token on every chain, which is how an agent ends up
|
|
15
|
+
* signing away something nobody meant to spend. This allows five specific
|
|
16
|
+
* contracts and nothing else.
|
|
17
|
+
*
|
|
18
|
+
* So yes, this duplicates the server's table in `src/payment/networks.ts` --
|
|
19
|
+
* deliberately. A shared table would mean the client trusting the server's
|
|
20
|
+
* word about which token is USDC, which is the thing being guarded against.
|
|
21
|
+
*
|
|
22
|
+
* ## Keeping it right
|
|
23
|
+
*
|
|
24
|
+
* Each address was read from the chain, not from memory:
|
|
25
|
+
* `decimals()` is 6 and `name()`/`symbol()` say USDC on all five. Arc's is the
|
|
26
|
+
* ERC-20 view of its native balance, checked on 2026-09-09 -- name "USDC",
|
|
27
|
+
* version "2", decimals 6, and a `DOMAIN_SEPARATOR()` that matches the hash a
|
|
28
|
+
* client computes from those values.
|
|
29
|
+
*/
|
|
30
|
+
/** CAIP-2 chain id → the USDC contract on it. */
|
|
31
|
+
const USDC_BY_CHAIN = {
|
|
32
|
+
'eip155:1': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // Ethereum
|
|
33
|
+
'eip155:11155111': '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // Ethereum Sepolia
|
|
34
|
+
'eip155:8453': '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // Base
|
|
35
|
+
'eip155:84532': '0x036CbD53842c5426634e7929541eC2318f3dCF7e', // Base Sepolia
|
|
36
|
+
'eip155:5042002': '0x3600000000000000000000000000000000000000', // Arc, native USDC's ERC-20 view
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The most this SDK will sign for in one payment, unless the caller says
|
|
40
|
+
* otherwise.
|
|
41
|
+
*
|
|
42
|
+
* A proof costs cents. A cap two orders of magnitude above that leaves room
|
|
43
|
+
* for a price change without leaving room for a mistake -- and it is the
|
|
44
|
+
* difference between a misconfigured service overcharging by a cent and
|
|
45
|
+
* draining a wallet.
|
|
46
|
+
*/
|
|
47
|
+
export const DEFAULT_MAX_PAYMENT = '$1';
|
|
48
|
+
/**
|
|
49
|
+
* The spend controls to sign under: these five USDC contracts, capped.
|
|
50
|
+
*
|
|
51
|
+
* Passing an asset the offer names that is NOT in the list produces a refusal
|
|
52
|
+
* from `@x402/core` rather than a signature.
|
|
53
|
+
*/
|
|
54
|
+
export function usdcSpendControls(maxPayment) {
|
|
55
|
+
return {
|
|
56
|
+
maxAmountPerPayment: maxPayment ?? DEFAULT_MAX_PAYMENT,
|
|
57
|
+
allowedAssets: Object.entries(USDC_BY_CHAIN).map(([network, asset]) => ({
|
|
58
|
+
network,
|
|
59
|
+
asset,
|
|
60
|
+
})),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Whether an offer names the USDC this SDK knows for that chain.
|
|
65
|
+
*
|
|
66
|
+
* Checked before signing so the error says which token was asked for, rather
|
|
67
|
+
* than letting `@x402/core` refuse with a message about allowedAssets that
|
|
68
|
+
* does not name the culprit.
|
|
69
|
+
*/
|
|
70
|
+
export function isKnownUsdc(network, asset) {
|
|
71
|
+
const known = USDC_BY_CHAIN[network];
|
|
72
|
+
return !!known && known.toLowerCase() === asset.toLowerCase();
|
|
73
|
+
}
|
|
74
|
+
/** The USDC this SDK knows for a chain, or undefined. */
|
|
75
|
+
export function knownUsdc(network) {
|
|
76
|
+
return USDC_BY_CHAIN[network];
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=usdc.js.map
|
package/dist/usdc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usdc.js","sourceRoot":"","sources":["../src/usdc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,iDAAiD;AACjD,MAAM,aAAa,GAA2B;IAC5C,UAAU,EAAE,4CAA4C,EAAa,WAAW;IAChF,iBAAiB,EAAE,4CAA4C,EAAM,mBAAmB;IACxF,aAAa,EAAE,4CAA4C,EAAU,OAAO;IAC5E,cAAc,EAAE,4CAA4C,EAAS,eAAe;IACpF,gBAAgB,EAAE,4CAA4C,EAAO,iCAAiC;CACvG,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAmB;IACnD,OAAO;QACL,mBAAmB,EAAE,UAAU,IAAI,mBAAmB;QACtD,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACtE,OAAO;YACP,KAAK;SACN,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,KAAa;IACxD,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC;AAChE,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wallet that pays for a proof.
|
|
3
|
+
*
|
|
4
|
+
* ## One interface, three wallets
|
|
5
|
+
*
|
|
6
|
+
* Paying for a proof means signing one EIP-712 message -- an EIP-3009
|
|
7
|
+
* `TransferWithAuthorization` over USDC. Nothing else. No transaction, no gas,
|
|
8
|
+
* no native balance on the chain being paid on. So a payment wallet needs
|
|
9
|
+
* exactly two things:
|
|
10
|
+
*
|
|
11
|
+
* { address, signTypedData({ domain, types, primaryType, message }) }
|
|
12
|
+
*
|
|
13
|
+
* which is `ClientEvmSigner` from `@x402/evm`. Every wallet below is a way of
|
|
14
|
+
* getting one:
|
|
15
|
+
*
|
|
16
|
+
* | To pay from | Call | What you need |
|
|
17
|
+
* |---|---|---|
|
|
18
|
+
* | a raw private key | `walletFromPrivateKey` | the key |
|
|
19
|
+
* | a Coinbase CDP server wallet | `walletFromCdp` | CDP API key id + secret + wallet secret |
|
|
20
|
+
* | a Circle wallet, including on Arc | `walletFromCircle` | Circle API key + entity secret + wallet id |
|
|
21
|
+
*
|
|
22
|
+
* The chain is chosen separately, when paying. A CDP wallet can pay on Arc and
|
|
23
|
+
* a Circle wallet can pay on Base; wallet and chain are independent, and the
|
|
24
|
+
* earlier version of this file got that wrong by baking one into the other.
|
|
25
|
+
*
|
|
26
|
+
* ## Why the CDP and Circle paths are thin
|
|
27
|
+
*
|
|
28
|
+
* Both vendors ship the adapter. `@coinbase/cdp-sdk/x402` exports
|
|
29
|
+
* `fromCdpEvmAccount`, which returns exactly this interface, so the CDP path is
|
|
30
|
+
* a call to their function rather than an EIP-712 client written here. Circle
|
|
31
|
+
* has no x402 adapter, so `walletFromCircle` is the one adapter this file
|
|
32
|
+
* really implements -- eleven lines around `signTypedData`, which is all Circle
|
|
33
|
+
* needs to participate.
|
|
34
|
+
*
|
|
35
|
+
* Both imports are lazy. Someone paying from a private key installs neither.
|
|
36
|
+
*/
|
|
37
|
+
import type { PaymentWallet } from './types.js';
|
|
38
|
+
/**
|
|
39
|
+
* Pay from a raw private key.
|
|
40
|
+
*
|
|
41
|
+
* The simplest thing that works, and the right choice for a test or a CI run.
|
|
42
|
+
* The key signs an authorization and nothing else -- it needs a USDC balance
|
|
43
|
+
* on the paying chain and no gas anywhere.
|
|
44
|
+
*/
|
|
45
|
+
export declare function walletFromPrivateKey(privateKey: string): Promise<PaymentWallet>;
|
|
46
|
+
/**
|
|
47
|
+
* Pay from a Coinbase CDP server wallet.
|
|
48
|
+
*
|
|
49
|
+
* Uses CDP's own x402 adapter rather than an EIP-712 client written here, so
|
|
50
|
+
* changes to how CDP signs arrive with a package upgrade instead of a bug.
|
|
51
|
+
*
|
|
52
|
+
* `walletName` names a wallet inside the CDP project; `getOrCreateAccount`
|
|
53
|
+
* makes it on first use, which is what lets a fresh environment pay without a
|
|
54
|
+
* setup step.
|
|
55
|
+
*/
|
|
56
|
+
export declare function walletFromCdp(opts: {
|
|
57
|
+
apiKeyId: string;
|
|
58
|
+
apiKeySecret: string;
|
|
59
|
+
walletSecret: string;
|
|
60
|
+
walletName?: string;
|
|
61
|
+
}): Promise<PaymentWallet>;
|
|
62
|
+
/**
|
|
63
|
+
* Pay from a Circle developer-controlled wallet -- the way to pay on Arc.
|
|
64
|
+
*
|
|
65
|
+
* Arc is Circle's chain and USDC is its gas asset, so a Circle wallet holding
|
|
66
|
+
* USDC there can pay without holding anything else. `ARC-TESTNET` is the
|
|
67
|
+
* blockchain name in Circle's own SDK types; it is not needed for signing (an
|
|
68
|
+
* authorization is chain-agnostic once the domain names the chain id) and is
|
|
69
|
+
* only used when this wallet is asked which chain it was created for.
|
|
70
|
+
*
|
|
71
|
+
* Note that Arc needs no special case in the payment path itself. Asked
|
|
72
|
+
* directly on 2026-09-09, Arc's USDC at 0x3600...0000 answers name()="USDC",
|
|
73
|
+
* version()="2", decimals()=6, and a DOMAIN_SEPARATOR() that matches what a
|
|
74
|
+
* client computes from those values -- so an Arc authorization is an ordinary
|
|
75
|
+
* USDC authorization and this wallet is an ordinary signer.
|
|
76
|
+
*/
|
|
77
|
+
export declare function walletFromCircle(opts: {
|
|
78
|
+
apiKey: string;
|
|
79
|
+
entitySecret: string;
|
|
80
|
+
walletId: string;
|
|
81
|
+
/** The wallet's address. Read from Circle when omitted. */
|
|
82
|
+
address?: string;
|
|
83
|
+
}): Promise<PaymentWallet>;
|
|
84
|
+
/**
|
|
85
|
+
* The wallet a set of environment variables describes, or an error saying
|
|
86
|
+
* which variables would have been needed.
|
|
87
|
+
*
|
|
88
|
+
* Deliberately refuses to pick when two wallets are configured, rather than
|
|
89
|
+
* preferring one. A machine holding both a CDP and a Circle credential has no
|
|
90
|
+
* obvious default, and silently choosing means the money leaves an account the
|
|
91
|
+
* caller did not name.
|
|
92
|
+
*/
|
|
93
|
+
export declare function walletFromEnv(env?: Record<string, string | undefined>): Promise<PaymentWallet>;
|
|
94
|
+
/** The wallet named by `which`, built from `env`. */
|
|
95
|
+
export declare function walletFor(which: string, env?: Record<string, string | undefined>): Promise<PaymentWallet>;
|
|
96
|
+
//# sourceMappingURL=wallets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../src/wallets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CASrF;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC,aAAa,CAAC,CA+BzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC,aAAa,CAAC,CAgDzB;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CAqBjH;AAED,qDAAqD;AACrD,wBAAsB,SAAS,CAC7B,KAAK,EAAE,MAAM,EACb,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,OAAO,CAAC,aAAa,CAAC,CAkCxB"}
|
package/dist/wallets.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wallet that pays for a proof.
|
|
3
|
+
*
|
|
4
|
+
* ## One interface, three wallets
|
|
5
|
+
*
|
|
6
|
+
* Paying for a proof means signing one EIP-712 message -- an EIP-3009
|
|
7
|
+
* `TransferWithAuthorization` over USDC. Nothing else. No transaction, no gas,
|
|
8
|
+
* no native balance on the chain being paid on. So a payment wallet needs
|
|
9
|
+
* exactly two things:
|
|
10
|
+
*
|
|
11
|
+
* { address, signTypedData({ domain, types, primaryType, message }) }
|
|
12
|
+
*
|
|
13
|
+
* which is `ClientEvmSigner` from `@x402/evm`. Every wallet below is a way of
|
|
14
|
+
* getting one:
|
|
15
|
+
*
|
|
16
|
+
* | To pay from | Call | What you need |
|
|
17
|
+
* |---|---|---|
|
|
18
|
+
* | a raw private key | `walletFromPrivateKey` | the key |
|
|
19
|
+
* | a Coinbase CDP server wallet | `walletFromCdp` | CDP API key id + secret + wallet secret |
|
|
20
|
+
* | a Circle wallet, including on Arc | `walletFromCircle` | Circle API key + entity secret + wallet id |
|
|
21
|
+
*
|
|
22
|
+
* The chain is chosen separately, when paying. A CDP wallet can pay on Arc and
|
|
23
|
+
* a Circle wallet can pay on Base; wallet and chain are independent, and the
|
|
24
|
+
* earlier version of this file got that wrong by baking one into the other.
|
|
25
|
+
*
|
|
26
|
+
* ## Why the CDP and Circle paths are thin
|
|
27
|
+
*
|
|
28
|
+
* Both vendors ship the adapter. `@coinbase/cdp-sdk/x402` exports
|
|
29
|
+
* `fromCdpEvmAccount`, which returns exactly this interface, so the CDP path is
|
|
30
|
+
* a call to their function rather than an EIP-712 client written here. Circle
|
|
31
|
+
* has no x402 adapter, so `walletFromCircle` is the one adapter this file
|
|
32
|
+
* really implements -- eleven lines around `signTypedData`, which is all Circle
|
|
33
|
+
* needs to participate.
|
|
34
|
+
*
|
|
35
|
+
* Both imports are lazy. Someone paying from a private key installs neither.
|
|
36
|
+
*/
|
|
37
|
+
import { walletFromArcAgent } from './arcWallet.js';
|
|
38
|
+
/**
|
|
39
|
+
* Pay from a raw private key.
|
|
40
|
+
*
|
|
41
|
+
* The simplest thing that works, and the right choice for a test or a CI run.
|
|
42
|
+
* The key signs an authorization and nothing else -- it needs a USDC balance
|
|
43
|
+
* on the paying chain and no gas anywhere.
|
|
44
|
+
*/
|
|
45
|
+
export async function walletFromPrivateKey(privateKey) {
|
|
46
|
+
const { privateKeyToAccount } = await import('viem/accounts');
|
|
47
|
+
const key = privateKey.startsWith('0x') ? privateKey : `0x${privateKey}`;
|
|
48
|
+
const account = privateKeyToAccount(key);
|
|
49
|
+
return {
|
|
50
|
+
address: account.address,
|
|
51
|
+
signTypedData: (message) => account.signTypedData(message),
|
|
52
|
+
describe: () => `private key ${account.address}`,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Pay from a Coinbase CDP server wallet.
|
|
57
|
+
*
|
|
58
|
+
* Uses CDP's own x402 adapter rather than an EIP-712 client written here, so
|
|
59
|
+
* changes to how CDP signs arrive with a package upgrade instead of a bug.
|
|
60
|
+
*
|
|
61
|
+
* `walletName` names a wallet inside the CDP project; `getOrCreateAccount`
|
|
62
|
+
* makes it on first use, which is what lets a fresh environment pay without a
|
|
63
|
+
* setup step.
|
|
64
|
+
*/
|
|
65
|
+
export async function walletFromCdp(opts) {
|
|
66
|
+
let CdpClient;
|
|
67
|
+
let fromCdpEvmAccount;
|
|
68
|
+
try {
|
|
69
|
+
({ CdpClient } = (await import('@coinbase/cdp-sdk')));
|
|
70
|
+
({ fromCdpEvmAccount } = (await import('@coinbase/cdp-sdk/x402')));
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
// The original message is included rather than replaced: this fired once
|
|
74
|
+
// saying "install @coinbase/cdp-sdk" when cdp-sdk WAS installed and the
|
|
75
|
+
// missing package was its own peer, `@x402/extensions`. A message that
|
|
76
|
+
// names the wrong cause costs more time than no message.
|
|
77
|
+
throw new Error(`Could not load the CDP wallet support. Both @coinbase/cdp-sdk (>=1.55, for its ` +
|
|
78
|
+
`x402 adapter) and its peer @x402/extensions must be installed. ` +
|
|
79
|
+
`Underlying error: ${e.message}`);
|
|
80
|
+
}
|
|
81
|
+
const cdp = new CdpClient({
|
|
82
|
+
apiKeyId: opts.apiKeyId,
|
|
83
|
+
apiKeySecret: opts.apiKeySecret,
|
|
84
|
+
walletSecret: opts.walletSecret,
|
|
85
|
+
});
|
|
86
|
+
const account = await cdp.evm.getOrCreateAccount({ name: opts.walletName ?? 'zkproofport-payer' });
|
|
87
|
+
const signer = fromCdpEvmAccount(account);
|
|
88
|
+
return {
|
|
89
|
+
address: signer.address,
|
|
90
|
+
signTypedData: (message) => signer.signTypedData(message),
|
|
91
|
+
describe: () => `CDP wallet ${opts.walletName ?? 'zkproofport-payer'} (${signer.address})`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Pay from a Circle developer-controlled wallet -- the way to pay on Arc.
|
|
96
|
+
*
|
|
97
|
+
* Arc is Circle's chain and USDC is its gas asset, so a Circle wallet holding
|
|
98
|
+
* USDC there can pay without holding anything else. `ARC-TESTNET` is the
|
|
99
|
+
* blockchain name in Circle's own SDK types; it is not needed for signing (an
|
|
100
|
+
* authorization is chain-agnostic once the domain names the chain id) and is
|
|
101
|
+
* only used when this wallet is asked which chain it was created for.
|
|
102
|
+
*
|
|
103
|
+
* Note that Arc needs no special case in the payment path itself. Asked
|
|
104
|
+
* directly on 2026-09-09, Arc's USDC at 0x3600...0000 answers name()="USDC",
|
|
105
|
+
* version()="2", decimals()=6, and a DOMAIN_SEPARATOR() that matches what a
|
|
106
|
+
* client computes from those values -- so an Arc authorization is an ordinary
|
|
107
|
+
* USDC authorization and this wallet is an ordinary signer.
|
|
108
|
+
*/
|
|
109
|
+
export async function walletFromCircle(opts) {
|
|
110
|
+
let initiateDeveloperControlledWalletsClient;
|
|
111
|
+
try {
|
|
112
|
+
({ initiateDeveloperControlledWalletsClient } = (await import('@circle-fin/developer-controlled-wallets')));
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
throw new Error(`Paying from a Circle wallet needs @circle-fin/developer-controlled-wallets installed: ` +
|
|
116
|
+
`npm i @circle-fin/developer-controlled-wallets (${e.message})`);
|
|
117
|
+
}
|
|
118
|
+
const circle = initiateDeveloperControlledWalletsClient({
|
|
119
|
+
apiKey: opts.apiKey,
|
|
120
|
+
entitySecret: opts.entitySecret,
|
|
121
|
+
});
|
|
122
|
+
let address = opts.address;
|
|
123
|
+
if (!address) {
|
|
124
|
+
const got = await circle.getWallet({ id: opts.walletId });
|
|
125
|
+
address = got.data?.wallet?.address;
|
|
126
|
+
if (!address) {
|
|
127
|
+
throw new Error(`Circle wallet ${opts.walletId} has no address; check the wallet id and the API key`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
address: address,
|
|
132
|
+
async signTypedData(message) {
|
|
133
|
+
const res = await circle.signTypedData({
|
|
134
|
+
walletId: opts.walletId,
|
|
135
|
+
data: JSON.stringify(message),
|
|
136
|
+
memo: 'ZKProofport proof generation fee',
|
|
137
|
+
});
|
|
138
|
+
const signature = res.data?.signature;
|
|
139
|
+
if (!signature) {
|
|
140
|
+
throw new Error(`Circle wallet ${opts.walletId} returned no signature. A wallet can only sign on a chain it was ` +
|
|
141
|
+
`created for -- check it exists on the chain named in the payment's domain.`);
|
|
142
|
+
}
|
|
143
|
+
return signature;
|
|
144
|
+
},
|
|
145
|
+
describe: () => `Circle wallet ${opts.walletId} (${address})`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The wallet a set of environment variables describes, or an error saying
|
|
150
|
+
* which variables would have been needed.
|
|
151
|
+
*
|
|
152
|
+
* Deliberately refuses to pick when two wallets are configured, rather than
|
|
153
|
+
* preferring one. A machine holding both a CDP and a Circle credential has no
|
|
154
|
+
* obvious default, and silently choosing means the money leaves an account the
|
|
155
|
+
* caller did not name.
|
|
156
|
+
*/
|
|
157
|
+
export async function walletFromEnv(env = process.env) {
|
|
158
|
+
const configured = [];
|
|
159
|
+
if (env.PAYMENT_PRIVATE_KEY)
|
|
160
|
+
configured.push('key');
|
|
161
|
+
if (env.CDP_API_KEY_ID)
|
|
162
|
+
configured.push('cdp');
|
|
163
|
+
if (env.CIRCLE_API_KEY)
|
|
164
|
+
configured.push('circle');
|
|
165
|
+
if (configured.length === 0) {
|
|
166
|
+
throw new Error('No payment wallet configured. Set one of:\n' +
|
|
167
|
+
' PAYMENT_PRIVATE_KEY\n' +
|
|
168
|
+
' CDP_API_KEY_ID + CDP_API_KEY_SECRET + CDP_WALLET_SECRET\n' +
|
|
169
|
+
' CIRCLE_API_KEY + CIRCLE_ENTITY_SECRET + CIRCLE_WALLET_ID');
|
|
170
|
+
}
|
|
171
|
+
if (configured.length > 1) {
|
|
172
|
+
throw new Error(`More than one payment wallet is configured (${configured.join(', ')}). ` +
|
|
173
|
+
`Name the one to use rather than leaving it to be guessed.`);
|
|
174
|
+
}
|
|
175
|
+
return walletFor(configured[0], env);
|
|
176
|
+
}
|
|
177
|
+
/** The wallet named by `which`, built from `env`. */
|
|
178
|
+
export async function walletFor(which, env = process.env) {
|
|
179
|
+
const need = (name) => {
|
|
180
|
+
const v = env[name];
|
|
181
|
+
if (!v)
|
|
182
|
+
throw new Error(`Paying from a ${which} wallet requires ${name}`);
|
|
183
|
+
return v;
|
|
184
|
+
};
|
|
185
|
+
switch (which) {
|
|
186
|
+
case 'key':
|
|
187
|
+
return walletFromPrivateKey(need('PAYMENT_PRIVATE_KEY'));
|
|
188
|
+
case 'cdp':
|
|
189
|
+
return walletFromCdp({
|
|
190
|
+
apiKeyId: need('CDP_API_KEY_ID'),
|
|
191
|
+
apiKeySecret: need('CDP_API_KEY_SECRET'),
|
|
192
|
+
walletSecret: need('CDP_WALLET_SECRET'),
|
|
193
|
+
walletName: env.CDP_WALLET_NAME,
|
|
194
|
+
});
|
|
195
|
+
case 'arc':
|
|
196
|
+
// No credentials here: Circle's CLI holds the login, and the wallet is
|
|
197
|
+
// whichever agent wallet that login has on Arc. `ARC_AGENT_WALLET` names
|
|
198
|
+
// one when an account has several.
|
|
199
|
+
return walletFromArcAgent({
|
|
200
|
+
address: env.ARC_AGENT_WALLET,
|
|
201
|
+
chain: env.ARC_CLI_CHAIN ?? undefined,
|
|
202
|
+
});
|
|
203
|
+
case 'circle':
|
|
204
|
+
return walletFromCircle({
|
|
205
|
+
apiKey: need('CIRCLE_API_KEY'),
|
|
206
|
+
entitySecret: need('CIRCLE_ENTITY_SECRET'),
|
|
207
|
+
walletId: need('CIRCLE_WALLET_ID'),
|
|
208
|
+
address: env.CIRCLE_WALLET_ADDRESS,
|
|
209
|
+
});
|
|
210
|
+
default:
|
|
211
|
+
throw new Error(`Unknown payment wallet '${which}'. Choose one of: key, cdp, circle, arc`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=wallets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallets.js","sourceRoot":"","sources":["../src/wallets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,UAAkB;IAC3D,MAAM,EAAE,mBAAmB,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;IAC9D,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;IACzE,MAAM,OAAO,GAAG,mBAAmB,CAAC,GAAoB,CAAC,CAAC;IAC1D,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,aAAa,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,OAAgB,CAAC;QACnE,QAAQ,EAAE,GAAG,EAAE,CAAC,eAAe,OAAO,CAAC,OAAO,EAAE;KACjD,CAAC;AACJ,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AAiB,KAAK,oBAAoB,IAAI,EAAE,CAAC,CAAC;QAC1E,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;IACF,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,KAAK;YACR,OAAO,oBAAoB,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;QAC3D,KAAK,KAAK;YACR,OAAO,aAAa,CAAC;gBACnB,QAAQ,EAAE,IAAI,CAAC,gBAAgB,CAAC;gBAChC,YAAY,EAAE,IAAI,CAAC,oBAAoB,CAAC;gBACxC,YAAY,EAAE,IAAI,CAAC,mBAAmB,CAAC;gBACvC,UAAU,EAAE,GAAG,CAAC,eAAe;aAChC,CAAC,CAAC;QACL,KAAK,KAAK;YACR,uEAAuE;YACvE,yEAAyE;YACzE,mCAAmC;YACnC,OAAO,kBAAkB,CAAC;gBACxB,OAAO,EAAE,GAAG,CAAC,gBAAgB;gBAC7B,KAAK,EAAG,GAAG,CAAC,aAAuB,IAAI,SAAS;aACjD,CAAC,CAAC;QACL,KAAK,QAAQ;YACX,OAAO,gBAAgB,CAAC;gBACtB,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC;gBAC9B,YAAY,EAAE,IAAI,CAAC,sBAAsB,CAAC;gBAC1C,QAAQ,EAAE,IAAI,CAAC,kBAAkB,CAAC;gBAClC,OAAO,EAAE,GAAG,CAAC,qBAAqB;aACnC,CAAC,CAAC;QACL;YACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,yCAAyC,CAAC,CAAC;IAC/F,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zkproofport-ai/sdk",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.11",
|
|
4
|
+
"description": "TypeScript SDK for AI agents to generate zero-knowledge proofs of identity (Coinbase KYC, Country, Google OIDC, Workspace, MS 365) via ZKProofport. x402 USDC payments on Base, ERC-8004 agent identity. Privacy-preserving authentication for autonomous agents.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sdk",
|
|
7
|
+
"typescript",
|
|
8
|
+
"zero-knowledge-proofs",
|
|
9
|
+
"zk-proofs",
|
|
10
|
+
"zkp",
|
|
11
|
+
"ai-agents",
|
|
12
|
+
"privacy",
|
|
13
|
+
"identity",
|
|
14
|
+
"coinbase-kyc",
|
|
15
|
+
"google-oidc",
|
|
16
|
+
"x402",
|
|
17
|
+
"erc-8004",
|
|
18
|
+
"noir-lang",
|
|
19
|
+
"base-chain",
|
|
20
|
+
"ethers"
|
|
21
|
+
],
|
|
5
22
|
"type": "module",
|
|
6
23
|
"main": "dist/index.js",
|
|
7
24
|
"types": "dist/index.d.ts",
|
|
@@ -16,7 +33,11 @@
|
|
|
16
33
|
"typecheck": "tsc --noEmit"
|
|
17
34
|
},
|
|
18
35
|
"dependencies": {
|
|
19
|
-
"
|
|
36
|
+
"@circle-fin/x402-batching": "^3.4.0",
|
|
37
|
+
"@x402/core": "^2.25.0",
|
|
38
|
+
"@x402/evm": "^2.25.0",
|
|
39
|
+
"ethers": "^6.13.0",
|
|
40
|
+
"viem": "^2.45.2"
|
|
20
41
|
},
|
|
21
42
|
"devDependencies": {
|
|
22
43
|
"typescript": "^5.6.0"
|
|
@@ -30,5 +51,21 @@
|
|
|
30
51
|
"type": "git",
|
|
31
52
|
"url": "https://github.com/zkproofport/proofport-ai",
|
|
32
53
|
"directory": "packages/sdk"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@circle-fin/developer-controlled-wallets": ">=10.0.0",
|
|
57
|
+
"@coinbase/cdp-sdk": ">=1.55.0",
|
|
58
|
+
"@x402/extensions": ">=2.25.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"@coinbase/cdp-sdk": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"@circle-fin/developer-controlled-wallets": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"@x402/extensions": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
33
70
|
}
|
|
34
71
|
}
|