diff options
author | Ian Coleman <coleman.ian@gmail.com> | 2017-10-31 10:35:52 +1100 |
---|---|---|
committer | Ian Coleman <coleman.ian@gmail.com> | 2017-10-31 10:35:52 +1100 |
commit | fe8f2d140d9c9e260ebeab7135aa5197b27df406 (patch) | |
tree | c4960fae035c86a2fcb1a98e1c7b3230a4b713af /src | |
parent | 0cca6e893af22e7b6d4e3621a8a0bf3c68c00e41 (diff) | |
download | BIP39-fe8f2d140d9c9e260ebeab7135aa5197b27df406.tar.gz BIP39-fe8f2d140d9c9e260ebeab7135aa5197b27df406.tar.zst BIP39-fe8f2d140d9c9e260ebeab7135aa5197b27df406.zip |
Allow BitPay address format for bitcoin cash
Diffstat (limited to 'src')
-rw-r--r-- | src/index.html | 10 | ||||
-rw-r--r-- | src/js/bitcoinjs-extensions.js | 11 | ||||
-rw-r--r-- | src/js/index.js | 25 |
3 files changed, 45 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 | }, |