suidouble 2.5.0 → 2.17.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +7 -0
- package/README.md +222 -131
- package/index.js +0 -2
- package/lib/SuiCliCommands.js +18 -25
- package/lib/SuiCoin.js +79 -137
- package/lib/SuiCoins.js +41 -29
- package/lib/SuiCommonMethods.js +40 -3
- package/lib/SuiEvent.js +54 -6
- package/lib/SuiInBrowser.js +161 -16
- package/lib/SuiInBrowserAdapter.js +192 -40
- package/lib/SuiLocalTestValidator.js +76 -14
- package/lib/SuiMaster.js +335 -139
- package/lib/SuiMemoryObjectStorage.js +66 -73
- package/lib/SuiObject.js +128 -153
- package/lib/SuiPackage.js +292 -187
- package/lib/SuiPackageModule.js +176 -221
- package/lib/SuiPaginatedResponse.js +288 -25
- package/lib/SuiPseudoRandomAddress.js +29 -2
- package/lib/SuiTransaction.js +115 -70
- package/lib/SuiUtils.js +179 -127
- package/package.json +29 -13
- package/test/build_modules.test.js +41 -0
- package/test/coins.test.js +17 -16
- package/test/custom_transaction.test.js +167 -0
- package/test/event_listeners.test.js +171 -0
- package/test/failed_transaction.test.js +184 -0
- package/test/name_service.test.js +28 -0
- package/test/owned_objects.test.js +148 -0
- package/test/rpc.test.js +3 -6
- package/test/sui_in_browser.test.js +2 -2
- package/test/sui_master_basic.test.js +4 -5
- package/test/sui_master_onlocal.test.js +84 -22
- package/test/sui_object_properties.test.js +85 -0
- package/test/test_move_contracts/different_types/Move.lock +18 -0
- package/test/test_move_contracts/suidouble_chat/Move.lock +18 -0
- package/tsconfig.json +15 -0
- package/types/index.d.ts +15 -0
- package/types/lib/SuiCliCommands.d.ts +6 -0
- package/types/lib/SuiCoin.d.ts +183 -0
- package/types/lib/SuiCoins.d.ts +93 -0
- package/types/lib/SuiCommonMethods.d.ts +37 -0
- package/types/lib/SuiEvent.d.ts +95 -0
- package/types/lib/SuiInBrowser.d.ts +195 -0
- package/types/lib/SuiInBrowserAdapter.d.ts +173 -0
- package/types/lib/SuiLocalTestValidator.d.ts +92 -0
- package/types/lib/SuiMaster.d.ts +333 -0
- package/types/lib/SuiMemoryObjectStorage.d.ts +96 -0
- package/types/lib/SuiObject.d.ts +135 -0
- package/types/lib/SuiPackage.d.ts +233 -0
- package/types/lib/SuiPackageModule.d.ts +139 -0
- package/types/lib/SuiPaginatedResponse.d.ts +148 -0
- package/types/lib/SuiPseudoRandomAddress.d.ts +33 -0
- package/types/lib/SuiTransaction.d.ts +92 -0
- package/types/lib/SuiUtils.d.ts +152 -0
- package/types/lib/data/icons.d.ts +12 -0
- package/lib/SuiTestScenario.js +0 -169
- package/test/sui_test_scenario.test.js +0 -61
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("./SuiMaster.js").default} SuiMaster
|
|
3
|
+
* @typedef {import("./SuiTransaction.js").default} SuiTransaction
|
|
4
|
+
* @typedef {import("./SuiEvent.js").default} SuiEvent
|
|
5
|
+
* @typedef {import("./SuiMemoryObjectStorage.js").default} SuiMemoryObjectStorage
|
|
6
|
+
* @typedef {import("@mysten/sui/transactions").Inputs} Inputs
|
|
7
|
+
*/
|
|
8
|
+
export default class SuiPackage extends SuiObject {
|
|
9
|
+
/**
|
|
10
|
+
* Smart Contract Package on Sui blockchain
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} params - Configuration parameters
|
|
13
|
+
* @param {SuiMaster} params.suiMaster - instance of SuiMaster
|
|
14
|
+
* @param {?string} [params.path] - Local filesystem path to the Move package source code
|
|
15
|
+
* @param {?string} [params.id] - ID or address of the Move package on the Sui blockchain
|
|
16
|
+
* @param {?Array.<string>|string} [params.modules] - List of modules in the package to look on chain in the UpgradeCap owned by current address
|
|
17
|
+
* @param {boolean} [params.debug] - Enable debug mode
|
|
18
|
+
*/
|
|
19
|
+
constructor(params: {
|
|
20
|
+
suiMaster: SuiMaster;
|
|
21
|
+
path?: string | null;
|
|
22
|
+
id?: string | null;
|
|
23
|
+
modules?: (Array<string> | string) | null;
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
});
|
|
26
|
+
/** @type {?string} */
|
|
27
|
+
_path: string | null;
|
|
28
|
+
/** @type {?Array.<string>|string} */
|
|
29
|
+
_expectedModules: (Array<string> | string) | null;
|
|
30
|
+
_isPublished: boolean;
|
|
31
|
+
_publishedVersion: number;
|
|
32
|
+
_upgradeCap: SuiObject;
|
|
33
|
+
_upgradeCapId: string;
|
|
34
|
+
_isBuilt: boolean;
|
|
35
|
+
_builtModules: any;
|
|
36
|
+
_builtDependencies: any;
|
|
37
|
+
_builtDigest: any;
|
|
38
|
+
/**
|
|
39
|
+
* Cached original package id (first published version). Stable across upgrades.
|
|
40
|
+
* Lazy — do not read directly, use `getOriginalPackageId()`.
|
|
41
|
+
* @type {?string}
|
|
42
|
+
*/
|
|
43
|
+
_originalPackageId: string | null;
|
|
44
|
+
/** @type {Object.<string, SuiPackageModule>} */
|
|
45
|
+
_modules: {
|
|
46
|
+
[x: string]: SuiPackageModule;
|
|
47
|
+
};
|
|
48
|
+
/** @returns {SuiMemoryObjectStorage} shared object storage for this suiMaster */
|
|
49
|
+
get objectStorage(): SuiMemoryObjectStorage;
|
|
50
|
+
/** @returns {Object.<string, SuiPackageModule>} map of module name → SuiPackageModule */
|
|
51
|
+
get modules(): {
|
|
52
|
+
[x: string]: SuiPackageModule;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Ensure the package is on chain, then return the named module.
|
|
56
|
+
* @param {string} moduleName
|
|
57
|
+
* @returns {Promise<SuiPackageModule|undefined>}
|
|
58
|
+
*/
|
|
59
|
+
getModule(moduleName: string): Promise<SuiPackageModule | undefined>;
|
|
60
|
+
/** @returns {boolean} true if the local Move project has been built via `build()` */
|
|
61
|
+
get isBuilt(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Returns true if this package is confirmed published on chain.
|
|
64
|
+
* Swallows `checkOnChainIfNeeded` errors so it always resolves.
|
|
65
|
+
* @returns {Promise<boolean>}
|
|
66
|
+
*/
|
|
67
|
+
isOnChain(): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Shortcut for `suiMaster.utils.pureInput(type, value)` — build a BCS-serialised Pure input
|
|
70
|
+
* to use as a moveCall parameter.
|
|
71
|
+
* @param {string} type - BCS type name, e.g. `'u64'`, `'address'`, `'string'`
|
|
72
|
+
* @param {*} value
|
|
73
|
+
* @returns {ReturnType<Inputs['Pure']>}
|
|
74
|
+
*/
|
|
75
|
+
arg(type: string, value: any): ReturnType<Inputs["Pure"]>;
|
|
76
|
+
/**
|
|
77
|
+
* Convenience wrapper — delegates to `this.modules[moduleName].moveCall(...)`.
|
|
78
|
+
* @param {string} moduleName
|
|
79
|
+
* @param {string} methodName
|
|
80
|
+
* @param {Array} params - see `SuiPackageModule.moveCall` for element shapes
|
|
81
|
+
* @param {string[]} [typeArguments]
|
|
82
|
+
* @returns {Promise<SuiTransaction>}
|
|
83
|
+
*/
|
|
84
|
+
moveCall(moduleName: string, methodName: string, params: any[], typeArguments?: string[]): Promise<SuiTransaction>;
|
|
85
|
+
/**
|
|
86
|
+
* Fetch all events emitted by any module of this package, via the GraphQL `events` query.
|
|
87
|
+
* Uses the original (first-version) package id so the filter stays stable across upgrades.
|
|
88
|
+
* For module-scoped or event-type-scoped queries use `this.modules[name].fetchEvents(...)`.
|
|
89
|
+
*
|
|
90
|
+
* @param {Object} [params]
|
|
91
|
+
* @param {number} [params.limit=50]
|
|
92
|
+
* @param {string} [params.order] - Passed through to the underlying paginated response
|
|
93
|
+
* @returns {Promise<SuiPaginatedResponse<SuiEvent>>}
|
|
94
|
+
*/
|
|
95
|
+
fetchEvents(params?: {
|
|
96
|
+
limit?: number;
|
|
97
|
+
order?: string;
|
|
98
|
+
}): Promise<SuiPaginatedResponse<SuiEvent>>;
|
|
99
|
+
/**
|
|
100
|
+
* List objects of any type belonging to this package owned by the current SuiMaster address.
|
|
101
|
+
* Uses the original (first-version) package id and GraphQL (gRPC can't filter by package alone).
|
|
102
|
+
*
|
|
103
|
+
* For module-scoped or full-struct-type filtering use `this.modules[name].getOwnedObjects(...)`.
|
|
104
|
+
*
|
|
105
|
+
* @param {Object} [params]
|
|
106
|
+
* @param {number} [params.limit=50]
|
|
107
|
+
* @param {string} [params.order]
|
|
108
|
+
* @returns {Promise<SuiPaginatedResponse<SuiObject>>}
|
|
109
|
+
*/
|
|
110
|
+
getOwnedObjects(params?: {
|
|
111
|
+
limit?: number;
|
|
112
|
+
order?: string;
|
|
113
|
+
}): Promise<SuiPaginatedResponse<SuiObject>>;
|
|
114
|
+
/**
|
|
115
|
+
* Get the original (first-version) package id, stable across upgrades.
|
|
116
|
+
* Caches the value on first fetch.
|
|
117
|
+
*
|
|
118
|
+
* @returns {Promise<string>}
|
|
119
|
+
*/
|
|
120
|
+
getOriginalPackageId(): Promise<string>;
|
|
121
|
+
checkOnChainIfNeeded(): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* Try to find package on chain using its modules names.
|
|
124
|
+
* Search for packages you own, in last versions of it
|
|
125
|
+
* List all UpgradeCap -> List packages -> Filter ( max version, all modules )
|
|
126
|
+
*
|
|
127
|
+
* @returns {Promise<?string>} id of the highest-version package that contains all expected modules, or null if none matched
|
|
128
|
+
*/
|
|
129
|
+
tryToFindByExpectedModules(): Promise<string | null>;
|
|
130
|
+
/**
|
|
131
|
+
* Get published package version
|
|
132
|
+
*
|
|
133
|
+
* @param {Object} [options]
|
|
134
|
+
* @param {number} [options.timeout=10000] - total time in ms to keep polling if package is not found
|
|
135
|
+
*
|
|
136
|
+
* @returns {Promise<?number>} on-chain package version, or null if it could not be read before the timeout
|
|
137
|
+
*/
|
|
138
|
+
getVersionOnChain(options?: {
|
|
139
|
+
timeout?: number;
|
|
140
|
+
}): Promise<number | null>;
|
|
141
|
+
/**
|
|
142
|
+
* Attach module to this package and add event listeners over it
|
|
143
|
+
*
|
|
144
|
+
* @param {string} moduleName
|
|
145
|
+
* @returns {boolean} true if the module was newly attached, false if it was already attached
|
|
146
|
+
*/
|
|
147
|
+
attachModule(moduleName: string): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* UpgradeCap is capability object required to publish updates for a package.
|
|
150
|
+
* We are trying to find it in owned objects with this function
|
|
151
|
+
*
|
|
152
|
+
* @returns {Promise<?string>} id of UpgradeCap for this package, or null if none is owned by the current address
|
|
153
|
+
*/
|
|
154
|
+
getUpgradeCapId(): Promise<string | null>;
|
|
155
|
+
/**
|
|
156
|
+
* Read the result of a publish/upgrade transaction and update local package state:
|
|
157
|
+
* sets `_id`, `_publishedVersion`, `_isPublished` from the created `package` object,
|
|
158
|
+
* records `_upgradeCapId` from the created `UpgradeCap`, and refreshes on-chain version.
|
|
159
|
+
*
|
|
160
|
+
* @param {SuiTransaction} result - transaction result returned from publish()/upgrade()
|
|
161
|
+
* @returns {Promise<boolean>} true if the package is now marked as published
|
|
162
|
+
*/
|
|
163
|
+
storeInfoFromPublishResult(result: SuiTransaction): Promise<boolean>;
|
|
164
|
+
/**
|
|
165
|
+
* Publish the Move package to the chain for the first time.
|
|
166
|
+
*
|
|
167
|
+
* Flow:
|
|
168
|
+
* - build the local Move project if it has not been built yet
|
|
169
|
+
* - throw if the package already has an on-chain address (use upgrade() instead)
|
|
170
|
+
* - submit a publish transaction and transfer the returned UpgradeCap to the current address
|
|
171
|
+
* - refresh local publish info from the result
|
|
172
|
+
*
|
|
173
|
+
* @param {Object} [params] - Configuration parameters
|
|
174
|
+
* @param {?string} [params.env] - Sui CLI env to switch to before building (forwarded to build())
|
|
175
|
+
* @returns {Promise<?string>} the on-chain package id, or null if publish info could not be read
|
|
176
|
+
* @throws if the package is already published
|
|
177
|
+
*/
|
|
178
|
+
publish(params?: {
|
|
179
|
+
env?: string | null;
|
|
180
|
+
}): Promise<string | null>;
|
|
181
|
+
/**
|
|
182
|
+
* Upgrade an on-chain package to a newer version from local Move sources.
|
|
183
|
+
*
|
|
184
|
+
* Flow:
|
|
185
|
+
* - ensure the package is known on chain (checkOnChainIfNeeded)
|
|
186
|
+
* - build the local Move project if it has not been built yet
|
|
187
|
+
* - authorize the upgrade using the owned UpgradeCap (COMPATIBLE policy)
|
|
188
|
+
* - execute the upgrade transaction and commit it
|
|
189
|
+
* - refresh local publish info from the result
|
|
190
|
+
*
|
|
191
|
+
* Requires an UpgradeCap owned by the current address.
|
|
192
|
+
*
|
|
193
|
+
* @param {Object} [params] - Configuration parameters
|
|
194
|
+
* @param {?string} [params.env] - Sui CLI env to switch to before building (forwarded to build())
|
|
195
|
+
* @returns {Promise<boolean>} true on successful upgrade (version incremented), false otherwise
|
|
196
|
+
*/
|
|
197
|
+
upgrade(params?: {
|
|
198
|
+
env?: string | null;
|
|
199
|
+
}): Promise<boolean>;
|
|
200
|
+
/**
|
|
201
|
+
* Build the local Move project by invoking `sui move build --dump-bytecode-as-base64`
|
|
202
|
+
* and cache the resulting modules, dependencies and digest on the instance
|
|
203
|
+
* (`_builtModules`, `_builtDependencies`, `_builtDigest`). Sets `_isBuilt = true`.
|
|
204
|
+
*
|
|
205
|
+
* Must have a local source `path` set on the package — throws otherwise.
|
|
206
|
+
*
|
|
207
|
+
* @param {Object} [params] - Configuration parameters
|
|
208
|
+
* @param {?string} [params.env] - If set, runs `sui client switch --env <env>` before building
|
|
209
|
+
* @param {?boolean} [params.withUnpublishedDependencies] - Pass `--with-unpublished-dependencies` to the build command
|
|
210
|
+
* @returns {Promise<boolean>} true on success
|
|
211
|
+
* @throws if no local path is set
|
|
212
|
+
*/
|
|
213
|
+
build(params?: {
|
|
214
|
+
env?: string | null;
|
|
215
|
+
withUnpublishedDependencies?: boolean | null;
|
|
216
|
+
}): Promise<boolean>;
|
|
217
|
+
/**
|
|
218
|
+
* Read the local `build/<pkg>/bytecode_modules` directory and return the list of compiled module names.
|
|
219
|
+
* Requires the package to have been built already (via `sui move build` or this instance's `build()`).
|
|
220
|
+
*
|
|
221
|
+
* @returns {Promise<string[]>} list of module names (without the `.mv` suffix)
|
|
222
|
+
* @throws if the local path is not set or the build directory can not be read
|
|
223
|
+
*/
|
|
224
|
+
getModulesNamesFromBuild(): Promise<string[]>;
|
|
225
|
+
}
|
|
226
|
+
export type SuiMaster = import("./SuiMaster.js").default;
|
|
227
|
+
export type SuiTransaction = import("./SuiTransaction.js").default;
|
|
228
|
+
export type SuiEvent = import("./SuiEvent.js").default;
|
|
229
|
+
export type SuiMemoryObjectStorage = import("./SuiMemoryObjectStorage.js").default;
|
|
230
|
+
export type Inputs = any;
|
|
231
|
+
import SuiObject from './SuiObject.js';
|
|
232
|
+
import SuiPackageModule from './SuiPackageModule.js';
|
|
233
|
+
import SuiPaginatedResponse from './SuiPaginatedResponse.js';
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("./SuiTransaction.js").default} SuiTransaction
|
|
3
|
+
* @typedef {import("./SuiMaster.js").default} SuiMaster
|
|
4
|
+
* @typedef {import("./SuiPackage.js").default} SuiPackage
|
|
5
|
+
* @typedef {import("./SuiEvent.js").default} SuiEvent
|
|
6
|
+
* @typedef {import("./SuiMemoryObjectStorage.js").default} SuiMemoryObjectStorage
|
|
7
|
+
* @typedef {import("@mysten/sui/transactions").CallArg} CallArg
|
|
8
|
+
*/
|
|
9
|
+
export default class SuiPackageModule extends SuiCommonMethods {
|
|
10
|
+
/**
|
|
11
|
+
* SuiPackageModule constructor
|
|
12
|
+
* @param {Object} params - Initialization parameters
|
|
13
|
+
* @param {SuiPackage} params.package - instance of SuiPackage this module is part of
|
|
14
|
+
* @param {SuiMaster} params.suiMaster - instance of SuiMaster
|
|
15
|
+
* @param {string} params.moduleName - name of the Move module
|
|
16
|
+
* @param {boolean} [params.debug]
|
|
17
|
+
*/
|
|
18
|
+
constructor(params: {
|
|
19
|
+
package: SuiPackage;
|
|
20
|
+
suiMaster: SuiMaster;
|
|
21
|
+
moduleName: string;
|
|
22
|
+
debug?: boolean;
|
|
23
|
+
});
|
|
24
|
+
_package: import("./SuiPackage.js").default;
|
|
25
|
+
_suiMaster: import("./SuiMaster.js").default;
|
|
26
|
+
_moduleName: string;
|
|
27
|
+
/**
|
|
28
|
+
* Shortcut for `suiMaster.utils.pureInput(type, value)` — build a BCS-serialised Pure input
|
|
29
|
+
* to use as a moveCall parameter.
|
|
30
|
+
* @param {string} type - BCS type name, e.g. `'u64'`, `'address'`, `'string'`
|
|
31
|
+
* @param {*} value
|
|
32
|
+
* @returns {CallArg}
|
|
33
|
+
*/
|
|
34
|
+
arg(type: string, value: any): CallArg;
|
|
35
|
+
/** @returns {SuiMemoryObjectStorage} shared object storage for this suiMaster */
|
|
36
|
+
get objectStorage(): SuiMemoryObjectStorage;
|
|
37
|
+
/** @returns {Object.<string, SuiObject>} raw map of address → SuiObject */
|
|
38
|
+
get objects(): {
|
|
39
|
+
[x: string]: SuiObject;
|
|
40
|
+
};
|
|
41
|
+
/** @returns {SuiObject[]} all objects in storage as an array */
|
|
42
|
+
get objectsArray(): SuiObject[];
|
|
43
|
+
/**
|
|
44
|
+
* Add an object to the shared objectStorage by address or SuiObject instance.
|
|
45
|
+
* If the object is already stored, returns the existing instance.
|
|
46
|
+
* Emits `'added'` if a new bare SuiObject is created from an id string.
|
|
47
|
+
*
|
|
48
|
+
* @param {SuiObject | string} suiObjectOrAddress
|
|
49
|
+
* @returns {?SuiObject}
|
|
50
|
+
*/
|
|
51
|
+
pushObject(suiObjectOrAddress: SuiObject | string): SuiObject | null;
|
|
52
|
+
/**
|
|
53
|
+
* Execute a Move function on this module.
|
|
54
|
+
*
|
|
55
|
+
* Builds a `Transaction` from `params`, signs and executes it, then syncs the local
|
|
56
|
+
* `objectStorage` with the effects.
|
|
57
|
+
*
|
|
58
|
+
* After the call the following events are emitted on this module:
|
|
59
|
+
* - `'added'` — for each created or first-seen-mutated SuiObject (payload: SuiObject)
|
|
60
|
+
* - `'created'` — for each chain-created SuiObject (payload: SuiObject)
|
|
61
|
+
* - `'deleted'` — for each deleted SuiObject (payload: SuiObject)
|
|
62
|
+
*
|
|
63
|
+
* `params` element shapes:
|
|
64
|
+
* - `{ type, amount }` — coin argument; converted via `SuiCoin.coinOfAmountToTxCoin`
|
|
65
|
+
* - `[{ type, amount }]` — single-element array → `vector<Coin<T>>` via `makeMoveVec`
|
|
66
|
+
* - `'0x…'` string → `tx.object(id)`
|
|
67
|
+
* - `{ Pure: { bytes } }` → already-serialised Pure input
|
|
68
|
+
* - anything else → `tx.pure(value)`
|
|
69
|
+
*
|
|
70
|
+
* @param {string} methodName - name of the Move function to call
|
|
71
|
+
* @param {Array} params - call arguments
|
|
72
|
+
* @param {string[]} [typeArguments] - Move type parameters, e.g. `['0x2::sui::SUI']`
|
|
73
|
+
* @returns {Promise<SuiTransaction>}
|
|
74
|
+
*/
|
|
75
|
+
moveCall(methodName: string, params: any[], typeArguments?: string[]): Promise<SuiTransaction>;
|
|
76
|
+
/**
|
|
77
|
+
* Sign and execute a pre-built Transaction, then sync `objectStorage` with the effects and
|
|
78
|
+
* emit change events on this module.
|
|
79
|
+
*
|
|
80
|
+
* Emits per-object events:
|
|
81
|
+
* - `'added'` — created objects not yet in storage, and first-seen mutated objects
|
|
82
|
+
* - `'created'` — every chain-created object
|
|
83
|
+
* - `'deleted'` — every deleted object
|
|
84
|
+
*
|
|
85
|
+
* @param {Transaction} tx
|
|
86
|
+
* @returns {Promise<SuiTransaction>}
|
|
87
|
+
*/
|
|
88
|
+
executeTransaction(tx: Transaction): Promise<SuiTransaction>;
|
|
89
|
+
/**
|
|
90
|
+
* List objects of this module owned by the current SuiMaster address.
|
|
91
|
+
* Uses the original (first-version) package id so the filter is stable across upgrades.
|
|
92
|
+
*
|
|
93
|
+
* @param {Object} [params]
|
|
94
|
+
* @param {?string} [params.typeName] - If set, narrows the type filter to `<pkg>::<module>::<typeName>`.
|
|
95
|
+
* Otherwise filters by `<pkg>::<module>`.
|
|
96
|
+
* @param {number} [params.limit=50]
|
|
97
|
+
* @param {string} [params.order]
|
|
98
|
+
* @returns {Promise<SuiPaginatedResponse<SuiObject>>}
|
|
99
|
+
*/
|
|
100
|
+
getOwnedObjects(params?: {
|
|
101
|
+
typeName?: string | null;
|
|
102
|
+
limit?: number;
|
|
103
|
+
order?: string;
|
|
104
|
+
}): Promise<SuiPaginatedResponse<SuiObject>>;
|
|
105
|
+
/**
|
|
106
|
+
* Fetch events emitted by this module, via the GraphQL `events` query.
|
|
107
|
+
* Uses the original (first-version) package id of the parent SuiPackage so the filter
|
|
108
|
+
* is stable across upgrades.
|
|
109
|
+
*
|
|
110
|
+
* @param {Object} [params]
|
|
111
|
+
* @param {?string} [params.eventTypeName] - If set, narrows the filter to a single event struct
|
|
112
|
+
* (`<pkg>::<module>::<EventName>`). Otherwise fetches
|
|
113
|
+
* all events emitted by any function in this module.
|
|
114
|
+
* @param {number} [params.limit=50]
|
|
115
|
+
* @param {string} [params.order] - Passed through to the underlying paginated response
|
|
116
|
+
* @returns {Promise<SuiPaginatedResponse<SuiEvent>>}
|
|
117
|
+
*/
|
|
118
|
+
fetchEvents(params?: {
|
|
119
|
+
eventTypeName?: string | null;
|
|
120
|
+
limit?: number;
|
|
121
|
+
order?: string;
|
|
122
|
+
}): Promise<SuiPaginatedResponse<SuiEvent>>;
|
|
123
|
+
/**
|
|
124
|
+
* Refresh all objects in the shared objectStorage from chain.
|
|
125
|
+
* Delegates to `SuiMemoryObjectStorage.fetchObjects()`.
|
|
126
|
+
* @returns {Promise<SuiObject[]>}
|
|
127
|
+
*/
|
|
128
|
+
fetchObjects(): Promise<SuiObject[]>;
|
|
129
|
+
}
|
|
130
|
+
export type SuiTransaction = import("./SuiTransaction.js").default;
|
|
131
|
+
export type SuiMaster = import("./SuiMaster.js").default;
|
|
132
|
+
export type SuiPackage = import("./SuiPackage.js").default;
|
|
133
|
+
export type SuiEvent = import("./SuiEvent.js").default;
|
|
134
|
+
export type SuiMemoryObjectStorage = import("./SuiMemoryObjectStorage.js").default;
|
|
135
|
+
export type CallArg = import("@mysten/sui/transactions").CallArg;
|
|
136
|
+
import SuiCommonMethods from './SuiCommonMethods.js';
|
|
137
|
+
import SuiObject from './SuiObject.js';
|
|
138
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
139
|
+
import SuiPaginatedResponse from './SuiPaginatedResponse.js';
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { SuiClientTypes } from "@mysten/sui/client"
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('./SuiObject.js').default} SuiObject
|
|
6
|
+
* @typedef {import('./SuiMaster.js').default} SuiMaster
|
|
7
|
+
* @typedef {{ filter?: object, limit?: number }} GraphqlEventsParams
|
|
8
|
+
* @typedef {{ owner: string, type?: string, limit?: number }} GraphqlOwnedObjectsParams
|
|
9
|
+
* @typedef {{ filter?: object, limit?: number }} GraphqlTransactionsParams
|
|
10
|
+
* @typedef {SuiClientTypes.ListOwnedObjectsOptions<SuiClientTypes.ObjectInclude>
|
|
11
|
+
* | SuiClientTypes.ListCoinsOptions
|
|
12
|
+
* | SuiClientTypes.ListDynamicFieldsOptions
|
|
13
|
+
* | GraphqlEventsParams
|
|
14
|
+
* | GraphqlOwnedObjectsParams
|
|
15
|
+
* | GraphqlTransactionsParams } SuiPaginatedResponseParams
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @template {SuiObject | SuiTransaction | SuiEvent} T
|
|
19
|
+
*/
|
|
20
|
+
export default class SuiPaginatedResponse<T extends SuiObject | SuiTransaction | SuiEvent> extends SuiCommonMethods {
|
|
21
|
+
/**
|
|
22
|
+
* Accept 'asc' | 'ascending' | 'desc' | 'descending' (case-insensitive).
|
|
23
|
+
* Defaults to 'descending' (newest first).
|
|
24
|
+
* @param {?string} input
|
|
25
|
+
* @returns {'ascending' | 'descending'}
|
|
26
|
+
*/
|
|
27
|
+
static _normalizeOrder(input: string | null): "ascending" | "descending";
|
|
28
|
+
/**
|
|
29
|
+
* Map a GraphQL Owner union node to the gRPC-style owner shape SuiObject consumes.
|
|
30
|
+
*/
|
|
31
|
+
static _normalizeGraphqlOwner(owner: any): "Immutable" | {
|
|
32
|
+
AddressOwner: any;
|
|
33
|
+
ObjectOwner?: undefined;
|
|
34
|
+
ConsensusAddressOwner?: undefined;
|
|
35
|
+
Shared?: undefined;
|
|
36
|
+
} | {
|
|
37
|
+
ObjectOwner: any;
|
|
38
|
+
AddressOwner?: undefined;
|
|
39
|
+
ConsensusAddressOwner?: undefined;
|
|
40
|
+
Shared?: undefined;
|
|
41
|
+
} | {
|
|
42
|
+
ConsensusAddressOwner: any;
|
|
43
|
+
AddressOwner?: undefined;
|
|
44
|
+
ObjectOwner?: undefined;
|
|
45
|
+
Shared?: undefined;
|
|
46
|
+
} | {
|
|
47
|
+
Shared: {};
|
|
48
|
+
AddressOwner?: undefined;
|
|
49
|
+
ObjectOwner?: undefined;
|
|
50
|
+
ConsensusAddressOwner?: undefined;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* @param {Object} params
|
|
54
|
+
* @param {SuiMaster} params.suiMaster
|
|
55
|
+
* @param {SuiPaginatedResponseParams} params.params
|
|
56
|
+
* @param {string} [params.method]
|
|
57
|
+
* @param {string} [params.order]
|
|
58
|
+
* @param {boolean} [params.debug]
|
|
59
|
+
*/
|
|
60
|
+
constructor(params: {
|
|
61
|
+
suiMaster: SuiMaster;
|
|
62
|
+
params: SuiPaginatedResponseParams;
|
|
63
|
+
method?: string;
|
|
64
|
+
order?: string;
|
|
65
|
+
debug?: boolean;
|
|
66
|
+
});
|
|
67
|
+
_suiMaster: import("./SuiMaster.js").default;
|
|
68
|
+
_method: string;
|
|
69
|
+
/** @type {SuiPaginatedResponseParams} */
|
|
70
|
+
_params: SuiPaginatedResponseParams;
|
|
71
|
+
_order: "ascending" | "descending";
|
|
72
|
+
_hasNextPage: boolean;
|
|
73
|
+
_nextCursor: any;
|
|
74
|
+
/** @type {T[]} */
|
|
75
|
+
_data: T[];
|
|
76
|
+
/**
|
|
77
|
+
* Simple itterator to go over all list of items, not caring about pagination/cursors etc. It fetches next page when needed
|
|
78
|
+
* Optional maxLimit second parameter to stop when reached count
|
|
79
|
+
* @param {(item: T) => (void | Promise<void>)} callbackFunc
|
|
80
|
+
* @param {Number} maxLimit
|
|
81
|
+
*/
|
|
82
|
+
forEach(callbackFunc: (item: T) => (void | Promise<void>), maxLimit?: number): Promise<void>;
|
|
83
|
+
get hasNextPage(): boolean;
|
|
84
|
+
/** @returns {T[]} */
|
|
85
|
+
get data(): T[];
|
|
86
|
+
nextPage(): Promise<false | T[]>;
|
|
87
|
+
fetch(params?: {}): Promise<T[]>;
|
|
88
|
+
/**
|
|
89
|
+
* Shared Relay-style GraphQL pagination:
|
|
90
|
+
* - ascending → `first` + `after`, `hasNextPage` / `endCursor`
|
|
91
|
+
* - descending → `last` + `before`, `hasPreviousPage` / `startCursor`
|
|
92
|
+
* `last` returns nodes ascending too, so descending callers get a reversed slice.
|
|
93
|
+
*
|
|
94
|
+
* @param {Object} config
|
|
95
|
+
* @param {string} config.query - GraphQL query declaring $first/$after/$last/$before + any extra vars
|
|
96
|
+
* @param {Object} [config.variables] - extra variables merged into the request (e.g. filter, owner)
|
|
97
|
+
* @param {(data: any) => any} config.extractConnection - pull the Connection (pageInfo + nodes) out of response.data
|
|
98
|
+
* @param {(node: any) => T} config.mapNode - turn a node into the wrapped T instance
|
|
99
|
+
* @param {string} [config.errorLabel='GraphQL query'] - prefix for errors
|
|
100
|
+
* @param {Object} [params]
|
|
101
|
+
* @param {?string} [params.cursor]
|
|
102
|
+
*/
|
|
103
|
+
_fetchGraphqlPaginated(config: {
|
|
104
|
+
query: string;
|
|
105
|
+
variables?: any;
|
|
106
|
+
extractConnection: (data: any) => any;
|
|
107
|
+
mapNode: (node: any) => T;
|
|
108
|
+
errorLabel?: string;
|
|
109
|
+
}, params?: {
|
|
110
|
+
cursor?: string | null;
|
|
111
|
+
}): Promise<T[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Paginate the GraphQL `events` query. `this._params` = { filter, limit } where
|
|
114
|
+
* `filter` is a GraphQL `EventFilter` (module/type/sender/checkpoint fields).
|
|
115
|
+
*/
|
|
116
|
+
_fetchEventsGraphql(params?: {}): Promise<T[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Paginate `address(address).objects(filter)` via GraphQL. `this._params` = { owner, type, limit }
|
|
119
|
+
* where `type` is a GraphQL `ObjectFilter.type` string.
|
|
120
|
+
*/
|
|
121
|
+
_fetchOwnedObjectsGraphql(params?: {}): Promise<T[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Paginate the GraphQL root `transactions(filter: TransactionFilter)` query.
|
|
124
|
+
* `this._params` = { filter, limit } where `filter` is a GraphQL `TransactionFilter`
|
|
125
|
+
* (`sentAddress`, `affectedAddress`, `affectedObject`, `function`, checkpoint bounds, `kind`).
|
|
126
|
+
*/
|
|
127
|
+
_fetchTransactionsGraphql(params?: {}): Promise<T[]>;
|
|
128
|
+
}
|
|
129
|
+
export type SuiObject = import("./SuiObject.js").default;
|
|
130
|
+
export type SuiMaster = import("./SuiMaster.js").default;
|
|
131
|
+
export type GraphqlEventsParams = {
|
|
132
|
+
filter?: object;
|
|
133
|
+
limit?: number;
|
|
134
|
+
};
|
|
135
|
+
export type GraphqlOwnedObjectsParams = {
|
|
136
|
+
owner: string;
|
|
137
|
+
type?: string;
|
|
138
|
+
limit?: number;
|
|
139
|
+
};
|
|
140
|
+
export type GraphqlTransactionsParams = {
|
|
141
|
+
filter?: object;
|
|
142
|
+
limit?: number;
|
|
143
|
+
};
|
|
144
|
+
export type SuiPaginatedResponseParams = SuiClientTypes.ListOwnedObjectsOptions<SuiClientTypes.ObjectInclude> | SuiClientTypes.ListCoinsOptions | SuiClientTypes.ListDynamicFieldsOptions | GraphqlEventsParams | GraphqlOwnedObjectsParams | GraphqlTransactionsParams;
|
|
145
|
+
import SuiTransaction from './SuiTransaction.js';
|
|
146
|
+
import SuiEvent from './SuiEvent.js';
|
|
147
|
+
import SuiCommonMethods from './SuiCommonMethods.js';
|
|
148
|
+
import type { SuiClientTypes } from "@mysten/sui/client";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministically derives an Ed25519 keypair (and thus a Sui address) from an arbitrary
|
|
3
|
+
* string seed. Useful for tests and local dev where you need a stable, human-readable
|
|
4
|
+
* "name" instead of a raw private key.
|
|
5
|
+
*
|
|
6
|
+
* The derivation is deterministic but **not cryptographically secure** — the hash function
|
|
7
|
+
* is intentionally simple. Do not use for production key management.
|
|
8
|
+
*/
|
|
9
|
+
export default class SuiPseudoRandomAddress {
|
|
10
|
+
/**
|
|
11
|
+
* Derive an Ed25519 keypair from an arbitrary string seed.
|
|
12
|
+
* The same string always produces the same keypair (and Sui address).
|
|
13
|
+
*
|
|
14
|
+
* @param {string} as - any string seed, e.g. `'alice'`, `'test-wallet-1'`
|
|
15
|
+
* @returns {Ed25519Keypair}
|
|
16
|
+
*/
|
|
17
|
+
static stringToKeyPair(as: string): Ed25519Keypair;
|
|
18
|
+
/**
|
|
19
|
+
* Convert an arbitrary string seed into a BIP-39 mnemonic phrase by mapping the string
|
|
20
|
+
* to 32 pseudo-random bytes and running them through `entropyToMnemonic`.
|
|
21
|
+
*
|
|
22
|
+
* The byte derivation:
|
|
23
|
+
* 1. Repeats the string until it is at least 32 chars (appending `*"` so `'test'` and
|
|
24
|
+
* `'testtest'` produce different entropy).
|
|
25
|
+
* 2. Maps each character to its char-code.
|
|
26
|
+
* 3. Folds any bytes beyond position 31 back into the first 32 via modular addition.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} as - any string seed
|
|
29
|
+
* @returns {string} 24-word BIP-39 mnemonic derived from the seed
|
|
30
|
+
*/
|
|
31
|
+
static stringToPhrase(as: string): string;
|
|
32
|
+
}
|
|
33
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { SuiClientTypes } from "@mysten/sui/client"
|
|
3
|
+
* @typedef {import("./SuiMaster.js").default} SuiMaster
|
|
4
|
+
* @typedef {import("./SuiObject.js").default} SuiObject
|
|
5
|
+
* @typedef {import("./SuiEvent.js").default} SuiEvent
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper over a Sui transaction result. Lazily parses `effects.changedObjects` into
|
|
9
|
+
* typed `created`, `mutated`, `deleted` lists and wraps events in `SuiEvent` instances.
|
|
10
|
+
*/
|
|
11
|
+
export default class SuiTransaction extends SuiCommonMethods {
|
|
12
|
+
/**
|
|
13
|
+
* @param {Object} params
|
|
14
|
+
* @param {SuiMaster} params.suiMaster
|
|
15
|
+
* @param {SuiClientTypes.Transaction} params.data - raw transaction data
|
|
16
|
+
* @param {boolean} [params.debug]
|
|
17
|
+
*/
|
|
18
|
+
constructor(params: {
|
|
19
|
+
suiMaster: SuiMaster;
|
|
20
|
+
data: SuiClientTypes.Transaction;
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
});
|
|
23
|
+
/** @type {SuiMaster} */
|
|
24
|
+
_suiMaster: SuiMaster;
|
|
25
|
+
/** @type {?SuiClientTypes.Transaction} */
|
|
26
|
+
_data: SuiClientTypes.Transaction | null;
|
|
27
|
+
/** @type {?{created: SuiObject[], mutated: SuiObject[], deleted: SuiObject[], objects: SuiObject[]}} */
|
|
28
|
+
_results: {
|
|
29
|
+
created: SuiObject[];
|
|
30
|
+
mutated: SuiObject[];
|
|
31
|
+
deleted: SuiObject[];
|
|
32
|
+
objects: SuiObject[];
|
|
33
|
+
} | null;
|
|
34
|
+
/** @type {?SuiEvent[]} */
|
|
35
|
+
_events: SuiEvent[] | null;
|
|
36
|
+
/** @returns {?number} epoch the transaction executed in, or null if unavailable */
|
|
37
|
+
get executedEpoch(): number | null;
|
|
38
|
+
/** @returns {?string} Base58-encoded transaction digest, or null if data isn't set */
|
|
39
|
+
get digest(): string | null;
|
|
40
|
+
/** @returns {?bigint} net gas cost in MIST (computationCost + storageCost − storageRebate), or null */
|
|
41
|
+
get gasUsed(): bigint | null;
|
|
42
|
+
/** @returns {SuiObject[]} objects deleted by this transaction */
|
|
43
|
+
get deleted(): SuiObject[];
|
|
44
|
+
/** @returns {SuiObject[]} objects mutated (version changed) by this transaction */
|
|
45
|
+
get mutated(): SuiObject[];
|
|
46
|
+
/** @returns {SuiObject[]} objects created by this transaction */
|
|
47
|
+
get created(): SuiObject[];
|
|
48
|
+
/** @returns {?SuiClientTypes.Transaction} raw transaction data as received from the client */
|
|
49
|
+
get data(): SuiClientTypes.Transaction | null;
|
|
50
|
+
/**
|
|
51
|
+
* Returns true if the transaction's status indicates success.
|
|
52
|
+
* @returns {boolean}
|
|
53
|
+
*/
|
|
54
|
+
isSuccessful(): boolean;
|
|
55
|
+
/** @returns {SuiEvent[]} events emitted by this transaction, lazily built and cached */
|
|
56
|
+
get events(): SuiEvent[];
|
|
57
|
+
/**
|
|
58
|
+
* Parsed object-change results, lazily built from `effects.changedObjects` and cached.
|
|
59
|
+
* @returns {{created: SuiObject[], mutated: SuiObject[], deleted: SuiObject[], objects: SuiObject[]}}
|
|
60
|
+
*/
|
|
61
|
+
get results(): {
|
|
62
|
+
created: SuiObject[];
|
|
63
|
+
mutated: SuiObject[];
|
|
64
|
+
deleted: SuiObject[];
|
|
65
|
+
objects: SuiObject[];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Wait for this transaction to be finalised on chain, then refresh `_data` with the full result.
|
|
69
|
+
* Clears the cached `_results` and `_events` so getters recompute from the fresh data.
|
|
70
|
+
*
|
|
71
|
+
* @param {SuiClientTypes.WaitForTransactionOptions} [input] - extra options forwarded to `client.waitForTransaction`
|
|
72
|
+
* @returns {Promise<this>}
|
|
73
|
+
* @throws if `digest` is not set
|
|
74
|
+
*/
|
|
75
|
+
waitForTransaction(input?: SuiClientTypes.WaitForTransactionOptions): Promise<this>;
|
|
76
|
+
/**
|
|
77
|
+
* Checkpoint timestamp in milliseconds since epoch, or null if unavailable.
|
|
78
|
+
*
|
|
79
|
+
* Only populated when the transaction was fetched via the GraphQL path
|
|
80
|
+
* (`SuiMaster.fetchTransactions`). Transactions returned from `signAndExecuteTransaction`
|
|
81
|
+
* or `waitForTransaction` (gRPC) do not carry a timestamp in their data shape and will
|
|
82
|
+
* always return null here.
|
|
83
|
+
*
|
|
84
|
+
* @returns {?number}
|
|
85
|
+
*/
|
|
86
|
+
get timestampMs(): number | null;
|
|
87
|
+
}
|
|
88
|
+
export type SuiMaster = import("./SuiMaster.js").default;
|
|
89
|
+
export type SuiObject = import("./SuiObject.js").default;
|
|
90
|
+
export type SuiEvent = import("./SuiEvent.js").default;
|
|
91
|
+
import SuiCommonMethods from './SuiCommonMethods.js';
|
|
92
|
+
import type { SuiClientTypes } from "@mysten/sui/client";
|