finlayer-cli 1.2.1 → 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.
Files changed (2) hide show
  1. package/index.js +40 -17
  2. 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(' 0ngn <command> [options]\n'));
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 and save it to ~/keypair.json');
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,13 @@ 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(' 0ngn info\n'));
65
+ console.log(chalk.cyan(' finlayer info\n'));
66
66
  console.log(chalk.gray(' # Query a balance'));
67
- console.log(chalk.cyan(' 0ngn balance 4410520adbebcffa68899f7bcddeaf8f\n'));
67
+ console.log(chalk.cyan(' finlayer balance 4410520adbebcffa68899f7bcddeaf8f\n'));
68
68
  console.log(chalk.gray(' # Look up a transaction'));
69
- console.log(chalk.cyan(' 0ngn tx e27ff5a046f317a1c62e4f9a6d7c55620b7fd0602891cc7c45554b112c394b9f\n'));
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(' 0ngn transfer -s <from_id> -r <to_id> -a 100000 -k <priv_key> -m "Invoice #001"'));
71
+ console.log(chalk.cyan(' finlayer transfer -s <from_id> -r <to_id> -a 100000 -k <priv_key> -m "Invoice #001"'));
72
72
  console.log(chalk.gray('\n # Create a new account keypair'));
73
73
  console.log(chalk.cyan(' finlayer create-account'));
74
74
  console.log(divider);
@@ -122,7 +122,7 @@ program.command('info')
122
122
  console.log(divider);
123
123
  console.log(chalk.green(' GET STARTED'));
124
124
  console.log(divider);
125
- console.log(label('New Account') + chalk.cyan('finlayer create-account'));
125
+ console.log(label('New Account') + chalk.cyan('finlayer create-account --register'));
126
126
  console.log(label('Check Balance') + chalk.cyan('finlayer balance <account_id>'));
127
127
  console.log(label('Send 0NGN') + chalk.cyan('finlayer transfer -s <id> -r <id> -a <kubo> -k <key>'));
128
128
  console.log(divider);
@@ -316,31 +316,53 @@ program.command('transfer')
316
316
 
317
317
  // ── CREATE ACCOUNT ────────────────────────────────────────────────────
318
318
  program.command('create-account')
319
- .description('Generate a new Ed25519 keypair and save to keypair.json')
319
+ .description('Generate a new Ed25519 keypair and save to ~/keypair.json')
320
320
  .option('-o, --output <file>', 'Output file path', join(homedir(), 'keypair.json'))
321
- .action((opts) => {
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
+
322
351
  const { privateKey, publicKey } = generateKeyPairSync('ed25519', {
323
352
  privateKeyEncoding: { type: 'pkcs8', format: 'der' },
324
353
  publicKeyEncoding: { type: 'spki', format: 'der' }
325
354
  });
326
-
327
- // Extract raw 32-byte keys from DER wrappers
328
355
  const privRaw = privateKey.slice(-32);
329
356
  const pubRaw = publicKey.slice(-32);
330
357
  const fullKey = Buffer.concat([privRaw, pubRaw]);
331
-
332
- // Derive a deterministic account_id from the public key
333
358
  const accountId = createHash('md5').update(pubRaw).digest('hex');
334
-
335
359
  const keypair = {
336
360
  account_id: accountId,
337
361
  public_key: pubRaw.toString('hex'),
338
362
  private_key: fullKey.toString('hex'),
339
363
  created_at: new Date().toISOString()
340
364
  };
341
-
342
365
  writeFileSync(opts.output, JSON.stringify(keypair, null, 2));
343
-
344
366
  console.log('\n');
345
367
  console.log(divider);
346
368
  console.log(chalk.green(' NEW ACCOUNT CREATED'));
@@ -349,6 +371,7 @@ program.command('create-account')
349
371
  console.log(label('Public Key') + chalk.cyan(keypair.public_key));
350
372
  console.log(label('Saved to') + chalk.yellow(opts.output));
351
373
  console.log(divider);
374
+ console.log(chalk.gray(' To register on the ledger run: finlayer create-account --register'));
352
375
  console.log(chalk.gray(' Keep your keypair.json safe. Never share your private_key.\n'));
353
376
  });
354
377
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "finlayer-cli",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Command Line Interface for the 0NGN FinLayer Nigerian Digital Currency Network",
5
5
  "main": "index.js",
6
6
  "type": "module",