@fastxyz/allset-sdk 0.1.11 → 1.0.0

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.
Files changed (44) hide show
  1. package/README.md +339 -266
  2. package/dist/index.d.ts +658 -5
  3. package/dist/index.js +927 -7
  4. package/package.json +21 -47
  5. package/dist/browser/index.d.ts +0 -2
  6. package/dist/browser/index.d.ts.map +0 -1
  7. package/dist/browser/index.js +0 -1
  8. package/dist/core/address.d.ts +0 -5
  9. package/dist/core/address.d.ts.map +0 -1
  10. package/dist/core/address.js +0 -29
  11. package/dist/core/deposit.d.ts +0 -59
  12. package/dist/core/deposit.d.ts.map +0 -1
  13. package/dist/core/deposit.js +0 -92
  14. package/dist/core/index.d.ts +0 -6
  15. package/dist/core/index.d.ts.map +0 -1
  16. package/dist/core/index.js +0 -3
  17. package/dist/default-config.d.ts +0 -78
  18. package/dist/default-config.d.ts.map +0 -1
  19. package/dist/default-config.js +0 -78
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/intents.d.ts +0 -94
  22. package/dist/intents.d.ts.map +0 -1
  23. package/dist/intents.js +0 -119
  24. package/dist/node/bridge.d.ts +0 -38
  25. package/dist/node/bridge.d.ts.map +0 -1
  26. package/dist/node/bridge.js +0 -519
  27. package/dist/node/config.d.ts +0 -45
  28. package/dist/node/config.d.ts.map +0 -1
  29. package/dist/node/config.js +0 -48
  30. package/dist/node/eip7702.d.ts +0 -47
  31. package/dist/node/eip7702.d.ts.map +0 -1
  32. package/dist/node/eip7702.js +0 -189
  33. package/dist/node/evm-executor.d.ts +0 -130
  34. package/dist/node/evm-executor.d.ts.map +0 -1
  35. package/dist/node/evm-executor.js +0 -160
  36. package/dist/node/index.d.ts +0 -15
  37. package/dist/node/index.d.ts.map +0 -1
  38. package/dist/node/index.js +0 -17
  39. package/dist/node/provider.d.ts +0 -162
  40. package/dist/node/provider.d.ts.map +0 -1
  41. package/dist/node/provider.js +0 -272
  42. package/dist/node/types.d.ts +0 -110
  43. package/dist/node/types.d.ts.map +0 -1
  44. package/dist/node/types.js +0 -4
@@ -1,45 +0,0 @@
1
- /**
2
- * config.ts — Embedded network configuration accessors
3
- */
4
- export interface TokenConfig {
5
- evmAddress: string;
6
- fastTokenId: string;
7
- decimals: number;
8
- }
9
- export interface ChainConfig {
10
- chainId: number;
11
- bridgeContract: string;
12
- fastBridgeAddress: string;
13
- relayerUrl: string;
14
- tokens: Record<string, TokenConfig>;
15
- }
16
- export interface NetworkConfig {
17
- crossSignUrl: string;
18
- chains: Record<string, ChainConfig>;
19
- }
20
- export interface AllNetworksConfig {
21
- testnet: NetworkConfig;
22
- mainnet: NetworkConfig;
23
- }
24
- /**
25
- * Load the networks configuration.
26
- * Caches a clone of the embedded default config after first load.
27
- */
28
- export declare function loadNetworksConfig(): AllNetworksConfig;
29
- /**
30
- * Get configuration for a specific network (testnet or mainnet).
31
- */
32
- export declare function getNetworkConfig(network?: 'testnet' | 'mainnet'): NetworkConfig;
33
- /**
34
- * Get configuration for a specific chain within a network.
35
- */
36
- export declare function getChainConfig(chain: string, network?: 'testnet' | 'mainnet'): ChainConfig | null;
37
- /**
38
- * Get token configuration for a chain.
39
- */
40
- export declare function getTokenConfig(chain: string, token: string, network?: 'testnet' | 'mainnet'): TokenConfig | null;
41
- /**
42
- * Clear the cached config (useful for testing).
43
- */
44
- export declare function clearConfigCache(): void;
45
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/node/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;CACxB;AAQD;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,iBAAiB,CAOtD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,SAAS,GAAG,SAAqB,GAAG,aAAa,CAG1F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,SAAS,GAAG,SAAqB,GACzC,WAAW,GAAG,IAAI,CAGpB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,SAAS,GAAG,SAAqB,GACzC,WAAW,GAAG,IAAI,CAIpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
@@ -1,48 +0,0 @@
1
- /**
2
- * config.ts — Embedded network configuration accessors
3
- */
4
- import { DEFAULT_NETWORKS_CONFIG } from '../default-config.js';
5
- // ---------------------------------------------------------------------------
6
- // Config Loading
7
- // ---------------------------------------------------------------------------
8
- let cachedConfig = null;
9
- /**
10
- * Load the networks configuration.
11
- * Caches a clone of the embedded default config after first load.
12
- */
13
- export function loadNetworksConfig() {
14
- if (cachedConfig) {
15
- return cachedConfig;
16
- }
17
- cachedConfig = structuredClone(DEFAULT_NETWORKS_CONFIG);
18
- return cachedConfig;
19
- }
20
- /**
21
- * Get configuration for a specific network (testnet or mainnet).
22
- */
23
- export function getNetworkConfig(network = 'testnet') {
24
- const config = loadNetworksConfig();
25
- return config[network];
26
- }
27
- /**
28
- * Get configuration for a specific chain within a network.
29
- */
30
- export function getChainConfig(chain, network = 'testnet') {
31
- const networkConfig = getNetworkConfig(network);
32
- return networkConfig.chains[chain] ?? null;
33
- }
34
- /**
35
- * Get token configuration for a chain.
36
- */
37
- export function getTokenConfig(chain, token, network = 'testnet') {
38
- const chainConfig = getChainConfig(chain, network);
39
- if (!chainConfig)
40
- return null;
41
- return chainConfig.tokens[token] ?? chainConfig.tokens[token.toUpperCase()] ?? null;
42
- }
43
- /**
44
- * Clear the cached config (useful for testing).
45
- */
46
- export function clearConfigCache() {
47
- cachedConfig = null;
48
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * eip7702.ts — EIP-7702 smartDeposit via AllSet Portal relay
3
- *
4
- * Flow:
5
- * 1. Poll ERC-20 balance until >= minAmount
6
- * 2. POST /userop/prepare → backend assembles UserOp + paymasterData
7
- * 3. Sign EIP-7702 authorization (re-delegate EOA to v0.8 impl)
8
- * 4. Sign UserOperation (EIP-712, v0.8)
9
- * 5. POST /userop/submit → backend calls Pimlico eth_sendUserOperation
10
- *
11
- * Private key never leaves the SDK.
12
- * Pimlico API key never touches the SDK.
13
- * Gas is paid in USDC via ERC-20 Paymaster.
14
- * Chain is inferred from rpcUrl (backend calls eth_chainId) — no hardcoded chain list.
15
- */
16
- import { type Address, type Hash, type Hex } from 'viem';
17
- export interface SmartDepositParams {
18
- /** EOA private key — stays local, never sent to backend */
19
- privateKey: Hex;
20
- /** EVM JSON-RPC URL — used for balance polling and forwarded to backend for chainId detection */
21
- rpcUrl: string;
22
- /** AllSet Portal backend base URL, e.g. https://api.allset.xyz */
23
- allsetApiUrl: string;
24
- /** ERC-20 token to watch (e.g. USDC on Base) */
25
- tokenAddress: Address;
26
- /** Minimum token balance (raw, with decimals) that triggers deposit */
27
- minAmount: bigint;
28
- /** AllSet bridge contract address */
29
- bridgeAddress: Address;
30
- /** Encoded bridge.deposit(...) calldata from encodeDepositCalldata() */
31
- depositCalldata: Hex;
32
- /** Balance poll interval in ms (default: 3000) */
33
- pollIntervalMs?: number;
34
- /** Total timeout in ms waiting for balance (default: no timeout) */
35
- timeoutMs?: number;
36
- /** Called on each balance check */
37
- onBalanceCheck?: (balance: bigint) => void;
38
- }
39
- export interface SmartDepositResult {
40
- txHash: Hash;
41
- userOpHash: Hash;
42
- userAddress: Address;
43
- /** Token balance at the time of deposit */
44
- tokenBalance: bigint;
45
- }
46
- export declare function smartDeposit(params: SmartDepositParams): Promise<SmartDepositResult>;
47
- //# sourceMappingURL=eip7702.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eip7702.d.ts","sourceRoot":"","sources":["../../src/node/eip7702.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAML,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,GAAG,EACT,MAAM,MAAM,CAAC;AAgBd,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,UAAU,EAAE,GAAG,CAAC;IAChB,iGAAiG;IACjG,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,YAAY,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,YAAY,EAAE,OAAO,CAAC;IACtB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,aAAa,EAAE,OAAO,CAAC;IACvB,wEAAwE;IACxE,eAAe,EAAE,GAAG,CAAC;IACrB,kDAAkD;IAClD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,IAAI,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;CACtB;AA2HD,wBAAsB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA8I1F"}
@@ -1,189 +0,0 @@
1
- /**
2
- * eip7702.ts — EIP-7702 smartDeposit via AllSet Portal relay
3
- *
4
- * Flow:
5
- * 1. Poll ERC-20 balance until >= minAmount
6
- * 2. POST /userop/prepare → backend assembles UserOp + paymasterData
7
- * 3. Sign EIP-7702 authorization (re-delegate EOA to v0.8 impl)
8
- * 4. Sign UserOperation (EIP-712, v0.8)
9
- * 5. POST /userop/submit → backend calls Pimlico eth_sendUserOperation
10
- *
11
- * Private key never leaves the SDK.
12
- * Pimlico API key never touches the SDK.
13
- * Gas is paid in USDC via ERC-20 Paymaster.
14
- * Chain is inferred from rpcUrl (backend calls eth_chainId) — no hardcoded chain list.
15
- */
16
- import { createPublicClient, encodePacked, http, keccak256, parseAbi, } from 'viem';
17
- import { privateKeyToAccount } from 'viem/accounts';
18
- import { getUserOperationTypedData } from 'viem/account-abstraction';
19
- const ENTRY_POINT_V08 = '0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108';
20
- const ERC20_BALANCEOF_ABI = parseAbi([
21
- 'function balanceOf(address account) view returns (uint256)',
22
- ]);
23
- function sleep(ms) {
24
- return new Promise((resolve) => setTimeout(resolve, ms));
25
- }
26
- // ─── Helpers ──────────────────────────────────────────────────────────────────
27
- /**
28
- * Convert the backend's hex-string UserOp to viem's bigint-typed UserOperation<'0.8'>.
29
- */
30
- function parseUserOp(raw) {
31
- return {
32
- sender: raw.sender,
33
- nonce: BigInt(raw.nonce),
34
- callData: raw.callData,
35
- callGasLimit: BigInt(raw.callGasLimit),
36
- verificationGasLimit: BigInt(raw.verificationGasLimit),
37
- preVerificationGas: BigInt(raw.preVerificationGas),
38
- maxFeePerGas: BigInt(raw.maxFeePerGas),
39
- maxPriorityFeePerGas: BigInt(raw.maxPriorityFeePerGas),
40
- ...(raw.paymaster && { paymaster: raw.paymaster }),
41
- ...(raw.paymasterVerificationGasLimit && {
42
- paymasterVerificationGasLimit: BigInt(raw.paymasterVerificationGasLimit),
43
- }),
44
- ...(raw.paymasterPostOpGasLimit && {
45
- paymasterPostOpGasLimit: BigInt(raw.paymasterPostOpGasLimit),
46
- }),
47
- ...(raw.paymasterData && { paymasterData: raw.paymasterData }),
48
- ...(raw.factory && { factory: raw.factory }),
49
- ...(raw.factoryData && { factoryData: raw.factoryData }),
50
- signature: '0x',
51
- };
52
- }
53
- /**
54
- * Convert UserOperation<'0.8'> bigint fields → hex strings for JSON serialization.
55
- * The Go backend expects all numeric fields as 0x-prefixed hex strings.
56
- */
57
- function serializeUserOp(op) {
58
- const toHex = (n) => `0x${n.toString(16)}`;
59
- return {
60
- sender: op.sender,
61
- nonce: toHex(op.nonce),
62
- callData: op.callData,
63
- callGasLimit: toHex(op.callGasLimit),
64
- verificationGasLimit: toHex(op.verificationGasLimit),
65
- preVerificationGas: toHex(op.preVerificationGas),
66
- maxFeePerGas: toHex(op.maxFeePerGas),
67
- maxPriorityFeePerGas: toHex(op.maxPriorityFeePerGas),
68
- ...(op.paymaster && { paymaster: op.paymaster }),
69
- ...(op.paymasterVerificationGasLimit !== undefined && {
70
- paymasterVerificationGasLimit: toHex(op.paymasterVerificationGasLimit),
71
- }),
72
- ...(op.paymasterPostOpGasLimit !== undefined && {
73
- paymasterPostOpGasLimit: toHex(op.paymasterPostOpGasLimit),
74
- }),
75
- ...(op.paymasterData && { paymasterData: op.paymasterData }),
76
- ...(op.factory && { factory: op.factory }),
77
- ...(op.factoryData && { factoryData: op.factoryData }),
78
- ...(op.signature && { signature: op.signature }),
79
- };
80
- }
81
- // ─── Main function ─────────────────────────────────────────────────────────────
82
- export async function smartDeposit(params) {
83
- const { privateKey, rpcUrl, allsetApiUrl, tokenAddress, minAmount, bridgeAddress, depositCalldata, pollIntervalMs = 3000, timeoutMs, onBalanceCheck, } = params;
84
- const eoa = privateKeyToAccount(privateKey);
85
- // No chain object needed — chainId is fetched dynamically from the RPC
86
- const publicClient = createPublicClient({ transport: http(rpcUrl) });
87
- // Step 1: Poll ERC-20 balance
88
- const startTime = Date.now();
89
- let tokenBalance = 0n;
90
- while (true) {
91
- if (timeoutMs && Date.now() - startTime > timeoutMs) {
92
- throw new Error('smartDeposit: timed out waiting for balance');
93
- }
94
- tokenBalance = (await publicClient.readContract({
95
- address: tokenAddress,
96
- abi: ERC20_BALANCEOF_ABI,
97
- functionName: 'balanceOf',
98
- args: [eoa.address],
99
- }));
100
- onBalanceCheck?.(tokenBalance);
101
- if (tokenBalance >= minAmount)
102
- break;
103
- await sleep(pollIntervalMs);
104
- }
105
- // Fetch chainId once — used for EIP-7702 auth and UserOp signing
106
- const chainId = await publicClient.getChainId();
107
- // Step 2: Build request auth signature (proves caller owns the private key)
108
- // Backend verifies: ecrecover(hash, authSig) == from
109
- const timestamp = Math.floor(Date.now() / 1000);
110
- const msgHash = keccak256(encodePacked(['address', 'address', 'uint256', 'address', 'bytes', 'uint256'], [eoa.address, tokenAddress, minAmount, bridgeAddress, depositCalldata, BigInt(timestamp)]));
111
- const authSig = await eoa.signMessage({ message: { raw: msgHash } });
112
- // Step 3: POST /userop/prepare
113
- const prepareReq = {
114
- rpcUrl,
115
- from: eoa.address,
116
- tokenAddress,
117
- amount: minAmount.toString(),
118
- bridgeAddress,
119
- depositCalldata,
120
- timestamp,
121
- authSig,
122
- };
123
- const prepareRes = await fetch(`${allsetApiUrl}/userop/prepare`, {
124
- method: 'POST',
125
- headers: { 'Content-Type': 'application/json' },
126
- body: JSON.stringify(prepareReq),
127
- });
128
- if (!prepareRes.ok) {
129
- const err = await prepareRes.text();
130
- throw new Error(`smartDeposit prepare failed (${prepareRes.status}): ${err}`);
131
- }
132
- const prepared = (await prepareRes.json());
133
- // Step 4: Sign EIP-7702 authorization.
134
- // We always re-sign to ensure the EOA is delegated to the correct v0.8 impl,
135
- // even if a prior (possibly outdated) delegation exists.
136
- let eip7702Auth;
137
- if (prepared.needsAuthorization) {
138
- const accountNonce = await publicClient.getTransactionCount({ address: eoa.address });
139
- const signed = await eoa.signAuthorization({
140
- address: prepared.delegate7702Address,
141
- chainId,
142
- nonce: accountNonce,
143
- });
144
- const yParity = signed.yParity ?? 0;
145
- eip7702Auth = {
146
- address: prepared.delegate7702Address,
147
- chainId: `0x${chainId.toString(16)}`,
148
- nonce: `0x${accountNonce.toString(16)}`,
149
- yParity: `0x${yParity.toString(16)}`,
150
- r: `0x${BigInt(signed.r).toString(16).padStart(64, '0')}`,
151
- s: `0x${BigInt(signed.s).toString(16).padStart(64, '0')}`,
152
- };
153
- }
154
- // Step 5: Parse backend response + sign UserOperation (v0.8 uses EIP-712 typed data)
155
- const userOpToSign = parseUserOp(prepared.unsignedUserOp);
156
- // v0.8 requires EIP-712 signTypedData, NOT signMessage/personal_sign
157
- const typedData = getUserOperationTypedData({
158
- chainId,
159
- entryPointAddress: ENTRY_POINT_V08,
160
- userOperation: { ...userOpToSign, signature: '0x' },
161
- });
162
- const signature = await eoa.signTypedData(typedData);
163
- const signedUserOp = { ...userOpToSign, signature };
164
- // Step 6: POST /userop/submit
165
- const serialized = serializeUserOp(signedUserOp);
166
- if (eip7702Auth) {
167
- serialized.eip7702Auth = eip7702Auth;
168
- }
169
- const submitReq = {
170
- rpcUrl,
171
- signedUserOp: serialized,
172
- };
173
- const submitRes = await fetch(`${allsetApiUrl}/userop/submit`, {
174
- method: 'POST',
175
- headers: { 'Content-Type': 'application/json' },
176
- body: JSON.stringify(submitReq),
177
- });
178
- if (!submitRes.ok) {
179
- const err = await submitRes.text();
180
- throw new Error(`smartDeposit submit failed (${submitRes.status}): ${err}`);
181
- }
182
- const { txHash, userOpHash: returnedUserOpHash } = (await submitRes.json());
183
- return {
184
- txHash,
185
- userOpHash: returnedUserOpHash,
186
- userAddress: eoa.address,
187
- tokenBalance,
188
- };
189
- }
@@ -1,130 +0,0 @@
1
- /**
2
- * evm-executor.ts — EVM client utilities using viem
3
- *
4
- * Provides createEvmExecutor() to create viem wallet and public clients,
5
- * and createEvmWallet() to generate or load EVM wallets.
6
- *
7
- * Wallet keyfiles are managed by the user at ~/.evm/keys/ or custom paths.
8
- * Expected format: { "privateKey": "...", "address": "..." (optional) }
9
- */
10
- import { type Account, type Chain, type PublicClient, type WalletClient } from 'viem';
11
- /**
12
- * Account-compatible wallet returned by createEvmWallet().
13
- *
14
- * Includes the normalized private key so generated accounts can be persisted
15
- * or reconstructed by the caller.
16
- */
17
- export type EvmAccount = Account & {
18
- privateKey: `0x${string}`;
19
- };
20
- /**
21
- * Get the default EVM keys directory (~/.evm/keys).
22
- */
23
- export declare function getEvmKeysDir(): string;
24
- /**
25
- * Create or load an EVM wallet and return an Account-compatible object.
26
- *
27
- * @param keyOrPath - Optional. Can be:
28
- * - Omitted: generates a new random wallet
29
- * - Private key (64 hex chars, with or without 0x): derives account from it
30
- * - File path (contains `/` or `~`, or ends with `.json`): loads from JSON keyfile
31
- *
32
- * The keyfile must be a JSON file containing:
33
- * - `privateKey` (required): hex string, with or without 0x prefix
34
- * - `address` (optional): for user reference only
35
- *
36
- * It is the user's responsibility to create and manage keyfiles.
37
- * Generated accounts expose `privateKey` so callers can persist them.
38
- *
39
- * @returns Account-compatible object with viem signing methods and `privateKey`
40
- *
41
- * @example
42
- * ```ts
43
- * // Generate new wallet
44
- * const account = createEvmWallet();
45
- * console.log(account.address); // 0x...
46
- * console.log(account.privateKey); // persist this if you generated the wallet
47
- *
48
- * // Derive from private key
49
- * const account = createEvmWallet('0x1234...64hexchars');
50
- *
51
- * // Load from keyfile
52
- * const account = createEvmWallet('~/.evm/keys/default.json');
53
- *
54
- * // Use with createEvmExecutor
55
- * const { walletClient, publicClient } = createEvmExecutor(account, rpcUrl, chainId);
56
- * ```
57
- *
58
- * @example Keyfile format
59
- * ```json
60
- * {
61
- * "privateKey": "abc123...64hexchars",
62
- * "address": "0x..." // optional, for reference
63
- * }
64
- * ```
65
- */
66
- export declare function createEvmWallet(keyOrPath?: string): EvmAccount;
67
- /** ERC20 ABI for allowance and approve */
68
- export declare const ERC20_ABI: readonly [{
69
- readonly name: "approve";
70
- readonly type: "function";
71
- readonly stateMutability: "nonpayable";
72
- readonly inputs: readonly [{
73
- readonly type: "address";
74
- readonly name: "spender";
75
- }, {
76
- readonly type: "uint256";
77
- readonly name: "amount";
78
- }];
79
- readonly outputs: readonly [{
80
- readonly type: "bool";
81
- }];
82
- }, {
83
- readonly name: "allowance";
84
- readonly type: "function";
85
- readonly stateMutability: "view";
86
- readonly inputs: readonly [{
87
- readonly type: "address";
88
- readonly name: "owner";
89
- }, {
90
- readonly type: "address";
91
- readonly name: "spender";
92
- }];
93
- readonly outputs: readonly [{
94
- readonly type: "uint256";
95
- }];
96
- }];
97
- /** Bundled supported chain mappings */
98
- export declare const CHAIN_MAP: Record<number, Chain>;
99
- /**
100
- * EVM clients returned by createEvmExecutor.
101
- */
102
- export interface EvmClients {
103
- walletClient: WalletClient;
104
- publicClient: PublicClient;
105
- }
106
- /**
107
- * Create viem wallet and public clients for EVM operations.
108
- *
109
- * @param account - viem Account from createEvmWallet() or privateKeyToAccount()
110
- * @param rpcUrl - RPC endpoint URL
111
- * @param chainId - Chain ID (11155111 for Sepolia, 421614 for Arbitrum Sepolia, 8453 for Base)
112
- * @returns Object with walletClient and publicClient
113
- *
114
- * @example
115
- * ```ts
116
- * // Using Account from createEvmWallet (loads from keyfile)
117
- * const account = createEvmWallet('~/.evm/keys/default.json');
118
- * const { walletClient, publicClient } = createEvmExecutor(account, 'https://sepolia-rollup.arbitrum.io/rpc', 421614);
119
- *
120
- * // Using viem's privateKeyToAccount directly
121
- * import { privateKeyToAccount } from 'viem/accounts';
122
- * const account = privateKeyToAccount('0xabc123...');
123
- * const { walletClient, publicClient } = createEvmExecutor(account, rpcUrl, chainId);
124
- *
125
- * // Use clients for bridge deposit
126
- * await allset.sendToFast({ ..., evmClients: { walletClient, publicClient } });
127
- * ```
128
- */
129
- export declare function createEvmExecutor(account: Account, rpcUrl: string, chainId: number): EvmClients;
130
- //# sourceMappingURL=evm-executor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"evm-executor.d.ts","sourceRoot":"","sources":["../../src/node/evm-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAKL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAId;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG;IACjC,UAAU,EAAE,KAAK,MAAM,EAAE,CAAC;CAC3B,CAAC;AASF;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,CAwB9D;AAED,0CAA0C;AAC1C,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGpB,CAAC;AAEH,uCAAuC;AACvC,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAM3C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,UAAU,CAoBZ"}
@@ -1,160 +0,0 @@
1
- /**
2
- * evm-executor.ts — EVM client utilities using viem
3
- *
4
- * Provides createEvmExecutor() to create viem wallet and public clients,
5
- * and createEvmWallet() to generate or load EVM wallets.
6
- *
7
- * Wallet keyfiles are managed by the user at ~/.evm/keys/ or custom paths.
8
- * Expected format: { "privateKey": "...", "address": "..." (optional) }
9
- */
10
- import { existsSync, readFileSync } from 'node:fs';
11
- import { join } from 'node:path';
12
- import { createPublicClient, createWalletClient, http, parseAbi, } from 'viem';
13
- import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
14
- import { arbitrum, arbitrumSepolia, base, mainnet as ethereum, sepolia } from 'viem/chains';
15
- // Default EVM keys directory
16
- const DEFAULT_EVM_KEYS_DIR = join(process.env.HOME || process.env.USERPROFILE || '', '.evm', 'keys');
17
- /**
18
- * Get the default EVM keys directory (~/.evm/keys).
19
- */
20
- export function getEvmKeysDir() {
21
- return DEFAULT_EVM_KEYS_DIR;
22
- }
23
- /**
24
- * Expand ~ to home directory
25
- */
26
- function expandPath(path) {
27
- if (path.startsWith('~/')) {
28
- const home = process.env.HOME || process.env.USERPROFILE || '';
29
- return path.replace('~', home);
30
- }
31
- return path;
32
- }
33
- /**
34
- * Detect if a string is a file path (vs a private key)
35
- */
36
- function isFilePath(input) {
37
- return input.includes('/') || input.startsWith('~') || input.endsWith('.json');
38
- }
39
- function normalizePrivateKey(privateKey) {
40
- return (privateKey.startsWith('0x') ? privateKey : `0x${privateKey}`);
41
- }
42
- /**
43
- * Create or load an EVM wallet and return an Account-compatible object.
44
- *
45
- * @param keyOrPath - Optional. Can be:
46
- * - Omitted: generates a new random wallet
47
- * - Private key (64 hex chars, with or without 0x): derives account from it
48
- * - File path (contains `/` or `~`, or ends with `.json`): loads from JSON keyfile
49
- *
50
- * The keyfile must be a JSON file containing:
51
- * - `privateKey` (required): hex string, with or without 0x prefix
52
- * - `address` (optional): for user reference only
53
- *
54
- * It is the user's responsibility to create and manage keyfiles.
55
- * Generated accounts expose `privateKey` so callers can persist them.
56
- *
57
- * @returns Account-compatible object with viem signing methods and `privateKey`
58
- *
59
- * @example
60
- * ```ts
61
- * // Generate new wallet
62
- * const account = createEvmWallet();
63
- * console.log(account.address); // 0x...
64
- * console.log(account.privateKey); // persist this if you generated the wallet
65
- *
66
- * // Derive from private key
67
- * const account = createEvmWallet('0x1234...64hexchars');
68
- *
69
- * // Load from keyfile
70
- * const account = createEvmWallet('~/.evm/keys/default.json');
71
- *
72
- * // Use with createEvmExecutor
73
- * const { walletClient, publicClient } = createEvmExecutor(account, rpcUrl, chainId);
74
- * ```
75
- *
76
- * @example Keyfile format
77
- * ```json
78
- * {
79
- * "privateKey": "abc123...64hexchars",
80
- * "address": "0x..." // optional, for reference
81
- * }
82
- * ```
83
- */
84
- export function createEvmWallet(keyOrPath) {
85
- let key;
86
- if (!keyOrPath) {
87
- // Generate new wallet
88
- key = generatePrivateKey();
89
- }
90
- else if (isFilePath(keyOrPath)) {
91
- // Load from file
92
- const fullPath = expandPath(keyOrPath);
93
- if (!existsSync(fullPath)) {
94
- throw new Error(`Wallet file not found: ${keyOrPath}`);
95
- }
96
- const content = readFileSync(fullPath, 'utf-8');
97
- const data = JSON.parse(content);
98
- if (!data.privateKey) {
99
- throw new Error(`Invalid wallet file: missing privateKey`);
100
- }
101
- key = normalizePrivateKey(data.privateKey);
102
- }
103
- else {
104
- // Treat as private key
105
- key = normalizePrivateKey(keyOrPath);
106
- }
107
- return Object.assign(privateKeyToAccount(key), { privateKey: key });
108
- }
109
- /** ERC20 ABI for allowance and approve */
110
- export const ERC20_ABI = parseAbi([
111
- 'function approve(address spender, uint256 amount) returns (bool)',
112
- 'function allowance(address owner, address spender) view returns (uint256)',
113
- ]);
114
- /** Bundled supported chain mappings */
115
- export const CHAIN_MAP = {
116
- 1: ethereum,
117
- 11155111: sepolia,
118
- 421614: arbitrumSepolia,
119
- 42161: arbitrum,
120
- 8453: base,
121
- };
122
- /**
123
- * Create viem wallet and public clients for EVM operations.
124
- *
125
- * @param account - viem Account from createEvmWallet() or privateKeyToAccount()
126
- * @param rpcUrl - RPC endpoint URL
127
- * @param chainId - Chain ID (11155111 for Sepolia, 421614 for Arbitrum Sepolia, 8453 for Base)
128
- * @returns Object with walletClient and publicClient
129
- *
130
- * @example
131
- * ```ts
132
- * // Using Account from createEvmWallet (loads from keyfile)
133
- * const account = createEvmWallet('~/.evm/keys/default.json');
134
- * const { walletClient, publicClient } = createEvmExecutor(account, 'https://sepolia-rollup.arbitrum.io/rpc', 421614);
135
- *
136
- * // Using viem's privateKeyToAccount directly
137
- * import { privateKeyToAccount } from 'viem/accounts';
138
- * const account = privateKeyToAccount('0xabc123...');
139
- * const { walletClient, publicClient } = createEvmExecutor(account, rpcUrl, chainId);
140
- *
141
- * // Use clients for bridge deposit
142
- * await allset.sendToFast({ ..., evmClients: { walletClient, publicClient } });
143
- * ```
144
- */
145
- export function createEvmExecutor(account, rpcUrl, chainId) {
146
- const chain = CHAIN_MAP[chainId];
147
- if (!chain) {
148
- throw new Error(`Unsupported EVM chain ID: ${chainId}. Supported: ${Object.keys(CHAIN_MAP).join(', ')}`);
149
- }
150
- const walletClient = createWalletClient({
151
- account,
152
- chain,
153
- transport: http(rpcUrl),
154
- });
155
- const publicClient = createPublicClient({
156
- chain,
157
- transport: http(rpcUrl),
158
- });
159
- return { walletClient, publicClient };
160
- }
@@ -1,15 +0,0 @@
1
- export * from '../core/index.js';
2
- export * from './eip7702.js';
3
- export { AllSetProvider, getAllSetDir, getEvmKeysDir as getAllSetEvmKeysDir, ensureAllSetDirs, initUserConfig, } from './provider.js';
4
- export { createEvmExecutor, createEvmWallet, getEvmKeysDir, } from './evm-executor.js';
5
- export { loadNetworksConfig, getNetworkConfig, getChainConfig, getTokenConfig, clearConfigCache, } from './config.js';
6
- export type { BridgeProvider, BridgeParams, BridgeResult, FastWalletLike, AllSetChainConfig, AllSetTokenInfo, SendToFastParams, SendToExternalParams, ExecuteIntentParams, } from './types.js';
7
- export type { Intent } from '../intents.js';
8
- export type { EvmSignResult } from './bridge.js';
9
- export type { EvmAccount, EvmClients } from './evm-executor.js';
10
- export type { NetworkConfig, ChainConfig, TokenConfig, AllNetworksConfig } from './config.js';
11
- export type { AllSetProviderOptions } from './provider.js';
12
- export declare function evmSign(...args: Parameters<typeof import('./bridge.js').evmSign>): ReturnType<typeof import('./bridge.js').evmSign>;
13
- export declare function executeBridge(...args: Parameters<typeof import('./bridge.js').executeBridge>): ReturnType<typeof import('./bridge.js').executeBridge>;
14
- export declare function executeIntent(...args: Parameters<typeof import('./bridge.js').executeIntent>): ReturnType<typeof import('./bridge.js').executeIntent>;
15
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAE7B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,aAAa,IAAI,mBAAmB,EACpC,gBAAgB,EAChB,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9F,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,wBAAsB,OAAO,CAC3B,GAAG,IAAI,EAAE,UAAU,CAAC,cAAc,aAAa,EAAE,OAAO,CAAC,GACxD,UAAU,CAAC,cAAc,aAAa,EAAE,OAAO,CAAC,CAGlD;AAED,wBAAsB,aAAa,CACjC,GAAG,IAAI,EAAE,UAAU,CAAC,cAAc,aAAa,EAAE,aAAa,CAAC,GAC9D,UAAU,CAAC,cAAc,aAAa,EAAE,aAAa,CAAC,CAGxD;AAED,wBAAsB,aAAa,CACjC,GAAG,IAAI,EAAE,UAAU,CAAC,cAAc,aAAa,EAAE,aAAa,CAAC,GAC9D,UAAU,CAAC,cAAc,aAAa,EAAE,aAAa,CAAC,CAGxD"}
@@ -1,17 +0,0 @@
1
- export * from '../core/index.js';
2
- export * from './eip7702.js';
3
- export { AllSetProvider, getAllSetDir, getEvmKeysDir as getAllSetEvmKeysDir, ensureAllSetDirs, initUserConfig, } from './provider.js';
4
- export { createEvmExecutor, createEvmWallet, getEvmKeysDir, } from './evm-executor.js';
5
- export { loadNetworksConfig, getNetworkConfig, getChainConfig, getTokenConfig, clearConfigCache, } from './config.js';
6
- export async function evmSign(...args) {
7
- const mod = await import('./bridge.js');
8
- return mod.evmSign(...args);
9
- }
10
- export async function executeBridge(...args) {
11
- const mod = await import('./bridge.js');
12
- return mod.executeBridge(...args);
13
- }
14
- export async function executeIntent(...args) {
15
- const mod = await import('./bridge.js');
16
- return mod.executeIntent(...args);
17
- }