@layerzerolabs/lz-foundation 3.0.14 → 3.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,26 +1,86 @@
1
+ import { Hex } from '@layerzerolabs/lz-utilities';
2
+ import * as _layerzerolabs_lz_definitions from '@layerzerolabs/lz-definitions';
3
+
4
+ /**
5
+ * Computes the Keccak-256 hash of the given message.
6
+ * introduction: https://wiki.rugdoc.io/docs/introduction-to-ethereums-keccak-256-algorithm/
7
+ *
8
+ * @param {Uint8Array | string} message - The input message to hash.
9
+ * @returns {Uint8Array} The Keccak-256 hash of the input message.
10
+ */
1
11
  declare function keccak_256(message: Uint8Array | string): Uint8Array;
12
+ /**
13
+ * Computes the BLAKE2b hash of the given message.
14
+ * introduction: https://en.wikipedia.org/wiki/BLAKE_(hash_function)
15
+ *
16
+ * @param {Uint8Array | string} message - The input message to hash.
17
+ * @returns {Uint8Array} The BLAKE2b hash of the input message.
18
+ */
2
19
  declare function blake2b(message: Uint8Array | string): Uint8Array;
20
+ /**
21
+ * Computes the SHA3-256 hash of the given message.
22
+ *
23
+ * @param {Uint8Array | string} message - The input message to hash.
24
+ * @returns {Uint8Array} The SHA3-256 hash of the input message.
25
+ */
3
26
  declare function sha3_256(message: Uint8Array | string): Uint8Array;
27
+ /**
28
+ * Computes the SHA-256 hash of the given message.
29
+ *
30
+ * @param {Uint8Array | string} message - The input message to hash.
31
+ * @returns {Uint8Array} The SHA-256 hash of the input message.
32
+ */
4
33
  declare function sha2_256(message: Uint8Array | string): Uint8Array;
5
34
 
35
+ /**
36
+ * Enum representing different signing algorithms.
37
+ */
6
38
  declare enum SignAlgorithm {
39
+ /**
40
+ * Native signing algorithm.
41
+ */
7
42
  NATIVE = 0,
43
+ /**
44
+ * SECP256K1 signing algorithm.
45
+ * introduction: https://en.bitcoin.it/wiki/Secp256k1
46
+ */
8
47
  SECP256K1 = 1,
48
+ /**
49
+ * ED25519 signing algorithm.
50
+ * introduction: https://ed25519.cr.yp.to/
51
+ */
9
52
  ED25519 = 2
10
53
  }
11
54
 
55
+ /**
56
+ * Interface representing a key pair consisting of a private key and a public key.
57
+ */
12
58
  interface KeyPair {
59
+ /**
60
+ * The private key as a Uint8Array.
61
+ */
13
62
  privateKey: Uint8Array;
63
+ /**
64
+ * The public key as a Uint8Array.
65
+ */
14
66
  publicKey: Uint8Array;
15
67
  }
16
68
 
17
69
  /**
18
- * Sign a hash using ed25519
19
- * @param hash - 32 bytes long
20
- * @param privateKey - private key in hex format
21
- * @returns
70
+ * Signs a hash using the ed25519 algorithm.
71
+ *
72
+ * @param {Uint8Array} hash - The hash to sign, must be 32 bytes long.
73
+ * @param {string | Uint8Array | bigint} privateKey - The private key in hex format, Uint8Array, or bigint.
74
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signature.
75
+ * @throws {Error} If the hash is not 32 bytes long or the signature is invalid.
22
76
  */
23
77
  declare function signHash$2(hash: Uint8Array, privateKey: string | Uint8Array | bigint): Promise<Uint8Array>;
78
+ /**
79
+ * Gets the public key corresponding to the given private key using the ed25519 algorithm.
80
+ *
81
+ * @param {string | Uint8Array | bigint} privateKey - The private key in hex format, Uint8Array, or bigint.
82
+ * @returns {Promise<Uint8Array>} A promise that resolves to the public key.
83
+ */
24
84
  declare function getPublicKey$1(privateKey: string | Uint8Array | bigint): Promise<Uint8Array>;
25
85
 
26
86
  declare namespace ed25519 {
@@ -28,12 +88,20 @@ declare namespace ed25519 {
28
88
  }
29
89
 
30
90
  /**
31
- * Sign a hash using secp256k1
32
- * @param hash - 32 bytes long
33
- * @param privateKey - private key in hex format
34
- * @returns
91
+ * Signs a hash using the secp256k1 algorithm.
92
+ *
93
+ * @param {Uint8Array} hash - The hash to sign, must be 32 bytes long.
94
+ * @param {string | Uint8Array | bigint} privateKey - The private key in hex format, Uint8Array, or bigint.
95
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signature.
96
+ * @throws {Error} If the hash is not 32 bytes long or the signature is invalid.
35
97
  */
36
98
  declare function signHash$1(hash: Uint8Array, privateKey: string | Uint8Array | bigint): Promise<Uint8Array>;
99
+ /**
100
+ * Gets the public key corresponding to the given private key using the secp256k1 algorithm.
101
+ *
102
+ * @param {string | Uint8Array | bigint} privateKey - The private key in hex format, Uint8Array, or bigint.
103
+ * @returns {Promise<Uint8Array>} A promise that resolves to the public key.
104
+ */
37
105
  declare function getPublicKey(privateKey: string | Uint8Array | bigint): Promise<Uint8Array>;
38
106
 
39
107
  declare const secp256k1_getPublicKey: typeof getPublicKey;
@@ -41,6 +109,15 @@ declare namespace secp256k1 {
41
109
  export { secp256k1_getPublicKey as getPublicKey, signHash$1 as signHash };
42
110
  }
43
111
 
112
+ /**
113
+ * Signs a hash using the specified signing algorithm.
114
+ *
115
+ * @param {Uint8Array} hash - The hash to sign, must be 32 bytes long.
116
+ * @param {string | Uint8Array} privateKey - The private key in hex format or Uint8Array.
117
+ * @param {SignAlgorithm} algorithm - The signing algorithm to use.
118
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signature.
119
+ * @throws {Error} If the hash is not 32 bytes long or the algorithm is unsupported.
120
+ */
44
121
  declare function signHash(hash: Uint8Array, privateKey: string | Uint8Array, algorithm: SignAlgorithm): Promise<Uint8Array>;
45
122
 
46
123
  /**
@@ -48,28 +125,351 @@ declare function signHash(hash: Uint8Array, privateKey: string | Uint8Array, alg
48
125
  */
49
126
  interface HashSigner {
50
127
  /**
51
- * signHash signs a hash
52
- * @param hash - 32 bytes long
128
+ * Signs a hash.
129
+ * @param {Uint8Array} hash - The hash to sign, must be 32 bytes long.
130
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signature.
53
131
  */
54
132
  signHash(hash: Uint8Array): Promise<Uint8Array>;
55
133
  /**
56
- * publicKey returns the public key of the signer
134
+ * Returns the public key of the signer.
135
+ * @returns {Promise<Uint8Array>} A promise that resolves to the public key.
57
136
  */
58
137
  getPublicKey(): Promise<Uint8Array>;
59
138
  }
139
+ /**
140
+ * Class for signing hashes using the secp256k1 algorithm.
141
+ */
60
142
  declare class Secp256k1Signer implements HashSigner {
61
143
  private readonly privateKey;
62
144
  private constructor();
145
+ /**
146
+ * Creates an instance of Secp256k1Signer from a private key.
147
+ * @param {Uint8Array} privateKey - The private key.
148
+ * @returns {Secp256k1Signer} The created Secp256k1Signer instance.
149
+ */
63
150
  static from(privatekey: Uint8Array): Secp256k1Signer;
151
+ /**
152
+ * Returns the public key of the signer.
153
+ * @returns {Promise<Uint8Array>} A promise that resolves to the public key.
154
+ */
64
155
  getPublicKey(): Promise<Uint8Array>;
156
+ /**
157
+ * Signs a hash.
158
+ * @param {Uint8Array} hash - The hash to sign, must be 32 bytes long.
159
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signature.
160
+ */
65
161
  signHash(hash: Uint8Array): Promise<Uint8Array>;
66
162
  }
163
+ /**
164
+ * Class for signing hashes using the ed25519 algorithm.
165
+ */
67
166
  declare class Ed25519Signer implements HashSigner {
68
167
  private readonly privateKey;
69
168
  private constructor();
169
+ /**
170
+ * Creates an instance of Ed25519Signer from a private key.
171
+ * @param {Uint8Array} privateKey - The private key.
172
+ * @returns {Ed25519Signer} The created Ed25519Signer instance.
173
+ */
70
174
  static from(privateKey: Uint8Array): Ed25519Signer;
175
+ /**
176
+ * Signs a hash.
177
+ * @param {Uint8Array} hash - The hash to sign, must be 32 bytes long.
178
+ * @returns {Promise<Uint8Array>} A promise that resolves to the signature.
179
+ */
71
180
  signHash(hash: Uint8Array): Promise<Uint8Array>;
181
+ /**
182
+ * Returns the public key of the signer.
183
+ * @returns {Promise<Uint8Array>} A promise that resolves to the public key.
184
+ */
72
185
  getPublicKey(): Promise<Uint8Array>;
73
186
  }
74
187
 
75
- export { Ed25519Signer, type HashSigner, type KeyPair, Secp256k1Signer, SignAlgorithm, blake2b, ed25519, keccak_256, secp256k1, sha2_256, sha3_256, signHash };
188
+ /**
189
+ * Encodes a string or Uint8Array to a base58 string.
190
+ *
191
+ * @param {string | Uint8Array} value - The value to encode.
192
+ * @returns {string} The base58 encoded string.
193
+ */
194
+ declare function encode$2(value: string | Uint8Array): string;
195
+ /**
196
+ * Decodes a base58 string to a Uint8Array.
197
+ *
198
+ * @param {string} value - The base58 string to decode.
199
+ * @returns {Uint8Array} The decoded Uint8Array.
200
+ */
201
+ declare function decode$2(value: string): Uint8Array;
202
+
203
+ declare namespace base58 {
204
+ export { decode$2 as decode, encode$2 as encode };
205
+ }
206
+
207
+ /**
208
+ * Encodes a string or Uint8Array to a base58check string.
209
+ *
210
+ * @param {string | Uint8Array} value - The value to encode.
211
+ * @returns {string} The base58check encoded string.
212
+ */
213
+ declare function encode$1(value: string | Uint8Array): string;
214
+ /**
215
+ * Decodes a base58check string to a Uint8Array.
216
+ *
217
+ * @param {string} value - The base58check string to decode.
218
+ * @returns {Uint8Array} The decoded Uint8Array.
219
+ */
220
+ declare function decode$1(value: string): Uint8Array;
221
+
222
+ declare namespace base58check {
223
+ export { decode$1 as decode, encode$1 as encode };
224
+ }
225
+
226
+ /**
227
+ * Encodes a string or Uint8Array to a base64 string.
228
+ *
229
+ * @param {string | Uint8Array} value - The value to encode.
230
+ * @returns {string} The base64 encoded string.
231
+ */
232
+ declare function encode(value: string | Uint8Array): string;
233
+ /**
234
+ * Decodes a base64 string to a Uint8Array.
235
+ *
236
+ * @param {string} value - The base64 string to decode.
237
+ * @returns {Uint8Array} The decoded Uint8Array.
238
+ */
239
+ declare function decode(value: string): Uint8Array;
240
+
241
+ declare const base64_decode: typeof decode;
242
+ declare const base64_encode: typeof encode;
243
+ declare namespace base64 {
244
+ export { base64_decode as decode, base64_encode as encode };
245
+ }
246
+
247
+ interface Address$5 {
248
+ raw(): Uint8Array;
249
+ hr(): string;
250
+ hex(): Hex;
251
+ }
252
+
253
+ declare const Address$4: {
254
+ from: (address: string | Uint8Array, chain: _layerzerolabs_lz_definitions.Chain) => Address$5;
255
+ };
256
+ type Address$4 = Address$5;
257
+
258
+ /**
259
+ * Represents an Aptos address.
260
+ * @see {@link AddressInterface}
261
+ */
262
+ declare class Address$3 implements Address$4 {
263
+ /**
264
+ * The raw address data.
265
+ */
266
+ private data;
267
+ /**
268
+ * Creates an instance of Address.
269
+ * @param {Uint8Array | string} value - The address value.
270
+ * @throws {Error} If the address is invalid.
271
+ */
272
+ constructor(value: Uint8Array | string);
273
+ /**
274
+ * Creates an Address instance from a value.
275
+ * @param {Uint8Array | string} value - The address value.
276
+ * @returns {Address} The Address instance.
277
+ */
278
+ static from(value: Uint8Array | string): Address$3;
279
+ /**
280
+ * Inspects the address.
281
+ * @returns {string} The address as a string.
282
+ */
283
+ inspect(): string;
284
+ /**
285
+ * Converts the address to a string.
286
+ * @returns {string} The address as a string.
287
+ */
288
+ toString(): string;
289
+ /**
290
+ * Gets the raw address data.
291
+ * @returns {Uint8Array} The raw address data.
292
+ */
293
+ raw(): Uint8Array;
294
+ /**
295
+ * Gets the human-readable address.
296
+ * @returns {string} The human-readable address.
297
+ */
298
+ hr(): string;
299
+ /**
300
+ * Gets the address as a hexadecimal string.
301
+ * @returns {Hex} The address as a hexadecimal string.
302
+ */
303
+ hex(): Hex;
304
+ }
305
+
306
+ declare namespace aptos {
307
+ export { Address$3 as Address };
308
+ }
309
+
310
+ /**
311
+ * Represents an EVM address.
312
+ * @see {@link AddressInterface}
313
+ */
314
+ declare class Address$2 implements Address$4 {
315
+ /**
316
+ * The raw address data.
317
+ */
318
+ private data;
319
+ /**
320
+ * Creates an instance of Address.
321
+ * @param {Uint8Array | string} value - The address value.
322
+ * @throws {Error} If the address is invalid.
323
+ */
324
+ constructor(value: Uint8Array | string);
325
+ /**
326
+ * Creates an Address instance from a value.
327
+ * @param {Uint8Array | string} value - The address value.
328
+ * @returns {Address} The Address instance.
329
+ */
330
+ static from(value: Uint8Array | string): Address$2;
331
+ /**
332
+ * Inspects the address.
333
+ * @returns {string} The address as a string.
334
+ */
335
+ inspect(): string;
336
+ /**
337
+ * Converts the address to a string.
338
+ * @returns {string} The address as a string.
339
+ */
340
+ toString(): string;
341
+ /**
342
+ * Gets the raw address data.
343
+ * @returns {Uint8Array} The raw address data.
344
+ */
345
+ raw(): Uint8Array;
346
+ /**
347
+ * Gets the human-readable address.
348
+ * @returns {string} The human-readable address.
349
+ */
350
+ hr(): string;
351
+ /**
352
+ * Gets the address as a hexadecimal string.
353
+ * @returns {Hex} The address as a hexadecimal string.
354
+ */
355
+ hex(): Hex;
356
+ }
357
+ /**
358
+ * Converts an address to its checksum format.
359
+ * @param {string} address - The address to convert.
360
+ * @returns {string} The checksummed address.
361
+ */
362
+ declare function toChecksumAddress(address: string): string;
363
+
364
+ declare const evm_toChecksumAddress: typeof toChecksumAddress;
365
+ declare namespace evm {
366
+ export { Address$2 as Address, evm_toChecksumAddress as toChecksumAddress };
367
+ }
368
+
369
+ /**
370
+ * Represents a Solana address.
371
+ * @see {@link AddressInterface}
372
+ */
373
+ declare class Address$1 implements Address$4 {
374
+ /**
375
+ * The raw address data.
376
+ */
377
+ private data;
378
+ /**
379
+ * Creates an instance of Address.
380
+ * @param {Uint8Array | string} value - The address value.
381
+ * @throws {Error} If the address is invalid.
382
+ */
383
+ constructor(value: Uint8Array | string);
384
+ /**
385
+ * Creates an Address instance from a value.
386
+ * @param {Uint8Array | string} value - The address value.
387
+ * @returns {Address} The Address instance.
388
+ */
389
+ static from(value: Uint8Array | string): Address$1;
390
+ /**
391
+ * Inspects the address.
392
+ * @returns {string} The address as a string.
393
+ */
394
+ inspect(): string;
395
+ /**
396
+ * Converts the address to a string.
397
+ * @returns {string} The address as a string.
398
+ */
399
+ toString(): string;
400
+ /**
401
+ * Gets the raw address data.
402
+ * @returns {Uint8Array} The raw address data.
403
+ */
404
+ raw(): Uint8Array;
405
+ /**
406
+ * Gets the human-readable address.
407
+ * @returns {string} The human-readable address.
408
+ */
409
+ hr(): string;
410
+ /**
411
+ * Gets the address as a hexadecimal string.
412
+ * @returns {Hex} The address as a hexadecimal string.
413
+ */
414
+ hex(): Hex;
415
+ }
416
+
417
+ declare namespace solana {
418
+ export { Address$1 as Address };
419
+ }
420
+
421
+ /**
422
+ * Represents a Tron address.
423
+ * @see {@link AddressInterface}
424
+ */
425
+ declare class Address implements Address$4 {
426
+ /**
427
+ * The raw address data.
428
+ */
429
+ private data;
430
+ /**
431
+ * Creates an instance of Address.
432
+ * @param {Uint8Array | string} value - The address value.
433
+ * @throws {Error} If the address is invalid.
434
+ */
435
+ constructor(value: Uint8Array | string);
436
+ /**
437
+ * Creates an Address instance from a value.
438
+ * @param {Uint8Array | string} value - The address value.
439
+ * @returns {Address} The Address instance.
440
+ */
441
+ static from(value: Uint8Array | string): Address;
442
+ /**
443
+ * Inspects the address.
444
+ * @returns {string} The address as a string.
445
+ */
446
+ inspect(): string;
447
+ /**
448
+ * Converts the address to a string.
449
+ * @returns {string} The address as a string.
450
+ */
451
+ toString(): string;
452
+ /**
453
+ * Gets the raw address data.
454
+ * @returns {Uint8Array} The raw address data.
455
+ */
456
+ raw(): Uint8Array;
457
+ /**
458
+ * Gets the human-readable address.
459
+ * @returns {string} The human-readable address.
460
+ */
461
+ hr(): string;
462
+ /**
463
+ * Gets the address as a hexadecimal string.
464
+ * @returns {Hex} The address as a hexadecimal string.
465
+ */
466
+ hex(): Hex;
467
+ }
468
+
469
+ type tron_Address = Address;
470
+ declare const tron_Address: typeof Address;
471
+ declare namespace tron {
472
+ export { tron_Address as Address };
473
+ }
474
+
475
+ export { Address$4 as Address, Ed25519Signer, type HashSigner, type KeyPair, Secp256k1Signer, SignAlgorithm, aptos, base58, base58check, base64, blake2b, ed25519, evm, keccak_256, secp256k1, sha2_256, sha3_256, signHash, solana, tron };