@coinfello/agent-cli 0.1.11 → 0.1.12
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/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { Command } from "commander";
|
|
|
3
3
|
import { toMetaMaskSmartAccount, Implementation, createDelegation } from "@metamask/smart-accounts-kit";
|
|
4
4
|
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
|
|
5
5
|
import { toWebAuthnAccount } from "viem/account-abstraction";
|
|
6
|
-
import { createPublicClient, http, serializeErc6492Signature } from "viem";
|
|
7
6
|
import * as chains from "viem/chains";
|
|
8
7
|
import { createHash, randomBytes } from "node:crypto";
|
|
9
8
|
import { execFile } from "node:child_process";
|
|
@@ -12,6 +11,7 @@ import { dirname, join } from "node:path";
|
|
|
12
11
|
import { fileURLToPath } from "node:url";
|
|
13
12
|
import { platform, homedir } from "node:os";
|
|
14
13
|
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
|
14
|
+
import { http, createPublicClient as createPublicClient$1, serializeErc6492Signature } from "viem";
|
|
15
15
|
import { createSiweMessage } from "viem/siwe";
|
|
16
16
|
const execFileAsync = promisify(execFile);
|
|
17
17
|
const __filename$1 = fileURLToPath(import.meta.url);
|
|
@@ -115,6 +115,30 @@ function toArrayBuffer(buf) {
|
|
|
115
115
|
view.set(new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength));
|
|
116
116
|
return ab;
|
|
117
117
|
}
|
|
118
|
+
const INFURA_API_KEY = process.env.INFURA_API_KEY ?? "b6bf7d3508c941499b10025c0776eaf8";
|
|
119
|
+
const INFURA_CHAIN_NAMES = {
|
|
120
|
+
1: "mainnet",
|
|
121
|
+
11155111: "sepolia",
|
|
122
|
+
137: "polygon-mainnet",
|
|
123
|
+
80002: "polygon-amoy",
|
|
124
|
+
42161: "arbitrum-mainnet",
|
|
125
|
+
421614: "arbitrum-sepolia",
|
|
126
|
+
10: "optimism-mainnet",
|
|
127
|
+
11155420: "optimism-sepolia",
|
|
128
|
+
8453: "base-mainnet",
|
|
129
|
+
84532: "base-sepolia",
|
|
130
|
+
59144: "linea-mainnet",
|
|
131
|
+
59141: "linea-sepolia",
|
|
132
|
+
43114: "avalanche-mainnet",
|
|
133
|
+
43113: "avalanche-fuji",
|
|
134
|
+
56: "bsc-mainnet",
|
|
135
|
+
97: "bsc-testnet"
|
|
136
|
+
};
|
|
137
|
+
function createPublicClient(chain) {
|
|
138
|
+
const infuraName = INFURA_CHAIN_NAMES[chain.id];
|
|
139
|
+
const transport = infuraName ? http(`https://${infuraName}.infura.io/v3/${INFURA_API_KEY}`) : http();
|
|
140
|
+
return createPublicClient$1({ chain, transport });
|
|
141
|
+
}
|
|
118
142
|
function resolveChain(chainName) {
|
|
119
143
|
const chain = chains[chainName];
|
|
120
144
|
if (!chain) {
|
|
@@ -141,10 +165,7 @@ function resolveChainInput(chainInput) {
|
|
|
141
165
|
}
|
|
142
166
|
async function createSmartAccount(privateKey, chainInput) {
|
|
143
167
|
const chain = resolveChainInput(chainInput);
|
|
144
|
-
const publicClient = createPublicClient(
|
|
145
|
-
chain,
|
|
146
|
-
transport: http()
|
|
147
|
-
});
|
|
168
|
+
const publicClient = createPublicClient(chain);
|
|
148
169
|
const owner = privateKeyToAccount(privateKey);
|
|
149
170
|
const smartAccount = await toMetaMaskSmartAccount({
|
|
150
171
|
client: publicClient,
|
|
@@ -177,7 +198,7 @@ function createSubdelegation({
|
|
|
177
198
|
}
|
|
178
199
|
async function createSmartAccountWithSecureEnclave(chainInput) {
|
|
179
200
|
const chain = resolveChainInput(chainInput);
|
|
180
|
-
const publicClient = createPublicClient(
|
|
201
|
+
const publicClient = createPublicClient(chain);
|
|
181
202
|
const keyPair = await generateKey();
|
|
182
203
|
const keyId = `0x${randomBytes(32).toString("hex")}`;
|
|
183
204
|
const xHex = keyPair.x.toString(16).padStart(64, "0");
|
|
@@ -217,7 +238,7 @@ async function createSmartAccountWithSecureEnclave(chainInput) {
|
|
|
217
238
|
}
|
|
218
239
|
async function getSmartAccountFromSecureEnclave(keyTag, publicKeyX, publicKeyY, keyId, chainInput) {
|
|
219
240
|
const chain = resolveChainInput(chainInput);
|
|
220
|
-
const publicClient = createPublicClient(
|
|
241
|
+
const publicClient = createPublicClient(chain);
|
|
221
242
|
const xBigInt = BigInt(publicKeyX);
|
|
222
243
|
const yBigInt = BigInt(publicKeyY);
|
|
223
244
|
const xHex = xBigInt.toString(16).padStart(64, "0");
|
|
@@ -3050,18 +3071,17 @@ program.command("create_account").description("Create a MetaMask smart account a
|
|
|
3050
3071
|
if (useHardwareKey) {
|
|
3051
3072
|
console.log(`Creating Secure Enclave-backed smart account on ${chain}...`);
|
|
3052
3073
|
const { address, keyTag, publicKeyX, publicKeyY, keyId } = await createSmartAccountWithSecureEnclave(chain);
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
config2.secure_enclave = {
|
|
3074
|
+
config.signer_type = "secureEnclave";
|
|
3075
|
+
config.smart_account_address = address;
|
|
3076
|
+
config.chain = chain;
|
|
3077
|
+
config.secure_enclave = {
|
|
3058
3078
|
key_tag: keyTag,
|
|
3059
3079
|
public_key_x: publicKeyX,
|
|
3060
3080
|
public_key_y: publicKeyY,
|
|
3061
3081
|
key_id: keyId
|
|
3062
3082
|
};
|
|
3063
|
-
delete
|
|
3064
|
-
await saveConfig(
|
|
3083
|
+
delete config.private_key;
|
|
3084
|
+
await saveConfig(config);
|
|
3065
3085
|
console.log("Secure Enclave smart account created successfully.");
|
|
3066
3086
|
console.log(`Address: ${address}`);
|
|
3067
3087
|
console.log(`Key tag: ${keyTag}`);
|
|
@@ -3075,12 +3095,11 @@ program.command("create_account").description("Create a MetaMask smart account a
|
|
|
3075
3095
|
console.log(`Creating smart account on ${chain}...`);
|
|
3076
3096
|
const privateKey = generatePrivateKey();
|
|
3077
3097
|
const { address } = await createSmartAccount(privateKey, chain);
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
await saveConfig(config2);
|
|
3098
|
+
config.private_key = privateKey;
|
|
3099
|
+
config.signer_type = "privateKey";
|
|
3100
|
+
config.smart_account_address = address;
|
|
3101
|
+
config.chain = chain;
|
|
3102
|
+
await saveConfig(config);
|
|
3084
3103
|
console.log("Smart account created successfully.");
|
|
3085
3104
|
console.log(`Address: ${address}`);
|
|
3086
3105
|
console.log(`Config saved to: ${CONFIG_PATH}`);
|
|
@@ -3207,10 +3226,7 @@ program.command("send_prompt").description("Send a prompt to CoinFello, creating
|
|
|
3207
3226
|
});
|
|
3208
3227
|
let sig = signature;
|
|
3209
3228
|
const chain = resolveChainInput(config.chain);
|
|
3210
|
-
const publicClient = createPublicClient(
|
|
3211
|
-
chain,
|
|
3212
|
-
transport: http()
|
|
3213
|
-
});
|
|
3229
|
+
const publicClient = createPublicClient(chain);
|
|
3214
3230
|
const code = await publicClient.getCode({ address: smartAccount.address });
|
|
3215
3231
|
const isDeployed = !!(code && code !== "0x");
|
|
3216
3232
|
if (!isDeployed) {
|
|
Binary file
|