mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-28 13:20:41 +00:00
Add P2WSH and P2WSH-P2SH for bitcoin and testnet
Address generation still to come.
This commit is contained in:
@@ -539,6 +539,22 @@
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
// try parsing using p2wsh network params
|
||||
if ("p2wsh" in n) {
|
||||
try {
|
||||
bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wsh);
|
||||
return;
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
// try parsing using p2wsh-in-p2sh network params
|
||||
if ("p2wshInP2sh" in n) {
|
||||
try {
|
||||
bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wshInP2sh);
|
||||
return;
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
}
|
||||
// try the network params as currently specified
|
||||
bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
|
||||
@@ -681,6 +697,22 @@
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
// try parsing using p2wsh network params
|
||||
if ("p2wsh" in n) {
|
||||
try {
|
||||
bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wsh);
|
||||
return "";
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
// try parsing using p2wsh-in-p2sh network params
|
||||
if ("p2wshInP2sh" in n) {
|
||||
try {
|
||||
bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wshInP2sh);
|
||||
return "";
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
}
|
||||
// try the network params as currently specified
|
||||
try {
|
||||
@@ -968,6 +1000,14 @@
|
||||
(bip141TabSelected() && DOM.bip141semantics.val() == "p2wpkh-p2sh");
|
||||
}
|
||||
|
||||
function p2wshSelected() {
|
||||
return bip141TabSelected() && DOM.bip141semantics.val() == "p2wsh";
|
||||
}
|
||||
|
||||
function p2wshInP2shSelected() {
|
||||
return (bip141TabSelected() && DOM.bip141semantics.val() == "p2wsh-p2sh");
|
||||
}
|
||||
|
||||
function TableRow(index, isLast) {
|
||||
|
||||
var self = this;
|
||||
@@ -979,6 +1019,8 @@
|
||||
var segwitAvailable = networkHasSegwit();
|
||||
var isP2wpkh = p2wpkhSelected();
|
||||
var isP2wpkhInP2sh = p2wpkhInP2shSelected();
|
||||
var isP2wsh = p2wshSelected();
|
||||
var isP2wshInP2sh = p2wshInP2shSelected();
|
||||
|
||||
function init() {
|
||||
calculateValues();
|
||||
@@ -1109,6 +1151,14 @@
|
||||
var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes);
|
||||
address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
|
||||
}
|
||||
else if (isP2wsh) {
|
||||
// TODO
|
||||
address = "";
|
||||
}
|
||||
else if (isP2wshInP2sh) {
|
||||
// TODO
|
||||
address = "";
|
||||
}
|
||||
}
|
||||
|
||||
if ((networks[DOM.network.val()].name == "CRW - Crown")) {
|
||||
@@ -1794,6 +1844,12 @@
|
||||
else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network) {
|
||||
network = network.p2wpkhInP2sh;
|
||||
}
|
||||
else if (p2wshSelected() && "p2wsh" in network) {
|
||||
network = network.p2wsh;
|
||||
}
|
||||
else if (p2wshInP2shSelected() && "p2wshInP2sh" in network) {
|
||||
network = network.p2wshInP2sh;
|
||||
}
|
||||
}
|
||||
|
||||
function lastIndexInTable() {
|
||||
|
||||
@@ -56,6 +56,62 @@ bitcoinjs.bitcoin.networks.testnet.p2wpkhInP2sh = {
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
// p2wsh
|
||||
|
||||
bitcoinjs.bitcoin.networks.bitcoin.p2wsh = {
|
||||
baseNetwork: "bitcoin",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
bip32: {
|
||||
public: 0x02aa7ed3,
|
||||
private: 0x02aa7a99
|
||||
},
|
||||
pubKeyHash: 0x00,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.testnet.p2wsh = {
|
||||
baseNetwork: "testnet",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'tb',
|
||||
bip32: {
|
||||
public: 0x02575483,
|
||||
private: 0x02575048
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
// p2wsh in p2sh
|
||||
|
||||
bitcoinjs.bitcoin.networks.bitcoin.p2wshInP2sh = {
|
||||
baseNetwork: "bitcoin",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
bip32: {
|
||||
public: 0x0295b43f,
|
||||
private: 0x0295b005
|
||||
},
|
||||
pubKeyHash: 0x00,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.testnet.p2wshInP2sh = {
|
||||
baseNetwork: "testnet",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'tb',
|
||||
bip32: {
|
||||
public: 0x024289ef,
|
||||
private: 0x024285b5
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.litecoin.p2wpkh = {
|
||||
baseNetwork: "litecoin",
|
||||
messagePrefix: '\x19Litecoin Signed Message:\n',
|
||||
|
||||
Reference in New Issue
Block a user