1
+ // bip39 (All addresses / xpubs in this app are test addresses derived from the following testphrase, taken from https://github.com/bitcoinbook/bitcoinbook/blob/f8b883dcd4e3d1b9adf40fed59b7e898fbd9241f/ch05.asciidoc)
2
+ const bip39_const = {
3
+ "test_phrase" : "army van defense carry jealous true garbage claim echo media make crunch" , // random phrase used for test derive
4
+ "expected_seed" : "5b56c417303faa3fcba7e57400e120a0ca83ec5a4fc9ffba757fbe63fbd77a89a1a3be4c67196f57c39a88b76373733891bfaba16ed27a813ceed498804c0570" , // expected seed used for test derive
5
+ "expected_address" : "1HQ3rb7nyLPrjnuW85MUknPekwkn7poAUm" , // expected addres used for test derive
6
+ "expected_bech32" : "bc1qg0azlj4w2lrq8jssrrz6eprt2fe7f7edm4vpd5" , // expected bech32 addres used for test derive
7
+ "expected_bch_cashaddr" : "qp5p0eur784pk8wxy2kzlz3ctnq5whfnuqqpp78u22" ,
8
+ "expected_eth_address" : "0x2161DedC3Be05B7Bb5aa16154BcbD254E9e9eb68" ,
9
+ "c_derive" : {
10
+ "bitcoin" : true ,
11
+ "litecoin" : true ,
12
+ "dogecoin" : true ,
13
+ "dash" : true ,
14
+ "nano" : true ,
15
+ "monero" : true ,
16
+ "ethereum" : true ,
17
+ "bitcoin-cash" : true ,
18
+ "nimiq" : false ,
19
+ "kaspa" : false
20
+ } ,
21
+ "can_xpub" : {
22
+ "bitcoin" : true ,
23
+ "litecoin" : true ,
24
+ "dogecoin" : true ,
25
+ "dash" : true ,
26
+ "nano" : false ,
27
+ "monero" : false ,
28
+ "ethereum" : true ,
29
+ "bitcoin-cash" : true ,
30
+ "nimiq" : false ,
31
+ "kaspa" : false
32
+ }
33
+ }
34
+
1
35
$ ( document ) . ready ( function ( ) {
2
36
//istrial
3
37
//bipv_pass
@@ -153,19 +187,19 @@ function test_bip39() {
153
187
bip39_fail ( ) ;
154
188
return
155
189
}
156
- const k_str = glob_const . expected_seed . slice ( 0 , 32 ) ,
157
- enc_test = aes_enc ( glob_const . test_phrase , k_str ) ,
190
+ const k_str = bip39_const . expected_seed . slice ( 0 , 32 ) ,
191
+ enc_test = aes_enc ( bip39_const . test_phrase , k_str ) ,
158
192
dec_test = aes_dec ( enc_test , k_str ) ;
159
- if ( glob_const . test_phrase !== dec_test ) { // test encryption
193
+ if ( bip39_const . test_phrase !== dec_test ) { // test encryption
160
194
bip39_fail ( ) ;
161
195
return
162
196
}
163
- if ( toseed ( glob_const . test_phrase ) !== glob_const . expected_seed || test_derivation ( ) === false ) {
197
+ if ( toseed ( bip39_const . test_phrase ) !== bip39_const . expected_seed || test_derivation ( ) === false ) {
164
198
bip39_fail ( ) ;
165
199
const coinsToDeriveFailure = [ "bitcoin" , "litecoin" , "dogecoin" , "dash" , "ethereum" , "bitcoin-cash" , "monero" , "nano" ] ;
166
200
derive_fail ( coinsToDeriveFailure ) ;
167
201
coinsToDeriveFailure . forEach ( coin => {
168
- glob_const . c_derive [ coin ] = false ;
202
+ bip39_const . c_derive [ coin ] = false ;
169
203
} ) ;
170
204
}
171
205
const derivationChecks = [ {
@@ -195,20 +229,20 @@ function test_bip39() {
195
229
} ) {
196
230
if ( check ( ) === false ) {
197
231
derive_fail ( [ coin ] ) ;
198
- glob_const . c_derive [ coin ] = false ;
232
+ bip39_const . c_derive [ coin ] = false ;
199
233
}
200
234
} ) ;
201
235
// check xpub derivation
202
236
if ( xpub_check ( ) === false ) { // test for btc xpub derivation
203
237
const xpubFailCoins = [ "bitcoin" , "litecoin" , "dogecoin" , "dash" , "bitcoin-cash" ] ;
204
238
derive_xpub_fail ( xpubFailCoins ) ;
205
239
xpubFailCoins . forEach ( coin => {
206
- glob_const . can_xpub [ coin ] = false ;
240
+ bip39_const . can_xpub [ coin ] = false ;
207
241
} ) ;
208
242
}
209
243
if ( eth_xpub_check ( ) === false ) { // test for ethereum xpub derivation
210
244
derive_xpub_fail ( [ "ethereum" ] ) ;
211
- glob_const . can_xpub . ethereum = false ;
245
+ bip39_const . can_xpub . ethereum = false ;
212
246
}
213
247
}
214
248
@@ -242,16 +276,16 @@ function derive_xpub_fail(arr) {
242
276
function test_derivation ( ) {
243
277
try {
244
278
const currency = "bitcoin" ,
245
- test_rootkey = get_rootkey ( glob_const . expected_seed ) ,
279
+ test_rootkey = get_rootkey ( bip39_const . expected_seed ) ,
246
280
bip32dat = getbip32dat ( currency ) ,
247
281
dx_dat = {
248
282
"dpath" : "m/44'/0'/0'/0/0" ,
249
283
"key" : test_rootkey . slice ( 0 , 64 ) ,
250
284
"cc" : test_rootkey . slice ( 64 )
251
285
} ,
252
286
x_keys_dat = derive_x ( dx_dat ) ,
253
- key_object = format_keys ( glob_const . expected_seed , x_keys_dat , bip32dat , 0 , currency ) ;
254
- return key_object . address === glob_const . expected_address ;
287
+ key_object = format_keys ( bip39_const . expected_seed , x_keys_dat , bip32dat , 0 , currency ) ;
288
+ return key_object . address === bip39_const . expected_address ;
255
289
} catch ( e ) {
256
290
console . error ( e . name , e . message ) ;
257
291
return false ;
@@ -263,7 +297,7 @@ function bech32_check() {
263
297
try {
264
298
const bip84_pub = "03bb4a626f63436a64d7cf1e441713cc964c0d53289a5b17acb1b9c262be57cb17" ,
265
299
bip84_bech32 = pub_to_address_bech32 ( "bc" , bip84_pub ) ;
266
- return glob_const . expected_bech32 === bip84_bech32 ;
300
+ return bip39_const . expected_bech32 === bip84_bech32 ;
267
301
} catch ( e ) {
268
302
console . error ( e . name , e . message ) ;
269
303
return false ;
@@ -275,7 +309,7 @@ function cashaddr_check() {
275
309
try {
276
310
const bch_legacy = "1AVPurYZinnctgGPiXziwU6PuyZKX5rYZU" ,
277
311
bch_cashaddr = pub_to_cashaddr ( bch_legacy ) ;
278
- return glob_const . expected_bch_cashaddr === bch_cashaddr ;
312
+ return bip39_const . expected_bch_cashaddr === bch_cashaddr ;
279
313
} catch ( e ) {
280
314
console . error ( e . name , e . message ) ;
281
315
return false ;
@@ -286,7 +320,7 @@ function cashaddr_check() {
286
320
function nano_check ( ) {
287
321
try {
288
322
const expected_nano_address = "nano_1mbtirc4x3kixfy5wufxaqakd3gbojpn6gpmk6kjiyngnjwgy6yty3txgztq" ,
289
- xnano_address = NanocurrencyWeb . wallet . accounts ( glob_const . expected_seed , 0 , 0 ) [ 0 ] . address ;
323
+ xnano_address = NanocurrencyWeb . wallet . accounts ( bip39_const . expected_seed , 0 , 0 ) [ 0 ] . address ;
290
324
return expected_nano_address === xnano_address ;
291
325
} catch ( e ) {
292
326
console . error ( e . name , e . message ) ;
@@ -298,7 +332,7 @@ function nano_check() {
298
332
function xmr_check ( ) { // https://coinomi.github.io/tools/bip39/
299
333
try {
300
334
const expected_xmr_address = "477h3C6E6C4VLMR36bQL3yLcA8Aq3jts1AHLzm5QXipDdXVCYPnKEvUKykh2GTYqkkeQoTEhWpzvVQ4rMgLM1YpeD6qdHbS" ,
301
- ssk = get_ssk ( glob_const . expected_seed , true ) ,
335
+ ssk = get_ssk ( bip39_const . expected_seed , true ) ,
302
336
xko = xmr_getpubs ( ssk , 0 ) ;
303
337
return xko . address === expected_xmr_address ;
304
338
} catch ( e ) {
@@ -323,7 +357,7 @@ function xpub_check() {
323
357
key_object = format_keys ( null , x_keys_dat , bip32dat , 0 , currency ) ,
324
358
xpub_address = key_object . address ,
325
359
xpub_wildcard_address = "bc1qk0wlvl4xh3eqe5szqyrlcj4ws8633vz0vhhywl" ; // wildcard for bech32 Xpubs (Zpub)
326
- return xpub_address === glob_const . expected_address || xpub_address === xpub_wildcard_address ;
360
+ return xpub_address === bip39_const . expected_address || xpub_address === xpub_wildcard_address ;
327
361
} catch ( e ) {
328
362
console . error ( e . name , e . message ) ;
329
363
return false ;
@@ -335,7 +369,7 @@ function eth_xpub_check() {
335
369
try {
336
370
const eth_pub = "03c026c4b041059c84a187252682b6f80cbbe64eb81497111ab6914b050a8936fd" ,
337
371
eth_address = pub_to_eth_address ( eth_pub ) ;
338
- return glob_const . expected_eth_address === eth_address ;
372
+ return bip39_const . expected_eth_address === eth_address ;
339
373
} catch ( e ) {
340
374
console . error ( e . name , e . message ) ;
341
375
return false ;
@@ -346,7 +380,7 @@ function eth_xpub_check() {
346
380
347
381
// Checks derivation method for a given currency
348
382
function check_derivations ( currency ) {
349
- if ( glob_let . test_derive && glob_const . c_derive [ currency ] ) {
383
+ if ( glob_let . test_derive && bip39_const . c_derive [ currency ] ) {
350
384
const activepub = active_xpub ( currency ) ;
351
385
if ( cxpub ( currency ) && activepub ) {
352
386
return "xpub" ;
@@ -381,7 +415,7 @@ function is_xpub(currency) {
381
415
382
416
// Checks if a currency can use extended public keys
383
417
function cxpub ( currency ) {
384
- return ! ! glob_const . can_xpub [ currency ] ;
418
+ return ! ! bip39_const . can_xpub [ currency ] ;
385
419
}
386
420
387
421
// Retrieves BIP32 data for a given currency
@@ -1138,7 +1172,7 @@ function derive_all(phrase, seedid, extra) {
1138
1172
const currency = coinconfig . currency ,
1139
1173
coindat = coinconfig . data ,
1140
1174
bip32 = coinconfig . settings . Xpub ;
1141
- if ( bip32 . active && glob_const . c_derive [ currency ] ) {
1175
+ if ( bip32 . active && bip39_const . c_derive [ currency ] ) {
1142
1176
const keycc = {
1143
1177
"seed" : seed ,
1144
1178
"key" : master_key ,
@@ -1165,7 +1199,7 @@ function derive_add_address(currency, ad) {
1165
1199
1166
1200
// Retrieves derivation data for a given currency
1167
1201
function derive_data ( currency , extra ) {
1168
- if ( glob_let . test_derive === true && glob_const . c_derive [ currency ] ) {
1202
+ if ( glob_let . test_derive === true && bip39_const . c_derive [ currency ] ) {
1169
1203
const coindat = getcoindata ( currency ) ,
1170
1204
bip32 = getbip32dat ( currency ) ,
1171
1205
activepub = active_xpub ( currency ) ;
@@ -1645,7 +1679,7 @@ function format_keys(seed, key_object, bip32, index, coin) {
1645
1679
1646
1680
// Retrieves the extended public key prefix for a given currency
1647
1681
function xpub_prefix ( currency ) {
1648
- const test_rootkey = get_rootkey ( glob_const . expected_seed ) ,
1682
+ const test_rootkey = get_rootkey ( bip39_const . expected_seed ) ,
1649
1683
dx_dat = {
1650
1684
"dpath" : "m/0" ,
1651
1685
"key" : test_rootkey . slice ( 0 , 64 ) ,
@@ -1792,7 +1826,7 @@ function phrase_info_pu(coin) {
1792
1826
segw_node = $ ( "<li class='clearfix" + coinclass + "' data-currency='" + currency + "'><strong>SegWit:</strong><div class='toggle_segwit ait'>" + switchpanel ( hsw , " custom" ) + "</div></li>" ) ;
1793
1827
}
1794
1828
}
1795
- if ( glob_const . c_derive [ currency ] ) {
1829
+ if ( bip39_const . c_derive [ currency ] ) {
1796
1830
$ ( "#pi_icons" ) . append ( icon_node ) ;
1797
1831
$ ( "#d_paths" ) . append ( dp_node ) ;
1798
1832
$ ( "#xpub_box" ) . append ( xp_node ) ;
@@ -1910,7 +1944,7 @@ function test_derive_function(thisnode, prev) {
1910
1944
dp_node = thisnode . closest ( ".d_path" ) ,
1911
1945
dnd = dp_node . data ( ) ,
1912
1946
currency = dnd . currency ;
1913
- if ( glob_const . c_derive [ currency ] ) {
1947
+ if ( bip39_const . c_derive [ currency ] ) {
1914
1948
const test_derive_box = dp_node . find ( ".td_box" ) ,
1915
1949
td_prev = dp_node . find ( ".td_prev" ) ,
1916
1950
count = 5 ,
0 commit comments