u
This commit is contained in:
parent
07a88d9bc7
commit
0bc2108351
24
btc.js
24
btc.js
@ -3,15 +3,15 @@
|
||||
const axios = require('axios')
|
||||
const HDNode = require('./utils/hdnode')
|
||||
const bitcoinjs = require('bitcoinjs-lib')
|
||||
const Ticrypto = require('tic-crypto')
|
||||
const ticc = 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 (!Ticrypto.isSeckey(privateKey)) throw new Error('Invalid PrivateKey')
|
||||
var publicKey = Ticrypto.seckey2pubkey(privateKey)
|
||||
if (!ticc.is_seckey(privateKey)) throw new Error('Invalid PrivateKey')
|
||||
var publicKey = ticc.seckey_to_pubkey(privateKey)
|
||||
Object.defineProperties(this, {
|
||||
privateKey: {
|
||||
enumerable: true,
|
||||
@ -21,12 +21,12 @@ class BTC {
|
||||
publicKey: {
|
||||
enumerable: true,
|
||||
writable: false,
|
||||
value: Ticrypto.seckey2pubkey(privateKey, { coin: 'BTC' })
|
||||
value: ticc.seckey_to_pubkey({ seckey: privateKey, coin: 'BTC' })
|
||||
},
|
||||
address: {
|
||||
enumerable: true,
|
||||
writable: false,
|
||||
value: Ticrypto.pubkey2address(publicKey, { coin: 'BTC' })
|
||||
value: ticc.pubkey_to_address({ pubkey: publicKey, coin: 'BTC' })
|
||||
},
|
||||
url: {
|
||||
enumerable: true,
|
||||
@ -57,16 +57,20 @@ class BTC {
|
||||
this._defaultGasFee = BTC_TXFEE
|
||||
}
|
||||
static generateNewAccount () {
|
||||
var mnemonic = Ticrypto.randomSecword()
|
||||
var mnemonic = ticc.randomize_secword()
|
||||
return Object.assign(
|
||||
new BTC(Ticrypto.secword2keypair(mnemonic, { coin: 'BTC' }).seckey),
|
||||
new BTC(
|
||||
ticc.secword_to_keypair({ secword: mnemonic, coin: 'BTC' }).seckey
|
||||
),
|
||||
{ mnemonic: mnemonic }
|
||||
)
|
||||
}
|
||||
static fromMnemonic (mnemonic) {
|
||||
HDNode.isValidMnemonic(mnemonic)
|
||||
return Object.assign(
|
||||
new BTC(Ticrypto.secword2keypair(mnemonic, { coin: 'BTC' }).seckey),
|
||||
new BTC(
|
||||
ticc.secword_to_keypair({ secword: mnemonic, coin: 'BTC' }).seckey
|
||||
),
|
||||
{ mnemonic: mnemonic }
|
||||
)
|
||||
}
|
||||
@ -88,10 +92,10 @@ class BTC {
|
||||
}
|
||||
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 address.length == 34 && address[0] == '1'
|
||||
|
8
eth.js
8
eth.js
@ -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 Ticrypto = require('tic-crypto')
|
||||
const ticc = require('tic-crypto')
|
||||
const HDNode = require('./utils/hdnode')
|
||||
const utils = require('./util.js')
|
||||
const axios = require('axios')
|
||||
@ -79,7 +79,7 @@ class ETH {
|
||||
}
|
||||
static generateNewAccount (option = { path: defaultPath }) {
|
||||
//major path as default path >/0'/0/0
|
||||
var mnemonic = Ticrypto.randomSecword()
|
||||
var mnemonic = ticc.randomize_secword()
|
||||
return Object.assign(ETH.fromMnemonic(mnemonic, option), {
|
||||
mnemonic,
|
||||
mnemonic
|
||||
@ -233,10 +233,10 @@ class ETH {
|
||||
}
|
||||
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 async estimateGasPrice () {
|
||||
try {
|
||||
|
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)
|
||||
|
Loading…
Reference in New Issue
Block a user