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 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libs') 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'); -- cgit v1.2.3