diff options
-rw-r--r-- | src/index.html | 10 | ||||
-rw-r--r-- | src/js/bitcoinjs-extensions.js | 11 | ||||
-rw-r--r-- | src/js/index.js | 25 | ||||
-rw-r--r-- | tests.js | 31 |
4 files changed, 76 insertions, 1 deletions
diff --git a/src/index.html b/src/index.html index 281e48c..9da3e25 100644 --- a/src/index.html +++ b/src/index.html | |||
@@ -575,6 +575,16 @@ | |||
575 | <div class="col-md-12"> | 575 | <div class="col-md-12"> |
576 | <h2>Derived Addresses</h2> | 576 | <h2>Derived Addresses</h2> |
577 | <p>Note these addreses are derived from the BIP32 Extended Key</p> | 577 | <p>Note these addreses are derived from the BIP32 Extended Key</p> |
578 | </div> | ||
579 | <div class="col-md-12 use-bitpay-addresses-container hidden"> | ||
580 | <div class="checkbox"> | ||
581 | <label> | ||
582 | <input type="checkbox" class="use-bitpay-addresses"> | ||
583 | <span>Use BitPay-style addresses for Bitcoin Cash (ie starting with 'C' instead of '1')</span> | ||
584 | </label> | ||
585 | </div> | ||
586 | </div> | ||
587 | <div class="col-md-12"> | ||
578 | <table class="table table-striped"> | 588 | <table class="table table-striped"> |
579 | <thead> | 589 | <thead> |
580 | <th> | 590 | <th> |
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js index 661e089..4448c7f 100644 --- a/src/js/bitcoinjs-extensions.js +++ b/src/js/bitcoinjs-extensions.js | |||
@@ -250,3 +250,14 @@ bitcoinjs.bitcoin.networks.nubits = { | |||
250 | scriptHash: 0x1a, | 250 | scriptHash: 0x1a, |
251 | wif: 0x96, | 251 | wif: 0x96, |
252 | }; | 252 | }; |
253 | |||
254 | bitcoinjs.bitcoin.networks.bitcoinCashBitbpay = { | ||
255 | messagePrefix: '\x18Bitcoin Signed Message:\n', | ||
256 | bip32: { | ||
257 | public: 0x0488b21e, | ||
258 | private: 0x0488ade4 | ||
259 | }, | ||
260 | pubKeyHash: 0x1c, | ||
261 | scriptHash: 0x28, | ||
262 | wif: 0x80 | ||
263 | }; | ||
diff --git a/src/js/index.js b/src/js/index.js index d61c314..b1559ef 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -75,6 +75,8 @@ | |||
75 | DOM.generatedStrength = $(".generate-container .strength"); | 75 | DOM.generatedStrength = $(".generate-container .strength"); |
76 | DOM.hardenedAddresses = $(".hardened-addresses"); | 76 | DOM.hardenedAddresses = $(".hardened-addresses"); |
77 | DOM.useP2wpkhNestedInP2sh = $(".p2wpkh-nested-in-p2sh"); | 77 | DOM.useP2wpkhNestedInP2sh = $(".p2wpkh-nested-in-p2sh"); |
78 | DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container"); | ||
79 | DOM.useBitpayAddresses = $(".use-bitpay-addresses"); | ||
78 | DOM.addresses = $(".addresses"); | 80 | DOM.addresses = $(".addresses"); |
79 | DOM.rowsToAdd = $(".rows-to-add"); | 81 | DOM.rowsToAdd = $(".rows-to-add"); |
80 | DOM.more = $(".more"); | 82 | DOM.more = $(".more"); |
@@ -117,6 +119,7 @@ | |||
117 | DOM.publicKeyToggle.on("click", togglePublicKeys); | 119 | DOM.publicKeyToggle.on("click", togglePublicKeys); |
118 | DOM.privateKeyToggle.on("click", togglePrivateKeys); | 120 | DOM.privateKeyToggle.on("click", togglePrivateKeys); |
119 | DOM.languages.on("click", languageChanged); | 121 | DOM.languages.on("click", languageChanged); |
122 | DOM.useBitpayAddresses.on("change", useBitpayAddressesChange); | ||
120 | setQrEvents(DOM.showQrEls); | 123 | setQrEvents(DOM.showQrEls); |
121 | disableForms(); | 124 | disableForms(); |
122 | hidePending(); | 125 | hidePending(); |
@@ -131,6 +134,7 @@ | |||
131 | clearDerivedKeys(); | 134 | clearDerivedKeys(); |
132 | clearAddressesList(); | 135 | clearAddressesList(); |
133 | DOM.litecoinLtubContainer.addClass("hidden"); | 136 | DOM.litecoinLtubContainer.addClass("hidden"); |
137 | DOM.useBitpayAddressesContainer.addClass("hidden"); | ||
134 | var networkIndex = e.target.value; | 138 | var networkIndex = e.target.value; |
135 | var network = networks[networkIndex]; | 139 | var network = networks[networkIndex]; |
136 | network.onSelect(); | 140 | network.onSelect(); |
@@ -347,6 +351,11 @@ | |||
347 | }, 50); | 351 | }, 50); |
348 | } | 352 | } |
349 | 353 | ||
354 | function useBitpayAddressesChange() { | ||
355 | setBitcoinCashNetworkValues(); | ||
356 | phraseChanged(); | ||
357 | } | ||
358 | |||
350 | function toggleIndexes() { | 359 | function toggleIndexes() { |
351 | showIndex = !showIndex; | 360 | showIndex = !showIndex; |
352 | $("td.index span").toggleClass("invisible"); | 361 | $("td.index span").toggleClass("invisible"); |
@@ -1207,12 +1216,26 @@ | |||
1207 | DOM.useP2wpkhNestedInP2sh.prop("checked", false); | 1216 | DOM.useP2wpkhNestedInP2sh.prop("checked", false); |
1208 | } | 1217 | } |
1209 | 1218 | ||
1219 | function useBitpayAddresses() { | ||
1220 | return !(DOM.useBitpayAddresses.prop("checked")); | ||
1221 | } | ||
1222 | |||
1223 | function setBitcoinCashNetworkValues() { | ||
1224 | if (useBitpayAddresses()) { | ||
1225 | network = bitcoinjs.bitcoin.networks.bitcoin; | ||
1226 | } | ||
1227 | else { | ||
1228 | network = bitcoinjs.bitcoin.networks.bitcoinCashBitbpay; | ||
1229 | } | ||
1230 | } | ||
1231 | |||
1210 | var networks = [ | 1232 | var networks = [ |
1211 | { | 1233 | { |
1212 | name: "BCH - Bitcoin Cash", | 1234 | name: "BCH - Bitcoin Cash", |
1213 | p2wpkhNestedInP2shAvailable: false, | 1235 | p2wpkhNestedInP2shAvailable: false, |
1214 | onSelect: function() { | 1236 | onSelect: function() { |
1215 | network = bitcoinjs.bitcoin.networks.bitcoin; | 1237 | DOM.useBitpayAddressesContainer.removeClass("hidden"); |
1238 | setBitcoinCashNetworkValues(); | ||
1216 | setHdCoin(145); | 1239 | setHdCoin(145); |
1217 | }, | 1240 | }, |
1218 | }, | 1241 | }, |
@@ -4404,6 +4404,37 @@ page.open(url, function(status) { | |||
4404 | }); | 4404 | }); |
4405 | }, | 4405 | }, |
4406 | 4406 | ||
4407 | // Bitcoin Cash address can be set to use bitpay format | ||
4408 | function() { | ||
4409 | page.open(url, function(status) { | ||
4410 | // set the phrase and coin and address format | ||
4411 | var expected = "CZnpA9HPmvhuhLLPWJP8rNDpLUYXy1LXFk"; | ||
4412 | page.evaluate(function() { | ||
4413 | $(".use-bitpay-addresses").prop("checked", true); | ||
4414 | $(".phrase").val("abandon abandon ability"); | ||
4415 | $(".phrase").trigger("input"); | ||
4416 | $(".network option[selected]").removeAttr("selected"); | ||
4417 | $(".network option").filter(function() { | ||
4418 | return $(this).html() == "BCH - Bitcoin Cash"; | ||
4419 | }).prop("selected", true); | ||
4420 | $(".network").trigger("change"); | ||
4421 | }); | ||
4422 | // check the address is generated correctly | ||
4423 | waitForGenerate(function() { | ||
4424 | var actual = page.evaluate(function() { | ||
4425 | return $(".address:first").text(); | ||
4426 | }); | ||
4427 | if (actual != expected) { | ||
4428 | console.log("Bitcoin Cash address is incorrect"); | ||
4429 | console.log("Expected: " + expected); | ||
4430 | console.log("Actual: " + actual); | ||
4431 | fail(); | ||
4432 | } | ||
4433 | next(); | ||
4434 | }); | ||
4435 | }); | ||
4436 | }, | ||
4437 | |||
4407 | // If you wish to add more tests, do so here... | 4438 | // If you wish to add more tests, do so here... |
4408 | 4439 | ||
4409 | // Here is a blank test template | 4440 | // Here is a blank test template |