[tic.js] rename Ticrypto to ticCrypto, so as to follow the same naming convention.
This commit is contained in:
parent
601d535b71
commit
84c8d52932
32
tic.js
32
tic.js
@ -1,6 +1,6 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const Ticrypto = require('tic.crypto')
|
const ticCrypto = require('tic.crypto')
|
||||||
const ticActionTransfer = require('tic.action').ActionTransfer
|
const ticActionTransfer = require('tic.action').ActionTransfer
|
||||||
|
|
||||||
const TIC_TXFEE = 10;
|
const TIC_TXFEE = 10;
|
||||||
@ -8,7 +8,7 @@ const TIC_NODE = require('./netConfig').TIC_NODE
|
|||||||
|
|
||||||
class TIC {
|
class TIC {
|
||||||
constructor(seckey,option={}){
|
constructor(seckey,option={}){
|
||||||
if(!seckey||!Ticrypto.isSeckey(seckey)) throw "ERROR:Invalid Seckey"
|
if(!seckey||!ticCrypto.isSeckey(seckey)) throw "ERROR:Invalid Seckey"
|
||||||
Object.defineProperties(this, {
|
Object.defineProperties(this, {
|
||||||
'seckey' : {
|
'seckey' : {
|
||||||
value : seckey,
|
value : seckey,
|
||||||
@ -16,12 +16,12 @@ class TIC {
|
|||||||
writable : false,
|
writable : false,
|
||||||
},
|
},
|
||||||
'pubkey' : {
|
'pubkey' : {
|
||||||
value : Ticrypto.seckey2pubkey(seckey),
|
value : ticCrypto.seckey2pubkey(seckey),
|
||||||
enumerable : true,
|
enumerable : true,
|
||||||
writable : false,
|
writable : false,
|
||||||
},
|
},
|
||||||
'address' : {
|
'address' : {
|
||||||
value : Ticrypto.pubkey2address(Ticrypto.seckey2pubkey(seckey)),
|
value : ticCrypto.pubkey2address(ticCrypto.seckey2pubkey(seckey)),
|
||||||
enumerable : true,
|
enumerable : true,
|
||||||
writable : false
|
writable : false
|
||||||
}
|
}
|
||||||
@ -37,12 +37,12 @@ class TIC {
|
|||||||
set txfee(fee){this._defaultFee = fee}
|
set txfee(fee){this._defaultFee = fee}
|
||||||
|
|
||||||
static generateNewAccount(){
|
static generateNewAccount(){
|
||||||
var secword = Ticrypto.randomSecword()
|
var secword = ticCrypto.randomSecword()
|
||||||
return Object.assign(new TIC(Ticrypto.secword2keypair(secword).seckey),{secword:secword})
|
return Object.assign(new TIC(ticCrypto.secword2keypair(secword).seckey),{secword:secword})
|
||||||
}
|
}
|
||||||
static fromMnemonic(secword){
|
static fromMnemonic(secword){
|
||||||
if(!secword||!Ticrypto.isSecword(secword)) throw "ERROR:Invalid Secword"
|
if(!secword||!ticCrypto.isSecword(secword)) throw "ERROR:Invalid Secword"
|
||||||
return new TIC(Ticrypto.secword2keypair(secword).seckey)
|
return new TIC(ticCrypto.secword2keypair(secword).seckey)
|
||||||
}
|
}
|
||||||
static async getBalance(address){
|
static async getBalance(address){
|
||||||
if(!address){ throw new Error('Address is required'); }
|
if(!address){ throw new Error('Address is required'); }
|
||||||
@ -66,14 +66,14 @@ class TIC {
|
|||||||
}
|
}
|
||||||
static encrypt(data, key){
|
static encrypt(data, key){
|
||||||
if(!data || !key) throw new Error('Required Params Missing')
|
if(!data || !key) throw new Error('Required Params Missing')
|
||||||
return Ticrypto.encrypt(data,key)
|
return ticCrypto.encrypt(data,key)
|
||||||
}
|
}
|
||||||
static decrypt(data, key){
|
static decrypt(data, key){
|
||||||
return Ticrypto.decrypt(data, key, {format:"json"}) //return null for wrong key
|
return ticCrypto.decrypt(data, key, {format:"json"}) //return null for wrong key
|
||||||
}
|
}
|
||||||
|
|
||||||
static isValidAddress(address){
|
static isValidAddress(address){
|
||||||
return Ticrypto.isAddress(address)
|
return ticCrypto.isAddress(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendTransaction(toAddress, amount, option = {gasFee : TIC_TXFEE}){
|
async sendTransaction(toAddress, amount, option = {gasFee : TIC_TXFEE}){
|
||||||
@ -81,13 +81,12 @@ class TIC {
|
|||||||
let action = new ticActionTransfer({
|
let action = new ticActionTransfer({
|
||||||
amount: parseInt(amount),
|
amount: parseInt(amount),
|
||||||
toAddress: toAddress,
|
toAddress: toAddress,
|
||||||
fee: option.gasFee
|
fee: option.gasFee,
|
||||||
})
|
})
|
||||||
//对交易数据签名,packMe 内的参数是交易发起人的keypair
|
//对交易数据签名,packMe 内的参数是交易发起人的keypair
|
||||||
action.packMe({
|
action.packMe({
|
||||||
seckey: this.seckey,
|
seckey: this.seckey,
|
||||||
pubkey: this.pubkey,
|
pubkey: this.pubkey,
|
||||||
address: this.address
|
|
||||||
})
|
})
|
||||||
let data = {
|
let data = {
|
||||||
Action:action
|
Action:action
|
||||||
@ -111,7 +110,7 @@ class TIC {
|
|||||||
let action=new ticActionTransfer({
|
let action=new ticActionTransfer({
|
||||||
amount: parseInt(option.amount),
|
amount: parseInt(option.amount),
|
||||||
toAddress: option.toAddress,
|
toAddress: option.toAddress,
|
||||||
fee:option.fee||this._defaultFee,
|
fee: option.fee||this._defaultFee,
|
||||||
})
|
})
|
||||||
//sign for txBody use function packMe, which needs actor's keypair as parameter
|
//sign for txBody use function packMe, which needs actor's keypair as parameter
|
||||||
action.packMe({
|
action.packMe({
|
||||||
@ -122,14 +121,15 @@ class TIC {
|
|||||||
}
|
}
|
||||||
//default key for sign&encrypt is account's seckey,other keys are optional.
|
//default key for sign&encrypt is account's seckey,other keys are optional.
|
||||||
sign(message,key = this.seckey){
|
sign(message,key = this.seckey){
|
||||||
return Ticrypto.sign(message,key)
|
return ticCrypto.sign(message,key)
|
||||||
}
|
}
|
||||||
verify(message,signature){
|
verify(message,signature){
|
||||||
return Ticrypto.sign(message,signature,this.seckey)
|
return ticCrypto.sign(message,signature,this.seckey)
|
||||||
}
|
}
|
||||||
encrypt(key){
|
encrypt(key){
|
||||||
return TIC.encrypt(this, key)
|
return TIC.encrypt(this, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {TIC}
|
module.exports = {TIC}
|
||||||
|
Loading…
Reference in New Issue
Block a user