@twin.org/dlt-iota 0.0.3-next.13 → 0.0.3-next.15
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/dist/es/index.js +7 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/iota.js +104 -89
- package/dist/es/iota.js.map +1 -1
- package/dist/es/iotaIdentityUtils.js +2 -4
- package/dist/es/iotaIdentityUtils.js.map +1 -1
- package/dist/es/iotaSmartContractUtils.js +2 -1
- package/dist/es/iotaSmartContractUtils.js.map +1 -1
- package/dist/es/models/IAdminCapFields.js.map +1 -1
- package/dist/es/models/IGasStationExecuteResponse.js.map +1 -1
- package/dist/es/models/IIotaControllerCapInfo.js.map +1 -1
- package/dist/es/models/IIotaResponseOptions.js.map +1 -1
- package/dist/es/models/IMigrationStateFields.js.map +1 -1
- package/dist/es/models/ISmartContractObject.js.map +1 -1
- package/dist/es/models/ITransactionSigner.js +2 -0
- package/dist/es/models/ITransactionSigner.js.map +1 -0
- package/dist/es/vaultJwkStorage.js +71 -0
- package/dist/es/vaultJwkStorage.js.map +1 -0
- package/dist/es/vaultJwtSigner.js +49 -0
- package/dist/es/vaultJwtSigner.js.map +1 -0
- package/dist/es/vaultSigner.js +60 -0
- package/dist/es/vaultSigner.js.map +1 -0
- package/dist/es/vaultTransactionSigner.js +74 -0
- package/dist/es/vaultTransactionSigner.js.map +1 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/iota.d.ts +13 -28
- package/dist/types/iotaIdentityUtils.d.ts +2 -4
- package/dist/types/iotaSmartContractUtils.d.ts +0 -1
- package/dist/types/models/IAdminCapFields.d.ts +2 -2
- package/dist/types/models/IGasStationExecuteResponse.d.ts +1 -3
- package/dist/types/models/IIotaControllerCapInfo.d.ts +3 -6
- package/dist/types/models/IIotaResponseOptions.d.ts +1 -1
- package/dist/types/models/IMigrationStateFields.d.ts +2 -2
- package/dist/types/models/ISmartContractObject.d.ts +2 -2
- package/dist/types/models/ITransactionSigner.d.ts +27 -0
- package/dist/types/vaultJwkStorage.d.ts +50 -0
- package/dist/types/vaultJwtSigner.d.ts +26 -0
- package/dist/types/vaultSigner.d.ts +32 -0
- package/dist/types/vaultTransactionSigner.d.ts +39 -0
- package/docs/changelog.md +15 -0
- package/docs/reference/classes/Iota.md +30 -82
- package/docs/reference/classes/IotaIdentityUtils.md +2 -4
- package/docs/reference/classes/IotaSmartContractUtils.md +0 -1
- package/docs/reference/classes/VaultJwtSigner.md +71 -0
- package/docs/reference/classes/VaultSigner.md +106 -0
- package/docs/reference/classes/VaultTransactionSigner.md +122 -0
- package/docs/reference/index.md +4 -0
- package/docs/reference/interfaces/IAdminCapFields.md +2 -2
- package/docs/reference/interfaces/IGasStationExecuteResponse.md +1 -3
- package/docs/reference/interfaces/IIotaControllerCapInfo.md +3 -6
- package/docs/reference/interfaces/IIotaResponseOptions.md +1 -1
- package/docs/reference/interfaces/IMigrationStateFields.md +2 -2
- package/docs/reference/interfaces/ISmartContractObject.md +2 -2
- package/docs/reference/interfaces/ITransactionSigner.md +67 -0
- package/locales/en.json +5 -1
- package/package.json +3 -3
package/dist/es/iota.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iota.js","sourceRoot":"","sources":["../../src/iota.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,YAAY,EAEZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM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a,CAAC,OAAO,CAAC,UAAU,CAAC;oBACvD,SAAS,EAAE,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC;iBACrD,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,cAAc,CAAC,SAAS,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAC/D,CAAC;QAED,OAAO,YAAY,CAAC;IACrB,CAAC;IAED;;;;;;;;OAQG;IACK,MAAM,CAAC,oBAAoB,CAClC,QAAgB,EAChB,YAAoB,EACpB,QAAiB,EACjB,YAAoB;QAEpB,OAAO,GAAG,QAAQ,YAAY,YAAY,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAClH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { IotaClient } from \"@iota/iota-sdk/client\";\nimport { requestIotaFromFaucetV0 } from \"@iota/iota-sdk/faucet\";\nimport { Ed25519Keypair } from \"@iota/iota-sdk/keypairs/ed25519\";\nimport { Transaction } from \"@iota/iota-sdk/transactions\";\nimport {\n\tBaseError,\n\tCoerce,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tStringHelper,\n\ttype IError\n} from \"@twin.org/core\";\nimport { Bip39, Bip44, Blake2b, KeyType } from \"@twin.org/crypto\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IVaultConnector } from \"@twin.org/vault-models\";\nimport { FetchHelper, HttpMethod } from \"@twin.org/web\";\nimport type { IGasReservationResult } from \"./models/IGasReservationResult.js\";\nimport type { IGasStationConfig } from \"./models/IGasStationConfig.js\";\nimport type { IGasStationExecuteResponse } from \"./models/IGasStationExecuteResponse.js\";\nimport type { IGasStationReserveGasResponse } from \"./models/IGasStationReserveGasResponse.js\";\nimport type { IIotaClient } from \"./models/IIotaClient.js\";\nimport type { IIotaConfig } from \"./models/IIotaConfig.js\";\nimport type { IIotaDryRun } from \"./models/IIotaDryRun.js\";\nimport type { IIotaResponseOptions } from \"./models/IIotaResponseOptions.js\";\nimport type { IIotaTransaction } from \"./models/IIotaTransaction.js\";\nimport type { IIotaTransactionBlockResponse } from \"./models/IIotaTransactionBlockResponse.js\";\n\n/**\n * Class for performing operations on IOTA.\n */\nexport class Iota {\n\t/**\n\t * Default name for the mnemonic secret.\n\t */\n\tpublic static readonly DEFAULT_MNEMONIC_SECRET_NAME: string = \"mnemonic\";\n\n\t/**\n\t * Default name for the seed secret.\n\t */\n\tpublic static readonly DEFAULT_SEED_SECRET_NAME: string = \"seed\";\n\n\t/**\n\t * Default coin type.\n\t */\n\tpublic static readonly DEFAULT_COIN_TYPE: number = 4218;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Iota>();\n\n\t/**\n\t * Default scan range.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_SCAN_RANGE: number = 1000;\n\n\t/**\n\t * Default pre-calculation chunk size.\n\t * @internal\n\t */\n\tprivate static readonly _PRE_CALC_CHUNK_SIZE: number = 25;\n\n\t/**\n\t * Default inclusion timeout.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_INCLUSION_TIMEOUT: number = 60;\n\n\t/**\n\t * Default gas budget for all transactions (including sponsored and direct).\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_GAS_BUDGET: number = 50000000;\n\n\t/**\n\t * Default gas reservation duration.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_GAS_RESERVATION_DURATION: number = 60;\n\n\t/**\n\t * Create a new IOTA client.\n\t * @param config The configuration.\n\t * @returns The client instance.\n\t */\n\tpublic static createClient(config: IIotaConfig): IIotaClient {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.object(Iota.CLASS_NAME, nameof(config.clientOptions), config.clientOptions);\n\t\tGuards.string(Iota.CLASS_NAME, nameof(config.clientOptions.url), config.clientOptions.url);\n\n\t\treturn new IotaClient(config.clientOptions);\n\t}\n\n\t/**\n\t * Create configuration using defaults where necessary.\n\t * @param config The configuration to populate.\n\t */\n\tpublic static populateConfig(config: IIotaConfig): void {\n\t\tGuards.object<IIotaConfig[\"clientOptions\"]>(\n\t\t\tIota.CLASS_NAME,\n\t\t\tnameof(config.clientOptions),\n\t\t\tconfig.clientOptions\n\t\t);\n\n\t\tconfig.vaultMnemonicId ??= Iota.DEFAULT_MNEMONIC_SECRET_NAME;\n\t\tconfig.vaultSeedId ??= Iota.DEFAULT_SEED_SECRET_NAME;\n\t\tconfig.coinType ??= Iota.DEFAULT_COIN_TYPE;\n\t\tconfig.inclusionTimeoutSeconds ??= Iota._DEFAULT_INCLUSION_TIMEOUT;\n\t}\n\n\t/**\n\t * Store a mnemonic in the vault, derive and store the seed, and pre-cache the first keypair chunk.\n\t * @param vaultConnector The vault connector.\n\t * @param config The configuration.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param mnemonic The mnemonic to store, if undefined a new one will be generated and returned.\n\t * @param accountIndex The account index to pre-cache.\n\t * @returns The mnemonic that was stored.\n\t */\n\tpublic static async storeMnemonic(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: IIotaConfig,\n\t\tidentity: string,\n\t\tmnemonic: string | undefined,\n\t\taccountIndex: number\n\t): Promise<string> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(vaultConnector), vaultConnector);\n\t\tGuards.object<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(accountIndex), accountIndex);\n\n\t\tconst mnemonicToStore = mnemonic ?? Bip39.randomMnemonic();\n\n\t\tawait vaultConnector.setSecret(\n\t\t\tIota.buildMnemonicKey(identity, config.vaultMnemonicId),\n\t\t\tmnemonicToStore\n\t\t);\n\n\t\tconst seed = Bip39.mnemonicToSeed(mnemonicToStore);\n\t\tawait vaultConnector.setSecret(\n\t\t\tIota.buildSeedKey(identity, config.vaultSeedId),\n\t\t\tConverter.bytesToBase64(seed)\n\t\t);\n\n\t\tawait Iota.buildKeyPairRange(vaultConnector, config, identity, accountIndex, false, 0);\n\n\t\treturn mnemonicToStore;\n\t}\n\n\t/**\n\t * Derive an address from a public key.\n\t * @param publicKey The public key to derive the address from.\n\t * @returns The derived address.\n\t */\n\tpublic static publicKeyToAddress(publicKey: Uint8Array): string {\n\t\treturn Converter.bytesToHex(Blake2b.sum256(publicKey), true);\n\t}\n\n\t/**\n\t * Get address for the identity.\n\t * @param vaultConnector The vault connector.\n\t * @param config The configuration.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index to get the addresses for.\n\t * @param startAddressIndex The start index for the addresses.\n\t * @param isInternal Whether the addresses are internal.\n\t * @returns The address.\n\t */\n\tpublic static async getAddress(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: Pick<IIotaConfig, \"coinType\" | \"vaultMnemonicId\" | \"vaultSeedId\">,\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tstartAddressIndex: number,\n\t\tisInternal?: boolean\n\t): Promise<string> {\n\t\tconst addresses = await Iota.getAddresses(\n\t\t\tvaultConnector,\n\t\t\tconfig,\n\t\t\tidentity,\n\t\t\taccountIndex,\n\t\t\tstartAddressIndex,\n\t\t\t1,\n\t\t\tisInternal\n\t\t);\n\t\treturn addresses[0];\n\t}\n\n\t/**\n\t * Get addresses for the identity.\n\t * @param vaultConnector The vault connector.\n\t * @param config The configuration.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index to get the addresses for.\n\t * @param startAddressIndex The start index for the addresses.\n\t * @param count The number of addresses to generate.\n\t * @param isInternal Whether the addresses are internal.\n\t * @returns The list of addresses.\n\t */\n\tpublic static async getAddresses(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: Pick<IIotaConfig, \"coinType\" | \"vaultMnemonicId\" | \"vaultSeedId\">,\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tstartAddressIndex: number,\n\t\tcount: number,\n\t\tisInternal?: boolean\n\t): Promise<string[]> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(vaultConnector), vaultConnector);\n\t\tGuards.object<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(accountIndex), accountIndex);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(startAddressIndex), startAddressIndex);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(count), count);\n\n\t\tconst addresses: string[] = [];\n\t\tconst internal = isInternal ?? false;\n\t\tlet currentIndex = startAddressIndex;\n\n\t\twhile (addresses.length < count) {\n\t\t\tconst chunkStart =\n\t\t\t\tMath.floor(currentIndex / Iota._PRE_CALC_CHUNK_SIZE) * Iota._PRE_CALC_CHUNK_SIZE;\n\t\t\tconst keyPairs = await Iota.buildKeyPairRange(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountIndex,\n\t\t\t\tinternal,\n\t\t\t\tchunkStart\n\t\t\t);\n\t\t\tconst chunk = keyPairs.map(kp =>\n\t\t\t\tIota.publicKeyToAddress(Converter.base64ToBytes(kp.publicKey))\n\t\t\t);\n\t\t\tconst offsetInChunk = currentIndex - chunkStart;\n\t\t\tconst remaining = count - addresses.length;\n\t\t\taddresses.push(...chunk.slice(offsetInChunk, offsetInChunk + remaining));\n\t\t\tcurrentIndex = chunkStart + Iota._PRE_CALC_CHUNK_SIZE;\n\t\t}\n\n\t\treturn addresses;\n\t}\n\n\t/**\n\t * Get a key pair for the specified index.\n\t * @param vaultConnector The vault connector.\n\t * @param config The configuration.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index to get the key pair for.\n\t * @param addressIndex The address index to get the key pair for.\n\t * @param isInternal Whether the address is internal.\n\t * @returns The key pair containing private key and public key.\n\t */\n\tpublic static async getKeyPair(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: IIotaConfig,\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\taddressIndex: number,\n\t\tisInternal?: boolean\n\t): Promise<{\n\t\tprivateKey: Uint8Array;\n\t\tpublicKey: Uint8Array;\n\t}> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(vaultConnector), vaultConnector);\n\t\tGuards.object<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(accountIndex), accountIndex);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(addressIndex), addressIndex);\n\n\t\tconst internal = isInternal ?? false;\n\t\tconst chunkStart =\n\t\t\tMath.floor(addressIndex / Iota._PRE_CALC_CHUNK_SIZE) * Iota._PRE_CALC_CHUNK_SIZE;\n\t\tconst keyPairs = await Iota.buildKeyPairRange(\n\t\t\tvaultConnector,\n\t\t\tconfig,\n\t\t\tidentity,\n\t\t\taccountIndex,\n\t\t\tinternal,\n\t\t\tchunkStart\n\t\t);\n\t\tconst offsetInChunk = addressIndex - chunkStart;\n\t\tconst entry = keyPairs[offsetInChunk];\n\n\t\treturn {\n\t\t\tprivateKey: Converter.base64ToBytes(entry.privateKey),\n\t\t\tpublicKey: Converter.base64ToBytes(entry.publicKey)\n\t\t};\n\t}\n\n\t/**\n\t * Create a new transaction instance.\n\t * @returns A new transaction instance.\n\t */\n\tpublic static createTransaction(): IIotaTransaction {\n\t\treturn new Transaction();\n\t}\n\n\t/**\n\t * Prepare and post a transaction.\n\t * @param config The configuration.\n\t * @param vaultConnector The vault connector.\n\t * @param logging The logging component.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param client The client instance.\n\t * @param source The source address.\n\t * @param amount The amount to transfer.\n\t * @param recipient The recipient address.\n\t * @param options The transaction options.\n\t * @returns The transaction result.\n\t */\n\tpublic static async prepareAndPostValueTransaction(\n\t\tconfig: IIotaConfig,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tidentity: string,\n\t\tclient: IIotaClient,\n\t\tsource: string,\n\t\tamount: bigint,\n\t\trecipient: string,\n\t\toptions?: IIotaResponseOptions\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\ttry {\n\t\t\tconst txb = new Transaction();\n\t\t\tconst [coin] = txb.splitCoins(txb.gas, [txb.pure.u64(amount)]);\n\t\t\ttxb.transferObjects([coin], txb.pure.address(recipient));\n\n\t\t\t// Check if gas station configuration is present\n\t\t\tif (Is.object<IGasStationConfig>(config.gasStation)) {\n\t\t\t\treturn await Iota.prepareAndPostGasStationTransaction(\n\t\t\t\t\tconfig,\n\t\t\t\t\tvaultConnector,\n\t\t\t\t\tidentity,\n\t\t\t\t\tclient,\n\t\t\t\t\tsource,\n\t\t\t\t\ttxb\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst result = await Iota.prepareAndPostTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tlogging,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\tsource,\n\t\t\t\ttxb,\n\t\t\t\toptions\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"valueTransactionFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Prepare and post a transaction.\n\t * @param config The configuration.\n\t * @param vaultConnector The vault connector.\n\t * @param logging The logging component.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param client The client instance.\n\t * @param owner The owner of the address.\n\t * @param transaction The transaction to execute.\n\t * @param options The transaction options.\n\t * @returns The transaction response.\n\t */\n\tpublic static async prepareAndPostTransaction(\n\t\tconfig: IIotaConfig,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tidentity: string,\n\t\tclient: IIotaClient,\n\t\towner: string,\n\t\ttransaction: IIotaTransaction,\n\t\toptions?: IIotaResponseOptions\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\t// Check if gas station configuration is present\n\t\tif (Is.object<IGasStationConfig>(config.gasStation)) {\n\t\t\treturn Iota.prepareAndPostGasStationTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\towner,\n\t\t\t\ttransaction,\n\t\t\t\toptions\n\t\t\t);\n\t\t}\n\n\t\t// Traditional transaction flow\n\t\t// Dry run the transaction if cost logging is enabled to get the gas and storage costs\n\t\tif (Is.stringValue(options?.dryRunLabel)) {\n\t\t\tawait Iota.dryRunTransaction(client, logging, transaction, owner, options.dryRunLabel);\n\t\t}\n\n\t\tconst addressKeyPair = await Iota.findAddress(vaultConnector, config, identity, owner, 0);\n\t\tconst keypair = Ed25519Keypair.fromSecretKey(addressKeyPair.privateKey);\n\n\t\ttry {\n\t\t\tconst response = await client.signAndExecuteTransaction({\n\t\t\t\ttransaction,\n\t\t\t\tsigner: keypair,\n\t\t\t\trequestType: \"WaitForLocalExecution\",\n\t\t\t\toptions: {\n\t\t\t\t\tshowEffects: options?.showEffects ?? true,\n\t\t\t\t\tshowEvents: options?.showEvents ?? true,\n\t\t\t\t\tshowObjectChanges: options?.showObjectChanges ?? true\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (options?.waitForConfirmation ?? true) {\n\t\t\t\t// Wait for transaction to be indexed and available over API\n\t\t\t\tconst confirmedTransaction = await Iota.waitForTransactionConfirmation(\n\t\t\t\t\tclient,\n\t\t\t\t\tresponse.digest,\n\t\t\t\t\tconfig,\n\t\t\t\t\t{\n\t\t\t\t\t\tshowEffects: options?.showEffects ?? true,\n\t\t\t\t\t\tshowEvents: options?.showEvents ?? true,\n\t\t\t\t\t\tshowObjectChanges: options?.showObjectChanges ?? true\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn confirmedTransaction;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"transactionFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Find the address in the seed.\n\t * @param vaultConnector The vault connector to use.\n\t * @param config The configuration to use.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The address to find.\n\t * @param accountIndex The account index to search.\n\t * @param isInternal Whether to search internal addresses.\n\t * @param startScanIndex The address index to start scanning from.\n\t * @param maxScanRange The maximum range to scan.\n\t * @returns The address key pair.\n\t * @throws Error if the address is not found.\n\t */\n\tpublic static async findAddress(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: IIotaConfig,\n\t\tidentity: string,\n\t\taddress: string,\n\t\taccountIndex: number,\n\t\tisInternal?: boolean,\n\t\tstartScanIndex?: number,\n\t\tmaxScanRange?: number\n\t): Promise<{\n\t\taddress: string;\n\t\tprivateKey: Uint8Array;\n\t\tpublicKey: Uint8Array;\n\t}> {\n\t\tconst internal = isInternal ?? false;\n\t\tconst startIndex = startScanIndex ?? 0;\n\t\tconst scanRange = maxScanRange ?? config.maxAddressScanRange ?? Iota._DEFAULT_SCAN_RANGE;\n\n\t\tfor (\n\t\t\tlet chunkStart = startIndex;\n\t\t\tchunkStart < startIndex + scanRange;\n\t\t\tchunkStart += Iota._PRE_CALC_CHUNK_SIZE\n\t\t) {\n\t\t\tconst keyPairs = await Iota.buildKeyPairRange(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountIndex,\n\t\t\t\tinternal,\n\t\t\t\tchunkStart\n\t\t\t);\n\t\t\tconst offsetInChunk = keyPairs.findIndex(\n\t\t\t\tkp => Iota.publicKeyToAddress(Converter.base64ToBytes(kp.publicKey)) === address\n\t\t\t);\n\t\t\tif (offsetInChunk !== -1) {\n\t\t\t\tconst entry = keyPairs[offsetInChunk];\n\t\t\t\treturn {\n\t\t\t\t\taddress,\n\t\t\t\t\tprivateKey: Converter.base64ToBytes(entry.privateKey),\n\t\t\t\t\tpublicKey: Converter.base64ToBytes(entry.publicKey)\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tthrow new GeneralError(Iota.CLASS_NAME, \"addressNotFound\", { address });\n\t}\n\n\t/**\n\t * Extract error from SDK payload.\n\t * Errors from the IOTA SDK are usually not JSON strings but objects.\n\t * @param error The error to extract.\n\t * @returns The extracted error.\n\t */\n\tpublic static extractPayloadError(error: unknown): IError {\n\t\tif (Is.object<{ code?: string; message?: string; inner?: unknown; cause?: unknown }>(error)) {\n\t\t\tif (!Is.empty(error.inner)) {\n\t\t\t\terror.inner = Iota.extractPayloadError(error.inner);\n\t\t\t}\n\t\t\tif (!Is.empty(error.cause)) {\n\t\t\t\terror.cause = Iota.extractPayloadError(error.cause);\n\t\t\t}\n\n\t\t\tif (error.code === \"InsufficientGas\") {\n\t\t\t\treturn new GeneralError(Iota.CLASS_NAME, \"insufficientFunds\");\n\t\t\t} else if (error.message?.startsWith(\"ErrorObject\")) {\n\t\t\t\tconst msg = /message: \"(.*)\"/.exec(error.message);\n\t\t\t\tif (msg && msg.length > 1) {\n\t\t\t\t\terror = msg[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst baseError = BaseError.fromError(error);\n\t\tif (baseError.name === \"Base\" && !Is.stringValue(baseError.source)) {\n\t\t\tbaseError.name = \"IOTA\";\n\t\t\tbaseError.source = Iota.CLASS_NAME;\n\t\t}\n\t\treturn baseError;\n\t}\n\n\t/**\n\t * Check if the package exists on the network.\n\t * @param client The client to use.\n\t * @param packageId The package ID to check.\n\t * @returns True if the package exists, false otherwise.\n\t */\n\tpublic static async packageExistsOnNetwork(\n\t\tclient: IIotaClient,\n\t\tpackageId: string\n\t): Promise<boolean> {\n\t\ttry {\n\t\t\tconst packageObject = await client.getObject({\n\t\t\t\tid: packageId,\n\t\t\t\toptions: {\n\t\t\t\t\tshowType: true\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (\"error\" in packageObject) {\n\t\t\t\tif (packageObject?.error?.code === \"notExists\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tthrow new GeneralError(Iota.CLASS_NAME, \"packageObjectError\", {\n\t\t\t\t\tpackageId,\n\t\t\t\t\terror: packageObject.error\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"packageNotFoundOnNetwork\",\n\t\t\t\t{\n\t\t\t\t\tpackageId\n\t\t\t\t},\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Dry run a transaction and log the results.\n\t * @param client The IOTA client.\n\t * @param logging The logging component.\n\t * @param txb The transaction to dry run.\n\t * @param sender The sender address.\n\t * @param operation The operation to log.\n\t * @returns void.\n\t */\n\tpublic static async dryRunTransaction(\n\t\tclient: IIotaClient,\n\t\tlogging: ILoggingComponent | undefined,\n\t\ttxb: IIotaTransaction,\n\t\tsender: string,\n\t\toperation: string\n\t): Promise<IIotaDryRun> {\n\t\ttry {\n\t\t\ttxb.setSender(sender);\n\n\t\t\tconst builtTx = await txb.build({\n\t\t\t\tclient,\n\t\t\t\tonlyTransactionKind: false\n\t\t\t});\n\n\t\t\tconst dryRunResult = await client.dryRunTransactionBlock({\n\t\t\t\ttransactionBlock: builtTx\n\t\t\t});\n\n\t\t\tif (dryRunResult.effects.status?.status !== \"success\") {\n\t\t\t\tthrow new GeneralError(Iota.CLASS_NAME, \"dryRunFailed\", {\n\t\t\t\t\terror: dryRunResult.effects?.status?.error\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst result = {\n\t\t\t\tstatus: dryRunResult.effects.status.status,\n\t\t\t\tcosts: {\n\t\t\t\t\tcomputationCost: dryRunResult.effects.gasUsed.computationCost,\n\t\t\t\t\tcomputationCostBurned: dryRunResult.effects.gasUsed.computationCostBurned,\n\t\t\t\t\tstorageCost: dryRunResult.effects.gasUsed.storageCost,\n\t\t\t\t\tstorageRebate: dryRunResult.effects.gasUsed.storageRebate,\n\t\t\t\t\tnonRefundableStorageFee: dryRunResult.effects.gasUsed.nonRefundableStorageFee\n\t\t\t\t},\n\t\t\t\tevents: dryRunResult.events ?? [],\n\t\t\t\tbalanceChanges: dryRunResult.balanceChanges ?? [],\n\t\t\t\tobjectChanges: dryRunResult.objectChanges ?? []\n\t\t\t};\n\n\t\t\tawait logging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: Iota.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"transactionCosts\",\n\t\t\t\tdata: {\n\t\t\t\t\toperation,\n\t\t\t\t\tcost: JSON.stringify(result)\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.isErrorName(error, GeneralError.CLASS_NAME)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"dryRunFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Wait for a transaction to be indexed and available over the API.\n\t * @param client The IOTA client instance.\n\t * @param digest The digest of the transaction to wait for.\n\t * @param config The IOTA configuration.\n\t * @param options Additional options for the transaction query.\n\t * @param options.showEffects Whether to show effects.\n\t * @param options.showEvents Whether to show events.\n\t * @param options.showObjectChanges Whether to show object changes.\n\t * @returns The confirmed transaction response.\n\t */\n\tpublic static async waitForTransactionConfirmation(\n\t\tclient: IIotaClient,\n\t\tdigest: string,\n\t\tconfig: IIotaConfig,\n\t\toptions?: {\n\t\t\tshowEffects?: boolean;\n\t\t\tshowEvents?: boolean;\n\t\t\tshowObjectChanges?: boolean;\n\t\t}\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\tconst timeoutMs = (config.inclusionTimeoutSeconds ?? Iota._DEFAULT_INCLUSION_TIMEOUT) * 1000;\n\n\t\treturn client.waitForTransaction({\n\t\t\tdigest,\n\t\t\ttimeout: timeoutMs,\n\t\t\toptions: {\n\t\t\t\tshowEffects: options?.showEffects ?? true,\n\t\t\t\tshowEvents: options?.showEvents ?? true,\n\t\t\t\tshowObjectChanges: options?.showObjectChanges ?? true\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Check if the error is an abort error with a specific code.\n\t * @param error The error to check.\n\t * @param code The error code to check for.\n\t * @returns True if the error is an abort error, false otherwise.\n\t */\n\tpublic static isAbortError(error: unknown, code: number): boolean {\n\t\tconst err = BaseError.fromError(error);\n\t\tif (Is.stringValue(err.properties?.error)) {\n\t\t\tconst abortCodeMatch = /abort code\\s*:\\s*(\\d+)/i.exec(err.properties.error);\n\t\t\treturn abortCodeMatch?.[1] === code.toString();\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Extracts the abort code from a transaction result if the transaction was aborted.\n\t * @param response The transaction result to extract the abort code from.\n\t * @returns The abort code if the transaction was aborted, or undefined if it was not an abort error or the code could not be extracted.\n\t */\n\tpublic static extractAbortCode(response: IIotaTransactionBlockResponse): number | undefined {\n\t\tif (\n\t\t\tresponse.effects?.status?.status === \"failure\" &&\n\t\t\tIs.stringValue(response.effects.status.error)\n\t\t) {\n\t\t\tconst match = /abort code: (\\d+)/.exec(response.effects.status.error);\n\t\t\tif (match) {\n\t\t\t\treturn Coerce.integer(match[1]);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Prepare and post a transaction using gas station sponsoring.\n\t * @param config The configuration.\n\t * @param vaultConnector The vault connector.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param client The client instance.\n\t * @param owner The owner of the address.\n\t * @param transaction The transaction to execute.\n\t * @param options Response options including confirmation behavior.\n\t * @returns The transaction response.\n\t */\n\tpublic static async prepareAndPostGasStationTransaction(\n\t\tconfig: IIotaConfig,\n\t\tvaultConnector: IVaultConnector,\n\t\tidentity: string,\n\t\tclient: IIotaClient,\n\t\towner: string,\n\t\ttransaction: IIotaTransaction,\n\t\toptions?: IIotaResponseOptions\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(config.gasStation), config.gasStation);\n\n\t\ttry {\n\t\t\t// Reserve gas from the gas station\n\t\t\tconst gasReservation = await Iota.reserveGas(config);\n\n\t\t\t// Set transaction parameters for sponsoring\n\t\t\ttransaction.setSender(owner);\n\t\t\ttransaction.setGasOwner(gasReservation.sponsorAddress);\n\t\t\ttransaction.setGasPayment(gasReservation.gasCoins);\n\t\t\ttransaction.setGasBudget(config.gasBudget ?? Iota._DEFAULT_GAS_BUDGET);\n\n\t\t\t// Build and sign transaction\n\t\t\tconst unsignedTxBytes = await transaction.build({ client });\n\n\t\t\t// Sign the transaction with the user's private key\n\t\t\tconst addressKeyPair = await Iota.findAddress(vaultConnector, config, identity, owner, 0);\n\t\t\tconst keypair = Ed25519Keypair.fromSecretKey(addressKeyPair.privateKey);\n\t\t\tconst signature = await keypair.signTransaction(unsignedTxBytes);\n\n\t\t\treturn await Iota.executeAndConfirmGasStationTransaction(\n\t\t\t\tconfig,\n\t\t\t\tclient,\n\t\t\t\tgasReservation.reservationId,\n\t\t\t\tunsignedTxBytes,\n\t\t\t\tsignature.signature,\n\t\t\t\toptions\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"gasStationTransactionFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Reserve gas from the gas station.\n\t * @param config The configuration containing gas station settings.\n\t * @returns The gas reservation result.\n\t */\n\tpublic static async reserveGas(config: IIotaConfig): Promise<IGasReservationResult> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(config.gasStation), config.gasStation);\n\n\t\tconst requestData = {\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\tgas_budget: config.gasBudget ?? Iota._DEFAULT_GAS_BUDGET,\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\treserve_duration_secs: config.gasReservationDuration ?? Iota._DEFAULT_GAS_RESERVATION_DURATION\n\t\t};\n\n\t\tconst baseUrl = StringHelper.trimTrailingSlashes(config.gasStation.gasStationUrl);\n\t\tconst result = await FetchHelper.fetchJson<typeof requestData, IGasStationReserveGasResponse>(\n\t\t\tIota.CLASS_NAME,\n\t\t\t`${baseUrl}/v1/reserve_gas`,\n\t\t\tHttpMethod.POST,\n\t\t\trequestData,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${config.gasStation.gasStationAuthToken}`\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\tconst apiResponse = result.result;\n\n\t\treturn {\n\t\t\tsponsorAddress: apiResponse.sponsor_address,\n\t\t\treservationId: apiResponse.reservation_id,\n\t\t\tgasCoins: apiResponse.gas_coins\n\t\t};\n\t}\n\n\t/**\n\t * Execute a sponsored transaction through the gas station.\n\t * @param config The configuration containing gas station settings.\n\t * @param reservationId The reservation ID from gas reservation.\n\t * @param transactionBytes The unsigned transaction bytes.\n\t * @param userSignature The user's signature.\n\t * @returns The transaction response.\n\t */\n\tpublic static async executeGasStationTransaction(\n\t\tconfig: IIotaConfig,\n\t\treservationId: number,\n\t\ttransactionBytes: Uint8Array,\n\t\tuserSignature: string\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\tGuards.object<IGasStationConfig>(Iota.CLASS_NAME, nameof(config.gasStation), config.gasStation);\n\n\t\tconst requestData = {\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\treservation_id: reservationId,\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\ttx_bytes: Converter.bytesToBase64(transactionBytes),\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\tuser_sig: userSignature\n\t\t};\n\n\t\tconst baseUrl = StringHelper.trimTrailingSlashes(config.gasStation.gasStationUrl);\n\t\tconst result = await FetchHelper.fetchJson<typeof requestData, IGasStationExecuteResponse>(\n\t\t\tIota.CLASS_NAME,\n\t\t\t`${baseUrl}/v1/execute_tx`,\n\t\t\tHttpMethod.POST,\n\t\t\trequestData,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${config.gasStation.gasStationAuthToken}`\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\tconst effectsData = result.effects;\n\n\t\t// Match IotaTransactionBlockResponse format\n\t\treturn {\n\t\t\tdigest: effectsData.transactionDigest,\n\t\t\teffects: effectsData as unknown,\n\t\t\tevents: [],\n\t\t\tobjectChanges: [],\n\t\t\tconfirmedLocalExecution: true\n\t\t} as unknown as IIotaTransactionBlockResponse;\n\t}\n\n\t/**\n\t * Execute and confirm a gas station transaction.\n\t * @param config The configuration containing gas station settings.\n\t * @param client The IOTA client for confirmation.\n\t * @param reservationId The reservation ID from gas reservation.\n\t * @param transactionBytes The unsigned transaction bytes.\n\t * @param userSignature The user's signature.\n\t * @param options Response options including confirmation behavior.\n\t * @returns The transaction response (confirmed if waitForConfirmation is true).\n\t */\n\tpublic static async executeAndConfirmGasStationTransaction(\n\t\tconfig: IIotaConfig,\n\t\tclient: IIotaClient,\n\t\treservationId: number,\n\t\ttransactionBytes: Uint8Array,\n\t\tuserSignature: string,\n\t\toptions?: IIotaResponseOptions\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\tGuards.object<IGasStationConfig>(Iota.CLASS_NAME, nameof(config.gasStation), config.gasStation);\n\n\t\tconst response = await Iota.executeGasStationTransaction(\n\t\t\tconfig,\n\t\t\treservationId,\n\t\t\ttransactionBytes,\n\t\t\tuserSignature\n\t\t);\n\n\t\tif (options?.waitForConfirmation ?? true) {\n\t\t\tconst confirmedTransaction = await Iota.waitForTransactionConfirmation(\n\t\t\t\tclient,\n\t\t\t\tresponse.digest,\n\t\t\t\tconfig,\n\t\t\t\t{\n\t\t\t\t\tshowEffects: options?.showEffects ?? true,\n\t\t\t\t\tshowEvents: options?.showEvents ?? true,\n\t\t\t\t\tshowObjectChanges: options?.showObjectChanges ?? true\n\t\t\t\t}\n\t\t\t);\n\n\t\t\treturn confirmedTransaction;\n\t\t}\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Fund an address with IOTA from the faucet.\n\t * @param config The configuration containing endpoint information.\n\t * @param faucetUrl The URL of the faucet to request funds from.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The address to fund.\n\t * @param timeoutInSeconds The timeout in seconds to wait for the funding to complete.\n\t * @returns The amount funded.\n\t */\n\tpublic static async fundAddress(\n\t\tconfig: IIotaConfig,\n\t\tfaucetUrl: string,\n\t\tidentity: string,\n\t\taddress: string,\n\t\ttimeoutInSeconds: number = 60\n\t): Promise<bigint> {\n\t\tGuards.objectValue<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(config.clientOptions.url), config.clientOptions.url);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(faucetUrl), faucetUrl);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(address), address);\n\n\t\ttry {\n\t\t\tconst initialBalance = await Iota.getBalance(config, address);\n\n\t\t\tconst response = await requestIotaFromFaucetV0({\n\t\t\t\thost: faucetUrl,\n\t\t\t\trecipient: address\n\t\t\t});\n\n\t\t\tif (response?.error) {\n\t\t\t\tthrow new GeneralError(Iota.CLASS_NAME, \"fundingFailed\", undefined, response.error);\n\t\t\t}\n\n\t\t\t// Poll for balance change\n\t\t\tconst numTries = Math.ceil(timeoutInSeconds / 5);\n\t\t\tfor (let i = 0; i < numTries; i++) {\n\t\t\t\tconst newBalance = await Iota.getBalance(config, address);\n\n\t\t\t\tif (newBalance > initialBalance) {\n\t\t\t\t\treturn newBalance - initialBalance;\n\t\t\t\t}\n\n\t\t\t\tif (i < numTries - 1) {\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, 5000));\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst payloadError = Iota.extractPayloadError(error);\n\t\t\tif (\n\t\t\t\tpayloadError.message.includes(\n\t\t\t\t\t\"Too many requests from this client have been sent to the faucet\"\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new GeneralError(\n\t\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\t\"faucetRateLimit\",\n\t\t\t\t\tundefined,\n\t\t\t\t\tIota.extractPayloadError(error)\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"fundingFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\n\t\treturn 0n;\n\t}\n\n\t/**\n\t * Ensure the balance for the given address is at least the given amount.\n\t * @param config The configuration containing endpoint information.\n\t * @param faucetUrl The URL of the faucet to request funds from.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The address to ensure the balance for.\n\t * @param ensureBalance The minimum balance to ensure.\n\t * @param timeoutInSeconds Optional timeout in seconds, defaults to 10 seconds.\n\t * @returns True if the balance is at least the given amount, false otherwise.\n\t */\n\tpublic static async ensureBalance(\n\t\tconfig: IIotaConfig,\n\t\tfaucetUrl: string | undefined,\n\t\tidentity: string,\n\t\taddress: string,\n\t\tensureBalance: bigint,\n\t\ttimeoutInSeconds?: number\n\t): Promise<boolean> {\n\t\tGuards.objectValue<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(config.clientOptions.url), config.clientOptions.url);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(address), address);\n\t\tGuards.bigint(Iota.CLASS_NAME, nameof(ensureBalance), ensureBalance);\n\n\t\tlet currentBalance = await Iota.getBalance(config, address);\n\n\t\tif (Is.stringValue(faucetUrl)) {\n\t\t\tlet retryCount = 10;\n\n\t\t\twhile (currentBalance < ensureBalance && retryCount > 0) {\n\t\t\t\tconst addedBalance = await Iota.fundAddress(\n\t\t\t\t\tconfig,\n\t\t\t\t\tfaucetUrl,\n\t\t\t\t\tidentity,\n\t\t\t\t\taddress,\n\t\t\t\t\ttimeoutInSeconds\n\t\t\t\t);\n\t\t\t\tif (addedBalance === 0n) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tcurrentBalance += addedBalance;\n\t\t\t\tif (currentBalance < ensureBalance) {\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\t\t\t\t\tretryCount--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn currentBalance >= ensureBalance;\n\t}\n\n\t/**\n\t * Get the balance for the given address.\n\t * @param config The configuration containing endpoint information.\n\t * @param address The address to get the balance for.\n\t * @returns The balance of the given address.\n\t */\n\tpublic static async getBalance(config: IIotaConfig, address: string): Promise<bigint> {\n\t\tGuards.objectValue<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(config.clientOptions.url), config.clientOptions.url);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(address), address);\n\n\t\tconst client = Iota.createClient(config);\n\t\tconst balance = await client.getBalance({\n\t\t\towner: address\n\t\t});\n\t\treturn BigInt(balance.totalBalance);\n\t}\n\n\t/**\n\t * Get the seed from the vault.\n\t * @param vaultConnector The vault connector to use.\n\t * @param config The configuration to use.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @returns The seed.\n\t * @internal\n\t */\n\tprivate static async getSeed(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: Pick<IIotaConfig, \"vaultMnemonicId\" | \"vaultSeedId\">,\n\t\tidentity: string\n\t): Promise<Uint8Array> {\n\t\tconst seedKey = Iota.buildSeedKey(identity, config.vaultSeedId);\n\n\t\ttry {\n\t\t\tconst seedBase64 = await vaultConnector.getSecret<string>(seedKey);\n\t\t\treturn Converter.base64ToBytes(seedBase64);\n\t\t} catch {}\n\n\t\tconst mnemonic = await vaultConnector.getSecret<string>(\n\t\t\tIota.buildMnemonicKey(identity, config.vaultMnemonicId)\n\t\t);\n\n\t\t// If the seed is not found but the mnemonic exists, derive the seed and store it for future use\n\t\tconst seed = Bip39.mnemonicToSeed(mnemonic);\n\t\tawait vaultConnector.setSecret(seedKey, Converter.bytesToBase64(seed));\n\n\t\treturn seed;\n\t}\n\n\t/**\n\t * Get the key for storing the mnemonic.\n\t * @param identity The identity to use.\n\t * @param vaultMnemonicId The mnemonic ID to use.\n\t * @returns The mnemonic key.\n\t * @internal\n\t */\n\tprivate static buildMnemonicKey(identity: string, vaultMnemonicId?: string): string {\n\t\treturn `${identity}/${vaultMnemonicId ?? Iota.DEFAULT_MNEMONIC_SECRET_NAME}`;\n\t}\n\n\t/**\n\t * Get the key for storing the seed.\n\t * @param identity The identity to use.\n\t * @param vaultSeedId The seed ID to use.\n\t * @returns The seed key.\n\t * @internal\n\t */\n\tprivate static buildSeedKey(identity: string, vaultSeedId?: string): string {\n\t\treturn `${identity}/${vaultSeedId ?? Iota.DEFAULT_SEED_SECRET_NAME}`;\n\t}\n\n\t/**\n\t * Build a chunk of key pairs from vault cache or derived from seed.\n\t * @param vaultConnector The vault connector to use.\n\t * @param config The configuration to use.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index.\n\t * @param internal Whether the addresses are internal or external.\n\t * @param addressIndex The starting address index.\n\t * @returns The key pairs for the chunk.\n\t * @internal\n\t */\n\tprivate static async buildKeyPairRange(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: Pick<IIotaConfig, \"coinType\" | \"vaultMnemonicId\" | \"vaultSeedId\">,\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tinternal: boolean,\n\t\taddressIndex: number\n\t): Promise<{ privateKey: string; publicKey: string }[]> {\n\t\tconst keyPairChunkKey = Iota.buildAccountChunkKey(\n\t\t\tidentity,\n\t\t\taccountIndex,\n\t\t\tinternal,\n\t\t\taddressIndex\n\t\t);\n\n\t\tlet keyPairChunk: { privateKey: string; publicKey: string }[] | undefined;\n\t\ttry {\n\t\t\tkeyPairChunk =\n\t\t\t\tawait vaultConnector.getSecret<{ privateKey: string; publicKey: string }[]>(\n\t\t\t\t\tkeyPairChunkKey\n\t\t\t\t);\n\t\t} catch {}\n\n\t\tif (Is.empty(keyPairChunk)) {\n\t\t\tconst startChunkIndex = addressIndex % Iota._PRE_CALC_CHUNK_SIZE;\n\t\t\tconst endChunkIndex = startChunkIndex + Iota._PRE_CALC_CHUNK_SIZE;\n\n\t\t\tconst seed = await Iota.getSeed(vaultConnector, config, identity);\n\n\t\t\tkeyPairChunk = [];\n\n\t\t\tfor (let i = startChunkIndex; i < endChunkIndex; i++) {\n\t\t\t\tconst keyPair = Bip44.keyPair(\n\t\t\t\t\tseed,\n\t\t\t\t\tKeyType.Ed25519,\n\t\t\t\t\tconfig.coinType ?? Iota.DEFAULT_COIN_TYPE,\n\t\t\t\t\taccountIndex,\n\t\t\t\t\tinternal,\n\t\t\t\t\ti\n\t\t\t\t);\n\t\t\t\tkeyPairChunk.push({\n\t\t\t\t\tprivateKey: Converter.bytesToBase64(keyPair.privateKey),\n\t\t\t\t\tpublicKey: Converter.bytesToBase64(keyPair.publicKey)\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait vaultConnector.setSecret(keyPairChunkKey, keyPairChunk);\n\t\t}\n\n\t\treturn keyPairChunk;\n\t}\n\n\t/**\n\t * Get the key for storing a keypair chunk.\n\t * @param identity The identity to use.\n\t * @param accountIndex The account index.\n\t * @param internal Whether the address is internal or external.\n\t * @param addressIndex The address index to determine the chunk.\n\t * @returns The keypair chunk key.\n\t * @internal\n\t */\n\tprivate static buildAccountChunkKey(\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tinternal: boolean,\n\t\taddressIndex: number\n\t): string {\n\t\treturn `${identity}/account/${accountIndex}/${internal ? \"1\" : \"0\"}/${addressIndex % Iota._PRE_CALC_CHUNK_SIZE}`;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"iota.js","sourceRoot":"","sources":["../../src/iota.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,YAAY,EAEZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAWxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;GAEG;AACH,MAAM,OAAO,IAAI;IAChB;;OAEG;IACI,MAAM,CAAU,4BAA4B,GAAW,UAAU,CAAC;IAEzE;;OAEG;IACI,MAAM,CAAU,wBAAwB,GAAW,MAAM,CAAC;IAEjE;;OAEG;IACI,MAAM,CAAU,iBAAiB,GAAW,IAAI,CAAC;IAExD;;OAEG;IACI,MAAM,CAAU,UAAU,UAA0B;IAE3D;;;OAGG;I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AC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { IotaClient } from \"@iota/iota-sdk/client\";\nimport { requestIotaFromFaucetV0 } from \"@iota/iota-sdk/faucet\";\nimport { Transaction } from \"@iota/iota-sdk/transactions\";\nimport {\n\tBaseError,\n\tCoerce,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tStringHelper,\n\ttype IError\n} from \"@twin.org/core\";\nimport { Bip39, Bip44, Blake2b, KeyType } from \"@twin.org/crypto\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { VaultConnectorHelper, VaultKeyType } from \"@twin.org/vault-models\";\nimport type { IVaultConnector } from \"@twin.org/vault-models\";\nimport { FetchHelper, HttpMethod } from \"@twin.org/web\";\nimport type { IGasReservationResult } from \"./models/IGasReservationResult.js\";\nimport type { IGasStationConfig } from \"./models/IGasStationConfig.js\";\nimport type { IGasStationExecuteResponse } from \"./models/IGasStationExecuteResponse.js\";\nimport type { IGasStationReserveGasResponse } from \"./models/IGasStationReserveGasResponse.js\";\nimport type { IIotaClient } from \"./models/IIotaClient.js\";\nimport type { IIotaConfig } from \"./models/IIotaConfig.js\";\nimport type { IIotaDryRun } from \"./models/IIotaDryRun.js\";\nimport type { IIotaResponseOptions } from \"./models/IIotaResponseOptions.js\";\nimport type { IIotaTransaction } from \"./models/IIotaTransaction.js\";\nimport type { IIotaTransactionBlockResponse } from \"./models/IIotaTransactionBlockResponse.js\";\nimport { VaultSigner } from \"./vaultSigner.js\";\nimport { VaultTransactionSigner } from \"./vaultTransactionSigner.js\";\n\n/**\n * Class for performing operations on IOTA.\n */\nexport class Iota {\n\t/**\n\t * Default name for the mnemonic secret.\n\t */\n\tpublic static readonly DEFAULT_MNEMONIC_SECRET_NAME: string = \"mnemonic\";\n\n\t/**\n\t * Default name for the seed secret.\n\t */\n\tpublic static readonly DEFAULT_SEED_SECRET_NAME: string = \"seed\";\n\n\t/**\n\t * Default coin type.\n\t */\n\tpublic static readonly DEFAULT_COIN_TYPE: number = 4218;\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Iota>();\n\n\t/**\n\t * Default scan range.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_SCAN_RANGE: number = 1000;\n\n\t/**\n\t * Default pre-calculation chunk size.\n\t * @internal\n\t */\n\tprivate static readonly _PRE_CALC_CHUNK_SIZE: number = 25;\n\n\t/**\n\t * Default inclusion timeout.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_INCLUSION_TIMEOUT: number = 60;\n\n\t/**\n\t * Default gas budget for all transactions (including sponsored and direct).\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_GAS_BUDGET: number = 50000000;\n\n\t/**\n\t * Default gas reservation duration.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_GAS_RESERVATION_DURATION: number = 60;\n\n\t/**\n\t * Create a new IOTA client.\n\t * @param config The configuration.\n\t * @returns The client instance.\n\t */\n\tpublic static createClient(config: IIotaConfig): IIotaClient {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.object(Iota.CLASS_NAME, nameof(config.clientOptions), config.clientOptions);\n\t\tGuards.string(Iota.CLASS_NAME, nameof(config.clientOptions.url), config.clientOptions.url);\n\n\t\treturn new IotaClient(config.clientOptions);\n\t}\n\n\t/**\n\t * Create configuration using defaults where necessary.\n\t * @param config The configuration to populate.\n\t */\n\tpublic static populateConfig(config: IIotaConfig): void {\n\t\tGuards.object<IIotaConfig[\"clientOptions\"]>(\n\t\t\tIota.CLASS_NAME,\n\t\t\tnameof(config.clientOptions),\n\t\t\tconfig.clientOptions\n\t\t);\n\n\t\tconfig.vaultMnemonicId ??= Iota.DEFAULT_MNEMONIC_SECRET_NAME;\n\t\tconfig.vaultSeedId ??= Iota.DEFAULT_SEED_SECRET_NAME;\n\t\tconfig.coinType ??= Iota.DEFAULT_COIN_TYPE;\n\t\tconfig.inclusionTimeoutSeconds ??= Iota._DEFAULT_INCLUSION_TIMEOUT;\n\t}\n\n\t/**\n\t * Store a mnemonic in the vault, derive and store the seed, and pre-cache the first keypair chunk.\n\t * @param vaultConnector The vault connector.\n\t * @param config The configuration.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param mnemonic The mnemonic to store, if undefined a new one will be generated and returned.\n\t * @param accountIndex The account index to pre-cache.\n\t * @returns The mnemonic that was stored.\n\t */\n\tpublic static async storeMnemonic(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: IIotaConfig,\n\t\tidentity: string,\n\t\tmnemonic: string | undefined,\n\t\taccountIndex: number\n\t): Promise<string> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(vaultConnector), vaultConnector);\n\t\tGuards.object<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(accountIndex), accountIndex);\n\n\t\tconst mnemonicToStore = mnemonic ?? Bip39.randomMnemonic();\n\n\t\tawait vaultConnector.setSecret(\n\t\t\tIota.buildMnemonicKey(identity, config.vaultMnemonicId),\n\t\t\tmnemonicToStore\n\t\t);\n\n\t\tconst seed = Bip39.mnemonicToSeed(mnemonicToStore);\n\t\tawait vaultConnector.setSecret(\n\t\t\tIota.buildSeedKey(identity, config.vaultSeedId),\n\t\t\tConverter.bytesToBase64(seed)\n\t\t);\n\n\t\tawait Iota.getPublicKeys(\n\t\t\tvaultConnector,\n\t\t\tconfig,\n\t\t\tidentity,\n\t\t\taccountIndex,\n\t\t\tfalse,\n\t\t\t0,\n\t\t\tasync () => seed\n\t\t);\n\n\t\treturn mnemonicToStore;\n\t}\n\n\t/**\n\t * Derive an address from a public key.\n\t * @param publicKey The public key to derive the address from.\n\t * @returns The derived address.\n\t */\n\tpublic static publicKeyToAddress(publicKey: Uint8Array): string {\n\t\treturn Converter.bytesToHex(Blake2b.sum256(publicKey), true);\n\t}\n\n\t/**\n\t * Get address for the identity.\n\t * @param vaultConnector The vault connector.\n\t * @param config The configuration.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index to get the addresses for.\n\t * @param startAddressIndex The start index for the addresses.\n\t * @param isInternal Whether the addresses are internal.\n\t * @returns The address.\n\t */\n\tpublic static async getAddress(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: Pick<IIotaConfig, \"coinType\" | \"vaultMnemonicId\" | \"vaultSeedId\">,\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tstartAddressIndex: number,\n\t\tisInternal?: boolean\n\t): Promise<string> {\n\t\tconst addresses = await Iota.getAddresses(\n\t\t\tvaultConnector,\n\t\t\tconfig,\n\t\t\tidentity,\n\t\t\taccountIndex,\n\t\t\tstartAddressIndex,\n\t\t\t1,\n\t\t\tisInternal\n\t\t);\n\t\treturn addresses[0];\n\t}\n\n\t/**\n\t * Get addresses for the identity.\n\t * @param vaultConnector The vault connector.\n\t * @param config The configuration.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index to get the addresses for.\n\t * @param startAddressIndex The start index for the addresses.\n\t * @param count The number of addresses to generate.\n\t * @param isInternal Whether the addresses are internal.\n\t * @returns The list of addresses.\n\t */\n\tpublic static async getAddresses(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: Pick<IIotaConfig, \"coinType\" | \"vaultMnemonicId\" | \"vaultSeedId\">,\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tstartAddressIndex: number,\n\t\tcount: number,\n\t\tisInternal?: boolean\n\t): Promise<string[]> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(vaultConnector), vaultConnector);\n\t\tGuards.object<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(accountIndex), accountIndex);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(startAddressIndex), startAddressIndex);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(count), count);\n\n\t\tconst addresses: string[] = [];\n\t\tconst internal = isInternal ?? false;\n\t\tlet currentIndex = startAddressIndex;\n\t\tlet cachedSeed: Uint8Array | undefined;\n\t\tconst seedProvider = async (): Promise<Uint8Array> => {\n\t\t\tcachedSeed ??= await Iota.getSeed(vaultConnector, config, identity);\n\t\t\treturn cachedSeed;\n\t\t};\n\n\t\twhile (addresses.length < count) {\n\t\t\tconst chunkStart =\n\t\t\t\tMath.floor(currentIndex / Iota._PRE_CALC_CHUNK_SIZE) * Iota._PRE_CALC_CHUNK_SIZE;\n\t\t\tconst publicKeys = await Iota.getPublicKeys(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountIndex,\n\t\t\t\tinternal,\n\t\t\t\tchunkStart,\n\t\t\t\tseedProvider\n\t\t\t);\n\t\t\tconst chunk = publicKeys.map((pk: string) =>\n\t\t\t\tIota.publicKeyToAddress(Converter.base64ToBytes(pk))\n\t\t\t);\n\t\t\tconst offsetInChunk = currentIndex - chunkStart;\n\t\t\tconst remaining = count - addresses.length;\n\t\t\taddresses.push(...chunk.slice(offsetInChunk, offsetInChunk + remaining));\n\t\t\tcurrentIndex = chunkStart + Iota._PRE_CALC_CHUNK_SIZE;\n\t\t}\n\n\t\treturn addresses;\n\t}\n\n\t/**\n\t * Get a vault-backed transaction signer for the given identity and key indices.\n\t * @param vaultConnector The vault connector.\n\t * @param config The configuration.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index.\n\t * @param addressIndex The address index within the account.\n\t * @returns A VaultTransactionSigner for the specified key.\n\t */\n\tpublic static async getTransactionSigner(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: IIotaConfig,\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\taddressIndex: number\n\t): Promise<VaultTransactionSigner> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(vaultConnector), vaultConnector);\n\t\tGuards.object<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(accountIndex), accountIndex);\n\t\tGuards.integer(Iota.CLASS_NAME, nameof(addressIndex), addressIndex);\n\n\t\tconst publicKeys = await Iota.getPublicKeys(\n\t\t\tvaultConnector,\n\t\t\tconfig,\n\t\t\tidentity,\n\t\t\taccountIndex,\n\t\t\tfalse,\n\t\t\taddressIndex,\n\t\t\tasync () => Iota.getSeed(vaultConnector, config, identity)\n\t\t);\n\n\t\tconst chunkStart = addressIndex - (addressIndex % Iota._PRE_CALC_CHUNK_SIZE);\n\t\tconst offsetInChunk = addressIndex - chunkStart;\n\t\tconst publicKey = Converter.base64ToBytes(publicKeys[offsetInChunk]);\n\t\tconst keyName = Iota.buildAddressKeyName(identity, accountIndex, false, addressIndex);\n\n\t\treturn new VaultTransactionSigner(vaultConnector, keyName, publicKey);\n\t}\n\n\t/**\n\t * Create a new transaction instance.\n\t * @returns A new transaction instance.\n\t */\n\tpublic static createTransaction(): IIotaTransaction {\n\t\treturn new Transaction();\n\t}\n\n\t/**\n\t * Prepare and post a transaction.\n\t * @param config The configuration.\n\t * @param vaultConnector The vault connector.\n\t * @param logging The logging component.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param client The client instance.\n\t * @param source The source address.\n\t * @param amount The amount to transfer.\n\t * @param recipient The recipient address.\n\t * @param options The transaction options.\n\t * @returns The transaction result.\n\t */\n\tpublic static async prepareAndPostValueTransaction(\n\t\tconfig: IIotaConfig,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tidentity: string,\n\t\tclient: IIotaClient,\n\t\tsource: string,\n\t\tamount: bigint,\n\t\trecipient: string,\n\t\toptions?: IIotaResponseOptions\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\ttry {\n\t\t\tconst txb = new Transaction();\n\t\t\tconst [coin] = txb.splitCoins(txb.gas, [txb.pure.u64(amount)]);\n\t\t\ttxb.transferObjects([coin], txb.pure.address(recipient));\n\n\t\t\t// Check if gas station configuration is present\n\t\t\tif (Is.object<IGasStationConfig>(config.gasStation)) {\n\t\t\t\treturn await Iota.prepareAndPostGasStationTransaction(\n\t\t\t\t\tconfig,\n\t\t\t\t\tvaultConnector,\n\t\t\t\t\tidentity,\n\t\t\t\t\tclient,\n\t\t\t\t\tsource,\n\t\t\t\t\ttxb\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst result = await Iota.prepareAndPostTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tlogging,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\tsource,\n\t\t\t\ttxb,\n\t\t\t\toptions\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"valueTransactionFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Prepare and post a transaction.\n\t * @param config The configuration.\n\t * @param vaultConnector The vault connector.\n\t * @param logging The logging component.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param client The client instance.\n\t * @param owner The owner of the address.\n\t * @param transaction The transaction to execute.\n\t * @param options The transaction options.\n\t * @returns The transaction response.\n\t */\n\tpublic static async prepareAndPostTransaction(\n\t\tconfig: IIotaConfig,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tidentity: string,\n\t\tclient: IIotaClient,\n\t\towner: string,\n\t\ttransaction: IIotaTransaction,\n\t\toptions?: IIotaResponseOptions\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\t// Check if gas station configuration is present\n\t\tif (Is.object<IGasStationConfig>(config.gasStation)) {\n\t\t\treturn Iota.prepareAndPostGasStationTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\towner,\n\t\t\t\ttransaction,\n\t\t\t\toptions\n\t\t\t);\n\t\t}\n\n\t\t// Traditional transaction flow\n\t\t// Dry run the transaction if cost logging is enabled to get the gas and storage costs\n\t\tif (Is.stringValue(options?.dryRunLabel)) {\n\t\t\tawait Iota.dryRunTransaction(client, logging, transaction, owner, options.dryRunLabel);\n\t\t}\n\n\t\tconst { keyName, publicKey } = await Iota.ensureOwnerKey(\n\t\t\tvaultConnector,\n\t\t\tconfig,\n\t\t\tidentity,\n\t\t\towner\n\t\t);\n\t\tconst signer = new VaultSigner(vaultConnector, keyName, publicKey);\n\n\t\ttry {\n\t\t\tconst response = await client.signAndExecuteTransaction({\n\t\t\t\ttransaction,\n\t\t\t\tsigner,\n\t\t\t\trequestType: \"WaitForLocalExecution\",\n\t\t\t\toptions: {\n\t\t\t\t\tshowEffects: options?.showEffects ?? true,\n\t\t\t\t\tshowEvents: options?.showEvents ?? true,\n\t\t\t\t\tshowObjectChanges: options?.showObjectChanges ?? true\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (options?.waitForConfirmation ?? true) {\n\t\t\t\t// Wait for transaction to be indexed and available over API\n\t\t\t\tconst confirmedTransaction = await Iota.waitForTransactionConfirmation(\n\t\t\t\t\tclient,\n\t\t\t\t\tresponse.digest,\n\t\t\t\t\tconfig,\n\t\t\t\t\t{\n\t\t\t\t\t\tshowEffects: options?.showEffects ?? true,\n\t\t\t\t\t\tshowEvents: options?.showEvents ?? true,\n\t\t\t\t\t\tshowObjectChanges: options?.showObjectChanges ?? true\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\treturn confirmedTransaction;\n\t\t\t}\n\n\t\t\treturn response;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"transactionFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Extract error from SDK payload.\n\t * Errors from the IOTA SDK are usually not JSON strings but objects.\n\t * @param error The error to extract.\n\t * @returns The extracted error.\n\t */\n\tpublic static extractPayloadError(error: unknown): IError {\n\t\tif (Is.object<{ code?: string; message?: string; inner?: unknown; cause?: unknown }>(error)) {\n\t\t\tif (!Is.empty(error.inner)) {\n\t\t\t\terror.inner = Iota.extractPayloadError(error.inner);\n\t\t\t}\n\t\t\tif (!Is.empty(error.cause)) {\n\t\t\t\terror.cause = Iota.extractPayloadError(error.cause);\n\t\t\t}\n\n\t\t\tif (error.code === \"InsufficientGas\") {\n\t\t\t\treturn new GeneralError(Iota.CLASS_NAME, \"insufficientFunds\");\n\t\t\t} else if (error.message?.startsWith(\"ErrorObject\")) {\n\t\t\t\tconst msg = /message: \"(.*)\"/.exec(error.message);\n\t\t\t\tif (msg && msg.length > 1) {\n\t\t\t\t\terror = msg[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst baseError = BaseError.fromError(error);\n\t\tif (baseError.name === \"Base\" && !Is.stringValue(baseError.source)) {\n\t\t\tbaseError.name = \"IOTA\";\n\t\t\tbaseError.source = Iota.CLASS_NAME;\n\t\t}\n\t\treturn baseError;\n\t}\n\n\t/**\n\t * Check if the package exists on the network.\n\t * @param client The client to use.\n\t * @param packageId The package ID to check.\n\t * @returns True if the package exists, false otherwise.\n\t */\n\tpublic static async packageExistsOnNetwork(\n\t\tclient: IIotaClient,\n\t\tpackageId: string\n\t): Promise<boolean> {\n\t\ttry {\n\t\t\tconst packageObject = await client.getObject({\n\t\t\t\tid: packageId,\n\t\t\t\toptions: {\n\t\t\t\t\tshowType: true\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (\"error\" in packageObject) {\n\t\t\t\tif (packageObject?.error?.code === \"notExists\") {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tthrow new GeneralError(Iota.CLASS_NAME, \"packageObjectError\", {\n\t\t\t\t\tpackageId,\n\t\t\t\t\terror: packageObject.error\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"packageNotFoundOnNetwork\",\n\t\t\t\t{\n\t\t\t\t\tpackageId\n\t\t\t\t},\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Dry run a transaction and log the results.\n\t * @param client The IOTA client.\n\t * @param logging The logging component.\n\t * @param txb The transaction to dry run.\n\t * @param sender The sender address.\n\t * @param operation The operation to log.\n\t * @returns The dry run result including status, costs, events, and object changes.\n\t */\n\tpublic static async dryRunTransaction(\n\t\tclient: IIotaClient,\n\t\tlogging: ILoggingComponent | undefined,\n\t\ttxb: IIotaTransaction,\n\t\tsender: string,\n\t\toperation: string\n\t): Promise<IIotaDryRun> {\n\t\ttry {\n\t\t\ttxb.setSender(sender);\n\n\t\t\tconst builtTx = await txb.build({\n\t\t\t\tclient,\n\t\t\t\tonlyTransactionKind: false\n\t\t\t});\n\n\t\t\tconst dryRunResult = await client.dryRunTransactionBlock({\n\t\t\t\ttransactionBlock: builtTx\n\t\t\t});\n\n\t\t\tif (dryRunResult.effects.status?.status !== \"success\") {\n\t\t\t\tthrow new GeneralError(Iota.CLASS_NAME, \"dryRunFailed\", {\n\t\t\t\t\terror: dryRunResult.effects?.status?.error\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst result = {\n\t\t\t\tstatus: dryRunResult.effects.status.status,\n\t\t\t\tcosts: {\n\t\t\t\t\tcomputationCost: dryRunResult.effects.gasUsed.computationCost,\n\t\t\t\t\tcomputationCostBurned: dryRunResult.effects.gasUsed.computationCostBurned,\n\t\t\t\t\tstorageCost: dryRunResult.effects.gasUsed.storageCost,\n\t\t\t\t\tstorageRebate: dryRunResult.effects.gasUsed.storageRebate,\n\t\t\t\t\tnonRefundableStorageFee: dryRunResult.effects.gasUsed.nonRefundableStorageFee\n\t\t\t\t},\n\t\t\t\tevents: dryRunResult.events ?? [],\n\t\t\t\tbalanceChanges: dryRunResult.balanceChanges ?? [],\n\t\t\t\tobjectChanges: dryRunResult.objectChanges ?? []\n\t\t\t};\n\n\t\t\tawait logging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: Iota.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"transactionCosts\",\n\t\t\t\tdata: {\n\t\t\t\t\toperation,\n\t\t\t\t\tcost: JSON.stringify(result)\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.isErrorName(error, GeneralError.CLASS_NAME)) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"dryRunFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Wait for a transaction to be indexed and available over the API.\n\t * @param client The IOTA client instance.\n\t * @param digest The digest of the transaction to wait for.\n\t * @param config The IOTA configuration.\n\t * @param options Additional options for the transaction query.\n\t * @param options.showEffects Whether to show effects.\n\t * @param options.showEvents Whether to show events.\n\t * @param options.showObjectChanges Whether to show object changes.\n\t * @returns The confirmed transaction response.\n\t */\n\tpublic static async waitForTransactionConfirmation(\n\t\tclient: IIotaClient,\n\t\tdigest: string,\n\t\tconfig: IIotaConfig,\n\t\toptions?: {\n\t\t\tshowEffects?: boolean;\n\t\t\tshowEvents?: boolean;\n\t\t\tshowObjectChanges?: boolean;\n\t\t}\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\tconst timeoutMs = (config.inclusionTimeoutSeconds ?? Iota._DEFAULT_INCLUSION_TIMEOUT) * 1000;\n\n\t\treturn client.waitForTransaction({\n\t\t\tdigest,\n\t\t\ttimeout: timeoutMs,\n\t\t\toptions: {\n\t\t\t\tshowEffects: options?.showEffects ?? true,\n\t\t\t\tshowEvents: options?.showEvents ?? true,\n\t\t\t\tshowObjectChanges: options?.showObjectChanges ?? true\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Check if the error is an abort error with a specific code.\n\t * @param error The error to check.\n\t * @param code The error code to check for.\n\t * @returns True if the error is an abort error, false otherwise.\n\t */\n\tpublic static isAbortError(error: unknown, code: number): boolean {\n\t\tconst err = BaseError.fromError(error);\n\t\tif (Is.stringValue(err.properties?.error)) {\n\t\t\tconst abortCodeMatch = /abort code\\s*:\\s*(\\d+)/i.exec(err.properties.error);\n\t\t\treturn abortCodeMatch?.[1] === code.toString();\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Extracts the abort code from a transaction result if the transaction was aborted.\n\t * @param response The transaction result to extract the abort code from.\n\t * @returns The abort code if the transaction was aborted, or undefined if it was not an abort error or the code could not be extracted.\n\t */\n\tpublic static extractAbortCode(response: IIotaTransactionBlockResponse): number | undefined {\n\t\tif (\n\t\t\tresponse.effects?.status?.status === \"failure\" &&\n\t\t\tIs.stringValue(response.effects.status.error)\n\t\t) {\n\t\t\tconst match = /abort code: (\\d+)/.exec(response.effects.status.error);\n\t\t\tif (match) {\n\t\t\t\treturn Coerce.integer(match[1]);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Prepare and post a transaction using gas station sponsoring.\n\t * @param config The configuration.\n\t * @param vaultConnector The vault connector.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param client The client instance.\n\t * @param owner The owner of the address.\n\t * @param transaction The transaction to execute.\n\t * @param options Response options including confirmation behavior.\n\t * @returns The transaction response.\n\t */\n\tpublic static async prepareAndPostGasStationTransaction(\n\t\tconfig: IIotaConfig,\n\t\tvaultConnector: IVaultConnector,\n\t\tidentity: string,\n\t\tclient: IIotaClient,\n\t\towner: string,\n\t\ttransaction: IIotaTransaction,\n\t\toptions?: IIotaResponseOptions\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(config.gasStation), config.gasStation);\n\n\t\ttry {\n\t\t\t// Reserve gas from the gas station\n\t\t\tconst gasReservation = await Iota.reserveGas(config);\n\n\t\t\t// Set transaction parameters for sponsoring\n\t\t\ttransaction.setSender(owner);\n\t\t\ttransaction.setGasOwner(gasReservation.sponsorAddress);\n\t\t\ttransaction.setGasPayment(gasReservation.gasCoins);\n\t\t\ttransaction.setGasBudget(config.gasBudget ?? Iota._DEFAULT_GAS_BUDGET);\n\n\t\t\t// Build and sign transaction\n\t\t\tconst unsignedTxBytes = await transaction.build({ client });\n\n\t\t\tconst { keyName, publicKey } = await Iota.ensureOwnerKey(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\towner\n\t\t\t);\n\t\t\tconst signer = new VaultSigner(vaultConnector, keyName, publicKey);\n\t\t\tconst signature = await signer.signTransaction(unsignedTxBytes);\n\n\t\t\treturn await Iota.executeAndConfirmGasStationTransaction(\n\t\t\t\tconfig,\n\t\t\t\tclient,\n\t\t\t\tgasReservation.reservationId,\n\t\t\t\tunsignedTxBytes,\n\t\t\t\tsignature.signature,\n\t\t\t\toptions\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"gasStationTransactionFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Reserve gas from the gas station.\n\t * @param config The configuration containing gas station settings.\n\t * @returns The gas reservation result.\n\t */\n\tpublic static async reserveGas(config: IIotaConfig): Promise<IGasReservationResult> {\n\t\tGuards.object(Iota.CLASS_NAME, nameof(config.gasStation), config.gasStation);\n\n\t\tconst requestData = {\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\tgas_budget: config.gasBudget ?? Iota._DEFAULT_GAS_BUDGET,\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\treserve_duration_secs: config.gasReservationDuration ?? Iota._DEFAULT_GAS_RESERVATION_DURATION\n\t\t};\n\n\t\tconst baseUrl = StringHelper.trimTrailingSlashes(config.gasStation.gasStationUrl);\n\t\tconst result = await FetchHelper.fetchJson<typeof requestData, IGasStationReserveGasResponse>(\n\t\t\tIota.CLASS_NAME,\n\t\t\t`${baseUrl}/v1/reserve_gas`,\n\t\t\tHttpMethod.POST,\n\t\t\trequestData,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${config.gasStation.gasStationAuthToken}`\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\tconst apiResponse = result.result;\n\n\t\treturn {\n\t\t\tsponsorAddress: apiResponse.sponsor_address,\n\t\t\treservationId: apiResponse.reservation_id,\n\t\t\tgasCoins: apiResponse.gas_coins\n\t\t};\n\t}\n\n\t/**\n\t * Execute a sponsored transaction through the gas station.\n\t * @param config The configuration containing gas station settings.\n\t * @param reservationId The reservation ID from gas reservation.\n\t * @param transactionBytes The unsigned transaction bytes.\n\t * @param userSignature The user's signature.\n\t * @returns The transaction response.\n\t */\n\tpublic static async executeGasStationTransaction(\n\t\tconfig: IIotaConfig,\n\t\treservationId: number,\n\t\ttransactionBytes: Uint8Array,\n\t\tuserSignature: string\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\tGuards.object<IGasStationConfig>(Iota.CLASS_NAME, nameof(config.gasStation), config.gasStation);\n\n\t\tconst requestData = {\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\treservation_id: reservationId,\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\ttx_bytes: Converter.bytesToBase64(transactionBytes),\n\t\t\t// eslint-disable-next-line camelcase\n\t\t\tuser_sig: userSignature\n\t\t};\n\n\t\tconst baseUrl = StringHelper.trimTrailingSlashes(config.gasStation.gasStationUrl);\n\t\tconst result = await FetchHelper.fetchJson<typeof requestData, IGasStationExecuteResponse>(\n\t\t\tIota.CLASS_NAME,\n\t\t\t`${baseUrl}/v1/execute_tx`,\n\t\t\tHttpMethod.POST,\n\t\t\trequestData,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${config.gasStation.gasStationAuthToken}`\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\tconst effectsData = result.effects;\n\n\t\t// Match IotaTransactionBlockResponse format\n\t\treturn {\n\t\t\tdigest: effectsData.transactionDigest,\n\t\t\teffects: effectsData as unknown,\n\t\t\tevents: [],\n\t\t\tobjectChanges: [],\n\t\t\tconfirmedLocalExecution: true\n\t\t} as unknown as IIotaTransactionBlockResponse;\n\t}\n\n\t/**\n\t * Execute and confirm a gas station transaction.\n\t * @param config The configuration containing gas station settings.\n\t * @param client The IOTA client for confirmation.\n\t * @param reservationId The reservation ID from gas reservation.\n\t * @param transactionBytes The unsigned transaction bytes.\n\t * @param userSignature The user's signature.\n\t * @param options Response options including confirmation behavior.\n\t * @returns The transaction response (confirmed if waitForConfirmation is true).\n\t */\n\tpublic static async executeAndConfirmGasStationTransaction(\n\t\tconfig: IIotaConfig,\n\t\tclient: IIotaClient,\n\t\treservationId: number,\n\t\ttransactionBytes: Uint8Array,\n\t\tuserSignature: string,\n\t\toptions?: IIotaResponseOptions\n\t): Promise<IIotaTransactionBlockResponse> {\n\t\tGuards.object<IGasStationConfig>(Iota.CLASS_NAME, nameof(config.gasStation), config.gasStation);\n\n\t\tconst response = await Iota.executeGasStationTransaction(\n\t\t\tconfig,\n\t\t\treservationId,\n\t\t\ttransactionBytes,\n\t\t\tuserSignature\n\t\t);\n\n\t\tif (options?.waitForConfirmation ?? true) {\n\t\t\tconst confirmedTransaction = await Iota.waitForTransactionConfirmation(\n\t\t\t\tclient,\n\t\t\t\tresponse.digest,\n\t\t\t\tconfig,\n\t\t\t\t{\n\t\t\t\t\tshowEffects: options?.showEffects ?? true,\n\t\t\t\t\tshowEvents: options?.showEvents ?? true,\n\t\t\t\t\tshowObjectChanges: options?.showObjectChanges ?? true\n\t\t\t\t}\n\t\t\t);\n\n\t\t\treturn confirmedTransaction;\n\t\t}\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Fund an address with IOTA from the faucet.\n\t * @param config The configuration containing endpoint information.\n\t * @param faucetUrl The URL of the faucet to request funds from.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The address to fund.\n\t * @param timeoutInSeconds The timeout in seconds to wait for the funding to complete.\n\t * @returns The amount funded.\n\t */\n\tpublic static async fundAddress(\n\t\tconfig: IIotaConfig,\n\t\tfaucetUrl: string,\n\t\tidentity: string,\n\t\taddress: string,\n\t\ttimeoutInSeconds: number = 60\n\t): Promise<bigint> {\n\t\tGuards.objectValue<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(config.clientOptions.url), config.clientOptions.url);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(faucetUrl), faucetUrl);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(address), address);\n\n\t\ttry {\n\t\t\tconst initialBalance = await Iota.getBalance(config, address);\n\n\t\t\tconst response = await requestIotaFromFaucetV0({\n\t\t\t\thost: faucetUrl,\n\t\t\t\trecipient: address\n\t\t\t});\n\n\t\t\tif (response?.error) {\n\t\t\t\tthrow new GeneralError(Iota.CLASS_NAME, \"fundingFailed\", undefined, response.error);\n\t\t\t}\n\n\t\t\t// Poll for balance change\n\t\t\tconst numTries = Math.ceil(timeoutInSeconds / 5);\n\t\t\tfor (let i = 0; i < numTries; i++) {\n\t\t\t\tconst newBalance = await Iota.getBalance(config, address);\n\n\t\t\t\tif (newBalance > initialBalance) {\n\t\t\t\t\treturn newBalance - initialBalance;\n\t\t\t\t}\n\n\t\t\t\tif (i < numTries - 1) {\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, 5000));\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst payloadError = Iota.extractPayloadError(error);\n\t\t\tif (\n\t\t\t\tpayloadError.message.includes(\n\t\t\t\t\t\"Too many requests from this client have been sent to the faucet\"\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new GeneralError(\n\t\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\t\"faucetRateLimit\",\n\t\t\t\t\tundefined,\n\t\t\t\t\tIota.extractPayloadError(error)\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tIota.CLASS_NAME,\n\t\t\t\t\"fundingFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\n\t\treturn 0n;\n\t}\n\n\t/**\n\t * Ensure the balance for the given address is at least the given amount.\n\t * @param config The configuration containing endpoint information.\n\t * @param faucetUrl The URL of the faucet to request funds from.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The address to ensure the balance for.\n\t * @param ensureBalance The minimum balance to ensure.\n\t * @param timeoutInSeconds Optional timeout in seconds, defaults to 10 seconds.\n\t * @returns True if the balance is at least the given amount, false otherwise.\n\t */\n\tpublic static async ensureBalance(\n\t\tconfig: IIotaConfig,\n\t\tfaucetUrl: string | undefined,\n\t\tidentity: string,\n\t\taddress: string,\n\t\tensureBalance: bigint,\n\t\ttimeoutInSeconds?: number\n\t): Promise<boolean> {\n\t\tGuards.objectValue<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(config.clientOptions.url), config.clientOptions.url);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(address), address);\n\t\tGuards.bigint(Iota.CLASS_NAME, nameof(ensureBalance), ensureBalance);\n\n\t\tlet currentBalance = await Iota.getBalance(config, address);\n\n\t\tif (Is.stringValue(faucetUrl)) {\n\t\t\tlet retryCount = 10;\n\n\t\t\twhile (currentBalance < ensureBalance && retryCount > 0) {\n\t\t\t\tconst addedBalance = await Iota.fundAddress(\n\t\t\t\t\tconfig,\n\t\t\t\t\tfaucetUrl,\n\t\t\t\t\tidentity,\n\t\t\t\t\taddress,\n\t\t\t\t\ttimeoutInSeconds\n\t\t\t\t);\n\t\t\t\tif (addedBalance === 0n) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tcurrentBalance += addedBalance;\n\t\t\t\tif (currentBalance < ensureBalance) {\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\t\t\t\t\tretryCount--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn currentBalance >= ensureBalance;\n\t}\n\n\t/**\n\t * Get the balance for the given address.\n\t * @param config The configuration containing endpoint information.\n\t * @param address The address to get the balance for.\n\t * @returns The balance of the given address.\n\t */\n\tpublic static async getBalance(config: IIotaConfig, address: string): Promise<bigint> {\n\t\tGuards.objectValue<IIotaConfig>(Iota.CLASS_NAME, nameof(config), config);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(config.clientOptions.url), config.clientOptions.url);\n\t\tGuards.stringValue(Iota.CLASS_NAME, nameof(address), address);\n\n\t\tconst client = Iota.createClient(config);\n\t\tconst balance = await client.getBalance({\n\t\t\towner: address\n\t\t});\n\t\treturn BigInt(balance.totalBalance);\n\t}\n\n\t/**\n\t * Create a transaction instance from the given bytes.\n\t * @param bytes The transaction bytes to create the transaction from.\n\t * @returns The transaction instance created from the given bytes.\n\t */\n\tpublic static transactionFromBytes(bytes: Uint8Array): IIotaTransaction {\n\t\treturn Transaction.from(bytes);\n\t}\n\n\t/**\n\t * Find the vault key name and public key for the given owner address.\n\t * Keys are individually registered in the vault by buildKeyPairRange, so no addKey is needed here.\n\t * @param vaultConnector The vault connector to use.\n\t * @param config The configuration to use.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param owner The owner address whose key should be located.\n\t * @param accountIndex The account index to search.\n\t * @returns The vault key name and the public key bytes.\n\t * @internal\n\t */\n\tprivate static async ensureOwnerKey(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: IIotaConfig,\n\t\tidentity: string,\n\t\towner: string,\n\t\taccountIndex: number = 0\n\t): Promise<{ keyName: string; publicKey: Uint8Array }> {\n\t\tconst scanRange = config.maxAddressScanRange ?? Iota._DEFAULT_SCAN_RANGE;\n\t\tlet cachedSeed: Uint8Array | undefined;\n\t\tconst seedProvider = async (): Promise<Uint8Array> => {\n\t\t\tcachedSeed ??= await Iota.getSeed(vaultConnector, config, identity);\n\t\t\treturn cachedSeed;\n\t\t};\n\n\t\tfor (let chunkStart = 0; chunkStart < scanRange; chunkStart += Iota._PRE_CALC_CHUNK_SIZE) {\n\t\t\tconst publicKeys = await Iota.getPublicKeys(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountIndex,\n\t\t\t\tfalse,\n\t\t\t\tchunkStart,\n\t\t\t\tseedProvider\n\t\t\t);\n\t\t\tconst matchIndex = publicKeys.findIndex(\n\t\t\t\t(pk: string) => Iota.publicKeyToAddress(Converter.base64ToBytes(pk)) === owner\n\t\t\t);\n\t\t\tif (matchIndex >= 0) {\n\t\t\t\tconst addressIndex = chunkStart + matchIndex;\n\t\t\t\treturn {\n\t\t\t\t\tkeyName: Iota.buildAddressKeyName(identity, accountIndex, false, addressIndex),\n\t\t\t\t\tpublicKey: Converter.base64ToBytes(publicKeys[matchIndex])\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tthrow new GeneralError(Iota.CLASS_NAME, \"addressNotFound\", { address: owner });\n\t}\n\n\t/**\n\t * Get the seed from the vault, deriving it from the mnemonic if necessary.\n\t * @param vaultConnector The vault connector to use.\n\t * @param config The configuration to use.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @returns The seed bytes.\n\t * @internal\n\t */\n\tprivate static async getSeed(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: Pick<IIotaConfig, \"vaultMnemonicId\" | \"vaultSeedId\">,\n\t\tidentity: string\n\t): Promise<Uint8Array> {\n\t\tconst seedKey = Iota.buildSeedKey(identity, config.vaultSeedId);\n\n\t\ttry {\n\t\t\tconst seedBase64 = await vaultConnector.getSecret<string>(seedKey);\n\t\t\treturn Converter.base64ToBytes(seedBase64);\n\t\t} catch {}\n\n\t\tconst mnemonic = await vaultConnector.getSecret<string>(\n\t\t\tIota.buildMnemonicKey(identity, config.vaultMnemonicId)\n\t\t);\n\n\t\t// If the seed is not found but the mnemonic exists, derive the seed and store it for future use\n\t\tconst seed = Bip39.mnemonicToSeed(mnemonic);\n\t\tawait vaultConnector.setSecret(seedKey, Converter.bytesToBase64(seed));\n\n\t\treturn seed;\n\t}\n\n\t/**\n\t * Get the key for storing the mnemonic.\n\t * @param identity The identity to use.\n\t * @param vaultMnemonicId The mnemonic ID to use.\n\t * @returns The mnemonic key.\n\t * @internal\n\t */\n\tprivate static buildMnemonicKey(identity: string, vaultMnemonicId?: string): string {\n\t\treturn VaultConnectorHelper.buildKeyName(\n\t\t\tidentity,\n\t\t\tvaultMnemonicId ?? Iota.DEFAULT_MNEMONIC_SECRET_NAME\n\t\t);\n\t}\n\n\t/**\n\t * Get the key for storing the seed.\n\t * @param identity The identity to use.\n\t * @param vaultSeedId The seed ID to use.\n\t * @returns The seed key.\n\t * @internal\n\t */\n\tprivate static buildSeedKey(identity: string, vaultSeedId?: string): string {\n\t\treturn VaultConnectorHelper.buildKeyName(\n\t\t\tidentity,\n\t\t\tvaultSeedId ?? Iota.DEFAULT_SEED_SECRET_NAME\n\t\t);\n\t}\n\n\t/**\n\t * Ensure a range of BIP44-derived keys are registered as individual vault keys and return their public keys.\n\t * If the first key of the range already exists the range is considered registered and only public keys are derived.\n\t * If not registered, all keys are derived and added to the vault before returning the public keys.\n\t * @param vaultConnector The vault connector to use.\n\t * @param config The configuration to use.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index.\n\t * @param internal Whether the addresses are internal or external.\n\t * @param addressIndex Any address index within the desired chunk; aligned internally.\n\t * @param seedProvider Callback invoked at most once per call to supply the seed when a chunk is not yet registered.\n\t * @returns The base64-encoded public keys for each address in the range.\n\t * @internal\n\t */\n\tprivate static async getPublicKeys(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: Pick<IIotaConfig, \"coinType\">,\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tinternal: boolean,\n\t\taddressIndex: number,\n\t\tseedProvider: () => Promise<Uint8Array>\n\t): Promise<string[]> {\n\t\tconst chunkStart = addressIndex - (addressIndex % Iota._PRE_CALC_CHUNK_SIZE);\n\t\tconst firstKeyName = Iota.buildAddressKeyName(identity, accountIndex, internal, chunkStart);\n\t\tconst publicKeys: string[] = [];\n\n\t\tif (await vaultConnector.keyExists(firstKeyName)) {\n\t\t\tfor (let i = chunkStart; i < chunkStart + Iota._PRE_CALC_CHUNK_SIZE; i++) {\n\t\t\t\tconst keyName = Iota.buildAddressKeyName(identity, accountIndex, internal, i);\n\t\t\t\tconst keyData = await vaultConnector.getKey(keyName, \"public\");\n\t\t\t\tif (!keyData.publicKey) {\n\t\t\t\t\tthrow new GeneralError(Iota.CLASS_NAME, \"missingPublicKey\", { keyName });\n\t\t\t\t}\n\t\t\t\tpublicKeys.push(Converter.bytesToBase64(keyData.publicKey));\n\t\t\t}\n\t\t} else {\n\t\t\tconst seed = await seedProvider();\n\t\t\tconst coinType = config.coinType ?? Iota.DEFAULT_COIN_TYPE;\n\n\t\t\tfor (let i = chunkStart; i < chunkStart + Iota._PRE_CALC_CHUNK_SIZE; i++) {\n\t\t\t\tconst keyName = Iota.buildAddressKeyName(identity, accountIndex, internal, i);\n\t\t\t\tconst keyPair = Bip44.keyPair(seed, KeyType.Ed25519, coinType, accountIndex, internal, i);\n\t\t\t\tawait vaultConnector.addKey(\n\t\t\t\t\tkeyName,\n\t\t\t\t\tVaultKeyType.Ed25519,\n\t\t\t\t\tkeyPair.privateKey,\n\t\t\t\t\tkeyPair.publicKey\n\t\t\t\t);\n\t\t\t\tpublicKeys.push(Converter.bytesToBase64(keyPair.publicKey));\n\t\t\t}\n\t\t}\n\n\t\treturn publicKeys;\n\t}\n\n\t/**\n\t * Build the vault key name for a specific derived address.\n\t * @param identity The identity to use.\n\t * @param accountIndex The account index.\n\t * @param internal Whether the address is internal or external.\n\t * @param addressIndex The address index.\n\t * @returns The vault key name.\n\t * @internal\n\t */\n\tprivate static buildAddressKeyName(\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tinternal: boolean,\n\t\taddressIndex: number\n\t): string {\n\t\treturn VaultConnectorHelper.buildKeyName(\n\t\t\tidentity,\n\t\t\t\"account\",\n\t\t\taccountIndex.toString(),\n\t\t\tinternal ? \"1\" : \"0\",\n\t\t\t`${addressIndex}`\n\t\t);\n\t}\n}\n"]}
|
|
@@ -6,8 +6,7 @@ import { Ed25519Keypair } from "@iota/iota-sdk/keypairs/ed25519";
|
|
|
6
6
|
import { Base64Url, GeneralError, Guards, Is, NotFoundError } from "@twin.org/core";
|
|
7
7
|
import { Iota } from "./iota.js";
|
|
8
8
|
/**
|
|
9
|
-
* Utility class for resolving IOTA Identity on-chain objects
|
|
10
|
-
* the NFT mint_with_identity() Move contract function.
|
|
9
|
+
* Utility class for resolving IOTA Identity on-chain objects and controller tokens.
|
|
11
10
|
*/
|
|
12
11
|
export class IotaIdentityUtils {
|
|
13
12
|
/**
|
|
@@ -15,8 +14,7 @@ export class IotaIdentityUtils {
|
|
|
15
14
|
*/
|
|
16
15
|
static CLASS_NAME = "IotaIdentityUtils";
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
19
|
-
* Returns the IDs needed to call mint_with_identity() on the NFT Move contract.
|
|
17
|
+
* Resolves the on-chain object IDs for an identity and its controller token.
|
|
20
18
|
* @param identityId The DID of the identity (e.g. "did:iota:testnet:0x...").
|
|
21
19
|
* @param controllerAddress The on-chain address of the controller wallet.
|
|
22
20
|
* @param client The IOTA client instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iotaIdentityUtils.js","sourceRoot":"","sources":["../../src/iotaIdentityUtils.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,cAAc,EACd,sBAAsB,EACtB,GAAG,EACH,WAAW,EAGX,aAAa,EACb,eAAe,EACf,OAAO,EACP,aAAa,EACb,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC
|
|
1
|
+
{"version":3,"file":"iotaIdentityUtils.js","sourceRoot":"","sources":["../../src/iotaIdentityUtils.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,cAAc,EACd,sBAAsB,EACtB,GAAG,EACH,WAAW,EAGX,aAAa,EACb,eAAe,EACf,OAAO,EACP,aAAa,EACb,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC7B;;OAEG;IACI,MAAM,CAAU,UAAU,uBAAuC;IAExE;;;;;;;;OAQG;IACI,MAAM,CAAC,KAAK,CAAC,oBAAoB,CACvC,UAAkB,EAClB,iBAAyB,EACzB,MAAmB;QAEnB,MAAM,CAAC,WAAW,CAAC,iBAAiB,CA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;SAC3C,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tIdentityClient,\n\tIdentityClientReadOnly,\n\tJwk,\n\tJwkMemStore,\n\tJwkType,\n\tJwsAlgorithm,\n\tKeyIdMemStore,\n\tOnChainIdentity,\n\tStorage,\n\tStorageSigner\n} from \"@iota/identity-wasm/node/index.js\";\nimport { decodeIotaPrivateKey } from \"@iota/iota-sdk/cryptography\";\nimport { Ed25519Keypair } from \"@iota/iota-sdk/keypairs/ed25519\";\nimport { Base64Url, GeneralError, Guards, Is, NotFoundError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { Iota } from \"./iota.js\";\nimport type { IIotaClient } from \"./models/IIotaClient.js\";\nimport type { IIotaControllerCapInfo } from \"./models/IIotaControllerCapInfo.js\";\n\n/**\n * Utility class for resolving IOTA Identity on-chain objects and controller tokens.\n */\nexport class IotaIdentityUtils {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IotaIdentityUtils>();\n\n\t/**\n\t * Resolves the on-chain object IDs for an identity and its controller token.\n\t * @param identityId The DID of the identity (e.g. \"did:iota:testnet:0x...\").\n\t * @param controllerAddress The on-chain address of the controller wallet.\n\t * @param client The IOTA client instance.\n\t * @returns The identity object ID and controller token object ID.\n\t * @throws NotFoundError if the identity does not exist on-chain.\n\t * @throws GeneralError if the identity has been deleted or the controller token is not found.\n\t */\n\tpublic static async getControllerCapInfo(\n\t\tidentityId: string,\n\t\tcontrollerAddress: string,\n\t\tclient: IIotaClient\n\t): Promise<IIotaControllerCapInfo> {\n\t\tGuards.stringValue(IotaIdentityUtils.CLASS_NAME, nameof(identityId), identityId);\n\t\tGuards.stringValue(IotaIdentityUtils.CLASS_NAME, nameof(controllerAddress), controllerAddress);\n\t\tGuards.object(IotaIdentityUtils.CLASS_NAME, nameof(client), client);\n\n\t\t// Extract the Object ID from the DID — last colon-delimited segment.\n\t\t// On-chain DIDs include the 0x prefix in the segment; the check avoids double-prefixing.\n\t\tconst idParts = identityId.split(\":\");\n\t\tconst lastSegment = idParts[idParts.length - 1];\n\t\tconst identityObjectId = lastSegment.startsWith(\"0x\") ? lastSegment : `0x${lastSegment}`;\n\n\t\tlet onChain: OnChainIdentity | undefined;\n\t\tlet controllerToken: Awaited<ReturnType<OnChainIdentity[\"getControllerTokenForAddress\"]>>;\n\n\t\ttry {\n\t\t\t// IIotaClient and the IotaClient expected by identity-wasm resolve from different\n\t\t\t// module entry points (dist/esm vs dist/cjs). The protected `transport` field causes\n\t\t\t// a structural incompatibility even though the runtime types are identical.\n\t\t\tconst identityClientReadOnly = await IdentityClientReadOnly.create(\n\t\t\t\tclient as unknown as Parameters<(typeof IdentityClientReadOnly)[\"create\"]>[0]\n\t\t\t);\n\n\t\t\t// getControllerTokenForAddress requires IdentityClient even though the operation\n\t\t\t// is read-only — the signer is never called, only the embedded read-only client.\n\t\t\t// StorageSigner is used (rather than a plain object satisfying TransactionSigner\n\t\t\t// structurally) because IdentityClient.create() validates iotaPublicKeyBytes()\n\t\t\t// through an internal WASM code path that only accepts bytes from the library's\n\t\t\t// own signer implementations. Plain JS objects fail with \"Unsupported curve\"\n\t\t\t// even for valid Ed25519 keys because they take a different callback path.\n\t\t\tconst noOpKeypair = new Ed25519Keypair();\n\t\t\tconst rawPublic = noOpKeypair.getPublicKey().toRawBytes();\n\t\t\tconst { secretKey: rawPrivate } = decodeIotaPrivateKey(noOpKeypair.getSecretKey());\n\t\t\tconst noOpSigner = new StorageSigner(\n\t\t\t\tnew Storage(new JwkMemStore(), new KeyIdMemStore()),\n\t\t\t\t\"\",\n\t\t\t\tnew Jwk({\n\t\t\t\t\tkty: JwkType.Okp,\n\t\t\t\t\tcrv: \"Ed25519\",\n\t\t\t\t\talg: JwsAlgorithm.EdDSA,\n\t\t\t\t\tx: Base64Url.encode(rawPublic),\n\t\t\t\t\td: Base64Url.encode(rawPrivate)\n\t\t\t\t})\n\t\t\t);\n\t\t\tconst identityClient = await IdentityClient.create(identityClientReadOnly, noOpSigner);\n\n\t\t\tonChain = await OnChainIdentity.getById(identityObjectId, identityClient);\n\t\t\tif (!Is.undefined(onChain) && !onChain.hasDeletedDid()) {\n\t\t\t\tcontrollerToken = await onChain.getControllerTokenForAddress(\n\t\t\t\t\tcontrollerAddress,\n\t\t\t\t\tidentityClient\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaIdentityUtils.CLASS_NAME,\n\t\t\t\t\"getControllerCapInfoFailed\",\n\t\t\t\tundefined,\n\t\t\t\tIota.extractPayloadError(error)\n\t\t\t);\n\t\t}\n\n\t\tif (Is.undefined(onChain)) {\n\t\t\tthrow new NotFoundError(IotaIdentityUtils.CLASS_NAME, \"identityNotFound\", identityId);\n\t\t}\n\n\t\tif (onChain.hasDeletedDid()) {\n\t\t\tthrow new GeneralError(IotaIdentityUtils.CLASS_NAME, \"identityDeleted\", { identityId });\n\t\t}\n\n\t\tif (Is.undefined(controllerToken)) {\n\t\t\tthrow new NotFoundError(IotaIdentityUtils.CLASS_NAME, \"controllerTokenNotFound\", identityId);\n\t\t}\n\n\t\treturn {\n\t\t\tidentityObjectId,\n\t\t\tcontrollerCapObjectId: controllerToken.id()\n\t\t};\n\t}\n}\n"]}
|
|
@@ -6,7 +6,6 @@ import { GeneralError, Is, StringHelper } from "@twin.org/core";
|
|
|
6
6
|
import { Iota } from "./iota.js";
|
|
7
7
|
/**
|
|
8
8
|
* Utility class providing common smart contract operations for IOTA-based contracts.
|
|
9
|
-
* This class uses composition pattern to provide shared functionality without inheritance complexity.
|
|
10
9
|
*/
|
|
11
10
|
export class IotaSmartContractUtils {
|
|
12
11
|
/**
|
|
@@ -289,6 +288,8 @@ export class IotaSmartContractUtils {
|
|
|
289
288
|
}
|
|
290
289
|
/**
|
|
291
290
|
* Get the package controller address for transactions.
|
|
291
|
+
* @param vaultConnector The vault connector to use.
|
|
292
|
+
* @param config The IOTA configuration.
|
|
292
293
|
* @param identity The identity to use.
|
|
293
294
|
* @param accountAddressIndex Optional account address index to use.
|
|
294
295
|
* @param walletAddressIndex Optional address index to use.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iotaSmartContractUtils.js","sourceRoot":"","sources":["../../src/iotaSmartContractUtils.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAIhE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKjC;;;GAGG;AACH,MAAM,OAAO,sBAAsB;IAClC;;OAEG;IACI,MAAM,CAAU,UAAU,4BAA4C;IAE7E;;;;;;;;;;;;;;;;OAgBG;IACI,MAAM,CAAC,KAAK,CAAC,oBAAoB,CACvC,MAAmB,EACnB,MAAkB,EAClB,cAA+B,EAC/B,OAAsC,EACtC,SAAiB,EACjB,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,gBAA2C,EAC3C,mBAA4B,EAC5B,kBAA2B;QAE3B,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YAE5B,MAAM,UAAU,GAAG,sBAAsB,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;YAEnE,wCAAwC;YACxC,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,2BAA2B,CAC5E,cAAc,EACd,MAAM,EACN,QAAQ,EACR,mBAAmB,EACnB,kBAAkB,CAClB,CAAC;YAEF,qDAAqD;YACrD,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,MAAM,sBAAs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C;gBAClC,KAAK,MAAM,MAAM,IAAI,aAAa,EAAE,CAAC;oBACpC,IACC,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC;wBACxD,YAAY,IAAI,MAAM;wBACtB,MAAM,CAAC,UAAU,KAAK,kBAAkB,EACvC,CAAC;wBACF,gBAAgB,GAAG,MAAM,CAAC,QAAQ,CAAC;wBACnC,MAAM;oBACP,CAAC;gBACF,CAAC;gBACD,IAAI,gBAAgB,EAAE,CAAC;oBACtB,MAAM;gBACP,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACvB,MAAM,IAAI,YAAY,CAAC,sBAAsB,CAAC,UAAU,EAAE,wBAAwB,EAAE;gBACnF,kBAAkB;gBAClB,YAAY;aACZ,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;IACzC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { bcs } from \"@iota/bcs\";\nimport type { IotaClient } from \"@iota/iota-sdk/client\";\nimport { Transaction } from \"@iota/iota-sdk/transactions\";\nimport { GeneralError, Is, StringHelper } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IVaultConnector } from \"@twin.org/vault-models\";\nimport { Iota } from \"./iota.js\";\nimport type { IIotaConfig } from \"./models/IIotaConfig.js\";\nimport type { ISmartContractDeployments } from \"./models/ISmartContractDeployments.js\";\nimport type { NetworkTypes } from \"./models/networkTypes.js\";\n\n/**\n * Utility class providing common smart contract operations for IOTA-based contracts.\n * This class uses composition pattern to provide shared functionality without inheritance complexity.\n */\nexport class IotaSmartContractUtils {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IotaSmartContractUtils>();\n\n\t/**\n\t * Migrate a smart contract object to the current version using admin privileges.\n\t * This is a generic migration method that works with any IOTA smart contract.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param logging Optional logging component.\n\t * @param gasBudget The gas budget for the transaction.\n\t * @param identity The identity of the controller with admin privileges.\n\t * @param objectId The ID of the object to migrate.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param deploymentConfig The deployment configuration containing object IDs.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns Promise that resolves when migration is complete.\n\t */\n\tpublic static async migrateSmartContract(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tgasBudget: number,\n\t\tidentity: string,\n\t\tobjectId: string,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst txb = new Transaction();\n\t\t\ttxb.setGasBudget(gasBudget);\n\n\t\t\tconst moduleName = IotaSmartContractUtils.getModuleName(namespace);\n\n\t\t\t// Get admin address for the transaction\n\t\t\tconst adminAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get the required object IDs from deployment config\n\t\t\tconst { adminCapId, migrationStateId } = await IotaSmartContractUtils.getContractObjectIds(\n\t\t\t\tclient,\n\t\t\t\tnamespace,\n\t\t\t\tconfig.network as NetworkTypes,\n\t\t\t\tdeploymentConfig,\n\t\t\t\tpackageId,\n\t\t\t\tadminAddress\n\t\t\t);\n\n\t\t\ttxb.moveCall({\n\t\t\t\ttarget: `${packageId}::${moduleName}::migrate_${moduleName}`,\n\t\t\t\targuments: [txb.object(adminCapId), txb.object(migrationStateId), txb.object(objectId)]\n\t\t\t});\n\n\t\t\tconst result = await Iota.prepareAndPostTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tlogging,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\tadminAddress,\n\t\t\t\ttxb,\n\t\t\t\t{\n\t\t\t\t\tdryRunLabel: config.enableCostLogging ? \"migrate_object\" : undefined\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif (result.effects?.status?.status !== \"success\") {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"migrationFailed\", {\n\t\t\t\t\terror: result.effects?.status?.error,\n\t\t\t\t\tobjectId\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"migrateSmartContractFailed\",\n\t\t\t\t{ objectId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Enable migration operations using admin privileges.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param logging Optional logging component.\n\t * @param gasBudget The gas budget for the transaction.\n\t * @param identity The identity of the controller with admin privileges.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param deploymentConfig The deployment configuration containing object IDs.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns Promise that resolves when migration is enabled.\n\t */\n\tpublic static async enableMigration(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tgasBudget: number,\n\t\tidentity: string,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst txb = new Transaction();\n\t\t\ttxb.setGasBudget(gasBudget);\n\n\t\t\tconst moduleName = IotaSmartContractUtils.getModuleName(namespace);\n\n\t\t\t// Get admin address for the transaction\n\t\t\tconst adminAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get the required object IDs from deployment config\n\t\t\tconst { adminCapId, migrationStateId } = await IotaSmartContractUtils.getContractObjectIds(\n\t\t\t\tclient,\n\t\t\t\tnamespace,\n\t\t\t\tconfig.network as NetworkTypes,\n\t\t\t\tdeploymentConfig,\n\t\t\t\tpackageId,\n\t\t\t\tadminAddress\n\t\t\t);\n\n\t\t\ttxb.moveCall({\n\t\t\t\ttarget: `${packageId}::${moduleName}::enable_migration`,\n\t\t\t\targuments: [txb.object(adminCapId), txb.object(migrationStateId)]\n\t\t\t});\n\n\t\t\tconst result = await Iota.prepareAndPostTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tlogging,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\tadminAddress,\n\t\t\t\ttxb,\n\t\t\t\t{\n\t\t\t\t\tdryRunLabel: config.enableCostLogging ? \"enable_migration\" : undefined\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif (result.effects?.status?.status !== \"success\") {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"enableMigrationFailed\", {\n\t\t\t\t\terror: result.effects?.status?.error\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"enableMigrationFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Disable migration operations using admin privileges.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param logging Optional logging component.\n\t * @param gasBudget The gas budget for the transaction.\n\t * @param identity The identity of the controller with admin privileges.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param deploymentConfig The deployment configuration containing object IDs.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns Promise that resolves when migration is disabled.\n\t */\n\tpublic static async disableMigration(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tgasBudget: number,\n\t\tidentity: string,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst txb = new Transaction();\n\t\t\ttxb.setGasBudget(gasBudget);\n\n\t\t\tconst moduleName = IotaSmartContractUtils.getModuleName(namespace);\n\n\t\t\t// Get admin address for the transaction\n\t\t\tconst adminAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get the required object IDs from deployment config\n\t\t\tconst { adminCapId, migrationStateId } = await IotaSmartContractUtils.getContractObjectIds(\n\t\t\t\tclient,\n\t\t\t\tnamespace,\n\t\t\t\tconfig.network as NetworkTypes,\n\t\t\t\tdeploymentConfig,\n\t\t\t\tpackageId,\n\t\t\t\tadminAddress\n\t\t\t);\n\n\t\t\ttxb.moveCall({\n\t\t\t\ttarget: `${packageId}::${moduleName}::disable_migration`,\n\t\t\t\targuments: [txb.object(adminCapId), txb.object(migrationStateId)]\n\t\t\t});\n\n\t\t\tconst result = await Iota.prepareAndPostTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tlogging,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\tadminAddress,\n\t\t\t\ttxb,\n\t\t\t\t{\n\t\t\t\t\tdryRunLabel: config.enableCostLogging ? \"disable_migration\" : undefined\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif (result.effects?.status?.status !== \"success\") {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"disableMigrationFailed\", {\n\t\t\t\t\terror: result.effects?.status?.error\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"disableMigrationFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Check if migration is currently active for a smart contract.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param deploymentConfig The deployment configuration containing object IDs.\n\t * @param identity The identity for MigrationState discovery.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns True if migration is enabled, false otherwise.\n\t */\n\tpublic static async isMigrationActive(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\tidentity: string,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<boolean> {\n\t\ttry {\n\t\t\t// Get admin address for discovery\n\t\t\tconst adminAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get the migration state ID\n\t\t\tconst { migrationStateId } = await IotaSmartContractUtils.getContractObjectIds(\n\t\t\t\tclient,\n\t\t\t\tnamespace,\n\t\t\t\tconfig.network as NetworkTypes,\n\t\t\t\tdeploymentConfig,\n\t\t\t\tpackageId,\n\t\t\t\tadminAddress\n\t\t\t);\n\n\t\t\tconst migrationStateResponse = await client.getObject({\n\t\t\t\tid: migrationStateId,\n\t\t\t\toptions: {\n\t\t\t\t\tshowContent: true,\n\t\t\t\t\tshowType: true\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (!migrationStateResponse.data?.content) {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"migrationStateNotReadable\", {\n\t\t\t\t\tmigrationStateId\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst content = migrationStateResponse.data.content;\n\t\t\tif (content.dataType === \"moveObject\" && Is.objectValue(content.fields)) {\n\t\t\t\tconst fields = content.fields as { enabled: boolean };\n\t\t\t\treturn Is.boolean(fields.enabled) ? fields.enabled : false;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"isMigrationActiveFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get the current contract version from the deployed smart contract.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param identity The identity for package controller address.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns The current version number of the contract.\n\t */\n\tpublic static async getCurrentContractVersion(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tidentity: string,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<number> {\n\t\ttry {\n\t\t\tconst tx = new Transaction();\n\t\t\tconst moduleName = IotaSmartContractUtils.getModuleName(namespace);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${packageId}::${moduleName}::get_current_version`,\n\t\t\t\targuments: []\n\t\t\t});\n\n\t\t\tconst controllerAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\tconst result = await client.devInspectTransactionBlock({\n\t\t\t\tsender: controllerAddress,\n\t\t\t\ttransactionBlock: tx\n\t\t\t});\n\n\t\t\tif (\n\t\t\t\tIs.arrayValue(result.results) &&\n\t\t\t\tIs.object(result.results[0]) &&\n\t\t\t\tIs.arrayValue<Uint8Array>(result.results[0].returnValues)\n\t\t\t) {\n\t\t\t\tconst versionBytes = result.results[0].returnValues[0];\n\n\t\t\t\t// Convert to Uint8Array if it's a regular array\n\t\t\t\tconst byteData = versionBytes[0];\n\t\t\t\tif (!Is.arrayValue(byteData) && !Is.uint8Array(byteData)) {\n\t\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"invalidVersionData\");\n\t\t\t\t}\n\n\t\t\t\t// Convert to Uint8Array for BCS parsing\n\t\t\t\tconst uint8Data = Is.uint8Array(byteData) ? byteData : new Uint8Array(byteData);\n\n\t\t\t\t// The version is returned as a u64, decode it from bytes using BCS\n\t\t\t\t// IOTA Move contracts return data in BCS format\n\t\t\t\tconst version = Number(bcs.u64().parse(uint8Data));\n\t\t\t\treturn version;\n\t\t\t}\n\n\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"getCurrentContractVersionNoData\", {\n\t\t\t\tresultExists: Is.arrayValue(result.results),\n\t\t\t\tresultLength: Is.arrayValue(result.results) ? result.results.length : 0,\n\t\t\t\thasReturnValues: Is.arrayValue(result.results?.[0]?.returnValues)\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"getCurrentContractVersionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Validate that an object version is compatible with the current contract.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param identity The identity for version checking.\n\t * @param objectId The object ID to validate.\n\t * @param versionExtractor Function to extract version from object content.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns True if the object version is compatible, false otherwise.\n\t */\n\tpublic static async validateObjectVersion<T>(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tidentity: string,\n\t\tobjectId: string,\n\t\tversionExtractor: (content: T) => number,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<boolean> {\n\t\ttry {\n\t\t\t// Get current contract version\n\t\t\tconst currentVersion = await IotaSmartContractUtils.getCurrentContractVersion(\n\t\t\t\tconfig,\n\t\t\t\tclient,\n\t\t\t\tvaultConnector,\n\t\t\t\tnamespace,\n\t\t\t\tpackageId,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get object version\n\t\t\tconst objectResponse = await client.getObject({\n\t\t\t\tid: objectId,\n\t\t\t\toptions: {\n\t\t\t\t\tshowContent: true,\n\t\t\t\t\tshowType: true\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (!objectResponse.data?.content) {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"objectNotReadable\", {\n\t\t\t\t\tobjectId\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst content = objectResponse.data.content;\n\t\t\tif (content.dataType === \"moveObject\" && Is.objectValue(content.fields)) {\n\t\t\t\tconst objectVersion = versionExtractor(content as T);\n\t\t\t\treturn objectVersion <= currentVersion;\n\t\t\t}\n\n\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"objectInvalidFormat\", {\n\t\t\t\tobjectId,\n\t\t\t\tcontent\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"validateObjectVersionFailed\",\n\t\t\t\t{ objectId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get the module name for a given namespace.\n\t * @param namespace The contract namespace.\n\t * @returns The module name in snake_case format.\n\t * @internal\n\t */\n\tprivate static getModuleName(namespace: string): string {\n\t\t// Convert namespace to snake_case for module name\n\t\treturn StringHelper.snakeCase(namespace);\n\t}\n\n\t/**\n\t * Get the package controller address for transactions.\n\t * @param identity The identity to use.\n\t * @param accountAddressIndex Optional account address index to use.\n\t * @param walletAddressIndex Optional address index to use.\n\t * @returns The controller address.\n\t * @internal\n\t */\n\tprivate static async getPackageControllerAddress(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: IIotaConfig,\n\t\tidentity: string,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<string> {\n\t\tconst address = await Iota.getAddress(\n\t\t\tvaultConnector,\n\t\t\tconfig,\n\t\t\tidentity,\n\t\t\taccountAddressIndex ?? 0,\n\t\t\twalletAddressIndex ?? 0\n\t\t);\n\t\treturn address;\n\t}\n\n\t/**\n\t * Get contract object IDs (AdminCap and MigrationState) from deployment config with fallback discovery.\n\t * @param client The IOTA client instance.\n\t * @param namespace The contract namespace.\n\t * @param network The network name.\n\t * @param deploymentConfig The deployment configuration.\n\t * @param packageId The package ID.\n\t * @param adminAddress The admin address for object discovery.\n\t * @returns Object containing adminCapId and migrationStateId.\n\t * @internal\n\t */\n\tprivate static async getContractObjectIds(\n\t\tclient: IotaClient,\n\t\tnamespace: string,\n\t\tnetwork: NetworkTypes,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\tpackageId: string,\n\t\tadminAddress: string\n\t): Promise<{ adminCapId: string; migrationStateId: string }> {\n\t\ttry {\n\t\t\t// First try to load from deployment JSON\n\t\t\tconst networkConfig = deploymentConfig[network];\n\t\t\tif (Is.objectValue(networkConfig)) {\n\t\t\t\tconst migrationStateId = networkConfig.migrationStateId;\n\n\t\t\t\t// AdminCap must be discovered from blockchain (not stored in JSON)\n\t\t\t\tconst adminCapId = await IotaSmartContractUtils.discoverAdminCap(\n\t\t\t\t\tclient,\n\t\t\t\t\tpackageId,\n\t\t\t\t\tnamespace,\n\t\t\t\t\tadminAddress\n\t\t\t\t);\n\n\t\t\t\tif (Is.stringValue(migrationStateId) && Is.stringValue(adminCapId)) {\n\t\t\t\t\treturn { adminCapId, migrationStateId };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Fallback: discover both from blockchain\n\t\t\treturn await IotaSmartContractUtils.discoverContractObjectsFromBlockchain(\n\t\t\t\tclient,\n\t\t\t\tpackageId,\n\t\t\t\tnamespace,\n\t\t\t\tadminAddress\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"getContractObjectIdsFailed\",\n\t\t\t\t{ namespace, network, packageId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Discover AdminCap object from the blockchain.\n\t * @param client The IOTA client instance.\n\t * @param packageId The package ID.\n\t * @param namespace The contract namespace.\n\t * @param adminAddress The admin address.\n\t * @returns The AdminCap object ID.\n\t * @internal\n\t */\n\tprivate static async discoverAdminCap(\n\t\tclient: IotaClient,\n\t\tpackageId: string,\n\t\tnamespace: string,\n\t\tadminAddress: string\n\t): Promise<string> {\n\t\tconst adminCapType = `${packageId}::${IotaSmartContractUtils.getModuleName(namespace)}::AdminCap`;\n\n\t\tconst adminCapObjects = await client.getOwnedObjects({\n\t\t\towner: adminAddress,\n\t\t\tfilter: {\n\t\t\t\tStructType: adminCapType\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tshowContent: true,\n\t\t\t\tshowType: true\n\t\t\t}\n\t\t});\n\n\t\tif (Is.arrayValue(adminCapObjects.data) && adminCapObjects.data.length > 0) {\n\t\t\tconst adminCapObject = adminCapObjects.data[0];\n\t\t\tif (Is.stringValue(adminCapObject.data?.objectId)) {\n\t\t\t\treturn adminCapObject.data.objectId;\n\t\t\t}\n\t\t}\n\n\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"adminCapNotFound\", {\n\t\t\tadminCapType,\n\t\t\tadminAddress\n\t\t});\n\t}\n\n\t/**\n\t * Discover contract objects from blockchain as fallback.\n\t * @param client The IOTA client instance.\n\t * @param packageId The package ID.\n\t * @param namespace The contract namespace.\n\t * @param adminAddress The admin address.\n\t * @returns Object containing adminCapId and migrationStateId.\n\t * @internal\n\t */\n\tprivate static async discoverContractObjectsFromBlockchain(\n\t\tclient: IotaClient,\n\t\tpackageId: string,\n\t\tnamespace: string,\n\t\tadminAddress: string\n\t): Promise<{ adminCapId: string; migrationStateId: string }> {\n\t\t// Discover AdminCap\n\t\tconst adminCapId = await IotaSmartContractUtils.discoverAdminCap(\n\t\t\tclient,\n\t\t\tpackageId,\n\t\t\tnamespace,\n\t\t\tadminAddress\n\t\t);\n\n\t\t// Discover MigrationState through transaction history\n\t\tconst migrationStateType = `${packageId}::${IotaSmartContractUtils.getModuleName(namespace)}::MigrationState`;\n\n\t\tconst transactions = await client.queryTransactionBlocks({\n\t\t\tfilter: {\n\t\t\t\tFromAddress: adminAddress\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tshowObjectChanges: true,\n\t\t\t\tshowEffects: true\n\t\t\t},\n\t\t\tlimit: 20,\n\t\t\torder: \"descending\"\n\t\t});\n\n\t\t// Look for MigrationState object creation in transaction history\n\t\tlet migrationStateId: string | undefined;\n\t\tfor (const tx of transactions.data) {\n\t\t\tconst objectChanges = tx.objectChanges;\n\t\t\tif (Is.arrayValue(objectChanges)) {\n\t\t\t\tfor (const change of objectChanges) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t(change.type === \"created\" || change.type === \"mutated\") &&\n\t\t\t\t\t\t\"objectType\" in change &&\n\t\t\t\t\t\tchange.objectType === migrationStateType\n\t\t\t\t\t) {\n\t\t\t\t\t\tmigrationStateId = change.objectId;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (migrationStateId) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!migrationStateId) {\n\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"migrationStateNotFound\", {\n\t\t\t\tmigrationStateType,\n\t\t\t\tadminAddress\n\t\t\t});\n\t\t}\n\n\t\treturn { adminCapId, migrationStateId };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"iotaSmartContractUtils.js","sourceRoot":"","sources":["../../src/iotaSmartContractUtils.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE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C,gBAAgB,EAAE,CAAC;YACvB,MAAM,IAAI,YAAY,CAAC,sBAAsB,CAAC,UAAU,EAAE,wBAAwB,EAAE;gBACnF,kBAAkB;gBAClB,YAAY;aACZ,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;IACzC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { bcs } from \"@iota/bcs\";\nimport type { IotaClient } from \"@iota/iota-sdk/client\";\nimport { Transaction } from \"@iota/iota-sdk/transactions\";\nimport { GeneralError, Is, StringHelper } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IVaultConnector } from \"@twin.org/vault-models\";\nimport { Iota } from \"./iota.js\";\nimport type { IIotaConfig } from \"./models/IIotaConfig.js\";\nimport type { ISmartContractDeployments } from \"./models/ISmartContractDeployments.js\";\nimport type { NetworkTypes } from \"./models/networkTypes.js\";\n\n/**\n * Utility class providing common smart contract operations for IOTA-based contracts.\n */\nexport class IotaSmartContractUtils {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IotaSmartContractUtils>();\n\n\t/**\n\t * Migrate a smart contract object to the current version using admin privileges.\n\t * This is a generic migration method that works with any IOTA smart contract.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param logging Optional logging component.\n\t * @param gasBudget The gas budget for the transaction.\n\t * @param identity The identity of the controller with admin privileges.\n\t * @param objectId The ID of the object to migrate.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param deploymentConfig The deployment configuration containing object IDs.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns Promise that resolves when migration is complete.\n\t */\n\tpublic static async migrateSmartContract(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tgasBudget: number,\n\t\tidentity: string,\n\t\tobjectId: string,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst txb = new Transaction();\n\t\t\ttxb.setGasBudget(gasBudget);\n\n\t\t\tconst moduleName = IotaSmartContractUtils.getModuleName(namespace);\n\n\t\t\t// Get admin address for the transaction\n\t\t\tconst adminAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get the required object IDs from deployment config\n\t\t\tconst { adminCapId, migrationStateId } = await IotaSmartContractUtils.getContractObjectIds(\n\t\t\t\tclient,\n\t\t\t\tnamespace,\n\t\t\t\tconfig.network as NetworkTypes,\n\t\t\t\tdeploymentConfig,\n\t\t\t\tpackageId,\n\t\t\t\tadminAddress\n\t\t\t);\n\n\t\t\ttxb.moveCall({\n\t\t\t\ttarget: `${packageId}::${moduleName}::migrate_${moduleName}`,\n\t\t\t\targuments: [txb.object(adminCapId), txb.object(migrationStateId), txb.object(objectId)]\n\t\t\t});\n\n\t\t\tconst result = await Iota.prepareAndPostTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tlogging,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\tadminAddress,\n\t\t\t\ttxb,\n\t\t\t\t{\n\t\t\t\t\tdryRunLabel: config.enableCostLogging ? \"migrate_object\" : undefined\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif (result.effects?.status?.status !== \"success\") {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"migrationFailed\", {\n\t\t\t\t\terror: result.effects?.status?.error,\n\t\t\t\t\tobjectId\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"migrateSmartContractFailed\",\n\t\t\t\t{ objectId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Enable migration operations using admin privileges.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param logging Optional logging component.\n\t * @param gasBudget The gas budget for the transaction.\n\t * @param identity The identity of the controller with admin privileges.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param deploymentConfig The deployment configuration containing object IDs.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns Promise that resolves when migration is enabled.\n\t */\n\tpublic static async enableMigration(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tgasBudget: number,\n\t\tidentity: string,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst txb = new Transaction();\n\t\t\ttxb.setGasBudget(gasBudget);\n\n\t\t\tconst moduleName = IotaSmartContractUtils.getModuleName(namespace);\n\n\t\t\t// Get admin address for the transaction\n\t\t\tconst adminAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get the required object IDs from deployment config\n\t\t\tconst { adminCapId, migrationStateId } = await IotaSmartContractUtils.getContractObjectIds(\n\t\t\t\tclient,\n\t\t\t\tnamespace,\n\t\t\t\tconfig.network as NetworkTypes,\n\t\t\t\tdeploymentConfig,\n\t\t\t\tpackageId,\n\t\t\t\tadminAddress\n\t\t\t);\n\n\t\t\ttxb.moveCall({\n\t\t\t\ttarget: `${packageId}::${moduleName}::enable_migration`,\n\t\t\t\targuments: [txb.object(adminCapId), txb.object(migrationStateId)]\n\t\t\t});\n\n\t\t\tconst result = await Iota.prepareAndPostTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tlogging,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\tadminAddress,\n\t\t\t\ttxb,\n\t\t\t\t{\n\t\t\t\t\tdryRunLabel: config.enableCostLogging ? \"enable_migration\" : undefined\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif (result.effects?.status?.status !== \"success\") {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"enableMigrationFailed\", {\n\t\t\t\t\terror: result.effects?.status?.error\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"enableMigrationFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Disable migration operations using admin privileges.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param logging Optional logging component.\n\t * @param gasBudget The gas budget for the transaction.\n\t * @param identity The identity of the controller with admin privileges.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param deploymentConfig The deployment configuration containing object IDs.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns Promise that resolves when migration is disabled.\n\t */\n\tpublic static async disableMigration(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tlogging: ILoggingComponent | undefined,\n\t\tgasBudget: number,\n\t\tidentity: string,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst txb = new Transaction();\n\t\t\ttxb.setGasBudget(gasBudget);\n\n\t\t\tconst moduleName = IotaSmartContractUtils.getModuleName(namespace);\n\n\t\t\t// Get admin address for the transaction\n\t\t\tconst adminAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get the required object IDs from deployment config\n\t\t\tconst { adminCapId, migrationStateId } = await IotaSmartContractUtils.getContractObjectIds(\n\t\t\t\tclient,\n\t\t\t\tnamespace,\n\t\t\t\tconfig.network as NetworkTypes,\n\t\t\t\tdeploymentConfig,\n\t\t\t\tpackageId,\n\t\t\t\tadminAddress\n\t\t\t);\n\n\t\t\ttxb.moveCall({\n\t\t\t\ttarget: `${packageId}::${moduleName}::disable_migration`,\n\t\t\t\targuments: [txb.object(adminCapId), txb.object(migrationStateId)]\n\t\t\t});\n\n\t\t\tconst result = await Iota.prepareAndPostTransaction(\n\t\t\t\tconfig,\n\t\t\t\tvaultConnector,\n\t\t\t\tlogging,\n\t\t\t\tidentity,\n\t\t\t\tclient,\n\t\t\t\tadminAddress,\n\t\t\t\ttxb,\n\t\t\t\t{\n\t\t\t\t\tdryRunLabel: config.enableCostLogging ? \"disable_migration\" : undefined\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif (result.effects?.status?.status !== \"success\") {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"disableMigrationFailed\", {\n\t\t\t\t\terror: result.effects?.status?.error\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"disableMigrationFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Check if migration is currently active for a smart contract.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param deploymentConfig The deployment configuration containing object IDs.\n\t * @param identity The identity for MigrationState discovery.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns True if migration is enabled, false otherwise.\n\t */\n\tpublic static async isMigrationActive(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\tidentity: string,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<boolean> {\n\t\ttry {\n\t\t\t// Get admin address for discovery\n\t\t\tconst adminAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get the migration state ID\n\t\t\tconst { migrationStateId } = await IotaSmartContractUtils.getContractObjectIds(\n\t\t\t\tclient,\n\t\t\t\tnamespace,\n\t\t\t\tconfig.network as NetworkTypes,\n\t\t\t\tdeploymentConfig,\n\t\t\t\tpackageId,\n\t\t\t\tadminAddress\n\t\t\t);\n\n\t\t\tconst migrationStateResponse = await client.getObject({\n\t\t\t\tid: migrationStateId,\n\t\t\t\toptions: {\n\t\t\t\t\tshowContent: true,\n\t\t\t\t\tshowType: true\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (!migrationStateResponse.data?.content) {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"migrationStateNotReadable\", {\n\t\t\t\t\tmigrationStateId\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst content = migrationStateResponse.data.content;\n\t\t\tif (content.dataType === \"moveObject\" && Is.objectValue(content.fields)) {\n\t\t\t\tconst fields = content.fields as { enabled: boolean };\n\t\t\t\treturn Is.boolean(fields.enabled) ? fields.enabled : false;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"isMigrationActiveFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get the current contract version from the deployed smart contract.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param identity The identity for package controller address.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns The current version number of the contract.\n\t */\n\tpublic static async getCurrentContractVersion(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tidentity: string,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<number> {\n\t\ttry {\n\t\t\tconst tx = new Transaction();\n\t\t\tconst moduleName = IotaSmartContractUtils.getModuleName(namespace);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${packageId}::${moduleName}::get_current_version`,\n\t\t\t\targuments: []\n\t\t\t});\n\n\t\t\tconst controllerAddress = await IotaSmartContractUtils.getPackageControllerAddress(\n\t\t\t\tvaultConnector,\n\t\t\t\tconfig,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\tconst result = await client.devInspectTransactionBlock({\n\t\t\t\tsender: controllerAddress,\n\t\t\t\ttransactionBlock: tx\n\t\t\t});\n\n\t\t\tif (\n\t\t\t\tIs.arrayValue(result.results) &&\n\t\t\t\tIs.object(result.results[0]) &&\n\t\t\t\tIs.arrayValue<Uint8Array>(result.results[0].returnValues)\n\t\t\t) {\n\t\t\t\tconst versionBytes = result.results[0].returnValues[0];\n\n\t\t\t\t// Convert to Uint8Array if it's a regular array\n\t\t\t\tconst byteData = versionBytes[0];\n\t\t\t\tif (!Is.arrayValue(byteData) && !Is.uint8Array(byteData)) {\n\t\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"invalidVersionData\");\n\t\t\t\t}\n\n\t\t\t\t// Convert to Uint8Array for BCS parsing\n\t\t\t\tconst uint8Data = Is.uint8Array(byteData) ? byteData : new Uint8Array(byteData);\n\n\t\t\t\t// The version is returned as a u64, decode it from bytes using BCS\n\t\t\t\t// IOTA Move contracts return data in BCS format\n\t\t\t\tconst version = Number(bcs.u64().parse(uint8Data));\n\t\t\t\treturn version;\n\t\t\t}\n\n\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"getCurrentContractVersionNoData\", {\n\t\t\t\tresultExists: Is.arrayValue(result.results),\n\t\t\t\tresultLength: Is.arrayValue(result.results) ? result.results.length : 0,\n\t\t\t\thasReturnValues: Is.arrayValue(result.results?.[0]?.returnValues)\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"getCurrentContractVersionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Validate that an object version is compatible with the current contract.\n\t * @param config The IOTA configuration.\n\t * @param client The IOTA client instance.\n\t * @param vaultConnector The vault connector for key management.\n\t * @param namespace The contract namespace (e.g., \"nft\", \"verifiable_storage\").\n\t * @param packageId The deployed package ID for the contract.\n\t * @param identity The identity for version checking.\n\t * @param objectId The object ID to validate.\n\t * @param versionExtractor Function to extract version from object content.\n\t * @param accountAddressIndex Optional account address index for the controller.\n\t * @param walletAddressIndex Optional wallet address index for the controller.\n\t * @returns True if the object version is compatible, false otherwise.\n\t */\n\tpublic static async validateObjectVersion<T>(\n\t\tconfig: IIotaConfig,\n\t\tclient: IotaClient,\n\t\tvaultConnector: IVaultConnector,\n\t\tnamespace: string,\n\t\tpackageId: string,\n\t\tidentity: string,\n\t\tobjectId: string,\n\t\tversionExtractor: (content: T) => number,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<boolean> {\n\t\ttry {\n\t\t\t// Get current contract version\n\t\t\tconst currentVersion = await IotaSmartContractUtils.getCurrentContractVersion(\n\t\t\t\tconfig,\n\t\t\t\tclient,\n\t\t\t\tvaultConnector,\n\t\t\t\tnamespace,\n\t\t\t\tpackageId,\n\t\t\t\tidentity,\n\t\t\t\taccountAddressIndex,\n\t\t\t\twalletAddressIndex\n\t\t\t);\n\n\t\t\t// Get object version\n\t\t\tconst objectResponse = await client.getObject({\n\t\t\t\tid: objectId,\n\t\t\t\toptions: {\n\t\t\t\t\tshowContent: true,\n\t\t\t\t\tshowType: true\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tif (!objectResponse.data?.content) {\n\t\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"objectNotReadable\", {\n\t\t\t\t\tobjectId\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst content = objectResponse.data.content;\n\t\t\tif (content.dataType === \"moveObject\" && Is.objectValue(content.fields)) {\n\t\t\t\tconst objectVersion = versionExtractor(content as T);\n\t\t\t\treturn objectVersion <= currentVersion;\n\t\t\t}\n\n\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"objectInvalidFormat\", {\n\t\t\t\tobjectId,\n\t\t\t\tcontent\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"validateObjectVersionFailed\",\n\t\t\t\t{ objectId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get the module name for a given namespace.\n\t * @param namespace The contract namespace.\n\t * @returns The module name in snake_case format.\n\t * @internal\n\t */\n\tprivate static getModuleName(namespace: string): string {\n\t\t// Convert namespace to snake_case for module name\n\t\treturn StringHelper.snakeCase(namespace);\n\t}\n\n\t/**\n\t * Get the package controller address for transactions.\n\t * @param vaultConnector The vault connector to use.\n\t * @param config The IOTA configuration.\n\t * @param identity The identity to use.\n\t * @param accountAddressIndex Optional account address index to use.\n\t * @param walletAddressIndex Optional address index to use.\n\t * @returns The controller address.\n\t * @internal\n\t */\n\tprivate static async getPackageControllerAddress(\n\t\tvaultConnector: IVaultConnector,\n\t\tconfig: IIotaConfig,\n\t\tidentity: string,\n\t\taccountAddressIndex?: number,\n\t\twalletAddressIndex?: number\n\t): Promise<string> {\n\t\tconst address = await Iota.getAddress(\n\t\t\tvaultConnector,\n\t\t\tconfig,\n\t\t\tidentity,\n\t\t\taccountAddressIndex ?? 0,\n\t\t\twalletAddressIndex ?? 0\n\t\t);\n\t\treturn address;\n\t}\n\n\t/**\n\t * Get contract object IDs (AdminCap and MigrationState) from deployment config with fallback discovery.\n\t * @param client The IOTA client instance.\n\t * @param namespace The contract namespace.\n\t * @param network The network name.\n\t * @param deploymentConfig The deployment configuration.\n\t * @param packageId The package ID.\n\t * @param adminAddress The admin address for object discovery.\n\t * @returns Object containing adminCapId and migrationStateId.\n\t * @internal\n\t */\n\tprivate static async getContractObjectIds(\n\t\tclient: IotaClient,\n\t\tnamespace: string,\n\t\tnetwork: NetworkTypes,\n\t\tdeploymentConfig: ISmartContractDeployments,\n\t\tpackageId: string,\n\t\tadminAddress: string\n\t): Promise<{ adminCapId: string; migrationStateId: string }> {\n\t\ttry {\n\t\t\t// First try to load from deployment JSON\n\t\t\tconst networkConfig = deploymentConfig[network];\n\t\t\tif (Is.objectValue(networkConfig)) {\n\t\t\t\tconst migrationStateId = networkConfig.migrationStateId;\n\n\t\t\t\t// AdminCap must be discovered from blockchain (not stored in JSON)\n\t\t\t\tconst adminCapId = await IotaSmartContractUtils.discoverAdminCap(\n\t\t\t\t\tclient,\n\t\t\t\t\tpackageId,\n\t\t\t\t\tnamespace,\n\t\t\t\t\tadminAddress\n\t\t\t\t);\n\n\t\t\t\tif (Is.stringValue(migrationStateId) && Is.stringValue(adminCapId)) {\n\t\t\t\t\treturn { adminCapId, migrationStateId };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Fallback: discover both from blockchain\n\t\t\treturn await IotaSmartContractUtils.discoverContractObjectsFromBlockchain(\n\t\t\t\tclient,\n\t\t\t\tpackageId,\n\t\t\t\tnamespace,\n\t\t\t\tadminAddress\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIotaSmartContractUtils.CLASS_NAME,\n\t\t\t\t\"getContractObjectIdsFailed\",\n\t\t\t\t{ namespace, network, packageId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Discover AdminCap object from the blockchain.\n\t * @param client The IOTA client instance.\n\t * @param packageId The package ID.\n\t * @param namespace The contract namespace.\n\t * @param adminAddress The admin address.\n\t * @returns The AdminCap object ID.\n\t * @internal\n\t */\n\tprivate static async discoverAdminCap(\n\t\tclient: IotaClient,\n\t\tpackageId: string,\n\t\tnamespace: string,\n\t\tadminAddress: string\n\t): Promise<string> {\n\t\tconst adminCapType = `${packageId}::${IotaSmartContractUtils.getModuleName(namespace)}::AdminCap`;\n\n\t\tconst adminCapObjects = await client.getOwnedObjects({\n\t\t\towner: adminAddress,\n\t\t\tfilter: {\n\t\t\t\tStructType: adminCapType\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tshowContent: true,\n\t\t\t\tshowType: true\n\t\t\t}\n\t\t});\n\n\t\tif (Is.arrayValue(adminCapObjects.data) && adminCapObjects.data.length > 0) {\n\t\t\tconst adminCapObject = adminCapObjects.data[0];\n\t\t\tif (Is.stringValue(adminCapObject.data?.objectId)) {\n\t\t\t\treturn adminCapObject.data.objectId;\n\t\t\t}\n\t\t}\n\n\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"adminCapNotFound\", {\n\t\t\tadminCapType,\n\t\t\tadminAddress\n\t\t});\n\t}\n\n\t/**\n\t * Discover contract objects from blockchain as fallback.\n\t * @param client The IOTA client instance.\n\t * @param packageId The package ID.\n\t * @param namespace The contract namespace.\n\t * @param adminAddress The admin address.\n\t * @returns Object containing adminCapId and migrationStateId.\n\t * @internal\n\t */\n\tprivate static async discoverContractObjectsFromBlockchain(\n\t\tclient: IotaClient,\n\t\tpackageId: string,\n\t\tnamespace: string,\n\t\tadminAddress: string\n\t): Promise<{ adminCapId: string; migrationStateId: string }> {\n\t\t// Discover AdminCap\n\t\tconst adminCapId = await IotaSmartContractUtils.discoverAdminCap(\n\t\t\tclient,\n\t\t\tpackageId,\n\t\t\tnamespace,\n\t\t\tadminAddress\n\t\t);\n\n\t\t// Discover MigrationState through transaction history\n\t\tconst migrationStateType = `${packageId}::${IotaSmartContractUtils.getModuleName(namespace)}::MigrationState`;\n\n\t\tconst transactions = await client.queryTransactionBlocks({\n\t\t\tfilter: {\n\t\t\t\tFromAddress: adminAddress\n\t\t\t},\n\t\t\toptions: {\n\t\t\t\tshowObjectChanges: true,\n\t\t\t\tshowEffects: true\n\t\t\t},\n\t\t\tlimit: 20,\n\t\t\torder: \"descending\"\n\t\t});\n\n\t\t// Look for MigrationState object creation in transaction history\n\t\tlet migrationStateId: string | undefined;\n\t\tfor (const tx of transactions.data) {\n\t\t\tconst objectChanges = tx.objectChanges;\n\t\t\tif (Is.arrayValue(objectChanges)) {\n\t\t\t\tfor (const change of objectChanges) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t(change.type === \"created\" || change.type === \"mutated\") &&\n\t\t\t\t\t\t\"objectType\" in change &&\n\t\t\t\t\t\tchange.objectType === migrationStateType\n\t\t\t\t\t) {\n\t\t\t\t\t\tmigrationStateId = change.objectId;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (migrationStateId) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!migrationStateId) {\n\t\t\tthrow new GeneralError(IotaSmartContractUtils.CLASS_NAME, \"migrationStateNotFound\", {\n\t\t\t\tmigrationStateType,\n\t\t\t\tadminAddress\n\t\t\t});\n\t\t}\n\n\t\treturn { adminCapId, migrationStateId };\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IAdminCapFields.js","sourceRoot":"","sources":["../../../src/models/IAdminCapFields.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Generic interface representing the storage fields of an AdminCap object.\n */\nexport interface IAdminCapFields {\n\t/**\n\t * The
|
|
1
|
+
{"version":3,"file":"IAdminCapFields.js","sourceRoot":"","sources":["../../../src/models/IAdminCapFields.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Generic interface representing the storage fields of an AdminCap object.\n */\nexport interface IAdminCapFields {\n\t/**\n\t * The UID wrapper of the AdminCap object.\n\t */\n\tid: {\n\t\t/**\n\t\t * The hex string ID of the AdminCap object.\n\t\t */\n\t\tid: string;\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IGasStationExecuteResponse.js","sourceRoot":"","sources":["../../../src/models/IGasStationExecuteResponse.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface for the gas station execute transaction response.\n */\nexport interface IGasStationExecuteResponse {\n\t/**\n\t * The transaction effects from the IOTA network.\n\t
|
|
1
|
+
{"version":3,"file":"IGasStationExecuteResponse.js","sourceRoot":"","sources":["../../../src/models/IGasStationExecuteResponse.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface for the gas station execute transaction response.\n */\nexport interface IGasStationExecuteResponse {\n\t/**\n\t * The transaction effects from the IOTA network.\n\t */\n\teffects: {\n\t\t/**\n\t\t * Additional fields from the IOTA network effects object.\n\t\t */\n\t\t[key: string]: unknown;\n\n\t\t/**\n\t\t * The transaction digest.\n\t\t */\n\t\ttransactionDigest: string;\n\t};\n\n\t/**\n\t * Error message if the request failed.\n\t */\n\terror?: string | null;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IIotaControllerCapInfo.js","sourceRoot":"","sources":["../../../src/models/IIotaControllerCapInfo.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * On-chain object IDs
|
|
1
|
+
{"version":3,"file":"IIotaControllerCapInfo.js","sourceRoot":"","sources":["../../../src/models/IIotaControllerCapInfo.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * On-chain object IDs for an identity and its associated controller token.\n */\nexport interface IIotaControllerCapInfo {\n\t/**\n\t * The on-chain object ID of the Identity Move object (hex string, e.g. \"0x...\").\n\t */\n\tidentityObjectId: string;\n\n\t/**\n\t * The on-chain object ID of the ControllerToken Move object (hex string, e.g. \"0x...\").\n\t */\n\tcontrollerCapObjectId: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IIotaResponseOptions.js","sourceRoot":"","sources":["../../../src/models/IIotaResponseOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IotaTransactionBlockResponseOptions } from \"@iota/iota-sdk/client\";\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"IIotaResponseOptions.js","sourceRoot":"","sources":["../../../src/models/IIotaResponseOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IotaTransactionBlockResponseOptions } from \"@iota/iota-sdk/client\";\n\n/**\n * Options for controlling transaction execution and response behaviour.\n */\nexport interface IIotaResponseOptions extends IotaTransactionBlockResponseOptions {\n\t/**\n\t * Wait for confirmation of the transaction.\n\t * @default true\n\t */\n\twaitForConfirmation?: boolean;\n\n\t/**\n\t * Dry run the transaction with this label, if not set no dry run will occur.\n\t */\n\tdryRunLabel?: string;\n}\n"]}
|