@layerzerolabs/lz-corekit-initia 3.0.16 → 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/CHANGELOG.md +12 -0
- package/dist/index.cjs +3 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +11 -77
- package/dist/index.d.ts +11 -77
- package/dist/index.mjs +6 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @layerzerolabs/lz-corekit-initia
|
|
2
2
|
|
|
3
|
+
## 3.0.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 40f2269: islander mainnet
|
|
8
|
+
- 40f2269: testnets
|
|
9
|
+
- Updated dependencies [40f2269]
|
|
10
|
+
- Updated dependencies [40f2269]
|
|
11
|
+
- @layerzerolabs/lz-core@3.0.17
|
|
12
|
+
- @layerzerolabs/lz-utilities@3.0.17
|
|
13
|
+
- @layerzerolabs/move-definitions@3.0.17
|
|
14
|
+
|
|
3
15
|
## 3.0.16
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -203,64 +203,6 @@ var InitiaProvider = class _InitiaProvider {
|
|
|
203
203
|
return this.confirmTransaction(pending, opts);
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
|
-
function convertPayloadToMsgExecute(sender, payload) {
|
|
207
|
-
const functionStructs = payload.function.split("::");
|
|
208
|
-
const moduleAddress = functionStructs[0];
|
|
209
|
-
const moduleName = functionStructs[1];
|
|
210
|
-
const functionName = functionStructs[2];
|
|
211
|
-
const args = covertPayloadArgs(payload.functionArgumentTypes ?? [], payload.functionArguments);
|
|
212
|
-
const msg = new initia_js.MsgExecute(
|
|
213
|
-
sender,
|
|
214
|
-
// sender address
|
|
215
|
-
moduleAddress,
|
|
216
|
-
// module owner address
|
|
217
|
-
moduleName,
|
|
218
|
-
// module name
|
|
219
|
-
functionName,
|
|
220
|
-
// function name
|
|
221
|
-
payload.typeArguments ?? [],
|
|
222
|
-
// type args
|
|
223
|
-
args
|
|
224
|
-
);
|
|
225
|
-
return msg;
|
|
226
|
-
}
|
|
227
|
-
function covertPayloadArgs(functionArgumentTypes, functionArguments) {
|
|
228
|
-
const args = [];
|
|
229
|
-
for (let i = 0; i < functionArguments.length; i++) {
|
|
230
|
-
args.push(convertArg(functionArgumentTypes[i], functionArguments[i]));
|
|
231
|
-
}
|
|
232
|
-
return args;
|
|
233
|
-
}
|
|
234
|
-
function convertArg(argsType, arg) {
|
|
235
|
-
switch (argsType) {
|
|
236
|
-
case "bool":
|
|
237
|
-
return initia_js.bcs.bool().serialize(arg).toBase64();
|
|
238
|
-
case "u256":
|
|
239
|
-
return initia_js.bcs.u256().serialize(arg).toBase64();
|
|
240
|
-
case "u128":
|
|
241
|
-
return initia_js.bcs.u128().serialize(arg).toBase64();
|
|
242
|
-
case "u64":
|
|
243
|
-
return initia_js.bcs.u64().serialize(arg).toBase64();
|
|
244
|
-
case "u32":
|
|
245
|
-
return initia_js.bcs.u32().serialize(arg).toBase64();
|
|
246
|
-
case "u16":
|
|
247
|
-
return initia_js.bcs.u16().serialize(arg).toBase64();
|
|
248
|
-
case "u8":
|
|
249
|
-
return initia_js.bcs.u8().serialize(arg).toBase64();
|
|
250
|
-
case "address":
|
|
251
|
-
return initia_js.bcs.address().serialize(arg).toBase64();
|
|
252
|
-
case "vector<u8>":
|
|
253
|
-
return initia_js.bcs.vector(initia_js.bcs.u8()).serialize(arg).toBase64();
|
|
254
|
-
case "vector<address>":
|
|
255
|
-
return initia_js.bcs.vector(initia_js.bcs.address()).serialize(arg).toBase64();
|
|
256
|
-
case "vector<vector<u8>>":
|
|
257
|
-
return initia_js.bcs.vector(initia_js.bcs.vector(initia_js.bcs.u8())).serialize(arg).toBase64();
|
|
258
|
-
default:
|
|
259
|
-
throw new Error(`Invalid type argsType: ${argsType.toString()}`);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// src/signers/initia.ts
|
|
264
206
|
var InitiaSigner = class {
|
|
265
207
|
/**
|
|
266
208
|
* Creates an instance of InitiaSigner.
|
|
@@ -275,7 +217,7 @@ var InitiaSigner = class {
|
|
|
275
217
|
*
|
|
276
218
|
* @param {string | MnemonicKey} source - The source to create the signer from.
|
|
277
219
|
* @param {string} [path] - The derivation path (optional).
|
|
278
|
-
* @returns {Signer
|
|
220
|
+
* @returns {Signer} The created InitiaSigner instance.
|
|
279
221
|
* @throws {Error} If the parameters are invalid.
|
|
280
222
|
*/
|
|
281
223
|
static from(source, path) {
|
|
@@ -316,7 +258,7 @@ var InitiaSigner = class {
|
|
|
316
258
|
* Connects the signer to a provider.
|
|
317
259
|
*
|
|
318
260
|
* @param {Provider} provider - The provider to connect to.
|
|
319
|
-
* @returns {Signer
|
|
261
|
+
* @returns {Signer} The connected signer.
|
|
320
262
|
* @throws {Error} If the provider is not an instance of InitiaProvider.
|
|
321
263
|
*/
|
|
322
264
|
connect(provider) {
|
|
@@ -401,40 +343,9 @@ var InitiaSigner = class {
|
|
|
401
343
|
async signBuffer(buffer) {
|
|
402
344
|
return this.nativeKey.sign(Buffer.from(buffer));
|
|
403
345
|
}
|
|
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
|
-
*/
|
|
411
|
-
async buildTransaction(buildTxRequest) {
|
|
412
|
-
const sender = this.nativeSigner.key.accAddress.toString();
|
|
413
|
-
const msg = convertPayloadToMsgExecute(sender, buildTxRequest.payload);
|
|
414
|
-
const createOptions = {
|
|
415
|
-
msgs: [msg]
|
|
416
|
-
};
|
|
417
|
-
if (buildTxRequest.options?.gas !== void 0) {
|
|
418
|
-
createOptions.gas = buildTxRequest.options.gas;
|
|
419
|
-
}
|
|
420
|
-
if (buildTxRequest.options?.gasPrice !== void 0) {
|
|
421
|
-
if (isNaN(Number(buildTxRequest.options.gasPrice)) && buildTxRequest.options.gasPrice.endsWith("uinit")) {
|
|
422
|
-
createOptions.gasPrices = buildTxRequest.options.gasPrice;
|
|
423
|
-
} else if (!isNaN(Number(buildTxRequest.options.gasPrice))) {
|
|
424
|
-
createOptions.gasPrices = `${buildTxRequest.options.gasPrice}uinit`;
|
|
425
|
-
} else {
|
|
426
|
-
throw Error(`Invalid gas price for initia :${buildTxRequest.options.gasPrice}`);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
const tx = await this.nativeSigner.createTx(createOptions);
|
|
430
|
-
return lzCore.TransactionRequest.from(tx);
|
|
431
|
-
}
|
|
432
346
|
};
|
|
433
347
|
|
|
434
348
|
exports.InitiaProvider = InitiaProvider;
|
|
435
349
|
exports.InitiaSigner = InitiaSigner;
|
|
436
|
-
|
|
437
|
-
exports.convertPayloadToMsgExecute = convertPayloadToMsgExecute;
|
|
438
|
-
exports.covertPayloadArgs = covertPayloadArgs;
|
|
439
|
-
//# sourceMappingURL=out.js.map
|
|
350
|
+
//# sourceMappingURL=index.cjs.map
|
|
440
351
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -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,aAAa;AAMf,IAAM,iBAAN,MAAM,gBAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpC,YAAmB,KAAa;AAAb;AACvB,SAAK,iBAAiB,IAAI,UAAU,GAAG;AAAA,EAC3C;AAAA,E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M,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/providers/initia.ts","../src/signers/initia.ts"],"names":["LCDClient","isHex","AccAddress","Block","TransactionResponse","TransactionReceipt","TransactionPending","MnemonicKey","RawKey","trim0x","Wallet","ModeInfo","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,IAAIA,mBAAA,CAAU,GAAG,CAAA;AAAA;AAC3C,EAUA,OAAO,KAAK,MAAgC,EAAA;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AACrG,IAAI,IAAA,IAAA,CAAK,aAAa,KAAW,CAAA,EAAA;AAC7B,MAAM,MAAA,IAAI,MAAM,sBAAsB,CAAA;AAAA;AAG1C,IAAA,OAAO,IAAK,CAAA,QAAA,CAAS,eAAgB,CAAA,WAAA,EAAa,WAAW,CAAA;AAAA;AACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,gBAAgB,WAA6D,EAAA;AAC/E,IAAI,IAAA,CAAC,KAAK,YAAc,EAAA;AACpB,MAAM,MAAA,IAAI,MAAM,+DAA+D,CAAA;AAAA;AAInF,IAAA,MAAM,KAAK,WAAY,CAAA,OAAA;AACvB,IAAA,MAAM,EAAE,cAAgB,EAAA,QAAA,KAAa,MAAM,IAAA,CAAK,aAAa,wBAAyB,EAAA;AACtF,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,YAAa,CAAA,GAAA,CAAI,OAAO,EAAI,EAAA;AAAA,MACpD,aAAe,EAAA,cAAA;AAAA,MACf,QAAA;AAAA,MACA,SAAS,MAAM,IAAA,CAAK,YAAa,CAAA,GAAA,CAAI,WAAW,OAAQ,EAAA;AAAA,MACxD,QAAA,EAAUS,mBAAS,QAAS,CAAA;AAAA,KAC/B,CAAA;AACD,IAAOC,OAAAA,wBAAAA,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.cjs","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/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { LCDClient, MnemonicKey, RawKey, Wallet
|
|
1
|
+
import { LCDClient, MnemonicKey, RawKey, Wallet } from '@initia/initia.js';
|
|
2
2
|
import { Provider, Block, BlockWithTransactions, Finality, TransactionResponse, TransactionReceipt, BlockTag, SignedTransaction, TransactionPending, Signer, TransactionRequest } from '@layerzerolabs/lz-core';
|
|
3
|
-
import { InputEntryFunctionData, EntryFunctionArgumentTypes } from '@layerzerolabs/move-definitions';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Represents an Initia blockchain provider.
|
|
@@ -128,42 +127,11 @@ declare class InitiaProvider implements Provider {
|
|
|
128
127
|
sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt>;
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
/**
|
|
132
|
-
* Represents a request to build a transaction on the Initia blockchain.
|
|
133
|
-
*/
|
|
134
|
-
interface InitiaBuildTxRequest {
|
|
135
|
-
/**
|
|
136
|
-
* The payload of the transaction. {@link InputEntryFunctionData}
|
|
137
|
-
*/
|
|
138
|
-
payload: InputEntryFunctionData;
|
|
139
|
-
/**
|
|
140
|
-
* Optional parameters for building the transaction. {@link InitiaBuildTxRequestOptions}
|
|
141
|
-
*/
|
|
142
|
-
options?: InitiaBuildTxRequestOptions;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Represents optional parameters for building a transaction on the Initia blockchain.
|
|
146
|
-
*/
|
|
147
|
-
interface InitiaBuildTxRequestOptions {
|
|
148
|
-
/**
|
|
149
|
-
* The sequence number of the transaction.
|
|
150
|
-
*/
|
|
151
|
-
sequence?: number;
|
|
152
|
-
/**
|
|
153
|
-
* The gas limit for the transaction.
|
|
154
|
-
*/
|
|
155
|
-
gas?: string;
|
|
156
|
-
/**
|
|
157
|
-
* The gas price for the transaction.
|
|
158
|
-
*/
|
|
159
|
-
gasPrice?: string;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
130
|
/**
|
|
163
131
|
* Represents an Initia blockchain signer.
|
|
164
132
|
* Implements the Signer interface for interacting with Initia-compatible blockchains.
|
|
165
133
|
*/
|
|
166
|
-
declare class InitiaSigner implements Signer
|
|
134
|
+
declare class InitiaSigner implements Signer {
|
|
167
135
|
nativeKey: MnemonicKey | RawKey;
|
|
168
136
|
nativeSigner: Wallet | undefined;
|
|
169
137
|
provider: InitiaProvider | undefined;
|
|
@@ -177,24 +145,24 @@ declare class InitiaSigner implements Signer<InitiaBuildTxRequest> {
|
|
|
177
145
|
* Creates an instance of InitiaSigner from a MnemonicKey.
|
|
178
146
|
*
|
|
179
147
|
* @param {MnemonicKey} signer - The MnemonicKey to create the signer from.
|
|
180
|
-
* @returns {Signer
|
|
148
|
+
* @returns {Signer} The created InitiaSigner instance.
|
|
181
149
|
*/
|
|
182
|
-
static from(signer: MnemonicKey): Signer
|
|
150
|
+
static from(signer: MnemonicKey): Signer;
|
|
183
151
|
/**
|
|
184
152
|
* Creates an instance of InitiaSigner from a private key.
|
|
185
153
|
*
|
|
186
154
|
* @param {string} privKey - The private key to create the signer from.
|
|
187
|
-
* @returns {Signer
|
|
155
|
+
* @returns {Signer} The created InitiaSigner instance.
|
|
188
156
|
*/
|
|
189
|
-
static from(privKey: string): Signer
|
|
157
|
+
static from(privKey: string): Signer;
|
|
190
158
|
/**
|
|
191
159
|
* Creates an instance of InitiaSigner from a mnemonic and derivation path.
|
|
192
160
|
*
|
|
193
161
|
* @param {string} mnemonic - The mnemonic to create the signer from.
|
|
194
162
|
* @param {string} path - The derivation path (e.g., m/44'/637'/0'/0'/0').
|
|
195
|
-
* @returns {Signer
|
|
163
|
+
* @returns {Signer} The created InitiaSigner instance.
|
|
196
164
|
*/
|
|
197
|
-
static from(mnemonic: string, path: string): Signer
|
|
165
|
+
static from(mnemonic: string, path: string): Signer;
|
|
198
166
|
/**
|
|
199
167
|
* Gets the native Initia wallet instance.
|
|
200
168
|
* Invoke connect method first to make sure the native provider is not undefined.
|
|
@@ -207,10 +175,10 @@ declare class InitiaSigner implements Signer<InitiaBuildTxRequest> {
|
|
|
207
175
|
* Connects the signer to a provider.
|
|
208
176
|
*
|
|
209
177
|
* @param {Provider} provider - The provider to connect to.
|
|
210
|
-
* @returns {Signer
|
|
178
|
+
* @returns {Signer} The connected signer.
|
|
211
179
|
* @throws {Error} If the provider is not an instance of InitiaProvider.
|
|
212
180
|
*/
|
|
213
|
-
connect(provider: Provider): Signer
|
|
181
|
+
connect(provider: Provider): Signer;
|
|
214
182
|
/**
|
|
215
183
|
* Gets the address of the signer.
|
|
216
184
|
*
|
|
@@ -256,40 +224,6 @@ declare class InitiaSigner implements Signer<InitiaBuildTxRequest> {
|
|
|
256
224
|
* @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
|
|
257
225
|
*/
|
|
258
226
|
signBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
259
|
-
/**
|
|
260
|
-
* Builds a transaction.
|
|
261
|
-
*
|
|
262
|
-
* @param {InitiaBuildTxRequest} buildTxRequest - The transaction request to build.
|
|
263
|
-
* @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.
|
|
264
|
-
* @throws {Error} If the gas price is invalid.
|
|
265
|
-
*/
|
|
266
|
-
buildTransaction(buildTxRequest: InitiaBuildTxRequest): Promise<TransactionRequest>;
|
|
267
227
|
}
|
|
268
228
|
|
|
269
|
-
|
|
270
|
-
* Converts a payload to a MsgExecute object for the Initia blockchain.
|
|
271
|
-
*
|
|
272
|
-
* @param {string} sender - The address of the sender.
|
|
273
|
-
* @param {InputEntryFunctionData} payload - The payload of the transaction.
|
|
274
|
-
* @returns {Msg} The MsgExecute object.
|
|
275
|
-
*/
|
|
276
|
-
declare function convertPayloadToMsgExecute(sender: string, payload: InputEntryFunctionData): Msg;
|
|
277
|
-
/**
|
|
278
|
-
* Converts payload arguments to a list of strings.
|
|
279
|
-
*
|
|
280
|
-
* @param {string[]} functionArgumentTypes - The types of the function arguments.
|
|
281
|
-
* @param {EntryFunctionArgumentTypes[]} functionArguments - The function arguments.
|
|
282
|
-
* @returns {string[]} The list of converted arguments.
|
|
283
|
-
*/
|
|
284
|
-
declare function covertPayloadArgs(functionArgumentTypes: string[], functionArguments: EntryFunctionArgumentTypes[]): string[];
|
|
285
|
-
/**
|
|
286
|
-
* Converts a single argument to a string based on its type.
|
|
287
|
-
*
|
|
288
|
-
* @param {string} argsType - The type of the argument.
|
|
289
|
-
* @param {EntryFunctionArgumentTypes} arg - The argument to convert.
|
|
290
|
-
* @returns {string} The converted argument as a string.
|
|
291
|
-
* @throws {Error} If the argument type is invalid.
|
|
292
|
-
*/
|
|
293
|
-
declare function convertArg(argsType: string, arg: EntryFunctionArgumentTypes): string;
|
|
294
|
-
|
|
295
|
-
export { type InitiaBuildTxRequest, type InitiaBuildTxRequestOptions, InitiaProvider, InitiaSigner, convertArg, convertPayloadToMsgExecute, covertPayloadArgs };
|
|
229
|
+
export { InitiaProvider, InitiaSigner };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { LCDClient, MnemonicKey, RawKey, Wallet
|
|
1
|
+
import { LCDClient, MnemonicKey, RawKey, Wallet } from '@initia/initia.js';
|
|
2
2
|
import { Provider, Block, BlockWithTransactions, Finality, TransactionResponse, TransactionReceipt, BlockTag, SignedTransaction, TransactionPending, Signer, TransactionRequest } from '@layerzerolabs/lz-core';
|
|
3
|
-
import { InputEntryFunctionData, EntryFunctionArgumentTypes } from '@layerzerolabs/move-definitions';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Represents an Initia blockchain provider.
|
|
@@ -128,42 +127,11 @@ declare class InitiaProvider implements Provider {
|
|
|
128
127
|
sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt>;
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
/**
|
|
132
|
-
* Represents a request to build a transaction on the Initia blockchain.
|
|
133
|
-
*/
|
|
134
|
-
interface InitiaBuildTxRequest {
|
|
135
|
-
/**
|
|
136
|
-
* The payload of the transaction. {@link InputEntryFunctionData}
|
|
137
|
-
*/
|
|
138
|
-
payload: InputEntryFunctionData;
|
|
139
|
-
/**
|
|
140
|
-
* Optional parameters for building the transaction. {@link InitiaBuildTxRequestOptions}
|
|
141
|
-
*/
|
|
142
|
-
options?: InitiaBuildTxRequestOptions;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Represents optional parameters for building a transaction on the Initia blockchain.
|
|
146
|
-
*/
|
|
147
|
-
interface InitiaBuildTxRequestOptions {
|
|
148
|
-
/**
|
|
149
|
-
* The sequence number of the transaction.
|
|
150
|
-
*/
|
|
151
|
-
sequence?: number;
|
|
152
|
-
/**
|
|
153
|
-
* The gas limit for the transaction.
|
|
154
|
-
*/
|
|
155
|
-
gas?: string;
|
|
156
|
-
/**
|
|
157
|
-
* The gas price for the transaction.
|
|
158
|
-
*/
|
|
159
|
-
gasPrice?: string;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
130
|
/**
|
|
163
131
|
* Represents an Initia blockchain signer.
|
|
164
132
|
* Implements the Signer interface for interacting with Initia-compatible blockchains.
|
|
165
133
|
*/
|
|
166
|
-
declare class InitiaSigner implements Signer
|
|
134
|
+
declare class InitiaSigner implements Signer {
|
|
167
135
|
nativeKey: MnemonicKey | RawKey;
|
|
168
136
|
nativeSigner: Wallet | undefined;
|
|
169
137
|
provider: InitiaProvider | undefined;
|
|
@@ -177,24 +145,24 @@ declare class InitiaSigner implements Signer<InitiaBuildTxRequest> {
|
|
|
177
145
|
* Creates an instance of InitiaSigner from a MnemonicKey.
|
|
178
146
|
*
|
|
179
147
|
* @param {MnemonicKey} signer - The MnemonicKey to create the signer from.
|
|
180
|
-
* @returns {Signer
|
|
148
|
+
* @returns {Signer} The created InitiaSigner instance.
|
|
181
149
|
*/
|
|
182
|
-
static from(signer: MnemonicKey): Signer
|
|
150
|
+
static from(signer: MnemonicKey): Signer;
|
|
183
151
|
/**
|
|
184
152
|
* Creates an instance of InitiaSigner from a private key.
|
|
185
153
|
*
|
|
186
154
|
* @param {string} privKey - The private key to create the signer from.
|
|
187
|
-
* @returns {Signer
|
|
155
|
+
* @returns {Signer} The created InitiaSigner instance.
|
|
188
156
|
*/
|
|
189
|
-
static from(privKey: string): Signer
|
|
157
|
+
static from(privKey: string): Signer;
|
|
190
158
|
/**
|
|
191
159
|
* Creates an instance of InitiaSigner from a mnemonic and derivation path.
|
|
192
160
|
*
|
|
193
161
|
* @param {string} mnemonic - The mnemonic to create the signer from.
|
|
194
162
|
* @param {string} path - The derivation path (e.g., m/44'/637'/0'/0'/0').
|
|
195
|
-
* @returns {Signer
|
|
163
|
+
* @returns {Signer} The created InitiaSigner instance.
|
|
196
164
|
*/
|
|
197
|
-
static from(mnemonic: string, path: string): Signer
|
|
165
|
+
static from(mnemonic: string, path: string): Signer;
|
|
198
166
|
/**
|
|
199
167
|
* Gets the native Initia wallet instance.
|
|
200
168
|
* Invoke connect method first to make sure the native provider is not undefined.
|
|
@@ -207,10 +175,10 @@ declare class InitiaSigner implements Signer<InitiaBuildTxRequest> {
|
|
|
207
175
|
* Connects the signer to a provider.
|
|
208
176
|
*
|
|
209
177
|
* @param {Provider} provider - The provider to connect to.
|
|
210
|
-
* @returns {Signer
|
|
178
|
+
* @returns {Signer} The connected signer.
|
|
211
179
|
* @throws {Error} If the provider is not an instance of InitiaProvider.
|
|
212
180
|
*/
|
|
213
|
-
connect(provider: Provider): Signer
|
|
181
|
+
connect(provider: Provider): Signer;
|
|
214
182
|
/**
|
|
215
183
|
* Gets the address of the signer.
|
|
216
184
|
*
|
|
@@ -256,40 +224,6 @@ declare class InitiaSigner implements Signer<InitiaBuildTxRequest> {
|
|
|
256
224
|
* @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
|
|
257
225
|
*/
|
|
258
226
|
signBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
259
|
-
/**
|
|
260
|
-
* Builds a transaction.
|
|
261
|
-
*
|
|
262
|
-
* @param {InitiaBuildTxRequest} buildTxRequest - The transaction request to build.
|
|
263
|
-
* @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.
|
|
264
|
-
* @throws {Error} If the gas price is invalid.
|
|
265
|
-
*/
|
|
266
|
-
buildTransaction(buildTxRequest: InitiaBuildTxRequest): Promise<TransactionRequest>;
|
|
267
227
|
}
|
|
268
228
|
|
|
269
|
-
|
|
270
|
-
* Converts a payload to a MsgExecute object for the Initia blockchain.
|
|
271
|
-
*
|
|
272
|
-
* @param {string} sender - The address of the sender.
|
|
273
|
-
* @param {InputEntryFunctionData} payload - The payload of the transaction.
|
|
274
|
-
* @returns {Msg} The MsgExecute object.
|
|
275
|
-
*/
|
|
276
|
-
declare function convertPayloadToMsgExecute(sender: string, payload: InputEntryFunctionData): Msg;
|
|
277
|
-
/**
|
|
278
|
-
* Converts payload arguments to a list of strings.
|
|
279
|
-
*
|
|
280
|
-
* @param {string[]} functionArgumentTypes - The types of the function arguments.
|
|
281
|
-
* @param {EntryFunctionArgumentTypes[]} functionArguments - The function arguments.
|
|
282
|
-
* @returns {string[]} The list of converted arguments.
|
|
283
|
-
*/
|
|
284
|
-
declare function covertPayloadArgs(functionArgumentTypes: string[], functionArguments: EntryFunctionArgumentTypes[]): string[];
|
|
285
|
-
/**
|
|
286
|
-
* Converts a single argument to a string based on its type.
|
|
287
|
-
*
|
|
288
|
-
* @param {string} argsType - The type of the argument.
|
|
289
|
-
* @param {EntryFunctionArgumentTypes} arg - The argument to convert.
|
|
290
|
-
* @returns {string} The converted argument as a string.
|
|
291
|
-
* @throws {Error} If the argument type is invalid.
|
|
292
|
-
*/
|
|
293
|
-
declare function convertArg(argsType: string, arg: EntryFunctionArgumentTypes): string;
|
|
294
|
-
|
|
295
|
-
export { type InitiaBuildTxRequest, type InitiaBuildTxRequestOptions, InitiaProvider, InitiaSigner, convertArg, convertPayloadToMsgExecute, covertPayloadArgs };
|
|
229
|
+
export { InitiaProvider, InitiaSigner };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LCDClient, AccAddress,
|
|
2
|
-
import { Block, TransactionResponse, TransactionReceipt, TransactionPending, SignedTransaction
|
|
1
|
+
import { LCDClient, AccAddress, MnemonicKey, RawKey, Wallet, ModeInfo } from '@initia/initia.js';
|
|
2
|
+
import { Block, TransactionResponse, TransactionReceipt, TransactionPending, SignedTransaction } from '@layerzerolabs/lz-core';
|
|
3
3
|
import { isHex, trim0x } from '@layerzerolabs/lz-utilities';
|
|
4
4
|
|
|
5
5
|
// src/providers/initia.ts
|
|
@@ -201,64 +201,6 @@ var InitiaProvider = class _InitiaProvider {
|
|
|
201
201
|
return this.confirmTransaction(pending, opts);
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
|
-
function convertPayloadToMsgExecute(sender, payload) {
|
|
205
|
-
const functionStructs = payload.function.split("::");
|
|
206
|
-
const moduleAddress = functionStructs[0];
|
|
207
|
-
const moduleName = functionStructs[1];
|
|
208
|
-
const functionName = functionStructs[2];
|
|
209
|
-
const args = covertPayloadArgs(payload.functionArgumentTypes ?? [], payload.functionArguments);
|
|
210
|
-
const msg = new MsgExecute(
|
|
211
|
-
sender,
|
|
212
|
-
// sender address
|
|
213
|
-
moduleAddress,
|
|
214
|
-
// module owner address
|
|
215
|
-
moduleName,
|
|
216
|
-
// module name
|
|
217
|
-
functionName,
|
|
218
|
-
// function name
|
|
219
|
-
payload.typeArguments ?? [],
|
|
220
|
-
// type args
|
|
221
|
-
args
|
|
222
|
-
);
|
|
223
|
-
return msg;
|
|
224
|
-
}
|
|
225
|
-
function covertPayloadArgs(functionArgumentTypes, functionArguments) {
|
|
226
|
-
const args = [];
|
|
227
|
-
for (let i = 0; i < functionArguments.length; i++) {
|
|
228
|
-
args.push(convertArg(functionArgumentTypes[i], functionArguments[i]));
|
|
229
|
-
}
|
|
230
|
-
return args;
|
|
231
|
-
}
|
|
232
|
-
function convertArg(argsType, arg) {
|
|
233
|
-
switch (argsType) {
|
|
234
|
-
case "bool":
|
|
235
|
-
return bcs.bool().serialize(arg).toBase64();
|
|
236
|
-
case "u256":
|
|
237
|
-
return bcs.u256().serialize(arg).toBase64();
|
|
238
|
-
case "u128":
|
|
239
|
-
return bcs.u128().serialize(arg).toBase64();
|
|
240
|
-
case "u64":
|
|
241
|
-
return bcs.u64().serialize(arg).toBase64();
|
|
242
|
-
case "u32":
|
|
243
|
-
return bcs.u32().serialize(arg).toBase64();
|
|
244
|
-
case "u16":
|
|
245
|
-
return bcs.u16().serialize(arg).toBase64();
|
|
246
|
-
case "u8":
|
|
247
|
-
return bcs.u8().serialize(arg).toBase64();
|
|
248
|
-
case "address":
|
|
249
|
-
return bcs.address().serialize(arg).toBase64();
|
|
250
|
-
case "vector<u8>":
|
|
251
|
-
return bcs.vector(bcs.u8()).serialize(arg).toBase64();
|
|
252
|
-
case "vector<address>":
|
|
253
|
-
return bcs.vector(bcs.address()).serialize(arg).toBase64();
|
|
254
|
-
case "vector<vector<u8>>":
|
|
255
|
-
return bcs.vector(bcs.vector(bcs.u8())).serialize(arg).toBase64();
|
|
256
|
-
default:
|
|
257
|
-
throw new Error(`Invalid type argsType: ${argsType.toString()}`);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// src/signers/initia.ts
|
|
262
204
|
var InitiaSigner = class {
|
|
263
205
|
/**
|
|
264
206
|
* Creates an instance of InitiaSigner.
|
|
@@ -273,7 +215,7 @@ var InitiaSigner = class {
|
|
|
273
215
|
*
|
|
274
216
|
* @param {string | MnemonicKey} source - The source to create the signer from.
|
|
275
217
|
* @param {string} [path] - The derivation path (optional).
|
|
276
|
-
* @returns {Signer
|
|
218
|
+
* @returns {Signer} The created InitiaSigner instance.
|
|
277
219
|
* @throws {Error} If the parameters are invalid.
|
|
278
220
|
*/
|
|
279
221
|
static from(source, path) {
|
|
@@ -314,7 +256,7 @@ var InitiaSigner = class {
|
|
|
314
256
|
* Connects the signer to a provider.
|
|
315
257
|
*
|
|
316
258
|
* @param {Provider} provider - The provider to connect to.
|
|
317
|
-
* @returns {Signer
|
|
259
|
+
* @returns {Signer} The connected signer.
|
|
318
260
|
* @throws {Error} If the provider is not an instance of InitiaProvider.
|
|
319
261
|
*/
|
|
320
262
|
connect(provider) {
|
|
@@ -399,36 +341,8 @@ var InitiaSigner = class {
|
|
|
399
341
|
async signBuffer(buffer) {
|
|
400
342
|
return this.nativeKey.sign(Buffer.from(buffer));
|
|
401
343
|
}
|
|
402
|
-
/**
|
|
403
|
-
* Builds a transaction.
|
|
404
|
-
*
|
|
405
|
-
* @param {InitiaBuildTxRequest} buildTxRequest - The transaction request to build.
|
|
406
|
-
* @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.
|
|
407
|
-
* @throws {Error} If the gas price is invalid.
|
|
408
|
-
*/
|
|
409
|
-
async buildTransaction(buildTxRequest) {
|
|
410
|
-
const sender = this.nativeSigner.key.accAddress.toString();
|
|
411
|
-
const msg = convertPayloadToMsgExecute(sender, buildTxRequest.payload);
|
|
412
|
-
const createOptions = {
|
|
413
|
-
msgs: [msg]
|
|
414
|
-
};
|
|
415
|
-
if (buildTxRequest.options?.gas !== void 0) {
|
|
416
|
-
createOptions.gas = buildTxRequest.options.gas;
|
|
417
|
-
}
|
|
418
|
-
if (buildTxRequest.options?.gasPrice !== void 0) {
|
|
419
|
-
if (isNaN(Number(buildTxRequest.options.gasPrice)) && buildTxRequest.options.gasPrice.endsWith("uinit")) {
|
|
420
|
-
createOptions.gasPrices = buildTxRequest.options.gasPrice;
|
|
421
|
-
} else if (!isNaN(Number(buildTxRequest.options.gasPrice))) {
|
|
422
|
-
createOptions.gasPrices = `${buildTxRequest.options.gasPrice}uinit`;
|
|
423
|
-
} else {
|
|
424
|
-
throw Error(`Invalid gas price for initia :${buildTxRequest.options.gasPrice}`);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
const tx = await this.nativeSigner.createTx(createOptions);
|
|
428
|
-
return TransactionRequest.from(tx);
|
|
429
|
-
}
|
|
430
344
|
};
|
|
431
345
|
|
|
432
|
-
export { InitiaProvider, InitiaSigner
|
|
433
|
-
//# sourceMappingURL=
|
|
346
|
+
export { InitiaProvider, InitiaSigner };
|
|
347
|
+
//# sourceMappingURL=index.mjs.map
|
|
434
348
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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,aAAa;AAMf,IAAM,iBAAN,MAAM,gBAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpC,YAAmB,KAAa;AAAb;AACvB,SAAK,iBAAiB,IAAI,UAAU,GAAG;AAAA,EAC3C;AAAA,EAUA,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;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,SAAoB;AACpB,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAW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;AAAA,MACxD,UAAU,SAAS,SAAS;AAAA,IAChC,CAAC;AACD,WAAOC,mBAAkB,KAAK,QAAQ;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,QAAyC;AACtD,WAAO,KAAK,UAAU,KAAK,OAAO,KAAK,MAAM,CAAC;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,iBAAiB,gBAAmE;AACtF,UAAM,SAAS,KAAK,aAAc,IAAI,WAAW,SAAS;AAC1D,UAAM,MAAM,2BAA2B,QAAQ,eAAe,OAAO;AACrE,UAAM,gBAEF;AAAA,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 { 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"]}
|
|
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,KA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M,EAAE,cAAgB,EAAA,QAAA,KAAa,MAAM,IAAA,CAAK,aAAa,wBAAyB,EAAA;AACtF,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,YAAa,CAAA,GAAA,CAAI,OAAO,EAAI,EAAA;AAAA,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.
|
|
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.
|
|
28
|
-
"@layerzerolabs/lz-utilities": "^3.0.
|
|
29
|
-
"@layerzerolabs/move-definitions": "^3.0.
|
|
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.
|
|
34
|
-
"@layerzerolabs/typescript-config-next": "^3.0.
|
|
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.
|
|
40
|
+
"tsup": "^8.3.5",
|
|
41
41
|
"typescript": "~5.2.2"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|