@ocap/tx-pipeline 1.18.128 → 1.18.129

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.
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ const VerifyListSize = require('./pipes/verify-list-size');
13
13
  const VerifyMultiSig = require('./pipes/verify-multisig');
14
14
  const VerifyMultiSigV2 = require('./pipes/verify-multisig-v2');
15
15
  const VerifySender = require('./pipes/verify-sender');
16
+ const VerifyBlocked = require('./pipes/verify-blocked');
16
17
  const VerifyServiceFee = require('./pipes/verify-service-fee');
17
18
  const VerifySignature = require('./pipes/verify-signature');
18
19
  const VerifySigner = require('./pipes/verify-signer');
@@ -41,6 +42,7 @@ module.exports = {
41
42
  VerifyMultiSigV2,
42
43
  VerifyUpdater,
43
44
  VerifySender,
45
+ VerifyBlocked,
44
46
  VerifyServiceFee,
45
47
  VerifySignature,
46
48
  VerifySigner,
@@ -1,23 +1,29 @@
1
1
  /* eslint-disable no-restricted-syntax */
2
2
  const get = require('lodash/get');
3
+ const { isSameDid } = require('@ocap/util');
3
4
  const { CustomError: Error } = require('@ocap/util/lib/error');
4
5
 
5
6
  module.exports = function CreateAntiLandAttackPipe({
6
7
  senderState = 'senderState',
7
8
  receiverState = 'receiverState',
8
- receiverAddress = 'receiver',
9
9
  } = {}) {
10
10
  return function AntiLandAttack(context, next) {
11
11
  const sender = get(context, senderState);
12
12
  const receiver = get(context, receiverState);
13
13
 
14
- if (receiver && sender.address === receiver.address) {
15
- return next(new Error('INVALID_TX', 'Sender and receiver are the same'));
14
+ const senders = (Array.isArray(sender) ? sender : [sender]).filter(Boolean);
15
+ const receivers = (Array.isArray(receiver) ? receiver : [receiver]).filter(Boolean);
16
+
17
+ for (const s of senders) {
18
+ if (receivers.some((r) => isSameDid(r.address, s.address))) {
19
+ return next(new Error('INVALID_TX', `Sender should not exist in receiver list: ${s.address}`));
20
+ }
16
21
  }
17
22
 
18
- const receiverAddr = get(context, receiverAddress);
19
- if (sender.address === receiverAddr) {
20
- return next(new Error('INVALID_TX', 'Sender and receiver are the same'));
23
+ for (const r of receivers) {
24
+ if (senders.some((s) => isSameDid(s.address, r.address))) {
25
+ return next(new Error('INVALID_TX', `Receiver should not exist in sender list: ${r.address}`));
26
+ }
21
27
  }
22
28
 
23
29
  next();
@@ -0,0 +1,14 @@
1
+ const { CustomError: Error } = require('@ocap/util/lib/error');
2
+
3
+ module.exports = function CreatedVerifyBlockedPipe(filter) {
4
+ return async function VerifyTx(context, next) {
5
+ if (typeof filter?.isBlocked === 'function' && context.tx?.from) {
6
+ const blocked = await filter.isBlocked(context.tx.from);
7
+ if (blocked) {
8
+ return next(new Error('FORBIDDEN', 'Sender blocked'));
9
+ }
10
+ }
11
+
12
+ next();
13
+ };
14
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.128",
6
+ "version": "1.18.129",
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.128",
33
- "@arcblock/did-util": "1.18.128",
34
- "@ocap/mcrypto": "1.18.128",
35
- "@ocap/message": "1.18.128",
36
- "@ocap/state": "1.18.128",
37
- "@ocap/util": "1.18.128",
38
- "@ocap/wallet": "1.18.128",
32
+ "@arcblock/did": "1.18.129",
33
+ "@arcblock/did-util": "1.18.129",
34
+ "@ocap/mcrypto": "1.18.129",
35
+ "@ocap/message": "1.18.129",
36
+ "@ocap/state": "1.18.129",
37
+ "@ocap/util": "1.18.129",
38
+ "@ocap/wallet": "1.18.129",
39
39
  "debug": "^4.3.4",
40
40
  "empty-value": "^1.0.1",
41
41
  "lodash": "^4.17.21"
42
42
  },
43
- "gitHead": "97c217e51a0c250f8804c67c893c09d9f4c127c8"
43
+ "gitHead": "422e48b5668be8d25d76037d86926a625b194758"
44
44
  }