@ocap/tx-pipeline 1.31.0 → 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-itx.mjs +3 -0
- package/esm/pipes/decode-tx.mjs +32 -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 +58 -2
- package/esm/pipes/pre-flight-waf.mjs +202 -14
- 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.cjs +3 -0
- package/lib/pipes/decode-itx.d.cts +1 -1
- package/lib/pipes/decode-tx.cjs +31 -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 +209 -15
- package/lib/pipes/pre-flight-waf.d.cts +58 -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,11 +1,11 @@
|
|
|
1
|
-
import { assertEnvelopeMatchesTxContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra } from "../helpers/replay-guard.mjs";
|
|
1
|
+
import { assertEnvelopeMatchesTxContext, getBridgeWithdrawEnvelopeContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra } from "../helpers/replay-guard.mjs";
|
|
2
2
|
import { encodeTxByEncoding } from "../helpers/encode-tx-by-context.mjs";
|
|
3
|
-
import { types } from "@ocap/mcrypto";
|
|
3
|
+
import { toTxHash, types } from "@ocap/mcrypto";
|
|
4
4
|
import { CustomError } from "@ocap/util/lib/error";
|
|
5
|
-
import
|
|
5
|
+
import { isFromPublicKey, normalizePublicKeyHex, toTypeInfo } from "@arcblock/did";
|
|
6
6
|
import { deleteListField, getListField } from "@ocap/util/lib/get-list-field";
|
|
7
|
+
import get from "lodash/get.js";
|
|
7
8
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
8
|
-
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
9
9
|
import { fromPublicKey } from "@ocap/wallet";
|
|
10
10
|
|
|
11
11
|
//#region src/pipes/verify-signature.ts
|
|
@@ -14,6 +14,94 @@ const V1_MULTISIG_TX_TYPES = new Set([
|
|
|
14
14
|
"fg:t:exchange_v2",
|
|
15
15
|
"fg:t:account_migrate"
|
|
16
16
|
]);
|
|
17
|
+
const ALLOWED_COSIG_KEYS = new Set([
|
|
18
|
+
"pk",
|
|
19
|
+
"signature",
|
|
20
|
+
"extra"
|
|
21
|
+
]);
|
|
22
|
+
const ALLOWED_PASSKEY_COSIG_EXTRA_KEYS = new Set(["authenticatorData", "clientDataJSON"]);
|
|
23
|
+
const MAX_CO_SIGNATURE_TX_EXTRA_CHARS = 4096;
|
|
24
|
+
const MAX_CO_SIGNATURE_PASSKEY_EXTRA_CHARS = 2048;
|
|
25
|
+
function isCanonicalPasskeyCoSigExtra(extra) {
|
|
26
|
+
if (typeof extra !== "string" || extra.length === 0 || extra.length > MAX_CO_SIGNATURE_PASSKEY_EXTRA_CHARS || !isCanonicalPasskeyExtra(extra)) return false;
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(extra);
|
|
29
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || JSON.stringify(parsed) !== extra) return false;
|
|
30
|
+
if (Object.keys(parsed).some((k) => !ALLOWED_PASSKEY_COSIG_EXTRA_KEYS.has(k))) return false;
|
|
31
|
+
return true;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function parseCanonicalCoSignatureTxExtra(rawTxExtra) {
|
|
37
|
+
try {
|
|
38
|
+
let parsed = null;
|
|
39
|
+
if (typeof rawTxExtra === "string") {
|
|
40
|
+
if (rawTxExtra.length > MAX_CO_SIGNATURE_TX_EXTRA_CHARS || !rawTxExtra.startsWith("{")) return null;
|
|
41
|
+
parsed = JSON.parse(rawTxExtra);
|
|
42
|
+
if (JSON.stringify(parsed) !== rawTxExtra) return null;
|
|
43
|
+
} else if (rawTxExtra && typeof rawTxExtra === "object" && !Array.isArray(rawTxExtra)) {
|
|
44
|
+
const serialized = JSON.stringify(rawTxExtra);
|
|
45
|
+
if (!serialized || serialized.length > MAX_CO_SIGNATURE_TX_EXTRA_CHARS) return null;
|
|
46
|
+
parsed = rawTxExtra;
|
|
47
|
+
} else return null;
|
|
48
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
49
|
+
const topKeys = Object.keys(parsed);
|
|
50
|
+
if (topKeys.length !== 1 || topKeys[0] !== "coSignature") return null;
|
|
51
|
+
const coSig = parsed.coSignature;
|
|
52
|
+
if (!coSig || typeof coSig !== "object" || Array.isArray(coSig)) return null;
|
|
53
|
+
const coSigKeys = Object.keys(coSig);
|
|
54
|
+
if (coSigKeys.length < 2 || coSigKeys.length > 3 || coSigKeys.some((k) => !ALLOWED_COSIG_KEYS.has(k))) return null;
|
|
55
|
+
const { pk, signature, extra } = coSig;
|
|
56
|
+
if (typeof pk !== "string" || pk.trim().length === 0 || pk.length > 256) return null;
|
|
57
|
+
if (typeof signature !== "string" || signature.trim().length === 0 || signature.length > 512) return null;
|
|
58
|
+
if (extra !== void 0 && extra !== "") {
|
|
59
|
+
if (typeof extra !== "string" || !isCanonicalPasskeyCoSigExtra(extra)) return null;
|
|
60
|
+
return {
|
|
61
|
+
pk,
|
|
62
|
+
signature,
|
|
63
|
+
extra
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
pk,
|
|
68
|
+
signature
|
|
69
|
+
};
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function verifyStatelessCoSignature(coSig, candidates, candidatePayloads) {
|
|
75
|
+
if (candidates.length === 0 || candidatePayloads.length === 0) return false;
|
|
76
|
+
const coSigPkHex = normalizePublicKeyHex(coSig.pk);
|
|
77
|
+
if (!coSigPkHex) return false;
|
|
78
|
+
for (const { ownerAddr, delegateePk } of candidates) {
|
|
79
|
+
if (!ownerAddr) continue;
|
|
80
|
+
const forbiddenPkHex = delegateePk ? normalizePublicKeyHex(delegateePk) : "";
|
|
81
|
+
if (forbiddenPkHex && coSigPkHex === forbiddenPkHex) continue;
|
|
82
|
+
if (!isFromPublicKey(ownerAddr, coSig.pk)) continue;
|
|
83
|
+
const ownerType = toTypeInfo(ownerAddr);
|
|
84
|
+
const isOwnerPasskey = ownerType.role === types.RoleType.ROLE_PASSKEY || ownerType.pk === types.KeyType.PASSKEY;
|
|
85
|
+
const coSigExtra = coSig.extra || "";
|
|
86
|
+
if (isOwnerPasskey && !coSigExtra) continue;
|
|
87
|
+
if (!isOwnerPasskey && coSigExtra) continue;
|
|
88
|
+
let wallet;
|
|
89
|
+
try {
|
|
90
|
+
wallet = fromPublicKey(coSig.pk, ownerType);
|
|
91
|
+
} catch {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
for (const payload of candidatePayloads) {
|
|
95
|
+
try {
|
|
96
|
+
if (await wallet.verify(payload, coSig.signature, false, coSigExtra)) return true;
|
|
97
|
+
} catch {}
|
|
98
|
+
try {
|
|
99
|
+
if (await wallet.verify(payload, coSig.signature, true, coSigExtra)) return true;
|
|
100
|
+
} catch {}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
17
105
|
async function VerifySignature(context, next) {
|
|
18
106
|
const tx = cloneDeep(context.tx);
|
|
19
107
|
const { signature } = tx;
|
|
@@ -35,22 +123,36 @@ async function VerifySignature(context, next) {
|
|
|
35
123
|
const type = toTypeInfo(signer);
|
|
36
124
|
const wallet = fromPublicKey(pk, type);
|
|
37
125
|
const rawTxExtra = get(context, "extra.txExtra");
|
|
126
|
+
const rawDirectCoSig = get(context, "extra.coSignature");
|
|
127
|
+
const hasDirectCoSig = rawDirectCoSig !== void 0 && rawDirectCoSig !== null;
|
|
38
128
|
const isPasskey = type.role === types.RoleType.ROLE_PASSKEY || type.pk === types.KeyType.PASSKEY;
|
|
39
129
|
if (isPasskey && (typeof rawTxExtra !== "string" || !isCanonicalPasskeyExtra(rawTxExtra))) return next(new CustomError("INVALID_SIGNATURE", "Non-canonical extra data for passkey signer"));
|
|
40
130
|
const isWalletEnvelope = !isPasskey && typeof rawTxExtra === "string" && isCanonicalWalletEnvelopeExtra(rawTxExtra, type.pk);
|
|
41
|
-
if (!isPasskey && !isWalletEnvelope && rawTxExtra) {
|
|
131
|
+
if (!isPasskey && !isWalletEnvelope && rawTxExtra || hasDirectCoSig) {
|
|
42
132
|
const v1Sigs = getListField(context.tx, "signatures");
|
|
43
133
|
const v1Counterparty = v1Sigs[0]?.delegator || v1Sigs[0]?.signer;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
134
|
+
if (!Boolean(!hasDirectCoSig && 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))) {
|
|
135
|
+
const hasDelegator = Boolean(tx.delegator) || v1Sigs.some((s) => Boolean(s?.delegator));
|
|
136
|
+
const parsedFromTxExtra = !isPasskey && !isWalletEnvelope && rawTxExtra ? parseCanonicalCoSignatureTxExtra(rawTxExtra) : null;
|
|
137
|
+
const parsedFromDirect = hasDirectCoSig ? parseCanonicalCoSignatureTxExtra({ coSignature: rawDirectCoSig }) : null;
|
|
138
|
+
if (hasDirectCoSig && !parsedFromDirect) return next(new CustomError("INVALID_SIGNATURE", "Invalid owner coSignature"));
|
|
139
|
+
if (!isPasskey && !isWalletEnvelope && rawTxExtra && !parsedFromTxExtra) return next(new CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${signer}`));
|
|
140
|
+
if (parsedFromTxExtra && parsedFromDirect && (parsedFromTxExtra.pk !== parsedFromDirect.pk || parsedFromTxExtra.signature !== parsedFromDirect.signature || (parsedFromTxExtra.extra || "") !== (parsedFromDirect.extra || ""))) return next(new CustomError("INVALID_SIGNATURE", "Conflicting owner coSignature inputs"));
|
|
141
|
+
const parsedCoSig = parsedFromTxExtra || parsedFromDirect;
|
|
142
|
+
if (!hasDelegator || !parsedCoSig) return next(new CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${signer}`));
|
|
143
|
+
const coSigCandidates = [];
|
|
144
|
+
if (tx.delegator && tx.from) coSigCandidates.push({
|
|
145
|
+
ownerAddr: tx.from,
|
|
146
|
+
delegateePk: tx.pk
|
|
147
|
+
});
|
|
148
|
+
for (const s of v1Sigs) if (s?.delegator && s?.signer) coSigCandidates.push({
|
|
149
|
+
ownerAddr: s.signer,
|
|
150
|
+
delegateePk: s.pk
|
|
151
|
+
});
|
|
152
|
+
const ctxTxHash = context.txHash;
|
|
153
|
+
const ctxUnsignedTxHash = context.unsignedTxHash || toTxHash(txBytes);
|
|
154
|
+
if (!await verifyStatelessCoSignature(parsedCoSig, coSigCandidates, Array.from(new Set([ctxTxHash, ctxUnsignedTxHash].filter((x) => typeof x === "string" && x.length > 0))))) return next(new CustomError("INVALID_SIGNATURE", "Invalid owner coSignature"));
|
|
52
155
|
}
|
|
53
|
-
if (!isV1CounterpartyPasskey && !isTier3CoSignatureExtra) return next(new CustomError("INVALID_SIGNATURE", `Unexpected extra data for non-passkey signer ${signer}`));
|
|
54
156
|
}
|
|
55
157
|
const extra = isPasskey ? rawTxExtra : isWalletEnvelope ? rawTxExtra : "";
|
|
56
158
|
try {
|
|
@@ -59,7 +161,8 @@ async function VerifySignature(context, next) {
|
|
|
59
161
|
signer,
|
|
60
162
|
from: tx.from,
|
|
61
163
|
nonce: tx.nonce,
|
|
62
|
-
action: txType
|
|
164
|
+
action: txType,
|
|
165
|
+
withdraw: await getBridgeWithdrawEnvelopeContext(context)
|
|
63
166
|
});
|
|
64
167
|
if (!signature || await wallet.verify(txBytes, signature, true, extra || "") === false) return next(new CustomError("INVALID_SIGNATURE", "tx.signature is invalid"));
|
|
65
168
|
} catch (err) {
|
|
@@ -71,4 +174,4 @@ async function VerifySignature(context, next) {
|
|
|
71
174
|
}
|
|
72
175
|
|
|
73
176
|
//#endregion
|
|
74
|
-
export { VerifySignature as default };
|
|
177
|
+
export { VerifySignature as default, parseCanonicalCoSignatureTxExtra };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { name } from "../package.mjs";
|
|
2
2
|
import { types } from "@ocap/mcrypto";
|
|
3
3
|
import { CustomError } from "@ocap/util/lib/error";
|
|
4
|
-
import
|
|
4
|
+
import { toTypeInfo } from "@arcblock/did";
|
|
5
5
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
6
|
+
import get from "lodash/get.js";
|
|
6
7
|
import Debug from "debug";
|
|
7
|
-
import { toTypeInfo } from "@arcblock/did";
|
|
8
8
|
|
|
9
9
|
//#region src/pipes/verify-signer.ts
|
|
10
10
|
const debug = Debug(`${name}:pipe:verify-signer`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toAddress } from "@ocap/util";
|
|
2
2
|
import { CustomError } from "@ocap/util/lib/error";
|
|
3
|
-
import get from "lodash/get.js";
|
|
4
3
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
4
|
+
import get from "lodash/get.js";
|
|
5
5
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
6
6
|
import isEmpty from "lodash/isEmpty.js";
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BN, isSameDid } from "@ocap/util";
|
|
2
2
|
import { CustomError } from "@ocap/util/lib/error";
|
|
3
|
-
import get from "lodash/get.js";
|
|
4
3
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
4
|
+
import get from "lodash/get.js";
|
|
5
5
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
6
6
|
import isEmpty from "lodash/isEmpty.js";
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BN } from "@ocap/util";
|
|
2
2
|
import { CustomError } from "@ocap/util/lib/error";
|
|
3
|
-
import get from "lodash/get.js";
|
|
4
3
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
4
|
+
import get from "lodash/get.js";
|
|
5
5
|
import isEmpty from "lodash/isEmpty.js";
|
|
6
6
|
import { createSortedList } from "@ocap/util/lib/create-sorted-list";
|
|
7
7
|
|
package/esm/pipes/verify-tx.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { parseNonceBn } from "../helpers/replay-guard.mjs";
|
|
1
|
+
import { parseNonceBn as parseNonceBn$1 } from "../helpers/replay-guard.mjs";
|
|
2
2
|
import { types } from "@ocap/mcrypto";
|
|
3
3
|
import { BN } from "@ocap/util";
|
|
4
4
|
import { CustomError } from "@ocap/util/lib/error";
|
|
5
|
-
import
|
|
5
|
+
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
6
|
+
import { account } from "@ocap/state";
|
|
6
7
|
import { toTypeUrl } from "@ocap/message";
|
|
7
8
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
8
|
-
import
|
|
9
|
+
import get from "lodash/get.js";
|
|
9
10
|
import isEmpty from "lodash/isEmpty.js";
|
|
10
11
|
|
|
11
12
|
//#region src/pipes/verify-tx.ts
|
|
@@ -20,11 +21,17 @@ async function VerifyTx(context, next) {
|
|
|
20
21
|
const { itx, chainId, nonce, pk, from, delegator } = context.tx;
|
|
21
22
|
const expected = get(context, "config.chainId");
|
|
22
23
|
if (chainId !== expected) return next(new CustomError("INVALID_CHAIN_ID", `Invalid chain id: expected ${expected}, got ${chainId}`));
|
|
23
|
-
const nonceBn = parseNonceBn(nonce);
|
|
24
|
+
const nonceBn = parseNonceBn$1(nonce);
|
|
24
25
|
if (!nonceBn || nonceBn.lte(new BN(0))) return next(new CustomError("INVALID_NONCE", "tx.nonce should be a positive integer"));
|
|
25
|
-
const { supportedTxs, maxMultisig } = get(context, "config.transaction");
|
|
26
26
|
const rawItx = itx;
|
|
27
27
|
const itxTypeUrl = rawItx.typeUrl || (rawItx.type ? toTypeUrl(rawItx.type) : void 0);
|
|
28
|
+
const isExchangeV2 = itxTypeUrl === "fg:t:exchange_v2" || context.txType === "fg:t:exchange_v2";
|
|
29
|
+
if (!isEmpty(delegator) || isExchangeV2) {
|
|
30
|
+
const txTimeMs = context.txTime ? new Date(context.txTime).getTime() : NaN;
|
|
31
|
+
const maxNonce = (Number.isFinite(txTimeMs) ? txTimeMs : Date.now()) + account.DELEGATED_NONCE_MAX_FUTURE_MS;
|
|
32
|
+
if (nonceBn.gt(new BN(String(maxNonce), 10))) return next(new CustomError("INVALID_NONCE", `tx.nonce of a ${!isEmpty(delegator) ? "delegated" : "exchange_v2"} tx should not exceed the tx time in milliseconds plus 24 hours (max ${maxNonce}, got ${nonceBn.toString(10)})`));
|
|
33
|
+
}
|
|
34
|
+
const { supportedTxs, maxMultisig } = get(context, "config.transaction");
|
|
28
35
|
if (!itxTypeUrl || supportedTxs.includes(itxTypeUrl) === false) return next(new CustomError("UNSUPPORTED_TX", `Transaction ${itxTypeUrl} is not supported`));
|
|
29
36
|
if (getListField(context, "tx.signatures").length > maxMultisig) return next(new CustomError("INVALID_TX", "Too many multisig signatures"));
|
|
30
37
|
if (toTypeInfo(from).role === types.RoleType.ROLE_ASSET && isEmpty(delegator)) return next(new CustomError("INVALID_TX", "Asset sender requires a delegator"));
|
|
@@ -253,7 +253,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
253
253
|
}];
|
|
254
254
|
const postConditions = {
|
|
255
255
|
signer: pool.poolDid,
|
|
256
|
-
maxTokenOutflow: { [pool.tokenAddress]: redeemAmountAbt.toString(10) },
|
|
256
|
+
maxTokenOutflow: { [pool.poolDid]: { [pool.tokenAddress]: redeemAmountAbt.toString(10) } },
|
|
257
257
|
strictZeroUnlistedOutflow: true
|
|
258
258
|
};
|
|
259
259
|
return {
|
|
@@ -471,7 +471,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
471
471
|
pushSplitTransfer(org.creatorDid, creatorNetAbt, "CREATOR_NET_REVENUE");
|
|
472
472
|
const postConditions = {
|
|
473
473
|
signer: payerDid,
|
|
474
|
-
maxTokenOutflow: { [org.tokenAddress]: ticketPriceAbt.toString(10) },
|
|
474
|
+
maxTokenOutflow: { [payerDid]: { [org.tokenAddress]: ticketPriceAbt.toString(10) } },
|
|
475
475
|
strictZeroUnlistedOutflow: true
|
|
476
476
|
};
|
|
477
477
|
return {
|
|
@@ -668,7 +668,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
668
668
|
pushSplit(machineDid, poolCAddedAbt, "C_CONSERVATION_PRIZE_POOL");
|
|
669
669
|
const postConditions = {
|
|
670
670
|
signer: payerDid,
|
|
671
|
-
maxTokenOutflow: { [machine.tokenAddress]: A.toString(10) },
|
|
671
|
+
maxTokenOutflow: { [payerDid]: { [machine.tokenAddress]: A.toString(10) } },
|
|
672
672
|
strictZeroUnlistedOutflow: true
|
|
673
673
|
};
|
|
674
674
|
return {
|
|
@@ -773,7 +773,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
773
773
|
}));
|
|
774
774
|
const postConditions = {
|
|
775
775
|
signer: machineDid,
|
|
776
|
-
maxTokenOutflow: { [machine.tokenAddress]: totalPayoutAbt.toString(10) },
|
|
776
|
+
maxTokenOutflow: { [machineDid]: { [machine.tokenAddress]: totalPayoutAbt.toString(10) } },
|
|
777
777
|
strictZeroUnlistedOutflow: true
|
|
778
778
|
};
|
|
779
779
|
return {
|
|
@@ -944,7 +944,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
944
944
|
});
|
|
945
945
|
const postConditions = {
|
|
946
946
|
signer: offer.buyerDid,
|
|
947
|
-
maxTokenOutflow: { [DEFAULT_ABT_TOKEN_ADDRESS]: grossOfferAbt.toString(10) },
|
|
947
|
+
maxTokenOutflow: { [offer.buyerDid]: { [DEFAULT_ABT_TOKEN_ADDRESS]: grossOfferAbt.toString(10) } },
|
|
948
948
|
mustOwnAssetsAfter: { [offer.buyerDid]: [sticker.stickerDid] },
|
|
949
949
|
strictZeroUnlistedOutflow: true
|
|
950
950
|
};
|
|
@@ -1207,7 +1207,7 @@ var OcapSuperSuitesFoundationEngine = class {
|
|
|
1207
1207
|
if (senderRefundAbt + recipientNetAbt + referrerAbt + protocolFeeAbt + spamSinkAbt !== stamp.stampAmountAbt) throw new CustomError(ErrorCode.ConservationViolation, "AttentionStamp resolution violated ABT conservation");
|
|
1208
1208
|
const postConditions = {
|
|
1209
1209
|
signer: stampId,
|
|
1210
|
-
maxTokenOutflow: { [DEFAULT_ABT_TOKEN_ADDRESS]: stamp.stampAmountAbt.toString(10) },
|
|
1210
|
+
maxTokenOutflow: { [stampId]: { [DEFAULT_ABT_TOKEN_ADDRESS]: stamp.stampAmountAbt.toString(10) } },
|
|
1211
1211
|
strictZeroUnlistedOutflow: true
|
|
1212
1212
|
};
|
|
1213
1213
|
return {
|
|
@@ -21,6 +21,8 @@ interface TransactionBlockResourceBudget {
|
|
|
21
21
|
maxExecuteAssetCallsPerBlock?: number;
|
|
22
22
|
}
|
|
23
23
|
interface TransactionBlockPostConditions {
|
|
24
|
+
/** Optional signer/account DID associated with this PostCondition envelope */
|
|
25
|
+
signer?: string;
|
|
24
26
|
/**
|
|
25
27
|
* Maximum allowed net token outflow per account DID and token address:
|
|
26
28
|
* `{ [accountDid]: { [tokenAddress]: "100" } }`
|
|
@@ -173,6 +175,7 @@ declare class OverlayStateDB {
|
|
|
173
175
|
private readonly base;
|
|
174
176
|
private writes;
|
|
175
177
|
private reads;
|
|
178
|
+
private balanceReadsByAddress;
|
|
176
179
|
private runtimeIoBudget;
|
|
177
180
|
private savepoints;
|
|
178
181
|
[key: string]: any;
|
|
@@ -187,9 +190,10 @@ declare class OverlayStateDB {
|
|
|
187
190
|
private getTableReads;
|
|
188
191
|
private assertLiveReadBudget;
|
|
189
192
|
private assertLiveWriteBudget;
|
|
193
|
+
private normalizeTableKey;
|
|
190
194
|
private readBase;
|
|
191
|
-
getBaseSnapshot(table: string, rawKey:
|
|
192
|
-
hasTableWrite(table: string, rawKey:
|
|
195
|
+
getBaseSnapshot(table: string, rawKey: unknown, ctx?: unknown): Promise<any>;
|
|
196
|
+
hasTableWrite(table: string, rawKey: unknown): boolean;
|
|
193
197
|
private createTableProxy;
|
|
194
198
|
createSavepoint(): number;
|
|
195
199
|
rollbackToSavepoint(savepointId: number): void;
|