suidouble 1.38.0 → 1.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
 
2
+
2
3
  class CustomEvent extends Event {
3
4
  #detail;
4
5
 
@@ -47,6 +47,12 @@ export default class SuiLocalTestValidator extends SuiCommonMethods {
47
47
  return this._active;
48
48
  }
49
49
 
50
+ /**
51
+ * Launch a localnet sui and wait for it to become available to accept transactions.
52
+ * Don't forget to .stop() it after usage.
53
+ *
54
+ * @returns {SuiLocalTestValidator}
55
+ */
50
56
  static async launch(params = {}) {
51
57
  if (SuiLocalTestValidator.__instance) {
52
58
  return await SuiLocalTestValidator.__instance.launch();
@@ -56,6 +62,9 @@ export default class SuiLocalTestValidator extends SuiCommonMethods {
56
62
  return await SuiLocalTestValidator.__instance.launch();
57
63
  }
58
64
 
65
+ /**
66
+ * Stop the local sui node
67
+ */
59
68
  static async stop() {
60
69
  if (SuiLocalTestValidator.__instance) {
61
70
  return await SuiLocalTestValidator.__instance.stop();
@@ -81,6 +90,11 @@ export default class SuiLocalTestValidator extends SuiCommonMethods {
81
90
  return portIsThere;
82
91
  }
83
92
 
93
+ /**
94
+ * Launch a local sui node and wait for it to become available to accept transactions.
95
+ *
96
+ * @returns {SuiLocalTestValidator}
97
+ */
84
98
  async launch() {
85
99
  if (this._active) {
86
100
  return this;
package/lib/SuiMaster.js CHANGED
@@ -21,19 +21,38 @@ import { decodeSuiPrivateKey } from '@mysten/sui/cryptography';
21
21
 
22
22
  /**
23
23
  * @typedef {import("@mysten/sui/client").SuiClient} SuiClient
24
+ * @typedef {import("@mysten/sui/cryptography").Signer} SuiSigner
25
+ * @typedef {import("@mysten/sui/cryptography").Keypair} SuiKeypair
26
+ * @typedef {import("@mysten/sui/client").SuiTransactionBlockResponse} SuiTransactionBlockResponse
24
27
  */
25
28
 
26
29
  export default class SuiMaster extends SuiCommonMethods {
27
- constructor(params = {}) {
30
+ /**
31
+ * SuiMaster constructor
32
+ * @param {Object} params - Initialization parameters
33
+ * @param {?SuiSigner} params.signer - instance of Sui SDK Signer (like Keypair)
34
+ * @param {?SuiKeypair} params.keypair - instance of Sui SDK Keypair
35
+ * @param {?string} param.privateKey - private key in Sui format, starting with "suiprivkey1"
36
+ * @param {?boolean} param.debug - enable debug mode
37
+ * @param {?string} param.phrase - mnemonic phrase to derive keypair from
38
+ * @param {?string} param.keypairAlgo - keypair algorithm to use with mnemonic phrase. One of 'ed25519' (default), 'secp256k1', 'secp256r1'
39
+ * @param {?number} param.accountIndex - index of account to derive from mnemonic phrase. Default is 0
40
+ * @param {?string} param.as - pseudo-random address generation seed string
41
+ * @param {?SuiClient|string} params.client - instance of SuiClient or chain name to make SuiClient connected to it (like 'local', 'devnet', 'testnet', 'mainnet')
42
+ */
43
+ constructor(params) {
28
44
  super(params);
29
45
 
30
46
  // quick value to differenciate instances (if there're few) in logs
31
47
  SuiMaster.instancesCount++;
32
48
  this._instanceN = SuiMaster.instancesCount;
33
49
 
50
+ /** @type {SuiSigner} */
34
51
  this._signer = null;
52
+ /** @type {SuiKeypair} */
35
53
  this._keypair = null;
36
54
 
55
+ /** @type {string} */
37
56
  this._address = null;
38
57
 
39
58
  if (params.signer) {
@@ -53,6 +72,14 @@ export default class SuiMaster extends SuiCommonMethods {
53
72
  } else if (parsed.schema == 'Secp256r1') {
54
73
  this._keypair = Secp256r1Keypair.fromSecretKey(parsed.secretKey);
55
74
  }
75
+ } else if (parsed && parsed.scheme) {
76
+ if (parsed.scheme === 'ED25519') {
77
+ this._keypair = Ed25519Keypair.fromSecretKey(parsed.secretKey);
78
+ } else if (parsed.scheme == 'Secp256k1') {
79
+ this._keypair = Secp256k1Keypair.fromSecretKey(parsed.secretKey);
80
+ } else if (parsed.scheme == 'Secp256r1') {
81
+ this._keypair = Secp256r1Keypair.fromSecretKey(parsed.secretKey);
82
+ }
56
83
  }
57
84
  } else if (params.phrase) {
58
85
  if (params.keypairAlgo && (''+params.keypairAlgo).toLowerCase() == 'secp256r1') {
@@ -72,7 +99,6 @@ export default class SuiMaster extends SuiCommonMethods {
72
99
  this._keypair = Secp256k1Keypair.deriveKeypair(params.phrase, derivePath);
73
100
  }
74
101
  } else {
75
- // default is Ed25519{
76
102
  // default is Ed25519
77
103
 
78
104
  if (!params.accountIndex) {
@@ -95,6 +121,7 @@ export default class SuiMaster extends SuiCommonMethods {
95
121
 
96
122
  /** @type {SuiClient} */
97
123
  this._client = SuiUtils.normalizeClient(params.client);
124
+ /** @type {string} */
98
125
  this._providerName = this._client ? this._client.providerName : null;
99
126
 
100
127
  if (!this._client) {
@@ -108,8 +135,10 @@ export default class SuiMaster extends SuiCommonMethods {
108
135
  suiMaster: this,
109
136
  });
110
137
 
138
+ /** @type {boolean} */
111
139
  this._initialized = false;
112
140
 
141
+ /** @type {Object.<string, SuiPackage>} */
113
142
  this._packages = {};
114
143
 
115
144
  /** @type {SuiCoins} */
@@ -214,11 +243,31 @@ export default class SuiMaster extends SuiCommonMethods {
214
243
  return this._signer;
215
244
  }
216
245
 
246
+ /**
247
+ * Attach a smart contract package to this SuiMaster instance.
248
+ *
249
+ * @param {Object} params - Configuration parameters
250
+ * @param {?string} [params.path] - Local filesystem path to the Move package source code
251
+ * @param {?string} [params.id] - ID or address of the Move package on the Sui blockchain
252
+ * @param {?Array.<string>|string} [params.modules] - List of modules in the package to look on chain in the UpgradeCap owned by current address
253
+ *
254
+ * @returns {SuiPackage}
255
+ */
217
256
  package(params = {}) {
218
257
  return this.addPackage(params);
219
258
  }
220
259
 
221
- addPackage(params = {}) {
260
+ /**
261
+ * Attach a smart contract package to this SuiMaster instance.
262
+ *
263
+ * @param {Object} params - Configuration parameters
264
+ * @param {?string} [params.path] - Local filesystem path to the Move package source code
265
+ * @param {?string} [params.id] - ID or address of the Move package on the Sui blockchain
266
+ * @param {?Array.<string>|string} [params.modules] - List of modules in the package to look on chain in the UpgradeCap owned by current address
267
+ *
268
+ * @returns {SuiPackage}
269
+ */
270
+ addPackage(params) {
222
271
  if (params.id && this._packages[params.id]) {
223
272
  return this._packages[params.id];
224
273
  }
@@ -249,13 +298,10 @@ export default class SuiMaster extends SuiCommonMethods {
249
298
 
250
299
  this._initialized = true;
251
300
 
252
- // this._keypair = sui.Ed25519Keypair.deriveKeypair(this._phrase);
253
301
  if (!this._signer && this._keypair) { // we may optionally go without signer, to work in read-only mode
254
302
  this._signer = this._keypair;//
255
303
  }
256
304
 
257
- // const publicKey = this._keypair.getPublicKey();
258
- // this._address = publicKey.toSuiAddress();
259
305
  if (this._signer) {
260
306
  if (this._signer.toSuiAddress) {
261
307
  this._address = this._signer.toSuiAddress(); // after Sui's refactor Keypair's method
@@ -325,6 +371,7 @@ export default class SuiMaster extends SuiCommonMethods {
325
371
  params.account = { address: this._address };
326
372
  }
327
373
 
374
+ /** @type {SuiTransactionBlockResponse} */
328
375
  let txResults = null;
329
376
  if (this._keypair) {
330
377
  params.signer = this._keypair;
package/lib/SuiObject.js CHANGED
@@ -2,17 +2,33 @@ import SuiCommonMethods from './SuiCommonMethods.js';
2
2
  import SuiPaginatedResponse from './SuiPaginatedResponse.js';
3
3
  import { normalizeSuiAddress } from './SuiUtils.js';
4
4
 
5
+ /**
6
+ * @typedef {import("./SuiMaster.js").default} SuiMaster
7
+ */
8
+
5
9
  export default class SuiObject extends SuiCommonMethods {
10
+ /**
11
+ * Sui Object representation
12
+ *
13
+ * @param {Object} params - parameters
14
+ * @param {SuiMaster} params.suiMaster - instance of SuiMaster
15
+ * @param {?string} [params.id] - ID or address on the sui blockchain
16
+ */
6
17
  constructor(params = {}) {
7
18
  super(params);
8
19
 
20
+ /** @type {SuiMaster} */
9
21
  this._suiMaster = params.suiMaster;
10
22
  if (!this._suiMaster) {
11
23
  throw new Error('suiMaster is requried for suiPackage');
12
24
  }
13
25
 
26
+ /** @type {string} */
14
27
  this._id = params.id || null;
15
28
  this._version = params.version || null;
29
+
30
+
31
+ /** @type {string} */
16
32
  this._type = params.type || null;
17
33
 
18
34
  this._fields = {}; // on-chain fields on the object
package/lib/SuiPackage.js CHANGED
@@ -5,7 +5,21 @@ import SuiPaginatedResponse from './SuiPaginatedResponse.js';
5
5
  import { Transaction } from '@mysten/sui/transactions';
6
6
  import { normalizeSuiAddress } from './SuiUtils.js';
7
7
 
8
+ /**
9
+ * @typedef {import("./SuiMaster.js").default} SuiMaster
10
+ */
11
+
8
12
  export default class SuiPackage extends SuiObject {
13
+ /**
14
+ * Smart Contract Package on Sui blockchain
15
+ *
16
+ * @param {Object} params - Configuration parameters
17
+ * @param {SuiMaster} params.suiMaster - instance of SuiMaster
18
+ * @param {?string} [params.path] - Local filesystem path to the Move package source code
19
+ * @param {?string} [params.id] - ID or address of the Move package on the Sui blockchain
20
+ * @param {?Array.<string>|string} [params.modules] - List of modules in the package to look on chain in the UpgradeCap owned by current address
21
+ * @param {boolean} [params.debug] - Enable debug mode
22
+ */
9
23
  constructor(params = {}) {
10
24
  super(params);
11
25
 
@@ -13,8 +27,12 @@ export default class SuiPackage extends SuiObject {
13
27
  // this._id
14
28
  // this._suiMaster
15
29
 
30
+
31
+ /** @type {?string} */
16
32
  this._path = params.path;
33
+ /** @type {?string} */
17
34
  this._id = params.id || null;
35
+ /** @type {?Array.<string>|string} */
18
36
  this._expectedModules = params.modules || null;
19
37
 
20
38
  this._isPublished = false;
@@ -28,6 +46,7 @@ export default class SuiPackage extends SuiObject {
28
46
  this._builtDependencies = null;
29
47
  this._builtDigest = null;
30
48
 
49
+ /** @type {Object.<string, SuiPackageModule>} */
31
50
  this._modules = {
32
51
 
33
52
  };
@@ -246,13 +246,6 @@ export default class SuiPackageModule extends SuiCommonMethods {
246
246
  }
247
247
 
248
248
  return suiTransaction;
249
-
250
- // return {
251
- // created: listCreated,
252
- // mutated: listMutated,
253
- // deleted: listDeleted,
254
- // status: status,
255
- // };
256
249
  }
257
250
 
258
251
  async getOwnedObjects(params = {}) {
@@ -24,7 +24,7 @@ export default class SuiPaginatedResponse extends SuiCommonMethods {
24
24
  /**
25
25
  * Simple itterator to go over all list of items, not caring about pagination/cursors etc. It fetches next page when needed
26
26
  * Optional maxLimit second parameter to stop when reached count
27
- * @param {Function taking single argument of item} callbackFunc
27
+ * @param {function} callbackFunc
28
28
  * @param {Number} maxLimit
29
29
  */
30
30
  async forEach(callbackFunc, maxLimit = null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suidouble",
3
- "version": "1.38.0",
3
+ "version": "1.45.0",
4
4
  "description": "Set of provider, package and object classes for javascript representation of Sui Move smart contracts. Use same code for publishing, upgrading, integration testing, interaction with smart contracts and integration in browser web3 dapps",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -22,8 +22,8 @@
22
22
  "author": "suidouble (https://github.com/suidouble)",
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@mysten/bcs": "^1.8.0",
26
- "@mysten/sui": "^1.38.0",
25
+ "@mysten/bcs": "^1.9.2",
26
+ "@mysten/sui": "^1.45.0",
27
27
  "@polymedia/coinmeta": "^0.0.17",
28
28
  "@scure/bip39": "^1.6.0",
29
29
  "@wallet-standard/core": "^1.1.1",