This commit is contained in:
Luk Lu
2022-07-03 16:02:58 +08:00
parent e3920911b0
commit f70b97cbb2
4 changed files with 143 additions and 70 deletions

View File

@@ -1,6 +1,5 @@
const Ling = require('so.ling')
const ticrypto = require('tic-crypto')
const wo = {}
const ticc = require('tic-crypto')
/** ****************** Public of instance ********************/
@@ -42,7 +41,7 @@ MOM._model = {
MOM.packMe = async function (keypair) {
// 由前端调用,后台不创建
this.actorPubkey = keypair.pubkey
this.actorAddress = ticrypto.pubkey2address(keypair.pubkey)
this.actorAddress = ticc.pubkey_to_address({ pubkey: keypair.pubkey })
this.timestamp = new Date()
await this.signMe(keypair.seckey)
@@ -53,22 +52,18 @@ MOM.packMe = async function (keypair) {
MOM.signMe = async function (seckey) {
// 由前端调用,后台不该进行签名
let json = this.getJson({ exclude: ['hash', 'blockHash', 'actorSignature'] }) // 是前端用户发起事务时签字这时候还不知道进入哪个区块所以不能计入blockHash
this.actorSignature = await ticrypto.sign(json, seckey)
this.actorSignature = await ticc.sign(json, seckey)
return this
}
MOM.hashMe = function () {
this.hash = ticrypto.hash(this.getJson({ exclude: ['hash', 'blockHash'] })) // block.hash 受到所包含的actionList影响所以action不能受blockHash影响否则循环了
this.hash = ticc.hash(this.getJson({ exclude: ['hash', 'blockHash'] })) // block.hash 受到所包含的actionList影响所以action不能受blockHash影响否则循环了
return this
}
MOM.verifySig = async function () {
let json = this.getJson({ exclude: ['hash', 'blockHash', 'actorSignature'] })
let result = await ticrypto.verify(
json,
this.actorSignature,
this.actorPubkey
)
let result = await ticc.verify(json, this.actorSignature, this.actorPubkey)
return result
}
DAD.verifySig = async function (actionData) {
@@ -77,7 +72,9 @@ DAD.verifySig = async function (actionData) {
}
MOM.verifyAddress = function () {
return this.actorAddress === ticrypto.pubkey2address(this.actorPubkey)
return (
this.actorAddress === ticc.pubkey_to_address({ pubkey: this.actorPubkey })
)
}
DAD.verifyAddress = function (actionData) {
let typedAction = new wo[actionData.type](actionData)
@@ -86,8 +83,7 @@ DAD.verifyAddress = function (actionData) {
MOM.verifyHash = function () {
return (
this.hash ===
ticrypto.hash(this.getJson({ exclude: ['hash', 'blockHash'] }))
this.hash === ticc.hash(this.getJson({ exclude: ['hash', 'blockHash'] }))
)
}
DAD.verifyHash = function (actionData) {
@@ -157,7 +153,7 @@ DAD.buildUserAction = async function (action, keypair) {
keypair &&
keypair.seckey &&
keypair.pubkey &&
ticrypto.seckey2pubkey(keypair.seckey) === keypair.pubkey
ticc.seckey_to_pubkey({ seckey: keypair.seckey }) === keypair.pubkey
) {
let typedAction = new wo[action.type](action)
typedAction.actorPubkey = keypair.pubkey