@ocap/tx-pipeline 1.31.1 → 1.31.3

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.
Files changed (105) hide show
  1. package/esm/bridge-release-keys.d.mts +33 -0
  2. package/esm/bridge-release-keys.mjs +81 -0
  3. package/esm/bridge-reserves.d.mts +107 -0
  4. package/esm/bridge-reserves.mjs +242 -0
  5. package/esm/helpers/bridge-withdraw.d.mts +86 -0
  6. package/esm/helpers/bridge-withdraw.mjs +123 -0
  7. package/esm/helpers/replay-guard.d.mts +19 -1
  8. package/esm/helpers/replay-guard.mjs +39 -1
  9. package/esm/index.d.mts +3 -1
  10. package/esm/index.mjs +8 -6
  11. package/esm/legacy-protocol-sunset.d.mts +2 -2
  12. package/esm/legacy-protocol-sunset.mjs +5 -5
  13. package/esm/legacy-rollup-archive.d.mts +67 -0
  14. package/esm/legacy-rollup-archive.mjs +199 -0
  15. package/esm/library.d.mts +4 -4
  16. package/esm/library.mjs +3 -3
  17. package/esm/native-abt-exchange.d.mts +3 -0
  18. package/esm/native-abt-exchange.mjs +93 -46
  19. package/esm/pipes/bridge-release-gate.d.mts +30 -0
  20. package/esm/pipes/bridge-release-gate.mjs +143 -0
  21. package/esm/pipes/bridge-reserve-v2-gate.d.mts +53 -0
  22. package/esm/pipes/bridge-reserve-v2-gate.mjs +264 -0
  23. package/esm/pipes/decode-tx.mjs +29 -4
  24. package/esm/pipes/extract-signer.mjs +1 -1
  25. package/esm/pipes/extract-state.mjs +2 -2
  26. package/esm/pipes/post-execution-invariant-gate.d.mts +19 -2
  27. package/esm/pipes/post-execution-invariant-gate.mjs +121 -6
  28. package/esm/pipes/pre-flight-waf.d.mts +18 -1
  29. package/esm/pipes/pre-flight-waf.mjs +48 -13
  30. package/esm/pipes/update-owner.mjs +1 -1
  31. package/esm/pipes/verify-account-migration.mjs +1 -1
  32. package/esm/pipes/verify-delegation.mjs +49 -25
  33. package/esm/pipes/verify-multisig-v2.mjs +5 -4
  34. package/esm/pipes/verify-multisig.mjs +5 -4
  35. package/esm/pipes/verify-signature.d.mts +7 -1
  36. package/esm/pipes/verify-signature.mjs +119 -16
  37. package/esm/pipes/verify-signer.mjs +2 -2
  38. package/esm/pipes/verify-token-access.mjs +1 -1
  39. package/esm/pipes/verify-token-balance.mjs +1 -1
  40. package/esm/pipes/verify-tx-input.mjs +1 -1
  41. package/esm/pipes/verify-tx-size.mjs +1 -1
  42. package/esm/pipes/verify-tx.mjs +12 -5
  43. package/esm/super-suites-foundation.mjs +6 -6
  44. package/esm/transaction-block.d.mts +6 -2
  45. package/esm/transaction-block.mjs +282 -40
  46. package/esm/uniswap-router.d.mts +247 -1
  47. package/esm/uniswap-router.mjs +573 -2
  48. package/lib/bridge-release-keys.cjs +88 -0
  49. package/lib/bridge-release-keys.d.cts +33 -0
  50. package/lib/bridge-reserves.cjs +257 -0
  51. package/lib/bridge-reserves.d.cts +107 -0
  52. package/lib/helpers/bridge-withdraw.cjs +136 -0
  53. package/lib/helpers/bridge-withdraw.d.cts +86 -0
  54. package/lib/helpers/replay-guard.cjs +39 -0
  55. package/lib/helpers/replay-guard.d.cts +20 -2
  56. package/lib/index.cjs +25 -5
  57. package/lib/index.d.cts +3 -1
  58. package/lib/legacy-protocol-sunset.cjs +7 -7
  59. package/lib/legacy-protocol-sunset.d.cts +2 -2
  60. package/lib/legacy-rollup-archive.cjs +208 -0
  61. package/lib/legacy-rollup-archive.d.cts +67 -0
  62. package/lib/library.cjs +14 -68
  63. package/lib/library.d.cts +4 -4
  64. package/lib/native-abt-exchange.cjs +93 -46
  65. package/lib/native-abt-exchange.d.cts +3 -0
  66. package/lib/pipes/bridge-release-gate.cjs +145 -0
  67. package/lib/pipes/bridge-release-gate.d.cts +30 -0
  68. package/lib/pipes/bridge-reserve-v2-gate.cjs +273 -0
  69. package/lib/pipes/bridge-reserve-v2-gate.d.cts +53 -0
  70. package/lib/pipes/decode-itx.d.cts +1 -1
  71. package/lib/pipes/decode-tx.cjs +28 -3
  72. package/lib/pipes/decode-tx.d.cts +1 -1
  73. package/lib/pipes/extract-signer.cjs +1 -1
  74. package/lib/pipes/extract-state.cjs +3 -3
  75. package/lib/pipes/post-execution-invariant-gate.cjs +121 -4
  76. package/lib/pipes/post-execution-invariant-gate.d.cts +19 -2
  77. package/lib/pipes/pre-flight-waf.cjs +51 -13
  78. package/lib/pipes/pre-flight-waf.d.cts +19 -2
  79. package/lib/pipes/update-owner.cjs +1 -1
  80. package/lib/pipes/update-owner.d.cts +1 -1
  81. package/lib/pipes/verify-account-migration.cjs +1 -1
  82. package/lib/pipes/verify-delegation.cjs +50 -26
  83. package/lib/pipes/verify-multisig-v2.cjs +5 -4
  84. package/lib/pipes/verify-multisig.cjs +5 -4
  85. package/lib/pipes/verify-service-fee.d.cts +1 -1
  86. package/lib/pipes/verify-signature.cjs +118 -14
  87. package/lib/pipes/verify-signature.d.cts +8 -2
  88. package/lib/pipes/verify-signer.cjs +2 -2
  89. package/lib/pipes/verify-token-access.cjs +1 -1
  90. package/lib/pipes/verify-token-balance.cjs +1 -1
  91. package/lib/pipes/verify-tx-input.cjs +1 -1
  92. package/lib/pipes/verify-tx-size.cjs +1 -1
  93. package/lib/pipes/verify-tx-size.d.cts +1 -1
  94. package/lib/pipes/verify-tx.cjs +11 -5
  95. package/lib/pipes/verify-tx.d.cts +1 -1
  96. package/lib/super-suites-foundation.cjs +6 -6
  97. package/lib/transaction-block.cjs +282 -40
  98. package/lib/transaction-block.d.cts +6 -2
  99. package/lib/uniswap-router.cjs +576 -1
  100. package/lib/uniswap-router.d.cts +247 -1
  101. package/package.json +10 -10
  102. package/esm/evm-simplified-bridge.d.mts +0 -1370
  103. package/esm/evm-simplified-bridge.mjs +0 -3875
  104. package/lib/evm-simplified-bridge.cjs +0 -3943
  105. package/lib/evm-simplified-bridge.d.cts +0 -1370
@@ -0,0 +1,86 @@
1
+ import { ResolvedBridge } from "../bridge-reserves.cjs";
2
+
3
+ //#region src/helpers/bridge-withdraw.d.ts
4
+
5
+ /**
6
+ * Withdraw rule for a `transfer_v2` into a bridge reserve (#1465, bridge/docs/ocap-protocols.md §2 and §v2.4).
7
+ *
8
+ * Pure function of (tx, itx, resolved bridge, master switch): no state, no clock. The caller resolves the bridge that
9
+ * owns `itx.to` with `resolveBridgeForReserve` (pre-tx flags); this module validates what a withdraw must look like and
10
+ * takes every parameter from that bridge's body. It is used twice on purpose:
11
+ * - by the `transfer_v2` protocol, which rejects with the returned code;
12
+ * - by the post-execution invariant gate (rule R2), as defence in depth against any other path that credits a reserve.
13
+ */
14
+ declare const BRIDGE_DISABLED = "BRIDGE_DISABLED";
15
+ declare const BRIDGE_PAUSED = "BRIDGE_PAUSED";
16
+ declare const BRIDGE_CLOSED = "BRIDGE_CLOSED";
17
+ declare const BRIDGE_WITHDRAW_RESERVE = "BRIDGE_WITHDRAW_RESERVE";
18
+ declare const BRIDGE_WITHDRAW_TOKEN = "BRIDGE_WITHDRAW_TOKEN";
19
+ declare const BRIDGE_WITHDRAW_AMOUNT = "BRIDGE_WITHDRAW_AMOUNT";
20
+ declare const BRIDGE_WITHDRAW_RECIPIENT = "BRIDGE_WITHDRAW_RECIPIENT";
21
+ declare const BRIDGE_WITHDRAW_DELEGATED = "BRIDGE_WITHDRAW_DELEGATED";
22
+ declare const BRIDGE_WITHDRAW_FEE = "BRIDGE_WITHDRAW_FEE";
23
+ type BridgeWithdrawErrorCode = typeof BRIDGE_DISABLED | typeof BRIDGE_PAUSED | typeof BRIDGE_CLOSED | typeof BRIDGE_WITHDRAW_RESERVE | typeof BRIDGE_WITHDRAW_TOKEN | typeof BRIDGE_WITHDRAW_AMOUNT | typeof BRIDGE_WITHDRAW_RECIPIENT | typeof BRIDGE_WITHDRAW_DELEGATED | typeof BRIDGE_WITHDRAW_FEE;
24
+ interface BridgeWithdrawFailure {
25
+ code: BridgeWithdrawErrorCode;
26
+ message: string;
27
+ }
28
+ interface BridgeWithdrawOk {
29
+ /** Amount of the bridge token in base units. */
30
+ amount: string;
31
+ /** Lowercase `0x` Ethereum recipient. */
32
+ ethRecipient: string;
33
+ }
34
+ interface WithdrawContext {
35
+ config?: {
36
+ transaction?: {
37
+ bridge?: {
38
+ enabled?: boolean;
39
+ };
40
+ };
41
+ } | null;
42
+ tx?: {
43
+ delegator?: string;
44
+ } | null;
45
+ itx?: unknown;
46
+ /** Token inputs after `transfer_v2` merged `itx.value` into them. Falls back to `itx` when absent. */
47
+ tokens?: Array<{
48
+ address: string;
49
+ value: string;
50
+ }>;
51
+ assets?: string[];
52
+ }
53
+ /**
54
+ * Token inputs of a `transfer_v2` itx the way the protocol sees them after its merge step: a positive primary-token
55
+ * `itx.value` is added to the OFFICIAL token entry, a zero or absent value changes nothing. The envelope expectation
56
+ * and the withdraw rule both read the itx through this function, so they can not disagree about what is being sent.
57
+ */
58
+ declare function mergedTransferTokens(itx: {
59
+ value?: unknown;
60
+ }, officialToken: string | undefined): Array<{
61
+ address: string;
62
+ value: string;
63
+ }>;
64
+ /**
65
+ * The amount and recipient a withdraw into `bridge` carries, decoded exactly like `checkBridgeWithdraw` does (same token
66
+ * rule, same strict parser input), without the policy checks. `null` when the itx is not shaped like a withdraw of the
67
+ * bridge token. `ethRecipient` is the raw value as written (the envelope must show that), `''` when absent.
68
+ */
69
+ declare function decodeBridgeWithdrawFields(itx: {
70
+ value?: unknown;
71
+ data?: {
72
+ typeUrl?: string;
73
+ value?: unknown;
74
+ } | null;
75
+ }, bridgeToken: string, officialToken: string | undefined): {
76
+ amount: string;
77
+ ethRecipient: string;
78
+ } | null;
79
+ /**
80
+ * Validate a transfer into the reserve of `bridge`. Returns the parsed withdraw, or the first failing check.
81
+ * Order follows the design: 1 accepting, 2 token set and amount range, 3 recipient, 4 delegator, 5 fee.
82
+ */
83
+ declare function checkBridgeWithdraw(context: WithdrawContext, bridge: ResolvedBridge): BridgeWithdrawOk | BridgeWithdrawFailure;
84
+ declare function isBridgeWithdrawFailure(x: BridgeWithdrawOk | BridgeWithdrawFailure): x is BridgeWithdrawFailure;
85
+ //#endregion
86
+ export { BRIDGE_CLOSED, BRIDGE_DISABLED, BRIDGE_PAUSED, BRIDGE_WITHDRAW_AMOUNT, BRIDGE_WITHDRAW_DELEGATED, BRIDGE_WITHDRAW_FEE, BRIDGE_WITHDRAW_RECIPIENT, BRIDGE_WITHDRAW_RESERVE, BRIDGE_WITHDRAW_TOKEN, BridgeWithdrawErrorCode, BridgeWithdrawFailure, BridgeWithdrawOk, checkBridgeWithdraw, decodeBridgeWithdrawFields, isBridgeWithdrawFailure, mergedTransferTokens };
@@ -1,4 +1,6 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_bridge_reserves = require('../bridge-reserves.cjs');
3
+ const require_helpers_bridge_withdraw = require('./bridge-withdraw.cjs');
2
4
  let _ocap_mcrypto = require("@ocap/mcrypto");
3
5
  let _ocap_state = require("@ocap/state");
4
6
 
@@ -19,9 +21,46 @@ function isCanonicalPasskeyExtra(extra) {
19
21
  return false;
20
22
  }
21
23
  }
24
+ const WITHDRAW_NONE = {
25
+ bridge: "",
26
+ amount: "",
27
+ token: "",
28
+ ethRecipient: ""
29
+ };
30
+ /**
31
+ * Clear-signing expectation for a wallet envelope (#1465, bridge/docs/ocap-protocols.md §2, §v2.4).
32
+ *
33
+ * Returns the decoded `{ bridge, amount, token, ethRecipient }` when the tx is a `transfer_v2` whose `itx.to` has the bridge
34
+ * reserve role, and `null` for every other tx. `token` is the TOKEN OF THE BRIDGE that owns the reserve. A withdraw whose
35
+ * itx is not even shaped like one (other tokens, assets, missing recipient), or whose reserve maps to no bridge, returns
36
+ * empty fields, which no envelope can match: the withdraw rule rejects it anyway, this keeps the signature stage from
37
+ * blessing it first.
38
+ */
39
+ async function getBridgeWithdrawEnvelopeContext(context) {
40
+ if (String(context.txType || "").replace(/^fg:t:/, "") !== "transfer_v2") return null;
41
+ const itx = context.itx || {};
42
+ if (!itx.to || !require_bridge_reserves.isBridgeReserveRole(itx.to)) return null;
43
+ try {
44
+ const bridge = await require_bridge_reserves.resolveBridgeForReserve(context, itx.to);
45
+ if (!bridge?.token) return { ...WITHDRAW_NONE };
46
+ const official = context.config?.token?.address;
47
+ const fields = require_helpers_bridge_withdraw.decodeBridgeWithdrawFields(itx, bridge.token, official);
48
+ if (!fields) return { ...WITHDRAW_NONE };
49
+ return {
50
+ bridge: bridge.address,
51
+ amount: fields.amount,
52
+ token: bridge.token,
53
+ ethRecipient: fields.ethRecipient
54
+ };
55
+ } catch (err) {
56
+ console.warn(`bridge withdraw envelope expectation failed for ${String(itx.to).slice(0, 12)}...: ${String(err?.message || err).slice(0, 120)}`);
57
+ return { ...WITHDRAW_NONE };
58
+ }
59
+ }
22
60
 
23
61
  //#endregion
24
62
  exports.assertEnvelopeMatchesTxContext = _ocap_mcrypto.assertEnvelopeMatchesTxContext;
63
+ exports.getBridgeWithdrawEnvelopeContext = getBridgeWithdrawEnvelopeContext;
25
64
  exports.isCanonicalPasskeyExtra = isCanonicalPasskeyExtra;
26
65
  exports.isCanonicalWalletEnvelopeExtra = _ocap_mcrypto.isCanonicalWalletEnvelopeExtra;
27
66
  exports.parseNonceBn = _ocap_state.parseNonceBn;
@@ -1,5 +1,5 @@
1
- import { assertEnvelopeMatchesTxContext, isCanonicalWalletEnvelopeExtra } from "@ocap/mcrypto";
2
1
  import { parseNonceBn } from "@ocap/state";
2
+ import { assertEnvelopeMatchesTxContext, isCanonicalWalletEnvelopeExtra } from "@ocap/mcrypto";
3
3
 
4
4
  //#region src/helpers/replay-guard.d.ts
5
5
 
@@ -11,5 +11,23 @@ import { parseNonceBn } from "@ocap/state";
11
11
  * deduplication and `nonce > 0` for replay protection.
12
12
  */
13
13
  declare function isCanonicalPasskeyExtra(extra: string): boolean;
14
+ /**
15
+ * Clear-signing expectation for a wallet envelope (#1465, bridge/docs/ocap-protocols.md §2, §v2.4).
16
+ *
17
+ * Returns the decoded `{ bridge, amount, token, ethRecipient }` when the tx is a `transfer_v2` whose `itx.to` has the bridge
18
+ * reserve role, and `null` for every other tx. `token` is the TOKEN OF THE BRIDGE that owns the reserve. A withdraw whose
19
+ * itx is not even shaped like one (other tokens, assets, missing recipient), or whose reserve maps to no bridge, returns
20
+ * empty fields, which no envelope can match: the withdraw rule rejects it anyway, this keeps the signature stage from
21
+ * blessing it first.
22
+ */
23
+ declare function getBridgeWithdrawEnvelopeContext(context: {
24
+ txType?: string;
25
+ itx?: unknown;
26
+ }): Promise<{
27
+ bridge: string;
28
+ amount: string;
29
+ token: string;
30
+ ethRecipient: string;
31
+ } | null>;
14
32
  //#endregion
15
- export { assertEnvelopeMatchesTxContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra, parseNonceBn };
33
+ export { assertEnvelopeMatchesTxContext, getBridgeWithdrawEnvelopeContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra, parseNonceBn };
package/lib/index.cjs CHANGED
@@ -1,14 +1,11 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
+ const require_bridge_release_keys = require('./bridge-release-keys.cjs');
4
+ const require_bridge_reserves = require('./bridge-reserves.cjs');
3
5
  const require_encrypted_nft_envelope = require('./encrypted-nft-envelope.cjs');
4
6
  const require_helpers_replay_guard = require('./helpers/replay-guard.cjs');
5
7
  const require_pipes_anti_land_attack = require('./pipes/anti-land-attack.cjs');
6
8
  const require_pipes_decode_itx = require('./pipes/decode-itx.cjs');
7
- const require_pipes_decode_tx = require('./pipes/decode-tx.cjs');
8
- const require_pipes_extract_receiver = require('./pipes/extract-receiver.cjs');
9
- const require_pipes_extract_signer = require('./pipes/extract-signer.cjs');
10
- const require_pipes_extract_state = require('./pipes/extract-state.cjs');
11
- const require_pipes_post_execution_invariant_gate = require('./pipes/post-execution-invariant-gate.cjs');
12
9
  const require_runner = require('./runner.cjs');
13
10
  const require_pipes_verify_blocked = require('./pipes/verify-blocked.cjs');
14
11
  const require_pipes_verify_service_fee = require('./pipes/verify-service-fee.cjs');
@@ -16,6 +13,11 @@ const require_pipes_verify_signature = require('./pipes/verify-signature.cjs');
16
13
  const require_pipes_verify_tx = require('./pipes/verify-tx.cjs');
17
14
  const require_pipes_verify_tx_size = require('./pipes/verify-tx-size.cjs');
18
15
  const require_pipes_pre_flight_waf = require('./pipes/pre-flight-waf.cjs');
16
+ const require_pipes_decode_tx = require('./pipes/decode-tx.cjs');
17
+ const require_pipes_extract_receiver = require('./pipes/extract-receiver.cjs');
18
+ const require_pipes_extract_signer = require('./pipes/extract-signer.cjs');
19
+ const require_pipes_extract_state = require('./pipes/extract-state.cjs');
20
+ const require_pipes_post_execution_invariant_gate = require('./pipes/post-execution-invariant-gate.cjs');
19
21
  const require_pipes_verify_state_diff = require('./pipes/verify-state-diff.cjs');
20
22
  const require_pipes_take_state_snapshot = require('./pipes/take-state-snapshot.cjs');
21
23
  const require_pipes_update_owner = require('./pipes/update-owner.cjs');
@@ -73,6 +75,12 @@ var src_default = {
73
75
 
74
76
  //#endregion
75
77
  exports.AntiLandAttack = require_pipes_anti_land_attack.default;
78
+ exports.BRIDGE_MAX_MIGRATION_HOPS = require_bridge_reserves.BRIDGE_MAX_MIGRATION_HOPS;
79
+ exports.BRIDGE_RECONCILE_TX_TYPES = require_bridge_reserves.BRIDGE_RECONCILE_TX_TYPES;
80
+ exports.BRIDGE_RELEASE_TX_TYPE = require_bridge_reserves.BRIDGE_RELEASE_TX_TYPE;
81
+ exports.BRIDGE_RESERVE_CREDIT_TX_TYPES = require_bridge_reserves.BRIDGE_RESERVE_CREDIT_TX_TYPES;
82
+ exports.BRIDGE_RESERVE_DEBIT_TX_TYPES = require_bridge_reserves.BRIDGE_RESERVE_DEBIT_TX_TYPES;
83
+ exports.BRIDGE_WITHDRAW_TX_TYPE = require_bridge_reserves.BRIDGE_WITHDRAW_TX_TYPE;
76
84
  exports.DecodeItx = require_pipes_decode_itx.default;
77
85
  exports.DecodeTx = require_pipes_decode_tx.default;
78
86
  exports.ENCRYPTED_NFT_SCHEMA_VERSION = require_encrypted_nft_envelope.ENCRYPTED_NFT_SCHEMA_VERSION;
@@ -94,6 +102,7 @@ exports.MAX_PREFLIGHT_WIRE_BYTES_FALLBACK = require_pipes_pre_flight_waf.MAX_PRE
94
102
  exports.MAX_ROLLUP_TXS_LIST_SIZE = require_pipes_pre_flight_waf.MAX_ROLLUP_TXS_LIST_SIZE;
95
103
  exports.PostExecutionInvariantGate = require_pipes_post_execution_invariant_gate.default;
96
104
  exports.PreFlightWaf = require_pipes_pre_flight_waf.default;
105
+ exports.RELEASE_RING_SLOTS = require_bridge_release_keys.RELEASE_RING_SLOTS;
97
106
  exports.Runner = require_runner.default;
98
107
  exports.TRACKED_STATE_TABLES = require_pipes_post_execution_invariant_gate.TRACKED_STATE_TABLES;
99
108
  exports.TakeStateSnapshot = require_pipes_take_state_snapshot.default;
@@ -125,16 +134,27 @@ exports.computeEncryptedNftPlaintextHash = require_encrypted_nft_envelope.comput
125
134
  exports.computeEncryptedNftPublicHeaderAad = require_encrypted_nft_envelope.computeEncryptedNftPublicHeaderAad;
126
135
  exports.default = src_default;
127
136
  exports.deriveOwnerPublicKeyHexFromSecretKey = require_encrypted_nft_envelope.deriveOwnerPublicKeyHexFromSecretKey;
137
+ exports.describeBridge = require_bridge_reserves.describeBridge;
138
+ exports.formatBucketData = require_bridge_release_keys.formatBucketData;
139
+ exports.getReleaseBucketKey = require_bridge_release_keys.getReleaseBucketKey;
140
+ exports.getReleaseTombstoneKey = require_bridge_release_keys.getReleaseTombstoneKey;
128
141
  exports.groupStatesByAddress = require_pipes_verify_state_diff.groupStatesByAddress;
129
142
  exports.inspectPostExecutionInvariants = require_pipes_post_execution_invariant_gate.inspectPostExecutionInvariants;
130
143
  exports.inspectTransactionPreFlight = require_pipes_pre_flight_waf.inspectTransactionPreFlight;
131
144
  exports.installStateWriteInterceptor = require_pipes_post_execution_invariant_gate.installStateWriteInterceptor;
145
+ exports.isBridgeReserveRole = require_bridge_reserves.isBridgeReserveRole;
132
146
  exports.isCanonicalPasskeyExtra = require_helpers_replay_guard.isCanonicalPasskeyExtra;
133
147
  exports.isDelegationSufficient = require_pipes_verify_delegation.isDelegationSufficient;
134
148
  exports.normalizeEntityKey = require_pipes_post_execution_invariant_gate.normalizeEntityKey;
135
149
  exports.openEncryptedNftAsOwner = require_encrypted_nft_envelope.openEncryptedNftAsOwner;
150
+ exports.parseBucketData = require_bridge_release_keys.parseBucketData;
136
151
  exports.parseNonceBn = _ocap_state.parseNonceBn;
137
152
  exports.pipes = pipes;
153
+ exports.prepareBridgeReserveGate = require_bridge_reserves.prepareBridgeReserveGate;
154
+ exports.reserveIndexKey = require_bridge_reserves.reserveIndexKey;
155
+ exports.resolveBridge = require_bridge_reserves.resolveBridge;
156
+ exports.resolveBridgeForRelease = require_bridge_reserves.resolveBridgeForRelease;
157
+ exports.resolveBridgeForReserve = require_bridge_reserves.resolveBridgeForReserve;
138
158
  exports.rewrapEncryptedNftForNewOwner = require_encrypted_nft_envelope.rewrapEncryptedNftForNewOwner;
139
159
  exports.rollbackTrackedStateWrites = require_pipes_post_execution_invariant_gate.rollbackTrackedStateWrites;
140
160
  exports.scanItxPayloadAnomalies = require_pipes_pre_flight_waf.scanItxPayloadAnomalies;
package/lib/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import { RELEASE_RING_SLOTS, ReleaseRing, formatBucketData, getReleaseBucketKey, getReleaseTombstoneKey, parseBucketData } from "./bridge-release-keys.cjs";
2
+ import { BRIDGE_MAX_MIGRATION_HOPS, BRIDGE_RECONCILE_TX_TYPES, BRIDGE_RELEASE_TX_TYPE, BRIDGE_RESERVE_CREDIT_TX_TYPES, BRIDGE_RESERVE_DEBIT_TX_TYPES, BRIDGE_WITHDRAW_TX_TYPE, BridgeReserveResolution, ReleaseResolution, ResolvedBridge, describeBridge, isBridgeReserveRole, prepareBridgeReserveGate, reserveIndexKey, resolveBridge, resolveBridgeForRelease, resolveBridgeForReserve } from "./bridge-reserves.cjs";
1
3
  import { ENCRYPTED_NFT_SCHEMA_VERSION, EncryptedAssetEnvelope, EncryptedNftAlgorithm, EncryptedNftOwnerCipherEnvelope, EncryptedNftPrivateMetadata, EncryptedNftPublicDiscoveryHeader, MAX_ENCRYPTED_NFT_CATEGORY_LENGTH, MAX_ENCRYPTED_NFT_CIPHERTEXT_HEX_CHARS, MAX_ENCRYPTED_NFT_SUMMARY_LENGTH, MAX_ENCRYPTED_NFT_TAGS, MAX_ENCRYPTED_NFT_TAG_LENGTH, MAX_ENCRYPTED_NFT_URI_LENGTH, OpenEncryptedNftAsOwnerInput, OpenEncryptedNftAsOwnerResult, RewrapEncryptedNftForNewOwnerInput, SealEncryptedNftForOwnerInput, VALID_ENCRYPTED_NFT_ALGORITHMS, VerifyEncryptedNftHandoverInput, canonicalizeEncryptedNftMetadata, computeEncryptedNftCekCommitmentHash, computeEncryptedNftPlaintextHash, computeEncryptedNftPublicHeaderAad, deriveOwnerPublicKeyHexFromSecretKey, openEncryptedNftAsOwner, rewrapEncryptedNftForNewOwner, sealEncryptedNftForOwner, validateEncryptedAssetEnvelope, verifyEncryptedNftHandover } from "./encrypted-nft-envelope.cjs";
2
4
  import { isCanonicalPasskeyExtra, parseNonceBn } from "./helpers/replay-guard.cjs";
3
5
  import PipelineRunner, { ErrorPipeFunction, PipeFunction, PipeNext, PipeOptions } from "./runner.cjs";
@@ -99,4 +101,4 @@ declare const _default: {
99
101
  };
100
102
  };
101
103
  //#endregion
102
- export { CreateAntiLandAttackPipe as AntiLandAttack, DecodeItx, DecodeTx, ENCRYPTED_NFT_SCHEMA_VERSION, type EncryptedAssetEnvelope, type EncryptedNftAlgorithm, type EncryptedNftOwnerCipherEnvelope, type EncryptedNftPrivateMetadata, type EncryptedNftPublicDiscoveryHeader, type ErrorPipeFunction, CreateExtractReceiverPipe as ExtractReceiver, CreateExtractSignerPipe as ExtractSigner, CreateExtractStatePipe as ExtractState, type IAccountUpdate, type IBaseContext, type IDecodedContext, type IDecodedTransaction, type IExecutedContext, type IGasContext, type IReadyContext, type IStateWriteTracker, type ITxOnlyContext, type IWithAsset, type IWithAssets, type IWithDelegation, type IWithDelegator, type IWithEvidence, type IWithFactory, type IWithLocked, type IWithOwner, type IWithReceiver, type IWithRollup, type IWithRollupBlock, type IWithSender, type IWithStake, type IWithStakes, type IWithToken, type IWithTokenFactory, type IWithTokens, MAX_DELEGATE_TYPE_URLS_LIST_SIZE, MAX_ENCRYPTED_NFT_CATEGORY_LENGTH, MAX_ENCRYPTED_NFT_CIPHERTEXT_HEX_CHARS, MAX_ENCRYPTED_NFT_SUMMARY_LENGTH, MAX_ENCRYPTED_NFT_TAGS, MAX_ENCRYPTED_NFT_TAG_LENGTH, MAX_ENCRYPTED_NFT_URI_LENGTH, MAX_POST_EXECUTION_WRITE_SET_ENTRIES, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, MAX_PREFLIGHT_STRING_FIELD_BYTES, MAX_PREFLIGHT_WIRE_BYTES_FALLBACK, MAX_ROLLUP_TXS_LIST_SIZE, type OpenEncryptedNftAsOwnerInput, type OpenEncryptedNftAsOwnerResult, type PipeFunction, type PipeNext, type PipeOptions, CreatePostExecutionInvariantGatePipe as PostExecutionInvariantGate, PreFlightWaf, type RewrapEncryptedNftForNewOwnerInput, PipelineRunner as Runner, type SealEncryptedNftForOwnerInput, TRACKED_STATE_TABLES, type TTransactionReceipt, CreateTakeStateSnapshotPipe as TakeStateSnapshot, type TrackedStateTable, CreateUpdateOwnerPipe as UpdateOwner, VALID_ENCRYPTED_NFT_ALGORITHMS, CreateVerifyAccountMigrationPipe as VerifyAccountMigration, CreatedVerifyBlockedPipe as VerifyBlocked, CreateVerifyDelegationPipe as VerifyDelegation, type VerifyEncryptedNftHandoverInput, CreateVerifyInfoPipe as VerifyInfo, CreateVerifyListSizePipe as VerifyListSize, CreateVerifyMultiSigPipe as VerifyMultiSig, CreateVerifyMultiSigV2Pipe as VerifyMultiSigV2, CreateVerifySenderPipe as VerifySender, VerifyServiceFee, VerifySignature, CreateVerifySignerPipe as VerifySigner, CreateVerifyStateDiffPipe as VerifyStateDiff, CreateVerifyTokenBalancePipe as VerifyTokenBalance, CreateVerifyTransferrablePipe as VerifyTransferrable, VerifyTx, CreateVerifyTxInputPipe as VerifyTxInput, VerifyTxSize, CreateVerifyUpdaterPipe as VerifyUpdater, assertKnownItxFields, assertRawWireEnvelope, canonicalizeEncryptedNftMetadata, computeEncryptedNftCekCommitmentHash, computeEncryptedNftPlaintextHash, computeEncryptedNftPublicHeaderAad, _default as default, deriveOwnerPublicKeyHexFromSecretKey, groupStatesByAddress, inspectPostExecutionInvariants, inspectTransactionPreFlight, installStateWriteInterceptor, isCanonicalPasskeyExtra, isDelegationSufficient, normalizeEntityKey, openEncryptedNftAsOwner, parseNonceBn, pipes, rewrapEncryptedNftForNewOwner, rollbackTrackedStateWrites, scanItxPayloadAnomalies, sealEncryptedNftForOwner, validateEncryptedAssetEnvelope, verifyAssetHierarchy, verifyEncryptedNftHandover, verifyImplicitAssetOwnership, CreateVerifyTokenAccessPipe as verifyTokenAccess };
104
+ export { CreateAntiLandAttackPipe as AntiLandAttack, BRIDGE_MAX_MIGRATION_HOPS, BRIDGE_RECONCILE_TX_TYPES, BRIDGE_RELEASE_TX_TYPE, BRIDGE_RESERVE_CREDIT_TX_TYPES, BRIDGE_RESERVE_DEBIT_TX_TYPES, BRIDGE_WITHDRAW_TX_TYPE, type BridgeReserveResolution, DecodeItx, DecodeTx, ENCRYPTED_NFT_SCHEMA_VERSION, type EncryptedAssetEnvelope, type EncryptedNftAlgorithm, type EncryptedNftOwnerCipherEnvelope, type EncryptedNftPrivateMetadata, type EncryptedNftPublicDiscoveryHeader, type ErrorPipeFunction, CreateExtractReceiverPipe as ExtractReceiver, CreateExtractSignerPipe as ExtractSigner, CreateExtractStatePipe as ExtractState, type IAccountUpdate, type IBaseContext, type IDecodedContext, type IDecodedTransaction, type IExecutedContext, type IGasContext, type IReadyContext, type IStateWriteTracker, type ITxOnlyContext, type IWithAsset, type IWithAssets, type IWithDelegation, type IWithDelegator, type IWithEvidence, type IWithFactory, type IWithLocked, type IWithOwner, type IWithReceiver, type IWithRollup, type IWithRollupBlock, type IWithSender, type IWithStake, type IWithStakes, type IWithToken, type IWithTokenFactory, type IWithTokens, MAX_DELEGATE_TYPE_URLS_LIST_SIZE, MAX_ENCRYPTED_NFT_CATEGORY_LENGTH, MAX_ENCRYPTED_NFT_CIPHERTEXT_HEX_CHARS, MAX_ENCRYPTED_NFT_SUMMARY_LENGTH, MAX_ENCRYPTED_NFT_TAGS, MAX_ENCRYPTED_NFT_TAG_LENGTH, MAX_ENCRYPTED_NFT_URI_LENGTH, MAX_POST_EXECUTION_WRITE_SET_ENTRIES, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, MAX_PREFLIGHT_STRING_FIELD_BYTES, MAX_PREFLIGHT_WIRE_BYTES_FALLBACK, MAX_ROLLUP_TXS_LIST_SIZE, type OpenEncryptedNftAsOwnerInput, type OpenEncryptedNftAsOwnerResult, type PipeFunction, type PipeNext, type PipeOptions, CreatePostExecutionInvariantGatePipe as PostExecutionInvariantGate, PreFlightWaf, RELEASE_RING_SLOTS, type ReleaseResolution, type ReleaseRing, type ResolvedBridge, type RewrapEncryptedNftForNewOwnerInput, PipelineRunner as Runner, type SealEncryptedNftForOwnerInput, TRACKED_STATE_TABLES, type TTransactionReceipt, CreateTakeStateSnapshotPipe as TakeStateSnapshot, type TrackedStateTable, CreateUpdateOwnerPipe as UpdateOwner, VALID_ENCRYPTED_NFT_ALGORITHMS, CreateVerifyAccountMigrationPipe as VerifyAccountMigration, CreatedVerifyBlockedPipe as VerifyBlocked, CreateVerifyDelegationPipe as VerifyDelegation, type VerifyEncryptedNftHandoverInput, CreateVerifyInfoPipe as VerifyInfo, CreateVerifyListSizePipe as VerifyListSize, CreateVerifyMultiSigPipe as VerifyMultiSig, CreateVerifyMultiSigV2Pipe as VerifyMultiSigV2, CreateVerifySenderPipe as VerifySender, VerifyServiceFee, VerifySignature, CreateVerifySignerPipe as VerifySigner, CreateVerifyStateDiffPipe as VerifyStateDiff, CreateVerifyTokenBalancePipe as VerifyTokenBalance, CreateVerifyTransferrablePipe as VerifyTransferrable, VerifyTx, CreateVerifyTxInputPipe as VerifyTxInput, VerifyTxSize, CreateVerifyUpdaterPipe as VerifyUpdater, assertKnownItxFields, assertRawWireEnvelope, canonicalizeEncryptedNftMetadata, computeEncryptedNftCekCommitmentHash, computeEncryptedNftPlaintextHash, computeEncryptedNftPublicHeaderAad, _default as default, deriveOwnerPublicKeyHexFromSecretKey, describeBridge, formatBucketData, getReleaseBucketKey, getReleaseTombstoneKey, groupStatesByAddress, inspectPostExecutionInvariants, inspectTransactionPreFlight, installStateWriteInterceptor, isBridgeReserveRole, isCanonicalPasskeyExtra, isDelegationSufficient, normalizeEntityKey, openEncryptedNftAsOwner, parseBucketData, parseNonceBn, pipes, prepareBridgeReserveGate, reserveIndexKey, resolveBridge, resolveBridgeForRelease, resolveBridgeForReserve, rewrapEncryptedNftForNewOwner, rollbackTrackedStateWrites, scanItxPayloadAnomalies, sealEncryptedNftForOwner, validateEncryptedAssetEnvelope, verifyAssetHierarchy, verifyEncryptedNftHandover, verifyImplicitAssetOwnership, CreateVerifyTokenAccessPipe as verifyTokenAccess };
@@ -1,5 +1,5 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
- const require_evm_simplified_bridge = require('./evm-simplified-bridge.cjs');
2
+ const require_legacy_rollup_archive = require('./legacy-rollup-archive.cjs');
3
3
  const require_transaction_block = require('./transaction-block.cjs');
4
4
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
5
 
@@ -8,7 +8,7 @@ const ErrorCode = {
8
8
  InvalidSunset: "INVALID_LEGACY_PROTOCOL_SUNSET",
9
9
  ForbiddenSunset: "FORBIDDEN_LEGACY_PROTOCOL_SUNSET"
10
10
  };
11
- const DEFAULT_LEGACY_PROTOCOL_SUNSET_HEIGHT = require_evm_simplified_bridge.DEFAULT_ROLLUP_SUNSET_ACTIVATION_HEIGHT;
11
+ const DEFAULT_LEGACY_PROTOCOL_SUNSET_HEIGHT = require_legacy_rollup_archive.DEFAULT_ROLLUP_SUNSET_ACTIVATION_HEIGHT;
12
12
  const MAX_LEGACY_MIOTX_PARTICIPANTS = 64;
13
13
  const MAX_LEGACY_MIOTX_TOKENS_PER_ENTRY = 32;
14
14
  const MAX_LEGACY_MIOTX_ASSETS_PER_ENTRY = 64;
@@ -44,7 +44,7 @@ const DEPRECATED_VERSIONED_ASSET_TYPE_URLS = Object.freeze([
44
44
  ]);
45
45
  /**
46
46
  * Category 3: Deprecated Rollup & legacy versioned token bridge write protocols.
47
- * Replaced by Zero-Rollup-Block EIP-712 `fg:t:evm_bridge_settlement` (`OcapSimplifiedEvmBridgeNode`).
47
+ * Replaced by the new ABT bridge (ArcBlock/ArcBridge).
48
48
  */
49
49
  const DEPRECATED_ROLLUP_AND_BRIDGE_TYPE_URLS = Object.freeze([
50
50
  "fg:t:create_rollup",
@@ -253,14 +253,14 @@ const LEGACY_REPLACEMENT_MAP = Object.freeze({
253
253
  category: "LEGACY_ROLLUP_AND_BRIDGE",
254
254
  isMiotx: false,
255
255
  vnextReplacementTypeUrl: "fg:t:settle_attestation",
256
- migrationGuidance: "Legacy Rollup is retired; use Guardian circuit breaker on OcapSimplifiedEvmBridgeNode"
256
+ migrationGuidance: "Legacy Rollup is retired; use the pause / sentinel controls of the new ABT bridge (ArcBlock/ArcBridge)"
257
257
  },
258
258
  "fg:t:resume_rollup": {
259
259
  legacyTypeUrl: "fg:t:resume_rollup",
260
260
  category: "LEGACY_ROLLUP_AND_BRIDGE",
261
261
  isMiotx: false,
262
262
  vnextReplacementTypeUrl: "fg:t:settle_attestation",
263
- migrationGuidance: "Legacy Rollup is retired; use Guardian circuit breaker on OcapSimplifiedEvmBridgeNode"
263
+ migrationGuidance: "Legacy Rollup is retired; use the pause / sentinel controls of the new ABT bridge (ArcBlock/ArcBridge)"
264
264
  },
265
265
  "fg:t:close_rollup": {
266
266
  legacyTypeUrl: "fg:t:close_rollup",
@@ -606,7 +606,7 @@ function parseLegacyTxReadOnlyArchiveRecord(rawRecord) {
606
606
  if (resolvedRollupKind) {
607
607
  const nestedItx = rawRecord.itx && typeof rawRecord.itx === "object" && !Array.isArray(rawRecord.itx) ? rawRecord.itx : {};
608
608
  assertNoProtoPollutionKeys(nestedItx, "itx");
609
- const rollupSummary = require_evm_simplified_bridge.parseLegacyRollupReadOnlyRecord({
609
+ const rollupSummary = require_legacy_rollup_archive.parseLegacyRollupReadOnlyRecord({
610
610
  ...nestedItx,
611
611
  ...rawRecord,
612
612
  recordKind: resolvedRollupKind
@@ -1169,7 +1169,7 @@ function compileLegacyTxToVNextTransactionBlock(rawRecord) {
1169
1169
  transactionBlock
1170
1170
  };
1171
1171
  }
1172
- throw new _ocap_util_lib_error.CustomError(ErrorCode.ForbiddenSunset, `LegacyProtocolSunset: legacy Rollup/Bridge record ${summary.recordKind} cannot be compiled to an L1 TransactionBlock; use Zero-Rollup-Block EIP-712 OcapSimplifiedEvmBridgeNode instead`);
1172
+ throw new _ocap_util_lib_error.CustomError(ErrorCode.ForbiddenSunset, `LegacyProtocolSunset: legacy Rollup/Bridge record ${summary.recordKind} cannot be compiled to an L1 TransactionBlock; use the new ABT bridge (ArcBlock/ArcBridge) instead`);
1173
1173
  }
1174
1174
  /**
1175
1175
  * Executes a VNext `TransactionBlockInput` after enforcing `assertTransactionBlockVNextPure`
@@ -1,5 +1,5 @@
1
+ import { LegacyRollupReadOnlySummary } from "./legacy-rollup-archive.cjs";
1
2
  import { StatementExecutor, TransactionBlockInput, TransactionBlockResult } from "./transaction-block.cjs";
2
- import { LegacyRollupReadOnlySummary } from "./evm-simplified-bridge.cjs";
3
3
 
4
4
  //#region src/legacy-protocol-sunset.d.ts
5
5
  declare const DEFAULT_LEGACY_PROTOCOL_SUNSET_HEIGHT = 1;
@@ -18,7 +18,7 @@ declare const DEPRECATED_MIOTX_AND_TRADE_TYPE_URLS: readonly ["fg:t:transfer_v2"
18
18
  declare const DEPRECATED_VERSIONED_ASSET_TYPE_URLS: readonly ["fg:t:acquire_asset_v2", "fg:t:acquire_asset_v3", "fg:t:mint_asset_v2", "fg:t:update_asset_v2", "fg:t:create_factory_v2"];
19
19
  /**
20
20
  * Category 3: Deprecated Rollup & legacy versioned token bridge write protocols.
21
- * Replaced by Zero-Rollup-Block EIP-712 `fg:t:evm_bridge_settlement` (`OcapSimplifiedEvmBridgeNode`).
21
+ * Replaced by the new ABT bridge (ArcBlock/ArcBridge).
22
22
  */
23
23
  declare const DEPRECATED_ROLLUP_AND_BRIDGE_TYPE_URLS: readonly ["fg:t:create_rollup", "fg:t:update_rollup", "fg:t:join_rollup", "fg:t:leave_rollup", "fg:t:create_rollup_block", "fg:t:claim_block_reward", "fg:t:pause_rollup", "fg:t:resume_rollup", "fg:t:close_rollup", "fg:t:migrate_rollup", "fg:t:deposit_token", "fg:t:deposit_token_v2", "fg:t:withdraw_token", "fg:t:withdraw_token_v2", "fg:t:revoke_withdraw"];
24
24
  /**
@@ -0,0 +1,208 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let _ocap_mcrypto = require("@ocap/mcrypto");
3
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
4
+
5
+ //#region src/legacy-rollup-archive.ts
6
+ /**
7
+ * Read-only access to legacy Rollup records and the guard for the retired Rollup write protocols.
8
+ * Extracted unchanged from the removed `evm-simplified-bridge.ts` simulation (ArcBlock/ArcBridge#16):
9
+ * this part is an OCAP-side legacy concern and is used by `legacy-protocol-sunset.ts`.
10
+ */
11
+ const keccak256 = _ocap_mcrypto.Hasher.Keccak.hash256;
12
+ const ErrorCode = {
13
+ InvalidBridge: "INVALID_EVM_SIMPLIFIED_BRIDGE",
14
+ ForbiddenBridge: "FORBIDDEN_EVM_SIMPLIFIED_BRIDGE"
15
+ };
16
+ const DEFAULT_MAX_ROLLUP_BLOCK_SIZE = 256;
17
+ const DEFAULT_ROLLUP_SUNSET_ACTIVATION_HEIGHT = 1;
18
+ const DEPRECATED_ROLLUP_PROTOCOL_TYPE_URLS = Object.freeze([
19
+ "fg:t:create_rollup",
20
+ "fg:t:update_rollup",
21
+ "fg:t:join_rollup",
22
+ "fg:t:leave_rollup",
23
+ "fg:t:create_rollup_block",
24
+ "fg:t:claim_block_reward",
25
+ "fg:t:pause_rollup",
26
+ "fg:t:resume_rollup"
27
+ ]);
28
+ const ZERO_BYTES32_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
29
+ const BYTES32_HEX_REGEX = /^0x[0-9a-fA-F]{64}$/;
30
+ const CANONICAL_UINT256_DECIMAL_REGEX = /^(0|[1-9]\d{0,77})$/;
31
+ function assertCleanString(value, label) {
32
+ if (typeof value !== "string" || value.trim().length === 0) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, `SimplifiedEvmBridge: ${label} must be a non-empty string`);
33
+ const trimmed = value.trim();
34
+ if (trimmed !== value || /[\s/\\?#%]|::|->/.test(trimmed)) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, `SimplifiedEvmBridge: ${label} contains invalid characters`);
35
+ return trimmed;
36
+ }
37
+ function assertBytes32Hex(value, label) {
38
+ if (typeof value !== "string" || !BYTES32_HEX_REGEX.test(value)) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, `SimplifiedEvmBridge: ${label} must be a 32-byte 0x-prefixed hex string`);
39
+ return value.toLowerCase();
40
+ }
41
+ function uint256ToHex64(value) {
42
+ const big = typeof value === "number" ? BigInt(value) : value;
43
+ if (big < 0n || big >= 1n << 256n) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: uint256 out of range");
44
+ return big.toString(16).padStart(64, "0");
45
+ }
46
+ function parseStrictUint256JsonValue(value, label) {
47
+ if (typeof value === "bigint") {
48
+ if (value < 0n || value >= 1n << 256n) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, `SimplifiedEvmBridge: ${label} out of uint256 range`);
49
+ return value;
50
+ }
51
+ if (typeof value === "string" && CANONICAL_UINT256_DECIMAL_REGEX.test(value)) {
52
+ const big = BigInt(value);
53
+ if (big < 0n || big >= 1n << 256n) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, `SimplifiedEvmBridge: ${label} out of uint256 range`);
54
+ return big;
55
+ }
56
+ throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, `SimplifiedEvmBridge: ${label} must be a canonical base-10 uint256 string`);
57
+ }
58
+ /**
59
+ * Computes the `@ocap/merkle-tree` compatible `getListHash(txHashes)`.
60
+ */
61
+ function computeEvmBridgeTxsHash(txHashes) {
62
+ if (txHashes.length === 0) return ZERO_BYTES32_HASH;
63
+ return keccak256(`0x${txHashes.map((h) => assertBytes32Hex(h, "txHash").slice(2)).join("")}`).toLowerCase();
64
+ }
65
+ /**
66
+ * Computes the `@ocap/merkle-tree` compatible `getBlockHash`:
67
+ * `keccak256(encodePacked(uint256 height, bytes32 previousHash, bytes32 merkleRoot, bytes32 txsHash))`
68
+ */
69
+ function computeEvmBridgeBlockHash(block) {
70
+ if (!Number.isSafeInteger(block.height) || block.height <= 0) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: block height must be a positive safe integer");
71
+ return keccak256(`0x${uint256ToHex64(block.height)}${assertBytes32Hex(block.previousHash, "previousHash").slice(2)}${assertBytes32Hex(block.merkleRoot, "merkleRoot").slice(2)}${assertBytes32Hex(block.txsHash, "txsHash").slice(2)}`).toLowerCase();
72
+ }
73
+ const DEPRECATED_ROLLUP_PROTOCOL_SET = new Set(DEPRECATED_ROLLUP_PROTOCOL_TYPE_URLS);
74
+ function normalizeRollupProtocolTypeUrl(rawTypeUrl) {
75
+ if (typeof rawTypeUrl !== "string") return "";
76
+ const trimmed = rawTypeUrl.trim();
77
+ if (!trimmed) return "";
78
+ const snakeCased = trimmed.replace(/^(?:type\.googleapis\.com\/)?(?:forge_abi\.)?(?:fg:t:|fg:x:tx:)?/i, "").replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().replace(/_tx$/, "");
79
+ if (!snakeCased) return "";
80
+ return `fg:t:${snakeCased}`;
81
+ }
82
+ /**
83
+ * Issue #1245:
84
+ * Returns true if `typeUrl` belongs to the 8 deprecated Rollup write protocols
85
+ * (`create_rollup`, `update_rollup`, `join_rollup`, `leave_rollup`, `create_rollup_block`,
86
+ * `claim_block_reward`, `pause_rollup`, `resume_rollup`).
87
+ * Normalizes case, whitespace, camelCase/PascalCase, protobuf type URLs, and bare protocol names (`RT-1245-3`).
88
+ */
89
+ function isDeprecatedRollupWriteProtocol(typeUrl) {
90
+ const normalized = normalizeRollupProtocolTypeUrl(typeUrl);
91
+ return DEPRECATED_ROLLUP_PROTOCOL_SET.has(normalized);
92
+ }
93
+ /**
94
+ * Issue #1245:
95
+ * Sunset guard for active transaction pipeline execution:
96
+ * - Blocks all 8 deprecated Rollup write protocols when `currentBlockHeight >= rollupSunsetActivationHeight`.
97
+ * - Allows historical block replay when `currentBlockHeight < rollupSunsetActivationHeight`.
98
+ */
99
+ function assertRollupProtocolNotSunset(params) {
100
+ if (!params || typeof params !== "object") throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: sunset guard params must be an object");
101
+ if (typeof params.typeUrl !== "string" || params.typeUrl.trim().length === 0) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: typeUrl must be a non-empty string");
102
+ if (!Number.isSafeInteger(params.currentBlockHeight) || params.currentBlockHeight < 0) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: currentBlockHeight must be a non-negative safe integer");
103
+ const activationHeight = params.rollupSunsetActivationHeight ?? DEFAULT_ROLLUP_SUNSET_ACTIVATION_HEIGHT;
104
+ if (!Number.isSafeInteger(activationHeight) || activationHeight < 1) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: rollupSunsetActivationHeight must be a positive safe integer (>= 1)");
105
+ if (isDeprecatedRollupWriteProtocol(params.typeUrl)) {
106
+ if (params.currentBlockHeight >= activationHeight) {
107
+ const canonicalTypeUrl = normalizeRollupProtocolTypeUrl(params.typeUrl);
108
+ throw new _ocap_util_lib_error.CustomError(ErrorCode.ForbiddenBridge, `SimplifiedEvmBridge: legacy Rollup write protocol ${canonicalTypeUrl} is deprecated and disabled at block height ${params.currentBlockHeight} (>= sunset height ${activationHeight}); use Zero-Rollup-Block EIP-712 DirectWithdrawVoucher instead`);
109
+ }
110
+ return;
111
+ }
112
+ assertCleanString(params.typeUrl, "typeUrl");
113
+ }
114
+ /**
115
+ * Issue #1245:
116
+ * Strictly read-only historical parser for legacy `RollupState`, `RollupBlock`, `deposit_token_v2`,
117
+ * and `withdraw_token_v2` records so block explorers, indexers, and audit tools can inspect historical
118
+ * chain data after the active Rollup write protocols are removed.
119
+ */
120
+ function parseLegacyRollupReadOnlyRecord(rawRecord) {
121
+ if (!rawRecord || typeof rawRecord !== "object" || Array.isArray(rawRecord)) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: legacy Rollup record must be a plain object");
122
+ if (Object.prototype.hasOwnProperty.call(rawRecord, "__proto__") || Object.prototype.hasOwnProperty.call(rawRecord, "constructor") || Object.prototype.hasOwnProperty.call(rawRecord, "prototype")) throw new _ocap_util_lib_error.CustomError(ErrorCode.ForbiddenBridge, "SimplifiedEvmBridge: prototype pollution keys rejected in legacy Rollup record");
123
+ const rawKind = String(rawRecord.recordKind ?? rawRecord.typeUrl ?? "").trim();
124
+ const normalizedKind = rawKind.startsWith("fg:t:") ? rawKind.slice(5) : rawKind;
125
+ if (normalizedKind === "RollupState") {
126
+ const rollupAddress = assertCleanString(String(rawRecord.rollupAddress ?? rawRecord.address ?? ""), "rollupAddress");
127
+ const tokenAddress = assertCleanString(String(rawRecord.tokenAddress ?? ""), "tokenAddress");
128
+ const rawValidators = Array.isArray(rawRecord.validatorDids ?? rawRecord.validators) ? rawRecord.validatorDids ?? rawRecord.validators : [];
129
+ if (rawValidators.length > 64) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: legacy RollupState validator list too large");
130
+ const validatorDids = Object.freeze(rawValidators.map((v) => assertCleanString(String(v ?? ""), "validatorDid")));
131
+ const latestHeight = rawRecord.blockHeight !== void 0 ? Number(rawRecord.blockHeight) : Number(rawRecord.latestBlockHeight ?? 0);
132
+ if (!Number.isSafeInteger(latestHeight) || latestHeight < 0) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: invalid legacy RollupState blockHeight");
133
+ return Object.freeze({
134
+ recordKind: "RollupState",
135
+ mode: "READ_ONLY_LEGACY_ARCHIVE",
136
+ rollupAddress,
137
+ tokenAddress,
138
+ blockHeight: latestHeight,
139
+ validatorDids
140
+ });
141
+ }
142
+ if (normalizedKind === "RollupBlock" || normalizedKind === "create_rollup_block") {
143
+ const rollupAddress = assertCleanString(String(rawRecord.rollupAddress ?? rawRecord.rollup ?? ""), "rollupAddress");
144
+ const blockHeight = Number(rawRecord.blockHeight ?? rawRecord.height);
145
+ if (!Number.isSafeInteger(blockHeight) || blockHeight <= 0) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: legacy RollupBlock height must be >= 1");
146
+ const previousHash = rawRecord.previousHash ? assertBytes32Hex(String(rawRecord.previousHash), "previousHash") : ZERO_BYTES32_HASH;
147
+ const merkleRoot = assertBytes32Hex(String(rawRecord.merkleRoot ?? ""), "merkleRoot");
148
+ const hasExplicitTxArray = rawRecord.txHashes !== void 0 || rawRecord.txs !== void 0;
149
+ const rawTxs = Array.isArray(rawRecord.txHashes ?? rawRecord.txs) ? rawRecord.txHashes ?? rawRecord.txs : [];
150
+ if (rawTxs.length > DEFAULT_MAX_ROLLUP_BLOCK_SIZE) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: legacy RollupBlock txHashes exceeds max size");
151
+ const txHashes = Object.freeze(rawTxs.map((h) => assertBytes32Hex(String(h ?? ""), "txHash")));
152
+ const computedTxsHash = computeEvmBridgeTxsHash([...txHashes]);
153
+ const txsHash = rawRecord.txsHash ? assertBytes32Hex(String(rawRecord.txsHash), "txsHash") : computedTxsHash;
154
+ if (rawRecord.txsHash && hasExplicitTxArray && txsHash !== computedTxsHash) throw new _ocap_util_lib_error.CustomError(ErrorCode.ForbiddenBridge, `SimplifiedEvmBridge: legacy RollupBlock #${blockHeight} txsHash mismatch against txHashes`);
155
+ const computedBlockHash = computeEvmBridgeBlockHash({
156
+ height: blockHeight,
157
+ previousHash,
158
+ merkleRoot,
159
+ txsHash
160
+ });
161
+ const blockHash = rawRecord.blockHash ? assertBytes32Hex(String(rawRecord.blockHash), "blockHash") : computedBlockHash;
162
+ if (blockHash !== computedBlockHash) throw new _ocap_util_lib_error.CustomError(ErrorCode.ForbiddenBridge, `SimplifiedEvmBridge: legacy RollupBlock #${blockHeight} blockHash mismatch`);
163
+ const proposerDid = rawRecord.proposerDid ? assertCleanString(String(rawRecord.proposerDid), "proposerDid") : void 0;
164
+ return Object.freeze({
165
+ recordKind: "RollupBlock",
166
+ mode: "READ_ONLY_LEGACY_ARCHIVE",
167
+ rollupAddress,
168
+ blockHeight,
169
+ previousHash,
170
+ merkleRoot,
171
+ txsHash,
172
+ blockHash,
173
+ txHashes,
174
+ proposerDid
175
+ });
176
+ }
177
+ if (normalizedKind === "deposit_token_v2" || normalizedKind === "withdraw_token_v2") {
178
+ const rollupAddress = assertCleanString(String(rawRecord.rollupAddress ?? rawRecord.rollup ?? ""), "rollupAddress");
179
+ const tokenAddress = assertCleanString(String(rawRecord.tokenAddress ?? ""), "tokenAddress");
180
+ const fromDid = rawRecord.fromDid ? assertCleanString(String(rawRecord.fromDid), "fromDid") : void 0;
181
+ const recipientAddress = assertCleanString(String(rawRecord.recipientAddress ?? rawRecord.to ?? ""), "recipientAddress");
182
+ const amount = parseStrictUint256JsonValue(rawRecord.amount ?? rawRecord.value, "amount");
183
+ if (amount <= 0n) throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, "SimplifiedEvmBridge: legacy transfer amount must be > 0n");
184
+ const evidenceHash = rawRecord.evidenceHash ? assertBytes32Hex(String(rawRecord.evidenceHash), "evidenceHash") : void 0;
185
+ return Object.freeze({
186
+ recordKind: normalizedKind,
187
+ mode: "READ_ONLY_LEGACY_ARCHIVE",
188
+ rollupAddress,
189
+ tokenAddress,
190
+ fromDid,
191
+ recipientAddress,
192
+ amount,
193
+ evidenceHash
194
+ });
195
+ }
196
+ throw new _ocap_util_lib_error.CustomError(ErrorCode.InvalidBridge, `SimplifiedEvmBridge: unsupported legacy Rollup record kind (${rawKind || "empty"})`);
197
+ }
198
+
199
+ //#endregion
200
+ exports.DEFAULT_MAX_ROLLUP_BLOCK_SIZE = DEFAULT_MAX_ROLLUP_BLOCK_SIZE;
201
+ exports.DEFAULT_ROLLUP_SUNSET_ACTIVATION_HEIGHT = DEFAULT_ROLLUP_SUNSET_ACTIVATION_HEIGHT;
202
+ exports.DEPRECATED_ROLLUP_PROTOCOL_TYPE_URLS = DEPRECATED_ROLLUP_PROTOCOL_TYPE_URLS;
203
+ exports.ZERO_BYTES32_HASH = ZERO_BYTES32_HASH;
204
+ exports.assertRollupProtocolNotSunset = assertRollupProtocolNotSunset;
205
+ exports.computeEvmBridgeBlockHash = computeEvmBridgeBlockHash;
206
+ exports.computeEvmBridgeTxsHash = computeEvmBridgeTxsHash;
207
+ exports.isDeprecatedRollupWriteProtocol = isDeprecatedRollupWriteProtocol;
208
+ exports.parseLegacyRollupReadOnlyRecord = parseLegacyRollupReadOnlyRecord;
@@ -0,0 +1,67 @@
1
+ //#region src/legacy-rollup-archive.d.ts
2
+ declare const DEFAULT_MAX_ROLLUP_BLOCK_SIZE = 256;
3
+ declare const DEFAULT_ROLLUP_SUNSET_ACTIVATION_HEIGHT = 1;
4
+ declare const DEPRECATED_ROLLUP_PROTOCOL_TYPE_URLS: readonly ["fg:t:create_rollup", "fg:t:update_rollup", "fg:t:join_rollup", "fg:t:leave_rollup", "fg:t:create_rollup_block", "fg:t:claim_block_reward", "fg:t:pause_rollup", "fg:t:resume_rollup"];
5
+ declare const ZERO_BYTES32_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
6
+ type DeprecatedRollupProtocolTypeUrl = (typeof DEPRECATED_ROLLUP_PROTOCOL_TYPE_URLS)[number];
7
+ type LegacyRollupRecordKind = 'RollupState' | 'RollupBlock' | 'deposit_token_v2' | 'withdraw_token_v2';
8
+ interface LegacyRollupReadOnlySummary {
9
+ readonly recordKind: LegacyRollupRecordKind;
10
+ readonly mode: 'READ_ONLY_LEGACY_ARCHIVE';
11
+ readonly rollupAddress: string;
12
+ readonly tokenAddress?: string;
13
+ readonly blockHeight?: number;
14
+ readonly blockHash?: string;
15
+ readonly previousHash?: string;
16
+ readonly merkleRoot?: string;
17
+ readonly txsHash?: string;
18
+ readonly txHashes?: readonly string[];
19
+ readonly proposerDid?: string;
20
+ readonly validatorDids?: readonly string[];
21
+ readonly fromDid?: string;
22
+ readonly recipientAddress?: string;
23
+ readonly amount?: bigint;
24
+ readonly evidenceHash?: string;
25
+ }
26
+ /**
27
+ * Computes the `@ocap/merkle-tree` compatible `getListHash(txHashes)`.
28
+ */
29
+ declare function computeEvmBridgeTxsHash(txHashes: string[]): string;
30
+ /**
31
+ * Computes the `@ocap/merkle-tree` compatible `getBlockHash`:
32
+ * `keccak256(encodePacked(uint256 height, bytes32 previousHash, bytes32 merkleRoot, bytes32 txsHash))`
33
+ */
34
+ declare function computeEvmBridgeBlockHash(block: {
35
+ height: number;
36
+ previousHash: string;
37
+ merkleRoot: string;
38
+ txsHash: string;
39
+ }): string;
40
+ /**
41
+ * Issue #1245:
42
+ * Returns true if `typeUrl` belongs to the 8 deprecated Rollup write protocols
43
+ * (`create_rollup`, `update_rollup`, `join_rollup`, `leave_rollup`, `create_rollup_block`,
44
+ * `claim_block_reward`, `pause_rollup`, `resume_rollup`).
45
+ * Normalizes case, whitespace, camelCase/PascalCase, protobuf type URLs, and bare protocol names (`RT-1245-3`).
46
+ */
47
+ declare function isDeprecatedRollupWriteProtocol(typeUrl: string): boolean;
48
+ /**
49
+ * Issue #1245:
50
+ * Sunset guard for active transaction pipeline execution:
51
+ * - Blocks all 8 deprecated Rollup write protocols when `currentBlockHeight >= rollupSunsetActivationHeight`.
52
+ * - Allows historical block replay when `currentBlockHeight < rollupSunsetActivationHeight`.
53
+ */
54
+ declare function assertRollupProtocolNotSunset(params: {
55
+ typeUrl: string;
56
+ currentBlockHeight: number;
57
+ rollupSunsetActivationHeight?: number;
58
+ }): void;
59
+ /**
60
+ * Issue #1245:
61
+ * Strictly read-only historical parser for legacy `RollupState`, `RollupBlock`, `deposit_token_v2`,
62
+ * and `withdraw_token_v2` records so block explorers, indexers, and audit tools can inspect historical
63
+ * chain data after the active Rollup write protocols are removed.
64
+ */
65
+ declare function parseLegacyRollupReadOnlyRecord(rawRecord: Record<string, unknown>): LegacyRollupReadOnlySummary;
66
+ //#endregion
67
+ export { DEFAULT_MAX_ROLLUP_BLOCK_SIZE, DEFAULT_ROLLUP_SUNSET_ACTIVATION_HEIGHT, DEPRECATED_ROLLUP_PROTOCOL_TYPE_URLS, DeprecatedRollupProtocolTypeUrl, LegacyRollupReadOnlySummary, LegacyRollupRecordKind, ZERO_BYTES32_HASH, assertRollupProtocolNotSunset, computeEvmBridgeBlockHash, computeEvmBridgeTxsHash, isDeprecatedRollupWriteProtocol, parseLegacyRollupReadOnlyRecord };