diff --git a/groups/coinNetworks.js b/groups/coinNetworks.js index 5325811..3a42b31 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..51f467b --- /dev/null +++ b/groups/lsk.js @@ -0,0 +1,42 @@ +const cryptography = require('@liskhq/lisk-cryptography') +const sodium = require('sodium-browserify-tweetnacl') +const pbkdf2 = require('pbkdf2'); + +const coinNetworks = require('./coinNetworks'); +const {bytesToHex} = require('../helpers/encryptor'); + +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, address, addressHexBinary, addressHex, privateKey + */ + +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'); + + return { + network, + keyPair, + address, + addressHexBinary, + addressHex, + privateKey + } +}; + +module.exports = lsk; diff --git a/index.js b/index.js index a016996..daba8ec 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,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'); @@ -34,6 +35,7 @@ module.exports = (params, log) => { dash, btc, doge, + lsk, transactionFormer, keys, encryptor, diff --git a/package.json b/package.json index 04d8ec2..7a7c87e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adamant-api", - "version": "1.4.0", + "version": "1.5.0", "description": "REST API for ADAMANT Blockchain", "main": "index.js", "scripts": { @@ -14,10 +14,12 @@ "bitcoinjs-lib": "^5.2.0", "bitcore-mnemonic": "^8.25.25", "bytebuffer": "^5.0.1", - "coininfo": "^5.1.0", + "coininfo": "^5.1.0", "ed2curve": "^0.3.0", "ethereumjs-util": "^7.1.4", "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" },