@ocap/tx-pipeline 1.29.13 → 1.29.15
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isSameDid, toBN } from "@ocap/util";
|
|
1
|
+
import { isSameDid, scopeMatch, scopeMatchAny, toBN } from "@ocap/util";
|
|
2
2
|
import { CustomError } from "@ocap/util/lib/error";
|
|
3
3
|
import get from "lodash/get.js";
|
|
4
4
|
import set from "lodash/set.js";
|
|
@@ -119,12 +119,36 @@ function CreateVerifyDelegationPipe({ type = "signature", delegationKey = "deleg
|
|
|
119
119
|
return null;
|
|
120
120
|
};
|
|
121
121
|
const checkDelegation = (delegationState) => {
|
|
122
|
-
|
|
122
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
123
|
+
const validUntil = delegationState.validUntil || 0;
|
|
124
|
+
if (validUntil > 0 && validUntil < now) return {
|
|
125
|
+
valid: false,
|
|
126
|
+
code: "DELEGATION_EXPIRED",
|
|
127
|
+
reason: "Delegation has expired"
|
|
128
|
+
};
|
|
129
|
+
const deny = delegationState.deny || [];
|
|
130
|
+
if (txType && deny.length > 0 && scopeMatchAny(txType, deny)) return {
|
|
131
|
+
valid: false,
|
|
132
|
+
code: "DELEGATION_DENIED",
|
|
133
|
+
reason: `${txType} is denied in delegation`
|
|
134
|
+
};
|
|
135
|
+
if (!delegationState.ops || !txType) return {
|
|
136
|
+
valid: false,
|
|
137
|
+
code: "INVALID_DELEGATION_TYPE_URL",
|
|
138
|
+
reason: `${txType} is not allowed in delegation`
|
|
139
|
+
};
|
|
140
|
+
let matchedOp = delegationState.ops[txType];
|
|
141
|
+
if (!matchedOp) {
|
|
142
|
+
const matchedKey = Object.keys(delegationState.ops).find((key) => scopeMatch(txType, key));
|
|
143
|
+
if (matchedKey) matchedOp = delegationState.ops[matchedKey];
|
|
144
|
+
}
|
|
145
|
+
if (!matchedOp) return {
|
|
123
146
|
valid: false,
|
|
124
147
|
code: "INVALID_DELEGATION_TYPE_URL",
|
|
125
148
|
reason: `${txType} is not allowed in delegation`
|
|
126
149
|
};
|
|
127
|
-
|
|
150
|
+
if (txType.startsWith("fg:x:")) return { valid: true };
|
|
151
|
+
const rawLimit = matchedOp.limit || {
|
|
128
152
|
tokens: [],
|
|
129
153
|
assets: []
|
|
130
154
|
};
|
|
@@ -124,12 +124,36 @@ function CreateVerifyDelegationPipe({ type = "signature", delegationKey = "deleg
|
|
|
124
124
|
return null;
|
|
125
125
|
};
|
|
126
126
|
const checkDelegation = (delegationState) => {
|
|
127
|
-
|
|
127
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
128
|
+
const validUntil = delegationState.validUntil || 0;
|
|
129
|
+
if (validUntil > 0 && validUntil < now) return {
|
|
130
|
+
valid: false,
|
|
131
|
+
code: "DELEGATION_EXPIRED",
|
|
132
|
+
reason: "Delegation has expired"
|
|
133
|
+
};
|
|
134
|
+
const deny = delegationState.deny || [];
|
|
135
|
+
if (txType && deny.length > 0 && (0, _ocap_util.scopeMatchAny)(txType, deny)) return {
|
|
136
|
+
valid: false,
|
|
137
|
+
code: "DELEGATION_DENIED",
|
|
138
|
+
reason: `${txType} is denied in delegation`
|
|
139
|
+
};
|
|
140
|
+
if (!delegationState.ops || !txType) return {
|
|
141
|
+
valid: false,
|
|
142
|
+
code: "INVALID_DELEGATION_TYPE_URL",
|
|
143
|
+
reason: `${txType} is not allowed in delegation`
|
|
144
|
+
};
|
|
145
|
+
let matchedOp = delegationState.ops[txType];
|
|
146
|
+
if (!matchedOp) {
|
|
147
|
+
const matchedKey = Object.keys(delegationState.ops).find((key) => (0, _ocap_util.scopeMatch)(txType, key));
|
|
148
|
+
if (matchedKey) matchedOp = delegationState.ops[matchedKey];
|
|
149
|
+
}
|
|
150
|
+
if (!matchedOp) return {
|
|
128
151
|
valid: false,
|
|
129
152
|
code: "INVALID_DELEGATION_TYPE_URL",
|
|
130
153
|
reason: `${txType} is not allowed in delegation`
|
|
131
154
|
};
|
|
132
|
-
|
|
155
|
+
if (txType.startsWith("fg:x:")) return { valid: true };
|
|
156
|
+
const rawLimit = matchedOp.limit || {
|
|
133
157
|
tokens: [],
|
|
134
158
|
assets: []
|
|
135
159
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.29.
|
|
6
|
+
"version": "1.29.15",
|
|
7
7
|
"description": "Pipeline runner and common pipelines to process transactions",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -43,24 +43,24 @@
|
|
|
43
43
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@ocap/e2e-test": "1.29.
|
|
47
|
-
"@ocap/statedb-memory": "1.29.
|
|
46
|
+
"@ocap/e2e-test": "1.29.15",
|
|
47
|
+
"@ocap/statedb-memory": "1.29.15",
|
|
48
48
|
"@types/lodash": "^4.17.16"
|
|
49
49
|
},
|
|
50
50
|
"resolutions": {
|
|
51
|
-
"bn.js": "5.2.
|
|
51
|
+
"bn.js": "5.2.3",
|
|
52
52
|
"elliptic": "6.5.3"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@arcblock/did": "1.29.
|
|
56
|
-
"@arcblock/did-util": "1.29.
|
|
57
|
-
"@ocap/client": "1.29.
|
|
58
|
-
"@ocap/mcrypto": "1.29.
|
|
59
|
-
"@ocap/message": "1.29.
|
|
60
|
-
"@ocap/state": "1.29.
|
|
61
|
-
"@ocap/types": "1.29.
|
|
62
|
-
"@ocap/util": "1.29.
|
|
63
|
-
"@ocap/wallet": "1.29.
|
|
55
|
+
"@arcblock/did": "1.29.15",
|
|
56
|
+
"@arcblock/did-util": "1.29.15",
|
|
57
|
+
"@ocap/client": "1.29.15",
|
|
58
|
+
"@ocap/mcrypto": "1.29.15",
|
|
59
|
+
"@ocap/message": "1.29.15",
|
|
60
|
+
"@ocap/state": "1.29.15",
|
|
61
|
+
"@ocap/types": "1.29.15",
|
|
62
|
+
"@ocap/util": "1.29.15",
|
|
63
|
+
"@ocap/wallet": "1.29.15",
|
|
64
64
|
"debug": "^4.4.3",
|
|
65
65
|
"lodash": "^4.17.23"
|
|
66
66
|
}
|