测试开分支,去除对 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'