suidouble 2.5.0 → 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 (55) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/README.md +222 -131
  3. package/index.js +0 -2
  4. package/lib/SuiCliCommands.js +18 -25
  5. package/lib/SuiCoin.js +79 -137
  6. package/lib/SuiCoins.js +41 -29
  7. package/lib/SuiCommonMethods.js +40 -3
  8. package/lib/SuiEvent.js +54 -6
  9. package/lib/SuiInBrowser.js +143 -15
  10. package/lib/SuiInBrowserAdapter.js +164 -37
  11. package/lib/SuiLocalTestValidator.js +76 -14
  12. package/lib/SuiMaster.js +335 -139
  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 -127
  21. package/package.json +29 -13
  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/tsconfig.json +15 -0
  35. package/types/index.d.ts +15 -0
  36. package/types/lib/SuiCliCommands.d.ts +6 -0
  37. package/types/lib/SuiCoin.d.ts +183 -0
  38. package/types/lib/SuiCoins.d.ts +93 -0
  39. package/types/lib/SuiCommonMethods.d.ts +37 -0
  40. package/types/lib/SuiEvent.d.ts +95 -0
  41. package/types/lib/SuiInBrowser.d.ts +189 -0
  42. package/types/lib/SuiInBrowserAdapter.d.ts +167 -0
  43. package/types/lib/SuiLocalTestValidator.d.ts +92 -0
  44. package/types/lib/SuiMaster.d.ts +333 -0
  45. package/types/lib/SuiMemoryObjectStorage.d.ts +96 -0
  46. package/types/lib/SuiObject.d.ts +135 -0
  47. package/types/lib/SuiPackage.d.ts +233 -0
  48. package/types/lib/SuiPackageModule.d.ts +139 -0
  49. package/types/lib/SuiPaginatedResponse.d.ts +148 -0
  50. package/types/lib/SuiPseudoRandomAddress.d.ts +33 -0
  51. package/types/lib/SuiTransaction.d.ts +92 -0
  52. package/types/lib/SuiUtils.d.ts +152 -0
  53. package/types/lib/data/icons.d.ts +12 -0
  54. package/lib/SuiTestScenario.js +0 -169
  55. package/test/sui_test_scenario.test.js +0 -61
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Browser-side entry point for wallet integration. Manages a registry of SuiInBrowserAdapter
3
+ * instances (one per known wallet), tracks the active connection, and creates a SuiMaster
4
+ * pointing at the connected chain.
5
+ *
6
+ * Starts initialising itself 50 ms after construction so callers have time to attach listeners.
7
+ * Use SuiInBrowser.getSingleton({ defaultChain }) for the typical single-page-app pattern.
8
+ *
9
+ * Events emitted:
10
+ * - 'adapter' — a new SuiInBrowserAdapter was registered (detail: adapter)
11
+ * - 'connected' — the active adapter connected
12
+ * - 'disconnected' — the active adapter disconnected
13
+ * - 'rpc' — the RPC endpoint was changed via setRPC
14
+ */
15
+ export default class SuiInBrowser extends SuiCommonMethods {
16
+ static _singleInstances: {};
17
+ /**
18
+ * Returns the singleton SuiInBrowser instance for the given defaultChain, creating it if
19
+ * necessary. Ideal for single-page-app usage where one instance is shared across the app.
20
+ * @param {Object} [params]
21
+ * @param {string} [params.defaultChain]
22
+ * @returns {SuiInBrowser}
23
+ */
24
+ static getSingleton(params?: {
25
+ defaultChain?: string;
26
+ }): SuiInBrowser;
27
+ /**
28
+ * Returns the list of known wallet placeholder params used to pre-populate the adapter
29
+ * registry before the Wallet Standard registry is queried.
30
+ * @returns {Array<{name: string, icon: string, downloadUrls: Object}>}
31
+ */
32
+ static getPossibleWallets(): Array<{
33
+ name: string;
34
+ icon: string;
35
+ downloadUrls: any;
36
+ }>;
37
+ /**
38
+ * @param {Object} [params]
39
+ * @param {string} [params.defaultChain='sui:devnet'] - chain used before any wallet connects
40
+ * @param {boolean} [params.debug]
41
+ */
42
+ constructor(params?: {
43
+ defaultChain?: string;
44
+ debug?: boolean;
45
+ });
46
+ /** @type {Object.<string, SuiInBrowserAdapter>} */
47
+ _adapters: {
48
+ [x: string]: SuiInBrowserAdapter;
49
+ };
50
+ /** @type {string} */
51
+ _defaultChain: string;
52
+ /** @type {?SuiInBrowserAdapter} */
53
+ _activeAdapter: SuiInBrowserAdapter | null;
54
+ /** @type {?string} */
55
+ _connectedAddress: string | null;
56
+ /** @type {?string} */
57
+ _connectedChain: string | null;
58
+ /** @type {boolean} */
59
+ _isConnected: boolean;
60
+ /** @type {boolean} */
61
+ _isConnecting: boolean;
62
+ _client: import("@mysten/sui/grpc").SuiGrpcClient;
63
+ _suiMaster: SuiMaster;
64
+ /** @type {?Object} */
65
+ _rpcSettings: any | null;
66
+ /** @returns {?SuiInBrowserAdapter} The currently active wallet adapter, or null. */
67
+ get activeAdapter(): SuiInBrowserAdapter | null;
68
+ /**
69
+ * Returns the currently connected wallet address, or null if not connected.
70
+ * @returns {?string}
71
+ */
72
+ getAddress(): string | null;
73
+ /**
74
+ * Sign a transaction using the current `sui:signTransaction` feature.
75
+ * @param {Object} params
76
+ * @returns {Promise<SignatureWithBytes>}
77
+ */
78
+ signTransaction(params: any): Promise<SignatureWithBytes>;
79
+ /**
80
+ * Delegates to the active adapter using the legacy transaction-block API.
81
+ * @param {Object} params
82
+ * @returns {Promise<*>}
83
+ */
84
+ signAndExecuteTransactionBlock(params: any): Promise<any>;
85
+ /**
86
+ * Delegates to the active adapter using the current transaction API.
87
+ * @param {Object} params
88
+ * @returns {Promise<*>}
89
+ */
90
+ signAndExecuteTransaction(params: any): Promise<any>;
91
+ /** @returns {*} The gRPC client instance, or null if not yet initialised. */
92
+ get client(): any;
93
+ toSuiAddress(): string;
94
+ /**
95
+ * Ensures the client is initialised, then returns it.
96
+ * @returns {Promise<*>}
97
+ */
98
+ getClient(): Promise<any>;
99
+ /**
100
+ * Ensures the client is initialised, then returns the SuiMaster instance.
101
+ * @returns {Promise<SuiMaster>}
102
+ */
103
+ getSuiMaster(): Promise<SuiMaster>;
104
+ /** @returns {?SuiMaster} The current SuiMaster instance, or null if not yet initialised. */
105
+ get suiMaster(): SuiMaster | null;
106
+ /** @returns {boolean} True if a wallet adapter is currently connected. */
107
+ get isConnected(): boolean;
108
+ /** @returns {?string} The active wallet address, or null if not connected. */
109
+ get connectedAddress(): string | null;
110
+ /** @returns {?string} The chain the active adapter is connected to (e.g. 'sui:mainnet'), or null. */
111
+ get connectedChain(): string | null;
112
+ /** @returns {Object.<string, SuiInBrowserAdapter>} Map of adapter name to SuiInBrowserAdapter. */
113
+ get adapters(): {
114
+ [x: string]: SuiInBrowserAdapter;
115
+ };
116
+ /**
117
+ * Connects to a named adapter or an adapter instance. Returns false if the adapter is not
118
+ * found in the registry.
119
+ * @param {string|SuiInBrowserAdapter} adapterOrAdapterName
120
+ * @returns {Promise<boolean|void>}
121
+ */
122
+ connect(adapterOrAdapterName: string | SuiInBrowserAdapter): Promise<boolean | void>;
123
+ /**
124
+ * Called when an adapter fires its 'connected' event. Updates the active adapter, connected
125
+ * address and chain, rebuilds the gRPC client and SuiMaster, and emits 'connected'.
126
+ * @param {SuiInBrowserAdapter} suiInBrowserAdapter
127
+ */
128
+ adapterConnected(suiInBrowserAdapter: SuiInBrowserAdapter): void;
129
+ /**
130
+ * Switch connection to use custom RPC endpoint
131
+ * @param {Object} params parameters
132
+ * @param {string} params.url rpc url
133
+ * @param {Object} params.rpc rpc settings
134
+ * @param {Object.<string, string>} params.rpc.headers rpc headers
135
+ */
136
+ setRPC(params: {
137
+ url: string;
138
+ rpc: {
139
+ headers: {
140
+ [x: string]: string;
141
+ };
142
+ };
143
+ }): Promise<void>;
144
+ /**
145
+ * Called when an adapter fires its 'disconnected' event. Resets connection state and emits
146
+ * 'disconnected'.
147
+ * @param {SuiInBrowserAdapter} [_suiInBrowserAdapter]
148
+ */
149
+ adapterDisconnected(_suiInBrowserAdapter?: SuiInBrowserAdapter): void;
150
+ /**
151
+ * Registers a wallet adapter in the registry. If the adapter is new, creates a
152
+ * SuiInBrowserAdapter instance, wires up its events, and emits 'adapter'. If the adapter
153
+ * already exists and a standartAdapter is provided, updates it instead.
154
+ * @param {Object} adapterParams
155
+ * @param {string} [adapterParams.name]
156
+ * @param {Object} [adapterParams.standartAdapter]
157
+ * @param {string} [adapterParams.icon]
158
+ * @param {Object} [adapterParams.downloadUrls]
159
+ * @returns {void|false}
160
+ */
161
+ attachAdapter(adapterParams: {
162
+ name?: string;
163
+ standartAdapter?: any;
164
+ icon?: string;
165
+ downloadUrls?: any;
166
+ }): void | false;
167
+ /**
168
+ * Returns the currently connected chain, or the default chain if no wallet is connected.
169
+ * @returns {string}
170
+ */
171
+ getCurrentChain(): string;
172
+ /**
173
+ * Builds the gRPC client and SuiMaster for the current chain. No-op if already built.
174
+ * Uses _rpcSettings when a custom RPC endpoint has been set via setRPC.
175
+ * @returns {Promise<void>}
176
+ */
177
+ initClient(): Promise<void>;
178
+ /**
179
+ * Seeds the adapter registry from the known-wallets list and the live Wallet Standard
180
+ * registry, then subscribes to future 'register' events for dynamically installed wallets.
181
+ * @returns {Promise<void>}
182
+ */
183
+ initialize(): Promise<void>;
184
+ }
185
+ export type SuiGrpcClient = import("@mysten/sui/grpc").SuiGrpcClient;
186
+ export type SignatureWithBytes = import("@mysten/sui/cryptography").SignatureWithBytes;
187
+ import SuiCommonMethods from './SuiCommonMethods.js';
188
+ import SuiInBrowserAdapter from './SuiInBrowserAdapter.js';
189
+ import SuiMaster from './SuiMaster.js';
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Wrapper over a single Wallet Standard adapter (e.g. Sui Wallet, Martian, Suiet).
3
+ * Abstracts away legacy `signAndExecuteTransactionBlock` vs the current
4
+ * `signAndExecuteTransaction` API, and normalises connection state changes into
5
+ * `'connected'` / `'disconnected'` events on this instance.
6
+ */
7
+ export default class SuiInBrowserAdapter extends SuiCommonMethods {
8
+ /**
9
+ * @param {Object} [params]
10
+ * @param {Object} [params.standardAdapter] - raw Wallet Standard adapter from `@wallet-standard/core`
11
+ * @param {?string} [params.name] - display name used when no adapter is attached (e.g. "not installed" placeholder)
12
+ * @param {?string} [params.icon] - data-URI icon used when no adapter is attached
13
+ * @param {Object} [params.downloadUrls] - map of browser name → extension store URL (e.g. `{ chrome: 'https://…' }`)
14
+ * @param {boolean} [params.debug]
15
+ */
16
+ constructor(params?: {
17
+ standardAdapter?: any;
18
+ name?: string | null;
19
+ icon?: string | null;
20
+ downloadUrls?: any;
21
+ debug?: boolean;
22
+ });
23
+ /** @type {?Object} raw Wallet Standard adapter */
24
+ _standardAdapter: any | null;
25
+ /** @type {?string} */
26
+ _name: string | null;
27
+ /** @type {?string} */
28
+ _icon: string | null;
29
+ /** @type {Object.<string, string>} */
30
+ _downloadUrls: {
31
+ [x: string]: string;
32
+ };
33
+ /** @type {?string} */
34
+ _connectedAddress: string | null;
35
+ /** @type {?string} */
36
+ _connectedChain: string | null;
37
+ /** @type {boolean} */
38
+ _isConnected: boolean;
39
+ /**
40
+ * Sign and execute a transaction. Prefers the current `sui:signAndExecuteTransaction`
41
+ * feature; falls back to the legacy `sui:signAndExecuteTransactionBlock` for older wallets.
42
+ * @param {Object} params
43
+ * @returns {Promise<*>}
44
+ */
45
+ signAndExecuteTransaction(params: any): Promise<any>;
46
+ /**
47
+ * Sign and execute a transaction using the legacy `sui:signAndExecuteTransactionBlock` feature.
48
+ * @param {Object} params
49
+ * @returns {Promise<*>}
50
+ */
51
+ signAndExecuteTransactionBlock(params: any): Promise<any>;
52
+ /**
53
+ * Sign a transaction using the current `sui:signTransaction` feature.
54
+ * @param {Object} params
55
+ * @returns {Promise<SignatureWithBytes>}
56
+ */
57
+ signTransaction(params: any): Promise<SignatureWithBytes>;
58
+ /**
59
+ * Sign a transaction. Prefers the current `sui:signTransaction` feature;
60
+ * falls back to the legacy `sui:signTransactionBlock` for older wallets.
61
+ * @param {Object} params
62
+ * @returns {Promise<*>}
63
+ */
64
+ signTransactionBlock(params: any): Promise<any>;
65
+ /**
66
+ * Sign a personal/arbitrary message. Prefers `sui:signPersonalMessage`;
67
+ * falls back to `sui:signMessage` for older wallets.
68
+ * @param {Object} params
69
+ * @returns {Promise<*>}
70
+ */
71
+ signPersonalMessage(params: any): Promise<any>;
72
+ /**
73
+ * Alias for `signPersonalMessage`.
74
+ * @param {Object} params
75
+ * @returns {Promise<*>}
76
+ */
77
+ signMessage(params: any): Promise<any>;
78
+ /**
79
+ * Disconnect from the wallet and refresh connection state.
80
+ * @param {Object} [params]
81
+ * @returns {Promise<*>}
82
+ */
83
+ disconnect(params?: any): Promise<any>;
84
+ /**
85
+ * Return the Chrome Web Store download URL, or null if not configured.
86
+ * @returns {?string}
87
+ */
88
+ getDownloadURL(): string | null;
89
+ /**
90
+ * True when no underlying adapter has been attached (i.e. this is a "not installed" placeholder).
91
+ * @returns {boolean}
92
+ */
93
+ get isDefault(): boolean;
94
+ /** @returns {?string} currently connected Sui address, or null */
95
+ get connectedAddress(): string | null;
96
+ /** @returns {?string} currently connected chain identifier (e.g. `'sui:mainnet'`), or null */
97
+ get connectedChain(): string | null;
98
+ /** @returns {boolean} true if the wallet is connected and an address is available */
99
+ get isConnected(): boolean;
100
+ /**
101
+ * Request connection to the wallet. Errors are swallowed; connection state is refreshed
102
+ * via `connectionUpdated` regardless.
103
+ * @returns {Promise<void>}
104
+ */
105
+ connect(): Promise<void>;
106
+ /**
107
+ * Read the current connection state from the underlying adapter and update
108
+ * `connectedAddress`, `connectedChain`, and `isConnected`. Emits `'connected'` or
109
+ * `'disconnected'` if the state changed.
110
+ */
111
+ connectionUpdated(): void;
112
+ /**
113
+ * Attach a Wallet Standard adapter to this instance. No-op if already attached.
114
+ * Returns false and does nothing if the adapter has no `sui:` features.
115
+ * Subscribes to adapter `'change'` events to keep connection state up to date.
116
+ *
117
+ * @param {Object} standardAdapter - raw adapter from `@wallet-standard/core`
118
+ * @returns {boolean} false if the adapter lacks Sui features, undefined on success
119
+ */
120
+ setStandartAdapter(standardAdapter: any): boolean;
121
+ __standardAdapterChangeListener: () => void;
122
+ /**
123
+ * True if the adapter is installed and supports the minimum required Sui features
124
+ * (`sui:signAndExecuteTransaction` or `sui:signAndExecuteTransactionBlock`, plus `standard:events`).
125
+ * @returns {boolean}
126
+ */
127
+ get okForSui(): boolean;
128
+ /** @returns {boolean} true if a Wallet Standard adapter has been attached */
129
+ get isInstalled(): boolean;
130
+ /**
131
+ * Feature map from the underlying adapter, or an empty object if not installed.
132
+ * Keys are Wallet Standard feature strings (e.g. `'sui:signAndExecuteTransaction'`).
133
+ * @returns {Object}
134
+ */
135
+ get features(): any;
136
+ /**
137
+ * Display name — from the adapter if installed, otherwise from the constructor param.
138
+ * @returns {?string}
139
+ */
140
+ get name(): string | null;
141
+ /**
142
+ * Data-URI icon — from the adapter if installed, otherwise from the constructor param.
143
+ * @returns {?string}
144
+ */
145
+ get icon(): string | null;
146
+ /**
147
+ * Wallet version string from the adapter, or undefined if not installed.
148
+ * @returns {?string}
149
+ */
150
+ get version(): string | null;
151
+ /**
152
+ * Returns true if this adapter supports the given feature.
153
+ * Accepts either a `Feature` enum key (e.g. `'SUI_SIGN_TX'`) or a raw feature string.
154
+ * @param {string} featureName
155
+ * @returns {boolean}
156
+ */
157
+ hasFeature(featureName: string): boolean;
158
+ /**
159
+ * Return the feature object for `featureName`, or null if not available.
160
+ * Accepts either a `Feature` enum key (e.g. `'SUI_SIGN_TX'`) or a raw feature string.
161
+ * @param {string} featureName
162
+ * @returns {?Object}
163
+ */
164
+ getFeature(featureName: string): any | null;
165
+ }
166
+ export type SignatureWithBytes = import("@mysten/sui/cryptography").SignatureWithBytes;
167
+ import SuiCommonMethods from './SuiCommonMethods.js';
@@ -0,0 +1,92 @@
1
+ /** @typedef {import("@mysten/sui/grpc").SuiGrpcClient} SuiGrpcClient */
2
+ /**
3
+ * Manages a local `sui start` test-validator process. The singleton pattern (`launch` / `stop`)
4
+ * means only one validator runs per test suite even when called from multiple test files.
5
+ *
6
+ * When `testFallbackEnabled` is true and `sui start` fails (e.g. Sui CLI not installed),
7
+ * the instance transparently switches to `sui:devnet` so tests can still run against a live node.
8
+ */
9
+ export default class SuiLocalTestValidator extends SuiCommonMethods {
10
+ /** @type {?SuiLocalTestValidator} */
11
+ static __instance: SuiLocalTestValidator | null;
12
+ /**
13
+ * Launch the local sui node (singleton). If already running, returns the existing instance.
14
+ * Don't forget to call `.stop()` after usage.
15
+ *
16
+ * @param {Object} [params]
17
+ * @param {boolean} [params.testFallbackEnabled]
18
+ * @param {?number} [params.epochDuration]
19
+ * @returns {Promise<SuiLocalTestValidator>}
20
+ */
21
+ static launch(params?: {
22
+ testFallbackEnabled?: boolean;
23
+ epochDuration?: number | null;
24
+ }): Promise<SuiLocalTestValidator>;
25
+ /**
26
+ * Stop the singleton local sui node if running.
27
+ * @returns {Promise<void>}
28
+ */
29
+ static stop(): Promise<void>;
30
+ /**
31
+ * @param {Object} [params]
32
+ * @param {boolean} [params.testFallbackEnabled] - fall back to devnet if the local node can't start
33
+ * @param {?number} [params.epochDuration] - custom epoch duration in ms (only valid with `--force-regenesis`)
34
+ * @param {boolean} [params.debug]
35
+ */
36
+ constructor(params?: {
37
+ testFallbackEnabled?: boolean;
38
+ epochDuration?: number | null;
39
+ debug?: boolean;
40
+ });
41
+ /** @type {?Object} spawned child process */
42
+ _child: any | null;
43
+ /** @type {boolean} */
44
+ _active: boolean;
45
+ /**
46
+ * When true, falls back to sui:devnet if the local node can't be started.
47
+ * @type {boolean}
48
+ */
49
+ _testFallbackEnabled: boolean;
50
+ /** @type {?number} */
51
+ _epochDuration: number | null;
52
+ /** @type {string} */
53
+ _providerName: string;
54
+ /** @returns {string} active chain identifier, e.g. `'sui:localnet'` or `'sui:devnet'` after fallback */
55
+ get providerName(): string;
56
+ /**
57
+ * gRPC client for the currently active chain.
58
+ * @returns {SuiGrpcClient}
59
+ */
60
+ get client(): SuiGrpcClient;
61
+ /** @returns {boolean} true once the node is up and accepting transactions */
62
+ get active(): boolean;
63
+ /**
64
+ * @param {number} port
65
+ * @returns {Promise<boolean>} true if the port accepts a TCP connection within 3 seconds
66
+ */
67
+ isPortThere(port: number): Promise<boolean>;
68
+ /**
69
+ * Poll `isPortThere` every 500 ms until the port is open or the timeout elapses.
70
+ * @param {number} port
71
+ * @param {number} timeout - total wait time in ms
72
+ * @returns {Promise<boolean>}
73
+ */
74
+ waitForPort(port: number, timeout: number): Promise<boolean>;
75
+ /**
76
+ * Start `sui start --with-faucet --with-indexer --with-graphql --force-regenesis`,
77
+ * wait for the faucet (port 9123) and GraphQL (port 9125) to come up,
78
+ * then return this instance with `active === true`.
79
+ *
80
+ * If `testFallbackEnabled` is set and the spawn fails, silently switches to devnet.
81
+ *
82
+ * @returns {Promise<SuiLocalTestValidator>}
83
+ */
84
+ launch(): Promise<SuiLocalTestValidator>;
85
+ /**
86
+ * Kill the child `sui start` process if it is running.
87
+ * @returns {Promise<void>}
88
+ */
89
+ stop(): Promise<void>;
90
+ }
91
+ export type SuiGrpcClient = import("@mysten/sui/grpc").SuiGrpcClient;
92
+ import SuiCommonMethods from "./SuiCommonMethods.js";