diff options
author | jhonkus <putukn@gmail.com> | 2020-12-07 20:25:25 +0800 |
---|---|---|
committer | jhonkus <putukn@gmail.com> | 2020-12-07 20:25:25 +0800 |
commit | 6d2e202083c4166aa4be8557789a8a461df6bd5c (patch) | |
tree | f360db3ad1a2de8fe1f5fda0f864f0a2134d4c4c | |
parent | 0cb81e1117053c93debfa501a5bdb11169636dd2 (diff) | |
download | BIP39-6d2e202083c4166aa4be8557789a8a461df6bd5c.tar.gz BIP39-6d2e202083c4166aa4be8557789a8a461df6bd5c.tar.zst BIP39-6d2e202083c4166aa4be8557789a8a461df6bd5c.zip |
Add ZooBC address format
-rw-r--r-- | libs/combined/index.js | 33 | ||||
-rw-r--r-- | src/js/index.js | 21 | ||||
-rw-r--r-- | tests/spec/tests.js | 11 |
3 files changed, 65 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/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 @@ | |||
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) { |
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 | ||
2331 | it('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 |
2332 | it('Sets the bip39 seed from the prhase', function(done) { | 2343 | it('Sets the bip39 seed from the prhase', function(done) { |
2333 | driver.findElement(By.css('.phrase')) | 2344 | driver.findElement(By.css('.phrase')) |