-
Notifications
You must be signed in to change notification settings - Fork 38
/
bitcoin-networks.js
169 lines (162 loc) · 4.49 KB
/
bitcoin-networks.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
window.allNetworks = [{
label: 'BTC (Bitcoin Regtest, legacy, BIP32/44)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'bcrt',
bip32: {public: 0x043587cf, private: 0x04358394},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin Regtest, SegWit, BIP49)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'bcrt',
bip32: {public: 0x044a5262, private: 0x044a4e28},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin Regtest, Native SegWit, BIP84)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'bcrt',
bip32: {public: 0x045f1cf6, private: 0x045f18bc},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin Signet, legacy, BIP32/44)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'tb',
bip32: {public: 0x043587cf, private: 0x04358394},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin Signet, SegWit, BIP49)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'tb',
bip32: {public: 0x044a5262, private: 0x044a4e28},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin Signet, Native SegWit, BIP84)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'tb',
bip32: {public: 0x045f1cf6, private: 0x045f18bc},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin Testnet, legacy, BIP32/44)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'tb',
bip32: {public: 0x043587cf, private: 0x04358394},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin Testnet, SegWit, BIP49)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'tb',
bip32: {public: 0x044a5262, private: 0x044a4e28},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin Testnet, Native SegWit, BIP84)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'tb',
bip32: {public: 0x045f1cf6, private: 0x045f18bc},
pubKeyHash: 111,
scriptHash: 196,
wif: 239,
bip44: 0x01
}
}, {
label: 'BTC (Bitcoin, legacy, BIP32/44)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'bc',
bip32: {public: 0x0488b21e, private: 0x0488ade4},
pubKeyHash: 0,
scriptHash: 5,
wif: 128,
bip44: 0x00
}
}, {
label: 'BTC (Bitcoin, SegWit, BIP49)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'bc',
bip32: {public: 0x049d7cb2, private: 0x049d7878},
pubKeyHash: 0,
scriptHash: 5,
wif: 128,
bip44: 0x00
}
}, {
label: 'BTC (Bitcoin, Native SegWit, BIP84)',
config: {
messagePrefix: '\u0018Bitcoin Signed Message:\n',
bech32: 'bc',
bip32: {public: 0x04b24746, private: 0x04b2430c},
pubKeyHash: 0,
scriptHash: 5,
wif: 128,
bip44: 0x00
}
}];
window.bitcoinNetworks = _.filter(allNetworks, n => n.config.bech32 && (n.config.bip44 === 0x00 || n.config.bip44 === 0x01));
function customToWIF(keyPair, network) {
return keyPair.toWIF();
}
function getP2PKHAddress(keyPair, network) {
return bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: network }).address;
}
function getP2WPKHAddress(keyPair, network) {
return bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey, network: network }).address;
}
function getNestedP2WPKHAddress(keyPair, network) {
const p2wpkh = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey, network: network });
return bitcoin.payments.p2sh({ redeem: p2wpkh }).address;
}
function getP2TRAddress(keyPair, network) {
const pubKey = bitcoin.ecurve.Point.decodeFrom(bitcoin.secp256k1, keyPair.publicKey);
const taprootPubkey = bitcoin.schnorr.taproot.taprootConstruct(pubKey);
const words = bitcoin.bech32.toWords(taprootPubkey);
words.unshift(1);
return bitcoin.bech32m.encode(network.bech32, words);
}
function calculateAddresses(keyPair, network) {
keyPair.address = getP2PKHAddress(keyPair, network);
if (network.bech32) {
keyPair.nestedP2WPKHAddress = getNestedP2WPKHAddress(keyPair, network);
keyPair.P2WPKHAddress = getP2WPKHAddress(keyPair, network);
keyPair.P2TRAddress = getP2TRAddress(keyPair, network);
}
}