@layerzerolabs/lz-foundation 3.0.139 → 3.0.140
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 +9 -0
- package/dist/index.cjs +79 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +27 -27
- package/dist/index.d.ts +27 -27
- package/dist/index.mjs +79 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -256,7 +256,7 @@ declare const Address$6: {
|
|
|
256
256
|
type Address$6 = Address$7;
|
|
257
257
|
|
|
258
258
|
/**
|
|
259
|
-
* Represents an
|
|
259
|
+
* Represents an EVM address.
|
|
260
260
|
* @see {@link AddressInterface}
|
|
261
261
|
*/
|
|
262
262
|
declare class Address$5 implements Address$6 {
|
|
@@ -302,13 +302,20 @@ declare class Address$5 implements Address$6 {
|
|
|
302
302
|
*/
|
|
303
303
|
hex(): Hex;
|
|
304
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Converts an address to its checksum format.
|
|
307
|
+
* @param {string} address - The address to convert.
|
|
308
|
+
* @returns {string} The checksummed address.
|
|
309
|
+
*/
|
|
310
|
+
declare function toChecksumAddress(address: string): string;
|
|
305
311
|
|
|
306
|
-
declare
|
|
307
|
-
|
|
312
|
+
declare const evm_toChecksumAddress: typeof toChecksumAddress;
|
|
313
|
+
declare namespace evm {
|
|
314
|
+
export { Address$5 as Address, evm_toChecksumAddress as toChecksumAddress };
|
|
308
315
|
}
|
|
309
316
|
|
|
310
317
|
/**
|
|
311
|
-
* Represents an
|
|
318
|
+
* Represents an Initia address.
|
|
312
319
|
* @see {@link AddressInterface}
|
|
313
320
|
*/
|
|
314
321
|
declare class Address$4 implements Address$6 {
|
|
@@ -353,21 +360,25 @@ declare class Address$4 implements Address$6 {
|
|
|
353
360
|
* @returns {Hex} The address as a hexadecimal string.
|
|
354
361
|
*/
|
|
355
362
|
hex(): Hex;
|
|
363
|
+
private checkPrefixAndLength;
|
|
364
|
+
/**
|
|
365
|
+
* Checks if a string is a valid Initia account address.
|
|
366
|
+
* @param data string to check
|
|
367
|
+
*/
|
|
368
|
+
private validateInitiaAddress;
|
|
369
|
+
/**
|
|
370
|
+
* Converts a hex address into an account address
|
|
371
|
+
* @param hexAddress hex address
|
|
372
|
+
*/
|
|
373
|
+
private fromHex;
|
|
356
374
|
}
|
|
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
375
|
|
|
364
|
-
declare
|
|
365
|
-
|
|
366
|
-
export { Address$4 as Address, evm_toChecksumAddress as toChecksumAddress };
|
|
376
|
+
declare namespace initia {
|
|
377
|
+
export { Address$4 as Address };
|
|
367
378
|
}
|
|
368
379
|
|
|
369
380
|
/**
|
|
370
|
-
* Represents an
|
|
381
|
+
* Represents an Aptos address.
|
|
371
382
|
* @see {@link AddressInterface}
|
|
372
383
|
*/
|
|
373
384
|
declare class Address$3 implements Address$6 {
|
|
@@ -412,20 +423,9 @@ declare class Address$3 implements Address$6 {
|
|
|
412
423
|
* @returns {Hex} The address as a hexadecimal string.
|
|
413
424
|
*/
|
|
414
425
|
hex(): Hex;
|
|
415
|
-
private checkPrefixAndLength;
|
|
416
|
-
/**
|
|
417
|
-
* Checks if a string is a valid Initia account address.
|
|
418
|
-
* @param data string to check
|
|
419
|
-
*/
|
|
420
|
-
private validateInitiaAddress;
|
|
421
|
-
/**
|
|
422
|
-
* Converts a hex address into an account address
|
|
423
|
-
* @param hexAddress hex address
|
|
424
|
-
*/
|
|
425
|
-
private fromHex;
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
-
declare namespace
|
|
428
|
+
declare namespace move {
|
|
429
429
|
export { Address$3 as Address };
|
|
430
430
|
}
|
|
431
431
|
|
|
@@ -596,4 +596,4 @@ type tron_Address = Address;
|
|
|
596
596
|
export { tron_Address as Address };
|
|
597
597
|
}
|
|
598
598
|
|
|
599
|
-
export { Address$6 as Address, Ed25519Signer, type HashSigner, type KeyPair, Secp256k1Signer, SignAlgorithm,
|
|
599
|
+
export { Address$6 as Address, Ed25519Signer, type HashSigner, type KeyPair, Secp256k1Signer, SignAlgorithm, base58, base58check, base64, blake2b, ed25519, evm, initia, keccak_256, move, secp256k1, sha2_256, sha3_256, signHash, solana, ton, tron };
|
package/dist/index.d.ts
CHANGED
|
@@ -256,7 +256,7 @@ declare const Address$6: {
|
|
|
256
256
|
type Address$6 = Address$7;
|
|
257
257
|
|
|
258
258
|
/**
|
|
259
|
-
* Represents an
|
|
259
|
+
* Represents an EVM address.
|
|
260
260
|
* @see {@link AddressInterface}
|
|
261
261
|
*/
|
|
262
262
|
declare class Address$5 implements Address$6 {
|
|
@@ -302,13 +302,20 @@ declare class Address$5 implements Address$6 {
|
|
|
302
302
|
*/
|
|
303
303
|
hex(): Hex;
|
|
304
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Converts an address to its checksum format.
|
|
307
|
+
* @param {string} address - The address to convert.
|
|
308
|
+
* @returns {string} The checksummed address.
|
|
309
|
+
*/
|
|
310
|
+
declare function toChecksumAddress(address: string): string;
|
|
305
311
|
|
|
306
|
-
declare
|
|
307
|
-
|
|
312
|
+
declare const evm_toChecksumAddress: typeof toChecksumAddress;
|
|
313
|
+
declare namespace evm {
|
|
314
|
+
export { Address$5 as Address, evm_toChecksumAddress as toChecksumAddress };
|
|
308
315
|
}
|
|
309
316
|
|
|
310
317
|
/**
|
|
311
|
-
* Represents an
|
|
318
|
+
* Represents an Initia address.
|
|
312
319
|
* @see {@link AddressInterface}
|
|
313
320
|
*/
|
|
314
321
|
declare class Address$4 implements Address$6 {
|
|
@@ -353,21 +360,25 @@ declare class Address$4 implements Address$6 {
|
|
|
353
360
|
* @returns {Hex} The address as a hexadecimal string.
|
|
354
361
|
*/
|
|
355
362
|
hex(): Hex;
|
|
363
|
+
private checkPrefixAndLength;
|
|
364
|
+
/**
|
|
365
|
+
* Checks if a string is a valid Initia account address.
|
|
366
|
+
* @param data string to check
|
|
367
|
+
*/
|
|
368
|
+
private validateInitiaAddress;
|
|
369
|
+
/**
|
|
370
|
+
* Converts a hex address into an account address
|
|
371
|
+
* @param hexAddress hex address
|
|
372
|
+
*/
|
|
373
|
+
private fromHex;
|
|
356
374
|
}
|
|
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
375
|
|
|
364
|
-
declare
|
|
365
|
-
|
|
366
|
-
export { Address$4 as Address, evm_toChecksumAddress as toChecksumAddress };
|
|
376
|
+
declare namespace initia {
|
|
377
|
+
export { Address$4 as Address };
|
|
367
378
|
}
|
|
368
379
|
|
|
369
380
|
/**
|
|
370
|
-
* Represents an
|
|
381
|
+
* Represents an Aptos address.
|
|
371
382
|
* @see {@link AddressInterface}
|
|
372
383
|
*/
|
|
373
384
|
declare class Address$3 implements Address$6 {
|
|
@@ -412,20 +423,9 @@ declare class Address$3 implements Address$6 {
|
|
|
412
423
|
* @returns {Hex} The address as a hexadecimal string.
|
|
413
424
|
*/
|
|
414
425
|
hex(): Hex;
|
|
415
|
-
private checkPrefixAndLength;
|
|
416
|
-
/**
|
|
417
|
-
* Checks if a string is a valid Initia account address.
|
|
418
|
-
* @param data string to check
|
|
419
|
-
*/
|
|
420
|
-
private validateInitiaAddress;
|
|
421
|
-
/**
|
|
422
|
-
* Converts a hex address into an account address
|
|
423
|
-
* @param hexAddress hex address
|
|
424
|
-
*/
|
|
425
|
-
private fromHex;
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
-
declare namespace
|
|
428
|
+
declare namespace move {
|
|
429
429
|
export { Address$3 as Address };
|
|
430
430
|
}
|
|
431
431
|
|
|
@@ -596,4 +596,4 @@ type tron_Address = Address;
|
|
|
596
596
|
export { tron_Address as Address };
|
|
597
597
|
}
|
|
598
598
|
|
|
599
|
-
export { Address$6 as Address, Ed25519Signer, type HashSigner, type KeyPair, Secp256k1Signer, SignAlgorithm,
|
|
599
|
+
export { Address$6 as Address, Ed25519Signer, type HashSigner, type KeyPair, Secp256k1Signer, SignAlgorithm, base58, base58check, base64, blake2b, ed25519, evm, initia, keccak_256, move, secp256k1, sha2_256, sha3_256, signHash, solana, ton, tron };
|
package/dist/index.mjs
CHANGED
|
@@ -231,10 +231,11 @@ function decode3(value) {
|
|
|
231
231
|
return base64.decode(value);
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
// src/address/
|
|
235
|
-
var
|
|
236
|
-
__export(
|
|
237
|
-
Address: () => Address
|
|
234
|
+
// src/address/evm.ts
|
|
235
|
+
var evm_exports = {};
|
|
236
|
+
__export(evm_exports, {
|
|
237
|
+
Address: () => Address,
|
|
238
|
+
toChecksumAddress: () => toChecksumAddress
|
|
238
239
|
});
|
|
239
240
|
var Address = class _Address {
|
|
240
241
|
/**
|
|
@@ -246,16 +247,18 @@ var Address = class _Address {
|
|
|
246
247
|
let data = void 0;
|
|
247
248
|
if (value instanceof Uint8Array) {
|
|
248
249
|
data = value;
|
|
249
|
-
} else if (typeof value === "string") {
|
|
250
|
-
|
|
251
|
-
data = arrayify(value);
|
|
252
|
-
}
|
|
250
|
+
} else if (typeof value === "string" && isHex(value)) {
|
|
251
|
+
data = arrayify(value);
|
|
253
252
|
}
|
|
254
253
|
if (data === void 0) {
|
|
255
254
|
throw new Error("Invalid address");
|
|
256
255
|
}
|
|
257
|
-
if (data.length >
|
|
258
|
-
|
|
256
|
+
if (data.length > 20) {
|
|
257
|
+
const prefix = data.slice(0, data.length - 20);
|
|
258
|
+
const isAllZero = prefix.every((byte) => byte === 0);
|
|
259
|
+
if (!isAllZero) {
|
|
260
|
+
throw new Error("Invalid address length. Expected less or equal than 20 bytes.");
|
|
261
|
+
}
|
|
259
262
|
}
|
|
260
263
|
this.data = data;
|
|
261
264
|
}
|
|
@@ -293,22 +296,35 @@ var Address = class _Address {
|
|
|
293
296
|
* @returns {string} The human-readable address.
|
|
294
297
|
*/
|
|
295
298
|
hr() {
|
|
296
|
-
|
|
299
|
+
const value = hexlify(padify(this.data, { size: 20 }));
|
|
300
|
+
return toChecksumAddress(value);
|
|
297
301
|
}
|
|
298
302
|
/**
|
|
299
303
|
* Gets the address as a hexadecimal string.
|
|
300
304
|
* @returns {Hex} The address as a hexadecimal string.
|
|
301
305
|
*/
|
|
302
306
|
hex() {
|
|
303
|
-
return hexlify(this.data);
|
|
307
|
+
return hexlify(padify(this.data, { size: 20 }));
|
|
304
308
|
}
|
|
305
309
|
};
|
|
310
|
+
function toChecksumAddress(address) {
|
|
311
|
+
const lowercasedAddress = address.toLowerCase().replace("0x", "");
|
|
312
|
+
const hash = Buffer.from(keccak_256(lowercasedAddress)).toString("hex");
|
|
313
|
+
let checksumAddress = "0x";
|
|
314
|
+
for (let i = 0; i < lowercasedAddress.length; i++) {
|
|
315
|
+
if (parseInt(hash[i], 16) > 7) {
|
|
316
|
+
checksumAddress += lowercasedAddress[i].toUpperCase();
|
|
317
|
+
} else {
|
|
318
|
+
checksumAddress += lowercasedAddress[i];
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return checksumAddress;
|
|
322
|
+
}
|
|
306
323
|
|
|
307
|
-
// src/address/
|
|
308
|
-
var
|
|
309
|
-
__export(
|
|
310
|
-
Address: () => Address2
|
|
311
|
-
toChecksumAddress: () => toChecksumAddress
|
|
324
|
+
// src/address/initia.ts
|
|
325
|
+
var initia_exports = {};
|
|
326
|
+
__export(initia_exports, {
|
|
327
|
+
Address: () => Address2
|
|
312
328
|
});
|
|
313
329
|
var Address2 = class _Address {
|
|
314
330
|
/**
|
|
@@ -320,18 +336,19 @@ var Address2 = class _Address {
|
|
|
320
336
|
let data = void 0;
|
|
321
337
|
if (value instanceof Uint8Array) {
|
|
322
338
|
data = value;
|
|
323
|
-
} else
|
|
324
|
-
|
|
339
|
+
} else {
|
|
340
|
+
if (isHex(value)) {
|
|
341
|
+
data = arrayify(value);
|
|
342
|
+
} else if (this.validateInitiaAddress(value)) {
|
|
343
|
+
const vals = bech32.decode(value);
|
|
344
|
+
data = new Uint8Array(Buffer.from(bech32.fromWords(vals.words)));
|
|
345
|
+
}
|
|
325
346
|
}
|
|
326
347
|
if (data === void 0) {
|
|
327
348
|
throw new Error("Invalid address");
|
|
328
349
|
}
|
|
329
|
-
if (data.length >
|
|
330
|
-
|
|
331
|
-
const isAllZero = prefix.every((byte) => byte === 0);
|
|
332
|
-
if (!isAllZero) {
|
|
333
|
-
throw new Error("Invalid address length. Expected less or equal than 20 bytes.");
|
|
334
|
-
}
|
|
350
|
+
if (data.length > 32) {
|
|
351
|
+
throw new Error("Invalid address length. Expected less or equal than 32 bytes.");
|
|
335
352
|
}
|
|
336
353
|
this.data = data;
|
|
337
354
|
}
|
|
@@ -369,34 +386,47 @@ var Address2 = class _Address {
|
|
|
369
386
|
* @returns {string} The human-readable address.
|
|
370
387
|
*/
|
|
371
388
|
hr() {
|
|
372
|
-
|
|
373
|
-
return toChecksumAddress(value);
|
|
389
|
+
return this.fromHex(this.hex());
|
|
374
390
|
}
|
|
375
391
|
/**
|
|
376
392
|
* Gets the address as a hexadecimal string.
|
|
377
393
|
* @returns {Hex} The address as a hexadecimal string.
|
|
378
394
|
*/
|
|
379
395
|
hex() {
|
|
380
|
-
return hexlify(
|
|
396
|
+
return hexlify(this.data);
|
|
381
397
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
398
|
+
checkPrefixAndLength(prefix, data, length) {
|
|
399
|
+
try {
|
|
400
|
+
const vals = bech32.decode(data);
|
|
401
|
+
return vals.prefix === prefix && data.length == length;
|
|
402
|
+
} catch (e) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Checks if a string is a valid Initia account address.
|
|
408
|
+
* @param data string to check
|
|
409
|
+
*/
|
|
410
|
+
validateInitiaAddress(data) {
|
|
411
|
+
return this.checkPrefixAndLength("init", data, 43) || this.checkPrefixAndLength("init", data, 63);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Converts a hex address into an account address
|
|
415
|
+
* @param hexAddress hex address
|
|
416
|
+
*/
|
|
417
|
+
fromHex(hexAddress) {
|
|
418
|
+
const hex = hexAddress.replace(/^0x0+|^0x|^0+(?!x)/, "");
|
|
419
|
+
if (hex.length <= 40) {
|
|
420
|
+
return bech32.encode("init", bech32.toWords(Buffer.from(hex.padStart(40, "0"), "hex")));
|
|
390
421
|
} else {
|
|
391
|
-
|
|
422
|
+
return bech32.encode("init", bech32.toWords(Buffer.from(hex.padStart(64, "0"), "hex")));
|
|
392
423
|
}
|
|
393
424
|
}
|
|
394
|
-
|
|
395
|
-
}
|
|
425
|
+
};
|
|
396
426
|
|
|
397
|
-
// src/address/
|
|
398
|
-
var
|
|
399
|
-
__export(
|
|
427
|
+
// src/address/move.ts
|
|
428
|
+
var move_exports = {};
|
|
429
|
+
__export(move_exports, {
|
|
400
430
|
Address: () => Address3
|
|
401
431
|
});
|
|
402
432
|
var Address3 = class _Address {
|
|
@@ -409,12 +439,9 @@ var Address3 = class _Address {
|
|
|
409
439
|
let data = void 0;
|
|
410
440
|
if (value instanceof Uint8Array) {
|
|
411
441
|
data = value;
|
|
412
|
-
} else {
|
|
442
|
+
} else if (typeof value === "string") {
|
|
413
443
|
if (isHex(value)) {
|
|
414
444
|
data = arrayify(value);
|
|
415
|
-
} else if (this.validateInitiaAddress(value)) {
|
|
416
|
-
const vals = bech32.decode(value);
|
|
417
|
-
data = new Uint8Array(Buffer.from(bech32.fromWords(vals.words)));
|
|
418
445
|
}
|
|
419
446
|
}
|
|
420
447
|
if (data === void 0) {
|
|
@@ -459,7 +486,7 @@ var Address3 = class _Address {
|
|
|
459
486
|
* @returns {string} The human-readable address.
|
|
460
487
|
*/
|
|
461
488
|
hr() {
|
|
462
|
-
return
|
|
489
|
+
return hexlify(this.data);
|
|
463
490
|
}
|
|
464
491
|
/**
|
|
465
492
|
* Gets the address as a hexadecimal string.
|
|
@@ -468,33 +495,6 @@ var Address3 = class _Address {
|
|
|
468
495
|
hex() {
|
|
469
496
|
return hexlify(this.data);
|
|
470
497
|
}
|
|
471
|
-
checkPrefixAndLength(prefix, data, length) {
|
|
472
|
-
try {
|
|
473
|
-
const vals = bech32.decode(data);
|
|
474
|
-
return vals.prefix === prefix && data.length == length;
|
|
475
|
-
} catch (e) {
|
|
476
|
-
return false;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Checks if a string is a valid Initia account address.
|
|
481
|
-
* @param data string to check
|
|
482
|
-
*/
|
|
483
|
-
validateInitiaAddress(data) {
|
|
484
|
-
return this.checkPrefixAndLength("init", data, 43) || this.checkPrefixAndLength("init", data, 63);
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Converts a hex address into an account address
|
|
488
|
-
* @param hexAddress hex address
|
|
489
|
-
*/
|
|
490
|
-
fromHex(hexAddress) {
|
|
491
|
-
const hex = hexAddress.replace(/^0x0+|^0x|^0+(?!x)/, "");
|
|
492
|
-
if (hex.length <= 40) {
|
|
493
|
-
return bech32.encode("init", bech32.toWords(Buffer.from(hex.padStart(40, "0"), "hex")));
|
|
494
|
-
} else {
|
|
495
|
-
return bech32.encode("init", bech32.toWords(Buffer.from(hex.padStart(64, "0"), "hex")));
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
498
|
};
|
|
499
499
|
|
|
500
500
|
// src/address/solana.ts
|
|
@@ -845,12 +845,13 @@ var Address7 = {
|
|
|
845
845
|
if (chain === Chain.TRON) {
|
|
846
846
|
return Address6.from(address);
|
|
847
847
|
}
|
|
848
|
-
return
|
|
848
|
+
return Address.from(address);
|
|
849
|
+
case ChainType.IOTAMOVE:
|
|
849
850
|
case ChainType.APTOS:
|
|
850
851
|
case ChainType.SUI:
|
|
851
|
-
return Address.from(address);
|
|
852
|
-
case ChainType.INITIA:
|
|
853
852
|
return Address3.from(address);
|
|
853
|
+
case ChainType.INITIA:
|
|
854
|
+
return Address2.from(address);
|
|
854
855
|
case ChainType.SOLANA:
|
|
855
856
|
return Address4.from(address);
|
|
856
857
|
case ChainType.TON:
|
|
@@ -864,6 +865,6 @@ var Address7 = {
|
|
|
864
865
|
// src/address/address.ts
|
|
865
866
|
var Address8 = Address7;
|
|
866
867
|
|
|
867
|
-
export { Address8 as Address, Ed25519Signer, Secp256k1Signer, SignAlgorithm,
|
|
868
|
+
export { Address8 as Address, Ed25519Signer, Secp256k1Signer, SignAlgorithm, base58_exports as base58, base58check_exports as base58check, base64_exports as base64, blake2b, ed25519_exports as ed25519, evm_exports as evm, initia_exports as initia, keccak_256, move_exports as move, secp256k1_exports as secp256k1, sha2_256, sha3_256, signHash3 as signHash, solana_exports as solana, ton_exports as ton, tron_exports as tron };
|
|
868
869
|
//# sourceMappingURL=index.mjs.map
|
|
869
870
|
//# sourceMappingURL=index.mjs.map
|