@layerzerolabs/lz-corekit-aptos 3.0.112 → 3.0.113
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/CHANGELOG.md +9 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @layerzerolabs/lz-corekit-aptos
|
|
2
2
|
|
|
3
|
+
## 3.0.113
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 45c8e28: Publish new packages, including verification-data.json files in the evm sdk packages
|
|
8
|
+
- Updated dependencies [45c8e28]
|
|
9
|
+
- @layerzerolabs/lz-core@3.0.113
|
|
10
|
+
- @layerzerolabs/lz-utilities@3.0.113
|
|
11
|
+
|
|
3
12
|
## 3.0.112
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -51,7 +51,7 @@ var AptosProvider = class _AptosProvider {
|
|
|
51
51
|
* @param {string} source - The URL of the Aptos node.
|
|
52
52
|
* @param {string} [faucet] - The URL of the faucet (optional).
|
|
53
53
|
* @param {string} [indexer] - The URL of the indexer (optional).
|
|
54
|
-
* @param authHeader
|
|
54
|
+
* @param authHeader - The authentication header (optional).
|
|
55
55
|
* @returns {AptosProvider} The created AptosProvider instance.
|
|
56
56
|
* @throws {Error} If the source parameter is not a string.
|
|
57
57
|
*/
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/providers/aptos.ts","../src/signers/aptos.ts"],"names":["aptos","isHex","Block","BlockWithTransactions","TransactionResponse","TransactionReceipt","TransactionPending","aptos2","trim0x","SignedTransaction"],"mappings":";;;;;;;;;;;;;;;;;;;;;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MAAM,8DAA8D,CAAA;AAAA;AAIlF,IAAA,MAAM,KAAK,WAAY,CAAA,OAAA;AAGvB,IAAA,MAAM,WAAW,MAAM,cAAA,CAAe,eAAgB,CAAA,IAAA,CAAK,cAAc,EAAE,CAAA;AAC3E,IAAOE,OAAAA,wBAAAA,CAAkB,KAAK,QAAQ,CAAA;AAAA;AAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,MAAyC,EAAA;AACtD,IAAM,MAAA,EAAA,GAAK,KAAK,YAAa,CAAA,UAAA,CAAW,OAAO,IAAK,CAAA,MAAM,CAAC,CAAA,CAAE,YAAa,EAAA;AAC1E,IAAO,OAAA,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAAA;AAEjC","file":"index.cjs","sourcesContent":["import * as aptos from 'aptos'\n\nimport {\n Block,\n BlockTag,\n BlockWithTransactions,\n Finality,\n Provider,\n SignedTransaction,\n TransactionPending,\n TransactionReceipt,\n TransactionResponse,\n} from '@layerzerolabs/lz-core'\nimport { isHex } from '@layerzerolabs/lz-utilities'\n\n/**\n * Represents an Aptos blockchain provider.\n * Implements the Provider interface for interacting with the Aptos blockchain.\n */\nexport class AptosProvider implements Provider {\n readonly nativeProvider: aptos.AptosClient\n\n /**\n * Creates an instance of AptosProvider.\n *\n * @param {string} url - The URL of the Aptos node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader\n */\n private constructor(\n public readonly url: string,\n public readonly faucet?: string,\n public readonly indexer?: string,\n public readonly authHeader?: { authField: string; authValue: string }\n ) {\n this.nativeProvider = new aptos.AptosClient(url, {\n HEADERS: {\n ...(authHeader !== undefined ? { [authHeader.authField]: authHeader.authValue } : {}),\n },\n })\n }\n\n /**\n * Creates an instance of AptosProvider from the given parameters.\n *\n * @param {string} source - The URL of the Aptos node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader\n * @returns {AptosProvider} The created AptosProvider instance.\n * @throws {Error} If the source parameter is not a string.\n */\n static from(\n source: string,\n faucet?: string,\n indexer?: string,\n authHeader?: { authField: string; authValue: string }\n ): AptosProvider {\n if (typeof source === 'string') {\n return new AptosProvider(source, faucet, indexer, authHeader)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n /**\n * Gets the native Aptos client instance.\n *\n * @returns {aptos.AptosClient} The native Aptos client instance.\n */\n get native(): aptos.AptosClient {\n return this.nativeProvider\n }\n\n /**\n * Gets the balance of the specified address.\n *\n * @param {string} address - The address to get the balance of.\n * @returns {Promise<string>} A promise that resolves to the balance of the address.\n * @throws {Error} If the address is not a valid Aptos address.\n */\n async getBalance(address: string): Promise<string> {\n if (!isHex(address)) {\n throw new Error('Invalid Aptos address')\n }\n const aptosCoin = '0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>'\n const resources = await this.nativeProvider.getAccountResources(address)\n const accountResource = resources.find((r) => r.type === aptosCoin)\n if (accountResource === undefined) {\n throw new Error('Account resource not found')\n }\n\n const { coin } = accountResource.data as { coin: { value: string } }\n return BigInt(coin.value).toString()\n }\n\n /**\n * Gets the block specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<Block>} A promise that resolves to the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlock(blockTag: string | number): Promise<Block> {\n let blockNumber = 0\n if (typeof blockTag === 'number') {\n blockNumber = blockTag\n } else if (blockTag === 'latest') {\n blockNumber = await this.nativeProvider\n .getLedgerInfo()\n .then((ledgerInfo) => Number(ledgerInfo.block_height))\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.getBlockByHeight(blockNumber)\n return Block.from(response)\n }\n\n /**\n * Gets the block with transactions specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions> {\n let blockNumber = 0\n if (typeof blockTag === 'number') {\n blockNumber = blockTag\n } else if (blockTag === 'latest') {\n blockNumber = await this.getBlockNumber()\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.getBlockByHeight(blockNumber, true)\n return BlockWithTransactions.from(response)\n }\n\n /**\n * Gets the current block number.\n *\n * @returns {Promise<number>} A promise that resolves to the current block number.\n */\n async getBlockNumber(): Promise<number> {\n return this.nativeProvider.getLedgerInfo().then((ledgerInfo) => Number(ledgerInfo.block_height))\n }\n\n /**\n * Gets the current slot number for commitment, not suitable for Aptos.\n *\n * @param {Finality} [commitment] - The commitment level (optional).\n * @returns {Promise<number>} A promise that resolves to the current slot number.\n * @throws {Error} Method not implemented.\n */\n async getSlot(_finality?: Finality): Promise<number> {\n await Promise.resolve()\n throw new Error('Method not implemented.')\n }\n\n /**\n * Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<number>} A promise that resolves to the timestamp of the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockTimestamp(blockTag: string | number): Promise<number> {\n if (typeof blockTag === 'number') {\n return this.nativeProvider.getBlockByHeight(blockTag).then((block) => Number(block.block_timestamp))\n } else if (blockTag === 'latest') {\n return this.nativeProvider.getLedgerInfo().then((ledgerInfo) => Number(ledgerInfo.ledger_timestamp))\n } else {\n throw new Error('Invalid blockTag')\n }\n }\n\n /**\n * Gets information about a transaction.\n *\n * @param {string} txHash - The hash of the transaction.\n * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.\n * @throws {Error} If the transaction hash is invalid.\n */\n async getTransaction(txHash: string): Promise<TransactionResponse> {\n if (!isHex(txHash)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionByHash(txHash)\n return TransactionResponse.from(response)\n }\n\n /**\n * Gets the receipt of a transaction.\n *\n * @param {string} txHash - The hash of the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction hash is invalid.\n */\n async getTransactionReceipt(txHash: string): Promise<TransactionReceipt> {\n if (!isHex(txHash)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionByHash(txHash)\n return TransactionReceipt.from(response)\n }\n\n /**\n * Gets the number of transactions sent from the specified address.\n *\n * @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.\n * @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).\n * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.\n * @throws {Error} If the address is invalid.\n */\n async getTransactionCount(\n addressOrName: string | Promise<string>,\n _blockTag?: BlockTag | Promise<BlockTag>\n ): Promise<number> {\n const _addressOrName = await Promise.resolve(addressOrName)\n if (!isHex(_addressOrName)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getAccount(_addressOrName)\n return parseInt(response.sequence_number)\n }\n\n /**\n * Sends a signed transaction to the blockchain.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n */\n async sendTransaction(transaction: SignedTransaction, _sendOptions?: object): Promise<TransactionPending> {\n type NativeSignedTransaction = Parameters<typeof this.nativeProvider.submitSignedBCSTransaction>[0] // Uint8Array\n const stx = transaction.signed as NativeSignedTransaction\n\n const response = await this.nativeProvider.submitSignedBCSTransaction(stx)\n return TransactionPending.from(response)\n }\n\n /**\n * Confirms a pending transaction.\n *\n * @param {TransactionPending} pending - The pending transaction to confirm.\n * @param {object} [opts] - Optional parameters for the confirmation.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction fails.\n */\n async confirmTransaction(pending: TransactionPending, opts?: object): Promise<TransactionReceipt> {\n let response: aptos.Types.Transaction\n if (typeof pending.pending === 'string') {\n response = await this.nativeProvider.waitForTransactionWithResult(pending.pending, {\n checkSuccess: true,\n })\n } else if (\n typeof pending.pending === 'object' &&\n pending.pending !== null &&\n 'hash' in pending.pending &&\n typeof pending.pending.hash === 'string'\n ) {\n response = await this.nativeProvider.waitForTransactionWithResult(pending.pending.hash, {\n checkSuccess: true,\n })\n } else {\n throw new Error('Invalid pending transaction')\n }\n\n if (response.type !== 'user_transaction') {\n throw new Error(`Invalid response type: ${response.type}`)\n }\n const userTransaction = response as aptos.Types.UserTransaction\n if (!userTransaction.success) {\n throw new Error(`aptos transaction failed ,vm_status: ${userTransaction.vm_status}`)\n }\n return TransactionReceipt.from(response)\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n const pending = await this.sendTransaction(transaction, opts)\n return this.confirmTransaction(pending, opts)\n }\n}\n","import * as aptos from 'aptos'\n\nimport {\n Provider,\n SignedTransaction,\n Signer,\n TransactionPending,\n TransactionReceipt,\n TransactionRequest,\n} from '@layerzerolabs/lz-core'\nimport { trim0x } from '@layerzerolabs/lz-utilities'\n\nimport { AptosProvider } from '../providers'\n\n/**\n * Represents an Aptos blockchain signer.\n * Implements the Signer interface for interacting with the Aptos blockchain.\n */\nexport class AptosSigner implements Signer {\n public nativeSigner: aptos.AptosAccount\n public provider: AptosProvider | undefined\n\n /**\n * Creates an instance of AptosSigner.\n *\n * @param {aptos.AptosAccount} signer - The Aptos account to use as the signer.\n */\n private constructor(signer: aptos.AptosAccount) {\n this.nativeSigner = signer\n }\n\n /**\n * Creates an instance of AptosSigner from the given parameters.\n *\n * @param {string | aptos.AptosAccount} source - The source to create the signer from, could be a private key, a mnemonics or an Aptos account.\n * @param {string} [path] - The derivation path (optional). e.g. m/44'/637'/0'/0'/0' If provided, the source is treated as a mnemonics.\n * @returns {AptosSigner} The created AptosSigner instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | aptos.AptosAccount, path?: string): AptosSigner {\n if (source instanceof aptos.AptosAccount) {\n return new this(source)\n }\n if (path === undefined) {\n const signer = new aptos.AptosAccount(Buffer.from(trim0x(source), 'hex'))\n return new this(signer)\n } else if (path.startsWith('m/')) {\n const signer = aptos.AptosAccount.fromDerivePath(path, source)\n return new this(signer)\n }\n throw new Error('Invalid parameters')\n }\n\n /**\n * Gets the native Aptos signer instance.\n *\n * @returns {aptos.AptosAccount} The native Aptos signer instance.\n */\n get native(): aptos.AptosAccount {\n return this.nativeSigner\n }\n\n /**\n * Connects the signer to a provider.\n *\n * @param {Provider} provider - The provider to connect to.\n * @returns {this} The connected signer.\n * @throws {Error} If the provider is not an instance of AptosProvider.\n */\n connect(provider: Provider): this {\n if (!(provider instanceof AptosProvider)) {\n throw new Error('Only aptos.AptosClient is supported.')\n }\n\n this.provider = provider\n return this\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {Promise<string>} A promise that resolves to the address of the signer.\n */\n async getAddress(): Promise<string> {\n return Promise.resolve(this.nativeSigner.address().toString())\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {string} The address of the signer.\n */\n get address(): string {\n return this.nativeSigner.address().toString()\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the provider is not connected.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendAndConfirm(transaction, opts)\n }\n\n /**\n * Sends a signed transaction.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n * @throws {Error} If the provider is not connected.\n */\n async sendTransaction(transaction: SignedTransaction, sendOptions?: object): Promise<TransactionPending> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendTransaction(transaction, sendOptions)\n }\n\n /**\n * Signs a transaction.\n *\n * @param {TransactionRequest} transaction - The transaction request to sign.\n * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.\n * @throws {Error} If the native provider is not connected.\n */\n async signTransaction(transaction: TransactionRequest): Promise<SignedTransaction> {\n const nativeProvider = this.provider?.native\n if (nativeProvider === undefined) {\n throw new Error('Connect the native provider first with AptosSigner.connect()')\n }\n\n type NativeTransactionRequest = Parameters<aptos.AptosClient['signTransaction']>[1]\n const tx = transaction.request as NativeTransactionRequest\n\n // signTransaction is an offline operation\n const response = await nativeProvider.signTransaction(this.nativeSigner, tx)\n return SignedTransaction.from(response)\n }\n\n /**\n * Signs a buffer (e.g., a message hash) using the native Aptos signer.\n *\n * @param {Uint8Array} buffer - The buffer to sign.\n * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.\n */\n async signBuffer(buffer: Uint8Array): Promise<Uint8Array> {\n const rv = this.nativeSigner.signBuffer(Buffer.from(buffer)).toUint8Array()\n return Promise.resolve(rv)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/providers/aptos.ts","../src/signers/aptos.ts"],"names":["aptos","isHex","Block","BlockWithTransactions","TransactionResponse","TransactionReceipt","TransactionPending","aptos2","trim0x","SignedTransaction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBa,IAAA,aAAA,GAAN,MAAM,cAAkC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWnC,WACY,CAAA,GAAA,EACA,MACA,EAAA,OAAA,EACA,UAClB,EAAA;AAJkB,IAAA,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AAA,CAAkB,KAAK,QAAQ,CAAA;AAAA;AAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,MAAyC,EAAA;AACtD,IAAM,MAAA,EAAA,GAAK,KAAK,YAAa,CAAA,UAAA,CAAW,OAAO,IAAK,CAAA,MAAM,CAAC,CAAA,CAAE,YAAa,EAAA;AAC1E,IAAO,OAAA,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAAA;AAEjC","file":"index.cjs","sourcesContent":["import * as aptos from 'aptos'\n\nimport {\n Block,\n BlockTag,\n BlockWithTransactions,\n Finality,\n Provider,\n SignedTransaction,\n TransactionPending,\n TransactionReceipt,\n TransactionResponse,\n} from '@layerzerolabs/lz-core'\nimport { isHex } from '@layerzerolabs/lz-utilities'\n\n/**\n * Represents an Aptos blockchain provider.\n * Implements the Provider interface for interacting with the Aptos blockchain.\n */\nexport class AptosProvider implements Provider {\n readonly nativeProvider: aptos.AptosClient\n\n /**\n * Creates an instance of AptosProvider.\n *\n * @param {string} url - The URL of the Aptos node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader\n */\n private constructor(\n public readonly url: string,\n public readonly faucet?: string,\n public readonly indexer?: string,\n public readonly authHeader?: { authField: string; authValue: string }\n ) {\n this.nativeProvider = new aptos.AptosClient(url, {\n HEADERS: {\n ...(authHeader !== undefined ? { [authHeader.authField]: authHeader.authValue } : {}),\n },\n })\n }\n\n /**\n * Creates an instance of AptosProvider from the given parameters.\n *\n * @param {string} source - The URL of the Aptos node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader - The authentication header (optional).\n * @returns {AptosProvider} The created AptosProvider instance.\n * @throws {Error} If the source parameter is not a string.\n */\n static from(\n source: string,\n faucet?: string,\n indexer?: string,\n authHeader?: { authField: string; authValue: string }\n ): AptosProvider {\n if (typeof source === 'string') {\n return new AptosProvider(source, faucet, indexer, authHeader)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n /**\n * Gets the native Aptos client instance.\n *\n * @returns {aptos.AptosClient} The native Aptos client instance.\n */\n get native(): aptos.AptosClient {\n return this.nativeProvider\n }\n\n /**\n * Gets the balance of the specified address.\n *\n * @param {string} address - The address to get the balance of.\n * @returns {Promise<string>} A promise that resolves to the balance of the address.\n * @throws {Error} If the address is not a valid Aptos address.\n */\n async getBalance(address: string): Promise<string> {\n if (!isHex(address)) {\n throw new Error('Invalid Aptos address')\n }\n const aptosCoin = '0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>'\n const resources = await this.nativeProvider.getAccountResources(address)\n const accountResource = resources.find((r) => r.type === aptosCoin)\n if (accountResource === undefined) {\n throw new Error('Account resource not found')\n }\n\n const { coin } = accountResource.data as { coin: { value: string } }\n return BigInt(coin.value).toString()\n }\n\n /**\n * Gets the block specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<Block>} A promise that resolves to the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlock(blockTag: string | number): Promise<Block> {\n let blockNumber = 0\n if (typeof blockTag === 'number') {\n blockNumber = blockTag\n } else if (blockTag === 'latest') {\n blockNumber = await this.nativeProvider\n .getLedgerInfo()\n .then((ledgerInfo) => Number(ledgerInfo.block_height))\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.getBlockByHeight(blockNumber)\n return Block.from(response)\n }\n\n /**\n * Gets the block with transactions specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions> {\n let blockNumber = 0\n if (typeof blockTag === 'number') {\n blockNumber = blockTag\n } else if (blockTag === 'latest') {\n blockNumber = await this.getBlockNumber()\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.getBlockByHeight(blockNumber, true)\n return BlockWithTransactions.from(response)\n }\n\n /**\n * Gets the current block number.\n *\n * @returns {Promise<number>} A promise that resolves to the current block number.\n */\n async getBlockNumber(): Promise<number> {\n return this.nativeProvider.getLedgerInfo().then((ledgerInfo) => Number(ledgerInfo.block_height))\n }\n\n /**\n * Gets the current slot number for commitment, not suitable for Aptos.\n *\n * @param {Finality} [commitment] - The commitment level (optional).\n * @returns {Promise<number>} A promise that resolves to the current slot number.\n * @throws {Error} Method not implemented.\n */\n async getSlot(_finality?: Finality): Promise<number> {\n await Promise.resolve()\n throw new Error('Method not implemented.')\n }\n\n /**\n * Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<number>} A promise that resolves to the timestamp of the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockTimestamp(blockTag: string | number): Promise<number> {\n if (typeof blockTag === 'number') {\n return this.nativeProvider.getBlockByHeight(blockTag).then((block) => Number(block.block_timestamp))\n } else if (blockTag === 'latest') {\n return this.nativeProvider.getLedgerInfo().then((ledgerInfo) => Number(ledgerInfo.ledger_timestamp))\n } else {\n throw new Error('Invalid blockTag')\n }\n }\n\n /**\n * Gets information about a transaction.\n *\n * @param {string} txHash - The hash of the transaction.\n * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.\n * @throws {Error} If the transaction hash is invalid.\n */\n async getTransaction(txHash: string): Promise<TransactionResponse> {\n if (!isHex(txHash)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionByHash(txHash)\n return TransactionResponse.from(response)\n }\n\n /**\n * Gets the receipt of a transaction.\n *\n * @param {string} txHash - The hash of the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction hash is invalid.\n */\n async getTransactionReceipt(txHash: string): Promise<TransactionReceipt> {\n if (!isHex(txHash)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionByHash(txHash)\n return TransactionReceipt.from(response)\n }\n\n /**\n * Gets the number of transactions sent from the specified address.\n *\n * @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.\n * @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).\n * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.\n * @throws {Error} If the address is invalid.\n */\n async getTransactionCount(\n addressOrName: string | Promise<string>,\n _blockTag?: BlockTag | Promise<BlockTag>\n ): Promise<number> {\n const _addressOrName = await Promise.resolve(addressOrName)\n if (!isHex(_addressOrName)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getAccount(_addressOrName)\n return parseInt(response.sequence_number)\n }\n\n /**\n * Sends a signed transaction to the blockchain.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n */\n async sendTransaction(transaction: SignedTransaction, _sendOptions?: object): Promise<TransactionPending> {\n type NativeSignedTransaction = Parameters<typeof this.nativeProvider.submitSignedBCSTransaction>[0] // Uint8Array\n const stx = transaction.signed as NativeSignedTransaction\n\n const response = await this.nativeProvider.submitSignedBCSTransaction(stx)\n return TransactionPending.from(response)\n }\n\n /**\n * Confirms a pending transaction.\n *\n * @param {TransactionPending} pending - The pending transaction to confirm.\n * @param {object} [opts] - Optional parameters for the confirmation.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction fails.\n */\n async confirmTransaction(pending: TransactionPending, opts?: object): Promise<TransactionReceipt> {\n let response: aptos.Types.Transaction\n if (typeof pending.pending === 'string') {\n response = await this.nativeProvider.waitForTransactionWithResult(pending.pending, {\n checkSuccess: true,\n })\n } else if (\n typeof pending.pending === 'object' &&\n pending.pending !== null &&\n 'hash' in pending.pending &&\n typeof pending.pending.hash === 'string'\n ) {\n response = await this.nativeProvider.waitForTransactionWithResult(pending.pending.hash, {\n checkSuccess: true,\n })\n } else {\n throw new Error('Invalid pending transaction')\n }\n\n if (response.type !== 'user_transaction') {\n throw new Error(`Invalid response type: ${response.type}`)\n }\n const userTransaction = response as aptos.Types.UserTransaction\n if (!userTransaction.success) {\n throw new Error(`aptos transaction failed ,vm_status: ${userTransaction.vm_status}`)\n }\n return TransactionReceipt.from(response)\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n const pending = await this.sendTransaction(transaction, opts)\n return this.confirmTransaction(pending, opts)\n }\n}\n","import * as aptos from 'aptos'\n\nimport {\n Provider,\n SignedTransaction,\n Signer,\n TransactionPending,\n TransactionReceipt,\n TransactionRequest,\n} from '@layerzerolabs/lz-core'\nimport { trim0x } from '@layerzerolabs/lz-utilities'\n\nimport { AptosProvider } from '../providers'\n\n/**\n * Represents an Aptos blockchain signer.\n * Implements the Signer interface for interacting with the Aptos blockchain.\n */\nexport class AptosSigner implements Signer {\n public nativeSigner: aptos.AptosAccount\n public provider: AptosProvider | undefined\n\n /**\n * Creates an instance of AptosSigner.\n *\n * @param {aptos.AptosAccount} signer - The Aptos account to use as the signer.\n */\n private constructor(signer: aptos.AptosAccount) {\n this.nativeSigner = signer\n }\n\n /**\n * Creates an instance of AptosSigner from the given parameters.\n *\n * @param {string | aptos.AptosAccount} source - The source to create the signer from, could be a private key, a mnemonics or an Aptos account.\n * @param {string} [path] - The derivation path (optional). e.g. m/44'/637'/0'/0'/0' If provided, the source is treated as a mnemonics.\n * @returns {AptosSigner} The created AptosSigner instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | aptos.AptosAccount, path?: string): AptosSigner {\n if (source instanceof aptos.AptosAccount) {\n return new this(source)\n }\n if (path === undefined) {\n const signer = new aptos.AptosAccount(Buffer.from(trim0x(source), 'hex'))\n return new this(signer)\n } else if (path.startsWith('m/')) {\n const signer = aptos.AptosAccount.fromDerivePath(path, source)\n return new this(signer)\n }\n throw new Error('Invalid parameters')\n }\n\n /**\n * Gets the native Aptos signer instance.\n *\n * @returns {aptos.AptosAccount} The native Aptos signer instance.\n */\n get native(): aptos.AptosAccount {\n return this.nativeSigner\n }\n\n /**\n * Connects the signer to a provider.\n *\n * @param {Provider} provider - The provider to connect to.\n * @returns {this} The connected signer.\n * @throws {Error} If the provider is not an instance of AptosProvider.\n */\n connect(provider: Provider): this {\n if (!(provider instanceof AptosProvider)) {\n throw new Error('Only aptos.AptosClient is supported.')\n }\n\n this.provider = provider\n return this\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {Promise<string>} A promise that resolves to the address of the signer.\n */\n async getAddress(): Promise<string> {\n return Promise.resolve(this.nativeSigner.address().toString())\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {string} The address of the signer.\n */\n get address(): string {\n return this.nativeSigner.address().toString()\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the provider is not connected.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendAndConfirm(transaction, opts)\n }\n\n /**\n * Sends a signed transaction.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n * @throws {Error} If the provider is not connected.\n */\n async sendTransaction(transaction: SignedTransaction, sendOptions?: object): Promise<TransactionPending> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendTransaction(transaction, sendOptions)\n }\n\n /**\n * Signs a transaction.\n *\n * @param {TransactionRequest} transaction - The transaction request to sign.\n * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.\n * @throws {Error} If the native provider is not connected.\n */\n async signTransaction(transaction: TransactionRequest): Promise<SignedTransaction> {\n const nativeProvider = this.provider?.native\n if (nativeProvider === undefined) {\n throw new Error('Connect the native provider first with AptosSigner.connect()')\n }\n\n type NativeTransactionRequest = Parameters<aptos.AptosClient['signTransaction']>[1]\n const tx = transaction.request as NativeTransactionRequest\n\n // signTransaction is an offline operation\n const response = await nativeProvider.signTransaction(this.nativeSigner, tx)\n return SignedTransaction.from(response)\n }\n\n /**\n * Signs a buffer (e.g., a message hash) using the native Aptos signer.\n *\n * @param {Uint8Array} buffer - The buffer to sign.\n * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.\n */\n async signBuffer(buffer: Uint8Array): Promise<Uint8Array> {\n const rv = this.nativeSigner.signBuffer(Buffer.from(buffer)).toUint8Array()\n return Promise.resolve(rv)\n }\n}\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -29,7 +29,7 @@ declare class AptosProvider implements Provider {
|
|
|
29
29
|
* @param {string} source - The URL of the Aptos node.
|
|
30
30
|
* @param {string} [faucet] - The URL of the faucet (optional).
|
|
31
31
|
* @param {string} [indexer] - The URL of the indexer (optional).
|
|
32
|
-
* @param authHeader
|
|
32
|
+
* @param authHeader - The authentication header (optional).
|
|
33
33
|
* @returns {AptosProvider} The created AptosProvider instance.
|
|
34
34
|
* @throws {Error} If the source parameter is not a string.
|
|
35
35
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ declare class AptosProvider implements Provider {
|
|
|
29
29
|
* @param {string} source - The URL of the Aptos node.
|
|
30
30
|
* @param {string} [faucet] - The URL of the faucet (optional).
|
|
31
31
|
* @param {string} [indexer] - The URL of the indexer (optional).
|
|
32
|
-
* @param authHeader
|
|
32
|
+
* @param authHeader - The authentication header (optional).
|
|
33
33
|
* @returns {AptosProvider} The created AptosProvider instance.
|
|
34
34
|
* @throws {Error} If the source parameter is not a string.
|
|
35
35
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -29,7 +29,7 @@ var AptosProvider = class _AptosProvider {
|
|
|
29
29
|
* @param {string} source - The URL of the Aptos node.
|
|
30
30
|
* @param {string} [faucet] - The URL of the faucet (optional).
|
|
31
31
|
* @param {string} [indexer] - The URL of the indexer (optional).
|
|
32
|
-
* @param authHeader
|
|
32
|
+
* @param authHeader - The authentication header (optional).
|
|
33
33
|
* @returns {AptosProvider} The created AptosProvider instance.
|
|
34
34
|
* @throws {Error} If the source parameter is not a string.
|
|
35
35
|
*/
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/providers/aptos.ts","../src/signers/aptos.ts"],"names":["aptos","SignedTransaction"],"mappings":";;;;;AAmBa,IAAA,aAAA,GAAN,MAAM,cAAkC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWnC,WACY,CAAA,GAAA,EACA,MACA,EAAA,OAAA,EACA,UAClB,EAAA;AAJkB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAEhB,IAAK,IAAA,CAAA,cAAA,GAAiB,IAAUA,MAAA,CAAA,WAAA,CAAY,GAAK,EAAA;AAAA,MAC7C,OAAS,EAAA;AAAA,QACL,GAAI,UAAe,KAAA,KAAA,CAAA,GAAY,EAAE,CAAC,UAAW,CAAA,SAAS,GAAG,UAAA,CAAW,SAAU,EAAA,GAAI;AAAC;AACvF,KACH,CAAA;AAAA;AACL;AAAA;AAAA;AAAA;AAAA;AAAA;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AG1C,IAAA,OAAO,IAAK,CAAA,QAAA,CAAS,cAAe,CAAA,WAAA,EAAa,IAAI,CAAA;AAAA;AACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,eAAgB,CAAA,WAAA,EAAgC,WAAmD,EAAA;AACrG,IAAI,IAAA,IAAA,CAAK,aAAa,KAAW,CAAA,EAAA;AAC7B,MAAM,MAAA,IAAI,MAAM,sBAAsB,CAAA;AAAA;AAG1C,IAAA,OAAO,IAAK,CAAA,QAAA,CAAS,eAAgB,CAAA,WAAA,EAAa,WAAW,CAAA;AAAA;AACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,gBAAgB,WAA6D,EAAA;AAC/E,IAAM,MAAA,cAAA,GAAiB,KAAK,QAAU,EAAA,MAAA;AACtC,IAAA,IAAI,mBAAmB,KAAW,CAAA,EAAA;AAC9B,MAAM,MAAA,IAAI,MAAM,8DAA8D,CAAA;AAAA;AAIlF,IAAA,MAAM,KAAK,WAAY,CAAA,OAAA;AAGvB,IAAA,MAAM,WAAW,MAAM,cAAA,CAAe,eAAgB,CAAA,IAAA,CAAK,cAAc,EAAE,CAAA;AAC3E,IAAOC,OAAAA,iBAAAA,CAAkB,KAAK,QAAQ,CAAA;AAAA;AAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,MAAyC,EAAA;AACtD,IAAM,MAAA,EAAA,GAAK,KAAK,YAAa,CAAA,UAAA,CAAW,OAAO,IAAK,CAAA,MAAM,CAAC,CAAA,CAAE,YAAa,EAAA;AAC1E,IAAO,OAAA,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAAA;AAEjC","file":"index.mjs","sourcesContent":["import * as aptos from 'aptos'\n\nimport {\n Block,\n BlockTag,\n BlockWithTransactions,\n Finality,\n Provider,\n SignedTransaction,\n TransactionPending,\n TransactionReceipt,\n TransactionResponse,\n} from '@layerzerolabs/lz-core'\nimport { isHex } from '@layerzerolabs/lz-utilities'\n\n/**\n * Represents an Aptos blockchain provider.\n * Implements the Provider interface for interacting with the Aptos blockchain.\n */\nexport class AptosProvider implements Provider {\n readonly nativeProvider: aptos.AptosClient\n\n /**\n * Creates an instance of AptosProvider.\n *\n * @param {string} url - The URL of the Aptos node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader\n */\n private constructor(\n public readonly url: string,\n public readonly faucet?: string,\n public readonly indexer?: string,\n public readonly authHeader?: { authField: string; authValue: string }\n ) {\n this.nativeProvider = new aptos.AptosClient(url, {\n HEADERS: {\n ...(authHeader !== undefined ? { [authHeader.authField]: authHeader.authValue } : {}),\n },\n })\n }\n\n /**\n * Creates an instance of AptosProvider from the given parameters.\n *\n * @param {string} source - The URL of the Aptos node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader\n * @returns {AptosProvider} The created AptosProvider instance.\n * @throws {Error} If the source parameter is not a string.\n */\n static from(\n source: string,\n faucet?: string,\n indexer?: string,\n authHeader?: { authField: string; authValue: string }\n ): AptosProvider {\n if (typeof source === 'string') {\n return new AptosProvider(source, faucet, indexer, authHeader)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n /**\n * Gets the native Aptos client instance.\n *\n * @returns {aptos.AptosClient} The native Aptos client instance.\n */\n get native(): aptos.AptosClient {\n return this.nativeProvider\n }\n\n /**\n * Gets the balance of the specified address.\n *\n * @param {string} address - The address to get the balance of.\n * @returns {Promise<string>} A promise that resolves to the balance of the address.\n * @throws {Error} If the address is not a valid Aptos address.\n */\n async getBalance(address: string): Promise<string> {\n if (!isHex(address)) {\n throw new Error('Invalid Aptos address')\n }\n const aptosCoin = '0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>'\n const resources = await this.nativeProvider.getAccountResources(address)\n const accountResource = resources.find((r) => r.type === aptosCoin)\n if (accountResource === undefined) {\n throw new Error('Account resource not found')\n }\n\n const { coin } = accountResource.data as { coin: { value: string } }\n return BigInt(coin.value).toString()\n }\n\n /**\n * Gets the block specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<Block>} A promise that resolves to the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlock(blockTag: string | number): Promise<Block> {\n let blockNumber = 0\n if (typeof blockTag === 'number') {\n blockNumber = blockTag\n } else if (blockTag === 'latest') {\n blockNumber = await this.nativeProvider\n .getLedgerInfo()\n .then((ledgerInfo) => Number(ledgerInfo.block_height))\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.getBlockByHeight(blockNumber)\n return Block.from(response)\n }\n\n /**\n * Gets the block with transactions specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions> {\n let blockNumber = 0\n if (typeof blockTag === 'number') {\n blockNumber = blockTag\n } else if (blockTag === 'latest') {\n blockNumber = await this.getBlockNumber()\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.getBlockByHeight(blockNumber, true)\n return BlockWithTransactions.from(response)\n }\n\n /**\n * Gets the current block number.\n *\n * @returns {Promise<number>} A promise that resolves to the current block number.\n */\n async getBlockNumber(): Promise<number> {\n return this.nativeProvider.getLedgerInfo().then((ledgerInfo) => Number(ledgerInfo.block_height))\n }\n\n /**\n * Gets the current slot number for commitment, not suitable for Aptos.\n *\n * @param {Finality} [commitment] - The commitment level (optional).\n * @returns {Promise<number>} A promise that resolves to the current slot number.\n * @throws {Error} Method not implemented.\n */\n async getSlot(_finality?: Finality): Promise<number> {\n await Promise.resolve()\n throw new Error('Method not implemented.')\n }\n\n /**\n * Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<number>} A promise that resolves to the timestamp of the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockTimestamp(blockTag: string | number): Promise<number> {\n if (typeof blockTag === 'number') {\n return this.nativeProvider.getBlockByHeight(blockTag).then((block) => Number(block.block_timestamp))\n } else if (blockTag === 'latest') {\n return this.nativeProvider.getLedgerInfo().then((ledgerInfo) => Number(ledgerInfo.ledger_timestamp))\n } else {\n throw new Error('Invalid blockTag')\n }\n }\n\n /**\n * Gets information about a transaction.\n *\n * @param {string} txHash - The hash of the transaction.\n * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.\n * @throws {Error} If the transaction hash is invalid.\n */\n async getTransaction(txHash: string): Promise<TransactionResponse> {\n if (!isHex(txHash)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionByHash(txHash)\n return TransactionResponse.from(response)\n }\n\n /**\n * Gets the receipt of a transaction.\n *\n * @param {string} txHash - The hash of the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction hash is invalid.\n */\n async getTransactionReceipt(txHash: string): Promise<TransactionReceipt> {\n if (!isHex(txHash)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionByHash(txHash)\n return TransactionReceipt.from(response)\n }\n\n /**\n * Gets the number of transactions sent from the specified address.\n *\n * @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.\n * @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).\n * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.\n * @throws {Error} If the address is invalid.\n */\n async getTransactionCount(\n addressOrName: string | Promise<string>,\n _blockTag?: BlockTag | Promise<BlockTag>\n ): Promise<number> {\n const _addressOrName = await Promise.resolve(addressOrName)\n if (!isHex(_addressOrName)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getAccount(_addressOrName)\n return parseInt(response.sequence_number)\n }\n\n /**\n * Sends a signed transaction to the blockchain.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n */\n async sendTransaction(transaction: SignedTransaction, _sendOptions?: object): Promise<TransactionPending> {\n type NativeSignedTransaction = Parameters<typeof this.nativeProvider.submitSignedBCSTransaction>[0] // Uint8Array\n const stx = transaction.signed as NativeSignedTransaction\n\n const response = await this.nativeProvider.submitSignedBCSTransaction(stx)\n return TransactionPending.from(response)\n }\n\n /**\n * Confirms a pending transaction.\n *\n * @param {TransactionPending} pending - The pending transaction to confirm.\n * @param {object} [opts] - Optional parameters for the confirmation.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction fails.\n */\n async confirmTransaction(pending: TransactionPending, opts?: object): Promise<TransactionReceipt> {\n let response: aptos.Types.Transaction\n if (typeof pending.pending === 'string') {\n response = await this.nativeProvider.waitForTransactionWithResult(pending.pending, {\n checkSuccess: true,\n })\n } else if (\n typeof pending.pending === 'object' &&\n pending.pending !== null &&\n 'hash' in pending.pending &&\n typeof pending.pending.hash === 'string'\n ) {\n response = await this.nativeProvider.waitForTransactionWithResult(pending.pending.hash, {\n checkSuccess: true,\n })\n } else {\n throw new Error('Invalid pending transaction')\n }\n\n if (response.type !== 'user_transaction') {\n throw new Error(`Invalid response type: ${response.type}`)\n }\n const userTransaction = response as aptos.Types.UserTransaction\n if (!userTransaction.success) {\n throw new Error(`aptos transaction failed ,vm_status: ${userTransaction.vm_status}`)\n }\n return TransactionReceipt.from(response)\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n const pending = await this.sendTransaction(transaction, opts)\n return this.confirmTransaction(pending, opts)\n }\n}\n","import * as aptos from 'aptos'\n\nimport {\n Provider,\n SignedTransaction,\n Signer,\n TransactionPending,\n TransactionReceipt,\n TransactionRequest,\n} from '@layerzerolabs/lz-core'\nimport { trim0x } from '@layerzerolabs/lz-utilities'\n\nimport { AptosProvider } from '../providers'\n\n/**\n * Represents an Aptos blockchain signer.\n * Implements the Signer interface for interacting with the Aptos blockchain.\n */\nexport class AptosSigner implements Signer {\n public nativeSigner: aptos.AptosAccount\n public provider: AptosProvider | undefined\n\n /**\n * Creates an instance of AptosSigner.\n *\n * @param {aptos.AptosAccount} signer - The Aptos account to use as the signer.\n */\n private constructor(signer: aptos.AptosAccount) {\n this.nativeSigner = signer\n }\n\n /**\n * Creates an instance of AptosSigner from the given parameters.\n *\n * @param {string | aptos.AptosAccount} source - The source to create the signer from, could be a private key, a mnemonics or an Aptos account.\n * @param {string} [path] - The derivation path (optional). e.g. m/44'/637'/0'/0'/0' If provided, the source is treated as a mnemonics.\n * @returns {AptosSigner} The created AptosSigner instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | aptos.AptosAccount, path?: string): AptosSigner {\n if (source instanceof aptos.AptosAccount) {\n return new this(source)\n }\n if (path === undefined) {\n const signer = new aptos.AptosAccount(Buffer.from(trim0x(source), 'hex'))\n return new this(signer)\n } else if (path.startsWith('m/')) {\n const signer = aptos.AptosAccount.fromDerivePath(path, source)\n return new this(signer)\n }\n throw new Error('Invalid parameters')\n }\n\n /**\n * Gets the native Aptos signer instance.\n *\n * @returns {aptos.AptosAccount} The native Aptos signer instance.\n */\n get native(): aptos.AptosAccount {\n return this.nativeSigner\n }\n\n /**\n * Connects the signer to a provider.\n *\n * @param {Provider} provider - The provider to connect to.\n * @returns {this} The connected signer.\n * @throws {Error} If the provider is not an instance of AptosProvider.\n */\n connect(provider: Provider): this {\n if (!(provider instanceof AptosProvider)) {\n throw new Error('Only aptos.AptosClient is supported.')\n }\n\n this.provider = provider\n return this\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {Promise<string>} A promise that resolves to the address of the signer.\n */\n async getAddress(): Promise<string> {\n return Promise.resolve(this.nativeSigner.address().toString())\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {string} The address of the signer.\n */\n get address(): string {\n return this.nativeSigner.address().toString()\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the provider is not connected.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendAndConfirm(transaction, opts)\n }\n\n /**\n * Sends a signed transaction.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n * @throws {Error} If the provider is not connected.\n */\n async sendTransaction(transaction: SignedTransaction, sendOptions?: object): Promise<TransactionPending> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendTransaction(transaction, sendOptions)\n }\n\n /**\n * Signs a transaction.\n *\n * @param {TransactionRequest} transaction - The transaction request to sign.\n * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.\n * @throws {Error} If the native provider is not connected.\n */\n async signTransaction(transaction: TransactionRequest): Promise<SignedTransaction> {\n const nativeProvider = this.provider?.native\n if (nativeProvider === undefined) {\n throw new Error('Connect the native provider first with AptosSigner.connect()')\n }\n\n type NativeTransactionRequest = Parameters<aptos.AptosClient['signTransaction']>[1]\n const tx = transaction.request as NativeTransactionRequest\n\n // signTransaction is an offline operation\n const response = await nativeProvider.signTransaction(this.nativeSigner, tx)\n return SignedTransaction.from(response)\n }\n\n /**\n * Signs a buffer (e.g., a message hash) using the native Aptos signer.\n *\n * @param {Uint8Array} buffer - The buffer to sign.\n * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.\n */\n async signBuffer(buffer: Uint8Array): Promise<Uint8Array> {\n const rv = this.nativeSigner.signBuffer(Buffer.from(buffer)).toUint8Array()\n return Promise.resolve(rv)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/providers/aptos.ts","../src/signers/aptos.ts"],"names":["aptos","SignedTransaction"],"mappings":";;;;;AAmBa,IAAA,aAAA,GAAN,MAAM,cAAkC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWnC,WACY,CAAA,GAAA,EACA,MACA,EAAA,OAAA,EACA,UAClB,EAAA;AAJkB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAEhB,IAAK,IAAA,CAAA,cAAA,GAAiB,IAAUA,MAAA,CAAA,WAAA,CAAY,GAAK,EAAA;AAAA,MAC7C,OAAS,EAAA;AAAA,QACL,GAAI,UAAe,KAAA,KAAA,CAAA,GAAY,EAAE,CAAC,UAAW,CAAA,SAAS,GAAG,UAAA,CAAW,SAAU,EAAA,GAAI;AAAC;AACvF,KACH,CAAA;AAAA;AACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,OAAO,IAAA,CACH,MACA,EAAA,MAAA,EACA,SACA,UACa,EAAA;AACb,IAAI,IAAA,OAAO,WAAW,QAAU,EAAA;AAC5B,MAAA,OAAO,IAAI,cAAA,CAAc,MAAQ,EAAA,MAAA,EAAQ,SAAS,UAAU,CAAA;AAAA,KACzD,MAAA;AACH,MAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;AAAA;AACxC;AACJ;A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A;AAG1C,IAAA,OAAO,IAAK,CAAA,QAAA,CAAS,eAAgB,CAAA,WAAA,EAAa,WAAW,CAAA;AAAA;AACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,gBAAgB,WAA6D,EAAA;AAC/E,IAAM,MAAA,cAAA,GAAiB,KAAK,QAAU,EAAA,MAAA;AACtC,IAAA,IAAI,mBAAmB,KAAW,CAAA,EAAA;AAC9B,MAAM,MAAA,IAAI,MAAM,8DAA8D,CAAA;AAAA;AAIlF,IAAA,MAAM,KAAK,WAAY,CAAA,OAAA;AAGvB,IAAA,MAAM,WAAW,MAAM,cAAA,CAAe,eAAgB,CAAA,IAAA,CAAK,cAAc,EAAE,CAAA;AAC3E,IAAOC,OAAAA,iBAAAA,CAAkB,KAAK,QAAQ,CAAA;AAAA;AAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,MAAyC,EAAA;AACtD,IAAM,MAAA,EAAA,GAAK,KAAK,YAAa,CAAA,UAAA,CAAW,OAAO,IAAK,CAAA,MAAM,CAAC,CAAA,CAAE,YAAa,EAAA;AAC1E,IAAO,OAAA,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAAA;AAEjC","file":"index.mjs","sourcesContent":["import * as aptos from 'aptos'\n\nimport {\n Block,\n BlockTag,\n BlockWithTransactions,\n Finality,\n Provider,\n SignedTransaction,\n TransactionPending,\n TransactionReceipt,\n TransactionResponse,\n} from '@layerzerolabs/lz-core'\nimport { isHex } from '@layerzerolabs/lz-utilities'\n\n/**\n * Represents an Aptos blockchain provider.\n * Implements the Provider interface for interacting with the Aptos blockchain.\n */\nexport class AptosProvider implements Provider {\n readonly nativeProvider: aptos.AptosClient\n\n /**\n * Creates an instance of AptosProvider.\n *\n * @param {string} url - The URL of the Aptos node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader\n */\n private constructor(\n public readonly url: string,\n public readonly faucet?: string,\n public readonly indexer?: string,\n public readonly authHeader?: { authField: string; authValue: string }\n ) {\n this.nativeProvider = new aptos.AptosClient(url, {\n HEADERS: {\n ...(authHeader !== undefined ? { [authHeader.authField]: authHeader.authValue } : {}),\n },\n })\n }\n\n /**\n * Creates an instance of AptosProvider from the given parameters.\n *\n * @param {string} source - The URL of the Aptos node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader - The authentication header (optional).\n * @returns {AptosProvider} The created AptosProvider instance.\n * @throws {Error} If the source parameter is not a string.\n */\n static from(\n source: string,\n faucet?: string,\n indexer?: string,\n authHeader?: { authField: string; authValue: string }\n ): AptosProvider {\n if (typeof source === 'string') {\n return new AptosProvider(source, faucet, indexer, authHeader)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n /**\n * Gets the native Aptos client instance.\n *\n * @returns {aptos.AptosClient} The native Aptos client instance.\n */\n get native(): aptos.AptosClient {\n return this.nativeProvider\n }\n\n /**\n * Gets the balance of the specified address.\n *\n * @param {string} address - The address to get the balance of.\n * @returns {Promise<string>} A promise that resolves to the balance of the address.\n * @throws {Error} If the address is not a valid Aptos address.\n */\n async getBalance(address: string): Promise<string> {\n if (!isHex(address)) {\n throw new Error('Invalid Aptos address')\n }\n const aptosCoin = '0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>'\n const resources = await this.nativeProvider.getAccountResources(address)\n const accountResource = resources.find((r) => r.type === aptosCoin)\n if (accountResource === undefined) {\n throw new Error('Account resource not found')\n }\n\n const { coin } = accountResource.data as { coin: { value: string } }\n return BigInt(coin.value).toString()\n }\n\n /**\n * Gets the block specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<Block>} A promise that resolves to the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlock(blockTag: string | number): Promise<Block> {\n let blockNumber = 0\n if (typeof blockTag === 'number') {\n blockNumber = blockTag\n } else if (blockTag === 'latest') {\n blockNumber = await this.nativeProvider\n .getLedgerInfo()\n .then((ledgerInfo) => Number(ledgerInfo.block_height))\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.getBlockByHeight(blockNumber)\n return Block.from(response)\n }\n\n /**\n * Gets the block with transactions specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions> {\n let blockNumber = 0\n if (typeof blockTag === 'number') {\n blockNumber = blockTag\n } else if (blockTag === 'latest') {\n blockNumber = await this.getBlockNumber()\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.getBlockByHeight(blockNumber, true)\n return BlockWithTransactions.from(response)\n }\n\n /**\n * Gets the current block number.\n *\n * @returns {Promise<number>} A promise that resolves to the current block number.\n */\n async getBlockNumber(): Promise<number> {\n return this.nativeProvider.getLedgerInfo().then((ledgerInfo) => Number(ledgerInfo.block_height))\n }\n\n /**\n * Gets the current slot number for commitment, not suitable for Aptos.\n *\n * @param {Finality} [commitment] - The commitment level (optional).\n * @returns {Promise<number>} A promise that resolves to the current slot number.\n * @throws {Error} Method not implemented.\n */\n async getSlot(_finality?: Finality): Promise<number> {\n await Promise.resolve()\n throw new Error('Method not implemented.')\n }\n\n /**\n * Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<number>} A promise that resolves to the timestamp of the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockTimestamp(blockTag: string | number): Promise<number> {\n if (typeof blockTag === 'number') {\n return this.nativeProvider.getBlockByHeight(blockTag).then((block) => Number(block.block_timestamp))\n } else if (blockTag === 'latest') {\n return this.nativeProvider.getLedgerInfo().then((ledgerInfo) => Number(ledgerInfo.ledger_timestamp))\n } else {\n throw new Error('Invalid blockTag')\n }\n }\n\n /**\n * Gets information about a transaction.\n *\n * @param {string} txHash - The hash of the transaction.\n * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.\n * @throws {Error} If the transaction hash is invalid.\n */\n async getTransaction(txHash: string): Promise<TransactionResponse> {\n if (!isHex(txHash)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionByHash(txHash)\n return TransactionResponse.from(response)\n }\n\n /**\n * Gets the receipt of a transaction.\n *\n * @param {string} txHash - The hash of the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction hash is invalid.\n */\n async getTransactionReceipt(txHash: string): Promise<TransactionReceipt> {\n if (!isHex(txHash)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionByHash(txHash)\n return TransactionReceipt.from(response)\n }\n\n /**\n * Gets the number of transactions sent from the specified address.\n *\n * @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.\n * @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).\n * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.\n * @throws {Error} If the address is invalid.\n */\n async getTransactionCount(\n addressOrName: string | Promise<string>,\n _blockTag?: BlockTag | Promise<BlockTag>\n ): Promise<number> {\n const _addressOrName = await Promise.resolve(addressOrName)\n if (!isHex(_addressOrName)) {\n throw new Error('Invalid Aptos transaction hash')\n }\n\n const response = await this.nativeProvider.getAccount(_addressOrName)\n return parseInt(response.sequence_number)\n }\n\n /**\n * Sends a signed transaction to the blockchain.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n */\n async sendTransaction(transaction: SignedTransaction, _sendOptions?: object): Promise<TransactionPending> {\n type NativeSignedTransaction = Parameters<typeof this.nativeProvider.submitSignedBCSTransaction>[0] // Uint8Array\n const stx = transaction.signed as NativeSignedTransaction\n\n const response = await this.nativeProvider.submitSignedBCSTransaction(stx)\n return TransactionPending.from(response)\n }\n\n /**\n * Confirms a pending transaction.\n *\n * @param {TransactionPending} pending - The pending transaction to confirm.\n * @param {object} [opts] - Optional parameters for the confirmation.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction fails.\n */\n async confirmTransaction(pending: TransactionPending, opts?: object): Promise<TransactionReceipt> {\n let response: aptos.Types.Transaction\n if (typeof pending.pending === 'string') {\n response = await this.nativeProvider.waitForTransactionWithResult(pending.pending, {\n checkSuccess: true,\n })\n } else if (\n typeof pending.pending === 'object' &&\n pending.pending !== null &&\n 'hash' in pending.pending &&\n typeof pending.pending.hash === 'string'\n ) {\n response = await this.nativeProvider.waitForTransactionWithResult(pending.pending.hash, {\n checkSuccess: true,\n })\n } else {\n throw new Error('Invalid pending transaction')\n }\n\n if (response.type !== 'user_transaction') {\n throw new Error(`Invalid response type: ${response.type}`)\n }\n const userTransaction = response as aptos.Types.UserTransaction\n if (!userTransaction.success) {\n throw new Error(`aptos transaction failed ,vm_status: ${userTransaction.vm_status}`)\n }\n return TransactionReceipt.from(response)\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n const pending = await this.sendTransaction(transaction, opts)\n return this.confirmTransaction(pending, opts)\n }\n}\n","import * as aptos from 'aptos'\n\nimport {\n Provider,\n SignedTransaction,\n Signer,\n TransactionPending,\n TransactionReceipt,\n TransactionRequest,\n} from '@layerzerolabs/lz-core'\nimport { trim0x } from '@layerzerolabs/lz-utilities'\n\nimport { AptosProvider } from '../providers'\n\n/**\n * Represents an Aptos blockchain signer.\n * Implements the Signer interface for interacting with the Aptos blockchain.\n */\nexport class AptosSigner implements Signer {\n public nativeSigner: aptos.AptosAccount\n public provider: AptosProvider | undefined\n\n /**\n * Creates an instance of AptosSigner.\n *\n * @param {aptos.AptosAccount} signer - The Aptos account to use as the signer.\n */\n private constructor(signer: aptos.AptosAccount) {\n this.nativeSigner = signer\n }\n\n /**\n * Creates an instance of AptosSigner from the given parameters.\n *\n * @param {string | aptos.AptosAccount} source - The source to create the signer from, could be a private key, a mnemonics or an Aptos account.\n * @param {string} [path] - The derivation path (optional). e.g. m/44'/637'/0'/0'/0' If provided, the source is treated as a mnemonics.\n * @returns {AptosSigner} The created AptosSigner instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | aptos.AptosAccount, path?: string): AptosSigner {\n if (source instanceof aptos.AptosAccount) {\n return new this(source)\n }\n if (path === undefined) {\n const signer = new aptos.AptosAccount(Buffer.from(trim0x(source), 'hex'))\n return new this(signer)\n } else if (path.startsWith('m/')) {\n const signer = aptos.AptosAccount.fromDerivePath(path, source)\n return new this(signer)\n }\n throw new Error('Invalid parameters')\n }\n\n /**\n * Gets the native Aptos signer instance.\n *\n * @returns {aptos.AptosAccount} The native Aptos signer instance.\n */\n get native(): aptos.AptosAccount {\n return this.nativeSigner\n }\n\n /**\n * Connects the signer to a provider.\n *\n * @param {Provider} provider - The provider to connect to.\n * @returns {this} The connected signer.\n * @throws {Error} If the provider is not an instance of AptosProvider.\n */\n connect(provider: Provider): this {\n if (!(provider instanceof AptosProvider)) {\n throw new Error('Only aptos.AptosClient is supported.')\n }\n\n this.provider = provider\n return this\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {Promise<string>} A promise that resolves to the address of the signer.\n */\n async getAddress(): Promise<string> {\n return Promise.resolve(this.nativeSigner.address().toString())\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {string} The address of the signer.\n */\n get address(): string {\n return this.nativeSigner.address().toString()\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the provider is not connected.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendAndConfirm(transaction, opts)\n }\n\n /**\n * Sends a signed transaction.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n * @throws {Error} If the provider is not connected.\n */\n async sendTransaction(transaction: SignedTransaction, sendOptions?: object): Promise<TransactionPending> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendTransaction(transaction, sendOptions)\n }\n\n /**\n * Signs a transaction.\n *\n * @param {TransactionRequest} transaction - The transaction request to sign.\n * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.\n * @throws {Error} If the native provider is not connected.\n */\n async signTransaction(transaction: TransactionRequest): Promise<SignedTransaction> {\n const nativeProvider = this.provider?.native\n if (nativeProvider === undefined) {\n throw new Error('Connect the native provider first with AptosSigner.connect()')\n }\n\n type NativeTransactionRequest = Parameters<aptos.AptosClient['signTransaction']>[1]\n const tx = transaction.request as NativeTransactionRequest\n\n // signTransaction is an offline operation\n const response = await nativeProvider.signTransaction(this.nativeSigner, tx)\n return SignedTransaction.from(response)\n }\n\n /**\n * Signs a buffer (e.g., a message hash) using the native Aptos signer.\n *\n * @param {Uint8Array} buffer - The buffer to sign.\n * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.\n */\n async signBuffer(buffer: Uint8Array): Promise<Uint8Array> {\n const rv = this.nativeSigner.signBuffer(Buffer.from(buffer)).toUint8Array()\n return Promise.resolve(rv)\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/lz-corekit-aptos",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.113",
|
|
4
4
|
"description": "LayerZero Core Library",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"exports": {
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"clean-prebuild": "rm -rf dist"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@layerzerolabs/lz-core": "^3.0.
|
|
27
|
-
"@layerzerolabs/lz-utilities": "^3.0.
|
|
26
|
+
"@layerzerolabs/lz-core": "^3.0.113",
|
|
27
|
+
"@layerzerolabs/lz-utilities": "^3.0.113",
|
|
28
28
|
"aptos": "^1.20.0",
|
|
29
29
|
"memoizee": "^0.4.17"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@jest/globals": "^29.7.0",
|
|
33
|
-
"@layerzerolabs/tsup-config-next": "^3.0.
|
|
34
|
-
"@layerzerolabs/typescript-config-next": "^3.0.
|
|
33
|
+
"@layerzerolabs/tsup-config-next": "^3.0.113",
|
|
34
|
+
"@layerzerolabs/typescript-config-next": "^3.0.113",
|
|
35
35
|
"@types/jest": "^29.5.10",
|
|
36
36
|
"jest": "^29.7.0",
|
|
37
37
|
"jest-extended": "^4.0.2",
|