mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-06 02:43:49 +00:00
Allow BitPay address format for bitcoin cash
This commit is contained in:
@@ -575,6 +575,16 @@
|
||||
<div class="col-md-12">
|
||||
<h2>Derived Addresses</h2>
|
||||
<p>Note these addreses are derived from the BIP32 Extended Key</p>
|
||||
</div>
|
||||
<div class="col-md-12 use-bitpay-addresses-container hidden">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" class="use-bitpay-addresses">
|
||||
<span>Use BitPay-style addresses for Bitcoin Cash (ie starting with 'C' instead of '1')</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<th>
|
||||
|
||||
@@ -250,3 +250,14 @@ bitcoinjs.bitcoin.networks.nubits = {
|
||||
scriptHash: 0x1a,
|
||||
wif: 0x96,
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.bitcoinCashBitbpay = {
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4
|
||||
},
|
||||
pubKeyHash: 0x1c,
|
||||
scriptHash: 0x28,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
@@ -75,6 +75,8 @@
|
||||
DOM.generatedStrength = $(".generate-container .strength");
|
||||
DOM.hardenedAddresses = $(".hardened-addresses");
|
||||
DOM.useP2wpkhNestedInP2sh = $(".p2wpkh-nested-in-p2sh");
|
||||
DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container");
|
||||
DOM.useBitpayAddresses = $(".use-bitpay-addresses");
|
||||
DOM.addresses = $(".addresses");
|
||||
DOM.rowsToAdd = $(".rows-to-add");
|
||||
DOM.more = $(".more");
|
||||
@@ -117,6 +119,7 @@
|
||||
DOM.publicKeyToggle.on("click", togglePublicKeys);
|
||||
DOM.privateKeyToggle.on("click", togglePrivateKeys);
|
||||
DOM.languages.on("click", languageChanged);
|
||||
DOM.useBitpayAddresses.on("change", useBitpayAddressesChange);
|
||||
setQrEvents(DOM.showQrEls);
|
||||
disableForms();
|
||||
hidePending();
|
||||
@@ -131,6 +134,7 @@
|
||||
clearDerivedKeys();
|
||||
clearAddressesList();
|
||||
DOM.litecoinLtubContainer.addClass("hidden");
|
||||
DOM.useBitpayAddressesContainer.addClass("hidden");
|
||||
var networkIndex = e.target.value;
|
||||
var network = networks[networkIndex];
|
||||
network.onSelect();
|
||||
@@ -347,6 +351,11 @@
|
||||
}, 50);
|
||||
}
|
||||
|
||||
function useBitpayAddressesChange() {
|
||||
setBitcoinCashNetworkValues();
|
||||
phraseChanged();
|
||||
}
|
||||
|
||||
function toggleIndexes() {
|
||||
showIndex = !showIndex;
|
||||
$("td.index span").toggleClass("invisible");
|
||||
@@ -1207,12 +1216,26 @@
|
||||
DOM.useP2wpkhNestedInP2sh.prop("checked", false);
|
||||
}
|
||||
|
||||
function useBitpayAddresses() {
|
||||
return !(DOM.useBitpayAddresses.prop("checked"));
|
||||
}
|
||||
|
||||
function setBitcoinCashNetworkValues() {
|
||||
if (useBitpayAddresses()) {
|
||||
network = bitcoinjs.bitcoin.networks.bitcoin;
|
||||
}
|
||||
else {
|
||||
network = bitcoinjs.bitcoin.networks.bitcoinCashBitbpay;
|
||||
}
|
||||
}
|
||||
|
||||
var networks = [
|
||||
{
|
||||
name: "BCH - Bitcoin Cash",
|
||||
p2wpkhNestedInP2shAvailable: false,
|
||||
onSelect: function() {
|
||||
network = bitcoinjs.bitcoin.networks.bitcoin;
|
||||
DOM.useBitpayAddressesContainer.removeClass("hidden");
|
||||
setBitcoinCashNetworkValues();
|
||||
setHdCoin(145);
|
||||
},
|
||||
},
|
||||
|
||||
31
tests.js
31
tests.js
@@ -4404,6 +4404,37 @@ page.open(url, function(status) {
|
||||
});
|
||||
},
|
||||
|
||||
// Bitcoin Cash address can be set to use bitpay format
|
||||
function() {
|
||||
page.open(url, function(status) {
|
||||
// set the phrase and coin and address format
|
||||
var expected = "CZnpA9HPmvhuhLLPWJP8rNDpLUYXy1LXFk";
|
||||
page.evaluate(function() {
|
||||
$(".use-bitpay-addresses").prop("checked", true);
|
||||
$(".phrase").val("abandon abandon ability");
|
||||
$(".phrase").trigger("input");
|
||||
$(".network option[selected]").removeAttr("selected");
|
||||
$(".network option").filter(function() {
|
||||
return $(this).html() == "BCH - Bitcoin Cash";
|
||||
}).prop("selected", true);
|
||||
$(".network").trigger("change");
|
||||
});
|
||||
// check the address is generated correctly
|
||||
waitForGenerate(function() {
|
||||
var actual = page.evaluate(function() {
|
||||
return $(".address:first").text();
|
||||
});
|
||||
if (actual != expected) {
|
||||
console.log("Bitcoin Cash address is incorrect");
|
||||
console.log("Expected: " + expected);
|
||||
console.log("Actual: " + actual);
|
||||
fail();
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// If you wish to add more tests, do so here...
|
||||
|
||||
// Here is a blank test template
|
||||
|
||||
Reference in New Issue
Block a user