@ocap/tx-pipeline 1.30.24 → 1.30.25

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.
Files changed (63) hide show
  1. package/esm/helpers/dedup-height.d.mts +16 -0
  2. package/esm/helpers/dedup-height.mjs +61 -0
  3. package/esm/index.d.mts +7 -4
  4. package/esm/index.mjs +6 -4
  5. package/esm/pipes/anti-land-attack.mjs +1 -1
  6. package/esm/pipes/decode-tx.d.mts +3 -2
  7. package/esm/pipes/decode-tx.mjs +175 -29
  8. package/esm/pipes/extract-signer.mjs +11 -2
  9. package/esm/pipes/extract-state.d.mts +4 -1
  10. package/esm/pipes/extract-state.mjs +14 -7
  11. package/esm/pipes/take-state-snapshot.mjs +8 -0
  12. package/esm/pipes/update-owner.d.mts +3 -1
  13. package/esm/pipes/update-owner.mjs +28 -2
  14. package/esm/pipes/verify-account-migration.mjs +2 -2
  15. package/esm/pipes/verify-blocked.mjs +1 -1
  16. package/esm/pipes/verify-delegation.d.mts +6 -3
  17. package/esm/pipes/verify-delegation.mjs +121 -47
  18. package/esm/pipes/verify-list-size.mjs +1 -1
  19. package/esm/pipes/verify-multisig-v2.mjs +39 -9
  20. package/esm/pipes/verify-multisig.mjs +20 -5
  21. package/esm/pipes/verify-sender.mjs +1 -1
  22. package/esm/pipes/verify-signature.mjs +14 -5
  23. package/esm/pipes/verify-signer.mjs +5 -3
  24. package/esm/pipes/verify-token-access.mjs +31 -2
  25. package/esm/pipes/verify-token-balance.mjs +4 -2
  26. package/esm/pipes/verify-transferrable.mjs +1 -1
  27. package/esm/pipes/verify-tx-input.mjs +3 -3
  28. package/esm/pipes/verify-tx-size.mjs +1 -1
  29. package/esm/pipes/verify-tx.d.mts +1 -1
  30. package/esm/pipes/verify-tx.mjs +12 -5
  31. package/esm/pipes/verify-updater.mjs +1 -1
  32. package/lib/helpers/dedup-height.cjs +72 -0
  33. package/lib/helpers/dedup-height.d.cts +16 -0
  34. package/lib/index.cjs +15 -0
  35. package/lib/index.d.cts +7 -4
  36. package/lib/pipes/anti-land-attack.cjs +2 -2
  37. package/lib/pipes/decode-tx.cjs +176 -26
  38. package/lib/pipes/decode-tx.d.cts +3 -2
  39. package/lib/pipes/extract-signer.cjs +11 -2
  40. package/lib/pipes/extract-state.cjs +14 -7
  41. package/lib/pipes/extract-state.d.cts +4 -1
  42. package/lib/pipes/take-state-snapshot.cjs +8 -0
  43. package/lib/pipes/update-owner.cjs +29 -2
  44. package/lib/pipes/update-owner.d.cts +3 -1
  45. package/lib/pipes/verify-account-migration.cjs +2 -2
  46. package/lib/pipes/verify-blocked.cjs +1 -1
  47. package/lib/pipes/verify-delegation.cjs +123 -48
  48. package/lib/pipes/verify-delegation.d.cts +6 -3
  49. package/lib/pipes/verify-list-size.cjs +1 -1
  50. package/lib/pipes/verify-multisig-v2.cjs +40 -9
  51. package/lib/pipes/verify-multisig.cjs +21 -5
  52. package/lib/pipes/verify-sender.cjs +1 -1
  53. package/lib/pipes/verify-signature.cjs +13 -4
  54. package/lib/pipes/verify-signer.cjs +5 -3
  55. package/lib/pipes/verify-token-access.cjs +32 -3
  56. package/lib/pipes/verify-token-balance.cjs +5 -3
  57. package/lib/pipes/verify-transferrable.cjs +1 -1
  58. package/lib/pipes/verify-tx-input.cjs +4 -4
  59. package/lib/pipes/verify-tx-size.cjs +1 -1
  60. package/lib/pipes/verify-tx.cjs +12 -4
  61. package/lib/pipes/verify-tx.d.cts +1 -1
  62. package/lib/pipes/verify-updater.cjs +1 -1
  63. package/package.json +10 -10
@@ -0,0 +1,16 @@
1
+ import { CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, EXPLICIT_HEIGHT_PATHS, PENDING_DEDUP_ACTIVATION_HEIGHT, parseNonceBn, readExplicitHeight, resolveDedupActivationHeight } from "@ocap/state";
2
+
3
+ //#region src/helpers/dedup-height.d.ts
4
+ declare function resolveEffectiveHeight(context: unknown): Promise<number>;
5
+ declare function tryResolveDedupHeightActiveSync(context: unknown): boolean | null;
6
+ declare function isDedupHeightActive(context: unknown): Promise<boolean>;
7
+ /**
8
+ * Validate that a passkey Multisig.extra payload is a JSON object containing
9
+ * non-empty string `authenticatorData` and `clientDataJSON`.
10
+ * Does not restrict key ordering or additional client fields (such as iOS
11
+ * DIDConnect `signature` and `userHandle`), relying on `unsignedTxHash`
12
+ * deduplication and `nonce > 0` for replay protection.
13
+ */
14
+ declare function isCanonicalPasskeyExtra(extra: string): boolean;
15
+ //#endregion
16
+ export { CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, EXPLICIT_HEIGHT_PATHS, PENDING_DEDUP_ACTIVATION_HEIGHT, isCanonicalPasskeyExtra, isDedupHeightActive, parseNonceBn, readExplicitHeight, resolveDedupActivationHeight, resolveEffectiveHeight, tryResolveDedupHeightActiveSync };
@@ -0,0 +1,61 @@
1
+ import { CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, EXPLICIT_HEIGHT_PATHS, PENDING_DEDUP_ACTIVATION_HEIGHT, parseNonceBn, readExplicitHeight, resolveDedupActivationHeight } from "@ocap/state";
2
+ import get from "lodash/get.js";
3
+
4
+ //#region src/helpers/dedup-height.ts
5
+ const hasLedgerSequenceProvider = (context) => {
6
+ const ledger = context?.ledger;
7
+ return typeof ledger?.getLatestSequence === "function" || typeof ledger?.getSequence === "function";
8
+ };
9
+ async function resolveEffectiveHeight(context) {
10
+ const explicit = readExplicitHeight(context);
11
+ if (explicit !== void 0) return explicit;
12
+ const ledger = context?.ledger;
13
+ const getSeqFn = typeof ledger?.getLatestSequence === "function" ? () => ledger.getLatestSequence() : typeof ledger?.getSequence === "function" ? () => ledger.getSequence() : null;
14
+ if (getSeqFn) try {
15
+ const seq = await getSeqFn();
16
+ const num = Number(seq);
17
+ if (Number.isFinite(num) && num >= 0) {
18
+ const nextSeq = num + 1;
19
+ if (context && typeof context === "object") context.expectedLedgerSequence = nextSeq;
20
+ return nextSeq;
21
+ }
22
+ } catch (err) {
23
+ if (!(err instanceof Error ? err.message : String(err)).includes("No read ledger configured on the sequencer-driven ledger facade")) throw err;
24
+ }
25
+ return 0;
26
+ }
27
+ function tryResolveDedupHeightActiveSync(context) {
28
+ const explicitFlag = get(context, "dedupActive");
29
+ if (typeof explicitFlag === "boolean") return explicitFlag;
30
+ const dedupHeight = resolveDedupActivationHeight(context);
31
+ if (dedupHeight <= 0) return true;
32
+ const explicitHeight = readExplicitHeight(context);
33
+ if (explicitHeight !== void 0) return explicitHeight >= dedupHeight;
34
+ if (!hasLedgerSequenceProvider(context) || dedupHeight >= PENDING_DEDUP_ACTIVATION_HEIGHT) return dedupHeight < PENDING_DEDUP_ACTIVATION_HEIGHT;
35
+ return null;
36
+ }
37
+ async function isDedupHeightActive(context) {
38
+ const syncResult = tryResolveDedupHeightActiveSync(context);
39
+ if (syncResult !== null) return syncResult;
40
+ const dedupHeight = resolveDedupActivationHeight(context);
41
+ return await resolveEffectiveHeight(context) >= dedupHeight;
42
+ }
43
+ /**
44
+ * Validate that a passkey Multisig.extra payload is a JSON object containing
45
+ * non-empty string `authenticatorData` and `clientDataJSON`.
46
+ * Does not restrict key ordering or additional client fields (such as iOS
47
+ * DIDConnect `signature` and `userHandle`), relying on `unsignedTxHash`
48
+ * deduplication and `nonce > 0` for replay protection.
49
+ */
50
+ function isCanonicalPasskeyExtra(extra) {
51
+ try {
52
+ const parsed = JSON.parse(extra);
53
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
54
+ return typeof parsed.authenticatorData === "string" && parsed.authenticatorData.length > 0 && typeof parsed.clientDataJSON === "string" && parsed.clientDataJSON.length > 0;
55
+ } catch {
56
+ return false;
57
+ }
58
+ }
59
+
60
+ //#endregion
61
+ export { CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, EXPLICIT_HEIGHT_PATHS, PENDING_DEDUP_ACTIVATION_HEIGHT, isCanonicalPasskeyExtra, isDedupHeightActive, parseNonceBn, readExplicitHeight, resolveDedupActivationHeight, resolveEffectiveHeight, tryResolveDedupHeightActiveSync };
package/esm/index.d.mts CHANGED
@@ -1,15 +1,16 @@
1
+ import { CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, PENDING_DEDUP_ACTIVATION_HEIGHT, isCanonicalPasskeyExtra, isDedupHeightActive, parseNonceBn, readExplicitHeight, resolveDedupActivationHeight, resolveEffectiveHeight } from "./helpers/dedup-height.mjs";
1
2
  import PipelineRunner, { ErrorPipeFunction, PipeFunction, PipeNext, PipeOptions } from "./runner.mjs";
2
3
  import CreateAntiLandAttackPipe from "./pipes/anti-land-attack.mjs";
3
4
  import DecodeItx from "./pipes/decode-itx.mjs";
4
- import DecodeTx from "./pipes/decode-tx.mjs";
5
+ import DecodeTx, { assertCanonicalActiveTx } from "./pipes/decode-tx.mjs";
5
6
  import CreateExtractReceiverPipe from "./pipes/extract-receiver.mjs";
6
7
  import CreateExtractSignerPipe from "./pipes/extract-signer.mjs";
7
8
  import CreateExtractStatePipe from "./pipes/extract-state.mjs";
8
9
  import CreateTakeStateSnapshotPipe from "./pipes/take-state-snapshot.mjs";
9
- import CreateUpdateOwnerPipe from "./pipes/update-owner.mjs";
10
+ import CreateUpdateOwnerPipe, { verifyAssetHierarchy } from "./pipes/update-owner.mjs";
10
11
  import CreateVerifyAccountMigrationPipe from "./pipes/verify-account-migration.mjs";
11
12
  import CreatedVerifyBlockedPipe from "./pipes/verify-blocked.mjs";
12
- import CreateVerifyDelegationPipe, { isDelegationSufficient } from "./pipes/verify-delegation.mjs";
13
+ import CreateVerifyDelegationPipe, { isDelegationSufficient, verifyImplicitAssetOwnership } from "./pipes/verify-delegation.mjs";
13
14
  import CreateVerifyInfoPipe from "./pipes/verify-info.mjs";
14
15
  import CreateVerifyListSizePipe from "./pipes/verify-list-size.mjs";
15
16
  import CreateVerifyMultiSigPipe from "./pipes/verify-multisig.mjs";
@@ -33,6 +34,7 @@ declare const pipes: {
33
34
  AntiLandAttack: typeof CreateAntiLandAttackPipe;
34
35
  DecodeItx: typeof DecodeItx;
35
36
  DecodeTx: typeof DecodeTx;
37
+ assertCanonicalActiveTx: typeof assertCanonicalActiveTx;
36
38
  ExtractReceiver: typeof CreateExtractReceiverPipe;
37
39
  ExtractSigner: typeof CreateExtractSignerPipe;
38
40
  ExtractState: typeof CreateExtractStatePipe;
@@ -64,6 +66,7 @@ declare const _default: {
64
66
  AntiLandAttack: typeof CreateAntiLandAttackPipe;
65
67
  DecodeItx: typeof DecodeItx;
66
68
  DecodeTx: typeof DecodeTx;
69
+ assertCanonicalActiveTx: typeof assertCanonicalActiveTx;
67
70
  ExtractReceiver: typeof CreateExtractReceiverPipe;
68
71
  ExtractSigner: typeof CreateExtractSignerPipe;
69
72
  ExtractState: typeof CreateExtractStatePipe;
@@ -91,4 +94,4 @@ declare const _default: {
91
94
  };
92
95
  };
93
96
  //#endregion
94
- export { CreateAntiLandAttackPipe as AntiLandAttack, DecodeItx, DecodeTx, type ErrorPipeFunction, CreateExtractReceiverPipe as ExtractReceiver, CreateExtractSignerPipe as ExtractSigner, CreateExtractStatePipe as ExtractState, type IAccountUpdate, type IBaseContext, type IDecodedContext, type IDecodedTransaction, type IExecutedContext, type IGasContext, type IReadyContext, type ITxOnlyContext, type IWithAsset, type IWithAssets, type IWithDelegation, type IWithDelegator, type IWithEvidence, type IWithFactory, type IWithLocked, type IWithOwner, type IWithReceiver, type IWithRollup, type IWithRollupBlock, type IWithSender, type IWithStake, type IWithStakes, type IWithToken, type IWithTokenFactory, type IWithTokens, type PipeFunction, type PipeNext, type PipeOptions, PipelineRunner as Runner, type TTransactionReceipt, CreateTakeStateSnapshotPipe as TakeStateSnapshot, CreateUpdateOwnerPipe as UpdateOwner, CreateVerifyAccountMigrationPipe as VerifyAccountMigration, CreatedVerifyBlockedPipe as VerifyBlocked, CreateVerifyDelegationPipe as VerifyDelegation, CreateVerifyInfoPipe as VerifyInfo, CreateVerifyListSizePipe as VerifyListSize, CreateVerifyMultiSigPipe as VerifyMultiSig, CreateVerifyMultiSigV2Pipe as VerifyMultiSigV2, CreateVerifySenderPipe as VerifySender, VerifyServiceFee, VerifySignature, CreateVerifySignerPipe as VerifySigner, CreateVerifyStateDiffPipe as VerifyStateDiff, CreateVerifyTokenBalancePipe as VerifyTokenBalance, CreateVerifyTransferrablePipe as VerifyTransferrable, VerifyTx, CreateVerifyTxInputPipe as VerifyTxInput, VerifyTxSize, CreateVerifyUpdaterPipe as VerifyUpdater, _default as default, groupStatesByAddress, isDelegationSufficient, pipes, CreateVerifyTokenAccessPipe as verifyTokenAccess };
97
+ export { CreateAntiLandAttackPipe as AntiLandAttack, CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, DecodeItx, DecodeTx, type ErrorPipeFunction, CreateExtractReceiverPipe as ExtractReceiver, CreateExtractSignerPipe as ExtractSigner, CreateExtractStatePipe as ExtractState, type IAccountUpdate, type IBaseContext, type IDecodedContext, type IDecodedTransaction, type IExecutedContext, type IGasContext, type IReadyContext, type ITxOnlyContext, type IWithAsset, type IWithAssets, type IWithDelegation, type IWithDelegator, type IWithEvidence, type IWithFactory, type IWithLocked, type IWithOwner, type IWithReceiver, type IWithRollup, type IWithRollupBlock, type IWithSender, type IWithStake, type IWithStakes, type IWithToken, type IWithTokenFactory, type IWithTokens, PENDING_DEDUP_ACTIVATION_HEIGHT, type PipeFunction, type PipeNext, type PipeOptions, PipelineRunner as Runner, type TTransactionReceipt, CreateTakeStateSnapshotPipe as TakeStateSnapshot, CreateUpdateOwnerPipe as UpdateOwner, CreateVerifyAccountMigrationPipe as VerifyAccountMigration, CreatedVerifyBlockedPipe as VerifyBlocked, CreateVerifyDelegationPipe as VerifyDelegation, CreateVerifyInfoPipe as VerifyInfo, CreateVerifyListSizePipe as VerifyListSize, CreateVerifyMultiSigPipe as VerifyMultiSig, CreateVerifyMultiSigV2Pipe as VerifyMultiSigV2, CreateVerifySenderPipe as VerifySender, VerifyServiceFee, VerifySignature, CreateVerifySignerPipe as VerifySigner, CreateVerifyStateDiffPipe as VerifyStateDiff, CreateVerifyTokenBalancePipe as VerifyTokenBalance, CreateVerifyTransferrablePipe as VerifyTransferrable, VerifyTx, CreateVerifyTxInputPipe as VerifyTxInput, VerifyTxSize, CreateVerifyUpdaterPipe as VerifyUpdater, assertCanonicalActiveTx, _default as default, groupStatesByAddress, isCanonicalPasskeyExtra, isDedupHeightActive, isDelegationSufficient, parseNonceBn, pipes, readExplicitHeight, resolveDedupActivationHeight, resolveEffectiveHeight, verifyAssetHierarchy, verifyImplicitAssetOwnership, CreateVerifyTokenAccessPipe as verifyTokenAccess };
package/esm/index.mjs CHANGED
@@ -1,15 +1,16 @@
1
+ import { CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, PENDING_DEDUP_ACTIVATION_HEIGHT, isCanonicalPasskeyExtra, isDedupHeightActive, parseNonceBn, readExplicitHeight, resolveDedupActivationHeight, resolveEffectiveHeight } from "./helpers/dedup-height.mjs";
1
2
  import CreateAntiLandAttackPipe from "./pipes/anti-land-attack.mjs";
2
3
  import DecodeItx from "./pipes/decode-itx.mjs";
3
- import DecodeTx from "./pipes/decode-tx.mjs";
4
+ import DecodeTx, { assertCanonicalActiveTx } from "./pipes/decode-tx.mjs";
4
5
  import CreateExtractReceiverPipe from "./pipes/extract-receiver.mjs";
5
6
  import CreateExtractSignerPipe from "./pipes/extract-signer.mjs";
6
7
  import CreateExtractStatePipe from "./pipes/extract-state.mjs";
7
8
  import CreateVerifyStateDiffPipe, { groupStatesByAddress } from "./pipes/verify-state-diff.mjs";
8
9
  import CreateTakeStateSnapshotPipe from "./pipes/take-state-snapshot.mjs";
9
- import CreateUpdateOwnerPipe from "./pipes/update-owner.mjs";
10
+ import CreateUpdateOwnerPipe, { verifyAssetHierarchy } from "./pipes/update-owner.mjs";
10
11
  import CreateVerifyAccountMigrationPipe from "./pipes/verify-account-migration.mjs";
11
12
  import CreatedVerifyBlockedPipe from "./pipes/verify-blocked.mjs";
12
- import CreateVerifyDelegationPipe, { isDelegationSufficient } from "./pipes/verify-delegation.mjs";
13
+ import CreateVerifyDelegationPipe, { isDelegationSufficient, verifyImplicitAssetOwnership } from "./pipes/verify-delegation.mjs";
13
14
  import CreateVerifyInfoPipe from "./pipes/verify-info.mjs";
14
15
  import CreateVerifyListSizePipe from "./pipes/verify-list-size.mjs";
15
16
  import CreateVerifyMultiSigPipe from "./pipes/verify-multisig.mjs";
@@ -32,6 +33,7 @@ const pipes = {
32
33
  AntiLandAttack: CreateAntiLandAttackPipe,
33
34
  DecodeItx,
34
35
  DecodeTx,
36
+ assertCanonicalActiveTx,
35
37
  ExtractReceiver: CreateExtractReceiverPipe,
36
38
  ExtractSigner: CreateExtractSignerPipe,
37
39
  ExtractState: CreateExtractStatePipe,
@@ -63,4 +65,4 @@ var src_default = {
63
65
  };
64
66
 
65
67
  //#endregion
66
- export { CreateAntiLandAttackPipe as AntiLandAttack, DecodeItx, DecodeTx, CreateExtractReceiverPipe as ExtractReceiver, CreateExtractSignerPipe as ExtractSigner, CreateExtractStatePipe as ExtractState, runner_default as Runner, CreateTakeStateSnapshotPipe as TakeStateSnapshot, CreateUpdateOwnerPipe as UpdateOwner, CreateVerifyAccountMigrationPipe as VerifyAccountMigration, CreatedVerifyBlockedPipe as VerifyBlocked, CreateVerifyDelegationPipe as VerifyDelegation, CreateVerifyInfoPipe as VerifyInfo, CreateVerifyListSizePipe as VerifyListSize, CreateVerifyMultiSigPipe as VerifyMultiSig, CreateVerifyMultiSigV2Pipe as VerifyMultiSigV2, CreateVerifySenderPipe as VerifySender, VerifyServiceFee, VerifySignature, CreateVerifySignerPipe as VerifySigner, CreateVerifyStateDiffPipe as VerifyStateDiff, CreateVerifyTokenBalancePipe as VerifyTokenBalance, CreateVerifyTransferrablePipe as VerifyTransferrable, VerifyTx, CreateVerifyTxInputPipe as VerifyTxInput, VerifyTxSize, CreateVerifyUpdaterPipe as VerifyUpdater, src_default as default, groupStatesByAddress, isDelegationSufficient, pipes, CreateVerifyTokenAccessPipe as verifyTokenAccess };
68
+ export { CreateAntiLandAttackPipe as AntiLandAttack, CHAIN_UNSIGNED_TX_DEDUP_HEIGHTS, DecodeItx, DecodeTx, CreateExtractReceiverPipe as ExtractReceiver, CreateExtractSignerPipe as ExtractSigner, CreateExtractStatePipe as ExtractState, PENDING_DEDUP_ACTIVATION_HEIGHT, runner_default as Runner, CreateTakeStateSnapshotPipe as TakeStateSnapshot, CreateUpdateOwnerPipe as UpdateOwner, CreateVerifyAccountMigrationPipe as VerifyAccountMigration, CreatedVerifyBlockedPipe as VerifyBlocked, CreateVerifyDelegationPipe as VerifyDelegation, CreateVerifyInfoPipe as VerifyInfo, CreateVerifyListSizePipe as VerifyListSize, CreateVerifyMultiSigPipe as VerifyMultiSig, CreateVerifyMultiSigV2Pipe as VerifyMultiSigV2, CreateVerifySenderPipe as VerifySender, VerifyServiceFee, VerifySignature, CreateVerifySignerPipe as VerifySigner, CreateVerifyStateDiffPipe as VerifyStateDiff, CreateVerifyTokenBalancePipe as VerifyTokenBalance, CreateVerifyTransferrablePipe as VerifyTransferrable, VerifyTx, CreateVerifyTxInputPipe as VerifyTxInput, VerifyTxSize, CreateVerifyUpdaterPipe as VerifyUpdater, assertCanonicalActiveTx, src_default as default, groupStatesByAddress, isCanonicalPasskeyExtra, isDedupHeightActive, isDelegationSufficient, parseNonceBn, pipes, readExplicitHeight, resolveDedupActivationHeight, resolveEffectiveHeight, verifyAssetHierarchy, verifyImplicitAssetOwnership, CreateVerifyTokenAccessPipe as verifyTokenAccess };
@@ -1,6 +1,6 @@
1
+ import get from "lodash/get.js";
1
2
  import { isSameDid } from "@ocap/util";
2
3
  import { CustomError } from "@ocap/util/lib/error";
3
- import get from "lodash/get.js";
4
4
 
5
5
  //#region src/pipes/anti-land-attack.ts
6
6
  function CreateAntiLandAttackPipe({ senderState = "senderState", receiverState = "receiverState" } = {}) {
@@ -2,6 +2,7 @@ import { CustomError } from "@ocap/util/lib/error";
2
2
  import { IBaseContext } from "@ocap/types";
3
3
 
4
4
  //#region src/pipes/decode-tx.d.ts
5
- declare function DecodeTx(context: IBaseContext, next: (err?: CustomError) => void): void;
5
+ declare function assertCanonicalActiveTx(context: IBaseContext): void;
6
+ declare function DecodeTx(context: IBaseContext, next: (err?: CustomError) => void): void | Promise<void>;
6
7
  //#endregion
7
- export { DecodeTx as default };
8
+ export { assertCanonicalActiveTx, DecodeTx as default };
@@ -1,13 +1,62 @@
1
+ import { isDedupHeightActive, tryResolveDedupHeightActiveSync } from "../helpers/dedup-height.mjs";
1
2
  import { name } from "../package.mjs";
3
+ import { unwrapOpaqueAnyData } from "../helpers/unwrap-opaque-any.mjs";
4
+ import get from "lodash/get.js";
2
5
  import { fromBase64, toUint8Array } from "@ocap/util";
3
6
  import { CustomError } from "@ocap/util/lib/error";
7
+ import { decodeAny, encodeAny } from "@ocap/message";
4
8
  import { toTxHash } from "@ocap/mcrypto";
5
- import { CANONICAL_SELF_DESCRIBE_PREFIX, decodeTx } from "@ocap/message/cbor";
6
- import { decodeTx as decodeTx$1 } from "@ocap/message/protobuf";
9
+ import { CANONICAL_SELF_DESCRIBE_PREFIX, decodeTx, encodeTx } from "@ocap/message/cbor";
10
+ import { decodeTx as decodeTx$1, encodeTx as encodeTx$1 } from "@ocap/message/protobuf";
11
+ import { getListField, setListField } from "@ocap/util/lib/get-list-field";
12
+ import cloneDeep from "lodash/cloneDeep.js";
13
+ import omit from "lodash/omit.js";
7
14
  import Debug from "debug";
8
15
 
9
16
  //#region src/pipes/decode-tx.ts
10
17
  const debug = Debug(`${name}:pipe:decode-tx`);
18
+ function isCanonicalSigData(data, isCbor) {
19
+ if (!data || typeof data !== "object") return true;
20
+ const anyData = data;
21
+ const { typeUrl, value } = anyData;
22
+ if (!typeUrl && !value && !anyData.type) return true;
23
+ if (typeUrl && ["json", "vc"].includes(typeUrl)) {
24
+ if (!isCbor && typeof value === "string") {
25
+ const rawBytes = Buffer.from(value, "base64");
26
+ if (rawBytes.toString("base64") !== value) return false;
27
+ const rawStr = rawBytes.toString("utf8");
28
+ let parsed;
29
+ try {
30
+ parsed = JSON.parse(rawStr);
31
+ } catch {
32
+ return false;
33
+ }
34
+ if (JSON.stringify(parsed) !== rawStr) return false;
35
+ if (typeof parsed === "string") try {
36
+ const innerBytes = Buffer.from(parsed, "base64");
37
+ const innerStr = innerBytes.toString("utf8");
38
+ const innerParsed = JSON.parse(innerStr);
39
+ if (innerBytes.toString("base64") !== parsed || JSON.stringify(innerParsed) !== innerStr) return false;
40
+ } catch {}
41
+ return true;
42
+ }
43
+ if (isCbor && typeof value === "string") try {
44
+ const innerBytes = Buffer.from(value, "base64");
45
+ const innerStr = innerBytes.toString("utf8");
46
+ const innerParsed = JSON.parse(innerStr);
47
+ if (innerBytes.toString("base64") !== value || JSON.stringify(innerParsed) !== innerStr) return false;
48
+ } catch {}
49
+ return true;
50
+ }
51
+ if (!isCbor && typeUrl && typeUrl !== "fg:x:address" && typeof value === "string" && value.length > 0) {
52
+ const decoded = decodeAny(anyData);
53
+ if (decoded?.type && decoded.type !== "Unknown") {
54
+ const reencodedAny = encodeAny(decoded)?.toObject();
55
+ if (!reencodedAny || reencodedAny.value !== value) return false;
56
+ }
57
+ }
58
+ return true;
59
+ }
11
60
  /**
12
61
  * Detect the CBOR self-describe tag 55799 that our canonical encoder always
13
62
  * prepends to a Transaction. The first three bytes are unambiguously distinct
@@ -18,45 +67,142 @@ const debug = Debug(`${name}:pipe:decode-tx`);
18
67
  function hasCborSelfDescribeTag(buf) {
19
68
  return buf.length >= CANONICAL_SELF_DESCRIBE_PREFIX.length && buf[0] === CANONICAL_SELF_DESCRIBE_PREFIX[0] && buf[1] === CANONICAL_SELF_DESCRIBE_PREFIX[1] && buf[2] === CANONICAL_SELF_DESCRIBE_PREFIX[2];
20
69
  }
70
+ const NON_CANONICAL_MESSAGE = "Transaction encoding is not canonical";
71
+ const V1_MULTISIG_TX_TYPES = new Set(["fg:t:exchange", "fg:t:exchange_v2"]);
72
+ function assertCanonicalActiveTx(context) {
73
+ if (!context?.txBase64) return;
74
+ const txBuffer = toUint8Array(fromBase64(context.txBase64));
75
+ const isCbor = hasCborSelfDescribeTag(txBuffer);
76
+ const unsignedTx = cloneDeep(isCbor ? decodeTx(txBuffer) : decodeTx$1(txBuffer));
77
+ unsignedTx.signature = void 0;
78
+ const sigs = getListField(unsignedTx, "signatures");
79
+ if (sigs.length > 0) {
80
+ for (const sig of sigs) if (!isCanonicalSigData(sig.data, isCbor)) throw new CustomError("INVALID_TX", NON_CANONICAL_MESSAGE);
81
+ try {
82
+ setListField(unsignedTx, "signatures", sigs.map((x) => {
83
+ const stripped = omit(x, ["signature", "extra"]);
84
+ if (stripped.data) stripped.data = unwrapOpaqueAnyData(decodeAny(stripped.data));
85
+ return stripped;
86
+ }));
87
+ } catch {
88
+ throw new CustomError("INVALID_TX", "Can not decode base64 encoded transaction");
89
+ }
90
+ const unsignedBytes = isCbor ? encodeTx(unsignedTx) : encodeTx$1(unsignedTx);
91
+ Object.defineProperty(context, "unsignedTxHash", {
92
+ value: toTxHash(unsignedBytes),
93
+ enumerable: true,
94
+ configurable: true
95
+ });
96
+ const multiSignV2Txs = get(context, "config.transaction.multiSignV2Txs", []);
97
+ const txType = context.txType;
98
+ if (txType && !multiSignV2Txs.includes(txType)) {
99
+ if (!V1_MULTISIG_TX_TYPES.has(txType)) throw new CustomError("INVALID_SIGNATURE", `Expect 0 multi signatures but found ${sigs.length}`);
100
+ if (sigs.length > 1) throw new CustomError("INVALID_SIGNATURE", `Expect 1 multi signatures but found ${sigs.length}`);
101
+ }
102
+ }
103
+ }
21
104
  function DecodeTx(context, next) {
105
+ let nonCanonical = false;
22
106
  try {
23
107
  const txBuffer = toUint8Array(fromBase64(context.txBase64));
24
108
  const isCbor = hasCborSelfDescribeTag(txBuffer);
25
109
  const tx = isCbor ? decodeTx(txBuffer) : decodeTx$1(txBuffer);
26
- Object.defineProperty(context, "tx", {
27
- value: tx,
28
- enumerable: true
29
- });
30
- Object.defineProperty(context, "txEncoding", {
31
- value: isCbor ? "cbor" : "protobuf",
32
- enumerable: true
33
- });
34
- Object.defineProperty(context, "txSize", {
35
- value: Buffer.byteLength(txBuffer),
36
- enumerable: true
37
- });
38
- Object.defineProperty(context, "txHash", {
39
- value: toTxHash(txBuffer),
40
- enumerable: true
41
- });
42
- Object.defineProperty(context, "txTime", {
43
- value: (/* @__PURE__ */ new Date()).toISOString(),
44
- enumerable: true
45
- });
46
- Object.defineProperty(context, "txBaseGas", {
47
- value: true,
48
- enumerable: true,
49
- writable: true
50
- });
110
+ const reencoded = isCbor ? encodeTx(tx) : encodeTx$1(tx);
111
+ if (reencoded.length !== txBuffer.length || !reencoded.every((b, i) => b === txBuffer[i])) {
112
+ nonCanonical = true;
113
+ throw new CustomError("INVALID_TX", NON_CANONICAL_MESSAGE);
114
+ }
115
+ const unsignedTx = cloneDeep(tx);
116
+ unsignedTx.signature = void 0;
117
+ const sigs = getListField(unsignedTx, "signatures");
118
+ const finalizeDecode = (dedupActive) => {
119
+ if (sigs.length > 0) {
120
+ if (dedupActive) {
121
+ for (const sig of sigs) if (!isCanonicalSigData(sig.data, isCbor)) {
122
+ nonCanonical = true;
123
+ throw new CustomError("INVALID_TX", NON_CANONICAL_MESSAGE);
124
+ }
125
+ }
126
+ setListField(unsignedTx, "signatures", sigs.map((x) => {
127
+ const stripped = omit(x, ["signature", "extra"]);
128
+ if (stripped.data) if (dedupActive) stripped.data = unwrapOpaqueAnyData(decodeAny(stripped.data));
129
+ else try {
130
+ stripped.data = unwrapOpaqueAnyData(decodeAny(stripped.data));
131
+ } catch {}
132
+ return stripped;
133
+ }));
134
+ }
135
+ const unsignedBytes = isCbor ? encodeTx(unsignedTx) : encodeTx$1(unsignedTx);
136
+ Object.defineProperty(context, "tx", {
137
+ value: tx,
138
+ enumerable: true,
139
+ configurable: true
140
+ });
141
+ Object.defineProperty(context, "txEncoding", {
142
+ value: isCbor ? "cbor" : "protobuf",
143
+ enumerable: true,
144
+ configurable: true
145
+ });
146
+ Object.defineProperty(context, "txSize", {
147
+ value: Buffer.byteLength(txBuffer),
148
+ enumerable: true,
149
+ configurable: true
150
+ });
151
+ Object.defineProperty(context, "txHash", {
152
+ value: toTxHash(txBuffer),
153
+ enumerable: true,
154
+ configurable: true
155
+ });
156
+ Object.defineProperty(context, "unsignedTxHash", {
157
+ value: toTxHash(unsignedBytes),
158
+ enumerable: true,
159
+ configurable: true
160
+ });
161
+ const pinned = context.extra?.txTime;
162
+ const pinnedMs = pinned === void 0 || pinned === null || pinned === "" ? NaN : new Date(pinned).getTime();
163
+ Object.defineProperty(context, "txTime", {
164
+ value: Number.isFinite(pinnedMs) ? new Date(pinnedMs).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
165
+ enumerable: true,
166
+ configurable: true
167
+ });
168
+ Object.defineProperty(context, "txBaseGas", {
169
+ value: true,
170
+ enumerable: true,
171
+ writable: true,
172
+ configurable: true
173
+ });
174
+ };
175
+ if (sigs.length > 0) {
176
+ const syncActive = tryResolveDedupHeightActiveSync(context);
177
+ if (syncActive === null) return isDedupHeightActive(context).then((dedupActive) => {
178
+ try {
179
+ finalizeDecode(dedupActive);
180
+ } catch (err) {
181
+ debug("failed to decode transaction", {
182
+ txBase64: context.txBase64,
183
+ error: err
184
+ });
185
+ return next(new CustomError("INVALID_TX", nonCanonical ? NON_CANONICAL_MESSAGE : "Can not decode base64 encoded transaction"));
186
+ }
187
+ next();
188
+ }, (err) => {
189
+ debug("failed to resolve dedup height for transaction", {
190
+ txBase64: context.txBase64,
191
+ error: err
192
+ });
193
+ return next(err);
194
+ });
195
+ finalizeDecode(syncActive);
196
+ } else finalizeDecode(true);
51
197
  } catch (err) {
52
198
  debug("failed to decode transaction", {
53
199
  txBase64: context.txBase64,
54
200
  error: err
55
201
  });
56
- return next(new CustomError("INVALID_TX", "Can not decode base64 encoded transaction"));
202
+ return next(new CustomError("INVALID_TX", nonCanonical ? NON_CANONICAL_MESSAGE : "Can not decode base64 encoded transaction"));
57
203
  }
58
204
  next();
59
205
  }
60
206
 
61
207
  //#endregion
62
- export { DecodeTx as default };
208
+ export { assertCanonicalActiveTx, DecodeTx as default };
@@ -1,6 +1,9 @@
1
+ import { account } from "@ocap/state";
1
2
  import { CustomError } from "@ocap/util/lib/error";
2
- import set from "lodash/set.js";
3
+ import { types } from "@ocap/mcrypto";
3
4
  import { getListField } from "@ocap/util/lib/get-list-field";
5
+ import set from "lodash/set.js";
6
+ import { toTypeInfo } from "@arcblock/did";
4
7
 
5
8
  //#region src/pipes/extract-signer.ts
6
9
  function CreateExtractSignerPipe({ signerKey = "signerStates", delegatorKey = "delegatorStates" } = {}) {
@@ -14,7 +17,13 @@ function CreateExtractSignerPipe({ signerKey = "signerStates", delegatorKey = "d
14
17
  }
15
18
  const signers = signatures.map((x) => x.signer).filter(Boolean);
16
19
  const delegators = signatures.map((x) => x.delegator).filter(Boolean);
17
- const signerStates = (await Promise.all(signers.map((x) => statedb.account.get(x, context)))).filter(Boolean);
20
+ const signerStates = (await Promise.all(signers.map(async (x) => {
21
+ const state = await statedb.account.get(x, context);
22
+ if (!state && toTypeInfo(x).role === types.RoleType.ROLE_ASSET) {
23
+ if (await statedb.asset?.get?.(x, context)) return account.create({ address: x }, context);
24
+ }
25
+ return state;
26
+ }))).filter(Boolean);
18
27
  const delegatorStates = (await Promise.all(delegators.map((x) => statedb.account.get(x, context)))).filter(Boolean);
19
28
  if (signerStates.length !== signers.length) return next(new CustomError("INVALID_SIGNER_STATE", "Signer states does not match"));
20
29
  set(context, signerKey, signerStates);
@@ -7,6 +7,8 @@ interface ExtractStateOptions {
7
7
  to: string;
8
8
  table?: string;
9
9
  status?: string;
10
+ /** Override the default "Invalid state extracted for X: Y" message with a clearer, caller-specific one. */
11
+ message?: (address: string, role: string) => string;
10
12
  }
11
13
  /**
12
14
  * Extract state from state db
@@ -21,7 +23,8 @@ declare function CreateExtractStatePipe<TContext extends IBaseContext = IBaseCon
21
23
  from,
22
24
  to,
23
25
  table,
24
- status
26
+ status,
27
+ message
25
28
  }: ExtractStateOptions): PipeFunction<TContext>;
26
29
  //#endregion
27
30
  export { CreateExtractStatePipe as default };
@@ -1,11 +1,11 @@
1
1
  import { name } from "../package.mjs";
2
- import { CustomError } from "@ocap/util/lib/error";
2
+ import { account, tables } from "@ocap/state";
3
3
  import get from "lodash/get.js";
4
+ import { CustomError } from "@ocap/util/lib/error";
4
5
  import { types } from "@ocap/mcrypto";
5
6
  import Debug from "debug";
6
7
  import set from "lodash/set.js";
7
8
  import { toTypeInfo, toTypeInfoStr } from "@arcblock/did";
8
- import { tables } from "@ocap/state";
9
9
  import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
10
10
  import isEmpty from "lodash/isEmpty.js";
11
11
 
@@ -21,17 +21,17 @@ const getRelatedAddrList = (x) => x.hash ? [x.hash] : getRelatedAddresses(x);
21
21
  * @return {string} params.table which statedb to query, default is auto detect, can be [account,asset,delegation,factory,token]
22
22
  * @return {string} params.status error code when the extracted state is empty
23
23
  */
24
- function CreateExtractStatePipe({ from, to, table, status = "OK" }) {
24
+ function CreateExtractStatePipe({ from, to, table, status = "OK", message }) {
25
25
  if (table && !tables.includes(table)) throw new CustomError("INTERNAL", "Invalid table param for ExtractState pipe");
26
26
  return async function ExtractState(context, next) {
27
27
  if (typeof get(context, to) !== "undefined") return next();
28
- const address = get(context, from);
28
+ const address = get(context, from) ?? (from.endsWith("List") ? get(context, from.slice(0, -4)) : void 0);
29
29
  if (isEmpty(address)) {
30
30
  set(context, to, void 0);
31
31
  return next();
32
32
  }
33
33
  const list = Array.isArray(address) ? address : [address];
34
- const result = (await Promise.all(list.map((x) => {
34
+ const result = (await Promise.all(list.map(async (x) => {
35
35
  if (typeof table === "undefined") {
36
36
  const type = toTypeInfo(x);
37
37
  if (type.role === types.RoleType.ROLE_ASSET) return context.statedb.asset.get(x, context);
@@ -43,7 +43,11 @@ function CreateExtractStatePipe({ from, to, table, status = "OK" }) {
43
43
  if (type.role === types.RoleType.ROLE_TOKEN_FACTORY) return context.statedb.tokenFactory.get(x, context);
44
44
  return context.statedb.account.get(x, context);
45
45
  }
46
- return context.statedb[table].get(x, context);
46
+ const state = await context.statedb[table].get(x, context);
47
+ if (!state && status !== "OK" && table === "account" && toTypeInfo(x).role === types.RoleType.ROLE_ASSET) {
48
+ if (await context.statedb.asset?.get?.(x, context)) return account.create({ address: x }, context);
49
+ }
50
+ return state;
47
51
  }))).filter(Boolean);
48
52
  if (status !== "OK") {
49
53
  const missing = list.find((x) => !result.find((r) => getRelatedAddrList(r).includes(x)));
@@ -52,7 +56,10 @@ function CreateExtractStatePipe({ from, to, table, status = "OK" }) {
52
56
  result,
53
57
  missing
54
58
  });
55
- if (missing) return next(new CustomError(status, `Invalid state extracted for ${(toTypeInfoStr(missing).role || "").replace("ROLE_", "") || table}: ${missing}`, { persist: true }));
59
+ if (missing) {
60
+ const role = (toTypeInfoStr(missing).role || "").replace("ROLE_", "");
61
+ return next(new CustomError(status, message ? message(missing, role || table || "") : `Invalid state extracted for ${role || table}: ${missing}`, { persist: true }));
62
+ }
56
63
  }
57
64
  set(context, to, Array.isArray(address) ? result : result.shift());
58
65
  next();
@@ -1,4 +1,7 @@
1
1
  import { groupStatesByAddress } from "./verify-state-diff.mjs";
2
+ import { isSameDid } from "@ocap/util";
3
+ import { CustomError } from "@ocap/util/lib/error";
4
+ import { getListField } from "@ocap/util/lib/get-list-field";
2
5
  import cloneDeep from "lodash/cloneDeep.js";
3
6
 
4
7
  //#region src/pipes/take-state-snapshot.ts
@@ -10,6 +13,11 @@ function CreateTakeStateSnapshotPipe({ key = "stateSnapshot" } = {}) {
10
13
  return async function TakeStateSnapshot(context, next) {
11
14
  const { statedb } = context;
12
15
  const ctx = context;
16
+ if (ctx.tx?.from && ctx.senderState?.address && ctx.senderState.address !== ctx.tx.from && !isSameDid(ctx.senderState.address, ctx.tx.from)) return next(new CustomError("ACCOUNT_MIGRATED", "Cannot send tx from migrated account"));
17
+ if (ctx.tx && !context.txType?.startsWith("fg:x:")) {
18
+ if (ctx.tx.delegator && !ctx.delegationState && !ctx.isImplicitDelegation) return next(new CustomError("INVALID_DELEGATION", "Delegation is not supported for this transaction"));
19
+ if (getListField(ctx.tx, "signatures").some((s) => Boolean(s?.delegator)) && !ctx.delegationStates && !Array.isArray(ctx.delegationState)) return next(new CustomError("INVALID_DELEGATION", "Multisig delegation is not supported for this transaction"));
20
+ }
13
21
  const [feeVaultState, gasVaultState] = await Promise.all([context.feeVault && !ctx.feeVaultState ? statedb.account.get(context.feeVault, context) : null, context.gasVault && !ctx.gasVaultState ? statedb.account.get(context.gasVault, context) : null]);
14
22
  if (feeVaultState) ctx.feeVaultState = feeVaultState;
15
23
  if (gasVaultState) ctx.gasVaultState = gasVaultState;
@@ -1,7 +1,9 @@
1
1
  import { PipeFunction } from "../runner.mjs";
2
+ import { CustomError } from "@ocap/util/lib/error";
2
3
  import { IBaseContext } from "@ocap/types";
3
4
 
4
5
  //#region src/pipes/update-owner.d.ts
6
+ declare function verifyAssetHierarchy(assetAddresses: string[], newOwnerAddress: string | undefined, context: IBaseContext, pendingOwners?: Record<string, string>, pendingConsumed?: string[]): Promise<CustomError | null>;
5
7
  interface UpdateOwnerOptions {
6
8
  assets: string;
7
9
  owner: string;
@@ -11,4 +13,4 @@ declare function CreateUpdateOwnerPipe({
11
13
  owner
12
14
  }: UpdateOwnerOptions): PipeFunction<IBaseContext>;
13
15
  //#endregion
14
- export { CreateUpdateOwnerPipe as default };
16
+ export { CreateUpdateOwnerPipe as default, verifyAssetHierarchy };
@@ -1,11 +1,35 @@
1
1
  import { name } from "../package.mjs";
2
- import { CustomError } from "@ocap/util/lib/error";
3
2
  import get from "lodash/get.js";
3
+ import { isSameDid } from "@ocap/util";
4
+ import { CustomError } from "@ocap/util/lib/error";
5
+ import { types } from "@ocap/mcrypto";
4
6
  import Debug from "debug";
5
7
  import set from "lodash/set.js";
8
+ import { toTypeInfo } from "@arcblock/did";
6
9
 
7
10
  //#region src/pipes/update-owner.ts
8
11
  const debug = Debug(`${name}:pipe:update-owner`);
12
+ async function verifyAssetHierarchy(assetAddresses, newOwnerAddress, context, pendingOwners, pendingConsumed) {
13
+ if (!newOwnerAddress || !assetAddresses || assetAddresses.length === 0) return null;
14
+ if (toTypeInfo(newOwnerAddress).role !== types.RoleType.ROLE_ASSET) return null;
15
+ if (assetAddresses.some((addr) => isSameDid(addr, newOwnerAddress))) return new CustomError("INVALID_OWNER", `Asset ${newOwnerAddress} cannot own itself`, { persist: true });
16
+ if (!context.statedb?.asset?.get) return new CustomError("INVALID_OWNER", `Target owner asset ${newOwnerAddress} does not exist`, { persist: true });
17
+ const visited = new Set(assetAddresses);
18
+ let current = newOwnerAddress;
19
+ while (current) {
20
+ if (visited.has(current)) return new CustomError("INVALID_OWNER", `Circular asset ownership detected for ${current}`, { persist: true });
21
+ visited.add(current);
22
+ const parentAsset = await context.statedb.asset.get(current, context);
23
+ if (!parentAsset) return new CustomError("INVALID_OWNER", `Target owner asset ${current} does not exist`, { persist: true });
24
+ if (parentAsset.consumedTime || pendingConsumed?.some((addr) => isSameDid(addr, current))) return new CustomError("INVALID_OWNER", `Target owner asset ${current} is already consumed`, { persist: true });
25
+ const nextOwner = pendingOwners?.[current] ?? parentAsset.owner;
26
+ if (!nextOwner) return new CustomError("INVALID_OWNER", `Target owner asset ${current} has no owner`, { persist: true });
27
+ if (assetAddresses.some((addr) => isSameDid(addr, nextOwner)) || visited.has(nextOwner)) return new CustomError("INVALID_OWNER", `Circular asset ownership detected for ${nextOwner}`, { persist: true });
28
+ if (toTypeInfo(nextOwner).role !== types.RoleType.ROLE_ASSET) return null;
29
+ current = nextOwner;
30
+ }
31
+ return null;
32
+ }
9
33
  function CreateUpdateOwnerPipe({ assets, owner }) {
10
34
  return async function UpdateOwner(context, next) {
11
35
  const items = get(context, assets);
@@ -20,6 +44,8 @@ function CreateUpdateOwnerPipe({ assets, owner }) {
20
44
  ownerAddress,
21
45
  items: itemList
22
46
  });
47
+ const hierarchyError = await verifyAssetHierarchy(itemList.map((item) => item.address), ownerAddress, context);
48
+ if (hierarchyError) return next(hierarchyError);
23
49
  try {
24
50
  const updated = await Promise.all(itemList.map(async (item) => {
25
51
  const old = await statedb.asset.get(item.address, context);
@@ -35,4 +61,4 @@ function CreateUpdateOwnerPipe({ assets, owner }) {
35
61
  }
36
62
 
37
63
  //#endregion
38
- export { CreateUpdateOwnerPipe as default };
64
+ export { CreateUpdateOwnerPipe as default, verifyAssetHierarchy };
@@ -1,12 +1,12 @@
1
- import { CustomError } from "@ocap/util/lib/error";
2
1
  import get from "lodash/get.js";
2
+ import { CustomError } from "@ocap/util/lib/error";
3
3
  import { getListField } from "@ocap/util/lib/get-list-field";
4
4
 
5
5
  //#region src/pipes/verify-account-migration.ts
6
6
  function CreateVerifyAccountMigrationPipe({ stateKey = "", addressKey = "", signerKey = "" }) {
7
7
  return function VerifyAccountMigration(context, next) {
8
8
  if (stateKey && addressKey) {
9
- const rawAddressList = get(context, addressKey);
9
+ const rawAddressList = get(context, addressKey) ?? (addressKey.endsWith("List") ? get(context, addressKey.slice(0, -4)) : void 0);
10
10
  const rawStateList = get(context, stateKey);
11
11
  if (rawAddressList && rawStateList) {
12
12
  const stateList = (Array.isArray(rawStateList) ? rawStateList : [rawStateList]).filter(Boolean);
@@ -1,5 +1,5 @@
1
- import { CustomError } from "@ocap/util/lib/error";
2
1
  import get from "lodash/get.js";
2
+ import { CustomError } from "@ocap/util/lib/error";
3
3
  import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
4
4
 
5
5
  //#region src/pipes/verify-blocked.ts