arc402-cli 0.5.0 → 0.6.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.
- 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 +414 -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 +539 -147
- 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 +458 -32
- package/src/config.ts +1 -0
- package/src/index.ts +15 -1
- package/src/repl.ts +643 -178
- 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,422 @@ 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 7: Workroom Init ─────────────────────────────────────────────────
|
|
430
|
+
console.log("\n" + c.dim("── Step 7: Workroom ────────────────────────────────────────────"));
|
|
431
|
+
|
|
432
|
+
let workroomInitialized = false;
|
|
433
|
+
let dockerFound = false;
|
|
434
|
+
try {
|
|
435
|
+
const dockerCheck = spawnSync("docker", ["--version"], { encoding: "utf-8", timeout: 5000 });
|
|
436
|
+
dockerFound = dockerCheck.status === 0;
|
|
437
|
+
} catch { dockerFound = false; }
|
|
438
|
+
|
|
439
|
+
if (dockerFound) {
|
|
440
|
+
console.log(" " + c.dim("Docker found — initializing workroom..."));
|
|
441
|
+
try {
|
|
442
|
+
const initResult = spawnSync(process.execPath, [process.argv[1], "workroom", "init"], {
|
|
443
|
+
encoding: "utf-8",
|
|
444
|
+
timeout: 120000,
|
|
445
|
+
env: { ...process.env },
|
|
446
|
+
});
|
|
447
|
+
workroomInitialized = initResult.status === 0;
|
|
448
|
+
if (workroomInitialized) {
|
|
449
|
+
console.log(" " + c.success + " Workroom initialized");
|
|
450
|
+
} else {
|
|
451
|
+
console.log(" " + c.warning + " Workroom init incomplete — run: arc402 workroom init");
|
|
452
|
+
}
|
|
453
|
+
} catch {
|
|
454
|
+
console.log(" " + c.warning + " Workroom init failed — run: arc402 workroom init");
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
console.log(" " + c.warning + " Docker not found");
|
|
458
|
+
console.log(" Install Docker: https://docs.docker.com/get-docker/");
|
|
459
|
+
console.log(" Or run daemon in host mode: " + c.white("arc402 daemon start --host"));
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// ── Step 8: Daemon Start ──────────────────────────────────────────────────
|
|
463
|
+
console.log("\n" + c.dim("── Step 8: Daemon ──────────────────────────────────────────────"));
|
|
464
|
+
|
|
465
|
+
let daemonRunning = false;
|
|
466
|
+
const relayPort = 4402;
|
|
467
|
+
|
|
468
|
+
if (workroomInitialized) {
|
|
469
|
+
try {
|
|
470
|
+
const startResult = spawnSync(process.execPath, [process.argv[1], "workroom", "start"], {
|
|
471
|
+
encoding: "utf-8",
|
|
472
|
+
timeout: 30000,
|
|
473
|
+
env: { ...process.env },
|
|
474
|
+
});
|
|
475
|
+
daemonRunning = startResult.status === 0;
|
|
476
|
+
if (daemonRunning) {
|
|
477
|
+
console.log(" " + c.success + " Daemon online (port " + relayPort + ")");
|
|
478
|
+
} else {
|
|
479
|
+
console.log(" " + c.warning + " Daemon start failed — run: arc402 workroom start");
|
|
480
|
+
}
|
|
481
|
+
} catch {
|
|
482
|
+
console.log(" " + c.warning + " Daemon start failed — run: arc402 workroom start");
|
|
483
|
+
}
|
|
484
|
+
} else if (!dockerFound) {
|
|
485
|
+
try {
|
|
486
|
+
const startResult = spawnSync(process.execPath, [process.argv[1], "daemon", "start", "--host"], {
|
|
487
|
+
encoding: "utf-8",
|
|
488
|
+
timeout: 30000,
|
|
489
|
+
env: { ...process.env },
|
|
490
|
+
});
|
|
491
|
+
daemonRunning = startResult.status === 0;
|
|
492
|
+
if (daemonRunning) {
|
|
493
|
+
console.log(" " + c.success + " Daemon online — host mode (port " + relayPort + ")");
|
|
494
|
+
} else {
|
|
495
|
+
console.log(" " + c.warning + " Daemon not started — run: arc402 daemon start --host");
|
|
496
|
+
}
|
|
497
|
+
} catch {
|
|
498
|
+
console.log(" " + c.warning + " Daemon not started — run: arc402 daemon start --host");
|
|
499
|
+
}
|
|
500
|
+
} else {
|
|
501
|
+
console.log(" " + c.warning + " Daemon not started — run: arc402 workroom init first");
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// ── Step 6: Summary ───────────────────────────────────────────────────────
|
|
505
|
+
const trustScore = await (async () => {
|
|
506
|
+
try {
|
|
507
|
+
const trust = new ethers.Contract(config.trustRegistryAddress, TRUST_REGISTRY_ABI, provider);
|
|
508
|
+
const s = await trust.getScore(walletAddress) as bigint;
|
|
509
|
+
return s.toString();
|
|
510
|
+
} catch { return "100"; }
|
|
511
|
+
})();
|
|
512
|
+
|
|
513
|
+
const workroomLabel = dockerFound
|
|
514
|
+
? (workroomInitialized ? (daemonRunning ? c.green("✓ Running") : c.yellow("✓ Initialized")) : c.yellow("⚠ Init needed"))
|
|
515
|
+
: c.yellow("⚠ No Docker");
|
|
516
|
+
const daemonLabel = daemonRunning
|
|
517
|
+
? c.green("✓ Online (port " + relayPort + ")")
|
|
518
|
+
: c.dim("not started");
|
|
519
|
+
const endpointLabel = agentEndpoint
|
|
520
|
+
? c.white(agentEndpoint) + c.dim(` → localhost:${relayPort}`)
|
|
521
|
+
: c.dim("—");
|
|
522
|
+
|
|
523
|
+
console.log("\n " + c.success + c.white(" Onboarding complete"));
|
|
524
|
+
renderTree([
|
|
525
|
+
{ label: "Wallet", value: c.white(walletAddress) },
|
|
526
|
+
{ label: "Owner", value: c.white(ownerAddress) },
|
|
527
|
+
{ label: "Machine", value: c.white(machineKeyAddress) + c.dim(" (authorized)") },
|
|
528
|
+
{ label: "Passkey", value: passkeyActive ? c.green("✓ set") : c.yellow("⚠ skipped") },
|
|
529
|
+
{ label: "Velocity", value: c.white(velocityLimitEth + " ETH") },
|
|
530
|
+
{ label: "Guardian", value: guardianAddress ? c.white(guardianAddress) : c.dim("none") },
|
|
531
|
+
{ label: "Hire limit", value: c.white(hireLimit + " ETH") },
|
|
532
|
+
{ label: "Agent", value: agentName ? c.white(agentName) : c.dim("not registered") },
|
|
533
|
+
{ label: "Service", value: agentServiceType ? c.white(agentServiceType) : c.dim("—") },
|
|
534
|
+
{ label: "Workroom", value: workroomLabel },
|
|
535
|
+
{ label: "Daemon", value: daemonLabel },
|
|
536
|
+
{ label: "Endpoint", value: endpointLabel },
|
|
537
|
+
{ label: "Trust", value: c.white(`${trustScore}`), last: true },
|
|
538
|
+
]);
|
|
539
|
+
console.log("\n " + c.dim("Next: fund your wallet with 0.002 ETH on Base"));
|
|
540
|
+
}
|
|
541
|
+
|
|
126
542
|
function printOpenShellHint(): void {
|
|
127
543
|
const r = spawnSync("which", ["openshell"], { encoding: "utf-8" });
|
|
128
544
|
if (r.status === 0 && r.stdout.trim()) {
|
|
@@ -655,38 +1071,30 @@ export function registerWalletCommands(program: Command): void {
|
|
|
655
1071
|
console.error("Could not find WalletCreated event in receipt. Check the transaction on-chain.");
|
|
656
1072
|
process.exit(1);
|
|
657
1073
|
}
|
|
1074
|
+
// ── Step 1 complete: save wallet + owner immediately ─────────────────
|
|
658
1075
|
config.walletContractAddress = walletAddress;
|
|
659
1076
|
config.ownerAddress = account;
|
|
660
1077
|
saveConfig(config);
|
|
661
|
-
|
|
1078
|
+
try { fs.chmodSync(getConfigPath(), 0o600); } catch { /* best-effort */ }
|
|
1079
|
+
console.log("\n " + c.success + c.white(" Wallet deployed"));
|
|
662
1080
|
renderTree([
|
|
663
1081
|
{ label: "Wallet", value: walletAddress },
|
|
664
|
-
{ label: "Owner", value: account
|
|
1082
|
+
{ label: "Owner", value: account, last: true },
|
|
665
1083
|
]);
|
|
666
1084
|
|
|
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."));
|
|
1085
|
+
// ── Steps 2–6: Complete onboarding ceremony (same WalletConnect session)
|
|
1086
|
+
const sendTxCeremony = async (
|
|
1087
|
+
call: { to: string; data: string; value: string },
|
|
1088
|
+
description: string,
|
|
1089
|
+
): Promise<string> => {
|
|
1090
|
+
console.log(" " + c.dim(`◈ ${description}`));
|
|
1091
|
+
const hash = await sendTransactionWithSession(client, session, account, chainId, call);
|
|
1092
|
+
console.log(" " + c.dim(" waiting for confirmation..."));
|
|
1093
|
+
await provider.waitForTransaction(hash, 1);
|
|
1094
|
+
console.log(" " + c.success + " " + c.white(description));
|
|
1095
|
+
return hash;
|
|
1096
|
+
};
|
|
1097
|
+
await runCompleteOnboardingCeremony(walletAddress, account, config, provider, sendTxCeremony);
|
|
690
1098
|
printOpenShellHint();
|
|
691
1099
|
} else {
|
|
692
1100
|
console.warn("⚠ WalletConnect not configured. Using stored private key (insecure).");
|
|
@@ -715,6 +1123,7 @@ export function registerWalletCommands(program: Command): void {
|
|
|
715
1123
|
// Generate guardian key (separate from hot key) and call setGuardian
|
|
716
1124
|
const guardianWallet = ethers.Wallet.createRandom();
|
|
717
1125
|
config.walletContractAddress = walletAddress;
|
|
1126
|
+
config.ownerAddress = address;
|
|
718
1127
|
config.guardianPrivateKey = guardianWallet.privateKey;
|
|
719
1128
|
config.guardianAddress = guardianWallet.address;
|
|
720
1129
|
saveConfig(config);
|
|
@@ -1572,16 +1981,33 @@ export function registerWalletCommands(program: Command): void {
|
|
|
1572
1981
|
console.error("walletConnectProjectId not set in config. Run `arc402 config set walletConnectProjectId <id>`.");
|
|
1573
1982
|
process.exit(1);
|
|
1574
1983
|
}
|
|
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
1984
|
const policyAddress = config.policyEngineAddress ?? POLICY_ENGINE_DEFAULT;
|
|
1582
1985
|
const chainId = config.network === "base-mainnet" ? 8453 : 84532;
|
|
1583
1986
|
const provider = new ethers.JsonRpcProvider(config.rpcUrl);
|
|
1584
1987
|
|
|
1988
|
+
let ownerAddress = config.ownerAddress;
|
|
1989
|
+
if (!ownerAddress) {
|
|
1990
|
+
// Fallback 1: WalletConnect session account
|
|
1991
|
+
if (config.wcSession?.account) {
|
|
1992
|
+
ownerAddress = config.wcSession.account;
|
|
1993
|
+
console.log(c.dim(`Owner resolved from WalletConnect session: ${ownerAddress}`));
|
|
1994
|
+
} else {
|
|
1995
|
+
// Fallback 2: call owner() on the wallet contract
|
|
1996
|
+
try {
|
|
1997
|
+
const walletOwnerContract = new ethers.Contract(
|
|
1998
|
+
config.walletContractAddress!,
|
|
1999
|
+
["function owner() external view returns (address)"],
|
|
2000
|
+
provider,
|
|
2001
|
+
);
|
|
2002
|
+
ownerAddress = await walletOwnerContract.owner();
|
|
2003
|
+
console.log(c.dim(`Owner resolved from contract: ${ownerAddress}`));
|
|
2004
|
+
} catch {
|
|
2005
|
+
console.error("ownerAddress not set in config and could not be resolved from contract or WalletConnect session.");
|
|
2006
|
+
process.exit(1);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
|
|
1585
2011
|
// Encode registerWallet(wallet, owner) calldata — called on PolicyEngine
|
|
1586
2012
|
const policyInterface = new ethers.Interface([
|
|
1587
2013
|
"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 {
|