rename seckey to prikey

This commit is contained in:
陆柯 2022-08-14 15:51:14 +08:00
parent bbba2589d5
commit 6bcc378170
2 changed files with 18 additions and 18 deletions

8
btc.js
View File

@ -10,7 +10,7 @@ const BTC_TXFEE = 30
class BTC { class BTC {
constructor (privateKey) { constructor (privateKey) {
if (!ticc.is_seckey({ seckey: privateKey })) if (!ticc.is_seckey({ prikey: privateKey }))
throw new Error('Invalid PrivateKey') throw new Error('Invalid PrivateKey')
var publicKey = ticc.seckey_to_pubkey(privateKey) var publicKey = ticc.seckey_to_pubkey(privateKey)
Object.defineProperties(this, { Object.defineProperties(this, {
@ -22,7 +22,7 @@ class BTC {
publicKey: { publicKey: {
enumerable: true, enumerable: true,
writable: false, writable: false,
value: ticc.seckey_to_pubkey({ seckey: privateKey, coin: 'BTC' }) value: ticc.seckey_to_pubkey({ prikey: privateKey, coin: 'BTC' })
}, },
address: { address: {
enumerable: true, enumerable: true,
@ -61,7 +61,7 @@ class BTC {
var mnemonic = ticc.randomize_secword() var mnemonic = ticc.randomize_secword()
return Object.assign( return Object.assign(
new BTC( new BTC(
ticc.secword_to_keypair({ secword: mnemonic, coin: 'BTC' }).seckey ticc.secword_to_keypair({ secword: mnemonic, coin: 'BTC' }).prikey
), ),
{ mnemonic: mnemonic } { mnemonic: mnemonic }
) )
@ -70,7 +70,7 @@ class BTC {
HDNode.isValidMnemonic(mnemonic) HDNode.isValidMnemonic(mnemonic)
return Object.assign( return Object.assign(
new BTC( new BTC(
ticc.secword_to_keypair({ secword: mnemonic, coin: 'BTC' }).seckey ticc.secword_to_keypair({ secword: mnemonic, coin: 'BTC' }).prikey
), ),
{ mnemonic: mnemonic } { mnemonic: mnemonic }
) )

28
tic.js
View File

@ -7,22 +7,22 @@ const TIC_TXFEE = 10
const TIC_NODE = require('./netConfig').TIC_NODE const TIC_NODE = require('./netConfig').TIC_NODE
class TIC { class TIC {
constructor (seckey, option = {}) { constructor (prikey, option = {}) {
if (!seckey || !ticc.is_seckey({ seckey })) throw 'ERROR:Invalid Seckey' if (!prikey || !ticc.is_seckey({ prikey })) throw 'ERROR:Invalid Seckey'
Object.defineProperties(this, { Object.defineProperties(this, {
seckey: { prikey: {
value: seckey, value: prikey,
enumerable: true, enumerable: true,
writable: false writable: false
}, },
pubkey: { pubkey: {
value: ticc.seckey_to_pubkey({ seckey }), value: ticc.seckey_to_pubkey({ prikey }),
enumerable: true, enumerable: true,
writable: false writable: false
}, },
address: { address: {
value: ticc.pubkey_to_address({ value: ticc.pubkey_to_address({
pubkey: ticc.seckey_to_pubkey(seckey) pubkey: ticc.seckey_to_pubkey(prikey)
}), }),
enumerable: true, enumerable: true,
writable: false writable: false
@ -48,13 +48,13 @@ class TIC {
static generateNewAccount () { static generateNewAccount () {
var secword = ticc.randomize_secword() var secword = ticc.randomize_secword()
return Object.assign(new TIC(ticc.secword_to_keypair({ secword }).seckey), { return Object.assign(new TIC(ticc.secword_to_keypair({ secword }).prikey), {
secword: secword secword: secword
}) })
} }
static fromMnemonic (secword) { static fromMnemonic (secword) {
if (!secword || !ticc.is_secword(secword)) throw 'ERROR:Invalid Secword' if (!secword || !ticc.is_secword(secword)) throw 'ERROR:Invalid Secword'
return new TIC(ticc.secword_to_keypair({ secword }).seckey) return new TIC(ticc.secword_to_keypair({ secword }).prikey)
} }
static async getBalance (address) { static async getBalance (address) {
if (!address) { if (!address) {
@ -107,7 +107,7 @@ class TIC {
}) })
//对交易数据签名,packMe 内的参数是交易发起人的keypair //对交易数据签名,packMe 内的参数是交易发起人的keypair
action.packMe({ action.packMe({
seckey: this.seckey, prikey: this.prikey,
pubkey: this.pubkey pubkey: this.pubkey
}) })
let data = { let data = {
@ -137,17 +137,17 @@ class TIC {
}) })
//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({
seckey: this.seckey, prikey: this.prikey,
pubkey: this.pubkey pubkey: this.pubkey
}) })
return action return action
} }
//default key for sign&encrypt is account's seckey,other keys are optional. //default key for sign&encrypt is account's prikey,other keys are optional.
sign (message, key = this.seckey) { sign (message, key = this.prikey) {
return ticc.sign_easy({ data: message, seckey: key }) return ticc.sign_easy({ data: message, prikey: key })
} }
verify (message, signature) { verify (message, signature) {
return ticc.sign_easy({ data: message, signature, seckey: this.seckey }) return ticc.sign_easy({ data: message, signature, prikey: this.prikey })
} }
encrypt (key) { encrypt (key) {
return TIC.encrypt(this, key) return TIC.encrypt(this, key)