@0xobelisk/client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.js +757 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +755 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/libs/suiAccountManager/crypto.d.ts +1 -0
  9. package/dist/libs/suiAccountManager/index.d.ts +35 -0
  10. package/dist/libs/suiAccountManager/keypair.d.ts +21 -0
  11. package/dist/libs/suiAccountManager/types.d.ts +9 -0
  12. package/dist/libs/suiAccountManager/util.d.ts +29 -0
  13. package/dist/libs/suiRpcProvider/defaultChainConfigs.d.ts +8 -0
  14. package/dist/libs/suiRpcProvider/faucet.d.ts +8 -0
  15. package/dist/libs/suiRpcProvider/index.d.ts +40 -0
  16. package/dist/libs/suiRpcProvider/types.d.ts +14 -0
  17. package/dist/libs/suiTxBuilder/index.d.ts +544 -0
  18. package/dist/libs/suiTxBuilder/types.d.ts +12 -0
  19. package/dist/libs/suiTxBuilder/util.d.ts +76 -0
  20. package/dist/obelisk.d.ts +2857 -0
  21. package/dist/test/tsconfig.tsbuildinfo +1 -0
  22. package/dist/types/index.d.ts +11 -0
  23. package/package.json +152 -0
  24. package/src/index.ts +10 -0
  25. package/src/libs/suiAccountManager/crypto.ts +7 -0
  26. package/src/libs/suiAccountManager/index.ts +72 -0
  27. package/src/libs/suiAccountManager/keypair.ts +38 -0
  28. package/src/libs/suiAccountManager/types.ts +10 -0
  29. package/src/libs/suiAccountManager/util.ts +70 -0
  30. package/src/libs/suiRpcProvider/defaultChainConfigs.ts +30 -0
  31. package/src/libs/suiRpcProvider/faucet.ts +57 -0
  32. package/src/libs/suiRpcProvider/index.ts +114 -0
  33. package/src/libs/suiRpcProvider/types.ts +17 -0
  34. package/src/libs/suiTxBuilder/index.ts +245 -0
  35. package/src/libs/suiTxBuilder/types.ts +32 -0
  36. package/src/libs/suiTxBuilder/util.ts +84 -0
  37. package/src/obelisk.ts +297 -0
  38. package/src/types/index.ts +17 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/obelisk.ts","../src/libs/suiAccountManager/index.ts","../src/libs/suiAccountManager/keypair.ts","../src/libs/suiAccountManager/util.ts","../src/libs/suiAccountManager/crypto.ts","../src/libs/suiRpcProvider/index.ts","../src/libs/suiRpcProvider/faucet.ts","../src/libs/suiRpcProvider/defaultChainConfigs.ts","../src/libs/suiTxBuilder/index.ts","../src/libs/suiTxBuilder/util.ts"],"sourcesContent":["export {\n TransactionBlock,\n SUI_CLOCK_OBJECT_ID,\n SUI_SYSTEM_STATE_OBJECT_ID,\n} from '@mysten/sui.js';\nexport { Obelisk } from './obelisk';\nexport { SuiAccountManager } from './libs/suiAccountManager';\nexport { SuiTxBlock } from './libs/suiTxBuilder';\nexport { SuiRpcProvider } from './libs/suiRpcProvider';\nexport type * from './types';\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 {\n RawSigner,\n TransactionBlock,\n DevInspectResults,\n SuiTransactionBlockResponse, JsonRpcProvider, testnetConnection, Ed25519Keypair,\n} from '@mysten/sui.js';\nimport { SuiAccountManager } from './libs/suiAccountManager';\nimport { SuiRpcProvider } from './libs/suiRpcProvider';\nimport { SuiTxBlock } from './libs/suiTxBuilder';\nimport { SuiKitParams, DerivePathParams, SuiTxArg, SuiVecTxArg } from './types';\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 Obelisk {\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({\n mnemonics,\n secretKey,\n networkType,\n fullnodeUrl,\n faucetUrl,\n }: SuiKitParams = {}) {\n // Init the account manager\n this.accountManager = new SuiAccountManager({ mnemonics, secretKey });\n // Init the rpc provider\n this.rpcProvider = new SuiRpcProvider({\n fullnodeUrl,\n faucetUrl,\n networkType,\n });\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() {\n return this.accountManager.currentAddress;\n }\n\n provider() {\n return this.rpcProvider.provider;\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(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(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ) {\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(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<SuiTransactionBlockResponse> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n const signer = this.getSigner(derivePathParams);\n return signer.signAndExecuteTransactionBlock({\n transactionBlock: tx,\n options: {\n showEffects: true,\n showEvents: true,\n showObjectChanges: true,\n },\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(\n recipient: string,\n amount: number,\n derivePathParams?: DerivePathParams\n ) {\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(\n recipients: string[],\n amounts: number[],\n derivePathParams?: DerivePathParams\n ) {\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(\n recipients: string[],\n amounts: number[],\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\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(\n owner,\n totalAmount,\n coinType\n );\n tx.transferCoinToMany(\n coins.map((c) => c.objectId),\n owner,\n recipients,\n amounts\n );\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async transferCoin(\n recipient: string,\n amount: number,\n coinType: string,\n derivePathParams?: DerivePathParams\n ) {\n return this.transferCoinToMany(\n [recipient],\n [amount],\n coinType,\n derivePathParams\n );\n }\n\n async transferObjects(\n objects: string[],\n recipient: string,\n derivePathParams?: DerivePathParams\n ) {\n const tx = new SuiTxBlock();\n tx.transferObjects(objects, recipient);\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n async moveCall(callParams: {\n target: string;\n arguments?: (SuiTxArg | SuiVecTxArg)[];\n typeArguments?: string[];\n derivePathParams?: DerivePathParams;\n }) {\n const {\n target,\n arguments: args = [],\n typeArguments = [],\n derivePathParams,\n } = 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(\n amount: number,\n coinType: string,\n owner?: string\n ) {\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(\n amount: number,\n validatorAddr: string,\n derivePathParams?: DerivePathParams\n ) {\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(\n tx: Uint8Array | TransactionBlock | SuiTxBlock,\n derivePathParams?: DerivePathParams\n ): Promise<DevInspectResults> {\n tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;\n return this.rpcProvider.provider.devInspectTransactionBlock({\n transactionBlock: tx,\n sender: this.getAddress(derivePathParams),\n });\n }\n\n async call(world_id: string, system_name: string, counter: any,derivePathParams?: DerivePathParams) {\n const tx = new TransactionBlock();\n tx.moveCall({\n target: `${world_id}::system::${system_name}`,\n arguments: [\n // txb.pure(manager),\n tx.pure(counter),\n ],\n })\n return this.signAndSendTxn(tx, derivePathParams);\n }\n\n}\n","import { Ed25519Keypair } from '@mysten/sui.js';\nimport { getKeyPair } from './keypair';\nimport { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';\nimport { generateMnemonic } from './crypto';\nimport type { AccountMangerParams, DerivePathParams } from './types';\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)\n .getPublicKey()\n .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';\nimport type { DerivePathParams } from './types';\n\n/**\n * @description Get ed25519 derive path for SUI\n * @param derivePathParams\n */\nexport const getDerivePathForSUI = (\n derivePathParams: DerivePathParams = {}\n) => {\n const {\n accountIndex = 0,\n isExternal = false,\n addressIndex = 0,\n } = 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 = (\n mnemonics: string,\n derivePathParams: DerivePathParams = {}\n) => {\n const derivePath = getDerivePathForSUI(derivePathParams);\n return Ed25519Keypair.deriveKeypair(mnemonics, derivePath);\n};\n","import { fromB64 } from '@mysten/sui.js';\n\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) =>\n /^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 const fromHEX = (hexStr: string): Uint8Array => {\n if (!hexStr) {\n throw new Error('cannot parse empty string to Uint8Array');\n }\n const intArr = hexStr\n .replace('0x', '')\n .match(/.{1,2}/g)\n ?.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';\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} from '@mysten/sui.js';\nimport { requestFaucet } from './faucet';\nimport { getDefaultNetworkParams } from './defaultChainConfigs';\nimport type { ObjectData, SuiRpcProviderParams } from './types';\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({\n fullnodeUrl,\n faucetUrl,\n networkType,\n }: SuiRpcProviderParams = {}) {\n // Get the default fullnode url and faucet url for the given network type, default is 'testnet'\n const defaultNetworkParams = getDefaultNetworkParams(\n networkType || 'devnet'\n );\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 {\n objectId,\n objectType,\n objectVersion,\n objectFields,\n objectDisplay,\n };\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(\n addr: string,\n amount: number,\n coinType: string = '0x2::SUI::SUI'\n ) {\n const coins = await this.provider.getCoins({ owner: addr, coinType });\n const selectedCoins: {\n objectId: string;\n digest: string;\n version: string;\n }[] = [];\n let totalAmount = 0;\n // Sort the coins by balance in descending order\n 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 {\n JsonRpcProvider,\n FaucetRateLimitError,\n assert,\n FaucetResponse,\n} 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 (\n address: string,\n provider: JsonRpcProvider\n) => {\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:\n '_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':\n '\"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':\n '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>(\n () => provider.requestSuiFromFaucet(address, headers),\n {\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 );\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';\nimport type { NetworkType } from './types';\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 = (\n networkType: NetworkType = 'devnet'\n): 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 TransactionExpiration,\n SuiObjectRef,\n SharedObjectRef,\n JsonRpcProvider,\n TransactionType,\n Transactions,\n ObjectCallArg,\n} from '@mysten/sui.js';\nimport { convertArgs } from './util';\nimport type { SuiTxArg, SuiObjectArg, SuiVecTxArg } from './types';\n\nexport class SuiTxBlock {\n public txBlock: TransactionBlock;\n constructor(transaction?: TransactionBlock) {\n this.txBlock = new TransactionBlock(transaction);\n }\n\n //======== override methods of TransactionBlock ============\n\n address(value: string) {\n return this.txBlock.pure(value, 'address');\n }\n pure(value: unknown, type?: string) {\n return this.txBlock.pure(value, type);\n }\n object(value: string | ObjectCallArg) {\n return this.txBlock.object(value);\n }\n objectRef(ref: SuiObjectRef) {\n return this.txBlock.objectRef(ref);\n }\n sharedObjectRef(ref: SharedObjectRef) {\n return this.txBlock.sharedObjectRef(ref);\n }\n setSender(sender: string) {\n return this.txBlock.setSender(sender);\n }\n setSenderIfNotSet(sender: string) {\n return this.txBlock.setSenderIfNotSet(sender);\n }\n setExpiration(expiration?: TransactionExpiration) {\n return this.txBlock.setExpiration(expiration);\n }\n setGasPrice(price: number | bigint) {\n return this.txBlock.setGasPrice(price);\n }\n setGasBudget(budget: number | bigint) {\n return this.txBlock.setGasBudget(budget);\n }\n setGasOwner(owner: string) {\n return this.txBlock.setGasOwner(owner);\n }\n setGasPayment(payments: SuiObjectRef[]) {\n return this.txBlock.setGasPayment(payments);\n }\n\n add(transaction: TransactionType) {\n return this.txBlock.add(transaction);\n }\n serialize() {\n return this.txBlock.serialize();\n }\n build(\n params: {\n provider?: JsonRpcProvider;\n onlyTransactionKind?: boolean;\n } = {}\n ) {\n return this.txBlock.build(params);\n }\n getDigest({ provider }: { provider?: JsonRpcProvider } = {}) {\n return this.txBlock.getDigest({ provider });\n }\n\n get gas() {\n return this.txBlock.gas;\n }\n get blockData() {\n return this.txBlock.blockData;\n }\n\n transferObjects(objects: SuiObjectArg[], recipient: string) {\n const tx = this.txBlock;\n tx.transferObjects(convertArgs(this.txBlock, objects), tx.pure(recipient));\n return this;\n }\n splitCoins(coin: SuiObjectArg, amounts: number[]) {\n const tx = this.txBlock;\n const coinObject = convertArgs(this.txBlock, [coin])[0];\n const res = tx.splitCoins(\n coinObject,\n amounts.map((m) => tx.pure(m))\n );\n return amounts.map((_, i) => res[i]);\n }\n mergeCoins(destination: SuiObjectArg, sources: SuiObjectArg[]) {\n const destinationObject = convertArgs(this.txBlock, [destination])[0];\n const sourceObjects = convertArgs(this.txBlock, sources);\n return this.txBlock.mergeCoins(destinationObject, sourceObjects);\n }\n publish(...args: Parameters<(typeof Transactions)['Publish']>) {\n return this.txBlock.publish(...args);\n }\n upgrade(...args: Parameters<(typeof Transactions)['Upgrade']>) {\n return this.txBlock.upgrade(...args);\n }\n makeMoveVec(...args: Parameters<(typeof Transactions)['MakeMoveVec']>) {\n return this.txBlock.makeMoveVec(...args);\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(\n target: string,\n args: (SuiTxArg | SuiVecTxArg)[] = [],\n typeArgs: string[] = []\n ) {\n // a regex for pattern `${string}::${string}::${string}`\n const regex =\n /(?<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)\n throw new Error(\n 'Invalid target format. Expected `${string}::${string}::${string}`'\n );\n const convertedArgs = convertArgs(this.txBlock, 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 //======== enhance methods ============\n transferSuiToMany(recipients: string[], amounts: number[]) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n\n const tx = this.txBlock;\n const coins = tx.splitCoins(\n tx.gas,\n amounts.map((amount) => tx.pure(amount))\n );\n recipients.forEach((recipient, index) => {\n tx.transferObjects([coins[index]], tx.pure(recipient));\n });\n return this;\n }\n\n transferSui(recipient: string, amount: number) {\n return this.transferSuiToMany([recipient], [amount]);\n }\n\n takeAmountFromCoins(coins: SuiObjectArg[], amount: number) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, 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(\n tx.gas,\n amounts.map((m) => tx.pure(m))\n );\n }\n\n splitMultiCoins(coins: SuiObjectArg[], amounts: number[]) {\n const tx = this.txBlock;\n const coinObjects = convertArgs(this.txBlock, coins);\n const mergedCoin = coinObjects[0];\n if (coins.length > 1) {\n tx.mergeCoins(mergedCoin, coinObjects.slice(1));\n }\n const splitedCoins = tx.splitCoins(\n mergedCoin,\n amounts.map((m) => tx.pure(m))\n );\n return { splitedCoins, mergedCoin };\n }\n\n transferCoinToMany(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipients: string[],\n amounts: number[]\n ) {\n // require recipients.length === amounts.length\n if (recipients.length !== amounts.length) {\n throw new Error(\n 'transferSuiToMany: recipients.length !== amounts.length'\n );\n }\n const tx = this.txBlock;\n const { splitedCoins, mergedCoin } = this.splitMultiCoins(\n inputCoins,\n amounts\n );\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(\n inputCoins: SuiObjectArg[],\n sender: string,\n recipient: string,\n amount: number\n ) {\n return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);\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: [\n tx.object(SUI_SYSTEM_STATE_OBJECT_ID),\n stakeCoin,\n tx.pure(validatorAddr),\n ],\n });\n return tx;\n }\n}\n","import {\n normalizeSuiObjectId,\n TransactionArgument,\n TransactionBlock,\n} from '@mysten/sui.js';\nimport { SuiTxArg, SuiInputTypes } from './types';\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\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 */\nexport function makeVecParam(\n txBlock: TransactionBlock,\n args: SuiTxArg[],\n type?: SuiInputTypes\n) {\n if (args.length === 0)\n 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'\n ? txBlock.object(normalizeSuiObjectId(arg))\n : (arg as any)\n );\n return txBlock.makeMoveVec({ objects });\n } else {\n const vecType = type || defaultSuiType;\n return txBlock.pure(args, `vector<${vecType}>`);\n }\n}\n\nexport function isMoveVecArg(arg: any) {\n const isFullMoveVecArg =\n arg && arg.value && Array.isArray(arg.value) && arg.vecType;\n const isSimpleMoveVecArg = Array.isArray(arg);\n return isFullMoveVecArg || isSimpleMoveVecArg;\n}\n\nexport function convertArgs(\n txBlock: TransactionBlock,\n args: any[]\n): 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 txBlock.object(normalizeSuiObjectId(arg));\n } else if (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 ? makeVecParam(txBlock, arg.value, vecType)\n : makeVecParam(txBlock, arg);\n } else if (typeof arg !== 'object') {\n // Other basic types such as string, number, boolean are converted to pure value\n return 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"],"mappings":";AAAA;AAAA,EACE,oBAAAA;AAAA,EACA;AAAA,EACA,8BAAAC;AAAA,OACK;;;ACEP;AAAA,EACE;AAAA,EACA,oBAAAC;AAAA,OAGK;;;ACXP,SAAS,kBAAAC,uBAAsB;;;ACA/B,SAAS,sBAAsB;AAOxB,IAAM,sBAAsB,CACjC,mBAAqC,CAAC,MACnC;AACH,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,aAAa;AAAA,IACb,eAAe;AAAA,EACjB,IAAI;AACJ,SAAO,cAAc,iBAAiB,aAAa,IAAI,MAAM;AAC/D;AAeO,IAAM,aAAa,CACxB,WACA,mBAAqC,CAAC,MACnC;AACH,QAAM,aAAa,oBAAoB,gBAAgB;AACvD,SAAO,eAAe,cAAc,WAAW,UAAU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A;AACA,YAAQ,SAAS,KAAK,eAAe;AACrC,UAAM,QAAQ,MAAM,KAAK,YAAY,YAAY,OAAO,QAAQ,QAAQ;AACxE,WAAO,MAAM,IAAI,CAAC,MAAM,EAAE,QAAQ;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SACJ,QACA,eACA,kBACA;AACA,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,WACJ,IACA,kBAC4B;AAC5B,SAAK,cAAc,aAAa,GAAG,UAAU;AAC7C,WAAO,KAAK,YAAY,SAAS,2BAA2B;AAAA,MAC1D,kBAAkB;AAAA,MAClB,QAAQ,KAAK,WAAW,gBAAgB;AAAA,IAC1C,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,KAAK,UAAkB,aAAqB,SAAa,kBAAqC;AAClG,UAAM,KAAK,IAAIC,kBAAiB;AAChC,OAAG,SAAS;AAAA,MACV,QAAQ,GAAG,qBAAqB;AAAA,MAChC,WAAW;AAAA;AAAA,QAET,GAAG,KAAK,OAAO;AAAA,MACjB;AAAA,IACF,CAAC;AACD,WAAO,KAAK,eAAe,IAAI,gBAAgB;AAAA,EACjD;AAEF;","names":["TransactionBlock","SUI_SYSTEM_STATE_OBJECT_ID","TransactionBlock","Ed25519Keypair","Ed25519Keypair","JsonRpcProvider","JsonRpcProvider","TransactionBlock","TransactionBlock","TransactionBlock"]}
@@ -0,0 +1 @@
1
+ export declare const generateMnemonic: (numberOfWords?: 12 | 24) => string;
@@ -0,0 +1,35 @@
1
+ import { Ed25519Keypair } from '@mysten/sui.js';
2
+ import type { AccountMangerParams, DerivePathParams } from './types';
3
+ export declare class SuiAccountManager {
4
+ private mnemonics;
5
+ private secretKey;
6
+ currentKeyPair: Ed25519Keypair;
7
+ currentAddress: string;
8
+ /**
9
+ * Support the following ways to init the SuiToolkit:
10
+ * 1. mnemonics
11
+ * 2. secretKey (base64 or hex)
12
+ * If none of them is provided, will generate a random mnemonics with 24 words.
13
+ *
14
+ * @param mnemonics, 12 or 24 mnemonics words, separated by space
15
+ * @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
16
+ */
17
+ constructor({ mnemonics, secretKey }?: AccountMangerParams);
18
+ /**
19
+ * if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.
20
+ * else:
21
+ * it will generate keyPair from the mnemonic with the given derivePathParams.
22
+ */
23
+ getKeyPair(derivePathParams?: DerivePathParams): Ed25519Keypair;
24
+ /**
25
+ * if derivePathParams is not provided or mnemonics is empty, it will return the currentAddress.
26
+ * else:
27
+ * it will generate address from the mnemonic with the given derivePathParams.
28
+ */
29
+ getAddress(derivePathParams?: DerivePathParams): string;
30
+ /**
31
+ * Switch the current account with the given derivePathParams.
32
+ * This is only useful when the mnemonics is provided. For secretKey mode, it will always use the same account.
33
+ */
34
+ switchAccount(derivePathParams: DerivePathParams): void;
35
+ }
@@ -0,0 +1,21 @@
1
+ import { Ed25519Keypair } from '@mysten/sui.js';
2
+ import type { DerivePathParams } from './types';
3
+ /**
4
+ * @description Get ed25519 derive path for SUI
5
+ * @param derivePathParams
6
+ */
7
+ export declare const getDerivePathForSUI: (derivePathParams?: DerivePathParams) => string;
8
+ /**
9
+ * the format is m/44'/784'/accountIndex'/${isExternal ? 1 : 0}'/addressIndex'
10
+ *
11
+ * accountIndex is the index of the account, default is 0.
12
+ *
13
+ * 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.
14
+ *
15
+ * addressIndex is the index of the address, default is 0. It's used to generate multiple addresses for one account.
16
+ *
17
+ * @description Get keypair from mnemonics and derive path
18
+ * @param mnemonics
19
+ * @param derivePathParams
20
+ */
21
+ export declare const getKeyPair: (mnemonics: string, derivePathParams?: DerivePathParams) => Ed25519Keypair;
@@ -0,0 +1,9 @@
1
+ export type AccountMangerParams = {
2
+ mnemonics?: string;
3
+ secretKey?: string;
4
+ };
5
+ export type DerivePathParams = {
6
+ accountIndex?: number;
7
+ isExternal?: boolean;
8
+ addressIndex?: number;
9
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @description This regular expression matches any string that contains only hexadecimal digits (0-9, A-F, a-f).
3
+ * @param str
4
+ */
5
+ export declare const isHex: (str: string) => boolean;
6
+ /**
7
+ * @description This regular expression matches any string that contains only base64 digits (0-9, A-Z, a-z, +, /, =).
8
+ * Note that the "=" signs at the end are optional padding characters that may be present in some base64 encoded strings.
9
+ * @param str
10
+ */
11
+ export declare const isBase64: (str: string) => boolean;
12
+ /**
13
+ * Convert a hex string to Uint8Array
14
+ * @param hexStr
15
+ */
16
+ export declare const fromHEX: (hexStr: string) => Uint8Array;
17
+ /**
18
+ * @description Convert a hex or base64 string to Uint8Array
19
+ */
20
+ export declare const hexOrBase64ToUint8Array: (str: string) => Uint8Array;
21
+ /**
22
+ * normalize a private key
23
+ * A private key is a 32-byte array.
24
+ * But there are two different formats for private keys:
25
+ * 1. A 32-byte array
26
+ * 2. A 64-byte array with the first 32 bytes being the private key and the last 32 bytes being the public key
27
+ * 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)
28
+ */
29
+ export declare const normalizePrivateKey: (key: Uint8Array) => Uint8Array;
@@ -0,0 +1,8 @@
1
+ import type { Connection } from '@mysten/sui.js';
2
+ import type { NetworkType } from './types';
3
+ /**
4
+ * @description Get the default fullnode url and faucet url for the given network type
5
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
6
+ * @returns { fullNode: string, websocket: string, faucet?: string }
7
+ */
8
+ export declare const getDefaultNetworkParams: (networkType?: NetworkType) => Connection;
@@ -0,0 +1,8 @@
1
+ import { JsonRpcProvider } from '@mysten/sui.js';
2
+ /**
3
+ * Request some SUI from faucet
4
+ * @param address
5
+ * @param provider
6
+ * @returns {Promise<boolean>}, return true if the request is successful
7
+ */
8
+ export declare const requestFaucet: (address: string, provider: JsonRpcProvider) => Promise<void>;
@@ -0,0 +1,40 @@
1
+ import { JsonRpcProvider } from '@mysten/sui.js';
2
+ import type { ObjectData, SuiRpcProviderParams } from './types';
3
+ export declare class SuiRpcProvider {
4
+ fullnodeUrl: string;
5
+ faucetUrl?: string;
6
+ provider: JsonRpcProvider;
7
+ /**
8
+ *
9
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
10
+ * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
11
+ * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
12
+ */
13
+ constructor({ fullnodeUrl, faucetUrl, networkType, }?: SuiRpcProviderParams);
14
+ /**
15
+ * Request some SUI from faucet
16
+ * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
17
+ */
18
+ requestFaucet(addr: string): Promise<void>;
19
+ getBalance(addr: string, coinType?: string): Promise<{
20
+ coinType: string;
21
+ coinObjectCount: number;
22
+ totalBalance: string;
23
+ lockedBalance: {
24
+ number?: number | undefined;
25
+ epochId?: number | undefined;
26
+ };
27
+ }>;
28
+ getObjects(ids: string[]): Promise<ObjectData[]>;
29
+ /**
30
+ * @description Select coins that add up to the given amount.
31
+ * @param addr the address of the owner
32
+ * @param amount the amount that is needed for the coin
33
+ * @param coinType the coin type, default is '0x2::SUI::SUI'
34
+ */
35
+ selectCoins(addr: string, amount: number, coinType?: string): Promise<{
36
+ objectId: string;
37
+ digest: string;
38
+ version: string;
39
+ }[]>;
40
+ }
@@ -0,0 +1,14 @@
1
+ import { DisplayFieldsResponse, ObjectContentFields } from '@mysten/sui.js';
2
+ export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
3
+ export type ObjectData = {
4
+ objectId: string;
5
+ objectType: string;
6
+ objectVersion: number;
7
+ objectDisplay: DisplayFieldsResponse;
8
+ objectFields: ObjectContentFields;
9
+ };
10
+ export type SuiRpcProviderParams = {
11
+ fullnodeUrl?: string;
12
+ faucetUrl?: string;
13
+ networkType?: NetworkType;
14
+ };