@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.
- package/esm/appchain-sovereign-hub.d.mts +160 -0
- package/esm/appchain-sovereign-hub.mjs +348 -0
- package/esm/arcvault-external-adapter.d.mts +166 -0
- package/esm/arcvault-external-adapter.mjs +376 -0
- package/esm/encrypted-nft-envelope.d.mts +172 -0
- package/esm/encrypted-nft-envelope.mjs +458 -0
- package/esm/evm-simplified-bridge.d.mts +1370 -0
- package/esm/evm-simplified-bridge.mjs +3875 -0
- package/esm/give-to-mint-karma.d.mts +472 -0
- package/esm/give-to-mint-karma.mjs +1057 -0
- package/esm/helpers/replay-guard.d.mts +15 -0
- package/esm/helpers/replay-guard.mjs +23 -0
- package/esm/index.d.mts +10 -5
- package/esm/index.mjs +14 -10
- package/esm/legacy-protocol-sunset.d.mts +251 -0
- package/esm/legacy-protocol-sunset.mjs +1519 -0
- package/esm/library.d.mts +16 -0
- package/esm/library.mjs +17 -0
- package/esm/native-abt-exchange.d.mts +2055 -0
- package/esm/native-abt-exchange.mjs +7250 -0
- package/esm/ofac-screening.d.mts +17 -0
- package/esm/ofac-screening.mjs +39 -0
- package/esm/pipes/anti-land-attack.mjs +1 -1
- package/esm/pipes/decode-itx.mjs +43 -4
- package/esm/pipes/decode-tx.d.mts +2 -3
- package/esm/pipes/decode-tx.mjs +53 -115
- package/esm/pipes/extract-signer.mjs +2 -2
- package/esm/pipes/extract-state.mjs +14 -3
- package/esm/pipes/post-execution-invariant-gate.d.mts +61 -0
- package/esm/pipes/post-execution-invariant-gate.mjs +789 -0
- package/esm/pipes/pre-flight-waf.d.mts +34 -0
- package/esm/pipes/pre-flight-waf.mjs +603 -0
- package/esm/pipes/take-state-snapshot.mjs +3 -2
- package/esm/pipes/update-owner.mjs +39 -4
- package/esm/pipes/verify-account-migration.mjs +14 -4
- package/esm/pipes/verify-blocked.mjs +1 -1
- package/esm/pipes/verify-delegation.d.mts +22 -3
- package/esm/pipes/verify-delegation.mjs +259 -36
- package/esm/pipes/verify-list-size.mjs +1 -1
- package/esm/pipes/verify-multisig-v2.mjs +15 -7
- package/esm/pipes/verify-multisig.mjs +15 -7
- package/esm/pipes/verify-sender.mjs +1 -1
- package/esm/pipes/verify-signature.mjs +35 -6
- package/esm/pipes/verify-signer.mjs +2 -2
- package/esm/pipes/verify-state-diff.mjs +3 -3
- package/esm/pipes/verify-token-access.mjs +1 -1
- package/esm/pipes/verify-token-balance.mjs +13 -5
- package/esm/pipes/verify-transferrable.d.mts +8 -1
- package/esm/pipes/verify-transferrable.mjs +3 -3
- package/esm/pipes/verify-tx-input.mjs +2 -2
- package/esm/pipes/verify-tx-size.mjs +46 -2
- package/esm/pipes/verify-tx.mjs +5 -7
- package/esm/pipes/verify-updater.mjs +1 -1
- package/esm/social-economy-factories.d.mts +346 -0
- package/esm/social-economy-factories.mjs +845 -0
- package/esm/super-suites-foundation.d.mts +513 -0
- package/esm/super-suites-foundation.mjs +1241 -0
- package/esm/transaction-block.d.mts +471 -0
- package/esm/transaction-block.mjs +1906 -0
- package/esm/uniswap-erc7683-solver.d.mts +201 -0
- package/esm/uniswap-erc7683-solver.mjs +321 -0
- package/esm/uniswap-lp-copilot.d.mts +113 -0
- package/esm/uniswap-lp-copilot.mjs +320 -0
- package/esm/uniswap-router.d.mts +335 -0
- package/esm/uniswap-router.mjs +578 -0
- package/esm/uniswap-token-factory-graduation.d.mts +187 -0
- package/esm/uniswap-token-factory-graduation.mjs +426 -0
- package/esm/uniswap-v4-hook.d.mts +173 -0
- package/esm/uniswap-v4-hook.mjs +517 -0
- package/lib/appchain-sovereign-hub.cjs +352 -0
- package/lib/appchain-sovereign-hub.d.cts +160 -0
- package/lib/arcvault-external-adapter.cjs +383 -0
- package/lib/arcvault-external-adapter.d.cts +166 -0
- package/lib/encrypted-nft-envelope.cjs +477 -0
- package/lib/encrypted-nft-envelope.d.cts +172 -0
- package/lib/evm-simplified-bridge.cjs +3943 -0
- package/lib/evm-simplified-bridge.d.cts +1370 -0
- package/lib/give-to-mint-karma.cjs +1084 -0
- package/lib/give-to-mint-karma.d.cts +472 -0
- package/lib/helpers/replay-guard.cjs +27 -0
- package/lib/helpers/replay-guard.d.cts +15 -0
- package/lib/index.cjs +49 -16
- package/lib/index.d.cts +10 -5
- package/lib/legacy-protocol-sunset.cjs +1543 -0
- package/lib/legacy-protocol-sunset.d.cts +251 -0
- package/lib/library.cjs +303 -0
- package/lib/library.d.cts +16 -0
- package/lib/native-abt-exchange.cjs +7322 -0
- package/lib/native-abt-exchange.d.cts +2055 -0
- package/lib/ofac-screening.cjs +42 -0
- package/lib/ofac-screening.d.cts +17 -0
- package/lib/pipes/anti-land-attack.cjs +2 -2
- package/lib/pipes/decode-itx.cjs +43 -4
- package/lib/pipes/decode-itx.d.cts +1 -1
- package/lib/pipes/decode-tx.cjs +52 -116
- package/lib/pipes/decode-tx.d.cts +3 -4
- package/lib/pipes/extract-signer.cjs +2 -2
- package/lib/pipes/extract-state.cjs +14 -3
- package/lib/pipes/post-execution-invariant-gate.cjs +800 -0
- package/lib/pipes/post-execution-invariant-gate.d.cts +61 -0
- package/lib/pipes/pre-flight-waf.cjs +616 -0
- package/lib/pipes/pre-flight-waf.d.cts +34 -0
- package/lib/pipes/take-state-snapshot.cjs +3 -2
- package/lib/pipes/update-owner.cjs +40 -5
- package/lib/pipes/update-owner.d.cts +1 -1
- package/lib/pipes/verify-account-migration.cjs +14 -4
- package/lib/pipes/verify-blocked.cjs +1 -1
- package/lib/pipes/verify-delegation.cjs +259 -36
- package/lib/pipes/verify-delegation.d.cts +22 -3
- package/lib/pipes/verify-list-size.cjs +1 -1
- package/lib/pipes/verify-multisig-v2.cjs +15 -7
- package/lib/pipes/verify-multisig.cjs +15 -7
- package/lib/pipes/verify-sender.cjs +1 -1
- package/lib/pipes/verify-service-fee.d.cts +1 -1
- package/lib/pipes/verify-signature.cjs +35 -6
- package/lib/pipes/verify-signature.d.cts +1 -1
- package/lib/pipes/verify-signer.cjs +2 -2
- package/lib/pipes/verify-state-diff.cjs +4 -4
- package/lib/pipes/verify-token-access.cjs +2 -2
- package/lib/pipes/verify-token-balance.cjs +13 -5
- package/lib/pipes/verify-transferrable.cjs +3 -3
- package/lib/pipes/verify-transferrable.d.cts +8 -1
- package/lib/pipes/verify-tx-input.cjs +3 -3
- package/lib/pipes/verify-tx-size.cjs +46 -2
- package/lib/pipes/verify-tx-size.d.cts +1 -1
- package/lib/pipes/verify-tx.cjs +6 -8
- package/lib/pipes/verify-tx.d.cts +1 -1
- package/lib/pipes/verify-updater.cjs +1 -1
- package/lib/social-economy-factories.cjs +852 -0
- package/lib/social-economy-factories.d.cts +346 -0
- package/lib/super-suites-foundation.cjs +1257 -0
- package/lib/super-suites-foundation.d.cts +513 -0
- package/lib/transaction-block.cjs +1941 -0
- package/lib/transaction-block.d.cts +471 -0
- package/lib/uniswap-erc7683-solver.cjs +327 -0
- package/lib/uniswap-erc7683-solver.d.cts +201 -0
- package/lib/uniswap-lp-copilot.cjs +328 -0
- package/lib/uniswap-lp-copilot.d.cts +113 -0
- package/lib/uniswap-router.cjs +593 -0
- package/lib/uniswap-router.d.cts +335 -0
- package/lib/uniswap-token-factory-graduation.cjs +431 -0
- package/lib/uniswap-token-factory-graduation.d.cts +187 -0
- package/lib/uniswap-v4-hook.cjs +527 -0
- package/lib/uniswap-v4-hook.d.cts +173 -0
- package/package.json +11 -10
- package/esm/helpers/dedup-height.d.mts +0 -16
- package/esm/helpers/dedup-height.mjs +0 -61
- package/lib/helpers/dedup-height.cjs +0 -72
- package/lib/helpers/dedup-height.d.cts +0 -16
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isCanonicalPasskeyExtra,
|
|
1
|
+
import { assertEnvelopeMatchesTxContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra } from "../helpers/replay-guard.mjs";
|
|
2
2
|
import { unwrapOpaqueAnyData } from "../helpers/unwrap-opaque-any.mjs";
|
|
3
3
|
import { encodeTxByEncoding } from "../helpers/encode-tx-by-context.mjs";
|
|
4
|
-
import
|
|
4
|
+
import { types } from "@ocap/mcrypto";
|
|
5
5
|
import { CustomError } from "@ocap/util/lib/error";
|
|
6
|
+
import get from "lodash/get.js";
|
|
6
7
|
import { decodeAny } from "@ocap/message";
|
|
7
|
-
import { types } from "@ocap/mcrypto";
|
|
8
8
|
import { deleteListField, getListField, setListField } from "@ocap/util/lib/get-list-field";
|
|
9
9
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
10
10
|
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
@@ -26,11 +26,12 @@ function CreateVerifyMultiSigPipe(numSigs = 0) {
|
|
|
26
26
|
if (isFromPublicKey(address, pk) === false) return next(new CustomError("INVALID_SIGNATURE", `signer ${address} and pk do not match`));
|
|
27
27
|
const type = toTypeInfo(address);
|
|
28
28
|
const isPasskey = type.role === types.RoleType.ROLE_PASSKEY || type.pk === types.KeyType.PASSKEY;
|
|
29
|
-
const
|
|
30
|
-
if (!isPasskey &&
|
|
31
|
-
|
|
29
|
+
const isWalletEnvelope = !isPasskey && Boolean(sigExtra && isCanonicalWalletEnvelopeExtra(sigExtra, type.pk));
|
|
30
|
+
if (!isPasskey && !isWalletEnvelope && sigExtra) return next(new CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${address}`));
|
|
31
|
+
const fallbackTxExtra = get(context, "extra.txExtra");
|
|
32
|
+
const extra = isPasskey ? sigExtra || fallbackTxExtra || "" : isWalletEnvelope ? sigExtra : "";
|
|
33
|
+
if (isPasskey && (!extra || !isCanonicalPasskeyExtra(extra))) return next(new CustomError("INVALID_SIGNATURE", `Non-canonical extra data for passkey signer ${address}`));
|
|
32
34
|
const wallet = fromPublicKey(pk, type);
|
|
33
|
-
const extra = sigExtra || (isPasskey ? get(context, "extra.txExtra") || "" : "");
|
|
34
35
|
setListField(tx, "signatures", [{
|
|
35
36
|
signer,
|
|
36
37
|
pk,
|
|
@@ -39,6 +40,13 @@ function CreateVerifyMultiSigPipe(numSigs = 0) {
|
|
|
39
40
|
}].concat(signatures));
|
|
40
41
|
const txBytes = encodeTxByEncoding(context.txEncoding, tx);
|
|
41
42
|
try {
|
|
43
|
+
if (isWalletEnvelope) assertEnvelopeMatchesTxContext(extra, {
|
|
44
|
+
chainId: tx.chainId,
|
|
45
|
+
signer: address,
|
|
46
|
+
from: signer,
|
|
47
|
+
nonce: tx.nonce,
|
|
48
|
+
action: context.txType
|
|
49
|
+
});
|
|
42
50
|
if (await wallet.verify(txBytes, signature, true, extra) === false) return next(new CustomError("INVALID_SIGNATURE", `Multi signature for ${address} is not valid`));
|
|
43
51
|
} catch (err) {
|
|
44
52
|
return next(new CustomError("INVALID_SIGNATURE", `Multi signature for ${address} verify failed: ${err.message}`));
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assertEnvelopeMatchesTxContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra } from "../helpers/replay-guard.mjs";
|
|
2
2
|
import { encodeTxByEncoding } from "../helpers/encode-tx-by-context.mjs";
|
|
3
|
-
import get from "lodash/get.js";
|
|
4
|
-
import { CustomError } from "@ocap/util/lib/error";
|
|
5
3
|
import { types } from "@ocap/mcrypto";
|
|
4
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
5
|
+
import get from "lodash/get.js";
|
|
6
6
|
import { deleteListField, getListField } from "@ocap/util/lib/get-list-field";
|
|
7
7
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
8
8
|
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
9
9
|
import { fromPublicKey } from "@ocap/wallet";
|
|
10
10
|
|
|
11
11
|
//#region src/pipes/verify-signature.ts
|
|
12
|
-
const V1_MULTISIG_TX_TYPES = new Set([
|
|
12
|
+
const V1_MULTISIG_TX_TYPES = new Set([
|
|
13
|
+
"fg:t:exchange",
|
|
14
|
+
"fg:t:exchange_v2",
|
|
15
|
+
"fg:t:account_migrate"
|
|
16
|
+
]);
|
|
13
17
|
async function VerifySignature(context, next) {
|
|
14
18
|
const tx = cloneDeep(context.tx);
|
|
15
19
|
const { signature } = tx;
|
|
@@ -18,7 +22,7 @@ async function VerifySignature(context, next) {
|
|
|
18
22
|
const txType = context.txType;
|
|
19
23
|
if (!txType || multiSignV2Txs.includes(txType) === false) {
|
|
20
24
|
const sigs = getListField(tx, "signatures");
|
|
21
|
-
if (txType && sigs.length > 0
|
|
25
|
+
if (txType && sigs.length > 0) {
|
|
22
26
|
if (!V1_MULTISIG_TX_TYPES.has(txType)) return next(new CustomError("INVALID_SIGNATURE", `Expect 0 multi signatures but found ${sigs.length}`));
|
|
23
27
|
if (sigs.length > 1) return next(new CustomError("INVALID_SIGNATURE", `Expect 1 multi signatures but found ${sigs.length}`));
|
|
24
28
|
}
|
|
@@ -30,8 +34,33 @@ async function VerifySignature(context, next) {
|
|
|
30
34
|
const txBytes = encodeTxByEncoding(context.txEncoding, tx);
|
|
31
35
|
const type = toTypeInfo(signer);
|
|
32
36
|
const wallet = fromPublicKey(pk, type);
|
|
33
|
-
const
|
|
37
|
+
const rawTxExtra = get(context, "extra.txExtra");
|
|
38
|
+
const isPasskey = type.role === types.RoleType.ROLE_PASSKEY || type.pk === types.KeyType.PASSKEY;
|
|
39
|
+
if (isPasskey && (typeof rawTxExtra !== "string" || !isCanonicalPasskeyExtra(rawTxExtra))) return next(new CustomError("INVALID_SIGNATURE", "Non-canonical extra data for passkey signer"));
|
|
40
|
+
const isWalletEnvelope = !isPasskey && typeof rawTxExtra === "string" && isCanonicalWalletEnvelopeExtra(rawTxExtra, type.pk);
|
|
41
|
+
if (!isPasskey && !isWalletEnvelope && rawTxExtra) {
|
|
42
|
+
const v1Sigs = getListField(context.tx, "signatures");
|
|
43
|
+
const v1Counterparty = v1Sigs[0]?.delegator || v1Sigs[0]?.signer;
|
|
44
|
+
const isV1CounterpartyPasskey = Boolean(txType && V1_MULTISIG_TX_TYPES.has(txType) && v1Counterparty && (toTypeInfo(v1Counterparty).role === types.RoleType.ROLE_PASSKEY || toTypeInfo(v1Counterparty).pk === types.KeyType.PASSKEY) && typeof rawTxExtra === "string" && isCanonicalPasskeyExtra(rawTxExtra));
|
|
45
|
+
const hasDelegator = Boolean(tx.delegator) || v1Sigs.some((s) => Boolean(s?.delegator));
|
|
46
|
+
let isTier3CoSignatureExtra = false;
|
|
47
|
+
if (hasDelegator) try {
|
|
48
|
+
const parsed = typeof rawTxExtra === "string" ? rawTxExtra.trim().startsWith("{") ? JSON.parse(rawTxExtra) : null : rawTxExtra;
|
|
49
|
+
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");
|
|
50
|
+
} catch {
|
|
51
|
+
isTier3CoSignatureExtra = false;
|
|
52
|
+
}
|
|
53
|
+
if (!isV1CounterpartyPasskey && !isTier3CoSignatureExtra) return next(new CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${signer}`));
|
|
54
|
+
}
|
|
55
|
+
const extra = isPasskey ? rawTxExtra : isWalletEnvelope ? rawTxExtra : "";
|
|
34
56
|
try {
|
|
57
|
+
if (isWalletEnvelope) assertEnvelopeMatchesTxContext(extra, {
|
|
58
|
+
chainId: tx.chainId,
|
|
59
|
+
signer,
|
|
60
|
+
from: tx.from,
|
|
61
|
+
nonce: tx.nonce,
|
|
62
|
+
action: txType
|
|
63
|
+
});
|
|
35
64
|
if (!signature || await wallet.verify(txBytes, signature, true, extra || "") === false) return next(new CustomError("INVALID_SIGNATURE", "tx.signature is invalid"));
|
|
36
65
|
} catch (err) {
|
|
37
66
|
console.error("tx.signature verify failed", err);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { name } from "../package.mjs";
|
|
2
|
-
import get from "lodash/get.js";
|
|
3
|
-
import { CustomError } from "@ocap/util/lib/error";
|
|
4
2
|
import { types } from "@ocap/mcrypto";
|
|
3
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
4
|
+
import get from "lodash/get.js";
|
|
5
5
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
6
6
|
import Debug from "debug";
|
|
7
7
|
import { toTypeInfo } from "@arcblock/did";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { types } from "@ocap/mcrypto";
|
|
1
2
|
import { BN, isSameDid } from "@ocap/util";
|
|
2
3
|
import { CustomError } from "@ocap/util/lib/error";
|
|
3
|
-
import { types } from "@ocap/mcrypto";
|
|
4
4
|
import { toTypeInfo } from "@arcblock/did";
|
|
5
5
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
6
|
+
import isEqual from "lodash/isEqual.js";
|
|
6
7
|
import { create, groupReceiptTokenChanges } from "@ocap/state/lib/states/tx";
|
|
7
8
|
import clone from "lodash/clone.js";
|
|
8
|
-
import isEqual from "lodash/isEqual.js";
|
|
9
9
|
import mergeWith from "lodash/mergeWith.js";
|
|
10
10
|
import pickBy from "lodash/pickBy.js";
|
|
11
11
|
|
|
@@ -94,7 +94,7 @@ function CreateVerifyStateDiffPipe({ snapshotKey = "stateSnapshot" } = {}) {
|
|
|
94
94
|
return next(new CustomError("INVALID_RECEIPT", "Changed state not found for receipt"));
|
|
95
95
|
}
|
|
96
96
|
const expectedTokens = beforeState ? mergeTokenChange(getStateTokens(beforeState, txState.type), tokenChanges) : tokenChanges;
|
|
97
|
-
if (!isEqual(expectedTokens, getStateTokens(afterState, txState.type))) {
|
|
97
|
+
if (!isEqual(pickBy(expectedTokens, (value) => value !== "0"), pickBy(getStateTokens(afterState, txState.type), (value) => value !== "0"))) {
|
|
98
98
|
logger?.error("INVALID_RECEIPT", "Tx receipts does not match with state diff", {
|
|
99
99
|
txState,
|
|
100
100
|
expectedTokens,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import get from "lodash/get.js";
|
|
2
1
|
import { toAddress } from "@ocap/util";
|
|
3
2
|
import { CustomError } from "@ocap/util/lib/error";
|
|
3
|
+
import get from "lodash/get.js";
|
|
4
4
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
5
5
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
6
6
|
import isEmpty from "lodash/isEmpty.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BN } from "@ocap/util";
|
|
1
|
+
import { BN, isSameDid } from "@ocap/util";
|
|
3
2
|
import { CustomError } from "@ocap/util/lib/error";
|
|
3
|
+
import get from "lodash/get.js";
|
|
4
4
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
5
|
+
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
5
6
|
import isEmpty from "lodash/isEmpty.js";
|
|
6
7
|
|
|
7
8
|
//#region src/pipes/verify-token-balance.ts
|
|
@@ -13,18 +14,25 @@ function CreateVerifyTokenBalancePipe({ ownerKey, conditionKey, tokensKey = "tok
|
|
|
13
14
|
if (isEmpty(rawOwners)) return next(new CustomError("INVALID_TX", "Token owner not found", { persist: true }));
|
|
14
15
|
const conditions = Array.isArray(rawConditions) ? rawConditions : [rawConditions];
|
|
15
16
|
const owners = Array.isArray(rawOwners) ? rawOwners : [rawOwners];
|
|
17
|
+
const aggregatedRequirementsByOwner = /* @__PURE__ */ new Map();
|
|
16
18
|
for (const condition of conditions) {
|
|
17
|
-
const owner = owners.find((x) => x.address
|
|
19
|
+
const owner = owners.find((x) => isSameDid(x.address, condition.owner) || getRelatedAddresses(x).some((addr) => isSameDid(addr, condition.owner)));
|
|
18
20
|
if (!owner) return next(new CustomError("INVALID_TX", `Token owner ${condition.owner} not found`, { persist: true }));
|
|
19
21
|
const { tokens: actual } = owner;
|
|
20
22
|
const requirements = getListField(condition, tokensKey);
|
|
21
|
-
|
|
23
|
+
let aggregatedRequirements = aggregatedRequirementsByOwner.get(owner.address);
|
|
24
|
+
if (!aggregatedRequirements) {
|
|
25
|
+
aggregatedRequirements = /* @__PURE__ */ new Map();
|
|
26
|
+
aggregatedRequirementsByOwner.set(owner.address, aggregatedRequirements);
|
|
27
|
+
}
|
|
22
28
|
for (const requirement of requirements) {
|
|
23
29
|
const { address, value } = requirement;
|
|
24
30
|
if (!address || !value) return next(new CustomError("INTERNAL", "Invalid requirement params provided for VerifyTokenBalance pipe", { persist: true }));
|
|
31
|
+
const valueBn = new BN(value);
|
|
32
|
+
if (valueBn.isNeg()) return next(new CustomError("INVALID_TX", "Negative token value is not allowed in VerifyTokenBalance", { persist: true }));
|
|
25
33
|
if (isEmpty(actual)) return next(new CustomError("INSUFFICIENT_FUND", `Account(${owner.address}) does not own any token`, { persist: true }));
|
|
26
34
|
if (!actual[address]) return next(new CustomError("INSUFFICIENT_FUND", `Account(${owner.address}) does not own token(${address})`, { persist: true }));
|
|
27
|
-
const expectedBalance = (aggregatedRequirements.get(address) || new BN(0)).add(
|
|
35
|
+
const expectedBalance = (aggregatedRequirements.get(address) || new BN(0)).add(valueBn);
|
|
28
36
|
aggregatedRequirements.set(address, expectedBalance);
|
|
29
37
|
const actualBalance = new BN(actual[address]);
|
|
30
38
|
if (actualBalance.lt(expectedBalance)) return next(new CustomError("INSUFFICIENT_FUND", `Account(${owner.address}) does not have enough token(${address}) to complete the transaction, expected (${expectedBalance}), actual (${actualBalance})`, { persist: true }));
|
|
@@ -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,12 +1,12 @@
|
|
|
1
|
-
import get from "lodash/get.js";
|
|
2
1
|
import { CustomError } from "@ocap/util/lib/error";
|
|
2
|
+
import get from "lodash/get.js";
|
|
3
3
|
|
|
4
4
|
//#region src/pipes/verify-transferrable.ts
|
|
5
|
-
function CreateVerifyTransferrablePipe({ assets }) {
|
|
5
|
+
function CreateVerifyTransferrablePipe({ assets, allowConsumed = false }) {
|
|
6
6
|
return function VerifyTransferrable(context, next) {
|
|
7
7
|
const rawItems = get(context, assets);
|
|
8
8
|
const items = (Array.isArray(rawItems) ? rawItems : [rawItems]).filter((x) => Boolean(x));
|
|
9
|
-
for (const item of items) if (item.transferrable === false) return next(new CustomError("UNTRANSFERRABLE_ASSET", `Asset ${item.address} is not transferrable`, { persist: true }));
|
|
9
|
+
for (const item of items) if (item.transferrable === false || !allowConsumed && Boolean(item.consumedTime)) return next(new CustomError("UNTRANSFERRABLE_ASSET", `Asset ${item.address} is not transferrable`, { persist: true }));
|
|
10
10
|
next();
|
|
11
11
|
};
|
|
12
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import get from "lodash/get.js";
|
|
2
1
|
import { BN } from "@ocap/util";
|
|
3
2
|
import { CustomError } from "@ocap/util/lib/error";
|
|
3
|
+
import get from "lodash/get.js";
|
|
4
4
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
5
5
|
import isEmpty from "lodash/isEmpty.js";
|
|
6
6
|
import { createSortedList } from "@ocap/util/lib/create-sorted-list";
|
|
@@ -40,7 +40,7 @@ function CreateVerifyTxInputPipe({ fieldKey = "itx.inputs", inputsKey = "inputs"
|
|
|
40
40
|
{
|
|
41
41
|
error: "INVALID_TX",
|
|
42
42
|
message: `Each ${fieldKey} item should not contain duplicate asset`,
|
|
43
|
-
fn: () => inputs.every((x) => createSortedList(getAssets(x)).length === getAssets(x).length)
|
|
43
|
+
fn: () => inputs.every((x) => createSortedList(getAssets(x)).length === getAssets(x).length) && createSortedList(inputs.flatMap((x) => getAssets(x))).length === inputs.flatMap((x) => getAssets(x)).length
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
error: "INVALID_TX",
|
|
@@ -1,14 +1,58 @@
|
|
|
1
|
-
import get from "lodash/get.js";
|
|
2
1
|
import { CustomError } from "@ocap/util/lib/error";
|
|
2
|
+
import get from "lodash/get.js";
|
|
3
3
|
import { toTypeUrl } from "@ocap/message";
|
|
4
4
|
|
|
5
5
|
//#region src/pipes/verify-tx-size.ts
|
|
6
|
+
const DEFAULT_MAX_EXTRA_SIZE = 8 * 1024;
|
|
7
|
+
const MAX_GAS_STAKE_HEADERS_SIZE = 8 * 1024;
|
|
8
|
+
const MAX_CO_SIGNATURE_SIZE = 4 * 1024;
|
|
9
|
+
const getFieldByteSize = (val) => {
|
|
10
|
+
if (val === void 0 || val === null || val === "") return 0;
|
|
11
|
+
return Buffer.byteLength(typeof val === "string" ? val : JSON.stringify(val), "utf8");
|
|
12
|
+
};
|
|
13
|
+
const getExtraByteSizes = (extra) => {
|
|
14
|
+
if (!extra || typeof extra !== "object") return {
|
|
15
|
+
txExtraBytes: 0,
|
|
16
|
+
gasStakeHeadersBytes: 0,
|
|
17
|
+
coSignatureBytes: 0,
|
|
18
|
+
totalExtraBytes: 0
|
|
19
|
+
};
|
|
20
|
+
const { txExtra, gasStakeHeaders, coSignature } = extra;
|
|
21
|
+
const txExtraBytes = getFieldByteSize(txExtra);
|
|
22
|
+
const gasStakeHeadersBytes = getFieldByteSize(gasStakeHeaders);
|
|
23
|
+
const coSignatureBytes = getFieldByteSize(coSignature);
|
|
24
|
+
return {
|
|
25
|
+
txExtraBytes,
|
|
26
|
+
gasStakeHeadersBytes,
|
|
27
|
+
coSignatureBytes,
|
|
28
|
+
totalExtraBytes: txExtraBytes + gasStakeHeadersBytes + coSignatureBytes
|
|
29
|
+
};
|
|
30
|
+
};
|
|
6
31
|
function VerifyTxSize(context, next) {
|
|
7
32
|
const { txSize, txType, tx, config } = context;
|
|
33
|
+
const { txExtraBytes, gasStakeHeadersBytes, coSignatureBytes, totalExtraBytes } = getExtraByteSizes(context.extra);
|
|
34
|
+
const alreadyCounted = Boolean(context._extraSizeCounted);
|
|
35
|
+
const baseTxSize = alreadyCounted ? Math.max(0, (txSize || 0) - txExtraBytes) : txSize || 0;
|
|
36
|
+
context._baseTxSize = baseTxSize;
|
|
8
37
|
const defaultSizeLimit = get(config, "transaction.maxTxSize.default");
|
|
9
38
|
const rawItx = tx.itx;
|
|
10
39
|
const sizeLimit = get(config, `transaction.maxTxSize.${txType || rawItx?.typeUrl || (rawItx?.type ? toTypeUrl(rawItx.type) : void 0)}`, defaultSizeLimit);
|
|
11
|
-
if (
|
|
40
|
+
if (baseTxSize > sizeLimit) return next(new CustomError("INVALID_TX_SIZE", `Transaction size too large for ${txType}: expect ${sizeLimit}, got ${baseTxSize}`));
|
|
41
|
+
const maxExtraSize = get(config, "transaction.maxExtraSize", DEFAULT_MAX_EXTRA_SIZE);
|
|
42
|
+
if (totalExtraBytes > maxExtraSize || gasStakeHeadersBytes > MAX_GAS_STAKE_HEADERS_SIZE || coSignatureBytes > MAX_CO_SIGNATURE_SIZE) {
|
|
43
|
+
const extraErr = new CustomError("INVALID_TX_SIZE", `Transaction extra size too large for ${txType}: expect <= ${maxExtraSize}, got ${totalExtraBytes}`);
|
|
44
|
+
extraErr._unauthenticatedExtraFailure = true;
|
|
45
|
+
return next(extraErr);
|
|
46
|
+
}
|
|
47
|
+
if (txExtraBytes > 0 && !alreadyCounted) {
|
|
48
|
+
Object.defineProperty(context, "txSize", {
|
|
49
|
+
value: baseTxSize + txExtraBytes,
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true
|
|
53
|
+
});
|
|
54
|
+
context._extraSizeCounted = true;
|
|
55
|
+
}
|
|
12
56
|
next();
|
|
13
57
|
}
|
|
14
58
|
|
package/esm/pipes/verify-tx.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { parseNonceBn } from "../helpers/replay-guard.mjs";
|
|
2
|
+
import { types } from "@ocap/mcrypto";
|
|
3
3
|
import { BN } from "@ocap/util";
|
|
4
4
|
import { CustomError } from "@ocap/util/lib/error";
|
|
5
|
+
import get from "lodash/get.js";
|
|
5
6
|
import { toTypeUrl } from "@ocap/message";
|
|
6
|
-
import { types } from "@ocap/mcrypto";
|
|
7
7
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
8
8
|
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
9
9
|
import isEmpty from "lodash/isEmpty.js";
|
|
@@ -20,10 +20,8 @@ async function VerifyTx(context, next) {
|
|
|
20
20
|
const { itx, chainId, nonce, pk, from, delegator } = context.tx;
|
|
21
21
|
const expected = get(context, "config.chainId");
|
|
22
22
|
if (chainId !== expected) return next(new CustomError("INVALID_CHAIN_ID", `Invalid chain id: expected ${expected}, got ${chainId}`));
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!nonceBn || nonceBn.lte(new BN(0))) return next(new CustomError("INVALID_NONCE", "tx.nonce should be a positive integer"));
|
|
26
|
-
} else if (Number.isNaN(Number(nonce)) || Number(nonce) < 0) return next(new CustomError("INVALID_NONCE", "tx.nonce should be a positive integer"));
|
|
23
|
+
const nonceBn = parseNonceBn(nonce);
|
|
24
|
+
if (!nonceBn || nonceBn.lte(new BN(0))) return next(new CustomError("INVALID_NONCE", "tx.nonce should be a positive integer"));
|
|
27
25
|
const { supportedTxs, maxMultisig } = get(context, "config.transaction");
|
|
28
26
|
const rawItx = itx;
|
|
29
27
|
const itxTypeUrl = rawItx.typeUrl || (rawItx.type ? toTypeUrl(rawItx.type) : void 0);
|