rename seckey to prikey

This commit is contained in:
Luk Lu
2022-08-14 15:52:39 +08:00
parent b1d8bc039a
commit 908ba3c66e
3 changed files with 16 additions and 16 deletions

View File

@@ -2,7 +2,7 @@
import ticrypto from 'tic-crypto' import ticrypto from 'tic-crypto'
import { TIC } from '../tic' import { TIC } from '../tic'
export const seckey2pubkey = seckey => ticrypto.seckey2pubkey(seckey) export const seckey2pubkey = prikey => ticrypto.seckey2pubkey(prikey)
export const secword2address = secword => ticrypto.secword2address(secword) export const secword2address = secword => ticrypto.secword2address(secword)
export const secword2account = secword => ticrypto.secword2account(secword) export const secword2account = secword => ticrypto.secword2account(secword)
// export const randomSecword = lang => ticrypto.randomSecword(lang) // export const randomSecword = lang => ticrypto.randomSecword(lang)

View File

@@ -4,10 +4,10 @@ import * as worker from 'workerize-loader!./tic-bg'
const instance = worker() const instance = worker()
export default { export default {
seckey2pubkey: seckey => instance.seckey2pubkey(seckey), seckey2pubkey: prikey => instance.seckey2pubkey(prikey),
secword2address: secword => instance.secword2address(secword), secword2address: secword => instance.secword2address(secword),
isAddress: address => instance.isAddress(address), isAddress: address => instance.isAddress(address),
secword2account: secword => instance.secword2account(secword), secword2account: secword => instance.secword2account(secword),
// randomSecword: async lang => instance.randomSecword(lang), // randomSecword: async lang => instance.randomSecword(lang),
transferTic: params => instance.transferTic(params), transferTic: params => instance.transferTic(params)
} }

View File

@@ -7,22 +7,22 @@ const TicActionTransfer = ticAction.ActionTransfer
const TIC_TXFEE = 10 const TIC_TXFEE = 10
export class TIC { export class TIC {
constructor (seckey, option = {}) { constructor (prikey, option = {}) {
if (!seckey || !Ticrypto.isSeckey(seckey)) if (!prikey || !Ticrypto.isSeckey(prikey))
throw Error('ERROR:Invalid Seckey') throw Error('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: Ticrypto.seckey2pubkey(seckey), value: Ticrypto.seckey2pubkey(prikey),
enumerable: true, enumerable: true,
writable: false writable: false
}, },
address: { address: {
value: Ticrypto.pubkey2address(Ticrypto.seckey2pubkey(seckey)), value: Ticrypto.pubkey2address(Ticrypto.seckey2pubkey(prikey)),
enumerable: true, enumerable: true,
writable: false writable: false
} }
@@ -40,14 +40,14 @@ export class TIC {
static generateNewAccount () { static generateNewAccount () {
var secword = Ticrypto.randomSecword() var secword = Ticrypto.randomSecword()
return Object.assign(new TIC(Ticrypto.secword2keypair(secword).seckey), { return Object.assign(new TIC(Ticrypto.secword2keypair(secword).prikey), {
secword: secword secword: secword
}) })
} }
static fromMnemonic (secword) { static fromMnemonic (secword) {
if (!secword || !Ticrypto.isSecword(secword)) if (!secword || !Ticrypto.isSecword(secword))
throw Error('ERROR:Invalid Secword') throw Error('ERROR:Invalid Secword')
return new TIC(Ticrypto.secword2keypair(secword).seckey) return new TIC(Ticrypto.secword2keypair(secword).prikey)
} }
static async getBalance (address) { static async getBalance (address) {
if (!address) { if (!address) {
@@ -108,7 +108,7 @@ export class TIC {
}) })
// 对交易数据签名,packMe 内的参数是交易发起人的keypair // 对交易数据签名,packMe 内的参数是交易发起人的keypair
action.packMe({ action.packMe({
seckey: this.seckey, prikey: this.prikey,
pubkey: this.pubkey, pubkey: this.pubkey,
address: this.address address: this.address
}) })
@@ -140,18 +140,18 @@ export 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,
address: this.address address: this.address
}) })
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 Ticrypto.sign(message, key) return Ticrypto.sign(message, key)
} }
verify (message, signature) { verify (message, signature) {
return Ticrypto.sign(message, signature, this.seckey) return Ticrypto.sign(message, signature, this.prikey)
} }
encrypt (key) { encrypt (key) {
return TIC.encrypt(this, key) return TIC.encrypt(this, key)