@layerzerolabs/lz-corekit-initia 3.0.15 → 3.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,9 +1,14 @@
1
- import { LCDClient, AccAddress, MsgExecute, bcs, MnemonicKey, RawKey, Wallet, ModeInfo } from '@initia/initia.js';
2
- import { Block, TransactionResponse, TransactionReceipt, TransactionPending, SignedTransaction, TransactionRequest } from '@layerzerolabs/lz-core';
3
- import { isHexString, trim0x } from '@layerzerolabs/lz-utilities';
1
+ import { LCDClient, AccAddress, MnemonicKey, RawKey, Wallet, ModeInfo } from '@initia/initia.js';
2
+ import { Block, TransactionResponse, TransactionReceipt, TransactionPending, SignedTransaction } from '@layerzerolabs/lz-core';
3
+ import { isHex, trim0x } from '@layerzerolabs/lz-utilities';
4
4
 
5
5
  // src/providers/initia.ts
6
6
  var InitiaProvider = class _InitiaProvider {
7
+ /**
8
+ * Creates an instance of InitiaProvider.
9
+ *
10
+ * @param {string} url - The URL of the Initia node.
11
+ */
7
12
  constructor(url) {
8
13
  this.url = url;
9
14
  this.nativeProvider = new LCDClient(url);
@@ -15,22 +20,41 @@ var InitiaProvider = class _InitiaProvider {
15
20
  throw new Error("Invalid parameters");
16
21
  }
17
22
  }
23
+ /**
24
+ * Gets the native Initia provider instance.
25
+ *
26
+ * @returns {LCDClient} The native Initia provider instance.
27
+ */
18
28
  get native() {
19
29
  return this.nativeProvider;
20
30
  }
31
+ /**
32
+ * Gets the balance of the specified address.
33
+ *
34
+ * @param {string} address - The address to get the balance of.
35
+ * @returns {Promise<string>} A promise that resolves to the balance of the address.
36
+ * @throws {Error} If the address is not a valid Initia address.
37
+ */
21
38
  async getBalance(address) {
22
39
  let accAddress;
23
- if (!isHexString(address)) {
40
+ if (!isHex(address)) {
24
41
  accAddress = AccAddress.fromHex(address);
25
42
  } else if (address.startsWith("init")) {
26
43
  accAddress = address;
27
44
  } else {
28
- throw new Error("Invalid Aptos address");
45
+ throw new Error("Invalid Initia address");
29
46
  }
30
47
  const resources = await this.nativeProvider.bank.balance(accAddress);
31
48
  const coins = resources[0];
32
49
  return coins.toString();
33
50
  }
51
+ /**
52
+ * Gets the block specified by blockTag.
53
+ *
54
+ * @param {BlockTag} blockTag - The block tag to specify the block.
55
+ * @returns {Promise<Block>} A promise that resolves to the block.
56
+ * @throws {Error} If the blockTag is invalid.
57
+ */
34
58
  async getBlock(blockTag) {
35
59
  let blockNumber = 0;
36
60
  if (typeof blockTag === "number") {
@@ -43,16 +67,43 @@ var InitiaProvider = class _InitiaProvider {
43
67
  const response = await this.nativeProvider.tendermint.blockInfo(blockNumber);
44
68
  return Block.from(response);
45
69
  }
70
+ /**
71
+ * Gets the block with transactions specified by blockTag.
72
+ * Later: could invoke txInfosByHeight method in TxAPI
73
+ *
74
+ * @param {BlockTag} blockTag - The block tag to specify the block.
75
+ * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
76
+ * @throws {Error} Method not implemented.
77
+ */
46
78
  async getBlockWithTransactions(blockTag) {
47
79
  return Promise.reject(new Error("Method not implemented."));
48
80
  }
81
+ /**
82
+ * Gets the current block number.
83
+ *
84
+ * @returns {Promise<number>} A promise that resolves to the current block number.
85
+ */
49
86
  async getBlockNumber() {
50
87
  return this.nativeProvider.tendermint.blockInfo().then((ledgerInfo) => Number(ledgerInfo.block.header.height));
51
88
  }
89
+ /**
90
+ * Gets the current slot number for commitment, not suitable for Initia.
91
+ *
92
+ * @param {Finality} [finality] - The commitment level (optional).
93
+ * @returns {Promise<number>} A promise that resolves to the current slot number.
94
+ * @throws {Error} Method not implemented.
95
+ */
52
96
  async getSlot(_finality) {
53
97
  await Promise.resolve();
54
98
  throw new Error("Method not implemented.");
55
99
  }
100
+ /**
101
+ * Gets the UNIX timestamp for the block identified by blockTag.
102
+ *
103
+ * @param {BlockTag} blockTag - The block tag to specify the block.
104
+ * @returns {Promise<number>} A promise that resolves to the UNIX timestamp of the block.
105
+ * @throws {Error} If the blockTag is invalid.
106
+ */
56
107
  async getBlockTimestamp(blockTag) {
57
108
  if (typeof blockTag === "number") {
58
109
  return this.nativeProvider.tendermint.blockInfo(blockTag).then((block) => Number(block.block.header.time));
@@ -62,38 +113,75 @@ var InitiaProvider = class _InitiaProvider {
62
113
  throw new Error("Invalid blockTag");
63
114
  }
64
115
  }
116
+ /**
117
+ * Gets information about a transaction.
118
+ *
119
+ * @param {string} txHash - The hash of the transaction.
120
+ * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
121
+ * @throws {Error} If the transaction hash is invalid.
122
+ */
65
123
  async getTransaction(txHash) {
66
- if (!isHexString(txHash)) {
124
+ if (!isHex(txHash)) {
67
125
  throw new Error("Invalid Initia transaction hash");
68
126
  }
69
127
  const response = await this.nativeProvider.tx.txInfo(txHash);
70
128
  return TransactionResponse.from(response);
71
129
  }
130
+ /**
131
+ * Gets the receipt of a transaction.
132
+ *
133
+ * @param {string} txHash - The hash of the transaction.
134
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
135
+ * @throws {Error} If the transaction hash is invalid.
136
+ */
72
137
  async getTransactionReceipt(txHash) {
73
- if (!isHexString(txHash)) {
138
+ if (!isHex(txHash)) {
74
139
  throw new Error("Invalid Initia transaction hash");
75
140
  }
76
141
  const response = await this.nativeProvider.tx.txInfo(txHash);
77
142
  return TransactionReceipt.from(response);
78
143
  }
144
+ /**
145
+ * Gets the number of transactions sent from the specified address.
146
+ *
147
+ * @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.
148
+ * @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).
149
+ * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
150
+ * @throws {Error} If the address is invalid.
151
+ */
79
152
  async getTransactionCount(addressOrName, _blockTag) {
80
153
  const _addressOrName = await Promise.resolve(addressOrName);
81
154
  let accAddress;
82
- if (!isHexString(_addressOrName)) {
155
+ if (!isHex(_addressOrName)) {
83
156
  accAddress = AccAddress.fromHex(_addressOrName);
84
157
  } else if (_addressOrName.startsWith("init")) {
85
158
  accAddress = _addressOrName;
86
159
  } else {
87
- throw new Error("Invalid Aptos address");
160
+ throw new Error("Invalid Initia address");
88
161
  }
89
162
  const response = await this.nativeProvider.auth.accountInfo(accAddress);
90
163
  return response.getSequenceNumber();
91
164
  }
165
+ /**
166
+ * Sends a signed transaction to the blockchain.
167
+ *
168
+ * @param {SignedTransaction} transaction - The signed transaction to send.
169
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
170
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
171
+ */
92
172
  async sendTransaction(transaction, _sendOptions) {
93
173
  const stx = transaction.signed;
94
174
  const response = await this.nativeProvider.tx.broadcast(stx);
95
175
  return TransactionPending.from(response);
96
176
  }
177
+ /**
178
+ * Confirms a pending transaction.
179
+ *
180
+ * @param {TransactionPending} pending - The pending transaction to confirm.
181
+ * @param {object} [opts] - Optional parameters for the confirmation.
182
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
183
+ * @throws {Error} If the transaction fails.
184
+ */
97
185
  async confirmTransaction(pending, _opts) {
98
186
  const nativePending = pending.pending;
99
187
  if (nativePending.code !== 0) {
@@ -101,73 +189,35 @@ var InitiaProvider = class _InitiaProvider {
101
189
  }
102
190
  return Promise.resolve(TransactionReceipt.from(nativePending));
103
191
  }
192
+ /**
193
+ * Sends a signed transaction and waits for confirmation.
194
+ *
195
+ * @param {SignedTransaction} transaction - The signed transaction to send.
196
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
197
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
198
+ */
104
199
  async sendAndConfirm(transaction, opts) {
105
200
  const pending = await this.sendTransaction(transaction, opts);
106
201
  return this.confirmTransaction(pending, opts);
107
202
  }
108
203
  };
109
- function convertPayloadToMsgExecute(sender, payload) {
110
- const functionStructs = payload.function.split("::");
111
- const moduleAddress = functionStructs[0];
112
- const moduleName = functionStructs[1];
113
- const functionName = functionStructs[2];
114
- const args = covertPayloadArgs(payload.functionArgumentTypes ?? [], payload.functionArguments);
115
- const msg = new MsgExecute(
116
- sender,
117
- // sender address
118
- moduleAddress,
119
- // module owner address
120
- moduleName,
121
- // module name
122
- functionName,
123
- // function name
124
- payload.typeArguments ?? [],
125
- // type args
126
- args
127
- );
128
- return msg;
129
- }
130
- function covertPayloadArgs(functionArgumentTypes, functionArguments) {
131
- const args = [];
132
- for (let i = 0; i < functionArguments.length; i++) {
133
- args.push(convertArg(functionArgumentTypes[i], functionArguments[i]));
134
- }
135
- return args;
136
- }
137
- function convertArg(argsType, arg) {
138
- switch (argsType) {
139
- case "bool":
140
- return bcs.bool().serialize(arg).toBase64();
141
- case "u256":
142
- return bcs.u256().serialize(arg).toBase64();
143
- case "u128":
144
- return bcs.u128().serialize(arg).toBase64();
145
- case "u64":
146
- return bcs.u64().serialize(arg).toBase64();
147
- case "u32":
148
- return bcs.u32().serialize(arg).toBase64();
149
- case "u16":
150
- return bcs.u16().serialize(arg).toBase64();
151
- case "u8":
152
- return bcs.u8().serialize(arg).toBase64();
153
- case "address":
154
- return bcs.address().serialize(arg).toBase64();
155
- case "vector<u8>":
156
- return bcs.vector(bcs.u8()).serialize(arg).toBase64();
157
- case "vector<address>":
158
- return bcs.vector(bcs.address()).serialize(arg).toBase64();
159
- case "vector<vector<u8>>":
160
- return bcs.vector(bcs.vector(bcs.u8())).serialize(arg).toBase64();
161
- default:
162
- throw new Error(`Invalid type argsType: ${argsType.toString()}`);
163
- }
164
- }
165
-
166
- // src/signers/initia.ts
167
204
  var InitiaSigner = class {
205
+ /**
206
+ * Creates an instance of InitiaSigner.
207
+ *
208
+ * @param {MnemonicKey | RawKey} signer - The Initia key to use as the signer.
209
+ */
168
210
  constructor(signer) {
169
211
  this.nativeKey = signer;
170
212
  }
213
+ /**
214
+ * Creates an instance of InitiaSigner from the given source.
215
+ *
216
+ * @param {string | MnemonicKey} source - The source to create the signer from.
217
+ * @param {string} [path] - The derivation path (optional).
218
+ * @returns {Signer} The created InitiaSigner instance.
219
+ * @throws {Error} If the parameters are invalid.
220
+ */
171
221
  static from(source, path) {
172
222
  if (source instanceof MnemonicKey) {
173
223
  return new this(source);
@@ -189,12 +239,26 @@ var InitiaSigner = class {
189
239
  }
190
240
  throw new Error("Invalid parameters");
191
241
  }
242
+ /**
243
+ * Gets the native Initia wallet instance.
244
+ * Invoke connect method first to make sure the native provider is not undefined.
245
+ *
246
+ * @returns {Wallet} The native Initia wallet instance.
247
+ * @throws {Error} If the native provider is not connected.
248
+ */
192
249
  get native() {
193
250
  if (!this.nativeSigner) {
194
251
  throw new Error("Connect the native provider first with InitiaSigner.connect()");
195
252
  }
196
253
  return this.nativeSigner;
197
254
  }
255
+ /**
256
+ * Connects the signer to a provider.
257
+ *
258
+ * @param {Provider} provider - The provider to connect to.
259
+ * @returns {Signer} The connected signer.
260
+ * @throws {Error} If the provider is not an instance of InitiaProvider.
261
+ */
198
262
  connect(provider) {
199
263
  if (!(provider instanceof InitiaProvider)) {
200
264
  throw new Error("Only InitiaProvider is supported.");
@@ -203,24 +267,57 @@ var InitiaSigner = class {
203
267
  this.nativeSigner = new Wallet(this.provider.native, this.nativeKey);
204
268
  return this;
205
269
  }
270
+ /**
271
+ * Gets the address of the signer.
272
+ *
273
+ * @returns {Promise<string>} A promise that resolves to the address of the signer.
274
+ */
206
275
  async getAddress() {
207
276
  return Promise.resolve(AccAddress.toHex(this.nativeKey.accAddress));
208
277
  }
278
+ /**
279
+ * Gets the address of the signer.
280
+ *
281
+ * @returns {string} The address of the signer.
282
+ */
209
283
  get address() {
210
284
  return AccAddress.toHex(this.nativeKey.accAddress);
211
285
  }
286
+ /**
287
+ * Sends a signed transaction and waits for confirmation.
288
+ *
289
+ * @param {SignedTransaction} transaction - The signed transaction to send.
290
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
291
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
292
+ * @throws {Error} If the provider is not connected.
293
+ */
212
294
  async sendAndConfirm(transaction, opts) {
213
295
  if (this.provider === void 0) {
214
296
  throw new Error("provider is required");
215
297
  }
216
298
  return this.provider.sendAndConfirm(transaction, opts);
217
299
  }
300
+ /**
301
+ * Sends a signed transaction.
302
+ *
303
+ * @param {SignedTransaction} transaction - The signed transaction to send.
304
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
305
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
306
+ * @throws {Error} If the provider is not connected.
307
+ */
218
308
  async sendTransaction(transaction, sendOptions) {
219
309
  if (this.provider === void 0) {
220
310
  throw new Error("provider is required");
221
311
  }
222
312
  return this.provider.sendTransaction(transaction, sendOptions);
223
313
  }
314
+ /**
315
+ * Signs a transaction.
316
+ *
317
+ * @param {TransactionRequest} transaction - The transaction request to sign.
318
+ * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
319
+ * @throws {Error} If the native provider is not connected.
320
+ */
224
321
  async signTransaction(transaction) {
225
322
  if (!this.nativeSigner) {
226
323
  throw new Error("Connect the native provider first with InitiaSigner.connect()");
@@ -235,32 +332,17 @@ var InitiaSigner = class {
235
332
  });
236
333
  return SignedTransaction.from(response);
237
334
  }
335
+ /**
336
+ * Signs a buffer (e.g., a message hash) using the native Initia signer.
337
+ *
338
+ * @param {Uint8Array} buffer - The buffer to sign.
339
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
340
+ */
238
341
  async signBuffer(buffer) {
239
342
  return this.nativeKey.sign(Buffer.from(buffer));
240
343
  }
241
- async buildTransaction(buildTxRequest) {
242
- const sender = this.nativeSigner.key.accAddress.toString();
243
- const msg = convertPayloadToMsgExecute(sender, buildTxRequest.payload);
244
- const createOptions = {
245
- msgs: [msg]
246
- };
247
- if (buildTxRequest.options?.gas !== void 0) {
248
- createOptions.gas = buildTxRequest.options.gas;
249
- }
250
- if (buildTxRequest.options?.gasPrice !== void 0) {
251
- if (isNaN(Number(buildTxRequest.options.gasPrice)) && buildTxRequest.options.gasPrice.endsWith("uinit")) {
252
- createOptions.gasPrices = buildTxRequest.options.gasPrice;
253
- } else if (!isNaN(Number(buildTxRequest.options.gasPrice))) {
254
- createOptions.gasPrices = `${buildTxRequest.options.gasPrice}uinit`;
255
- } else {
256
- throw Error(`Invalid gas price for initia :${buildTxRequest.options.gasPrice}`);
257
- }
258
- }
259
- const tx = await this.nativeSigner.createTx(createOptions);
260
- return TransactionRequest.from(tx);
261
- }
262
344
  };
263
345
 
264
- export { InitiaProvider, InitiaSigner, convertArg, convertPayloadToMsgExecute, covertPayloadArgs };
265
- //# sourceMappingURL=out.js.map
346
+ export { InitiaProvider, InitiaSigner };
347
+ //# sourceMappingURL=index.mjs.map
266
348
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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,mBAAmB;AAErB,IAAM,iBAAN,MAAM,gBAAmC;AAAA,EAGpC,YAAmB,KAAa;AAAb;AACvB,SAAK,iBAAiB,IAAI,UAAU,GAAG;AAAA,EAC3C;AAAA,EAGA,OAAO,KAAK,QAAgC;AACxC,QAAI,OAAO,WAAW,UAAU;AAC5B,aAAO,IAAI,gBAAe,MAAM;AAAA,IACpC,OAAO;AACH,YAAM,IAAI,MAAM,oBAAoB;AAAA,IACxC;AAAA,EACJ;AAAA,EAEA,IAAI,SAAoB;AACpB,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,MAAM,WAAW,SAAkC;AAC/C,QAAI;AACJ,QAAI,CAAC,YAAY,OAAO,GAAG;AACvB,mBAAa,WAAW,QAAQ,OAAO;AAAA,IAC3C,WAAW,QAAQ,WAAW,MAAM,GAAG;AACnC,mBA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, 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"],"names":["AccAddress","SignedTransaction"],"mappings":";;;;;AAmBa,IAAA,cAAA,GAAN,MAAM,eAAmC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpC,YAAmB,GAAa,EAAA;AAAb,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AACvB,IAAK,IAAA,CAAA,cAAA,GAAiB,IAAI,SAAA,CAAU,GAAG,CAAA;AAAA;AAC3C,EAUA,OAAO,KAAK,MAAgC,EAAA;AACxC,IAAI,IAAA,OAAO,WAAW,QAAU,EAAA;AAC5B,MAAO,OAAA,IAAI,gBAAe,MAAM,CAAA;AAAA,KAC7B,MAAA;AACH,MAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;AAAA;AACxC;AACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,MAAoB,GAAA;AACpB,IAAA,OAAO,IAAK,CAAA,cAAA;AAAA;AAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAW,OAAkC,EAAA;AAC/C,IAAI,IAAA,UAAA;AACJ,IAAI,IAAA,CAAC,KAAM,CAAA,OAAO,CAAG,EAAA;AACjB,MAAa,UAAA,GAAA,UAAA,CAAW,QAAQ,OAAO,CAAA;AAAA,KAChC,MAAA,IAAA,OAAA,CAAQ,UAAW,CAAA,MAAM,CAAG,EAAA;AACnC,MAAa,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MACpD,aAAe,EAAA,cAAA;AAAA,MACf,QAAA;AAAA,MACA,SAAS,MAAM,IAAA,CAAK,YAAa,CAAA,GAAA,CAAI,WAAW,OAAQ,EAAA;AAAA,MACxD,QAAA,EAAU,SAAS,QAAS,CAAA;AAAA,KAC/B,CAAA;AACD,IAAOC,OAAAA,iBAAAA,CAAkB,KAAK,QAAQ,CAAA;AAAA;AAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,MAAyC,EAAA;AACtD,IAAA,OAAO,KAAK,SAAU,CAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,MAAM,CAAC,CAAA;AAAA;AAEtD","file":"index.mjs","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, 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\n/**\n * Represents an Initia blockchain signer.\n * Implements the Signer interface for interacting with Initia-compatible blockchains.\n */\nexport class InitiaSigner implements Signer {\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} The created InitiaSigner instance.\n */\n static from(signer: MnemonicKey): Signer\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} The created InitiaSigner instance.\n */\n static from(privKey: string): Signer\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} The created InitiaSigner instance.\n */\n static from(mnemonic: string, path: string): Signer\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} The created InitiaSigner instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | MnemonicKey, path?: string): Signer {\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} The connected signer.\n * @throws {Error} If the provider is not an instance of InitiaProvider.\n */\n connect(provider: Provider): Signer {\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/lz-corekit-initia",
3
- "version": "3.0.15",
3
+ "version": "3.0.17",
4
4
  "description": "LayerZero Core Library",
5
5
  "license": "BUSL-1.1",
6
6
  "exports": {
@@ -24,20 +24,20 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@initia/initia.js": "^0.2.11",
27
- "@layerzerolabs/lz-core": "^3.0.15",
28
- "@layerzerolabs/lz-utilities": "^3.0.15",
29
- "@layerzerolabs/move-definitions": "^3.0.15"
27
+ "@layerzerolabs/lz-core": "^3.0.17",
28
+ "@layerzerolabs/lz-utilities": "^3.0.17",
29
+ "@layerzerolabs/move-definitions": "^3.0.17"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@jest/globals": "^29.7.0",
33
- "@layerzerolabs/tsup-config-next": "^3.0.15",
34
- "@layerzerolabs/typescript-config-next": "^3.0.15",
33
+ "@layerzerolabs/tsup-config-next": "^3.0.17",
34
+ "@layerzerolabs/typescript-config-next": "^3.0.17",
35
35
  "@types/jest": "^29.5.10",
36
36
  "jest": "^29.7.0",
37
37
  "jest-extended": "^4.0.2",
38
38
  "rimraf": "^5.0.5",
39
39
  "ts-jest": "^29.1.1",
40
- "tsup": "^8.0.1",
40
+ "tsup": "^8.3.5",
41
41
  "typescript": "~5.2.2"
42
42
  },
43
43
  "publishConfig": {