@scallop-io/sui-kit 0.33.1 → 0.34.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.
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  ## Pre-requisites
14
14
 
15
15
  ```bash
16
- npm install @scallop-dao/sui-kit
16
+ npm install @scallop-io/sui-kit
17
17
  ```
18
18
 
19
19
 
@@ -22,7 +22,7 @@ npm install @scallop-dao/sui-kit
22
22
  ### Init SuiKit
23
23
 
24
24
  ```typescript
25
- import { SuiKit } from '@scallop-dao/sui-kit';
25
+ import { SuiKit } from '@scallop-io/sui-kit';
26
26
 
27
27
  // The following types of secret key are supported:
28
28
  // 1. base64 key from SUI cli keystore file
@@ -158,7 +158,7 @@ The following is an example using flashloan to make arbitrage.
158
158
 
159
159
 
160
160
  ```typescript
161
- import { SuiKit, SuiTxBlock } from "@scallop-dao/sui-kit";
161
+ import { SuiKit, SuiTxBlock } from "@scallop-io/sui-kit";
162
162
  import * as process from "process";
163
163
  import * as dotenv from "dotenv";
164
164
  dotenv.config();
@@ -215,7 +215,7 @@ When init SuiKit, you can pass in your mnemonics to create a wallet with multipl
215
215
  /**
216
216
  * This is an example of using SuiKit to manage multiple accounts.
217
217
  */
218
- import { SuiKit } from '@scallop-dao/sui-kit';
218
+ import { SuiKit } from '@scallop-io/sui-kit';
219
219
 
220
220
  async function checkAccounts(suiKit: SuiKit) {
221
221
  const displayAccounts = async (suiKit: SuiKit, accountIndex: number) => {
@@ -249,7 +249,7 @@ We have a standalone npm package to help you publish and upgrade Move package wi
249
249
 
250
250
  1. Install the package
251
251
  ```bash
252
- npm install @scallop-dao/sui-package-kit
252
+ npm install @scallop-io/sui-package-kit
253
253
  ```
254
254
 
255
255
  2. Install SUI cli
@@ -259,7 +259,7 @@ Please refer to the official documentation: [How to install SUI cli](https://doc
259
259
  /**
260
260
  * This is an example of using SuiKit to publish a move package
261
261
  */
262
- import { SuiKit } from "@scallop-dao/sui-kit";
262
+ import { SuiKit } from "@scallop-io/sui-kit";
263
263
  import { SuiPackagePublisher } from "@scallop-dao/sui-package-kit";
264
264
 
265
265
  (async() => {
@@ -277,7 +277,7 @@ import { SuiPackagePublisher } from "@scallop-dao/sui-package-kit";
277
277
  /**
278
278
  * This is an example of using SuiKit to upgrade a move package
279
279
  */
280
- import { SuiKit } from "@scallop-dao/sui-kit";
280
+ import { SuiKit } from "@scallop-io/sui-kit";
281
281
  import { SuiPackagePublisher } from "@scallop-dao/sui-package-kit";
282
282
 
283
283
  (async() => {
package/dist/index.js CHANGED
@@ -33,19 +33,19 @@ var __privateMethod = (obj, member, method) => {
33
33
  // src/index.ts
34
34
  var src_exports = {};
35
35
  __export(src_exports, {
36
- SUI_CLOCK_OBJECT_ID: () => import_sui8.SUI_CLOCK_OBJECT_ID,
37
- SUI_SYSTEM_STATE_OBJECT_ID: () => import_sui8.SUI_SYSTEM_STATE_OBJECT_ID,
36
+ SUI_CLOCK_OBJECT_ID: () => import_sui9.SUI_CLOCK_OBJECT_ID,
37
+ SUI_SYSTEM_STATE_OBJECT_ID: () => import_sui9.SUI_SYSTEM_STATE_OBJECT_ID,
38
38
  SuiAccountManager: () => SuiAccountManager,
39
39
  SuiKit: () => SuiKit,
40
40
  SuiRpcProvider: () => SuiRpcProvider,
41
41
  SuiTxBlock: () => SuiTxBlock,
42
- TransactionBlock: () => import_sui8.TransactionBlock
42
+ TransactionBlock: () => import_sui9.TransactionBlock
43
43
  });
44
44
  module.exports = __toCommonJS(src_exports);
45
- var import_sui8 = require("@mysten/sui.js");
45
+ var import_sui9 = require("@mysten/sui.js");
46
46
 
47
47
  // src/lib/sui-kit.ts
48
- var import_sui7 = require("@mysten/sui.js");
48
+ var import_sui8 = require("@mysten/sui.js");
49
49
 
50
50
  // src/lib/sui-account-manager/sui-account-manager.ts
51
51
  var import_sui3 = require("@mysten/sui.js");
@@ -160,7 +160,7 @@ var SuiAccountManager = class {
160
160
  };
161
161
 
162
162
  // src/lib/sui-rpc-provider/sui-rpc-provider.ts
163
- var import_sui5 = require("@mysten/sui.js");
163
+ var import_sui6 = require("@mysten/sui.js");
164
164
 
165
165
  // src/lib/sui-rpc-provider/faucet.ts
166
166
  var import_sui4 = require("@mysten/sui.js");
@@ -200,36 +200,19 @@ var requestFaucet = async (address, provider) => {
200
200
  };
201
201
 
202
202
  // src/lib/sui-rpc-provider/default-chain-configs.ts
203
- var DEFAULT_LOCALHOST_FULLNODE = "http://0.0.0.0:9000";
204
- var DEFAULT_LOCALHOST_FAUCET = "";
205
- var DEFAULT_DEVNET_FULLNODE = "https://fullnode.devnet.sui.io:443";
206
- var DEFAULT_DEVNET_FAUCET = "https://faucet.devnet.sui.io/gas";
207
- var DEFAULT_TESTNET_FULLNODE = "https://fullnode.testnet.sui.io:443";
208
- var DEFAULT_TESTNET_FAUCET = "https://faucet.testnet.sui.io/gas";
209
- var DEFAULT_MAINNET_FULLNODE = "https://fullnode.mainnet.sui.io:443";
210
- var DEFAULT_MAINNET_FAUCET = "";
203
+ var import_sui5 = require("@mysten/sui.js");
211
204
  var getDefaultNetworkParams = (networkType = "devnet") => {
212
205
  switch (networkType) {
213
- case "localhost":
214
- return {
215
- fullNode: DEFAULT_LOCALHOST_FULLNODE,
216
- faucet: DEFAULT_LOCALHOST_FAUCET
217
- };
206
+ case "localnet":
207
+ return import_sui5.localnetConnection;
208
+ case "devnet":
209
+ return import_sui5.devnetConnection;
218
210
  case "testnet":
219
- return {
220
- fullNode: DEFAULT_TESTNET_FULLNODE,
221
- faucet: DEFAULT_TESTNET_FAUCET
222
- };
211
+ return import_sui5.testnetConnection;
223
212
  case "mainnet":
224
- return {
225
- fullNode: DEFAULT_MAINNET_FULLNODE,
226
- faucet: DEFAULT_MAINNET_FAUCET
227
- };
213
+ return import_sui5.mainnetConnection;
228
214
  default:
229
- return {
230
- fullNode: DEFAULT_DEVNET_FULLNODE,
231
- faucet: DEFAULT_DEVNET_FAUCET
232
- };
215
+ return import_sui5.devnetConnection;
233
216
  }
234
217
  };
235
218
 
@@ -237,19 +220,19 @@ var getDefaultNetworkParams = (networkType = "devnet") => {
237
220
  var SuiRpcProvider = class {
238
221
  /**
239
222
  *
240
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
223
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
241
224
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
242
225
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
243
226
  */
244
227
  constructor({ fullnodeUrl, faucetUrl, networkType } = {}) {
245
228
  const defaultNetworkParams = getDefaultNetworkParams(networkType || "devnet");
246
- this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullNode;
229
+ this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullnode;
247
230
  this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;
248
- const connection = new import_sui5.Connection({
231
+ const connection = new import_sui6.Connection({
249
232
  fullnode: this.fullnodeUrl,
250
233
  faucet: this.faucetUrl
251
234
  });
252
- this.provider = new import_sui5.JsonRpcProvider(connection);
235
+ this.provider = new import_sui6.JsonRpcProvider(connection);
253
236
  }
254
237
  /**
255
238
  * Request some SUI from faucet
@@ -265,11 +248,11 @@ var SuiRpcProvider = class {
265
248
  const options = { showContent: true, showDisplay: true, showType: true };
266
249
  const objects = await this.provider.multiGetObjects({ ids, options });
267
250
  const parsedObjects = objects.map((object) => {
268
- const objectId = (0, import_sui5.getObjectId)(object);
269
- const objectType = (0, import_sui5.getObjectType)(object);
270
- const objectVersion = (0, import_sui5.getObjectVersion)(object);
271
- const objectFields = (0, import_sui5.getObjectFields)(object);
272
- const objectDisplay = (0, import_sui5.getObjectDisplay)(object);
251
+ const objectId = (0, import_sui6.getObjectId)(object);
252
+ const objectType = (0, import_sui6.getObjectType)(object);
253
+ const objectVersion = (0, import_sui6.getObjectVersion)(object);
254
+ const objectFields = (0, import_sui6.getObjectFields)(object);
255
+ const objectDisplay = (0, import_sui6.getObjectDisplay)(object);
273
256
  return { objectId, objectType, objectVersion, objectFields, objectDisplay };
274
257
  });
275
258
  return parsedObjects;
@@ -304,7 +287,7 @@ var SuiRpcProvider = class {
304
287
  };
305
288
 
306
289
  // src/lib/sui-tx-builder/sui-tx-block.ts
307
- var import_sui6 = require("@mysten/sui.js");
290
+ var import_sui7 = require("@mysten/sui.js");
308
291
 
309
292
  // src/lib/sui-tx-builder/util.ts
310
293
  var getDefaultSuiInputType = (value) => {
@@ -325,7 +308,7 @@ var SuiTxBlock = class {
325
308
  constructor() {
326
309
  __privateAdd(this, _isMoveVecArg);
327
310
  __privateAdd(this, _convertArgs);
328
- this.txBlock = new import_sui6.TransactionBlock();
311
+ this.txBlock = new import_sui7.TransactionBlock();
329
312
  }
330
313
  transferSuiToMany(recipients, amounts) {
331
314
  if (recipients.length !== amounts.length) {
@@ -414,7 +397,7 @@ var SuiTxBlock = class {
414
397
  const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);
415
398
  tx.moveCall({
416
399
  target: "0x3::sui_system::request_add_stake",
417
- arguments: [tx.object(import_sui6.SUI_SYSTEM_STATE_OBJECT_ID), stakeCoin, tx.pure(validatorAddr)]
400
+ arguments: [tx.object(import_sui7.SUI_SYSTEM_STATE_OBJECT_ID), stakeCoin, tx.pure(validatorAddr)]
418
401
  });
419
402
  return tx;
420
403
  }
@@ -447,7 +430,7 @@ var SuiTxBlock = class {
447
430
  const defaultSuiType = getDefaultSuiInputType(args[0]);
448
431
  if (type === "object" || !type && defaultSuiType === "object") {
449
432
  const objects = args.map(
450
- (arg) => typeof arg === "string" ? this.txBlock.object((0, import_sui6.normalizeSuiObjectId)(arg)) : arg
433
+ (arg) => typeof arg === "string" ? this.txBlock.object((0, import_sui7.normalizeSuiObjectId)(arg)) : arg
451
434
  );
452
435
  return this.txBlock.makeMoveVec({ objects });
453
436
  } else {
@@ -466,7 +449,7 @@ _convertArgs = new WeakSet();
466
449
  convertArgs_fn = function(args) {
467
450
  return args.map((arg) => {
468
451
  if (typeof arg === "string" && arg.startsWith("0x")) {
469
- return this.txBlock.object((0, import_sui6.normalizeSuiObjectId)(arg));
452
+ return this.txBlock.object((0, import_sui7.normalizeSuiObjectId)(arg));
470
453
  } else if (__privateMethod(this, _isMoveVecArg, isMoveVecArg_fn).call(this, arg)) {
471
454
  const vecType = arg.vecType || void 0;
472
455
  return vecType ? this.makeMoveVec(arg.value, vecType) : this.makeMoveVec(arg);
@@ -488,7 +471,7 @@ var SuiKit = class {
488
471
  *
489
472
  * @param mnemonics, 12 or 24 mnemonics words, separated by space
490
473
  * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
491
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
474
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
492
475
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
493
476
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
494
477
  */
@@ -504,7 +487,7 @@ var SuiKit = class {
504
487
  */
505
488
  getSigner(derivePathParams) {
506
489
  const keyPair = this.accountManager.getKeyPair(derivePathParams);
507
- return new import_sui7.RawSigner(keyPair, this.rpcProvider.provider);
490
+ return new import_sui8.RawSigner(keyPair, this.rpcProvider.provider);
508
491
  }
509
492
  /**
510
493
  * @description Switch the current account with the given derivePathParams
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/sui-kit.ts","../src/lib/sui-account-manager/sui-account-manager.ts","../src/lib/sui-account-manager/keypair.ts","../src/lib/sui-account-manager/util.ts","../src/lib/sui-account-manager/crypto.ts","../src/lib/sui-rpc-provider/sui-rpc-provider.ts","../src/lib/sui-rpc-provider/faucet.ts","../src/lib/sui-rpc-provider/default-chain-configs.ts","../src/lib/sui-tx-builder/sui-tx-block.ts","../src/lib/sui-tx-builder/util.ts"],"sourcesContent":["export { TransactionBlock, SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui.js'\nexport { SuiKit } from './lib/sui-kit'\nexport type { SuiKitParams } from './lib/sui-kit'\nexport { SuiAccountManager } from './lib/sui-account-manager'\nexport type { DerivePathParams } from './lib/sui-account-manager'\nexport { SuiTxBlock } from './lib/sui-tx-builder'\nexport type { SuiTxArg } from './lib/sui-tx-builder'\n\nexport { SuiRpcProvider } from './lib/sui-rpc-provider'\nexport type { NetworkType } from './lib/sui-rpc-provider'\n","/**\n * @file src.ts\n * @description This file is used to aggregate the tools that used to interact with SUI network.\n * @author IceFox\n * @version 0.1.0\n */\nimport { RawSigner, TransactionBlock, DevInspectResults, SuiTransactionBlockResponse } from '@mysten/sui.js';\nimport { SuiAccountManager, DerivePathParams } from \"./sui-account-manager\";\nimport { SuiRpcProvider, NetworkType } from './sui-rpc-provider';\nimport { SuiTxBlock, SuiTxArg, SuiVecTxArg } from \"./sui-tx-builder\";\n\nexport type SuiKitParams = {\n mnemonics?: string;\n secretKey?: string;\n fullnodeUrl?: string;\n faucetUrl?: string;\n networkType?: NetworkType;\n}\n/**\n * @class SuiKit\n * @description This class is used to aggregate the tools that used to interact with SUI network.\n */\nexport class SuiKit {\n\n public accountManager: SuiAccountManager;\n public rpcProvider: SuiRpcProvider;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type\n */\n constructor({ mnemonics, secretKey, networkType, fullnodeUrl, faucetUrl }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n this.rpcProvider = new SuiRpcProvider({ fullnodeUrl, faucetUrl, networkType });\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.\n * else:\n * it will generate signer from the mnemonic with the given derivePathParams.\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getSigner(derivePathParams?: DerivePathParams) {\n const keyPair = this.accountManager.getKeyPair(derivePathParams);\n return new RawSigner(keyPair, this.rpcProvider.provider);\n }\n\n /**\n * @description Switch the current account with the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n switchAccount(derivePathParams: DerivePathParams) {\n this.accountManager.switchAccount(derivePathParams);\n }\n\n /**\n * @description Get the address of the account for the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getAddress(derivePathParams?: DerivePathParams) {\n return this.accountManager.getAddress(derivePathParams);\n }\n currentAddress() { return this.accountManager.currentAddress }\n \n provider() { return this.rpcProvider.provider }\n\n /**\n * Request some SUI from faucet\n * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.\n */\n async requestFaucet(derivePathParams?: DerivePathParams) {\n const addr = this.accountManager.getAddress(derivePathParams);\n return this.rpcProvider.requestFaucet(addr);\n }\n\n async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {\n const owner = this.accountManager.getAddress(derivePathParams);\n return this.rpcProvider.getBalance(owner, coinType);\n }\n\n async getObjects(objectIds: string[]) {\n return this.rpcProvider.getObjects(objectIds);\n }\n\n async signTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams) {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signTransactionBlock({ transactionBlock: tx });\n }\n\n async signAndSendTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signAndExecuteTransactionBlock({ transactionBlock: tx, options: {\n showEffects: true,\n showEvents: true,\n showObjectChanges: true,\n }})\n }\n\n /**\n * Transfer the given amount of SUI to the recipient\n * @param recipient\n * @param amount\n * @param derivePathParams\n */\n async transferSui(recipient: string, amount: number, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferSui(recipient, amount);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer to mutliple recipients\n * @param recipients the recipients addresses\n * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients\n * @param derivePathParams\n */\n async transferSuiToMany(recipients: string[], amounts: number[], derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferSuiToMany(recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer the given amounts of coin to multiple recipients\n * @param recipients the list of recipient address\n * @param amounts the amounts to transfer for each recipient\n * @param coinType any custom coin type but not SUI\n * @param derivePathParams the derive path params for the current signer\n */\n async transferCoinToMany(recipients: string[], amounts: number[], coinType: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n const owner = this.accountManager.getAddress(derivePathParams);\n const totalAmount = amounts.reduce((a, b) => a + b, 0);\n const coins = await this.rpcProvider.selectCoins(owner, totalAmount, coinType);\n tx.transferCoinToMany(coins.map(c => c.objectId), owner, recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n \n async transferCoin(recipient: string, amount: number, coinType: string, derivePathParams?: DerivePathParams) {\n return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams)\n }\n \n async transferObjects(objects: string[], recipient: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n \n async moveCall(callParams: {target: string, arguments?: (SuiTxArg | SuiVecTxArg)[], typeArguments?: string[], derivePathParams?: DerivePathParams}) {\n const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;\n const tx = new SuiTxBlock();\n tx.moveCall(target, args, typeArguments);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount\n * @param amount\n * @param coinType\n * @param owner\n */\n async selectCoinsWithAmount(amount: number, coinType: string, owner?: string) {\n owner = owner || this.accountManager.currentAddress;\n const coins = await this.rpcProvider.selectCoins(owner, amount, coinType);\n return coins.map(c => c.objectId)\n }\n\n /**\n * stake the given amount of SUI to the validator\n * @param amount the amount of SUI to stake\n * @param validatorAddr the validator address\n * @param derivePathParams the derive path params for the current signer\n */\n async stakeSui(amount: number, validatorAddr: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.stakeSui(amount, validatorAddr);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.\n * Since the transaction is not submitted, its gas cost is not charged.\n * @param tx the transaction to execute\n * @param derivePathParams the derive path params\n * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.\n */\n async inspectTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.rpcProvider.provider.devInspectTransactionBlock({ transactionBlock: tx, sender: this.getAddress(derivePathParams) })\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js'\nimport { getKeyPair, DerivePathParams } from \"./keypair\";\nimport {hexOrBase64ToUint8Array, normalizePrivateKey} from \"./util\";\nimport { generateMnemonic } from './crypto';\n\ntype AccountMangerParams = {\n mnemonics?: string;\n secretKey?: string;\n}\nexport class SuiAccountManager {\n private mnemonics: string;\n private secretKey: string;\n public currentKeyPair: Ed25519Keypair;\n public currentAddress: string;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n */\n constructor({ mnemonics, secretKey }: AccountMangerParams = {}) {\n // If the mnemonics or secretKey is provided, use it\n // Otherwise, generate a random mnemonics with 24 words\n this.mnemonics = mnemonics || \"\";\n this.secretKey = secretKey || \"\";\n if (!this.mnemonics && !this.secretKey) {\n this.mnemonics = generateMnemonic(24)\n }\n\n // Init the current account\n this.currentKeyPair = this.secretKey\n ? Ed25519Keypair.fromSecretKey(\n normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))\n )\n : getKeyPair(this.mnemonics);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.\n * else:\n * it will generate keyPair from the mnemonic with the given derivePathParams.\n */\n getKeyPair(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentKeyPair;\n return getKeyPair(this.mnemonics, derivePathParams);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.\n * else:\n * it will generate address from the mnemonic with the given derivePathParams.\n */\n getAddress(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentAddress;\n return getKeyPair(this.mnemonics, derivePathParams).getPublicKey().toSuiAddress();\n }\n\n /**\n * Switch the current account with the given derivePathParams.\n * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.\n */\n switchAccount(derivePathParams: DerivePathParams) {\n if (this.mnemonics) {\n this.currentKeyPair = getKeyPair(this.mnemonics, derivePathParams);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js'\n\nexport type DerivePathParams = {\n accountIndex?: number;\n isExternal?: boolean;\n addressIndex?: number;\n}\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (derivePathParams: DerivePathParams = {}) => {\n const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;\n return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;\n}\n\n/**\n * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'\n *\n * accountIndex is the index of the account, default is 0.\n *\n * isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.\n *\n * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.\n *\n * @description Get keypair from mnemonics and derive path\n * @param mnemonics\n * @param derivePathParams\n */\nexport const getKeyPair = (mnemonics: string, derivePathParams: DerivePathParams = {}) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n}\n","import { fromB64 } from '@mysten/sui.js'\n/**\n * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).\n * @param str\n */\nexport const isHex = (str: string) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);\n\n/**\n * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).\n * Note that the \"=\" signs at the end are optional padding characters that may be present in some base64 encoded strings.\n * @param str\n */\nexport const isBase64 = (str: string) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);\n\n/**\n * Convert a hex string to Uint8Array\n * @param hexStr\n */\nexport function fromHEX(hexStr: string): Uint8Array {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array')\n }\n let intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)?.map(byte => parseInt(byte, 16));\n\n if (!intArr || intArr.length === 0) {\n throw new Error(`Unable to parse HEX: ${hexStr}`);\n }\n return Uint8Array.from(intArr);\n}\n\n/**\n * @description Convert a hex or base64 string to Uint8Array\n */\nexport const hexOrBase64ToUint8Array = (str: string): Uint8Array => {\n if (isHex(str)) {\n return fromHEX(str)\n } else if (isBase64(str)) {\n return fromB64(str)\n } else {\n throw new Error('The string is not a valid hex or base64 string.');\n }\n}\n\nconst PRIVATE_KEY_SIZE = 32;\nconst LEGACY_PRIVATE_KEY_SIZE = 64;\n/**\n * normalize a private key\n * A private key is a 32-byte array.\n * But there are two different formats for private keys:\n * 1. A 32-byte array\n * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key\n * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)\n */\nexport const normalizePrivateKey = (key: Uint8Array): Uint8Array => {\n if (key.length === LEGACY_PRIVATE_KEY_SIZE) {\n // This is a legacy secret key, we need to strip the public key bytes and only read the first 32 bytes\n key = key.slice(0, PRIVATE_KEY_SIZE);\n } else if (key.length === PRIVATE_KEY_SIZE + 1 && key[0] === 0) {\n // sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning\n return key.slice(1);\n } else if (key.length === PRIVATE_KEY_SIZE) {\n return key;\n }\n throw new Error('invalid secret key');\n}\n","import { generateMnemonic as genMnemonic } from '@scure/bip39'\nimport { wordlist } from '@scure/bip39/wordlists/english.js'\n\nexport const generateMnemonic = (numberOfWords: 12 | 24 = 24) => {\n const strength = numberOfWords === 12 ? 128 : 256\n return genMnemonic(wordlist, strength)\n}\n","import {\n Connection,\n JsonRpcProvider,\n getObjectType,\n getObjectId,\n getObjectFields,\n getObjectDisplay,\n getObjectVersion,\n DisplayFieldsResponse,\n ObjectContentFields,\n} from \"@mysten/sui.js\";\nimport { requestFaucet } from './faucet'\nimport { NetworkType, getDefaultNetworkParams } from \"./default-chain-configs\";\n\ntype ObjectData = {\n objectId: string;\n objectType: string;\n objectVersion: number;\n objectDisplay: DisplayFieldsResponse;\n objectFields: ObjectContentFields;\n}\n\ntype Params = {\n fullnodeUrl?: string;\n faucetUrl?: string;\n networkType?: NetworkType;\n}\n\nexport class SuiRpcProvider {\n public fullnodeUrl: string;\n public faucetUrl: string;\n public provider: JsonRpcProvider;\n /**\n *\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type\n */\n constructor({ fullnodeUrl, faucetUrl, networkType }: Params = {}) {\n // Get the default fullnode url and faucet url for the given network type, default is 'testnet'\n const defaultNetworkParams = getDefaultNetworkParams(networkType || 'devnet');\n // Set fullnodeUrl and faucetUrl, if they are not provided, use the default value.\n this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullNode;\n this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;\n\n // Init the provider\n const connection = new Connection({\n fullnode: this.fullnodeUrl,\n faucet: this.faucetUrl,\n });\n this.provider = new JsonRpcProvider(connection);\n }\n\n /**\n * Request some SUI from faucet\n * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.\n */\n async requestFaucet(addr: string) {\n return requestFaucet(addr, this.provider)\n }\n\n async getBalance(addr: string, coinType?: string) {\n return this.provider.getBalance({ owner: addr, coinType });\n }\n\n async getObjects(ids: string[]) {\n const options = { showContent: true, showDisplay: true, showType: true };\n const objects = await this.provider.multiGetObjects({ ids, options });\n const parsedObjects = objects.map((object) => {\n const objectId = getObjectId(object);\n const objectType = getObjectType(object);\n const objectVersion = getObjectVersion(object);\n const objectFields = getObjectFields(object);\n const objectDisplay = getObjectDisplay(object);\n return { objectId, objectType, objectVersion, objectFields, objectDisplay };\n });\n return parsedObjects as ObjectData[]\n }\n\n /**\n * @description Select coins that add up to the given amount.\n * @param addr the address of the owner\n * @param amount the amount that is needed for the coin\n * @param coinType the coin type, default is '0x2::SUI::SUI'\n */\n async selectCoins(addr: string, amount: number, coinType: string = '0x2::SUI::SUI') {\n const coins = await this.provider.getCoins({ owner: addr, coinType });\n let selectedCoins: {objectId: string, digest: string, version: string}[] = [];\n let totalAmount = 0;\n // Sort the coins by balance in descending order\n const coinsData = coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance))\n for(const coinData of coins.data) {\n selectedCoins.push({\n objectId: coinData.coinObjectId,\n digest: coinData.digest,\n version: coinData.version,\n });\n totalAmount = totalAmount + parseInt(coinData.balance);\n if (totalAmount >= amount) {\n break;\n }\n }\n\n if (!selectedCoins.length) {\n throw new Error('No valid coins found for the transaction.');\n }\n return selectedCoins;\n }\n}\n","import {JsonRpcProvider, FaucetRateLimitError, assert, FaucetResponse} from '@mysten/sui.js'\nimport { retry } from 'ts-retry-promise'\n\n/**\n * Request some SUI from faucet\n * @param address\n * @param provider\n * @returns {Promise<boolean>}, return true if the request is successful\n */\nexport const requestFaucet = async (address: string, provider: JsonRpcProvider) => {\n console.log('\\nRequesting SUI from faucet for address: ', address)\n const headers = {\n authority: 'faucet.testnet.sui.io',\n method: 'POST',\n path: '/gas',\n scheme: 'https',\n accept: '*/*',\n 'accept-encoding': 'gzip, deflate, br',\n 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7',\n 'content-length': '105',\n 'content-type': 'application/json',\n 'origin': 'chrome-extension://opcgpfmipidbgpenhmajoajpbobppdil',\n cookie: '_ga=GA1.1.2092533979.1664032306; sui_io_cookie={\"level\":[\"necessary\",\"analytics\"],\"revision\":0,\"data\":null,\"rfc_cookie\":false}; _ga_YKP53WJMB0=GS1.1.1680531285.31.0.1680531334.11.0.0; _ga_0GW4F97GFL=GS1.1.1680826187.125.0.1680826187.60.0.0; __cf_bm=6rPjXUwuzUPy4yDlZuXgDj0v7xLPpUd5z0CFGCoN_YI-1680867579-0-AZMhU7/mKUUbUlOa27LmfW6eIFkBkXsPKqYgWjpjWpj2XzDckgUsRu/pxSRGfvXCspn3w7Df+uO1MR/b+XikJU0=; _cfuvid=zjwCXMmu19KBIVo_L9Qbq4TqFXJpophG3.EvFTxqdf4-1680867579342-0-604800000',\n 'sec-ch-ua': '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"',\n 'sec-ch-ua-mobile': '?0',\n 'sec-ch-ua-platform': \"macOS\",\n 'sec-fetch-dest': 'empty',\n 'sec-fetch-mode': 'cors',\n 'sec-fetch-site': 'none',\n 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',\n }\n // We need to add the following headers to the request, otherwise the request will be rejected by the faucet server\n const resp = await retry<FaucetResponse>(() => provider.requestSuiFromFaucet(address, headers), {\n backoff: 'EXPONENTIAL',\n // overall timeout in 60 seconds\n timeout: 1000 * 60,\n // skip retry if we hit the rate-limit error\n retryIf: (error: any) => !(error instanceof FaucetRateLimitError),\n logger: (msg) => console.warn(`Retry requesting faucet: ${msg}`),\n });\n assert(resp, FaucetResponse, 'Request faucet failed\\n');\n console.log('Request faucet success\\n');\n}\n","/**\n * @description This file is used to store the default chain parameters for the different networks.\n * @author IceFox@Scallop\n */\n// For localhost\nexport const DEFAULT_LOCALHOST_FULLNODE = \"http://0.0.0.0:9000\"\nexport const DEFAULT_LOCALHOST_FAUCET = \"\"\n\n// For devnet\nexport const DEFAULT_DEVNET_FULLNODE =\"https://fullnode.devnet.sui.io:443\"\nexport const DEFAULT_DEVNET_FAUCET = \"https://faucet.devnet.sui.io/gas\"\n\n// For testnet\nexport const DEFAULT_TESTNET_FULLNODE = \"https://fullnode.testnet.sui.io:443\"\nexport const DEFAULT_TESTNET_FAUCET = \"https://faucet.testnet.sui.io/gas\"\n\n// For mainnet\nexport const DEFAULT_MAINNET_FULLNODE = \"https://fullnode.mainnet.sui.io:443\"\nexport const DEFAULT_MAINNET_FAUCET = \"\"\n\n\nexport type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localhost';\n\n/**\n * @description Get the default fullnode url and faucet url for the given network type\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'\n * @returns { fullNode: string, faucet: string }\n */\nexport const getDefaultNetworkParams = (networkType: NetworkType = 'devnet'): { fullNode: string, faucet: string } => {\n switch (networkType) {\n case 'localhost':\n return {\n fullNode: DEFAULT_LOCALHOST_FULLNODE,\n faucet: DEFAULT_LOCALHOST_FAUCET,\n }\n case 'testnet':\n return {\n fullNode: DEFAULT_TESTNET_FULLNODE,\n faucet: DEFAULT_TESTNET_FAUCET,\n }\n case 'mainnet':\n return {\n fullNode: DEFAULT_MAINNET_FULLNODE,\n faucet: DEFAULT_MAINNET_FAUCET,\n }\n default:\n return {\n fullNode: DEFAULT_DEVNET_FULLNODE,\n faucet: DEFAULT_DEVNET_FAUCET,\n }\n }\n}\n","import {\n TransactionBlock,\n SUI_SYSTEM_STATE_OBJECT_ID,\n normalizeSuiObjectId,\n TransactionArgument,\n} from '@mysten/sui.js'\nimport { SuiInputTypes, getDefaultSuiInputType } from './util'\n\nexport type SuiTxArg = TransactionArgument | string | number | bigint | boolean;\nexport type SuiVecTxArg = { value: SuiTxArg[], vecType: SuiInputTypes } | SuiTxArg[];\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor() {\n this.txBlock = new TransactionBlock();\n }\n\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error('transferSuiToMany: recipients.length !== amounts.length');\n }\n const tx = this.txBlock;\n const coins = tx.splitCoins(tx.gas, amounts.map(amount => tx.pure(amount)));\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n transferObjects(objects: SuiTxArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(this.#convertArgs(objects), tx.pure(recipient));\n return this;\n }\n\n takeAmountFromCoins(coins: SuiTxArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = this.#convertArgs(coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);\n return [sendCoin, mergedCoin];\n }\n\n splitSUIFromGas(amounts: number[]) {\n const tx = this.txBlock;\n return tx.splitCoins(tx.gas, amounts.map(m => tx.pure(m)));\n }\n \n splitCoins(coin: SuiTxArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = this.#convertArgs([coin])[0];\n return tx.splitCoins(coinObject, amounts.map(m => tx.pure(m)));\n }\n \n splitMultiCoins(coins: SuiTxArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = this.#convertArgs(coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(mergedCoin, amounts.map(m => tx.pure(m)));\n return { splitedCoins, mergedCoin }\n }\n \n transferCoinToMany(inputCoins: SuiTxArg[], sender: string, recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error('transferSuiToMany: recipients.length !== amounts.length');\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(inputCoins, amounts);\n recipients.forEach((recipient, index) => {\n tx.transferObjects([splitedCoins[index]], tx.pure(recipient));\n });\n tx.transferObjects([mergedCoin], tx.pure(sender))\n return this;\n }\n \n transferCoin(inputCoins: SuiTxArg[], sender: string, recipient: string, amount: number) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\n }\n \n /**\n * @description Move call\n * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`\n * @param args the arguments of the move call, such as `['0x1', '0x2']`\n * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`\n */\n moveCall(target: string, args: (SuiTxArg | SuiVecTxArg)[] = [], typeArgs: string[] = []) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex = /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;\n const match = target.match(regex);\n if (match === null) throw new Error('Invalid target format. Expected `${string}::${string}::${string}`');\n const convertedArgs = this.#convertArgs(args);\n const tx = this.txBlock;\n return tx.moveCall({\n target: target as `${string}::${string}::${string}`,\n arguments: convertedArgs,\n typeArguments: typeArgs,\n });\n }\n\n stakeSui(amount: number, validatorAddr: string) {\n const tx = this.txBlock;\n const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);\n tx.moveCall({\n target: '0x3::sui_system::request_add_stake',\n arguments: [tx.object(SUI_SYSTEM_STATE_OBJECT_ID), stakeCoin, tx.pure(validatorAddr)],\n });\n return tx;\n }\n\n address(value: string) {\n return this.txBlock.pure(value)\n }\n\n pure(value: any) {\n return this.txBlock.pure(value)\n }\n\n object(value: string) {\n return this.txBlock.object(value)\n }\n\n /**\n * Since we know the elements in the array are the same type\n * If type is not provided, we will try to infer the type from the first element\n * By default,\n *\n * string starting with `0x` =====> object id\n * number, bigint ====> u64\n * boolean =====> bool\n *\n *\n * If type is provided, we will use the type to convert the array\n * @param args\n * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'\n */\n makeMoveVec(args: SuiTxArg[], type?: SuiInputTypes) {\n if (args.length === 0) throw new Error('Transaction builder error: Empty array is not allowed');\n const defaultSuiType = getDefaultSuiInputType(args[0])\n if (type === 'object' || (!type && defaultSuiType === 'object')) {\n const objects = args.map(arg =>\n typeof arg === 'string' ? this.txBlock.object(normalizeSuiObjectId(arg)) : (arg as any)\n );\n return this.txBlock.makeMoveVec({ objects })\n } else {\n const vecType = type || defaultSuiType;\n return this.txBlock.pure(args, `vector<${vecType}>`)\n }\n }\n\n #isMoveVecArg(arg: any) {\n const isFullMoveVecArg = arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n }\n\n #convertArgs(args: any[]): TransactionArgument[] {\n return args.map(arg => {\n if (typeof arg === 'string' && arg.startsWith('0x')) {\n // We always treat string starting with `0x` as object id\n return this.txBlock.object(normalizeSuiObjectId(arg))\n } else if (this.#isMoveVecArg(arg)) {\n // if it's an array arg, we will convert it to move vec\n const vecType = arg.vecType || undefined;\n return vecType\n ? this.makeMoveVec(arg.value, vecType)\n : this.makeMoveVec(arg)\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return this.txBlock.pure(arg)\n } else {\n // We do nothing, because it's most likely already a move value\n return arg\n }\n })\n }\n}\n","/**\n * These are the basics types that can be used in the SUI\n */\nexport type SuiBasicTypes =\n |'address'\n |'bool'\n |'u8'\n | 'u16'\n | 'u32'\n | 'u64'\n | 'u128'\n | 'u256'\n\nexport type SuiInputTypes = 'object' | SuiBasicTypes\n\nexport const getDefaultSuiInputType = (value: any): SuiInputTypes => {\n if (typeof value === 'string' && value.startsWith('0x')) {\n return 'object'\n } else if (typeof value === 'number' || typeof value === 'bigint') {\n return 'u64'\n } else if (typeof value === 'boolean') {\n return 'bool'\n } else {\n return 'object'\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAAkF;;;ACMlF,IAAAC,cAA4F;;;ACN5F,IAAAC,cAA+B;;;ACA/B,iBAA+B;AAWxB,IAAM,sBAAsB,CAAC,mBAAqC,CAAC,MAAM;AAC9E,QAAM,EAAE,eAAe,GAAG,aAAa,OAAO,eAAe,EAAE,IAAI;AACnE,SAAO,cAAc,iBAAiB,aAAa,IAAI,MAAM;AAC/D;AAeO,IAAM,aAAa,CAAC,WAAmB,mBAAqC,CAAC,MAAM;AACxF,QAAM,aAAa,oBAAoB,gBAAgB;AACvD,SAAO,0BAAe,cAAc,WAAW,UAAU;AA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gD,kBAAiE;AAChI,SAAK,cAAc,aAAa,GAAG,UAAU;AAC7C,WAAO,KAAK,YAAY,SAAS,2BAA2B,EAAE,kBAAkB,IAAI,QAAQ,KAAK,WAAW,gBAAgB,EAAE,CAAC;AAAA,EACjI;AACF;","names":["import_sui","import_sui","import_sui","import_sui","genMnemonic","import_sui","import_sui","import_sui"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/sui-kit.ts","../src/lib/sui-account-manager/sui-account-manager.ts","../src/lib/sui-account-manager/keypair.ts","../src/lib/sui-account-manager/util.ts","../src/lib/sui-account-manager/crypto.ts","../src/lib/sui-rpc-provider/sui-rpc-provider.ts","../src/lib/sui-rpc-provider/faucet.ts","../src/lib/sui-rpc-provider/default-chain-configs.ts","../src/lib/sui-tx-builder/sui-tx-block.ts","../src/lib/sui-tx-builder/util.ts"],"sourcesContent":["export { TransactionBlock, SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui.js'\nexport { SuiKit } from './lib/sui-kit'\nexport type { SuiKitParams } from './lib/sui-kit'\nexport { SuiAccountManager } from './lib/sui-account-manager'\nexport type { DerivePathParams } from './lib/sui-account-manager'\nexport { SuiTxBlock } from './lib/sui-tx-builder'\nexport type { SuiTxArg } from './lib/sui-tx-builder'\n\nexport { SuiRpcProvider } from './lib/sui-rpc-provider'\nexport type { NetworkType } from './lib/sui-rpc-provider'\n","/**\n * @file src.ts\n * @description This file is used to aggregate the tools that used to interact with SUI network.\n * @author IceFox\n * @version 0.1.0\n */\nimport { RawSigner, TransactionBlock, DevInspectResults, SuiTransactionBlockResponse } from '@mysten/sui.js';\nimport { SuiAccountManager, DerivePathParams } from \"./sui-account-manager\";\nimport { SuiRpcProvider, NetworkType } from './sui-rpc-provider';\nimport { SuiTxBlock, SuiTxArg, SuiVecTxArg } from \"./sui-tx-builder\";\n\nexport type SuiKitParams = {\n mnemonics?: string;\n secretKey?: string;\n fullnodeUrl?: string;\n faucetUrl?: string;\n networkType?: NetworkType;\n}\n/**\n * @class SuiKit\n * @description This class is used to aggregate the tools that used to interact with SUI network.\n */\nexport class SuiKit {\n\n public accountManager: SuiAccountManager;\n public rpcProvider: SuiRpcProvider;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type\n */\n constructor({ mnemonics, secretKey, networkType, fullnodeUrl, faucetUrl }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n this.rpcProvider = new SuiRpcProvider({ fullnodeUrl, faucetUrl, networkType });\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.\n * else:\n * it will generate signer from the mnemonic with the given derivePathParams.\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getSigner(derivePathParams?: DerivePathParams) {\n const keyPair = this.accountManager.getKeyPair(derivePathParams);\n return new RawSigner(keyPair, this.rpcProvider.provider);\n }\n\n /**\n * @description Switch the current account with the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n switchAccount(derivePathParams: DerivePathParams) {\n this.accountManager.switchAccount(derivePathParams);\n }\n\n /**\n * @description Get the address of the account for the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getAddress(derivePathParams?: DerivePathParams) {\n return this.accountManager.getAddress(derivePathParams);\n }\n currentAddress() { return this.accountManager.currentAddress }\n \n provider() { return this.rpcProvider.provider }\n\n /**\n * Request some SUI from faucet\n * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.\n */\n async requestFaucet(derivePathParams?: DerivePathParams) {\n const addr = this.accountManager.getAddress(derivePathParams);\n return this.rpcProvider.requestFaucet(addr);\n }\n\n async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {\n const owner = this.accountManager.getAddress(derivePathParams);\n return this.rpcProvider.getBalance(owner, coinType);\n }\n\n async getObjects(objectIds: string[]) {\n return this.rpcProvider.getObjects(objectIds);\n }\n\n async signTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams) {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signTransactionBlock({ transactionBlock: tx });\n }\n\n async signAndSendTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signAndExecuteTransactionBlock({ transactionBlock: tx, options: {\n showEffects: true,\n showEvents: true,\n showObjectChanges: true,\n }})\n }\n\n /**\n * Transfer the given amount of SUI to the recipient\n * @param recipient\n * @param amount\n * @param derivePathParams\n */\n async transferSui(recipient: string, amount: number, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferSui(recipient, amount);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer to mutliple recipients\n * @param recipients the recipients addresses\n * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients\n * @param derivePathParams\n */\n async transferSuiToMany(recipients: string[], amounts: number[], derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferSuiToMany(recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer the given amounts of coin to multiple recipients\n * @param recipients the list of recipient address\n * @param amounts the amounts to transfer for each recipient\n * @param coinType any custom coin type but not SUI\n * @param derivePathParams the derive path params for the current signer\n */\n async transferCoinToMany(recipients: string[], amounts: number[], coinType: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n const owner = this.accountManager.getAddress(derivePathParams);\n const totalAmount = amounts.reduce((a, b) => a + b, 0);\n const coins = await this.rpcProvider.selectCoins(owner, totalAmount, coinType);\n tx.transferCoinToMany(coins.map(c => c.objectId), owner, recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n \n async transferCoin(recipient: string, amount: number, coinType: string, derivePathParams?: DerivePathParams) {\n return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams)\n }\n \n async transferObjects(objects: string[], recipient: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n \n async moveCall(callParams: {target: string, arguments?: (SuiTxArg | SuiVecTxArg)[], typeArguments?: string[], derivePathParams?: DerivePathParams}) {\n const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;\n const tx = new SuiTxBlock();\n tx.moveCall(target, args, typeArguments);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount\n * @param amount\n * @param coinType\n * @param owner\n */\n async selectCoinsWithAmount(amount: number, coinType: string, owner?: string) {\n owner = owner || this.accountManager.currentAddress;\n const coins = await this.rpcProvider.selectCoins(owner, amount, coinType);\n return coins.map(c => c.objectId)\n }\n\n /**\n * stake the given amount of SUI to the validator\n * @param amount the amount of SUI to stake\n * @param validatorAddr the validator address\n * @param derivePathParams the derive path params for the current signer\n */\n async stakeSui(amount: number, validatorAddr: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.stakeSui(amount, validatorAddr);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.\n * Since the transaction is not submitted, its gas cost is not charged.\n * @param tx the transaction to execute\n * @param derivePathParams the derive path params\n * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.\n */\n async inspectTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.rpcProvider.provider.devInspectTransactionBlock({ transactionBlock: tx, sender: this.getAddress(derivePathParams) })\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js'\nimport { getKeyPair, DerivePathParams } from \"./keypair\";\nimport {hexOrBase64ToUint8Array, normalizePrivateKey} from \"./util\";\nimport { generateMnemonic } from './crypto';\n\ntype AccountMangerParams = {\n mnemonics?: string;\n secretKey?: string;\n}\nexport class SuiAccountManager {\n private mnemonics: string;\n private secretKey: string;\n public currentKeyPair: Ed25519Keypair;\n public currentAddress: string;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n */\n constructor({ mnemonics, secretKey }: AccountMangerParams = {}) {\n // If the mnemonics or secretKey is provided, use it\n // Otherwise, generate a random mnemonics with 24 words\n this.mnemonics = mnemonics || \"\";\n this.secretKey = secretKey || \"\";\n if (!this.mnemonics && !this.secretKey) {\n this.mnemonics = generateMnemonic(24)\n }\n\n // Init the current account\n this.currentKeyPair = this.secretKey\n ? Ed25519Keypair.fromSecretKey(\n normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))\n )\n : getKeyPair(this.mnemonics);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.\n * else:\n * it will generate keyPair from the mnemonic with the given derivePathParams.\n */\n getKeyPair(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentKeyPair;\n return getKeyPair(this.mnemonics, derivePathParams);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.\n * else:\n * it will generate address from the mnemonic with the given derivePathParams.\n */\n getAddress(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentAddress;\n return getKeyPair(this.mnemonics, derivePathParams).getPublicKey().toSuiAddress();\n }\n\n /**\n * Switch the current account with the given derivePathParams.\n * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.\n */\n switchAccount(derivePathParams: DerivePathParams) {\n if (this.mnemonics) {\n this.currentKeyPair = getKeyPair(this.mnemonics, derivePathParams);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js'\n\nexport type DerivePathParams = {\n accountIndex?: number;\n isExternal?: boolean;\n addressIndex?: number;\n}\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (derivePathParams: DerivePathParams = {}) => {\n const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;\n return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;\n}\n\n/**\n * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'\n *\n * accountIndex is the index of the account, default is 0.\n *\n * isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.\n *\n * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.\n *\n * @description Get keypair from mnemonics and derive path\n * @param mnemonics\n * @param derivePathParams\n */\nexport const getKeyPair = (mnemonics: string, derivePathParams: DerivePathParams = {}) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n}\n","import { fromB64 } from '@mysten/sui.js'\n/**\n * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).\n * @param str\n */\nexport const isHex = (str: string) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);\n\n/**\n * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).\n * Note that the \"=\" signs at the end are optional padding characters that may be present in some base64 encoded strings.\n * @param str\n */\nexport const isBase64 = (str: string) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);\n\n/**\n * Convert a hex string to Uint8Array\n * @param hexStr\n */\nexport function fromHEX(hexStr: string): Uint8Array {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array')\n }\n let intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)?.map(byte => parseInt(byte, 16));\n\n if (!intArr || intArr.length === 0) {\n throw new Error(`Unable to parse HEX: ${hexStr}`);\n }\n return Uint8Array.from(intArr);\n}\n\n/**\n * @description Convert a hex or base64 string to Uint8Array\n */\nexport const hexOrBase64ToUint8Array = (str: string): Uint8Array => {\n if (isHex(str)) {\n return fromHEX(str)\n } else if (isBase64(str)) {\n return fromB64(str)\n } else {\n throw new Error('The string is not a valid hex or base64 string.');\n }\n}\n\nconst PRIVATE_KEY_SIZE = 32;\nconst LEGACY_PRIVATE_KEY_SIZE = 64;\n/**\n * normalize a private key\n * A private key is a 32-byte array.\n * But there are two different formats for private keys:\n * 1. A 32-byte array\n * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key\n * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)\n */\nexport const normalizePrivateKey = (key: Uint8Array): Uint8Array => {\n if (key.length === LEGACY_PRIVATE_KEY_SIZE) {\n // This is a legacy secret key, we need to strip the public key bytes and only read the first 32 bytes\n key = key.slice(0, PRIVATE_KEY_SIZE);\n } else if (key.length === PRIVATE_KEY_SIZE + 1 && key[0] === 0) {\n // sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning\n return key.slice(1);\n } else if (key.length === PRIVATE_KEY_SIZE) {\n return key;\n }\n throw new Error('invalid secret key');\n}\n","import { generateMnemonic as genMnemonic } from '@scure/bip39'\nimport { wordlist } from '@scure/bip39/wordlists/english.js'\n\nexport const generateMnemonic = (numberOfWords: 12 | 24 = 24) => {\n const strength = numberOfWords === 12 ? 128 : 256\n return genMnemonic(wordlist, strength)\n}\n","import {\n Connection,\n JsonRpcProvider,\n getObjectType,\n getObjectId,\n getObjectFields,\n getObjectDisplay,\n getObjectVersion,\n DisplayFieldsResponse,\n ObjectContentFields,\n} from \"@mysten/sui.js\";\nimport { requestFaucet } from './faucet'\nimport { NetworkType, getDefaultNetworkParams } from \"./default-chain-configs\";\n\ntype ObjectData = {\n objectId: string;\n objectType: string;\n objectVersion: number;\n objectDisplay: DisplayFieldsResponse;\n objectFields: ObjectContentFields;\n}\n\ntype Params = {\n fullnodeUrl?: string;\n faucetUrl?: string;\n networkType?: NetworkType;\n}\n\nexport class SuiRpcProvider {\n public fullnodeUrl: string;\n public faucetUrl?: string;\n public provider: JsonRpcProvider;\n /**\n *\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type\n */\n constructor({ fullnodeUrl, faucetUrl, networkType }: Params = {}) {\n // Get the default fullnode url and faucet url for the given network type, default is 'testnet'\n const defaultNetworkParams = getDefaultNetworkParams(networkType || 'devnet');\n // Set fullnodeUrl and faucetUrl, if they are not provided, use the default value.\n this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullnode;\n this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;\n\n // Init the provider\n const connection = new Connection({\n fullnode: this.fullnodeUrl,\n faucet: this.faucetUrl,\n });\n this.provider = new JsonRpcProvider(connection);\n }\n\n /**\n * Request some SUI from faucet\n * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.\n */\n async requestFaucet(addr: string) {\n return requestFaucet(addr, this.provider)\n }\n\n async getBalance(addr: string, coinType?: string) {\n return this.provider.getBalance({ owner: addr, coinType });\n }\n\n async getObjects(ids: string[]) {\n const options = { showContent: true, showDisplay: true, showType: true };\n const objects = await this.provider.multiGetObjects({ ids, options });\n const parsedObjects = objects.map((object) => {\n const objectId = getObjectId(object);\n const objectType = getObjectType(object);\n const objectVersion = getObjectVersion(object);\n const objectFields = getObjectFields(object);\n const objectDisplay = getObjectDisplay(object);\n return { objectId, objectType, objectVersion, objectFields, objectDisplay };\n });\n return parsedObjects as ObjectData[]\n }\n\n /**\n * @description Select coins that add up to the given amount.\n * @param addr the address of the owner\n * @param amount the amount that is needed for the coin\n * @param coinType the coin type, default is '0x2::SUI::SUI'\n */\n async selectCoins(addr: string, amount: number, coinType: string = '0x2::SUI::SUI') {\n const coins = await this.provider.getCoins({ owner: addr, coinType });\n let selectedCoins: {objectId: string, digest: string, version: string}[] = [];\n let totalAmount = 0;\n // Sort the coins by balance in descending order\n const coinsData = coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance))\n for(const coinData of coins.data) {\n selectedCoins.push({\n objectId: coinData.coinObjectId,\n digest: coinData.digest,\n version: coinData.version,\n });\n totalAmount = totalAmount + parseInt(coinData.balance);\n if (totalAmount >= amount) {\n break;\n }\n }\n\n if (!selectedCoins.length) {\n throw new Error('No valid coins found for the transaction.');\n }\n return selectedCoins;\n }\n}\n","import {JsonRpcProvider, FaucetRateLimitError, assert, FaucetResponse} from '@mysten/sui.js'\nimport { retry } from 'ts-retry-promise'\n\n/**\n * Request some SUI from faucet\n * @param address\n * @param provider\n * @returns {Promise<boolean>}, return true if the request is successful\n */\nexport const requestFaucet = async (address: string, provider: JsonRpcProvider) => {\n console.log('\\nRequesting SUI from faucet for address: ', address)\n const headers = {\n authority: 'faucet.testnet.sui.io',\n method: 'POST',\n path: '/gas',\n scheme: 'https',\n accept: '*/*',\n 'accept-encoding': 'gzip, deflate, br',\n 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7',\n 'content-length': '105',\n 'content-type': 'application/json',\n 'origin': 'chrome-extension://opcgpfmipidbgpenhmajoajpbobppdil',\n cookie: '_ga=GA1.1.2092533979.1664032306; sui_io_cookie={\"level\":[\"necessary\",\"analytics\"],\"revision\":0,\"data\":null,\"rfc_cookie\":false}; _ga_YKP53WJMB0=GS1.1.1680531285.31.0.1680531334.11.0.0; _ga_0GW4F97GFL=GS1.1.1680826187.125.0.1680826187.60.0.0; __cf_bm=6rPjXUwuzUPy4yDlZuXgDj0v7xLPpUd5z0CFGCoN_YI-1680867579-0-AZMhU7/mKUUbUlOa27LmfW6eIFkBkXsPKqYgWjpjWpj2XzDckgUsRu/pxSRGfvXCspn3w7Df+uO1MR/b+XikJU0=; _cfuvid=zjwCXMmu19KBIVo_L9Qbq4TqFXJpophG3.EvFTxqdf4-1680867579342-0-604800000',\n 'sec-ch-ua': '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"',\n 'sec-ch-ua-mobile': '?0',\n 'sec-ch-ua-platform': \"macOS\",\n 'sec-fetch-dest': 'empty',\n 'sec-fetch-mode': 'cors',\n 'sec-fetch-site': 'none',\n 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',\n }\n // We need to add the following headers to the request, otherwise the request will be rejected by the faucet server\n const resp = await retry<FaucetResponse>(() => provider.requestSuiFromFaucet(address, headers), {\n backoff: 'EXPONENTIAL',\n // overall timeout in 60 seconds\n timeout: 1000 * 60,\n // skip retry if we hit the rate-limit error\n retryIf: (error: any) => !(error instanceof FaucetRateLimitError),\n logger: (msg) => console.warn(`Retry requesting faucet: ${msg}`),\n });\n assert(resp, FaucetResponse, 'Request faucet failed\\n');\n console.log('Request faucet success\\n');\n}\n","import {\n localnetConnection,\n devnetConnection,\n testnetConnection,\n mainnetConnection,\n} from '@mysten/sui.js'\nimport type { Connection } from '@mysten/sui.js'\n\nexport type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';\n\n/**\n * @description Get the default fullnode url and faucet url for the given network type\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @returns { fullNode: string, websocket: string, faucet?: string }\n */\nexport const getDefaultNetworkParams = (networkType: NetworkType = 'devnet'): Connection => {\n switch (networkType) {\n case 'localnet':\n return localnetConnection\n case 'devnet':\n return devnetConnection\n case 'testnet':\n return testnetConnection\n case 'mainnet':\n return mainnetConnection\n default:\n return devnetConnection\n }\n}\n","import {\n TransactionBlock,\n SUI_SYSTEM_STATE_OBJECT_ID,\n normalizeSuiObjectId,\n TransactionArgument,\n} from '@mysten/sui.js'\nimport { SuiInputTypes, getDefaultSuiInputType } from './util'\n\nexport type SuiTxArg = TransactionArgument | string | number | bigint | boolean;\nexport type SuiVecTxArg = { value: SuiTxArg[], vecType: SuiInputTypes } | SuiTxArg[];\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor() {\n this.txBlock = new TransactionBlock();\n }\n\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error('transferSuiToMany: recipients.length !== amounts.length');\n }\n const tx = this.txBlock;\n const coins = tx.splitCoins(tx.gas, amounts.map(amount => tx.pure(amount)));\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n transferObjects(objects: SuiTxArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(this.#convertArgs(objects), tx.pure(recipient));\n return this;\n }\n\n takeAmountFromCoins(coins: SuiTxArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = this.#convertArgs(coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);\n return [sendCoin, mergedCoin];\n }\n\n splitSUIFromGas(amounts: number[]) {\n const tx = this.txBlock;\n return tx.splitCoins(tx.gas, amounts.map(m => tx.pure(m)));\n }\n \n splitCoins(coin: SuiTxArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = this.#convertArgs([coin])[0];\n return tx.splitCoins(coinObject, amounts.map(m => tx.pure(m)));\n }\n \n splitMultiCoins(coins: SuiTxArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = this.#convertArgs(coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(mergedCoin, amounts.map(m => tx.pure(m)));\n return { splitedCoins, mergedCoin }\n }\n \n transferCoinToMany(inputCoins: SuiTxArg[], sender: string, recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error('transferSuiToMany: recipients.length !== amounts.length');\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(inputCoins, amounts);\n recipients.forEach((recipient, index) => {\n tx.transferObjects([splitedCoins[index]], tx.pure(recipient));\n });\n tx.transferObjects([mergedCoin], tx.pure(sender))\n return this;\n }\n \n transferCoin(inputCoins: SuiTxArg[], sender: string, recipient: string, amount: number) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\n }\n \n /**\n * @description Move call\n * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`\n * @param args the arguments of the move call, such as `['0x1', '0x2']`\n * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`\n */\n moveCall(target: string, args: (SuiTxArg | SuiVecTxArg)[] = [], typeArgs: string[] = []) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex = /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;\n const match = target.match(regex);\n if (match === null) throw new Error('Invalid target format. Expected `${string}::${string}::${string}`');\n const convertedArgs = this.#convertArgs(args);\n const tx = this.txBlock;\n return tx.moveCall({\n target: target as `${string}::${string}::${string}`,\n arguments: convertedArgs,\n typeArguments: typeArgs,\n });\n }\n\n stakeSui(amount: number, validatorAddr: string) {\n const tx = this.txBlock;\n const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);\n tx.moveCall({\n target: '0x3::sui_system::request_add_stake',\n arguments: [tx.object(SUI_SYSTEM_STATE_OBJECT_ID), stakeCoin, tx.pure(validatorAddr)],\n });\n return tx;\n }\n\n address(value: string) {\n return this.txBlock.pure(value)\n }\n\n pure(value: any) {\n return this.txBlock.pure(value)\n }\n\n object(value: string) {\n return this.txBlock.object(value)\n }\n\n /**\n * Since we know the elements in the array are the same type\n * If type is not provided, we will try to infer the type from the first element\n * By default,\n *\n * string starting with `0x` =====> object id\n * number, bigint ====> u64\n * boolean =====> bool\n *\n *\n * If type is provided, we will use the type to convert the array\n * @param args\n * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'\n */\n makeMoveVec(args: SuiTxArg[], type?: SuiInputTypes) {\n if (args.length === 0) throw new Error('Transaction builder error: Empty array is not allowed');\n const defaultSuiType = getDefaultSuiInputType(args[0])\n if (type === 'object' || (!type && defaultSuiType === 'object')) {\n const objects = args.map(arg =>\n typeof arg === 'string' ? this.txBlock.object(normalizeSuiObjectId(arg)) : (arg as any)\n );\n return this.txBlock.makeMoveVec({ objects })\n } else {\n const vecType = type || defaultSuiType;\n return this.txBlock.pure(args, `vector<${vecType}>`)\n }\n }\n\n #isMoveVecArg(arg: any) {\n const isFullMoveVecArg = arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n }\n\n #convertArgs(args: any[]): TransactionArgument[] {\n return args.map(arg => {\n if (typeof arg === 'string' && arg.startsWith('0x')) {\n // We always treat string starting with `0x` as object id\n return this.txBlock.object(normalizeSuiObjectId(arg))\n } else if (this.#isMoveVecArg(arg)) {\n // if it's an array arg, we will convert it to move vec\n const vecType = arg.vecType || undefined;\n return vecType\n ? this.makeMoveVec(arg.value, vecType)\n : this.makeMoveVec(arg)\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return this.txBlock.pure(arg)\n } else {\n // We do nothing, because it's most likely already a move value\n return arg\n }\n })\n }\n}\n","/**\n * These are the basics types that can be used in the SUI\n */\nexport type SuiBasicTypes =\n |'address'\n |'bool'\n |'u8'\n | 'u16'\n | 'u32'\n | 'u64'\n | 'u128'\n | 'u256'\n\nexport type SuiInputTypes = 'object' | SuiBasicTypes\n\nexport const getDefaultSuiInputType = (value: any): SuiInputTypes => {\n if (typeof value === 'string' && value.startsWith('0x')) {\n return 'object'\n } else if (typeof value === 'number' || typeof value === 'bigint') {\n return 'u64'\n } else if (typeof value === 'boolean') {\n return 'bool'\n } else {\n return 'object'\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAAkF;;;ACMlF,IAAAC,cAA4F;;;ACN5F,IAAAC,cAA+B;;;ACA/B,iBAA+B;AAWxB,IAAM,sBAAsB,CAAC,mBAAqC,CAAC,MAAM;AAC9E,QAAM,EAAE,eAAe,GAAG,aAAa,OAAO,eAAe,EAAE,IAAI;AACnE,SAAO,cAAc,iBAAiB,aAAa,IAAI,MAAM;AAC/D;AAeO,IAAM,aAAa,CAAC,WAAmB,mBAAqC,CAAC,MAAM;AACxF,QAAM,aAAa,oBAAoB,gBAAgB;AACvD,SAAO,0BAAe,cAAc,WAAW,UAAU;AAC3D;;;AChCA,IAAAC,cAAwB;AAKjB,IAAM,QAAQ,CAAC,QAAgB,kCAAkC,KAAK,GAAG;AAOzE,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K,IAAI,WAAW;AAC1B,OAAG,gBAAgB,SAAS,SAAS;AACrC,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAAA,EAEA,MAAM,SAAS,YAAqI;AAClJ,UAAM,EAAE,QAAQ,WAAW,OAAO,CAAC,GAAG,gBAAgB,CAAC,GAAG,iBAAiB,IAAI;AAC/E,UAAM,KAAK,IAAI,WAAW;AAC1B,OAAG,SAAS,QAAQ,MAAM,aAAa;AACvC,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,sBAAsB,QAAgB,UAAkB,OAAgB;AAC5E,YAAQ,SAAS,KAAK,eAAe;AACrC,UAAM,QAAQ,MAAM,KAAK,YAAY,YAAY,OAAO,QAAQ,QAAQ;AACxE,WAAO,MAAM,IAAI,OAAK,EAAE,QAAQ;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,QAAgB,eAAuB,kBAAqC;AACzF,UAAM,KAAK,IAAI,WAAW;AAC1B,OAAG,SAAS,QAAQ,aAAa;AACjC,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAW,IAAgD,kBAAiE;AAChI,SAAK,cAAc,aAAa,GAAG,UAAU;AAC7C,WAAO,KAAK,YAAY,SAAS,2BAA2B,EAAE,kBAAkB,IAAI,QAAQ,KAAK,WAAW,gBAAgB,EAAE,CAAC;AAAA,EACjI;AACF;","names":["import_sui","import_sui","import_sui","import_sui","genMnemonic","import_sui","import_sui","import_sui","import_sui"]}
package/dist/index.mjs CHANGED
@@ -179,36 +179,24 @@ var requestFaucet = async (address, provider) => {
179
179
  };
180
180
 
181
181
  // src/lib/sui-rpc-provider/default-chain-configs.ts
182
- var DEFAULT_LOCALHOST_FULLNODE = "http://0.0.0.0:9000";
183
- var DEFAULT_LOCALHOST_FAUCET = "";
184
- var DEFAULT_DEVNET_FULLNODE = "https://fullnode.devnet.sui.io:443";
185
- var DEFAULT_DEVNET_FAUCET = "https://faucet.devnet.sui.io/gas";
186
- var DEFAULT_TESTNET_FULLNODE = "https://fullnode.testnet.sui.io:443";
187
- var DEFAULT_TESTNET_FAUCET = "https://faucet.testnet.sui.io/gas";
188
- var DEFAULT_MAINNET_FULLNODE = "https://fullnode.mainnet.sui.io:443";
189
- var DEFAULT_MAINNET_FAUCET = "";
182
+ import {
183
+ localnetConnection,
184
+ devnetConnection,
185
+ testnetConnection,
186
+ mainnetConnection
187
+ } from "@mysten/sui.js";
190
188
  var getDefaultNetworkParams = (networkType = "devnet") => {
191
189
  switch (networkType) {
192
- case "localhost":
193
- return {
194
- fullNode: DEFAULT_LOCALHOST_FULLNODE,
195
- faucet: DEFAULT_LOCALHOST_FAUCET
196
- };
190
+ case "localnet":
191
+ return localnetConnection;
192
+ case "devnet":
193
+ return devnetConnection;
197
194
  case "testnet":
198
- return {
199
- fullNode: DEFAULT_TESTNET_FULLNODE,
200
- faucet: DEFAULT_TESTNET_FAUCET
201
- };
195
+ return testnetConnection;
202
196
  case "mainnet":
203
- return {
204
- fullNode: DEFAULT_MAINNET_FULLNODE,
205
- faucet: DEFAULT_MAINNET_FAUCET
206
- };
197
+ return mainnetConnection;
207
198
  default:
208
- return {
209
- fullNode: DEFAULT_DEVNET_FULLNODE,
210
- faucet: DEFAULT_DEVNET_FAUCET
211
- };
199
+ return devnetConnection;
212
200
  }
213
201
  };
214
202
 
@@ -216,13 +204,13 @@ var getDefaultNetworkParams = (networkType = "devnet") => {
216
204
  var SuiRpcProvider = class {
217
205
  /**
218
206
  *
219
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
207
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
220
208
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
221
209
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
222
210
  */
223
211
  constructor({ fullnodeUrl, faucetUrl, networkType } = {}) {
224
212
  const defaultNetworkParams = getDefaultNetworkParams(networkType || "devnet");
225
- this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullNode;
213
+ this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullnode;
226
214
  this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;
227
215
  const connection = new Connection({
228
216
  fullnode: this.fullnodeUrl,
@@ -471,7 +459,7 @@ var SuiKit = class {
471
459
  *
472
460
  * @param mnemonics, 12 or 24 mnemonics words, separated by space
473
461
  * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
474
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
462
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
475
463
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
476
464
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
477
465
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/sui-kit.ts","../src/lib/sui-account-manager/sui-account-manager.ts","../src/lib/sui-account-manager/keypair.ts","../src/lib/sui-account-manager/util.ts","../src/lib/sui-account-manager/crypto.ts","../src/lib/sui-rpc-provider/sui-rpc-provider.ts","../src/lib/sui-rpc-provider/faucet.ts","../src/lib/sui-rpc-provider/default-chain-configs.ts","../src/lib/sui-tx-builder/sui-tx-block.ts","../src/lib/sui-tx-builder/util.ts"],"sourcesContent":["export { TransactionBlock, SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui.js'\nexport { SuiKit } from './lib/sui-kit'\nexport type { SuiKitParams } from './lib/sui-kit'\nexport { SuiAccountManager } from './lib/sui-account-manager'\nexport type { DerivePathParams } from './lib/sui-account-manager'\nexport { SuiTxBlock } from './lib/sui-tx-builder'\nexport type { SuiTxArg } from './lib/sui-tx-builder'\n\nexport { SuiRpcProvider } from './lib/sui-rpc-provider'\nexport type { NetworkType } from './lib/sui-rpc-provider'\n","/**\n * @file src.ts\n * @description This file is used to aggregate the tools that used to interact with SUI network.\n * @author IceFox\n * @version 0.1.0\n */\nimport { RawSigner, TransactionBlock, DevInspectResults, SuiTransactionBlockResponse } from '@mysten/sui.js';\nimport { SuiAccountManager, DerivePathParams } from \"./sui-account-manager\";\nimport { SuiRpcProvider, NetworkType } from './sui-rpc-provider';\nimport { SuiTxBlock, SuiTxArg, SuiVecTxArg } from \"./sui-tx-builder\";\n\nexport type SuiKitParams = {\n mnemonics?: string;\n secretKey?: string;\n fullnodeUrl?: string;\n faucetUrl?: string;\n networkType?: NetworkType;\n}\n/**\n * @class SuiKit\n * @description This class is used to aggregate the tools that used to interact with SUI network.\n */\nexport class SuiKit {\n\n public accountManager: SuiAccountManager;\n public rpcProvider: SuiRpcProvider;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type\n */\n constructor({ mnemonics, secretKey, networkType, fullnodeUrl, faucetUrl }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n this.rpcProvider = new SuiRpcProvider({ fullnodeUrl, faucetUrl, networkType });\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.\n * else:\n * it will generate signer from the mnemonic with the given derivePathParams.\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getSigner(derivePathParams?: DerivePathParams) {\n const keyPair = this.accountManager.getKeyPair(derivePathParams);\n return new RawSigner(keyPair, this.rpcProvider.provider);\n }\n\n /**\n * @description Switch the current account with the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n switchAccount(derivePathParams: DerivePathParams) {\n this.accountManager.switchAccount(derivePathParams);\n }\n\n /**\n * @description Get the address of the account for the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getAddress(derivePathParams?: DerivePathParams) {\n return this.accountManager.getAddress(derivePathParams);\n }\n currentAddress() { return this.accountManager.currentAddress }\n \n provider() { return this.rpcProvider.provider }\n\n /**\n * Request some SUI from faucet\n * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.\n */\n async requestFaucet(derivePathParams?: DerivePathParams) {\n const addr = this.accountManager.getAddress(derivePathParams);\n return this.rpcProvider.requestFaucet(addr);\n }\n\n async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {\n const owner = this.accountManager.getAddress(derivePathParams);\n return this.rpcProvider.getBalance(owner, coinType);\n }\n\n async getObjects(objectIds: string[]) {\n return this.rpcProvider.getObjects(objectIds);\n }\n\n async signTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams) {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signTransactionBlock({ transactionBlock: tx });\n }\n\n async signAndSendTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signAndExecuteTransactionBlock({ transactionBlock: tx, options: {\n showEffects: true,\n showEvents: true,\n showObjectChanges: true,\n }})\n }\n\n /**\n * Transfer the given amount of SUI to the recipient\n * @param recipient\n * @param amount\n * @param derivePathParams\n */\n async transferSui(recipient: string, amount: number, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferSui(recipient, amount);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer to mutliple recipients\n * @param recipients the recipients addresses\n * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients\n * @param derivePathParams\n */\n async transferSuiToMany(recipients: string[], amounts: number[], derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferSuiToMany(recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer the given amounts of coin to multiple recipients\n * @param recipients the list of recipient address\n * @param amounts the amounts to transfer for each recipient\n * @param coinType any custom coin type but not SUI\n * @param derivePathParams the derive path params for the current signer\n */\n async transferCoinToMany(recipients: string[], amounts: number[], coinType: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n const owner = this.accountManager.getAddress(derivePathParams);\n const totalAmount = amounts.reduce((a, b) => a + b, 0);\n const coins = await this.rpcProvider.selectCoins(owner, totalAmount, coinType);\n tx.transferCoinToMany(coins.map(c => c.objectId), owner, recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n \n async transferCoin(recipient: string, amount: number, coinType: string, derivePathParams?: DerivePathParams) {\n return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams)\n }\n \n async transferObjects(objects: string[], recipient: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n \n async moveCall(callParams: {target: string, arguments?: (SuiTxArg | SuiVecTxArg)[], typeArguments?: string[], derivePathParams?: DerivePathParams}) {\n const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;\n const tx = new SuiTxBlock();\n tx.moveCall(target, args, typeArguments);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount\n * @param amount\n * @param coinType\n * @param owner\n */\n async selectCoinsWithAmount(amount: number, coinType: string, owner?: string) {\n owner = owner || this.accountManager.currentAddress;\n const coins = await this.rpcProvider.selectCoins(owner, amount, coinType);\n return coins.map(c => c.objectId)\n }\n\n /**\n * stake the given amount of SUI to the validator\n * @param amount the amount of SUI to stake\n * @param validatorAddr the validator address\n * @param derivePathParams the derive path params for the current signer\n */\n async stakeSui(amount: number, validatorAddr: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.stakeSui(amount, validatorAddr);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.\n * Since the transaction is not submitted, its gas cost is not charged.\n * @param tx the transaction to execute\n * @param derivePathParams the derive path params\n * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.\n */\n async inspectTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.rpcProvider.provider.devInspectTransactionBlock({ transactionBlock: tx, sender: this.getAddress(derivePathParams) })\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js'\nimport { getKeyPair, DerivePathParams } from \"./keypair\";\nimport {hexOrBase64ToUint8Array, normalizePrivateKey} from \"./util\";\nimport { generateMnemonic } from './crypto';\n\ntype AccountMangerParams = {\n mnemonics?: string;\n secretKey?: string;\n}\nexport class SuiAccountManager {\n private mnemonics: string;\n private secretKey: string;\n public currentKeyPair: Ed25519Keypair;\n public currentAddress: string;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n */\n constructor({ mnemonics, secretKey }: AccountMangerParams = {}) {\n // If the mnemonics or secretKey is provided, use it\n // Otherwise, generate a random mnemonics with 24 words\n this.mnemonics = mnemonics || \"\";\n this.secretKey = secretKey || \"\";\n if (!this.mnemonics && !this.secretKey) {\n this.mnemonics = generateMnemonic(24)\n }\n\n // Init the current account\n this.currentKeyPair = this.secretKey\n ? Ed25519Keypair.fromSecretKey(\n normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))\n )\n : getKeyPair(this.mnemonics);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.\n * else:\n * it will generate keyPair from the mnemonic with the given derivePathParams.\n */\n getKeyPair(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentKeyPair;\n return getKeyPair(this.mnemonics, derivePathParams);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.\n * else:\n * it will generate address from the mnemonic with the given derivePathParams.\n */\n getAddress(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentAddress;\n return getKeyPair(this.mnemonics, derivePathParams).getPublicKey().toSuiAddress();\n }\n\n /**\n * Switch the current account with the given derivePathParams.\n * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.\n */\n switchAccount(derivePathParams: DerivePathParams) {\n if (this.mnemonics) {\n this.currentKeyPair = getKeyPair(this.mnemonics, derivePathParams);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js'\n\nexport type DerivePathParams = {\n accountIndex?: number;\n isExternal?: boolean;\n addressIndex?: number;\n}\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (derivePathParams: DerivePathParams = {}) => {\n const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;\n return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;\n}\n\n/**\n * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'\n *\n * accountIndex is the index of the account, default is 0.\n *\n * isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.\n *\n * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.\n *\n * @description Get keypair from mnemonics and derive path\n * @param mnemonics\n * @param derivePathParams\n */\nexport const getKeyPair = (mnemonics: string, derivePathParams: DerivePathParams = {}) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n}\n","import { fromB64 } from '@mysten/sui.js'\n/**\n * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).\n * @param str\n */\nexport const isHex = (str: string) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);\n\n/**\n * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).\n * Note that the \"=\" signs at the end are optional padding characters that may be present in some base64 encoded strings.\n * @param str\n */\nexport const isBase64 = (str: string) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);\n\n/**\n * Convert a hex string to Uint8Array\n * @param hexStr\n */\nexport function fromHEX(hexStr: string): Uint8Array {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array')\n }\n let intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)?.map(byte => parseInt(byte, 16));\n\n if (!intArr || intArr.length === 0) {\n throw new Error(`Unable to parse HEX: ${hexStr}`);\n }\n return Uint8Array.from(intArr);\n}\n\n/**\n * @description Convert a hex or base64 string to Uint8Array\n */\nexport const hexOrBase64ToUint8Array = (str: string): Uint8Array => {\n if (isHex(str)) {\n return fromHEX(str)\n } else if (isBase64(str)) {\n return fromB64(str)\n } else {\n throw new Error('The string is not a valid hex or base64 string.');\n }\n}\n\nconst PRIVATE_KEY_SIZE = 32;\nconst LEGACY_PRIVATE_KEY_SIZE = 64;\n/**\n * normalize a private key\n * A private key is a 32-byte array.\n * But there are two different formats for private keys:\n * 1. A 32-byte array\n * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key\n * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)\n */\nexport const normalizePrivateKey = (key: Uint8Array): Uint8Array => {\n if (key.length === LEGACY_PRIVATE_KEY_SIZE) {\n // This is a legacy secret key, we need to strip the public key bytes and only read the first 32 bytes\n key = key.slice(0, PRIVATE_KEY_SIZE);\n } else if (key.length === PRIVATE_KEY_SIZE + 1 && key[0] === 0) {\n // sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning\n return key.slice(1);\n } else if (key.length === PRIVATE_KEY_SIZE) {\n return key;\n }\n throw new Error('invalid secret key');\n}\n","import { generateMnemonic as genMnemonic } from '@scure/bip39'\nimport { wordlist } from '@scure/bip39/wordlists/english.js'\n\nexport const generateMnemonic = (numberOfWords: 12 | 24 = 24) => {\n const strength = numberOfWords === 12 ? 128 : 256\n return genMnemonic(wordlist, strength)\n}\n","import {\n Connection,\n JsonRpcProvider,\n getObjectType,\n getObjectId,\n getObjectFields,\n getObjectDisplay,\n getObjectVersion,\n DisplayFieldsResponse,\n ObjectContentFields,\n} from \"@mysten/sui.js\";\nimport { requestFaucet } from './faucet'\nimport { NetworkType, getDefaultNetworkParams } from \"./default-chain-configs\";\n\ntype ObjectData = {\n objectId: string;\n objectType: string;\n objectVersion: number;\n objectDisplay: DisplayFieldsResponse;\n objectFields: ObjectContentFields;\n}\n\ntype Params = {\n fullnodeUrl?: string;\n faucetUrl?: string;\n networkType?: NetworkType;\n}\n\nexport class SuiRpcProvider {\n public fullnodeUrl: string;\n public faucetUrl: string;\n public provider: JsonRpcProvider;\n /**\n *\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type\n */\n constructor({ fullnodeUrl, faucetUrl, networkType }: Params = {}) {\n // Get the default fullnode url and faucet url for the given network type, default is 'testnet'\n const defaultNetworkParams = getDefaultNetworkParams(networkType || 'devnet');\n // Set fullnodeUrl and faucetUrl, if they are not provided, use the default value.\n this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullNode;\n this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;\n\n // Init the provider\n const connection = new Connection({\n fullnode: this.fullnodeUrl,\n faucet: this.faucetUrl,\n });\n this.provider = new JsonRpcProvider(connection);\n }\n\n /**\n * Request some SUI from faucet\n * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.\n */\n async requestFaucet(addr: string) {\n return requestFaucet(addr, this.provider)\n }\n\n async getBalance(addr: string, coinType?: string) {\n return this.provider.getBalance({ owner: addr, coinType });\n }\n\n async getObjects(ids: string[]) {\n const options = { showContent: true, showDisplay: true, showType: true };\n const objects = await this.provider.multiGetObjects({ ids, options });\n const parsedObjects = objects.map((object) => {\n const objectId = getObjectId(object);\n const objectType = getObjectType(object);\n const objectVersion = getObjectVersion(object);\n const objectFields = getObjectFields(object);\n const objectDisplay = getObjectDisplay(object);\n return { objectId, objectType, objectVersion, objectFields, objectDisplay };\n });\n return parsedObjects as ObjectData[]\n }\n\n /**\n * @description Select coins that add up to the given amount.\n * @param addr the address of the owner\n * @param amount the amount that is needed for the coin\n * @param coinType the coin type, default is '0x2::SUI::SUI'\n */\n async selectCoins(addr: string, amount: number, coinType: string = '0x2::SUI::SUI') {\n const coins = await this.provider.getCoins({ owner: addr, coinType });\n let selectedCoins: {objectId: string, digest: string, version: string}[] = [];\n let totalAmount = 0;\n // Sort the coins by balance in descending order\n const coinsData = coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance))\n for(const coinData of coins.data) {\n selectedCoins.push({\n objectId: coinData.coinObjectId,\n digest: coinData.digest,\n version: coinData.version,\n });\n totalAmount = totalAmount + parseInt(coinData.balance);\n if (totalAmount >= amount) {\n break;\n }\n }\n\n if (!selectedCoins.length) {\n throw new Error('No valid coins found for the transaction.');\n }\n return selectedCoins;\n }\n}\n","import {JsonRpcProvider, FaucetRateLimitError, assert, FaucetResponse} from '@mysten/sui.js'\nimport { retry } from 'ts-retry-promise'\n\n/**\n * Request some SUI from faucet\n * @param address\n * @param provider\n * @returns {Promise<boolean>}, return true if the request is successful\n */\nexport const requestFaucet = async (address: string, provider: JsonRpcProvider) => {\n console.log('\\nRequesting SUI from faucet for address: ', address)\n const headers = {\n authority: 'faucet.testnet.sui.io',\n method: 'POST',\n path: '/gas',\n scheme: 'https',\n accept: '*/*',\n 'accept-encoding': 'gzip, deflate, br',\n 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7',\n 'content-length': '105',\n 'content-type': 'application/json',\n 'origin': 'chrome-extension://opcgpfmipidbgpenhmajoajpbobppdil',\n cookie: '_ga=GA1.1.2092533979.1664032306; sui_io_cookie={\"level\":[\"necessary\",\"analytics\"],\"revision\":0,\"data\":null,\"rfc_cookie\":false}; _ga_YKP53WJMB0=GS1.1.1680531285.31.0.1680531334.11.0.0; _ga_0GW4F97GFL=GS1.1.1680826187.125.0.1680826187.60.0.0; __cf_bm=6rPjXUwuzUPy4yDlZuXgDj0v7xLPpUd5z0CFGCoN_YI-1680867579-0-AZMhU7/mKUUbUlOa27LmfW6eIFkBkXsPKqYgWjpjWpj2XzDckgUsRu/pxSRGfvXCspn3w7Df+uO1MR/b+XikJU0=; _cfuvid=zjwCXMmu19KBIVo_L9Qbq4TqFXJpophG3.EvFTxqdf4-1680867579342-0-604800000',\n 'sec-ch-ua': '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"',\n 'sec-ch-ua-mobile': '?0',\n 'sec-ch-ua-platform': \"macOS\",\n 'sec-fetch-dest': 'empty',\n 'sec-fetch-mode': 'cors',\n 'sec-fetch-site': 'none',\n 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',\n }\n // We need to add the following headers to the request, otherwise the request will be rejected by the faucet server\n const resp = await retry<FaucetResponse>(() => provider.requestSuiFromFaucet(address, headers), {\n backoff: 'EXPONENTIAL',\n // overall timeout in 60 seconds\n timeout: 1000 * 60,\n // skip retry if we hit the rate-limit error\n retryIf: (error: any) => !(error instanceof FaucetRateLimitError),\n logger: (msg) => console.warn(`Retry requesting faucet: ${msg}`),\n });\n assert(resp, FaucetResponse, 'Request faucet failed\\n');\n console.log('Request faucet success\\n');\n}\n","/**\n * @description This file is used to store the default chain parameters for the different networks.\n * @author IceFox@Scallop\n */\n// For localhost\nexport const DEFAULT_LOCALHOST_FULLNODE = \"http://0.0.0.0:9000\"\nexport const DEFAULT_LOCALHOST_FAUCET = \"\"\n\n// For devnet\nexport const DEFAULT_DEVNET_FULLNODE =\"https://fullnode.devnet.sui.io:443\"\nexport const DEFAULT_DEVNET_FAUCET = \"https://faucet.devnet.sui.io/gas\"\n\n// For testnet\nexport const DEFAULT_TESTNET_FULLNODE = \"https://fullnode.testnet.sui.io:443\"\nexport const DEFAULT_TESTNET_FAUCET = \"https://faucet.testnet.sui.io/gas\"\n\n// For mainnet\nexport const DEFAULT_MAINNET_FULLNODE = \"https://fullnode.mainnet.sui.io:443\"\nexport const DEFAULT_MAINNET_FAUCET = \"\"\n\n\nexport type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localhost';\n\n/**\n * @description Get the default fullnode url and faucet url for the given network type\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'\n * @returns { fullNode: string, faucet: string }\n */\nexport const getDefaultNetworkParams = (networkType: NetworkType = 'devnet'): { fullNode: string, faucet: string } => {\n switch (networkType) {\n case 'localhost':\n return {\n fullNode: DEFAULT_LOCALHOST_FULLNODE,\n faucet: DEFAULT_LOCALHOST_FAUCET,\n }\n case 'testnet':\n return {\n fullNode: DEFAULT_TESTNET_FULLNODE,\n faucet: DEFAULT_TESTNET_FAUCET,\n }\n case 'mainnet':\n return {\n fullNode: DEFAULT_MAINNET_FULLNODE,\n faucet: DEFAULT_MAINNET_FAUCET,\n }\n default:\n return {\n fullNode: DEFAULT_DEVNET_FULLNODE,\n faucet: DEFAULT_DEVNET_FAUCET,\n }\n }\n}\n","import {\n TransactionBlock,\n SUI_SYSTEM_STATE_OBJECT_ID,\n normalizeSuiObjectId,\n TransactionArgument,\n} from '@mysten/sui.js'\nimport { SuiInputTypes, getDefaultSuiInputType } from './util'\n\nexport type SuiTxArg = TransactionArgument | string | number | bigint | boolean;\nexport type SuiVecTxArg = { value: SuiTxArg[], vecType: SuiInputTypes } | SuiTxArg[];\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor() {\n this.txBlock = new TransactionBlock();\n }\n\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error('transferSuiToMany: recipients.length !== amounts.length');\n }\n const tx = this.txBlock;\n const coins = tx.splitCoins(tx.gas, amounts.map(amount => tx.pure(amount)));\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n transferObjects(objects: SuiTxArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(this.#convertArgs(objects), tx.pure(recipient));\n return this;\n }\n\n takeAmountFromCoins(coins: SuiTxArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = this.#convertArgs(coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);\n return [sendCoin, mergedCoin];\n }\n\n splitSUIFromGas(amounts: number[]) {\n const tx = this.txBlock;\n return tx.splitCoins(tx.gas, amounts.map(m => tx.pure(m)));\n }\n \n splitCoins(coin: SuiTxArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = this.#convertArgs([coin])[0];\n return tx.splitCoins(coinObject, amounts.map(m => tx.pure(m)));\n }\n \n splitMultiCoins(coins: SuiTxArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = this.#convertArgs(coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(mergedCoin, amounts.map(m => tx.pure(m)));\n return { splitedCoins, mergedCoin }\n }\n \n transferCoinToMany(inputCoins: SuiTxArg[], sender: string, recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error('transferSuiToMany: recipients.length !== amounts.length');\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(inputCoins, amounts);\n recipients.forEach((recipient, index) => {\n tx.transferObjects([splitedCoins[index]], tx.pure(recipient));\n });\n tx.transferObjects([mergedCoin], tx.pure(sender))\n return this;\n }\n \n transferCoin(inputCoins: SuiTxArg[], sender: string, recipient: string, amount: number) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\n }\n \n /**\n * @description Move call\n * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`\n * @param args the arguments of the move call, such as `['0x1', '0x2']`\n * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`\n */\n moveCall(target: string, args: (SuiTxArg | SuiVecTxArg)[] = [], typeArgs: string[] = []) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex = /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;\n const match = target.match(regex);\n if (match === null) throw new Error('Invalid target format. Expected `${string}::${string}::${string}`');\n const convertedArgs = this.#convertArgs(args);\n const tx = this.txBlock;\n return tx.moveCall({\n target: target as `${string}::${string}::${string}`,\n arguments: convertedArgs,\n typeArguments: typeArgs,\n });\n }\n\n stakeSui(amount: number, validatorAddr: string) {\n const tx = this.txBlock;\n const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);\n tx.moveCall({\n target: '0x3::sui_system::request_add_stake',\n arguments: [tx.object(SUI_SYSTEM_STATE_OBJECT_ID), stakeCoin, tx.pure(validatorAddr)],\n });\n return tx;\n }\n\n address(value: string) {\n return this.txBlock.pure(value)\n }\n\n pure(value: any) {\n return this.txBlock.pure(value)\n }\n\n object(value: string) {\n return this.txBlock.object(value)\n }\n\n /**\n * Since we know the elements in the array are the same type\n * If type is not provided, we will try to infer the type from the first element\n * By default,\n *\n * string starting with `0x` =====> object id\n * number, bigint ====> u64\n * boolean =====> bool\n *\n *\n * If type is provided, we will use the type to convert the array\n * @param args\n * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'\n */\n makeMoveVec(args: SuiTxArg[], type?: SuiInputTypes) {\n if (args.length === 0) throw new Error('Transaction builder error: Empty array is not allowed');\n const defaultSuiType = getDefaultSuiInputType(args[0])\n if (type === 'object' || (!type && defaultSuiType === 'object')) {\n const objects = args.map(arg =>\n typeof arg === 'string' ? this.txBlock.object(normalizeSuiObjectId(arg)) : (arg as any)\n );\n return this.txBlock.makeMoveVec({ objects })\n } else {\n const vecType = type || defaultSuiType;\n return this.txBlock.pure(args, `vector<${vecType}>`)\n }\n }\n\n #isMoveVecArg(arg: any) {\n const isFullMoveVecArg = arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n }\n\n #convertArgs(args: any[]): TransactionArgument[] {\n return args.map(arg => {\n if (typeof arg === 'string' && arg.startsWith('0x')) {\n // We always treat string starting with `0x` as object id\n return this.txBlock.object(normalizeSuiObjectId(arg))\n } else if (this.#isMoveVecArg(arg)) {\n // if it's an array arg, we will convert it to move vec\n const vecType = arg.vecType || undefined;\n return vecType\n ? this.makeMoveVec(arg.value, vecType)\n : this.makeMoveVec(arg)\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return this.txBlock.pure(arg)\n } else {\n // We do nothing, because it's most likely already a move value\n return arg\n }\n })\n }\n}\n","/**\n * These are the basics types that can be used in the SUI\n */\nexport type SuiBasicTypes =\n |'address'\n |'bool'\n |'u8'\n | 'u16'\n | 'u32'\n | 'u64'\n | 'u128'\n | 'u256'\n\nexport type SuiInputTypes = 'object' | SuiBasicTypes\n\nexport const getDefaultSuiInputType = (value: any): SuiInputTypes => {\n if (typeof value === 'string' && value.startsWith('0x')) {\n return 'object'\n } else if (typeof value === 'number' || typeof value === 'bigint') {\n return 'u64'\n } else if (typeof value === 'boolean') {\n return 'bool'\n } else {\n return 'object'\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,oBAAAA,mBAAkB,qBAAqB,8BAAAC,mCAAkC;;;ACMlF,SAAS,iBAAmF;;;ACN5F,SAAS,kBAAAC,uBAAsB;;;ACA/B,SAAS,sBAAsB;AAWxB,IAAM,sBAAsB,CAAC,mBAAqC,CAAC,MAAM;AAC9E,QAAM,EAAE,eAAe,GAAG,aAAa,OAAO,eAAe,EAAE,IAAI;AACnE,SAAO,cAAc,iBAAiB,aAAa,IAAI,MAAM;AAC/D;AAeO,IAAM,aAAa,CAAC,WAAmB,mBAAqC,CAAC,MAAM;AACxF,QAAM,aAAa,oBAAoB,gBAAgB;AACvD,SAAO,eAAe,cAAc,WAAW,UAAU;AAC3D;;;AChCA,SAAS,eAAe;AAKjB,IAAM,QAAQ,CAAC,QAAgB,kCAAkC,KAAK,GAAG;AAOzE,IAAM,WAAW,CAAC,QAAgB,0BAA0B,KAAK,GAAG;AAMpE,SAAS,QAAQ,QAA4B;AAClD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,MAAI,SAAS,OACV,QAAQ,MAAM,EAAE,EACh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E,CAAC;AAAA,EACjI;AACF;","names":["TransactionBlock","SUI_SYSTEM_STATE_OBJECT_ID","Ed25519Keypair","Ed25519Keypair","JsonRpcProvider","JsonRpcProvider"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/sui-kit.ts","../src/lib/sui-account-manager/sui-account-manager.ts","../src/lib/sui-account-manager/keypair.ts","../src/lib/sui-account-manager/util.ts","../src/lib/sui-account-manager/crypto.ts","../src/lib/sui-rpc-provider/sui-rpc-provider.ts","../src/lib/sui-rpc-provider/faucet.ts","../src/lib/sui-rpc-provider/default-chain-configs.ts","../src/lib/sui-tx-builder/sui-tx-block.ts","../src/lib/sui-tx-builder/util.ts"],"sourcesContent":["export { TransactionBlock, SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui.js'\nexport { SuiKit } from './lib/sui-kit'\nexport type { SuiKitParams } from './lib/sui-kit'\nexport { SuiAccountManager } from './lib/sui-account-manager'\nexport type { DerivePathParams } from './lib/sui-account-manager'\nexport { SuiTxBlock } from './lib/sui-tx-builder'\nexport type { SuiTxArg } from './lib/sui-tx-builder'\n\nexport { SuiRpcProvider } from './lib/sui-rpc-provider'\nexport type { NetworkType } from './lib/sui-rpc-provider'\n","/**\n * @file src.ts\n * @description This file is used to aggregate the tools that used to interact with SUI network.\n * @author IceFox\n * @version 0.1.0\n */\nimport { RawSigner, TransactionBlock, DevInspectResults, SuiTransactionBlockResponse } from '@mysten/sui.js';\nimport { SuiAccountManager, DerivePathParams } from \"./sui-account-manager\";\nimport { SuiRpcProvider, NetworkType } from './sui-rpc-provider';\nimport { SuiTxBlock, SuiTxArg, SuiVecTxArg } from \"./sui-tx-builder\";\n\nexport type SuiKitParams = {\n mnemonics?: string;\n secretKey?: string;\n fullnodeUrl?: string;\n faucetUrl?: string;\n networkType?: NetworkType;\n}\n/**\n * @class SuiKit\n * @description This class is used to aggregate the tools that used to interact with SUI network.\n */\nexport class SuiKit {\n\n public accountManager: SuiAccountManager;\n public rpcProvider: SuiRpcProvider;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type\n */\n constructor({ mnemonics, secretKey, networkType, fullnodeUrl, faucetUrl }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n this.rpcProvider = new SuiRpcProvider({ fullnodeUrl, faucetUrl, networkType });\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.\n * else:\n * it will generate signer from the mnemonic with the given derivePathParams.\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getSigner(derivePathParams?: DerivePathParams) {\n const keyPair = this.accountManager.getKeyPair(derivePathParams);\n return new RawSigner(keyPair, this.rpcProvider.provider);\n }\n\n /**\n * @description Switch the current account with the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n switchAccount(derivePathParams: DerivePathParams) {\n this.accountManager.switchAccount(derivePathParams);\n }\n\n /**\n * @description Get the address of the account for the given derivePathParams\n * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard\n */\n getAddress(derivePathParams?: DerivePathParams) {\n return this.accountManager.getAddress(derivePathParams);\n }\n currentAddress() { return this.accountManager.currentAddress }\n \n provider() { return this.rpcProvider.provider }\n\n /**\n * Request some SUI from faucet\n * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.\n */\n async requestFaucet(derivePathParams?: DerivePathParams) {\n const addr = this.accountManager.getAddress(derivePathParams);\n return this.rpcProvider.requestFaucet(addr);\n }\n\n async getBalance(coinType?: string, derivePathParams?: DerivePathParams) {\n const owner = this.accountManager.getAddress(derivePathParams);\n return this.rpcProvider.getBalance(owner, coinType);\n }\n\n async getObjects(objectIds: string[]) {\n return this.rpcProvider.getObjects(objectIds);\n }\n\n async signTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams) {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signTransactionBlock({ transactionBlock: tx });\n }\n\n async signAndSendTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signAndExecuteTransactionBlock({ transactionBlock: tx, options: {\n showEffects: true,\n showEvents: true,\n showObjectChanges: true,\n }})\n }\n\n /**\n * Transfer the given amount of SUI to the recipient\n * @param recipient\n * @param amount\n * @param derivePathParams\n */\n async transferSui(recipient: string, amount: number, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferSui(recipient, amount);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer to mutliple recipients\n * @param recipients the recipients addresses\n * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients\n * @param derivePathParams\n */\n async transferSuiToMany(recipients: string[], amounts: number[], derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferSuiToMany(recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Transfer the given amounts of coin to multiple recipients\n * @param recipients the list of recipient address\n * @param amounts the amounts to transfer for each recipient\n * @param coinType any custom coin type but not SUI\n * @param derivePathParams the derive path params for the current signer\n */\n async transferCoinToMany(recipients: string[], amounts: number[], coinType: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n const owner = this.accountManager.getAddress(derivePathParams);\n const totalAmount = amounts.reduce((a, b) => a + b, 0);\n const coins = await this.rpcProvider.selectCoins(owner, totalAmount, coinType);\n tx.transferCoinToMany(coins.map(c => c.objectId), owner, recipients, amounts);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n \n async transferCoin(recipient: string, amount: number, coinType: string, derivePathParams?: DerivePathParams) {\n return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams)\n }\n \n async transferObjects(objects: string[], recipient: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n \n async moveCall(callParams: {target: string, arguments?: (SuiTxArg | SuiVecTxArg)[], typeArguments?: string[], derivePathParams?: DerivePathParams}) {\n const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;\n const tx = new SuiTxBlock();\n tx.moveCall(target, args, typeArguments);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount\n * @param amount\n * @param coinType\n * @param owner\n */\n async selectCoinsWithAmount(amount: number, coinType: string, owner?: string) {\n owner = owner || this.accountManager.currentAddress;\n const coins = await this.rpcProvider.selectCoins(owner, amount, coinType);\n return coins.map(c => c.objectId)\n }\n\n /**\n * stake the given amount of SUI to the validator\n * @param amount the amount of SUI to stake\n * @param validatorAddr the validator address\n * @param derivePathParams the derive path params for the current signer\n */\n async stakeSui(amount: number, validatorAddr: string, derivePathParams?: DerivePathParams) {\n const tx = new SuiTxBlock();\n tx.stakeSui(amount, validatorAddr);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n /**\n * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.\n * Since the transaction is not submitted, its gas cost is not charged.\n * @param tx the transaction to execute\n * @param derivePathParams the derive path params\n * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.\n */\n async inspectTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.rpcProvider.provider.devInspectTransactionBlock({ transactionBlock: tx, sender: this.getAddress(derivePathParams) })\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js'\nimport { getKeyPair, DerivePathParams } from \"./keypair\";\nimport {hexOrBase64ToUint8Array, normalizePrivateKey} from \"./util\";\nimport { generateMnemonic } from './crypto';\n\ntype AccountMangerParams = {\n mnemonics?: string;\n secretKey?: string;\n}\nexport class SuiAccountManager {\n private mnemonics: string;\n private secretKey: string;\n public currentKeyPair: Ed25519Keypair;\n public currentAddress: string;\n\n /**\n * Support the following ways to init the SuiToolkit:\n * 1. mnemonics\n * 2. secretKey (base64 or hex)\n * If none of them is provided, will generate a random mnemonics with 24 words.\n *\n * @param mnemonics, 12 or 24 mnemonics words, separated by space\n * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored\n */\n constructor({ mnemonics, secretKey }: AccountMangerParams = {}) {\n // If the mnemonics or secretKey is provided, use it\n // Otherwise, generate a random mnemonics with 24 words\n this.mnemonics = mnemonics || \"\";\n this.secretKey = secretKey || \"\";\n if (!this.mnemonics && !this.secretKey) {\n this.mnemonics = generateMnemonic(24)\n }\n\n // Init the current account\n this.currentKeyPair = this.secretKey\n ? Ed25519Keypair.fromSecretKey(\n normalizePrivateKey(hexOrBase64ToUint8Array(this.secretKey))\n )\n : getKeyPair(this.mnemonics);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.\n * else:\n * it will generate keyPair from the mnemonic with the given derivePathParams.\n */\n getKeyPair(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentKeyPair;\n return getKeyPair(this.mnemonics, derivePathParams);\n }\n\n /**\n * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.\n * else:\n * it will generate address from the mnemonic with the given derivePathParams.\n */\n getAddress(derivePathParams?: DerivePathParams) {\n if (!derivePathParams || !this.mnemonics) return this.currentAddress;\n return getKeyPair(this.mnemonics, derivePathParams).getPublicKey().toSuiAddress();\n }\n\n /**\n * Switch the current account with the given derivePathParams.\n * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.\n */\n switchAccount(derivePathParams: DerivePathParams) {\n if (this.mnemonics) {\n this.currentKeyPair = getKeyPair(this.mnemonics, derivePathParams);\n this.currentAddress = this.currentKeyPair.getPublicKey().toSuiAddress();\n }\n }\n}\n","import { Ed25519Keypair } from '@mysten/sui.js'\n\nexport type DerivePathParams = {\n accountIndex?: number;\n isExternal?: boolean;\n addressIndex?: number;\n}\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (derivePathParams: DerivePathParams = {}) => {\n const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;\n return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;\n}\n\n/**\n * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'\n *\n * accountIndex is the index of the account, default is 0.\n *\n * isExternal is the type of the address, default is false. Usually, the external address is used to receive coins. The internal address is used to change coins.\n *\n * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.\n *\n * @description Get keypair from mnemonics and derive path\n * @param mnemonics\n * @param derivePathParams\n */\nexport const getKeyPair = (mnemonics: string, derivePathParams: DerivePathParams = {}) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n}\n","import { fromB64 } from '@mysten/sui.js'\n/**\n * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).\n * @param str\n */\nexport const isHex = (str: string) => /^0x[0-9a-fA-F]+$|^[0-9a-fA-F]+$/.test(str);\n\n/**\n * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).\n * Note that the \"=\" signs at the end are optional padding characters that may be present in some base64 encoded strings.\n * @param str\n */\nexport const isBase64 = (str: string) => /^[a-zA-Z0-9+/]+={0,2}$/g.test(str);\n\n/**\n * Convert a hex string to Uint8Array\n * @param hexStr\n */\nexport function fromHEX(hexStr: string): Uint8Array {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array')\n }\n let intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)?.map(byte => parseInt(byte, 16));\n\n if (!intArr || intArr.length === 0) {\n throw new Error(`Unable to parse HEX: ${hexStr}`);\n }\n return Uint8Array.from(intArr);\n}\n\n/**\n * @description Convert a hex or base64 string to Uint8Array\n */\nexport const hexOrBase64ToUint8Array = (str: string): Uint8Array => {\n if (isHex(str)) {\n return fromHEX(str)\n } else if (isBase64(str)) {\n return fromB64(str)\n } else {\n throw new Error('The string is not a valid hex or base64 string.');\n }\n}\n\nconst PRIVATE_KEY_SIZE = 32;\nconst LEGACY_PRIVATE_KEY_SIZE = 64;\n/**\n * normalize a private key\n * A private key is a 32-byte array.\n * But there are two different formats for private keys:\n * 1. A 32-byte array\n * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key\n * 3. A 33-byte array with the first byte being 0x00 (sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning)\n */\nexport const normalizePrivateKey = (key: Uint8Array): Uint8Array => {\n if (key.length === LEGACY_PRIVATE_KEY_SIZE) {\n // This is a legacy secret key, we need to strip the public key bytes and only read the first 32 bytes\n key = key.slice(0, PRIVATE_KEY_SIZE);\n } else if (key.length === PRIVATE_KEY_SIZE + 1 && key[0] === 0) {\n // sui.keystore key is a Base64 string with scheme flag 0x00 at the beginning\n return key.slice(1);\n } else if (key.length === PRIVATE_KEY_SIZE) {\n return key;\n }\n throw new Error('invalid secret key');\n}\n","import { generateMnemonic as genMnemonic } from '@scure/bip39'\nimport { wordlist } from '@scure/bip39/wordlists/english.js'\n\nexport const generateMnemonic = (numberOfWords: 12 | 24 = 24) => {\n const strength = numberOfWords === 12 ? 128 : 256\n return genMnemonic(wordlist, strength)\n}\n","import {\n Connection,\n JsonRpcProvider,\n getObjectType,\n getObjectId,\n getObjectFields,\n getObjectDisplay,\n getObjectVersion,\n DisplayFieldsResponse,\n ObjectContentFields,\n} from \"@mysten/sui.js\";\nimport { requestFaucet } from './faucet'\nimport { NetworkType, getDefaultNetworkParams } from \"./default-chain-configs\";\n\ntype ObjectData = {\n objectId: string;\n objectType: string;\n objectVersion: number;\n objectDisplay: DisplayFieldsResponse;\n objectFields: ObjectContentFields;\n}\n\ntype Params = {\n fullnodeUrl?: string;\n faucetUrl?: string;\n networkType?: NetworkType;\n}\n\nexport class SuiRpcProvider {\n public fullnodeUrl: string;\n public faucetUrl?: string;\n public provider: JsonRpcProvider;\n /**\n *\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type\n * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type\n */\n constructor({ fullnodeUrl, faucetUrl, networkType }: Params = {}) {\n // Get the default fullnode url and faucet url for the given network type, default is 'testnet'\n const defaultNetworkParams = getDefaultNetworkParams(networkType || 'devnet');\n // Set fullnodeUrl and faucetUrl, if they are not provided, use the default value.\n this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullnode;\n this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;\n\n // Init the provider\n const connection = new Connection({\n fullnode: this.fullnodeUrl,\n faucet: this.faucetUrl,\n });\n this.provider = new JsonRpcProvider(connection);\n }\n\n /**\n * Request some SUI from faucet\n * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.\n */\n async requestFaucet(addr: string) {\n return requestFaucet(addr, this.provider)\n }\n\n async getBalance(addr: string, coinType?: string) {\n return this.provider.getBalance({ owner: addr, coinType });\n }\n\n async getObjects(ids: string[]) {\n const options = { showContent: true, showDisplay: true, showType: true };\n const objects = await this.provider.multiGetObjects({ ids, options });\n const parsedObjects = objects.map((object) => {\n const objectId = getObjectId(object);\n const objectType = getObjectType(object);\n const objectVersion = getObjectVersion(object);\n const objectFields = getObjectFields(object);\n const objectDisplay = getObjectDisplay(object);\n return { objectId, objectType, objectVersion, objectFields, objectDisplay };\n });\n return parsedObjects as ObjectData[]\n }\n\n /**\n * @description Select coins that add up to the given amount.\n * @param addr the address of the owner\n * @param amount the amount that is needed for the coin\n * @param coinType the coin type, default is '0x2::SUI::SUI'\n */\n async selectCoins(addr: string, amount: number, coinType: string = '0x2::SUI::SUI') {\n const coins = await this.provider.getCoins({ owner: addr, coinType });\n let selectedCoins: {objectId: string, digest: string, version: string}[] = [];\n let totalAmount = 0;\n // Sort the coins by balance in descending order\n const coinsData = coins.data.sort((a, b) => parseInt(b.balance) - parseInt(a.balance))\n for(const coinData of coins.data) {\n selectedCoins.push({\n objectId: coinData.coinObjectId,\n digest: coinData.digest,\n version: coinData.version,\n });\n totalAmount = totalAmount + parseInt(coinData.balance);\n if (totalAmount >= amount) {\n break;\n }\n }\n\n if (!selectedCoins.length) {\n throw new Error('No valid coins found for the transaction.');\n }\n return selectedCoins;\n }\n}\n","import {JsonRpcProvider, FaucetRateLimitError, assert, FaucetResponse} from '@mysten/sui.js'\nimport { retry } from 'ts-retry-promise'\n\n/**\n * Request some SUI from faucet\n * @param address\n * @param provider\n * @returns {Promise<boolean>}, return true if the request is successful\n */\nexport const requestFaucet = async (address: string, provider: JsonRpcProvider) => {\n console.log('\\nRequesting SUI from faucet for address: ', address)\n const headers = {\n authority: 'faucet.testnet.sui.io',\n method: 'POST',\n path: '/gas',\n scheme: 'https',\n accept: '*/*',\n 'accept-encoding': 'gzip, deflate, br',\n 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7',\n 'content-length': '105',\n 'content-type': 'application/json',\n 'origin': 'chrome-extension://opcgpfmipidbgpenhmajoajpbobppdil',\n cookie: '_ga=GA1.1.2092533979.1664032306; sui_io_cookie={\"level\":[\"necessary\",\"analytics\"],\"revision\":0,\"data\":null,\"rfc_cookie\":false}; _ga_YKP53WJMB0=GS1.1.1680531285.31.0.1680531334.11.0.0; _ga_0GW4F97GFL=GS1.1.1680826187.125.0.1680826187.60.0.0; __cf_bm=6rPjXUwuzUPy4yDlZuXgDj0v7xLPpUd5z0CFGCoN_YI-1680867579-0-AZMhU7/mKUUbUlOa27LmfW6eIFkBkXsPKqYgWjpjWpj2XzDckgUsRu/pxSRGfvXCspn3w7Df+uO1MR/b+XikJU0=; _cfuvid=zjwCXMmu19KBIVo_L9Qbq4TqFXJpophG3.EvFTxqdf4-1680867579342-0-604800000',\n 'sec-ch-ua': '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"',\n 'sec-ch-ua-mobile': '?0',\n 'sec-ch-ua-platform': \"macOS\",\n 'sec-fetch-dest': 'empty',\n 'sec-fetch-mode': 'cors',\n 'sec-fetch-site': 'none',\n 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',\n }\n // We need to add the following headers to the request, otherwise the request will be rejected by the faucet server\n const resp = await retry<FaucetResponse>(() => provider.requestSuiFromFaucet(address, headers), {\n backoff: 'EXPONENTIAL',\n // overall timeout in 60 seconds\n timeout: 1000 * 60,\n // skip retry if we hit the rate-limit error\n retryIf: (error: any) => !(error instanceof FaucetRateLimitError),\n logger: (msg) => console.warn(`Retry requesting faucet: ${msg}`),\n });\n assert(resp, FaucetResponse, 'Request faucet failed\\n');\n console.log('Request faucet success\\n');\n}\n","import {\n localnetConnection,\n devnetConnection,\n testnetConnection,\n mainnetConnection,\n} from '@mysten/sui.js'\nimport type { Connection } from '@mysten/sui.js'\n\nexport type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';\n\n/**\n * @description Get the default fullnode url and faucet url for the given network type\n * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'\n * @returns { fullNode: string, websocket: string, faucet?: string }\n */\nexport const getDefaultNetworkParams = (networkType: NetworkType = 'devnet'): Connection => {\n switch (networkType) {\n case 'localnet':\n return localnetConnection\n case 'devnet':\n return devnetConnection\n case 'testnet':\n return testnetConnection\n case 'mainnet':\n return mainnetConnection\n default:\n return devnetConnection\n }\n}\n","import {\n TransactionBlock,\n SUI_SYSTEM_STATE_OBJECT_ID,\n normalizeSuiObjectId,\n TransactionArgument,\n} from '@mysten/sui.js'\nimport { SuiInputTypes, getDefaultSuiInputType } from './util'\n\nexport type SuiTxArg = TransactionArgument | string | number | bigint | boolean;\nexport type SuiVecTxArg = { value: SuiTxArg[], vecType: SuiInputTypes } | SuiTxArg[];\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor() {\n this.txBlock = new TransactionBlock();\n }\n\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error('transferSuiToMany: recipients.length !== amounts.length');\n }\n const tx = this.txBlock;\n const coins = tx.splitCoins(tx.gas, amounts.map(amount => tx.pure(amount)));\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n transferObjects(objects: SuiTxArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(this.#convertArgs(objects), tx.pure(recipient));\n return this;\n }\n\n takeAmountFromCoins(coins: SuiTxArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = this.#convertArgs(coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);\n return [sendCoin, mergedCoin];\n }\n\n splitSUIFromGas(amounts: number[]) {\n const tx = this.txBlock;\n return tx.splitCoins(tx.gas, amounts.map(m => tx.pure(m)));\n }\n \n splitCoins(coin: SuiTxArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = this.#convertArgs([coin])[0];\n return tx.splitCoins(coinObject, amounts.map(m => tx.pure(m)));\n }\n \n splitMultiCoins(coins: SuiTxArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = this.#convertArgs(coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(mergedCoin, amounts.map(m => tx.pure(m)));\n return { splitedCoins, mergedCoin }\n }\n \n transferCoinToMany(inputCoins: SuiTxArg[], sender: string, recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error('transferSuiToMany: recipients.length !== amounts.length');\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(inputCoins, amounts);\n recipients.forEach((recipient, index) => {\n tx.transferObjects([splitedCoins[index]], tx.pure(recipient));\n });\n tx.transferObjects([mergedCoin], tx.pure(sender))\n return this;\n }\n \n transferCoin(inputCoins: SuiTxArg[], sender: string, recipient: string, amount: number) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\n }\n \n /**\n * @description Move call\n * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`\n * @param args the arguments of the move call, such as `['0x1', '0x2']`\n * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`\n */\n moveCall(target: string, args: (SuiTxArg | SuiVecTxArg)[] = [], typeArgs: string[] = []) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex = /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;\n const match = target.match(regex);\n if (match === null) throw new Error('Invalid target format. Expected `${string}::${string}::${string}`');\n const convertedArgs = this.#convertArgs(args);\n const tx = this.txBlock;\n return tx.moveCall({\n target: target as `${string}::${string}::${string}`,\n arguments: convertedArgs,\n typeArguments: typeArgs,\n });\n }\n\n stakeSui(amount: number, validatorAddr: string) {\n const tx = this.txBlock;\n const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);\n tx.moveCall({\n target: '0x3::sui_system::request_add_stake',\n arguments: [tx.object(SUI_SYSTEM_STATE_OBJECT_ID), stakeCoin, tx.pure(validatorAddr)],\n });\n return tx;\n }\n\n address(value: string) {\n return this.txBlock.pure(value)\n }\n\n pure(value: any) {\n return this.txBlock.pure(value)\n }\n\n object(value: string) {\n return this.txBlock.object(value)\n }\n\n /**\n * Since we know the elements in the array are the same type\n * If type is not provided, we will try to infer the type from the first element\n * By default,\n *\n * string starting with `0x` =====> object id\n * number, bigint ====> u64\n * boolean =====> bool\n *\n *\n * If type is provided, we will use the type to convert the array\n * @param args\n * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'\n */\n makeMoveVec(args: SuiTxArg[], type?: SuiInputTypes) {\n if (args.length === 0) throw new Error('Transaction builder error: Empty array is not allowed');\n const defaultSuiType = getDefaultSuiInputType(args[0])\n if (type === 'object' || (!type && defaultSuiType === 'object')) {\n const objects = args.map(arg =>\n typeof arg === 'string' ? this.txBlock.object(normalizeSuiObjectId(arg)) : (arg as any)\n );\n return this.txBlock.makeMoveVec({ objects })\n } else {\n const vecType = type || defaultSuiType;\n return this.txBlock.pure(args, `vector<${vecType}>`)\n }\n }\n\n #isMoveVecArg(arg: any) {\n const isFullMoveVecArg = arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n }\n\n #convertArgs(args: any[]): TransactionArgument[] {\n return args.map(arg => {\n if (typeof arg === 'string' && arg.startsWith('0x')) {\n // We always treat string starting with `0x` as object id\n return this.txBlock.object(normalizeSuiObjectId(arg))\n } else if (this.#isMoveVecArg(arg)) {\n // if it's an array arg, we will convert it to move vec\n const vecType = arg.vecType || undefined;\n return vecType\n ? this.makeMoveVec(arg.value, vecType)\n : this.makeMoveVec(arg)\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return this.txBlock.pure(arg)\n } else {\n // We do nothing, because it's most likely already a move value\n return arg\n }\n })\n }\n}\n","/**\n * These are the basics types that can be used in the SUI\n */\nexport type SuiBasicTypes =\n |'address'\n |'bool'\n |'u8'\n | 'u16'\n | 'u32'\n | 'u64'\n | 'u128'\n | 'u256'\n\nexport type SuiInputTypes = 'object' | SuiBasicTypes\n\nexport const getDefaultSuiInputType = (value: any): SuiInputTypes => {\n if (typeof value === 'string' && value.startsWith('0x')) {\n return 'object'\n } else if (typeof value === 'number' || typeof value === 'bigint') {\n return 'u64'\n } else if (typeof value === 'boolean') {\n return 'bool'\n } else {\n return 'object'\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,oBAAAA,mBAAkB,qBAAqB,8BAAAC,mCAAkC;;;ACMlF,SAAS,iBAAmF;;;ACN5F,SAAS,kBAAAC,uBAAsB;;;ACA/B,SAAS,sBAAsB;AAWxB,IAAM,sBAAsB,CAAC,mBAAqC,CAAC,MAAM;AAC9E,QAAM,EAAE,eAAe,GAAG,aAAa,OAAO,eAAe,EAAE,IAAI;AACnE,SAAO,cAAc,iBAAiB,aAAa,IAAI,MAAM;AAC/D;AAeO,IAAM,aAAa,CAAC,WAAmB,mBAAqC,CAAC,MAAM;AACxF,QAAM,aAAa,oBAAoB,gBAAgB;AACvD,SAAO,eAAe,cAAc,WAAW,UAAU;AAC3D;;;AChCA,SAAS,eAAe;AAKjB,IAAM,QAAQ,CAAC,QAAgB,kCAAkC,KAAK,GAAG;AAOzE,IAAM,WAAW,CAAC,QAAgB,0BAA0B,KAAK,GAAG;AAMpE,SAAS,QAAQ,QAA4B;AAClD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA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AAmB,kBAAqC;AAC/F,UAAM,KAAK,IAAI,WAAW;AAC1B,OAAG,gBAAgB,SAAS,SAAS;AACrC,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAAA,EAEA,MAAM,SAAS,YAAqI;AAClJ,UAAM,EAAE,QAAQ,WAAW,OAAO,CAAC,GAAG,gBAAgB,CAAC,GAAG,iBAAiB,IAAI;AAC/E,UAAM,KAAK,IAAI,WAAW;AAC1B,OAAG,SAAS,QAAQ,MAAM,aAAa;AACvC,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,sBAAsB,QAAgB,UAAkB,OAAgB;AAC5E,YAAQ,SAAS,KAAK,eAAe;AACrC,UAAM,QAAQ,MAAM,KAAK,YAAY,YAAY,OAAO,QAAQ,QAAQ;AACxE,WAAO,MAAM,IAAI,OAAK,EAAE,QAAQ;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,QAAgB,eAAuB,kBAAqC;AACzF,UAAM,KAAK,IAAI,WAAW;AAC1B,OAAG,SAAS,QAAQ,aAAa;AACjC,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAW,IAAgD,kBAAiE;AAChI,SAAK,cAAc,aAAa,GAAG,UAAU;AAC7C,WAAO,KAAK,YAAY,SAAS,2BAA2B,EAAE,kBAAkB,IAAI,QAAQ,KAAK,WAAW,gBAAgB,EAAE,CAAC;AAAA,EACjI;AACF;","names":["TransactionBlock","SUI_SYSTEM_STATE_OBJECT_ID","Ed25519Keypair","Ed25519Keypair","JsonRpcProvider","JsonRpcProvider"]}
@@ -30,7 +30,7 @@ export declare class SuiKit {
30
30
  *
31
31
  * @param mnemonics, 12 or 24 mnemonics words, separated by space
32
32
  * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
33
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
33
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
34
34
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
35
35
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
36
36
  */
@@ -1,22 +1,8 @@
1
- /**
2
- * @description This file is used to store the default chain parameters for the different networks.
3
- * @author IceFox@Scallop
4
- */
5
- export declare const DEFAULT_LOCALHOST_FULLNODE = "http://0.0.0.0:9000";
6
- export declare const DEFAULT_LOCALHOST_FAUCET = "";
7
- export declare const DEFAULT_DEVNET_FULLNODE = "https://fullnode.devnet.sui.io:443";
8
- export declare const DEFAULT_DEVNET_FAUCET = "https://faucet.devnet.sui.io/gas";
9
- export declare const DEFAULT_TESTNET_FULLNODE = "https://fullnode.testnet.sui.io:443";
10
- export declare const DEFAULT_TESTNET_FAUCET = "https://faucet.testnet.sui.io/gas";
11
- export declare const DEFAULT_MAINNET_FULLNODE = "https://fullnode.mainnet.sui.io:443";
12
- export declare const DEFAULT_MAINNET_FAUCET = "";
13
- export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localhost';
1
+ import type { Connection } from '@mysten/sui.js';
2
+ export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
14
3
  /**
15
4
  * @description Get the default fullnode url and faucet url for the given network type
16
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
17
- * @returns { fullNode: string, faucet: string }
5
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
6
+ * @returns { fullNode: string, websocket: string, faucet?: string }
18
7
  */
19
- export declare const getDefaultNetworkParams: (networkType?: NetworkType) => {
20
- fullNode: string;
21
- faucet: string;
22
- };
8
+ export declare const getDefaultNetworkParams: (networkType?: NetworkType) => Connection;
@@ -14,11 +14,11 @@ type Params = {
14
14
  };
15
15
  export declare class SuiRpcProvider {
16
16
  fullnodeUrl: string;
17
- faucetUrl: string;
17
+ faucetUrl?: string;
18
18
  provider: JsonRpcProvider;
19
19
  /**
20
20
  *
21
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
21
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
22
22
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
23
23
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
24
24
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-kit",
3
- "version": "0.33.1",
3
+ "version": "0.34.0",
4
4
  "description": "Tookit for interacting with SUI network",
5
5
  "keywords": [
6
6
  "sui",
@@ -37,7 +37,7 @@
37
37
  "src"
38
38
  ],
39
39
  "dependencies": {
40
- "@mysten/sui.js": "^0.33.0",
40
+ "@mysten/sui.js": "^0.34.0",
41
41
  "@scure/bip39": "^1.2.0",
42
42
  "assert": "^2.0.0",
43
43
  "colorts": "^0.1.63",
@@ -46,15 +46,15 @@
46
46
  "ts-retry-promise": "^0.7.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "@mysten/sui.js": "^0.33.0"
49
+ "@mysten/sui.js": "^0.34.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/node": "^18.15.11",
52
+ "@types/node": "^20.1.5",
53
53
  "@types/tmp": "^0.2.3",
54
54
  "dotenv": "^16.0.3",
55
55
  "ts-node": "^10.9.1",
56
56
  "tsup": "^6.7.0",
57
- "typescript": "^5.0.2"
57
+ "typescript": "^5.0.4"
58
58
  },
59
59
  "scripts": {
60
60
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
@@ -33,7 +33,7 @@ export class SuiKit {
33
33
  *
34
34
  * @param mnemonics, 12 or 24 mnemonics words, separated by space
35
35
  * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
36
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
36
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
37
37
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
38
38
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
39
39
  */
@@ -1,52 +1,29 @@
1
- /**
2
- * @description This file is used to store the default chain parameters for the different networks.
3
- * @author IceFox@Scallop
4
- */
5
- // For localhost
6
- export const DEFAULT_LOCALHOST_FULLNODE = "http://0.0.0.0:9000"
7
- export const DEFAULT_LOCALHOST_FAUCET = ""
8
-
9
- // For devnet
10
- export const DEFAULT_DEVNET_FULLNODE ="https://fullnode.devnet.sui.io:443"
11
- export const DEFAULT_DEVNET_FAUCET = "https://faucet.devnet.sui.io/gas"
12
-
13
- // For testnet
14
- export const DEFAULT_TESTNET_FULLNODE = "https://fullnode.testnet.sui.io:443"
15
- export const DEFAULT_TESTNET_FAUCET = "https://faucet.testnet.sui.io/gas"
16
-
17
- // For mainnet
18
- export const DEFAULT_MAINNET_FULLNODE = "https://fullnode.mainnet.sui.io:443"
19
- export const DEFAULT_MAINNET_FAUCET = ""
20
-
1
+ import {
2
+ localnetConnection,
3
+ devnetConnection,
4
+ testnetConnection,
5
+ mainnetConnection,
6
+ } from '@mysten/sui.js'
7
+ import type { Connection } from '@mysten/sui.js'
21
8
 
22
- export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localhost';
9
+ export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
23
10
 
24
11
  /**
25
12
  * @description Get the default fullnode url and faucet url for the given network type
26
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
27
- * @returns { fullNode: string, faucet: string }
13
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
14
+ * @returns { fullNode: string, websocket: string, faucet?: string }
28
15
  */
29
- export const getDefaultNetworkParams = (networkType: NetworkType = 'devnet'): { fullNode: string, faucet: string } => {
16
+ export const getDefaultNetworkParams = (networkType: NetworkType = 'devnet'): Connection => {
30
17
  switch (networkType) {
31
- case 'localhost':
32
- return {
33
- fullNode: DEFAULT_LOCALHOST_FULLNODE,
34
- faucet: DEFAULT_LOCALHOST_FAUCET,
35
- }
18
+ case 'localnet':
19
+ return localnetConnection
20
+ case 'devnet':
21
+ return devnetConnection
36
22
  case 'testnet':
37
- return {
38
- fullNode: DEFAULT_TESTNET_FULLNODE,
39
- faucet: DEFAULT_TESTNET_FAUCET,
40
- }
23
+ return testnetConnection
41
24
  case 'mainnet':
42
- return {
43
- fullNode: DEFAULT_MAINNET_FULLNODE,
44
- faucet: DEFAULT_MAINNET_FAUCET,
45
- }
25
+ return mainnetConnection
46
26
  default:
47
- return {
48
- fullNode: DEFAULT_DEVNET_FULLNODE,
49
- faucet: DEFAULT_DEVNET_FAUCET,
50
- }
27
+ return devnetConnection
51
28
  }
52
29
  }
@@ -28,11 +28,11 @@ type Params = {
28
28
 
29
29
  export class SuiRpcProvider {
30
30
  public fullnodeUrl: string;
31
- public faucetUrl: string;
31
+ public faucetUrl?: string;
32
32
  public provider: JsonRpcProvider;
33
33
  /**
34
34
  *
35
- * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localhost', default is 'devnet'
35
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
36
36
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
37
37
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
38
38
  */
@@ -40,7 +40,7 @@ export class SuiRpcProvider {
40
40
  // Get the default fullnode url and faucet url for the given network type, default is 'testnet'
41
41
  const defaultNetworkParams = getDefaultNetworkParams(networkType || 'devnet');
42
42
  // Set fullnodeUrl and faucetUrl, if they are not provided, use the default value.
43
- this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullNode;
43
+ this.fullnodeUrl = fullnodeUrl || defaultNetworkParams.fullnode;
44
44
  this.faucetUrl = faucetUrl || defaultNetworkParams.faucet;
45
45
 
46
46
  // Init the provider