测试开分支,去除对 tic.common 的依赖,转成对 tic.crypto 和 tic.action

This commit is contained in:
luk.lu 2018-11-27 11:41:48 +08:00
parent 006219b7ee
commit efa4788bc3
5 changed files with 31 additions and 31 deletions

21
btc.js
View File

@ -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'

8
eth.js
View File

@ -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{

View File

@ -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,

View File

@ -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,

28
tic.js
View File

@ -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)