@clawtrail/init 1.2.0 → 1.2.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/index.js +45 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -205,34 +205,56 @@ async function main() {
|
|
|
205
205
|
}
|
|
206
206
|
]);
|
|
207
207
|
if (shouldRegister) {
|
|
208
|
-
const { walletChoice } = await inquirer.prompt([{
|
|
209
|
-
type: "list",
|
|
210
|
-
name: "walletChoice",
|
|
211
|
-
message: "Ethereum wallet for DKG identity:",
|
|
212
|
-
choices: [
|
|
213
|
-
{ name: "Enter my existing wallet address", value: "existing" },
|
|
214
|
-
{ name: "Generate a new wallet for me", value: "generate" }
|
|
215
|
-
],
|
|
216
|
-
default: "existing"
|
|
217
|
-
}]);
|
|
218
208
|
let walletAddress;
|
|
219
209
|
let generatedPrivateKey = null;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
210
|
+
const existingPrivateKey = await (async () => {
|
|
211
|
+
try {
|
|
212
|
+
const configPath = path.join(os.homedir(), ".openclaw", "openclaw.json");
|
|
213
|
+
const raw = await fs.readFile(configPath, "utf-8");
|
|
214
|
+
const cfg = JSON5.parse(raw);
|
|
215
|
+
const key = cfg?.plugins?.entries?.clawtrail?.config?.walletPrivateKey;
|
|
216
|
+
if (key && typeof key === "string" && key.startsWith("0x") && key.length === 66) {
|
|
217
|
+
return key;
|
|
218
|
+
}
|
|
219
|
+
} catch {
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
})();
|
|
223
|
+
if (existingPrivateKey) {
|
|
224
|
+
const account = privateKeyToAccount(existingPrivateKey);
|
|
224
225
|
walletAddress = account.address;
|
|
225
|
-
generatedPrivateKey =
|
|
226
|
-
|
|
227
|
-
console.log(chalk.
|
|
226
|
+
generatedPrivateKey = existingPrivateKey;
|
|
227
|
+
console.log(chalk.cyan(`\u267B Reusing existing wallet from ~/.openclaw/openclaw.json`));
|
|
228
|
+
console.log(chalk.gray(` Address: ${chalk.cyan(walletAddress)}
|
|
229
|
+
`));
|
|
228
230
|
} else {
|
|
229
|
-
const {
|
|
230
|
-
type: "
|
|
231
|
-
name: "
|
|
232
|
-
message: "
|
|
233
|
-
|
|
231
|
+
const { walletChoice } = await inquirer.prompt([{
|
|
232
|
+
type: "list",
|
|
233
|
+
name: "walletChoice",
|
|
234
|
+
message: "Ethereum wallet for DKG identity:",
|
|
235
|
+
choices: [
|
|
236
|
+
{ name: "Enter my existing wallet address", value: "existing" },
|
|
237
|
+
{ name: "Generate a new wallet for me", value: "generate" }
|
|
238
|
+
],
|
|
239
|
+
default: "existing"
|
|
234
240
|
}]);
|
|
235
|
-
|
|
241
|
+
if (walletChoice === "generate") {
|
|
242
|
+
const walletSpinner = ora("Generating Ethereum wallet...").start();
|
|
243
|
+
const privateKey = generatePrivateKey();
|
|
244
|
+
const account = privateKeyToAccount(privateKey);
|
|
245
|
+
walletAddress = account.address;
|
|
246
|
+
generatedPrivateKey = privateKey;
|
|
247
|
+
walletSpinner.succeed(chalk.green(`\u2713 Generated wallet: ${chalk.cyan(walletAddress)}`));
|
|
248
|
+
console.log(chalk.yellow(" \u26A0 Private key will be saved to ~/.openclaw/openclaw.json\n"));
|
|
249
|
+
} else {
|
|
250
|
+
const { wallet } = await inquirer.prompt([{
|
|
251
|
+
type: "input",
|
|
252
|
+
name: "wallet",
|
|
253
|
+
message: "Wallet address (0x...):",
|
|
254
|
+
validate: (input) => input.startsWith("0x") && input.length === 42 ? true : "Valid Ethereum address required"
|
|
255
|
+
}]);
|
|
256
|
+
walletAddress = wallet;
|
|
257
|
+
}
|
|
236
258
|
}
|
|
237
259
|
const answers = await inquirer.prompt([
|
|
238
260
|
{
|