@layerzerolabs/chain-utils 0.2.58 → 0.2.60
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/.turbo/turbo-build.log +21 -21
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +4 -4
- package/dist/{3457WEGJ.js → OVN7SCH2.js} +75 -9
- package/dist/OVN7SCH2.js.map +1 -0
- package/dist/{QNFJ2P5R.cjs → X46YPLVF.cjs} +74 -8
- package/dist/X46YPLVF.cjs.map +1 -0
- package/dist/addressParser.cjs +9 -9
- package/dist/addressParser.d.ts +3 -2
- package/dist/addressParser.d.ts.map +1 -1
- package/dist/addressParser.js +1 -1
- package/dist/addressParser.test.cjs +174 -10
- package/dist/addressParser.test.cjs.map +1 -1
- package/dist/addressParser.test.js +167 -3
- package/dist/addressParser.test.js.map +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.js +1 -1
- package/package.json +9 -9
- package/src/addressParser.test.ts +181 -3
- package/src/addressParser.ts +99 -8
- package/dist/3457WEGJ.js.map +0 -1
- package/dist/QNFJ2P5R.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { addressParser } from './
|
|
1
|
+
import { addressParser } from './OVN7SCH2.js';
|
|
2
2
|
import { __commonJS, init_esm_shims, __name, __toESM } from './CWKWODSW.js';
|
|
3
3
|
import * as bs58 from 'bs58';
|
|
4
4
|
import { isatty } from 'tty';
|
|
5
|
-
import { normalizeHex } from '@layerzerolabs/common-chain-model';
|
|
5
|
+
import { normalizeHex, NORMALIZED_HEX_ZERO } from '@layerzerolabs/common-chain-model';
|
|
6
6
|
import { hexToBytes, hexZeroPad, bytesToHexPrefixed } from '@layerzerolabs/common-encoding-utils';
|
|
7
7
|
import { ChainName } from '@layerzerolabs/layerzero-definitions';
|
|
8
8
|
|
|
@@ -18131,7 +18131,7 @@ describe("addressParser - hex/EVM chains", () => {
|
|
|
18131
18131
|
runPropertyTest(() => {
|
|
18132
18132
|
const byteLength = Math.floor(Math.random() * 32) + 1;
|
|
18133
18133
|
const input = randomHex(byteLength);
|
|
18134
|
-
const padded = addressParser.normalizedToBytes32Hex(input);
|
|
18134
|
+
const padded = addressParser(ChainName.ETHEREUM).normalizedToBytes32Hex(input);
|
|
18135
18135
|
globalExpect(padded.length).toBe(66);
|
|
18136
18136
|
globalExpect(padded).toBe(hexZeroPad(input, 32));
|
|
18137
18137
|
});
|
|
@@ -18467,6 +18467,23 @@ describe("addressParser - Stellar", () => {
|
|
|
18467
18467
|
globalExpect(bytes32.length).toBe(32);
|
|
18468
18468
|
});
|
|
18469
18469
|
});
|
|
18470
|
+
describe("normalizedToBytes32 operations", () => {
|
|
18471
|
+
it("produces same result as nativeToBytes32Hex for contract address (C...)", () => {
|
|
18472
|
+
const stellarAddress = validTestAddresses.contract;
|
|
18473
|
+
const normalized = parser.nativeToNormalized(stellarAddress);
|
|
18474
|
+
const fromNative = parser.nativeToBytes32Hex(stellarAddress);
|
|
18475
|
+
const fromNormalized = parser.normalizedToBytes32Hex(normalized);
|
|
18476
|
+
globalExpect(fromNormalized).toBe(fromNative);
|
|
18477
|
+
});
|
|
18478
|
+
it("normalizedToBytes32 returns correct Uint8Array", () => {
|
|
18479
|
+
const stellarAddress = validTestAddresses.account;
|
|
18480
|
+
const normalized = parser.nativeToNormalized(stellarAddress);
|
|
18481
|
+
const bytes32Hex = parser.normalizedToBytes32Hex(normalized);
|
|
18482
|
+
const bytes32 = parser.normalizedToBytes32(normalized);
|
|
18483
|
+
globalExpect(bytes32.length).toBe(32);
|
|
18484
|
+
globalExpect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
|
|
18485
|
+
});
|
|
18486
|
+
});
|
|
18470
18487
|
describe("address type preservation", () => {
|
|
18471
18488
|
it("preserves address type information through conversion", () => {
|
|
18472
18489
|
const addresses = [
|
|
@@ -18536,6 +18553,153 @@ describe("addressParser - Stellar", () => {
|
|
|
18536
18553
|
});
|
|
18537
18554
|
});
|
|
18538
18555
|
});
|
|
18556
|
+
describe("addressParser - normalizedToBytes32Hex (cross-chain)", () => {
|
|
18557
|
+
const testCases = [
|
|
18558
|
+
{
|
|
18559
|
+
name: "EVM (Ethereum)",
|
|
18560
|
+
chainName: ChainName.ETHEREUM,
|
|
18561
|
+
nativeAddr: "0x1234567890abcdef1234567890abcdef12345678"
|
|
18562
|
+
},
|
|
18563
|
+
{
|
|
18564
|
+
name: "Solana",
|
|
18565
|
+
chainName: ChainName.SOLANA,
|
|
18566
|
+
nativeAddr: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
|
|
18567
|
+
},
|
|
18568
|
+
{
|
|
18569
|
+
name: "TON",
|
|
18570
|
+
chainName: ChainName.TON,
|
|
18571
|
+
nativeAddr: "EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2"
|
|
18572
|
+
},
|
|
18573
|
+
{
|
|
18574
|
+
name: "Stellar",
|
|
18575
|
+
chainName: ChainName.STELLAR,
|
|
18576
|
+
nativeAddr: "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7"
|
|
18577
|
+
},
|
|
18578
|
+
{
|
|
18579
|
+
name: "Aptos",
|
|
18580
|
+
chainName: ChainName.APTOS,
|
|
18581
|
+
nativeAddr: "0x1"
|
|
18582
|
+
},
|
|
18583
|
+
{
|
|
18584
|
+
name: "Starknet",
|
|
18585
|
+
chainName: ChainName.STARKNET,
|
|
18586
|
+
nativeAddr: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
|
|
18587
|
+
},
|
|
18588
|
+
{
|
|
18589
|
+
name: "Initia",
|
|
18590
|
+
chainName: ChainName.INITIA,
|
|
18591
|
+
nativeAddr: "0x1"
|
|
18592
|
+
}
|
|
18593
|
+
];
|
|
18594
|
+
testCases.forEach(({ name, chainName, nativeAddr }) => {
|
|
18595
|
+
it(`${name}: normalizedToBytes32Hex(normalized) === nativeToBytes32Hex(native)`, () => {
|
|
18596
|
+
const p3 = addressParser(chainName);
|
|
18597
|
+
const normalized = p3.nativeToNormalized(nativeAddr);
|
|
18598
|
+
const fromNormalized = p3.normalizedToBytes32Hex(normalized);
|
|
18599
|
+
const fromNative = p3.nativeToBytes32Hex(nativeAddr);
|
|
18600
|
+
globalExpect(fromNormalized).toBe(fromNative);
|
|
18601
|
+
globalExpect(fromNormalized.length).toBe(66);
|
|
18602
|
+
globalExpect(fromNormalized).toMatch(/^0x[0-9a-f]{64}$/);
|
|
18603
|
+
});
|
|
18604
|
+
});
|
|
18605
|
+
it("normalizedToBytes32Hex is consistent across chain parsers for \u226432 byte hex", () => {
|
|
18606
|
+
const evmParser = addressParser(ChainName.ETHEREUM);
|
|
18607
|
+
const solanaParser = addressParser(ChainName.SOLANA);
|
|
18608
|
+
const normalized = normalizeHex("0x1234567890abcdef1234567890abcdef12345678");
|
|
18609
|
+
globalExpect(evmParser.normalizedToBytes32Hex(normalized)).toBe(solanaParser.normalizedToBytes32Hex(normalized));
|
|
18610
|
+
});
|
|
18611
|
+
it("normalizedToBytes32 returns correct Uint8Array", () => {
|
|
18612
|
+
const p3 = addressParser(ChainName.ETHEREUM);
|
|
18613
|
+
const normalized = normalizeHex("0x1234567890abcdef1234567890abcdef12345678");
|
|
18614
|
+
const bytes32Hex = p3.normalizedToBytes32Hex(normalized);
|
|
18615
|
+
const bytes32 = p3.normalizedToBytes32(normalized);
|
|
18616
|
+
globalExpect(bytes32.length).toBe(32);
|
|
18617
|
+
globalExpect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
|
|
18618
|
+
});
|
|
18619
|
+
it("returns undefined for undefined input", () => {
|
|
18620
|
+
const p3 = addressParser(ChainName.ETHEREUM);
|
|
18621
|
+
globalExpect(p3.normalizedToBytes32Hex(void 0)).toBeUndefined();
|
|
18622
|
+
globalExpect(p3.normalizedToBytes32(void 0)).toBeUndefined();
|
|
18623
|
+
});
|
|
18624
|
+
});
|
|
18625
|
+
describe("addressParser - bytes32ToNormalized", () => {
|
|
18626
|
+
const ZERO_BYTES32 = "0x" + "00".repeat(32);
|
|
18627
|
+
describe("round-trip: bytes32ToNormalized(nativeToBytes32Hex(native)) === nativeToNormalized(native)", () => {
|
|
18628
|
+
const cases = [
|
|
18629
|
+
{
|
|
18630
|
+
name: "EVM",
|
|
18631
|
+
chainName: ChainName.ETHEREUM,
|
|
18632
|
+
native: "0x1234567890abcdef1234567890abcdef12345678"
|
|
18633
|
+
},
|
|
18634
|
+
{
|
|
18635
|
+
name: "Solana",
|
|
18636
|
+
chainName: ChainName.SOLANA,
|
|
18637
|
+
native: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
|
|
18638
|
+
},
|
|
18639
|
+
{
|
|
18640
|
+
name: "TON",
|
|
18641
|
+
chainName: ChainName.TON,
|
|
18642
|
+
native: "EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2"
|
|
18643
|
+
},
|
|
18644
|
+
{
|
|
18645
|
+
name: "Initia",
|
|
18646
|
+
chainName: ChainName.INITIA,
|
|
18647
|
+
native: "0x1"
|
|
18648
|
+
},
|
|
18649
|
+
{
|
|
18650
|
+
name: "Starknet",
|
|
18651
|
+
chainName: ChainName.STARKNET,
|
|
18652
|
+
native: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
|
|
18653
|
+
},
|
|
18654
|
+
{
|
|
18655
|
+
name: "Aptos",
|
|
18656
|
+
chainName: ChainName.APTOS,
|
|
18657
|
+
native: "0x1"
|
|
18658
|
+
}
|
|
18659
|
+
];
|
|
18660
|
+
cases.forEach(({ name, chainName, native }) => {
|
|
18661
|
+
it(`${name}: round-trip`, () => {
|
|
18662
|
+
const p3 = addressParser(chainName);
|
|
18663
|
+
const normalized = p3.nativeToNormalized(native);
|
|
18664
|
+
const bytes32Hex = p3.nativeToBytes32Hex(native);
|
|
18665
|
+
globalExpect(p3.bytes32ToNormalized(bytes32Hex)).toBe(normalized);
|
|
18666
|
+
});
|
|
18667
|
+
});
|
|
18668
|
+
it("Stellar contract: round-trip", () => {
|
|
18669
|
+
const p3 = addressParser(ChainName.STELLAR);
|
|
18670
|
+
const contractAddr = "CA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUWDA";
|
|
18671
|
+
const normalized = p3.nativeToNormalized(contractAddr);
|
|
18672
|
+
const bytes32Hex = p3.nativeToBytes32Hex(contractAddr);
|
|
18673
|
+
globalExpect(p3.bytes32ToNormalized(bytes32Hex)).toBe(normalized);
|
|
18674
|
+
});
|
|
18675
|
+
});
|
|
18676
|
+
it("undefined input returns undefined", () => {
|
|
18677
|
+
const p3 = addressParser(ChainName.ETHEREUM);
|
|
18678
|
+
globalExpect(p3.bytes32ToNormalized(void 0)).toBeUndefined();
|
|
18679
|
+
});
|
|
18680
|
+
it("non-Stellar: bytes32ToNative === normalizeHex for same input", () => {
|
|
18681
|
+
const chains = [
|
|
18682
|
+
ChainName.ETHEREUM,
|
|
18683
|
+
ChainName.SOLANA,
|
|
18684
|
+
ChainName.TON,
|
|
18685
|
+
ChainName.STARKNET
|
|
18686
|
+
];
|
|
18687
|
+
const bytes32 = "0x0000000000000000000000001234567890abcdef1234567890abcdef12345678";
|
|
18688
|
+
chains.forEach((chainName) => {
|
|
18689
|
+
globalExpect(addressParser(chainName).bytes32ToNormalized(bytes32)).toBe(normalizeHex(bytes32));
|
|
18690
|
+
});
|
|
18691
|
+
});
|
|
18692
|
+
it("zero bytes32: EVM returns NORMALIZED_HEX_ZERO", () => {
|
|
18693
|
+
const p3 = addressParser(ChainName.ETHEREUM);
|
|
18694
|
+
globalExpect(p3.bytes32ToNormalized(ZERO_BYTES32)).toBe(NORMALIZED_HEX_ZERO);
|
|
18695
|
+
});
|
|
18696
|
+
it("zero bytes32: Stellar returns C-address for zero contract ID (not undefined)", () => {
|
|
18697
|
+
const p3 = addressParser(ChainName.STELLAR);
|
|
18698
|
+
const result = p3.bytes32ToNormalized(ZERO_BYTES32);
|
|
18699
|
+
globalExpect(result).toBeDefined();
|
|
18700
|
+
globalExpect(result).not.toBe(NORMALIZED_HEX_ZERO);
|
|
18701
|
+
});
|
|
18702
|
+
});
|
|
18539
18703
|
/*! Bundled license information:
|
|
18540
18704
|
|
|
18541
18705
|
@vitest/pretty-format/dist/index.js:
|