@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,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;
|
|
@@ -8,6 +8,23 @@ declare const MAX_PREFLIGHT_STRING_FIELD_BYTES: number;
|
|
|
8
8
|
declare const MAX_PREFLIGHT_WIRE_BYTES_FALLBACK: number;
|
|
9
9
|
declare const MAX_ROLLUP_TXS_LIST_SIZE = 512;
|
|
10
10
|
declare const MAX_DELEGATE_TYPE_URLS_LIST_SIZE = 128;
|
|
11
|
+
/**
|
|
12
|
+
* Compute the maximum allowed raw transaction wire size in bytes for a given chain config (#1336, #1516).
|
|
13
|
+
* Shared between `PreFlightWaf` and `DecodeTx` so callers that invoke `DecodeTx` without `PreFlightWaf`
|
|
14
|
+
* (e.g. `decodeOcapWireTx` on Cloudflare Durable Objects) enforce the exact same ceiling before `fromBase64`.
|
|
15
|
+
*/
|
|
16
|
+
declare function computeMaxWireEnvelopeBytes(config?: IChainConfig): number;
|
|
17
|
+
/**
|
|
18
|
+
* Upper-bound decoded byte length of a trimmed base64 / base64url string.
|
|
19
|
+
* Exact for all canonical base64 / base64url payloads (`0`, `1`, or `2` mod 3 bytes) and
|
|
20
|
+
* never under-estimates `Buffer.from(base64.unescape(trimmed), 'base64').byteLength` on malformed input.
|
|
21
|
+
*/
|
|
22
|
+
declare function estimateBase64WireBytes(trimmed: string): number;
|
|
23
|
+
/**
|
|
24
|
+
* Enforce the raw wire byte ceiling in O(1) before `.trim()`, regex scanning, or base64 decoding (#1516).
|
|
25
|
+
* Returns the ASCII-trimmed string when within the configured ceiling.
|
|
26
|
+
*/
|
|
27
|
+
declare function assertWireByteCeiling(txBase64: string, config?: IChainConfig, messagePrefix?: string): string;
|
|
11
28
|
/**
|
|
12
29
|
* Fast O(1) wire-size and base64 character validation before allocating buffers or decoding.
|
|
13
30
|
*/
|
|
@@ -25,10 +42,49 @@ declare function scanItxPayloadAnomalies(itx: unknown, txType: string | undefine
|
|
|
25
42
|
* Pipeline pipe that runs the Pre-Flight WAF structural & anomaly checks.
|
|
26
43
|
*/
|
|
27
44
|
declare function PreFlightWaf(context: IDecodedContext, next: (err?: CustomError) => void): void;
|
|
45
|
+
declare namespace PreFlightWaf {
|
|
46
|
+
var SNAPSHOT_SYMBOL: typeof PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL;
|
|
47
|
+
var tryApplyVerifiedSnapshot: typeof tryApplyPreFlightVerifiedSnapshot;
|
|
48
|
+
}
|
|
49
|
+
declare const PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL: unique symbol;
|
|
50
|
+
interface IPreFlightVerifiedSnapshot {
|
|
51
|
+
txBase64: string;
|
|
52
|
+
configRef: IChainConfig | undefined;
|
|
53
|
+
chainId: unknown;
|
|
54
|
+
tokenDecimal: unknown;
|
|
55
|
+
txFeeForType: unknown;
|
|
56
|
+
maxTxSizeForType: unknown;
|
|
57
|
+
maxExtraSize: unknown;
|
|
58
|
+
maxMultisig: unknown;
|
|
59
|
+
maxListSize: unknown;
|
|
60
|
+
maxAssetSize: unknown;
|
|
61
|
+
isSupportedTx: boolean;
|
|
62
|
+
isMultiSignV2Tx: boolean;
|
|
63
|
+
txExtraSerialized: string;
|
|
64
|
+
gasStakeHeadersSerialized: string;
|
|
65
|
+
coSignatureSerialized: string;
|
|
66
|
+
tx: IDecodedTransaction;
|
|
67
|
+
txEncoding: 'cbor' | 'protobuf';
|
|
68
|
+
txSize: number;
|
|
69
|
+
baseTxSize: number;
|
|
70
|
+
extraSizeCounted: boolean;
|
|
71
|
+
txHash: string;
|
|
72
|
+
unsignedTxHash: string;
|
|
73
|
+
txBaseGas: boolean;
|
|
74
|
+
itx: Record<string, unknown>;
|
|
75
|
+
txType: string;
|
|
76
|
+
rawTxItxBeforeNormalize: unknown;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Apply the verified pre-flight snapshot onto `context` if and only if all verified inputs
|
|
80
|
+
* (`txBase64`, `config` invariants, and `extra.{txExtra,gasStakeHeaders,coSignature}`) are
|
|
81
|
+
* unchanged since `inspectTransactionPreFlight(context)` succeeded.
|
|
82
|
+
*/
|
|
83
|
+
declare function tryApplyPreFlightVerifiedSnapshot(context: IBaseContext): boolean;
|
|
28
84
|
/**
|
|
29
85
|
* Stateless, zero-DB-I/O Pre-Flight inspection runner for `OCAPResolver.sendTx`
|
|
30
86
|
* BEFORE enqueuing into the single-writer queue (`this.queue`) or acquiring the SQLite write lock.
|
|
31
87
|
*/
|
|
32
88
|
declare function inspectTransactionPreFlight(context: IBaseContext): Promise<IDecodedContext>;
|
|
33
89
|
//#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 };
|
|
90
|
+
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, assertWireByteCeiling, computeMaxWireEnvelopeBytes, PreFlightWaf as default, estimateBase64WireBytes, inspectTransactionPreFlight, scanItxPayloadAnomalies, tryApplyPreFlightVerifiedSnapshot };
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { ENCRYPTED_NFT_SCHEMA_VERSION, validateEncryptedAssetEnvelope } from "../encrypted-nft-envelope.mjs";
|
|
2
2
|
import DecodeItx from "./decode-itx.mjs";
|
|
3
|
-
import DecodeTx from "./decode-tx.mjs";
|
|
4
3
|
import runner_default from "../runner.mjs";
|
|
5
4
|
import CreatedVerifyBlockedPipe from "./verify-blocked.mjs";
|
|
6
5
|
import VerifyServiceFee from "./verify-service-fee.mjs";
|
|
7
6
|
import VerifySignature from "./verify-signature.mjs";
|
|
8
7
|
import VerifyTx from "./verify-tx.mjs";
|
|
9
8
|
import VerifyTxSize from "./verify-tx-size.mjs";
|
|
9
|
+
import DecodeTx from "./decode-tx.mjs";
|
|
10
10
|
import { CustomError } from "@ocap/util/lib/error";
|
|
11
|
-
import get from "lodash/get.js";
|
|
12
11
|
import { createMessage, decodeAny, encodeAny, fromTypeUrl, toTypeUrl } from "@ocap/message";
|
|
13
12
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
13
|
+
import get from "lodash/get.js";
|
|
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;
|
|
@@ -29,7 +30,7 @@ const FORBIDDEN_STORAGE_DATA_URI_PATTERN = /^\s*data\s*:\s*(?:image\/|audio\/|vi
|
|
|
29
30
|
const FORBIDDEN_BINARY_MAGIC_BASE64_PATTERN = /^(?:AGFzbQ|f0VMRg|JVBERi0|UEsDB|H4sIA|iVBORw0KGgo|(?:\/9j\/|_9j_)4AAQ|R0lGOD(?:lh|dh))/;
|
|
30
31
|
const FORBIDDEN_BINARY_MAGIC_RAW_PATTERN = /^(?:\x00asm|\x7fELF|%PDF-|PK\x03\x04|\x1f\x8b\x08[\x00-\x1f]|\x89PNG\r\n\x1a\n|\xff\xd8\xff[\xdb\xe0\xe1\xe2\xee]|GIF8[79]a)/;
|
|
31
32
|
const FORBIDDEN_CONTROL_CHAR_PATTERN = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
|
|
32
|
-
const BASE64_WIRE_PATTERN = /^[A-Za-z0-9
|
|
33
|
+
const BASE64_WIRE_PATTERN = /^(?:[A-Za-z0-9+/]+={0,2}|[A-Za-z0-9_-]+={0,2})$/;
|
|
33
34
|
const STANDARD_BOUNDED_LIST_KEYS = [
|
|
34
35
|
"inputs",
|
|
35
36
|
"outputs",
|
|
@@ -120,20 +121,55 @@ function getAllowedTopLevelItxKeys(typeUrl) {
|
|
|
120
121
|
return null;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
124
|
+
const MAX_WIRE_WHITESPACE_SLACK = 64;
|
|
125
|
+
/**
|
|
126
|
+
* Compute the maximum allowed raw transaction wire size in bytes for a given chain config (#1336, #1516).
|
|
127
|
+
* Shared between `PreFlightWaf` and `DecodeTx` so callers that invoke `DecodeTx` without `PreFlightWaf`
|
|
128
|
+
* (e.g. `decodeOcapWireTx` on Cloudflare Durable Objects) enforce the exact same ceiling before `fromBase64`.
|
|
129
|
+
*/
|
|
130
|
+
function computeMaxWireEnvelopeBytes(config) {
|
|
131
|
+
const maxTxSizeMap = get(config, "transaction.maxTxSize");
|
|
132
|
+
const configuredLimits = maxTxSizeMap && typeof maxTxSizeMap === "object" ? Object.values(maxTxSizeMap).filter((v) => typeof v === "number" && Number.isFinite(v) && v > 0) : [];
|
|
133
|
+
if (configuredLimits.length === 0) return MAX_PREFLIGHT_WIRE_BYTES_FALLBACK;
|
|
134
|
+
const rawMaxAssetSize = get(config, "transaction.maxAssetSize");
|
|
135
|
+
const maxAssetSize = typeof rawMaxAssetSize === "number" && Number.isFinite(rawMaxAssetSize) && rawMaxAssetSize > 0 ? rawMaxAssetSize : 65536;
|
|
136
|
+
const rawMaxExtraSize = get(config, "transaction.maxExtraSize");
|
|
137
|
+
const maxExtraSize = typeof rawMaxExtraSize === "number" && Number.isFinite(rawMaxExtraSize) && rawMaxExtraSize >= 0 ? rawMaxExtraSize : 8192;
|
|
138
|
+
return Math.max(...configuredLimits, maxAssetSize) + maxExtraSize;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Upper-bound decoded byte length of a trimmed base64 / base64url string.
|
|
142
|
+
* Exact for all canonical base64 / base64url payloads (`0`, `1`, or `2` mod 3 bytes) and
|
|
143
|
+
* never under-estimates `Buffer.from(base64.unescape(trimmed), 'base64').byteLength` on malformed input.
|
|
144
|
+
*/
|
|
145
|
+
function estimateBase64WireBytes(trimmed) {
|
|
146
|
+
const len = trimmed.length;
|
|
147
|
+
const pad = len >= 4 && len % 4 === 0 ? trimmed.endsWith("==") ? 2 : trimmed.endsWith("=") ? 1 : 0 : 0;
|
|
148
|
+
return Math.max(0, Math.floor(len * 3 / 4) - pad);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Enforce the raw wire byte ceiling in O(1) before `.trim()`, regex scanning, or base64 decoding (#1516).
|
|
152
|
+
* Returns the ASCII-trimmed string when within the configured ceiling.
|
|
153
|
+
*/
|
|
154
|
+
function assertWireByteCeiling(txBase64, config, messagePrefix = "Raw transaction wire size") {
|
|
155
|
+
const maxConfiguredTxBytes = computeMaxWireEnvelopeBytes(config);
|
|
156
|
+
const maxBase64Chars = Math.ceil(maxConfiguredTxBytes * 4 / 3) + 4;
|
|
157
|
+
if (txBase64.length > maxBase64Chars + MAX_WIRE_WHITESPACE_SLACK) throw new CustomError("INVALID_TX_SIZE", `${messagePrefix} (${Math.floor(txBase64.length * 3 / 4)} bytes) exceeds maximum ceiling (${maxConfiguredTxBytes} bytes)`);
|
|
158
|
+
const utf8ByteLen = Buffer.byteLength(txBase64, "utf8");
|
|
159
|
+
if (utf8ByteLen > maxBase64Chars + MAX_WIRE_WHITESPACE_SLACK) throw new CustomError("INVALID_TX_SIZE", `${messagePrefix} (${Math.floor(utf8ByteLen * 3 / 4)} bytes) exceeds maximum ceiling (${maxConfiguredTxBytes} bytes)`);
|
|
160
|
+
const trimmed = txBase64.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, "");
|
|
161
|
+
const estimatedWireBytes = estimateBase64WireBytes(trimmed);
|
|
162
|
+
if (estimatedWireBytes > maxConfiguredTxBytes) throw new CustomError("INVALID_TX_SIZE", `${messagePrefix} (${estimatedWireBytes} bytes) exceeds maximum ceiling (${maxConfiguredTxBytes} bytes)`);
|
|
163
|
+
return trimmed;
|
|
164
|
+
}
|
|
123
165
|
/**
|
|
124
166
|
* Fast O(1) wire-size and base64 character validation before allocating buffers or decoding.
|
|
125
167
|
*/
|
|
126
168
|
function assertRawWireEnvelope(txBase64, config) {
|
|
127
169
|
if (!txBase64 || typeof txBase64 !== "string" || txBase64.length < 20) throw new CustomError("INVALID_TX", "Transaction data is empty or too short");
|
|
128
|
-
const trimmed = txBase64
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
const configuredLimits = Object.values(maxTxSizeMap).filter((v) => typeof v === "number" && v > 0);
|
|
132
|
-
const maxAssetSize = get(config, "transaction.maxAssetSize", 65536) || 65536;
|
|
133
|
-
const maxExtraSize = get(config, "transaction.maxExtraSize", 8192) || 8192;
|
|
134
|
-
const maxConfiguredTxBytes = configuredLimits.length > 0 ? Math.max(...configuredLimits, maxAssetSize) + maxExtraSize : MAX_PREFLIGHT_WIRE_BYTES_FALLBACK;
|
|
135
|
-
const estimatedWireBytes = Math.floor(trimmed.length * 3 / 4);
|
|
136
|
-
if (estimatedWireBytes > maxConfiguredTxBytes) throw new CustomError("INVALID_TX_SIZE", `Pre-Flight WAF: raw transaction wire size (${estimatedWireBytes} bytes) exceeds maximum ceiling (${maxConfiguredTxBytes} bytes)`);
|
|
170
|
+
const trimmed = assertWireByteCeiling(txBase64, config, "Pre-Flight WAF: raw transaction wire size");
|
|
171
|
+
if (trimmed.length < 20) throw new CustomError("INVALID_TX", "Transaction data is empty or too short");
|
|
172
|
+
if (txBase64 !== trimmed || !BASE64_WIRE_PATTERN.test(trimmed)) throw new CustomError("INVALID_TX", "Pre-Flight WAF: transaction wire data contains invalid non-base64 characters");
|
|
137
173
|
}
|
|
138
174
|
/**
|
|
139
175
|
* Reject unknown / alien fields in raw or CBOR `tx.itx` payloads that would otherwise be silently
|
|
@@ -532,6 +568,110 @@ function PreFlightWaf(context, next) {
|
|
|
532
568
|
return next(err);
|
|
533
569
|
}
|
|
534
570
|
}
|
|
571
|
+
const PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL = Symbol.for("@ocap/tx-pipeline/preFlightVerifiedSnapshot");
|
|
572
|
+
function serializeExtraField(val) {
|
|
573
|
+
if (val === void 0) return "u";
|
|
574
|
+
if (val === null) return "n";
|
|
575
|
+
if (typeof val === "string") return `s:${val}`;
|
|
576
|
+
try {
|
|
577
|
+
return `j:${JSON.stringify(val)}`;
|
|
578
|
+
} catch {
|
|
579
|
+
return "invalid";
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Apply the verified pre-flight snapshot onto `context` if and only if all verified inputs
|
|
584
|
+
* (`txBase64`, `config` invariants, and `extra.{txExtra,gasStakeHeaders,coSignature}`) are
|
|
585
|
+
* unchanged since `inspectTransactionPreFlight(context)` succeeded.
|
|
586
|
+
*/
|
|
587
|
+
function tryApplyPreFlightVerifiedSnapshot(context) {
|
|
588
|
+
context._preFlightWafScanned = false;
|
|
589
|
+
context._preFlightVerified = false;
|
|
590
|
+
context._preFlightSnapshotApplied = false;
|
|
591
|
+
const snap = context[PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL];
|
|
592
|
+
if (!snap || typeof context.txBase64 !== "string" || snap.txBase64 !== context.txBase64) return false;
|
|
593
|
+
const config = context.config;
|
|
594
|
+
if (snap.configRef !== config) return false;
|
|
595
|
+
const supportedTxs = get(config, "transaction.supportedTxs");
|
|
596
|
+
const multiSignV2Txs = get(config, "transaction.multiSignV2Txs");
|
|
597
|
+
const defaultSizeLimit = get(config, "transaction.maxTxSize.default");
|
|
598
|
+
if (snap.chainId !== get(config, "chainId") || snap.tokenDecimal !== get(config, "token.decimal") || snap.txFeeForType !== (snap.txType ? get(config, [
|
|
599
|
+
"transaction",
|
|
600
|
+
"txFee",
|
|
601
|
+
snap.txType
|
|
602
|
+
]) : void 0) || snap.maxTxSizeForType !== (snap.txType ? get(config, [
|
|
603
|
+
"transaction",
|
|
604
|
+
"maxTxSize",
|
|
605
|
+
snap.txType
|
|
606
|
+
], 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;
|
|
607
|
+
const extra = context.extra;
|
|
608
|
+
if (snap.txExtraSerialized !== serializeExtraField(extra?.txExtra) || snap.gasStakeHeadersSerialized !== serializeExtraField(extra?.gasStakeHeaders) || snap.coSignatureSerialized !== serializeExtraField(extra?.coSignature)) return false;
|
|
609
|
+
const pinned = extra?.txTime;
|
|
610
|
+
const pinnedMs = pinned === void 0 || pinned === null || pinned === "" ? NaN : new Date(pinned).getTime();
|
|
611
|
+
const resolvedTxTime = Number.isFinite(pinnedMs) ? new Date(pinnedMs).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
|
|
612
|
+
Object.defineProperty(context, "tx", {
|
|
613
|
+
value: cloneDeep(snap.tx),
|
|
614
|
+
enumerable: true,
|
|
615
|
+
configurable: true,
|
|
616
|
+
writable: true
|
|
617
|
+
});
|
|
618
|
+
Object.defineProperty(context, "txEncoding", {
|
|
619
|
+
value: snap.txEncoding,
|
|
620
|
+
enumerable: true,
|
|
621
|
+
configurable: true,
|
|
622
|
+
writable: true
|
|
623
|
+
});
|
|
624
|
+
Object.defineProperty(context, "txSize", {
|
|
625
|
+
value: snap.txSize,
|
|
626
|
+
enumerable: true,
|
|
627
|
+
configurable: true,
|
|
628
|
+
writable: true
|
|
629
|
+
});
|
|
630
|
+
Object.defineProperty(context, "txHash", {
|
|
631
|
+
value: snap.txHash,
|
|
632
|
+
enumerable: true,
|
|
633
|
+
configurable: true,
|
|
634
|
+
writable: true
|
|
635
|
+
});
|
|
636
|
+
Object.defineProperty(context, "unsignedTxHash", {
|
|
637
|
+
value: snap.unsignedTxHash,
|
|
638
|
+
enumerable: true,
|
|
639
|
+
configurable: true,
|
|
640
|
+
writable: true
|
|
641
|
+
});
|
|
642
|
+
Object.defineProperty(context, "txTime", {
|
|
643
|
+
value: resolvedTxTime,
|
|
644
|
+
enumerable: true,
|
|
645
|
+
configurable: true,
|
|
646
|
+
writable: true
|
|
647
|
+
});
|
|
648
|
+
Object.defineProperty(context, "txBaseGas", {
|
|
649
|
+
value: snap.txBaseGas,
|
|
650
|
+
enumerable: true,
|
|
651
|
+
configurable: true,
|
|
652
|
+
writable: true
|
|
653
|
+
});
|
|
654
|
+
Object.defineProperty(context, "itx", {
|
|
655
|
+
value: cloneDeep(snap.itx),
|
|
656
|
+
enumerable: true,
|
|
657
|
+
configurable: true,
|
|
658
|
+
writable: true
|
|
659
|
+
});
|
|
660
|
+
Object.defineProperty(context, "txType", {
|
|
661
|
+
value: snap.txType,
|
|
662
|
+
enumerable: true,
|
|
663
|
+
configurable: true,
|
|
664
|
+
writable: true
|
|
665
|
+
});
|
|
666
|
+
context._baseTxSize = snap.baseTxSize;
|
|
667
|
+
context._extraSizeCounted = snap.extraSizeCounted;
|
|
668
|
+
context._rawTxItxBeforeNormalize = snap.rawTxItxBeforeNormalize;
|
|
669
|
+
context._preFlightWafScanned = true;
|
|
670
|
+
context._preFlightVerified = true;
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
673
|
+
PreFlightWaf.SNAPSHOT_SYMBOL = PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL;
|
|
674
|
+
PreFlightWaf.tryApplyVerifiedSnapshot = tryApplyPreFlightVerifiedSnapshot;
|
|
535
675
|
/**
|
|
536
676
|
* Stateless, zero-DB-I/O Pre-Flight inspection runner for `OCAPResolver.sendTx`
|
|
537
677
|
* BEFORE enqueuing into the single-writer queue (`this.queue`) or acquiring the SQLite write lock.
|
|
@@ -591,13 +731,61 @@ async function inspectTransactionPreFlight(context) {
|
|
|
591
731
|
configurable: true,
|
|
592
732
|
writable: true
|
|
593
733
|
});
|
|
594
|
-
|
|
734
|
+
const baseTxSize = preFlightCtx._baseTxSize ?? preFlightCtx.txSize;
|
|
735
|
+
const extraSizeCounted = Boolean(preFlightCtx._extraSizeCounted);
|
|
736
|
+
const rawTxItxBeforeNormalize = preFlightCtx._rawTxItxBeforeNormalize;
|
|
737
|
+
context._baseTxSize = baseTxSize;
|
|
738
|
+
context._extraSizeCounted = extraSizeCounted;
|
|
739
|
+
context._rawTxItxBeforeNormalize = rawTxItxBeforeNormalize;
|
|
595
740
|
context._preFlightWafScanned = true;
|
|
596
741
|
context._preFlightVerified = true;
|
|
742
|
+
if (typeof context.txBase64 === "string" && preFlightCtx.tx && preFlightCtx.itx && preFlightCtx.txType) {
|
|
743
|
+
const config = context.config;
|
|
744
|
+
const supportedTxs = get(config, "transaction.supportedTxs");
|
|
745
|
+
const multiSignV2Txs = get(config, "transaction.multiSignV2Txs");
|
|
746
|
+
const defaultSizeLimit = get(config, "transaction.maxTxSize.default");
|
|
747
|
+
const extra = context.extra;
|
|
748
|
+
context[PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL] = {
|
|
749
|
+
txBase64: context.txBase64,
|
|
750
|
+
configRef: config,
|
|
751
|
+
chainId: get(config, "chainId"),
|
|
752
|
+
tokenDecimal: get(config, "token.decimal"),
|
|
753
|
+
txFeeForType: get(config, [
|
|
754
|
+
"transaction",
|
|
755
|
+
"txFee",
|
|
756
|
+
preFlightCtx.txType
|
|
757
|
+
]),
|
|
758
|
+
maxTxSizeForType: get(config, [
|
|
759
|
+
"transaction",
|
|
760
|
+
"maxTxSize",
|
|
761
|
+
preFlightCtx.txType
|
|
762
|
+
], defaultSizeLimit),
|
|
763
|
+
maxExtraSize: get(config, "transaction.maxExtraSize"),
|
|
764
|
+
maxMultisig: get(config, "transaction.maxMultisig"),
|
|
765
|
+
maxListSize: get(config, "transaction.maxListSize"),
|
|
766
|
+
maxAssetSize: get(config, "transaction.maxAssetSize"),
|
|
767
|
+
isSupportedTx: Boolean(Array.isArray(supportedTxs) && supportedTxs.includes(preFlightCtx.txType)),
|
|
768
|
+
isMultiSignV2Tx: Boolean(Array.isArray(multiSignV2Txs) && multiSignV2Txs.includes(preFlightCtx.txType)),
|
|
769
|
+
txExtraSerialized: serializeExtraField(extra?.txExtra),
|
|
770
|
+
gasStakeHeadersSerialized: serializeExtraField(extra?.gasStakeHeaders),
|
|
771
|
+
coSignatureSerialized: serializeExtraField(extra?.coSignature),
|
|
772
|
+
tx: cloneDeep(preFlightCtx.tx),
|
|
773
|
+
txEncoding: preFlightCtx.txEncoding,
|
|
774
|
+
txSize: preFlightCtx.txSize,
|
|
775
|
+
baseTxSize,
|
|
776
|
+
extraSizeCounted,
|
|
777
|
+
txHash: preFlightCtx.txHash,
|
|
778
|
+
unsignedTxHash: preFlightCtx.unsignedTxHash,
|
|
779
|
+
txBaseGas: Boolean(preFlightCtx.txBaseGas),
|
|
780
|
+
itx: cloneDeep(preFlightCtx.itx),
|
|
781
|
+
txType: preFlightCtx.txType,
|
|
782
|
+
rawTxItxBeforeNormalize
|
|
783
|
+
};
|
|
784
|
+
}
|
|
597
785
|
resolve(context);
|
|
598
786
|
});
|
|
599
787
|
});
|
|
600
788
|
}
|
|
601
789
|
|
|
602
790
|
//#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 };
|
|
791
|
+
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, assertWireByteCeiling, computeMaxWireEnvelopeBytes, PreFlightWaf as default, estimateBase64WireBytes, inspectTransactionPreFlight, scanItxPayloadAnomalies, tryApplyPreFlightVerifiedSnapshot };
|
|
@@ -2,10 +2,10 @@ import { name } from "../package.mjs";
|
|
|
2
2
|
import { types } from "@ocap/mcrypto";
|
|
3
3
|
import { isSameDid } from "@ocap/util";
|
|
4
4
|
import { CustomError } from "@ocap/util/lib/error";
|
|
5
|
+
import { toTypeInfo } from "@arcblock/did";
|
|
5
6
|
import get from "lodash/get.js";
|
|
6
7
|
import Debug from "debug";
|
|
7
8
|
import set from "lodash/set.js";
|
|
8
|
-
import { toTypeInfo } from "@arcblock/did";
|
|
9
9
|
|
|
10
10
|
//#region src/pipes/update-owner.ts
|
|
11
11
|
const debug = Debug(`${name}:pipe:update-owner`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomError } from "@ocap/util/lib/error";
|
|
2
|
-
import get from "lodash/get.js";
|
|
3
2
|
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
3
|
+
import get from "lodash/get.js";
|
|
4
4
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
5
5
|
|
|
6
6
|
//#region src/pipes/verify-account-migration.ts
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { parseCanonicalCoSignatureTxExtra } from "./verify-signature.mjs";
|
|
1
2
|
import { types } from "@ocap/mcrypto";
|
|
2
3
|
import { isSameDid, scopeMatch, scopeMatchAny, toBN } from "@ocap/util";
|
|
3
4
|
import { CustomError } from "@ocap/util/lib/error";
|
|
4
|
-
import get from "lodash/get.js";
|
|
5
|
-
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
6
|
-
import set from "lodash/set.js";
|
|
7
5
|
import { isFromPublicKey, normalizePublicKeyHex, toTypeInfo } from "@arcblock/did";
|
|
6
|
+
import { toDelegateAddress } from "@arcblock/did-util";
|
|
7
|
+
import { getListField } from "@ocap/util/lib/get-list-field";
|
|
8
|
+
import get from "lodash/get.js";
|
|
8
9
|
import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
|
|
9
|
-
import isEmpty from "lodash/isEmpty.js";
|
|
10
10
|
import { fromPublicKey } from "@ocap/wallet";
|
|
11
|
-
import
|
|
11
|
+
import isEmpty from "lodash/isEmpty.js";
|
|
12
|
+
import set from "lodash/set.js";
|
|
12
13
|
|
|
13
14
|
//#region src/pipes/verify-delegation.ts
|
|
14
15
|
const ZERO = toBN(0);
|
|
@@ -321,22 +322,31 @@ function CreateVerifyDelegationPipe({ type = "signature", delegationKey = "deleg
|
|
|
321
322
|
}
|
|
322
323
|
return null;
|
|
323
324
|
};
|
|
325
|
+
const hasExplicitCoSignatureInput = () => {
|
|
326
|
+
const explicitCoSig = get(context, "extra.coSignature");
|
|
327
|
+
if (explicitCoSig !== void 0 && explicitCoSig !== null) return true;
|
|
328
|
+
const rawTxExtra = get(context, "extra.txExtra");
|
|
329
|
+
if (typeof rawTxExtra === "string" && rawTxExtra.trim().startsWith("{")) try {
|
|
330
|
+
const parsed = JSON.parse(rawTxExtra);
|
|
331
|
+
return Boolean(parsed && typeof parsed === "object" && !Array.isArray(parsed) && "coSignature" in parsed);
|
|
332
|
+
} catch {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
if (rawTxExtra && typeof rawTxExtra === "object" && !Array.isArray(rawTxExtra)) return "coSignature" in rawTxExtra;
|
|
336
|
+
return false;
|
|
337
|
+
};
|
|
324
338
|
const verifyOwnerCoSignature = async (signerState, delegateePk) => {
|
|
325
339
|
if (!signerState?.address) return false;
|
|
326
340
|
if (Array.isArray(signerState.migratedTo) && signerState.migratedTo.length > 0) return false;
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (maybeCoSig && typeof maybeCoSig === "object") rawCoSig = maybeCoSig;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (!rawCoSig || typeof rawCoSig.pk !== "string" || typeof rawCoSig.signature !== "string") return false;
|
|
341
|
+
const rawDirectCoSig = get(context, "extra.coSignature");
|
|
342
|
+
const hasDirectCoSig = rawDirectCoSig !== void 0 && rawDirectCoSig !== null;
|
|
343
|
+
const rawTxExtra = get(context, "extra.txExtra");
|
|
344
|
+
const parsedFromDirect = hasDirectCoSig ? parseCanonicalCoSignatureTxExtra({ coSignature: rawDirectCoSig }) : null;
|
|
345
|
+
const parsedFromTxExtra = rawTxExtra !== void 0 && rawTxExtra !== null ? parseCanonicalCoSignatureTxExtra(rawTxExtra) : null;
|
|
346
|
+
if (hasDirectCoSig && !parsedFromDirect) return false;
|
|
347
|
+
if (parsedFromDirect && parsedFromTxExtra && (parsedFromDirect.pk !== parsedFromTxExtra.pk || parsedFromDirect.signature !== parsedFromTxExtra.signature || (parsedFromDirect.extra || "") !== (parsedFromTxExtra.extra || ""))) return false;
|
|
348
|
+
const rawCoSig = parsedFromDirect || parsedFromTxExtra;
|
|
349
|
+
if (!rawCoSig) return false;
|
|
340
350
|
const candidatePayloads = [context.txHash, context.unsignedTxHash].filter((x) => typeof x === "string" && x.length > 0);
|
|
341
351
|
if (candidatePayloads.length === 0) return false;
|
|
342
352
|
const ownerAddr = signerState.address;
|
|
@@ -345,15 +355,25 @@ function CreateVerifyDelegationPipe({ type = "signature", delegationKey = "deleg
|
|
|
345
355
|
const forbiddenPkHex = forbiddenPk ? normalizePublicKeyHex(forbiddenPk) : "";
|
|
346
356
|
if (!coSigPkHex || forbiddenPkHex && coSigPkHex === forbiddenPkHex) return false;
|
|
347
357
|
if (!isFromPublicKey(ownerAddr, rawCoSig.pk)) return false;
|
|
358
|
+
const ownerType = toTypeInfo(ownerAddr);
|
|
359
|
+
const isOwnerPasskey = ownerType.role === types.RoleType.ROLE_PASSKEY || ownerType.pk === types.KeyType.PASSKEY;
|
|
360
|
+
const coSigExtra = rawCoSig.extra || "";
|
|
361
|
+
if (isOwnerPasskey && !coSigExtra) return false;
|
|
362
|
+
if (!isOwnerPasskey && coSigExtra) return false;
|
|
363
|
+
let wallet;
|
|
348
364
|
try {
|
|
349
|
-
|
|
350
|
-
for (const payload of candidatePayloads) {
|
|
351
|
-
if (await wallet.verify(payload, rawCoSig.signature, false)) return true;
|
|
352
|
-
if (await wallet.verify(payload, rawCoSig.signature, true)) return true;
|
|
353
|
-
}
|
|
365
|
+
wallet = fromPublicKey(rawCoSig.pk, ownerType);
|
|
354
366
|
} catch {
|
|
355
367
|
return false;
|
|
356
368
|
}
|
|
369
|
+
for (const payload of candidatePayloads) {
|
|
370
|
+
try {
|
|
371
|
+
if (await wallet.verify(payload, rawCoSig.signature, false, coSigExtra)) return true;
|
|
372
|
+
} catch {}
|
|
373
|
+
try {
|
|
374
|
+
if (await wallet.verify(payload, rawCoSig.signature, true, coSigExtra)) return true;
|
|
375
|
+
} catch {}
|
|
376
|
+
}
|
|
357
377
|
return false;
|
|
358
378
|
};
|
|
359
379
|
const getTxTimestampSeconds = () => {
|
|
@@ -424,6 +444,7 @@ function CreateVerifyDelegationPipe({ type = "signature", delegationKey = "deleg
|
|
|
424
444
|
const signerAddress = signerState?.address || tx?.from;
|
|
425
445
|
if (delegatorState && (tx?.delegator && !isSameDid(delegatorState.address, tx.delegator) || Array.isArray(delegatorState.migratedTo) && delegatorState.migratedTo.length > 0)) return next(new CustomError("ACCOUNT_MIGRATED", `Delegator account ${tx?.delegator} is migrated`, { persist: false }));
|
|
426
446
|
if (signerAddress && toTypeInfo(signerAddress).role === types.RoleType.ROLE_ASSET) {
|
|
447
|
+
if (hasExplicitCoSignatureInput()) return next(new CustomError("INVALID_SIGNATURE", "Unexpected owner coSignature on implicit asset delegation", { persist: false }));
|
|
427
448
|
try {
|
|
428
449
|
if (await verifyImplicitAssetOwnership(signerAddress, delegatorState || (tx?.delegator ? { address: tx.delegator } : null), context, tx?.delegator)) {
|
|
429
450
|
set(context, "isImplicitDelegation", true);
|
|
@@ -446,6 +467,8 @@ function CreateVerifyDelegationPipe({ type = "signature", delegationKey = "deleg
|
|
|
446
467
|
const coSignedByOwner = await verifyOwnerCoSignature(signerState);
|
|
447
468
|
const result = checkDelegation(delegationState, requirements, coSignedByOwner);
|
|
448
469
|
if (result.code) return next(new CustomError(result.code, `Delegation check failed: ${result.reason}`, { persist: false }));
|
|
470
|
+
const hasDelegatedMultiSig = getListField(tx, "signatures").some((x) => Boolean(x?.delegator));
|
|
471
|
+
if (hasExplicitCoSignatureInput() && !coSignedByOwner && !hasDelegatedMultiSig) return next(new CustomError("INVALID_SIGNATURE", "Invalid owner coSignature", { persist: false }));
|
|
449
472
|
if (coSignedByOwner) set(context, "coSignedByOwner", true);
|
|
450
473
|
set(context, delegationKey, delegationState);
|
|
451
474
|
set(context, "isDelegationChanged", true);
|
|
@@ -468,8 +491,8 @@ function CreateVerifyDelegationPipe({ type = "signature", delegationKey = "deleg
|
|
|
468
491
|
const { signer, delegator } = signature;
|
|
469
492
|
const sigRequirements = typeof getRequirements === "function" ? getRequirements(context, index, signature) || [] : [];
|
|
470
493
|
allRequirements.push(...sigRequirements);
|
|
471
|
-
const signerState = signerStates?.find((x) => signer &&
|
|
472
|
-
const delegatorState = delegatorStates?.find((x) => delegator && getRelatedAddresses(x).some((addr) => isSameDid(addr, delegator)));
|
|
494
|
+
const signerState = signerStates?.find((x) => Boolean(x && signer && getRelatedAddresses(x).some((addr) => isSameDid(addr, signer))));
|
|
495
|
+
const delegatorState = delegatorStates?.find((x) => Boolean(x && delegator && getRelatedAddresses(x).some((addr) => isSameDid(addr, delegator))));
|
|
473
496
|
if (delegatorState && (delegator && !isSameDid(delegatorState.address, delegator) || Array.isArray(delegatorState.migratedTo) && delegatorState.migratedTo.length > 0)) return next(new CustomError("ACCOUNT_MIGRATED", `Delegator account ${delegator} is migrated`, { persist: false }));
|
|
474
497
|
const signerAddress = signerState?.address || signer;
|
|
475
498
|
if (signerAddress && toTypeInfo(signerAddress).role === types.RoleType.ROLE_ASSET) {
|
|
@@ -498,6 +521,7 @@ function CreateVerifyDelegationPipe({ type = "signature", delegationKey = "deleg
|
|
|
498
521
|
if (coSignedByOwner) set(context, "coSignedByOwner", true);
|
|
499
522
|
if (!delegationStates.some((d) => isSameDid(d.address, delegationState.address))) delegationStates.push(delegationState);
|
|
500
523
|
}
|
|
524
|
+
if (hasExplicitCoSignatureInput() && !get(context, "coSignedByOwner")) return next(new CustomError("INVALID_SIGNATURE", "Invalid owner coSignature", { persist: false }));
|
|
501
525
|
set(context, requirementsKey, allRequirements);
|
|
502
526
|
set(context, delegationKey, delegationStates);
|
|
503
527
|
set(context, "isMultiSigDelegationVerified", true);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { assertEnvelopeMatchesTxContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra } from "../helpers/replay-guard.mjs";
|
|
1
|
+
import { assertEnvelopeMatchesTxContext, getBridgeWithdrawEnvelopeContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra } from "../helpers/replay-guard.mjs";
|
|
2
2
|
import { name } from "../package.mjs";
|
|
3
3
|
import { unwrapOpaqueAnyData } from "../helpers/unwrap-opaque-any.mjs";
|
|
4
4
|
import { encodeTxByEncoding } from "../helpers/encode-tx-by-context.mjs";
|
|
5
5
|
import { types } from "@ocap/mcrypto";
|
|
6
6
|
import { CustomError } from "@ocap/util/lib/error";
|
|
7
|
-
import
|
|
7
|
+
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
8
8
|
import { decodeAny } from "@ocap/message";
|
|
9
9
|
import { getListField, setListField } from "@ocap/util/lib/get-list-field";
|
|
10
|
+
import get from "lodash/get.js";
|
|
10
11
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
11
12
|
import omit from "lodash/omit.js";
|
|
12
13
|
import Debug from "debug";
|
|
13
|
-
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
14
14
|
import { fromPublicKey } from "@ocap/wallet";
|
|
15
15
|
|
|
16
16
|
//#region src/pipes/verify-multisig-v2.ts
|
|
@@ -66,7 +66,8 @@ function CreateVerifyMultiSigV2Pipe({ signersKey }) {
|
|
|
66
66
|
signer: address,
|
|
67
67
|
from: signer,
|
|
68
68
|
nonce: tx.nonce,
|
|
69
|
-
action: context.txType
|
|
69
|
+
action: context.txType,
|
|
70
|
+
withdraw: await getBridgeWithdrawEnvelopeContext(context)
|
|
70
71
|
});
|
|
71
72
|
if (await wallet.verify(txBytes, signature, true, verifiedExtra) === false) return next(new CustomError("INVALID_SIGNATURE", `Signature for ${address} is not valid`));
|
|
72
73
|
} catch (err) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { assertEnvelopeMatchesTxContext, isCanonicalPasskeyExtra, isCanonicalWalletEnvelopeExtra } from "../helpers/replay-guard.mjs";
|
|
1
|
+
import { assertEnvelopeMatchesTxContext, getBridgeWithdrawEnvelopeContext, 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
4
|
import { types } from "@ocap/mcrypto";
|
|
5
5
|
import { CustomError } from "@ocap/util/lib/error";
|
|
6
|
-
import
|
|
6
|
+
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
7
7
|
import { decodeAny } from "@ocap/message";
|
|
8
8
|
import { deleteListField, getListField, setListField } from "@ocap/util/lib/get-list-field";
|
|
9
|
+
import get from "lodash/get.js";
|
|
9
10
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
10
|
-
import { isFromPublicKey, toTypeInfo } from "@arcblock/did";
|
|
11
11
|
import { fromPublicKey } from "@ocap/wallet";
|
|
12
12
|
|
|
13
13
|
//#region src/pipes/verify-multisig.ts
|
|
@@ -45,7 +45,8 @@ function CreateVerifyMultiSigPipe(numSigs = 0) {
|
|
|
45
45
|
signer: address,
|
|
46
46
|
from: signer,
|
|
47
47
|
nonce: tx.nonce,
|
|
48
|
-
action: context.txType
|
|
48
|
+
action: context.txType,
|
|
49
|
+
withdraw: await getBridgeWithdrawEnvelopeContext(context)
|
|
49
50
|
});
|
|
50
51
|
if (await wallet.verify(txBytes, signature, true, extra) === false) return next(new CustomError("INVALID_SIGNATURE", `Multi signature for ${address} is not valid`));
|
|
51
52
|
} catch (err) {
|
|
@@ -2,6 +2,12 @@ import { CustomError } from "@ocap/util/lib/error";
|
|
|
2
2
|
import { IDecodedContext } from "@ocap/types";
|
|
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 };
|