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

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)