From 0cb81e1117053c93debfa501a5bdb11169636dd2 Mon Sep 17 00:00:00 2001 From: jhonkus Date: Fri, 27 Nov 2020 06:27:21 +0800 Subject: Add ZooBC coin support --- src/js/bitcoinjs-extensions.js | 12 ++++++++++++ src/js/index.js | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js index 08a6be8..7e637e3 100644 --- a/src/js/bitcoinjs-extensions.js +++ b/src/js/bitcoinjs-extensions.js @@ -1553,6 +1553,18 @@ libs.bitcoin.networks.hush3 = { wif: 0xBC, }; +libs.bitcoin.networks.zoobc = { + messagePrefix: '\x18ZooBC Signed Message:\n', + bech32: 'bc', + bip32: { + public: 0x0488b21e, + private: 0x0488ade4, + }, + pubKeyHash: 0x00, + scriptHash: 0x05, + wif: 0x80, +}; + libs.bitcoin.networks.zclassic = { messagePrefix: '\x18Zcash Signed Message:\n', bip32: { diff --git a/src/js/index.js b/src/js/index.js index fd8c16b..61a2dd5 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -3540,6 +3540,13 @@ setHdCoin(136); }, }, + { + name: "ZBC - ZooBlockchain", + onSelect: function () { + network = libs.bitcoin.networks.zoobc; + setHdCoin(883); + }, + }, { name: "ZCL - Zclassic", onSelect: function() { -- cgit v1.2.3 From 6d2e202083c4166aa4be8557789a8a461df6bd5c Mon Sep 17 00:00:00 2001 From: jhonkus Date: Mon, 7 Dec 2020 20:25:25 +0800 Subject: Add ZooBC address format --- libs/combined/index.js | 33 +++++++++++++++++++++++++++++++++ src/js/index.js | 21 +++++++++++++++++++++ tests/spec/tests.js | 11 +++++++++++ 3 files changed, 65 insertions(+) diff --git a/libs/combined/index.js b/libs/combined/index.js index 99af3ce..d3bc7a5 100644 --- a/libs/combined/index.js +++ b/libs/combined/index.js @@ -2,6 +2,10 @@ module.exports.basex = require('base-x') +/* base32 */ + +module.exports.base32 = require('base32.js') + /* bchaddrjs */ module.exports.bchaddr = require('bchaddrjs') @@ -84,6 +88,35 @@ module.exports.stellarUtil = { }, } +/* zoobc-util */ + +let base32 = require('base32.js'); +let nbl = require('nebulas'); +module.exports.zoobcUtil = { + getKeypair: function (path, seed) { + const { key, chainCode} = edHd.derivePath(path, seed); + const pubKey = edHd.getPublicKey(key); + return {key,chainCode, pubKey}; + }, + getZBCAddress(publicKey, prefix = "ZBC") { + const prefixDefault = ["ZBC", "ZNK", "ZBL", "ZTX"]; + const valid = prefixDefault.indexOf(prefix) > -1; + if (valid) { + var bytes = new Uint8Array(35); + for (let i = 0; i < 32; i++) bytes[i] = publicKey[i]; + for (let i = 0; i < 3; i++) bytes[i + 32] = prefix.charCodeAt(i); + const checksum = nbl.CryptoUtils.sha3(bytes); + for (let i = 0; i < 3; i++) bytes[i + 32] = Number(checksum[i]); + var segs = [prefix]; + var b32 = base32.encode(bytes); + for (let i = 0; i < 7; i++) segs.push(b32.substr(i * 8, 8)); + return segs.join("_"); + } else { + throw new Error("The Prefix not available!"); + } + } +} + /* nano-util */ let NanoBase = require('nanocurrency-web'); diff --git a/src/js/index.js b/src/js/index.js index 61a2dd5..1f4cc1f 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1348,6 +1348,27 @@ address = libs.bchaddrSlp.toSlpAddress(address); } } + + // ZooBC address format may vary + 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'); + } + // Segwit addresses are different if (isSegwit) { if (!segwitAvailable) { diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 0332f96..ca5b1bb 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -2328,6 +2328,17 @@ it('Allows selection of TRX on Tron', function(done) { testNetwork(done, params); }); +it('Allows selection of ZooBlockchain', function(done) { + var params = { + selectText: "ZBC - ZooBlockchain", + phrase: "shy invest oxygen real lunar moral merge corn program air affair amazing dove imitate combine solve library fresh case alcohol pole question act thing", + firstAddress: "ZBC_MGEZVH3U_SXPCBHTU_KSWDPQ4X_K6MSI3VR_CQAYMTLC_RXUMM3DJ_LFABCAXA", + firstPubKey: "61899a9f7495de209e7454ac37c3975799246eb11401864d628de8c66c695940", + firstPrivKey: "adb11e79068fa7366ec4f5963ad57115d666b1ad2b369b92d962563adf7dd48b", + }; + testNetwork(done, params); +}); + // BIP39 seed is set from phrase it('Sets the bip39 seed from the prhase', function(done) { driver.findElement(By.css('.phrase')) -- cgit v1.2.3