u
This commit is contained in:
28
tic.js
28
tic.js
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
const axios = require('axios')
|
||||
const ticrypto = require('tic-crypto')
|
||||
const ticc = require('tic-crypto')
|
||||
const ticActionTransfer = require('tic.action').ActionTransfer
|
||||
|
||||
const TIC_TXFEE = 10
|
||||
@@ -8,7 +8,7 @@ const TIC_NODE = require('./netConfig').TIC_NODE
|
||||
|
||||
class TIC {
|
||||
constructor (seckey, option = {}) {
|
||||
if (!seckey || !ticrypto.isSeckey(seckey)) throw 'ERROR:Invalid Seckey'
|
||||
if (!seckey || !ticc.is_seckey(seckey)) throw 'ERROR:Invalid Seckey'
|
||||
Object.defineProperties(this, {
|
||||
seckey: {
|
||||
value: seckey,
|
||||
@@ -16,12 +16,14 @@ class TIC {
|
||||
writable: false
|
||||
},
|
||||
pubkey: {
|
||||
value: ticrypto.seckey2pubkey(seckey),
|
||||
value: ticc.seckey_to_pubkey({ seckey }),
|
||||
enumerable: true,
|
||||
writable: false
|
||||
},
|
||||
address: {
|
||||
value: ticrypto.pubkey2address(ticrypto.seckey2pubkey(seckey)),
|
||||
value: ticc.pubkey_to_address({
|
||||
pubkey: ticc.seckey_to_pubkey(seckey)
|
||||
}),
|
||||
enumerable: true,
|
||||
writable: false
|
||||
}
|
||||
@@ -45,14 +47,14 @@ class TIC {
|
||||
}
|
||||
|
||||
static generateNewAccount () {
|
||||
var secword = ticrypto.randomSecword()
|
||||
return Object.assign(new TIC(ticrypto.secword2keypair(secword).seckey), {
|
||||
var secword = ticc.randomize_secword()
|
||||
return Object.assign(new TIC(ticc.secword_to_keypair({ secword }).seckey), {
|
||||
secword: secword
|
||||
})
|
||||
}
|
||||
static fromMnemonic (secword) {
|
||||
if (!secword || !ticrypto.isSecword(secword)) throw 'ERROR:Invalid Secword'
|
||||
return new TIC(ticrypto.secword2keypair(secword).seckey)
|
||||
if (!secword || !ticc.is_secword(secword)) throw 'ERROR:Invalid Secword'
|
||||
return new TIC(ticc.secword_to_keypair({ secword }).seckey)
|
||||
}
|
||||
static async getBalance (address) {
|
||||
if (!address) {
|
||||
@@ -84,14 +86,14 @@ class TIC {
|
||||
}
|
||||
static encrypt (data, key) {
|
||||
if (!data || !key) throw new Error('Required Params Missing')
|
||||
return ticrypto.encrypt(data, key)
|
||||
return ticc.encrypt(data, key)
|
||||
}
|
||||
static decrypt (data, key) {
|
||||
return ticrypto.decrypt(data, key, { format: 'json' }) //return null for wrong key
|
||||
return ticc.decrypt(data, key, { format: 'json' }) //return null for wrong key
|
||||
}
|
||||
|
||||
static isValidAddress (address) {
|
||||
return ticrypto.isAddress(address)
|
||||
return ticc.is_chain_address({ address })
|
||||
}
|
||||
|
||||
async sendTransaction (toAddress, amount, option = { gasFee: TIC_TXFEE }) {
|
||||
@@ -142,10 +144,10 @@ class TIC {
|
||||
}
|
||||
//default key for sign&encrypt is account's seckey,other keys are optional.
|
||||
sign (message, key = this.seckey) {
|
||||
return ticrypto.sign({ data: message, seckey: key })
|
||||
return ticc.sign({ data: message, seckey: key })
|
||||
}
|
||||
verify (message, signature) {
|
||||
return ticrypto.sign({ data: message, signature, seckey: this.seckey })
|
||||
return ticc.sign({ data: message, signature, seckey: this.seckey })
|
||||
}
|
||||
encrypt (key) {
|
||||
return TIC.encrypt(this, key)
|
||||
|
||||
Reference in New Issue
Block a user