Skip to content

Commit 1a12046

Browse files
committed
move bip39 const
1 parent 33054f1 commit 1a12046

File tree

4 files changed

+65
-66
lines changed

4 files changed

+65
-66
lines changed

assets_js_bitrequest_bip39.js

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
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+
135
$(document).ready(function() {
236
//istrial
337
//bipv_pass
@@ -153,19 +187,19 @@ function test_bip39() {
153187
bip39_fail();
154188
return
155189
}
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),
158192
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
160194
bip39_fail();
161195
return
162196
}
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) {
164198
bip39_fail();
165199
const coinsToDeriveFailure = ["bitcoin", "litecoin", "dogecoin", "dash", "ethereum", "bitcoin-cash", "monero", "nano"];
166200
derive_fail(coinsToDeriveFailure);
167201
coinsToDeriveFailure.forEach(coin => {
168-
glob_const.c_derive[coin] = false;
202+
bip39_const.c_derive[coin] = false;
169203
});
170204
}
171205
const derivationChecks = [{
@@ -195,20 +229,20 @@ function test_bip39() {
195229
}) {
196230
if (check() === false) {
197231
derive_fail([coin]);
198-
glob_const.c_derive[coin] = false;
232+
bip39_const.c_derive[coin] = false;
199233
}
200234
});
201235
// check xpub derivation
202236
if (xpub_check() === false) { // test for btc xpub derivation
203237
const xpubFailCoins = ["bitcoin", "litecoin", "dogecoin", "dash", "bitcoin-cash"];
204238
derive_xpub_fail(xpubFailCoins);
205239
xpubFailCoins.forEach(coin => {
206-
glob_const.can_xpub[coin] = false;
240+
bip39_const.can_xpub[coin] = false;
207241
});
208242
}
209243
if (eth_xpub_check() === false) { // test for ethereum xpub derivation
210244
derive_xpub_fail(["ethereum"]);
211-
glob_const.can_xpub.ethereum = false;
245+
bip39_const.can_xpub.ethereum = false;
212246
}
213247
}
214248

@@ -242,16 +276,16 @@ function derive_xpub_fail(arr) {
242276
function test_derivation() {
243277
try {
244278
const currency = "bitcoin",
245-
test_rootkey = get_rootkey(glob_const.expected_seed),
279+
test_rootkey = get_rootkey(bip39_const.expected_seed),
246280
bip32dat = getbip32dat(currency),
247281
dx_dat = {
248282
"dpath": "m/44'/0'/0'/0/0",
249283
"key": test_rootkey.slice(0, 64),
250284
"cc": test_rootkey.slice(64)
251285
},
252286
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;
255289
} catch (e) {
256290
console.error(e.name, e.message);
257291
return false;
@@ -263,7 +297,7 @@ function bech32_check() {
263297
try {
264298
const bip84_pub = "03bb4a626f63436a64d7cf1e441713cc964c0d53289a5b17acb1b9c262be57cb17",
265299
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;
267301
} catch (e) {
268302
console.error(e.name, e.message);
269303
return false;
@@ -275,7 +309,7 @@ function cashaddr_check() {
275309
try {
276310
const bch_legacy = "1AVPurYZinnctgGPiXziwU6PuyZKX5rYZU",
277311
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;
279313
} catch (e) {
280314
console.error(e.name, e.message);
281315
return false;
@@ -286,7 +320,7 @@ function cashaddr_check() {
286320
function nano_check() {
287321
try {
288322
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;
290324
return expected_nano_address === xnano_address;
291325
} catch (e) {
292326
console.error(e.name, e.message);
@@ -298,7 +332,7 @@ function nano_check() {
298332
function xmr_check() { // https://coinomi.github.io/tools/bip39/
299333
try {
300334
const expected_xmr_address = "477h3C6E6C4VLMR36bQL3yLcA8Aq3jts1AHLzm5QXipDdXVCYPnKEvUKykh2GTYqkkeQoTEhWpzvVQ4rMgLM1YpeD6qdHbS",
301-
ssk = get_ssk(glob_const.expected_seed, true),
335+
ssk = get_ssk(bip39_const.expected_seed, true),
302336
xko = xmr_getpubs(ssk, 0);
303337
return xko.address === expected_xmr_address;
304338
} catch (e) {
@@ -323,7 +357,7 @@ function xpub_check() {
323357
key_object = format_keys(null, x_keys_dat, bip32dat, 0, currency),
324358
xpub_address = key_object.address,
325359
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;
327361
} catch (e) {
328362
console.error(e.name, e.message);
329363
return false;
@@ -335,7 +369,7 @@ function eth_xpub_check() {
335369
try {
336370
const eth_pub = "03c026c4b041059c84a187252682b6f80cbbe64eb81497111ab6914b050a8936fd",
337371
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;
339373
} catch (e) {
340374
console.error(e.name, e.message);
341375
return false;
@@ -346,7 +380,7 @@ function eth_xpub_check() {
346380

347381
// Checks derivation method for a given currency
348382
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]) {
350384
const activepub = active_xpub(currency);
351385
if (cxpub(currency) && activepub) {
352386
return "xpub";
@@ -381,7 +415,7 @@ function is_xpub(currency) {
381415

382416
// Checks if a currency can use extended public keys
383417
function cxpub(currency) {
384-
return !!glob_const.can_xpub[currency];
418+
return !!bip39_const.can_xpub[currency];
385419
}
386420

387421
// Retrieves BIP32 data for a given currency
@@ -1138,7 +1172,7 @@ function derive_all(phrase, seedid, extra) {
11381172
const currency = coinconfig.currency,
11391173
coindat = coinconfig.data,
11401174
bip32 = coinconfig.settings.Xpub;
1141-
if (bip32.active && glob_const.c_derive[currency]) {
1175+
if (bip32.active && bip39_const.c_derive[currency]) {
11421176
const keycc = {
11431177
"seed": seed,
11441178
"key": master_key,
@@ -1165,7 +1199,7 @@ function derive_add_address(currency, ad) {
11651199

11661200
// Retrieves derivation data for a given currency
11671201
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]) {
11691203
const coindat = getcoindata(currency),
11701204
bip32 = getbip32dat(currency),
11711205
activepub = active_xpub(currency);
@@ -1645,7 +1679,7 @@ function format_keys(seed, key_object, bip32, index, coin) {
16451679

16461680
// Retrieves the extended public key prefix for a given currency
16471681
function xpub_prefix(currency) {
1648-
const test_rootkey = get_rootkey(glob_const.expected_seed),
1682+
const test_rootkey = get_rootkey(bip39_const.expected_seed),
16491683
dx_dat = {
16501684
"dpath": "m/0",
16511685
"key": test_rootkey.slice(0, 64),
@@ -1792,7 +1826,7 @@ function phrase_info_pu(coin) {
17921826
segw_node = $("<li class='clearfix" + coinclass + "' data-currency='" + currency + "'><strong>SegWit:</strong><div class='toggle_segwit ait'>" + switchpanel(hsw, " custom") + "</div></li>");
17931827
}
17941828
}
1795-
if (glob_const.c_derive[currency]) {
1829+
if (bip39_const.c_derive[currency]) {
17961830
$("#pi_icons").append(icon_node);
17971831
$("#d_paths").append(dp_node);
17981832
$("#xpub_box").append(xp_node);
@@ -1910,7 +1944,7 @@ function test_derive_function(thisnode, prev) {
19101944
dp_node = thisnode.closest(".d_path"),
19111945
dnd = dp_node.data(),
19121946
currency = dnd.currency;
1913-
if (glob_const.c_derive[currency]) {
1947+
if (bip39_const.c_derive[currency]) {
19141948
const test_derive_box = dp_node.find(".td_box"),
19151949
td_prev = dp_node.find(".td_prev"),
19161950
count = 5,

assets_js_bitrequest_coin_settings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ function test_append_rpc(thiscurrency, optionlist, key, value, selected) {
474474
"id": 1,
475475
"method": "eth_subscribe",
476476
"params": ["logs", {
477-
"address": glob_const.expected_eth_address,
477+
"address": bip39_const.expected_eth_address,
478478
"topics": []
479479
}]
480480
});
@@ -614,10 +614,10 @@ function test_rpc(rpc_input_box, rpc_data, currency) {
614614
}
615615
const rpcurl = get_rpc_url(rpc_data),
616616
testadress = {
617-
"bitcoin": glob_const.expected_bech32,
617+
"bitcoin": bip39_const.expected_bech32,
618618
"litecoin": "LZakyXotaE29Pehw21SoPuU832UhvJp4LG",
619619
"dogecoin": "DKvWg8UhQSycj1J8QVxeBDkRpbjDkw3DiW",
620-
"bitcoin-cash": glob_const.expected_bch_cashaddr
620+
"bitcoin-cash": bip39_const.expected_bch_cashaddr
621621
} [currency] || "",
622622
pload = glob_let.is_btc ? {
623623
"api_url": rpcurl + "/api/address/" + testadress + "/txs",
@@ -688,7 +688,7 @@ function test_rpc(rpc_input_box, rpc_data, currency) {
688688
"id": 1,
689689
"method": "eth_subscribe",
690690
"params": ["logs", {
691-
"address": glob_const.expected_eth_address,
691+
"address": bip39_const.expected_eth_address,
692692
"topics": []
693693
}]
694694
});

assets_js_bitrequest_core.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ $(document).ready(function() {
5858
selectbox();
5959
pickselect();
6060
canceldialogtrigger();
61-
console.log({
62-
"config": glob_config
63-
});
61+
console.log({glob_config});
6462
})
6563

6664
// Check for PHP support by fetching fiat currencies from local API PHP file
@@ -530,9 +528,7 @@ function finishfunctions() {
530528

531529
setTimeout(function() { // wait for ios app detection
532530
detectapp();
533-
console.log({
534-
glob_const
535-
});
531+
console.log({glob_const});
536532
}, 700);
537533
//getapp
538534
close_app_panel();
@@ -2137,7 +2133,7 @@ function addaddress(ad, edit) {
21372133
"currency": currency
21382134
}) + "</span>",
21392135
derive_seed_str = "<span id='option_makeseed' class='address_option' data-currency='" + currency + "'>" + translate("generatewallet") + "</span>",
2140-
options = glob_let.hasbip ? choose_wallet_str : (glob_let.test_derive && glob_const.c_derive[currency]) ? (hasbip32(currency) === true ? derive_seed_str : choose_wallet_str) : choose_wallet_str,
2136+
options = glob_let.hasbip ? choose_wallet_str : (glob_let.test_derive && bip39_const.c_derive[currency]) ? (hasbip32(currency) === true ? derive_seed_str : choose_wallet_str) : choose_wallet_str,
21412137
pnotify = glob_const.body.hasClass("showstartpage") ? "<div class='popnotify' style='display:block'>" + options + "</div>" : "<div class='popnotify'></div>",
21422138
scanqr = glob_let.hascam && !edit ? "<div class='qrscanner' data-currency='" + currency + "' data-id='address' title='scan qr-code'><span class='icon-qrcode'></span></div>" : "",
21432139
title = edit ? "<h2 class='icon-pencil'>" + translate("editlabel") + "</h2>" : "<h2>" + getcc_icon(ad.cmcid, cpid, ad.erc20) + " " + translate("addcoinaddress", {

assets_js_lib_global_queries.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,6 @@ const br_bipobj = br_get_local("bpdat", true),
6262
"sec_kas_wss": "wss://api-v2-do.kas.fyi",
6363
"aws_bucket": "https://brq.s3.us-west-2.amazonaws.com/",
6464
"cmc_icon_loc": "https://s2.coinmarketcap.com/static/img/coins/200x200/",
65-
// 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)
66-
"test_phrase": "army van defense carry jealous true garbage claim echo media make crunch", // random phrase used for test derive
67-
"expected_seed": "5b56c417303faa3fcba7e57400e120a0ca83ec5a4fc9ffba757fbe63fbd77a89a1a3be4c67196f57c39a88b76373733891bfaba16ed27a813ceed498804c0570", // expected seed used for test derive
68-
"expected_address": "1HQ3rb7nyLPrjnuW85MUknPekwkn7poAUm", // expected addres used for test derive
69-
"expected_bech32": "bc1qg0azlj4w2lrq8jssrrz6eprt2fe7f7edm4vpd5", // expected bech32 addres used for test derive
70-
"expected_bch_cashaddr": "qp5p0eur784pk8wxy2kzlz3ctnq5whfnuqqpp78u22",
71-
"expected_eth_address": "0x2161DedC3Be05B7Bb5aa16154BcbD254E9e9eb68",
72-
"c_derive": {
73-
"bitcoin": true,
74-
"litecoin": true,
75-
"dogecoin": true,
76-
"dash": true,
77-
"nano": true,
78-
"monero": true,
79-
"ethereum": true,
80-
"bitcoin-cash": true,
81-
"nimiq": false,
82-
"kaspa": false
83-
},
84-
"can_xpub": {
85-
"bitcoin": true,
86-
"litecoin": true,
87-
"dogecoin": true,
88-
"dash": true,
89-
"nano": false,
90-
"monero": false,
91-
"ethereum": true,
92-
"bitcoin-cash": true,
93-
"nimiq": false,
94-
"kaspa": false
95-
},
9665
"ls_support": check_local(),
9766
"has_bigint": hasbigint(),
9867
"useragent": br_useragent,

0 commit comments

Comments
 (0)