-
Notifications
You must be signed in to change notification settings - Fork 0
/
BTCWAG.js
121 lines (85 loc) · 3.79 KB
/
BTCWAG.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @author Wyjson
* @version 1
* @date 2022-03-15 16:13:25
* 离线生成BTC钱包靓号地址(Generate an Bitcoin wallet good account number offline)
* 1. npm install [email protected]
* 2. npm install [email protected]
* 3. npm install bitcoinjs-lib
* 4. npm install tiny-secp256k1
*/
const bip39 = require('bip39');
const bip32 = require('bip32');
const bitcoin = require('bitcoinjs-lib');
const network = bitcoin.networks.bitcoin;
const ecc = require('tiny-secp256k1');
bitcoin.initEccLib(ecc);
//靓号正则
const _w4 = new RegExp("^([\\w])\\1{3,}","g");// 前4位相同
const w4_ = new RegExp("([\\w])\\1{3,}$","g");// 前4位相同
const aabb = new RegExp("^(.)\\1(.)\\2","g");// AABB
const mBitcoin = new RegExp("^Bitcoin","gi");// 以Bitcoin开头
const mBTC = new RegExp("^BTC","gi");// 以BTC开头
const mAddress = new RegExp("^address","gi");// 以address开头
for(;;){
// let mnemonic = "love slogan menu thunder liquid pave economy subject deposit organ trick loyal";
let mnemonic = bip39.generateMnemonic();
let seed = bip39.mnemonicToSeedSync(mnemonic);
// Legacy (P2PKH)格式 1LuXraXCFcWCMVWqnjigvZMmjSBmHY4Vez
let path = bip32.fromSeed(seed).derivePath("m/44'/0'/0'/0/0");
let privateKey = path.toWIF();
let p2pkh = bitcoin.payments.p2pkh({ pubkey: path.publicKey, network : network });
let address = p2pkh.address;
// Nested SegWit (P2SH)格式 3LoE438ufVn99qgaX5Gwvi22iAgKBzF9Hd
let swPath = bip32.fromSeed(seed).derivePath("m/49'/0'/0'/0/0");
let privateKey3 = swPath.toWIF();
let p2wpkh = bitcoin.payments.p2sh({ redeem: bitcoin.payments.p2wpkh({ pubkey: swPath.publicKey, network : network }) })
let address3 = p2wpkh.address;
// Native SegWit (Bech32)格式 bc1qjmfmsaj2mvgd7n46qrms6avlu0ku4qgrns9x7w
let bech32Path = bip32.fromSeed(seed).derivePath("m/84'/0'/0'/0/0");
let privateKey3bc1q = bech32Path.toWIF();
let bc1q = bitcoin.payments.p2wpkh({ pubkey: bech32Path.publicKey, network : network });
let address3bc1q = bc1q.address;
// Taproot (P2TR)格式 bc1ptyurxq9h7v4p6va48pd4nhu5lup9ttszhpnn3fggg59dup6j9n9srk3030
let bech32mPath = bip32.fromSeed(seed).derivePath("m/86'/0'/0'/0/0");
let privateKey3bc1p = bech32mPath.toWIF();
let bc1p = bitcoin.payments.p2tr({ internalPubkey: bech32mPath.publicKey.slice(1, 33), network : network });
let address3bc1p = bc1p.address;
let isLog = false;
if (_w4.exec(address3bc1p.substring(4)) != null) {
isLog = true;
console.log("正则(^w4)")
}
if (w4_.exec(address3bc1p.substring(4)) != null) {
isLog = true;
console.log("正则(w4$)")
}
if (aabb.exec(address3bc1p.substring(4)) != null) {
isLog = true;
console.log("正则(^AABB)")
}
if (mAddress.exec(address3bc1p.substring(4)) != null) {
isLog = true;
console.log("正则(^Address)")
}
if (mBitcoin.exec(address3bc1p.substring(4)) != null) {
isLog = true;
console.log("正则(^Bitcoin)")
}
if (mBTC.exec(address3bc1p.substring(4)) != null) {
isLog = true;
console.log("正则(^BTC)")
}
if (isLog) {
// console.log(`地址Legacy (P2PKH): ${address}`);
// console.log(`私钥Legacy (P2PKH): ${privateKey}`);
// console.log(`地址Nested SegWit (P2SH): ${address3}`);
// console.log(`私钥Nested SegWit (P2SH): ${privateKey3}`);
// console.log(`地址Native SegWit (Bech32): ${address3bc1q}`);
// console.log(`私钥Native SegWit (Bech32): ${privateKey3bc1q}`);
console.log(`地址Taproot (P2TR): ${address3bc1p}`);
// console.log(`私钥Taproot (P2TR): ${privateKey3bc1p}`);
console.log(`助记词: ${mnemonic}`)
console.log("-------------------------------------------------------------------")
}
}