suidouble 2.16.0 → 2.17.0-3
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/lib/SuiInBrowser.js +46 -2
- package/lib/SuiInBrowserAdapter.js +33 -5
- package/package.json +2 -2
- package/test/test_move_contracts/different_types/Move.lock +18 -0
- package/test/test_move_contracts/suidouble_chat/Move.lock +18 -0
- package/types/lib/SuiInBrowser.d.ts +15 -0
- package/types/lib/SuiInBrowserAdapter.d.ts +8 -2
package/lib/SuiInBrowser.js
CHANGED
|
@@ -94,7 +94,8 @@ export default class SuiInBrowser extends SuiCommonMethods {
|
|
|
94
94
|
* @returns {Promise<*>}
|
|
95
95
|
*/
|
|
96
96
|
async signAndExecuteTransactionBlock(params) {
|
|
97
|
-
|
|
97
|
+
const enriched = { account: { address: this._connectedAddress }, chain: this._connectedChain, ...params };
|
|
98
|
+
return await this._activeAdapter.signAndExecuteTransactionBlock(enriched);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
@@ -107,6 +108,43 @@ export default class SuiInBrowser extends SuiCommonMethods {
|
|
|
107
108
|
return await this._activeAdapter.signAndExecuteTransaction(enriched);
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Sign a personal/arbitrary message via the active adapter.
|
|
113
|
+
* @param {Object} params
|
|
114
|
+
* @returns {Promise<*>}
|
|
115
|
+
*/
|
|
116
|
+
async signPersonalMessage(params) {
|
|
117
|
+
const enriched = { account: { address: this._connectedAddress }, chain: this._connectedChain, ...params };
|
|
118
|
+
return await this._activeAdapter.signPersonalMessage(enriched);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
createBoundSigner() {
|
|
122
|
+
const adapter = this._activeAdapter;
|
|
123
|
+
const address = this._connectedAddress;
|
|
124
|
+
const chain = this._connectedChain;
|
|
125
|
+
return {
|
|
126
|
+
get activeAdapter() { return adapter; },
|
|
127
|
+
get connectedAddress() { return address; },
|
|
128
|
+
toSuiAddress() { return address; },
|
|
129
|
+
signTransaction(params) {
|
|
130
|
+
const enriched = { account: { address }, chain, ...params };
|
|
131
|
+
return adapter.signTransaction(enriched);
|
|
132
|
+
},
|
|
133
|
+
signAndExecuteTransaction(params) {
|
|
134
|
+
const enriched = { account: { address }, chain, ...params };
|
|
135
|
+
return adapter.signAndExecuteTransaction(enriched);
|
|
136
|
+
},
|
|
137
|
+
signAndExecuteTransactionBlock(params) {
|
|
138
|
+
const enriched = { account: { address }, chain, ...params };
|
|
139
|
+
return adapter.signAndExecuteTransactionBlock(enriched);
|
|
140
|
+
},
|
|
141
|
+
signPersonalMessage(params) {
|
|
142
|
+
const enriched = { account: { address }, chain, ...params };
|
|
143
|
+
return adapter.signPersonalMessage(enriched);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
110
148
|
/** @returns {*} The gRPC client instance, or null if not yet initialised. */
|
|
111
149
|
get client() {
|
|
112
150
|
return this._client;
|
|
@@ -200,6 +238,10 @@ export default class SuiInBrowser extends SuiCommonMethods {
|
|
|
200
238
|
this.log('error', e);
|
|
201
239
|
}
|
|
202
240
|
this._isConnecting = false;
|
|
241
|
+
|
|
242
|
+
if (this._activeAdapter.isConnected && this._connectedAddress !== this._activeAdapter.connectedAddress) {
|
|
243
|
+
this.adapterConnected(this._activeAdapter);
|
|
244
|
+
}
|
|
203
245
|
}
|
|
204
246
|
|
|
205
247
|
/**
|
|
@@ -279,8 +321,10 @@ export default class SuiInBrowser extends SuiCommonMethods {
|
|
|
279
321
|
...adapterParams,
|
|
280
322
|
debug: this._debug,
|
|
281
323
|
});
|
|
324
|
+
adapter._preferredChain = this._defaultChain;
|
|
282
325
|
if (this._adapters[adapterName]) {
|
|
283
326
|
// already attached
|
|
327
|
+
this._adapters[adapterName]._preferredChain = this._defaultChain;
|
|
284
328
|
if (adapterParams.standartAdapter) {
|
|
285
329
|
this._adapters[adapterName].setStandartAdapter(adapterParams.standartAdapter);
|
|
286
330
|
}
|
|
@@ -328,7 +372,7 @@ export default class SuiInBrowser extends SuiCommonMethods {
|
|
|
328
372
|
|
|
329
373
|
this._suiMaster = new SuiMaster({
|
|
330
374
|
debug: this._debug,
|
|
331
|
-
signer: this,
|
|
375
|
+
signer: this._activeAdapter ? this.createBoundSigner() : null,
|
|
332
376
|
client: this._client,
|
|
333
377
|
});
|
|
334
378
|
}
|
|
@@ -59,6 +59,10 @@ export default class SuiInBrowserAdapter extends SuiCommonMethods {
|
|
|
59
59
|
this._connectedChain = null;
|
|
60
60
|
/** @type {boolean} */
|
|
61
61
|
this._isConnected = false;
|
|
62
|
+
/** @type {boolean} */
|
|
63
|
+
this._userDisconnected = false;
|
|
64
|
+
/** @type {?string} */
|
|
65
|
+
this._preferredChain = null;
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
/**
|
|
@@ -138,13 +142,26 @@ export default class SuiInBrowserAdapter extends SuiCommonMethods {
|
|
|
138
142
|
|
|
139
143
|
/**
|
|
140
144
|
* Disconnect from the wallet and refresh connection state.
|
|
145
|
+
* Force-clears local connection state even if the wallet doesn't support
|
|
146
|
+
* standard:disconnect or doesn't revoke site authorization (e.g. Phantom).
|
|
141
147
|
* @param {Object} [params]
|
|
142
|
-
* @returns {Promise
|
|
148
|
+
* @returns {Promise<void>}
|
|
143
149
|
*/
|
|
144
150
|
async disconnect(params) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
151
|
+
try {
|
|
152
|
+
const feature = this.getFeature(Feature.DISCONNECT);
|
|
153
|
+
if (feature) {
|
|
154
|
+
await feature.disconnect(params);
|
|
155
|
+
}
|
|
156
|
+
} catch (e) {
|
|
157
|
+
console.warn('[SuiInBrowserAdapter] standard:disconnect failed:', e);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this._connectedAddress = null;
|
|
161
|
+
this._connectedChain = null;
|
|
162
|
+
this._isConnected = false;
|
|
163
|
+
this._userDisconnected = true;
|
|
164
|
+
this.emit('disconnected', this);
|
|
148
165
|
}
|
|
149
166
|
|
|
150
167
|
/**
|
|
@@ -187,6 +204,7 @@ export default class SuiInBrowserAdapter extends SuiCommonMethods {
|
|
|
187
204
|
* @returns {Promise<void>}
|
|
188
205
|
*/
|
|
189
206
|
async connect() {
|
|
207
|
+
this._userDisconnected = false;
|
|
190
208
|
try {
|
|
191
209
|
await this.getFeature(Feature.CONNECT).connect();
|
|
192
210
|
} catch (e) {
|
|
@@ -202,13 +220,23 @@ export default class SuiInBrowserAdapter extends SuiCommonMethods {
|
|
|
202
220
|
* `'disconnected'` if the state changed.
|
|
203
221
|
*/
|
|
204
222
|
connectionUpdated() {
|
|
223
|
+
if (this._userDisconnected) return;
|
|
224
|
+
|
|
205
225
|
const wasConnectedAddress = ''+this._connectedAddress;
|
|
206
226
|
const wasConnectedChain = ''+this._connectedChain;
|
|
207
227
|
|
|
208
228
|
try {
|
|
209
229
|
if (this._standardAdapter && this._standardAdapter.accounts && this._standardAdapter.accounts.length) {
|
|
210
230
|
this._connectedAddress = this._standardAdapter.accounts[0].address;
|
|
211
|
-
|
|
231
|
+
const accountChains = this._standardAdapter.accounts[0].chains;
|
|
232
|
+
const normalize = (c) => c ? c.replace(/^sui:/, '') : c;
|
|
233
|
+
const preferredNorm = normalize(this._preferredChain);
|
|
234
|
+
const match = this._preferredChain && accountChains.find(c => normalize(c) === preferredNorm);
|
|
235
|
+
if (match) {
|
|
236
|
+
this._connectedChain = match;
|
|
237
|
+
} else {
|
|
238
|
+
this._connectedChain = accountChains[0];
|
|
239
|
+
}
|
|
212
240
|
} else {
|
|
213
241
|
this._connectedAddress = null;
|
|
214
242
|
this._connectedChain = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0-3",
|
|
4
4
|
"description": "JavaScript library for Sui Move smart contracts. Publish, upgrade, and test packages; call contract methods; query objects and events — same code works on Node.js and in the browser.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"license": "Apache-2.0",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@mysten/bcs": "^2.0.3",
|
|
40
|
-
"@mysten/sui": "^2.
|
|
40
|
+
"@mysten/sui": "^2.17.0",
|
|
41
41
|
"@polymedia/coinmeta": "^0.0.24",
|
|
42
42
|
"@scure/bip39": "^1.6.0",
|
|
43
43
|
"@wallet-standard/core": "^1.1.1"
|
|
@@ -21,3 +21,21 @@ source = { root = true }
|
|
|
21
21
|
use_environment = "mainnet"
|
|
22
22
|
manifest_digest = "EC6E90369603CE16A65E2F7B784DCFCA80948E3C176AD82DC6EB101BAA942A89"
|
|
23
23
|
deps = { Sui = "Sui" }
|
|
24
|
+
|
|
25
|
+
[pinned.testnet.MoveStdlib]
|
|
26
|
+
source = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/move-stdlib", rev = "14bf3e318215db21415c7c0ab0c01cf8d7ef594a" }
|
|
27
|
+
use_environment = "testnet"
|
|
28
|
+
manifest_digest = "C4FE4C91DE74CBF223B2E380AE40F592177D21870DC2D7EB6227D2D694E05363"
|
|
29
|
+
deps = {}
|
|
30
|
+
|
|
31
|
+
[pinned.testnet.Sui]
|
|
32
|
+
source = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "14bf3e318215db21415c7c0ab0c01cf8d7ef594a" }
|
|
33
|
+
use_environment = "testnet"
|
|
34
|
+
manifest_digest = "7AFB66695545775FBFBB2D3078ADFD084244D5002392E837FDE21D9EA1C6D01C"
|
|
35
|
+
deps = { MoveStdlib = "MoveStdlib" }
|
|
36
|
+
|
|
37
|
+
[pinned.testnet.different_types]
|
|
38
|
+
source = { root = true }
|
|
39
|
+
use_environment = "testnet"
|
|
40
|
+
manifest_digest = "CC15E09306E902854F6BDD9B90D21287DB7EC557173965E5355493A2783E25B3"
|
|
41
|
+
deps = { Sui = "Sui" }
|
|
@@ -21,3 +21,21 @@ source = { root = true }
|
|
|
21
21
|
use_environment = "mainnet"
|
|
22
22
|
manifest_digest = "EC6E90369603CE16A65E2F7B784DCFCA80948E3C176AD82DC6EB101BAA942A89"
|
|
23
23
|
deps = { Sui = "Sui" }
|
|
24
|
+
|
|
25
|
+
[pinned.testnet.MoveStdlib]
|
|
26
|
+
source = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/move-stdlib", rev = "14bf3e318215db21415c7c0ab0c01cf8d7ef594a" }
|
|
27
|
+
use_environment = "testnet"
|
|
28
|
+
manifest_digest = "C4FE4C91DE74CBF223B2E380AE40F592177D21870DC2D7EB6227D2D694E05363"
|
|
29
|
+
deps = {}
|
|
30
|
+
|
|
31
|
+
[pinned.testnet.Sui]
|
|
32
|
+
source = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "14bf3e318215db21415c7c0ab0c01cf8d7ef594a" }
|
|
33
|
+
use_environment = "testnet"
|
|
34
|
+
manifest_digest = "7AFB66695545775FBFBB2D3078ADFD084244D5002392E837FDE21D9EA1C6D01C"
|
|
35
|
+
deps = { MoveStdlib = "MoveStdlib" }
|
|
36
|
+
|
|
37
|
+
[pinned.testnet.suidouble_chat]
|
|
38
|
+
source = { root = true }
|
|
39
|
+
use_environment = "testnet"
|
|
40
|
+
manifest_digest = "CC15E09306E902854F6BDD9B90D21287DB7EC557173965E5355493A2783E25B3"
|
|
41
|
+
deps = { Sui = "Sui" }
|
|
@@ -88,6 +88,21 @@ export default class SuiInBrowser extends SuiCommonMethods {
|
|
|
88
88
|
* @returns {Promise<*>}
|
|
89
89
|
*/
|
|
90
90
|
signAndExecuteTransaction(params: any): Promise<any>;
|
|
91
|
+
/**
|
|
92
|
+
* Sign a personal/arbitrary message via the active adapter.
|
|
93
|
+
* @param {Object} params
|
|
94
|
+
* @returns {Promise<*>}
|
|
95
|
+
*/
|
|
96
|
+
signPersonalMessage(params: any): Promise<any>;
|
|
97
|
+
createBoundSigner(): {
|
|
98
|
+
readonly activeAdapter: SuiInBrowserAdapter;
|
|
99
|
+
readonly connectedAddress: string;
|
|
100
|
+
toSuiAddress(): string;
|
|
101
|
+
signTransaction(params: any): Promise<import("@mysten/sui/cryptography").SignatureWithBytes>;
|
|
102
|
+
signAndExecuteTransaction(params: any): Promise<any>;
|
|
103
|
+
signAndExecuteTransactionBlock(params: any): Promise<any>;
|
|
104
|
+
signPersonalMessage(params: any): Promise<any>;
|
|
105
|
+
};
|
|
91
106
|
/** @returns {*} The gRPC client instance, or null if not yet initialised. */
|
|
92
107
|
get client(): any;
|
|
93
108
|
toSuiAddress(): string;
|
|
@@ -36,6 +36,10 @@ export default class SuiInBrowserAdapter extends SuiCommonMethods {
|
|
|
36
36
|
_connectedChain: string | null;
|
|
37
37
|
/** @type {boolean} */
|
|
38
38
|
_isConnected: boolean;
|
|
39
|
+
/** @type {boolean} */
|
|
40
|
+
_userDisconnected: boolean;
|
|
41
|
+
/** @type {?string} */
|
|
42
|
+
_preferredChain: string | null;
|
|
39
43
|
/**
|
|
40
44
|
* Sign and execute a transaction. Prefers the current `sui:signAndExecuteTransaction`
|
|
41
45
|
* feature; falls back to the legacy `sui:signAndExecuteTransactionBlock` for older wallets.
|
|
@@ -77,10 +81,12 @@ export default class SuiInBrowserAdapter extends SuiCommonMethods {
|
|
|
77
81
|
signMessage(params: any): Promise<any>;
|
|
78
82
|
/**
|
|
79
83
|
* Disconnect from the wallet and refresh connection state.
|
|
84
|
+
* Force-clears local connection state even if the wallet doesn't support
|
|
85
|
+
* standard:disconnect or doesn't revoke site authorization (e.g. Phantom).
|
|
80
86
|
* @param {Object} [params]
|
|
81
|
-
* @returns {Promise
|
|
87
|
+
* @returns {Promise<void>}
|
|
82
88
|
*/
|
|
83
|
-
disconnect(params?: any): Promise<
|
|
89
|
+
disconnect(params?: any): Promise<void>;
|
|
84
90
|
/**
|
|
85
91
|
* Return the Chrome Web Store download URL, or null if not configured.
|
|
86
92
|
* @returns {?string}
|