@ocap/tx-pipeline 1.30.25 → 1.31.0

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 (149) hide show
  1. package/esm/appchain-sovereign-hub.d.mts +160 -0
  2. package/esm/appchain-sovereign-hub.mjs +348 -0
  3. package/esm/arcvault-external-adapter.d.mts +166 -0
  4. package/esm/arcvault-external-adapter.mjs +376 -0
  5. package/esm/encrypted-nft-envelope.d.mts +172 -0
  6. package/esm/encrypted-nft-envelope.mjs +458 -0
  7. package/esm/evm-simplified-bridge.d.mts +1370 -0
  8. package/esm/evm-simplified-bridge.mjs +3875 -0
  9. package/esm/give-to-mint-karma.d.mts +472 -0
  10. package/esm/give-to-mint-karma.mjs +1057 -0
  11. package/esm/helpers/replay-guard.d.mts +15 -0
  12. package/esm/helpers/replay-guard.mjs +23 -0
  13. package/esm/index.d.mts +10 -5
  14. package/esm/index.mjs +14 -10
  15. package/esm/legacy-protocol-sunset.d.mts +251 -0
  16. package/esm/legacy-protocol-sunset.mjs +1519 -0
  17. package/esm/library.d.mts +16 -0
  18. package/esm/library.mjs +17 -0
  19. package/esm/native-abt-exchange.d.mts +2055 -0
  20. package/esm/native-abt-exchange.mjs +7250 -0
  21. package/esm/ofac-screening.d.mts +17 -0
  22. package/esm/ofac-screening.mjs +39 -0
  23. package/esm/pipes/anti-land-attack.mjs +1 -1
  24. package/esm/pipes/decode-itx.mjs +43 -4
  25. package/esm/pipes/decode-tx.d.mts +2 -3
  26. package/esm/pipes/decode-tx.mjs +53 -115
  27. package/esm/pipes/extract-signer.mjs +2 -2
  28. package/esm/pipes/extract-state.mjs +14 -3
  29. package/esm/pipes/post-execution-invariant-gate.d.mts +61 -0
  30. package/esm/pipes/post-execution-invariant-gate.mjs +789 -0
  31. package/esm/pipes/pre-flight-waf.d.mts +34 -0
  32. package/esm/pipes/pre-flight-waf.mjs +603 -0
  33. package/esm/pipes/take-state-snapshot.mjs +3 -2
  34. package/esm/pipes/update-owner.mjs +39 -4
  35. package/esm/pipes/verify-account-migration.mjs +14 -4
  36. package/esm/pipes/verify-blocked.mjs +1 -1
  37. package/esm/pipes/verify-delegation.d.mts +22 -3
  38. package/esm/pipes/verify-delegation.mjs +259 -36
  39. package/esm/pipes/verify-list-size.mjs +1 -1
  40. package/esm/pipes/verify-multisig-v2.mjs +15 -7
  41. package/esm/pipes/verify-multisig.mjs +15 -7
  42. package/esm/pipes/verify-sender.mjs +1 -1
  43. package/esm/pipes/verify-signature.mjs +35 -6
  44. package/esm/pipes/verify-signer.mjs +2 -2
  45. package/esm/pipes/verify-state-diff.mjs +3 -3
  46. package/esm/pipes/verify-token-access.mjs +1 -1
  47. package/esm/pipes/verify-token-balance.mjs +13 -5
  48. package/esm/pipes/verify-transferrable.d.mts +8 -1
  49. package/esm/pipes/verify-transferrable.mjs +3 -3
  50. package/esm/pipes/verify-tx-input.mjs +2 -2
  51. package/esm/pipes/verify-tx-size.mjs +46 -2
  52. package/esm/pipes/verify-tx.mjs +5 -7
  53. package/esm/pipes/verify-updater.mjs +1 -1
  54. package/esm/social-economy-factories.d.mts +346 -0
  55. package/esm/social-economy-factories.mjs +845 -0
  56. package/esm/super-suites-foundation.d.mts +513 -0
  57. package/esm/super-suites-foundation.mjs +1241 -0
  58. package/esm/transaction-block.d.mts +471 -0
  59. package/esm/transaction-block.mjs +1906 -0
  60. package/esm/uniswap-erc7683-solver.d.mts +201 -0
  61. package/esm/uniswap-erc7683-solver.mjs +321 -0
  62. package/esm/uniswap-lp-copilot.d.mts +113 -0
  63. package/esm/uniswap-lp-copilot.mjs +320 -0
  64. package/esm/uniswap-router.d.mts +335 -0
  65. package/esm/uniswap-router.mjs +578 -0
  66. package/esm/uniswap-token-factory-graduation.d.mts +187 -0
  67. package/esm/uniswap-token-factory-graduation.mjs +426 -0
  68. package/esm/uniswap-v4-hook.d.mts +173 -0
  69. package/esm/uniswap-v4-hook.mjs +517 -0
  70. package/lib/appchain-sovereign-hub.cjs +352 -0
  71. package/lib/appchain-sovereign-hub.d.cts +160 -0
  72. package/lib/arcvault-external-adapter.cjs +383 -0
  73. package/lib/arcvault-external-adapter.d.cts +166 -0
  74. package/lib/encrypted-nft-envelope.cjs +477 -0
  75. package/lib/encrypted-nft-envelope.d.cts +172 -0
  76. package/lib/evm-simplified-bridge.cjs +3943 -0
  77. package/lib/evm-simplified-bridge.d.cts +1370 -0
  78. package/lib/give-to-mint-karma.cjs +1084 -0
  79. package/lib/give-to-mint-karma.d.cts +472 -0
  80. package/lib/helpers/replay-guard.cjs +27 -0
  81. package/lib/helpers/replay-guard.d.cts +15 -0
  82. package/lib/index.cjs +49 -16
  83. package/lib/index.d.cts +10 -5
  84. package/lib/legacy-protocol-sunset.cjs +1543 -0
  85. package/lib/legacy-protocol-sunset.d.cts +251 -0
  86. package/lib/library.cjs +303 -0
  87. package/lib/library.d.cts +16 -0
  88. package/lib/native-abt-exchange.cjs +7322 -0
  89. package/lib/native-abt-exchange.d.cts +2055 -0
  90. package/lib/ofac-screening.cjs +42 -0
  91. package/lib/ofac-screening.d.cts +17 -0
  92. package/lib/pipes/anti-land-attack.cjs +2 -2
  93. package/lib/pipes/decode-itx.cjs +43 -4
  94. package/lib/pipes/decode-itx.d.cts +1 -1
  95. package/lib/pipes/decode-tx.cjs +52 -116
  96. package/lib/pipes/decode-tx.d.cts +3 -4
  97. package/lib/pipes/extract-signer.cjs +2 -2
  98. package/lib/pipes/extract-state.cjs +14 -3
  99. package/lib/pipes/post-execution-invariant-gate.cjs +800 -0
  100. package/lib/pipes/post-execution-invariant-gate.d.cts +61 -0
  101. package/lib/pipes/pre-flight-waf.cjs +616 -0
  102. package/lib/pipes/pre-flight-waf.d.cts +34 -0
  103. package/lib/pipes/take-state-snapshot.cjs +3 -2
  104. package/lib/pipes/update-owner.cjs +40 -5
  105. package/lib/pipes/update-owner.d.cts +1 -1
  106. package/lib/pipes/verify-account-migration.cjs +14 -4
  107. package/lib/pipes/verify-blocked.cjs +1 -1
  108. package/lib/pipes/verify-delegation.cjs +259 -36
  109. package/lib/pipes/verify-delegation.d.cts +22 -3
  110. package/lib/pipes/verify-list-size.cjs +1 -1
  111. package/lib/pipes/verify-multisig-v2.cjs +15 -7
  112. package/lib/pipes/verify-multisig.cjs +15 -7
  113. package/lib/pipes/verify-sender.cjs +1 -1
  114. package/lib/pipes/verify-service-fee.d.cts +1 -1
  115. package/lib/pipes/verify-signature.cjs +35 -6
  116. package/lib/pipes/verify-signature.d.cts +1 -1
  117. package/lib/pipes/verify-signer.cjs +2 -2
  118. package/lib/pipes/verify-state-diff.cjs +4 -4
  119. package/lib/pipes/verify-token-access.cjs +2 -2
  120. package/lib/pipes/verify-token-balance.cjs +13 -5
  121. package/lib/pipes/verify-transferrable.cjs +3 -3
  122. package/lib/pipes/verify-transferrable.d.cts +8 -1
  123. package/lib/pipes/verify-tx-input.cjs +3 -3
  124. package/lib/pipes/verify-tx-size.cjs +46 -2
  125. package/lib/pipes/verify-tx-size.d.cts +1 -1
  126. package/lib/pipes/verify-tx.cjs +6 -8
  127. package/lib/pipes/verify-tx.d.cts +1 -1
  128. package/lib/pipes/verify-updater.cjs +1 -1
  129. package/lib/social-economy-factories.cjs +852 -0
  130. package/lib/social-economy-factories.d.cts +346 -0
  131. package/lib/super-suites-foundation.cjs +1257 -0
  132. package/lib/super-suites-foundation.d.cts +513 -0
  133. package/lib/transaction-block.cjs +1941 -0
  134. package/lib/transaction-block.d.cts +471 -0
  135. package/lib/uniswap-erc7683-solver.cjs +327 -0
  136. package/lib/uniswap-erc7683-solver.d.cts +201 -0
  137. package/lib/uniswap-lp-copilot.cjs +328 -0
  138. package/lib/uniswap-lp-copilot.d.cts +113 -0
  139. package/lib/uniswap-router.cjs +593 -0
  140. package/lib/uniswap-router.d.cts +335 -0
  141. package/lib/uniswap-token-factory-graduation.cjs +431 -0
  142. package/lib/uniswap-token-factory-graduation.d.cts +187 -0
  143. package/lib/uniswap-v4-hook.cjs +527 -0
  144. package/lib/uniswap-v4-hook.d.cts +173 -0
  145. package/package.json +11 -10
  146. package/esm/helpers/dedup-height.d.mts +0 -16
  147. package/esm/helpers/dedup-height.mjs +0 -61
  148. package/lib/helpers/dedup-height.cjs +0 -72
  149. package/lib/helpers/dedup-height.d.cts +0 -16
@@ -1,14 +1,14 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
- const require_helpers_dedup_height = require('../helpers/dedup-height.cjs');
3
+ const require_helpers_replay_guard = require('../helpers/replay-guard.cjs');
4
4
  const require_package = require('../package.cjs');
5
5
  const require_helpers_unwrap_opaque_any = require('../helpers/unwrap-opaque-any.cjs');
6
6
  const require_helpers_encode_tx_by_context = require('../helpers/encode-tx-by-context.cjs');
7
+ let _ocap_mcrypto = require("@ocap/mcrypto");
8
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
7
9
  let lodash_get = require("lodash/get");
8
10
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
9
- let _ocap_util_lib_error = require("@ocap/util/lib/error");
10
11
  let _ocap_message = require("@ocap/message");
11
- let _ocap_mcrypto = require("@ocap/mcrypto");
12
12
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
13
13
  let lodash_cloneDeep = require("lodash/cloneDeep");
14
14
  lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
@@ -60,13 +60,21 @@ function CreateVerifyMultiSigV2Pipe({ signersKey }) {
60
60
  if ((0, _arcblock_did.isFromPublicKey)(address, pk) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `signer ${address} and pk do not match`));
61
61
  const type = (0, _arcblock_did.toTypeInfo)(address);
62
62
  const isPasskey = type.role === _ocap_mcrypto.types.RoleType.ROLE_PASSKEY || type.pk === _ocap_mcrypto.types.KeyType.PASSKEY;
63
- const dedupActive = await require_helpers_dedup_height.isDedupHeightActive(context);
64
- if (!isPasskey && extra && dedupActive) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${address}`));
65
- if (isPasskey && extra && dedupActive && !require_helpers_dedup_height.isCanonicalPasskeyExtra(extra)) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Non-canonical extra data for passkey signer ${address}`));
63
+ const isWalletEnvelope = !isPasskey && Boolean(extra && (0, _ocap_mcrypto.isCanonicalWalletEnvelopeExtra)(extra, type.pk));
64
+ if (!isPasskey && !isWalletEnvelope && extra) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${address}`));
65
+ if (isPasskey && (!extra || !require_helpers_replay_guard.isCanonicalPasskeyExtra(extra))) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Non-canonical extra data for passkey signer ${address}`));
66
66
  const wallet = (0, _ocap_wallet.fromPublicKey)(pk, type);
67
67
  txBytes ??= require_helpers_encode_tx_by_context.encodeTxByEncoding(context.txEncoding, tx);
68
+ const verifiedExtra = isPasskey || isWalletEnvelope ? extra : "";
68
69
  try {
69
- if (await wallet.verify(txBytes, signature, true, extra) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Signature for ${address} is not valid`));
70
+ if (isWalletEnvelope) (0, _ocap_mcrypto.assertEnvelopeMatchesTxContext)(verifiedExtra, {
71
+ chainId: tx.chainId,
72
+ signer: address,
73
+ from: signer,
74
+ nonce: tx.nonce,
75
+ action: context.txType
76
+ });
77
+ if (await wallet.verify(txBytes, signature, true, verifiedExtra) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Signature for ${address} is not valid`));
70
78
  } catch (err) {
71
79
  debug$1("verify failed", err);
72
80
  return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Signature for ${address} verify failed: ${err.message}`));
@@ -1,13 +1,13 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
- const require_helpers_dedup_height = require('../helpers/dedup-height.cjs');
3
+ const require_helpers_replay_guard = require('../helpers/replay-guard.cjs');
4
4
  const require_helpers_unwrap_opaque_any = require('../helpers/unwrap-opaque-any.cjs');
5
5
  const require_helpers_encode_tx_by_context = require('../helpers/encode-tx-by-context.cjs');
6
+ let _ocap_mcrypto = require("@ocap/mcrypto");
7
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
6
8
  let lodash_get = require("lodash/get");
7
9
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
8
- let _ocap_util_lib_error = require("@ocap/util/lib/error");
9
10
  let _ocap_message = require("@ocap/message");
10
- let _ocap_mcrypto = require("@ocap/mcrypto");
11
11
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
12
12
  let lodash_cloneDeep = require("lodash/cloneDeep");
13
13
  lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
@@ -30,11 +30,12 @@ function CreateVerifyMultiSigPipe(numSigs = 0) {
30
30
  if ((0, _arcblock_did.isFromPublicKey)(address, pk) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `signer ${address} and pk do not match`));
31
31
  const type = (0, _arcblock_did.toTypeInfo)(address);
32
32
  const isPasskey = type.role === _ocap_mcrypto.types.RoleType.ROLE_PASSKEY || type.pk === _ocap_mcrypto.types.KeyType.PASSKEY;
33
- const dedupActive = await require_helpers_dedup_height.isDedupHeightActive(context);
34
- if (!isPasskey && sigExtra && dedupActive) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${address}`));
35
- if (isPasskey && sigExtra && dedupActive && !require_helpers_dedup_height.isCanonicalPasskeyExtra(sigExtra)) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Non-canonical extra data for passkey signer ${address}`));
33
+ const isWalletEnvelope = !isPasskey && Boolean(sigExtra && (0, _ocap_mcrypto.isCanonicalWalletEnvelopeExtra)(sigExtra, type.pk));
34
+ if (!isPasskey && !isWalletEnvelope && sigExtra) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${address}`));
35
+ const fallbackTxExtra = (0, lodash_get.default)(context, "extra.txExtra");
36
+ const extra = isPasskey ? sigExtra || fallbackTxExtra || "" : isWalletEnvelope ? sigExtra : "";
37
+ if (isPasskey && (!extra || !require_helpers_replay_guard.isCanonicalPasskeyExtra(extra))) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Non-canonical extra data for passkey signer ${address}`));
36
38
  const wallet = (0, _ocap_wallet.fromPublicKey)(pk, type);
37
- const extra = sigExtra || (isPasskey ? (0, lodash_get.default)(context, "extra.txExtra") || "" : "");
38
39
  (0, _ocap_util_lib_get_list_field.setListField)(tx, "signatures", [{
39
40
  signer,
40
41
  pk,
@@ -43,6 +44,13 @@ function CreateVerifyMultiSigPipe(numSigs = 0) {
43
44
  }].concat(signatures));
44
45
  const txBytes = require_helpers_encode_tx_by_context.encodeTxByEncoding(context.txEncoding, tx);
45
46
  try {
47
+ if (isWalletEnvelope) (0, _ocap_mcrypto.assertEnvelopeMatchesTxContext)(extra, {
48
+ chainId: tx.chainId,
49
+ signer: address,
50
+ from: signer,
51
+ nonce: tx.nonce,
52
+ action: context.txType
53
+ });
46
54
  if (await wallet.verify(txBytes, signature, true, extra) === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Multi signature for ${address} is not valid`));
47
55
  } catch (err) {
48
56
  return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Multi signature for ${address} verify failed: ${err.message}`));
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
3
4
  let lodash_get = require("lodash/get");
4
5
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
5
- let _ocap_util_lib_error = require("@ocap/util/lib/error");
6
6
 
7
7
  //#region src/pipes/verify-sender.ts
8
8
  function CreateVerifySenderPipe({ state = "senderState" } = {}) {
@@ -1,5 +1,5 @@
1
- import { IDecodedContext } from "@ocap/types";
2
1
  import { CustomError } from "@ocap/util/lib/error";
2
+ import { IDecodedContext } from "@ocap/types";
3
3
 
4
4
  //#region src/pipes/verify-service-fee.d.ts
5
5
  declare function VerifyServiceFee(context: IDecodedContext, next: (err?: CustomError) => void): void;
@@ -1,11 +1,11 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
- const require_helpers_dedup_height = require('../helpers/dedup-height.cjs');
3
+ const require_helpers_replay_guard = require('../helpers/replay-guard.cjs');
4
4
  const require_helpers_encode_tx_by_context = require('../helpers/encode-tx-by-context.cjs');
5
+ let _ocap_mcrypto = require("@ocap/mcrypto");
6
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
7
  let lodash_get = require("lodash/get");
6
8
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
7
- let _ocap_util_lib_error = require("@ocap/util/lib/error");
8
- let _ocap_mcrypto = require("@ocap/mcrypto");
9
9
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
10
10
  let lodash_cloneDeep = require("lodash/cloneDeep");
11
11
  lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
@@ -13,7 +13,11 @@ let _arcblock_did = require("@arcblock/did");
13
13
  let _ocap_wallet = require("@ocap/wallet");
14
14
 
15
15
  //#region src/pipes/verify-signature.ts
16
- const V1_MULTISIG_TX_TYPES = new Set(["fg:t:exchange", "fg:t:exchange_v2"]);
16
+ const V1_MULTISIG_TX_TYPES = new Set([
17
+ "fg:t:exchange",
18
+ "fg:t:exchange_v2",
19
+ "fg:t:account_migrate"
20
+ ]);
17
21
  async function VerifySignature(context, next) {
18
22
  const tx = (0, lodash_cloneDeep.default)(context.tx);
19
23
  const { signature } = tx;
@@ -22,7 +26,7 @@ async function VerifySignature(context, next) {
22
26
  const txType = context.txType;
23
27
  if (!txType || multiSignV2Txs.includes(txType) === false) {
24
28
  const sigs = (0, _ocap_util_lib_get_list_field.getListField)(tx, "signatures");
25
- if (txType && sigs.length > 0 && await require_helpers_dedup_height.isDedupHeightActive(context)) {
29
+ if (txType && sigs.length > 0) {
26
30
  if (!V1_MULTISIG_TX_TYPES.has(txType)) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Expect 0 multi signatures but found ${sigs.length}`));
27
31
  if (sigs.length > 1) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Expect 1 multi signatures but found ${sigs.length}`));
28
32
  }
@@ -34,8 +38,33 @@ async function VerifySignature(context, next) {
34
38
  const txBytes = require_helpers_encode_tx_by_context.encodeTxByEncoding(context.txEncoding, tx);
35
39
  const type = (0, _arcblock_did.toTypeInfo)(signer);
36
40
  const wallet = (0, _ocap_wallet.fromPublicKey)(pk, type);
37
- const extra = type.role === _ocap_mcrypto.types.RoleType.ROLE_PASSKEY || type.pk === _ocap_mcrypto.types.KeyType.PASSKEY ? (0, lodash_get.default)(context, "extra.txExtra") : "";
41
+ const rawTxExtra = (0, lodash_get.default)(context, "extra.txExtra");
42
+ const isPasskey = type.role === _ocap_mcrypto.types.RoleType.ROLE_PASSKEY || type.pk === _ocap_mcrypto.types.KeyType.PASSKEY;
43
+ if (isPasskey && (typeof rawTxExtra !== "string" || !require_helpers_replay_guard.isCanonicalPasskeyExtra(rawTxExtra))) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", "Non-canonical extra data for passkey signer"));
44
+ const isWalletEnvelope = !isPasskey && typeof rawTxExtra === "string" && (0, _ocap_mcrypto.isCanonicalWalletEnvelopeExtra)(rawTxExtra, type.pk);
45
+ if (!isPasskey && !isWalletEnvelope && rawTxExtra) {
46
+ const v1Sigs = (0, _ocap_util_lib_get_list_field.getListField)(context.tx, "signatures");
47
+ const v1Counterparty = v1Sigs[0]?.delegator || v1Sigs[0]?.signer;
48
+ const isV1CounterpartyPasskey = Boolean(txType && V1_MULTISIG_TX_TYPES.has(txType) && v1Counterparty && ((0, _arcblock_did.toTypeInfo)(v1Counterparty).role === _ocap_mcrypto.types.RoleType.ROLE_PASSKEY || (0, _arcblock_did.toTypeInfo)(v1Counterparty).pk === _ocap_mcrypto.types.KeyType.PASSKEY) && typeof rawTxExtra === "string" && require_helpers_replay_guard.isCanonicalPasskeyExtra(rawTxExtra));
49
+ const hasDelegator = Boolean(tx.delegator) || v1Sigs.some((s) => Boolean(s?.delegator));
50
+ let isTier3CoSignatureExtra = false;
51
+ if (hasDelegator) try {
52
+ const parsed = typeof rawTxExtra === "string" ? rawTxExtra.trim().startsWith("{") ? JSON.parse(rawTxExtra) : null : rawTxExtra;
53
+ isTier3CoSignatureExtra = Boolean(parsed && typeof parsed === "object" && !Array.isArray(parsed) && parsed.coSignature && typeof parsed.coSignature === "object" && typeof parsed.coSignature.pk === "string" && typeof parsed.coSignature.signature === "string");
54
+ } catch {
55
+ isTier3CoSignatureExtra = false;
56
+ }
57
+ if (!isV1CounterpartyPasskey && !isTier3CoSignatureExtra) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${signer}`));
58
+ }
59
+ const extra = isPasskey ? rawTxExtra : isWalletEnvelope ? rawTxExtra : "";
38
60
  try {
61
+ if (isWalletEnvelope) (0, _ocap_mcrypto.assertEnvelopeMatchesTxContext)(extra, {
62
+ chainId: tx.chainId,
63
+ signer,
64
+ from: tx.from,
65
+ nonce: tx.nonce,
66
+ action: txType
67
+ });
39
68
  if (!signature || await wallet.verify(txBytes, signature, true, extra || "") === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", "tx.signature is invalid"));
40
69
  } catch (err) {
41
70
  console.error("tx.signature verify failed", err);
@@ -1,5 +1,5 @@
1
- import { IDecodedContext } from "@ocap/types";
2
1
  import { CustomError } from "@ocap/util/lib/error";
2
+ import { IDecodedContext } from "@ocap/types";
3
3
 
4
4
  //#region src/pipes/verify-signature.d.ts
5
5
  declare function VerifySignature(context: IDecodedContext, next: (err?: CustomError) => void): Promise<void>;
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
3
  const require_package = require('../package.cjs');
4
+ let _ocap_mcrypto = require("@ocap/mcrypto");
5
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
4
6
  let lodash_get = require("lodash/get");
5
7
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
6
- let _ocap_util_lib_error = require("@ocap/util/lib/error");
7
- let _ocap_mcrypto = require("@ocap/mcrypto");
8
8
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
9
9
  let debug = require("debug");
10
10
  debug = require_rolldown_runtime.__toESM(debug);
@@ -1,15 +1,15 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
+ let _ocap_mcrypto = require("@ocap/mcrypto");
3
4
  let _ocap_util = require("@ocap/util");
4
5
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
- let _ocap_mcrypto = require("@ocap/mcrypto");
6
6
  let _arcblock_did = require("@arcblock/did");
7
7
  let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
8
+ let lodash_isEqual = require("lodash/isEqual");
9
+ lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
8
10
  let _ocap_state_lib_states_tx = require("@ocap/state/lib/states/tx");
9
11
  let lodash_clone = require("lodash/clone");
10
12
  lodash_clone = require_rolldown_runtime.__toESM(lodash_clone);
11
- let lodash_isEqual = require("lodash/isEqual");
12
- lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
13
13
  let lodash_mergeWith = require("lodash/mergeWith");
14
14
  lodash_mergeWith = require_rolldown_runtime.__toESM(lodash_mergeWith);
15
15
  let lodash_pickBy = require("lodash/pickBy");
@@ -100,7 +100,7 @@ function CreateVerifyStateDiffPipe({ snapshotKey = "stateSnapshot" } = {}) {
100
100
  return next(new _ocap_util_lib_error.CustomError("INVALID_RECEIPT", "Changed state not found for receipt"));
101
101
  }
102
102
  const expectedTokens = beforeState ? mergeTokenChange(getStateTokens(beforeState, txState.type), tokenChanges) : tokenChanges;
103
- if (!(0, lodash_isEqual.default)(expectedTokens, getStateTokens(afterState, txState.type))) {
103
+ if (!(0, lodash_isEqual.default)((0, lodash_pickBy.default)(expectedTokens, (value) => value !== "0"), (0, lodash_pickBy.default)(getStateTokens(afterState, txState.type), (value) => value !== "0"))) {
104
104
  logger?.error("INVALID_RECEIPT", "Tx receipts does not match with state diff", {
105
105
  txState,
106
106
  expectedTokens,
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
- let lodash_get = require("lodash/get");
4
- lodash_get = require_rolldown_runtime.__toESM(lodash_get);
5
3
  let _ocap_util = require("@ocap/util");
6
4
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
+ let lodash_get = require("lodash/get");
6
+ lodash_get = require_rolldown_runtime.__toESM(lodash_get);
7
7
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
8
8
  let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
9
9
  let lodash_isEmpty = require("lodash/isEmpty");
@@ -1,10 +1,11 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
- let lodash_get = require("lodash/get");
4
- lodash_get = require_rolldown_runtime.__toESM(lodash_get);
5
3
  let _ocap_util = require("@ocap/util");
6
4
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
+ let lodash_get = require("lodash/get");
6
+ lodash_get = require_rolldown_runtime.__toESM(lodash_get);
7
7
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
8
+ let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
8
9
  let lodash_isEmpty = require("lodash/isEmpty");
9
10
  lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
10
11
 
@@ -17,18 +18,25 @@ function CreateVerifyTokenBalancePipe({ ownerKey, conditionKey, tokensKey = "tok
17
18
  if ((0, lodash_isEmpty.default)(rawOwners)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Token owner not found", { persist: true }));
18
19
  const conditions = Array.isArray(rawConditions) ? rawConditions : [rawConditions];
19
20
  const owners = Array.isArray(rawOwners) ? rawOwners : [rawOwners];
21
+ const aggregatedRequirementsByOwner = /* @__PURE__ */ new Map();
20
22
  for (const condition of conditions) {
21
- const owner = owners.find((x) => x.address === condition.owner);
23
+ const owner = owners.find((x) => (0, _ocap_util.isSameDid)(x.address, condition.owner) || (0, _ocap_util_lib_get_related_addr.getRelatedAddresses)(x).some((addr) => (0, _ocap_util.isSameDid)(addr, condition.owner)));
22
24
  if (!owner) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", `Token owner ${condition.owner} not found`, { persist: true }));
23
25
  const { tokens: actual } = owner;
24
26
  const requirements = (0, _ocap_util_lib_get_list_field.getListField)(condition, tokensKey);
25
- const aggregatedRequirements = /* @__PURE__ */ new Map();
27
+ let aggregatedRequirements = aggregatedRequirementsByOwner.get(owner.address);
28
+ if (!aggregatedRequirements) {
29
+ aggregatedRequirements = /* @__PURE__ */ new Map();
30
+ aggregatedRequirementsByOwner.set(owner.address, aggregatedRequirements);
31
+ }
26
32
  for (const requirement of requirements) {
27
33
  const { address, value } = requirement;
28
34
  if (!address || !value) return next(new _ocap_util_lib_error.CustomError("INTERNAL", "Invalid requirement params provided for VerifyTokenBalance pipe", { persist: true }));
35
+ const valueBn = new _ocap_util.BN(value);
36
+ if (valueBn.isNeg()) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Negative token value is not allowed in VerifyTokenBalance", { persist: true }));
29
37
  if ((0, lodash_isEmpty.default)(actual)) return next(new _ocap_util_lib_error.CustomError("INSUFFICIENT_FUND", `Account(${owner.address}) does not own any token`, { persist: true }));
30
38
  if (!actual[address]) return next(new _ocap_util_lib_error.CustomError("INSUFFICIENT_FUND", `Account(${owner.address}) does not own token(${address})`, { persist: true }));
31
- const expectedBalance = (aggregatedRequirements.get(address) || new _ocap_util.BN(0)).add(new _ocap_util.BN(value));
39
+ const expectedBalance = (aggregatedRequirements.get(address) || new _ocap_util.BN(0)).add(valueBn);
32
40
  aggregatedRequirements.set(address, expectedBalance);
33
41
  const actualBalance = new _ocap_util.BN(actual[address]);
34
42
  if (actualBalance.lt(expectedBalance)) return next(new _ocap_util_lib_error.CustomError("INSUFFICIENT_FUND", `Account(${owner.address}) does not have enough token(${address}) to complete the transaction, expected (${expectedBalance}), actual (${actualBalance})`, { persist: true }));
@@ -1,15 +1,15 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
3
4
  let lodash_get = require("lodash/get");
4
5
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
5
- let _ocap_util_lib_error = require("@ocap/util/lib/error");
6
6
 
7
7
  //#region src/pipes/verify-transferrable.ts
8
- function CreateVerifyTransferrablePipe({ assets }) {
8
+ function CreateVerifyTransferrablePipe({ assets, allowConsumed = false }) {
9
9
  return function VerifyTransferrable(context, next) {
10
10
  const rawItems = (0, lodash_get.default)(context, assets);
11
11
  const items = (Array.isArray(rawItems) ? rawItems : [rawItems]).filter((x) => Boolean(x));
12
- for (const item of items) if (item.transferrable === false) return next(new _ocap_util_lib_error.CustomError("UNTRANSFERRABLE_ASSET", `Asset ${item.address} is not transferrable`, { persist: true }));
12
+ for (const item of items) if (item.transferrable === false || !allowConsumed && Boolean(item.consumedTime)) return next(new _ocap_util_lib_error.CustomError("UNTRANSFERRABLE_ASSET", `Asset ${item.address} is not transferrable`, { persist: true }));
13
13
  next();
14
14
  };
15
15
  }
@@ -4,9 +4,16 @@ import { IBaseContext } from "@ocap/types";
4
4
  //#region src/pipes/verify-transferrable.d.ts
5
5
  interface VerifyTransferrableOptions {
6
6
  assets: string;
7
+ /**
8
+ * Stake exits (revoke/claim/return) may move an already-consumed asset out of a stake back to
9
+ * its rightful owner. Transfer/exchange/stake-in and slash must leave this unset (reject consumed).
10
+ * `transferrable === false` is always rejected regardless.
11
+ */
12
+ allowConsumed?: boolean;
7
13
  }
8
14
  declare function CreateVerifyTransferrablePipe({
9
- assets
15
+ assets,
16
+ allowConsumed
10
17
  }: VerifyTransferrableOptions): PipeFunction<IBaseContext>;
11
18
  //#endregion
12
19
  export { CreateVerifyTransferrablePipe as default };
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
- let lodash_get = require("lodash/get");
4
- lodash_get = require_rolldown_runtime.__toESM(lodash_get);
5
3
  let _ocap_util = require("@ocap/util");
6
4
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
+ let lodash_get = require("lodash/get");
6
+ lodash_get = require_rolldown_runtime.__toESM(lodash_get);
7
7
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
8
8
  let lodash_isEmpty = require("lodash/isEmpty");
9
9
  lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
@@ -44,7 +44,7 @@ function CreateVerifyTxInputPipe({ fieldKey = "itx.inputs", inputsKey = "inputs"
44
44
  {
45
45
  error: "INVALID_TX",
46
46
  message: `Each ${fieldKey} item should not contain duplicate asset`,
47
- fn: () => inputs.every((x) => (0, _ocap_util_lib_create_sorted_list.createSortedList)(getAssets(x)).length === getAssets(x).length)
47
+ fn: () => inputs.every((x) => (0, _ocap_util_lib_create_sorted_list.createSortedList)(getAssets(x)).length === getAssets(x).length) && (0, _ocap_util_lib_create_sorted_list.createSortedList)(inputs.flatMap((x) => getAssets(x))).length === inputs.flatMap((x) => getAssets(x)).length
48
48
  },
49
49
  {
50
50
  error: "INVALID_TX",
@@ -1,17 +1,61 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
3
4
  let lodash_get = require("lodash/get");
4
5
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
5
- let _ocap_util_lib_error = require("@ocap/util/lib/error");
6
6
  let _ocap_message = require("@ocap/message");
7
7
 
8
8
  //#region src/pipes/verify-tx-size.ts
9
+ const DEFAULT_MAX_EXTRA_SIZE = 8 * 1024;
10
+ const MAX_GAS_STAKE_HEADERS_SIZE = 8 * 1024;
11
+ const MAX_CO_SIGNATURE_SIZE = 4 * 1024;
12
+ const getFieldByteSize = (val) => {
13
+ if (val === void 0 || val === null || val === "") return 0;
14
+ return Buffer.byteLength(typeof val === "string" ? val : JSON.stringify(val), "utf8");
15
+ };
16
+ const getExtraByteSizes = (extra) => {
17
+ if (!extra || typeof extra !== "object") return {
18
+ txExtraBytes: 0,
19
+ gasStakeHeadersBytes: 0,
20
+ coSignatureBytes: 0,
21
+ totalExtraBytes: 0
22
+ };
23
+ const { txExtra, gasStakeHeaders, coSignature } = extra;
24
+ const txExtraBytes = getFieldByteSize(txExtra);
25
+ const gasStakeHeadersBytes = getFieldByteSize(gasStakeHeaders);
26
+ const coSignatureBytes = getFieldByteSize(coSignature);
27
+ return {
28
+ txExtraBytes,
29
+ gasStakeHeadersBytes,
30
+ coSignatureBytes,
31
+ totalExtraBytes: txExtraBytes + gasStakeHeadersBytes + coSignatureBytes
32
+ };
33
+ };
9
34
  function VerifyTxSize(context, next) {
10
35
  const { txSize, txType, tx, config } = context;
36
+ const { txExtraBytes, gasStakeHeadersBytes, coSignatureBytes, totalExtraBytes } = getExtraByteSizes(context.extra);
37
+ const alreadyCounted = Boolean(context._extraSizeCounted);
38
+ const baseTxSize = alreadyCounted ? Math.max(0, (txSize || 0) - txExtraBytes) : txSize || 0;
39
+ context._baseTxSize = baseTxSize;
11
40
  const defaultSizeLimit = (0, lodash_get.default)(config, "transaction.maxTxSize.default");
12
41
  const rawItx = tx.itx;
13
42
  const sizeLimit = (0, lodash_get.default)(config, `transaction.maxTxSize.${txType || rawItx?.typeUrl || (rawItx?.type ? (0, _ocap_message.toTypeUrl)(rawItx.type) : void 0)}`, defaultSizeLimit);
14
- if (txSize > sizeLimit) return next(new _ocap_util_lib_error.CustomError("INVALID_TX_SIZE", `Transaction size too large for ${txType}: expect ${sizeLimit}, got ${txSize}`));
43
+ if (baseTxSize > sizeLimit) return next(new _ocap_util_lib_error.CustomError("INVALID_TX_SIZE", `Transaction size too large for ${txType}: expect ${sizeLimit}, got ${baseTxSize}`));
44
+ const maxExtraSize = (0, lodash_get.default)(config, "transaction.maxExtraSize", DEFAULT_MAX_EXTRA_SIZE);
45
+ if (totalExtraBytes > maxExtraSize || gasStakeHeadersBytes > MAX_GAS_STAKE_HEADERS_SIZE || coSignatureBytes > MAX_CO_SIGNATURE_SIZE) {
46
+ const extraErr = new _ocap_util_lib_error.CustomError("INVALID_TX_SIZE", `Transaction extra size too large for ${txType}: expect <= ${maxExtraSize}, got ${totalExtraBytes}`);
47
+ extraErr._unauthenticatedExtraFailure = true;
48
+ return next(extraErr);
49
+ }
50
+ if (txExtraBytes > 0 && !alreadyCounted) {
51
+ Object.defineProperty(context, "txSize", {
52
+ value: baseTxSize + txExtraBytes,
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true
56
+ });
57
+ context._extraSizeCounted = true;
58
+ }
15
59
  next();
16
60
  }
17
61
 
@@ -1,5 +1,5 @@
1
- import { IDecodedContext } from "@ocap/types";
2
1
  import { CustomError } from "@ocap/util/lib/error";
2
+ import { IDecodedContext } from "@ocap/types";
3
3
 
4
4
  //#region src/pipes/verify-tx-size.d.ts
5
5
  declare function VerifyTxSize(context: IDecodedContext, next: (err?: CustomError) => void): void;
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
- const require_helpers_dedup_height = require('../helpers/dedup-height.cjs');
4
- let lodash_get = require("lodash/get");
5
- lodash_get = require_rolldown_runtime.__toESM(lodash_get);
3
+ require('../helpers/replay-guard.cjs');
4
+ let _ocap_mcrypto = require("@ocap/mcrypto");
6
5
  let _ocap_util = require("@ocap/util");
7
6
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
7
+ let lodash_get = require("lodash/get");
8
+ lodash_get = require_rolldown_runtime.__toESM(lodash_get);
8
9
  let _ocap_message = require("@ocap/message");
9
- let _ocap_mcrypto = require("@ocap/mcrypto");
10
10
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
11
11
  let _arcblock_did = require("@arcblock/did");
12
12
  let lodash_isEmpty = require("lodash/isEmpty");
@@ -25,10 +25,8 @@ async function VerifyTx(context, next) {
25
25
  const { itx, chainId, nonce, pk, from, delegator } = context.tx;
26
26
  const expected = (0, lodash_get.default)(context, "config.chainId");
27
27
  if (chainId !== expected) return next(new _ocap_util_lib_error.CustomError("INVALID_CHAIN_ID", `Invalid chain id: expected ${expected}, got ${chainId}`));
28
- if (await require_helpers_dedup_height.isDedupHeightActive(context)) {
29
- const nonceBn = (0, _ocap_state.parseNonceBn)(nonce);
30
- if (!nonceBn || nonceBn.lte(new _ocap_util.BN(0))) return next(new _ocap_util_lib_error.CustomError("INVALID_NONCE", "tx.nonce should be a positive integer"));
31
- } else if (Number.isNaN(Number(nonce)) || Number(nonce) < 0) return next(new _ocap_util_lib_error.CustomError("INVALID_NONCE", "tx.nonce should be a positive integer"));
28
+ const nonceBn = (0, _ocap_state.parseNonceBn)(nonce);
29
+ if (!nonceBn || nonceBn.lte(new _ocap_util.BN(0))) return next(new _ocap_util_lib_error.CustomError("INVALID_NONCE", "tx.nonce should be a positive integer"));
32
30
  const { supportedTxs, maxMultisig } = (0, lodash_get.default)(context, "config.transaction");
33
31
  const rawItx = itx;
34
32
  const itxTypeUrl = rawItx.typeUrl || (rawItx.type ? (0, _ocap_message.toTypeUrl)(rawItx.type) : void 0);
@@ -1,5 +1,5 @@
1
- import { IDecodedContext } from "@ocap/types";
2
1
  import { CustomError } from "@ocap/util/lib/error";
2
+ import { IDecodedContext } from "@ocap/types";
3
3
 
4
4
  //#region src/pipes/verify-tx.d.ts
5
5
  declare function VerifyTx(context: IDecodedContext, next: (err?: CustomError) => void): Promise<void>;
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
3
  const require_package = require('../package.cjs');
4
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
4
5
  let lodash_get = require("lodash/get");
5
6
  lodash_get = require_rolldown_runtime.__toESM(lodash_get);
6
- let _ocap_util_lib_error = require("@ocap/util/lib/error");
7
7
  let debug = require("debug");
8
8
  debug = require_rolldown_runtime.__toESM(debug);
9
9
  let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");