@ocap/tx-pipeline 1.31.1 → 1.31.2
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/bridge-release-keys.d.mts +33 -0
- package/esm/bridge-release-keys.mjs +81 -0
- package/esm/bridge-reserves.d.mts +107 -0
- package/esm/bridge-reserves.mjs +242 -0
- package/esm/helpers/bridge-withdraw.d.mts +86 -0
- package/esm/helpers/bridge-withdraw.mjs +123 -0
- package/esm/helpers/replay-guard.d.mts +19 -1
- package/esm/helpers/replay-guard.mjs +39 -1
- package/esm/index.d.mts +3 -1
- package/esm/index.mjs +8 -6
- package/esm/legacy-protocol-sunset.d.mts +2 -2
- package/esm/legacy-protocol-sunset.mjs +5 -5
- package/esm/legacy-rollup-archive.d.mts +67 -0
- package/esm/legacy-rollup-archive.mjs +199 -0
- package/esm/library.d.mts +4 -4
- package/esm/library.mjs +3 -3
- package/esm/native-abt-exchange.d.mts +3 -0
- package/esm/native-abt-exchange.mjs +93 -46
- package/esm/pipes/bridge-release-gate.d.mts +30 -0
- package/esm/pipes/bridge-release-gate.mjs +143 -0
- package/esm/pipes/bridge-reserve-v2-gate.d.mts +53 -0
- package/esm/pipes/bridge-reserve-v2-gate.mjs +264 -0
- package/esm/pipes/decode-tx.mjs +29 -4
- package/esm/pipes/extract-signer.mjs +1 -1
- package/esm/pipes/extract-state.mjs +2 -2
- package/esm/pipes/post-execution-invariant-gate.d.mts +19 -2
- package/esm/pipes/post-execution-invariant-gate.mjs +121 -6
- package/esm/pipes/pre-flight-waf.d.mts +18 -1
- package/esm/pipes/pre-flight-waf.mjs +48 -13
- package/esm/pipes/update-owner.mjs +1 -1
- package/esm/pipes/verify-account-migration.mjs +1 -1
- package/esm/pipes/verify-delegation.mjs +49 -25
- package/esm/pipes/verify-multisig-v2.mjs +5 -4
- package/esm/pipes/verify-multisig.mjs +5 -4
- package/esm/pipes/verify-signature.d.mts +7 -1
- package/esm/pipes/verify-signature.mjs +119 -16
- package/esm/pipes/verify-signer.mjs +2 -2
- package/esm/pipes/verify-token-access.mjs +1 -1
- package/esm/pipes/verify-token-balance.mjs +1 -1
- package/esm/pipes/verify-tx-input.mjs +1 -1
- package/esm/pipes/verify-tx-size.mjs +1 -1
- package/esm/pipes/verify-tx.mjs +12 -5
- package/esm/super-suites-foundation.mjs +6 -6
- package/esm/transaction-block.d.mts +6 -2
- package/esm/transaction-block.mjs +282 -40
- package/esm/uniswap-router.d.mts +247 -1
- package/esm/uniswap-router.mjs +573 -2
- package/lib/bridge-release-keys.cjs +88 -0
- package/lib/bridge-release-keys.d.cts +33 -0
- package/lib/bridge-reserves.cjs +257 -0
- package/lib/bridge-reserves.d.cts +107 -0
- package/lib/helpers/bridge-withdraw.cjs +136 -0
- package/lib/helpers/bridge-withdraw.d.cts +86 -0
- package/lib/helpers/replay-guard.cjs +39 -0
- package/lib/helpers/replay-guard.d.cts +20 -2
- package/lib/index.cjs +25 -5
- package/lib/index.d.cts +3 -1
- package/lib/legacy-protocol-sunset.cjs +7 -7
- package/lib/legacy-protocol-sunset.d.cts +2 -2
- package/lib/legacy-rollup-archive.cjs +208 -0
- package/lib/legacy-rollup-archive.d.cts +67 -0
- package/lib/library.cjs +14 -68
- package/lib/library.d.cts +4 -4
- package/lib/native-abt-exchange.cjs +93 -46
- package/lib/native-abt-exchange.d.cts +3 -0
- package/lib/pipes/bridge-release-gate.cjs +145 -0
- package/lib/pipes/bridge-release-gate.d.cts +30 -0
- package/lib/pipes/bridge-reserve-v2-gate.cjs +273 -0
- package/lib/pipes/bridge-reserve-v2-gate.d.cts +53 -0
- package/lib/pipes/decode-itx.d.cts +1 -1
- package/lib/pipes/decode-tx.cjs +28 -3
- package/lib/pipes/decode-tx.d.cts +1 -1
- package/lib/pipes/extract-signer.cjs +1 -1
- package/lib/pipes/extract-state.cjs +3 -3
- package/lib/pipes/post-execution-invariant-gate.cjs +121 -4
- package/lib/pipes/post-execution-invariant-gate.d.cts +19 -2
- package/lib/pipes/pre-flight-waf.cjs +51 -13
- package/lib/pipes/pre-flight-waf.d.cts +19 -2
- package/lib/pipes/update-owner.cjs +1 -1
- package/lib/pipes/update-owner.d.cts +1 -1
- package/lib/pipes/verify-account-migration.cjs +1 -1
- package/lib/pipes/verify-delegation.cjs +50 -26
- package/lib/pipes/verify-multisig-v2.cjs +5 -4
- package/lib/pipes/verify-multisig.cjs +5 -4
- package/lib/pipes/verify-service-fee.d.cts +1 -1
- package/lib/pipes/verify-signature.cjs +118 -14
- package/lib/pipes/verify-signature.d.cts +8 -2
- package/lib/pipes/verify-signer.cjs +2 -2
- package/lib/pipes/verify-token-access.cjs +1 -1
- package/lib/pipes/verify-token-balance.cjs +1 -1
- package/lib/pipes/verify-tx-input.cjs +1 -1
- package/lib/pipes/verify-tx-size.cjs +1 -1
- package/lib/pipes/verify-tx-size.d.cts +1 -1
- package/lib/pipes/verify-tx.cjs +11 -5
- package/lib/pipes/verify-tx.d.cts +1 -1
- package/lib/super-suites-foundation.cjs +6 -6
- package/lib/transaction-block.cjs +282 -40
- package/lib/transaction-block.d.cts +6 -2
- package/lib/uniswap-router.cjs +576 -1
- package/lib/uniswap-router.d.cts +247 -1
- package/package.json +10 -10
- package/esm/evm-simplified-bridge.d.mts +0 -1370
- package/esm/evm-simplified-bridge.mjs +0 -3875
- package/lib/evm-simplified-bridge.cjs +0 -3943
- package/lib/evm-simplified-bridge.d.cts +0 -1370
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CustomError } from "@ocap/util/lib/error";
|
|
2
1
|
import { IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
3
3
|
|
|
4
4
|
//#region src/pipes/verify-service-fee.d.ts
|
|
5
5
|
declare function VerifyServiceFee(context: IDecodedContext, next: (err?: CustomError) => void): void;
|
|
@@ -4,12 +4,12 @@ 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
5
|
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
6
6
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
|
+
let _arcblock_did = require("@arcblock/did");
|
|
8
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
7
9
|
let lodash_get = require("lodash/get");
|
|
8
10
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
9
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
10
11
|
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
11
12
|
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
12
|
-
let _arcblock_did = require("@arcblock/did");
|
|
13
13
|
let _ocap_wallet = require("@ocap/wallet");
|
|
14
14
|
|
|
15
15
|
//#region src/pipes/verify-signature.ts
|
|
@@ -18,6 +18,94 @@ const V1_MULTISIG_TX_TYPES = new Set([
|
|
|
18
18
|
"fg:t:exchange_v2",
|
|
19
19
|
"fg:t:account_migrate"
|
|
20
20
|
]);
|
|
21
|
+
const ALLOWED_COSIG_KEYS = new Set([
|
|
22
|
+
"pk",
|
|
23
|
+
"signature",
|
|
24
|
+
"extra"
|
|
25
|
+
]);
|
|
26
|
+
const ALLOWED_PASSKEY_COSIG_EXTRA_KEYS = new Set(["authenticatorData", "clientDataJSON"]);
|
|
27
|
+
const MAX_CO_SIGNATURE_TX_EXTRA_CHARS = 4096;
|
|
28
|
+
const MAX_CO_SIGNATURE_PASSKEY_EXTRA_CHARS = 2048;
|
|
29
|
+
function isCanonicalPasskeyCoSigExtra(extra) {
|
|
30
|
+
if (typeof extra !== "string" || extra.length === 0 || extra.length > MAX_CO_SIGNATURE_PASSKEY_EXTRA_CHARS || !require_helpers_replay_guard.isCanonicalPasskeyExtra(extra)) return false;
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(extra);
|
|
33
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || JSON.stringify(parsed) !== extra) return false;
|
|
34
|
+
if (Object.keys(parsed).some((k) => !ALLOWED_PASSKEY_COSIG_EXTRA_KEYS.has(k))) return false;
|
|
35
|
+
return true;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function parseCanonicalCoSignatureTxExtra(rawTxExtra) {
|
|
41
|
+
try {
|
|
42
|
+
let parsed = null;
|
|
43
|
+
if (typeof rawTxExtra === "string") {
|
|
44
|
+
if (rawTxExtra.length > MAX_CO_SIGNATURE_TX_EXTRA_CHARS || !rawTxExtra.startsWith("{")) return null;
|
|
45
|
+
parsed = JSON.parse(rawTxExtra);
|
|
46
|
+
if (JSON.stringify(parsed) !== rawTxExtra) return null;
|
|
47
|
+
} else if (rawTxExtra && typeof rawTxExtra === "object" && !Array.isArray(rawTxExtra)) {
|
|
48
|
+
const serialized = JSON.stringify(rawTxExtra);
|
|
49
|
+
if (!serialized || serialized.length > MAX_CO_SIGNATURE_TX_EXTRA_CHARS) return null;
|
|
50
|
+
parsed = rawTxExtra;
|
|
51
|
+
} else return null;
|
|
52
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
53
|
+
const topKeys = Object.keys(parsed);
|
|
54
|
+
if (topKeys.length !== 1 || topKeys[0] !== "coSignature") return null;
|
|
55
|
+
const coSig = parsed.coSignature;
|
|
56
|
+
if (!coSig || typeof coSig !== "object" || Array.isArray(coSig)) return null;
|
|
57
|
+
const coSigKeys = Object.keys(coSig);
|
|
58
|
+
if (coSigKeys.length < 2 || coSigKeys.length > 3 || coSigKeys.some((k) => !ALLOWED_COSIG_KEYS.has(k))) return null;
|
|
59
|
+
const { pk, signature, extra } = coSig;
|
|
60
|
+
if (typeof pk !== "string" || pk.trim().length === 0 || pk.length > 256) return null;
|
|
61
|
+
if (typeof signature !== "string" || signature.trim().length === 0 || signature.length > 512) return null;
|
|
62
|
+
if (extra !== void 0 && extra !== "") {
|
|
63
|
+
if (typeof extra !== "string" || !isCanonicalPasskeyCoSigExtra(extra)) return null;
|
|
64
|
+
return {
|
|
65
|
+
pk,
|
|
66
|
+
signature,
|
|
67
|
+
extra
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
pk,
|
|
72
|
+
signature
|
|
73
|
+
};
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function verifyStatelessCoSignature(coSig, candidates, candidatePayloads) {
|
|
79
|
+
if (candidates.length === 0 || candidatePayloads.length === 0) return false;
|
|
80
|
+
const coSigPkHex = (0, _arcblock_did.normalizePublicKeyHex)(coSig.pk);
|
|
81
|
+
if (!coSigPkHex) return false;
|
|
82
|
+
for (const { ownerAddr, delegateePk } of candidates) {
|
|
83
|
+
if (!ownerAddr) continue;
|
|
84
|
+
const forbiddenPkHex = delegateePk ? (0, _arcblock_did.normalizePublicKeyHex)(delegateePk) : "";
|
|
85
|
+
if (forbiddenPkHex && coSigPkHex === forbiddenPkHex) continue;
|
|
86
|
+
if (!(0, _arcblock_did.isFromPublicKey)(ownerAddr, coSig.pk)) continue;
|
|
87
|
+
const ownerType = (0, _arcblock_did.toTypeInfo)(ownerAddr);
|
|
88
|
+
const isOwnerPasskey = ownerType.role === _ocap_mcrypto.types.RoleType.ROLE_PASSKEY || ownerType.pk === _ocap_mcrypto.types.KeyType.PASSKEY;
|
|
89
|
+
const coSigExtra = coSig.extra || "";
|
|
90
|
+
if (isOwnerPasskey && !coSigExtra) continue;
|
|
91
|
+
if (!isOwnerPasskey && coSigExtra) continue;
|
|
92
|
+
let wallet;
|
|
93
|
+
try {
|
|
94
|
+
wallet = (0, _ocap_wallet.fromPublicKey)(coSig.pk, ownerType);
|
|
95
|
+
} catch {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
for (const payload of candidatePayloads) {
|
|
99
|
+
try {
|
|
100
|
+
if (await wallet.verify(payload, coSig.signature, false, coSigExtra)) return true;
|
|
101
|
+
} catch {}
|
|
102
|
+
try {
|
|
103
|
+
if (await wallet.verify(payload, coSig.signature, true, coSigExtra)) return true;
|
|
104
|
+
} catch {}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
21
109
|
async function VerifySignature(context, next) {
|
|
22
110
|
const tx = (0, lodash_cloneDeep.default)(context.tx);
|
|
23
111
|
const { signature } = tx;
|
|
@@ -39,22 +127,36 @@ async function VerifySignature(context, next) {
|
|
|
39
127
|
const type = (0, _arcblock_did.toTypeInfo)(signer);
|
|
40
128
|
const wallet = (0, _ocap_wallet.fromPublicKey)(pk, type);
|
|
41
129
|
const rawTxExtra = (0, lodash_get.default)(context, "extra.txExtra");
|
|
130
|
+
const rawDirectCoSig = (0, lodash_get.default)(context, "extra.coSignature");
|
|
131
|
+
const hasDirectCoSig = rawDirectCoSig !== void 0 && rawDirectCoSig !== null;
|
|
42
132
|
const isPasskey = type.role === _ocap_mcrypto.types.RoleType.ROLE_PASSKEY || type.pk === _ocap_mcrypto.types.KeyType.PASSKEY;
|
|
43
133
|
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
134
|
const isWalletEnvelope = !isPasskey && typeof rawTxExtra === "string" && (0, _ocap_mcrypto.isCanonicalWalletEnvelopeExtra)(rawTxExtra, type.pk);
|
|
45
|
-
if (!isPasskey && !isWalletEnvelope && rawTxExtra) {
|
|
135
|
+
if (!isPasskey && !isWalletEnvelope && rawTxExtra || hasDirectCoSig) {
|
|
46
136
|
const v1Sigs = (0, _ocap_util_lib_get_list_field.getListField)(context.tx, "signatures");
|
|
47
137
|
const v1Counterparty = v1Sigs[0]?.delegator || v1Sigs[0]?.signer;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
138
|
+
if (!Boolean(!hasDirectCoSig && 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))) {
|
|
139
|
+
const hasDelegator = Boolean(tx.delegator) || v1Sigs.some((s) => Boolean(s?.delegator));
|
|
140
|
+
const parsedFromTxExtra = !isPasskey && !isWalletEnvelope && rawTxExtra ? parseCanonicalCoSignatureTxExtra(rawTxExtra) : null;
|
|
141
|
+
const parsedFromDirect = hasDirectCoSig ? parseCanonicalCoSignatureTxExtra({ coSignature: rawDirectCoSig }) : null;
|
|
142
|
+
if (hasDirectCoSig && !parsedFromDirect) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", "Invalid owner coSignature"));
|
|
143
|
+
if (!isPasskey && !isWalletEnvelope && rawTxExtra && !parsedFromTxExtra) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${signer}`));
|
|
144
|
+
if (parsedFromTxExtra && parsedFromDirect && (parsedFromTxExtra.pk !== parsedFromDirect.pk || parsedFromTxExtra.signature !== parsedFromDirect.signature || (parsedFromTxExtra.extra || "") !== (parsedFromDirect.extra || ""))) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", "Conflicting owner coSignature inputs"));
|
|
145
|
+
const parsedCoSig = parsedFromTxExtra || parsedFromDirect;
|
|
146
|
+
if (!hasDelegator || !parsedCoSig) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${signer}`));
|
|
147
|
+
const coSigCandidates = [];
|
|
148
|
+
if (tx.delegator && tx.from) coSigCandidates.push({
|
|
149
|
+
ownerAddr: tx.from,
|
|
150
|
+
delegateePk: tx.pk
|
|
151
|
+
});
|
|
152
|
+
for (const s of v1Sigs) if (s?.delegator && s?.signer) coSigCandidates.push({
|
|
153
|
+
ownerAddr: s.signer,
|
|
154
|
+
delegateePk: s.pk
|
|
155
|
+
});
|
|
156
|
+
const ctxTxHash = context.txHash;
|
|
157
|
+
const ctxUnsignedTxHash = context.unsignedTxHash || (0, _ocap_mcrypto.toTxHash)(txBytes);
|
|
158
|
+
if (!await verifyStatelessCoSignature(parsedCoSig, coSigCandidates, Array.from(new Set([ctxTxHash, ctxUnsignedTxHash].filter((x) => typeof x === "string" && x.length > 0))))) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", "Invalid owner coSignature"));
|
|
56
159
|
}
|
|
57
|
-
if (!isV1CounterpartyPasskey && !isTier3CoSignatureExtra) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${signer}`));
|
|
58
160
|
}
|
|
59
161
|
const extra = isPasskey ? rawTxExtra : isWalletEnvelope ? rawTxExtra : "";
|
|
60
162
|
try {
|
|
@@ -63,7 +165,8 @@ async function VerifySignature(context, next) {
|
|
|
63
165
|
signer,
|
|
64
166
|
from: tx.from,
|
|
65
167
|
nonce: tx.nonce,
|
|
66
|
-
action: txType
|
|
168
|
+
action: txType,
|
|
169
|
+
withdraw: await require_helpers_replay_guard.getBridgeWithdrawEnvelopeContext(context)
|
|
67
170
|
});
|
|
68
171
|
if (!signature || await wallet.verify(txBytes, signature, true, extra || "") === false) return next(new _ocap_util_lib_error.CustomError("INVALID_SIGNATURE", "tx.signature is invalid"));
|
|
69
172
|
} catch (err) {
|
|
@@ -75,4 +178,5 @@ async function VerifySignature(context, next) {
|
|
|
75
178
|
}
|
|
76
179
|
|
|
77
180
|
//#endregion
|
|
78
|
-
exports.default = VerifySignature;
|
|
181
|
+
exports.default = VerifySignature;
|
|
182
|
+
exports.parseCanonicalCoSignatureTxExtra = parseCanonicalCoSignatureTxExtra;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { CustomError } from "@ocap/util/lib/error";
|
|
2
1
|
import { IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
3
3
|
|
|
4
4
|
//#region src/pipes/verify-signature.d.ts
|
|
5
|
+
interface ParsedCoSignature {
|
|
6
|
+
pk: string;
|
|
7
|
+
signature: string;
|
|
8
|
+
extra?: string;
|
|
9
|
+
}
|
|
10
|
+
declare function parseCanonicalCoSignatureTxExtra(rawTxExtra: unknown): ParsedCoSignature | null;
|
|
5
11
|
declare function VerifySignature(context: IDecodedContext, next: (err?: CustomError) => void): Promise<void>;
|
|
6
12
|
//#endregion
|
|
7
|
-
export { VerifySignature as default };
|
|
13
|
+
export { ParsedCoSignature, VerifySignature as default, parseCanonicalCoSignatureTxExtra };
|
|
@@ -3,12 +3,12 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
const require_package = require('../package.cjs');
|
|
4
4
|
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
5
5
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
6
|
+
let _arcblock_did = require("@arcblock/did");
|
|
7
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
6
8
|
let lodash_get = require("lodash/get");
|
|
7
9
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
8
|
-
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
9
10
|
let debug = require("debug");
|
|
10
11
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
11
|
-
let _arcblock_did = require("@arcblock/did");
|
|
12
12
|
|
|
13
13
|
//#region src/pipes/verify-signer.ts
|
|
14
14
|
const debug$1 = (0, debug.default)(`${require_package.name}:pipe:verify-signer`);
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
3
|
let _ocap_util = require("@ocap/util");
|
|
4
4
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
5
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
5
6
|
let lodash_get = require("lodash/get");
|
|
6
7
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
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");
|
|
10
10
|
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
3
|
let _ocap_util = require("@ocap/util");
|
|
4
4
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
5
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
5
6
|
let lodash_get = require("lodash/get");
|
|
6
7
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
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");
|
|
10
10
|
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
3
|
let _ocap_util = require("@ocap/util");
|
|
4
4
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
5
|
+
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
5
6
|
let lodash_get = require("lodash/get");
|
|
6
7
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
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);
|
|
10
10
|
let _ocap_util_lib_create_sorted_list = require("@ocap/util/lib/create-sorted-list");
|
|
@@ -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
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
4
|
+
let _ocap_message = require("@ocap/message");
|
|
4
5
|
let lodash_get = require("lodash/get");
|
|
5
6
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
6
|
-
let _ocap_message = require("@ocap/message");
|
|
7
7
|
|
|
8
8
|
//#region src/pipes/verify-tx-size.ts
|
|
9
9
|
const DEFAULT_MAX_EXTRA_SIZE = 8 * 1024;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CustomError } from "@ocap/util/lib/error";
|
|
2
1
|
import { IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
3
3
|
|
|
4
4
|
//#region src/pipes/verify-tx-size.d.ts
|
|
5
5
|
declare function VerifyTxSize(context: IDecodedContext, next: (err?: CustomError) => void): void;
|
package/lib/pipes/verify-tx.cjs
CHANGED
|
@@ -4,14 +4,14 @@ require('../helpers/replay-guard.cjs');
|
|
|
4
4
|
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
5
5
|
let _ocap_util = require("@ocap/util");
|
|
6
6
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
|
-
let
|
|
8
|
-
|
|
7
|
+
let _arcblock_did = require("@arcblock/did");
|
|
8
|
+
let _ocap_state = require("@ocap/state");
|
|
9
9
|
let _ocap_message = require("@ocap/message");
|
|
10
10
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
11
|
-
let
|
|
11
|
+
let lodash_get = require("lodash/get");
|
|
12
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
12
13
|
let lodash_isEmpty = require("lodash/isEmpty");
|
|
13
14
|
lodash_isEmpty = require_rolldown_runtime.__toESM(lodash_isEmpty);
|
|
14
|
-
let _ocap_state = require("@ocap/state");
|
|
15
15
|
|
|
16
16
|
//#region src/pipes/verify-tx.ts
|
|
17
17
|
async function VerifyTx(context, next) {
|
|
@@ -27,9 +27,15 @@ async function VerifyTx(context, next) {
|
|
|
27
27
|
if (chainId !== expected) return next(new _ocap_util_lib_error.CustomError("INVALID_CHAIN_ID", `Invalid chain id: expected ${expected}, got ${chainId}`));
|
|
28
28
|
const nonceBn = (0, _ocap_state.parseNonceBn)(nonce);
|
|
29
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"));
|
|
30
|
-
const { supportedTxs, maxMultisig } = (0, lodash_get.default)(context, "config.transaction");
|
|
31
30
|
const rawItx = itx;
|
|
32
31
|
const itxTypeUrl = rawItx.typeUrl || (rawItx.type ? (0, _ocap_message.toTypeUrl)(rawItx.type) : void 0);
|
|
32
|
+
const isExchangeV2 = itxTypeUrl === "fg:t:exchange_v2" || context.txType === "fg:t:exchange_v2";
|
|
33
|
+
if (!(0, lodash_isEmpty.default)(delegator) || isExchangeV2) {
|
|
34
|
+
const txTimeMs = context.txTime ? new Date(context.txTime).getTime() : NaN;
|
|
35
|
+
const maxNonce = (Number.isFinite(txTimeMs) ? txTimeMs : Date.now()) + _ocap_state.account.DELEGATED_NONCE_MAX_FUTURE_MS;
|
|
36
|
+
if (nonceBn.gt(new _ocap_util.BN(String(maxNonce), 10))) return next(new _ocap_util_lib_error.CustomError("INVALID_NONCE", `tx.nonce of a ${!(0, lodash_isEmpty.default)(delegator) ? "delegated" : "exchange_v2"} tx should not exceed the tx time in milliseconds plus 24 hours (max ${maxNonce}, got ${nonceBn.toString(10)})`));
|
|
37
|
+
}
|
|
38
|
+
const { supportedTxs, maxMultisig } = (0, lodash_get.default)(context, "config.transaction");
|
|
33
39
|
if (!itxTypeUrl || supportedTxs.includes(itxTypeUrl) === false) return next(new _ocap_util_lib_error.CustomError("UNSUPPORTED_TX", `Transaction ${itxTypeUrl} is not supported`));
|
|
34
40
|
if ((0, _ocap_util_lib_get_list_field.getListField)(context, "tx.signatures").length > maxMultisig) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Too many multisig signatures"));
|
|
35
41
|
if ((0, _arcblock_did.toTypeInfo)(from).role === _ocap_mcrypto.types.RoleType.ROLE_ASSET && (0, lodash_isEmpty.default)(delegator)) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Asset sender requires a delegator"));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CustomError } from "@ocap/util/lib/error";
|
|
2
1
|
import { IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { CustomError } from "@ocap/util/lib/error";
|
|
3
3
|
|
|
4
4
|
//#region src/pipes/verify-tx.d.ts
|
|
5
5
|
declare function VerifyTx(context: IDecodedContext, next: (err?: CustomError) => void): Promise<void>;
|
|
@@ -254,7 +254,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
254
254
|
}];
|
|
255
255
|
const postConditions = {
|
|
256
256
|
signer: pool.poolDid,
|
|
257
|
-
maxTokenOutflow: { [pool.tokenAddress]: redeemAmountAbt.toString(10) },
|
|
257
|
+
maxTokenOutflow: { [pool.poolDid]: { [pool.tokenAddress]: redeemAmountAbt.toString(10) } },
|
|
258
258
|
strictZeroUnlistedOutflow: true
|
|
259
259
|
};
|
|
260
260
|
return {
|
|
@@ -472,7 +472,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
472
472
|
pushSplitTransfer(org.creatorDid, creatorNetAbt, "CREATOR_NET_REVENUE");
|
|
473
473
|
const postConditions = {
|
|
474
474
|
signer: payerDid,
|
|
475
|
-
maxTokenOutflow: { [org.tokenAddress]: ticketPriceAbt.toString(10) },
|
|
475
|
+
maxTokenOutflow: { [payerDid]: { [org.tokenAddress]: ticketPriceAbt.toString(10) } },
|
|
476
476
|
strictZeroUnlistedOutflow: true
|
|
477
477
|
};
|
|
478
478
|
return {
|
|
@@ -669,7 +669,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
669
669
|
pushSplit(machineDid, poolCAddedAbt, "C_CONSERVATION_PRIZE_POOL");
|
|
670
670
|
const postConditions = {
|
|
671
671
|
signer: payerDid,
|
|
672
|
-
maxTokenOutflow: { [machine.tokenAddress]: A.toString(10) },
|
|
672
|
+
maxTokenOutflow: { [payerDid]: { [machine.tokenAddress]: A.toString(10) } },
|
|
673
673
|
strictZeroUnlistedOutflow: true
|
|
674
674
|
};
|
|
675
675
|
return {
|
|
@@ -774,7 +774,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
774
774
|
}));
|
|
775
775
|
const postConditions = {
|
|
776
776
|
signer: machineDid,
|
|
777
|
-
maxTokenOutflow: { [machine.tokenAddress]: totalPayoutAbt.toString(10) },
|
|
777
|
+
maxTokenOutflow: { [machineDid]: { [machine.tokenAddress]: totalPayoutAbt.toString(10) } },
|
|
778
778
|
strictZeroUnlistedOutflow: true
|
|
779
779
|
};
|
|
780
780
|
return {
|
|
@@ -945,7 +945,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
945
945
|
});
|
|
946
946
|
const postConditions = {
|
|
947
947
|
signer: offer.buyerDid,
|
|
948
|
-
maxTokenOutflow: { [DEFAULT_ABT_TOKEN_ADDRESS]: grossOfferAbt.toString(10) },
|
|
948
|
+
maxTokenOutflow: { [offer.buyerDid]: { [DEFAULT_ABT_TOKEN_ADDRESS]: grossOfferAbt.toString(10) } },
|
|
949
949
|
mustOwnAssetsAfter: { [offer.buyerDid]: [sticker.stickerDid] },
|
|
950
950
|
strictZeroUnlistedOutflow: true
|
|
951
951
|
};
|
|
@@ -1208,7 +1208,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
1208
1208
|
if (senderRefundAbt + recipientNetAbt + referrerAbt + protocolFeeAbt + spamSinkAbt !== stamp.stampAmountAbt) throw new _ocap_util_lib_error.CustomError(ErrorCode.ConservationViolation, "AttentionStamp resolution violated ABT conservation");
|
|
1209
1209
|
const postConditions = {
|
|
1210
1210
|
signer: stampId,
|
|
1211
|
-
maxTokenOutflow: { [DEFAULT_ABT_TOKEN_ADDRESS]: stamp.stampAmountAbt.toString(10) },
|
|
1211
|
+
maxTokenOutflow: { [stampId]: { [DEFAULT_ABT_TOKEN_ADDRESS]: stamp.stampAmountAbt.toString(10) } },
|
|
1212
1212
|
strictZeroUnlistedOutflow: true
|
|
1213
1213
|
};
|
|
1214
1214
|
return {
|