mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-29 13:36:01 +00:00
Allow BitPay address format for bitcoin cash
This commit is contained in:
@@ -575,6 +575,16 @@
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h2>Derived Addresses</h2>
|
<h2>Derived Addresses</h2>
|
||||||
<p>Note these addreses are derived from the BIP32 Extended Key</p>
|
<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">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<th>
|
<th>
|
||||||
|
|||||||
@@ -250,3 +250,14 @@ bitcoinjs.bitcoin.networks.nubits = {
|
|||||||
scriptHash: 0x1a,
|
scriptHash: 0x1a,
|
||||||
wif: 0x96,
|
wif: 0x96,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bitcoinjs.bitcoin.networks.bitcoinCashBitbpay = {
|
||||||
|
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||||
|
bip32: {
|
||||||
|
public: 0x0488b21e,
|
||||||
|
private: 0x0488ade4
|
||||||
|
},
|
||||||
|
pubKeyHash: 0x1c,
|
||||||
|
scriptHash: 0x28,
|
||||||
|
wif: 0x80
|
||||||
|
};
|
||||||
|
|||||||
+24
-1
@@ -75,6 +75,8 @@
|
|||||||
DOM.generatedStrength = $(".generate-container .strength");
|
DOM.generatedStrength = $(".generate-container .strength");
|
||||||
DOM.hardenedAddresses = $(".hardened-addresses");
|
DOM.hardenedAddresses = $(".hardened-addresses");
|
||||||
DOM.useP2wpkhNestedInP2sh = $(".p2wpkh-nested-in-p2sh");
|
DOM.useP2wpkhNestedInP2sh = $(".p2wpkh-nested-in-p2sh");
|
||||||
|
DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container");
|
||||||
|
DOM.useBitpayAddresses = $(".use-bitpay-addresses");
|
||||||
DOM.addresses = $(".addresses");
|
DOM.addresses = $(".addresses");
|
||||||
DOM.rowsToAdd = $(".rows-to-add");
|
DOM.rowsToAdd = $(".rows-to-add");
|
||||||
DOM.more = $(".more");
|
DOM.more = $(".more");
|
||||||
@@ -117,6 +119,7 @@
|
|||||||
DOM.publicKeyToggle.on("click", togglePublicKeys);
|
DOM.publicKeyToggle.on("click", togglePublicKeys);
|
||||||
DOM.privateKeyToggle.on("click", togglePrivateKeys);
|
DOM.privateKeyToggle.on("click", togglePrivateKeys);
|
||||||
DOM.languages.on("click", languageChanged);
|
DOM.languages.on("click", languageChanged);
|
||||||
|
DOM.useBitpayAddresses.on("change", useBitpayAddressesChange);
|
||||||
setQrEvents(DOM.showQrEls);
|
setQrEvents(DOM.showQrEls);
|
||||||
disableForms();
|
disableForms();
|
||||||
hidePending();
|
hidePending();
|
||||||
@@ -131,6 +134,7 @@
|
|||||||
clearDerivedKeys();
|
clearDerivedKeys();
|
||||||
clearAddressesList();
|
clearAddressesList();
|
||||||
DOM.litecoinLtubContainer.addClass("hidden");
|
DOM.litecoinLtubContainer.addClass("hidden");
|
||||||
|
DOM.useBitpayAddressesContainer.addClass("hidden");
|
||||||
var networkIndex = e.target.value;
|
var networkIndex = e.target.value;
|
||||||
var network = networks[networkIndex];
|
var network = networks[networkIndex];
|
||||||
network.onSelect();
|
network.onSelect();
|
||||||
@@ -347,6 +351,11 @@
|
|||||||
}, 50);
|
}, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useBitpayAddressesChange() {
|
||||||
|
setBitcoinCashNetworkValues();
|
||||||
|
phraseChanged();
|
||||||
|
}
|
||||||
|
|
||||||
function toggleIndexes() {
|
function toggleIndexes() {
|
||||||
showIndex = !showIndex;
|
showIndex = !showIndex;
|
||||||
$("td.index span").toggleClass("invisible");
|
$("td.index span").toggleClass("invisible");
|
||||||
@@ -1207,12 +1216,26 @@
|
|||||||
DOM.useP2wpkhNestedInP2sh.prop("checked", false);
|
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 = [
|
var networks = [
|
||||||
{
|
{
|
||||||
name: "BCH - Bitcoin Cash",
|
name: "BCH - Bitcoin Cash",
|
||||||
p2wpkhNestedInP2shAvailable: false,
|
p2wpkhNestedInP2shAvailable: false,
|
||||||
onSelect: function() {
|
onSelect: function() {
|
||||||
network = bitcoinjs.bitcoin.networks.bitcoin;
|
DOM.useBitpayAddressesContainer.removeClass("hidden");
|
||||||
|
setBitcoinCashNetworkValues();
|
||||||
setHdCoin(145);
|
setHdCoin(145);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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...
|
// If you wish to add more tests, do so here...
|
||||||
|
|
||||||
// Here is a blank test template
|
// Here is a blank test template
|
||||||
|
|||||||
Reference in New Issue
Block a user