@ocap/tx-protocols 1.28.9 → 1.29.1
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/esm/execute.d.mts +53 -0
- package/esm/execute.mjs +225 -0
- package/esm/index.d.mts +95 -0
- package/esm/index.mjs +100 -0
- package/esm/pipes/ensure-cost.d.mts +18 -0
- package/esm/pipes/ensure-cost.mjs +136 -0
- package/esm/pipes/ensure-gas.d.mts +14 -0
- package/esm/pipes/ensure-gas.mjs +38 -0
- package/esm/protocols/account/delegate.d.mts +4 -0
- package/esm/protocols/account/delegate.mjs +195 -0
- package/esm/protocols/account/migrate.d.mts +4 -0
- package/esm/protocols/account/migrate.mjs +130 -0
- package/esm/protocols/account/revoke-delegate.d.mts +4 -0
- package/esm/protocols/account/revoke-delegate.mjs +102 -0
- package/esm/protocols/asset/acquire-v2.d.mts +9 -0
- package/esm/protocols/asset/acquire-v2.mjs +213 -0
- package/esm/protocols/asset/acquire-v3.d.mts +17 -0
- package/esm/protocols/asset/acquire-v3.mjs +265 -0
- package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
- package/esm/protocols/asset/calls/transfer.d.mts +4 -0
- package/esm/protocols/asset/calls/transfer.mjs +32 -0
- package/esm/protocols/asset/consume.d.mts +4 -0
- package/esm/protocols/asset/consume.mjs +92 -0
- package/esm/protocols/asset/create.d.mts +4 -0
- package/esm/protocols/asset/create.mjs +136 -0
- package/esm/protocols/asset/mint.d.mts +4 -0
- package/esm/protocols/asset/mint.mjs +156 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
- package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
- package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
- package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
- package/esm/protocols/asset/update.d.mts +4 -0
- package/esm/protocols/asset/update.mjs +111 -0
- package/esm/protocols/factory/create.d.mts +29 -0
- package/esm/protocols/factory/create.mjs +155 -0
- package/esm/protocols/governance/claim-stake.d.mts +27 -0
- package/esm/protocols/governance/claim-stake.mjs +220 -0
- package/esm/protocols/governance/return-stake.d.mts +27 -0
- package/esm/protocols/governance/return-stake.mjs +211 -0
- package/esm/protocols/governance/revoke-stake.d.mts +27 -0
- package/esm/protocols/governance/revoke-stake.mjs +178 -0
- package/esm/protocols/governance/slash-stake.d.mts +17 -0
- package/esm/protocols/governance/slash-stake.mjs +213 -0
- package/esm/protocols/governance/stake.d.mts +15 -0
- package/esm/protocols/governance/stake.mjs +270 -0
- package/esm/protocols/rollup/claim-reward.d.mts +11 -0
- package/esm/protocols/rollup/claim-reward.mjs +322 -0
- package/esm/protocols/rollup/close.d.mts +4 -0
- package/esm/protocols/rollup/close.mjs +105 -0
- package/esm/protocols/rollup/create-block.d.mts +11 -0
- package/esm/protocols/rollup/create-block.mjs +303 -0
- package/esm/protocols/rollup/create.d.mts +4 -0
- package/esm/protocols/rollup/create.mjs +164 -0
- package/esm/protocols/rollup/join.d.mts +4 -0
- package/esm/protocols/rollup/join.mjs +152 -0
- package/esm/protocols/rollup/leave.d.mts +4 -0
- package/esm/protocols/rollup/leave.mjs +137 -0
- package/esm/protocols/rollup/migrate.d.mts +4 -0
- package/esm/protocols/rollup/migrate.mjs +85 -0
- package/esm/protocols/rollup/pause.d.mts +4 -0
- package/esm/protocols/rollup/pause.mjs +76 -0
- package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
- package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
- package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
- package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
- package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
- package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
- package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
- package/esm/protocols/rollup/resume.d.mts +4 -0
- package/esm/protocols/rollup/resume.mjs +79 -0
- package/esm/protocols/rollup/update.d.mts +4 -0
- package/esm/protocols/rollup/update.mjs +111 -0
- package/esm/protocols/token/create.d.mts +4 -0
- package/esm/protocols/token/create.mjs +150 -0
- package/esm/protocols/token/deposit-v2.d.mts +11 -0
- package/esm/protocols/token/deposit-v2.mjs +216 -0
- package/esm/protocols/token/withdraw-v2.d.mts +9 -0
- package/esm/protocols/token/withdraw-v2.mjs +222 -0
- package/esm/protocols/token-factory/burn.d.mts +15 -0
- package/esm/protocols/token-factory/burn.mjs +233 -0
- package/esm/protocols/token-factory/create.d.mts +4 -0
- package/esm/protocols/token-factory/create.mjs +254 -0
- package/esm/protocols/token-factory/mint.d.mts +15 -0
- package/esm/protocols/token-factory/mint.mjs +234 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
- package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
- package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
- package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
- package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
- package/esm/protocols/token-factory/update.d.mts +10 -0
- package/esm/protocols/token-factory/update.mjs +152 -0
- package/esm/protocols/trade/exchange-v2.d.mts +9 -0
- package/esm/protocols/trade/exchange-v2.mjs +239 -0
- package/esm/protocols/trade/transfer-v2.d.mts +9 -0
- package/esm/protocols/trade/transfer-v2.mjs +226 -0
- package/esm/protocols/trade/transfer-v3.d.mts +17 -0
- package/esm/protocols/trade/transfer-v3.mjs +270 -0
- package/esm/util.d.mts +141 -0
- package/esm/util.mjs +278 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/execute.cjs +231 -0
- package/lib/execute.d.cts +53 -0
- package/lib/index.cjs +105 -0
- package/lib/index.d.cts +95 -0
- package/lib/pipes/ensure-cost.cjs +141 -0
- package/lib/pipes/ensure-cost.d.cts +18 -0
- package/lib/pipes/ensure-gas.cjs +41 -0
- package/lib/pipes/ensure-gas.d.cts +14 -0
- package/lib/protocols/account/delegate.cjs +201 -0
- package/lib/protocols/account/delegate.d.cts +4 -0
- package/lib/protocols/account/migrate.cjs +135 -0
- package/lib/protocols/account/migrate.d.cts +4 -0
- package/lib/protocols/account/revoke-delegate.cjs +107 -0
- package/lib/protocols/account/revoke-delegate.d.cts +4 -0
- package/lib/protocols/asset/acquire-v2.cjs +216 -0
- package/lib/protocols/asset/acquire-v2.d.cts +9 -0
- package/lib/protocols/asset/acquire-v3.cjs +269 -0
- package/lib/protocols/asset/acquire-v3.d.cts +17 -0
- package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
- package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
- package/lib/protocols/asset/calls/transfer.cjs +35 -0
- package/lib/protocols/asset/calls/transfer.d.cts +4 -0
- package/lib/protocols/asset/consume.cjs +95 -0
- package/lib/protocols/asset/consume.d.cts +4 -0
- package/lib/protocols/asset/create.cjs +140 -0
- package/lib/protocols/asset/create.d.cts +4 -0
- package/lib/protocols/asset/mint.cjs +159 -0
- package/lib/protocols/asset/mint.d.cts +4 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
- package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
- package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
- package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
- package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
- package/lib/protocols/asset/update.cjs +114 -0
- package/lib/protocols/asset/update.d.cts +4 -0
- package/lib/protocols/factory/create.cjs +161 -0
- package/lib/protocols/factory/create.d.cts +29 -0
- package/lib/protocols/governance/claim-stake.cjs +223 -0
- package/lib/protocols/governance/claim-stake.d.cts +27 -0
- package/lib/protocols/governance/return-stake.cjs +215 -0
- package/lib/protocols/governance/return-stake.d.cts +27 -0
- package/lib/protocols/governance/revoke-stake.cjs +182 -0
- package/lib/protocols/governance/revoke-stake.d.cts +27 -0
- package/lib/protocols/governance/slash-stake.cjs +217 -0
- package/lib/protocols/governance/slash-stake.d.cts +17 -0
- package/lib/protocols/governance/stake.cjs +275 -0
- package/lib/protocols/governance/stake.d.cts +15 -0
- package/lib/protocols/rollup/claim-reward.cjs +328 -0
- package/lib/protocols/rollup/claim-reward.d.cts +11 -0
- package/lib/protocols/rollup/close.cjs +107 -0
- package/lib/protocols/rollup/close.d.cts +4 -0
- package/lib/protocols/rollup/create-block.cjs +309 -0
- package/lib/protocols/rollup/create-block.d.cts +11 -0
- package/lib/protocols/rollup/create.cjs +169 -0
- package/lib/protocols/rollup/create.d.cts +4 -0
- package/lib/protocols/rollup/join.cjs +157 -0
- package/lib/protocols/rollup/join.d.cts +4 -0
- package/lib/protocols/rollup/leave.cjs +141 -0
- package/lib/protocols/rollup/leave.d.cts +4 -0
- package/lib/protocols/rollup/migrate.cjs +87 -0
- package/lib/protocols/rollup/migrate.d.cts +4 -0
- package/lib/protocols/rollup/pause.cjs +78 -0
- package/lib/protocols/rollup/pause.d.cts +4 -0
- package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
- package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
- package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
- package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
- package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
- package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
- package/lib/protocols/rollup/resume.cjs +81 -0
- package/lib/protocols/rollup/resume.d.cts +4 -0
- package/lib/protocols/rollup/update.cjs +114 -0
- package/lib/protocols/rollup/update.d.cts +4 -0
- package/lib/protocols/token/create.cjs +156 -0
- package/lib/protocols/token/create.d.cts +4 -0
- package/lib/protocols/token/deposit-v2.cjs +219 -0
- package/lib/protocols/token/deposit-v2.d.cts +11 -0
- package/lib/protocols/token/withdraw-v2.cjs +225 -0
- package/lib/protocols/token/withdraw-v2.d.cts +9 -0
- package/lib/protocols/token-factory/burn.cjs +236 -0
- package/lib/protocols/token-factory/burn.d.cts +15 -0
- package/lib/protocols/token-factory/create.cjs +260 -0
- package/lib/protocols/token-factory/create.d.cts +4 -0
- package/lib/protocols/token-factory/mint.cjs +237 -0
- package/lib/protocols/token-factory/mint.d.cts +15 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
- package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
- package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
- package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
- package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
- package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
- package/lib/protocols/token-factory/update.cjs +155 -0
- package/lib/protocols/token-factory/update.d.cts +10 -0
- package/lib/protocols/trade/exchange-v2.cjs +243 -0
- package/lib/protocols/trade/exchange-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v2.cjs +229 -0
- package/lib/protocols/trade/transfer-v2.d.cts +9 -0
- package/lib/protocols/trade/transfer-v3.cjs +274 -0
- package/lib/protocols/trade/transfer-v3.d.cts +17 -0
- package/lib/util.cjs +296 -0
- package/lib/util.d.cts +141 -0
- package/package.json +49 -22
- package/tools/fixtures.ts +564 -0
- package/lib/execute.js +0 -254
- package/lib/index.js +0 -117
- package/lib/pipes/ensure-cost.js +0 -193
- package/lib/pipes/ensure-gas.js +0 -48
- package/lib/protocols/account/delegate.js +0 -223
- package/lib/protocols/account/migrate.js +0 -153
- package/lib/protocols/account/revoke-delegate.js +0 -110
- package/lib/protocols/asset/acquire-v2.js +0 -262
- package/lib/protocols/asset/acquire-v3.js +0 -330
- package/lib/protocols/asset/calls/README.md +0 -5
- package/lib/protocols/asset/calls/transfer-token.js +0 -36
- package/lib/protocols/asset/calls/transfer.js +0 -28
- package/lib/protocols/asset/consume.js +0 -105
- package/lib/protocols/asset/create.js +0 -151
- package/lib/protocols/asset/mint.js +0 -199
- package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
- package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
- package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
- package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
- package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
- package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
- package/lib/protocols/asset/update.js +0 -131
- package/lib/protocols/factory/create.js +0 -191
- package/lib/protocols/governance/claim-stake.js +0 -266
- package/lib/protocols/governance/return-stake.js +0 -248
- package/lib/protocols/governance/revoke-stake.js +0 -172
- package/lib/protocols/governance/slash-stake.js +0 -271
- package/lib/protocols/governance/stake.js +0 -303
- package/lib/protocols/rollup/claim-reward.js +0 -342
- package/lib/protocols/rollup/close.js +0 -104
- package/lib/protocols/rollup/create-block.js +0 -413
- package/lib/protocols/rollup/create.js +0 -197
- package/lib/protocols/rollup/join.js +0 -182
- package/lib/protocols/rollup/leave.js +0 -145
- package/lib/protocols/rollup/migrate.js +0 -85
- package/lib/protocols/rollup/pause.js +0 -75
- package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
- package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
- package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
- package/lib/protocols/rollup/pipes/verify-status.js +0 -30
- package/lib/protocols/rollup/resume.js +0 -75
- package/lib/protocols/rollup/update.js +0 -122
- package/lib/protocols/token/create.js +0 -199
- package/lib/protocols/token/deposit-v2.js +0 -290
- package/lib/protocols/token/withdraw-v2.js +0 -305
- package/lib/protocols/token-factory/burn.js +0 -371
- package/lib/protocols/token-factory/create.js +0 -342
- package/lib/protocols/token-factory/mint.js +0 -385
- package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
- package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
- package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
- package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
- package/lib/protocols/token-factory/update.js +0 -208
- package/lib/protocols/trade/exchange-v2.js +0 -239
- package/lib/protocols/trade/transfer-v2.js +0 -233
- package/lib/protocols/trade/transfer-v3.js +0 -333
- package/lib/util.js +0 -442
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
6
|
+
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
7
|
+
const require_protocols_rollup_pipes_verify_evidence = require('./pipes/verify-evidence.cjs');
|
|
8
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
|
+
let _arcblock_did = require("@arcblock/did");
|
|
11
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
12
|
+
let _ocap_state = require("@ocap/state");
|
|
13
|
+
let _ocap_util = require("@ocap/util");
|
|
14
|
+
let debug = require("debug");
|
|
15
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
16
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
17
|
+
let _ocap_merkle_tree = require("@ocap/merkle-tree");
|
|
18
|
+
_ocap_merkle_tree = require_rolldown_runtime.__toESM(_ocap_merkle_tree);
|
|
19
|
+
let url_join = require("url-join");
|
|
20
|
+
url_join = require_rolldown_runtime.__toESM(url_join);
|
|
21
|
+
|
|
22
|
+
//#region src/protocols/rollup/join.ts
|
|
23
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:join-rollup");
|
|
24
|
+
const runner = new _ocap_tx_pipeline.Runner("join_rollup");
|
|
25
|
+
const schema = _arcblock_validator.Joi.object({
|
|
26
|
+
rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
|
|
27
|
+
endpoint: _arcblock_validator.Joi.string().uri({ scheme: [/https?/] }).required(),
|
|
28
|
+
evidence: _arcblock_validator.Joi.object({ hash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required() }).required(),
|
|
29
|
+
signaturesList: _arcblock_validator.schemas.multiSig.min(1).required(),
|
|
30
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
31
|
+
}).options({
|
|
32
|
+
stripUnknown: true,
|
|
33
|
+
noDefaults: false
|
|
34
|
+
});
|
|
35
|
+
runner.use(({ itx }, next) => {
|
|
36
|
+
const { error } = schema.validate(itx);
|
|
37
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
38
|
+
});
|
|
39
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
40
|
+
from: "itx.rollup",
|
|
41
|
+
to: "rollupState",
|
|
42
|
+
status: "INVALID_ROLLUP",
|
|
43
|
+
table: "rollup"
|
|
44
|
+
}));
|
|
45
|
+
runner.use(require_protocols_rollup_pipes_verify_status.default({ paused: false }));
|
|
46
|
+
runner.use((context, next) => {
|
|
47
|
+
const { tx, itx, rollupState } = context;
|
|
48
|
+
const validator = {
|
|
49
|
+
pk: (0, _ocap_util.toHex)(tx.pk),
|
|
50
|
+
address: tx.from,
|
|
51
|
+
endpoint: itx.endpoint
|
|
52
|
+
};
|
|
53
|
+
if ((0, _arcblock_did.isEthereumDid)(tx.from) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Invalid tx.from: only ethereum compatible address can join rollup"));
|
|
54
|
+
if (rollupState?.validators.some((x) => x.address === validator.address)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Address ${validator.address} already exist in validators`));
|
|
55
|
+
if (rollupState?.validators.some((x) => (0, url_join.default)(x.endpoint, "/") === (0, url_join.default)(validator.endpoint, "/"))) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Endpoint ${validator.endpoint} already exist in validators`));
|
|
56
|
+
context.newValidator = validator;
|
|
57
|
+
context.validatorsHash = _ocap_merkle_tree.default.getListHash([validator.address]);
|
|
58
|
+
return next();
|
|
59
|
+
});
|
|
60
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
61
|
+
signersKey: "itx.signaturesList",
|
|
62
|
+
allowSender: false
|
|
63
|
+
}));
|
|
64
|
+
runner.use(require_protocols_rollup_pipes_verify_evidence.default({
|
|
65
|
+
evidenceKey: "validatorsHash",
|
|
66
|
+
signaturesKey: "itx.signaturesList",
|
|
67
|
+
verifyMethod: "ethVerify"
|
|
68
|
+
}));
|
|
69
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
70
|
+
from: "itx.evidence.hash",
|
|
71
|
+
to: "evidenceState",
|
|
72
|
+
status: "OK",
|
|
73
|
+
table: "evidence"
|
|
74
|
+
}));
|
|
75
|
+
runner.use(({ evidenceState }, next) => {
|
|
76
|
+
if (evidenceState) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Join evidence already seen on this chain"));
|
|
77
|
+
return next();
|
|
78
|
+
});
|
|
79
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
80
|
+
signersKey: "tx.signaturesList",
|
|
81
|
+
allowSender: false
|
|
82
|
+
}));
|
|
83
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
84
|
+
runner.use((context, next) => {
|
|
85
|
+
const { tx, itx } = context;
|
|
86
|
+
context.stakeAddress = (0, _arcblock_did_util.toStakeAddress)(tx.from, itx.rollup);
|
|
87
|
+
return next();
|
|
88
|
+
});
|
|
89
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
90
|
+
from: "stakeAddress",
|
|
91
|
+
to: "stakeState",
|
|
92
|
+
status: "INVALID_STAKE_STATE",
|
|
93
|
+
table: "stake"
|
|
94
|
+
}));
|
|
95
|
+
runner.use((context, next) => {
|
|
96
|
+
const { stakeState, rollupState } = context;
|
|
97
|
+
if (stakeState?.revocable === false) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", `Staking already locked: ${stakeState.address}`));
|
|
98
|
+
const actualStake = new _ocap_util.BN(stakeState?.tokens[rollupState?.tokenAddress || ""] || 0);
|
|
99
|
+
const requiredStake = new _ocap_util.BN(rollupState?.minStakeAmount || 0);
|
|
100
|
+
if (actualStake.lt(requiredStake)) return next(new _ocap_util_lib_error.CustomError("INVALID_STAKE_STATE", `Staking does not match min stake amount: ${requiredStake}`));
|
|
101
|
+
return next();
|
|
102
|
+
});
|
|
103
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
104
|
+
from: "tx.from",
|
|
105
|
+
to: "senderState",
|
|
106
|
+
status: "INVALID_SENDER_STATE",
|
|
107
|
+
table: "account"
|
|
108
|
+
}));
|
|
109
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
110
|
+
from: "signers",
|
|
111
|
+
to: "signerStates",
|
|
112
|
+
status: "INVALID_SIGNER_STATE",
|
|
113
|
+
table: "account"
|
|
114
|
+
}));
|
|
115
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
116
|
+
signerKey: "signerStates",
|
|
117
|
+
stateKey: "senderState",
|
|
118
|
+
addressKey: "tx.from"
|
|
119
|
+
}));
|
|
120
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
121
|
+
create: 1,
|
|
122
|
+
update: 3,
|
|
123
|
+
payment: 0
|
|
124
|
+
})));
|
|
125
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
126
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
127
|
+
runner.use(async (context, next) => {
|
|
128
|
+
const { tx, itx, rollupState, statedb, senderState, stakeState, newValidator, stakeAddress, senderUpdates, updateVaults } = context;
|
|
129
|
+
const newValidators = rollupState.validators.concat([newValidator]);
|
|
130
|
+
const [newSenderState, newRollupState, newStakeState, newEvidenceState] = await Promise.all([
|
|
131
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
132
|
+
nonce: tx.nonce,
|
|
133
|
+
...senderUpdates
|
|
134
|
+
}, context), context),
|
|
135
|
+
statedb.rollup.update(rollupState.address, _ocap_state.rollup.update(rollupState, { validators: newValidators }, context), context),
|
|
136
|
+
statedb.stake.update(stakeAddress, _ocap_state.stake.update(stakeState, {
|
|
137
|
+
revocable: false,
|
|
138
|
+
revokeWaitingPeriod: rollupState.leaveWaitingPeriod
|
|
139
|
+
}, context), context),
|
|
140
|
+
statedb.evidence.create(itx.evidence.hash, _ocap_state.evidence.create({
|
|
141
|
+
hash: itx.evidence.hash,
|
|
142
|
+
data: "rollup-join"
|
|
143
|
+
}, context), context)
|
|
144
|
+
]);
|
|
145
|
+
if (updateVaults) await updateVaults();
|
|
146
|
+
context.senderState = newSenderState;
|
|
147
|
+
context.rollupState = newRollupState;
|
|
148
|
+
context.stakeState = newStakeState;
|
|
149
|
+
context.evidenceState = newEvidenceState;
|
|
150
|
+
debug$1("join-rollup", newValidators);
|
|
151
|
+
next();
|
|
152
|
+
}, { persistError: true });
|
|
153
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
154
|
+
var join_default = runner;
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
exports.default = join_default;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
const require_protocols_rollup_pipes_ensure_validator = require('./pipes/ensure-validator.cjs');
|
|
6
|
+
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
7
|
+
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
8
|
+
const require_protocols_rollup_pipes_verify_evidence = require('./pipes/verify-evidence.cjs');
|
|
9
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
10
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
11
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
12
|
+
let _ocap_state = require("@ocap/state");
|
|
13
|
+
let debug = require("debug");
|
|
14
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
15
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
16
|
+
let _ocap_merkle_tree = require("@ocap/merkle-tree");
|
|
17
|
+
_ocap_merkle_tree = require_rolldown_runtime.__toESM(_ocap_merkle_tree);
|
|
18
|
+
|
|
19
|
+
//#region src/protocols/rollup/leave.ts
|
|
20
|
+
const debug$1 = (0, debug.default)("@ocap/tx-protocols:leave-rollup");
|
|
21
|
+
const runner = new _ocap_tx_pipeline.Runner("leave_rollup");
|
|
22
|
+
const schema = _arcblock_validator.Joi.object({
|
|
23
|
+
rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
|
|
24
|
+
evidence: _arcblock_validator.Joi.object({ hash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required() }).required(),
|
|
25
|
+
signaturesList: _arcblock_validator.schemas.multiSig.min(1).required(),
|
|
26
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
27
|
+
}).options({
|
|
28
|
+
stripUnknown: true,
|
|
29
|
+
noDefaults: false
|
|
30
|
+
});
|
|
31
|
+
runner.use(({ itx }, next) => {
|
|
32
|
+
const { error } = schema.validate(itx);
|
|
33
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
34
|
+
});
|
|
35
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
36
|
+
from: "itx.rollup",
|
|
37
|
+
to: "rollupState",
|
|
38
|
+
status: "INVALID_ROLLUP",
|
|
39
|
+
table: "rollup"
|
|
40
|
+
}));
|
|
41
|
+
runner.use(require_protocols_rollup_pipes_ensure_validator.default(false));
|
|
42
|
+
runner.use(require_protocols_rollup_pipes_verify_status.default({ paused: false }));
|
|
43
|
+
runner.use((context, next) => {
|
|
44
|
+
context.validatorsHash = _ocap_merkle_tree.default.getListHash([context.tx.from]);
|
|
45
|
+
return next();
|
|
46
|
+
});
|
|
47
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
48
|
+
signersKey: "itx.signaturesList",
|
|
49
|
+
allowSender: false,
|
|
50
|
+
allowShrink: true
|
|
51
|
+
}));
|
|
52
|
+
runner.use(require_protocols_rollup_pipes_verify_evidence.default({
|
|
53
|
+
evidenceKey: "validatorsHash",
|
|
54
|
+
signaturesKey: "itx.signaturesList",
|
|
55
|
+
verifyMethod: "ethVerify"
|
|
56
|
+
}));
|
|
57
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
58
|
+
from: "itx.evidence.hash",
|
|
59
|
+
to: "evidenceState",
|
|
60
|
+
status: "OK",
|
|
61
|
+
table: "evidence"
|
|
62
|
+
}));
|
|
63
|
+
runner.use((context, next) => {
|
|
64
|
+
if (context.evidenceState) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Leave evidence already seen on this chain"));
|
|
65
|
+
return next();
|
|
66
|
+
});
|
|
67
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
68
|
+
signersKey: "tx.signaturesList",
|
|
69
|
+
allowSender: false,
|
|
70
|
+
allowShrink: true
|
|
71
|
+
}));
|
|
72
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
73
|
+
runner.use((context, next) => {
|
|
74
|
+
const { tx, rollupState } = context;
|
|
75
|
+
if (rollupState?.seedValidators.some((x) => x.address === tx.from)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Address ${tx.from} can not leave since it's seed validator`));
|
|
76
|
+
if (rollupState?.validators.some((x) => x.address === tx.from) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Address ${tx.from} not exist in validator whitelist`));
|
|
77
|
+
return next();
|
|
78
|
+
});
|
|
79
|
+
runner.use((context, next) => {
|
|
80
|
+
const { tx, itx } = context;
|
|
81
|
+
context.stakeAddress = (0, _arcblock_did_util.toStakeAddress)(tx.from, itx.rollup);
|
|
82
|
+
return next();
|
|
83
|
+
});
|
|
84
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
85
|
+
from: "stakeAddress",
|
|
86
|
+
to: "stakeState",
|
|
87
|
+
status: "INVALID_STAKE_STATE",
|
|
88
|
+
table: "stake"
|
|
89
|
+
}));
|
|
90
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
91
|
+
from: "tx.from",
|
|
92
|
+
to: "senderState",
|
|
93
|
+
status: "INVALID_SENDER_STATE",
|
|
94
|
+
table: "account"
|
|
95
|
+
}));
|
|
96
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
97
|
+
from: "signers",
|
|
98
|
+
to: "signerStates",
|
|
99
|
+
status: "INVALID_SIGNER_STATE",
|
|
100
|
+
table: "account"
|
|
101
|
+
}));
|
|
102
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
103
|
+
signerKey: "signerStates",
|
|
104
|
+
stateKey: "senderState",
|
|
105
|
+
addressKey: "tx.from"
|
|
106
|
+
}));
|
|
107
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
108
|
+
create: 1,
|
|
109
|
+
update: 3,
|
|
110
|
+
payment: 0
|
|
111
|
+
})));
|
|
112
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
113
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
114
|
+
runner.use(async (context, next) => {
|
|
115
|
+
const { tx, itx, rollupState, statedb, senderState, stakeState, stakeAddress, senderUpdates, updateVaults } = context;
|
|
116
|
+
const newValidators = rollupState.validators.filter((x) => x.address !== tx.from);
|
|
117
|
+
const [newSenderState, newRollupState, newStakeState, newEvidenceState] = await Promise.all([
|
|
118
|
+
statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
119
|
+
nonce: tx.nonce,
|
|
120
|
+
...senderUpdates
|
|
121
|
+
}, context), context),
|
|
122
|
+
statedb.rollup.update(rollupState.address, _ocap_state.rollup.update(rollupState, { validators: newValidators }, context), context),
|
|
123
|
+
statedb.stake.update(stakeAddress, _ocap_state.stake.update(stakeState, { revocable: true }, context), context),
|
|
124
|
+
statedb.evidence.create(itx.evidence.hash, _ocap_state.evidence.create({
|
|
125
|
+
hash: itx.evidence.hash,
|
|
126
|
+
data: "rollup-leave"
|
|
127
|
+
}, context), context)
|
|
128
|
+
]);
|
|
129
|
+
if (updateVaults) await updateVaults();
|
|
130
|
+
context.senderState = newSenderState;
|
|
131
|
+
context.rollupState = newRollupState;
|
|
132
|
+
context.stakeState = newStakeState;
|
|
133
|
+
context.evidenceState = newEvidenceState;
|
|
134
|
+
debug$1("leave-rollup", newValidators);
|
|
135
|
+
next();
|
|
136
|
+
}, { persistError: true });
|
|
137
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
138
|
+
var leave_default = runner;
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
exports.default = leave_default;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
const require_protocols_rollup_pipes_ensure_validator = require('./pipes/ensure-validator.cjs');
|
|
6
|
+
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
7
|
+
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
8
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
|
+
let _ocap_state = require("@ocap/state");
|
|
11
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
12
|
+
|
|
13
|
+
//#region src/protocols/rollup/migrate.ts
|
|
14
|
+
const runner = new _ocap_tx_pipeline.Runner("migrate_rollup");
|
|
15
|
+
const schema = _arcblock_validator.Joi.object({
|
|
16
|
+
rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
|
|
17
|
+
to: _arcblock_validator.Joi.DID().prefix().wallet("ethereum").required(),
|
|
18
|
+
type: _arcblock_validator.Joi.string().trim().valid("vault", "contract").required(),
|
|
19
|
+
message: _arcblock_validator.Joi.string().trim().min(1).max(512).required(),
|
|
20
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
21
|
+
}).options({
|
|
22
|
+
stripUnknown: true,
|
|
23
|
+
noDefaults: false
|
|
24
|
+
});
|
|
25
|
+
runner.use(({ itx }, next) => {
|
|
26
|
+
const { error } = schema.validate(itx);
|
|
27
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
28
|
+
});
|
|
29
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
30
|
+
from: "itx.rollup",
|
|
31
|
+
to: "rollupState",
|
|
32
|
+
status: "INVALID_ROLLUP",
|
|
33
|
+
table: "rollup"
|
|
34
|
+
}));
|
|
35
|
+
runner.use(require_protocols_rollup_pipes_ensure_validator.default(true));
|
|
36
|
+
runner.use(require_protocols_rollup_pipes_verify_status.default({
|
|
37
|
+
paused: true,
|
|
38
|
+
closed: false
|
|
39
|
+
}));
|
|
40
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
41
|
+
signersKey: "tx.signaturesList",
|
|
42
|
+
allowSender: true
|
|
43
|
+
}));
|
|
44
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
45
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
46
|
+
from: "tx.from",
|
|
47
|
+
to: "senderState",
|
|
48
|
+
status: "INVALID_SENDER_STATE",
|
|
49
|
+
table: "account"
|
|
50
|
+
}));
|
|
51
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
52
|
+
from: "signers",
|
|
53
|
+
to: "signerStates",
|
|
54
|
+
status: "INVALID_SIGNER_STATE",
|
|
55
|
+
table: "account"
|
|
56
|
+
}));
|
|
57
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
58
|
+
signerKey: "signerStates",
|
|
59
|
+
stateKey: "senderState",
|
|
60
|
+
addressKey: "tx.from"
|
|
61
|
+
}));
|
|
62
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
63
|
+
create: 0,
|
|
64
|
+
update: 2,
|
|
65
|
+
payment: 0
|
|
66
|
+
})));
|
|
67
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
68
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
69
|
+
runner.use(async (context, next) => {
|
|
70
|
+
const { tx, itx, statedb, rollupState, senderState, senderUpdates, updateVaults } = context;
|
|
71
|
+
let updates = {};
|
|
72
|
+
if (itx.type === "vault") updates = _ocap_state.rollup.migrateVault(rollupState, itx.to, context);
|
|
73
|
+
if (itx.type === "contract") updates = _ocap_state.rollup.migrateContract(rollupState, itx.to, context);
|
|
74
|
+
const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
75
|
+
nonce: tx.nonce,
|
|
76
|
+
...senderUpdates
|
|
77
|
+
}, context), context), statedb.rollup.update(itx.rollup, updates, context)]);
|
|
78
|
+
if (updateVaults) await updateVaults();
|
|
79
|
+
context.senderState = newSenderState;
|
|
80
|
+
context.rollupState = newRollupState;
|
|
81
|
+
next();
|
|
82
|
+
}, { persistError: true });
|
|
83
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
84
|
+
var migrate_default = runner;
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
exports.default = migrate_default;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_pipes_ensure_cost = require('../../pipes/ensure-cost.cjs');
|
|
4
|
+
const require_pipes_ensure_gas = require('../../pipes/ensure-gas.cjs');
|
|
5
|
+
const require_protocols_rollup_pipes_ensure_validator = require('./pipes/ensure-validator.cjs');
|
|
6
|
+
const require_protocols_rollup_pipes_verify_signers = require('./pipes/verify-signers.cjs');
|
|
7
|
+
const require_protocols_rollup_pipes_verify_status = require('./pipes/verify-status.cjs');
|
|
8
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
10
|
+
let _ocap_state = require("@ocap/state");
|
|
11
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
12
|
+
|
|
13
|
+
//#region src/protocols/rollup/pause.ts
|
|
14
|
+
const runner = new _ocap_tx_pipeline.Runner("pause_rollup");
|
|
15
|
+
const schema = _arcblock_validator.Joi.object({
|
|
16
|
+
rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
|
|
17
|
+
data: _arcblock_validator.Joi.any().optional().allow(null)
|
|
18
|
+
}).options({
|
|
19
|
+
stripUnknown: true,
|
|
20
|
+
noDefaults: false
|
|
21
|
+
});
|
|
22
|
+
runner.use(({ itx }, next) => {
|
|
23
|
+
const { error } = schema.validate(itx);
|
|
24
|
+
return next(error ? new _ocap_util_lib_error.CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
|
|
25
|
+
});
|
|
26
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
27
|
+
from: "itx.rollup",
|
|
28
|
+
to: "rollupState",
|
|
29
|
+
status: "INVALID_ROLLUP",
|
|
30
|
+
table: "rollup"
|
|
31
|
+
}));
|
|
32
|
+
runner.use(require_protocols_rollup_pipes_ensure_validator.default(true));
|
|
33
|
+
runner.use(require_protocols_rollup_pipes_verify_status.default({ paused: false }));
|
|
34
|
+
runner.use(require_protocols_rollup_pipes_verify_signers.default({
|
|
35
|
+
signersKey: "tx.signaturesList",
|
|
36
|
+
allowSender: true
|
|
37
|
+
}));
|
|
38
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyMultiSigV2({ signersKey: "signers" }));
|
|
39
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
40
|
+
from: "tx.from",
|
|
41
|
+
to: "senderState",
|
|
42
|
+
status: "INVALID_SENDER_STATE",
|
|
43
|
+
table: "account"
|
|
44
|
+
}));
|
|
45
|
+
runner.use(_ocap_tx_pipeline.pipes.ExtractState({
|
|
46
|
+
from: "signers",
|
|
47
|
+
to: "signerStates",
|
|
48
|
+
status: "INVALID_SIGNER_STATE",
|
|
49
|
+
table: "account"
|
|
50
|
+
}));
|
|
51
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyAccountMigration({
|
|
52
|
+
signerKey: "signerStates",
|
|
53
|
+
stateKey: "senderState",
|
|
54
|
+
addressKey: "tx.from"
|
|
55
|
+
}));
|
|
56
|
+
runner.use(require_pipes_ensure_gas.default(() => ({
|
|
57
|
+
create: 0,
|
|
58
|
+
update: 2,
|
|
59
|
+
payment: 0
|
|
60
|
+
})));
|
|
61
|
+
runner.use(require_pipes_ensure_cost.default({ attachSenderChanges: true }));
|
|
62
|
+
runner.use(_ocap_tx_pipeline.pipes.TakeStateSnapshot());
|
|
63
|
+
runner.use(async (context, next) => {
|
|
64
|
+
const { tx, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
|
|
65
|
+
const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, _ocap_state.account.update(senderState, {
|
|
66
|
+
nonce: tx.nonce,
|
|
67
|
+
...senderUpdates
|
|
68
|
+
}, context), context), statedb.rollup.update(itx.rollup, _ocap_state.rollup.pause(rollupState, context), context)]);
|
|
69
|
+
if (updateVaults) await updateVaults();
|
|
70
|
+
context.senderState = newSenderState;
|
|
71
|
+
context.rollupState = newRollupState;
|
|
72
|
+
next();
|
|
73
|
+
}, { persistError: true });
|
|
74
|
+
runner.use(_ocap_tx_pipeline.pipes.VerifyStateDiff());
|
|
75
|
+
var pause_default = runner;
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.default = pause_default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
|
|
5
|
+
//#region src/protocols/rollup/pipes/ensure-validator.ts
|
|
6
|
+
const ensure_validator = (isSeed) => (context, next) => {
|
|
7
|
+
const { rollupState, tx } = context;
|
|
8
|
+
if ((isSeed ? rollupState.seedValidators : rollupState.validators).some((x) => x.address === tx?.from) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Tx sender is not an expected validator"));
|
|
9
|
+
return next();
|
|
10
|
+
};
|
|
11
|
+
var ensure_validator_default = ensure_validator;
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.default = ensure_validator_default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
let lodash_get = require("lodash/get");
|
|
5
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
6
|
+
let _arcblock_did = require("@arcblock/did");
|
|
7
|
+
let _ocap_util = require("@ocap/util");
|
|
8
|
+
let _ocap_wallet = require("@ocap/wallet");
|
|
9
|
+
|
|
10
|
+
//#region src/protocols/rollup/pipes/verify-evidence.ts
|
|
11
|
+
function CreateVerifyEvidencePipe({ evidenceKey, signaturesKey, verifyMethod = "verify" }) {
|
|
12
|
+
if (["verify", "ethVerify"].includes(verifyMethod) === false) throw new _ocap_util_lib_error.CustomError("INVALID_ARGUMENT", `Invalid verify method: ${verifyMethod}, supported methods are: verify, ethVerify`);
|
|
13
|
+
return async (context, next) => {
|
|
14
|
+
const evidence = (0, lodash_get.default)(context, evidenceKey);
|
|
15
|
+
const signatures = (0, lodash_get.default)(context, signaturesKey);
|
|
16
|
+
for (const sig of signatures) {
|
|
17
|
+
const { signer, pk, delegator, signature } = sig;
|
|
18
|
+
const address = delegator || signer;
|
|
19
|
+
const wallet = (0, _ocap_wallet.fromPublicKey)(pk, (0, _arcblock_did.toTypeInfo)(address));
|
|
20
|
+
try {
|
|
21
|
+
if (await wallet[verifyMethod]((0, _ocap_util.toHex)(evidence), (0, _ocap_util.toHex)(signature)) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Signature for evidence from ${address} is not valid`));
|
|
22
|
+
} catch (err) {
|
|
23
|
+
return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Signature for evidence from ${address} verify failed: ${err.message}`));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return next();
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var verify_evidence_default = CreateVerifyEvidencePipe;
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.default = verify_evidence_default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
2
|
+
|
|
3
|
+
//#region src/protocols/rollup/pipes/verify-evidence.d.ts
|
|
4
|
+
interface IVerifyEvidenceOptions {
|
|
5
|
+
evidenceKey: string;
|
|
6
|
+
signaturesKey: string;
|
|
7
|
+
verifyMethod?: 'verify' | 'ethVerify';
|
|
8
|
+
}
|
|
9
|
+
declare function CreateVerifyEvidencePipe({
|
|
10
|
+
evidenceKey,
|
|
11
|
+
signaturesKey,
|
|
12
|
+
verifyMethod
|
|
13
|
+
}: IVerifyEvidenceOptions): PipeFunction<any>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { CreateVerifyEvidencePipe as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
let lodash_get = require("lodash/get");
|
|
5
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
6
|
+
|
|
7
|
+
//#region src/protocols/rollup/pipes/verify-signers.ts
|
|
8
|
+
function CreateVerifySignersPipe({ signersKey, allowSender = true, allowShrink = false }) {
|
|
9
|
+
return (context, next) => {
|
|
10
|
+
const { tx, rollupState } = context;
|
|
11
|
+
const rollup = rollupState;
|
|
12
|
+
const { minSignerCount, maxSignerCount } = rollup;
|
|
13
|
+
const signatures = (0, lodash_get.default)(context, signersKey);
|
|
14
|
+
const signerCount = signatures.length;
|
|
15
|
+
const seedValidators = rollup.seedValidators.map((x) => x.address);
|
|
16
|
+
const validators = rollup.validators.map((x) => x.address);
|
|
17
|
+
if (!allowSender && signatures.some((x) => x.signer === tx.from)) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, sender not allowed to sign`));
|
|
18
|
+
if (validators.length > minSignerCount) {
|
|
19
|
+
if (signerCount < minSignerCount) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, expect at least ${minSignerCount} signatures, got ${signerCount}`));
|
|
20
|
+
if (signerCount > maxSignerCount) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, Expect at most ${maxSignerCount} signatures, got ${signerCount}`));
|
|
21
|
+
} else {
|
|
22
|
+
let actualValidatorCount = validators.length;
|
|
23
|
+
if (!allowSender && allowShrink) actualValidatorCount -= 1;
|
|
24
|
+
const expectedSignerCount = Math.min(actualValidatorCount, minSignerCount);
|
|
25
|
+
if (signerCount < expectedSignerCount) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Invalid ${signersKey}, all validators are expected to sign because we have less than ${expectedSignerCount} validators`));
|
|
26
|
+
}
|
|
27
|
+
const signers = signatures.map((x) => x.signer);
|
|
28
|
+
const missingSigner = seedValidators.find((x) => signers.includes(x) === false);
|
|
29
|
+
if (missingSigner) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, missing signature from seed validator: ${missingSigner}`));
|
|
30
|
+
const invalidSigner = signers.find((x) => validators.includes(x) === false);
|
|
31
|
+
if (invalidSigner) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, signer ${invalidSigner} does not exist in validator whitelist`));
|
|
32
|
+
context.signers = signers;
|
|
33
|
+
return next();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var verify_signers_default = CreateVerifySignersPipe;
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.default = verify_signers_default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
2
|
+
|
|
3
|
+
//#region src/protocols/rollup/pipes/verify-signers.d.ts
|
|
4
|
+
interface IVerifySignersOptions {
|
|
5
|
+
signersKey: string;
|
|
6
|
+
allowSender?: boolean;
|
|
7
|
+
allowShrink?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function CreateVerifySignersPipe({
|
|
10
|
+
signersKey,
|
|
11
|
+
allowSender,
|
|
12
|
+
allowShrink
|
|
13
|
+
}: IVerifySignersOptions): PipeFunction<any>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { CreateVerifySignersPipe as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
4
|
+
|
|
5
|
+
//#region src/protocols/rollup/pipes/verify-status.ts
|
|
6
|
+
const verify_status = ({ paused, closed } = {}) => {
|
|
7
|
+
const fns = [];
|
|
8
|
+
if (paused === false) fns.push({
|
|
9
|
+
error: "INVALID_TX",
|
|
10
|
+
message: "The rollup is paused",
|
|
11
|
+
fn: (context) => !context.rollupState.paused
|
|
12
|
+
});
|
|
13
|
+
if (paused === true) fns.push({
|
|
14
|
+
error: "INVALID_TX",
|
|
15
|
+
message: "The rollup is not paused",
|
|
16
|
+
fn: (context) => context.rollupState.paused
|
|
17
|
+
});
|
|
18
|
+
if (closed === false) fns.push({
|
|
19
|
+
error: "INVALID_TX",
|
|
20
|
+
message: "The rollup is closed",
|
|
21
|
+
fn: (context) => !context.rollupState.closed
|
|
22
|
+
});
|
|
23
|
+
return _ocap_tx_pipeline.pipes.VerifyInfo(fns);
|
|
24
|
+
};
|
|
25
|
+
var verify_status_default = verify_status;
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.default = verify_status_default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PipeFunction } from "@ocap/tx-pipeline";
|
|
2
|
+
|
|
3
|
+
//#region src/protocols/rollup/pipes/verify-status.d.ts
|
|
4
|
+
interface IVerifyStatusOptions {
|
|
5
|
+
paused?: boolean;
|
|
6
|
+
closed?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const verify_status: ({
|
|
9
|
+
paused,
|
|
10
|
+
closed
|
|
11
|
+
}?: IVerifyStatusOptions) => PipeFunction<any>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { verify_status as default };
|