aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorjhonkus <putukn@gmail.com>2020-12-07 20:25:25 +0800
committerjhonkus <putukn@gmail.com>2020-12-07 20:25:25 +0800
commit6d2e202083c4166aa4be8557789a8a461df6bd5c (patch)
treef360db3ad1a2de8fe1f5fda0f864f0a2134d4c4c /libs
parent0cb81e1117053c93debfa501a5bdb11169636dd2 (diff)
downloadBIP39-6d2e202083c4166aa4be8557789a8a461df6bd5c.tar.gz
BIP39-6d2e202083c4166aa4be8557789a8a461df6bd5c.tar.zst
BIP39-6d2e202083c4166aa4be8557789a8a461df6bd5c.zip
Add ZooBC address format
Diffstat (limited to 'libs')
-rw-r--r--libs/combined/index.js33
1 files changed, 33 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');