@@ -147,24 +147,22 @@ function bipv_pass() {
147
147
function test_bip39 ( ) {
148
148
if ( ! crypto ) { // test for window.crypto
149
149
bip39_fail ( ) ;
150
- glob_let . test_derive = false ;
151
150
return
152
151
}
153
152
if ( glob_const . has_bigint === false ) { // test for js BigInt
154
153
bip39_fail ( ) ;
155
- glob_let . test_derive = false ;
156
154
return
157
155
}
158
156
const k_str = glob_const . expected_seed . slice ( 0 , 32 ) ,
159
157
enc_test = aes_enc ( glob_const . test_phrase , k_str ) ,
160
158
dec_test = aes_dec ( enc_test , k_str ) ;
161
159
if ( glob_const . test_phrase !== dec_test ) { // test encryption
162
160
bip39_fail ( ) ;
163
- glob_let . test_derive = false ;
164
161
return
165
162
}
166
163
if ( toseed ( glob_const . test_phrase ) !== glob_const . expected_seed || test_derivation ( ) === false ) {
167
- const coinsToDeriveFailure = [ "bitcoin" , "litecoin" , "dogecoin" , "dash" , "ethereum" , "bitcoin-cash" ] ;
164
+ bip39_fail ( ) ;
165
+ const coinsToDeriveFailure = [ "bitcoin" , "litecoin" , "dogecoin" , "dash" , "ethereum" , "bitcoin-cash" , "monero" , "nano" ] ;
168
166
derive_fail ( coinsToDeriveFailure ) ;
169
167
coinsToDeriveFailure . forEach ( coin => {
170
168
glob_const . c_derive [ coin ] = false ;
@@ -174,6 +172,10 @@ function test_bip39() {
174
172
"check" : bech32_check ,
175
173
"coin" : "bitcoin"
176
174
} ,
175
+ {
176
+ "check" : bech32_check ,
177
+ "coin" : "litecoin"
178
+ } ,
177
179
{
178
180
"check" : cashaddr_check ,
179
181
"coin" : "bitcoin-cash"
@@ -187,10 +189,10 @@ function test_bip39() {
187
189
"coin" : "monero"
188
190
}
189
191
] ;
190
- derivationChecks . forEach ( ( {
192
+ derivationChecks . forEach ( function ( {
191
193
check,
192
194
coin
193
- } ) => {
195
+ } ) {
194
196
if ( check ( ) === false ) {
195
197
derive_fail ( [ coin ] ) ;
196
198
glob_const . c_derive [ coin ] = false ;
@@ -213,6 +215,7 @@ function test_bip39() {
213
215
// Handles BIP39 failure by adding a CSS class
214
216
function bip39_fail ( ) {
215
217
glob_const . body . addClass ( "nobip" ) ;
218
+ glob_let . test_derive = false ;
216
219
}
217
220
218
221
// Handles derivation failure for specified cryptocurrencies
@@ -237,71 +240,106 @@ function derive_xpub_fail(arr) {
237
240
238
241
// Tests derivation process for Bitcoin
239
242
function test_derivation ( ) {
240
- const currency = "bitcoin" ,
241
- test_rootkey = get_rootkey ( glob_const . expected_seed ) ,
242
- bip32dat = getbip32dat ( currency ) ,
243
- dx_dat = {
244
- "dpath" : "m/44'/0'/0'/0/0" ,
245
- "key" : test_rootkey . slice ( 0 , 64 ) ,
246
- "cc" : test_rootkey . slice ( 64 )
247
- } ,
248
- x_keys_dat = derive_x ( dx_dat ) ,
249
- key_object = format_keys ( glob_const . expected_seed , x_keys_dat , bip32dat , 0 , currency ) ;
250
- return key_object . address === glob_const . expected_address ;
243
+ try {
244
+ const currency = "bitcoin" ,
245
+ test_rootkey = get_rootkey ( glob_const . expected_seed ) ,
246
+ bip32dat = getbip32dat ( currency ) ,
247
+ dx_dat = {
248
+ "dpath" : "m/44'/0'/0'/0/0" ,
249
+ "key" : test_rootkey . slice ( 0 , 64 ) ,
250
+ "cc" : test_rootkey . slice ( 64 )
251
+ } ,
252
+ 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 ;
255
+ } catch ( e ) {
256
+ console . error ( e . name , e . message ) ;
257
+ return false ;
258
+ }
251
259
}
252
260
253
261
// Checks Bech32 address derivation
254
262
function bech32_check ( ) {
255
- const bip84_pub = "03bb4a626f63436a64d7cf1e441713cc964c0d53289a5b17acb1b9c262be57cb17" ,
256
- bip84_bech32 = pub_to_address_bech32 ( "bc" , bip84_pub ) ;
257
- return glob_const . expected_bech32 === bip84_bech32 ;
263
+ try {
264
+ const bip84_pub = "03bb4a626f63436a64d7cf1e441713cc964c0d53289a5b17acb1b9c262be57cb17" ,
265
+ bip84_bech32 = pub_to_address_bech32 ( "bc" , bip84_pub ) ;
266
+ return glob_const . expected_bech32 === bip84_bech32 ;
267
+ } catch ( e ) {
268
+ console . error ( e . name , e . message ) ;
269
+ return false ;
270
+ }
258
271
}
259
272
260
273
// Checks Bitcoin Cash cashaddr derivation
261
274
function cashaddr_check ( ) {
262
- const bch_legacy = "1AVPurYZinnctgGPiXziwU6PuyZKX5rYZU" ,
263
- bch_cashaddr = pub_to_cashaddr ( bch_legacy ) ;
264
- return glob_const . expected_bch_cashaddr === bch_cashaddr ;
275
+ try {
276
+ const bch_legacy = "1AVPurYZinnctgGPiXziwU6PuyZKX5rYZU" ,
277
+ bch_cashaddr = pub_to_cashaddr ( bch_legacy ) ;
278
+ return glob_const . expected_bch_cashaddr === bch_cashaddr ;
279
+ } catch ( e ) {
280
+ console . error ( e . name , e . message ) ;
281
+ return false ;
282
+ }
265
283
}
266
284
267
285
// Checks Nano address derivation
268
286
function nano_check ( ) {
269
- const expected_nano_address = "nano_1mbtirc4x3kixfy5wufxaqakd3gbojpn6gpmk6kjiyngnjwgy6yty3txgztq" ,
270
- xnano_address = NanocurrencyWeb . wallet . accounts ( glob_const . expected_seed , 0 , 0 ) [ 0 ] . address ;
271
- return expected_nano_address === xnano_address ;
287
+ try {
288
+ const expected_nano_address = "nano_1mbtirc4x3kixfy5wufxaqakd3gbojpn6gpmk6kjiyngnjwgy6yty3txgztq" ,
289
+ xnano_address = NanocurrencyWeb . wallet . accounts ( glob_const . expected_seed , 0 , 0 ) [ 0 ] . address ;
290
+ return expected_nano_address === xnano_address ;
291
+ } catch ( e ) {
292
+ console . error ( e . name , e . message ) ;
293
+ return false ;
294
+ }
272
295
}
273
296
274
297
// Checks Monero (XMR) address derivation
275
298
function xmr_check ( ) { // https://coinomi.github.io/tools/bip39/
276
- const expected_xmr_address = "477h3C6E6C4VLMR36bQL3yLcA8Aq3jts1AHLzm5QXipDdXVCYPnKEvUKykh2GTYqkkeQoTEhWpzvVQ4rMgLM1YpeD6qdHbS" ,
277
- ssk = get_ssk ( glob_const . expected_seed , true ) ,
278
- xko = xmr_getpubs ( ssk , 0 ) ;
279
- return xko . address === expected_xmr_address ;
299
+ try {
300
+ const expected_xmr_address = "477h3C6E6C4VLMR36bQL3yLcA8Aq3jts1AHLzm5QXipDdXVCYPnKEvUKykh2GTYqkkeQoTEhWpzvVQ4rMgLM1YpeD6qdHbS" ,
301
+ ssk = get_ssk ( glob_const . expected_seed , true ) ,
302
+ xko = xmr_getpubs ( ssk , 0 ) ;
303
+ return xko . address === expected_xmr_address ;
304
+ } catch ( e ) {
305
+ console . error ( e . name , e . message ) ;
306
+ return false ;
307
+ }
280
308
}
281
309
282
310
// Checks extended public key (xpub) derivation for Bitcoin
283
311
function xpub_check ( ) {
284
- const currency = "bitcoin" ,
285
- xpub_keycc = key_cc_xpub ( "xpub6Cy7dUR4ZKF22HEuVq7epRgRsoXfL2MK1RE81CSvp1ZySySoYGXk5PUY9y9Cc5ExpnSwXyimQAsVhyyPDNDrfj4xjDsKZJNYgsHXoEPNCYQ" ) ,
286
- dx_dat = {
287
- "dpath" : "M/0/0" ,
288
- "key" : xpub_keycc . key ,
289
- "cc" : xpub_keycc . cc ,
290
- "vb" : xpub_keycc . version
291
- } ,
292
- x_keys_dat = derive_x ( dx_dat ) ,
293
- bip32dat = getbip32dat ( currency ) ,
294
- key_object = format_keys ( null , x_keys_dat , bip32dat , 0 , currency ) ,
295
- xpub_address = key_object . address ,
296
- xpub_wildcard_address = "bc1qk0wlvl4xh3eqe5szqyrlcj4ws8633vz0vhhywl" ; // wildcard for bech32 Xpubs (Zpub)
297
- return xpub_address === glob_const . expected_address || xpub_address === xpub_wildcard_address ;
312
+ try {
313
+ const currency = "bitcoin" ,
314
+ xpub_keycc = key_cc_xpub ( "xpub6Cy7dUR4ZKF22HEuVq7epRgRsoXfL2MK1RE81CSvp1ZySySoYGXk5PUY9y9Cc5ExpnSwXyimQAsVhyyPDNDrfj4xjDsKZJNYgsHXoEPNCYQ" ) ,
315
+ dx_dat = {
316
+ "dpath" : "M/0/0" ,
317
+ "key" : xpub_keycc . key ,
318
+ "cc" : xpub_keycc . cc ,
319
+ "vb" : xpub_keycc . version
320
+ } ,
321
+ x_keys_dat = derive_x ( dx_dat ) ,
322
+ bip32dat = getbip32dat ( currency ) ,
323
+ key_object = format_keys ( null , x_keys_dat , bip32dat , 0 , currency ) ,
324
+ xpub_address = key_object . address ,
325
+ xpub_wildcard_address = "bc1qk0wlvl4xh3eqe5szqyrlcj4ws8633vz0vhhywl" ; // wildcard for bech32 Xpubs (Zpub)
326
+ return xpub_address === glob_const . expected_address || xpub_address === xpub_wildcard_address ;
327
+ } catch ( e ) {
328
+ console . error ( e . name , e . message ) ;
329
+ return false ;
330
+ }
298
331
}
299
332
300
333
// Checks Ethereum extended public key (xpub) derivation
301
334
function eth_xpub_check ( ) {
302
- const eth_pub = "03c026c4b041059c84a187252682b6f80cbbe64eb81497111ab6914b050a8936fd" ,
303
- eth_address = pub_to_eth_address ( eth_pub ) ;
304
- return glob_const . expected_eth_address === eth_address ;
335
+ try {
336
+ const eth_pub = "03c026c4b041059c84a187252682b6f80cbbe64eb81497111ab6914b050a8936fd" ,
337
+ eth_address = pub_to_eth_address ( eth_pub ) ;
338
+ return glob_const . expected_eth_address === eth_address ;
339
+ } catch ( e ) {
340
+ console . error ( e . name , e . message ) ;
341
+ return false ;
342
+ }
305
343
}
306
344
307
345
// Check derivations
@@ -1757,9 +1795,9 @@ function phrase_info_pu(coin) {
1757
1795
if ( glob_const . c_derive [ currency ] ) {
1758
1796
$ ( "#pi_icons" ) . append ( icon_node ) ;
1759
1797
$ ( "#d_paths" ) . append ( dp_node ) ;
1798
+ $ ( "#xpub_box" ) . append ( xp_node ) ;
1799
+ $ ( "#segw_box" ) . append ( segw_node ) ;
1760
1800
}
1761
- $ ( "#xpub_box" ) . append ( xp_node ) ;
1762
- $ ( "#segw_box" ) . append ( segw_node ) ;
1763
1801
$ ( "#supported_wallets" ) . append ( sw_node ) ;
1764
1802
pi_show ( ) ;
1765
1803
}
0 commit comments