From 051c3aba62bebfdb05433525e4071bc56ad9cb3a Mon Sep 17 00:00:00 2001 From: gost1k Date: Fri, 4 Feb 2022 23:09:17 +0300 Subject: [PATCH 1/6] feat: add lisk --- groups/coinNetworks.js | 8 +++++++- groups/lsk.js | 35 +++++++++++++++++++++++++++++++++++ index.js | 4 +++- package.json | 6 ++++-- 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 groups/lsk.js diff --git a/groups/coinNetworks.js b/groups/coinNetworks.js index 5325811..16eed08 100644 --- a/groups/coinNetworks.js +++ b/groups/coinNetworks.js @@ -3,5 +3,11 @@ coininfo = require('coininfo'); module.exports = { DOGE: coininfo.dogecoin.main.toBitcoinJS(), DASH: coininfo.dash.main.toBitcoinJS(), - BTC: coininfo.bitcoin.main.toBitcoinJS() + BTC: coininfo.bitcoin.main.toBitcoinJS(), + LSK: { + name: 'Lisk', + port: 8000, + wsPort: 8001, + unit: 'LSK' + }, } diff --git a/groups/lsk.js b/groups/lsk.js new file mode 100644 index 0000000..9e17f66 --- /dev/null +++ b/groups/lsk.js @@ -0,0 +1,35 @@ +const coinNetworks = require('./coinNetworks'); +const pbkdf2 = require('pbkdf2'); +const sodium = require('sodium-browserify-tweetnacl') +const cryptography = require('@liskhq/lisk-cryptography') +const lsk = {} + +const LiskHashSettings = { + SALT: 'adm', + ITERATIONS: 2048, + KEYLEN: 32, + DIGEST: 'sha256' +} + +/** + * Generates a LSK account from the passphrase specified. + * @param {string} passphrase ADAMANT account passphrase + * @returns {object} network info, keyPair, privateKey, privateKeyWIF + */ + +lsk.keys = passphrase => { + const network = coinNetworks.LSK + const liskSeed = pbkdf2.pbkdf2Sync(passphrase, LiskHashSettings.SALT, LiskHashSettings.ITERATIONS, LiskHashSettings.KEYLEN, LiskHashSettings.DIGEST) + const keyPair = sodium.crypto_sign_seed_keypair(liskSeed) + const address = cryptography.getBase32AddressFromPublicKey(keyPair.publicKey) + const privateKey = keyPair.secretKey.toString('hex') + + return { + network, + keyPair, + address, + privateKey + } +}; + +module.exports = lsk; diff --git a/index.js b/index.js index 97bcc82..a49d3d7 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ const eth = require('./groups/eth'); const dash = require('./groups/dash'); const btc = require('./groups/btc'); const doge = require('./groups/doge'); +const lsk = require('./groups/lsk'); const transactionFormer = require('./helpers/transactionFormer'); const keys = require('./helpers/keys'); const encryptor = require('./helpers/encryptor'); @@ -19,7 +20,7 @@ module.exports = (params, log) => { log = log || console; logger.initLogger(params.logLevel, log); const nodeManager = healthCheck(params.node); - + return { get: get(nodeManager), getPublicKey: getPublicKey(nodeManager), @@ -30,6 +31,7 @@ module.exports = (params, log) => { dash, btc, doge, + lsk, transactionFormer, keys, encryptor, diff --git a/package.json b/package.json index 306cd89..f9593cc 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,15 @@ "dependencies": { "axios": "^0.23.0", "bignumber.js": "^9.0.1", - "bitcoinjs-lib": "^5.2.0", + "bitcoinjs-lib": "^5.2.0", "bitcore-mnemonic": "^8.25.10", "bytebuffer": "^5.0.1", - "coininfo": "^5.1.0", + "coininfo": "^5.1.0", "ed2curve": "^0.3.0", "ethereumjs-util": "^7.1.3", "hdkey": "^2.0.1", + "pbkdf2": "^3.1.2", + "@liskhq/lisk-cryptography": "3.2.0", "socket.io-client": "^2.4.0", "sodium-browserify-tweetnacl": "^0.2.6" }, From 9d53844781991e0779faaf3d89272b818738588f Mon Sep 17 00:00:00 2001 From: gost1k Date: Mon, 7 Feb 2022 00:05:11 +0300 Subject: [PATCH 2/6] feat: add addressHex and adressHexBinary to lisk --- groups/lsk.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/groups/lsk.js b/groups/lsk.js index 9e17f66..ee934c5 100644 --- a/groups/lsk.js +++ b/groups/lsk.js @@ -2,6 +2,7 @@ const coinNetworks = require('./coinNetworks'); const pbkdf2 = require('pbkdf2'); const sodium = require('sodium-browserify-tweetnacl') const cryptography = require('@liskhq/lisk-cryptography') +const {bytesToHex} = require("../helpers/encryptor"); const lsk = {} const LiskHashSettings = { @@ -22,12 +23,16 @@ lsk.keys = passphrase => { const liskSeed = pbkdf2.pbkdf2Sync(passphrase, LiskHashSettings.SALT, LiskHashSettings.ITERATIONS, LiskHashSettings.KEYLEN, LiskHashSettings.DIGEST) const keyPair = sodium.crypto_sign_seed_keypair(liskSeed) const address = cryptography.getBase32AddressFromPublicKey(keyPair.publicKey) + const addressHexBinary = cryptography.getAddressFromPublicKey(keyPair.publicKey) + const addressHex = bytesToHex(addressHexBinary) const privateKey = keyPair.secretKey.toString('hex') return { network, keyPair, address, + addressHexBinary, + addressHex, privateKey } }; From 624f28c615345b7204c525f1ae5aaf511e62d80f Mon Sep 17 00:00:00 2001 From: gost1k Date: Sun, 13 Feb 2022 11:55:15 +0300 Subject: [PATCH 3/6] docs: update lsk documentation --- groups/lsk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/groups/lsk.js b/groups/lsk.js index ee934c5..7ba59ec 100644 --- a/groups/lsk.js +++ b/groups/lsk.js @@ -15,7 +15,7 @@ const LiskHashSettings = { /** * Generates a LSK account from the passphrase specified. * @param {string} passphrase ADAMANT account passphrase - * @returns {object} network info, keyPair, privateKey, privateKeyWIF + * @returns {object} network info, keyPair, address, addressHexBinary, addressHex, privateKey */ lsk.keys = passphrase => { From 8ae80d670da7d985b8848eb17ac7d01eb9ca66e6 Mon Sep 17 00:00:00 2001 From: gost1k Date: Sun, 13 Feb 2022 11:56:42 +0300 Subject: [PATCH 4/6] style: sort imports --- groups/lsk.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/groups/lsk.js b/groups/lsk.js index 7ba59ec..5dabb95 100644 --- a/groups/lsk.js +++ b/groups/lsk.js @@ -1,8 +1,10 @@ -const coinNetworks = require('./coinNetworks'); -const pbkdf2 = require('pbkdf2'); -const sodium = require('sodium-browserify-tweetnacl') const cryptography = require('@liskhq/lisk-cryptography') -const {bytesToHex} = require("../helpers/encryptor"); +const sodium = require('sodium-browserify-tweetnacl') +const pbkdf2 = require('pbkdf2'); + +const coinNetworks = require('./coinNetworks'); +const { bytesToHex } = require("../helpers/encryptor"); + const lsk = {} const LiskHashSettings = { From 4a302f38febe141c59ca1ad79972cdc958241970 Mon Sep 17 00:00:00 2001 From: gost1k Date: Sun, 13 Feb 2022 17:16:30 +0300 Subject: [PATCH 5/6] style fixes --- groups/lsk.js | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/groups/lsk.js b/groups/lsk.js index 5dabb95..acb3d3a 100644 --- a/groups/lsk.js +++ b/groups/lsk.js @@ -3,15 +3,15 @@ const sodium = require('sodium-browserify-tweetnacl') const pbkdf2 = require('pbkdf2'); const coinNetworks = require('./coinNetworks'); -const { bytesToHex } = require("../helpers/encryptor"); +const {bytesToHex} = require('../helpers/encryptor'); -const lsk = {} +const lsk = {}; const LiskHashSettings = { - SALT: 'adm', - ITERATIONS: 2048, - KEYLEN: 32, - DIGEST: 'sha256' + SALT: 'adm', + ITERATIONS: 2048, + KEYLEN: 32, + DIGEST: 'sha256' } /** @@ -21,22 +21,17 @@ const LiskHashSettings = { */ lsk.keys = passphrase => { - const network = coinNetworks.LSK - const liskSeed = pbkdf2.pbkdf2Sync(passphrase, LiskHashSettings.SALT, LiskHashSettings.ITERATIONS, LiskHashSettings.KEYLEN, LiskHashSettings.DIGEST) - const keyPair = sodium.crypto_sign_seed_keypair(liskSeed) - const address = cryptography.getBase32AddressFromPublicKey(keyPair.publicKey) - const addressHexBinary = cryptography.getAddressFromPublicKey(keyPair.publicKey) - const addressHex = bytesToHex(addressHexBinary) - const privateKey = keyPair.secretKey.toString('hex') + const network = coinNetworks.LSK; + const liskSeed = pbkdf2.pbkdf2Sync(passphrase, LiskHashSettings.SALT, LiskHashSettings.ITERATIONS, LiskHashSettings.KEYLEN, LiskHashSettings.DIGEST); + const keyPair = sodium.crypto_sign_seed_keypair(liskSeed); + const address = cryptography.getBase32AddressFromPublicKey(keyPair.publicKey); + const addressHexBinary = cryptography.getAddressFromPublicKey(keyPair.publicKey); + const addressHex = bytesToHex(addressHexBinary); + const privateKey = keyPair.secretKey.toString('hex'); - return { - network, - keyPair, - address, - addressHexBinary, - addressHex, - privateKey - } + return { + network, keyPair, address, addressHexBinary, addressHex, privateKey + } }; module.exports = lsk; From 4066a422269dae5b886cf25c5d4f2bd72c49ee91 Mon Sep 17 00:00:00 2001 From: gost1k Date: Sun, 13 Feb 2022 19:27:15 +0300 Subject: [PATCH 6/6] style fixes --- groups/coinNetworks.js | 8 ++++---- groups/lsk.js | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/groups/coinNetworks.js b/groups/coinNetworks.js index 16eed08..3a42b31 100644 --- a/groups/coinNetworks.js +++ b/groups/coinNetworks.js @@ -5,9 +5,9 @@ module.exports = { DASH: coininfo.dash.main.toBitcoinJS(), BTC: coininfo.bitcoin.main.toBitcoinJS(), LSK: { - name: 'Lisk', - port: 8000, - wsPort: 8001, - unit: 'LSK' + name: 'Lisk', + port: 8000, + wsPort: 8001, + unit: 'LSK' }, } diff --git a/groups/lsk.js b/groups/lsk.js index acb3d3a..51f467b 100644 --- a/groups/lsk.js +++ b/groups/lsk.js @@ -30,7 +30,12 @@ lsk.keys = passphrase => { const privateKey = keyPair.secretKey.toString('hex'); return { - network, keyPair, address, addressHexBinary, addressHex, privateKey + network, + keyPair, + address, + addressHexBinary, + addressHex, + privateKey } };