-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
58 lines (45 loc) · 1.84 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
process.title = "Segwit Bitcoin Wallet Generator in Nodejs by Corvus Codex";
//Creaded by: Corvus Codex
//Github: https://github.com/CorvusCodex/
//Licence : MIT License
//Support my work:
//BTC: bc1q7wth254atug2p4v9j3krk9kauc0ehys2u8tgg3
//ETH & BNB: 0x68B6D33Ad1A3e0aFaDA60d6ADf8594601BE492F0
//Buy me a coffee: https://www.buymeacoffee.com/CorvusCodex
// Importing required modules
const CoinKey = require('coinkey');
const fs = require('fs');
const crypto = require('crypto');
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const blessed = require('blessed');
const bip39 = require('bip39');
const ecc = require('tiny-secp256k1');
const { BIP32Factory } = require('bip32');
const bitcoin = require('bitcoinjs-lib');
// You must wrap a tiny-secp256k1 compatible implementation
const bip32 = BIP32Factory(ecc);
let seedPhrase = bip39.generateMnemonic();
console.log("Seed Phrase: " + seedPhrase);
// Generate a seed buffer from the seed phrase
const seedBuffer = bip39.mnemonicToSeedSync(seedPhrase);
//console.log(seedBuffer);
// Generate a root node from the seed buffer using the bip32 library
const root = bip32.fromSeed(seedBuffer);
//console.log(root);
// Derive the first account's node (m/44'/0'/0')
const account = root.derivePath("m/44'/0'/0'");
//console.log(account);
// Derive the external chain node of this account (m/44'/0'/0'/0)
const node = account.derivePath("0");
//console.log(node);
// Derive the first address from the external chain (m/44'/0'/0'/0/0)
const child = node.derive(0);
//console.log(child);
// Get the public key for this address
const publicKey = child.publicKey;
//console.log(publicKey);
// Generate a P2WPKH (Pay-to-Witness-Public-Key-Hash) output script
const { address } = bitcoin.payments.p2wpkh({ pubkey: publicKey });
console.log("Address: " + address);