@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/CHANGELOG.md +18 -0
- package/README.md +106 -2
- package/dist/index.cjs +427 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +412 -12
- package/dist/index.d.ts +412 -12
- package/dist/index.mjs +421 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @layerzerolabs/lz-foundation
|
|
2
2
|
|
|
3
|
+
## 3.0.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 87a4bc9: islander mainnet
|
|
8
|
+
- Updated dependencies [87a4bc9]
|
|
9
|
+
- @layerzerolabs/lz-definitions@3.0.16
|
|
10
|
+
- @layerzerolabs/lz-utilities@3.0.16
|
|
11
|
+
|
|
12
|
+
## 3.0.15
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 67856bd: endpoints
|
|
17
|
+
- Updated dependencies [67856bd]
|
|
18
|
+
- @layerzerolabs/lz-definitions@3.0.15
|
|
19
|
+
- @layerzerolabs/lz-utilities@3.0.15
|
|
20
|
+
|
|
3
21
|
## 3.0.14
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @layerzerolabs/lz-foundation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The LayerZero Foundation package provides essential functions and interfaces for chain interoperability. It includes utilities for signing, hashing, and managing key pairs.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Address Utilities**: Functions for manipulating addresses of different chains.
|
|
8
|
+
- **Base Utilities**: General-purpose utility functions.
|
|
9
|
+
- **Signing**: Sign messages and transactions using different algorithms.
|
|
10
|
+
- **Hashing**: Compute various cryptographic hashes.
|
|
11
|
+
- **Key Management**: Generate and manage key pairs.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
To install the LayerZero Foundation package, you can use npm or yarn:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @layerzerolabs/lz-foundation
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
or
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
yarn add @layerzerolabs/lz-foundation
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Address Utilities
|
|
30
|
+
|
|
31
|
+
Gets the human-readable address.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { aptos } from "@layerzerolabs/lz-foundation"
|
|
35
|
+
|
|
36
|
+
const address = "0x1234567890abcdef1234567890abcdef12345678"
|
|
37
|
+
const addr = aptos.Address.from(address)
|
|
38
|
+
const hr = addr.hr()
|
|
39
|
+
console.log(`human-readable address: ${hr}`)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Base Utilities
|
|
43
|
+
|
|
44
|
+
Encodes a string or Uint8Array to a base58 string.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { base58 } from "@layerzerolabs/lz-foundation"
|
|
48
|
+
|
|
49
|
+
const msg = "hello"
|
|
50
|
+
const encode = base58.encode(msg)
|
|
51
|
+
console.log(`base58 encoded message: ${encode}`)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Hashing
|
|
55
|
+
|
|
56
|
+
Computes the Keccak-256 hash of the given message.
|
|
57
|
+
|
|
58
|
+
- message: The input message to hash.
|
|
59
|
+
- Returns: The Keccak-256 hash of the input message.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { keccak_256 } from "@layerzerolabs/lz-foundation"
|
|
63
|
+
|
|
64
|
+
const message = "Hello, world!"
|
|
65
|
+
const hash = keccak_256(message)
|
|
66
|
+
console.log(`Keccak-256 Hash: ${Buffer.from(hash).toString("hex")}`)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Signing
|
|
70
|
+
|
|
71
|
+
Signs a hash using the specified signing algorithm.
|
|
72
|
+
|
|
73
|
+
- hash: The hash to sign, must be 32 bytes long.
|
|
74
|
+
- privateKey: The private key in hex format or Uint8Array.
|
|
75
|
+
- algorithm: The signing algorithm to use.
|
|
76
|
+
- Returns: A promise that resolves to the signature.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { signHash, SignAlgorithm } from "@layerzerolabs/lz-foundation"
|
|
80
|
+
|
|
81
|
+
const hash = new Uint8Array(32) // Example hash
|
|
82
|
+
const privateKey = "0xYourPrivateKey"
|
|
83
|
+
const algorithm = SignAlgorithm.SECP256K1
|
|
84
|
+
|
|
85
|
+
signHash(hash, privateKey, algorithm).then((signature) => {
|
|
86
|
+
console.log(`Signature: ${Buffer.from(signature).toString("hex")}`)
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Key Management
|
|
91
|
+
|
|
92
|
+
Interface representing a key pair consisting of a private key and a public key.
|
|
93
|
+
|
|
94
|
+
- privateKey: The private key as a Uint8Array.
|
|
95
|
+
- publicKey: The public key as a Uint8Array.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { KeyPair } from "@layerzerolabs/lz-foundation"
|
|
99
|
+
|
|
100
|
+
const keyPair: KeyPair = {
|
|
101
|
+
privateKey: new Uint8Array(32), // Example private key
|
|
102
|
+
publicKey: new Uint8Array(32), // Example public key
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log(`Private Key: ${Buffer.from(keyPair.privateKey).toString("hex")}`)
|
|
106
|
+
console.log(`Public Key: ${Buffer.from(keyPair.publicKey).toString("hex")}`)
|
|
107
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var sha256 = require('@noble/hashes/sha256');
|
|
|
5
5
|
var sha3 = require('@noble/hashes/sha3');
|
|
6
6
|
var ed25519 = require('@noble/ed25519');
|
|
7
7
|
var secp256k1 = require('@noble/secp256k1');
|
|
8
|
+
var base = require('@scure/base');
|
|
9
|
+
var lzUtilities = require('@layerzerolabs/lz-utilities');
|
|
10
|
+
var lzDefinitions = require('@layerzerolabs/lz-definitions');
|
|
8
11
|
|
|
9
12
|
function _interopNamespace(e) {
|
|
10
13
|
if (e && e.__esModule) return e;
|
|
@@ -33,7 +36,7 @@ var __export = (target, all) => {
|
|
|
33
36
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
34
37
|
};
|
|
35
38
|
function keccak_256(message) {
|
|
36
|
-
return keccak_256();
|
|
39
|
+
return sha3.keccak_256(message);
|
|
37
40
|
}
|
|
38
41
|
function blake2b(message) {
|
|
39
42
|
return blake2b$1.blake2b(message);
|
|
@@ -144,12 +147,26 @@ var Secp256k1Signer = class _Secp256k1Signer {
|
|
|
144
147
|
constructor(privateKey) {
|
|
145
148
|
this.privateKey = privateKey;
|
|
146
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Creates an instance of Secp256k1Signer from a private key.
|
|
152
|
+
* @param {Uint8Array} privateKey - The private key.
|
|
153
|
+
* @returns {Secp256k1Signer} The created Secp256k1Signer instance.
|
|
154
|
+
*/
|
|
147
155
|
static from(privatekey) {
|
|
148
156
|
return new _Secp256k1Signer(privatekey);
|
|
149
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Returns the public key of the signer.
|
|
160
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the public key.
|
|
161
|
+
*/
|
|
150
162
|
async getPublicKey() {
|
|
151
163
|
return secp256k1_exports.getPublicKey(this.privateKey);
|
|
152
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Signs a hash.
|
|
167
|
+
* @param {Uint8Array} hash - The hash to sign, must be 32 bytes long.
|
|
168
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the signature.
|
|
169
|
+
*/
|
|
153
170
|
async signHash(hash) {
|
|
154
171
|
return secp256k1_exports.signHash(hash, this.privateKey);
|
|
155
172
|
}
|
|
@@ -158,26 +175,435 @@ var Ed25519Signer = class _Ed25519Signer {
|
|
|
158
175
|
constructor(privateKey) {
|
|
159
176
|
this.privateKey = privateKey;
|
|
160
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Creates an instance of Ed25519Signer from a private key.
|
|
180
|
+
* @param {Uint8Array} privateKey - The private key.
|
|
181
|
+
* @returns {Ed25519Signer} The created Ed25519Signer instance.
|
|
182
|
+
*/
|
|
161
183
|
static from(privateKey) {
|
|
162
184
|
return new _Ed25519Signer(privateKey);
|
|
163
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Signs a hash.
|
|
188
|
+
* @param {Uint8Array} hash - The hash to sign, must be 32 bytes long.
|
|
189
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the signature.
|
|
190
|
+
*/
|
|
164
191
|
async signHash(hash) {
|
|
165
192
|
return ed25519_exports.signHash(hash, this.privateKey);
|
|
166
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Returns the public key of the signer.
|
|
196
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the public key.
|
|
197
|
+
*/
|
|
167
198
|
async getPublicKey() {
|
|
168
199
|
return ed25519_exports.getPublicKey(this.privateKey);
|
|
169
200
|
}
|
|
170
201
|
};
|
|
171
202
|
|
|
203
|
+
// src/base/base58.ts
|
|
204
|
+
var base58_exports = {};
|
|
205
|
+
__export(base58_exports, {
|
|
206
|
+
decode: () => decode,
|
|
207
|
+
encode: () => encode
|
|
208
|
+
});
|
|
209
|
+
function encode(value) {
|
|
210
|
+
if (typeof value === "string") {
|
|
211
|
+
return base.base58.encode(lzUtilities.arrayify(value));
|
|
212
|
+
} else {
|
|
213
|
+
return base.base58.encode(value);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function decode(value) {
|
|
217
|
+
return base.base58.decode(value);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/base/base58check.ts
|
|
221
|
+
var base58check_exports = {};
|
|
222
|
+
__export(base58check_exports, {
|
|
223
|
+
decode: () => decode2,
|
|
224
|
+
encode: () => encode2
|
|
225
|
+
});
|
|
226
|
+
function encode2(value) {
|
|
227
|
+
const base58check = base.createBase58check(sha256.sha256);
|
|
228
|
+
if (typeof value === "string") {
|
|
229
|
+
return base58check.encode(lzUtilities.arrayify(value));
|
|
230
|
+
} else {
|
|
231
|
+
return base58check.encode(value);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function decode2(value) {
|
|
235
|
+
const base58check = base.createBase58check(sha256.sha256);
|
|
236
|
+
return base58check.decode(value);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/base/base64.ts
|
|
240
|
+
var base64_exports = {};
|
|
241
|
+
__export(base64_exports, {
|
|
242
|
+
decode: () => decode3,
|
|
243
|
+
encode: () => encode3
|
|
244
|
+
});
|
|
245
|
+
function encode3(value) {
|
|
246
|
+
if (typeof value === "string") {
|
|
247
|
+
return base.base64.encode(lzUtilities.arrayify(value));
|
|
248
|
+
} else {
|
|
249
|
+
return base.base64.encode(value);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function decode3(value) {
|
|
253
|
+
return base.base64.decode(value);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/address/aptos.ts
|
|
257
|
+
var aptos_exports = {};
|
|
258
|
+
__export(aptos_exports, {
|
|
259
|
+
Address: () => Address
|
|
260
|
+
});
|
|
261
|
+
var Address = class _Address {
|
|
262
|
+
/**
|
|
263
|
+
* Creates an instance of Address.
|
|
264
|
+
* @param {Uint8Array | string} value - The address value.
|
|
265
|
+
* @throws {Error} If the address is invalid.
|
|
266
|
+
*/
|
|
267
|
+
constructor(value) {
|
|
268
|
+
let data = void 0;
|
|
269
|
+
if (value instanceof Uint8Array) {
|
|
270
|
+
data = value;
|
|
271
|
+
} else if (typeof value === "string") {
|
|
272
|
+
if (lzUtilities.isHex(value)) {
|
|
273
|
+
data = lzUtilities.arrayify(value);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (data === void 0) {
|
|
277
|
+
throw new Error("Invalid address");
|
|
278
|
+
}
|
|
279
|
+
if (data.length > 32) {
|
|
280
|
+
throw new Error("Invalid address length. Expected less or equal than 32 bytes.");
|
|
281
|
+
}
|
|
282
|
+
this.data = data;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Creates an Address instance from a value.
|
|
286
|
+
* @param {Uint8Array | string} value - The address value.
|
|
287
|
+
* @returns {Address} The Address instance.
|
|
288
|
+
*/
|
|
289
|
+
static from(value) {
|
|
290
|
+
return new _Address(value);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Inspects the address.
|
|
294
|
+
* @returns {string} The address as a string.
|
|
295
|
+
*/
|
|
296
|
+
inspect() {
|
|
297
|
+
return this.toString();
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Converts the address to a string.
|
|
301
|
+
* @returns {string} The address as a string.
|
|
302
|
+
*/
|
|
303
|
+
toString() {
|
|
304
|
+
return this.hr();
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Gets the raw address data.
|
|
308
|
+
* @returns {Uint8Array} The raw address data.
|
|
309
|
+
*/
|
|
310
|
+
raw() {
|
|
311
|
+
return this.data;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Gets the human-readable address.
|
|
315
|
+
* @returns {string} The human-readable address.
|
|
316
|
+
*/
|
|
317
|
+
hr() {
|
|
318
|
+
return lzUtilities.hexlify(this.data);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Gets the address as a hexadecimal string.
|
|
322
|
+
* @returns {Hex} The address as a hexadecimal string.
|
|
323
|
+
*/
|
|
324
|
+
hex() {
|
|
325
|
+
return lzUtilities.hexlify(this.data);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// src/address/evm.ts
|
|
330
|
+
var evm_exports = {};
|
|
331
|
+
__export(evm_exports, {
|
|
332
|
+
Address: () => Address2,
|
|
333
|
+
toChecksumAddress: () => toChecksumAddress
|
|
334
|
+
});
|
|
335
|
+
var Address2 = class _Address {
|
|
336
|
+
/**
|
|
337
|
+
* Creates an instance of Address.
|
|
338
|
+
* @param {Uint8Array | string} value - The address value.
|
|
339
|
+
* @throws {Error} If the address is invalid.
|
|
340
|
+
*/
|
|
341
|
+
constructor(value) {
|
|
342
|
+
let data = void 0;
|
|
343
|
+
if (value instanceof Uint8Array) {
|
|
344
|
+
data = value;
|
|
345
|
+
} else if (typeof value === "string" && lzUtilities.isHex(value)) {
|
|
346
|
+
data = lzUtilities.arrayify(value);
|
|
347
|
+
}
|
|
348
|
+
if (data === void 0) {
|
|
349
|
+
throw new Error("Invalid address");
|
|
350
|
+
}
|
|
351
|
+
if (data.length > 20) {
|
|
352
|
+
const prefix = data.slice(0, data.length - 20);
|
|
353
|
+
const isAllZero = prefix.every((byte) => byte === 0);
|
|
354
|
+
if (!isAllZero) {
|
|
355
|
+
throw new Error("Invalid address length. Expected less or equal than 20 bytes.");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
this.data = data;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Creates an Address instance from a value.
|
|
362
|
+
* @param {Uint8Array | string} value - The address value.
|
|
363
|
+
* @returns {Address} The Address instance.
|
|
364
|
+
*/
|
|
365
|
+
static from(value) {
|
|
366
|
+
return new _Address(value);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Inspects the address.
|
|
370
|
+
* @returns {string} The address as a string.
|
|
371
|
+
*/
|
|
372
|
+
inspect() {
|
|
373
|
+
return this.toString();
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Converts the address to a string.
|
|
377
|
+
* @returns {string} The address as a string.
|
|
378
|
+
*/
|
|
379
|
+
toString() {
|
|
380
|
+
return this.hr();
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Gets the raw address data.
|
|
384
|
+
* @returns {Uint8Array} The raw address data.
|
|
385
|
+
*/
|
|
386
|
+
raw() {
|
|
387
|
+
return this.data;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Gets the human-readable address.
|
|
391
|
+
* @returns {string} The human-readable address.
|
|
392
|
+
*/
|
|
393
|
+
hr() {
|
|
394
|
+
const value = lzUtilities.hexlify(lzUtilities.padify(this.data, { size: 20 }));
|
|
395
|
+
return toChecksumAddress(value);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Gets the address as a hexadecimal string.
|
|
399
|
+
* @returns {Hex} The address as a hexadecimal string.
|
|
400
|
+
*/
|
|
401
|
+
hex() {
|
|
402
|
+
return lzUtilities.hexlify(lzUtilities.padify(this.data, { size: 20 }));
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
function toChecksumAddress(address) {
|
|
406
|
+
const lowercasedAddress = address.toLowerCase().replace("0x", "");
|
|
407
|
+
const hash = Buffer.from(keccak_256(lowercasedAddress)).toString("hex");
|
|
408
|
+
let checksumAddress = "0x";
|
|
409
|
+
for (let i = 0; i < lowercasedAddress.length; i++) {
|
|
410
|
+
if (parseInt(hash[i], 16) > 7) {
|
|
411
|
+
checksumAddress += lowercasedAddress[i].toUpperCase();
|
|
412
|
+
} else {
|
|
413
|
+
checksumAddress += lowercasedAddress[i];
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return checksumAddress;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/address/solana.ts
|
|
420
|
+
var solana_exports = {};
|
|
421
|
+
__export(solana_exports, {
|
|
422
|
+
Address: () => Address3
|
|
423
|
+
});
|
|
424
|
+
var Address3 = class _Address {
|
|
425
|
+
/**
|
|
426
|
+
* Creates an instance of Address.
|
|
427
|
+
* @param {Uint8Array | string} value - The address value.
|
|
428
|
+
* @throws {Error} If the address is invalid.
|
|
429
|
+
*/
|
|
430
|
+
constructor(value) {
|
|
431
|
+
let data = void 0;
|
|
432
|
+
if (value instanceof Uint8Array) {
|
|
433
|
+
data = value;
|
|
434
|
+
} else if (typeof value === "string") {
|
|
435
|
+
if (lzUtilities.isHex(value)) {
|
|
436
|
+
data = lzUtilities.arrayify(value);
|
|
437
|
+
} else {
|
|
438
|
+
data = base58_exports.decode(value);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (data === void 0) {
|
|
442
|
+
throw new Error("Invalid address");
|
|
443
|
+
}
|
|
444
|
+
if (data.length > 32) {
|
|
445
|
+
throw new Error("Invalid address length. Expected less or equal than 32 bytes.");
|
|
446
|
+
}
|
|
447
|
+
this.data = data;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Creates an Address instance from a value.
|
|
451
|
+
* @param {Uint8Array | string} value - The address value.
|
|
452
|
+
* @returns {Address} The Address instance.
|
|
453
|
+
*/
|
|
454
|
+
static from(value) {
|
|
455
|
+
return new _Address(value);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Inspects the address.
|
|
459
|
+
* @returns {string} The address as a string.
|
|
460
|
+
*/
|
|
461
|
+
inspect() {
|
|
462
|
+
return this.toString();
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Converts the address to a string.
|
|
466
|
+
* @returns {string} The address as a string.
|
|
467
|
+
*/
|
|
468
|
+
toString() {
|
|
469
|
+
return this.hr();
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Gets the raw address data.
|
|
473
|
+
* @returns {Uint8Array} The raw address data.
|
|
474
|
+
*/
|
|
475
|
+
raw() {
|
|
476
|
+
return this.data;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Gets the human-readable address.
|
|
480
|
+
* @returns {string} The human-readable address.
|
|
481
|
+
*/
|
|
482
|
+
hr() {
|
|
483
|
+
return base58_exports.encode(this.data);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Gets the address as a hexadecimal string.
|
|
487
|
+
* @returns {Hex} The address as a hexadecimal string.
|
|
488
|
+
*/
|
|
489
|
+
hex() {
|
|
490
|
+
return lzUtilities.hexlify(this.data);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// src/address/tron.ts
|
|
495
|
+
var tron_exports = {};
|
|
496
|
+
__export(tron_exports, {
|
|
497
|
+
Address: () => Address4
|
|
498
|
+
});
|
|
499
|
+
var Address4 = class _Address {
|
|
500
|
+
/**
|
|
501
|
+
* Creates an instance of Address.
|
|
502
|
+
* @param {Uint8Array | string} value - The address value.
|
|
503
|
+
* @throws {Error} If the address is invalid.
|
|
504
|
+
*/
|
|
505
|
+
constructor(value) {
|
|
506
|
+
let data = void 0;
|
|
507
|
+
if (value instanceof Uint8Array) {
|
|
508
|
+
data = value;
|
|
509
|
+
} else if (typeof value === "string") {
|
|
510
|
+
if (lzUtilities.isHex(value)) {
|
|
511
|
+
data = lzUtilities.arrayify(value);
|
|
512
|
+
} else {
|
|
513
|
+
data = base58check_exports.decode(value);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (data === void 0) {
|
|
517
|
+
throw new Error("Invalid address");
|
|
518
|
+
}
|
|
519
|
+
if (data.length != 21) {
|
|
520
|
+
throw new Error("Invalid address length. Expected 21 bytes.");
|
|
521
|
+
}
|
|
522
|
+
this.data = data;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Creates an Address instance from a value.
|
|
526
|
+
* @param {Uint8Array | string} value - The address value.
|
|
527
|
+
* @returns {Address} The Address instance.
|
|
528
|
+
*/
|
|
529
|
+
static from(value) {
|
|
530
|
+
return new _Address(value);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Inspects the address.
|
|
534
|
+
* @returns {string} The address as a string.
|
|
535
|
+
*/
|
|
536
|
+
inspect() {
|
|
537
|
+
return this.toString();
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Converts the address to a string.
|
|
541
|
+
* @returns {string} The address as a string.
|
|
542
|
+
*/
|
|
543
|
+
toString() {
|
|
544
|
+
return this.hr();
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Gets the raw address data.
|
|
548
|
+
* @returns {Uint8Array} The raw address data.
|
|
549
|
+
*/
|
|
550
|
+
raw() {
|
|
551
|
+
return this.data;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Gets the human-readable address.
|
|
555
|
+
* @returns {string} The human-readable address.
|
|
556
|
+
*/
|
|
557
|
+
hr() {
|
|
558
|
+
return base58check_exports.encode(this.data);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Gets the address as a hexadecimal string.
|
|
562
|
+
* @returns {Hex} The address as a hexadecimal string.
|
|
563
|
+
*/
|
|
564
|
+
hex() {
|
|
565
|
+
return lzUtilities.hexlify(this.data);
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
var Address5 = {
|
|
569
|
+
from: (address, chain) => {
|
|
570
|
+
const chainType = lzDefinitions.chainToChainType(chain);
|
|
571
|
+
switch (chainType) {
|
|
572
|
+
case lzDefinitions.ChainType.EVM:
|
|
573
|
+
if (chain === lzDefinitions.Chain.TRON) {
|
|
574
|
+
return Address4.from(address);
|
|
575
|
+
}
|
|
576
|
+
return Address2.from(address);
|
|
577
|
+
case lzDefinitions.ChainType.APTOS:
|
|
578
|
+
return Address.from(address);
|
|
579
|
+
case lzDefinitions.ChainType.SOLANA:
|
|
580
|
+
return Address3.from(address);
|
|
581
|
+
default:
|
|
582
|
+
throw new Error(`Unsupported chain type: ${chainType}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
// src/address/address.ts
|
|
588
|
+
var Address6 = Address5;
|
|
589
|
+
|
|
590
|
+
exports.Address = Address6;
|
|
172
591
|
exports.Ed25519Signer = Ed25519Signer;
|
|
173
592
|
exports.Secp256k1Signer = Secp256k1Signer;
|
|
174
593
|
exports.SignAlgorithm = SignAlgorithm;
|
|
594
|
+
exports.aptos = aptos_exports;
|
|
595
|
+
exports.base58 = base58_exports;
|
|
596
|
+
exports.base58check = base58check_exports;
|
|
597
|
+
exports.base64 = base64_exports;
|
|
175
598
|
exports.blake2b = blake2b;
|
|
176
599
|
exports.ed25519 = ed25519_exports;
|
|
600
|
+
exports.evm = evm_exports;
|
|
177
601
|
exports.keccak_256 = keccak_256;
|
|
178
602
|
exports.secp256k1 = secp256k1_exports;
|
|
179
603
|
exports.sha2_256 = sha2_256;
|
|
180
604
|
exports.sha3_256 = sha3_256;
|
|
181
605
|
exports.signHash = signHash3;
|
|
606
|
+
exports.solana = solana_exports;
|
|
607
|
+
exports.tron = tron_exports;
|
|
182
608
|
//# sourceMappingURL=out.js.map
|
|
183
609
|
//# sourceMappingURL=index.cjs.map
|