From efa4788bc33b94f110ee8019b1f3a8248a27035a Mon Sep 17 00:00:00 2001 From: "luk.lu" Date: Tue, 27 Nov 2018 11:41:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=BC=80=E5=88=86=E6=94=AF?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E9=99=A4=E5=AF=B9=20tic.common=20=E7=9A=84?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=EF=BC=8C=E8=BD=AC=E6=88=90=E5=AF=B9=20tic.cr?= =?UTF-8?q?ypto=20=E5=92=8C=20tic.action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- btc.js | 21 ++++++++++----------- eth.js | 8 ++++---- index.js | 2 +- package.json | 3 ++- tic.js | 28 ++++++++++++++-------------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/btc.js b/btc.js index 1d3e81a..d42f4f8 100644 --- a/btc.js +++ b/btc.js @@ -3,16 +3,15 @@ const axios = require('axios'); const HDNode = require('./utils/hdnode'); const bitcoinjs = require('bitcoinjs-lib'); -// const bitcore = require('tic.common').Bitcore; -const ticCommon = require('tic.common').Crypto; +const Ticrypto = require('tic.crypto'); const BTC_NODE = require('./netConfig').BTC_NODE; const BTC_NODE2 = require('./netConfig').BTC_NODE2; const BTC_TXFEE = 30; class BTC { constructor(privateKey){ - if(!ticCommon.isSeckey(privateKey)) throw new Error('Invalid PrivateKey') - var publicKey = ticCommon.seckey2pubkey(privateKey) + if(!Ticrypto.isSeckey(privateKey)) throw new Error('Invalid PrivateKey') + var publicKey = Ticrypto.seckey2pubkey(privateKey) Object.defineProperties(this,{ "privateKey" : { enumerable : true, @@ -22,12 +21,12 @@ class BTC { "publicKey": { enumerable : true, writable : false, - value : ticCommon.seckey2pubkey(privateKey,{coin:"BTC"}) + value : Ticrypto.seckey2pubkey(privateKey,{coin:"BTC"}) }, "address" : { enumerable : true, writable : false, - value : ticCommon.pubkey2address(publicKey,{coin:"BTC"}) + value : Ticrypto.pubkey2address(publicKey,{coin:"BTC"}) }, "url" : { enumerable : true, @@ -51,12 +50,12 @@ class BTC { } static generateNewAccount(){ - var mnemonic = ticCommon.randomSecword() - return Object.assign(new BTC(ticCommon.secword2keypair(mnemonic, {coin:"BTC"}).seckey),{mnemonic : mnemonic}) + var mnemonic = Ticrypto.randomSecword() + return Object.assign(new BTC(Ticrypto.secword2keypair(mnemonic, {coin:"BTC"}).seckey),{mnemonic : mnemonic}) } static fromMnemonic(mnemonic){ HDNode.isValidMnemonic(mnemonic) - return Object.assign(new BTC(ticCommon.secword2keypair(mnemonic, {coin:"BTC"}).seckey),{mnemonic:mnemonic}) + return Object.assign(new BTC(Ticrypto.secword2keypair(mnemonic, {coin:"BTC"}).seckey),{mnemonic:mnemonic}) } static async getBalance(address){ return (await axios.get(`${BTC_NODE}/addrs/${address}/balance`)).data.balance @@ -74,10 +73,10 @@ class BTC { } static encrypt(data, key){ if(!data || !key) throw new Error('Required Params Missing') - return ticCommon.encrypt(data,key) + return Ticrypto.encrypt(data,key) } static decrypt(data, key){ - return ticCommon.decrypt(data, key, {format:"json"}) //return null for wrong key + return Ticrypto.decrypt(data, key, {format:"json"}) //return null for wrong key } static isValidAddress(address){ return address.length == 34 && address[0] == '1' diff --git a/eth.js b/eth.js index 7bc15e6..0e9aa27 100644 --- a/eth.js +++ b/eth.js @@ -2,7 +2,7 @@ const eth = require('etherscan-api').init('E3ZFFAEMNN33KX4HHVUZ4KF8XY1FXMR4BI'); const secretStorage = require('./utils/secret-storage'); const SigningKey = require('./utils/signing-key.js'); -const ticCommon = require('tic.common').Crypto; +const Ticrypto = require('tic.crypto'); const HDNode = require('./utils/hdnode'); const utils = require('./util.js'); const axios = require('axios'); @@ -68,7 +68,7 @@ class ETH { } static generateNewAccount(option = {path:defaultPath}){ //major path as default path >/0'/0/0 - var mnemonic = ticCommon.randomSecword(); + var mnemonic = Ticrypto.randomSecword(); return Object.assign(ETH.fromMnemonic(mnemonic, option),{mnemonic,mnemonic}) } static fromMnemonic(mnemonic, option = {path:defaultPath}){ @@ -198,10 +198,10 @@ class ETH { } static encrypt(data, key){ if(!data || !key) throw new Error('Required Params Missing') - return ticCommon.encrypt(data,key) + return Ticrypto.encrypt(data,key) } static decrypt(data, key){ - return ticCommon.decrypt(data, key, {format:"json"}) //return null for wrong key + return Ticrypto.decrypt(data, key, {format:"json"}) //return null for wrong key } static async estimateGasPrice(){ try{ diff --git a/index.js b/index.js index cb7839d..9525cf1 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const ETH = require('./eth.js').ETH; const ERC20 = require('./eth.js').ERC20; const BTC = require('./btc.js').BTC; const Account = require('./Account').Account; -const Crypto = require('tic.common').Crypto; +const Crypto = require('tic.crypto'); module.exports = { TIC, ETH, diff --git a/package.json b/package.json index ce3e7b0..250c53a 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "js-sha3": "^0.8.0", "scrypt-js": "^2.0.3", "setimmediate": "^1.0.5", - "tic.common": "git+https://git.faronear.org/tic/tic.common.git", + "tic.action": "git+https://git.faronear.org/tic/tic.action", + "tic.crypto": "git+https://git.faronear.org/tic/tic.crypto", "uuid": "^3.3.2" }, "deprecated": false, diff --git a/tic.js b/tic.js index ed47031..168cd7c 100644 --- a/tic.js +++ b/tic.js @@ -1,14 +1,14 @@ 'use strict' const axios = require('axios') -const ticCommon = require('tic.common').Crypto -const ticActTransfer = require('tic.common').ActTransfer +const Ticrypto = require('tic.crypto') +const ticActTransfer = require('tic.action').ActTransfer const TIC_TXFEE = 10; const TIC_NODE = require('./netConfig').TIC_NODE class TIC { constructor(seckey,option={}){ - if(!seckey||!ticCommon.isSeckey(seckey)) throw "ERROR:Invalid Seckey" + if(!seckey||!Ticrypto.isSeckey(seckey)) throw "ERROR:Invalid Seckey" Object.defineProperties(this, { 'seckey' : { value : seckey, @@ -16,12 +16,12 @@ class TIC { writable : false, }, 'pubkey' : { - value : ticCommon.seckey2pubkey(seckey), + value : Ticrypto.seckey2pubkey(seckey), enumerable : true, writable : false, }, 'address' : { - value : ticCommon.pubkey2address(ticCommon.seckey2pubkey(seckey)), + value : Ticrypto.pubkey2address(Ticrypto.seckey2pubkey(seckey)), enumerable : true, writable : false } @@ -37,12 +37,12 @@ class TIC { set txfee(fee){this._defaultFee = fee} static generateNewAccount(){ - var secword = ticCommon.randomSecword() - return Object.assign(new TIC(ticCommon.secword2keypair(secword).seckey),{secword:secword}) + var secword = Ticrypto.randomSecword() + return Object.assign(new TIC(Ticrypto.secword2keypair(secword).seckey),{secword:secword}) } static fromMnemonic(secword){ - if(!secword||!ticCommon.isSecword(secword)) throw "ERROR:Invalid Secword" - return new TIC(ticCommon.secword2keypair(secword).seckey) + if(!secword||!Ticrypto.isSecword(secword)) throw "ERROR:Invalid Secword" + return new TIC(Ticrypto.secword2keypair(secword).seckey) } static async getBalance(address){ if(!address){ throw new Error('Address is required'); } @@ -66,14 +66,14 @@ class TIC { } static encrypt(data, key){ if(!data || !key) throw new Error('Required Params Missing') - return ticCommon.encrypt(data,key) + return Ticrypto.encrypt(data,key) } static decrypt(data, key){ - return ticCommon.decrypt(data, key, {format:"json"}) //return null for wrong key + return Ticrypto.decrypt(data, key, {format:"json"}) //return null for wrong key } static isValidAddress(address){ - return ticCommon.isAddress(address) + return Ticrypto.isAddress(address) } async sendTransaction(toAddress, amount, option = {gasFee : TIC_TXFEE}){ @@ -123,10 +123,10 @@ class TIC { } //default key for sign&encrypt is account's seckey,other keys are optional. sign(message,key = this.seckey){ - return ticCommon.sign(message,key) + return Ticrypto.sign(message,key) } verify(message,signature){ - return ticCommon.sign(message,signature,this.seckey) + return Ticrypto.sign(message,signature,this.seckey) } encrypt(key){ return TIC.encrypt(this, key)