@lightsparkdev/lightspark-cli
Advanced tools
+6
-0
| # @lightsparkdev/lightspark-cli | ||
| ## 0.0.11 | ||
| ### Patch Changes | ||
| - c3c779f: Add generate-secp256k1-keypair command | ||
| ## 0.0.10 | ||
@@ -4,0 +10,0 @@ |
+5
-0
@@ -38,1 +38,6 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved | ||
| }; | ||
| export const bytesToHex = (bytes) => { | ||
| return bytes.reduce((acc, byte) => { | ||
| return (acc += ("0" + byte.toString(16)).slice(-2)); | ||
| }, ""); | ||
| }; |
+21
-4
@@ -6,7 +6,9 @@ #!/usr/bin/env node | ||
| import { Command, InvalidArgumentError } from "commander"; | ||
| import { randomBytes } from "crypto"; | ||
| import * as fs from "fs/promises"; | ||
| import qrcode from "qrcode-terminal"; | ||
| import secp256k1 from "secp256k1"; | ||
| import { LightsparkSigner, Mnemonic, Seed, } from "../lightspark_crypto/lightspark_crypto.js"; | ||
| import { getCredentialsFromEnvOrThrow, RequiredCredentials, } from "./authHelpers.js"; | ||
| import { getBitcoinNetworkOrThrow, getNodeId, getPackageVersion, isBitcoinNetwork, } from "./helpers.js"; | ||
| import { bytesToHex, getBitcoinNetworkOrThrow, getNodeId, getPackageVersion, isBitcoinNetwork, } from "./helpers.js"; | ||
| const main = async (options, action) => { | ||
@@ -268,5 +270,3 @@ const credentials = getCredentialsFromEnvOrThrow(); | ||
| const extendedPublicKey = lightsparkSigner.get_master_public_key(); | ||
| const seedAsHex = seed.as_bytes().reduce((acc, byte) => { | ||
| return (acc += ("0" + byte.toString(16)).slice(-2)); | ||
| }, ""); | ||
| const seedAsHex = bytesToHex(seed.as_bytes()); | ||
| console.log(`Seed phrase:\n${mnemonic.as_string()}\n`); | ||
@@ -276,2 +276,13 @@ console.log(`Hex-encoded seed:\n${seedAsHex}\n`); | ||
| }; | ||
| const generateSecp256k1Keypair = async () => { | ||
| let privateKey; | ||
| do { | ||
| privateKey = randomBytes(32); | ||
| } while (!secp256k1.privateKeyVerify(privateKey)); | ||
| const publicKey = secp256k1.publicKeyCreate(privateKey); | ||
| const publicKeyAsHex = bytesToHex(publicKey); | ||
| const privateKeyAsHex = bytesToHex(privateKey); | ||
| console.log(`Hex-encoded public key: \n${publicKeyAsHex}\n`); | ||
| console.log(`Hex-encoded private key: \n${privateKeyAsHex}\n`); | ||
| }; | ||
| const safeParseInt = (value /* dummyPrevious: any */) => { | ||
@@ -374,2 +385,7 @@ // parseInt takes a string and a radix | ||
| }); | ||
| const generateSecp256k1KeypairCmd = new Command("generate-secp256k1-keypair") | ||
| .description("Generates a secp256k1 keypair.") | ||
| .action((options) => { | ||
| main(options, generateSecp256k1Keypair).catch((err) => console.error("Oh no, something went wrong.\n", err)); | ||
| }); | ||
| const InitEnvCmd = new Command("init-env") | ||
@@ -401,2 +417,3 @@ .description("Initialize your environment with required variables.") | ||
| .addCommand(generateNodeKeysCmd) | ||
| .addCommand(generateSecp256k1KeypairCmd) | ||
| .addCommand(InitEnvCmd) | ||
@@ -403,0 +420,0 @@ .addHelpCommand() |
+5
-3
| { | ||
| "name": "@lightsparkdev/lightspark-cli", | ||
| "version": "0.0.10", | ||
| "version": "0.0.11", | ||
| "description": "CLI for the Lightspark JS sdk", | ||
@@ -34,2 +34,3 @@ "main": "./dist/index.js", | ||
| "@types/qrcode-terminal": "^0.12.0", | ||
| "@types/secp256k1": "^4.0.3", | ||
| "eslint": "^8.3.0", | ||
@@ -52,5 +53,6 @@ "eslint-watch": "^8.0.0", | ||
| "jose": "^4.14.4", | ||
| "jsonwebtoken": "^9.0.0", | ||
| "qrcode-terminal": "^0.12.0" | ||
| "jsonwebtoken": "^9.0.1", | ||
| "qrcode-terminal": "^0.12.0", | ||
| "secp256k1": "^5.0.0" | ||
| } | ||
| } |
+6
-0
@@ -62,1 +62,7 @@ // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved | ||
| }; | ||
| export const bytesToHex = (bytes: Uint8Array): string => { | ||
| return bytes.reduce((acc: string, byte: number) => { | ||
| return (acc += ("0" + byte.toString(16)).slice(-2)); | ||
| }, ""); | ||
| }; |
+28
-3
@@ -13,4 +13,6 @@ #!/usr/bin/env node | ||
| import { Command, InvalidArgumentError } from "commander"; | ||
| import { randomBytes } from "crypto"; | ||
| import * as fs from "fs/promises"; | ||
| import qrcode from "qrcode-terminal"; | ||
| import secp256k1 from "secp256k1"; | ||
| import { | ||
@@ -27,2 +29,3 @@ LightsparkSigner, | ||
| import { | ||
| bytesToHex, | ||
| getBitcoinNetworkOrThrow, | ||
@@ -452,5 +455,3 @@ getNodeId, | ||
| const seedAsHex = seed.as_bytes().reduce((acc: string, byte: number) => { | ||
| return (acc += ("0" + byte.toString(16)).slice(-2)); | ||
| }, ""); | ||
| const seedAsHex = bytesToHex(seed.as_bytes()); | ||
| console.log(`Seed phrase:\n${mnemonic.as_string()}\n`); | ||
@@ -461,2 +462,17 @@ console.log(`Hex-encoded seed:\n${seedAsHex}\n`); | ||
| const generateSecp256k1Keypair = async () => { | ||
| let privateKey; | ||
| do { | ||
| privateKey = randomBytes(32); | ||
| } while (!secp256k1.privateKeyVerify(privateKey)); | ||
| const publicKey = secp256k1.publicKeyCreate(privateKey); | ||
| const publicKeyAsHex = bytesToHex(publicKey); | ||
| const privateKeyAsHex = bytesToHex(privateKey); | ||
| console.log(`Hex-encoded public key: \n${publicKeyAsHex}\n`); | ||
| console.log(`Hex-encoded private key: \n${privateKeyAsHex}\n`); | ||
| }; | ||
| const safeParseInt = (value: string /* dummyPrevious: any */) => { | ||
@@ -648,2 +664,10 @@ // parseInt takes a string and a radix | ||
| const generateSecp256k1KeypairCmd = new Command("generate-secp256k1-keypair") | ||
| .description("Generates a secp256k1 keypair.") | ||
| .action((options) => { | ||
| main(options, generateSecp256k1Keypair).catch((err) => | ||
| console.error("Oh no, something went wrong.\n", err), | ||
| ); | ||
| }); | ||
| const InitEnvCmd = new Command("init-env") | ||
@@ -680,2 +704,3 @@ .description("Initialize your environment with required variables.") | ||
| .addCommand(generateNodeKeysCmd) | ||
| .addCommand(generateSecp256k1KeypairCmd) | ||
| .addCommand(InitEnvCmd) | ||
@@ -682,0 +707,0 @@ .addHelpCommand() |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
328437
0.64%1950
2.47%10
11.11%14
7.69%+ Added
+ Added
+ Added
+ Added
Updated