@layerzerolabs/chain-utils 0.0.67 → 0.0.74

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.
@@ -1,4 +1,4 @@
1
- import { addressParser } from './MR2I35UU.js';
1
+ import { addressParser } from './L4WCMHVM.js';
2
2
  import { __commonJS, init_esm_shims, __name, __require, __toESM } from './YXE7PREU.js';
3
3
  import * as bs58 from 'bs58';
4
4
  import { isatty } from 'tty';
@@ -18174,6 +18174,273 @@ describe("addressParser - TON", () => {
18174
18174
  globalExpect(parser.validateNative("invalid-ton-address")).toBe(false);
18175
18175
  });
18176
18176
  });
18177
+ describe("addressParser - Stellar", () => {
18178
+ const parser = addressParser(ChainName.STELLAR);
18179
+ const validTestAddresses = {
18180
+ // Account address (G...)
18181
+ account: "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ",
18182
+ // Contract address (C...)
18183
+ contract: "CA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUWDA",
18184
+ // Muxed address (M...)
18185
+ muxed: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAACJUQ",
18186
+ // Liquidity pool address (L...)
18187
+ liquidityPool: "LA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUPJN",
18188
+ // Claimable balance address (B...)
18189
+ claimableBalance: "BAAD6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGR4TU",
18190
+ // Signed payload (P...)
18191
+ signedPayload: "PA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAQACAQDAQCQMBYIBEFAWDANBYHRAEISCMKBKFQXDAMRUGY4DUPB6IBZGM"
18192
+ };
18193
+ describe("roundtrip conversions", () => {
18194
+ it("maintains roundtrip invariant for account addresses (G...)", () => {
18195
+ const stellarAddress = validTestAddresses.account;
18196
+ const normalized = parser.nativeToNormalized(stellarAddress);
18197
+ const native = parser.normalizedToNative(normalized);
18198
+ globalExpect(native.nativeAddress).toBe(stellarAddress);
18199
+ globalExpect(native.chainName).toBe(ChainName.STELLAR);
18200
+ });
18201
+ it("maintains roundtrip invariant for contract addresses (C...)", () => {
18202
+ const stellarAddress = validTestAddresses.contract;
18203
+ const normalized = parser.nativeToNormalized(stellarAddress);
18204
+ const native = parser.normalizedToNative(normalized);
18205
+ globalExpect(native.nativeAddress).toBe(stellarAddress);
18206
+ });
18207
+ it("maintains roundtrip invariant for muxed addresses (M...)", () => {
18208
+ const stellarAddress = validTestAddresses.muxed;
18209
+ const normalized = parser.nativeToNormalized(stellarAddress);
18210
+ const native = parser.normalizedToNative(normalized);
18211
+ globalExpect(native.nativeAddress).toBe(stellarAddress);
18212
+ });
18213
+ it("maintains roundtrip invariant for liquidity pool addresses (L...)", () => {
18214
+ const stellarAddress = validTestAddresses.liquidityPool;
18215
+ const normalized = parser.nativeToNormalized(stellarAddress);
18216
+ const native = parser.normalizedToNative(normalized);
18217
+ globalExpect(native.nativeAddress).toBe(stellarAddress);
18218
+ });
18219
+ it("maintains roundtrip invariant for claimable balance addresses (B...)", () => {
18220
+ const stellarAddress = validTestAddresses.claimableBalance;
18221
+ const normalized = parser.nativeToNormalized(stellarAddress);
18222
+ const native = parser.normalizedToNative(normalized);
18223
+ globalExpect(native.nativeAddress).toBe(stellarAddress);
18224
+ });
18225
+ it("maintains roundtrip invariant for signed payload (P...)", () => {
18226
+ const stellarAddress = validTestAddresses.signedPayload;
18227
+ const normalized = parser.nativeToNormalized(stellarAddress);
18228
+ const native = parser.normalizedToNative(normalized);
18229
+ globalExpect(native.nativeAddress).toBe(stellarAddress);
18230
+ });
18231
+ });
18232
+ describe("validation", () => {
18233
+ it("validates all valid Stellar address types", () => {
18234
+ globalExpect(parser.validateNative(validTestAddresses.account)).toBe(true);
18235
+ globalExpect(parser.validateNative(validTestAddresses.contract)).toBe(true);
18236
+ globalExpect(parser.validateNative(validTestAddresses.muxed)).toBe(true);
18237
+ globalExpect(parser.validateNative(validTestAddresses.liquidityPool)).toBe(true);
18238
+ globalExpect(parser.validateNative(validTestAddresses.claimableBalance)).toBe(true);
18239
+ globalExpect(parser.validateNative(validTestAddresses.signedPayload)).toBe(true);
18240
+ });
18241
+ it("rejects invalid Stellar addresses", () => {
18242
+ const invalidAddresses = [
18243
+ "GAAAAAAAACGC6",
18244
+ "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZA",
18245
+ "G47QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVP2I",
18246
+ "invalid-stellar-address",
18247
+ "",
18248
+ "0x1234567890abcdef"
18249
+ ];
18250
+ invalidAddresses.forEach((addr) => {
18251
+ globalExpect(parser.validateNative(addr)).toBe(false);
18252
+ });
18253
+ });
18254
+ it("rejects undefined addresses", () => {
18255
+ globalExpect(parser.validateNative(void 0)).toBe(false);
18256
+ });
18257
+ });
18258
+ describe("ASCII encoding/decoding", () => {
18259
+ it("converts Stellar address to UTF-8 bytes correctly", () => {
18260
+ const stellarAddress = validTestAddresses.account;
18261
+ const bytes = parser.nativeToBytes(stellarAddress);
18262
+ const decoder = new TextDecoder();
18263
+ const decoded = decoder.decode(bytes);
18264
+ globalExpect(decoded).toBe(stellarAddress);
18265
+ });
18266
+ it("preserves address length in byte representation", () => {
18267
+ const accountBytes = parser.nativeToBytes(validTestAddresses.account);
18268
+ globalExpect(accountBytes.length).toBe(56);
18269
+ const muxedBytes = parser.nativeToBytes(validTestAddresses.muxed);
18270
+ globalExpect(muxedBytes.length).toBe(69);
18271
+ const payloadBytes = parser.nativeToBytes(validTestAddresses.signedPayload);
18272
+ globalExpect(payloadBytes.length).toBeGreaterThan(56);
18273
+ });
18274
+ it("normalizedToNativeString returns the address string", () => {
18275
+ const stellarAddress = validTestAddresses.account;
18276
+ const normalized = parser.nativeToNormalized(stellarAddress);
18277
+ const nativeString = parser.normalizedToNativeString(normalized);
18278
+ globalExpect(nativeString).toBe(stellarAddress);
18279
+ });
18280
+ });
18281
+ describe("parseNative", () => {
18282
+ it("parses valid Stellar addresses", () => {
18283
+ const stellarAddress = validTestAddresses.account;
18284
+ const normalized = parser.parseNative(stellarAddress);
18285
+ globalExpect(normalized).toMatch(/^0x[0-9a-f]+$/);
18286
+ });
18287
+ it("throws on invalid addresses", () => {
18288
+ globalExpect(() => parser.parseNative("invalid-stellar-address")).toThrow(/Cannot convert/);
18289
+ });
18290
+ it("parseNativeToUnpaddedHex returns hex string", () => {
18291
+ const stellarAddress = validTestAddresses.account;
18292
+ const hex3 = parser.parseNativeToUnpaddedHex(stellarAddress);
18293
+ globalExpect(hex3).toMatch(/^0x[0-9a-f]+$/);
18294
+ globalExpect(hex3).toBe(parser.parseNative(stellarAddress));
18295
+ });
18296
+ });
18297
+ describe("bytes32 operations", () => {
18298
+ it("decodes account address (G...) to 32 bytes", () => {
18299
+ const stellarAddress = validTestAddresses.account;
18300
+ const bytes32Hex = parser.nativeToBytes32Hex(stellarAddress);
18301
+ const bytes32 = parser.nativeToBytes32(stellarAddress);
18302
+ globalExpect(bytes32Hex.length).toBe(66);
18303
+ globalExpect(bytes32Hex).toMatch(/^0x[0-9a-f]{64}$/);
18304
+ globalExpect(bytes32.length).toBe(32);
18305
+ globalExpect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
18306
+ });
18307
+ it("decodes contract address (C...) to 32 bytes", () => {
18308
+ const stellarAddress = validTestAddresses.contract;
18309
+ const bytes32Hex = parser.nativeToBytes32Hex(stellarAddress);
18310
+ const bytes32 = parser.nativeToBytes32(stellarAddress);
18311
+ globalExpect(bytes32Hex.length).toBe(66);
18312
+ globalExpect(bytes32.length).toBe(32);
18313
+ globalExpect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
18314
+ });
18315
+ it("decodes liquidity pool address (L...) to 32 bytes", () => {
18316
+ const stellarAddress = validTestAddresses.liquidityPool;
18317
+ const bytes32Hex = parser.nativeToBytes32Hex(stellarAddress);
18318
+ const bytes32 = parser.nativeToBytes32(stellarAddress);
18319
+ globalExpect(bytes32Hex.length).toBe(66);
18320
+ globalExpect(bytes32.length).toBe(32);
18321
+ globalExpect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
18322
+ });
18323
+ it("decodes claimable balance address (B...) to 32 bytes (skipping version byte)", () => {
18324
+ const stellarAddress = validTestAddresses.claimableBalance;
18325
+ const bytes32Hex = parser.nativeToBytes32Hex(stellarAddress);
18326
+ const bytes32 = parser.nativeToBytes32(stellarAddress);
18327
+ globalExpect(bytes32Hex.length).toBe(66);
18328
+ globalExpect(bytes32Hex).toMatch(/^0x[0-9a-f]{64}$/);
18329
+ globalExpect(bytes32.length).toBe(32);
18330
+ globalExpect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
18331
+ });
18332
+ it("throws error for muxed address (M...) - not 32 bytes", () => {
18333
+ const stellarAddress = validTestAddresses.muxed;
18334
+ globalExpect(() => parser.nativeToBytes32Hex(stellarAddress)).toThrow(/nativeToBytes32 is not supported for Stellar muxed addresses/);
18335
+ globalExpect(() => parser.nativeToBytes32(stellarAddress)).toThrow(/nativeToBytes32 is not supported for Stellar muxed addresses/);
18336
+ });
18337
+ it("throws error for signed payload (P...) - variable length", () => {
18338
+ const stellarAddress = validTestAddresses.signedPayload;
18339
+ globalExpect(() => parser.nativeToBytes32Hex(stellarAddress)).toThrow(/nativeToBytes32 is not supported for Stellar signed payload addresses/);
18340
+ globalExpect(() => parser.nativeToBytes32(stellarAddress)).toThrow(/nativeToBytes32 is not supported for Stellar signed payload addresses/);
18341
+ });
18342
+ it("returns undefined for undefined input", () => {
18343
+ globalExpect(parser.nativeToBytes32Hex(void 0)).toBeUndefined();
18344
+ globalExpect(parser.nativeToBytes32(void 0)).toBeUndefined();
18345
+ });
18346
+ it("decodes all supported address types to 32 bytes", () => {
18347
+ const accountBytes = parser.nativeToBytes32(validTestAddresses.account);
18348
+ const contractBytes = parser.nativeToBytes32(validTestAddresses.contract);
18349
+ const poolBytes = parser.nativeToBytes32(validTestAddresses.liquidityPool);
18350
+ const balanceBytes = parser.nativeToBytes32(validTestAddresses.claimableBalance);
18351
+ globalExpect(accountBytes.length).toBe(32);
18352
+ globalExpect(contractBytes.length).toBe(32);
18353
+ globalExpect(poolBytes.length).toBe(32);
18354
+ globalExpect(balanceBytes.length).toBe(32);
18355
+ const accountHex = parser.nativeToBytes32Hex(validTestAddresses.account);
18356
+ const contractHex = parser.nativeToBytes32Hex(validTestAddresses.contract);
18357
+ const poolHex = parser.nativeToBytes32Hex(validTestAddresses.liquidityPool);
18358
+ const balanceHex = parser.nativeToBytes32Hex(validTestAddresses.claimableBalance);
18359
+ globalExpect(bytesToHexPrefixed(accountBytes)).toBe(accountHex);
18360
+ globalExpect(bytesToHexPrefixed(contractBytes)).toBe(contractHex);
18361
+ globalExpect(bytesToHexPrefixed(poolBytes)).toBe(poolHex);
18362
+ globalExpect(bytesToHexPrefixed(balanceBytes)).toBe(balanceHex);
18363
+ });
18364
+ it("handles ChainNativeAddress objects for bytes32 operations", () => {
18365
+ const nativeObj = {
18366
+ chainName: ChainName.STELLAR,
18367
+ nativeAddress: validTestAddresses.account
18368
+ };
18369
+ const bytes32Hex = parser.nativeToBytes32Hex(nativeObj);
18370
+ const bytes32 = parser.nativeToBytes32(nativeObj);
18371
+ globalExpect(bytes32Hex.length).toBe(66);
18372
+ globalExpect(bytes32.length).toBe(32);
18373
+ });
18374
+ });
18375
+ describe("address type preservation", () => {
18376
+ it("preserves address type information through conversion", () => {
18377
+ const addresses = [
18378
+ {
18379
+ addr: validTestAddresses.account,
18380
+ prefix: "G"
18381
+ },
18382
+ {
18383
+ addr: validTestAddresses.contract,
18384
+ prefix: "C"
18385
+ },
18386
+ {
18387
+ addr: validTestAddresses.muxed,
18388
+ prefix: "M"
18389
+ },
18390
+ {
18391
+ addr: validTestAddresses.liquidityPool,
18392
+ prefix: "L"
18393
+ },
18394
+ {
18395
+ addr: validTestAddresses.claimableBalance,
18396
+ prefix: "B"
18397
+ },
18398
+ {
18399
+ addr: validTestAddresses.signedPayload,
18400
+ prefix: "P"
18401
+ }
18402
+ ];
18403
+ addresses.forEach(({ addr, prefix }) => {
18404
+ const normalized = parser.nativeToNormalized(addr);
18405
+ const recovered = parser.normalizedToNative(normalized);
18406
+ globalExpect(recovered.nativeAddress.startsWith(prefix)).toBe(true);
18407
+ globalExpect(recovered.nativeAddress).toBe(addr);
18408
+ });
18409
+ });
18410
+ });
18411
+ describe("edge cases", () => {
18412
+ it("handles ChainNativeAddress objects", () => {
18413
+ const nativeObj = {
18414
+ chainName: ChainName.STELLAR,
18415
+ nativeAddress: validTestAddresses.account
18416
+ };
18417
+ const normalized = parser.nativeToNormalized(nativeObj);
18418
+ globalExpect(normalized).toMatch(/^0x[0-9a-f]+$/);
18419
+ });
18420
+ it("returns undefined for undefined inputs", () => {
18421
+ globalExpect(parser.normalizedToNative(void 0)).toBeUndefined();
18422
+ globalExpect(parser.normalizedToNativeString(void 0)).toBeUndefined();
18423
+ globalExpect(parser.nativeToNormalized(void 0)).toBeUndefined();
18424
+ globalExpect(parser.nativeToBytes(void 0)).toBeUndefined();
18425
+ });
18426
+ it("handles different address lengths correctly", () => {
18427
+ const short = validTestAddresses.account;
18428
+ const shortBytes = parser.nativeToBytes(short);
18429
+ globalExpect(shortBytes.length).toBe(56);
18430
+ const medium = validTestAddresses.muxed;
18431
+ const mediumBytes = parser.nativeToBytes(medium);
18432
+ globalExpect(mediumBytes.length).toBe(69);
18433
+ const long = validTestAddresses.signedPayload;
18434
+ const longBytes = parser.nativeToBytes(long);
18435
+ globalExpect(longBytes.length).toBeGreaterThan(69);
18436
+ });
18437
+ });
18438
+ describe("encoding type", () => {
18439
+ it("has STELLAR encoding type", () => {
18440
+ globalExpect(parser.encoding).toBe("stellar");
18441
+ });
18442
+ });
18443
+ });
18177
18444
  /*! Bundled license information:
18178
18445
 
18179
18446
  @vitest/pretty-format/dist/index.js: