This commit is contained in:
Luk Lu
2022-07-03 16:03:25 +08:00
parent 07a88d9bc7
commit 0bc2108351
3 changed files with 33 additions and 27 deletions

24
btc.js
View File

@@ -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'