diff options
-rw-r--r-- | libs/combined/index.js | 33 | ||||
-rw-r--r-- | src/js/bitcoinjs-extensions.js | 12 | ||||
-rw-r--r-- | src/js/index.js | 28 | ||||
-rw-r--r-- | tests/spec/tests.js | 11 |
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 | ||
3 | module.exports.basex = require('base-x') | 3 | module.exports.basex = require('base-x') |
4 | 4 | ||
5 | /* base32 */ | ||
6 | |||
7 | module.exports.base32 = require('base32.js') | ||
8 | |||
5 | /* bchaddrjs */ | 9 | /* bchaddrjs */ |
6 | 10 | ||
7 | module.exports.bchaddr = require('bchaddrjs') | 11 | module.exports.bchaddr = require('bchaddrjs') |
@@ -84,6 +88,35 @@ module.exports.stellarUtil = { | |||
84 | }, | 88 | }, |
85 | } | 89 | } |
86 | 90 | ||
91 | /* zoobc-util */ | ||
92 | |||
93 | let base32 = require('base32.js'); | ||
94 | let nbl = require('nebulas'); | ||
95 | module.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 | ||
89 | let NanoBase = require('nanocurrency-web'); | 122 | let NanoBase = require('nanocurrency-web'); |
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js index 84363f6..84de8da 100644 --- a/src/js/bitcoinjs-extensions.js +++ b/src/js/bitcoinjs-extensions.js | |||
@@ -1564,6 +1564,18 @@ libs.bitcoin.networks.hush3 = { | |||
1564 | wif: 0xBC, | 1564 | wif: 0xBC, |
1565 | }; | 1565 | }; |
1566 | 1566 | ||
1567 | libs.bitcoin.networks.zoobc = { | ||
1568 | messagePrefix: '\x18ZooBC Signed Message:\n', | ||
1569 | bech32: 'bc', | ||
1570 | bip32: { | ||
1571 | public: 0x0488b21e, | ||
1572 | private: 0x0488ade4, | ||
1573 | }, | ||
1574 | pubKeyHash: 0x00, | ||
1575 | scriptHash: 0x05, | ||
1576 | wif: 0x80, | ||
1577 | }; | ||
1578 | |||
1567 | libs.bitcoin.networks.zclassic = { | 1579 | libs.bitcoin.networks.zclassic = { |
1568 | messagePrefix: '\x18Zcash Signed Message:\n', | 1580 | messagePrefix: '\x18Zcash Signed Message:\n', |
1569 | bip32: { | 1581 | bip32: { |
diff --git a/src/js/index.js b/src/js/index.js index f7835fa..713b5e8 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) { |
@@ -3548,6 +3569,13 @@ | |||
3548 | }, | 3569 | }, |
3549 | }, | 3570 | }, |
3550 | { | 3571 | { |
3572 | name: "ZBC - ZooBlockchain", | ||
3573 | onSelect: function () { | ||
3574 | network = libs.bitcoin.networks.zoobc; | ||
3575 | setHdCoin(883); | ||
3576 | }, | ||
3577 | }, | ||
3578 | { | ||
3551 | name: "ZCL - Zclassic", | 3579 | name: "ZCL - Zclassic", |
3552 | onSelect: function() { | 3580 | onSelect: function() { |
3553 | network = libs.bitcoin.networks.zclassic; | 3581 | network = libs.bitcoin.networks.zclassic; |
diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 9c3eb6a..f350fa7 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js | |||
@@ -2338,6 +2338,17 @@ it('Allows selection of TRX on Tron', function(done) { | |||
2338 | testNetwork(done, params); | 2338 | testNetwork(done, params); |
2339 | }); | 2339 | }); |
2340 | 2340 | ||
2341 | it('Allows selection of ZooBlockchain', function(done) { | ||
2342 | var params = { | ||
2343 | selectText: "ZBC - ZooBlockchain", | ||
2344 | 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", | ||
2345 | firstAddress: "ZBC_MGEZVH3U_SXPCBHTU_KSWDPQ4X_K6MSI3VR_CQAYMTLC_RXUMM3DJ_LFABCAXA", | ||
2346 | firstPubKey: "61899a9f7495de209e7454ac37c3975799246eb11401864d628de8c66c695940", | ||
2347 | firstPrivKey: "adb11e79068fa7366ec4f5963ad57115d666b1ad2b369b92d962563adf7dd48b", | ||
2348 | }; | ||
2349 | testNetwork(done, params); | ||
2350 | }); | ||
2351 | |||
2341 | // BIP39 seed is set from phrase | 2352 | // BIP39 seed is set from phrase |
2342 | it('Sets the bip39 seed from the prhase', function(done) { | 2353 | it('Sets the bip39 seed from the prhase', function(done) { |
2343 | driver.findElement(By.css('.phrase')) | 2354 | driver.findElement(By.css('.phrase')) |