@layerzerolabs/lz-corekit-iotal1 3.0.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,361 @@
1
+ import { IotaClient, IotaHTTPTransport } from '@iota/iota-sdk/client';
2
+ import { Block, BlockWithTransactions, TransactionResponse, TransactionReceipt, TransactionPending, SignedTransaction } from '@layerzerolabs/lz-core';
3
+ import { isHex, trim0x } from '@layerzerolabs/lz-utilities';
4
+ import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519';
5
+
6
+ // src/providers/iotal1.ts
7
+ var IotaL1Provider = class _IotaL1Provider {
8
+ /**
9
+ * Creates an instance of IotaL1Provider.
10
+ *
11
+ * @param {string} url - The URL of the Iota Move node.
12
+ * @param {string} [faucet] - The URL of the faucet (optional).
13
+ * @param {string} [indexer] - The URL of the indexer (optional).
14
+ * @param authHeader
15
+ */
16
+ constructor(url, authHeader) {
17
+ this.url = url;
18
+ this.authHeader = authHeader;
19
+ this.nativeProvider = new IotaClient({
20
+ transport: new IotaHTTPTransport({
21
+ url,
22
+ rpc: {
23
+ headers: {
24
+ ...authHeader !== void 0 ? { [authHeader.authField]: authHeader.authValue } : {}
25
+ },
26
+ url
27
+ }
28
+ })
29
+ });
30
+ }
31
+ /**
32
+ * Creates an instance of IotaL1Provider from the given parameters.
33
+ *
34
+ * @param {string} source - The URL of the Iota Move node.
35
+ * @param authHeader
36
+ * @returns {IotaL1Provider} The created IotaL1Provider instance.
37
+ * @throws {Error} If the source parameter is not a string.
38
+ */
39
+ static from(source, authHeader) {
40
+ if (typeof source === "string") {
41
+ return new _IotaL1Provider(source, authHeader);
42
+ } else {
43
+ throw new Error("Invalid parameters");
44
+ }
45
+ }
46
+ /**
47
+ * Gets the native Iota Move client instance.
48
+ *
49
+ * @returns {IotaClient} The native Iota Move client instance.
50
+ */
51
+ get native() {
52
+ return this.nativeProvider;
53
+ }
54
+ /**
55
+ * Gets the balance of the specified address.
56
+ *
57
+ * @param {string} address - The address to get the balance of.
58
+ * @returns {Promise<string>} A promise that resolves to the balance of the address.
59
+ * @throws {Error} If the address is not a valid Iota Move address.
60
+ */
61
+ async getBalance(address) {
62
+ if (!isHex(address)) {
63
+ throw new Error("Invalid Iota Move address");
64
+ }
65
+ const coinBalance = await this.nativeProvider.getBalance({
66
+ owner: address
67
+ });
68
+ return coinBalance.totalBalance;
69
+ }
70
+ /**
71
+ * Gets the block specified by blockTag.
72
+ *
73
+ * @param {BlockTag} blockTag - The block tag to specify the block.
74
+ * @returns {Promise<Block>} A promise that resolves to the block.
75
+ * @throws {Error} If the blockTag is invalid.
76
+ */
77
+ async getBlock(blockTag) {
78
+ let blockNumber = "0";
79
+ if (typeof blockTag === "number") {
80
+ blockNumber = blockTag.toString();
81
+ } else if (blockTag === "latest") {
82
+ blockNumber = await this.getBlockNumber().then((blockNumber2) => blockNumber2.toString());
83
+ } else {
84
+ throw new Error("Invalid blockTag");
85
+ }
86
+ const response = await this.nativeProvider.getCheckpoint({
87
+ id: blockNumber
88
+ });
89
+ return Block.from(response);
90
+ }
91
+ /**
92
+ * Gets the block with transactions specified by blockTag.
93
+ *
94
+ * @param {BlockTag} blockTag - The block tag to specify the block.
95
+ * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
96
+ * @throws {Error} If the blockTag is invalid.
97
+ */
98
+ async getBlockWithTransactions(blockTag) {
99
+ return BlockWithTransactions.from((await this.getBlock(blockTag)).block);
100
+ }
101
+ /**
102
+ * Gets the current block number.
103
+ *
104
+ * @returns {Promise<number>} A promise that resolves to the current check point.
105
+ */
106
+ async getBlockNumber() {
107
+ return Promise.resolve(Number(await this.nativeProvider.getLatestCheckpointSequenceNumber()));
108
+ }
109
+ /**
110
+ * Gets the current slot number for commitment, not suitable for Iota Move.
111
+ *
112
+ * @param {Finality} [commitment] - The commitment level (optional).
113
+ * @returns {Promise<number>} A promise that resolves to the current slot number.
114
+ * @throws {Error} Method not implemented.
115
+ */
116
+ async getSlot(_finality) {
117
+ await Promise.resolve();
118
+ throw new Error("Method not implemented.");
119
+ }
120
+ /**
121
+ * Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.
122
+ *
123
+ * @param {BlockTag} blockTag - The block tag to specify the block.
124
+ * @returns {Promise<number>} A promise that resolves to the timestamp of the block.
125
+ * @throws {Error} If the blockTag is invalid.
126
+ */
127
+ async getBlockTimestamp(blockTag) {
128
+ const checkPoint = (await this.getBlock(blockTag)).block;
129
+ return Promise.resolve(Number(checkPoint.timestampMs));
130
+ }
131
+ /**
132
+ * Gets information about a transaction.
133
+ *
134
+ * @param {string} txHash - The hash of the transaction.
135
+ * @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
136
+ * @throws {Error} If the transaction hash is invalid.
137
+ */
138
+ async getTransaction(txHash) {
139
+ if (!isHex(txHash)) {
140
+ throw new Error("Invalid Iota Move transaction hash");
141
+ }
142
+ const response = await this.nativeProvider.getTransactionBlock({ digest: txHash });
143
+ return TransactionResponse.from(response);
144
+ }
145
+ /**
146
+ * Gets the receipt of a transaction.
147
+ *
148
+ * @param {string} txHash - The hash of the transaction.
149
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
150
+ * @throws {Error} If the transaction hash is invalid.
151
+ */
152
+ async getTransactionReceipt(txHash) {
153
+ if (!isHex(txHash)) {
154
+ throw new Error("Invalid Iota Move transaction hash");
155
+ }
156
+ const response = await this.nativeProvider.getTransactionBlock({
157
+ digest: txHash,
158
+ options: {
159
+ showBalanceChanges: true,
160
+ showEffects: true,
161
+ showEvents: true,
162
+ showObjectChanges: true
163
+ }
164
+ });
165
+ return TransactionReceipt.from(response);
166
+ }
167
+ /**
168
+ * Gets the number of transactions sent from the specified address.
169
+ *
170
+ * @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.
171
+ * @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).
172
+ * @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
173
+ * @throws {Error} If the address is invalid.
174
+ */
175
+ async getTransactionCount(addressOrName, _blockTag) {
176
+ await Promise.resolve();
177
+ throw new Error("Method not implemented.");
178
+ }
179
+ /**
180
+ * Sends a signed transaction to the blockchain.
181
+ *
182
+ * @param {SignedTransaction} transaction - The signed transaction to send.
183
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
184
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
185
+ */
186
+ async sendTransaction(transaction, _sendOptions) {
187
+ const stx = transaction.signed;
188
+ const response = await this.nativeProvider.executeTransactionBlock({
189
+ transactionBlock: stx.bytes,
190
+ signature: stx.signature
191
+ });
192
+ return TransactionPending.from(response);
193
+ }
194
+ /**
195
+ * Confirms a pending transaction.
196
+ *
197
+ * @param {TransactionPending} pending - The pending transaction to confirm.
198
+ * @param {object} [opts] - Optional parameters for the confirmation.
199
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
200
+ * @throws {Error} If the transaction fails.
201
+ */
202
+ async confirmTransaction(pending, opts) {
203
+ let response;
204
+ if (typeof pending.pending === "string") {
205
+ response = await this.nativeProvider.waitForTransaction({ digest: pending.pending });
206
+ } else if (typeof pending.pending === "object" && pending.pending !== null && "digest" in pending.pending && typeof pending.pending.digest === "string") {
207
+ response = await this.nativeProvider.waitForTransaction({ digest: pending.pending.digest });
208
+ } else {
209
+ throw new Error("Invalid pending transaction");
210
+ }
211
+ if (response.errors && response.errors.length > 0) {
212
+ throw new Error(` transaction failed : ${JSON.stringify(response.errors)}`);
213
+ }
214
+ return TransactionReceipt.from(response);
215
+ }
216
+ /**
217
+ * Sends a signed transaction and waits for confirmation.
218
+ *
219
+ * @param {SignedTransaction} transaction - The signed transaction to send.
220
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
221
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
222
+ */
223
+ async sendAndConfirm(transaction, opts) {
224
+ const pending = await this.sendTransaction(transaction, opts);
225
+ return this.confirmTransaction(pending, opts);
226
+ }
227
+ };
228
+ var IotaL1Signer = class {
229
+ /**
230
+ * Creates an instance of IotaL1Signer.
231
+ *
232
+ * @param {Ed25519Keypair} signer - The Iota Move account to use as the signer.
233
+ */
234
+ constructor(signer) {
235
+ this.nativeSigner = signer;
236
+ }
237
+ /**
238
+ * Creates an instance of IotaL1Signer from the given parameters.
239
+ *
240
+ * @param {string | Ed25519Keypair} source - The source to create the signer from, could be a private key, a mnemonics or an Iota Move account.
241
+ * @param {string} [path] - The derivation path (optional). e.g. m/44'/4218'/0'/0'/0' If provided, the source is treated as a mnemonics.
242
+ * @returns {IotaL1Signer} The created IotaL1Signer instance.
243
+ * @throws {Error} If the parameters are invalid.
244
+ */
245
+ static from(source, path) {
246
+ if (source instanceof Ed25519Keypair) {
247
+ return new this(source);
248
+ }
249
+ if (path === void 0) {
250
+ const signer = Ed25519Keypair.fromSecretKey(Buffer.from(trim0x(source), "hex"));
251
+ return new this(signer);
252
+ } else if (path.startsWith("m/")) {
253
+ const signer = Ed25519Keypair.deriveKeypair(source, path);
254
+ return new this(signer);
255
+ }
256
+ throw new Error("Invalid parameters");
257
+ }
258
+ /**
259
+ * Gets the native Iota Move signer instance.
260
+ *
261
+ * @returns {Ed25519Keypair} The native Iota Move signer instance.
262
+ */
263
+ get native() {
264
+ return this.nativeSigner;
265
+ }
266
+ /**
267
+ * Connects the signer to a provider.
268
+ *
269
+ * @param {Provider} provider - The provider to connect to.
270
+ * @returns {this} The connected signer.
271
+ * @throws {Error} If the provider is not an instance of IotaL1Provider.
272
+ */
273
+ connect(provider) {
274
+ if (!(provider instanceof IotaL1Provider)) {
275
+ throw new Error("Only IotaL1Provider is supported.");
276
+ }
277
+ this.provider = provider;
278
+ return this;
279
+ }
280
+ /**
281
+ * Gets the address of the signer.
282
+ *
283
+ * @returns {Promise<string>} A promise that resolves to the address of the signer.
284
+ */
285
+ async getAddress() {
286
+ return Promise.resolve(this.nativeSigner.getPublicKey().toIotaAddress());
287
+ }
288
+ /**
289
+ * Gets the address of the signer.
290
+ *
291
+ * @returns {string} The address of the signer.
292
+ */
293
+ get address() {
294
+ return this.nativeSigner.getPublicKey().toIotaAddress();
295
+ }
296
+ /**
297
+ * Sends a signed transaction and waits for confirmation.
298
+ *
299
+ * @param {SignedTransaction} transaction - The signed transaction to send.
300
+ * @param {object} [opts] - Optional parameters for sending and confirming the transaction.
301
+ * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
302
+ * @throws {Error} If the provider is not connected.
303
+ */
304
+ async sendAndConfirm(transaction, opts) {
305
+ if (this.provider === void 0) {
306
+ throw new Error("provider is required");
307
+ }
308
+ return this.provider.sendAndConfirm(transaction, opts);
309
+ }
310
+ /**
311
+ * Sends a signed transaction.
312
+ *
313
+ * @param {SignedTransaction} transaction - The signed transaction to send.
314
+ * @param {object} [sendOptions] - Optional parameters for sending the transaction.
315
+ * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
316
+ * @throws {Error} If the provider is not connected.
317
+ */
318
+ async sendTransaction(transaction, sendOptions) {
319
+ if (this.provider === void 0) {
320
+ throw new Error("provider is required");
321
+ }
322
+ return this.provider.sendTransaction(transaction, sendOptions);
323
+ }
324
+ /**
325
+ * Signs a transaction.
326
+ *
327
+ * @param {TransactionRequest} transaction - The transaction request to sign.
328
+ * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
329
+ * @throws {Error} If the native provider is not connected.
330
+ */
331
+ async signTransaction(transaction) {
332
+ const nativeProvider = this.provider?.native;
333
+ if (nativeProvider === void 0) {
334
+ throw new Error("Connect the native provider first with IotaL1Signer.connect()");
335
+ }
336
+ const tx = transaction.request;
337
+ let transactionBytes;
338
+ if (tx instanceof Uint8Array) {
339
+ transactionBytes = tx;
340
+ } else {
341
+ tx.setSenderIfNotSet(this.nativeSigner.toIotaAddress());
342
+ transactionBytes = await tx.build({ client: this.provider?.nativeProvider });
343
+ }
344
+ const signatureWithBytes = await this.nativeSigner.signTransaction(transactionBytes);
345
+ return SignedTransaction.from(signatureWithBytes);
346
+ }
347
+ /**
348
+ * Signs a buffer (e.g., a message hash) using the native Iota Move signer.
349
+ *
350
+ * @param {Uint8Array} buffer - The buffer to sign.
351
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
352
+ */
353
+ async signBuffer(buffer) {
354
+ const { signature } = await this.nativeSigner.signPersonalMessage(buffer);
355
+ return Promise.resolve(Buffer.from(signature));
356
+ }
357
+ };
358
+
359
+ export { IotaL1Provider, IotaL1Signer };
360
+ //# sourceMappingURL=index.mjs.map
361
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/providers/iotal1.ts","../src/signers/iotal1.ts"],"names":["blockNumber","SignedTransaction"],"mappings":";;;;;;AAoBa,IAAA,cAAA,GAAN,MAAM,eAAmC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWpC,WAAA,CACY,KACA,UAClB,EAAA;AAFkB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AACA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAEhB,IAAK,IAAA,CAAA,cAAA,GAAiB,IAAI,UAAW,CAAA;AAAA,MACjC,SAAA,EAAW,IAAI,iBAAkB,CAAA;AAAA,QAC7B,GAAA;AAAA,QACA,GAAK,EAAA;AAAA,UACD,OAAS,EAAA;AAAA,YACL,GAAI,UAAe,KAAA,KAAA,CAAA,GAAY,EAAE,CAAC,UAAW,CAAA,SAAS,GAAG,UAAA,CAAW,SAAU,EAAA,GAAI;AAAC,WACvF;AAAA,UACA;AAAA;AACJ,OACH;AAAA,KACJ,CAAA;AAAA;AACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,IAAK,CAAA,MAAA,EAAgB,UAAuE,EAAA;AAC/F,IAAI,IAAA,OAAO,WAAW,QAAU,EAAA;AA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AAA,MAAM,EAAE,SAAU,EAAA,GAAI,MAAM,IAAK,CAAA,YAAA,CAAa,oBAAoB,MAAM,CAAA;AACxE,IAAA,OAAO,OAAQ,CAAA,OAAA,CAAQ,MAAO,CAAA,IAAA,CAAK,SAAS,CAAC,CAAA;AAAA;AAErD","file":"index.mjs","sourcesContent":["import { Checkpoint, IotaClient, IotaHTTPTransport, IotaTransactionBlockResponse } from '@iota/iota-sdk/client'\nimport { SignatureWithBytes } from '@iota/iota-sdk/cryptography'\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 Iota Move blockchain provider.\n * Implements the Provider interface for interacting with the Iota Move blockchain.\n */\nexport class IotaL1Provider implements Provider {\n readonly nativeProvider: IotaClient\n\n /**\n * Creates an instance of IotaL1Provider.\n *\n * @param {string} url - The URL of the Iota Move node.\n * @param {string} [faucet] - The URL of the faucet (optional).\n * @param {string} [indexer] - The URL of the indexer (optional).\n * @param authHeader\n */\n private constructor(\n public readonly url: string,\n public readonly authHeader?: { authField: string; authValue: string }\n ) {\n this.nativeProvider = new IotaClient({\n transport: new IotaHTTPTransport({\n url,\n rpc: {\n headers: {\n ...(authHeader !== undefined ? { [authHeader.authField]: authHeader.authValue } : {}),\n },\n url,\n },\n }),\n })\n }\n\n /**\n * Creates an instance of IotaL1Provider from the given parameters.\n *\n * @param {string} source - The URL of the Iota Move node.\n * @param authHeader\n * @returns {IotaL1Provider} The created IotaL1Provider instance.\n * @throws {Error} If the source parameter is not a string.\n */\n static from(source: string, authHeader?: { authField: string; authValue: string }): IotaL1Provider {\n if (typeof source === 'string') {\n return new IotaL1Provider(source, authHeader)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n /**\n * Gets the native Iota Move client instance.\n *\n * @returns {IotaClient} The native Iota Move client instance.\n */\n get native(): IotaClient {\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 Iota Move address.\n */\n async getBalance(address: string): Promise<string> {\n if (!isHex(address)) {\n throw new Error('Invalid Iota Move address')\n }\n\n const coinBalance = await this.nativeProvider.getBalance({\n owner: address,\n })\n\n return coinBalance.totalBalance\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.toString()\n } else if (blockTag === 'latest') {\n blockNumber = await this.getBlockNumber().then((blockNumber) => blockNumber.toString())\n } else {\n throw new Error('Invalid blockTag')\n }\n const response = await this.nativeProvider.getCheckpoint({\n id: blockNumber,\n })\n return Block.from(response)\n }\n\n /**\n * Gets the block with transactions specified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions> {\n return BlockWithTransactions.from((await this.getBlock(blockTag)).block)\n }\n\n /**\n * Gets the current block number.\n *\n * @returns {Promise<number>} A promise that resolves to the current check point.\n */\n async getBlockNumber(): Promise<number> {\n return Promise.resolve(Number(await this.nativeProvider.getLatestCheckpointSequenceNumber()))\n }\n\n /**\n * Gets the current slot number for commitment, not suitable for Iota Move.\n *\n * @param {Finality} [commitment] - The commitment level (optional).\n * @returns {Promise<number>} A promise that resolves to the current slot number.\n * @throws {Error} Method not implemented.\n */\n async getSlot(_finality?: Finality): Promise<number> {\n await Promise.resolve()\n throw new Error('Method not implemented.')\n }\n\n /**\n * Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.\n *\n * @param {BlockTag} blockTag - The block tag to specify the block.\n * @returns {Promise<number>} A promise that resolves to the timestamp of the block.\n * @throws {Error} If the blockTag is invalid.\n */\n async getBlockTimestamp(blockTag: string | number): Promise<number> {\n const checkPoint = (await this.getBlock(blockTag)).block as Checkpoint\n return Promise.resolve(Number(checkPoint.timestampMs))\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 Iota Move transaction hash')\n }\n const response = await this.nativeProvider.getTransactionBlock({ digest: 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 Iota Move transaction hash')\n }\n\n const response = await this.nativeProvider.getTransactionBlock({\n digest: txHash,\n options: {\n showBalanceChanges: true,\n showEffects: true,\n showEvents: true,\n showObjectChanges: true,\n },\n })\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 //TODO\n await Promise.resolve()\n throw new Error('Method not implemented.')\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 const stx = transaction.signed as SignatureWithBytes\n const response = await this.nativeProvider.executeTransactionBlock({\n transactionBlock: stx.bytes,\n signature: stx.signature,\n })\n\n return TransactionPending.from(response)\n }\n\n /**\n * Confirms a pending transaction.\n *\n * @param {TransactionPending} pending - The pending transaction to confirm.\n * @param {object} [opts] - Optional parameters for the confirmation.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the transaction fails.\n */\n async confirmTransaction(pending: TransactionPending, opts?: object): Promise<TransactionReceipt> {\n let response: IotaTransactionBlockResponse\n if (typeof pending.pending === 'string') {\n response = await this.nativeProvider.waitForTransaction({ digest: pending.pending })\n } else if (\n typeof pending.pending === 'object' &&\n pending.pending !== null &&\n 'digest' in pending.pending &&\n typeof pending.pending.digest === 'string'\n ) {\n response = await this.nativeProvider.waitForTransaction({ digest: pending.pending.digest })\n } else {\n throw new Error('Invalid pending transaction')\n }\n\n if (response.errors && response.errors.length > 0) {\n throw new Error(` transaction failed : ${JSON.stringify(response.errors)}`)\n }\n\n return TransactionReceipt.from(response)\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n const pending = await this.sendTransaction(transaction, opts)\n return this.confirmTransaction(pending, opts)\n }\n}\n","import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519'\nimport { Transaction } from '@iota/iota-sdk/transactions'\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 { IotaL1Provider } from '../providers'\n\n/**\n * Represents an Iota Move blockchain signer.\n * Implements the Signer interface for interacting with the Iota Move blockchain.\n */\nexport class IotaL1Signer implements Signer {\n public nativeSigner: Ed25519Keypair\n public provider: IotaL1Provider | undefined\n\n /**\n * Creates an instance of IotaL1Signer.\n *\n * @param {Ed25519Keypair} signer - The Iota Move account to use as the signer.\n */\n private constructor(signer: Ed25519Keypair) {\n this.nativeSigner = signer\n }\n\n /**\n * Creates an instance of IotaL1Signer from the given parameters.\n *\n * @param {string | Ed25519Keypair} source - The source to create the signer from, could be a private key, a mnemonics or an Iota Move account.\n * @param {string} [path] - The derivation path (optional). e.g. m/44'/4218'/0'/0'/0' If provided, the source is treated as a mnemonics.\n * @returns {IotaL1Signer} The created IotaL1Signer instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | Ed25519Keypair, path?: string): IotaL1Signer {\n if (source instanceof Ed25519Keypair) {\n return new this(source)\n }\n if (path === undefined) {\n const signer = Ed25519Keypair.fromSecretKey(Buffer.from(trim0x(source), 'hex'))\n return new this(signer)\n } else if (path.startsWith('m/')) {\n const signer = Ed25519Keypair.deriveKeypair(source, path)\n return new this(signer)\n }\n throw new Error('Invalid parameters')\n }\n\n /**\n * Gets the native Iota Move signer instance.\n *\n * @returns {Ed25519Keypair} The native Iota Move signer instance.\n */\n get native(): Ed25519Keypair {\n return this.nativeSigner\n }\n\n /**\n * Connects the signer to a provider.\n *\n * @param {Provider} provider - The provider to connect to.\n * @returns {this} The connected signer.\n * @throws {Error} If the provider is not an instance of IotaL1Provider.\n */\n connect(provider: Provider): this {\n if (!(provider instanceof IotaL1Provider)) {\n throw new Error('Only IotaL1Provider is supported.')\n }\n\n this.provider = provider\n return this\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {Promise<string>} A promise that resolves to the address of the signer.\n */\n async getAddress(): Promise<string> {\n return Promise.resolve(this.nativeSigner.getPublicKey().toIotaAddress())\n }\n\n /**\n * Gets the address of the signer.\n *\n * @returns {string} The address of the signer.\n */\n get address(): string {\n return this.nativeSigner.getPublicKey().toIotaAddress()\n }\n\n /**\n * Sends a signed transaction and waits for confirmation.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [opts] - Optional parameters for sending and confirming the transaction.\n * @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.\n * @throws {Error} If the provider is not connected.\n */\n async sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendAndConfirm(transaction, opts)\n }\n\n /**\n * Sends a signed transaction.\n *\n * @param {SignedTransaction} transaction - The signed transaction to send.\n * @param {object} [sendOptions] - Optional parameters for sending the transaction.\n * @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.\n * @throws {Error} If the provider is not connected.\n */\n async sendTransaction(transaction: SignedTransaction, sendOptions?: object): Promise<TransactionPending> {\n if (this.provider === undefined) {\n throw new Error('provider is required')\n }\n\n return this.provider.sendTransaction(transaction, sendOptions)\n }\n\n /**\n * Signs a transaction.\n *\n * @param {TransactionRequest} transaction - The transaction request to sign.\n * @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.\n * @throws {Error} If the native provider is not connected.\n */\n async signTransaction(transaction: TransactionRequest): Promise<SignedTransaction> {\n const nativeProvider = this.provider?.native\n if (nativeProvider === undefined) {\n throw new Error('Connect the native provider first with IotaL1Signer.connect()')\n }\n const tx = transaction.request as Uint8Array | Transaction\n\n let transactionBytes\n if (tx instanceof Uint8Array) {\n transactionBytes = tx\n } else {\n tx.setSenderIfNotSet(this.nativeSigner.toIotaAddress())\n transactionBytes = await tx.build({ client: this.provider?.nativeProvider })\n }\n const signatureWithBytes = await this.nativeSigner.signTransaction(transactionBytes)\n\n return SignedTransaction.from(signatureWithBytes)\n }\n\n /**\n * Signs a buffer (e.g., a message hash) using the native Iota Move signer.\n *\n * @param {Uint8Array} buffer - The buffer to sign.\n * @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.\n */\n async signBuffer(buffer: Uint8Array): Promise<Uint8Array> {\n const { signature } = await this.nativeSigner.signPersonalMessage(buffer)\n return Promise.resolve(Buffer.from(signature))\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@layerzerolabs/lz-corekit-iotal1",
3
+ "version": "3.0.143",
4
+ "description": "LayerZero Core Library",
5
+ "license": "BUSL-1.1",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.mjs",
10
+ "require": "./dist/index.cjs"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "main": "./dist/index.cjs",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist/**/*"
18
+ ],
19
+ "scripts": {
20
+ "build": "$npm_execpath clean-prebuild && $npm_execpath build-ts",
21
+ "build-ts": "$npm_execpath tsc --noEmit && $npm_execpath tsup",
22
+ "clean": "$npm_execpath clean-prebuild && rm -rf .turbo",
23
+ "clean-prebuild": "rm -rf dist"
24
+ },
25
+ "dependencies": {
26
+ "@iota/iota-sdk": "^1.6.1",
27
+ "@layerzerolabs/lz-core": "^3.0.143",
28
+ "@layerzerolabs/lz-utilities": "^3.0.143"
29
+ },
30
+ "devDependencies": {
31
+ "@jest/globals": "^29.7.0",
32
+ "@layerzerolabs/tsup-config-next": "^3.0.143",
33
+ "@layerzerolabs/typescript-config-next": "^3.0.143",
34
+ "@types/jest": "^29.5.10",
35
+ "jest": "^29.7.0",
36
+ "jest-extended": "^4.0.2",
37
+ "rimraf": "^5.0.5",
38
+ "ts-jest": "^29.1.1",
39
+ "tsup": "^8.3.5",
40
+ "typescript": "~5.2.2"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }