@ocap/tx-pipeline 1.31.0 → 1.31.1
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/pipes/decode-itx.mjs +3 -0
- package/esm/pipes/decode-tx.mjs +3 -0
- package/esm/pipes/pre-flight-waf.d.mts +41 -2
- package/esm/pipes/pre-flight-waf.mjs +155 -2
- package/lib/pipes/decode-itx.cjs +3 -0
- package/lib/pipes/decode-tx.cjs +3 -0
- package/lib/pipes/pre-flight-waf.cjs +158 -2
- package/lib/pipes/pre-flight-waf.d.cts +41 -2
- package/package.json +10 -10
package/esm/pipes/decode-itx.mjs
CHANGED
|
@@ -85,6 +85,9 @@ function normalizeItx(raw) {
|
|
|
85
85
|
}
|
|
86
86
|
function DecodeItx(context, next) {
|
|
87
87
|
try {
|
|
88
|
+
context._preFlightWafScanned = false;
|
|
89
|
+
context._preFlightVerified = false;
|
|
90
|
+
context._preFlightSnapshotApplied = false;
|
|
88
91
|
context._rawTxItxBeforeNormalize = context.tx?.itx;
|
|
89
92
|
const normalized = normalizeItx(context.tx.itx);
|
|
90
93
|
if (!normalized) return next(new CustomError("INVALID_TX", "Failed to decode itx"));
|
package/esm/pipes/decode-tx.mjs
CHANGED
|
@@ -109,6 +109,9 @@ function DecodeTx(context, next) {
|
|
|
109
109
|
writable: true
|
|
110
110
|
});
|
|
111
111
|
context._extraSizeCounted = false;
|
|
112
|
+
context._preFlightWafScanned = false;
|
|
113
|
+
context._preFlightVerified = false;
|
|
114
|
+
context._preFlightSnapshotApplied = false;
|
|
112
115
|
Object.defineProperty(context, "txHash", {
|
|
113
116
|
value: toTxHash(txBuffer),
|
|
114
117
|
enumerable: true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomError } from "@ocap/util/lib/error";
|
|
2
|
-
import { IBaseContext, IChainConfig, IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { IBaseContext, IChainConfig, IDecodedContext, IDecodedTransaction } from "@ocap/types";
|
|
3
3
|
|
|
4
4
|
//#region src/pipes/pre-flight-waf.d.ts
|
|
5
5
|
declare const MAX_PREFLIGHT_JSON_DEPTH = 16;
|
|
@@ -25,10 +25,49 @@ declare function scanItxPayloadAnomalies(itx: unknown, txType: string | undefine
|
|
|
25
25
|
* Pipeline pipe that runs the Pre-Flight WAF structural & anomaly checks.
|
|
26
26
|
*/
|
|
27
27
|
declare function PreFlightWaf(context: IDecodedContext, next: (err?: CustomError) => void): void;
|
|
28
|
+
declare namespace PreFlightWaf {
|
|
29
|
+
var SNAPSHOT_SYMBOL: typeof PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL;
|
|
30
|
+
var tryApplyVerifiedSnapshot: typeof tryApplyPreFlightVerifiedSnapshot;
|
|
31
|
+
}
|
|
32
|
+
declare const PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL: unique symbol;
|
|
33
|
+
interface IPreFlightVerifiedSnapshot {
|
|
34
|
+
txBase64: string;
|
|
35
|
+
configRef: IChainConfig | undefined;
|
|
36
|
+
chainId: unknown;
|
|
37
|
+
tokenDecimal: unknown;
|
|
38
|
+
txFeeForType: unknown;
|
|
39
|
+
maxTxSizeForType: unknown;
|
|
40
|
+
maxExtraSize: unknown;
|
|
41
|
+
maxMultisig: unknown;
|
|
42
|
+
maxListSize: unknown;
|
|
43
|
+
maxAssetSize: unknown;
|
|
44
|
+
isSupportedTx: boolean;
|
|
45
|
+
isMultiSignV2Tx: boolean;
|
|
46
|
+
txExtraSerialized: string;
|
|
47
|
+
gasStakeHeadersSerialized: string;
|
|
48
|
+
coSignatureSerialized: string;
|
|
49
|
+
tx: IDecodedTransaction;
|
|
50
|
+
txEncoding: 'cbor' | 'protobuf';
|
|
51
|
+
txSize: number;
|
|
52
|
+
baseTxSize: number;
|
|
53
|
+
extraSizeCounted: boolean;
|
|
54
|
+
txHash: string;
|
|
55
|
+
unsignedTxHash: string;
|
|
56
|
+
txBaseGas: boolean;
|
|
57
|
+
itx: Record<string, unknown>;
|
|
58
|
+
txType: string;
|
|
59
|
+
rawTxItxBeforeNormalize: unknown;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Apply the verified pre-flight snapshot onto `context` if and only if all verified inputs
|
|
63
|
+
* (`txBase64`, `config` invariants, and `extra.{txExtra,gasStakeHeaders,coSignature}`) are
|
|
64
|
+
* unchanged since `inspectTransactionPreFlight(context)` succeeded.
|
|
65
|
+
*/
|
|
66
|
+
declare function tryApplyPreFlightVerifiedSnapshot(context: IBaseContext): boolean;
|
|
28
67
|
/**
|
|
29
68
|
* Stateless, zero-DB-I/O Pre-Flight inspection runner for `OCAPResolver.sendTx`
|
|
30
69
|
* BEFORE enqueuing into the single-writer queue (`this.queue`) or acquiring the SQLite write lock.
|
|
31
70
|
*/
|
|
32
71
|
declare function inspectTransactionPreFlight(context: IBaseContext): Promise<IDecodedContext>;
|
|
33
72
|
//#endregion
|
|
34
|
-
export { MAX_DELEGATE_TYPE_URLS_LIST_SIZE, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, MAX_PREFLIGHT_STRING_FIELD_BYTES, MAX_PREFLIGHT_WIRE_BYTES_FALLBACK, MAX_ROLLUP_TXS_LIST_SIZE, assertKnownItxFields, assertRawWireEnvelope, PreFlightWaf as default, inspectTransactionPreFlight, scanItxPayloadAnomalies };
|
|
73
|
+
export { IPreFlightVerifiedSnapshot, MAX_DELEGATE_TYPE_URLS_LIST_SIZE, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, MAX_PREFLIGHT_STRING_FIELD_BYTES, MAX_PREFLIGHT_WIRE_BYTES_FALLBACK, MAX_ROLLUP_TXS_LIST_SIZE, PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL, assertKnownItxFields, assertRawWireEnvelope, PreFlightWaf as default, inspectTransactionPreFlight, scanItxPayloadAnomalies, tryApplyPreFlightVerifiedSnapshot };
|
|
@@ -11,6 +11,7 @@ import { CustomError } from "@ocap/util/lib/error";
|
|
|
11
11
|
import get from "lodash/get.js";
|
|
12
12
|
import { createMessage, decodeAny, encodeAny, fromTypeUrl, toTypeUrl } from "@ocap/message";
|
|
13
13
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
14
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
14
15
|
|
|
15
16
|
//#region src/pipes/pre-flight-waf.ts
|
|
16
17
|
const MAX_PREFLIGHT_JSON_DEPTH = 16;
|
|
@@ -532,6 +533,110 @@ function PreFlightWaf(context, next) {
|
|
|
532
533
|
return next(err);
|
|
533
534
|
}
|
|
534
535
|
}
|
|
536
|
+
const PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL = Symbol.for("@ocap/tx-pipeline/preFlightVerifiedSnapshot");
|
|
537
|
+
function serializeExtraField(val) {
|
|
538
|
+
if (val === void 0) return "u";
|
|
539
|
+
if (val === null) return "n";
|
|
540
|
+
if (typeof val === "string") return `s:${val}`;
|
|
541
|
+
try {
|
|
542
|
+
return `j:${JSON.stringify(val)}`;
|
|
543
|
+
} catch {
|
|
544
|
+
return "invalid";
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Apply the verified pre-flight snapshot onto `context` if and only if all verified inputs
|
|
549
|
+
* (`txBase64`, `config` invariants, and `extra.{txExtra,gasStakeHeaders,coSignature}`) are
|
|
550
|
+
* unchanged since `inspectTransactionPreFlight(context)` succeeded.
|
|
551
|
+
*/
|
|
552
|
+
function tryApplyPreFlightVerifiedSnapshot(context) {
|
|
553
|
+
context._preFlightWafScanned = false;
|
|
554
|
+
context._preFlightVerified = false;
|
|
555
|
+
context._preFlightSnapshotApplied = false;
|
|
556
|
+
const snap = context[PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL];
|
|
557
|
+
if (!snap || typeof context.txBase64 !== "string" || snap.txBase64 !== context.txBase64) return false;
|
|
558
|
+
const config = context.config;
|
|
559
|
+
if (snap.configRef !== config) return false;
|
|
560
|
+
const supportedTxs = get(config, "transaction.supportedTxs");
|
|
561
|
+
const multiSignV2Txs = get(config, "transaction.multiSignV2Txs");
|
|
562
|
+
const defaultSizeLimit = get(config, "transaction.maxTxSize.default");
|
|
563
|
+
if (snap.chainId !== get(config, "chainId") || snap.tokenDecimal !== get(config, "token.decimal") || snap.txFeeForType !== (snap.txType ? get(config, [
|
|
564
|
+
"transaction",
|
|
565
|
+
"txFee",
|
|
566
|
+
snap.txType
|
|
567
|
+
]) : void 0) || snap.maxTxSizeForType !== (snap.txType ? get(config, [
|
|
568
|
+
"transaction",
|
|
569
|
+
"maxTxSize",
|
|
570
|
+
snap.txType
|
|
571
|
+
], defaultSizeLimit) : defaultSizeLimit) || snap.maxExtraSize !== get(config, "transaction.maxExtraSize") || snap.maxMultisig !== get(config, "transaction.maxMultisig") || snap.maxListSize !== get(config, "transaction.maxListSize") || snap.maxAssetSize !== get(config, "transaction.maxAssetSize") || snap.isSupportedTx !== Boolean(Array.isArray(supportedTxs) && supportedTxs.includes(snap.txType)) || snap.isMultiSignV2Tx !== Boolean(Array.isArray(multiSignV2Txs) && multiSignV2Txs.includes(snap.txType))) return false;
|
|
572
|
+
const extra = context.extra;
|
|
573
|
+
if (snap.txExtraSerialized !== serializeExtraField(extra?.txExtra) || snap.gasStakeHeadersSerialized !== serializeExtraField(extra?.gasStakeHeaders) || snap.coSignatureSerialized !== serializeExtraField(extra?.coSignature)) return false;
|
|
574
|
+
const pinned = extra?.txTime;
|
|
575
|
+
const pinnedMs = pinned === void 0 || pinned === null || pinned === "" ? NaN : new Date(pinned).getTime();
|
|
576
|
+
const resolvedTxTime = Number.isFinite(pinnedMs) ? new Date(pinnedMs).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
577
|
+
Object.defineProperty(context, "tx", {
|
|
578
|
+
value: cloneDeep(snap.tx),
|
|
579
|
+
enumerable: true,
|
|
580
|
+
configurable: true,
|
|
581
|
+
writable: true
|
|
582
|
+
});
|
|
583
|
+
Object.defineProperty(context, "txEncoding", {
|
|
584
|
+
value: snap.txEncoding,
|
|
585
|
+
enumerable: true,
|
|
586
|
+
configurable: true,
|
|
587
|
+
writable: true
|
|
588
|
+
});
|
|
589
|
+
Object.defineProperty(context, "txSize", {
|
|
590
|
+
value: snap.txSize,
|
|
591
|
+
enumerable: true,
|
|
592
|
+
configurable: true,
|
|
593
|
+
writable: true
|
|
594
|
+
});
|
|
595
|
+
Object.defineProperty(context, "txHash", {
|
|
596
|
+
value: snap.txHash,
|
|
597
|
+
enumerable: true,
|
|
598
|
+
configurable: true,
|
|
599
|
+
writable: true
|
|
600
|
+
});
|
|
601
|
+
Object.defineProperty(context, "unsignedTxHash", {
|
|
602
|
+
value: snap.unsignedTxHash,
|
|
603
|
+
enumerable: true,
|
|
604
|
+
configurable: true,
|
|
605
|
+
writable: true
|
|
606
|
+
});
|
|
607
|
+
Object.defineProperty(context, "txTime", {
|
|
608
|
+
value: resolvedTxTime,
|
|
609
|
+
enumerable: true,
|
|
610
|
+
configurable: true,
|
|
611
|
+
writable: true
|
|
612
|
+
});
|
|
613
|
+
Object.defineProperty(context, "txBaseGas", {
|
|
614
|
+
value: snap.txBaseGas,
|
|
615
|
+
enumerable: true,
|
|
616
|
+
configurable: true,
|
|
617
|
+
writable: true
|
|
618
|
+
});
|
|
619
|
+
Object.defineProperty(context, "itx", {
|
|
620
|
+
value: cloneDeep(snap.itx),
|
|
621
|
+
enumerable: true,
|
|
622
|
+
configurable: true,
|
|
623
|
+
writable: true
|
|
624
|
+
});
|
|
625
|
+
Object.defineProperty(context, "txType", {
|
|
626
|
+
value: snap.txType,
|
|
627
|
+
enumerable: true,
|
|
628
|
+
configurable: true,
|
|
629
|
+
writable: true
|
|
630
|
+
});
|
|
631
|
+
context._baseTxSize = snap.baseTxSize;
|
|
632
|
+
context._extraSizeCounted = snap.extraSizeCounted;
|
|
633
|
+
context._rawTxItxBeforeNormalize = snap.rawTxItxBeforeNormalize;
|
|
634
|
+
context._preFlightWafScanned = true;
|
|
635
|
+
context._preFlightVerified = true;
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
638
|
+
PreFlightWaf.SNAPSHOT_SYMBOL = PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL;
|
|
639
|
+
PreFlightWaf.tryApplyVerifiedSnapshot = tryApplyPreFlightVerifiedSnapshot;
|
|
535
640
|
/**
|
|
536
641
|
* Stateless, zero-DB-I/O Pre-Flight inspection runner for `OCAPResolver.sendTx`
|
|
537
642
|
* BEFORE enqueuing into the single-writer queue (`this.queue`) or acquiring the SQLite write lock.
|
|
@@ -591,13 +696,61 @@ async function inspectTransactionPreFlight(context) {
|
|
|
591
696
|
configurable: true,
|
|
592
697
|
writable: true
|
|
593
698
|
});
|
|
594
|
-
|
|
699
|
+
const baseTxSize = preFlightCtx._baseTxSize ?? preFlightCtx.txSize;
|
|
700
|
+
const extraSizeCounted = Boolean(preFlightCtx._extraSizeCounted);
|
|
701
|
+
const rawTxItxBeforeNormalize = preFlightCtx._rawTxItxBeforeNormalize;
|
|
702
|
+
context._baseTxSize = baseTxSize;
|
|
703
|
+
context._extraSizeCounted = extraSizeCounted;
|
|
704
|
+
context._rawTxItxBeforeNormalize = rawTxItxBeforeNormalize;
|
|
595
705
|
context._preFlightWafScanned = true;
|
|
596
706
|
context._preFlightVerified = true;
|
|
707
|
+
if (typeof context.txBase64 === "string" && preFlightCtx.tx && preFlightCtx.itx && preFlightCtx.txType) {
|
|
708
|
+
const config = context.config;
|
|
709
|
+
const supportedTxs = get(config, "transaction.supportedTxs");
|
|
710
|
+
const multiSignV2Txs = get(config, "transaction.multiSignV2Txs");
|
|
711
|
+
const defaultSizeLimit = get(config, "transaction.maxTxSize.default");
|
|
712
|
+
const extra = context.extra;
|
|
713
|
+
context[PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL] = {
|
|
714
|
+
txBase64: context.txBase64,
|
|
715
|
+
configRef: config,
|
|
716
|
+
chainId: get(config, "chainId"),
|
|
717
|
+
tokenDecimal: get(config, "token.decimal"),
|
|
718
|
+
txFeeForType: get(config, [
|
|
719
|
+
"transaction",
|
|
720
|
+
"txFee",
|
|
721
|
+
preFlightCtx.txType
|
|
722
|
+
]),
|
|
723
|
+
maxTxSizeForType: get(config, [
|
|
724
|
+
"transaction",
|
|
725
|
+
"maxTxSize",
|
|
726
|
+
preFlightCtx.txType
|
|
727
|
+
], defaultSizeLimit),
|
|
728
|
+
maxExtraSize: get(config, "transaction.maxExtraSize"),
|
|
729
|
+
maxMultisig: get(config, "transaction.maxMultisig"),
|
|
730
|
+
maxListSize: get(config, "transaction.maxListSize"),
|
|
731
|
+
maxAssetSize: get(config, "transaction.maxAssetSize"),
|
|
732
|
+
isSupportedTx: Boolean(Array.isArray(supportedTxs) && supportedTxs.includes(preFlightCtx.txType)),
|
|
733
|
+
isMultiSignV2Tx: Boolean(Array.isArray(multiSignV2Txs) && multiSignV2Txs.includes(preFlightCtx.txType)),
|
|
734
|
+
txExtraSerialized: serializeExtraField(extra?.txExtra),
|
|
735
|
+
gasStakeHeadersSerialized: serializeExtraField(extra?.gasStakeHeaders),
|
|
736
|
+
coSignatureSerialized: serializeExtraField(extra?.coSignature),
|
|
737
|
+
tx: cloneDeep(preFlightCtx.tx),
|
|
738
|
+
txEncoding: preFlightCtx.txEncoding,
|
|
739
|
+
txSize: preFlightCtx.txSize,
|
|
740
|
+
baseTxSize,
|
|
741
|
+
extraSizeCounted,
|
|
742
|
+
txHash: preFlightCtx.txHash,
|
|
743
|
+
unsignedTxHash: preFlightCtx.unsignedTxHash,
|
|
744
|
+
txBaseGas: Boolean(preFlightCtx.txBaseGas),
|
|
745
|
+
itx: cloneDeep(preFlightCtx.itx),
|
|
746
|
+
txType: preFlightCtx.txType,
|
|
747
|
+
rawTxItxBeforeNormalize
|
|
748
|
+
};
|
|
749
|
+
}
|
|
597
750
|
resolve(context);
|
|
598
751
|
});
|
|
599
752
|
});
|
|
600
753
|
}
|
|
601
754
|
|
|
602
755
|
//#endregion
|
|
603
|
-
export { MAX_DELEGATE_TYPE_URLS_LIST_SIZE, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, MAX_PREFLIGHT_STRING_FIELD_BYTES, MAX_PREFLIGHT_WIRE_BYTES_FALLBACK, MAX_ROLLUP_TXS_LIST_SIZE, assertKnownItxFields, assertRawWireEnvelope, PreFlightWaf as default, inspectTransactionPreFlight, scanItxPayloadAnomalies };
|
|
756
|
+
export { MAX_DELEGATE_TYPE_URLS_LIST_SIZE, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, MAX_PREFLIGHT_STRING_FIELD_BYTES, MAX_PREFLIGHT_WIRE_BYTES_FALLBACK, MAX_ROLLUP_TXS_LIST_SIZE, PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL, assertKnownItxFields, assertRawWireEnvelope, PreFlightWaf as default, inspectTransactionPreFlight, scanItxPayloadAnomalies, tryApplyPreFlightVerifiedSnapshot };
|
package/lib/pipes/decode-itx.cjs
CHANGED
|
@@ -87,6 +87,9 @@ function normalizeItx(raw) {
|
|
|
87
87
|
}
|
|
88
88
|
function DecodeItx(context, next) {
|
|
89
89
|
try {
|
|
90
|
+
context._preFlightWafScanned = false;
|
|
91
|
+
context._preFlightVerified = false;
|
|
92
|
+
context._preFlightSnapshotApplied = false;
|
|
90
93
|
context._rawTxItxBeforeNormalize = context.tx?.itx;
|
|
91
94
|
const normalized = normalizeItx(context.tx.itx);
|
|
92
95
|
if (!normalized) return next(new _ocap_util_lib_error.CustomError("INVALID_TX", "Failed to decode itx"));
|
package/lib/pipes/decode-tx.cjs
CHANGED
|
@@ -114,6 +114,9 @@ function DecodeTx(context, next) {
|
|
|
114
114
|
writable: true
|
|
115
115
|
});
|
|
116
116
|
context._extraSizeCounted = false;
|
|
117
|
+
context._preFlightWafScanned = false;
|
|
118
|
+
context._preFlightVerified = false;
|
|
119
|
+
context._preFlightSnapshotApplied = false;
|
|
117
120
|
Object.defineProperty(context, "txHash", {
|
|
118
121
|
value: (0, _ocap_mcrypto.toTxHash)(txBuffer),
|
|
119
122
|
enumerable: true,
|
|
@@ -14,6 +14,8 @@ let lodash_get = require("lodash/get");
|
|
|
14
14
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
15
15
|
let _ocap_message = require("@ocap/message");
|
|
16
16
|
let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
|
|
17
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
18
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
17
19
|
|
|
18
20
|
//#region src/pipes/pre-flight-waf.ts
|
|
19
21
|
const MAX_PREFLIGHT_JSON_DEPTH = 16;
|
|
@@ -535,6 +537,110 @@ function PreFlightWaf(context, next) {
|
|
|
535
537
|
return next(err);
|
|
536
538
|
}
|
|
537
539
|
}
|
|
540
|
+
const PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL = Symbol.for("@ocap/tx-pipeline/preFlightVerifiedSnapshot");
|
|
541
|
+
function serializeExtraField(val) {
|
|
542
|
+
if (val === void 0) return "u";
|
|
543
|
+
if (val === null) return "n";
|
|
544
|
+
if (typeof val === "string") return `s:${val}`;
|
|
545
|
+
try {
|
|
546
|
+
return `j:${JSON.stringify(val)}`;
|
|
547
|
+
} catch {
|
|
548
|
+
return "invalid";
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Apply the verified pre-flight snapshot onto `context` if and only if all verified inputs
|
|
553
|
+
* (`txBase64`, `config` invariants, and `extra.{txExtra,gasStakeHeaders,coSignature}`) are
|
|
554
|
+
* unchanged since `inspectTransactionPreFlight(context)` succeeded.
|
|
555
|
+
*/
|
|
556
|
+
function tryApplyPreFlightVerifiedSnapshot(context) {
|
|
557
|
+
context._preFlightWafScanned = false;
|
|
558
|
+
context._preFlightVerified = false;
|
|
559
|
+
context._preFlightSnapshotApplied = false;
|
|
560
|
+
const snap = context[PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL];
|
|
561
|
+
if (!snap || typeof context.txBase64 !== "string" || snap.txBase64 !== context.txBase64) return false;
|
|
562
|
+
const config = context.config;
|
|
563
|
+
if (snap.configRef !== config) return false;
|
|
564
|
+
const supportedTxs = (0, lodash_get.default)(config, "transaction.supportedTxs");
|
|
565
|
+
const multiSignV2Txs = (0, lodash_get.default)(config, "transaction.multiSignV2Txs");
|
|
566
|
+
const defaultSizeLimit = (0, lodash_get.default)(config, "transaction.maxTxSize.default");
|
|
567
|
+
if (snap.chainId !== (0, lodash_get.default)(config, "chainId") || snap.tokenDecimal !== (0, lodash_get.default)(config, "token.decimal") || snap.txFeeForType !== (snap.txType ? (0, lodash_get.default)(config, [
|
|
568
|
+
"transaction",
|
|
569
|
+
"txFee",
|
|
570
|
+
snap.txType
|
|
571
|
+
]) : void 0) || snap.maxTxSizeForType !== (snap.txType ? (0, lodash_get.default)(config, [
|
|
572
|
+
"transaction",
|
|
573
|
+
"maxTxSize",
|
|
574
|
+
snap.txType
|
|
575
|
+
], defaultSizeLimit) : defaultSizeLimit) || snap.maxExtraSize !== (0, lodash_get.default)(config, "transaction.maxExtraSize") || snap.maxMultisig !== (0, lodash_get.default)(config, "transaction.maxMultisig") || snap.maxListSize !== (0, lodash_get.default)(config, "transaction.maxListSize") || snap.maxAssetSize !== (0, lodash_get.default)(config, "transaction.maxAssetSize") || snap.isSupportedTx !== Boolean(Array.isArray(supportedTxs) && supportedTxs.includes(snap.txType)) || snap.isMultiSignV2Tx !== Boolean(Array.isArray(multiSignV2Txs) && multiSignV2Txs.includes(snap.txType))) return false;
|
|
576
|
+
const extra = context.extra;
|
|
577
|
+
if (snap.txExtraSerialized !== serializeExtraField(extra?.txExtra) || snap.gasStakeHeadersSerialized !== serializeExtraField(extra?.gasStakeHeaders) || snap.coSignatureSerialized !== serializeExtraField(extra?.coSignature)) return false;
|
|
578
|
+
const pinned = extra?.txTime;
|
|
579
|
+
const pinnedMs = pinned === void 0 || pinned === null || pinned === "" ? NaN : new Date(pinned).getTime();
|
|
580
|
+
const resolvedTxTime = Number.isFinite(pinnedMs) ? new Date(pinnedMs).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
581
|
+
Object.defineProperty(context, "tx", {
|
|
582
|
+
value: (0, lodash_cloneDeep.default)(snap.tx),
|
|
583
|
+
enumerable: true,
|
|
584
|
+
configurable: true,
|
|
585
|
+
writable: true
|
|
586
|
+
});
|
|
587
|
+
Object.defineProperty(context, "txEncoding", {
|
|
588
|
+
value: snap.txEncoding,
|
|
589
|
+
enumerable: true,
|
|
590
|
+
configurable: true,
|
|
591
|
+
writable: true
|
|
592
|
+
});
|
|
593
|
+
Object.defineProperty(context, "txSize", {
|
|
594
|
+
value: snap.txSize,
|
|
595
|
+
enumerable: true,
|
|
596
|
+
configurable: true,
|
|
597
|
+
writable: true
|
|
598
|
+
});
|
|
599
|
+
Object.defineProperty(context, "txHash", {
|
|
600
|
+
value: snap.txHash,
|
|
601
|
+
enumerable: true,
|
|
602
|
+
configurable: true,
|
|
603
|
+
writable: true
|
|
604
|
+
});
|
|
605
|
+
Object.defineProperty(context, "unsignedTxHash", {
|
|
606
|
+
value: snap.unsignedTxHash,
|
|
607
|
+
enumerable: true,
|
|
608
|
+
configurable: true,
|
|
609
|
+
writable: true
|
|
610
|
+
});
|
|
611
|
+
Object.defineProperty(context, "txTime", {
|
|
612
|
+
value: resolvedTxTime,
|
|
613
|
+
enumerable: true,
|
|
614
|
+
configurable: true,
|
|
615
|
+
writable: true
|
|
616
|
+
});
|
|
617
|
+
Object.defineProperty(context, "txBaseGas", {
|
|
618
|
+
value: snap.txBaseGas,
|
|
619
|
+
enumerable: true,
|
|
620
|
+
configurable: true,
|
|
621
|
+
writable: true
|
|
622
|
+
});
|
|
623
|
+
Object.defineProperty(context, "itx", {
|
|
624
|
+
value: (0, lodash_cloneDeep.default)(snap.itx),
|
|
625
|
+
enumerable: true,
|
|
626
|
+
configurable: true,
|
|
627
|
+
writable: true
|
|
628
|
+
});
|
|
629
|
+
Object.defineProperty(context, "txType", {
|
|
630
|
+
value: snap.txType,
|
|
631
|
+
enumerable: true,
|
|
632
|
+
configurable: true,
|
|
633
|
+
writable: true
|
|
634
|
+
});
|
|
635
|
+
context._baseTxSize = snap.baseTxSize;
|
|
636
|
+
context._extraSizeCounted = snap.extraSizeCounted;
|
|
637
|
+
context._rawTxItxBeforeNormalize = snap.rawTxItxBeforeNormalize;
|
|
638
|
+
context._preFlightWafScanned = true;
|
|
639
|
+
context._preFlightVerified = true;
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
642
|
+
PreFlightWaf.SNAPSHOT_SYMBOL = PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL;
|
|
643
|
+
PreFlightWaf.tryApplyVerifiedSnapshot = tryApplyPreFlightVerifiedSnapshot;
|
|
538
644
|
/**
|
|
539
645
|
* Stateless, zero-DB-I/O Pre-Flight inspection runner for `OCAPResolver.sendTx`
|
|
540
646
|
* BEFORE enqueuing into the single-writer queue (`this.queue`) or acquiring the SQLite write lock.
|
|
@@ -594,9 +700,57 @@ async function inspectTransactionPreFlight(context) {
|
|
|
594
700
|
configurable: true,
|
|
595
701
|
writable: true
|
|
596
702
|
});
|
|
597
|
-
|
|
703
|
+
const baseTxSize = preFlightCtx._baseTxSize ?? preFlightCtx.txSize;
|
|
704
|
+
const extraSizeCounted = Boolean(preFlightCtx._extraSizeCounted);
|
|
705
|
+
const rawTxItxBeforeNormalize = preFlightCtx._rawTxItxBeforeNormalize;
|
|
706
|
+
context._baseTxSize = baseTxSize;
|
|
707
|
+
context._extraSizeCounted = extraSizeCounted;
|
|
708
|
+
context._rawTxItxBeforeNormalize = rawTxItxBeforeNormalize;
|
|
598
709
|
context._preFlightWafScanned = true;
|
|
599
710
|
context._preFlightVerified = true;
|
|
711
|
+
if (typeof context.txBase64 === "string" && preFlightCtx.tx && preFlightCtx.itx && preFlightCtx.txType) {
|
|
712
|
+
const config = context.config;
|
|
713
|
+
const supportedTxs = (0, lodash_get.default)(config, "transaction.supportedTxs");
|
|
714
|
+
const multiSignV2Txs = (0, lodash_get.default)(config, "transaction.multiSignV2Txs");
|
|
715
|
+
const defaultSizeLimit = (0, lodash_get.default)(config, "transaction.maxTxSize.default");
|
|
716
|
+
const extra = context.extra;
|
|
717
|
+
context[PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL] = {
|
|
718
|
+
txBase64: context.txBase64,
|
|
719
|
+
configRef: config,
|
|
720
|
+
chainId: (0, lodash_get.default)(config, "chainId"),
|
|
721
|
+
tokenDecimal: (0, lodash_get.default)(config, "token.decimal"),
|
|
722
|
+
txFeeForType: (0, lodash_get.default)(config, [
|
|
723
|
+
"transaction",
|
|
724
|
+
"txFee",
|
|
725
|
+
preFlightCtx.txType
|
|
726
|
+
]),
|
|
727
|
+
maxTxSizeForType: (0, lodash_get.default)(config, [
|
|
728
|
+
"transaction",
|
|
729
|
+
"maxTxSize",
|
|
730
|
+
preFlightCtx.txType
|
|
731
|
+
], defaultSizeLimit),
|
|
732
|
+
maxExtraSize: (0, lodash_get.default)(config, "transaction.maxExtraSize"),
|
|
733
|
+
maxMultisig: (0, lodash_get.default)(config, "transaction.maxMultisig"),
|
|
734
|
+
maxListSize: (0, lodash_get.default)(config, "transaction.maxListSize"),
|
|
735
|
+
maxAssetSize: (0, lodash_get.default)(config, "transaction.maxAssetSize"),
|
|
736
|
+
isSupportedTx: Boolean(Array.isArray(supportedTxs) && supportedTxs.includes(preFlightCtx.txType)),
|
|
737
|
+
isMultiSignV2Tx: Boolean(Array.isArray(multiSignV2Txs) && multiSignV2Txs.includes(preFlightCtx.txType)),
|
|
738
|
+
txExtraSerialized: serializeExtraField(extra?.txExtra),
|
|
739
|
+
gasStakeHeadersSerialized: serializeExtraField(extra?.gasStakeHeaders),
|
|
740
|
+
coSignatureSerialized: serializeExtraField(extra?.coSignature),
|
|
741
|
+
tx: (0, lodash_cloneDeep.default)(preFlightCtx.tx),
|
|
742
|
+
txEncoding: preFlightCtx.txEncoding,
|
|
743
|
+
txSize: preFlightCtx.txSize,
|
|
744
|
+
baseTxSize,
|
|
745
|
+
extraSizeCounted,
|
|
746
|
+
txHash: preFlightCtx.txHash,
|
|
747
|
+
unsignedTxHash: preFlightCtx.unsignedTxHash,
|
|
748
|
+
txBaseGas: Boolean(preFlightCtx.txBaseGas),
|
|
749
|
+
itx: (0, lodash_cloneDeep.default)(preFlightCtx.itx),
|
|
750
|
+
txType: preFlightCtx.txType,
|
|
751
|
+
rawTxItxBeforeNormalize
|
|
752
|
+
};
|
|
753
|
+
}
|
|
600
754
|
resolve(context);
|
|
601
755
|
});
|
|
602
756
|
});
|
|
@@ -609,8 +763,10 @@ exports.MAX_PREFLIGHT_JSON_KEYS = MAX_PREFLIGHT_JSON_KEYS;
|
|
|
609
763
|
exports.MAX_PREFLIGHT_STRING_FIELD_BYTES = MAX_PREFLIGHT_STRING_FIELD_BYTES;
|
|
610
764
|
exports.MAX_PREFLIGHT_WIRE_BYTES_FALLBACK = MAX_PREFLIGHT_WIRE_BYTES_FALLBACK;
|
|
611
765
|
exports.MAX_ROLLUP_TXS_LIST_SIZE = MAX_ROLLUP_TXS_LIST_SIZE;
|
|
766
|
+
exports.PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL = PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL;
|
|
612
767
|
exports.assertKnownItxFields = assertKnownItxFields;
|
|
613
768
|
exports.assertRawWireEnvelope = assertRawWireEnvelope;
|
|
614
769
|
exports.default = PreFlightWaf;
|
|
615
770
|
exports.inspectTransactionPreFlight = inspectTransactionPreFlight;
|
|
616
|
-
exports.scanItxPayloadAnomalies = scanItxPayloadAnomalies;
|
|
771
|
+
exports.scanItxPayloadAnomalies = scanItxPayloadAnomalies;
|
|
772
|
+
exports.tryApplyPreFlightVerifiedSnapshot = tryApplyPreFlightVerifiedSnapshot;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomError } from "@ocap/util/lib/error";
|
|
2
|
-
import { IBaseContext, IChainConfig, IDecodedContext } from "@ocap/types";
|
|
2
|
+
import { IBaseContext, IChainConfig, IDecodedContext, IDecodedTransaction } from "@ocap/types";
|
|
3
3
|
|
|
4
4
|
//#region src/pipes/pre-flight-waf.d.ts
|
|
5
5
|
declare const MAX_PREFLIGHT_JSON_DEPTH = 16;
|
|
@@ -25,10 +25,49 @@ declare function scanItxPayloadAnomalies(itx: unknown, txType: string | undefine
|
|
|
25
25
|
* Pipeline pipe that runs the Pre-Flight WAF structural & anomaly checks.
|
|
26
26
|
*/
|
|
27
27
|
declare function PreFlightWaf(context: IDecodedContext, next: (err?: CustomError) => void): void;
|
|
28
|
+
declare namespace PreFlightWaf {
|
|
29
|
+
var SNAPSHOT_SYMBOL: typeof PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL;
|
|
30
|
+
var tryApplyVerifiedSnapshot: typeof tryApplyPreFlightVerifiedSnapshot;
|
|
31
|
+
}
|
|
32
|
+
declare const PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL: unique symbol;
|
|
33
|
+
interface IPreFlightVerifiedSnapshot {
|
|
34
|
+
txBase64: string;
|
|
35
|
+
configRef: IChainConfig | undefined;
|
|
36
|
+
chainId: unknown;
|
|
37
|
+
tokenDecimal: unknown;
|
|
38
|
+
txFeeForType: unknown;
|
|
39
|
+
maxTxSizeForType: unknown;
|
|
40
|
+
maxExtraSize: unknown;
|
|
41
|
+
maxMultisig: unknown;
|
|
42
|
+
maxListSize: unknown;
|
|
43
|
+
maxAssetSize: unknown;
|
|
44
|
+
isSupportedTx: boolean;
|
|
45
|
+
isMultiSignV2Tx: boolean;
|
|
46
|
+
txExtraSerialized: string;
|
|
47
|
+
gasStakeHeadersSerialized: string;
|
|
48
|
+
coSignatureSerialized: string;
|
|
49
|
+
tx: IDecodedTransaction;
|
|
50
|
+
txEncoding: 'cbor' | 'protobuf';
|
|
51
|
+
txSize: number;
|
|
52
|
+
baseTxSize: number;
|
|
53
|
+
extraSizeCounted: boolean;
|
|
54
|
+
txHash: string;
|
|
55
|
+
unsignedTxHash: string;
|
|
56
|
+
txBaseGas: boolean;
|
|
57
|
+
itx: Record<string, unknown>;
|
|
58
|
+
txType: string;
|
|
59
|
+
rawTxItxBeforeNormalize: unknown;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Apply the verified pre-flight snapshot onto `context` if and only if all verified inputs
|
|
63
|
+
* (`txBase64`, `config` invariants, and `extra.{txExtra,gasStakeHeaders,coSignature}`) are
|
|
64
|
+
* unchanged since `inspectTransactionPreFlight(context)` succeeded.
|
|
65
|
+
*/
|
|
66
|
+
declare function tryApplyPreFlightVerifiedSnapshot(context: IBaseContext): boolean;
|
|
28
67
|
/**
|
|
29
68
|
* Stateless, zero-DB-I/O Pre-Flight inspection runner for `OCAPResolver.sendTx`
|
|
30
69
|
* BEFORE enqueuing into the single-writer queue (`this.queue`) or acquiring the SQLite write lock.
|
|
31
70
|
*/
|
|
32
71
|
declare function inspectTransactionPreFlight(context: IBaseContext): Promise<IDecodedContext>;
|
|
33
72
|
//#endregion
|
|
34
|
-
export { MAX_DELEGATE_TYPE_URLS_LIST_SIZE, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, MAX_PREFLIGHT_STRING_FIELD_BYTES, MAX_PREFLIGHT_WIRE_BYTES_FALLBACK, MAX_ROLLUP_TXS_LIST_SIZE, assertKnownItxFields, assertRawWireEnvelope, PreFlightWaf as default, inspectTransactionPreFlight, scanItxPayloadAnomalies };
|
|
73
|
+
export { IPreFlightVerifiedSnapshot, MAX_DELEGATE_TYPE_URLS_LIST_SIZE, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, MAX_PREFLIGHT_STRING_FIELD_BYTES, MAX_PREFLIGHT_WIRE_BYTES_FALLBACK, MAX_ROLLUP_TXS_LIST_SIZE, PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL, assertKnownItxFields, assertRawWireEnvelope, PreFlightWaf as default, inspectTransactionPreFlight, scanItxPayloadAnomalies, tryApplyPreFlightVerifiedSnapshot };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.31.
|
|
6
|
+
"version": "1.31.1",
|
|
7
7
|
"description": "Pipeline runner and common pipelines to process transactions",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"elliptic": "6.5.3"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@arcblock/did": "1.31.
|
|
53
|
-
"@arcblock/did-util": "1.31.
|
|
54
|
-
"@ocap/client": "1.31.
|
|
55
|
-
"@ocap/mcrypto": "1.31.
|
|
56
|
-
"@ocap/message": "1.31.
|
|
57
|
-
"@ocap/state": "1.31.
|
|
58
|
-
"@ocap/types": "1.31.
|
|
59
|
-
"@ocap/util": "1.31.
|
|
60
|
-
"@ocap/wallet": "1.31.
|
|
52
|
+
"@arcblock/did": "1.31.1",
|
|
53
|
+
"@arcblock/did-util": "1.31.1",
|
|
54
|
+
"@ocap/client": "1.31.1",
|
|
55
|
+
"@ocap/mcrypto": "1.31.1",
|
|
56
|
+
"@ocap/message": "1.31.1",
|
|
57
|
+
"@ocap/state": "1.31.1",
|
|
58
|
+
"@ocap/types": "1.31.1",
|
|
59
|
+
"@ocap/util": "1.31.1",
|
|
60
|
+
"@ocap/wallet": "1.31.1",
|
|
61
61
|
"elliptic": "6.6.1",
|
|
62
62
|
"debug": "^4.4.3",
|
|
63
63
|
"lodash": "^4.17.23"
|