@ocap/tx-protocols 1.30.26 → 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/execute.d.mts +11 -2
- package/esm/execute.mjs +724 -80
- package/esm/gas-security-guard.d.mts +375 -0
- package/esm/gas-security-guard.mjs +1103 -0
- package/esm/index.d.mts +36 -6
- package/esm/index.mjs +4 -2
- package/esm/pipes/ensure-cost.mjs +335 -59
- package/esm/protocols/account/delegate.mjs +64 -16
- package/esm/protocols/account/migrate.d.mts +3 -0
- package/esm/protocols/account/migrate.mjs +235 -35
- package/esm/protocols/account/revoke-delegate.d.mts +3 -3
- package/esm/protocols/account/revoke-delegate.mjs +70 -38
- package/esm/protocols/asset/acquire-v2.mjs +29 -12
- package/esm/protocols/asset/acquire-v3.mjs +78 -22
- package/esm/protocols/asset/calls/transfer-token.mjs +2 -1
- package/esm/protocols/asset/calls/transfer.mjs +1 -0
- package/esm/protocols/asset/consume.mjs +12 -4
- package/esm/protocols/asset/create.mjs +18 -5
- package/esm/protocols/asset/mint.mjs +23 -1
- package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +21 -1
- package/esm/protocols/asset/pipes/exec-mint-hook.mjs +115 -1
- package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +14 -8
- package/esm/protocols/asset/pipes/verify-itx-address.mjs +9 -0
- package/esm/protocols/asset/pipes/verify-itx-assets.mjs +21 -5
- package/esm/protocols/asset/update.d.mts +13 -2
- package/esm/protocols/asset/update.mjs +133 -14
- package/esm/protocols/factory/create.mjs +14 -6
- package/esm/protocols/governance/claim-stake.mjs +115 -11
- package/esm/protocols/governance/return-stake.mjs +44 -12
- package/esm/protocols/governance/revoke-ledger.d.mts +34 -0
- package/esm/protocols/governance/revoke-ledger.mjs +179 -0
- package/esm/protocols/governance/revoke-stake.mjs +25 -5
- package/esm/protocols/governance/slash-stake.mjs +72 -25
- package/esm/protocols/governance/stake.mjs +63 -13
- package/esm/protocols/rollup/claim-reward.mjs +39 -20
- package/esm/protocols/rollup/close.mjs +1 -1
- package/esm/protocols/rollup/create-block.mjs +8 -7
- package/esm/protocols/rollup/create.mjs +17 -6
- package/esm/protocols/rollup/join.mjs +3 -3
- package/esm/protocols/rollup/leave.mjs +1 -1
- package/esm/protocols/rollup/migrate.mjs +7 -4
- package/esm/protocols/rollup/pipes/verify-evidence.mjs +12 -4
- package/esm/protocols/rollup/update.mjs +6 -1
- package/esm/protocols/token/create.mjs +23 -12
- package/esm/protocols/token/deposit-v2.d.mts +5 -1
- package/esm/protocols/token/deposit-v2.mjs +81 -29
- package/esm/protocols/token/withdraw-v2.mjs +33 -16
- package/esm/protocols/token-factory/burn.mjs +43 -10
- package/esm/protocols/token-factory/create.mjs +23 -14
- package/esm/protocols/token-factory/mint.mjs +54 -21
- package/esm/protocols/token-factory/pipes/verify-icon.mjs +1 -1
- package/esm/protocols/token-factory/update.mjs +16 -6
- package/esm/protocols/trade/exchange-v2.d.mts +4 -0
- package/esm/protocols/trade/exchange-v2.mjs +78 -22
- package/esm/protocols/trade/transfer-v2.mjs +44 -13
- package/esm/protocols/trade/transfer-v3.mjs +72 -31
- package/esm/util.d.mts +3 -1
- package/esm/util.mjs +26 -17
- package/lib/execute.cjs +724 -76
- package/lib/execute.d.cts +11 -2
- package/lib/gas-security-guard.cjs +1142 -0
- package/lib/gas-security-guard.d.cts +375 -0
- package/lib/index.cjs +124 -1
- package/lib/index.d.cts +37 -7
- package/lib/pipes/ensure-cost.cjs +334 -58
- package/lib/protocols/account/delegate.cjs +64 -16
- package/lib/protocols/account/migrate.cjs +235 -35
- package/lib/protocols/account/migrate.d.cts +3 -0
- package/lib/protocols/account/revoke-delegate.cjs +71 -39
- package/lib/protocols/account/revoke-delegate.d.cts +3 -3
- package/lib/protocols/asset/acquire-v2.cjs +28 -11
- package/lib/protocols/asset/acquire-v3.cjs +77 -20
- package/lib/protocols/asset/calls/transfer-token.cjs +3 -2
- package/lib/protocols/asset/calls/transfer.cjs +1 -0
- package/lib/protocols/asset/consume.cjs +11 -3
- package/lib/protocols/asset/create.cjs +19 -6
- package/lib/protocols/asset/mint.cjs +23 -1
- package/lib/protocols/asset/pipes/exec-mint-hook.cjs +117 -1
- package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +21 -1
- package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +14 -9
- package/lib/protocols/asset/pipes/verify-itx-address.cjs +9 -0
- package/lib/protocols/asset/pipes/verify-itx-assets.cjs +21 -5
- package/lib/protocols/asset/update.cjs +131 -12
- package/lib/protocols/asset/update.d.cts +13 -2
- package/lib/protocols/factory/create.cjs +14 -6
- package/lib/protocols/governance/claim-stake.cjs +115 -10
- package/lib/protocols/governance/claim-stake.d.cts +1 -1
- package/lib/protocols/governance/return-stake.cjs +44 -11
- package/lib/protocols/governance/return-stake.d.cts +1 -1
- package/lib/protocols/governance/revoke-ledger.cjs +184 -0
- package/lib/protocols/governance/revoke-ledger.d.cts +34 -0
- package/lib/protocols/governance/revoke-stake.cjs +25 -5
- package/lib/protocols/governance/revoke-stake.d.cts +1 -1
- package/lib/protocols/governance/slash-stake.cjs +72 -24
- package/lib/protocols/governance/slash-stake.d.cts +1 -1
- package/lib/protocols/governance/stake.cjs +65 -14
- package/lib/protocols/rollup/claim-reward.cjs +39 -20
- package/lib/protocols/rollup/close.cjs +1 -1
- package/lib/protocols/rollup/create-block.cjs +9 -8
- package/lib/protocols/rollup/create-block.d.cts +1 -1
- package/lib/protocols/rollup/create.cjs +18 -7
- package/lib/protocols/rollup/join.cjs +3 -3
- package/lib/protocols/rollup/leave.cjs +1 -1
- package/lib/protocols/rollup/migrate.cjs +7 -4
- package/lib/protocols/rollup/pipes/verify-evidence.cjs +11 -3
- package/lib/protocols/rollup/update.cjs +6 -1
- package/lib/protocols/token/create.cjs +24 -13
- package/lib/protocols/token/deposit-v2.cjs +80 -28
- package/lib/protocols/token/deposit-v2.d.cts +5 -1
- package/lib/protocols/token/withdraw-v2.cjs +32 -15
- package/lib/protocols/token-factory/burn.cjs +42 -9
- package/lib/protocols/token-factory/create.cjs +24 -15
- package/lib/protocols/token-factory/mint.cjs +53 -20
- package/lib/protocols/token-factory/pipes/verify-icon.cjs +1 -1
- package/lib/protocols/token-factory/update.cjs +16 -6
- package/lib/protocols/trade/exchange-v2.cjs +76 -20
- package/lib/protocols/trade/exchange-v2.d.cts +4 -0
- package/lib/protocols/trade/transfer-v2.cjs +45 -14
- package/lib/protocols/trade/transfer-v3.cjs +72 -30
- package/lib/util.cjs +26 -17
- package/lib/util.d.cts +4 -2
- package/package.json +16 -16
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { IChainConfig, IStakeState } from "@ocap/types";
|
|
2
|
+
import { BN } from "@ocap/util";
|
|
3
|
+
|
|
4
|
+
//#region src/gas-security-guard.d.ts
|
|
5
|
+
declare const DEFAULT_MAX_FREE_GAS_TX_SIZE = 4096;
|
|
6
|
+
declare const DEFAULT_MAX_FREE_GAS_STATE_OPS = 6;
|
|
7
|
+
declare const DEFAULT_BURST_WINDOW_MS = 60000;
|
|
8
|
+
declare const DEFAULT_BASE_BURST_ALLOWANCE = 10;
|
|
9
|
+
declare const DEFAULT_BURST_REJECT_MULTIPLE = 100;
|
|
10
|
+
declare const DEFAULT_DELEGATED_BURST_MULTIPLE = 20;
|
|
11
|
+
declare const DEFAULT_STRIKE_WINDOW_MS = 600000;
|
|
12
|
+
declare const DEFAULT_WARNING_STRIKE_THRESHOLD = 2;
|
|
13
|
+
declare const DEFAULT_THROTTLE_STRIKE_THRESHOLD = 5;
|
|
14
|
+
declare const DEFAULT_SLASH_STRIKE_THRESHOLD = 10;
|
|
15
|
+
declare const DEFAULT_THROTTLE_COOLDOWN_MS = 15000;
|
|
16
|
+
declare const DEFAULT_GAS_PASS_EPOCH_SECONDS = 60;
|
|
17
|
+
declare const DEFAULT_FISHERMAN_BOUNTY_BPS = 1000;
|
|
18
|
+
/**
|
|
19
|
+
* High-overhead creator, factory, token-issuance, rollup, and batch transaction types
|
|
20
|
+
* that ALWAYS require direct gas payment (`requiresDirectGas: true`) and cannot waive
|
|
21
|
+
* gas via self-staked `Stake-for-Gas` or Unlinkable Gas Pass.
|
|
22
|
+
*/
|
|
23
|
+
declare const DIRECT_GAS_REQUIRED_TX_TYPES: ReadonlySet<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Everyday end-user transaction types eligible for `Stake-for-Gas` free gas waiver
|
|
26
|
+
* when within the 3D envelope (`txType` allowlist + `txSize <= 4096` + `stateOps <= 6`).
|
|
27
|
+
*/
|
|
28
|
+
declare const FREE_GAS_ELIGIBLE_TX_TYPES: ReadonlySet<string>;
|
|
29
|
+
type SecurityStrikeTier = 'NORMAL' | 'WARNING' | 'THROTTLED' | 'SLASH_TRIGGERED';
|
|
30
|
+
type StrikeReasonCategory = 'WAF_REJECT' | 'INVARIANT_VIOLATION' | 'PROTOCOL_REJECT' | 'QUOTA_EXCEEDED' | 'BENIGN_REJECT' | 'PAYMASTER_VIOLATION';
|
|
31
|
+
interface ITxGasQuotaTelemetry {
|
|
32
|
+
loadRatio: number;
|
|
33
|
+
remainingNormalQuota: number;
|
|
34
|
+
currentGasMultiplier: number;
|
|
35
|
+
nextTxEstimatedGas: string;
|
|
36
|
+
recommendedBackoffMs: number;
|
|
37
|
+
stakeRequiredFor1x: string;
|
|
38
|
+
}
|
|
39
|
+
interface ITxSecurityWarning {
|
|
40
|
+
tier: SecurityStrikeTier;
|
|
41
|
+
code: string;
|
|
42
|
+
message: string;
|
|
43
|
+
actor: string;
|
|
44
|
+
strikeCount: number;
|
|
45
|
+
warningThreshold: number;
|
|
46
|
+
throttleThreshold: number;
|
|
47
|
+
slashThreshold: number;
|
|
48
|
+
gasStakeQuotaRemaining: number;
|
|
49
|
+
cooldownUntilMs: number;
|
|
50
|
+
telemetry: ITxGasQuotaTelemetry;
|
|
51
|
+
}
|
|
52
|
+
interface IAbuseSlashEvidence {
|
|
53
|
+
evidenceHash: string;
|
|
54
|
+
offender: string;
|
|
55
|
+
stakeAddress: string;
|
|
56
|
+
strikeCount: number;
|
|
57
|
+
reasonCodes: string[];
|
|
58
|
+
recentTxHashes: string[];
|
|
59
|
+
slashedTokens: Record<string, string>;
|
|
60
|
+
fishermanAddress?: string;
|
|
61
|
+
fishermanBounty: string;
|
|
62
|
+
vaultDestination: string;
|
|
63
|
+
vaultAmount: string;
|
|
64
|
+
timestamp: string;
|
|
65
|
+
}
|
|
66
|
+
interface IUnlinkableGasPass {
|
|
67
|
+
stakeId: string;
|
|
68
|
+
epoch: number;
|
|
69
|
+
nullifier: string;
|
|
70
|
+
commitment: string;
|
|
71
|
+
passSecret?: string;
|
|
72
|
+
pk?: string;
|
|
73
|
+
signature?: string;
|
|
74
|
+
}
|
|
75
|
+
interface IPaymasterDecodedClaims {
|
|
76
|
+
iss?: string;
|
|
77
|
+
txHash?: string;
|
|
78
|
+
exp?: number | string;
|
|
79
|
+
nbf?: number | string;
|
|
80
|
+
iat?: number | string;
|
|
81
|
+
allowedTargets?: string[];
|
|
82
|
+
allowedTxTypes?: string[];
|
|
83
|
+
maxGasPerTx?: string | number;
|
|
84
|
+
mode?: 'waiver' | 'paymaster';
|
|
85
|
+
chargeSponsorBalance?: boolean;
|
|
86
|
+
}
|
|
87
|
+
interface IGasSecurityConfig {
|
|
88
|
+
/** Master switch (`transaction.security.enabled`); false disables strikes, throttle, burst quota and slash */
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
/** Strike-based expiring admission cooldown */
|
|
91
|
+
throttle: boolean;
|
|
92
|
+
/** Per-sender burst quota enforced at admission (never reprices gas) */
|
|
93
|
+
burstEscalation: boolean;
|
|
94
|
+
/** Experimental: slash inside the failing queued tx's own write set */
|
|
95
|
+
autoSlash: boolean;
|
|
96
|
+
/** Process-local gas pass nullifier registry (non-deterministic across processes) */
|
|
97
|
+
gasPassNullifierCheck: boolean;
|
|
98
|
+
burstRejectMultiple: number;
|
|
99
|
+
/** Normalized addresses never struck, throttled or burst-limited (operators' own infrastructure) */
|
|
100
|
+
exemptActors: string[];
|
|
101
|
+
/** Aggregate per-delegatee cap across all principals = hard limit x this */
|
|
102
|
+
delegatedBurstMultiple: number;
|
|
103
|
+
maxFreeGasTxSize: number;
|
|
104
|
+
maxFreeGasStateOps: number;
|
|
105
|
+
burstWindowMs: number;
|
|
106
|
+
baseBurstAllowance: number;
|
|
107
|
+
strikeWindowMs: number;
|
|
108
|
+
warningThreshold: number;
|
|
109
|
+
throttleThreshold: number;
|
|
110
|
+
slashThreshold: number;
|
|
111
|
+
throttleCooldownMs: number;
|
|
112
|
+
gasPassEpochSeconds: number;
|
|
113
|
+
fishermanBountyBps: number;
|
|
114
|
+
}
|
|
115
|
+
interface IStrikeEvent {
|
|
116
|
+
timestampMs: number;
|
|
117
|
+
weight: number;
|
|
118
|
+
code: string;
|
|
119
|
+
txHash?: string;
|
|
120
|
+
}
|
|
121
|
+
interface IActorSecurityRecord {
|
|
122
|
+
actor: string;
|
|
123
|
+
bursts: Array<{
|
|
124
|
+
t: number;
|
|
125
|
+
h?: string;
|
|
126
|
+
variants?: string[];
|
|
127
|
+
}>;
|
|
128
|
+
strikes: IStrikeEvent[];
|
|
129
|
+
cooldownUntilMs: number;
|
|
130
|
+
lastSlashEvidence?: IAbuseSlashEvidence;
|
|
131
|
+
lastWarning?: ITxSecurityWarning;
|
|
132
|
+
}
|
|
133
|
+
interface IConsumedNullifierEntry {
|
|
134
|
+
epoch: number;
|
|
135
|
+
txHash: string;
|
|
136
|
+
}
|
|
137
|
+
interface IGasSecurityRegistry {
|
|
138
|
+
actors: Map<string, IActorSecurityRecord>;
|
|
139
|
+
consumedNullifiers: Map<string, Map<string, IConsumedNullifierEntry>>;
|
|
140
|
+
txWarningsByHash: Map<string, ITxSecurityWarning>;
|
|
141
|
+
}
|
|
142
|
+
declare function getGasSecurityRegistry(statedb?: unknown): IGasSecurityRegistry;
|
|
143
|
+
declare function resetGasSecurityState(statedb?: unknown): void;
|
|
144
|
+
declare function normalizeActorAddress(raw: unknown): string;
|
|
145
|
+
declare function normalizeShortTxType(txType: unknown): string;
|
|
146
|
+
declare function resolveGasSecurityConfig(config?: Partial<IChainConfig>): IGasSecurityConfig;
|
|
147
|
+
interface IStakeForGasEligibilityResult {
|
|
148
|
+
eligible: boolean;
|
|
149
|
+
reason?: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 3D `Stake-for-Gas` Eligibility Gate:
|
|
153
|
+
* 1. `txType` must be in `FREE_GAS_ELIGIBLE_TX_TYPES` (everyday user actions only).
|
|
154
|
+
* 2. `txSize` must be <= `maxFreeGasTxSize` (default 4096 bytes).
|
|
155
|
+
* 3. `stateOps` (`estimate.create + estimate.update`) must be <= `maxFreeGasStateOps` (default 6).
|
|
156
|
+
* 4. Failed transactions (`isFailedTxGasCharge === true`) NEVER waive gas.
|
|
157
|
+
*/
|
|
158
|
+
declare function evaluateStakeForGasEligibility(params: {
|
|
159
|
+
txType?: string;
|
|
160
|
+
txSize?: number;
|
|
161
|
+
gasEstimate?: {
|
|
162
|
+
create?: number;
|
|
163
|
+
update?: number;
|
|
164
|
+
};
|
|
165
|
+
isFailedTxGasCharge?: boolean;
|
|
166
|
+
isThirdPartySponsor?: boolean;
|
|
167
|
+
enforceSponsor3DEligibility?: boolean;
|
|
168
|
+
config?: Partial<IChainConfig>;
|
|
169
|
+
}): IStakeForGasEligibilityResult;
|
|
170
|
+
/**
|
|
171
|
+
* Extracts all target DIDs referenced by a transaction (`itx.to`, `itx.factory`, `itx.tokenFactory`,
|
|
172
|
+
* `itx.address`, `itx.assets`, `itx.inputs`, `itx.outputs`, `itx.sender`, `itx.receiver`) for
|
|
173
|
+
* Paymaster `allowedTargets` scoping.
|
|
174
|
+
*/
|
|
175
|
+
declare function extractTransactionTargets(tx: Record<string, unknown> | undefined, decodedItx?: Record<string, unknown> | undefined, txType?: string): string[];
|
|
176
|
+
/**
|
|
177
|
+
* Verifies Merchant / DApp Paymaster (`extra.gasStakeHeaders` JWT) scope constraints:
|
|
178
|
+
* - `allowedTxTypes`: if present, transaction type must be in `allowedTxTypes`.
|
|
179
|
+
* - `allowedTargets`: if present, transaction must touch at least one target and EVERY target
|
|
180
|
+
* touched by the transaction (excluding the sender `tx.from` itself in multi-input change)
|
|
181
|
+
* must be in `allowedTargets`.
|
|
182
|
+
* - `maxGasPerTx`: if present, `totalGas` must not exceed `maxGasPerTx`.
|
|
183
|
+
*/
|
|
184
|
+
declare function verifyPaymasterConstraints(params: {
|
|
185
|
+
decoded: IPaymasterDecodedClaims;
|
|
186
|
+
tx?: Record<string, unknown>;
|
|
187
|
+
itx?: Record<string, unknown>;
|
|
188
|
+
txType?: string;
|
|
189
|
+
totalGas?: BN;
|
|
190
|
+
}): {
|
|
191
|
+
valid: boolean;
|
|
192
|
+
reason?: string;
|
|
193
|
+
isPaymasterDirectCharge: boolean;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Computes the SHA-256 hash of a stake owner's secret for Unlinkable Gas Pass verification:
|
|
197
|
+
* `SHA256("ocap:gas-pass-secret:v1:" + passSecret)`
|
|
198
|
+
*/
|
|
199
|
+
declare function computeUnlinkableGasPassSecretHash(passSecret: string): string;
|
|
200
|
+
/**
|
|
201
|
+
* Computes the deterministic commitment for a Consumer Self-Use Unlinkable Gas Pass:
|
|
202
|
+
* `SHA256("ocap:gas-pass:v1:" + normalizeActorAddress(stakeId) + ":" + epoch + ":" + nullifier + ":" + txHash)`
|
|
203
|
+
*/
|
|
204
|
+
declare function computeUnlinkableGasPassCommitment(params: {
|
|
205
|
+
stakeId: string;
|
|
206
|
+
epoch: number;
|
|
207
|
+
nullifier: string;
|
|
208
|
+
txHash: string;
|
|
209
|
+
}): string;
|
|
210
|
+
/**
|
|
211
|
+
* Verifies and consumes a Consumer Self-Use Unlinkable Gas Pass (`extra.gasPass`),
|
|
212
|
+
* allowing a user who staked ABT on their main DID to pay/waive gas from a fresh
|
|
213
|
+
* unlinked sub-DID without revealing their main DID on-chain in `tx.from`, while
|
|
214
|
+
* strictly enforcing cryptographic authorization (`passSecret` matching `stakeState.gasPassSecretHash`
|
|
215
|
+
* or `pk`+`signature` signed by `stakeState.sender`), `nullifier` single-use per epoch, and
|
|
216
|
+
* stake-proportional quota.
|
|
217
|
+
*/
|
|
218
|
+
declare function verifyAndConsumeUnlinkableGasPass(params: {
|
|
219
|
+
gasPass: IUnlinkableGasPass;
|
|
220
|
+
stakeState: IStakeState | null | undefined;
|
|
221
|
+
txHash: string;
|
|
222
|
+
nowMs?: number;
|
|
223
|
+
config: IChainConfig;
|
|
224
|
+
statedb?: unknown;
|
|
225
|
+
consumeNullifier?: boolean;
|
|
226
|
+
}): {
|
|
227
|
+
valid: boolean;
|
|
228
|
+
reason?: string;
|
|
229
|
+
stakeId?: string;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Stake-scaled per-sender burst quota (`rho = n_burst / B_normal(S)`) with machine-readable telemetry.
|
|
233
|
+
*
|
|
234
|
+
* RELIABILITY CONTRACT: the counter is process-local, so it is used for ADMISSION only (reject before the
|
|
235
|
+
* single-writer queue). It never reprices gas, never changes a waiver and never touches receipts; the executed
|
|
236
|
+
* outcome of a tx is a pure function of (tx, on-chain state). A request is rejected only above
|
|
237
|
+
* `baseBurstAllowance * stakeMultiple * burstRejectMultiple` (`hardLimitExceeded`); between 1x and the hard limit
|
|
238
|
+
* it is admitted and only advisory telemetry is returned (`quotaExceeded`).
|
|
239
|
+
*/
|
|
240
|
+
declare function evaluateBurstQuota(params: {
|
|
241
|
+
actor: string;
|
|
242
|
+
stakeState?: IStakeState | null;
|
|
243
|
+
baseGas?: BN;
|
|
244
|
+
config: IChainConfig;
|
|
245
|
+
statedb?: unknown;
|
|
246
|
+
nowMs?: number;
|
|
247
|
+
txHash?: string;
|
|
248
|
+
/** Actual (signed) tx hash when `txHash` is the unsigned hash shared by signature variants */
|
|
249
|
+
variantHash?: string;
|
|
250
|
+
/** Overrides `burstRejectMultiple` for the hard limit (aggregate delegatee window) */
|
|
251
|
+
rejectMultiple?: number;
|
|
252
|
+
/** Record this request in the sliding window (default true); rejected requests are never recorded */
|
|
253
|
+
recordBurst?: boolean;
|
|
254
|
+
}): {
|
|
255
|
+
burstCount: number;
|
|
256
|
+
normalAllowance: number;
|
|
257
|
+
hardLimit: number;
|
|
258
|
+
loadRatio: number;
|
|
259
|
+
quotaExceeded: boolean;
|
|
260
|
+
hardLimitExceeded: boolean;
|
|
261
|
+
telemetry: ITxGasQuotaTelemetry;
|
|
262
|
+
};
|
|
263
|
+
declare function classifyErrorStrikeCategory(err: {
|
|
264
|
+
code?: string;
|
|
265
|
+
message?: string;
|
|
266
|
+
} | undefined): {
|
|
267
|
+
shouldRecordStrike: boolean;
|
|
268
|
+
category: StrikeReasonCategory;
|
|
269
|
+
code: string;
|
|
270
|
+
};
|
|
271
|
+
declare function computeActorTier(strikeCount: number, cfg: IGasSecurityConfig): SecurityStrikeTier;
|
|
272
|
+
declare function getActorSecurityStatus(params: {
|
|
273
|
+
actor: string;
|
|
274
|
+
config?: Partial<IChainConfig>;
|
|
275
|
+
statedb?: unknown;
|
|
276
|
+
nowMs?: number;
|
|
277
|
+
telemetry?: ITxGasQuotaTelemetry;
|
|
278
|
+
}): {
|
|
279
|
+
strikeCount: number;
|
|
280
|
+
tier: SecurityStrikeTier;
|
|
281
|
+
cooldownUntilMs: number;
|
|
282
|
+
lastSlashEvidence?: IAbuseSlashEvidence;
|
|
283
|
+
warning?: ITxSecurityWarning;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Resolves the list of cryptographically verified actor addresses that may be penalized
|
|
287
|
+
* with a security strike for a failed or rejected transaction:
|
|
288
|
+
* - Never attributes strikes to `tx.from` or `tx.delegator` unless `VerifySignature` has
|
|
289
|
+
* cryptographically verified the transaction signature (`CRITICAL-2` protection).
|
|
290
|
+
* - When `tx.delegator` is present, attributes strikes ONLY to `tx.delegator` (the verified signer / delegatee),
|
|
291
|
+
* never to the principal `tx.from`, whether or not the delegation verified.
|
|
292
|
+
* - Never attributes sender-induced strikes to a third-party `gasStake.owner` (`CRITICAL-3`).
|
|
293
|
+
*/
|
|
294
|
+
declare function resolveVerifiedStrikeActors(ctx: Record<string, unknown> | undefined): Promise<string[]>;
|
|
295
|
+
/**
|
|
296
|
+
* Records a weighted security strike against one or more verified actor addresses,
|
|
297
|
+
* updates their tier (`NORMAL` -> `WARNING` -> `THROTTLED` -> `SLASH_TRIGGERED`), and if `SLASH_TRIGGERED` is reached,
|
|
298
|
+
* executes automatic `Stake-for-Gas` slashing into `config.vaults.slashedStake` (with optional Fisherman bounty split
|
|
299
|
+
* and 0% token burn per Axiom #3).
|
|
300
|
+
*/
|
|
301
|
+
declare function recordActorSecurityStrike(params: {
|
|
302
|
+
actors: string[];
|
|
303
|
+
category: StrikeReasonCategory;
|
|
304
|
+
reasonCode: string;
|
|
305
|
+
txHash?: string;
|
|
306
|
+
config?: Partial<IChainConfig>;
|
|
307
|
+
statedb?: unknown;
|
|
308
|
+
txn?: unknown;
|
|
309
|
+
fishermanAddress?: string;
|
|
310
|
+
nowMs?: number;
|
|
311
|
+
telemetry?: ITxGasQuotaTelemetry;
|
|
312
|
+
}): Promise<{
|
|
313
|
+
primaryWarning?: ITxSecurityWarning;
|
|
314
|
+
slashEvidence?: IAbuseSlashEvidence;
|
|
315
|
+
}>;
|
|
316
|
+
interface IActorSecuritySnapshot {
|
|
317
|
+
actors: Map<string, IActorSecurityRecord | null>;
|
|
318
|
+
txWarningExisted?: boolean;
|
|
319
|
+
prevTxWarning?: ITxSecurityWarning;
|
|
320
|
+
txHash?: string;
|
|
321
|
+
}
|
|
322
|
+
declare function snapshotActorSecurityRecords(actors: string[], statedb?: unknown, txHash?: string): IActorSecuritySnapshot;
|
|
323
|
+
declare function restoreActorSecurityRecords(snapshot: IActorSecuritySnapshot, statedb?: unknown): void;
|
|
324
|
+
/**
|
|
325
|
+
* Executes automatic `Stake-for-Gas` slashing when an actor crosses `slashThreshold` (opt-in via
|
|
326
|
+
* `transaction.security.autoSlash`; ONLY inside the enclosing queued tx's own write set, `params.txn` is required):
|
|
327
|
+
* - Transfers 100% of the offender's staked official tokens out of `toStakeAddress(offender, offender)`:
|
|
328
|
+
* - `fishermanBountyBps` (default 10%) to `fishermanAddress` (if provided and distinct from `offender`).
|
|
329
|
+
* - Remaining 90% (or 100% if no fisherman) to `config.vaults.slashedStake` (or `config.vaults.txGas[0]` / `config.vaults.txFee`).
|
|
330
|
+
* - ZERO official tokens are ever burned (Axiom #3).
|
|
331
|
+
* - Creates and persists a deterministic `IAbuseSlashEvidence` record in `statedb.evidence`.
|
|
332
|
+
*/
|
|
333
|
+
declare function executeAutoGasStakeSlash(params: {
|
|
334
|
+
offender: string;
|
|
335
|
+
strikeCount: number;
|
|
336
|
+
strikes: IStrikeEvent[];
|
|
337
|
+
config?: Partial<IChainConfig>;
|
|
338
|
+
statedb?: unknown;
|
|
339
|
+
txn?: unknown;
|
|
340
|
+
fishermanAddress?: string;
|
|
341
|
+
nowMs?: number;
|
|
342
|
+
}): Promise<IAbuseSlashEvidence | null>;
|
|
343
|
+
/**
|
|
344
|
+
* Pre-queue ADMISSION control. This is the only consumer of the process-local strike / burst counters:
|
|
345
|
+
* it decides whether a request is accepted into the single-writer queue at all. It never changes the gas,
|
|
346
|
+
* waiver or receipts of a tx that is admitted, so executed outcomes stay a pure function of (tx, chain state)
|
|
347
|
+
* and cannot diverge between the two OS processes on main or across restarts.
|
|
348
|
+
*
|
|
349
|
+
* - `throttle`: the verified signer (`tx.delegator || tx.from`, i.e. the delegatee for delegated txs) is rejected
|
|
350
|
+
* with `TOO_MANY_TXS` while its strike-driven cooldown is active. Cooldowns always expire; actors without any
|
|
351
|
+
* strikes (and actors without stake) are never locked.
|
|
352
|
+
* - `burstEscalation`: the per-sender sliding-window quota rejects with `TOO_MANY_TXS` only above
|
|
353
|
+
* `baseBurstAllowance * stakeMultiple * burstRejectMultiple`. Keyed by the sender, never by the gas sponsor, so a
|
|
354
|
+
* sponsoring app is not capped across all of its users.
|
|
355
|
+
*/
|
|
356
|
+
declare function assertTxAdmission(params: {
|
|
357
|
+
tx: {
|
|
358
|
+
from?: string;
|
|
359
|
+
delegator?: string;
|
|
360
|
+
nonce?: unknown;
|
|
361
|
+
} | undefined;
|
|
362
|
+
txHash?: string;
|
|
363
|
+
/** Hash of the tx without signatures: all signature-malleated twins of one logical tx share it */
|
|
364
|
+
unsignedTxHash?: string;
|
|
365
|
+
config?: Partial<IChainConfig>;
|
|
366
|
+
statedb?: unknown;
|
|
367
|
+
nowMs?: number;
|
|
368
|
+
}): Promise<{
|
|
369
|
+
telemetry?: ITxGasQuotaTelemetry;
|
|
370
|
+
warning?: ITxSecurityWarning;
|
|
371
|
+
}>;
|
|
372
|
+
declare function getTxSecurityWarningByHash(txHash: string, statedb?: unknown): ITxSecurityWarning | undefined;
|
|
373
|
+
declare function setTxSecurityWarningForHash(txHash: string, warning: ITxSecurityWarning, statedb?: unknown): void;
|
|
374
|
+
//#endregion
|
|
375
|
+
export { DEFAULT_BASE_BURST_ALLOWANCE, DEFAULT_BURST_REJECT_MULTIPLE, DEFAULT_BURST_WINDOW_MS, DEFAULT_DELEGATED_BURST_MULTIPLE, DEFAULT_FISHERMAN_BOUNTY_BPS, DEFAULT_GAS_PASS_EPOCH_SECONDS, DEFAULT_MAX_FREE_GAS_STATE_OPS, DEFAULT_MAX_FREE_GAS_TX_SIZE, DEFAULT_SLASH_STRIKE_THRESHOLD, DEFAULT_STRIKE_WINDOW_MS, DEFAULT_THROTTLE_COOLDOWN_MS, DEFAULT_THROTTLE_STRIKE_THRESHOLD, DEFAULT_WARNING_STRIKE_THRESHOLD, DIRECT_GAS_REQUIRED_TX_TYPES, FREE_GAS_ELIGIBLE_TX_TYPES, IAbuseSlashEvidence, IActorSecuritySnapshot, IGasSecurityConfig, IPaymasterDecodedClaims, IStakeForGasEligibilityResult, ITxGasQuotaTelemetry, ITxSecurityWarning, IUnlinkableGasPass, SecurityStrikeTier, StrikeReasonCategory, assertTxAdmission, classifyErrorStrikeCategory, computeActorTier, computeUnlinkableGasPassCommitment, computeUnlinkableGasPassSecretHash, evaluateBurstQuota, evaluateStakeForGasEligibility, executeAutoGasStakeSlash, extractTransactionTargets, getActorSecurityStatus, getGasSecurityRegistry, getTxSecurityWarningByHash, normalizeActorAddress, normalizeShortTxType, recordActorSecurityStrike, resetGasSecurityState, resolveGasSecurityConfig, resolveVerifiedStrikeActors, restoreActorSecurityRecords, setTxSecurityWarningForHash, snapshotActorSecurityRecords, verifyAndConsumeUnlinkableGasPass, verifyPaymasterConstraints };
|
package/lib/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_gas_security_guard = require('./gas-security-guard.cjs');
|
|
3
4
|
const require_pipes_write_ledger = require('./pipes/write-ledger.cjs');
|
|
4
5
|
const require_tx_timer = require('./tx-timer.cjs');
|
|
5
6
|
const require_execute = require('./execute.cjs');
|
|
@@ -40,6 +41,7 @@ const require_protocols_trade_transfer_v2 = require('./protocols/trade/transfer-
|
|
|
40
41
|
const require_protocols_trade_transfer_v3 = require('./protocols/trade/transfer-v3.cjs');
|
|
41
42
|
let _ocap_state = require("@ocap/state");
|
|
42
43
|
_ocap_state = require_rolldown_runtime.__toESM(_ocap_state);
|
|
44
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
43
45
|
|
|
44
46
|
//#region src/index.ts
|
|
45
47
|
const createExecutor = ({ filter, runAsLambda }) => {
|
|
@@ -103,11 +105,132 @@ var src_default = defaultExecutor;
|
|
|
103
105
|
|
|
104
106
|
//#endregion
|
|
105
107
|
exports.COUNTER_NAMES = require_tx_timer.COUNTER_NAMES;
|
|
108
|
+
exports.DEFAULT_BASE_BURST_ALLOWANCE = require_gas_security_guard.DEFAULT_BASE_BURST_ALLOWANCE;
|
|
109
|
+
exports.DEFAULT_BURST_REJECT_MULTIPLE = require_gas_security_guard.DEFAULT_BURST_REJECT_MULTIPLE;
|
|
110
|
+
exports.DEFAULT_BURST_WINDOW_MS = require_gas_security_guard.DEFAULT_BURST_WINDOW_MS;
|
|
111
|
+
exports.DEFAULT_FISHERMAN_BOUNTY_BPS = require_gas_security_guard.DEFAULT_FISHERMAN_BOUNTY_BPS;
|
|
112
|
+
exports.DEFAULT_GAS_PASS_EPOCH_SECONDS = require_gas_security_guard.DEFAULT_GAS_PASS_EPOCH_SECONDS;
|
|
113
|
+
exports.DEFAULT_MAX_FREE_GAS_STATE_OPS = require_gas_security_guard.DEFAULT_MAX_FREE_GAS_STATE_OPS;
|
|
114
|
+
exports.DEFAULT_MAX_FREE_GAS_TX_SIZE = require_gas_security_guard.DEFAULT_MAX_FREE_GAS_TX_SIZE;
|
|
115
|
+
exports.DEFAULT_SLASH_STRIKE_THRESHOLD = require_gas_security_guard.DEFAULT_SLASH_STRIKE_THRESHOLD;
|
|
116
|
+
exports.DEFAULT_STRIKE_WINDOW_MS = require_gas_security_guard.DEFAULT_STRIKE_WINDOW_MS;
|
|
117
|
+
exports.DEFAULT_THROTTLE_COOLDOWN_MS = require_gas_security_guard.DEFAULT_THROTTLE_COOLDOWN_MS;
|
|
118
|
+
exports.DEFAULT_THROTTLE_STRIKE_THRESHOLD = require_gas_security_guard.DEFAULT_THROTTLE_STRIKE_THRESHOLD;
|
|
119
|
+
exports.DEFAULT_WARNING_STRIKE_THRESHOLD = require_gas_security_guard.DEFAULT_WARNING_STRIKE_THRESHOLD;
|
|
120
|
+
exports.DIRECT_GAS_REQUIRED_TX_TYPES = require_gas_security_guard.DIRECT_GAS_REQUIRED_TX_TYPES;
|
|
121
|
+
exports.FREE_GAS_ELIGIBLE_TX_TYPES = require_gas_security_guard.FREE_GAS_ELIGIBLE_TX_TYPES;
|
|
122
|
+
Object.defineProperty(exports, 'MAX_POST_EXECUTION_WRITE_SET_ENTRIES', {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function () {
|
|
125
|
+
return _ocap_tx_pipeline.MAX_POST_EXECUTION_WRITE_SET_ENTRIES;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, 'MAX_PREFLIGHT_JSON_DEPTH', {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () {
|
|
131
|
+
return _ocap_tx_pipeline.MAX_PREFLIGHT_JSON_DEPTH;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(exports, 'MAX_PREFLIGHT_JSON_KEYS', {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function () {
|
|
137
|
+
return _ocap_tx_pipeline.MAX_PREFLIGHT_JSON_KEYS;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
exports.PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL = require_execute.PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL;
|
|
141
|
+
Object.defineProperty(exports, 'PostExecutionInvariantGate', {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function () {
|
|
144
|
+
return _ocap_tx_pipeline.PostExecutionInvariantGate;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, 'PreFlightWaf', {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function () {
|
|
150
|
+
return _ocap_tx_pipeline.PreFlightWaf;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
106
153
|
exports.STAGE_LABELS = require_tx_timer.STAGE_LABELS;
|
|
154
|
+
Object.defineProperty(exports, 'TRACKED_STATE_TABLES', {
|
|
155
|
+
enumerable: true,
|
|
156
|
+
get: function () {
|
|
157
|
+
return _ocap_tx_pipeline.TRACKED_STATE_TABLES;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
107
160
|
exports.TxTimer = require_tx_timer.TxTimer;
|
|
108
161
|
exports.UNSIGNED_TX_EVIDENCE_DATA_PREFIX = require_execute.UNSIGNED_TX_EVIDENCE_DATA_PREFIX;
|
|
109
162
|
exports.WriteLedger = require_pipes_write_ledger.WriteLedger;
|
|
163
|
+
Object.defineProperty(exports, 'assertKnownItxFields', {
|
|
164
|
+
enumerable: true,
|
|
165
|
+
get: function () {
|
|
166
|
+
return _ocap_tx_pipeline.assertKnownItxFields;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
Object.defineProperty(exports, 'assertRawWireEnvelope', {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
get: function () {
|
|
172
|
+
return _ocap_tx_pipeline.assertRawWireEnvelope;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
exports.assertTxAdmission = require_gas_security_guard.assertTxAdmission;
|
|
176
|
+
exports.classifyErrorStrikeCategory = require_gas_security_guard.classifyErrorStrikeCategory;
|
|
177
|
+
exports.computeActorTier = require_gas_security_guard.computeActorTier;
|
|
178
|
+
exports.computeUnlinkableGasPassCommitment = require_gas_security_guard.computeUnlinkableGasPassCommitment;
|
|
179
|
+
exports.computeUnlinkableGasPassSecretHash = require_gas_security_guard.computeUnlinkableGasPassSecretHash;
|
|
110
180
|
exports.createExecutor = createExecutor;
|
|
111
181
|
exports.default = src_default;
|
|
182
|
+
exports.evaluateBurstQuota = require_gas_security_guard.evaluateBurstQuota;
|
|
183
|
+
exports.evaluateStakeForGasEligibility = require_gas_security_guard.evaluateStakeForGasEligibility;
|
|
112
184
|
exports.execute = execute;
|
|
113
|
-
exports.
|
|
185
|
+
exports.executeAutoGasStakeSlash = require_gas_security_guard.executeAutoGasStakeSlash;
|
|
186
|
+
exports.extractTransactionTargets = require_gas_security_guard.extractTransactionTargets;
|
|
187
|
+
exports.getActorSecurityStatus = require_gas_security_guard.getActorSecurityStatus;
|
|
188
|
+
exports.getGasSecurityRegistry = require_gas_security_guard.getGasSecurityRegistry;
|
|
189
|
+
exports.getTxSecurityWarningByHash = require_gas_security_guard.getTxSecurityWarningByHash;
|
|
190
|
+
Object.defineProperty(exports, 'inspectPostExecutionInvariants', {
|
|
191
|
+
enumerable: true,
|
|
192
|
+
get: function () {
|
|
193
|
+
return _ocap_tx_pipeline.inspectPostExecutionInvariants;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
Object.defineProperty(exports, 'inspectTransactionPreFlight', {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
get: function () {
|
|
199
|
+
return _ocap_tx_pipeline.inspectTransactionPreFlight;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(exports, 'installStateWriteInterceptor', {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
get: function () {
|
|
205
|
+
return _ocap_tx_pipeline.installStateWriteInterceptor;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
exports.normalizeActorAddress = require_gas_security_guard.normalizeActorAddress;
|
|
209
|
+
Object.defineProperty(exports, 'normalizeEntityKey', {
|
|
210
|
+
enumerable: true,
|
|
211
|
+
get: function () {
|
|
212
|
+
return _ocap_tx_pipeline.normalizeEntityKey;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
exports.normalizeShortTxType = require_gas_security_guard.normalizeShortTxType;
|
|
216
|
+
exports.recordActorSecurityStrike = require_gas_security_guard.recordActorSecurityStrike;
|
|
217
|
+
exports.resetGasSecurityState = require_gas_security_guard.resetGasSecurityState;
|
|
218
|
+
exports.resolveGasSecurityConfig = require_gas_security_guard.resolveGasSecurityConfig;
|
|
219
|
+
exports.resolveVerifiedStrikeActors = require_gas_security_guard.resolveVerifiedStrikeActors;
|
|
220
|
+
Object.defineProperty(exports, 'rollbackTrackedStateWrites', {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function () {
|
|
223
|
+
return _ocap_tx_pipeline.rollbackTrackedStateWrites;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
Object.defineProperty(exports, 'scanItxPayloadAnomalies', {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
get: function () {
|
|
229
|
+
return _ocap_tx_pipeline.scanItxPayloadAnomalies;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
exports.setTxSecurityWarningForHash = require_gas_security_guard.setTxSecurityWarningForHash;
|
|
233
|
+
exports.toUnsignedEvidenceKey = require_execute.toUnsignedEvidenceKey;
|
|
234
|
+
exports.tryApplyPreFlightVerifiedSnapshot = require_execute.tryApplyPreFlightVerifiedSnapshot;
|
|
235
|
+
exports.verifyAndConsumeUnlinkableGasPass = require_gas_security_guard.verifyAndConsumeUnlinkableGasPass;
|
|
236
|
+
exports.verifyPaymasterConstraints = require_gas_security_guard.verifyPaymasterConstraints;
|
package/lib/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DEFAULT_BASE_BURST_ALLOWANCE, DEFAULT_BURST_REJECT_MULTIPLE, DEFAULT_BURST_WINDOW_MS, DEFAULT_FISHERMAN_BOUNTY_BPS, DEFAULT_GAS_PASS_EPOCH_SECONDS, DEFAULT_MAX_FREE_GAS_STATE_OPS, DEFAULT_MAX_FREE_GAS_TX_SIZE, DEFAULT_SLASH_STRIKE_THRESHOLD, DEFAULT_STRIKE_WINDOW_MS, DEFAULT_THROTTLE_COOLDOWN_MS, DEFAULT_THROTTLE_STRIKE_THRESHOLD, DEFAULT_WARNING_STRIKE_THRESHOLD, DIRECT_GAS_REQUIRED_TX_TYPES, FREE_GAS_ELIGIBLE_TX_TYPES, IAbuseSlashEvidence, IGasSecurityConfig, IPaymasterDecodedClaims, IStakeForGasEligibilityResult, ITxGasQuotaTelemetry, ITxSecurityWarning, IUnlinkableGasPass, SecurityStrikeTier, StrikeReasonCategory, assertTxAdmission, classifyErrorStrikeCategory, computeActorTier, computeUnlinkableGasPassCommitment, computeUnlinkableGasPassSecretHash, evaluateBurstQuota, evaluateStakeForGasEligibility, executeAutoGasStakeSlash, extractTransactionTargets, getActorSecurityStatus, getGasSecurityRegistry, getTxSecurityWarningByHash, normalizeActorAddress, normalizeShortTxType, recordActorSecurityStrike, resetGasSecurityState, resolveGasSecurityConfig, resolveVerifiedStrikeActors, setTxSecurityWarningForHash, verifyAndConsumeUnlinkableGasPass, verifyPaymasterConstraints } from "./gas-security-guard.cjs";
|
|
1
2
|
import { COUNTER_NAMES, CounterName, QueueState, STAGE_LABELS, StageLabel, TxMeta, TxStatus, TxTimer, TxTimerSummaryV2 } from "./tx-timer.cjs";
|
|
2
|
-
import { UNSIGNED_TX_EVIDENCE_DATA_PREFIX, toUnsignedEvidenceKey } from "./execute.cjs";
|
|
3
|
+
import { PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL, UNSIGNED_TX_EVIDENCE_DATA_PREFIX, toUnsignedEvidenceKey, tryApplyPreFlightVerifiedSnapshot } from "./execute.cjs";
|
|
3
4
|
import { TokenInput } from "./protocols/trade/transfer-v2.cjs";
|
|
4
5
|
import { MultiInput } from "./protocols/trade/transfer-v3.cjs";
|
|
5
6
|
import { TokenInput as TokenInput$1 } from "./protocols/trade/exchange-v2.cjs";
|
|
@@ -21,9 +22,10 @@ import { TokenChange as TokenChange$2 } from "./protocols/rollup/claim-reward.cj
|
|
|
21
22
|
import { WriteLedger } from "./pipes/write-ledger.cjs";
|
|
22
23
|
import * as states from "@ocap/state";
|
|
23
24
|
import * as _ocap_types0 from "@ocap/types";
|
|
25
|
+
import * as _ocap_util0 from "@ocap/util";
|
|
24
26
|
import * as _ocap_tx_pipeline0 from "@ocap/tx-pipeline";
|
|
27
|
+
import { MAX_POST_EXECUTION_WRITE_SET_ENTRIES, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, PostExecutionInvariantGate, PreFlightWaf, TRACKED_STATE_TABLES, assertKnownItxFields, assertRawWireEnvelope, inspectPostExecutionInvariants, inspectTransactionPreFlight, installStateWriteInterceptor, normalizeEntityKey, rollbackTrackedStateWrites, scanItxPayloadAnomalies } from "@ocap/tx-pipeline";
|
|
25
28
|
import * as _ocap_message0 from "@ocap/message";
|
|
26
|
-
import * as _ocap_util0 from "@ocap/util";
|
|
27
29
|
|
|
28
30
|
//#region src/index.d.ts
|
|
29
31
|
interface ICreateExecutorOptions {
|
|
@@ -100,6 +102,8 @@ declare const createExecutor: ({
|
|
|
100
102
|
tokens: TokenInput$1[];
|
|
101
103
|
};
|
|
102
104
|
tokenStates?: _ocap_types0.ITokenState[];
|
|
105
|
+
senderTokenStates?: _ocap_types0.ITokenState[];
|
|
106
|
+
receiverTokenStates?: _ocap_types0.ITokenState[];
|
|
103
107
|
receiver?: string;
|
|
104
108
|
delegationStates?: _ocap_types0.IDelegateState[];
|
|
105
109
|
priv?: {
|
|
@@ -109,6 +113,8 @@ declare const createExecutor: ({
|
|
|
109
113
|
}>;
|
|
110
114
|
accountMigrate: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TAccountMigrateTx> & Partial<_ocap_types0.IWithSender> & {
|
|
111
115
|
receiverState?: _ocap_types0.IAccountState;
|
|
116
|
+
hasVerifiedPreRotationOrEvent?: boolean;
|
|
117
|
+
hasActivePreRotationCommitment?: boolean;
|
|
112
118
|
}>;
|
|
113
119
|
delegate: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TDelegateTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithReceiver> & Partial<_ocap_types0.IWithDelegation> & {
|
|
114
120
|
formattedItx?: {
|
|
@@ -150,7 +156,7 @@ declare const createExecutor: ({
|
|
|
150
156
|
}>;
|
|
151
157
|
};
|
|
152
158
|
}>;
|
|
153
|
-
revokeDelegate: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TRevokeDelegateTx> & _ocap_types0.IWithSender & _ocap_types0.IWithDelegation & {
|
|
159
|
+
revokeDelegate: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TRevokeDelegateTx> & _ocap_types0.IWithSender & _ocap_types0.IWithDelegation & Partial<_ocap_types0.IWithReceiver> & {
|
|
154
160
|
typeUrls?: string[];
|
|
155
161
|
}>;
|
|
156
162
|
createAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TCreateAssetTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithIssuer> & Partial<_ocap_types0.IWithDelegator> & Partial<_ocap_types0.IWithDelegation> & Partial<_ocap_types0.IWithAsset> & {
|
|
@@ -160,8 +166,16 @@ declare const createExecutor: ({
|
|
|
160
166
|
parentAsset?: _ocap_types0.IAssetState;
|
|
161
167
|
isDelegationChanged?: boolean;
|
|
162
168
|
}>;
|
|
163
|
-
updateAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TUpdateAssetTx> & _ocap_types0.IWithAsset & _ocap_types0.IWithSender & Partial<_ocap_types0.IWithIssuer> & {
|
|
169
|
+
updateAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TUpdateAssetTx> & _ocap_types0.IWithAsset & _ocap_types0.IWithSender & Partial<_ocap_types0.IWithDelegator> & Partial<_ocap_types0.IWithDelegation> & Partial<_ocap_types0.IWithIssuer> & {
|
|
164
170
|
newData: _ocap_message0.AnyData | null;
|
|
171
|
+
isDelegationChanged?: boolean;
|
|
172
|
+
tokenInfoForVerification?: {
|
|
173
|
+
symbol: string;
|
|
174
|
+
address: string;
|
|
175
|
+
website?: string | null;
|
|
176
|
+
};
|
|
177
|
+
charterWebsite?: string;
|
|
178
|
+
charterCommunityUrl?: string;
|
|
165
179
|
}>;
|
|
166
180
|
consumeAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TConsumeAssetTx> & _ocap_types0.IWithAsset & _ocap_types0.IWithSender & _ocap_types0.IWithIssuer & _ocap_types0.IWithOwner & _ocap_types0.IWithSigners & {
|
|
167
181
|
signers: string[];
|
|
@@ -230,6 +244,8 @@ declare const createExecutor: ({
|
|
|
230
244
|
stakeAddress?: string;
|
|
231
245
|
lockerAddress?: string;
|
|
232
246
|
lockerState?: _ocap_types0.IStakeState;
|
|
247
|
+
receiverState?: _ocap_types0.IAccountState | null;
|
|
248
|
+
isProposerSponsor?: boolean;
|
|
233
249
|
signers?: string[];
|
|
234
250
|
stakeStates?: _ocap_types0.IStakeState[];
|
|
235
251
|
updatedAccounts?: TokenChange[];
|
|
@@ -470,6 +486,8 @@ declare const defaultExecutor: {
|
|
|
470
486
|
tokens: TokenInput$1[];
|
|
471
487
|
};
|
|
472
488
|
tokenStates?: _ocap_types0.ITokenState[];
|
|
489
|
+
senderTokenStates?: _ocap_types0.ITokenState[];
|
|
490
|
+
receiverTokenStates?: _ocap_types0.ITokenState[];
|
|
473
491
|
receiver?: string;
|
|
474
492
|
delegationStates?: _ocap_types0.IDelegateState[];
|
|
475
493
|
priv?: {
|
|
@@ -479,6 +497,8 @@ declare const defaultExecutor: {
|
|
|
479
497
|
}>;
|
|
480
498
|
accountMigrate: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TAccountMigrateTx> & Partial<_ocap_types0.IWithSender> & {
|
|
481
499
|
receiverState?: _ocap_types0.IAccountState;
|
|
500
|
+
hasVerifiedPreRotationOrEvent?: boolean;
|
|
501
|
+
hasActivePreRotationCommitment?: boolean;
|
|
482
502
|
}>;
|
|
483
503
|
delegate: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TDelegateTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithReceiver> & Partial<_ocap_types0.IWithDelegation> & {
|
|
484
504
|
formattedItx?: {
|
|
@@ -520,7 +540,7 @@ declare const defaultExecutor: {
|
|
|
520
540
|
}>;
|
|
521
541
|
};
|
|
522
542
|
}>;
|
|
523
|
-
revokeDelegate: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TRevokeDelegateTx> & _ocap_types0.IWithSender & _ocap_types0.IWithDelegation & {
|
|
543
|
+
revokeDelegate: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TRevokeDelegateTx> & _ocap_types0.IWithSender & _ocap_types0.IWithDelegation & Partial<_ocap_types0.IWithReceiver> & {
|
|
524
544
|
typeUrls?: string[];
|
|
525
545
|
}>;
|
|
526
546
|
createAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TCreateAssetTx> & Partial<_ocap_types0.IWithSender> & Partial<_ocap_types0.IWithIssuer> & Partial<_ocap_types0.IWithDelegator> & Partial<_ocap_types0.IWithDelegation> & Partial<_ocap_types0.IWithAsset> & {
|
|
@@ -530,8 +550,16 @@ declare const defaultExecutor: {
|
|
|
530
550
|
parentAsset?: _ocap_types0.IAssetState;
|
|
531
551
|
isDelegationChanged?: boolean;
|
|
532
552
|
}>;
|
|
533
|
-
updateAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TUpdateAssetTx> & _ocap_types0.IWithAsset & _ocap_types0.IWithSender & Partial<_ocap_types0.IWithIssuer> & {
|
|
553
|
+
updateAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TUpdateAssetTx> & _ocap_types0.IWithAsset & _ocap_types0.IWithSender & Partial<_ocap_types0.IWithDelegator> & Partial<_ocap_types0.IWithDelegation> & Partial<_ocap_types0.IWithIssuer> & {
|
|
534
554
|
newData: _ocap_message0.AnyData | null;
|
|
555
|
+
isDelegationChanged?: boolean;
|
|
556
|
+
tokenInfoForVerification?: {
|
|
557
|
+
symbol: string;
|
|
558
|
+
address: string;
|
|
559
|
+
website?: string | null;
|
|
560
|
+
};
|
|
561
|
+
charterWebsite?: string;
|
|
562
|
+
charterCommunityUrl?: string;
|
|
535
563
|
}>;
|
|
536
564
|
consumeAsset: _ocap_tx_pipeline0.Runner<_ocap_types0.IReadyContext<_ocap_types0.TConsumeAssetTx> & _ocap_types0.IWithAsset & _ocap_types0.IWithSender & _ocap_types0.IWithIssuer & _ocap_types0.IWithOwner & _ocap_types0.IWithSigners & {
|
|
537
565
|
signers: string[];
|
|
@@ -600,6 +628,8 @@ declare const defaultExecutor: {
|
|
|
600
628
|
stakeAddress?: string;
|
|
601
629
|
lockerAddress?: string;
|
|
602
630
|
lockerState?: _ocap_types0.IStakeState;
|
|
631
|
+
receiverState?: _ocap_types0.IAccountState | null;
|
|
632
|
+
isProposerSponsor?: boolean;
|
|
603
633
|
signers?: string[];
|
|
604
634
|
stakeStates?: _ocap_types0.IStakeState[];
|
|
605
635
|
updatedAccounts?: TokenChange[];
|
|
@@ -780,4 +810,4 @@ declare const defaultExecutor: {
|
|
|
780
810
|
};
|
|
781
811
|
declare const execute: (context: unknown, done?: (err: Error | null, res?: unknown) => void) => any;
|
|
782
812
|
//#endregion
|
|
783
|
-
export { COUNTER_NAMES, type CounterName, type QueueState, STAGE_LABELS, type StageLabel, type TxMeta, type TxStatus, TxTimer, type TxTimerSummaryV2, UNSIGNED_TX_EVIDENCE_DATA_PREFIX, WriteLedger, createExecutor, defaultExecutor as default, execute, toUnsignedEvidenceKey };
|
|
813
|
+
export { COUNTER_NAMES, type CounterName, DEFAULT_BASE_BURST_ALLOWANCE, DEFAULT_BURST_REJECT_MULTIPLE, DEFAULT_BURST_WINDOW_MS, DEFAULT_FISHERMAN_BOUNTY_BPS, DEFAULT_GAS_PASS_EPOCH_SECONDS, DEFAULT_MAX_FREE_GAS_STATE_OPS, DEFAULT_MAX_FREE_GAS_TX_SIZE, DEFAULT_SLASH_STRIKE_THRESHOLD, DEFAULT_STRIKE_WINDOW_MS, DEFAULT_THROTTLE_COOLDOWN_MS, DEFAULT_THROTTLE_STRIKE_THRESHOLD, DEFAULT_WARNING_STRIKE_THRESHOLD, DIRECT_GAS_REQUIRED_TX_TYPES, FREE_GAS_ELIGIBLE_TX_TYPES, type IAbuseSlashEvidence, type IGasSecurityConfig, type IPaymasterDecodedClaims, type IStakeForGasEligibilityResult, type ITxGasQuotaTelemetry, type ITxSecurityWarning, type IUnlinkableGasPass, MAX_POST_EXECUTION_WRITE_SET_ENTRIES, MAX_PREFLIGHT_JSON_DEPTH, MAX_PREFLIGHT_JSON_KEYS, PREFLIGHT_VERIFIED_SNAPSHOT_SYMBOL, PostExecutionInvariantGate, PreFlightWaf, type QueueState, STAGE_LABELS, type SecurityStrikeTier, type StageLabel, type StrikeReasonCategory, TRACKED_STATE_TABLES, type TxMeta, type TxStatus, TxTimer, type TxTimerSummaryV2, UNSIGNED_TX_EVIDENCE_DATA_PREFIX, WriteLedger, assertKnownItxFields, assertRawWireEnvelope, assertTxAdmission, classifyErrorStrikeCategory, computeActorTier, computeUnlinkableGasPassCommitment, computeUnlinkableGasPassSecretHash, createExecutor, defaultExecutor as default, evaluateBurstQuota, evaluateStakeForGasEligibility, execute, executeAutoGasStakeSlash, extractTransactionTargets, getActorSecurityStatus, getGasSecurityRegistry, getTxSecurityWarningByHash, inspectPostExecutionInvariants, inspectTransactionPreFlight, installStateWriteInterceptor, normalizeActorAddress, normalizeEntityKey, normalizeShortTxType, recordActorSecurityStrike, resetGasSecurityState, resolveGasSecurityConfig, resolveVerifiedStrikeActors, rollbackTrackedStateWrites, scanItxPayloadAnomalies, setTxSecurityWarningForHash, toUnsignedEvidenceKey, tryApplyPreFlightVerifiedSnapshot, verifyAndConsumeUnlinkableGasPass, verifyPaymasterConstraints };
|