@ocap/tx-pipeline 1.18.166 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ const get = require('lodash/get');
3
3
  const set = require('lodash/set');
4
4
 
5
5
  module.exports = function CreateExtractReceiverPipe({ from, to = 'receiver' }) {
6
- return async function ExtractReceiver(context, next) {
6
+ return function ExtractReceiver(context, next) {
7
7
  const keys = Array.isArray(from) ? from : [from];
8
8
  for (const key of keys) {
9
9
  const value = get(context, key);
@@ -9,7 +9,7 @@ const { fromPublicKey } = require('@ocap/wallet');
9
9
  const { createMessage, decodeAny } = require('@ocap/message');
10
10
 
11
11
  module.exports = function CreateVerifyMultiSigV2Pipe({ signersKey }) {
12
- return function VerifyMultiSigV2(context, next) {
12
+ return async function VerifyMultiSigV2(context, next) {
13
13
  const signers = get(context, signersKey);
14
14
  if (signers.length === 0) {
15
15
  return next();
@@ -49,19 +49,22 @@ module.exports = function CreateVerifyMultiSigV2Pipe({ signersKey }) {
49
49
  tx.signature = '';
50
50
  tx.signaturesList = signatures.map((x) => omit(x, 'signature'));
51
51
  for (let i = 0; i < signatures.length; i++) {
52
- const { signer, pk, delegator, signature } = signatures[i];
52
+ const { signer, pk, delegator, signature, extra = '' } = signatures[i];
53
53
 
54
54
  // if delegator is empty, pk and signer shall be a pair
55
55
  // if delegator is not empty, pk and delegator shall be a pair
56
56
  const address = delegator || signer;
57
- const wallet = fromPublicKey(pk, toTypeInfo(address));
57
+ const type = toTypeInfo(address);
58
+ const wallet = fromPublicKey(pk, type);
58
59
 
59
60
  const message = createMessage('Transaction', tx);
60
61
  try {
61
- if (wallet.verify(message.serializeBinary(), signature) === false) {
62
+ // eslint-disable-next-line no-await-in-loop
63
+ if ((await wallet.verify(message.serializeBinary(), signature, true, extra)) === false) {
62
64
  return next(new Error('INVALID_SIGNATURE', `Signature for ${address} is not valid`));
63
65
  }
64
66
  } catch (err) {
67
+ console.error(err);
65
68
  return next(new Error('INVALID_SIGNATURE', `Signature for ${address} verify failed: ${err.message}`));
66
69
  }
67
70
  }
@@ -6,7 +6,7 @@ const { fromPublicKey } = require('@ocap/wallet');
6
6
  const { createMessage, decodeAny } = require('@ocap/message');
7
7
 
8
8
  module.exports = function CreateVerifyMultiSigPipe(numSigs = 0) {
9
- return function VerifyMultiSig(context, next) {
9
+ return async function VerifyMultiSig(context, next) {
10
10
  const tx = cloneDeep(context.tx);
11
11
  const signatures = getListField(tx, 'signatures');
12
12
  if (signatures.length !== numSigs) {
@@ -40,7 +40,8 @@ module.exports = function CreateVerifyMultiSigPipe(numSigs = 0) {
40
40
 
41
41
  tx.signatures = [{ signer, pk, delegator, data: decoded }].concat(signatures);
42
42
  const message = createMessage('Transaction', tx);
43
- if (wallet.verify(message.serializeBinary(), signature) === false) {
43
+ // eslint-disable-next-line no-await-in-loop
44
+ if ((await wallet.verify(message.serializeBinary(), signature)) === false) {
44
45
  return next(new Error('INVALID_SIGNATURE', `Multi signature for ${address} is not valid`));
45
46
  }
46
47
  }
@@ -3,9 +3,10 @@ const cloneDeep = require('lodash/cloneDeep');
3
3
  const { CustomError: Error } = require('@ocap/util/lib/error');
4
4
  const { toTypeInfo, isFromPublicKey } = require('@arcblock/did');
5
5
  const { fromPublicKey } = require('@ocap/wallet');
6
+ const { types } = require('@ocap/mcrypto');
6
7
  const { createMessage } = require('@ocap/message');
7
8
 
8
- module.exports = function VerifySignature(context, next) {
9
+ module.exports = async function VerifySignature(context, next) {
9
10
  const tx = cloneDeep(context.tx);
10
11
  const { signature } = tx;
11
12
 
@@ -26,12 +27,15 @@ module.exports = function VerifySignature(context, next) {
26
27
  }
27
28
 
28
29
  const message = createMessage('Transaction', tx);
29
- const wallet = fromPublicKey(pk, toTypeInfo(signer));
30
+ const type = toTypeInfo(signer);
31
+ const wallet = fromPublicKey(pk, type);
32
+ const extra = type.role === types.RoleType.ROLE_PASSKEY ? get(context, 'extra.txExtra') : '';
30
33
  try {
31
- if (wallet.verify(message.serializeBinary(), signature) === false) {
34
+ if ((await wallet.verify(message.serializeBinary(), signature, true, extra || '')) === false) {
32
35
  return next(new Error('INVALID_SIGNATURE', 'tx.signature is invalid'));
33
36
  }
34
37
  } catch (err) {
38
+ console.error(err);
35
39
  return next(new Error('INVALID_SIGNATURE', 'tx.signature verify failed'));
36
40
  }
37
41
 
@@ -93,7 +93,7 @@ function fixMigratedReceipts(receipts, statesMap) {
93
93
  * verify that account balances are updated correctly by comparing before and after states
94
94
  */
95
95
  module.exports = function CreateVerifyStateDiffPipe({ snapshotKey = 'stateSnapshot' } = {}) {
96
- return async function VerifyStateDiff(context, next) {
96
+ return function VerifyStateDiff(context, next) {
97
97
  const { logger, [snapshotKey]: snapshotStates } = context;
98
98
 
99
99
  if (!snapshotStates) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.166",
6
+ "version": "1.19.0",
7
7
  "description": "Pipeline runner and common pipelines to process transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -29,16 +29,16 @@
29
29
  "elliptic": "6.5.3"
30
30
  },
31
31
  "dependencies": {
32
- "@arcblock/did": "1.18.166",
33
- "@arcblock/did-util": "1.18.166",
34
- "@ocap/mcrypto": "1.18.166",
35
- "@ocap/message": "1.18.166",
36
- "@ocap/state": "1.18.166",
37
- "@ocap/util": "1.18.166",
38
- "@ocap/wallet": "1.18.166",
32
+ "@arcblock/did": "1.19.0",
33
+ "@arcblock/did-util": "1.19.0",
34
+ "@ocap/mcrypto": "1.19.0",
35
+ "@ocap/message": "1.19.0",
36
+ "@ocap/state": "1.19.0",
37
+ "@ocap/util": "1.19.0",
38
+ "@ocap/wallet": "1.19.0",
39
39
  "debug": "^4.3.6",
40
40
  "empty-value": "^1.0.1",
41
41
  "lodash": "^4.17.21"
42
42
  },
43
- "gitHead": "58c8356b3b8c238728560e4c3fef6ed1704d3ac4"
43
+ "gitHead": "1b6fac03988fb18507c8ef4c21de282762005f87"
44
44
  }