@ocap/tx-protocols 1.18.23 → 1.18.25

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.
@@ -39,17 +39,18 @@ runner.use(pipes.VerifyAccountMigration({ senderKey: 'senderState' }));
39
39
  // Ensure factory exist
40
40
  runner.use(pipes.ExtractState({ from: 'itx.factory', to: 'factoryState', status: 'INVALID_FACTORY_STATE', table: 'factory' })); // prettier-ignore
41
41
 
42
- // Used to assemble issuer object
43
- runner.use(pipes.ExtractState({ from: 'factoryState.owner', to: 'factoryOwnerState', status: 'INVALID_OWNER', table: 'account' })); // prettier-ignore
42
+ // Ensure issuer exist: read them here because some maybe migrated
43
+ runner.use(pipes.ExtractState({ from: 'factoryState.trustedIssuers', to: 'issuerStates', status: 'INVALID_ISSUER_STATE' , table: 'account'})); // prettier-ignore
44
44
 
45
45
  // Ensure factory owner exist and equal to sender
46
46
  runner.use(pipes.ExtractState({ from: 'itx.owner', to: 'ownerState', status: 'OK', table: 'account' }));
47
47
  runner.use(
48
48
  pipes.VerifyInfo([
49
49
  {
50
- error: 'OWNER_ONLY_OPERATION',
51
- message: 'Only factory owner is allowed to mint',
52
- fn: ({ factoryState, senderState }) => factoryState.owner === senderState.address,
50
+ error: 'FORBIDDEN',
51
+ message: 'Only factory owner and trusted issuers are allowed to mint',
52
+ fn: ({ factoryState, senderState, issuerStates }) =>
53
+ senderState.address === factoryState.owner || issuerStates.find((x) => x.address === senderState.address),
53
54
  persist: true,
54
55
  },
55
56
  ])
@@ -2,7 +2,7 @@ const { CustomError: Error } = require('@ocap/util/lib/error');
2
2
  const { mintFromFactory } = require('@ocap/asset');
3
3
 
4
4
  module.exports = (mode) => (context, next) => {
5
- const { itx, senderState, ownerState, factoryState, delegatorState, factoryOwnerState, factoryInputs } = context;
5
+ const { itx, senderState, ownerState, factoryState, delegatorState, factoryInputs } = context;
6
6
 
7
7
  let issuer = null;
8
8
  let owner = null;
@@ -17,9 +17,9 @@ module.exports = (mode) => (context, next) => {
17
17
  } else if (mode === 'mint') {
18
18
  owner = ownerState || { address: itx.owner };
19
19
  issuer = {
20
- id: factoryOwnerState.address,
21
- pk: factoryOwnerState.pk,
22
- name: factoryOwnerState.moniker,
20
+ id: senderState.address,
21
+ pk: senderState.pk,
22
+ name: senderState.moniker,
23
23
  };
24
24
  }
25
25
 
@@ -107,6 +107,9 @@ runner.use((context, next) => {
107
107
  return next(new Error('INVALID_FACTORY_INPUT', 'Not all input.assets exist on chain'));
108
108
  });
109
109
 
110
+ // ensure issuer exists
111
+ runner.use(pipes.ExtractState({ from: 'factoryProps.trustedIssuers', to: 'issuerStates', table: 'account', status: 'INVALID_ISSUER_STATE' })); // prettier-ignore
112
+
110
113
  // Ensure tx fee and gas
111
114
  runner.use(EnsureTxGas(() => ({ create: 1, update: 1, payment: 0 })));
112
115
  runner.use(EnsureTxCost({ attachSenderChanges: true }));
@@ -55,7 +55,7 @@ runner.use(
55
55
  {
56
56
  error: 'INVALID_TX',
57
57
  message: 'Tx sender can not be slasher',
58
- fn: ({ tx, itx }) => itx.slashersList.includes(tx.from) === false,
58
+ fn: ({ tx, itx }) => itx.slashersList.length === 0 || itx.slashersList.includes(tx.from) === false,
59
59
  },
60
60
  {
61
61
  error: 'INSUFFICIENT_DATA',
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.23",
6
+ "version": "1.18.25",
7
7
  "description": "Predefined tx pipeline sets to execute certain type of transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -21,18 +21,18 @@
21
21
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@arcblock/did": "1.18.23",
25
- "@arcblock/did-util": "1.18.23",
26
- "@arcblock/jwt": "1.18.23",
27
- "@arcblock/validator": "1.18.23",
28
- "@ocap/asset": "1.18.23",
29
- "@ocap/mcrypto": "1.18.23",
30
- "@ocap/merkle-tree": "1.18.23",
31
- "@ocap/message": "1.18.23",
32
- "@ocap/state": "1.18.23",
33
- "@ocap/tx-pipeline": "1.18.23",
34
- "@ocap/util": "1.18.23",
35
- "@ocap/wallet": "1.18.23",
24
+ "@arcblock/did": "1.18.25",
25
+ "@arcblock/did-util": "1.18.25",
26
+ "@arcblock/jwt": "1.18.25",
27
+ "@arcblock/validator": "1.18.25",
28
+ "@ocap/asset": "1.18.25",
29
+ "@ocap/mcrypto": "1.18.25",
30
+ "@ocap/merkle-tree": "1.18.25",
31
+ "@ocap/message": "1.18.25",
32
+ "@ocap/state": "1.18.25",
33
+ "@ocap/tx-pipeline": "1.18.25",
34
+ "@ocap/util": "1.18.25",
35
+ "@ocap/wallet": "1.18.25",
36
36
  "debug": "^4.3.4",
37
37
  "deep-diff": "^1.0.2",
38
38
  "empty-value": "^1.0.1",
@@ -47,5 +47,5 @@
47
47
  "jest": "^27.5.1",
48
48
  "start-server-and-test": "^1.14.0"
49
49
  },
50
- "gitHead": "bb57afdd756f4a9608e53e40c91060c32b97f2f8"
50
+ "gitHead": "87830209c1f24e374c6b6577a9c08c6ead30a4be"
51
51
  }