@layerzerolabs/chain-utils 0.2.58 → 0.2.59
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 +19 -19
- 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
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var X46YPLVF_cjs = require('./X46YPLVF.cjs');
|
|
4
4
|
var KHVGLVR5_cjs = require('./KHVGLVR5.cjs');
|
|
5
5
|
|
|
6
6
|
// src/index.ts
|
|
@@ -8,35 +8,35 @@ KHVGLVR5_cjs.init_cjs_shims();
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, "AddressEncoding", {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return X46YPLVF_cjs.AddressEncoding; }
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "addressParser", {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
15
|
+
get: function () { return X46YPLVF_cjs.addressParser; }
|
|
16
16
|
});
|
|
17
17
|
Object.defineProperty(exports, "base58AddressParser", {
|
|
18
18
|
enumerable: true,
|
|
19
|
-
get: function () { return
|
|
19
|
+
get: function () { return X46YPLVF_cjs.base58AddressParser; }
|
|
20
20
|
});
|
|
21
21
|
Object.defineProperty(exports, "hexAddressParser", {
|
|
22
22
|
enumerable: true,
|
|
23
|
-
get: function () { return
|
|
23
|
+
get: function () { return X46YPLVF_cjs.hexAddressParser; }
|
|
24
24
|
});
|
|
25
25
|
Object.defineProperty(exports, "initiaAddressParser", {
|
|
26
26
|
enumerable: true,
|
|
27
|
-
get: function () { return
|
|
27
|
+
get: function () { return X46YPLVF_cjs.initiaAddressParser; }
|
|
28
28
|
});
|
|
29
29
|
Object.defineProperty(exports, "starknetAddressParser", {
|
|
30
30
|
enumerable: true,
|
|
31
|
-
get: function () { return
|
|
31
|
+
get: function () { return X46YPLVF_cjs.starknetAddressParser; }
|
|
32
32
|
});
|
|
33
33
|
Object.defineProperty(exports, "stellarAddressParser", {
|
|
34
34
|
enumerable: true,
|
|
35
|
-
get: function () { return
|
|
35
|
+
get: function () { return X46YPLVF_cjs.stellarAddressParser; }
|
|
36
36
|
});
|
|
37
37
|
Object.defineProperty(exports, "tonAddressParser", {
|
|
38
38
|
enumerable: true,
|
|
39
|
-
get: function () { return
|
|
39
|
+
get: function () { return X46YPLVF_cjs.tonAddressParser; }
|
|
40
40
|
});
|
|
41
41
|
//# sourceMappingURL=index.cjs.map
|
|
42
42
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AddressEncoding, addressParser, base58AddressParser, hexAddressParser, initiaAddressParser, starknetAddressParser, stellarAddressParser, tonAddressParser } from './
|
|
1
|
+
export { AddressEncoding, addressParser, base58AddressParser, hexAddressParser, initiaAddressParser, starknetAddressParser, stellarAddressParser, tonAddressParser } from './OVN7SCH2.js';
|
|
2
2
|
import { init_esm_shims } from './CWKWODSW.js';
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/chain-utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.59",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"@stellar/stellar-sdk": "^14.1.1",
|
|
19
19
|
"@ton/ton": "npm:@layerzerolabs/ton@15.1.0-rc.9",
|
|
20
20
|
"bs58": "^5.0.0",
|
|
21
|
-
"@layerzerolabs/common-chain-model": "0.2.
|
|
22
|
-
"@layerzerolabs/common-encoding-utils": "0.2.
|
|
23
|
-
"@layerzerolabs/
|
|
24
|
-
"@layerzerolabs/
|
|
25
|
-
"@layerzerolabs/static-chain-info": "0.2.
|
|
21
|
+
"@layerzerolabs/common-chain-model": "0.2.59",
|
|
22
|
+
"@layerzerolabs/common-encoding-utils": "0.2.59",
|
|
23
|
+
"@layerzerolabs/layerzero-definitions": "0.2.59",
|
|
24
|
+
"@layerzerolabs/common-ton": "0.2.59",
|
|
25
|
+
"@layerzerolabs/static-chain-info": "0.2.59"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"tsup": "^8.4.0",
|
|
29
29
|
"vitest": "^3.2.3",
|
|
30
|
-
"@layerzerolabs/tsup-configuration": "0.2.
|
|
31
|
-
"@layerzerolabs/typescript-
|
|
32
|
-
"@layerzerolabs/typescript-
|
|
30
|
+
"@layerzerolabs/tsup-configuration": "0.2.59",
|
|
31
|
+
"@layerzerolabs/typescript-utils": "0.2.59",
|
|
32
|
+
"@layerzerolabs/typescript-configuration": "0.2.59"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "restricted",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as bs58 from 'bs58';
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import type { NormalizedHexString } from '@layerzerolabs/common-chain-model';
|
|
5
|
-
import { normalizeHex } from '@layerzerolabs/common-chain-model';
|
|
4
|
+
import type { HexString, NormalizedHexString } from '@layerzerolabs/common-chain-model';
|
|
5
|
+
import { NORMALIZED_HEX_ZERO, normalizeHex } from '@layerzerolabs/common-chain-model';
|
|
6
6
|
import { bytesToHexPrefixed, hexToBytes, hexZeroPad } from '@layerzerolabs/common-encoding-utils';
|
|
7
7
|
import { ChainName } from '@layerzerolabs/layerzero-definitions';
|
|
8
8
|
|
|
@@ -70,7 +70,7 @@ describe('addressParser - hex/EVM chains', () => {
|
|
|
70
70
|
runPropertyTest(() => {
|
|
71
71
|
const byteLength = Math.floor(Math.random() * 32) + 1; // 1-32 bytes
|
|
72
72
|
const input = randomHex(byteLength);
|
|
73
|
-
const padded = addressParser.normalizedToBytes32Hex(input);
|
|
73
|
+
const padded = addressParser(ChainName.ETHEREUM).normalizedToBytes32Hex(input);
|
|
74
74
|
expect(padded.length).toBe(66); // 32 bytes -> 64 hex chars + 0x
|
|
75
75
|
expect(padded).toBe(hexZeroPad(input as any, 32));
|
|
76
76
|
});
|
|
@@ -551,6 +551,29 @@ describe('addressParser - Stellar', () => {
|
|
|
551
551
|
});
|
|
552
552
|
});
|
|
553
553
|
|
|
554
|
+
describe('normalizedToBytes32 operations', () => {
|
|
555
|
+
it('produces same result as nativeToBytes32Hex for contract address (C...)', () => {
|
|
556
|
+
const stellarAddress = validTestAddresses.contract;
|
|
557
|
+
const normalized = parser.nativeToNormalized(stellarAddress as any);
|
|
558
|
+
|
|
559
|
+
const fromNative = parser.nativeToBytes32Hex(stellarAddress as any)!;
|
|
560
|
+
const fromNormalized = parser.normalizedToBytes32Hex(normalized)!;
|
|
561
|
+
|
|
562
|
+
expect(fromNormalized).toBe(fromNative);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it('normalizedToBytes32 returns correct Uint8Array', () => {
|
|
566
|
+
const stellarAddress = validTestAddresses.account;
|
|
567
|
+
const normalized = parser.nativeToNormalized(stellarAddress as any);
|
|
568
|
+
|
|
569
|
+
const bytes32Hex = parser.normalizedToBytes32Hex(normalized)!;
|
|
570
|
+
const bytes32 = parser.normalizedToBytes32(normalized)!;
|
|
571
|
+
|
|
572
|
+
expect(bytes32.length).toBe(32);
|
|
573
|
+
expect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
|
|
554
577
|
describe('address type preservation', () => {
|
|
555
578
|
it('preserves address type information through conversion', () => {
|
|
556
579
|
const addresses = [
|
|
@@ -615,3 +638,158 @@ describe('addressParser - Stellar', () => {
|
|
|
615
638
|
});
|
|
616
639
|
});
|
|
617
640
|
});
|
|
641
|
+
|
|
642
|
+
describe('addressParser - normalizedToBytes32Hex (cross-chain)', () => {
|
|
643
|
+
const testCases: { name: string; chainName: ChainName; nativeAddr: string }[] = [
|
|
644
|
+
{
|
|
645
|
+
name: 'EVM (Ethereum)',
|
|
646
|
+
chainName: ChainName.ETHEREUM,
|
|
647
|
+
nativeAddr: '0x1234567890abcdef1234567890abcdef12345678',
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
name: 'Solana',
|
|
651
|
+
chainName: ChainName.SOLANA,
|
|
652
|
+
nativeAddr: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
name: 'TON',
|
|
656
|
+
chainName: ChainName.TON,
|
|
657
|
+
nativeAddr: 'EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2',
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
name: 'Stellar',
|
|
661
|
+
chainName: ChainName.STELLAR,
|
|
662
|
+
nativeAddr: 'GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7',
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
name: 'Aptos',
|
|
666
|
+
chainName: ChainName.APTOS,
|
|
667
|
+
nativeAddr: '0x1',
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
name: 'Starknet',
|
|
671
|
+
chainName: ChainName.STARKNET,
|
|
672
|
+
nativeAddr: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
name: 'Initia',
|
|
676
|
+
chainName: ChainName.INITIA,
|
|
677
|
+
nativeAddr: '0x1',
|
|
678
|
+
},
|
|
679
|
+
];
|
|
680
|
+
|
|
681
|
+
testCases.forEach(({ name, chainName, nativeAddr }) => {
|
|
682
|
+
it(`${name}: normalizedToBytes32Hex(normalized) === nativeToBytes32Hex(native)`, () => {
|
|
683
|
+
const p = addressParser(chainName);
|
|
684
|
+
const normalized = p.nativeToNormalized(nativeAddr as any);
|
|
685
|
+
|
|
686
|
+
const fromNormalized = p.normalizedToBytes32Hex(normalized)!;
|
|
687
|
+
const fromNative = p.nativeToBytes32Hex(nativeAddr as any)!;
|
|
688
|
+
|
|
689
|
+
expect(fromNormalized).toBe(fromNative);
|
|
690
|
+
expect(fromNormalized.length).toBe(66);
|
|
691
|
+
expect(fromNormalized).toMatch(/^0x[0-9a-f]{64}$/);
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
it('normalizedToBytes32Hex is consistent across chain parsers for ≤32 byte hex', () => {
|
|
696
|
+
const evmParser = addressParser(ChainName.ETHEREUM);
|
|
697
|
+
const solanaParser = addressParser(ChainName.SOLANA);
|
|
698
|
+
const normalized = normalizeHex('0x1234567890abcdef1234567890abcdef12345678');
|
|
699
|
+
expect(evmParser.normalizedToBytes32Hex(normalized)).toBe(
|
|
700
|
+
solanaParser.normalizedToBytes32Hex(normalized),
|
|
701
|
+
);
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
it('normalizedToBytes32 returns correct Uint8Array', () => {
|
|
705
|
+
const p = addressParser(ChainName.ETHEREUM);
|
|
706
|
+
const normalized = normalizeHex('0x1234567890abcdef1234567890abcdef12345678');
|
|
707
|
+
const bytes32Hex = p.normalizedToBytes32Hex(normalized)!;
|
|
708
|
+
const bytes32 = p.normalizedToBytes32(normalized)!;
|
|
709
|
+
expect(bytes32.length).toBe(32);
|
|
710
|
+
expect(bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
it('returns undefined for undefined input', () => {
|
|
714
|
+
const p = addressParser(ChainName.ETHEREUM);
|
|
715
|
+
expect(p.normalizedToBytes32Hex(undefined as any)).toBeUndefined();
|
|
716
|
+
expect(p.normalizedToBytes32(undefined as any)).toBeUndefined();
|
|
717
|
+
});
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
describe('addressParser - bytes32ToNormalized', () => {
|
|
721
|
+
const ZERO_BYTES32 = ('0x' + '00'.repeat(32)) as HexString;
|
|
722
|
+
|
|
723
|
+
describe('round-trip: bytes32ToNormalized(nativeToBytes32Hex(native)) === nativeToNormalized(native)', () => {
|
|
724
|
+
const cases = [
|
|
725
|
+
{
|
|
726
|
+
name: 'EVM',
|
|
727
|
+
chainName: ChainName.ETHEREUM,
|
|
728
|
+
native: '0x1234567890abcdef1234567890abcdef12345678',
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
name: 'Solana',
|
|
732
|
+
chainName: ChainName.SOLANA,
|
|
733
|
+
native: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
name: 'TON',
|
|
737
|
+
chainName: ChainName.TON,
|
|
738
|
+
native: 'EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2',
|
|
739
|
+
},
|
|
740
|
+
{ name: 'Initia', chainName: ChainName.INITIA, native: '0x1' },
|
|
741
|
+
{
|
|
742
|
+
name: 'Starknet',
|
|
743
|
+
chainName: ChainName.STARKNET,
|
|
744
|
+
native: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
|
|
745
|
+
},
|
|
746
|
+
{ name: 'Aptos', chainName: ChainName.APTOS, native: '0x1' },
|
|
747
|
+
];
|
|
748
|
+
|
|
749
|
+
cases.forEach(({ name, chainName, native }) => {
|
|
750
|
+
it(`${name}: round-trip`, () => {
|
|
751
|
+
const p = addressParser(chainName);
|
|
752
|
+
const normalized = p.nativeToNormalized(native as any);
|
|
753
|
+
const bytes32Hex = p.nativeToBytes32Hex(native as any)!;
|
|
754
|
+
expect(p.bytes32ToNormalized(bytes32Hex)).toBe(normalized);
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
it('Stellar contract: round-trip', () => {
|
|
759
|
+
const p = addressParser(ChainName.STELLAR);
|
|
760
|
+
const contractAddr = 'CA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUWDA';
|
|
761
|
+
const normalized = p.nativeToNormalized(contractAddr as any);
|
|
762
|
+
const bytes32Hex = p.nativeToBytes32Hex(contractAddr as any)!;
|
|
763
|
+
expect(p.bytes32ToNormalized(bytes32Hex)).toBe(normalized);
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
it('undefined input returns undefined', () => {
|
|
768
|
+
const p = addressParser(ChainName.ETHEREUM);
|
|
769
|
+
expect(p.bytes32ToNormalized(undefined as any)).toBeUndefined();
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
it('non-Stellar: bytes32ToNative === normalizeHex for same input', () => {
|
|
773
|
+
const chains = [ChainName.ETHEREUM, ChainName.SOLANA, ChainName.TON, ChainName.STARKNET];
|
|
774
|
+
const bytes32 =
|
|
775
|
+
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678' as HexString;
|
|
776
|
+
chains.forEach((chainName) => {
|
|
777
|
+
expect(addressParser(chainName).bytes32ToNormalized(bytes32)).toBe(
|
|
778
|
+
normalizeHex(bytes32),
|
|
779
|
+
);
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
it('zero bytes32: EVM returns NORMALIZED_HEX_ZERO', () => {
|
|
784
|
+
const p = addressParser(ChainName.ETHEREUM);
|
|
785
|
+
expect(p.bytes32ToNormalized(ZERO_BYTES32)).toBe(NORMALIZED_HEX_ZERO);
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
it('zero bytes32: Stellar returns C-address for zero contract ID (not undefined)', () => {
|
|
789
|
+
const p = addressParser(ChainName.STELLAR);
|
|
790
|
+
const result = p.bytes32ToNormalized(ZERO_BYTES32);
|
|
791
|
+
// Should be a valid C-address string encoded as UTF-8 normalized hex, not undefined
|
|
792
|
+
expect(result).toBeDefined();
|
|
793
|
+
expect(result).not.toBe(NORMALIZED_HEX_ZERO);
|
|
794
|
+
});
|
|
795
|
+
});
|
package/src/addressParser.ts
CHANGED
|
@@ -69,6 +69,15 @@ export type AddressParser<T extends ChainName> = {
|
|
|
69
69
|
nativeToBytes32: <Address extends NativeOrString<T> | undefined>(
|
|
70
70
|
nativeAddress: Address,
|
|
71
71
|
) => MaybeUndefinedMapped<Address, Uint8Array>;
|
|
72
|
+
normalizedToBytes32Hex: <Address extends NormalizedHexString | undefined>(
|
|
73
|
+
address: Address,
|
|
74
|
+
) => MaybeUndefinedMapped<Address, HexString>;
|
|
75
|
+
normalizedToBytes32: <Address extends NormalizedHexString | undefined>(
|
|
76
|
+
address: Address,
|
|
77
|
+
) => MaybeUndefinedMapped<Address, Uint8Array>;
|
|
78
|
+
bytes32ToNormalized: <B extends HexString | undefined>(
|
|
79
|
+
bytes32Hex: B,
|
|
80
|
+
) => MaybeUndefinedMapped<B, NormalizedHexString>;
|
|
72
81
|
validateNative: (
|
|
73
82
|
nativeAddress: string | undefined,
|
|
74
83
|
) => nativeAddress is ResolvedEncodingForChainName<T>;
|
|
@@ -99,18 +108,10 @@ export function addressParser<T extends ChainName>(chainName: T): AddressParser<
|
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
export namespace addressParser {
|
|
102
|
-
export const normalizedToBytes32Hex = (address: NormalizedHexString) => {
|
|
103
|
-
return hexZeroPad(address as unknown as HexString, 32);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
111
|
export const normalizedToUnpaddedString = (address: NormalizedHexString) => {
|
|
107
112
|
return address.toString() as HexString;
|
|
108
113
|
};
|
|
109
114
|
|
|
110
|
-
export const normalizedToBytes32 = (address: NormalizedHexString) => {
|
|
111
|
-
return hexToBytes(normalizedToBytes32Hex(address));
|
|
112
|
-
};
|
|
113
|
-
|
|
114
115
|
export const normalizedToBigInt = (address: NormalizedHexString) => {
|
|
115
116
|
return BigInt(address as unknown as HexString);
|
|
116
117
|
};
|
|
@@ -188,6 +189,18 @@ export const tonAddressParser: (
|
|
|
188
189
|
if (nativeAddress === undefined) return undefined as any;
|
|
189
190
|
return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));
|
|
190
191
|
},
|
|
192
|
+
normalizedToBytes32Hex: (address) => {
|
|
193
|
+
if (address === undefined) return undefined as any;
|
|
194
|
+
return hexZeroPad(address as unknown as HexString, 32);
|
|
195
|
+
},
|
|
196
|
+
normalizedToBytes32: (address) => {
|
|
197
|
+
if (address === undefined) return undefined as any;
|
|
198
|
+
return hexToBytes(addressParser(chainName).normalizedToBytes32Hex(address));
|
|
199
|
+
},
|
|
200
|
+
bytes32ToNormalized: (bytes32Hex) => {
|
|
201
|
+
if (bytes32Hex === undefined) return undefined as any;
|
|
202
|
+
return normalizeHex(bytes32Hex);
|
|
203
|
+
},
|
|
191
204
|
parseNative: (nativeAddress) => {
|
|
192
205
|
assertNative(nativeAddress, chainName);
|
|
193
206
|
return addressParser(chainName).nativeToNormalized(nativeAddress);
|
|
@@ -258,6 +271,18 @@ export const initiaAddressParser: (
|
|
|
258
271
|
if (nativeAddress === undefined) return undefined as any;
|
|
259
272
|
return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));
|
|
260
273
|
},
|
|
274
|
+
normalizedToBytes32Hex: (address) => {
|
|
275
|
+
if (address === undefined) return undefined as any;
|
|
276
|
+
return hexZeroPad(address as unknown as HexString, 32);
|
|
277
|
+
},
|
|
278
|
+
normalizedToBytes32: (address) => {
|
|
279
|
+
if (address === undefined) return undefined as any;
|
|
280
|
+
return hexToBytes(addressParser(chainName).normalizedToBytes32Hex(address));
|
|
281
|
+
},
|
|
282
|
+
bytes32ToNormalized: (bytes32Hex) => {
|
|
283
|
+
if (bytes32Hex === undefined) return undefined as any;
|
|
284
|
+
return normalizeHex(bytes32Hex);
|
|
285
|
+
},
|
|
261
286
|
parseNative: (nativeAddress) => {
|
|
262
287
|
assertNative(nativeAddress, chainName);
|
|
263
288
|
return addressParser(chainName).nativeToNormalized(nativeAddress);
|
|
@@ -315,6 +340,18 @@ export const base58AddressParser = (
|
|
|
315
340
|
if (nativeAddress === undefined) return undefined as any;
|
|
316
341
|
return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));
|
|
317
342
|
},
|
|
343
|
+
normalizedToBytes32Hex: (address) => {
|
|
344
|
+
if (address === undefined) return undefined as any;
|
|
345
|
+
return hexZeroPad(address as unknown as HexString, 32);
|
|
346
|
+
},
|
|
347
|
+
normalizedToBytes32: (address) => {
|
|
348
|
+
if (address === undefined) return undefined as any;
|
|
349
|
+
return hexToBytes(addressParser(chainName).normalizedToBytes32Hex(address));
|
|
350
|
+
},
|
|
351
|
+
bytes32ToNormalized: (bytes32Hex) => {
|
|
352
|
+
if (bytes32Hex === undefined) return undefined as any;
|
|
353
|
+
return normalizeHex(bytes32Hex);
|
|
354
|
+
},
|
|
318
355
|
parseNative: (nativeAddress) => {
|
|
319
356
|
assertNative(nativeAddress, chainName);
|
|
320
357
|
return addressParser(chainName).nativeToNormalized(nativeAddress);
|
|
@@ -372,6 +409,18 @@ export const hexAddressParser = (
|
|
|
372
409
|
if (nativeAddress === undefined) return undefined as any;
|
|
373
410
|
return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));
|
|
374
411
|
},
|
|
412
|
+
normalizedToBytes32Hex: (address) => {
|
|
413
|
+
if (address === undefined) return undefined as any;
|
|
414
|
+
return hexZeroPad(address as unknown as HexString, 32);
|
|
415
|
+
},
|
|
416
|
+
normalizedToBytes32: (address) => {
|
|
417
|
+
if (address === undefined) return undefined as any;
|
|
418
|
+
return hexToBytes(addressParser(chainName).normalizedToBytes32Hex(address));
|
|
419
|
+
},
|
|
420
|
+
bytes32ToNormalized: (bytes32Hex) => {
|
|
421
|
+
if (bytes32Hex === undefined) return undefined as any;
|
|
422
|
+
return normalizeHex(bytes32Hex);
|
|
423
|
+
},
|
|
375
424
|
parseNative: (nativeAddress) => {
|
|
376
425
|
// Specific case to make tron a little less flaky, handle the 41 prefix
|
|
377
426
|
if (chainName === ChainName.TRON && nativeAddress) {
|
|
@@ -390,6 +439,27 @@ export const hexAddressParser = (
|
|
|
390
439
|
};
|
|
391
440
|
};
|
|
392
441
|
|
|
442
|
+
const BYTES32_HEX_LENGTH = 64;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* If the input is a 0x-prefixed bytes32 hex string (raw contract ID),
|
|
446
|
+
* convert it to native Stellar base32 format. Only accepts exactly
|
|
447
|
+
* 32 bytes (64 hex chars) to avoid silent corruption from other hex
|
|
448
|
+
* representations (e.g. the UTF-8 "normalized" encoding which is 56 bytes,
|
|
449
|
+
* or a 20-byte EVM address).
|
|
450
|
+
*/
|
|
451
|
+
const hexToStellarNative = (address: string | undefined): string | undefined => {
|
|
452
|
+
if (!address || !address.startsWith('0x') || !isHexString(address)) return address;
|
|
453
|
+
const hexPayload = address.slice(2);
|
|
454
|
+
if (hexPayload.length !== BYTES32_HEX_LENGTH) {
|
|
455
|
+
throw new Error(
|
|
456
|
+
`Stellar hex address must be exactly 32 bytes (${BYTES32_HEX_LENGTH} hex chars), got ${hexPayload.length}: ${address}`,
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
const raw = Buffer.from(hexPayload, 'hex');
|
|
460
|
+
return StrKey.encodeContract(raw);
|
|
461
|
+
};
|
|
462
|
+
|
|
393
463
|
export const stellarAddressParser: (
|
|
394
464
|
chainName: InferChainNamesForChainType<ChainType.STELLAR>,
|
|
395
465
|
) => AddressParser<InferChainNamesForChainType<ChainType.STELLAR>> = (chainName) => {
|
|
@@ -514,11 +584,32 @@ export const stellarAddressParser: (
|
|
|
514
584
|
const hex = addressParser(chainName).nativeToBytes32Hex(nativeAddress);
|
|
515
585
|
return hexToBytes(hex);
|
|
516
586
|
},
|
|
587
|
+
normalizedToBytes32Hex: (address) => {
|
|
588
|
+
if (address === undefined) return undefined as any;
|
|
589
|
+
// Stellar normalized hex is UTF-8 of ASCII address (56 bytes), not raw bytes.
|
|
590
|
+
// Route through native string to extract the raw 32-byte StrKey payload.
|
|
591
|
+
return addressParser(chainName).nativeToBytes32Hex(
|
|
592
|
+
addressParser(chainName).normalizedToNativeString(address),
|
|
593
|
+
);
|
|
594
|
+
},
|
|
595
|
+
normalizedToBytes32: (address) => {
|
|
596
|
+
if (address === undefined) return undefined as any;
|
|
597
|
+
return hexToBytes(addressParser(chainName).normalizedToBytes32Hex(address));
|
|
598
|
+
},
|
|
599
|
+
bytes32ToNormalized: (bytes32Hex) => {
|
|
600
|
+
if (bytes32Hex === undefined) return undefined as any;
|
|
601
|
+
// Always assumes contract address type — G-address→bytes32 is a lossy upcast
|
|
602
|
+
return stellarAsciiToNormalized(
|
|
603
|
+
StrKey.encodeContract(Buffer.from(hexToBytes(bytes32Hex))),
|
|
604
|
+
);
|
|
605
|
+
},
|
|
517
606
|
parseNative: (nativeAddress) => {
|
|
607
|
+
nativeAddress = hexToStellarNative(nativeAddress);
|
|
518
608
|
assertNative(nativeAddress, chainName);
|
|
519
609
|
return addressParser(chainName).nativeToNormalized(nativeAddress);
|
|
520
610
|
},
|
|
521
611
|
parseNativeToUnpaddedHex: (nativeAddress) => {
|
|
612
|
+
nativeAddress = hexToStellarNative(nativeAddress);
|
|
522
613
|
assertNative(nativeAddress, chainName);
|
|
523
614
|
const normalized = addressParser(chainName).nativeToNormalized(nativeAddress);
|
|
524
615
|
return normalized as unknown as HexString;
|
package/dist/3457WEGJ.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/addressParser.ts"],"names":["AddressEncoding","addressParser","chainName","ChainName","TON","tonAddressParser","SOLANA","base58AddressParser","INITIA","initiaAddressParser","STELLAR","stellarAddressParser","STARKNET","starknetAddressParser","hexAddressParser","normalizedToBytes32Hex","address","hexZeroPad","normalizedToUnpaddedString","toString","normalizedToBytes32","hexToBytes","normalizedToBigInt","BigInt","parseNative","nativeAddress","assertNative","expectedChainName","validateNative","Error","getAddress","undefined","parseTonAddress","normalizedToNative","numericalValue","bigintToAddress","normalizedToNativeString","nativeToNormalized","normalizeHex","addressToHex","nativeToBytes32Hex","nativeToBytes","nativeToBytes32","parseNativeToUnpaddedHex","tonToNormalized","tonAddress","encoding","isHexString","test","AccAddress","fromHex","toHex","isBase58","bs58","encode","hex","bytesToHexPrefixed","decode","nativeByteLength","StaticChainConfigs","getAddressSizeInBytes","TRON","startsWith","slice","isValidStellarAddress","StrKey","isValidEd25519PublicKey","isValidContract","isValidMed25519PublicKey","isValidLiquidityPool","isValidClaimableBalance","isValidSignedPayload","stellarTextEncoder","TextEncoder","stellarAsciiToNormalized","bytes","stellarTextDecoder","TextDecoder","normalizedToStellarAscii","normalizedHex","stellarAddress","rawBytes","decodeEd25519PublicKey","decodeContract","decodeLiquidityPool","fullBytes","decodeClaimableBalance","subarray","normalized"],"mappings":";;;;;;;;;;;AAAA,cAAA,EAAA;AAiCO,IAAKA,eAAAA,6BAAAA,gBAAAA,EAAAA;;;;;;AAAAA,EAAAA,OAAAA,gBAAAA;;AAoDL,SAASC,cAAmCC,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AAClC,MAAA,OAAO;QACHN,aAAAA,EAAeT,OAAAA;AACfd,QAAAA;AACJ,OAAA;IACJ,CAAA,EANoB,oBAAA,CAAA;AAOpBkC,IAAAA,wBAAAA,0BAA2BpB,OAAAA,KAAAA;AACvB,MAAA,IAAIA,OAAAA,KAAYe,QAAW,OAAOA,MAAAA;AAClC,MAAA,OAAOf,OAAAA;IACX,CAAA,EAH0B,0BAAA;AAI9B,GAAA;AACJ,CAAA,EA7BqC,uBAAA","file":"3457WEGJ.js","sourcesContent":["import { AccAddress } from '@initia/initia.js';\nimport { StrKey } from '@stellar/stellar-sdk';\nimport type { Address } from '@ton/ton';\nimport bs58 from 'bs58';\n\nimport type { HexString, NormalizedHexString } from '@layerzerolabs/common-chain-model';\nimport { normalizeHex } from '@layerzerolabs/common-chain-model';\nimport {\n bytesToHexPrefixed,\n hexToBytes,\n hexZeroPad,\n isBase58,\n isHexString,\n} from '@layerzerolabs/common-encoding-utils';\nimport { addressToHex, bigintToAddress, parseTonAddress } from '@layerzerolabs/common-ton';\nimport type {\n Base58String,\n ChainsByEncoding,\n ChainType,\n InferChainNamesForChainType,\n InferChainTypeForChainName,\n InitiaString,\n NativeAddress,\n ResolvedEncodingForChainName,\n StellarString,\n} from '@layerzerolabs/layerzero-definitions';\nimport type { ChainNativeAddress } from '@layerzerolabs/layerzero-definitions';\nimport { ChainName } from '@layerzerolabs/layerzero-definitions';\nimport { StaticChainConfigs } from '@layerzerolabs/static-chain-info';\nimport type { MaybeUndefinedMapped } from '@layerzerolabs/typescript-utils';\n\ntype NativeOrString<T extends ChainName> = ChainNativeAddress<T> | ResolvedEncodingForChainName<T>;\n\nexport enum AddressEncoding {\n HEX = 'hex',\n BASE58 = 'base58',\n TON = 'ton',\n INITIA = 'initia',\n STELLAR = 'stellar',\n}\n\nexport type ExtensionByChainType = {\n ton: {\n tonToNormalized: (tonAddress: Address) => NormalizedHexString;\n };\n};\n\nexport type InferExtensionByChainName<T extends ChainName> =\n InferChainTypeForChainName<T> extends keyof ExtensionByChainType\n ? ExtensionByChainType[InferChainTypeForChainName<T>]\n : {};\n\nexport type AddressParser<T extends ChainName> = {\n normalizedToNative: <Address extends NormalizedHexString | undefined>(\n address: Address,\n ) => MaybeUndefinedMapped<Address, ChainNativeAddress<T>>;\n normalizedToNativeString: <Address extends NormalizedHexString | undefined>(\n address: Address,\n ) => MaybeUndefinedMapped<Address, ResolvedEncodingForChainName<T>>;\n nativeToNormalized: <Address extends NativeOrString<T> | undefined>(\n nativeAddress: Address,\n ) => MaybeUndefinedMapped<Address, NormalizedHexString>;\n nativeToBytes: <Address extends NativeOrString<T> | undefined>(\n nativeAddress: Address,\n ) => MaybeUndefinedMapped<Address, Uint8Array>;\n nativeToBytes32Hex: <Address extends NativeOrString<T> | undefined>(\n nativeAddress: Address,\n ) => MaybeUndefinedMapped<Address, HexString>;\n nativeToBytes32: <Address extends NativeOrString<T> | undefined>(\n nativeAddress: Address,\n ) => MaybeUndefinedMapped<Address, Uint8Array>;\n validateNative: (\n nativeAddress: string | undefined,\n ) => nativeAddress is ResolvedEncodingForChainName<T>;\n /**\n * Parse a native address to a string if it is valid.\n * Throws an error if the native address is invalid.\n * @param nativeAddress - The native address to parse.\n * @returns The parsed native address.\n */\n parseNative: (nativeAddress: string | undefined) => NormalizedHexString;\n parseNativeToUnpaddedHex: (nativeAddress: string | undefined) => HexString;\n encoding: AddressEncoding;\n} & InferExtensionByChainName<T>;\n\nexport function addressParser<T extends ChainName>(chainName: T): AddressParser<T> {\n // FIXME: figure out a way to not have to cast here\n if (chainName === ChainName.TON)\n return tonAddressParser(chainName) as unknown as AddressParser<T>;\n if (chainName === ChainName.SOLANA)\n return base58AddressParser(chainName) as unknown as AddressParser<T>;\n if (chainName === ChainName.INITIA)\n return initiaAddressParser(chainName) as unknown as AddressParser<T>;\n if (chainName === ChainName.STELLAR)\n return stellarAddressParser(chainName) as unknown as AddressParser<T>;\n if (chainName === ChainName.STARKNET)\n return starknetAddressParser(chainName) as unknown as AddressParser<T>;\n return hexAddressParser(chainName) as unknown as AddressParser<T>;\n}\n\nexport namespace addressParser {\n export const normalizedToBytes32Hex = (address: NormalizedHexString) => {\n return hexZeroPad(address as unknown as HexString, 32);\n };\n\n export const normalizedToUnpaddedString = (address: NormalizedHexString) => {\n return address.toString() as HexString;\n };\n\n export const normalizedToBytes32 = (address: NormalizedHexString) => {\n return hexToBytes(normalizedToBytes32Hex(address));\n };\n\n export const normalizedToBigInt = (address: NormalizedHexString) => {\n return BigInt(address as unknown as HexString);\n };\n\n export const parseNative = (nativeAddress: NativeAddress) => {\n return addressParser(nativeAddress.chainName).parseNative(nativeAddress.nativeAddress);\n };\n}\n\nfunction assertNative<T extends ChainName>(\n nativeAddress: string | undefined,\n expectedChainName: T,\n): asserts nativeAddress is ResolvedEncodingForChainName<T> {\n if (!addressParser(expectedChainName).validateNative(nativeAddress)) {\n throw new Error(\n 'Cannot convert: \"' +\n nativeAddress +\n '\" - The native address does not match the expected format for the chain: ' +\n expectedChainName,\n );\n }\n}\n\nconst getAddress = <T extends ChainName>(nativeAddress: NativeOrString<T>) => {\n return typeof nativeAddress === 'object' ? nativeAddress.nativeAddress : nativeAddress;\n};\n\nexport const tonAddressParser: (\n chainName: InferChainNamesForChainType<ChainType.TON>,\n) => AddressParser<InferChainNamesForChainType<ChainType.TON>> = (chainName) => {\n return {\n validateNative: (nativeAddress): nativeAddress is HexString => {\n if (nativeAddress === undefined) {\n return false;\n }\n try {\n parseTonAddress(nativeAddress);\n return true;\n } catch {\n return false;\n }\n },\n normalizedToNative: (address) => {\n if (address === undefined) return undefined as any;\n const numericalValue = addressParser.normalizedToBigInt(address);\n return {\n // FIXME this is wrong\n nativeAddress: bigintToAddress(numericalValue).toString() as HexString,\n chainName,\n };\n },\n normalizedToNativeString: (address) => {\n if (address === undefined) return undefined as any;\n return addressParser(chainName).normalizedToNative(address).nativeAddress;\n },\n nativeToNormalized: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n return normalizeHex(addressToHex(address));\n },\n nativeToBytes32Hex: (nativeAddress) => {\n // naturally ton is 32 bytes, pad it anyway\n if (nativeAddress === undefined) return undefined as any;\n return hexZeroPad(\n addressParser(chainName).nativeToNormalized(nativeAddress) as unknown as HexString,\n 32,\n );\n },\n nativeToBytes: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));\n },\n nativeToBytes32: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));\n },\n parseNative: (nativeAddress) => {\n assertNative(nativeAddress, chainName);\n return addressParser(chainName).nativeToNormalized(nativeAddress);\n },\n parseNativeToUnpaddedHex: (nativeAddress) => {\n return addressParser(chainName).parseNative(nativeAddress) as unknown as HexString;\n },\n tonToNormalized: (tonAddress) => {\n return addressParser(chainName).parseNative(addressToHex(tonAddress));\n },\n encoding: AddressEncoding.TON,\n };\n};\n\nexport const initiaAddressParser: (\n chainName: ChainsByEncoding[InitiaString],\n) => AddressParser<ChainsByEncoding[InitiaString]> = (chainName) => {\n return {\n validateNative: (nativeAddress): nativeAddress is InitiaString => {\n if (nativeAddress === undefined) {\n return false;\n }\n try {\n // Both formats are native for the chain and are used kind of randomly.\n return (\n isHexString(nativeAddress) ||\n /^(init)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38,66})$/.test(nativeAddress)\n );\n } catch {\n return false;\n }\n },\n normalizedToNative: (address) => {\n if (address === undefined) {\n return undefined as any;\n }\n return {\n nativeAddress: AccAddress.fromHex(address as unknown as HexString) as InitiaString,\n chainName,\n };\n },\n normalizedToNativeString: (address) => {\n if (address === undefined) return undefined as any;\n return addressParser(chainName).normalizedToNative(address).nativeAddress;\n },\n nativeToNormalized: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n if (isHexString(address)) {\n return normalizeHex(address);\n }\n return normalizeHex(AccAddress.toHex(nativeAddress.toString()) as HexString);\n },\n nativeToBytes32Hex: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n // naturally ton is 32 bytes, pad it anyway\n return hexZeroPad(\n addressParser(chainName).nativeToNormalized(nativeAddress) as unknown as HexString,\n 32,\n );\n },\n nativeToBytes: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));\n },\n nativeToBytes32: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));\n },\n parseNative: (nativeAddress) => {\n assertNative(nativeAddress, chainName);\n return addressParser(chainName).nativeToNormalized(nativeAddress);\n },\n parseNativeToUnpaddedHex: (nativeAddress) => {\n return addressParser(chainName).parseNative(nativeAddress) as unknown as HexString;\n },\n encoding: AddressEncoding.INITIA,\n };\n};\n\nexport const base58AddressParser = (\n chainName: ChainsByEncoding[Base58String],\n): AddressParser<ChainsByEncoding[Base58String]> => {\n return {\n validateNative: (nativeAddress): nativeAddress is Base58String => {\n if (nativeAddress === undefined) return false;\n return isBase58(nativeAddress);\n },\n normalizedToNative: (address) => {\n if (address === undefined) return undefined as any;\n return {\n nativeAddress: bs58.encode(\n hexToBytes(address as unknown as HexString),\n ) as Base58String,\n chainName,\n };\n },\n normalizedToNativeString: (address) => {\n if (address === undefined) return undefined as any;\n return addressParser(chainName).normalizedToNative(address).nativeAddress;\n },\n nativeToNormalized: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n const hex = bytesToHexPrefixed(bs58.decode(address));\n return normalizeHex(hex);\n },\n nativeToBytes32Hex: (nativeAddress) => {\n // naturally solana is 32 bytes, pad it anyway\n if (nativeAddress === undefined) return undefined as any;\n return hexZeroPad(\n addressParser(chainName).nativeToNormalized(nativeAddress) as unknown as HexString,\n 32,\n );\n },\n nativeToBytes: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n return bs58.decode(address);\n },\n nativeToBytes32: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));\n },\n parseNative: (nativeAddress) => {\n assertNative(nativeAddress, chainName);\n return addressParser(chainName).nativeToNormalized(nativeAddress);\n },\n parseNativeToUnpaddedHex: (nativeAddress) => {\n return addressParser(chainName).parseNative(nativeAddress) as unknown as HexString;\n },\n encoding: AddressEncoding.BASE58,\n };\n};\n\nexport const hexAddressParser = (\n chainName: ChainsByEncoding[HexString],\n): AddressParser<ChainsByEncoding[HexString]> => {\n return {\n validateNative: (nativeAddress): nativeAddress is HexString => {\n if (nativeAddress === undefined) return false;\n return isHexString(nativeAddress);\n },\n normalizedToNative: (address) => {\n if (address === undefined) return undefined as any;\n // we fetch here instead of storing by chain because some chains may not have this defined,\n // so we should only throw on those chains if they try to use these methods that need the native byte length\n const nativeByteLength = StaticChainConfigs.getAddressSizeInBytes(chainName);\n return {\n // we could have EIP-55 here, but omitted for now\n nativeAddress: hexZeroPad(address as unknown as HexString, nativeByteLength),\n chainName,\n };\n },\n normalizedToNativeString: (address) => {\n if (address === undefined) return undefined as any;\n const nativeByteLength = StaticChainConfigs.getAddressSizeInBytes(chainName);\n return hexZeroPad(address as unknown as HexString, nativeByteLength);\n },\n nativeToNormalized: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n return normalizeHex(address);\n },\n nativeToBytes: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n return hexToBytes(address);\n },\n nativeToBytes32Hex: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n return hexZeroPad(address, 32);\n },\n nativeToBytes32: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n return hexToBytes(addressParser(chainName).nativeToBytes32Hex(nativeAddress));\n },\n parseNative: (nativeAddress) => {\n // Specific case to make tron a little less flaky, handle the 41 prefix\n if (chainName === ChainName.TRON && nativeAddress) {\n nativeAddress = nativeAddress.startsWith('41')\n ? `0x${nativeAddress.slice(2)}`\n : nativeAddress;\n }\n\n assertNative(nativeAddress, chainName);\n return addressParser(chainName).nativeToNormalized(nativeAddress);\n },\n parseNativeToUnpaddedHex: (nativeAddress) => {\n return addressParser(chainName).parseNative(nativeAddress) as unknown as HexString;\n },\n encoding: AddressEncoding.HEX,\n };\n};\n\nexport const stellarAddressParser: (\n chainName: InferChainNamesForChainType<ChainType.STELLAR>,\n) => AddressParser<InferChainNamesForChainType<ChainType.STELLAR>> = (chainName) => {\n /**\n * Validate if a string is a valid Stellar address.\n *\n * According to SEP-0023 (https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md),\n * Stellar supports multiple address types encoded as base32 ASCII strings:\n * - Account addresses starting with 'G' (56 chars, Ed25519 public key)\n * - Contract addresses starting with 'C' (56 chars, contract ID)\n * - Muxed addresses starting with 'M' (69 chars, muxed account with ID)\n * - Liquidity pool addresses starting with 'L' (56 chars, pool ID)\n * - Claimable balance addresses starting with 'B' (56 chars, balance ID)\n * - Signed payload starting with 'P' (variable length)\n *\n * All addresses are stored in their native ASCII format to preserve type information.\n */\n const isValidStellarAddress = (address: string): boolean => {\n if (!address) return false;\n // Use the StrKey validation methods for all supported address types\n return (\n StrKey.isValidEd25519PublicKey(address) ||\n StrKey.isValidContract(address) ||\n StrKey.isValidMed25519PublicKey(address) ||\n StrKey.isValidLiquidityPool(address) ||\n StrKey.isValidClaimableBalance(address) ||\n StrKey.isValidSignedPayload(address)\n );\n };\n\n /**\n * Convert Stellar ASCII address to normalized hex by encoding the ASCII string as UTF-8 bytes.\n * This preserves the full address including type prefix and allows round-trip conversion.\n */\n const stellarTextEncoder = new TextEncoder();\n const stellarAsciiToNormalized = (address: string): NormalizedHexString => {\n // Convert ASCII address string to UTF-8 bytes, then to hex\n const bytes = stellarTextEncoder.encode(address);\n return normalizeHex(bytesToHexPrefixed(bytes));\n };\n\n /**\n * Convert normalized hex back to Stellar ASCII address by decoding UTF-8 bytes.\n */\n const stellarTextDecoder = new TextDecoder();\n const normalizedToStellarAscii = (normalizedHex: NormalizedHexString): string => {\n // Convert hex to bytes, then decode as UTF-8 string\n const bytes = hexToBytes(normalizedHex as unknown as HexString);\n return stellarTextDecoder.decode(bytes);\n };\n\n return {\n validateNative: (nativeAddress): nativeAddress is StellarString => {\n if (nativeAddress === undefined) return false;\n return isValidStellarAddress(nativeAddress);\n },\n normalizedToNative: (address) => {\n if (address === undefined) return undefined as any;\n // Decode normalized hex back to ASCII Stellar address\n const stellarAddress = normalizedToStellarAscii(address);\n return {\n nativeAddress: stellarAddress as StellarString,\n chainName,\n };\n },\n normalizedToNativeString: (address) => {\n if (address === undefined) return undefined as any;\n return normalizedToStellarAscii(address) as StellarString;\n },\n nativeToNormalized: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n // Convert ASCII address to normalized hex\n return stellarAsciiToNormalized(address);\n },\n nativeToBytes32Hex: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n // Decode the Stellar address to its raw 32-byte payload based on type\n let rawBytes: Buffer;\n if (StrKey.isValidEd25519PublicKey(address)) {\n // Account addresses (G...) - Ed25519 public key (32 bytes)\n rawBytes = StrKey.decodeEd25519PublicKey(address);\n } else if (StrKey.isValidContract(address)) {\n // Contract addresses (C...) - contract ID (32 bytes)\n rawBytes = StrKey.decodeContract(address);\n } else if (StrKey.isValidLiquidityPool(address)) {\n // Liquidity pool addresses (L...) - pool ID (32 bytes)\n rawBytes = StrKey.decodeLiquidityPool(address);\n } else if (StrKey.isValidClaimableBalance(address)) {\n // Claimable balance addresses (B...) - balance ID (33 bytes: 1-byte version + 32-byte hash)\n // Per SEP-0023: first byte is the claimable balance type (0x00 = V0), followed by 32-byte SHA256 hash\n const fullBytes = StrKey.decodeClaimableBalance(address);\n rawBytes = fullBytes.subarray(1); // Skip the first byte (version), return the 32-byte hash\n } else if (StrKey.isValidMed25519PublicKey(address)) {\n // Muxed addresses (M...) contain additional data beyond 32 bytes\n throw new Error(\n 'nativeToBytes32 is not supported for Stellar muxed addresses (M...)',\n );\n } else if (StrKey.isValidSignedPayload(address)) {\n // Signed payload (P...) has variable length\n throw new Error(\n 'nativeToBytes32 is not supported for Stellar signed payload addresses (P...)',\n );\n } else {\n throw new Error(`Unknown Stellar address type: ${address}`);\n }\n return bytesToHexPrefixed(rawBytes);\n },\n nativeToBytes: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n const address = getAddress(nativeAddress);\n assertNative(address, chainName);\n // Convert ASCII address to UTF-8 bytes\n return stellarTextEncoder.encode(address);\n },\n nativeToBytes32: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n // Use nativeToBytes32Hex and convert to Uint8Array\n const hex = addressParser(chainName).nativeToBytes32Hex(nativeAddress);\n return hexToBytes(hex);\n },\n parseNative: (nativeAddress) => {\n assertNative(nativeAddress, chainName);\n return addressParser(chainName).nativeToNormalized(nativeAddress);\n },\n parseNativeToUnpaddedHex: (nativeAddress) => {\n assertNative(nativeAddress, chainName);\n const normalized = addressParser(chainName).nativeToNormalized(nativeAddress);\n return normalized as unknown as HexString;\n },\n encoding: AddressEncoding.STELLAR,\n };\n};\n\n// Starknet addresses do not handle hex-zero padding, so we just return the address as is\nexport const starknetAddressParser = (\n chainName: ChainsByEncoding[HexString],\n): AddressParser<ChainsByEncoding[HexString]> => {\n return {\n ...hexAddressParser(chainName),\n validateNative: (nativeAddress): nativeAddress is HexString => {\n if (nativeAddress === undefined) return false;\n return isHexString(nativeAddress);\n },\n parseNative: (nativeAddress) => {\n if (nativeAddress === undefined) return undefined as any;\n // We can't trust starknet.js strings, they may actually be bigints!\n // so just convert everything to hex first, then convert to normalized\n nativeAddress = `0x${BigInt(nativeAddress).toString(16)}`;\n assertNative(nativeAddress, chainName);\n return addressParser(chainName).nativeToNormalized(nativeAddress);\n },\n normalizedToNative: (address) => {\n if (address === undefined) return undefined as any;\n return {\n nativeAddress: address,\n chainName,\n };\n },\n normalizedToNativeString: (address) => {\n if (address === undefined) return undefined as any;\n return address;\n },\n };\n};\n"]}
|