@layerzerolabs/lz-corekit-initia 3.0.14 → 3.0.16

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @layerzerolabs/lz-corekit-initia
2
2
 
3
+ ## 3.0.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 87a4bc9: islander mainnet
8
+ - Updated dependencies [87a4bc9]
9
+ - @layerzerolabs/lz-core@3.0.16
10
+ - @layerzerolabs/lz-utilities@3.0.16
11
+ - @layerzerolabs/move-definitions@3.0.16
12
+
13
+ ## 3.0.15
14
+
15
+ ### Patch Changes
16
+
17
+ - 67856bd: endpoints
18
+ - Updated dependencies [67856bd]
19
+ - @layerzerolabs/lz-core@3.0.15
20
+ - @layerzerolabs/lz-utilities@3.0.15
21
+ - @layerzerolabs/move-definitions@3.0.15
22
+
3
23
  ## 3.0.14
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -1 +1,98 @@
1
- # @layerzerolabs/lz-corekit
1
+ # @layerzerolabs/lz-corekit-initia
2
+
3
+ The Initia CoreKit is a comprehensive SDK designed to interact with the Initia blockchain. It provides a set of utilities and modules to facilitate the development and integration of applications with the Initia blockchain.
4
+
5
+ ## Features
6
+
7
+ - **Retrieve Account Information**: Gets the balance of the specified address.
8
+ - **Retrieve Block Information**: Gets the block height, timestamp and related transactions of the specified block.
9
+ - **Transaction Management**: Get, build, sign, send and confirm transactions.
10
+
11
+ ## Installation
12
+
13
+ To install the Initia CoreKit, you can use npm or yarn:
14
+
15
+ ```sh
16
+ npm install @layerzerolabs/lz-corekit-initia
17
+ ```
18
+
19
+ or
20
+
21
+ ```sh
22
+ yarn add @layerzerolabs/lz-corekit-initia
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Initialization
28
+
29
+ ```typescript
30
+ import { InitiaProvider } from "@layerzerolabs/lz-corekit-initia";
31
+
32
+ // url is the Initia chain full node url
33
+ const url = "http://127.0.0.1:8516";
34
+ const provider = InitiaProvider.from(url);
35
+ ```
36
+
37
+ ### Retrieve Account Information
38
+
39
+ #### Get Account Balance
40
+
41
+ ```typescript
42
+ import { InitiaProvider } from "@layerzerolabs/lz-corekit-initia";
43
+
44
+ // url is the Initia chain full node url
45
+ const url = "http://127.0.0.1:8516";
46
+ const provider = InitiaProvider.from(url);
47
+
48
+ const address = "0x1";
49
+ const balance = await provider.getBalance(address);
50
+ ```
51
+
52
+ ### Retrieve Block Information
53
+
54
+ #### Get Latest Block Height
55
+
56
+ ```typescript
57
+ import { InitiaProvider } from "@layerzerolabs/lz-corekit-initia";
58
+
59
+ // url is the Initia chain full node url
60
+ const url = "http://127.0.0.1:8516";
61
+ const provider = InitiaProvider.from(url);
62
+
63
+ const number = await provider.getBlockNumber();
64
+ ```
65
+
66
+ ### Transaction Management
67
+
68
+ #### Get Transaction by hash
69
+
70
+ ```typescript
71
+ import { InitiaProvider } from "@layerzerolabs/lz-corekit-initia";
72
+
73
+ // url is the Initia chain full node url
74
+ const url = "http://127.0.0.1:8516";
75
+ const provider = InitiaProvider.from(url);
76
+
77
+ const hash = "0x1";
78
+ const tx = await provider.getTransaction(hash);
79
+ ```
80
+
81
+ #### Sign, Send and Confirm Transaction
82
+
83
+ ```typescript
84
+ import { InitiaProvider, InitiaSigner } from '@layerzerolabs/lz-corekit-initia'
85
+ import { SignedTransaction, TransactionReceipt, TransactionRequest } from '@layerzerolabs/lz-core'
86
+
87
+ // url is the Initia chain full node url
88
+ const url = 'http://127.0.0.1:8516'
89
+ const provider = InitiaProvider.from(url)
90
+
91
+ const privateKey = '0x1234'
92
+ const signer = InitiaSigner.from(privateKey)
93
+ signer.connect(provider)
94
+
95
+ const tx: TransactionRequest = ...
96
+ const stx: SignedTransaction = await signer.signTransaction(tx)
97
+ const receipt: TransactionReceipt = await signer.sendAndConfirm(stx)
98
+ ```
package/dist/index.cjs CHANGED
@@ -6,6 +6,11 @@ var lzUtilities = require('@layerzerolabs/lz-utilities');
6
6
 
7
7
  // src/providers/initia.ts
8
8
  var InitiaProvider = class _InitiaProvider {
9
+ /**
10
+ * Creates an instance of InitiaProvider.
11
+ *
12
+ * @param {string} url - The URL of the Initia node.
13
+ */
9
14
  constructor(url) {
10
15
  this.url = url;
11
16
  this.nativeProvider = new initia_js.LCDClient(url);
@@ -17,22 +22,41 @@ var InitiaProvider = class _InitiaProvider {
17
22
  throw new Error("Invalid parameters");
18
23
  }
19
24
  }
25
+ /**
26
+ * Gets the native Initia provider instance.
27
+ *
28
+ * @returns {LCDClient} The native Initia provider instance.
29
+ */
20
30
  get native() {
21
31
  return this.nativeProvider;
22
32
  }
33
+ /**
34
+ * Gets the balance of the specified address.
35
+ *
36
+ * @param {string} address - The address to get the balance of.
37
+ * @returns {Promise<string>} A promise that resolves to the balance of the address.
38
+ * @throws {Error} If the address is not a valid Initia address.
39
+ */
23
40
  async getBalance(address) {
24
41
  let accAddress;
25
- if (!lzUtilities.isHexString(address)) {
42
+ if (!lzUtilities.isHex(address)) {
26
43
  accAddress = initia_js.AccAddress.fromHex(address);
27
44
  } else if (address.startsWith("init")) {
28
45
  accAddress = address;
29
46
  } else {
30
- throw new Error("Invalid Aptos address");
47
+ throw new Error("Invalid Initia address");
31
48
  }
32
49
  const resources = await this.nativeProvider.bank.balance(accAddress);
33
50
  const coins = resources[0];
34
51
  return coins.toString();
35
52
  }
53
+ /**
54
+ * Gets the block specified by blockTag.
55
+ *
56
+ * @param {BlockTag} blockTag - The block tag to specify the block.
57
+ * @returns {Promise<Block>} A promise that resolves to the block.
58
+ * @throws {Error} If the blockTag is invalid.
59
+ */
36
60
  async getBlock(blockTag) {
37
61
  let blockNumber = 0;
38
62
  if (typeof blockTag === "number") {
@@ -45,16 +69,43 @@ var InitiaProvider = class _InitiaProvider {
45
69
  const response = await this.nativeProvider.tendermint.blockInfo(blockNumber);
46
70
  return lzCore.Block.from(response);
47
71
  }
72
+ /**
73
+ * Gets the block with transactions specified by blockTag.
74
+ * Later: could invoke txInfosByHeight method in TxAPI
75
+ *
76
+ * @param {BlockTag} blockTag - The block tag to specify the block.
77
+ * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
78
+ * @throws {Error} Method not implemented.
79
+ */
48
80
  async getBlockWithTransactions(blockTag) {
49
81
  return Promise.reject(new Error("Method not implemented."));
50
82
  }
83
+ /**
84
+ * Gets the current block number.
85
+ *
86
+ * @returns {Promise<number>} A promise that resolves to the current block number.
87
+ */
51
88
  async getBlockNumber() {
52
89
  return this.nativeProvider.tendermint.blockInfo().then((ledgerInfo) => Number(ledgerInfo.block.header.height));
53
90
  }
91
+ /**
92
+ * Gets the current slot number for commitment, not suitable for Initia.
93
+ *
94
+ * @param {Finality} [finality] - The commitment level (optional).
95
+ * @returns {Promise<number>} A promise that resolves to the current slot number.
96
+ * @throws {Error} Method not implemented.
97
+ */
54
98
  async getSlot(_finality) {
55
99
  await Promise.resolve();
56
100
  throw new Error("Method not implemented.");
57
101
  }
102
+ /**
103
+ * Gets the UNIX timestamp for the block identified by blockTag.
104
+ *
105
+ * @param {BlockTag} blockTag - The block tag to specify the block.
106
+ * @returns {Promise<number>} A promise that resolves to the UNIX timestamp of the block.
107
+ * @throws {Error} If the blockTag is invalid.
108
+ */
58
109
  async getBlockTimestamp(blockTag) {
59
110
  if (typeof blockTag === "number") {
60
111
  return this.nativeProvider.tendermint.blockInfo(blockTag).then((block) => Number(block.block.header.time));
@@ -64,38 +115,75 @@ var InitiaProvider = class _InitiaProvider {
64
115
  throw new Error("Invalid blockTag");
65
116
  }
66
117
  }
118
+ /**
119
+ * Gets information about a transaction.
120
+ *
121
+ * @param {string} txHash - The hash of the transaction.
122
+ * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
123
+ * @throws {Error} If the transaction hash is invalid.
124
+ */
67
125
  async getTransaction(txHash) {
68
- if (!lzUtilities.isHexString(txHash)) {
126
+ if (!lzUtilities.isHex(txHash)) {
69
127
  throw new Error("Invalid Initia transaction hash");
70
128
  }
71
129
  const response = await this.nativeProvider.tx.txInfo(txHash);
72
130
  return lzCore.TransactionResponse.from(response);
73
131
  }
132
+ /**
133
+ * Gets the receipt of a transaction.
134
+ *
135
+ * @param {string} txHash - The hash of the transaction.
136
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
137
+ * @throws {Error} If the transaction hash is invalid.
138
+ */
74
139
  async getTransactionReceipt(txHash) {
75
- if (!lzUtilities.isHexString(txHash)) {
140
+ if (!lzUtilities.isHex(txHash)) {
76
141
  throw new Error("Invalid Initia transaction hash");
77
142
  }
78
143
  const response = await this.nativeProvider.tx.txInfo(txHash);
79
144
  return lzCore.TransactionReceipt.from(response);
80
145
  }
146
+ /**
147
+ * Gets the number of transactions sent from the specified address.
148
+ *
149
+ * @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.
150
+ * @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).
151
+ * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
152
+ * @throws {Error} If the address is invalid.
153
+ */
81
154
  async getTransactionCount(addressOrName, _blockTag) {
82
155
  const _addressOrName = await Promise.resolve(addressOrName);
83
156
  let accAddress;
84
- if (!lzUtilities.isHexString(_addressOrName)) {
157
+ if (!lzUtilities.isHex(_addressOrName)) {
85
158
  accAddress = initia_js.AccAddress.fromHex(_addressOrName);
86
159
  } else if (_addressOrName.startsWith("init")) {
87
160
  accAddress = _addressOrName;
88
161
  } else {
89
- throw new Error("Invalid Aptos address");
162
+ throw new Error("Invalid Initia address");
90
163
  }
91
164
  const response = await this.nativeProvider.auth.accountInfo(accAddress);
92
165
  return response.getSequenceNumber();
93
166
  }
167
+ /**
168
+ * Sends a signed transaction to the blockchain.
169
+ *
170
+ * @param {SignedTransaction} transaction - The signed transaction to send.
171
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
172
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
173
+ */
94
174
  async sendTransaction(transaction, _sendOptions) {
95
175
  const stx = transaction.signed;
96
176
  const response = await this.nativeProvider.tx.broadcast(stx);
97
177
  return lzCore.TransactionPending.from(response);
98
178
  }
179
+ /**
180
+ * Confirms a pending transaction.
181
+ *
182
+ * @param {TransactionPending} pending - The pending transaction to confirm.
183
+ * @param {object} [opts] - Optional parameters for the confirmation.
184
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
185
+ * @throws {Error} If the transaction fails.
186
+ */
99
187
  async confirmTransaction(pending, _opts) {
100
188
  const nativePending = pending.pending;
101
189
  if (nativePending.code !== 0) {
@@ -103,6 +191,13 @@ var InitiaProvider = class _InitiaProvider {
103
191
  }
104
192
  return Promise.resolve(lzCore.TransactionReceipt.from(nativePending));
105
193
  }
194
+ /**
195
+ * Sends a signed transaction and waits for confirmation.
196
+ *
197
+ * @param {SignedTransaction} transaction - The signed transaction to send.
198
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
199
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
200
+ */
106
201
  async sendAndConfirm(transaction, opts) {
107
202
  const pending = await this.sendTransaction(transaction, opts);
108
203
  return this.confirmTransaction(pending, opts);
@@ -167,9 +262,22 @@ function convertArg(argsType, arg) {
167
262
 
168
263
  // src/signers/initia.ts
169
264
  var InitiaSigner = class {
265
+ /**
266
+ * Creates an instance of InitiaSigner.
267
+ *
268
+ * @param {MnemonicKey | RawKey} signer - The Initia key to use as the signer.
269
+ */
170
270
  constructor(signer) {
171
271
  this.nativeKey = signer;
172
272
  }
273
+ /**
274
+ * Creates an instance of InitiaSigner from the given source.
275
+ *
276
+ * @param {string | MnemonicKey} source - The source to create the signer from.
277
+ * @param {string} [path] - The derivation path (optional).
278
+ * @returns {Signer<InitiaBuildTxRequest>} The created InitiaSigner instance.
279
+ * @throws {Error} If the parameters are invalid.
280
+ */
173
281
  static from(source, path) {
174
282
  if (source instanceof initia_js.MnemonicKey) {
175
283
  return new this(source);
@@ -191,12 +299,26 @@ var InitiaSigner = class {
191
299
  }
192
300
  throw new Error("Invalid parameters");
193
301
  }
302
+ /**
303
+ * Gets the native Initia wallet instance.
304
+ * Invoke connect method first to make sure the native provider is not undefined.
305
+ *
306
+ * @returns {Wallet} The native Initia wallet instance.
307
+ * @throws {Error} If the native provider is not connected.
308
+ */
194
309
  get native() {
195
310
  if (!this.nativeSigner) {
196
311
  throw new Error("Connect the native provider first with InitiaSigner.connect()");
197
312
  }
198
313
  return this.nativeSigner;
199
314
  }
315
+ /**
316
+ * Connects the signer to a provider.
317
+ *
318
+ * @param {Provider} provider - The provider to connect to.
319
+ * @returns {Signer<InitiaBuildTxRequest>} The connected signer.
320
+ * @throws {Error} If the provider is not an instance of InitiaProvider.
321
+ */
200
322
  connect(provider) {
201
323
  if (!(provider instanceof InitiaProvider)) {
202
324
  throw new Error("Only InitiaProvider is supported.");
@@ -205,24 +327,57 @@ var InitiaSigner = class {
205
327
  this.nativeSigner = new initia_js.Wallet(this.provider.native, this.nativeKey);
206
328
  return this;
207
329
  }
330
+ /**
331
+ * Gets the address of the signer.
332
+ *
333
+ * @returns {Promise<string>} A promise that resolves to the address of the signer.
334
+ */
208
335
  async getAddress() {
209
336
  return Promise.resolve(initia_js.AccAddress.toHex(this.nativeKey.accAddress));
210
337
  }
338
+ /**
339
+ * Gets the address of the signer.
340
+ *
341
+ * @returns {string} The address of the signer.
342
+ */
211
343
  get address() {
212
344
  return initia_js.AccAddress.toHex(this.nativeKey.accAddress);
213
345
  }
346
+ /**
347
+ * Sends a signed transaction and waits for confirmation.
348
+ *
349
+ * @param {SignedTransaction} transaction - The signed transaction to send.
350
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
351
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
352
+ * @throws {Error} If the provider is not connected.
353
+ */
214
354
  async sendAndConfirm(transaction, opts) {
215
355
  if (this.provider === void 0) {
216
356
  throw new Error("provider is required");
217
357
  }
218
358
  return this.provider.sendAndConfirm(transaction, opts);
219
359
  }
360
+ /**
361
+ * Sends a signed transaction.
362
+ *
363
+ * @param {SignedTransaction} transaction - The signed transaction to send.
364
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
365
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
366
+ * @throws {Error} If the provider is not connected.
367
+ */
220
368
  async sendTransaction(transaction, sendOptions) {
221
369
  if (this.provider === void 0) {
222
370
  throw new Error("provider is required");
223
371
  }
224
372
  return this.provider.sendTransaction(transaction, sendOptions);
225
373
  }
374
+ /**
375
+ * Signs a transaction.
376
+ *
377
+ * @param {TransactionRequest} transaction - The transaction request to sign.
378
+ * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
379
+ * @throws {Error} If the native provider is not connected.
380
+ */
226
381
  async signTransaction(transaction) {
227
382
  if (!this.nativeSigner) {
228
383
  throw new Error("Connect the native provider first with InitiaSigner.connect()");
@@ -237,9 +392,22 @@ var InitiaSigner = class {
237
392
  });
238
393
  return lzCore.SignedTransaction.from(response);
239
394
  }
395
+ /**
396
+ * Signs a buffer (e.g., a message hash) using the native Initia signer.
397
+ *
398
+ * @param {Uint8Array} buffer - The buffer to sign.
399
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
400
+ */
240
401
  async signBuffer(buffer) {
241
402
  return this.nativeKey.sign(Buffer.from(buffer));
242
403
  }
404
+ /**
405
+ * Builds a transaction.
406
+ *
407
+ * @param {InitiaBuildTxRequest} buildTxRequest - The transaction request to build.
408
+ * @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.
409
+ * @throws {Error} If the gas price is invalid.
410
+ */
243
411
  async buildTransaction(buildTxRequest) {
244
412
  const sender = this.nativeSigner.key.accAddress.toString();
245
413
  const msg = convertPayloadToMsgExecute(sender, buildTxRequest.payload);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/providers/initia.ts","../src/signers/initia.ts","../src/signers/utils.ts"],"names":["AccAddress","SignedTransaction"],"mappings":";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AAA,MACA,MAAM,CAAC,GAAG;AAAA,IACd;AACA,QAAI,eAAe,SAAS,QAAQ,QAAW;AAC3C,oBAAc,MAAM,eAAe,QAAQ;AAAA,IAC/C;AACA,QAAI,eAAe,SAAS,aAAa,QAAW;AAChD,UAAI,MAAM,OAAO,eAAe,QAAQ,QAAQ,CAAC,KAAK,eAAe,QAAQ,SAAS,SAAS,OAAO,GAAG;AACrG,sBAAc,YAAY,eAAe,QAAQ;AAAA,MACrD,WAAW,CAAC,MAAM,OAAO,eAAe,QAAQ,QAAQ,CAAC,GAAG;AACxD,sBAAc,YAAY,GAAG,eAAe,QAAQ,QAAQ;AAAA,MAChE,OAAO;AACH,cAAM,MAAM,iCAAiC,eAAe,QAAQ,QAAQ,EAAE;AAAA,MAClF;AAAA,IACJ;AAEA,UAAM,KAAK,MAAM,KAAK,aAAc,SAAS,aAAa;AAC1D,WAAO,mBAAmB,KAAK,EAAE;AAAA,EACrC;AACJ","sourcesContent":["import { AccAddress, LCDClient, WaitTxBroadcastResult } from '@initia/initia.js'\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 { isHexString } from '@layerzerolabs/lz-utilities'\n\nexport class InitiaProvider implements Provider {\n readonly nativeProvider: LCDClient\n\n private constructor(public url: string) {\n this.nativeProvider = new LCDClient(url)\n }\n\n static from(url: string): InitiaProvider\n static from(source: string): InitiaProvider {\n if (typeof source === 'string') {\n return new InitiaProvider(source)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n get native(): LCDClient {\n return this.nativeProvider\n }\n\n async getBalance(address: string): Promise<string> {\n let accAddress: AccAddress\n if (!isHexString(address)) {\n accAddress = AccAddress.fromHex(address)\n } else if (address.startsWith('init')) {\n accAddress = address\n } else {\n throw new Error('Invalid Aptos address')\n }\n\n //todo convert all address to aclAddress\n const resources = await this.nativeProvider.bank.balance(accAddress)\n const coins = resources[0]\n return coins.toString()\n }\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.tendermint\n .blockInfo()\n .then((ledgerInfo) => Number(ledgerInfo.block.header.height))\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.tendermint.blockInfo(blockNumber)\n return Block.from(response)\n }\n\n async getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions> {\n return Promise.reject(new Error('Method not implemented.'))\n }\n\n async getBlockNumber(): Promise<number> {\n return this.nativeProvider.tendermint.blockInfo().then((ledgerInfo) => Number(ledgerInfo.block.header.height))\n }\n\n async getSlot(_finality?: Finality): Promise<number> {\n await Promise.resolve()\n throw new Error('Method not implemented.')\n }\n\n async getBlockTimestamp(blockTag: string | number): Promise<number> {\n if (typeof blockTag === 'number') {\n return this.nativeProvider.tendermint.blockInfo(blockTag).then((block) => Number(block.block.header.time))\n } else if (blockTag === 'latest') {\n return this.nativeProvider.tendermint.blockInfo().then((block) => Number(block.block.header.time))\n } else {\n throw new Error('Invalid blockTag')\n }\n }\n\n async getTransaction(txHash: string): Promise<TransactionResponse> {\n if (!isHexString(txHash)) {\n throw new Error('Invalid Initia transaction hash')\n }\n\n const response = await this.nativeProvider.tx.txInfo(txHash)\n return TransactionResponse.from(response)\n }\n\n async getTransactionReceipt(txHash: string): Promise<TransactionReceipt> {\n if (!isHexString(txHash)) {\n throw new Error('Invalid Initia transaction hash')\n }\n\n const response = await this.nativeProvider.tx.txInfo(txHash)\n return TransactionReceipt.from(response)\n }\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\n let accAddress: AccAddress\n if (!isHexString(_addressOrName)) {\n accAddress = AccAddress.fromHex(_addressOrName)\n } else if (_addressOrName.startsWith('init')) {\n accAddress = _addressOrName\n } else {\n throw new Error('Invalid Aptos address')\n }\n const response = await this.nativeProvider.auth.accountInfo(accAddress)\n return response.getSequenceNumber()\n }\n\n async sendTransaction(transaction: SignedTransaction, _sendOptions?: object): Promise<TransactionPending> {\n type NativeSignedTransaction = Parameters<typeof this.nativeProvider.tx.broadcast>[0]\n const stx = transaction.signed as NativeSignedTransaction\n\n const response = await this.nativeProvider.tx.broadcast(stx) //TODO need change to broadcastAsync ??\n return TransactionPending.from(response)\n }\n\n async confirmTransaction(pending: TransactionPending, _opts?: object): Promise<TransactionReceipt> {\n const nativePending = pending.pending as WaitTxBroadcastResult\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (((nativePending as any).code as number) !== 0) {\n throw new Error(nativePending.raw_log)\n }\n return Promise.resolve(TransactionReceipt.from(nativePending))\n }\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 { AccAddress, CreateTxOptions, Key, MnemonicKey, ModeInfo, RawKey, Wallet } from '@initia/initia.js'\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 { InitiaProvider } from '../providers'\n\nimport { InitiaBuildTxRequest } from './types'\nimport { convertPayloadToMsgExecute } from './utils'\n\nexport class InitiaSigner implements Signer<InitiaBuildTxRequest> {\n public nativeKey: MnemonicKey | RawKey\n public nativeSigner: Wallet | undefined\n public provider: InitiaProvider | undefined\n\n private constructor(signer: MnemonicKey | RawKey) {\n this.nativeKey = signer\n }\n\n static from(signer: MnemonicKey): Signer<InitiaBuildTxRequest>\n static from(privKey: string): Signer<InitiaBuildTxRequest>\n /**\n *\n * @param mnemonic\n * @param path e.g. m/44'/637'/0'/0'/0'\n */\n static from(mnemonic: string, path: string): Signer<InitiaBuildTxRequest>\n\n static from(source: string | MnemonicKey, path?: string): Signer<InitiaBuildTxRequest> {\n if (source instanceof MnemonicKey) {\n return new this(source)\n } else if (typeof source === 'string' && path === undefined) {\n const signer = new RawKey(Buffer.from(trim0x(source))) // todo double check\n return new this(signer)\n } else if (typeof source === 'string' && path !== undefined) {\n if (path.startsWith('m/')) {\n const [_, coinType, account, __, index] = path.match(/\\d+/g)?.map(Number) ?? [44, 118, 0, 0, 0]\n const normalizeMnemonics = source\n .trim()\n .split(/\\s+/)\n .map((part) => part.toLowerCase())\n .join(' ')\n const key = new MnemonicKey({\n mnemonic: normalizeMnemonics,\n coinType,\n account,\n index,\n })\n return new this(key)\n }\n }\n throw new Error('Invalid parameters')\n }\n\n get native(): Wallet {\n if (!this.nativeSigner) {\n throw new Error('Connect the native provider first with InitiaSigner.connect()')\n }\n return this.nativeSigner\n }\n\n connect(provider: Provider): Signer<InitiaBuildTxRequest> {\n if (!(provider instanceof InitiaProvider)) {\n throw new Error('Only InitiaProvider is supported.')\n }\n\n this.provider = provider\n this.nativeSigner = new Wallet(this.provider.native, this.nativeKey)\n return this\n }\n\n async getAddress(): Promise<string> {\n return Promise.resolve(AccAddress.toHex(this.nativeKey.accAddress))\n }\n\n get address(): string {\n return AccAddress.toHex(this.nativeKey.accAddress)\n }\n\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n return this.provider.sendAndConfirm(transaction, opts)\n }\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 async signTransaction(transaction: TransactionRequest): Promise<SignedTransaction> {\n if (!this.nativeSigner) {\n throw new Error('Connect the native provider first with InitiaSigner.connect()')\n }\n\n type NativeTransactionRequest = Parameters<Key['signTx']>[0]\n const tx = transaction.request as NativeTransactionRequest\n\n const { account_number, sequence } = await this.nativeSigner.accountNumberAndSequence()\n\n const response = await this.nativeSigner.key.signTx(tx, {\n accountNumber: account_number,\n sequence,\n chainId: await this.nativeSigner.lcd.tendermint.chainId(),\n signMode: ModeInfo.SignMode.SIGN_MODE_DIRECT,\n })\n return SignedTransaction.from(response)\n }\n\n async signBuffer(buffer: Uint8Array): Promise<Uint8Array> {\n return this.nativeKey.sign(Buffer.from(buffer))\n }\n\n async buildTransaction(buildTxRequest: InitiaBuildTxRequest): Promise<TransactionRequest> {\n const sender = this.nativeSigner!.key.accAddress.toString()\n const msg = convertPayloadToMsgExecute(sender, buildTxRequest.payload)\n const createOptions: CreateTxOptions & {\n sequence?: number\n } = {\n msgs: [msg],\n }\n if (buildTxRequest.options?.gas !== undefined) {\n createOptions.gas = buildTxRequest.options.gas\n }\n if (buildTxRequest.options?.gasPrice !== undefined) {\n if (isNaN(Number(buildTxRequest.options.gasPrice)) && buildTxRequest.options.gasPrice.endsWith('uinit')) {\n createOptions.gasPrices = buildTxRequest.options.gasPrice\n } else if (!isNaN(Number(buildTxRequest.options.gasPrice))) {\n createOptions.gasPrices = `${buildTxRequest.options.gasPrice}uinit`\n } else {\n throw Error(`Invalid gas price for initia :${buildTxRequest.options.gasPrice}`)\n }\n }\n // createOptions.sequence = initial + offset\n const tx = await this.nativeSigner!.createTx(createOptions)\n return TransactionRequest.from(tx)\n }\n}\n","import { Msg, MsgExecute, bcs } from '@initia/initia.js'\n\nimport { EntryFunctionArgumentTypes, InputEntryFunctionData } from '@layerzerolabs/move-definitions'\n\nexport function convertPayloadToMsgExecute(sender: string, payload: InputEntryFunctionData): Msg {\n const functionStructs = payload.function.split('::')\n const moduleAddress = functionStructs[0]\n const moduleName = functionStructs[1]\n const functionName = functionStructs[2]\n const args = covertPayloadArgs(payload.functionArgumentTypes ?? [], payload.functionArguments)\n const msg = new MsgExecute(\n sender, // sender address\n moduleAddress, // module owner address\n moduleName, // module name\n functionName, // function name\n payload.typeArguments ?? [], // type args\n args\n )\n return msg\n}\nexport function covertPayloadArgs(\n functionArgumentTypes: string[],\n functionArguments: EntryFunctionArgumentTypes[]\n): string[] {\n const args: string[] = []\n for (let i = 0; i < functionArguments.length; i++) {\n args.push(convertArg(functionArgumentTypes[i], functionArguments[i]))\n }\n return args\n}\n\nexport function convertArg(argsType: string, arg: EntryFunctionArgumentTypes): string {\n switch (argsType) {\n case 'bool':\n return bcs\n .bool()\n .serialize(arg as boolean)\n .toBase64()\n case 'u256':\n return bcs\n .u256()\n .serialize(arg as bigint)\n .toBase64()\n case 'u128':\n return bcs\n .u128()\n .serialize(arg as bigint)\n .toBase64()\n case 'u64':\n return bcs\n .u64()\n .serialize(arg as bigint)\n .toBase64()\n case 'u32':\n return bcs\n .u32()\n .serialize(arg as number)\n .toBase64()\n case 'u16':\n return bcs\n .u16()\n .serialize(arg as number)\n .toBase64()\n case 'u8':\n return bcs\n .u8()\n .serialize(arg as number)\n .toBase64()\n case 'address':\n return bcs\n .address()\n .serialize(arg as string)\n .toBase64()\n case 'vector<u8>':\n return bcs\n .vector(bcs.u8())\n .serialize(arg as unknown as Uint8Array)\n .toBase64()\n case 'vector<address>':\n return bcs\n .vector(bcs.address())\n .serialize(arg as unknown as string[])\n .toBase64()\n case 'vector<vector<u8>>':\n return bcs\n .vector(bcs.vector(bcs.u8()))\n .serialize(arg as unknown as Uint8Array[])\n .toBase64()\n default:\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Invalid type argsType: ${argsType.toString()}`)\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/providers/initia.ts","../src/signers/initia.ts","../src/signers/utils.ts"],"names":["AccAddress","SignedTransaction"],"mappings":";AAAA,SAAS,YAAY,iBAAwC;AAE7D;AAAA,EACI;AAAA,EAMA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,aAAa;AAMf,IAAM,iBAAN,MAAM,gBAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpC,YAAmB,KA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iCAAiC,eAAe,QAAQ,QAAQ,EAAE;AAAA,MAClF;AAAA,IACJ;AAEA,UAAM,KAAK,MAAM,KAAK,aAAc,SAAS,aAAa;AAC1D,WAAO,mBAAmB,KAAK,EAAE;AAAA,EACrC;AACJ","sourcesContent":["import { AccAddress, LCDClient, WaitTxBroadcastResult } from '@initia/initia.js'\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 Initia blockchain provider.\n * Implements the Provider interface for interacting with Initia-compatible blockchains.\n */\nexport class InitiaProvider implements Provider {\n readonly nativeProvider: LCDClient\n\n /**\n * Creates an instance of InitiaProvider.\n *\n * @param {string} url - The URL of the Initia node.\n */\n private constructor(public url: string) {\n this.nativeProvider = new LCDClient(url)\n }\n\n /**\n * Creates an instance of InitiaProvider from the given URL.\n *\n * @param {string} url - The URL of the Initia node.\n * @returns {InitiaProvider} The created InitiaProvider instance.\n * @throws {Error} If the URL parameter is invalid.\n */\n static from(url: string): InitiaProvider\n static from(source: string): InitiaProvider {\n if (typeof source === 'string') {\n return new InitiaProvider(source)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n /**\n * Gets the native Initia provider instance.\n *\n * @returns {LCDClient} The native Initia provider instance.\n */\n get native(): LCDClient {\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 Initia address.\n */\n async getBalance(address: string): Promise<string> {\n let accAddress: AccAddress\n if (!isHex(address)) {\n accAddress = AccAddress.fromHex(address)\n } else if (address.startsWith('init')) {\n accAddress = address\n } else {\n throw new Error('Invalid Initia address')\n }\n\n //todo convert all address to aclAddress\n const resources = await this.nativeProvider.bank.balance(accAddress)\n const coins = resources[0]\n return coins.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.tendermint\n .blockInfo()\n .then((ledgerInfo) => Number(ledgerInfo.block.header.height))\n } else {\n throw new Error('Invalid blockTag')\n }\n\n const response = await this.nativeProvider.tendermint.blockInfo(blockNumber)\n return Block.from(response)\n }\n\n /**\n * Gets the block with transactions specified by blockTag.\n * Later: could invoke txInfosByHeight method in TxAPI\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} Method not implemented.\n */\n async getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions> {\n return Promise.reject(new Error('Method not implemented.'))\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.tendermint.blockInfo().then((ledgerInfo) => Number(ledgerInfo.block.header.height))\n }\n\n /**\n * Gets the current slot number for commitment, not suitable for Initia.\n *\n * @param {Finality} [finality] - 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 UNIX timestamp 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 UNIX 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.tendermint.blockInfo(blockTag).then((block) => Number(block.block.header.time))\n } else if (blockTag === 'latest') {\n return this.nativeProvider.tendermint.blockInfo().then((block) => Number(block.block.header.time))\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 Initia transaction hash')\n }\n\n const response = await this.nativeProvider.tx.txInfo(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 Initia transaction hash')\n }\n\n const response = await this.nativeProvider.tx.txInfo(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\n let accAddress: AccAddress\n if (!isHex(_addressOrName)) {\n accAddress = AccAddress.fromHex(_addressOrName)\n } else if (_addressOrName.startsWith('init')) {\n accAddress = _addressOrName\n } else {\n throw new Error('Invalid Initia address')\n }\n\n const response = await this.nativeProvider.auth.accountInfo(accAddress)\n return response.getSequenceNumber()\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.tx.broadcast>[0]\n const stx = transaction.signed as NativeSignedTransaction\n\n const response = await this.nativeProvider.tx.broadcast(stx) //TODO need change to broadcastAsync ??\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 const nativePending = pending.pending as WaitTxBroadcastResult\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (((nativePending as any).code as number) !== 0) {\n throw new Error(nativePending.raw_log)\n }\n return Promise.resolve(TransactionReceipt.from(nativePending))\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 { AccAddress, CreateTxOptions, Key, MnemonicKey, ModeInfo, RawKey, Wallet } from '@initia/initia.js'\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 { InitiaProvider } from '../providers'\n\nimport { InitiaBuildTxRequest } from './types'\nimport { convertPayloadToMsgExecute } from './utils'\n\n/**\n * Represents an Initia blockchain signer.\n * Implements the Signer interface for interacting with Initia-compatible blockchains.\n */\nexport class InitiaSigner implements Signer<InitiaBuildTxRequest> {\n public nativeKey: MnemonicKey | RawKey\n public nativeSigner: Wallet | undefined\n public provider: InitiaProvider | undefined\n\n /**\n * Creates an instance of InitiaSigner.\n *\n * @param {MnemonicKey | RawKey} signer - The Initia key to use as the signer.\n */\n private constructor(signer: MnemonicKey | RawKey) {\n this.nativeKey = signer\n }\n\n /**\n * Creates an instance of InitiaSigner from a MnemonicKey.\n *\n * @param {MnemonicKey} signer - The MnemonicKey to create the signer from.\n * @returns {Signer<InitiaBuildTxRequest>} The created InitiaSigner instance.\n */\n static from(signer: MnemonicKey): Signer<InitiaBuildTxRequest>\n\n /**\n * Creates an instance of InitiaSigner from a private key.\n *\n * @param {string} privKey - The private key to create the signer from.\n * @returns {Signer<InitiaBuildTxRequest>} The created InitiaSigner instance.\n */\n static from(privKey: string): Signer<InitiaBuildTxRequest>\n\n /**\n * Creates an instance of InitiaSigner from a mnemonic and derivation path.\n *\n * @param {string} mnemonic - The mnemonic to create the signer from.\n * @param {string} path - The derivation path (e.g., m/44'/637'/0'/0'/0').\n * @returns {Signer<InitiaBuildTxRequest>} The created InitiaSigner instance.\n */\n static from(mnemonic: string, path: string): Signer<InitiaBuildTxRequest>\n\n /**\n * Creates an instance of InitiaSigner from the given source.\n *\n * @param {string | MnemonicKey} source - The source to create the signer from.\n * @param {string} [path] - The derivation path (optional).\n * @returns {Signer<InitiaBuildTxRequest>} The created InitiaSigner instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | MnemonicKey, path?: string): Signer<InitiaBuildTxRequest> {\n if (source instanceof MnemonicKey) {\n return new this(source)\n } else if (typeof source === 'string' && path === undefined) {\n const signer = new RawKey(Buffer.from(trim0x(source))) // todo double check\n return new this(signer)\n } else if (typeof source === 'string' && path !== undefined) {\n if (path.startsWith('m/')) {\n const [_, coinType, account, __, index] = path.match(/\\d+/g)?.map(Number) ?? [44, 118, 0, 0, 0]\n const normalizeMnemonics = source\n .trim()\n .split(/\\s+/)\n .map((part) => part.toLowerCase())\n .join(' ')\n const key = new MnemonicKey({\n mnemonic: normalizeMnemonics,\n coinType,\n account,\n index,\n })\n return new this(key)\n }\n }\n throw new Error('Invalid parameters')\n }\n\n /**\n * Gets the native Initia wallet instance.\n * Invoke connect method first to make sure the native provider is not undefined.\n *\n * @returns {Wallet} The native Initia wallet instance.\n * @throws {Error} If the native provider is not connected.\n */\n get native(): Wallet {\n if (!this.nativeSigner) {\n throw new Error('Connect the native provider first with InitiaSigner.connect()')\n }\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 {Signer<InitiaBuildTxRequest>} The connected signer.\n * @throws {Error} If the provider is not an instance of InitiaProvider.\n */\n connect(provider: Provider): Signer<InitiaBuildTxRequest> {\n if (!(provider instanceof InitiaProvider)) {\n throw new Error('Only InitiaProvider is supported.')\n }\n\n this.provider = provider\n this.nativeSigner = new Wallet(this.provider.native, this.nativeKey)\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(AccAddress.toHex(this.nativeKey.accAddress))\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 AccAddress.toHex(this.nativeKey.accAddress)\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 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 if (!this.nativeSigner) {\n throw new Error('Connect the native provider first with InitiaSigner.connect()')\n }\n\n type NativeTransactionRequest = Parameters<Key['signTx']>[0]\n const tx = transaction.request as NativeTransactionRequest\n const { account_number, sequence } = await this.nativeSigner.accountNumberAndSequence()\n const response = await this.nativeSigner.key.signTx(tx, {\n accountNumber: account_number,\n sequence,\n chainId: await this.nativeSigner.lcd.tendermint.chainId(),\n signMode: ModeInfo.SignMode.SIGN_MODE_DIRECT,\n })\n return SignedTransaction.from(response)\n }\n\n /**\n * Signs a buffer (e.g., a message hash) using the native Initia 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 return this.nativeKey.sign(Buffer.from(buffer))\n }\n\n /**\n * Builds a transaction.\n *\n * @param {InitiaBuildTxRequest} buildTxRequest - The transaction request to build.\n * @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.\n * @throws {Error} If the gas price is invalid.\n */\n async buildTransaction(buildTxRequest: InitiaBuildTxRequest): Promise<TransactionRequest> {\n const sender = this.nativeSigner!.key.accAddress.toString()\n const msg = convertPayloadToMsgExecute(sender, buildTxRequest.payload)\n const createOptions: CreateTxOptions & {\n sequence?: number\n } = {\n msgs: [msg],\n }\n if (buildTxRequest.options?.gas !== undefined) {\n createOptions.gas = buildTxRequest.options.gas\n }\n if (buildTxRequest.options?.gasPrice !== undefined) {\n if (isNaN(Number(buildTxRequest.options.gasPrice)) && buildTxRequest.options.gasPrice.endsWith('uinit')) {\n createOptions.gasPrices = buildTxRequest.options.gasPrice\n } else if (!isNaN(Number(buildTxRequest.options.gasPrice))) {\n createOptions.gasPrices = `${buildTxRequest.options.gasPrice}uinit`\n } else {\n throw Error(`Invalid gas price for initia :${buildTxRequest.options.gasPrice}`)\n }\n }\n // createOptions.sequence = initial + offset\n const tx = await this.nativeSigner!.createTx(createOptions)\n return TransactionRequest.from(tx)\n }\n}\n","import { Msg, MsgExecute, bcs } from '@initia/initia.js'\n\nimport { EntryFunctionArgumentTypes, InputEntryFunctionData } from '@layerzerolabs/move-definitions'\n\n/**\n * Converts a payload to a MsgExecute object for the Initia blockchain.\n *\n * @param {string} sender - The address of the sender.\n * @param {InputEntryFunctionData} payload - The payload of the transaction.\n * @returns {Msg} The MsgExecute object.\n */\nexport function convertPayloadToMsgExecute(sender: string, payload: InputEntryFunctionData): Msg {\n const functionStructs = payload.function.split('::')\n const moduleAddress = functionStructs[0]\n const moduleName = functionStructs[1]\n const functionName = functionStructs[2]\n const args = covertPayloadArgs(payload.functionArgumentTypes ?? [], payload.functionArguments)\n const msg = new MsgExecute(\n sender, // sender address\n moduleAddress, // module owner address\n moduleName, // module name\n functionName, // function name\n payload.typeArguments ?? [], // type args\n args\n )\n return msg\n}\n\n/**\n * Converts payload arguments to a list of strings.\n *\n * @param {string[]} functionArgumentTypes - The types of the function arguments.\n * @param {EntryFunctionArgumentTypes[]} functionArguments - The function arguments.\n * @returns {string[]} The list of converted arguments.\n */\nexport function covertPayloadArgs(\n functionArgumentTypes: string[],\n functionArguments: EntryFunctionArgumentTypes[]\n): string[] {\n const args: string[] = []\n for (let i = 0; i < functionArguments.length; i++) {\n args.push(convertArg(functionArgumentTypes[i], functionArguments[i]))\n }\n return args\n}\n\n/**\n * Converts a single argument to a string based on its type.\n *\n * @param {string} argsType - The type of the argument.\n * @param {EntryFunctionArgumentTypes} arg - The argument to convert.\n * @returns {string} The converted argument as a string.\n * @throws {Error} If the argument type is invalid.\n */\nexport function convertArg(argsType: string, arg: EntryFunctionArgumentTypes): string {\n switch (argsType) {\n case 'bool':\n return bcs\n .bool()\n .serialize(arg as boolean)\n .toBase64()\n case 'u256':\n return bcs\n .u256()\n .serialize(arg as bigint)\n .toBase64()\n case 'u128':\n return bcs\n .u128()\n .serialize(arg as bigint)\n .toBase64()\n case 'u64':\n return bcs\n .u64()\n .serialize(arg as bigint)\n .toBase64()\n case 'u32':\n return bcs\n .u32()\n .serialize(arg as number)\n .toBase64()\n case 'u16':\n return bcs\n .u16()\n .serialize(arg as number)\n .toBase64()\n case 'u8':\n return bcs\n .u8()\n .serialize(arg as number)\n .toBase64()\n case 'address':\n return bcs\n .address()\n .serialize(arg as string)\n .toBase64()\n case 'vector<u8>':\n return bcs\n .vector(bcs.u8())\n .serialize(arg as unknown as Uint8Array)\n .toBase64()\n case 'vector<address>':\n return bcs\n .vector(bcs.address())\n .serialize(arg as unknown as string[])\n .toBase64()\n case 'vector<vector<u8>>':\n return bcs\n .vector(bcs.vector(bcs.u8()))\n .serialize(arg as unknown as Uint8Array[])\n .toBase64()\n default:\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Invalid type argsType: ${argsType.toString()}`)\n }\n}\n"]}