@ocap/state 1.30.26 → 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.
@@ -1,33 +1,57 @@
1
1
  import { StateContextInput } from "../contexts/state.cjs";
2
- import { ITokenState } from "@ocap/types";
2
+ import { IAssetState, ITokenState } from "@ocap/types";
3
3
  import { v } from "@arcblock/validator";
4
4
 
5
5
  //#region src/states/token.d.ts
6
6
  declare namespace token_d_exports {
7
- export { create, metadataSchema, stateSchema, update, validate };
7
+ export { TOKEN_CHARTER_KIND, TokenCharterAssetPayload, buildTokenCharterAssetData, buildTokenCharterAssetState, create, extractTokenUpdatesFromCharterAsset, iconToNftDisplay, isTokenCharterAsset, metadataSchema, migrateTokensToCharterAssets, multiChainForeignTokenSchema, normalizeLegacyTokenStateForUpdate, resolveCharterMoniker, sanitizeTokenSvg, stateSchema, syncCharterAssetWithToken, syncTokenCharterOwnership, toTokenCharterAssetAddress, update, validate, websiteToNftEndpoint };
8
+ }
9
+ declare const TOKEN_CHARTER_KIND: "TokenCharter";
10
+ interface TokenCharterAssetPayload {
11
+ kind: typeof TOKEN_CHARTER_KIND;
12
+ tokenAddress: string;
13
+ symbol: string;
14
+ name: string;
15
+ description: string;
16
+ unit: string;
17
+ decimal: number;
18
+ icon: string;
19
+ website: string;
20
+ metadata: {
21
+ communityUrl?: string | null;
22
+ issuer: string;
23
+ } | null;
24
+ tokenFactoryAddress: string;
8
25
  }
9
26
  declare const metadataSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
10
27
  readonly communityUrl: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>, v.CheckAction<string, "Must be HTTPS URL">]>], undefined>, undefined>, undefined>;
11
28
  readonly issuer: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 64, undefined>]>;
12
29
  }, undefined>, any]>;
30
+ declare const multiChainForeignTokenSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
31
+ readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
32
+ readonly contractAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
33
+ readonly chainType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
34
+ readonly chainName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
35
+ readonly chainId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.CheckAction<number, "Must be positive">]>;
36
+ }, undefined>, v.BaseValidation<any, any, v.CheckIssue<any>>, any]>;
13
37
  declare const stateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
14
38
  readonly address: any;
15
39
  readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
16
40
  readonly description: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 16, undefined>, v.MaxLengthAction<string, 128, undefined>]>;
17
41
  readonly symbol: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 2, undefined>, v.MaxLengthAction<string, 6, undefined>, v.TransformAction<string, string>]>;
18
42
  readonly unit: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 6, undefined>, v.TransformAction<string, string>]>;
19
- readonly decimal: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 2, undefined>, v.MaxValueAction<number, 18, undefined>]>;
43
+ readonly decimal: v.UnionSchema<[v.LiteralSchema<0, undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 2, undefined>, v.MaxValueAction<number, 18, undefined>]>], undefined>;
20
44
  readonly icon: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
21
45
  readonly totalSupply: any;
22
46
  readonly initialSupply: any;
23
47
  readonly maxTotalSupply: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, any], undefined>, undefined>, undefined>;
24
- readonly foreignToken: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
48
+ readonly foreignToken: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
25
49
  readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
26
- readonly contractAddress: any;
50
+ readonly contractAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
27
51
  readonly chainType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
28
52
  readonly chainName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
29
53
  readonly chainId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.CheckAction<number, "Must be positive">]>;
30
- }, undefined>, undefined>, undefined>;
54
+ }, undefined>, v.BaseValidation<any, any, v.CheckIssue<any>>, any]>, undefined>, undefined>;
31
55
  readonly issuer: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, any], undefined>, undefined>, undefined>;
32
56
  readonly website: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>, v.CheckAction<string, "Must be valid URL">]>], undefined>, undefined>, undefined>;
33
57
  readonly metadata: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
@@ -52,5 +76,85 @@ declare const stateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
52
76
  declare const create: (attrs: Partial<ITokenState>, context: StateContextInput) => ITokenState;
53
77
  declare const update: (state: ITokenState, attrs: Partial<ITokenState>) => ITokenState;
54
78
  declare const validate: (state: ITokenState) => ITokenState;
79
+ /**
80
+ * Deterministically derive the companion Master Charter NFT address (`ROLE_ASSET`)
81
+ * for a given Fungible Token address (`ROLE_TOKEN`).
82
+ */
83
+ declare const toTokenCharterAssetAddress: (tokenAddress: string) => string;
84
+ /**
85
+ * Strip dangerous XSS elements/attributes (`<script>`, `<foreignObject>`, `<iframe>`,
86
+ * inline `on*` event handlers, and `javascript:`/`data:text/html` URIs) from SVG strings.
87
+ */
88
+ declare const sanitizeTokenSvg: (svg: string) => string;
89
+ declare const iconToNftDisplay: (icon?: string | null) => IAssetState["display"];
90
+ declare const websiteToNftEndpoint: (website?: string | null) => IAssetState["endpoint"];
91
+ declare const buildTokenCharterAssetData: (tokenState: ITokenState) => {
92
+ type: "json";
93
+ value: TokenCharterAssetPayload;
94
+ };
95
+ declare const resolveCharterMoniker: (tokenState: ITokenState) => string;
96
+ /**
97
+ * Build the companion Master Charter `AssetState` (`ROLE_ASSET`) for a `TokenState`.
98
+ */
99
+ declare const buildTokenCharterAssetState: (tokenState: ITokenState, context?: StateContextInput, ownerOverride?: string) => IAssetState;
100
+ /**
101
+ * Verify whether an `AssetState` is a genuine, cryptographically bound Token Charter NFT.
102
+ * Checks both the `TokenCharter` payload structure and the deterministic 1:1 DID binding
103
+ * (`toTokenCharterAssetAddress(tokenAddress) === assetState.address`) to prevent spoofing.
104
+ */
105
+ declare const isTokenCharterAsset: (assetState?: Partial<IAssetState> | null) => boolean;
106
+ /**
107
+ * Extract validated `TokenState` field updates when a Token Charter NFT is updated via `UpdateAssetTx`
108
+ * or transferred via `UpdateOwner`.
109
+ */
110
+ declare const extractTokenUpdatesFromCharterAsset: (tokenState: ITokenState, charterAsset: IAssetState) => Partial<ITokenState>;
111
+ /**
112
+ * Synchronize an existing Token Charter `AssetState` with updated `TokenState` fields.
113
+ */
114
+ declare const syncCharterAssetWithToken: (charterAsset: IAssetState, tokenState: ITokenState, context: StateContextInput, ownerOverride?: string) => IAssetState;
115
+ /**
116
+ * Normalize legacy `TokenState` fields (such as short descriptions or non-ISO context dates)
117
+ * before re-validating during ownership transfer or migration so legacy rows never brick updates.
118
+ */
119
+ declare const normalizeLegacyTokenStateForUpdate: (existingToken: ITokenState) => ITokenState;
120
+ /**
121
+ * Atomically synchronize `TokenState.issuer` and `TokenFactoryState.owner` whenever
122
+ * a Token Charter NFT changes owner (via `UpdateOwner`, `TransferV3Tx`, `ClaimStakeTx`,
123
+ * `ReturnStakeTx`, or `SlashStakeTx`).
124
+ * Validates all target state updates BEFORE writing to `statedb` to prevent partial writes.
125
+ */
126
+ declare const syncTokenCharterOwnership: (charterAsset: Partial<IAssetState> | null | undefined, newOwnerAddress: string | undefined, statedb: {
127
+ token?: {
128
+ get?: (key: string, ctx?: any) => Promise<ITokenState | null>;
129
+ update?: (key: string, state: ITokenState, ctx?: any) => Promise<ITokenState>;
130
+ };
131
+ tokenFactory?: {
132
+ get?: (key: string, ctx?: any) => Promise<any>;
133
+ update?: (key: string, state: any, ctx?: any) => Promise<any>;
134
+ };
135
+ }, context: StateContextInput) => Promise<void>;
136
+ /**
137
+ * Programmatic state migration helper: scans all existing `TokenState` records in `statedb.token`
138
+ * and idempotently backfills their companion Master Charter `AssetState` records in `statedb.asset`.
139
+ */
140
+ declare const migrateTokensToCharterAssets: (statedb: {
141
+ token?: {
142
+ findAll?: (query?: Record<string, unknown>, ctx?: unknown) => Promise<ITokenState[]>;
143
+ find?: (query?: Record<string, unknown>, ctx?: unknown) => Promise<ITokenState[]>;
144
+ };
145
+ asset?: {
146
+ get: (key: string, ctx?: unknown) => Promise<IAssetState | null>;
147
+ create: (key: string, state: IAssetState, ctx?: unknown) => Promise<IAssetState>;
148
+ };
149
+ tokenFactory?: {
150
+ get: (key: string, ctx?: unknown) => Promise<{
151
+ owner?: string;
152
+ } | null>;
153
+ };
154
+ }, operationContext?: unknown) => Promise<{
155
+ migrated: number;
156
+ skipped: number;
157
+ charterAddresses: string[];
158
+ }>;
55
159
  //#endregion
56
- export { create, metadataSchema, stateSchema, token_d_exports, update, validate };
160
+ export { TOKEN_CHARTER_KIND, TokenCharterAssetPayload, buildTokenCharterAssetData, buildTokenCharterAssetState, create, extractTokenUpdatesFromCharterAsset, iconToNftDisplay, isTokenCharterAsset, metadataSchema, migrateTokensToCharterAssets, multiChainForeignTokenSchema, normalizeLegacyTokenStateForUpdate, resolveCharterMoniker, sanitizeTokenSvg, stateSchema, syncCharterAssetWithToken, syncTokenCharterOwnership, toTokenCharterAssetAddress, token_d_exports, update, validate, websiteToNftEndpoint };
package/lib/states/tx.cjs CHANGED
@@ -2,10 +2,10 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  let _arcblock_did = require("@arcblock/did");
3
3
  let _ocap_util = require("@ocap/util");
4
4
  let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
- let lodash_get = require("lodash/get");
6
- lodash_get = require_rolldown_runtime.__toESM(lodash_get);
7
5
  let lodash_pick = require("lodash/pick");
8
6
  lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
7
+ let lodash_get = require("lodash/get");
8
+ lodash_get = require_rolldown_runtime.__toESM(lodash_get);
9
9
  let _ocap_message = require("@ocap/message");
10
10
  let _ocap_util_lib_get_list_field = require("@ocap/util/lib/get-list-field");
11
11
  let _ocap_util_lib_get_related_addr = require("@ocap/util/lib/get-related-addr");
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.30.26",
6
+ "version": "1.31.0",
7
7
  "description": "State management utilities for OCAP blockchain",
8
8
  "type": "module",
9
9
  "main": "./lib/index.cjs",
@@ -40,14 +40,14 @@
40
40
  "clean": "rm -rf lib esm"
41
41
  },
42
42
  "dependencies": {
43
- "@arcblock/did": "1.30.26",
44
- "@arcblock/validator": "1.30.26",
45
- "@ocap/contract": "1.30.26",
46
- "@ocap/mcrypto": "1.30.26",
47
- "@ocap/message": "1.30.26",
48
- "@ocap/types": "1.30.26",
49
- "@ocap/util": "1.30.26",
50
- "@ocap/wallet": "1.30.26",
43
+ "@arcblock/did": "1.31.0",
44
+ "@arcblock/validator": "1.31.0",
45
+ "@ocap/contract": "1.31.0",
46
+ "@ocap/mcrypto": "1.31.0",
47
+ "@ocap/message": "1.31.0",
48
+ "@ocap/types": "1.31.0",
49
+ "@ocap/util": "1.31.0",
50
+ "@ocap/wallet": "1.31.0",
51
51
  "bloom-filters": "^1.3.9",
52
52
  "lodash": "^4.17.23"
53
53
  },