随着 tic.crypto 升级到 secp256k1 的公私钥和签名,把 signMe, packMe, verifySig 改成 async 的
This commit is contained in:
parent
4e2a4b35db
commit
c9f04b24eb
22
Action.js
22
Action.js
@ -34,19 +34,19 @@ MOM._model = {
|
||||
json: { default: undefined, sqlite: 'TEXT' } // 给不同类型的 ActionXxx 子类来自定义其所需的数据结构
|
||||
}
|
||||
|
||||
MOM.packMe = function (keypair) { // 由前端调用,后台不创建
|
||||
MOM.packMe = async function (keypair) { // 由前端调用,后台不创建
|
||||
this.actorPubkey = keypair.pubkey
|
||||
this.actorAddress = ticCrypto.pubkey2address(keypair.pubkey)
|
||||
this.timestamp = new Date()
|
||||
|
||||
this.signMe(keypair.seckey)
|
||||
await this.signMe(keypair.seckey)
|
||||
this.hashMe()
|
||||
return this
|
||||
}
|
||||
|
||||
MOM.signMe = function (seckey) { // 由前端调用,后台不该进行签名
|
||||
MOM.signMe = async function (seckey) { // 由前端调用,后台不该进行签名
|
||||
let json = this.getJson({ exclude: ['hash', 'blockHash', 'actorSignature'] }) // 是前端用户发起事务时签字,这时候还不知道进入哪个区块,所以不能计入blockHash
|
||||
this.actorSignature = ticCrypto.sign(json, seckey)
|
||||
this.actorSignature = await ticCrypto.sign(json, seckey)
|
||||
return this
|
||||
}
|
||||
|
||||
@ -55,14 +55,14 @@ MOM.hashMe = function () {
|
||||
return this
|
||||
}
|
||||
|
||||
MOM.verifySig = function() {
|
||||
MOM.verifySig = async function() {
|
||||
let json = this.getJson({ exclude: ['hash', 'blockHash', 'actorSignature'] })
|
||||
let result = ticCrypto.verify(json, this.actorSignature, this.actorPubkey)
|
||||
let result = await ticCrypto.verify(json, this.actorSignature, this.actorPubkey)
|
||||
return result
|
||||
}
|
||||
DAD.verifySig = function (actionData) {
|
||||
DAD.verifySig = async function (actionData) {
|
||||
let typedAction = new wo[actionData.type](actionData)
|
||||
return typedAction.verifySig()
|
||||
return await typedAction.verifySig()
|
||||
}
|
||||
|
||||
MOM.verifyAddress = function () {
|
||||
@ -81,11 +81,11 @@ DAD.verifyHash = function (actionData) {
|
||||
return typedAction.verifyHash()
|
||||
}
|
||||
|
||||
DAD.build = function (action, keypair) { // Applicable on client. 客户端调用 Action.build,即可新建、并打包成一个完整的子事务,不需要亲自调用 constructor, packMe 等方法。
|
||||
DAD.build = async function (action, keypair) { // Applicable on client. 客户端调用 Action.build,即可新建、并打包成一个完整的子事务,不需要亲自调用 constructor, packMe 等方法。
|
||||
if (action && action.type && keypair && keypair.seckey && keypair.pubkey) {
|
||||
let typedAction = new wo[action.type](action)
|
||||
if (typedAction.validateMe()) {
|
||||
typedAction.packMe(keypair)
|
||||
await typedAction.packMe(keypair)
|
||||
return typedAction
|
||||
}
|
||||
}
|
||||
@ -168,7 +168,7 @@ DAD.api.prepare = async function (option) {
|
||||
if (option && option.Action && option.Action.type && wo[option.Action.type] && option.Action.hash && !DAD.actionPool[option.Action.hash]) {
|
||||
let typedAction = new wo[option.Action.type](option.Action)
|
||||
if (typedAction.verifyAddress() && // 只检查所有事务通用的格式
|
||||
typedAction.verifySig() &&
|
||||
await typedAction.verifySig() &&
|
||||
typedAction.verifyHash() &&
|
||||
typedAction.validateMe() && // 检查事务的内容是否符合该子类事务的格式
|
||||
(await typedAction.executableMe()) // 检查事务是否可执行,在当前链的状态下。
|
||||
|
@ -13,15 +13,15 @@ const MOM = DAD.prototype
|
||||
MOM.__proto__ = Action.prototype
|
||||
// MOM._table=DAD.name // 注释掉,从而继承父类Action的数据库表格名
|
||||
|
||||
MOM.signMe = function (seckey) { // 由前端调用,后台不该进行签名
|
||||
MOM.signMe = async function (seckey) { // 由前端调用,后台不该进行签名
|
||||
let json = this.getJson({ exclude: ['hash', 'blockHash', 'actorSignature', 'json'] }) // 是前端用户发起事务时签字,这时候还不知道进入哪个区块,所以不能计入blockHash
|
||||
this.actorSignature = wo.Crypto.sign(json, seckey)
|
||||
this.actorSignature = await wo.Crypto.sign(json, seckey)
|
||||
return this
|
||||
}
|
||||
|
||||
MOM.verifySig = function () {
|
||||
MOM.verifySig = async function () {
|
||||
let json = this.getJson(({ exclude: ['hash', 'blockHash', 'actorSignature', 'json'] }))
|
||||
let res = wo.Crypto.verify(json, this.actorSignature, this.actorPubkey)
|
||||
let res = await wo.Crypto.verify(json, this.actorSignature, this.actorPubkey)
|
||||
return res
|
||||
}
|
||||
|
||||
@ -38,12 +38,12 @@ MOM.verifyHash = function () {
|
||||
return this.hash === wo.Crypto.hash(this.getJson({ exclude: ['hash', 'blockHash', 'json'] }))
|
||||
}
|
||||
|
||||
MOM.packMe = function (keypair) { // 由前端调用,后台不创建
|
||||
MOM.packMe = async function (keypair) { // 由前端调用,后台不创建
|
||||
this.actorPubkey = keypair.pubkey
|
||||
this.actorAddress = wo.Crypto.pubkey2address(keypair.pubkey)
|
||||
this.timestamp = new Date()
|
||||
|
||||
this.signMe(keypair.seckey)
|
||||
await this.signMe(keypair.seckey)
|
||||
this.hashMe()
|
||||
return this
|
||||
}
|
||||
@ -59,7 +59,7 @@ MOM.checkMultiSig = function (account) {
|
||||
}
|
||||
for (let i of sigers) // 该交易内已签名的每一个公钥
|
||||
{
|
||||
if (account.multiSignatures.keysgroup.indexOf(i) !== -1 && wo.Crypto.verify(json, this.json[i], i)) {
|
||||
if (account.multiSignatures.keysgroup.indexOf(i) !== -1 && await wo.Crypto.verify(json, this.json[i], i)) {
|
||||
M++
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user