@layerzerolabs/chain-utils 0.0.66 → 0.0.73

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.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var K6ILVJZQ_cjs = require('./K6ILVJZQ.cjs');
3
+ var QOTVRPBZ_cjs = require('./QOTVRPBZ.cjs');
4
4
  var NOJYY7DN_cjs = require('./NOJYY7DN.cjs');
5
5
  var J6P5K7DC_cjs = require('./J6P5K7DC.cjs');
6
6
 
@@ -9,27 +9,35 @@ J6P5K7DC_cjs.init_cjs_shims();
9
9
 
10
10
  Object.defineProperty(exports, "AddressEncoding", {
11
11
  enumerable: true,
12
- get: function () { return K6ILVJZQ_cjs.AddressEncoding; }
12
+ get: function () { return QOTVRPBZ_cjs.AddressEncoding; }
13
13
  });
14
14
  Object.defineProperty(exports, "addressParser", {
15
15
  enumerable: true,
16
- get: function () { return K6ILVJZQ_cjs.addressParser; }
16
+ get: function () { return QOTVRPBZ_cjs.addressParser; }
17
17
  });
18
18
  Object.defineProperty(exports, "base58AddressParser", {
19
19
  enumerable: true,
20
- get: function () { return K6ILVJZQ_cjs.base58AddressParser; }
20
+ get: function () { return QOTVRPBZ_cjs.base58AddressParser; }
21
21
  });
22
22
  Object.defineProperty(exports, "hexAddressParser", {
23
23
  enumerable: true,
24
- get: function () { return K6ILVJZQ_cjs.hexAddressParser; }
24
+ get: function () { return QOTVRPBZ_cjs.hexAddressParser; }
25
25
  });
26
26
  Object.defineProperty(exports, "initiaAddressParser", {
27
27
  enumerable: true,
28
- get: function () { return K6ILVJZQ_cjs.initiaAddressParser; }
28
+ get: function () { return QOTVRPBZ_cjs.initiaAddressParser; }
29
+ });
30
+ Object.defineProperty(exports, "starknetAddressParser", {
31
+ enumerable: true,
32
+ get: function () { return QOTVRPBZ_cjs.starknetAddressParser; }
33
+ });
34
+ Object.defineProperty(exports, "stellarAddressParser", {
35
+ enumerable: true,
36
+ get: function () { return QOTVRPBZ_cjs.stellarAddressParser; }
29
37
  });
30
38
  Object.defineProperty(exports, "tonAddressParser", {
31
39
  enumerable: true,
32
- get: function () { return K6ILVJZQ_cjs.tonAddressParser; }
40
+ get: function () { return QOTVRPBZ_cjs.tonAddressParser; }
33
41
  });
34
42
  Object.defineProperty(exports, "getNetworkName", {
35
43
  enumerable: true,
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { AddressEncoding, addressParser, base58AddressParser, hexAddressParser, initiaAddressParser, tonAddressParser } from './MR2I35UU.js';
1
+ export { AddressEncoding, addressParser, base58AddressParser, hexAddressParser, initiaAddressParser, starknetAddressParser, stellarAddressParser, tonAddressParser } from './L4WCMHVM.js';
2
2
  export { getNetworkName } from './FJIAQ3QL.js';
3
3
  import { init_esm_shims } from './YXE7PREU.js';
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/chain-utils",
3
- "version": "0.0.66",
3
+ "version": "0.0.73",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,20 +15,21 @@
15
15
  "types": "./dist/index.d.ts",
16
16
  "dependencies": {
17
17
  "@initia/initia.js": "1.0.4",
18
+ "@stellar/stellar-sdk": "^14.1.1",
18
19
  "@ton/ton": "npm:@layerzerolabs/ton@15.1.0-rc.9",
19
20
  "bs58": "^5.0.0",
20
- "@layerzerolabs/common-ton": "0.0.66",
21
- "@layerzerolabs/common-chain-model": "0.0.66",
22
- "@layerzerolabs/common-utils": "0.0.66",
23
- "@layerzerolabs/layerzero-definitions": "0.0.66",
24
- "@layerzerolabs/static-chain-info": "0.0.66"
21
+ "@layerzerolabs/common-chain-model": "0.0.73",
22
+ "@layerzerolabs/common-ton": "0.0.73",
23
+ "@layerzerolabs/common-utils": "0.0.73",
24
+ "@layerzerolabs/static-chain-info": "0.0.73",
25
+ "@layerzerolabs/layerzero-definitions": "0.0.73"
25
26
  },
26
27
  "devDependencies": {
27
28
  "tsup": "^8.4.0",
28
29
  "vitest": "^3.2.3",
29
- "@layerzerolabs/tsup-configuration": "0.0.66",
30
- "@layerzerolabs/typescript-configuration": "0.0.66",
31
- "@layerzerolabs/typescript-utils": "0.0.66"
30
+ "@layerzerolabs/tsup-configuration": "0.0.73",
31
+ "@layerzerolabs/typescript-configuration": "0.0.73",
32
+ "@layerzerolabs/typescript-utils": "0.0.73"
32
33
  },
33
34
  "publishConfig": {
34
35
  "access": "restricted",
@@ -172,7 +172,7 @@ describe('addressParser - chain validation', () => {
172
172
  const result = parser.nativeToNormalized(randomAddress as any);
173
173
  expect(result).toBe(normalizeHex(randomAddress as any));
174
174
 
175
- const padded = parser.nativeToBytes32Hex(randomAddress as any);
175
+ const padded = parser.nativeToBytes32Hex(randomAddress as any)!;
176
176
  expect(padded.length).toBe(66);
177
177
 
178
178
  const bytes = parser.nativeToBytes(randomAddress as any);
@@ -229,7 +229,7 @@ describe('addressParser - TON', () => {
229
229
  const byteLength = Math.floor(Math.random() * 32) + 1;
230
230
  const input = randomHex(byteLength);
231
231
  const native = parser.normalizedToNativeString(input);
232
- const padded = parser.nativeToBytes32Hex(native);
232
+ const padded = parser.nativeToBytes32Hex(native)!;
233
233
 
234
234
  expect(padded.length).toBe(66); // 32 bytes -> 64 hex chars + 0x
235
235
 
@@ -267,3 +267,351 @@ describe('addressParser - TON', () => {
267
267
  expect(parser.validateNative('invalid-ton-address')).toBe(false);
268
268
  });
269
269
  });
270
+
271
+ describe('addressParser - Stellar', () => {
272
+ const parser = addressParser(ChainName.STELLAR);
273
+
274
+ // Valid test addresses from SEP-0023 specification
275
+ const validTestAddresses = {
276
+ // Account address (G...)
277
+ account: 'GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ',
278
+ // Contract address (C...)
279
+ contract: 'CA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUWDA',
280
+ // Muxed address (M...)
281
+ muxed: 'MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAACJUQ',
282
+ // Liquidity pool address (L...)
283
+ liquidityPool: 'LA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUPJN',
284
+ // Claimable balance address (B...)
285
+ claimableBalance: 'BAAD6DBUX6J22DMZOHIEZTEQ64CVCHEDRKWZONFEUL5Q26QD7R76RGR4TU',
286
+ // Signed payload (P...)
287
+ signedPayload:
288
+ 'PA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAQACAQDAQCQMBYIBEFAWDANBYHRAEISCMKBKFQXDAMRUGY4DUPB6IBZGM',
289
+ };
290
+
291
+ describe('roundtrip conversions', () => {
292
+ it('maintains roundtrip invariant for account addresses (G...)', () => {
293
+ const stellarAddress = validTestAddresses.account;
294
+ const normalized = parser.nativeToNormalized(stellarAddress as any);
295
+ const native = parser.normalizedToNative(normalized)!;
296
+
297
+ expect(native.nativeAddress).toBe(stellarAddress);
298
+ expect(native.chainName).toBe(ChainName.STELLAR);
299
+ });
300
+
301
+ it('maintains roundtrip invariant for contract addresses (C...)', () => {
302
+ const stellarAddress = validTestAddresses.contract;
303
+ const normalized = parser.nativeToNormalized(stellarAddress as any);
304
+ const native = parser.normalizedToNative(normalized)!;
305
+
306
+ expect(native.nativeAddress).toBe(stellarAddress);
307
+ });
308
+
309
+ it('maintains roundtrip invariant for muxed addresses (M...)', () => {
310
+ const stellarAddress = validTestAddresses.muxed;
311
+ const normalized = parser.nativeToNormalized(stellarAddress as any);
312
+ const native = parser.normalizedToNative(normalized)!;
313
+
314
+ expect(native.nativeAddress).toBe(stellarAddress);
315
+ });
316
+
317
+ it('maintains roundtrip invariant for liquidity pool addresses (L...)', () => {
318
+ const stellarAddress = validTestAddresses.liquidityPool;
319
+ const normalized = parser.nativeToNormalized(stellarAddress as any);
320
+ const native = parser.normalizedToNative(normalized)!;
321
+
322
+ expect(native.nativeAddress).toBe(stellarAddress);
323
+ });
324
+
325
+ it('maintains roundtrip invariant for claimable balance addresses (B...)', () => {
326
+ const stellarAddress = validTestAddresses.claimableBalance;
327
+ const normalized = parser.nativeToNormalized(stellarAddress as any);
328
+ const native = parser.normalizedToNative(normalized)!;
329
+
330
+ expect(native.nativeAddress).toBe(stellarAddress);
331
+ });
332
+
333
+ it('maintains roundtrip invariant for signed payload (P...)', () => {
334
+ const stellarAddress = validTestAddresses.signedPayload;
335
+ const normalized = parser.nativeToNormalized(stellarAddress as any);
336
+ const native = parser.normalizedToNative(normalized)!;
337
+
338
+ expect(native.nativeAddress).toBe(stellarAddress);
339
+ });
340
+ });
341
+
342
+ describe('validation', () => {
343
+ it('validates all valid Stellar address types', () => {
344
+ expect(parser.validateNative(validTestAddresses.account)).toBe(true);
345
+ expect(parser.validateNative(validTestAddresses.contract)).toBe(true);
346
+ expect(parser.validateNative(validTestAddresses.muxed)).toBe(true);
347
+ expect(parser.validateNative(validTestAddresses.liquidityPool)).toBe(true);
348
+ expect(parser.validateNative(validTestAddresses.claimableBalance)).toBe(true);
349
+ expect(parser.validateNative(validTestAddresses.signedPayload)).toBe(true);
350
+ });
351
+
352
+ it('rejects invalid Stellar addresses', () => {
353
+ // Invalid addresses from SEP-0023 test cases
354
+ const invalidAddresses = [
355
+ 'GAAAAAAAACGC6', // Invalid length
356
+ 'GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZA', // Invalid length
357
+ 'G47QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVP2I', // Invalid algorithm
358
+ 'invalid-stellar-address',
359
+ '',
360
+ '0x1234567890abcdef', // EVM address
361
+ ];
362
+
363
+ invalidAddresses.forEach((addr) => {
364
+ expect(parser.validateNative(addr)).toBe(false);
365
+ });
366
+ });
367
+
368
+ it('rejects undefined addresses', () => {
369
+ expect(parser.validateNative(undefined)).toBe(false);
370
+ });
371
+ });
372
+
373
+ describe('ASCII encoding/decoding', () => {
374
+ it('converts Stellar address to UTF-8 bytes correctly', () => {
375
+ const stellarAddress = validTestAddresses.account;
376
+ const bytes = parser.nativeToBytes(stellarAddress as any)!;
377
+
378
+ // Verify it's UTF-8 encoded ASCII
379
+ const decoder = new TextDecoder();
380
+ const decoded = decoder.decode(bytes);
381
+ expect(decoded).toBe(stellarAddress);
382
+ });
383
+
384
+ it('preserves address length in byte representation', () => {
385
+ // Account address (56 chars)
386
+ const accountBytes = parser.nativeToBytes(validTestAddresses.account as any)!;
387
+ expect(accountBytes.length).toBe(56);
388
+
389
+ // Muxed address (69 chars)
390
+ const muxedBytes = parser.nativeToBytes(validTestAddresses.muxed as any)!;
391
+ expect(muxedBytes.length).toBe(69);
392
+
393
+ // Signed payload (variable length)
394
+ const payloadBytes = parser.nativeToBytes(validTestAddresses.signedPayload as any)!;
395
+ expect(payloadBytes.length).toBeGreaterThan(56);
396
+ });
397
+
398
+ it('normalizedToNativeString returns the address string', () => {
399
+ const stellarAddress = validTestAddresses.account;
400
+ const normalized = parser.nativeToNormalized(stellarAddress as any);
401
+ const nativeString = parser.normalizedToNativeString(normalized);
402
+
403
+ expect(nativeString).toBe(stellarAddress);
404
+ });
405
+ });
406
+
407
+ describe('parseNative', () => {
408
+ it('parses valid Stellar addresses', () => {
409
+ const stellarAddress = validTestAddresses.account;
410
+ const normalized = parser.parseNative(stellarAddress as any);
411
+
412
+ // Should return normalized hex representation
413
+ expect(normalized).toMatch(/^0x[0-9a-f]+$/);
414
+ });
415
+
416
+ it('throws on invalid addresses', () => {
417
+ expect(() => parser.parseNative('invalid-stellar-address' as any)).toThrow(
418
+ /Cannot convert/,
419
+ );
420
+ });
421
+
422
+ it('parseNativeToUnpaddedHex returns hex string', () => {
423
+ const stellarAddress = validTestAddresses.account;
424
+ const hex = parser.parseNativeToUnpaddedHex(stellarAddress as any);
425
+
426
+ expect(hex).toMatch(/^0x[0-9a-f]+$/);
427
+ expect(hex).toBe(parser.parseNative(stellarAddress as any));
428
+ });
429
+ });
430
+
431
+ describe('bytes32 operations', () => {
432
+ it('decodes account address (G...) to 32 bytes', () => {
433
+ const stellarAddress = validTestAddresses.account;
434
+ const bytes32Hex = parser.nativeToBytes32Hex(stellarAddress as any)!;
435
+ const bytes32 = parser.nativeToBytes32(stellarAddress as any)!;
436
+
437
+ // Should be 32 bytes (64 hex chars + 0x)
438
+ expect(bytes32Hex.length).toBe(66);
439
+ expect(bytes32Hex).toMatch(/^0x[0-9a-f]{64}$/);
440
+
441
+ // Bytes should be 32 bytes
442
+ expect(bytes32.length).toBe(32);
443
+
444
+ // Both methods should produce consistent results
445
+ expect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
446
+ });
447
+
448
+ it('decodes contract address (C...) to 32 bytes', () => {
449
+ const stellarAddress = validTestAddresses.contract;
450
+ const bytes32Hex = parser.nativeToBytes32Hex(stellarAddress as any)!;
451
+ const bytes32 = parser.nativeToBytes32(stellarAddress as any)!;
452
+
453
+ expect(bytes32Hex.length).toBe(66);
454
+ expect(bytes32.length).toBe(32);
455
+ expect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
456
+ });
457
+
458
+ it('decodes liquidity pool address (L...) to 32 bytes', () => {
459
+ const stellarAddress = validTestAddresses.liquidityPool;
460
+ const bytes32Hex = parser.nativeToBytes32Hex(stellarAddress as any)!;
461
+ const bytes32 = parser.nativeToBytes32(stellarAddress as any)!;
462
+
463
+ expect(bytes32Hex.length).toBe(66);
464
+ expect(bytes32.length).toBe(32);
465
+ expect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
466
+ });
467
+
468
+ it('decodes claimable balance address (B...) to 32 bytes (skipping version byte)', () => {
469
+ const stellarAddress = validTestAddresses.claimableBalance;
470
+ const bytes32Hex = parser.nativeToBytes32Hex(stellarAddress as any)!;
471
+ const bytes32 = parser.nativeToBytes32(stellarAddress as any)!;
472
+
473
+ // Should be 32 bytes (64 hex chars + 0x)
474
+ expect(bytes32Hex.length).toBe(66);
475
+ expect(bytes32Hex).toMatch(/^0x[0-9a-f]{64}$/);
476
+
477
+ // Bytes should be 32 bytes (the hash, without the version byte)
478
+ expect(bytes32.length).toBe(32);
479
+
480
+ // Both methods should produce consistent results
481
+ expect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
482
+ });
483
+
484
+ it('throws error for muxed address (M...) - not 32 bytes', () => {
485
+ const stellarAddress = validTestAddresses.muxed;
486
+
487
+ expect(() => parser.nativeToBytes32Hex(stellarAddress as any)).toThrow(
488
+ /nativeToBytes32 is not supported for Stellar muxed addresses/,
489
+ );
490
+ expect(() => parser.nativeToBytes32(stellarAddress as any)).toThrow(
491
+ /nativeToBytes32 is not supported for Stellar muxed addresses/,
492
+ );
493
+ });
494
+
495
+ it('throws error for signed payload (P...) - variable length', () => {
496
+ const stellarAddress = validTestAddresses.signedPayload;
497
+
498
+ expect(() => parser.nativeToBytes32Hex(stellarAddress as any)).toThrow(
499
+ /nativeToBytes32 is not supported for Stellar signed payload addresses/,
500
+ );
501
+ expect(() => parser.nativeToBytes32(stellarAddress as any)).toThrow(
502
+ /nativeToBytes32 is not supported for Stellar signed payload addresses/,
503
+ );
504
+ });
505
+
506
+ it('returns undefined for undefined input', () => {
507
+ expect(parser.nativeToBytes32Hex(undefined as any)).toBeUndefined();
508
+ expect(parser.nativeToBytes32(undefined as any)).toBeUndefined();
509
+ });
510
+
511
+ it('decodes all supported address types to 32 bytes', () => {
512
+ // Account (G), contract (C), liquidity pool (L), and claimable balance (B) addresses can be converted to 32 bytes
513
+ const accountBytes = parser.nativeToBytes32(validTestAddresses.account as any)!;
514
+ const contractBytes = parser.nativeToBytes32(validTestAddresses.contract as any)!;
515
+ const poolBytes = parser.nativeToBytes32(validTestAddresses.liquidityPool as any)!;
516
+ const balanceBytes = parser.nativeToBytes32(
517
+ validTestAddresses.claimableBalance as any,
518
+ )!;
519
+
520
+ // All should be exactly 32 bytes
521
+ expect(accountBytes.length).toBe(32);
522
+ expect(contractBytes.length).toBe(32);
523
+ expect(poolBytes.length).toBe(32);
524
+ expect(balanceBytes.length).toBe(32);
525
+
526
+ // Should produce consistent hex conversions
527
+ const accountHex = parser.nativeToBytes32Hex(validTestAddresses.account as any)!;
528
+ const contractHex = parser.nativeToBytes32Hex(validTestAddresses.contract as any)!;
529
+ const poolHex = parser.nativeToBytes32Hex(validTestAddresses.liquidityPool as any)!;
530
+ const balanceHex = parser.nativeToBytes32Hex(
531
+ validTestAddresses.claimableBalance as any,
532
+ )!;
533
+
534
+ expect(bytesToHexPrefixed(accountBytes)).toBe(accountHex);
535
+ expect(bytesToHexPrefixed(contractBytes)).toBe(contractHex);
536
+ expect(bytesToHexPrefixed(poolBytes)).toBe(poolHex);
537
+ expect(bytesToHexPrefixed(balanceBytes)).toBe(balanceHex);
538
+ });
539
+
540
+ it('handles ChainNativeAddress objects for bytes32 operations', () => {
541
+ const nativeObj = {
542
+ chainName: ChainName.STELLAR,
543
+ nativeAddress: validTestAddresses.account,
544
+ };
545
+
546
+ const bytes32Hex = parser.nativeToBytes32Hex(nativeObj as any)!;
547
+ const bytes32 = parser.nativeToBytes32(nativeObj as any)!;
548
+
549
+ expect(bytes32Hex.length).toBe(66);
550
+ expect(bytes32.length).toBe(32);
551
+ });
552
+ });
553
+
554
+ describe('address type preservation', () => {
555
+ it('preserves address type information through conversion', () => {
556
+ const addresses = [
557
+ { addr: validTestAddresses.account, prefix: 'G' },
558
+ { addr: validTestAddresses.contract, prefix: 'C' },
559
+ { addr: validTestAddresses.muxed, prefix: 'M' },
560
+ { addr: validTestAddresses.liquidityPool, prefix: 'L' },
561
+ { addr: validTestAddresses.claimableBalance, prefix: 'B' },
562
+ { addr: validTestAddresses.signedPayload, prefix: 'P' },
563
+ ];
564
+
565
+ addresses.forEach(({ addr, prefix }) => {
566
+ const normalized = parser.nativeToNormalized(addr as any);
567
+ const recovered = parser.normalizedToNative(normalized)!;
568
+
569
+ // Should preserve the prefix indicating address type
570
+ expect(recovered.nativeAddress.startsWith(prefix)).toBe(true);
571
+ expect(recovered.nativeAddress).toBe(addr);
572
+ });
573
+ });
574
+ });
575
+
576
+ describe('edge cases', () => {
577
+ it('handles ChainNativeAddress objects', () => {
578
+ const nativeObj = {
579
+ chainName: ChainName.STELLAR,
580
+ nativeAddress: validTestAddresses.account,
581
+ };
582
+
583
+ const normalized = parser.nativeToNormalized(nativeObj as any);
584
+ expect(normalized).toMatch(/^0x[0-9a-f]+$/);
585
+ });
586
+
587
+ it('returns undefined for undefined inputs', () => {
588
+ expect(parser.normalizedToNative(undefined as any)).toBeUndefined();
589
+ expect(parser.normalizedToNativeString(undefined as any)).toBeUndefined();
590
+ expect(parser.nativeToNormalized(undefined as any)).toBeUndefined();
591
+ expect(parser.nativeToBytes(undefined as any)).toBeUndefined();
592
+ });
593
+
594
+ it('handles different address lengths correctly', () => {
595
+ // 56-char addresses
596
+ const short = validTestAddresses.account;
597
+ const shortBytes = parser.nativeToBytes(short as any)!;
598
+ expect(shortBytes.length).toBe(56);
599
+
600
+ // 69-char addresses (muxed)
601
+ const medium = validTestAddresses.muxed;
602
+ const mediumBytes = parser.nativeToBytes(medium as any)!;
603
+ expect(mediumBytes.length).toBe(69);
604
+
605
+ // Variable-length (signed payload)
606
+ const long = validTestAddresses.signedPayload;
607
+ const longBytes = parser.nativeToBytes(long as any)!;
608
+ expect(longBytes.length).toBeGreaterThan(69);
609
+ });
610
+ });
611
+
612
+ describe('encoding type', () => {
613
+ it('has STELLAR encoding type', () => {
614
+ expect(parser.encoding).toBe('stellar');
615
+ });
616
+ });
617
+ });