From 20bd34b0147e0dcbd039523487035d43823ac267 Mon Sep 17 00:00:00 2001 From: Dave Puchyr Date: Thu, 25 Feb 2021 15:51:45 +0100 Subject: [PATCH 1/8] Add Starname (IOV) support --- src/js/cosmos-util.js | 8 ++++---- src/js/index.js | 26 ++++++++++++++++++++------ tests/spec/tests.js | 10 ++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/js/cosmos-util.js b/src/js/cosmos-util.js index a7f4605..e3a0ddf 100644 --- a/src/js/cosmos-util.js +++ b/src/js/cosmos-util.js @@ -1,13 +1,13 @@ -function CosmosBufferToPublic(pubBuf) { +function CosmosBufferToPublic(pubBuf, hrp = "cosmos") { const Buffer = libs.buffer.Buffer; const AminoSecp256k1PubkeyPrefix = Buffer.from("EB5AE987", "hex"); const AminoSecp256k1PubkeyLength = Buffer.from("21", "hex"); pubBuf = Buffer.concat([AminoSecp256k1PubkeyPrefix, AminoSecp256k1PubkeyLength, pubBuf]); - return libs.bech32.encode("cosmospub", libs.bech32.toWords(pubBuf)); + return libs.bech32.encode(`${hrp}pub`, libs.bech32.toWords(pubBuf)); } -function CosmosBufferToAddress(pubBuf) { +function CosmosBufferToAddress(pubBuf, hrp = "cosmos") { const sha256_ed = libs.createHash("sha256").update(pubBuf).digest(); const ripemd160_ed = libs.createHash("rmd160").update(sha256_ed).digest(); - return libs.bech32.encode("cosmos", libs.bech32.toWords(ripemd160_ed)); + return libs.bech32.encode(hrp, libs.bech32.toWords(ripemd160_ed)); } diff --git a/src/js/index.js b/src/js/index.js index c502208..0bc2506 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1350,21 +1350,21 @@ } // ZooBC address format may vary - if (networks[DOM.network.val()].name == "ZBC - ZooBlockchain") { - + if (networks[DOM.network.val()].name == "ZBC - ZooBlockchain") { + var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); var coin = parseIntNoNaN(DOM.bip44coin.val(), 0); var path = "m/"; path += purpose + "'/"; path += coin + "'/" + index + "'"; var result = libs.zoobcUtil.getKeypair(path, seed); - + let publicKey = result.pubKey.slice(1, 33); let privateKey = result.key; - + privkey = privateKey.toString('hex'); pubkey = publicKey.toString('hex'); - + indexText = path; address = libs.zoobcUtil.getZBCAddress(publicKey, 'ZBC'); } @@ -1425,7 +1425,14 @@ privkey = keyPair.d.toBuffer().toString("base64"); } - //Groestlcoin Addresses are different + if (networks[DOM.network.val()].name == "IOV - Starname") { + const hrp = "star"; + address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer(), hrp); + pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer(), hrp); + privkey = keyPair.d.toBuffer().toString("base64"); + } + + //Groestlcoin Addresses are different if(isGRS()) { if (isSegwit) { @@ -2851,6 +2858,13 @@ }, }, { + name: "IOV - Starname", + onSelect: function() { + network = libs.bitcoin.networks.bitcoin; + setHdCoin(234); + }, + }, + { name: "IXC - Ixcoin", onSelect: function() { network = libs.bitcoin.networks.ixcoin; diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 257cd7b..e33d618 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -1355,6 +1355,16 @@ it('Allows selection of Iop', function(done) { }; testNetwork(done, params); }); +it('Allows selection of Starname', function(done) { + var params = { + selectText: "IOV - Starname", + phrase: "abandon abandon ability", + firstAddress: "star1xgfvgq40r7ff8ylw9l95dw56xnr0pvtjnlp7h4", + firstPubKey: "starpub1addwnpepqg9x5cft48hcgx25vyzeyygntl7pt763datr6v50hrecafyane54xlqdxkd", + firstPrivKey: "bGI4BNRvMYT1lbCOoH000HvNFPkyXms9n3Xp1X/7E80=", + }; + testNetwork(done, params); +}); it('Allows selection of Ixcoin', function(done) { var params = { selectText: "IXC - Ixcoin", From 43bef4e19d623cfb46aa224ed5f7495d945d327a Mon Sep 17 00:00:00 2001 From: a00a63 Date: Sat, 27 Mar 2021 14:04:07 +0100 Subject: [PATCH 2/8] Add Terra (LUNA) support --- src/js/cosmos-util.js | 8 ++++---- src/js/index.js | 19 +++++++++++++++++-- tests/spec/tests.js | 10 ++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/js/cosmos-util.js b/src/js/cosmos-util.js index a7f4605..e3a0ddf 100644 --- a/src/js/cosmos-util.js +++ b/src/js/cosmos-util.js @@ -1,13 +1,13 @@ -function CosmosBufferToPublic(pubBuf) { +function CosmosBufferToPublic(pubBuf, hrp = "cosmos") { const Buffer = libs.buffer.Buffer; const AminoSecp256k1PubkeyPrefix = Buffer.from("EB5AE987", "hex"); const AminoSecp256k1PubkeyLength = Buffer.from("21", "hex"); pubBuf = Buffer.concat([AminoSecp256k1PubkeyPrefix, AminoSecp256k1PubkeyLength, pubBuf]); - return libs.bech32.encode("cosmospub", libs.bech32.toWords(pubBuf)); + return libs.bech32.encode(`${hrp}pub`, libs.bech32.toWords(pubBuf)); } -function CosmosBufferToAddress(pubBuf) { +function CosmosBufferToAddress(pubBuf, hrp = "cosmos") { const sha256_ed = libs.createHash("sha256").update(pubBuf).digest(); const ripemd160_ed = libs.createHash("rmd160").update(sha256_ed).digest(); - return libs.bech32.encode("cosmos", libs.bech32.toWords(ripemd160_ed)); + return libs.bech32.encode(hrp, libs.bech32.toWords(ripemd160_ed)); } diff --git a/src/js/index.js b/src/js/index.js index c502208..1f251a3 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1420,11 +1420,19 @@ } if (networks[DOM.network.val()].name == "ATOM - Cosmos Hub") { - address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer()); - pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer()); + const hrp = "cosmos"; + address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer(), hrp); + pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer(), hrp); privkey = keyPair.d.toBuffer().toString("base64"); } + if (networks[DOM.network.val()].name == "LUNA - Terra") { + const hrp = "terra"; + address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer(), hrp); + pubkey = keyPair.getPublicKeyBuffer().toString("hex"); + privkey = keyPair.d.toBuffer().toString("hex"); + } + //Groestlcoin Addresses are different if(isGRS()) { @@ -2939,6 +2947,13 @@ setHdCoin(221); }, }, + { + name: "LUNA - Terra", + onSelect: function() { + network = libs.bitcoin.networks.bitcoin; + setHdCoin(330); + }, + }, { name: "LYNX - Lynx", onSelect: function() { diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 257cd7b..d8f1fa0 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -927,6 +927,16 @@ it('Allows selection of Cosmos Hub', function(done) { }; testNetwork(done, params); }); +it('Allows selection of Terra', function(done) { + var params = { + selectText: "LUNA - Terra", + phrase: "abandon abandon ability", + firstAddress: "terra1txr4jwel3vjl64vrc08pljnjryqkhtffmyp265", + firstPubKey: "028e7658e3debb2d9d458919bfba0e85b0220e845f7552176f30a52acd0f809d71", + firstPrivKey: "d611b211e370aa1edd9743acd6ce537d16fade85d7ae7e88b32f3a0483f52535", + }; + testNetwork(done, params); +}); it('Allows selection of Auroracoin', function(done) { var params = { selectText: "AUR - Auroracoin", From 942de1bc5e8d4a5c900267f1b486e2d56725acf2 Mon Sep 17 00:00:00 2001 From: xwcdev Date: Sun, 28 Mar 2021 18:54:12 +0800 Subject: [PATCH 3/8] change xwc to xwcc,add new xwc --- src/index.html | 1 + src/js/index.js | 15 ++++++++++++++- src/js/xwc-util.js | 28 ++++++++++++++++++++++++++++ tests/spec/tests.js | 12 +++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/js/xwc-util.js diff --git a/src/index.html b/src/index.html index 0588171..cc84247 100644 --- a/src/index.html +++ b/src/index.html @@ -1104,6 +1104,7 @@ + diff --git a/src/js/index.js b/src/js/index.js index c502208..9c627e8 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1424,6 +1424,12 @@ pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer()); privkey = keyPair.d.toBuffer().toString("base64"); } + if (networks[DOM.network.val()].name == "XWC - Whitecoin"){ + address = XWCbufferToAddress(keyPair.getPublicKeyBuffer()); + pubkey = XWCbufferToPublic(keyPair.getPublicKeyBuffer()); + privkey = XWCbufferToPrivate(keyPair.d.toBuffer(32)); + + } //Groestlcoin Addresses are different if(isGRS()) { @@ -3568,7 +3574,7 @@ }, }, { - name: "XWC - Whitecoin", + name: "XWCC - Whitecoin Classic", onSelect: function() { network = libs.bitcoin.networks.whitecoin; setHdCoin(155); @@ -3609,6 +3615,13 @@ setHdCoin(121); }, }, + { + name: "XWC - Whitecoin", + onSelect: function() { + network = libs.bitcoin.networks.bitcoin; + setHdCoin(559); + }, + } ] var clients = [ diff --git a/src/js/xwc-util.js b/src/js/xwc-util.js new file mode 100644 index 0000000..fc47d05 --- /dev/null +++ b/src/js/xwc-util.js @@ -0,0 +1,28 @@ +function XWCbufferToAddress(pubBuf){ + const Buffer = libs.buffer.Buffer; + const XWC_ADDRESS_PREFIX = "XWC"; + const XWC_NORMAL_ADDRESS_VERSION = "35" + let addrData = libs.createHash("rmd160").update( libs.createHash("sha512").update(pubBuf).digest()).digest(); + let addrBuf = Buffer.concat([Buffer.from(XWC_NORMAL_ADDRESS_VERSION, "hex") ,addrData]) + let checksum = libs.createHash("rmd160").update(addrBuf).digest("hex").slice(0, 8); + addrBuf = Buffer.concat([addrBuf, Buffer.from(checksum, "hex")]); + return XWC_ADDRESS_PREFIX.concat(libs.bs58.encode(addrBuf)); +} + +function XWCbufferToPublic(pubBuf) { + const Buffer = libs.buffer.Buffer; + const XWC_PUBLIC_PREFIX = "XWC"; + let checksum = libs.createHash("rmd160").update(pubBuf).digest("hex").slice(0, 8); + pubBuf = Buffer.concat([pubBuf, Buffer.from(checksum, "hex")]); + return XWC_PUBLIC_PREFIX.concat(libs.bs58.encode(pubBuf)); +} + +function XWCbufferToPrivate(privBuf) { + const Buffer = libs.buffer.Buffer; + const XWC_PRIVATE_PREFIX = "80"; + privBuf = Buffer.concat([Buffer.from(XWC_PRIVATE_PREFIX, "hex"), privBuf]); + let tmp = libs.createHash("sha256").update(privBuf).digest(); + let checksum = libs.createHash("sha256").update(tmp).digest("hex").slice(0, 8); + privBuf = Buffer.concat([privBuf, Buffer.from(checksum, "hex")]); + return libs.bs58.encode(privBuf); +} diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 257cd7b..879405e 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -1877,7 +1877,7 @@ it('Allows selection of VeChain', function(done) { }); it('Allows selection of Whitecoin', function(done) { var params = { - selectText: "XWC - Whitecoin", + selectText: "XWCC - Whitecoin Classic", phrase: "abandon abandon ability", firstAddress: "WcSwCAUqrSgeSYbsaS3SSWWhsx8KRYTFDR", firstPubKey: "03d3f4fa758f6260bfb39664d248a32258b53a90a71224db056ee79abaa3e9f208", @@ -1885,6 +1885,16 @@ it('Allows selection of Whitecoin', function(done) { }; testNetwork(done, params); }); +it('Allows selection of Whitecoin', function(done) { + var params = { + selectText: "XWC - Whitecoin", + phrase: "abandon abandon ability", + firstAddress: "XWCNY5EQsC55ifxRVEbP7H28yc3TMXC2pqsb5", + firstPubKey: "XWC68fEy4cCc8G1UWyeMPnQ5NjEhMUFSvu1oz4gLKxvj3dPvh7v18", + firstPrivKey: "5K8toD6TYy5DMHkxjpywXNLj4M6CjZAT5h12uhRuVuBBRtci8Zw", + }; + testNetwork(done, params); +}); it('Allows selection of Wincoin', function(done) { var params = { selectText: "WC - Wincoin", From b500a60e28da9726e882a7d6963d59c2732d4d70 Mon Sep 17 00:00:00 2001 From: xwcdev Date: Sun, 28 Mar 2021 19:13:33 +0800 Subject: [PATCH 4/8] fix test title --- tests/spec/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 879405e..f3dee1b 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -1875,7 +1875,7 @@ it('Allows selection of VeChain', function(done) { }; testNetwork(done, params); }); -it('Allows selection of Whitecoin', function(done) { +it('Allows selection of Whitecoin Classic', function(done) { var params = { selectText: "XWCC - Whitecoin Classic", phrase: "abandon abandon ability", From 1820b6ac67fde197ed4ef72ab3cf9646ed98c64a Mon Sep 17 00:00:00 2001 From: J62 Date: Mon, 29 Mar 2021 19:46:51 -0700 Subject: [PATCH 5/8] add bitcoin private testnet support --- src/js/bitcoinjs-extensions.js | 11 +++++++++++ src/js/index.js | 17 ++++++++++++----- tests/spec/tests.js | 10 ++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js index 84de8da..cc28677 100644 --- a/src/js/bitcoinjs-extensions.js +++ b/src/js/bitcoinjs-extensions.js @@ -1531,6 +1531,17 @@ libs.bitcoin.networks.bitcoinprivate = { wif: 0x80, }; +libs.bitcoin.networks.bitcoinprivatetestnet = { + messagePrefix: '\x18BitcoinPrivate Signed Message:\n', + bip32: { + public: 0x043587CF, + private: 0x04358394, + }, + pubKeyHash: 0x1957, + scriptHash: 0x19E0, + wif: 0xEF, +}; + libs.bitcoin.networks.bitcoinz = { messagePrefix: '\x18BitcoinZ Signed Message:\n', bip32: { diff --git a/src/js/index.js b/src/js/index.js index c502208..1da98ba 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1350,21 +1350,21 @@ } // ZooBC address format may vary - if (networks[DOM.network.val()].name == "ZBC - ZooBlockchain") { - + if (networks[DOM.network.val()].name == "ZBC - ZooBlockchain") { + var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); var coin = parseIntNoNaN(DOM.bip44coin.val(), 0); var path = "m/"; path += purpose + "'/"; path += coin + "'/" + index + "'"; var result = libs.zoobcUtil.getKeypair(path, seed); - + let publicKey = result.pubKey.slice(1, 33); let privateKey = result.key; - + privkey = privateKey.toString('hex'); pubkey = publicKey.toString('hex'); - + indexText = path; address = libs.zoobcUtil.getZBCAddress(publicKey, 'ZBC'); } @@ -2389,6 +2389,13 @@ setHdCoin(183); }, }, + { + name: "BTCPt - Bitcoin Private Testnet", + onSelect: function() { + network = libs.bitcoin.networks.bitcoinprivatetestnet; + setHdCoin(1); + }, + }, { name: "BSC - Binance Smart Chain", onSelect: function() { diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 257cd7b..8b3cdeb 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -987,6 +987,16 @@ it('Allows selection of Bitcoin Private', function(done) { }; testNetwork(done, params); }); +it('Allows selection of Bitcoin Private testnet', function(done) { + var params = { + selectText: "BTCPt - Bitcoin Private Testnet", + phrase: "abandon abandon ability", + firstAddress: "n1UcUUSDfDppfzh7XLJNHmZkLdbTQg3VAZL", + firstPubKey: "0382a5450765e2025bdb5f7d109c9254a11ef97a566228bf171d80ecb348763bb0", + firstPrivKey: "cV3coiYD2NhHKfhC6Gb8DzpvPzcGYYExYxuNxpUtKq3VUJrkFLZx", + }; + testNetwork(done, params); +}); it('Allows selection of Bitcoin SV', function(done) { var params = { selectText: "BSV - BitcoinSV", From 85711db3bbad8cbc1176410e4320aaa24b0bcee7 Mon Sep 17 00:00:00 2001 From: Sylvia G Date: Tue, 6 Apr 2021 03:18:04 +0300 Subject: [PATCH 6/8] fix bip85 mode to work without mnemonic (using xprv or entropy) --- src/js/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/js/index.js b/src/js/index.js index c502208..9a32cbc 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -495,13 +495,12 @@ var app = DOM.bip85application.val(); - var phrase = DOM.phrase.val(); - var passphrase = DOM.passphrase.val(); - if (!phrase) { + var rootKey = DOM.rootKey.val(); + if (!rootKey) { return; } try { - var master = libs.bip85.BIP85.fromMnemonic(phrase, passphrase); + var master = libs.bip85.BIP85.fromBase58(rootKey); var result; From 5b5b11fd96bd2446751c84283648ed22e4f5e06f Mon Sep 17 00:00:00 2001 From: Sylvia G Date: Tue, 6 Apr 2021 03:55:40 +0300 Subject: [PATCH 7/8] fix "blank mnemonic" error when only using a BIP39 seed (no mnemonic phrase) and then changing the coin --- src/js/index.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/js/index.js b/src/js/index.js index c502208..072d489 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -209,12 +209,7 @@ var network = networks[networkIndex]; network.onSelect(); adjustNetworkForSegwit(); - if (seed != null) { - phraseChanged(); - } - else { - rootKeyChanged(); - } + rootKeyChanged(); } function bip32ClientChanged(e) { From 18d64d9586fbb668e411b865c0cae17b04b14857 Mon Sep 17 00:00:00 2001 From: Sylvia G Date: Tue, 6 Apr 2021 04:32:20 +0300 Subject: [PATCH 8/8] fix bip85 root key when using non-xprv version bytes --- src/js/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/js/index.js b/src/js/index.js index 9a32cbc..e329fa1 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -495,12 +495,16 @@ var app = DOM.bip85application.val(); - var rootKey = DOM.rootKey.val(); - if (!rootKey) { + var rootKeyBase58 = DOM.rootKey.val(); + if (!rootKeyBase58) { return; } try { - var master = libs.bip85.BIP85.fromBase58(rootKey); + // try parsing using base network params + // The bip85 lib only understands xpubs, so compute it + var rootKey = libs.bitcoin.HDNode.fromBase58(rootKeyBase58, network); + rootKey.keyPair.network = libs.bitcoin.networks['bitcoin'] + var master = libs.bip85.BIP85.fromBase58(rootKey.toBase58()); var result;