@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/CHANGELOG.md +36 -0
- package/README.md +9 -0
- package/dist/index.cjs +364 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +224 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.mjs +361 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @layerzerolabs/lz-corekit-iotal1
|
|
2
|
+
|
|
3
|
+
## 3.0.143
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2b9515d: endpoints: nexera, stable
|
|
8
|
+
- Updated dependencies [2b9515d]
|
|
9
|
+
- @layerzerolabs/lz-core@3.0.143
|
|
10
|
+
- @layerzerolabs/lz-utilities@3.0.143
|
|
11
|
+
|
|
12
|
+
## 3.0.142
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- ecf5da4: Update the Iota oft sdk
|
|
17
|
+
- Updated dependencies [ecf5da4]
|
|
18
|
+
- @layerzerolabs/lz-core@3.0.142
|
|
19
|
+
- @layerzerolabs/lz-utilities@3.0.142
|
|
20
|
+
|
|
21
|
+
## 3.0.141
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 6dd8a14: nexera testnet, injectiveevm mainnet
|
|
26
|
+
- Updated dependencies [6dd8a14]
|
|
27
|
+
- @layerzerolabs/lz-core@3.0.141
|
|
28
|
+
- @layerzerolabs/lz-utilities@3.0.141
|
|
29
|
+
|
|
30
|
+
## 3.0.140
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [837408a]
|
|
35
|
+
- @layerzerolabs/lz-core@3.0.140
|
|
36
|
+
- @layerzerolabs/lz-utilities@3.0.140
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @layerzerolabs/lz-corekit-iotal1
|
|
2
|
+
|
|
3
|
+
The IotaL1 CoreKit is a comprehensive SDK designed to interact with the Iota Move blockchain. It provides a set of utilities and modules to facilitate the development and integration of applications with the Iota Move blockchain.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Retrieve Account Information**: Gets the balance of the specified address.
|
|
8
|
+
- **Retrieve Block Information**: Gets the block height, timestamp and related transactions of the specified block.
|
|
9
|
+
- **Transaction Management**: Get, build, sign, send and confirm transactions.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@iota/iota-sdk/client');
|
|
4
|
+
var lzCore = require('@layerzerolabs/lz-core');
|
|
5
|
+
var lzUtilities = require('@layerzerolabs/lz-utilities');
|
|
6
|
+
var ed25519 = require('@iota/iota-sdk/keypairs/ed25519');
|
|
7
|
+
|
|
8
|
+
// src/providers/iotal1.ts
|
|
9
|
+
var IotaL1Provider = class _IotaL1Provider {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of IotaL1Provider.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} url - The URL of the Iota Move node.
|
|
14
|
+
* @param {string} [faucet] - The URL of the faucet (optional).
|
|
15
|
+
* @param {string} [indexer] - The URL of the indexer (optional).
|
|
16
|
+
* @param authHeader
|
|
17
|
+
*/
|
|
18
|
+
constructor(url, authHeader) {
|
|
19
|
+
this.url = url;
|
|
20
|
+
this.authHeader = authHeader;
|
|
21
|
+
this.nativeProvider = new client.IotaClient({
|
|
22
|
+
transport: new client.IotaHTTPTransport({
|
|
23
|
+
url,
|
|
24
|
+
rpc: {
|
|
25
|
+
headers: {
|
|
26
|
+
...authHeader !== void 0 ? { [authHeader.authField]: authHeader.authValue } : {}
|
|
27
|
+
},
|
|
28
|
+
url
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates an instance of IotaL1Provider from the given parameters.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} source - The URL of the Iota Move node.
|
|
37
|
+
* @param authHeader
|
|
38
|
+
* @returns {IotaL1Provider} The created IotaL1Provider instance.
|
|
39
|
+
* @throws {Error} If the source parameter is not a string.
|
|
40
|
+
*/
|
|
41
|
+
static from(source, authHeader) {
|
|
42
|
+
if (typeof source === "string") {
|
|
43
|
+
return new _IotaL1Provider(source, authHeader);
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error("Invalid parameters");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the native Iota Move client instance.
|
|
50
|
+
*
|
|
51
|
+
* @returns {IotaClient} The native Iota Move client instance.
|
|
52
|
+
*/
|
|
53
|
+
get native() {
|
|
54
|
+
return this.nativeProvider;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Gets the balance of the specified address.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} address - The address to get the balance of.
|
|
60
|
+
* @returns {Promise<string>} A promise that resolves to the balance of the address.
|
|
61
|
+
* @throws {Error} If the address is not a valid Iota Move address.
|
|
62
|
+
*/
|
|
63
|
+
async getBalance(address) {
|
|
64
|
+
if (!lzUtilities.isHex(address)) {
|
|
65
|
+
throw new Error("Invalid Iota Move address");
|
|
66
|
+
}
|
|
67
|
+
const coinBalance = await this.nativeProvider.getBalance({
|
|
68
|
+
owner: address
|
|
69
|
+
});
|
|
70
|
+
return coinBalance.totalBalance;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the block specified by blockTag.
|
|
74
|
+
*
|
|
75
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
76
|
+
* @returns {Promise<Block>} A promise that resolves to the block.
|
|
77
|
+
* @throws {Error} If the blockTag is invalid.
|
|
78
|
+
*/
|
|
79
|
+
async getBlock(blockTag) {
|
|
80
|
+
let blockNumber = "0";
|
|
81
|
+
if (typeof blockTag === "number") {
|
|
82
|
+
blockNumber = blockTag.toString();
|
|
83
|
+
} else if (blockTag === "latest") {
|
|
84
|
+
blockNumber = await this.getBlockNumber().then((blockNumber2) => blockNumber2.toString());
|
|
85
|
+
} else {
|
|
86
|
+
throw new Error("Invalid blockTag");
|
|
87
|
+
}
|
|
88
|
+
const response = await this.nativeProvider.getCheckpoint({
|
|
89
|
+
id: blockNumber
|
|
90
|
+
});
|
|
91
|
+
return lzCore.Block.from(response);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Gets the block with transactions specified by blockTag.
|
|
95
|
+
*
|
|
96
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
97
|
+
* @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
|
|
98
|
+
* @throws {Error} If the blockTag is invalid.
|
|
99
|
+
*/
|
|
100
|
+
async getBlockWithTransactions(blockTag) {
|
|
101
|
+
return lzCore.BlockWithTransactions.from((await this.getBlock(blockTag)).block);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Gets the current block number.
|
|
105
|
+
*
|
|
106
|
+
* @returns {Promise<number>} A promise that resolves to the current check point.
|
|
107
|
+
*/
|
|
108
|
+
async getBlockNumber() {
|
|
109
|
+
return Promise.resolve(Number(await this.nativeProvider.getLatestCheckpointSequenceNumber()));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Gets the current slot number for commitment, not suitable for Iota Move.
|
|
113
|
+
*
|
|
114
|
+
* @param {Finality} [commitment] - The commitment level (optional).
|
|
115
|
+
* @returns {Promise<number>} A promise that resolves to the current slot number.
|
|
116
|
+
* @throws {Error} Method not implemented.
|
|
117
|
+
*/
|
|
118
|
+
async getSlot(_finality) {
|
|
119
|
+
await Promise.resolve();
|
|
120
|
+
throw new Error("Method not implemented.");
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.
|
|
124
|
+
*
|
|
125
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
126
|
+
* @returns {Promise<number>} A promise that resolves to the timestamp of the block.
|
|
127
|
+
* @throws {Error} If the blockTag is invalid.
|
|
128
|
+
*/
|
|
129
|
+
async getBlockTimestamp(blockTag) {
|
|
130
|
+
const checkPoint = (await this.getBlock(blockTag)).block;
|
|
131
|
+
return Promise.resolve(Number(checkPoint.timestampMs));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Gets information about a transaction.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} txHash - The hash of the transaction.
|
|
137
|
+
* @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
|
|
138
|
+
* @throws {Error} If the transaction hash is invalid.
|
|
139
|
+
*/
|
|
140
|
+
async getTransaction(txHash) {
|
|
141
|
+
if (!lzUtilities.isHex(txHash)) {
|
|
142
|
+
throw new Error("Invalid Iota Move transaction hash");
|
|
143
|
+
}
|
|
144
|
+
const response = await this.nativeProvider.getTransactionBlock({ digest: txHash });
|
|
145
|
+
return lzCore.TransactionResponse.from(response);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Gets the receipt of a transaction.
|
|
149
|
+
*
|
|
150
|
+
* @param {string} txHash - The hash of the transaction.
|
|
151
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
152
|
+
* @throws {Error} If the transaction hash is invalid.
|
|
153
|
+
*/
|
|
154
|
+
async getTransactionReceipt(txHash) {
|
|
155
|
+
if (!lzUtilities.isHex(txHash)) {
|
|
156
|
+
throw new Error("Invalid Iota Move transaction hash");
|
|
157
|
+
}
|
|
158
|
+
const response = await this.nativeProvider.getTransactionBlock({
|
|
159
|
+
digest: txHash,
|
|
160
|
+
options: {
|
|
161
|
+
showBalanceChanges: true,
|
|
162
|
+
showEffects: true,
|
|
163
|
+
showEvents: true,
|
|
164
|
+
showObjectChanges: true
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return lzCore.TransactionReceipt.from(response);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Gets the number of transactions sent from the specified address.
|
|
171
|
+
*
|
|
172
|
+
* @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.
|
|
173
|
+
* @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).
|
|
174
|
+
* @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
|
|
175
|
+
* @throws {Error} If the address is invalid.
|
|
176
|
+
*/
|
|
177
|
+
async getTransactionCount(addressOrName, _blockTag) {
|
|
178
|
+
await Promise.resolve();
|
|
179
|
+
throw new Error("Method not implemented.");
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Sends a signed transaction to the blockchain.
|
|
183
|
+
*
|
|
184
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
185
|
+
* @param {object} [sendOptions] - Optional parameters for sending the transaction.
|
|
186
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
187
|
+
*/
|
|
188
|
+
async sendTransaction(transaction, _sendOptions) {
|
|
189
|
+
const stx = transaction.signed;
|
|
190
|
+
const response = await this.nativeProvider.executeTransactionBlock({
|
|
191
|
+
transactionBlock: stx.bytes,
|
|
192
|
+
signature: stx.signature
|
|
193
|
+
});
|
|
194
|
+
return lzCore.TransactionPending.from(response);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Confirms a pending transaction.
|
|
198
|
+
*
|
|
199
|
+
* @param {TransactionPending} pending - The pending transaction to confirm.
|
|
200
|
+
* @param {object} [opts] - Optional parameters for the confirmation.
|
|
201
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
202
|
+
* @throws {Error} If the transaction fails.
|
|
203
|
+
*/
|
|
204
|
+
async confirmTransaction(pending, opts) {
|
|
205
|
+
let response;
|
|
206
|
+
if (typeof pending.pending === "string") {
|
|
207
|
+
response = await this.nativeProvider.waitForTransaction({ digest: pending.pending });
|
|
208
|
+
} else if (typeof pending.pending === "object" && pending.pending !== null && "digest" in pending.pending && typeof pending.pending.digest === "string") {
|
|
209
|
+
response = await this.nativeProvider.waitForTransaction({ digest: pending.pending.digest });
|
|
210
|
+
} else {
|
|
211
|
+
throw new Error("Invalid pending transaction");
|
|
212
|
+
}
|
|
213
|
+
if (response.errors && response.errors.length > 0) {
|
|
214
|
+
throw new Error(` transaction failed : ${JSON.stringify(response.errors)}`);
|
|
215
|
+
}
|
|
216
|
+
return lzCore.TransactionReceipt.from(response);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Sends a signed transaction and waits for confirmation.
|
|
220
|
+
*
|
|
221
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
222
|
+
* @param {object} [opts] - Optional parameters for sending and confirming the transaction.
|
|
223
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
224
|
+
*/
|
|
225
|
+
async sendAndConfirm(transaction, opts) {
|
|
226
|
+
const pending = await this.sendTransaction(transaction, opts);
|
|
227
|
+
return this.confirmTransaction(pending, opts);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var IotaL1Signer = class {
|
|
231
|
+
/**
|
|
232
|
+
* Creates an instance of IotaL1Signer.
|
|
233
|
+
*
|
|
234
|
+
* @param {Ed25519Keypair} signer - The Iota Move account to use as the signer.
|
|
235
|
+
*/
|
|
236
|
+
constructor(signer) {
|
|
237
|
+
this.nativeSigner = signer;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Creates an instance of IotaL1Signer from the given parameters.
|
|
241
|
+
*
|
|
242
|
+
* @param {string | Ed25519Keypair} source - The source to create the signer from, could be a private key, a mnemonics or an Iota Move account.
|
|
243
|
+
* @param {string} [path] - The derivation path (optional). e.g. m/44'/4218'/0'/0'/0' If provided, the source is treated as a mnemonics.
|
|
244
|
+
* @returns {IotaL1Signer} The created IotaL1Signer instance.
|
|
245
|
+
* @throws {Error} If the parameters are invalid.
|
|
246
|
+
*/
|
|
247
|
+
static from(source, path) {
|
|
248
|
+
if (source instanceof ed25519.Ed25519Keypair) {
|
|
249
|
+
return new this(source);
|
|
250
|
+
}
|
|
251
|
+
if (path === void 0) {
|
|
252
|
+
const signer = ed25519.Ed25519Keypair.fromSecretKey(Buffer.from(lzUtilities.trim0x(source), "hex"));
|
|
253
|
+
return new this(signer);
|
|
254
|
+
} else if (path.startsWith("m/")) {
|
|
255
|
+
const signer = ed25519.Ed25519Keypair.deriveKeypair(source, path);
|
|
256
|
+
return new this(signer);
|
|
257
|
+
}
|
|
258
|
+
throw new Error("Invalid parameters");
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Gets the native Iota Move signer instance.
|
|
262
|
+
*
|
|
263
|
+
* @returns {Ed25519Keypair} The native Iota Move signer instance.
|
|
264
|
+
*/
|
|
265
|
+
get native() {
|
|
266
|
+
return this.nativeSigner;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Connects the signer to a provider.
|
|
270
|
+
*
|
|
271
|
+
* @param {Provider} provider - The provider to connect to.
|
|
272
|
+
* @returns {this} The connected signer.
|
|
273
|
+
* @throws {Error} If the provider is not an instance of IotaL1Provider.
|
|
274
|
+
*/
|
|
275
|
+
connect(provider) {
|
|
276
|
+
if (!(provider instanceof IotaL1Provider)) {
|
|
277
|
+
throw new Error("Only IotaL1Provider is supported.");
|
|
278
|
+
}
|
|
279
|
+
this.provider = provider;
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Gets the address of the signer.
|
|
284
|
+
*
|
|
285
|
+
* @returns {Promise<string>} A promise that resolves to the address of the signer.
|
|
286
|
+
*/
|
|
287
|
+
async getAddress() {
|
|
288
|
+
return Promise.resolve(this.nativeSigner.getPublicKey().toIotaAddress());
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Gets the address of the signer.
|
|
292
|
+
*
|
|
293
|
+
* @returns {string} The address of the signer.
|
|
294
|
+
*/
|
|
295
|
+
get address() {
|
|
296
|
+
return this.nativeSigner.getPublicKey().toIotaAddress();
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Sends a signed transaction and waits for confirmation.
|
|
300
|
+
*
|
|
301
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
302
|
+
* @param {object} [opts] - Optional parameters for sending and confirming the transaction.
|
|
303
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
304
|
+
* @throws {Error} If the provider is not connected.
|
|
305
|
+
*/
|
|
306
|
+
async sendAndConfirm(transaction, opts) {
|
|
307
|
+
if (this.provider === void 0) {
|
|
308
|
+
throw new Error("provider is required");
|
|
309
|
+
}
|
|
310
|
+
return this.provider.sendAndConfirm(transaction, opts);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Sends a signed transaction.
|
|
314
|
+
*
|
|
315
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
316
|
+
* @param {object} [sendOptions] - Optional parameters for sending the transaction.
|
|
317
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
318
|
+
* @throws {Error} If the provider is not connected.
|
|
319
|
+
*/
|
|
320
|
+
async sendTransaction(transaction, sendOptions) {
|
|
321
|
+
if (this.provider === void 0) {
|
|
322
|
+
throw new Error("provider is required");
|
|
323
|
+
}
|
|
324
|
+
return this.provider.sendTransaction(transaction, sendOptions);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Signs a transaction.
|
|
328
|
+
*
|
|
329
|
+
* @param {TransactionRequest} transaction - The transaction request to sign.
|
|
330
|
+
* @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
|
|
331
|
+
* @throws {Error} If the native provider is not connected.
|
|
332
|
+
*/
|
|
333
|
+
async signTransaction(transaction) {
|
|
334
|
+
const nativeProvider = this.provider?.native;
|
|
335
|
+
if (nativeProvider === void 0) {
|
|
336
|
+
throw new Error("Connect the native provider first with IotaL1Signer.connect()");
|
|
337
|
+
}
|
|
338
|
+
const tx = transaction.request;
|
|
339
|
+
let transactionBytes;
|
|
340
|
+
if (tx instanceof Uint8Array) {
|
|
341
|
+
transactionBytes = tx;
|
|
342
|
+
} else {
|
|
343
|
+
tx.setSenderIfNotSet(this.nativeSigner.toIotaAddress());
|
|
344
|
+
transactionBytes = await tx.build({ client: this.provider?.nativeProvider });
|
|
345
|
+
}
|
|
346
|
+
const signatureWithBytes = await this.nativeSigner.signTransaction(transactionBytes);
|
|
347
|
+
return lzCore.SignedTransaction.from(signatureWithBytes);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Signs a buffer (e.g., a message hash) using the native Iota Move signer.
|
|
351
|
+
*
|
|
352
|
+
* @param {Uint8Array} buffer - The buffer to sign.
|
|
353
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
|
|
354
|
+
*/
|
|
355
|
+
async signBuffer(buffer) {
|
|
356
|
+
const { signature } = await this.nativeSigner.signPersonalMessage(buffer);
|
|
357
|
+
return Promise.resolve(Buffer.from(signature));
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
exports.IotaL1Provider = IotaL1Provider;
|
|
362
|
+
exports.IotaL1Signer = IotaL1Signer;
|
|
363
|
+
//# sourceMappingURL=index.cjs.map
|
|
364
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/providers/iotal1.ts","../src/signers/iotal1.ts"],"names":["IotaClient","IotaHTTPTransport","isHex","blockNumber","Block","BlockWithTransactions","TransactionResponse","TransactionReceipt","TransactionPending","Ed25519Keypair","trim0x","SignedTransaction"],"mappings":";;;;;;;;AAoBa,IAAA,cAAA,GAAN,MAAM,eAAmC,CAAA;AAAA;AAAA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MAAA;AACtC,IAAA,IAAI,mBAAmB,KAAW,CAAA,EAAA;AAC9B,MAAM,MAAA,IAAI,MAAM,+DAA+D,CAAA;AAAA;AAEnF,IAAA,MAAM,KAAK,WAAY,CAAA,OAAA;AAEvB,IAAI,IAAA,gBAAA;AACJ,IAAA,IAAI,cAAc,UAAY,EAAA;AAC1B,MAAmB,gBAAA,GAAA,EAAA;AAAA,KAChB,MAAA;AACH,MAAA,EAAA,CAAG,iBAAkB,CAAA,IAAA,CAAK,YAAa,CAAA,aAAA,EAAe,CAAA;AACtD,MAAmB,gBAAA,GAAA,MAAM,GAAG,KAAM,CAAA,EAAE,QAAQ,IAAK,CAAA,QAAA,EAAU,gBAAgB,CAAA;AAAA;AAE/E,IAAA,MAAM,kBAAqB,GAAA,MAAM,IAAK,CAAA,YAAA,CAAa,gBAAgB,gBAAgB,CAAA;AAEnF,IAAOE,OAAAA,wBAAAA,CAAkB,KAAK,kBAAkB,CAAA;AAAA;AACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,MAAyC,EAAA;AACtD,IAAA,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.cjs","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"]}
|