aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/combined/index.js33
-rw-r--r--src/js/bitcoinjs-extensions.js12
-rw-r--r--src/js/index.js28
-rw-r--r--tests/spec/tests.js11
4 files changed, 84 insertions, 0 deletions
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 @@
2 2
3module.exports.basex = require('base-x') 3module.exports.basex = require('base-x')
4 4
5/* base32 */
6
7module.exports.base32 = require('base32.js')
8
5/* bchaddrjs */ 9/* bchaddrjs */
6 10
7module.exports.bchaddr = require('bchaddrjs') 11module.exports.bchaddr = require('bchaddrjs')
@@ -84,6 +88,35 @@ module.exports.stellarUtil = {
84 }, 88 },
85} 89}
86 90
91/* zoobc-util */
92
93let base32 = require('base32.js');
94let nbl = require('nebulas');
95module.exports.zoobcUtil = {
96 getKeypair: function (path, seed) {
97 const { key, chainCode} = edHd.derivePath(path, seed);
98 const pubKey = edHd.getPublicKey(key);
99 return {key,chainCode, pubKey};
100 },
101 getZBCAddress(publicKey, prefix = "ZBC") {
102 const prefixDefault = ["ZBC", "ZNK", "ZBL", "ZTX"];
103 const valid = prefixDefault.indexOf(prefix) > -1;
104 if (valid) {
105 var bytes = new Uint8Array(35);
106 for (let i = 0; i < 32; i++) bytes[i] = publicKey[i];
107 for (let i = 0; i < 3; i++) bytes[i + 32] = prefix.charCodeAt(i);
108 const checksum = nbl.CryptoUtils.sha3(bytes);
109 for (let i = 0; i < 3; i++) bytes[i + 32] = Number(checksum[i]);
110 var segs = [prefix];
111 var b32 = base32.encode(bytes);
112 for (let i = 0; i < 7; i++) segs.push(b32.substr(i * 8, 8));
113 return segs.join("_");
114 } else {
115 throw new Error("The Prefix not available!");
116 }
117 }
118}
119
87/* nano-util */ 120/* nano-util */
88 121
89let NanoBase = require('nanocurrency-web'); 122let NanoBase = require('nanocurrency-web');
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js
index b049d78..e4996ed 100644
--- a/src/js/bitcoinjs-extensions.js
+++ b/src/js/bitcoinjs-extensions.js
@@ -1553,6 +1553,18 @@ libs.bitcoin.networks.hush3 = {
1553 wif: 0xBC, 1553 wif: 0xBC,
1554}; 1554};
1555 1555
1556libs.bitcoin.networks.zoobc = {
1557 messagePrefix: '\x18ZooBC Signed Message:\n',
1558 bech32: 'bc',
1559 bip32: {
1560 public: 0x0488b21e,
1561 private: 0x0488ade4,
1562 },
1563 pubKeyHash: 0x00,
1564 scriptHash: 0x05,
1565 wif: 0x80,
1566};
1567
1556libs.bitcoin.networks.zclassic = { 1568libs.bitcoin.networks.zclassic = {
1557 messagePrefix: '\x18Zcash Signed Message:\n', 1569 messagePrefix: '\x18Zcash Signed Message:\n',
1558 bip32: { 1570 bip32: {
diff --git a/src/js/index.js b/src/js/index.js
index fd8c16b..1f4cc1f 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -1348,6 +1348,27 @@
1348 address = libs.bchaddrSlp.toSlpAddress(address); 1348 address = libs.bchaddrSlp.toSlpAddress(address);
1349 } 1349 }
1350 } 1350 }
1351
1352 // ZooBC address format may vary
1353 if (networks[DOM.network.val()].name == "ZBC - ZooBlockchain") {
1354
1355 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
1356 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
1357 var path = "m/";
1358 path += purpose + "'/";
1359 path += coin + "'/" + index + "'";
1360 var result = libs.zoobcUtil.getKeypair(path, seed);
1361
1362 let publicKey = result.pubKey.slice(1, 33);
1363 let privateKey = result.key;
1364
1365 privkey = privateKey.toString('hex');
1366 pubkey = publicKey.toString('hex');
1367
1368 indexText = path;
1369 address = libs.zoobcUtil.getZBCAddress(publicKey, 'ZBC');
1370 }
1371
1351 // Segwit addresses are different 1372 // Segwit addresses are different
1352 if (isSegwit) { 1373 if (isSegwit) {
1353 if (!segwitAvailable) { 1374 if (!segwitAvailable) {
@@ -3541,6 +3562,13 @@
3541 }, 3562 },
3542 }, 3563 },
3543 { 3564 {
3565 name: "ZBC - ZooBlockchain",
3566 onSelect: function () {
3567 network = libs.bitcoin.networks.zoobc;
3568 setHdCoin(883);
3569 },
3570 },
3571 {
3544 name: "ZCL - Zclassic", 3572 name: "ZCL - Zclassic",
3545 onSelect: function() { 3573 onSelect: function() {
3546 network = libs.bitcoin.networks.zclassic; 3574 network = libs.bitcoin.networks.zclassic;
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) {
2328 testNetwork(done, params); 2328 testNetwork(done, params);
2329}); 2329});
2330 2330
2331it('Allows selection of ZooBlockchain', function(done) {
2332 var params = {
2333 selectText: "ZBC - ZooBlockchain",
2334 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",
2335 firstAddress: "ZBC_MGEZVH3U_SXPCBHTU_KSWDPQ4X_K6MSI3VR_CQAYMTLC_RXUMM3DJ_LFABCAXA",
2336 firstPubKey: "61899a9f7495de209e7454ac37c3975799246eb11401864d628de8c66c695940",
2337 firstPrivKey: "adb11e79068fa7366ec4f5963ad57115d666b1ad2b369b92d962563adf7dd48b",
2338 };
2339 testNetwork(done, params);
2340});
2341
2331// BIP39 seed is set from phrase 2342// BIP39 seed is set from phrase
2332it('Sets the bip39 seed from the prhase', function(done) { 2343it('Sets the bip39 seed from the prhase', function(done) {
2333 driver.findElement(By.css('.phrase')) 2344 driver.findElement(By.css('.phrase'))