@layerzerolabs/lz-corekit-sui 3.0.92
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 +10 -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
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @layerzerolabs/lz-corekit-sui
|
|
2
|
+
|
|
3
|
+
The Sui CoreKit is a comprehensive SDK designed to interact with the Sui blockchain. It provides a set of utilities and modules to facilitate the development and integration of applications with the Initia blockchain.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Retrieve Account Information**: Gets the balance of the specified address.
|
|
8
|
+
- **Retrieve Block Information**: Gets the block height, timestamp and related transactions of the specified block.
|
|
9
|
+
- **Transaction Management**: Get, build, sign, send and confirm transactions.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@mysten/sui/client');
|
|
4
|
+
var lzCore = require('@layerzerolabs/lz-core');
|
|
5
|
+
var lzUtilities = require('@layerzerolabs/lz-utilities');
|
|
6
|
+
var ed25519 = require('@mysten/sui/keypairs/ed25519');
|
|
7
|
+
|
|
8
|
+
// src/providers/sui.ts
|
|
9
|
+
var SuiProvider = class _SuiProvider {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of SuiProvider.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} url - The URL of the Sui 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.SuiClient({
|
|
22
|
+
transport: new client.SuiHTTPTransport({
|
|
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 SuiProvider from the given parameters.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} source - The URL of the Sui node.
|
|
37
|
+
* @param authHeader
|
|
38
|
+
* @returns {SuiProvider} The created SuiProvider 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 _SuiProvider(source, authHeader);
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error("Invalid parameters");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the native Sui client instance.
|
|
50
|
+
*
|
|
51
|
+
* @returns {SuiClient} The native Sui 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 Sui address.
|
|
62
|
+
*/
|
|
63
|
+
async getBalance(address) {
|
|
64
|
+
if (!lzUtilities.isHex(address)) {
|
|
65
|
+
throw new Error("Invalid Sui 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 Sui.
|
|
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 Sui 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 Sui 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 SuiSigner = class {
|
|
231
|
+
/**
|
|
232
|
+
* Creates an instance of SuiSigner.
|
|
233
|
+
*
|
|
234
|
+
* @param {Ed25519Keypair} signer - The Sui account to use as the signer.
|
|
235
|
+
*/
|
|
236
|
+
constructor(signer) {
|
|
237
|
+
this.nativeSigner = signer;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Creates an instance of SuiSigner 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 Sui account.
|
|
243
|
+
* @param {string} [path] - The derivation path (optional). e.g. m/44'/784'/0'/0'/0' If provided, the source is treated as a mnemonics.
|
|
244
|
+
* @returns {SuiSigner} The created SuiSigner 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 Sui signer instance.
|
|
262
|
+
*
|
|
263
|
+
* @returns {Ed25519Keypair} The native Sui 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 SuiProvider.
|
|
274
|
+
*/
|
|
275
|
+
connect(provider) {
|
|
276
|
+
if (!(provider instanceof SuiProvider)) {
|
|
277
|
+
throw new Error("Only SuiProvider 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().toSuiAddress());
|
|
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().toSuiAddress();
|
|
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 SuiSigner.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.toSuiAddress());
|
|
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 Sui 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.SuiProvider = SuiProvider;
|
|
362
|
+
exports.SuiSigner = SuiSigner;
|
|
363
|
+
//# sourceMappingURL=index.cjs.map
|
|
364
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/providers/sui.ts","../src/signers/sui.ts"],"names":["SuiClient","SuiHTTPTransport","isHex","blockNumber","Block","BlockWithTransactions","TransactionResponse","TransactionReceipt","TransactionPending","Ed25519Keypair","trim0x","SignedTransaction"],"mappings":";;;;;;;;AAoBa,IAAA,WAAA,GAAN,MAAM,YAAgC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWjC,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,IAAIA,gBAAU,CAAA;AAAA,MAChC,SAAA,EAAW,IAAIC,uBAAiB,CAAA;AAAA,QAC5B,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,UAAoE,EAAA;AAC5F,IAAI,IAAA,OAAO,WAAW,QAAU,EAAA;AAC5B,MAAO,OAAA,IAAI,YAAY,CAAA,MAAA,EAAQ,UAAU,CAAA;AAAA,KACtC,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,CAACC,iBAAM,CAAA,OAAO,CAAG,EAAA;AACjB,MAAM,M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,QAAA,CAAS,eAAgB,CAAA,WAAA,EAAa,WAAW,CAAA;AAAA;AACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,gBAAgB,WAA6D,EAAA;AAC/E,IAAM,MAAA,cAAA,GAAiB,KAAK,QAAU,EAAA,MAAA;AACtC,IAAA,IAAI,mBAAmB,KAAW,CAAA,EAAA;AAC9B,MAAM,MAAA,IAAI,MAAM,4DAA4D,CAAA;AAAA;AAEhF,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,YAAA,EAAc,CAAA;AACrD,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, SuiClient, SuiHTTPTransport, SuiTransactionBlockResponse } from '@mysten/sui/client'\nimport { SignatureWithBytes } from '@mysten/sui/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 Sui blockchain provider.\n * Implements the Provider interface for interacting with the Sui blockchain.\n */\nexport class SuiProvider implements Provider {\n readonly nativeProvider: SuiClient\n\n /**\n * Creates an instance of SuiProvider.\n *\n * @param {string} url - The URL of the Sui 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 SuiClient({\n transport: new SuiHTTPTransport({\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 SuiProvider from the given parameters.\n *\n * @param {string} source - The URL of the Sui node.\n * @param authHeader\n * @returns {SuiProvider} The created SuiProvider instance.\n * @throws {Error} If the source parameter is not a string.\n */\n static from(source: string, authHeader?: { authField: string; authValue: string }): SuiProvider {\n if (typeof source === 'string') {\n return new SuiProvider(source, authHeader)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n /**\n * Gets the native Sui client instance.\n *\n * @returns {SuiClient} The native Sui client instance.\n */\n get native(): SuiClient {\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 Sui address.\n */\n async getBalance(address: string): Promise<string> {\n if (!isHex(address)) {\n throw new Error('Invalid Sui 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 Sui.\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 Sui 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 Sui 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: SuiTransactionBlockResponse\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 '@mysten/sui/keypairs/ed25519'\nimport { Transaction } from '@mysten/sui/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 { SuiProvider } from '../providers'\n\n/**\n * Represents an Sui blockchain signer.\n * Implements the Signer interface for interacting with the Sui blockchain.\n */\nexport class SuiSigner implements Signer {\n public nativeSigner: Ed25519Keypair\n public provider: SuiProvider | undefined\n\n /**\n * Creates an instance of SuiSigner.\n *\n * @param {Ed25519Keypair} signer - The Sui account to use as the signer.\n */\n private constructor(signer: Ed25519Keypair) {\n this.nativeSigner = signer\n }\n\n /**\n * Creates an instance of SuiSigner 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 Sui account.\n * @param {string} [path] - The derivation path (optional). e.g. m/44'/784'/0'/0'/0' If provided, the source is treated as a mnemonics.\n * @returns {SuiSigner} The created SuiSigner instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | Ed25519Keypair, path?: string): SuiSigner {\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 Sui signer instance.\n *\n * @returns {Ed25519Keypair} The native Sui 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 SuiProvider.\n */\n connect(provider: Provider): this {\n if (!(provider instanceof SuiProvider)) {\n throw new Error('Only SuiProvider 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().toSuiAddress())\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().toSuiAddress()\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 SuiSigner.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.toSuiAddress())\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 Sui 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/dist/index.d.mts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
2
|
+
import { Provider, Block, BlockWithTransactions, Finality, TransactionResponse, TransactionReceipt, BlockTag, SignedTransaction, TransactionPending, Signer, TransactionRequest } from '@layerzerolabs/lz-core';
|
|
3
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents an Sui blockchain provider.
|
|
7
|
+
* Implements the Provider interface for interacting with the Sui blockchain.
|
|
8
|
+
*/
|
|
9
|
+
declare class SuiProvider implements Provider {
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly authHeader?: {
|
|
12
|
+
authField: string;
|
|
13
|
+
authValue: string;
|
|
14
|
+
} | undefined;
|
|
15
|
+
readonly nativeProvider: SuiClient;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of SuiProvider.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} url - The URL of the Sui node.
|
|
20
|
+
* @param {string} [faucet] - The URL of the faucet (optional).
|
|
21
|
+
* @param {string} [indexer] - The URL of the indexer (optional).
|
|
22
|
+
* @param authHeader
|
|
23
|
+
*/
|
|
24
|
+
private constructor();
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of SuiProvider from the given parameters.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} source - The URL of the Sui node.
|
|
29
|
+
* @param authHeader
|
|
30
|
+
* @returns {SuiProvider} The created SuiProvider instance.
|
|
31
|
+
* @throws {Error} If the source parameter is not a string.
|
|
32
|
+
*/
|
|
33
|
+
static from(source: string, authHeader?: {
|
|
34
|
+
authField: string;
|
|
35
|
+
authValue: string;
|
|
36
|
+
}): SuiProvider;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the native Sui client instance.
|
|
39
|
+
*
|
|
40
|
+
* @returns {SuiClient} The native Sui client instance.
|
|
41
|
+
*/
|
|
42
|
+
get native(): SuiClient;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the balance of the specified address.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} address - The address to get the balance of.
|
|
47
|
+
* @returns {Promise<string>} A promise that resolves to the balance of the address.
|
|
48
|
+
* @throws {Error} If the address is not a valid Sui address.
|
|
49
|
+
*/
|
|
50
|
+
getBalance(address: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the block specified by blockTag.
|
|
53
|
+
*
|
|
54
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
55
|
+
* @returns {Promise<Block>} A promise that resolves to the block.
|
|
56
|
+
* @throws {Error} If the blockTag is invalid.
|
|
57
|
+
*/
|
|
58
|
+
getBlock(blockTag: string | number): Promise<Block>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the block with transactions specified by blockTag.
|
|
61
|
+
*
|
|
62
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
63
|
+
* @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
|
|
64
|
+
* @throws {Error} If the blockTag is invalid.
|
|
65
|
+
*/
|
|
66
|
+
getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions>;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the current block number.
|
|
69
|
+
*
|
|
70
|
+
* @returns {Promise<number>} A promise that resolves to the current check point.
|
|
71
|
+
*/
|
|
72
|
+
getBlockNumber(): Promise<number>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the current slot number for commitment, not suitable for Sui.
|
|
75
|
+
*
|
|
76
|
+
* @param {Finality} [commitment] - The commitment level (optional).
|
|
77
|
+
* @returns {Promise<number>} A promise that resolves to the current slot number.
|
|
78
|
+
* @throws {Error} Method not implemented.
|
|
79
|
+
*/
|
|
80
|
+
getSlot(_finality?: Finality): Promise<number>;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.
|
|
83
|
+
*
|
|
84
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
85
|
+
* @returns {Promise<number>} A promise that resolves to the timestamp of the block.
|
|
86
|
+
* @throws {Error} If the blockTag is invalid.
|
|
87
|
+
*/
|
|
88
|
+
getBlockTimestamp(blockTag: string | number): Promise<number>;
|
|
89
|
+
/**
|
|
90
|
+
* Gets information about a transaction.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} txHash - The hash of the transaction.
|
|
93
|
+
* @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
|
|
94
|
+
* @throws {Error} If the transaction hash is invalid.
|
|
95
|
+
*/
|
|
96
|
+
getTransaction(txHash: string): Promise<TransactionResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* Gets the receipt of a transaction.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} txHash - The hash of the transaction.
|
|
101
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
102
|
+
* @throws {Error} If the transaction hash is invalid.
|
|
103
|
+
*/
|
|
104
|
+
getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the number of transactions sent from the specified address.
|
|
107
|
+
*
|
|
108
|
+
* @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.
|
|
109
|
+
* @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).
|
|
110
|
+
* @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
|
|
111
|
+
* @throws {Error} If the address is invalid.
|
|
112
|
+
*/
|
|
113
|
+
getTransactionCount(addressOrName: string | Promise<string>, _blockTag?: BlockTag | Promise<BlockTag>): Promise<number>;
|
|
114
|
+
/**
|
|
115
|
+
* Sends a signed transaction to the blockchain.
|
|
116
|
+
*
|
|
117
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
118
|
+
* @param {object} [sendOptions] - Optional parameters for sending the transaction.
|
|
119
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
120
|
+
*/
|
|
121
|
+
sendTransaction(transaction: SignedTransaction, _sendOptions?: object): Promise<TransactionPending>;
|
|
122
|
+
/**
|
|
123
|
+
* Confirms a pending transaction.
|
|
124
|
+
*
|
|
125
|
+
* @param {TransactionPending} pending - The pending transaction to confirm.
|
|
126
|
+
* @param {object} [opts] - Optional parameters for the confirmation.
|
|
127
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
128
|
+
* @throws {Error} If the transaction fails.
|
|
129
|
+
*/
|
|
130
|
+
confirmTransaction(pending: TransactionPending, opts?: object): Promise<TransactionReceipt>;
|
|
131
|
+
/**
|
|
132
|
+
* Sends a signed transaction and waits for confirmation.
|
|
133
|
+
*
|
|
134
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
135
|
+
* @param {object} [opts] - Optional parameters for sending and confirming the transaction.
|
|
136
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
137
|
+
*/
|
|
138
|
+
sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Represents an Sui blockchain signer.
|
|
143
|
+
* Implements the Signer interface for interacting with the Sui blockchain.
|
|
144
|
+
*/
|
|
145
|
+
declare class SuiSigner implements Signer {
|
|
146
|
+
nativeSigner: Ed25519Keypair;
|
|
147
|
+
provider: SuiProvider | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Creates an instance of SuiSigner.
|
|
150
|
+
*
|
|
151
|
+
* @param {Ed25519Keypair} signer - The Sui account to use as the signer.
|
|
152
|
+
*/
|
|
153
|
+
private constructor();
|
|
154
|
+
/**
|
|
155
|
+
* Creates an instance of SuiSigner from the given parameters.
|
|
156
|
+
*
|
|
157
|
+
* @param {string | Ed25519Keypair} source - The source to create the signer from, could be a private key, a mnemonics or an Sui account.
|
|
158
|
+
* @param {string} [path] - The derivation path (optional). e.g. m/44'/784'/0'/0'/0' If provided, the source is treated as a mnemonics.
|
|
159
|
+
* @returns {SuiSigner} The created SuiSigner instance.
|
|
160
|
+
* @throws {Error} If the parameters are invalid.
|
|
161
|
+
*/
|
|
162
|
+
static from(source: string | Ed25519Keypair, path?: string): SuiSigner;
|
|
163
|
+
/**
|
|
164
|
+
* Gets the native Sui signer instance.
|
|
165
|
+
*
|
|
166
|
+
* @returns {Ed25519Keypair} The native Sui signer instance.
|
|
167
|
+
*/
|
|
168
|
+
get native(): Ed25519Keypair;
|
|
169
|
+
/**
|
|
170
|
+
* Connects the signer to a provider.
|
|
171
|
+
*
|
|
172
|
+
* @param {Provider} provider - The provider to connect to.
|
|
173
|
+
* @returns {this} The connected signer.
|
|
174
|
+
* @throws {Error} If the provider is not an instance of SuiProvider.
|
|
175
|
+
*/
|
|
176
|
+
connect(provider: Provider): this;
|
|
177
|
+
/**
|
|
178
|
+
* Gets the address of the signer.
|
|
179
|
+
*
|
|
180
|
+
* @returns {Promise<string>} A promise that resolves to the address of the signer.
|
|
181
|
+
*/
|
|
182
|
+
getAddress(): Promise<string>;
|
|
183
|
+
/**
|
|
184
|
+
* Gets the address of the signer.
|
|
185
|
+
*
|
|
186
|
+
* @returns {string} The address of the signer.
|
|
187
|
+
*/
|
|
188
|
+
get address(): string;
|
|
189
|
+
/**
|
|
190
|
+
* Sends a signed transaction and waits for confirmation.
|
|
191
|
+
*
|
|
192
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
193
|
+
* @param {object} [opts] - Optional parameters for sending and confirming the transaction.
|
|
194
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
195
|
+
* @throws {Error} If the provider is not connected.
|
|
196
|
+
*/
|
|
197
|
+
sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt>;
|
|
198
|
+
/**
|
|
199
|
+
* Sends a signed transaction.
|
|
200
|
+
*
|
|
201
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
202
|
+
* @param {object} [sendOptions] - Optional parameters for sending the transaction.
|
|
203
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
204
|
+
* @throws {Error} If the provider is not connected.
|
|
205
|
+
*/
|
|
206
|
+
sendTransaction(transaction: SignedTransaction, sendOptions?: object): Promise<TransactionPending>;
|
|
207
|
+
/**
|
|
208
|
+
* Signs a transaction.
|
|
209
|
+
*
|
|
210
|
+
* @param {TransactionRequest} transaction - The transaction request to sign.
|
|
211
|
+
* @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
|
|
212
|
+
* @throws {Error} If the native provider is not connected.
|
|
213
|
+
*/
|
|
214
|
+
signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>;
|
|
215
|
+
/**
|
|
216
|
+
* Signs a buffer (e.g., a message hash) using the native Sui signer.
|
|
217
|
+
*
|
|
218
|
+
* @param {Uint8Array} buffer - The buffer to sign.
|
|
219
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
|
|
220
|
+
*/
|
|
221
|
+
signBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { SuiProvider, SuiSigner };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
2
|
+
import { Provider, Block, BlockWithTransactions, Finality, TransactionResponse, TransactionReceipt, BlockTag, SignedTransaction, TransactionPending, Signer, TransactionRequest } from '@layerzerolabs/lz-core';
|
|
3
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents an Sui blockchain provider.
|
|
7
|
+
* Implements the Provider interface for interacting with the Sui blockchain.
|
|
8
|
+
*/
|
|
9
|
+
declare class SuiProvider implements Provider {
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly authHeader?: {
|
|
12
|
+
authField: string;
|
|
13
|
+
authValue: string;
|
|
14
|
+
} | undefined;
|
|
15
|
+
readonly nativeProvider: SuiClient;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of SuiProvider.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} url - The URL of the Sui node.
|
|
20
|
+
* @param {string} [faucet] - The URL of the faucet (optional).
|
|
21
|
+
* @param {string} [indexer] - The URL of the indexer (optional).
|
|
22
|
+
* @param authHeader
|
|
23
|
+
*/
|
|
24
|
+
private constructor();
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of SuiProvider from the given parameters.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} source - The URL of the Sui node.
|
|
29
|
+
* @param authHeader
|
|
30
|
+
* @returns {SuiProvider} The created SuiProvider instance.
|
|
31
|
+
* @throws {Error} If the source parameter is not a string.
|
|
32
|
+
*/
|
|
33
|
+
static from(source: string, authHeader?: {
|
|
34
|
+
authField: string;
|
|
35
|
+
authValue: string;
|
|
36
|
+
}): SuiProvider;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the native Sui client instance.
|
|
39
|
+
*
|
|
40
|
+
* @returns {SuiClient} The native Sui client instance.
|
|
41
|
+
*/
|
|
42
|
+
get native(): SuiClient;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the balance of the specified address.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} address - The address to get the balance of.
|
|
47
|
+
* @returns {Promise<string>} A promise that resolves to the balance of the address.
|
|
48
|
+
* @throws {Error} If the address is not a valid Sui address.
|
|
49
|
+
*/
|
|
50
|
+
getBalance(address: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the block specified by blockTag.
|
|
53
|
+
*
|
|
54
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
55
|
+
* @returns {Promise<Block>} A promise that resolves to the block.
|
|
56
|
+
* @throws {Error} If the blockTag is invalid.
|
|
57
|
+
*/
|
|
58
|
+
getBlock(blockTag: string | number): Promise<Block>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the block with transactions specified by blockTag.
|
|
61
|
+
*
|
|
62
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
63
|
+
* @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
|
|
64
|
+
* @throws {Error} If the blockTag is invalid.
|
|
65
|
+
*/
|
|
66
|
+
getBlockWithTransactions(blockTag: string | number): Promise<BlockWithTransactions>;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the current block number.
|
|
69
|
+
*
|
|
70
|
+
* @returns {Promise<number>} A promise that resolves to the current check point.
|
|
71
|
+
*/
|
|
72
|
+
getBlockNumber(): Promise<number>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the current slot number for commitment, not suitable for Sui.
|
|
75
|
+
*
|
|
76
|
+
* @param {Finality} [commitment] - The commitment level (optional).
|
|
77
|
+
* @returns {Promise<number>} A promise that resolves to the current slot number.
|
|
78
|
+
* @throws {Error} Method not implemented.
|
|
79
|
+
*/
|
|
80
|
+
getSlot(_finality?: Finality): Promise<number>;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the timestamp (A string containing a 64-bit unsigned integer) for the block identified by blockTag.
|
|
83
|
+
*
|
|
84
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
85
|
+
* @returns {Promise<number>} A promise that resolves to the timestamp of the block.
|
|
86
|
+
* @throws {Error} If the blockTag is invalid.
|
|
87
|
+
*/
|
|
88
|
+
getBlockTimestamp(blockTag: string | number): Promise<number>;
|
|
89
|
+
/**
|
|
90
|
+
* Gets information about a transaction.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} txHash - The hash of the transaction.
|
|
93
|
+
* @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response.
|
|
94
|
+
* @throws {Error} If the transaction hash is invalid.
|
|
95
|
+
*/
|
|
96
|
+
getTransaction(txHash: string): Promise<TransactionResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* Gets the receipt of a transaction.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} txHash - The hash of the transaction.
|
|
101
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
102
|
+
* @throws {Error} If the transaction hash is invalid.
|
|
103
|
+
*/
|
|
104
|
+
getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the number of transactions sent from the specified address.
|
|
107
|
+
*
|
|
108
|
+
* @param {string | Promise<string>} addressOrName - The address to get the number of transactions from.
|
|
109
|
+
* @param {BlockTag | Promise<BlockTag>} [blockTag] - The block tag to get the number of transactions from (optional).
|
|
110
|
+
* @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
|
|
111
|
+
* @throws {Error} If the address is invalid.
|
|
112
|
+
*/
|
|
113
|
+
getTransactionCount(addressOrName: string | Promise<string>, _blockTag?: BlockTag | Promise<BlockTag>): Promise<number>;
|
|
114
|
+
/**
|
|
115
|
+
* Sends a signed transaction to the blockchain.
|
|
116
|
+
*
|
|
117
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
118
|
+
* @param {object} [sendOptions] - Optional parameters for sending the transaction.
|
|
119
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
120
|
+
*/
|
|
121
|
+
sendTransaction(transaction: SignedTransaction, _sendOptions?: object): Promise<TransactionPending>;
|
|
122
|
+
/**
|
|
123
|
+
* Confirms a pending transaction.
|
|
124
|
+
*
|
|
125
|
+
* @param {TransactionPending} pending - The pending transaction to confirm.
|
|
126
|
+
* @param {object} [opts] - Optional parameters for the confirmation.
|
|
127
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
128
|
+
* @throws {Error} If the transaction fails.
|
|
129
|
+
*/
|
|
130
|
+
confirmTransaction(pending: TransactionPending, opts?: object): Promise<TransactionReceipt>;
|
|
131
|
+
/**
|
|
132
|
+
* Sends a signed transaction and waits for confirmation.
|
|
133
|
+
*
|
|
134
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
135
|
+
* @param {object} [opts] - Optional parameters for sending and confirming the transaction.
|
|
136
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
137
|
+
*/
|
|
138
|
+
sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Represents an Sui blockchain signer.
|
|
143
|
+
* Implements the Signer interface for interacting with the Sui blockchain.
|
|
144
|
+
*/
|
|
145
|
+
declare class SuiSigner implements Signer {
|
|
146
|
+
nativeSigner: Ed25519Keypair;
|
|
147
|
+
provider: SuiProvider | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Creates an instance of SuiSigner.
|
|
150
|
+
*
|
|
151
|
+
* @param {Ed25519Keypair} signer - The Sui account to use as the signer.
|
|
152
|
+
*/
|
|
153
|
+
private constructor();
|
|
154
|
+
/**
|
|
155
|
+
* Creates an instance of SuiSigner from the given parameters.
|
|
156
|
+
*
|
|
157
|
+
* @param {string | Ed25519Keypair} source - The source to create the signer from, could be a private key, a mnemonics or an Sui account.
|
|
158
|
+
* @param {string} [path] - The derivation path (optional). e.g. m/44'/784'/0'/0'/0' If provided, the source is treated as a mnemonics.
|
|
159
|
+
* @returns {SuiSigner} The created SuiSigner instance.
|
|
160
|
+
* @throws {Error} If the parameters are invalid.
|
|
161
|
+
*/
|
|
162
|
+
static from(source: string | Ed25519Keypair, path?: string): SuiSigner;
|
|
163
|
+
/**
|
|
164
|
+
* Gets the native Sui signer instance.
|
|
165
|
+
*
|
|
166
|
+
* @returns {Ed25519Keypair} The native Sui signer instance.
|
|
167
|
+
*/
|
|
168
|
+
get native(): Ed25519Keypair;
|
|
169
|
+
/**
|
|
170
|
+
* Connects the signer to a provider.
|
|
171
|
+
*
|
|
172
|
+
* @param {Provider} provider - The provider to connect to.
|
|
173
|
+
* @returns {this} The connected signer.
|
|
174
|
+
* @throws {Error} If the provider is not an instance of SuiProvider.
|
|
175
|
+
*/
|
|
176
|
+
connect(provider: Provider): this;
|
|
177
|
+
/**
|
|
178
|
+
* Gets the address of the signer.
|
|
179
|
+
*
|
|
180
|
+
* @returns {Promise<string>} A promise that resolves to the address of the signer.
|
|
181
|
+
*/
|
|
182
|
+
getAddress(): Promise<string>;
|
|
183
|
+
/**
|
|
184
|
+
* Gets the address of the signer.
|
|
185
|
+
*
|
|
186
|
+
* @returns {string} The address of the signer.
|
|
187
|
+
*/
|
|
188
|
+
get address(): string;
|
|
189
|
+
/**
|
|
190
|
+
* Sends a signed transaction and waits for confirmation.
|
|
191
|
+
*
|
|
192
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
193
|
+
* @param {object} [opts] - Optional parameters for sending and confirming the transaction.
|
|
194
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
195
|
+
* @throws {Error} If the provider is not connected.
|
|
196
|
+
*/
|
|
197
|
+
sendAndConfirm(transaction: SignedTransaction, opts?: object): Promise<TransactionReceipt>;
|
|
198
|
+
/**
|
|
199
|
+
* Sends a signed transaction.
|
|
200
|
+
*
|
|
201
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
202
|
+
* @param {object} [sendOptions] - Optional parameters for sending the transaction.
|
|
203
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
204
|
+
* @throws {Error} If the provider is not connected.
|
|
205
|
+
*/
|
|
206
|
+
sendTransaction(transaction: SignedTransaction, sendOptions?: object): Promise<TransactionPending>;
|
|
207
|
+
/**
|
|
208
|
+
* Signs a transaction.
|
|
209
|
+
*
|
|
210
|
+
* @param {TransactionRequest} transaction - The transaction request to sign.
|
|
211
|
+
* @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
|
|
212
|
+
* @throws {Error} If the native provider is not connected.
|
|
213
|
+
*/
|
|
214
|
+
signTransaction(transaction: TransactionRequest): Promise<SignedTransaction>;
|
|
215
|
+
/**
|
|
216
|
+
* Signs a buffer (e.g., a message hash) using the native Sui signer.
|
|
217
|
+
*
|
|
218
|
+
* @param {Uint8Array} buffer - The buffer to sign.
|
|
219
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
|
|
220
|
+
*/
|
|
221
|
+
signBuffer(buffer: Uint8Array): Promise<Uint8Array>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { SuiProvider, SuiSigner };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { SuiClient, SuiHTTPTransport } from '@mysten/sui/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 '@mysten/sui/keypairs/ed25519';
|
|
5
|
+
|
|
6
|
+
// src/providers/sui.ts
|
|
7
|
+
var SuiProvider = class _SuiProvider {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of SuiProvider.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} url - The URL of the Sui 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 SuiClient({
|
|
20
|
+
transport: new SuiHTTPTransport({
|
|
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 SuiProvider from the given parameters.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} source - The URL of the Sui node.
|
|
35
|
+
* @param authHeader
|
|
36
|
+
* @returns {SuiProvider} The created SuiProvider 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 _SuiProvider(source, authHeader);
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error("Invalid parameters");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the native Sui client instance.
|
|
48
|
+
*
|
|
49
|
+
* @returns {SuiClient} The native Sui 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 Sui address.
|
|
60
|
+
*/
|
|
61
|
+
async getBalance(address) {
|
|
62
|
+
if (!isHex(address)) {
|
|
63
|
+
throw new Error("Invalid Sui 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 Sui.
|
|
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 Sui 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 Sui 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 SuiSigner = class {
|
|
229
|
+
/**
|
|
230
|
+
* Creates an instance of SuiSigner.
|
|
231
|
+
*
|
|
232
|
+
* @param {Ed25519Keypair} signer - The Sui account to use as the signer.
|
|
233
|
+
*/
|
|
234
|
+
constructor(signer) {
|
|
235
|
+
this.nativeSigner = signer;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Creates an instance of SuiSigner 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 Sui account.
|
|
241
|
+
* @param {string} [path] - The derivation path (optional). e.g. m/44'/784'/0'/0'/0' If provided, the source is treated as a mnemonics.
|
|
242
|
+
* @returns {SuiSigner} The created SuiSigner 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 Sui signer instance.
|
|
260
|
+
*
|
|
261
|
+
* @returns {Ed25519Keypair} The native Sui 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 SuiProvider.
|
|
272
|
+
*/
|
|
273
|
+
connect(provider) {
|
|
274
|
+
if (!(provider instanceof SuiProvider)) {
|
|
275
|
+
throw new Error("Only SuiProvider 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().toSuiAddress());
|
|
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().toSuiAddress();
|
|
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 SuiSigner.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.toSuiAddress());
|
|
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 Sui 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 { SuiProvider, SuiSigner };
|
|
360
|
+
//# sourceMappingURL=index.mjs.map
|
|
361
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/providers/sui.ts","../src/signers/sui.ts"],"names":["blockNumber","SignedTransaction"],"mappings":";;;;;;AAoBa,IAAA,WAAA,GAAN,MAAM,YAAgC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWjC,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,SAAU,CAAA;AAAA,MAChC,SAAA,EAAW,IAAI,gBAAiB,CAAA;AAAA,QAC5B,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,UAAoE,EAAA;AAC5F,IAAI,IAAA,OAAO,WAAW,QAAU,EAAA;AAC5B,MAAO,OAAA,IAAI,YAAY,CAA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,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, SuiClient, SuiHTTPTransport, SuiTransactionBlockResponse } from '@mysten/sui/client'\nimport { SignatureWithBytes } from '@mysten/sui/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 Sui blockchain provider.\n * Implements the Provider interface for interacting with the Sui blockchain.\n */\nexport class SuiProvider implements Provider {\n readonly nativeProvider: SuiClient\n\n /**\n * Creates an instance of SuiProvider.\n *\n * @param {string} url - The URL of the Sui 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 SuiClient({\n transport: new SuiHTTPTransport({\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 SuiProvider from the given parameters.\n *\n * @param {string} source - The URL of the Sui node.\n * @param authHeader\n * @returns {SuiProvider} The created SuiProvider instance.\n * @throws {Error} If the source parameter is not a string.\n */\n static from(source: string, authHeader?: { authField: string; authValue: string }): SuiProvider {\n if (typeof source === 'string') {\n return new SuiProvider(source, authHeader)\n } else {\n throw new Error('Invalid parameters')\n }\n }\n\n /**\n * Gets the native Sui client instance.\n *\n * @returns {SuiClient} The native Sui client instance.\n */\n get native(): SuiClient {\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 Sui address.\n */\n async getBalance(address: string): Promise<string> {\n if (!isHex(address)) {\n throw new Error('Invalid Sui 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 Sui.\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 Sui 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 Sui 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: SuiTransactionBlockResponse\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 '@mysten/sui/keypairs/ed25519'\nimport { Transaction } from '@mysten/sui/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 { SuiProvider } from '../providers'\n\n/**\n * Represents an Sui blockchain signer.\n * Implements the Signer interface for interacting with the Sui blockchain.\n */\nexport class SuiSigner implements Signer {\n public nativeSigner: Ed25519Keypair\n public provider: SuiProvider | undefined\n\n /**\n * Creates an instance of SuiSigner.\n *\n * @param {Ed25519Keypair} signer - The Sui account to use as the signer.\n */\n private constructor(signer: Ed25519Keypair) {\n this.nativeSigner = signer\n }\n\n /**\n * Creates an instance of SuiSigner 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 Sui account.\n * @param {string} [path] - The derivation path (optional). e.g. m/44'/784'/0'/0'/0' If provided, the source is treated as a mnemonics.\n * @returns {SuiSigner} The created SuiSigner instance.\n * @throws {Error} If the parameters are invalid.\n */\n static from(source: string | Ed25519Keypair, path?: string): SuiSigner {\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 Sui signer instance.\n *\n * @returns {Ed25519Keypair} The native Sui 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 SuiProvider.\n */\n connect(provider: Provider): this {\n if (!(provider instanceof SuiProvider)) {\n throw new Error('Only SuiProvider 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().toSuiAddress())\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().toSuiAddress()\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 SuiSigner.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.toSuiAddress())\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 Sui 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-sui",
|
|
3
|
+
"version": "3.0.92",
|
|
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
|
+
"@layerzerolabs/lz-core": "^3.0.107",
|
|
27
|
+
"@layerzerolabs/lz-utilities": "^3.0.107",
|
|
28
|
+
"@mysten/sui": "^1.33.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@jest/globals": "^29.7.0",
|
|
32
|
+
"@layerzerolabs/tsup-config-next": "^3.0.107",
|
|
33
|
+
"@layerzerolabs/typescript-config-next": "^3.0.107",
|
|
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": "restricted"
|
|
44
|
+
}
|
|
45
|
+
}
|