finlayer-cli 1.2.0 → 1.2.2
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/index.js +47 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const showHelp = () => {
|
|
|
27
27
|
console.log(divider);
|
|
28
28
|
console.log(chalk.white.bold(' USAGE'));
|
|
29
29
|
console.log(divider);
|
|
30
|
-
console.log(chalk.yellow('
|
|
30
|
+
console.log(chalk.yellow(' finlayer <command> [options]\n'));
|
|
31
31
|
console.log(divider);
|
|
32
32
|
console.log(chalk.white.bold(' COMMANDS'));
|
|
33
33
|
console.log(divider);
|
|
@@ -43,8 +43,8 @@ const showHelp = () => {
|
|
|
43
43
|
'Full transaction receipt — parties, amount, ed25519 sig, Solana L1 anchor');
|
|
44
44
|
cmd('transfer', '-s <id> -r <id> -a <kubo> -k <key> [-m <memo>] [--rpc <url>]',
|
|
45
45
|
'Broadcast a signed transfer and stream Solana Devnet confirmation');
|
|
46
|
-
cmd('create-account', '[-o <file>]',
|
|
47
|
-
'Generate a new Ed25519 keypair
|
|
46
|
+
cmd('create-account', '[--register] [-o <file>]',
|
|
47
|
+
'Generate a new Ed25519 keypair locally, or use --register to create & register on the ledger');
|
|
48
48
|
console.log(divider);
|
|
49
49
|
console.log(chalk.white.bold(' OPTIONS'));
|
|
50
50
|
console.log(divider);
|
|
@@ -62,13 +62,15 @@ const showHelp = () => {
|
|
|
62
62
|
console.log(chalk.white.bold(' EXAMPLES'));
|
|
63
63
|
console.log(divider);
|
|
64
64
|
console.log(chalk.gray(' # Check network status'));
|
|
65
|
-
console.log(chalk.cyan('
|
|
65
|
+
console.log(chalk.cyan(' finlayer info\n'));
|
|
66
66
|
console.log(chalk.gray(' # Query a balance'));
|
|
67
|
-
console.log(chalk.cyan('
|
|
67
|
+
console.log(chalk.cyan(' finlayer balance 4410520adbebcffa68899f7bcddeaf8f\n'));
|
|
68
68
|
console.log(chalk.gray(' # Look up a transaction'));
|
|
69
|
-
console.log(chalk.cyan('
|
|
69
|
+
console.log(chalk.cyan(' finlayer tx e27ff5a046f317a1c62e4f9a6d7c55620b7fd0602891cc7c45554b112c394b9f\n'));
|
|
70
70
|
console.log(chalk.gray(' # Send 1000 0NGN with a memo'));
|
|
71
|
-
console.log(chalk.cyan('
|
|
71
|
+
console.log(chalk.cyan(' finlayer transfer -s <from_id> -r <to_id> -a 100000 -k <priv_key> -m "Invoice #001"'));
|
|
72
|
+
console.log(chalk.gray('\n # Create a new account keypair'));
|
|
73
|
+
console.log(chalk.cyan(' finlayer create-account'));
|
|
72
74
|
console.log(divider);
|
|
73
75
|
console.log();
|
|
74
76
|
};
|
|
@@ -118,6 +120,12 @@ program.command('info')
|
|
|
118
120
|
console.log(label('L1 Anchor') + chalk.magenta('Solana Devnet via SPL Memo Program'));
|
|
119
121
|
console.log(label('Checkpoint') + chalk.magenta('Arweave / Irys (daily state root)'));
|
|
120
122
|
console.log(divider);
|
|
123
|
+
console.log(chalk.green(' GET STARTED'));
|
|
124
|
+
console.log(divider);
|
|
125
|
+
console.log(label('New Account') + chalk.cyan('finlayer create-account --register'));
|
|
126
|
+
console.log(label('Check Balance') + chalk.cyan('finlayer balance <account_id>'));
|
|
127
|
+
console.log(label('Send 0NGN') + chalk.cyan('finlayer transfer -s <id> -r <id> -a <kubo> -k <key>'));
|
|
128
|
+
console.log(divider);
|
|
121
129
|
console.log();
|
|
122
130
|
} catch (e) {
|
|
123
131
|
console.log(chalk.red(`\n [ERROR] Network unreachable — ${e.message}\n`));
|
|
@@ -308,31 +316,53 @@ program.command('transfer')
|
|
|
308
316
|
|
|
309
317
|
// ── CREATE ACCOUNT ────────────────────────────────────────────────────
|
|
310
318
|
program.command('create-account')
|
|
311
|
-
.description('Generate a new Ed25519 keypair and save to keypair.json')
|
|
319
|
+
.description('Generate a new Ed25519 keypair and save to ~/keypair.json')
|
|
312
320
|
.option('-o, --output <file>', 'Output file path', join(homedir(), 'keypair.json'))
|
|
313
|
-
.
|
|
321
|
+
.option('--register', 'Register the account on the 0NGN ledger')
|
|
322
|
+
.option('--rpc <url>', 'Target RPC Node', API)
|
|
323
|
+
.action(async (opts) => {
|
|
324
|
+
if (opts.register) {
|
|
325
|
+
process.stdout.write(chalk.gray('\n Registering account on ledger...'));
|
|
326
|
+
const res = await fetch(`${opts.rpc}/account/create`, { method: 'POST' });
|
|
327
|
+
const j = await res.json();
|
|
328
|
+
if (!j.data?.account_id) {
|
|
329
|
+
console.log(chalk.red('\n [ERROR] Registration failed.\n'));
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const keypair = {
|
|
333
|
+
account_id: j.data.account_id,
|
|
334
|
+
public_key: j.data.public_key,
|
|
335
|
+
private_key: j.data.private_key,
|
|
336
|
+
created_at: j.data.created_at
|
|
337
|
+
};
|
|
338
|
+
writeFileSync(opts.output, JSON.stringify(keypair, null, 2));
|
|
339
|
+
console.log('\n');
|
|
340
|
+
console.log(divider);
|
|
341
|
+
console.log(chalk.green(' ACCOUNT REGISTERED ON LEDGER'));
|
|
342
|
+
console.log(divider);
|
|
343
|
+
console.log(label('Account ID') + chalk.cyan.bold(keypair.account_id));
|
|
344
|
+
console.log(label('Public Key') + chalk.cyan(keypair.public_key));
|
|
345
|
+
console.log(label('Saved to') + chalk.yellow(opts.output));
|
|
346
|
+
console.log(divider);
|
|
347
|
+
console.log(chalk.gray(' Keep your keypair.json safe. Never share your private_key.\n'));
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
314
351
|
const { privateKey, publicKey } = generateKeyPairSync('ed25519', {
|
|
315
352
|
privateKeyEncoding: { type: 'pkcs8', format: 'der' },
|
|
316
353
|
publicKeyEncoding: { type: 'spki', format: 'der' }
|
|
317
354
|
});
|
|
318
|
-
|
|
319
|
-
// Extract raw 32-byte keys from DER wrappers
|
|
320
355
|
const privRaw = privateKey.slice(-32);
|
|
321
356
|
const pubRaw = publicKey.slice(-32);
|
|
322
357
|
const fullKey = Buffer.concat([privRaw, pubRaw]);
|
|
323
|
-
|
|
324
|
-
// Derive a deterministic account_id from the public key
|
|
325
358
|
const accountId = createHash('md5').update(pubRaw).digest('hex');
|
|
326
|
-
|
|
327
359
|
const keypair = {
|
|
328
360
|
account_id: accountId,
|
|
329
361
|
public_key: pubRaw.toString('hex'),
|
|
330
362
|
private_key: fullKey.toString('hex'),
|
|
331
363
|
created_at: new Date().toISOString()
|
|
332
364
|
};
|
|
333
|
-
|
|
334
365
|
writeFileSync(opts.output, JSON.stringify(keypair, null, 2));
|
|
335
|
-
|
|
336
366
|
console.log('\n');
|
|
337
367
|
console.log(divider);
|
|
338
368
|
console.log(chalk.green(' NEW ACCOUNT CREATED'));
|
|
@@ -341,6 +371,7 @@ program.command('create-account')
|
|
|
341
371
|
console.log(label('Public Key') + chalk.cyan(keypair.public_key));
|
|
342
372
|
console.log(label('Saved to') + chalk.yellow(opts.output));
|
|
343
373
|
console.log(divider);
|
|
374
|
+
console.log(chalk.gray(' To register on the ledger run: finlayer create-account --register'));
|
|
344
375
|
console.log(chalk.gray(' Keep your keypair.json safe. Never share your private_key.\n'));
|
|
345
376
|
});
|
|
346
377
|
|