@ocap/resolver 1.30.25 → 1.31.0

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/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IAddressArgs, IAssetState, IChainConfig, IChunkIterator, IDataObject, IDelegateState, IEvidenceState, IFilter, IGetAccountStateArgs, IGetAccountTokensArgs, IGetStateParams, IIndexDB as IIndexDB$1, IListChunksParams, IPaginatedResult, IPipelineLogger as IPipelineLogger$1, IResolver, IResolverAccountState, IResolverChainInfo, IResolverContext as IResolverContext$1, IResolverFactoryState, IResolverForgeStats, IResolverListAccountsResult, IResolverListAssetsResult, IResolverListDelegationsResult, IResolverListFactoriesResult, IResolverListRollupBlocksResult, IResolverListRollupValidatorsResult, IResolverListRollupsResult, IResolverListStakesResult, IResolverListTokenFactoriesResult, IResolverListTokensResult, IResolverListTransactionsResult, IResolverNetInfo, IResolverNodeInfo, IResolverPaging, IResolverParams, IResolverRollupState, IResolverStakeState, IResolverTransaction, IResolverValidatorsInfo, IRollupBlock, IStateDB as IStateDB$1, ITokenCache, ITokenFactoryState, ITokenFlowsResult, ITokenInfo, ITokenState, TIndexedTokenState as TIndexedTokenState$1, TRequestEstimateGas, TRequestGetEvidenceState, TRequestGetRollupBlock, TRequestGetTokenDistribution, TRequestGetTx, TRequestListAssetTransactions, TRequestListAssets, TRequestListDelegations, TRequestListFactories, TRequestListRollupBlocks, TRequestListRollupValidators, TRequestListRollups, TRequestListStakes, TRequestListTokenFactories, TRequestListTokenFlows, TRequestListTokens, TRequestListTopAccounts, TRequestListTransactions, TRequestSearch, TRequestVerifyAccountRisk, TSearchResult, TTokenDistribution, TVerifyAccountRiskResult } from "./types.mjs";
2
2
  import { MigrationChainManager } from "./migration-chain.mjs";
3
3
  import { TokenDistributionManager } from "./token-distribution.mjs";
4
- import { createExecutor } from "@ocap/tx-protocols";
4
+ import { ITxSecurityWarning, createExecutor } from "@ocap/tx-protocols";
5
5
  import Queue from "queue";
6
6
  import { ILedger } from "@ocap/types";
7
7
 
@@ -51,6 +51,7 @@ declare class OCAPResolver implements IResolver {
51
51
  tx: string;
52
52
  extra?: Record<string, unknown>;
53
53
  }, ctx?: IResolverContext$1): Promise<string>;
54
+ getTxSecurityWarning(txHash: string): ITxSecurityWarning | undefined;
54
55
  getTx({
55
56
  hash
56
57
  }: TRequestGetTx, ctx?: IResolverContext$1): Promise<IResolverTransaction | null>;
package/esm/index.mjs CHANGED
@@ -16,7 +16,7 @@ import { formatSearchResult, rebuildIndexFromState } from "@ocap/indexdb";
16
16
  import { types } from "@ocap/mcrypto";
17
17
  import { fromTypeUrl } from "@ocap/message";
18
18
  import * as states from "@ocap/state";
19
- import { TxTimer, createExecutor } from "@ocap/tx-protocols";
19
+ import { TxTimer, assertRawWireEnvelope, assertTxAdmission, classifyErrorStrikeCategory, createExecutor, getTxSecurityWarningByHash, inspectTransactionPreFlight, recordActorSecurityStrike, resolveVerifiedStrikeActors, setTxSecurityWarningForHash } from "@ocap/tx-protocols";
20
20
  import { decodeAnySafe } from "@ocap/tx-protocols/lib/util";
21
21
  import { DEFAULT_TOKEN_DECIMAL } from "@ocap/util/lib/constant";
22
22
  import { CustomError } from "@ocap/util/lib/error";
@@ -294,7 +294,7 @@ var OCAPResolver = class {
294
294
  });
295
295
  if (process.env.CHAIN_MODE === "readonly") throw new CustomError("FORBIDDEN", "This chain node is running in readonly mode");
296
296
  if (this.queue.length >= txRequestConfig.maxRequest) throw new CustomError("FORBIDDEN", "Chain is busy");
297
- if (!txBase64 || typeof txBase64 !== "string" || txBase64.length < 20) throw new CustomError("INVALID_TX", "Transaction data is empty or too short");
297
+ assertRawWireEnvelope(txBase64, this.config);
298
298
  const timer = new TxTimer();
299
299
  timer.setQueueState({
300
300
  waitingAtEnqueue: Math.max(0, this.queue.length - (this.queue.pending ?? 0)),
@@ -316,18 +316,63 @@ var OCAPResolver = class {
316
316
  }
317
317
  };
318
318
  return new Promise((resolve, reject) => {
319
- const task = async () => {
320
- timer.mark("queueWait");
319
+ const enqueueAfterPreFlight = async () => {
321
320
  try {
322
321
  await this.initializationPromise;
323
- resolve((await this.executor.execute(context)).txHash);
324
- } catch (err) {
325
- reject(err);
322
+ await inspectTransactionPreFlight(context);
323
+ const preTx = context.tx;
324
+ const preTxHash = context.txHash;
325
+ if (preTx) await assertTxAdmission({
326
+ tx: preTx,
327
+ txHash: preTxHash,
328
+ unsignedTxHash: context.unsignedTxHash,
329
+ config: this.config,
330
+ statedb: this.statedb
331
+ });
332
+ } catch (preFlightErr) {
333
+ const errObj = preFlightErr;
334
+ const strikeCtx = errObj._preFlightCtx || context;
335
+ const txHash = strikeCtx.txHash || context.txHash;
336
+ const classified = classifyErrorStrikeCategory(errObj);
337
+ if (classified.shouldRecordStrike && !errObj._strikeRecorded && errObj._unauthenticatedExtraFailure !== true) try {
338
+ const actors = await resolveVerifiedStrikeActors(strikeCtx);
339
+ if (actors.length > 0) {
340
+ errObj._strikeRecorded = true;
341
+ const { primaryWarning, slashEvidence } = await recordActorSecurityStrike({
342
+ actors,
343
+ category: classified.category,
344
+ reasonCode: classified.code,
345
+ txHash,
346
+ config: this.config,
347
+ statedb: this.statedb
348
+ });
349
+ if (primaryWarning && !errObj.warning) errObj.warning = primaryWarning;
350
+ if (slashEvidence && !errObj.slashEvidence) errObj.slashEvidence = slashEvidence;
351
+ }
352
+ } catch (strikeErr) {
353
+ this.logger?.warn?.("Failed to record security strike", { error: strikeErr });
354
+ }
355
+ reject(preFlightErr);
356
+ return;
326
357
  }
358
+ const task = async () => {
359
+ timer.mark("queueWait");
360
+ try {
361
+ const result = await this.executor.execute(context);
362
+ if (result?.txHash && result?.securityWarning) setTxSecurityWarningForHash(result.txHash, result.securityWarning, this.statedb);
363
+ resolve(result.txHash);
364
+ } catch (err) {
365
+ reject(err);
366
+ }
367
+ };
368
+ this.queue.push(task);
327
369
  };
328
- this.queue.push(task);
370
+ enqueueAfterPreFlight().catch(reject);
329
371
  });
330
372
  }
373
+ getTxSecurityWarning(txHash) {
374
+ return getTxSecurityWarningByHash(txHash, this.statedb);
375
+ }
331
376
  getTx({ hash }, ctx) {
332
377
  if (patterns.txHash.test(hash)) return this._getState({
333
378
  table: "tx",
package/lib/index.cjs CHANGED
@@ -308,7 +308,7 @@ var OCAPResolver = class {
308
308
  });
309
309
  if (process.env.CHAIN_MODE === "readonly") throw new _ocap_util_lib_error.CustomError("FORBIDDEN", "This chain node is running in readonly mode");
310
310
  if (this.queue.length >= txRequestConfig.maxRequest) throw new _ocap_util_lib_error.CustomError("FORBIDDEN", "Chain is busy");
311
- if (!txBase64 || typeof txBase64 !== "string" || txBase64.length < 20) throw new _ocap_util_lib_error.CustomError("INVALID_TX", "Transaction data is empty or too short");
311
+ (0, _ocap_tx_protocols.assertRawWireEnvelope)(txBase64, this.config);
312
312
  const timer = new _ocap_tx_protocols.TxTimer();
313
313
  timer.setQueueState({
314
314
  waitingAtEnqueue: Math.max(0, this.queue.length - (this.queue.pending ?? 0)),
@@ -330,18 +330,63 @@ var OCAPResolver = class {
330
330
  }
331
331
  };
332
332
  return new Promise((resolve, reject) => {
333
- const task = async () => {
334
- timer.mark("queueWait");
333
+ const enqueueAfterPreFlight = async () => {
335
334
  try {
336
335
  await this.initializationPromise;
337
- resolve((await this.executor.execute(context)).txHash);
338
- } catch (err) {
339
- reject(err);
336
+ await (0, _ocap_tx_protocols.inspectTransactionPreFlight)(context);
337
+ const preTx = context.tx;
338
+ const preTxHash = context.txHash;
339
+ if (preTx) await (0, _ocap_tx_protocols.assertTxAdmission)({
340
+ tx: preTx,
341
+ txHash: preTxHash,
342
+ unsignedTxHash: context.unsignedTxHash,
343
+ config: this.config,
344
+ statedb: this.statedb
345
+ });
346
+ } catch (preFlightErr) {
347
+ const errObj = preFlightErr;
348
+ const strikeCtx = errObj._preFlightCtx || context;
349
+ const txHash = strikeCtx.txHash || context.txHash;
350
+ const classified = (0, _ocap_tx_protocols.classifyErrorStrikeCategory)(errObj);
351
+ if (classified.shouldRecordStrike && !errObj._strikeRecorded && errObj._unauthenticatedExtraFailure !== true) try {
352
+ const actors = await (0, _ocap_tx_protocols.resolveVerifiedStrikeActors)(strikeCtx);
353
+ if (actors.length > 0) {
354
+ errObj._strikeRecorded = true;
355
+ const { primaryWarning, slashEvidence } = await (0, _ocap_tx_protocols.recordActorSecurityStrike)({
356
+ actors,
357
+ category: classified.category,
358
+ reasonCode: classified.code,
359
+ txHash,
360
+ config: this.config,
361
+ statedb: this.statedb
362
+ });
363
+ if (primaryWarning && !errObj.warning) errObj.warning = primaryWarning;
364
+ if (slashEvidence && !errObj.slashEvidence) errObj.slashEvidence = slashEvidence;
365
+ }
366
+ } catch (strikeErr) {
367
+ this.logger?.warn?.("Failed to record security strike", { error: strikeErr });
368
+ }
369
+ reject(preFlightErr);
370
+ return;
340
371
  }
372
+ const task = async () => {
373
+ timer.mark("queueWait");
374
+ try {
375
+ const result = await this.executor.execute(context);
376
+ if (result?.txHash && result?.securityWarning) (0, _ocap_tx_protocols.setTxSecurityWarningForHash)(result.txHash, result.securityWarning, this.statedb);
377
+ resolve(result.txHash);
378
+ } catch (err) {
379
+ reject(err);
380
+ }
381
+ };
382
+ this.queue.push(task);
341
383
  };
342
- this.queue.push(task);
384
+ enqueueAfterPreFlight().catch(reject);
343
385
  });
344
386
  }
387
+ getTxSecurityWarning(txHash) {
388
+ return (0, _ocap_tx_protocols.getTxSecurityWarningByHash)(txHash, this.statedb);
389
+ }
345
390
  getTx({ hash }, ctx) {
346
391
  if (_arcblock_validator.patterns.txHash.test(hash)) return this._getState({
347
392
  table: "tx",
package/lib/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { IAddressArgs, IAssetState, IChainConfig, IChunkIterator, IDataObject, I
2
2
  import { MigrationChainManager } from "./migration-chain.cjs";
3
3
  import { TokenDistributionManager } from "./token-distribution.cjs";
4
4
  import { ILedger } from "@ocap/types";
5
- import { createExecutor } from "@ocap/tx-protocols";
5
+ import { ITxSecurityWarning, createExecutor } from "@ocap/tx-protocols";
6
6
  import Queue from "queue";
7
7
 
8
8
  //#region src/index.d.ts
@@ -51,6 +51,7 @@ declare class OCAPResolver implements IResolver {
51
51
  tx: string;
52
52
  extra?: Record<string, unknown>;
53
53
  }, ctx?: IResolverContext$1): Promise<string>;
54
+ getTxSecurityWarning(txHash: string): ITxSecurityWarning | undefined;
54
55
  getTx({
55
56
  hash
56
57
  }: TRequestGetTx, ctx?: IResolverContext$1): Promise<IResolverTransaction | null>;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.30.25",
6
+ "version": "1.31.0",
7
7
  "description": "GraphQL resolver built upon ocap statedb and GQL layer",
8
8
  "type": "module",
9
9
  "main": "./lib/index.cjs",
@@ -49,20 +49,20 @@
49
49
  "tsdown": "^0.18.4"
50
50
  },
51
51
  "dependencies": {
52
- "@arcblock/did": "1.30.25",
53
- "@arcblock/did-ext": "1.30.25",
54
- "@arcblock/did-util": "1.30.25",
52
+ "@arcblock/did": "1.31.0",
53
+ "@arcblock/did-ext": "1.31.0",
54
+ "@arcblock/did-util": "1.31.0",
55
55
  "@arcblock/nft-display": "^3.2.3",
56
- "@arcblock/validator": "1.30.25",
57
- "@ocap/config": "1.30.25",
58
- "@ocap/indexdb": "1.30.25",
59
- "@ocap/mcrypto": "1.30.25",
60
- "@ocap/message": "1.30.25",
61
- "@ocap/state": "1.30.25",
62
- "@ocap/tx-protocols": "1.30.25",
63
- "@ocap/types": "1.30.25",
64
- "@ocap/util": "1.30.25",
65
- "@ocap/wallet": "1.30.25",
56
+ "@arcblock/validator": "1.31.0",
57
+ "@ocap/config": "1.31.0",
58
+ "@ocap/indexdb": "1.31.0",
59
+ "@ocap/mcrypto": "1.31.0",
60
+ "@ocap/message": "1.31.0",
61
+ "@ocap/state": "1.31.0",
62
+ "@ocap/tx-protocols": "1.31.0",
63
+ "@ocap/types": "1.31.0",
64
+ "@ocap/util": "1.31.0",
65
+ "@ocap/wallet": "1.31.0",
66
66
  "debug": "^4.4.3",
67
67
  "express": "^4.22.1",
68
68
  "lodash": "^4.17.23",