arc402-cli 0.5.0 → 1.0.0-rc.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/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +6 -0
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/wallet.d.ts.map +1 -1
- package/dist/commands/wallet.js +323 -20
- package/dist/commands/wallet.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/repl.d.ts.map +1 -1
- package/dist/repl.js +447 -148
- package/dist/repl.js.map +1 -1
- package/dist/ui/banner.d.ts +2 -0
- package/dist/ui/banner.d.ts.map +1 -1
- package/dist/ui/banner.js +27 -18
- package/dist/ui/banner.js.map +1 -1
- package/dist/ui/spinner.d.ts.map +1 -1
- package/dist/ui/spinner.js +11 -0
- package/dist/ui/spinner.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/config.ts +6 -0
- package/src/commands/wallet.ts +372 -32
- package/src/config.ts +1 -0
- package/src/index.ts +15 -1
- package/src/repl.ts +531 -179
- package/src/ui/banner.ts +26 -19
- package/src/ui/spinner.ts +10 -0
package/src/commands/wallet.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { spawnSync } from "child_process";
|
|
|
9
9
|
import { Arc402Config, getConfigPath, getUsdcAddress, loadConfig, NETWORK_DEFAULTS, saveConfig } from "../config";
|
|
10
10
|
import { getClient, requireSigner } from "../client";
|
|
11
11
|
import { getTrustTier } from "../utils/format";
|
|
12
|
-
import { ARC402_WALLET_EXECUTE_ABI, ARC402_WALLET_GUARDIAN_ABI, ARC402_WALLET_MACHINE_KEY_ABI, ARC402_WALLET_OWNER_ABI, ARC402_WALLET_PASSKEY_ABI, ARC402_WALLET_PROTOCOL_ABI, ARC402_WALLET_REGISTRY_ABI, POLICY_ENGINE_GOVERNANCE_ABI, POLICY_ENGINE_LIMITS_ABI, TRUST_REGISTRY_ABI, WALLET_FACTORY_ABI } from "../abis";
|
|
12
|
+
import { AGENT_REGISTRY_ABI, ARC402_WALLET_EXECUTE_ABI, ARC402_WALLET_GUARDIAN_ABI, ARC402_WALLET_MACHINE_KEY_ABI, ARC402_WALLET_OWNER_ABI, ARC402_WALLET_PASSKEY_ABI, ARC402_WALLET_PROTOCOL_ABI, ARC402_WALLET_REGISTRY_ABI, POLICY_ENGINE_GOVERNANCE_ABI, POLICY_ENGINE_LIMITS_ABI, TRUST_REGISTRY_ABI, WALLET_FACTORY_ABI } from "../abis";
|
|
13
13
|
import { warnIfPublicRpc } from "../config";
|
|
14
14
|
import { connectPhoneWallet, sendTransactionWithSession, requestPhoneWalletSignature } from "../walletconnect";
|
|
15
15
|
import { BundlerClient, buildSponsoredUserOp, PaymasterClient, DEFAULT_ENTRY_POINT } from "../bundler";
|
|
@@ -123,6 +123,336 @@ async function runWalletOnboardingCeremony(
|
|
|
123
123
|
console.log(" " + c.dim("arc402 wallet policy set-daily-limit --category general --amount <eth> — daily per-category cap"));
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Complete ARC-402 onboarding ceremony — matches web flow at app.arc402.xyz/onboard.
|
|
128
|
+
* Runs in a single WalletConnect session (or any sendTx provider). Idempotent.
|
|
129
|
+
*
|
|
130
|
+
* Steps:
|
|
131
|
+
* 2. Machine key — generate + authorizeMachineKey
|
|
132
|
+
* 3. Passkey — CLI shows browser URL (WebAuthn requires browser)
|
|
133
|
+
* 4. Policy — v5 protocol bypass; set hire limit + optional guardian
|
|
134
|
+
* 5. Agent — register on AgentRegistry via executeContractCall
|
|
135
|
+
* 6. Summary — branded tree
|
|
136
|
+
*/
|
|
137
|
+
async function runCompleteOnboardingCeremony(
|
|
138
|
+
walletAddress: string,
|
|
139
|
+
ownerAddress: string,
|
|
140
|
+
config: Arc402Config,
|
|
141
|
+
provider: ethers.JsonRpcProvider,
|
|
142
|
+
sendTx: (call: { to: string; data: string; value: string }, description: string) => Promise<string>,
|
|
143
|
+
): Promise<void> {
|
|
144
|
+
const policyAddress = config.policyEngineAddress ?? POLICY_ENGINE_DEFAULT;
|
|
145
|
+
const agentRegistryAddress =
|
|
146
|
+
config.agentRegistryV2Address ??
|
|
147
|
+
NETWORK_DEFAULTS[config.network]?.agentRegistryV2Address;
|
|
148
|
+
const handshakeAddress =
|
|
149
|
+
config.handshakeAddress ??
|
|
150
|
+
NETWORK_DEFAULTS[config.network]?.handshakeAddress ??
|
|
151
|
+
"0x4F5A38Bb746d7E5d49d8fd26CA6beD141Ec2DDb3";
|
|
152
|
+
|
|
153
|
+
// ── Step 2: Machine Key ────────────────────────────────────────────────────
|
|
154
|
+
console.log("\n" + c.dim("── Step 2: Machine Key ────────────────────────────────────────"));
|
|
155
|
+
|
|
156
|
+
let machineKeyAddress: string;
|
|
157
|
+
if (config.privateKey) {
|
|
158
|
+
machineKeyAddress = new ethers.Wallet(config.privateKey).address;
|
|
159
|
+
} else {
|
|
160
|
+
const mk = ethers.Wallet.createRandom();
|
|
161
|
+
machineKeyAddress = mk.address;
|
|
162
|
+
config.privateKey = mk.privateKey;
|
|
163
|
+
saveConfig(config);
|
|
164
|
+
console.log(" " + c.dim("Machine key generated: ") + c.white(machineKeyAddress));
|
|
165
|
+
console.log(" " + c.dim("Private key saved to ~/.arc402/config.json (chmod 600)"));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let mkAlreadyAuthorized = false;
|
|
169
|
+
try {
|
|
170
|
+
const mkContract = new ethers.Contract(walletAddress, ARC402_WALLET_MACHINE_KEY_ABI, provider);
|
|
171
|
+
mkAlreadyAuthorized = await mkContract.authorizedMachineKeys(machineKeyAddress) as boolean;
|
|
172
|
+
} catch { /* older wallet — will try to authorize */ }
|
|
173
|
+
|
|
174
|
+
if (mkAlreadyAuthorized) {
|
|
175
|
+
console.log(" " + c.success + c.dim(" Machine key already authorized: ") + c.white(machineKeyAddress));
|
|
176
|
+
} else {
|
|
177
|
+
console.log(" " + c.dim("Authorizing machine key: ") + c.white(machineKeyAddress));
|
|
178
|
+
const mkIface = new ethers.Interface(ARC402_WALLET_MACHINE_KEY_ABI);
|
|
179
|
+
await sendTx(
|
|
180
|
+
{ to: walletAddress, data: mkIface.encodeFunctionData("authorizeMachineKey", [machineKeyAddress]), value: "0x0" },
|
|
181
|
+
"authorizeMachineKey",
|
|
182
|
+
);
|
|
183
|
+
console.log(" " + c.success + " Machine key authorized");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ── Step 3: Passkey ───────────────────────────────────────────────────────
|
|
187
|
+
console.log("\n" + c.dim("── Step 3: Passkey (Face ID / WebAuthn) ──────────────────────"));
|
|
188
|
+
|
|
189
|
+
let passkeyActive = false;
|
|
190
|
+
try {
|
|
191
|
+
const walletC = new ethers.Contract(walletAddress, ARC402_WALLET_PASSKEY_ABI, provider);
|
|
192
|
+
const auth = await walletC.ownerAuth() as [bigint, string, string];
|
|
193
|
+
passkeyActive = Number(auth[0]) === 1;
|
|
194
|
+
} catch { /* ignore */ }
|
|
195
|
+
|
|
196
|
+
if (passkeyActive) {
|
|
197
|
+
console.log(" " + c.success + c.dim(" Passkey already active"));
|
|
198
|
+
} else {
|
|
199
|
+
const passkeyUrl = `https://app.arc402.xyz/passkey-setup?wallet=${walletAddress}`;
|
|
200
|
+
console.log("\n " + c.white("Open this URL in your browser to set up Face ID:"));
|
|
201
|
+
console.log(" " + c.cyan(passkeyUrl));
|
|
202
|
+
console.log(" " + c.dim("Complete Face ID registration, then press Enter. Type 'n' + Enter to skip.\n"));
|
|
203
|
+
const passkeyAns = await prompts({
|
|
204
|
+
type: "text",
|
|
205
|
+
name: "done",
|
|
206
|
+
message: "Press Enter when done (or type 'n' to skip)",
|
|
207
|
+
initial: "",
|
|
208
|
+
});
|
|
209
|
+
if ((passkeyAns.done as string | undefined)?.toLowerCase() === "n") {
|
|
210
|
+
console.log(" " + c.warning + " Passkey skipped");
|
|
211
|
+
} else {
|
|
212
|
+
passkeyActive = true;
|
|
213
|
+
console.log(" " + c.success + " Passkey set (via browser)");
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// ── Step 4: Policy ────────────────────────────────────────────────────────
|
|
218
|
+
console.log("\n" + c.dim("── Step 4: Policy ─────────────────────────────────────────────"));
|
|
219
|
+
|
|
220
|
+
// 4a) setVelocityLimit
|
|
221
|
+
let velocityLimitEth = "0.05";
|
|
222
|
+
let velocityAlreadySet = false;
|
|
223
|
+
try {
|
|
224
|
+
const ownerC = new ethers.Contract(walletAddress, ARC402_WALLET_OWNER_ABI, provider);
|
|
225
|
+
const existing = await ownerC.velocityLimit() as bigint;
|
|
226
|
+
if (existing > 0n) {
|
|
227
|
+
velocityAlreadySet = true;
|
|
228
|
+
velocityLimitEth = ethers.formatEther(existing);
|
|
229
|
+
console.log(" " + c.success + c.dim(` Velocity limit already set: ${velocityLimitEth} ETH`));
|
|
230
|
+
}
|
|
231
|
+
} catch { /* ignore */ }
|
|
232
|
+
|
|
233
|
+
if (!velocityAlreadySet) {
|
|
234
|
+
const velAns = await prompts({
|
|
235
|
+
type: "text",
|
|
236
|
+
name: "limit",
|
|
237
|
+
message: "Velocity limit (ETH / rolling window)?",
|
|
238
|
+
initial: "0.05",
|
|
239
|
+
});
|
|
240
|
+
velocityLimitEth = (velAns.limit as string | undefined) || "0.05";
|
|
241
|
+
const velIface = new ethers.Interface(["function setVelocityLimit(uint256 limit) external"]);
|
|
242
|
+
await sendTx(
|
|
243
|
+
{ to: walletAddress, data: velIface.encodeFunctionData("setVelocityLimit", [ethers.parseEther(velocityLimitEth)]), value: "0x0" },
|
|
244
|
+
`setVelocityLimit: ${velocityLimitEth} ETH`,
|
|
245
|
+
);
|
|
246
|
+
saveConfig(config);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 4b) setGuardian (optional — address, 'g' to generate, or skip)
|
|
250
|
+
let guardianAddress: string | null = null;
|
|
251
|
+
try {
|
|
252
|
+
const guardianC = new ethers.Contract(walletAddress, ARC402_WALLET_GUARDIAN_ABI, provider);
|
|
253
|
+
const existing = await guardianC.guardian() as string;
|
|
254
|
+
if (existing && existing !== ethers.ZeroAddress) {
|
|
255
|
+
guardianAddress = existing;
|
|
256
|
+
console.log(" " + c.success + c.dim(` Guardian already set: ${existing}`));
|
|
257
|
+
}
|
|
258
|
+
} catch { /* ignore */ }
|
|
259
|
+
|
|
260
|
+
if (!guardianAddress) {
|
|
261
|
+
const guardianAns = await prompts({
|
|
262
|
+
type: "text",
|
|
263
|
+
name: "guardian",
|
|
264
|
+
message: "Guardian address? (address, 'g' to generate, Enter to skip)",
|
|
265
|
+
initial: "",
|
|
266
|
+
});
|
|
267
|
+
const guardianInput = (guardianAns.guardian as string | undefined)?.trim() ?? "";
|
|
268
|
+
if (guardianInput.toLowerCase() === "g") {
|
|
269
|
+
const generatedGuardian = ethers.Wallet.createRandom();
|
|
270
|
+
config.guardianPrivateKey = generatedGuardian.privateKey;
|
|
271
|
+
config.guardianAddress = generatedGuardian.address;
|
|
272
|
+
saveConfig(config);
|
|
273
|
+
guardianAddress = generatedGuardian.address;
|
|
274
|
+
console.log("\n " + c.warning + " IMPORTANT: Save this guardian private key (emergency freeze key):");
|
|
275
|
+
console.log(" " + c.dim(generatedGuardian.privateKey));
|
|
276
|
+
console.log(" " + c.dim("Address: ") + c.white(generatedGuardian.address) + "\n");
|
|
277
|
+
const guardianIface = new ethers.Interface(["function setGuardian(address _guardian) external"]);
|
|
278
|
+
await sendTx(
|
|
279
|
+
{ to: walletAddress, data: guardianIface.encodeFunctionData("setGuardian", [guardianAddress]), value: "0x0" },
|
|
280
|
+
"setGuardian",
|
|
281
|
+
);
|
|
282
|
+
saveConfig(config);
|
|
283
|
+
} else if (guardianInput && ethers.isAddress(guardianInput)) {
|
|
284
|
+
guardianAddress = guardianInput;
|
|
285
|
+
config.guardianAddress = guardianInput;
|
|
286
|
+
const guardianIface = new ethers.Interface(["function setGuardian(address _guardian) external"]);
|
|
287
|
+
await sendTx(
|
|
288
|
+
{ to: walletAddress, data: guardianIface.encodeFunctionData("setGuardian", [guardianAddress]), value: "0x0" },
|
|
289
|
+
"setGuardian",
|
|
290
|
+
);
|
|
291
|
+
saveConfig(config);
|
|
292
|
+
} else if (guardianInput) {
|
|
293
|
+
console.log(" " + c.warning + " Invalid address — guardian skipped");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// 4c) setCategoryLimitFor('hire')
|
|
298
|
+
let hireLimit = "0.1";
|
|
299
|
+
let hireLimitAlreadySet = false;
|
|
300
|
+
try {
|
|
301
|
+
const limitsContract = new ethers.Contract(policyAddress, POLICY_ENGINE_LIMITS_ABI, provider);
|
|
302
|
+
const existing = await limitsContract.categoryLimits(walletAddress, "hire") as bigint;
|
|
303
|
+
if (existing > 0n) {
|
|
304
|
+
hireLimitAlreadySet = true;
|
|
305
|
+
hireLimit = ethers.formatEther(existing);
|
|
306
|
+
console.log(" " + c.success + c.dim(` Hire limit already set: ${hireLimit} ETH`));
|
|
307
|
+
}
|
|
308
|
+
} catch { /* ignore */ }
|
|
309
|
+
|
|
310
|
+
if (!hireLimitAlreadySet) {
|
|
311
|
+
const limitAns = await prompts({
|
|
312
|
+
type: "text",
|
|
313
|
+
name: "limit",
|
|
314
|
+
message: "Max price per hire (ETH)?",
|
|
315
|
+
initial: "0.1",
|
|
316
|
+
});
|
|
317
|
+
hireLimit = (limitAns.limit as string | undefined) || "0.1";
|
|
318
|
+
const hireLimitWei = ethers.parseEther(hireLimit);
|
|
319
|
+
const policyIface = new ethers.Interface([
|
|
320
|
+
"function setCategoryLimitFor(address wallet, string category, uint256 limitPerTx) external",
|
|
321
|
+
]);
|
|
322
|
+
await sendTx(
|
|
323
|
+
{ to: policyAddress, data: policyIface.encodeFunctionData("setCategoryLimitFor", [walletAddress, "hire", hireLimitWei]), value: "0x0" },
|
|
324
|
+
`setCategoryLimitFor: hire → ${hireLimit} ETH`,
|
|
325
|
+
);
|
|
326
|
+
saveConfig(config);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 4d) enableContractInteraction(wallet, Handshake)
|
|
330
|
+
const contractInteractionIface = new ethers.Interface([
|
|
331
|
+
"function enableContractInteraction(address wallet, address target) external",
|
|
332
|
+
]);
|
|
333
|
+
await sendTx(
|
|
334
|
+
{ to: policyAddress, data: contractInteractionIface.encodeFunctionData("enableContractInteraction", [walletAddress, handshakeAddress]), value: "0x0" },
|
|
335
|
+
"enableContractInteraction: Handshake",
|
|
336
|
+
);
|
|
337
|
+
saveConfig(config);
|
|
338
|
+
|
|
339
|
+
console.log(" " + c.success + " Policy configured");
|
|
340
|
+
|
|
341
|
+
// ── Step 5: Agent Registration ─────────────────────────────────────────────
|
|
342
|
+
console.log("\n" + c.dim("── Step 5: Agent Registration ─────────────────────────────────"));
|
|
343
|
+
|
|
344
|
+
let agentAlreadyRegistered = false;
|
|
345
|
+
let agentName = "";
|
|
346
|
+
let agentServiceType = "";
|
|
347
|
+
let agentEndpoint = "";
|
|
348
|
+
|
|
349
|
+
if (agentRegistryAddress) {
|
|
350
|
+
try {
|
|
351
|
+
const regContract = new ethers.Contract(agentRegistryAddress, AGENT_REGISTRY_ABI, provider);
|
|
352
|
+
agentAlreadyRegistered = await regContract.isRegistered(walletAddress) as boolean;
|
|
353
|
+
if (agentAlreadyRegistered) {
|
|
354
|
+
const info = await regContract.getAgent(walletAddress) as { name: string; serviceType: string; endpoint: string };
|
|
355
|
+
agentName = info.name;
|
|
356
|
+
agentServiceType = info.serviceType;
|
|
357
|
+
agentEndpoint = info.endpoint;
|
|
358
|
+
console.log(" " + c.success + c.dim(` Agent already registered: ${agentName}`));
|
|
359
|
+
}
|
|
360
|
+
} catch { /* ignore */ }
|
|
361
|
+
|
|
362
|
+
if (!agentAlreadyRegistered) {
|
|
363
|
+
const rawHostname = os.hostname();
|
|
364
|
+
const cleanHostname = rawHostname.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
365
|
+
const answers = await prompts([
|
|
366
|
+
{ type: "text", name: "name", message: "Agent name?", initial: cleanHostname },
|
|
367
|
+
{ type: "text", name: "serviceType", message: "Service type?", initial: "intelligence" },
|
|
368
|
+
{ type: "text", name: "caps", message: "Capabilities? (comma-separated)", initial: "research" },
|
|
369
|
+
{ type: "text", name: "endpoint", message: "Endpoint?", initial: `https://${cleanHostname}.arc402.xyz` },
|
|
370
|
+
]);
|
|
371
|
+
|
|
372
|
+
agentName = (answers.name as string | undefined) || cleanHostname;
|
|
373
|
+
agentServiceType = (answers.serviceType as string | undefined) || "intelligence";
|
|
374
|
+
agentEndpoint = (answers.endpoint as string | undefined) || `https://${cleanHostname}.arc402.xyz`;
|
|
375
|
+
const capabilities: string[] = ((answers.caps as string | undefined) || "research")
|
|
376
|
+
.split(",").map((s) => s.trim()).filter(Boolean);
|
|
377
|
+
|
|
378
|
+
// 5a) enableDefiAccess (check first)
|
|
379
|
+
const peExtIface = new ethers.Interface([
|
|
380
|
+
"function enableDefiAccess(address wallet) external",
|
|
381
|
+
"function whitelistContract(address wallet, address target) external",
|
|
382
|
+
"function defiAccessEnabled(address) external view returns (bool)",
|
|
383
|
+
"function isContractWhitelisted(address wallet, address target) external view returns (bool)",
|
|
384
|
+
]);
|
|
385
|
+
const peContract = new ethers.Contract(policyAddress, peExtIface, provider);
|
|
386
|
+
|
|
387
|
+
const defiEnabled = await peContract.defiAccessEnabled(walletAddress).catch(() => false) as boolean;
|
|
388
|
+
if (!defiEnabled) {
|
|
389
|
+
await sendTx(
|
|
390
|
+
{ to: policyAddress, data: peExtIface.encodeFunctionData("enableDefiAccess", [walletAddress]), value: "0x0" },
|
|
391
|
+
"enableDefiAccess on PolicyEngine",
|
|
392
|
+
);
|
|
393
|
+
saveConfig(config);
|
|
394
|
+
} else {
|
|
395
|
+
console.log(" " + c.success + c.dim(" enableDefiAccess — already done"));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// 5b) whitelistContract for AgentRegistry (check first)
|
|
399
|
+
const whitelisted = await peContract.isContractWhitelisted(walletAddress, agentRegistryAddress).catch(() => false) as boolean;
|
|
400
|
+
if (!whitelisted) {
|
|
401
|
+
await sendTx(
|
|
402
|
+
{ to: policyAddress, data: peExtIface.encodeFunctionData("whitelistContract", [walletAddress, agentRegistryAddress]), value: "0x0" },
|
|
403
|
+
"whitelistContract: AgentRegistry on PolicyEngine",
|
|
404
|
+
);
|
|
405
|
+
saveConfig(config);
|
|
406
|
+
} else {
|
|
407
|
+
console.log(" " + c.success + c.dim(" whitelistContract(AgentRegistry) — already done"));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// 5c+d) executeContractCall → register
|
|
411
|
+
const regIface = new ethers.Interface(AGENT_REGISTRY_ABI);
|
|
412
|
+
const execIface = new ethers.Interface(ARC402_WALLET_EXECUTE_ABI);
|
|
413
|
+
const regData = regIface.encodeFunctionData("register", [agentName, capabilities, agentServiceType, agentEndpoint, ""]);
|
|
414
|
+
const execData = execIface.encodeFunctionData("executeContractCall", [{
|
|
415
|
+
target: agentRegistryAddress,
|
|
416
|
+
data: regData,
|
|
417
|
+
value: 0n,
|
|
418
|
+
minReturnValue: 0n,
|
|
419
|
+
maxApprovalAmount: 0n,
|
|
420
|
+
approvalToken: ethers.ZeroAddress,
|
|
421
|
+
}]);
|
|
422
|
+
await sendTx({ to: walletAddress, data: execData, value: "0x0" }, `register agent: ${agentName}`);
|
|
423
|
+
console.log(" " + c.success + " Agent registered: " + agentName);
|
|
424
|
+
}
|
|
425
|
+
} else {
|
|
426
|
+
console.log(" " + c.warning + " AgentRegistry address not configured — skipping");
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// ── Step 6: Summary ───────────────────────────────────────────────────────
|
|
430
|
+
const trustScore = await (async () => {
|
|
431
|
+
try {
|
|
432
|
+
const trust = new ethers.Contract(config.trustRegistryAddress, TRUST_REGISTRY_ABI, provider);
|
|
433
|
+
const s = await trust.getScore(walletAddress) as bigint;
|
|
434
|
+
return s.toString();
|
|
435
|
+
} catch { return "100"; }
|
|
436
|
+
})();
|
|
437
|
+
|
|
438
|
+
console.log("\n " + c.success + c.white(" Onboarding complete"));
|
|
439
|
+
renderTree([
|
|
440
|
+
{ label: "Wallet", value: c.white(walletAddress) },
|
|
441
|
+
{ label: "Owner", value: c.white(ownerAddress) },
|
|
442
|
+
{ label: "Machine", value: c.white(machineKeyAddress) + c.dim(" (authorized)") },
|
|
443
|
+
{ label: "Passkey", value: passkeyActive ? c.green("✓ set") : c.yellow("⚠ skipped") },
|
|
444
|
+
{ label: "Velocity", value: c.white(velocityLimitEth + " ETH") },
|
|
445
|
+
{ label: "Guardian", value: guardianAddress ? c.white(guardianAddress) : c.dim("none") },
|
|
446
|
+
{ label: "Hire limit", value: c.white(hireLimit + " ETH") },
|
|
447
|
+
{ label: "Agent", value: agentName ? c.white(agentName) : c.dim("not registered") },
|
|
448
|
+
{ label: "Service", value: agentServiceType ? c.white(agentServiceType) : c.dim("—") },
|
|
449
|
+
{ label: "Endpoint", value: agentEndpoint ? c.white(agentEndpoint) : c.dim("—") },
|
|
450
|
+
{ label: "Trust", value: c.white(`${trustScore}`), last: true },
|
|
451
|
+
]);
|
|
452
|
+
console.log("\n " + c.dim("Next: fund your wallet with 0.002 ETH on Base"));
|
|
453
|
+
console.log(" " + c.dim(" arc402 daemon start"));
|
|
454
|
+
}
|
|
455
|
+
|
|
126
456
|
function printOpenShellHint(): void {
|
|
127
457
|
const r = spawnSync("which", ["openshell"], { encoding: "utf-8" });
|
|
128
458
|
if (r.status === 0 && r.stdout.trim()) {
|
|
@@ -655,38 +985,30 @@ export function registerWalletCommands(program: Command): void {
|
|
|
655
985
|
console.error("Could not find WalletCreated event in receipt. Check the transaction on-chain.");
|
|
656
986
|
process.exit(1);
|
|
657
987
|
}
|
|
988
|
+
// ── Step 1 complete: save wallet + owner immediately ─────────────────
|
|
658
989
|
config.walletContractAddress = walletAddress;
|
|
659
990
|
config.ownerAddress = account;
|
|
660
991
|
saveConfig(config);
|
|
661
|
-
|
|
992
|
+
try { fs.chmodSync(getConfigPath(), 0o600); } catch { /* best-effort */ }
|
|
993
|
+
console.log("\n " + c.success + c.white(" Wallet deployed"));
|
|
662
994
|
renderTree([
|
|
663
995
|
{ label: "Wallet", value: walletAddress },
|
|
664
|
-
{ label: "Owner", value: account
|
|
996
|
+
{ label: "Owner", value: account, last: true },
|
|
665
997
|
]);
|
|
666
998
|
|
|
667
|
-
// ──
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
},
|
|
681
|
-
);
|
|
682
|
-
|
|
683
|
-
console.log(c.dim("Your wallet contract is ready for policy enforcement"));
|
|
684
|
-
const paymasterUrl2 = config.paymasterUrl ?? NETWORK_DEFAULTS[config.network]?.paymasterUrl;
|
|
685
|
-
const deployedBalance = await provider.getBalance(walletAddress);
|
|
686
|
-
if (paymasterUrl2 && deployedBalance < BigInt(1_000_000_000_000_000)) {
|
|
687
|
-
console.log(c.dim("Gas sponsorship active — initial setup ops are free"));
|
|
688
|
-
}
|
|
689
|
-
console.log(c.dim("\nNext: run 'arc402 wallet set-guardian' to configure the emergency guardian key."));
|
|
999
|
+
// ── Steps 2–6: Complete onboarding ceremony (same WalletConnect session)
|
|
1000
|
+
const sendTxCeremony = async (
|
|
1001
|
+
call: { to: string; data: string; value: string },
|
|
1002
|
+
description: string,
|
|
1003
|
+
): Promise<string> => {
|
|
1004
|
+
console.log(" " + c.dim(`◈ ${description}`));
|
|
1005
|
+
const hash = await sendTransactionWithSession(client, session, account, chainId, call);
|
|
1006
|
+
console.log(" " + c.dim(" waiting for confirmation..."));
|
|
1007
|
+
await provider.waitForTransaction(hash, 1);
|
|
1008
|
+
console.log(" " + c.success + " " + c.white(description));
|
|
1009
|
+
return hash;
|
|
1010
|
+
};
|
|
1011
|
+
await runCompleteOnboardingCeremony(walletAddress, account, config, provider, sendTxCeremony);
|
|
690
1012
|
printOpenShellHint();
|
|
691
1013
|
} else {
|
|
692
1014
|
console.warn("⚠ WalletConnect not configured. Using stored private key (insecure).");
|
|
@@ -715,6 +1037,7 @@ export function registerWalletCommands(program: Command): void {
|
|
|
715
1037
|
// Generate guardian key (separate from hot key) and call setGuardian
|
|
716
1038
|
const guardianWallet = ethers.Wallet.createRandom();
|
|
717
1039
|
config.walletContractAddress = walletAddress;
|
|
1040
|
+
config.ownerAddress = address;
|
|
718
1041
|
config.guardianPrivateKey = guardianWallet.privateKey;
|
|
719
1042
|
config.guardianAddress = guardianWallet.address;
|
|
720
1043
|
saveConfig(config);
|
|
@@ -1572,16 +1895,33 @@ export function registerWalletCommands(program: Command): void {
|
|
|
1572
1895
|
console.error("walletConnectProjectId not set in config. Run `arc402 config set walletConnectProjectId <id>`.");
|
|
1573
1896
|
process.exit(1);
|
|
1574
1897
|
}
|
|
1575
|
-
const ownerAddress = config.ownerAddress;
|
|
1576
|
-
if (!ownerAddress) {
|
|
1577
|
-
console.error("ownerAddress not set in config. Run `arc402 wallet deploy` first.");
|
|
1578
|
-
process.exit(1);
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
1898
|
const policyAddress = config.policyEngineAddress ?? POLICY_ENGINE_DEFAULT;
|
|
1582
1899
|
const chainId = config.network === "base-mainnet" ? 8453 : 84532;
|
|
1583
1900
|
const provider = new ethers.JsonRpcProvider(config.rpcUrl);
|
|
1584
1901
|
|
|
1902
|
+
let ownerAddress = config.ownerAddress;
|
|
1903
|
+
if (!ownerAddress) {
|
|
1904
|
+
// Fallback 1: WalletConnect session account
|
|
1905
|
+
if (config.wcSession?.account) {
|
|
1906
|
+
ownerAddress = config.wcSession.account;
|
|
1907
|
+
console.log(c.dim(`Owner resolved from WalletConnect session: ${ownerAddress}`));
|
|
1908
|
+
} else {
|
|
1909
|
+
// Fallback 2: call owner() on the wallet contract
|
|
1910
|
+
try {
|
|
1911
|
+
const walletOwnerContract = new ethers.Contract(
|
|
1912
|
+
config.walletContractAddress!,
|
|
1913
|
+
["function owner() external view returns (address)"],
|
|
1914
|
+
provider,
|
|
1915
|
+
);
|
|
1916
|
+
ownerAddress = await walletOwnerContract.owner();
|
|
1917
|
+
console.log(c.dim(`Owner resolved from contract: ${ownerAddress}`));
|
|
1918
|
+
} catch {
|
|
1919
|
+
console.error("ownerAddress not set in config and could not be resolved from contract or WalletConnect session.");
|
|
1920
|
+
process.exit(1);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1585
1925
|
// Encode registerWallet(wallet, owner) calldata — called on PolicyEngine
|
|
1586
1926
|
const policyInterface = new ethers.Interface([
|
|
1587
1927
|
"function registerWallet(address wallet, address owner) external",
|
package/src/config.ts
CHANGED
|
@@ -62,6 +62,7 @@ export function loadConfig(): Arc402Config {
|
|
|
62
62
|
network: "base-mainnet",
|
|
63
63
|
rpcUrl: defaults.rpcUrl ?? "https://mainnet.base.org",
|
|
64
64
|
walletConnectProjectId: "455e9425343b9156fce1428250c9a54a",
|
|
65
|
+
ownerAddress: undefined,
|
|
65
66
|
policyEngineAddress: defaults.policyEngineAddress,
|
|
66
67
|
trustRegistryAddress: defaults.trustRegistryAddress ?? "",
|
|
67
68
|
agentRegistryAddress: d.agentRegistryV2Address ?? defaults.agentRegistryAddress,
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,21 @@
|
|
|
2
2
|
import { createProgram } from "./program";
|
|
3
3
|
import { startREPL } from "./repl";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const printMode = process.argv.includes("--print");
|
|
6
|
+
|
|
7
|
+
if (printMode) {
|
|
8
|
+
// --print mode: skip REPL entirely, suppress ANSI/spinners, run command, exit.
|
|
9
|
+
// Used by OpenClaw agents running arc402 commands via ACP.
|
|
10
|
+
process.argv = process.argv.filter((a) => a !== "--print");
|
|
11
|
+
process.env["NO_COLOR"] = "1";
|
|
12
|
+
process.env["FORCE_COLOR"] = "0";
|
|
13
|
+
process.env["ARC402_PRINT"] = "1";
|
|
14
|
+
const program = createProgram();
|
|
15
|
+
void program.parseAsync(process.argv).then(() => process.exit(0)).catch((e: unknown) => {
|
|
16
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
|
19
|
+
} else if (process.argv.length <= 2) {
|
|
6
20
|
// No subcommand — enter interactive REPL
|
|
7
21
|
void startREPL();
|
|
8
22
|
} else {
|