suidouble 1.45.2 → 2.16.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.
Files changed (59) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/README.md +222 -131
  3. package/index.js +1 -3
  4. package/lib/SuiCliCommands.js +18 -25
  5. package/lib/SuiCoin.js +86 -138
  6. package/lib/SuiCoins.js +70 -31
  7. package/lib/SuiCommonMethods.js +40 -3
  8. package/lib/SuiEvent.js +54 -6
  9. package/lib/SuiInBrowser.js +145 -46
  10. package/lib/SuiInBrowserAdapter.js +164 -37
  11. package/lib/SuiLocalTestValidator.js +78 -25
  12. package/lib/SuiMaster.js +351 -126
  13. package/lib/SuiMemoryObjectStorage.js +66 -73
  14. package/lib/SuiObject.js +128 -153
  15. package/lib/SuiPackage.js +292 -187
  16. package/lib/SuiPackageModule.js +176 -221
  17. package/lib/SuiPaginatedResponse.js +288 -25
  18. package/lib/SuiPseudoRandomAddress.js +29 -2
  19. package/lib/SuiTransaction.js +115 -70
  20. package/lib/SuiUtils.js +179 -124
  21. package/package.json +30 -14
  22. package/test/build_modules.test.js +41 -0
  23. package/test/coins.test.js +17 -16
  24. package/test/custom_transaction.test.js +167 -0
  25. package/test/event_listeners.test.js +171 -0
  26. package/test/failed_transaction.test.js +184 -0
  27. package/test/name_service.test.js +28 -0
  28. package/test/owned_objects.test.js +148 -0
  29. package/test/rpc.test.js +3 -6
  30. package/test/sui_in_browser.test.js +2 -2
  31. package/test/sui_master_basic.test.js +4 -5
  32. package/test/sui_master_onlocal.test.js +84 -22
  33. package/test/sui_object_properties.test.js +85 -0
  34. package/test/test_move_contracts/different_types/Move.lock +18 -21
  35. package/test/test_move_contracts/different_types/sources/different_types.move +12 -12
  36. package/test/test_move_contracts/suidouble_chat/Move.lock +18 -22
  37. package/test/test_move_contracts/suidouble_chat/sources/suidouble_chat.move +9 -8
  38. package/tsconfig.json +15 -0
  39. package/types/index.d.ts +15 -0
  40. package/types/lib/SuiCliCommands.d.ts +6 -0
  41. package/types/lib/SuiCoin.d.ts +183 -0
  42. package/types/lib/SuiCoins.d.ts +93 -0
  43. package/types/lib/SuiCommonMethods.d.ts +37 -0
  44. package/types/lib/SuiEvent.d.ts +95 -0
  45. package/types/lib/SuiInBrowser.d.ts +189 -0
  46. package/types/lib/SuiInBrowserAdapter.d.ts +167 -0
  47. package/types/lib/SuiLocalTestValidator.d.ts +92 -0
  48. package/types/lib/SuiMaster.d.ts +333 -0
  49. package/types/lib/SuiMemoryObjectStorage.d.ts +96 -0
  50. package/types/lib/SuiObject.d.ts +135 -0
  51. package/types/lib/SuiPackage.d.ts +233 -0
  52. package/types/lib/SuiPackageModule.d.ts +139 -0
  53. package/types/lib/SuiPaginatedResponse.d.ts +148 -0
  54. package/types/lib/SuiPseudoRandomAddress.d.ts +33 -0
  55. package/types/lib/SuiTransaction.d.ts +92 -0
  56. package/types/lib/SuiUtils.d.ts +152 -0
  57. package/types/lib/data/icons.d.ts +12 -0
  58. package/lib/SuiTestScenario.js +0 -169
  59. package/test/sui_test_scenario.test.js +0 -61
@@ -0,0 +1,333 @@
1
+ /**
2
+ * @import { SuiClientTypes } from "@mysten/sui/client"
3
+ *
4
+ * @typedef {import("@mysten/sui/grpc").SuiGrpcClient} SuiGrpcClient
5
+ * @typedef {import("@mysten/sui/graphql").SuiGraphQLClient} SuiGraphQLClient
6
+ * @typedef {import("@mysten/sui/cryptography").Signer} SuiSigner
7
+ * @typedef {import("@mysten/sui/cryptography").Keypair} SuiKeypair
8
+ * @typedef {import("./SuiInBrowser.js").default} SuiInBrowser
9
+ */
10
+ declare class SuiMaster extends SuiCommonMethods {
11
+ static instancesCount: number;
12
+ /**
13
+ * gRPC `ListOwnedObjects.objectType` only accepts a full struct type. A bare package address or
14
+ * `package::module` string needs the GraphQL path.
15
+ * @param {?string} type
16
+ * @returns {boolean}
17
+ */
18
+ static _typeNeedsGraphqlOwned(type: string | null): boolean;
19
+ /**
20
+ * SuiMaster constructor
21
+ * @param {Object} params - Initialization parameters
22
+ * @param {SuiSigner|SuiInBrowser} [params.signer] - instance of Sui SDK Signer (like Keypair) or SuiInBrowser for browser wallet signing
23
+ * @param {SuiKeypair} [params.keypair] - instance of Sui SDK Keypair
24
+ * @param {string} [params.privateKey] - private key in Sui format, starting with "suiprivkey1"
25
+ * @param {boolean} [params.debug] - enable debug mode
26
+ * @param {string} [params.phrase] - mnemonic phrase to derive keypair from
27
+ * @param {string} [params.keypairAlgo] - keypair algorithm to use with mnemonic phrase. One of 'ed25519' (default), 'secp256k1', 'secp256r1'
28
+ * @param {number} [params.accountIndex] - index of account to derive from mnemonic phrase. Default is 0
29
+ * @param {string} [params.as] - pseudo-random address generation seed string
30
+ * @param {SuiGrpcClient|string} [params.client] - instance of SuiGrpcClient or chain name to make SuiGrpcClient connected to it (like 'local', 'devnet', 'testnet', 'mainnet')
31
+ */
32
+ constructor(params: {
33
+ signer?: SuiSigner | SuiInBrowser;
34
+ keypair?: SuiKeypair;
35
+ privateKey?: string;
36
+ debug?: boolean;
37
+ phrase?: string;
38
+ keypairAlgo?: string;
39
+ accountIndex?: number;
40
+ as?: string;
41
+ client?: SuiGrpcClient | string;
42
+ });
43
+ _instanceN: number;
44
+ /** @type {SuiSigner|SuiInBrowser|null} */
45
+ _signer: SuiSigner | SuiInBrowser | null;
46
+ /** @type {SuiKeypair} */
47
+ _keypair: SuiKeypair;
48
+ /** @type {string} */
49
+ _address: string;
50
+ /** @type {SuiGrpcClient} */
51
+ _client: SuiGrpcClient;
52
+ /**
53
+ * Lazy — do not read directly, use the `graphqlClient` getter so it's built on first access.
54
+ * @type {?SuiGraphQLClient}
55
+ */
56
+ _graphqlClient: SuiGraphQLClient | null;
57
+ /** @type {string} */
58
+ _providerName: string;
59
+ /** @type {SuiMemoryObjectStorage} */
60
+ _objectStorage: SuiMemoryObjectStorage;
61
+ /** @type {boolean} */
62
+ _initialized: boolean;
63
+ /** @type {Object.<string, SuiPackage>} */
64
+ _packages: {
65
+ [x: string]: SuiPackage;
66
+ };
67
+ /** @type {SuiCoins} */
68
+ _suiCoins: SuiCoins;
69
+ /** @returns {typeof SuiUtils} static SuiUtils helper class */
70
+ get utils(): typeof SuiUtils;
71
+ /**
72
+ * Instance of SuiCoins class connected to this SuiMaster
73
+ *
74
+ * @type {SuiCoins}
75
+ */
76
+ get suiCoins(): SuiCoins;
77
+ /** @returns {bigint} `1_000_000_000n` — number of MIST per SUI */
78
+ get MIST_PER_SUI(): bigint;
79
+ /** @returns {typeof Transaction} SDK `Transaction` class, exposed to avoid extra imports at call sites */
80
+ get Transaction(): typeof Transaction;
81
+ /** @returns {typeof Commands} SDK `TransactionCommands` class, exposed to avoid extra imports at call sites */
82
+ get Commands(): typeof Commands;
83
+ /**
84
+ * Referencing it here to get rid of circullar dependency. So you can always call SuiObject contructor if you have instance of SuiMaster
85
+ */
86
+ get SuiObject(): typeof SuiObject;
87
+ /**
88
+ * Referencing it here to get rid of circullar dependency. So you can always call SuiTransaction contructor if you have instance of SuiMaster
89
+ */
90
+ get SuiTransaction(): typeof SuiTransaction;
91
+ /**
92
+ * Referencing it here to get rid of circullar dependency. So you can always call SuiEvent contructor if you have instance of SuiMaster
93
+ */
94
+ get SuiEvent(): typeof SuiEvent;
95
+ /**
96
+ * Referencing it here to get rid of circullar dependency. So you can always call SuiPaginatedResponse contructor if you have instance of SuiMaster
97
+ */
98
+ get SuiPaginatedResponse(): typeof SuiPaginatedResponse;
99
+ /**
100
+ * Storage storing all objects interacted by this suiMaster
101
+ *
102
+ * @type {SuiMemoryObjectStorage}
103
+ */
104
+ get objectStorage(): SuiMemoryObjectStorage;
105
+ /** @returns {number} monotonically increasing instance counter, useful for differentiating logs */
106
+ get instanceN(): number;
107
+ /** @returns {SuiGrpcClient} gRPC client for the connected chain */
108
+ get client(): SuiGrpcClient;
109
+ /**
110
+ * Lazily-built SuiGraphQLClient that reuses the network of this suiMaster's gRPC client.
111
+ * @returns {SuiGraphQLClient}
112
+ */
113
+ get graphqlClient(): SuiGraphQLClient;
114
+ /** @returns {string} connected chain identifier, e.g. `'mainnet'` or `'localnet'` */
115
+ get connectedChain(): string;
116
+ /**
117
+ * determine if this suiMaster is connected to mainnet or not
118
+ * @returns {boolean} is on mainnet
119
+ */
120
+ get onMainnet(): boolean;
121
+ /** @returns {?string} connected Sui address, or null in read-only mode before `initialize()` */
122
+ get address(): string | null;
123
+ /** @returns {SuiSigner|SuiInBrowser|null} active signer/keypair, or null in read-only mode */
124
+ get signer(): SuiSigner | SuiInBrowser | null;
125
+ /**
126
+ * Attach a smart contract package to this SuiMaster instance.
127
+ *
128
+ * @param {Object} params - Configuration parameters
129
+ * @param {?string} [params.path] - Local filesystem path to the Move package source code
130
+ * @param {?string} [params.id] - ID or address of the Move package on the Sui blockchain
131
+ * @param {?Array.<string>|string} [params.modules] - List of modules in the package to look on chain in the UpgradeCap owned by current address
132
+ *
133
+ * @returns {SuiPackage}
134
+ */
135
+ package(params?: {
136
+ path?: string | null;
137
+ id?: string | null;
138
+ modules?: (Array<string> | string) | null;
139
+ }): SuiPackage;
140
+ /**
141
+ * Attach a smart contract package to this SuiMaster instance.
142
+ *
143
+ * @param {Object} params - Configuration parameters
144
+ * @param {?string} [params.path] - Local filesystem path to the Move package source code
145
+ * @param {?string} [params.id] - ID or address of the Move package on the Sui blockchain
146
+ * @param {?Array.<string>|string} [params.modules] - List of modules in the package to look on chain in the UpgradeCap owned by current address
147
+ *
148
+ * @returns {SuiPackage}
149
+ */
150
+ addPackage(params: {
151
+ path?: string | null;
152
+ id?: string | null;
153
+ modules?: (Array<string> | string) | null;
154
+ }): SuiPackage;
155
+ /**
156
+ * Ensure `initialize()` has run, then return the gRPC client.
157
+ * @returns {Promise<SuiGrpcClient>}
158
+ */
159
+ getClient(): Promise<SuiGrpcClient>;
160
+ /**
161
+ * Resolve the connected address from the signer/keypair (if any) and mark the instance as
162
+ * ready. Idempotent — subsequent calls return immediately.
163
+ * @returns {Promise<boolean>}
164
+ */
165
+ initialize(): Promise<boolean>;
166
+ /**
167
+ * Return the primary Name Service name for the connected wallet address, or null if none.
168
+ * Uses `client.core.defaultNameServiceName` (v2 gRPC).
169
+ * @returns {Promise<string | null>}
170
+ */
171
+ defaultNameServiceName(): Promise<string | null>;
172
+ /**
173
+ * Fetch many on-chain objects. The v2 client batches internally (50 per request).
174
+ *
175
+ * Per-item behavior:
176
+ * - if a `SuiObject` is passed in, it is updated in place via `replaceWithSuiObjectIfNeeded`
177
+ * and returned at its original index in the output array (same instance reference).
178
+ * - if a string id is passed in, a freshly-constructed `SuiObject` is returned at that index.
179
+ * - if an item couldn't be matched in the response, the original (or a new bare) SuiObject is
180
+ * still placed at that index — no nulls, no skipped slots.
181
+ *
182
+ * Errors-in-results entries from the client are skipped silently. Returns `[]` for empty input.
183
+ *
184
+ * @param {Array<string | SuiObject>} idsOrSuiObjects - mix of object ids and/or SuiObject instances
185
+ * @param {SuiClientTypes.ObjectInclude} [include] - fields to include; defaults to content/json/display
186
+ * @returns {Promise<SuiObject[]>} array aligned with input order
187
+ */
188
+ getObjects(idsOrSuiObjects: Array<string | SuiObject>, include?: SuiClientTypes.ObjectInclude): Promise<SuiObject[]>;
189
+ /**
190
+ * Fetch a single on-chain object and return it wrapped in a SuiObject.
191
+ *
192
+ * @param {string | SuiObject} idOrSuiObject - object id, or a SuiObject instance whose `.address` will be used
193
+ * @param {SuiClientTypes.ObjectInclude} [include] - fields to include; defaults to content/json/display
194
+ * @returns {Promise<?SuiObject>} SuiObject populated from the api, or null if not found
195
+ */
196
+ getObject(idOrSuiObject: string | SuiObject, include?: SuiClientTypes.ObjectInclude): Promise<SuiObject | null>;
197
+ /**
198
+ * List objects owned by an address. Picks the right backend based on `input.type`:
199
+ *
200
+ * - no type / full struct type (`pkg::mod::Struct[<...>]`) → gRPC `listOwnedObjects` (fast path)
201
+ * - package (`pkg`) or module (`pkg::mod`) filter → GraphQL `address.objects` (gRPC can't parse those)
202
+ *
203
+ * @param {SuiClientTypes.ListOwnedObjectsOptions<SuiClientTypes.ObjectInclude>} input
204
+ * @param {Object} [extra]
205
+ * @param {string} [extra.order]
206
+ * @returns {Promise<SuiPaginatedResponse<SuiObject>>}
207
+ */
208
+ getOwnedObjects(input: SuiClientTypes.ListOwnedObjectsOptions<SuiClientTypes.ObjectInclude>, extra?: {
209
+ order?: string;
210
+ }): Promise<SuiPaginatedResponse<SuiObject>>;
211
+ /**
212
+ * Sign and execute a transaction on the Sui blockchain.
213
+ * Uses the connected keypair or signer or browser extension wallet adapter to sign the transaction before submitting it.
214
+ *
215
+ * Throws on two failure paths, both with a normalised `executionError` + `digest` shape:
216
+ *
217
+ * 1. **`SimulationError`** (SDK, pre-submission) — thrown during `tx.build()` / gas selection
218
+ * when the SDK simulates the transaction and detects an abort before even submitting.
219
+ * `executionError` is set by the SDK; `digest` is `null` (no submission happened).
220
+ *
221
+ * 2. **`FailedTransaction`** (on-chain) — the transaction was submitted and executed but aborted.
222
+ * Both `executionError` and `digest` are set.
223
+ *
224
+ * In both cases the error has:
225
+ * - `message` — human-readable failure reason
226
+ * - `executionError` — `SuiClientTypes.ExecutionError`:
227
+ * `{ message, command?, MoveAbort?, SizeError?, CommandArgumentError?, TypeArgumentError?, ... }`
228
+ * - `digest` — transaction digest, or `null` for pre-submission failures
229
+ *
230
+ * @param {{ transaction: Transaction, include?: SuiClientTypes.TransactionInclude, requestType?: string }} params
231
+ * @returns {Promise<SuiTransaction>}
232
+ * @throws {Error & { executionError: SuiClientTypes.ExecutionError, digest: ?string }} if the transaction fails on-chain
233
+ */
234
+ signAndExecuteTransaction(params: {
235
+ transaction: Transaction;
236
+ include?: SuiClientTypes.TransactionInclude;
237
+ requestType?: string;
238
+ }): Promise<SuiTransaction>;
239
+ /**
240
+ * Request SUI tokens from the faucet for the connected address.
241
+ * Only works on localnet, devnet, and testnet.
242
+ * @returns {Promise<bigint>} total MIST received across all coin objects
243
+ */
244
+ requestSuiFromFaucet(): Promise<bigint>;
245
+ /**
246
+ * Query the balance of specific coinType for an owner. If owner == null, returns balance of connected address owner
247
+ *
248
+ * @param {string} [coinType='0x2::sui::SUI']
249
+ * @param {?string} [owner] - defaults to the connected address
250
+ * @returns {Promise<bigint>}
251
+ */
252
+ getBalance(coinType?: string, owner?: string | null): Promise<bigint>;
253
+ /**
254
+ * Fetch events via the GraphQL `events` query. Lowest-level entry point —
255
+ * `SuiPackage.fetchEvents` and `SuiPackageModule.fetchEvents` both delegate here.
256
+ *
257
+ * The filter is a GraphQL `EventFilter`:
258
+ * - `module` : "<package>" or "<package>::<module>"
259
+ * - `type` : "<package>::<module>::<EventName>" (or a prefix thereof)
260
+ * - `sender` : SuiAddress
261
+ * - `atCheckpoint` / `afterCheckpoint` / `beforeCheckpoint` : UInt53
262
+ *
263
+ * @param {Object} [params]
264
+ * @param {Object} [params.filter] - GraphQL EventFilter
265
+ * @param {number} [params.limit=50]
266
+ * @param {string} [params.order] - Passed through to the underlying paginated response
267
+ * @returns {Promise<SuiPaginatedResponse<SuiEvent>>}
268
+ */
269
+ fetchEvents(params?: {
270
+ filter?: any;
271
+ limit?: number;
272
+ order?: string;
273
+ }): Promise<SuiPaginatedResponse<SuiEvent>>;
274
+ /**
275
+ * Fetch transactions via the GraphQL root `transactions(filter: TransactionFilter)` query.
276
+ *
277
+ * Accepts either a direct `params.filter` (GraphQL `TransactionFilter` shape) or the legacy
278
+ * convenience fields (`fromAddress`, `affectedAddress`, `affectedObject`, `function`, `atCheckpoint`,
279
+ * `afterCheckpoint`, `beforeCheckpoint`, `kind`) which get translated to the corresponding
280
+ * `TransactionFilter` fields.
281
+ *
282
+ * @param {Object} [params]
283
+ * @param {Object} [params.filter] - raw TransactionFilter; overrides the convenience fields if set
284
+ * @param {?string} [params.fromAddress]
285
+ * @param {?string} [params.affectedAddress]
286
+ * @param {?string} [params.affectedObject]
287
+ * @param {?string} [params.function]
288
+ * @param {?number} [params.atCheckpoint]
289
+ * @param {?number} [params.afterCheckpoint]
290
+ * @param {?number} [params.beforeCheckpoint]
291
+ * @param {?string} [params.kind]
292
+ * @param {number} [params.limit=50]
293
+ * @param {string} [params.order]
294
+ * @returns {Promise<SuiPaginatedResponse<SuiTransaction>>}
295
+ */
296
+ fetchTransactions(params?: {
297
+ filter?: any;
298
+ fromAddress?: string | null;
299
+ affectedAddress?: string | null;
300
+ affectedObject?: string | null;
301
+ function?: string | null;
302
+ atCheckpoint?: number | null;
303
+ afterCheckpoint?: number | null;
304
+ beforeCheckpoint?: number | null;
305
+ kind?: string | null;
306
+ limit?: number;
307
+ order?: string;
308
+ }): Promise<SuiPaginatedResponse<SuiTransaction>>;
309
+ }
310
+ declare namespace SuiMaster {
311
+ export let MIST_PER_SUI: bigint;
312
+ export { Transaction };
313
+ export { Commands };
314
+ export { SuiUtils };
315
+ }
316
+ export default SuiMaster;
317
+ export type SuiGrpcClient = import("@mysten/sui/grpc").SuiGrpcClient;
318
+ export type SuiGraphQLClient = import("@mysten/sui/graphql").SuiGraphQLClient;
319
+ export type SuiSigner = import("@mysten/sui/cryptography").Signer;
320
+ export type SuiKeypair = import("@mysten/sui/cryptography").Keypair;
321
+ export type SuiInBrowser = import("./SuiInBrowser.js").default;
322
+ import SuiCommonMethods from './SuiCommonMethods.js';
323
+ import SuiMemoryObjectStorage from './SuiMemoryObjectStorage.js';
324
+ import SuiPackage from './SuiPackage.js';
325
+ import SuiCoins from './SuiCoins.js';
326
+ import SuiUtils from './SuiUtils.js';
327
+ import { Transaction } from '@mysten/sui/transactions';
328
+ import { TransactionCommands as Commands } from '@mysten/sui/transactions';
329
+ import SuiObject from './SuiObject.js';
330
+ import SuiTransaction from './SuiTransaction.js';
331
+ import SuiEvent from './SuiEvent.js';
332
+ import SuiPaginatedResponse from './SuiPaginatedResponse.js';
333
+ import type { SuiClientTypes } from "@mysten/sui/client";
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @typedef {import("./SuiMaster.js").default} SuiMaster
3
+ */
4
+ /**
5
+ * In-memory registry of `SuiObject` instances keyed by normalized address. One instance is
6
+ * created per connected chain (see `instanceOf`). Used by `SuiPackageModule` and friends to
7
+ * deduplicate object references across moveCall results and queries.
8
+ *
9
+ * Sample usage:
10
+ * ```
11
+ * suiMemoryObjectStorage.push(id);
12
+ * suiMemoryObjectStorage.push(suiObject);
13
+ * await suiMemoryObjectStorage.fetchObjects();
14
+ * suiMemoryObjectStorage.byAddress(id);
15
+ * ```
16
+ */
17
+ export default class SuiMemoryObjectStorage extends SuiCommonMethods {
18
+ static _instances: {};
19
+ /**
20
+ * Return (and lazily create) a shared SuiMemoryObjectStorage keyed by `validatorId`.
21
+ * Typically `validatorId` is the connected chain name (`sui:mainnet`, `sui:localnet`, …) so that
22
+ * objects from different chains stay isolated.
23
+ *
24
+ * @param {string} validatorId - identifier for the singleton slot (chain name by convention)
25
+ * @param {Object} params - Initialization parameters used only on first creation for that slot
26
+ * @param {SuiMaster} params.suiMaster - instance of SuiMaster
27
+ * @param {boolean} [params.debug]
28
+ * @returns {SuiMemoryObjectStorage}
29
+ */
30
+ static instanceOf(validatorId: string, params: {
31
+ suiMaster: SuiMaster;
32
+ debug?: boolean;
33
+ }): SuiMemoryObjectStorage;
34
+ /**
35
+ * SuiMemoryObjectStorage constructor
36
+ * @param {Object} params - Initialization parameters
37
+ * @param {SuiMaster} params.suiMaster - instance of SuiMaster
38
+ * @param {boolean} [params.debug]
39
+ */
40
+ constructor(params: {
41
+ suiMaster: SuiMaster;
42
+ debug?: boolean;
43
+ });
44
+ /** @type {SuiMaster} */
45
+ _suiMaster: SuiMaster;
46
+ /** @type {Object.<string, SuiObject>} */
47
+ _objects: {
48
+ [x: string]: SuiObject;
49
+ };
50
+ /** @returns {SuiObject[]} all stored SuiObjects, in insertion order */
51
+ asArray(): SuiObject[];
52
+ /**
53
+ * Find the most-recently-pushed object whose `typeName` (short type name, e.g. "ChatTopMessage")
54
+ * matches `typeName`. Ordering is by each object's `constructedAt` timestamp.
55
+ *
56
+ * @param {string} typeName
57
+ * @returns {?SuiObject}
58
+ */
59
+ findMostRecentByTypeName(typeName: string): SuiObject | null;
60
+ /**
61
+ * Return the first stored object for which `filterFunction` returns truthy.
62
+ * @param {(obj: SuiObject) => boolean} filterFunction
63
+ * @returns {?SuiObject}
64
+ */
65
+ find(filterFunction: (obj: SuiObject) => boolean): SuiObject | null;
66
+ /**
67
+ * Return the most-recently-constructed object (by `constructedAt`) that matches `filterFunction`.
68
+ * @param {(obj: SuiObject) => boolean} filterFunction
69
+ * @returns {?SuiObject}
70
+ */
71
+ findMostRecent(filterFunction: (obj: SuiObject) => boolean): SuiObject | null;
72
+ /**
73
+ * Store a SuiObject, or wrap a raw `0x…` id in a new SuiObject and store it.
74
+ * If an object with the same address is already stored, it is returned as-is (no replacement).
75
+ *
76
+ * @param {SuiObject | string} suiObjectOrId - a SuiObject instance, or a `0x…` id string
77
+ * @returns {?SuiObject} the stored instance, or null if input didn't look like either
78
+ */
79
+ push(suiObjectOrId: SuiObject | string): SuiObject | null;
80
+ /**
81
+ * Lookup by address. The address must already be in its normalized form (as produced by SuiObject).
82
+ * @param {string} address
83
+ * @returns {?SuiObject}
84
+ */
85
+ byAddress(address: string): SuiObject | null;
86
+ /**
87
+ * Refresh every non-deleted stored SuiObject's fields from chain.
88
+ * Delegates to `SuiMaster.getObjects(...)` which mutates the passed-in instances in place.
89
+ *
90
+ * @returns {Promise<SuiObject[]>}
91
+ */
92
+ fetchObjects(): Promise<SuiObject[]>;
93
+ }
94
+ export type SuiMaster = import("./SuiMaster.js").default;
95
+ import SuiCommonMethods from './SuiCommonMethods.js';
96
+ import SuiObject from './SuiObject.js';
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @import { SuiClientTypes } from "@mysten/sui/client"
3
+ */
4
+ /**
5
+ * @typedef {import("./SuiMaster.js").default} SuiMaster
6
+ */
7
+ export default class SuiObject extends SuiCommonMethods {
8
+ /**
9
+ * Compare two Sui object IDs after normalisation.
10
+ * @param {string} id1
11
+ * @param {string} id2
12
+ * @returns {boolean}
13
+ */
14
+ static idsEqual(id1: string, id2: string): boolean;
15
+ /**
16
+ * Sui Object representation
17
+ *
18
+ * @param {Object} params - parameters
19
+ * @param {SuiMaster} params.suiMaster - instance of SuiMaster
20
+ * @param {SuiClientTypes.Object} [params.raw] - raw data from api
21
+ * @param {?string} [params.id] - ID or address on the sui blockchain
22
+ * @param {string|number} [params.version] - object version
23
+ * @param {?string} [params.type] - fully-qualified Move type string
24
+ * @param {boolean} [params.debug]
25
+ */
26
+ constructor(params: {
27
+ suiMaster: SuiMaster;
28
+ raw?: SuiClientTypes.Object;
29
+ id?: string | null;
30
+ version?: string | number;
31
+ type?: string | null;
32
+ debug?: boolean;
33
+ });
34
+ /** @type {SuiMaster} */
35
+ _suiMaster: SuiMaster;
36
+ /** @type {?string} */
37
+ _id: string | null;
38
+ /** @type {?number} */
39
+ _version: number | null;
40
+ /** @type {?string} */
41
+ _type: string | null;
42
+ _fields: {};
43
+ _display: {};
44
+ _owner: any;
45
+ _localProperties: {};
46
+ _isDeleted: boolean;
47
+ _constructedAt: Date;
48
+ /**
49
+ * Fill local properties from raw SuiClientTypes.Object api response
50
+ * @param {SuiClientTypes.Object} raw
51
+ */
52
+ fillDataFromApi(raw: SuiClientTypes.Object): void;
53
+ /** @returns {Date} timestamp when this JS object was instantiated (useful for sorting by recency) */
54
+ get constructedAt(): Date;
55
+ /** @returns {boolean} true if this object has been marked deleted */
56
+ get isDeleted(): boolean;
57
+ /** @returns {boolean} true if the object is shared (owned by the network) */
58
+ get isShared(): boolean;
59
+ /** @returns {boolean} true if the object is immutable (frozen) */
60
+ get isImmutable(): boolean;
61
+ /**
62
+ * Check whether this object is address-owned by the given address or SuiObject.
63
+ * @param {string | SuiObject} addressOrSuiObject
64
+ * @returns {boolean}
65
+ */
66
+ isOwnedBy(addressOrSuiObject: string | SuiObject): boolean;
67
+ /** Mark this object as deleted on-chain and set `isDeleted` to true. */
68
+ markAsDeleted(): void;
69
+ /** @returns {?string} raw object id as stored (not normalised) */
70
+ get id(): string | null;
71
+ /** @returns {?string} fully-qualified Move type string, e.g. `'0x2::coin::Coin<0x2::sui::SUI>'` */
72
+ get type(): string | null;
73
+ /**
74
+ * Short type name — last `::` segment without `<T…>` suffix.
75
+ * @returns {?string} e.g. `'ChatTopMessage'`
76
+ */
77
+ get typeName(): string | null;
78
+ /**
79
+ * Check whether this object's normalised address equals `toId`.
80
+ * @param {string} toId
81
+ * @returns {boolean}
82
+ */
83
+ idEquals(toId: string): boolean;
84
+ /**
85
+ * Normalised 0x-padded Sui address, or null if the id is invalid.
86
+ * @returns {?string}
87
+ */
88
+ get address(): string | null;
89
+ /** @returns {Object} on-chain Move struct fields (populated by `fillDataFromApi` or `fetchFields`) */
90
+ get fields(): any;
91
+ /** @returns {Object} Display template rendered output (populated by `fillDataFromApi` or `fetchFields`) */
92
+ get display(): any;
93
+ /** @returns {Object} local-only property bag — never sent to chain, for caller convenience */
94
+ get localProperties(): any;
95
+ /** @returns {?number} object version (lamport timestamp), or null before `fetchFields` */
96
+ get version(): number | null;
97
+ /**
98
+ * Fetch transactions that interacted with this object, via GraphQL.
99
+ *
100
+ * @param {Object} [params]
101
+ * @param {number} [params.limit=10]
102
+ * @param {string} [params.order]
103
+ * @returns {Promise<SuiPaginatedResponse>}
104
+ */
105
+ fetchTransactions(params?: {
106
+ limit?: number;
107
+ order?: string;
108
+ }): Promise<SuiPaginatedResponse<any>>;
109
+ /**
110
+ * Fetch dynamic fields owned by this object, paginated.
111
+ * @param {Object} [params]
112
+ * @param {number} [params.limit=50]
113
+ * @param {string} [params.order]
114
+ * @returns {Promise<SuiPaginatedResponse>}
115
+ */
116
+ getDynamicFields(params?: {
117
+ limit?: number;
118
+ order?: string;
119
+ }): Promise<SuiPaginatedResponse<any>>;
120
+ /**
121
+ * Fetch full field data for this object from chain and merge via `replaceWithSuiObjectIfNeeded`.
122
+ * Populates `fields`, `display`, `type`, and `version` if not already filled.
123
+ * @returns {Promise<this>}
124
+ */
125
+ fetchFields(): Promise<this>;
126
+ /**
127
+ * Replace data with another suiObject data if it's version is newer compared to this one
128
+ * @param {SuiObject} suiObject
129
+ */
130
+ replaceWithSuiObjectIfNeeded(suiObject: SuiObject): boolean;
131
+ }
132
+ export type SuiMaster = import("./SuiMaster.js").default;
133
+ import SuiCommonMethods from './SuiCommonMethods.js';
134
+ import type { SuiClientTypes } from "@mysten/sui/client";
135
+ import SuiPaginatedResponse from './SuiPaginatedResponse.js';