@layerzerolabs/address-utils-stellar 0.0.0-stage → 4.0.8

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2026 - LayerZero Labs Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any
4
+ person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the
6
+ Software without restriction, including without
7
+ limitation the rights to use, copy, modify, merge,
8
+ publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software
10
+ is furnished to do so, subject to the following
11
+ conditions:
12
+ The above copyright notice and this permission notice
13
+ shall be included in all copies or substantial portions
14
+ of the Software.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ import type { HexString, NormalizedHexString } from '@layerzerolabs/common-chain-model';
2
+ export type StellarStrKeyPrefix = 'C' | 'G';
3
+ /**
4
+ * Validate if a string is a valid Stellar address.
5
+ *
6
+ * According to SEP-0023 (https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md),
7
+ * Stellar supports multiple address types encoded as base32 ASCII strings:
8
+ * - Account addresses starting with 'G' (56 chars, Ed25519 public key)
9
+ * - Contract addresses starting with 'C' (56 chars, contract ID)
10
+ * - Muxed addresses starting with 'M' (69 chars, muxed account with ID)
11
+ * - Liquidity pool addresses starting with 'L' (56 chars, pool ID)
12
+ * - Claimable balance addresses starting with 'B' (56 chars, balance ID)
13
+ * - Signed payload starting with 'P' (variable length)
14
+ *
15
+ * All addresses are stored in their native ASCII format to preserve type information.
16
+ */
17
+ export declare const isValidStellarAddress: (address: string) => boolean;
18
+ /** Convert Stellar ASCII address to normalized hex by encoding the ASCII string as UTF-8 bytes. */
19
+ export declare const stellarAsciiToNormalized: (address: string) => NormalizedHexString;
20
+ /** Convert normalized hex back to Stellar ASCII address by decoding UTF-8 bytes. */
21
+ export declare const normalizedToStellarAscii: (normalizedHex: NormalizedHexString) => string;
22
+ /** UTF-8 bytes of a Stellar ASCII address. */
23
+ export declare const stellarAddressToUtf8Bytes: (address: string) => Uint8Array;
24
+ export declare const toStellarPayload: (hexAddress: string) => Buffer;
25
+ export declare const stellarAddressToHex: (stellarAddress: string) => HexString;
26
+ export declare const stellarNormalizedToHex: (address: NormalizedHexString) => HexString;
27
+ /**
28
+ * Converts a hex address back to a Stellar contract address (C...).
29
+ *
30
+ * Hex carries no address-type information, so the caller must know that the hex
31
+ * originated from a 'C' address. If the hex came from a 'G' address, use
32
+ * {@link hexToStellarAccountAddress}.
33
+ *
34
+ * @param hexOrStellarAddress - Hex string (with or without 0x prefix), or an already-native
35
+ * Stellar address ('C...' or 'G...') which is passed through unchanged
36
+ * @returns A 'C...' contract address for hex input, or the native 'C...'/'G...' address unchanged
37
+ */
38
+ export declare const hexToStellarContractAddress: (hexOrStellarAddress: string) => string;
39
+ export declare const hexToStellarAccountAddress: (hexAddress: HexString) => string;
40
+ export declare const stellarContractHexToNormalized: (hexAddress: HexString) => NormalizedHexString;
41
+ export declare const stellarAccountHexToNormalized: (hexAddress: HexString) => NormalizedHexString;
42
+ /** Deterministic Stellar contract sentinel for test fixtures. */
43
+ export declare const stellarSentinelNormalizedFromLabel: (label: string) => NormalizedHexString;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AASxF,MAAM,MAAM,mBAAmB,GAAG,GAAG,GAAG,GAAG,CAAC;AAS5C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,YAAa,MAAM,KAAG,OAWvD,CAAC;AAEF,mGAAmG;AACnG,eAAO,MAAM,wBAAwB,YAAa,MAAM,KAAG,mBACa,CAAC;AAEzE,oFAAoF;AACpF,eAAO,MAAM,wBAAwB,kBAAmB,mBAAmB,KAAG,MAI7E,CAAC;AAEF,8CAA8C;AAC9C,eAAO,MAAM,yBAAyB,YAAa,MAAM,KAAG,UACtB,CAAC;AAEvC,eAAO,MAAM,gBAAgB,eAAgB,MAAM,KAAG,MAQrD,CAAC;AAEF,eAAO,MAAM,mBAAmB,mBAAoB,MAAM,KAAG,SAoB5D,CAAC;AAEF,eAAO,MAAM,sBAAsB,YAAa,mBAAmB,KAAG,SACZ,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,wBAAyB,MAAM,KAAG,MAYzE,CAAC;AAEF,eAAO,MAAM,0BAA0B,eAAgB,SAAS,KAAG,MACJ,CAAC;AAEhE,eAAO,MAAM,8BAA8B,eAAgB,SAAS,KAAG,mBACU,CAAC;AAElF,eAAO,MAAM,6BAA6B,eAAgB,SAAS,KAAG,mBACmB,CAAC;AAE1F,iEAAiE;AACjE,eAAO,MAAM,kCAAkC,UAAW,MAAM,KAAG,mBAGlE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ import { StrKey } from '@stellar/stellar-sdk';
2
+ import { normalizeHex } from '@layerzerolabs/common-chain-model';
3
+ import { bytesToHexPrefixed, hexToBytes, ensure0xPrefixed, tileHex } from '@layerzerolabs/common-encoding-utils';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var STELLAR_ADDRESS_BYTE_LENGTH = 32;
8
+ var CONTRACT_ID_HEX_LENGTH = 64;
9
+ var STRKEY_LENGTH = 56;
10
+ var stellarTextEncoder = new TextEncoder();
11
+ var stellarTextDecoder = new TextDecoder();
12
+ var isValidStellarAddress = /* @__PURE__ */ __name((address) => {
13
+ if (!address) return false;
14
+ return StrKey.isValidEd25519PublicKey(address) || StrKey.isValidContract(address) || StrKey.isValidMed25519PublicKey(address) || StrKey.isValidLiquidityPool(address) || StrKey.isValidClaimableBalance(address) || StrKey.isValidSignedPayload(address);
15
+ }, "isValidStellarAddress");
16
+ var stellarAsciiToNormalized = /* @__PURE__ */ __name((address) => normalizeHex(bytesToHexPrefixed(stellarTextEncoder.encode(address))), "stellarAsciiToNormalized");
17
+ var normalizedToStellarAscii = /* @__PURE__ */ __name((normalizedHex) => {
18
+ return stellarTextDecoder.decode(hexToBytes(normalizedHex));
19
+ }, "normalizedToStellarAscii");
20
+ var stellarAddressToUtf8Bytes = /* @__PURE__ */ __name((address) => stellarTextEncoder.encode(address), "stellarAddressToUtf8Bytes");
21
+ var toStellarPayload = /* @__PURE__ */ __name((hexAddress) => {
22
+ const payload = Buffer.from(hexToBytes(ensure0xPrefixed(hexAddress)));
23
+ if (payload.length !== STELLAR_ADDRESS_BYTE_LENGTH) {
24
+ throw new Error(`Stellar address payload must be exactly ${STELLAR_ADDRESS_BYTE_LENGTH} bytes, got ${payload.length}`);
25
+ }
26
+ return payload;
27
+ }, "toStellarPayload");
28
+ var stellarAddressToHex = /* @__PURE__ */ __name((stellarAddress) => {
29
+ if (StrKey.isValidEd25519PublicKey(stellarAddress)) {
30
+ return bytesToHexPrefixed(StrKey.decodeEd25519PublicKey(stellarAddress));
31
+ }
32
+ if (StrKey.isValidContract(stellarAddress)) {
33
+ return bytesToHexPrefixed(StrKey.decodeContract(stellarAddress));
34
+ }
35
+ if (StrKey.isValidLiquidityPool(stellarAddress)) {
36
+ return bytesToHexPrefixed(StrKey.decodeLiquidityPool(stellarAddress));
37
+ }
38
+ if (StrKey.isValidClaimableBalance(stellarAddress)) {
39
+ return bytesToHexPrefixed(StrKey.decodeClaimableBalance(stellarAddress).subarray(1));
40
+ }
41
+ if (StrKey.isValidMed25519PublicKey(stellarAddress)) {
42
+ throw new Error("stellarAddressToHex is not supported for muxed addresses (M...)");
43
+ }
44
+ if (StrKey.isValidSignedPayload(stellarAddress)) {
45
+ throw new Error("stellarAddressToHex is not supported for signed payload addresses (P...)");
46
+ }
47
+ throw new Error(`Unknown Stellar address type: ${stellarAddress}`);
48
+ }, "stellarAddressToHex");
49
+ var stellarNormalizedToHex = /* @__PURE__ */ __name((address) => stellarAddressToHex(normalizedToStellarAscii(address)), "stellarNormalizedToHex");
50
+ var hexToStellarContractAddress = /* @__PURE__ */ __name((hexOrStellarAddress) => {
51
+ if (!hexOrStellarAddress) {
52
+ return StrKey.encodeContract(Buffer.alloc(STELLAR_ADDRESS_BYTE_LENGTH));
53
+ }
54
+ if (hexOrStellarAddress.length === STRKEY_LENGTH && (StrKey.isValidContract(hexOrStellarAddress) || StrKey.isValidEd25519PublicKey(hexOrStellarAddress))) {
55
+ return hexOrStellarAddress;
56
+ }
57
+ return StrKey.encodeContract(toStellarPayload(hexOrStellarAddress));
58
+ }, "hexToStellarContractAddress");
59
+ var hexToStellarAccountAddress = /* @__PURE__ */ __name((hexAddress) => StrKey.encodeEd25519PublicKey(toStellarPayload(hexAddress)), "hexToStellarAccountAddress");
60
+ var stellarContractHexToNormalized = /* @__PURE__ */ __name((hexAddress) => stellarAsciiToNormalized(StrKey.encodeContract(toStellarPayload(hexAddress))), "stellarContractHexToNormalized");
61
+ var stellarAccountHexToNormalized = /* @__PURE__ */ __name((hexAddress) => stellarAsciiToNormalized(StrKey.encodeEd25519PublicKey(toStellarPayload(hexAddress))), "stellarAccountHexToNormalized");
62
+ var stellarSentinelNormalizedFromLabel = /* @__PURE__ */ __name((label) => {
63
+ const contractId = Buffer.from(hexToBytes(tileHex(label, CONTRACT_ID_HEX_LENGTH)));
64
+ return stellarAsciiToNormalized(StrKey.encodeContract(contractId));
65
+ }, "stellarSentinelNormalizedFromLabel");
66
+
67
+ export { hexToStellarAccountAddress, hexToStellarContractAddress, isValidStellarAddress, normalizedToStellarAscii, stellarAccountHexToNormalized, stellarAddressToHex, stellarAddressToUtf8Bytes, stellarAsciiToNormalized, stellarContractHexToNormalized, stellarNormalizedToHex, stellarSentinelNormalizedFromLabel, toStellarPayload };
68
+ //# sourceMappingURL=index.js.map
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["STELLAR_ADDRESS_BYTE_LENGTH","CONTRACT_ID_HEX_LENGTH","STRKEY_LENGTH","stellarTextEncoder","TextEncoder","stellarTextDecoder","TextDecoder","isValidStellarAddress","address","StrKey","isValidEd25519PublicKey","isValidContract","isValidMed25519PublicKey","isValidLiquidityPool","isValidClaimableBalance","isValidSignedPayload","stellarAsciiToNormalized","normalizeHex","bytesToHexPrefixed","encode","normalizedToStellarAscii","normalizedHex","decode","hexToBytes","stellarAddressToUtf8Bytes","toStellarPayload","hexAddress","payload","Buffer","from","ensure0xPrefixed","length","Error","stellarAddressToHex","stellarAddress","decodeEd25519PublicKey","decodeContract","decodeLiquidityPool","decodeClaimableBalance","subarray","stellarNormalizedToHex","hexToStellarContractAddress","hexOrStellarAddress","encodeContract","alloc","hexToStellarAccountAddress","encodeEd25519PublicKey","stellarContractHexToNormalized","stellarAccountHexToNormalized","stellarSentinelNormalizedFromLabel","label","contractId","tileHex"],"mappings":";;;;;;AAaA,IAAMA,2BAAAA,GAA8B,EAAA;AACpC,IAAMC,sBAAAA,GAAyB,EAAA;AAC/B,IAAMC,aAAAA,GAAgB,EAAA;AAEtB,IAAMC,kBAAAA,GAAqB,IAAIC,WAAAA,EAAAA;AAC/B,IAAMC,kBAAAA,GAAqB,IAAIC,WAAAA,EAAAA;A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jD,sBAAAA,CAAAA,CAAAA,CAAAA;AACzD,EAAA,OAAOe,wBAAAA,CAAyBP,MAAAA,CAAOkC,cAAAA,CAAeQ,UAAAA,CAAAA,CAAAA;AAC1D,CAAA,EAHkD,oCAAA","file":"index.js","sourcesContent":["import { StrKey } from '@stellar/stellar-sdk';\n\nimport type { HexString, NormalizedHexString } from '@layerzerolabs/common-chain-model';\nimport { normalizeHex } from '@layerzerolabs/common-chain-model';\nimport {\n bytesToHexPrefixed,\n ensure0xPrefixed,\n hexToBytes,\n tileHex,\n} from '@layerzerolabs/common-encoding-utils';\n\nexport type StellarStrKeyPrefix = 'C' | 'G';\n\nconst STELLAR_ADDRESS_BYTE_LENGTH = 32;\nconst CONTRACT_ID_HEX_LENGTH = 64;\nconst STRKEY_LENGTH = 56;\n\nconst stellarTextEncoder = new TextEncoder();\nconst stellarTextDecoder = new TextDecoder();\n\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 */\nexport 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/** Convert Stellar ASCII address to normalized hex by encoding the ASCII string as UTF-8 bytes. */\nexport const stellarAsciiToNormalized = (address: string): NormalizedHexString =>\n normalizeHex(bytesToHexPrefixed(stellarTextEncoder.encode(address)));\n\n/** Convert normalized hex back to Stellar ASCII address by decoding UTF-8 bytes. */\nexport const normalizedToStellarAscii = (normalizedHex: NormalizedHexString): string => {\n // A StrKey address's first byte is always >= 0x42, so normalizeHex never strips a leading\n // nibble and the body stays even-length; hexToBytes rejects anything odd as malformed.\n return stellarTextDecoder.decode(hexToBytes(normalizedHex as unknown as HexString));\n};\n\n/** UTF-8 bytes of a Stellar ASCII address. */\nexport const stellarAddressToUtf8Bytes = (address: string): Uint8Array =>\n stellarTextEncoder.encode(address);\n\nexport const toStellarPayload = (hexAddress: string): Buffer => {\n const payload = Buffer.from(hexToBytes(ensure0xPrefixed(hexAddress)));\n if (payload.length !== STELLAR_ADDRESS_BYTE_LENGTH) {\n throw new Error(\n `Stellar address payload must be exactly ${STELLAR_ADDRESS_BYTE_LENGTH} bytes, got ${payload.length}`,\n );\n }\n return payload;\n};\n\nexport const stellarAddressToHex = (stellarAddress: string): HexString => {\n if (StrKey.isValidEd25519PublicKey(stellarAddress)) {\n return bytesToHexPrefixed(StrKey.decodeEd25519PublicKey(stellarAddress));\n }\n if (StrKey.isValidContract(stellarAddress)) {\n return bytesToHexPrefixed(StrKey.decodeContract(stellarAddress));\n }\n if (StrKey.isValidLiquidityPool(stellarAddress)) {\n return bytesToHexPrefixed(StrKey.decodeLiquidityPool(stellarAddress));\n }\n if (StrKey.isValidClaimableBalance(stellarAddress)) {\n return bytesToHexPrefixed(StrKey.decodeClaimableBalance(stellarAddress).subarray(1));\n }\n if (StrKey.isValidMed25519PublicKey(stellarAddress)) {\n throw new Error('stellarAddressToHex is not supported for muxed addresses (M...)');\n }\n if (StrKey.isValidSignedPayload(stellarAddress)) {\n throw new Error('stellarAddressToHex is not supported for signed payload addresses (P...)');\n }\n throw new Error(`Unknown Stellar address type: ${stellarAddress}`);\n};\n\nexport const stellarNormalizedToHex = (address: NormalizedHexString): HexString =>\n stellarAddressToHex(normalizedToStellarAscii(address));\n\n/**\n * Converts a hex address back to a Stellar contract address (C...).\n *\n * Hex carries no address-type information, so the caller must know that the hex\n * originated from a 'C' address. If the hex came from a 'G' address, use\n * {@link hexToStellarAccountAddress}.\n *\n * @param hexOrStellarAddress - Hex string (with or without 0x prefix), or an already-native\n * Stellar address ('C...' or 'G...') which is passed through unchanged\n * @returns A 'C...' contract address for hex input, or the native 'C...'/'G...' address unchanged\n */\nexport const hexToStellarContractAddress = (hexOrStellarAddress: string): string => {\n if (!hexOrStellarAddress) {\n return StrKey.encodeContract(Buffer.alloc(STELLAR_ADDRESS_BYTE_LENGTH));\n }\n if (\n hexOrStellarAddress.length === STRKEY_LENGTH &&\n (StrKey.isValidContract(hexOrStellarAddress) ||\n StrKey.isValidEd25519PublicKey(hexOrStellarAddress))\n ) {\n return hexOrStellarAddress;\n }\n return StrKey.encodeContract(toStellarPayload(hexOrStellarAddress));\n};\n\nexport const hexToStellarAccountAddress = (hexAddress: HexString): string =>\n StrKey.encodeEd25519PublicKey(toStellarPayload(hexAddress));\n\nexport const stellarContractHexToNormalized = (hexAddress: HexString): NormalizedHexString =>\n stellarAsciiToNormalized(StrKey.encodeContract(toStellarPayload(hexAddress)));\n\nexport const stellarAccountHexToNormalized = (hexAddress: HexString): NormalizedHexString =>\n stellarAsciiToNormalized(StrKey.encodeEd25519PublicKey(toStellarPayload(hexAddress)));\n\n/** Deterministic Stellar contract sentinel for test fixtures. */\nexport const stellarSentinelNormalizedFromLabel = (label: string): NormalizedHexString => {\n const contractId = Buffer.from(hexToBytes(tileHex(label, CONTRACT_ID_HEX_LENGTH)));\n return stellarAsciiToNormalized(StrKey.encodeContract(contractId));\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@layerzerolabs/address-utils-stellar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "4.0.8",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist/**/*"
17
+ ],
18
+ "dependencies": {
19
+ "@layerzerolabs/common-chain-model": "4.0.8",
20
+ "@layerzerolabs/common-encoding-utils": "4.0.8",
21
+ "@stellar/stellar-sdk": "^16.4.0"
22
+ },
23
+ "devDependencies": {
24
+ "@layerzerolabs/tsup-configuration": "4.0.8",
25
+ "@layerzerolabs/typescript-configuration": "4.0.8",
26
+ "tsup": "^8.4.0",
27
+ "vitest": "^4.1.10"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "registry": "https://registry.npmjs.org/"
32
+ },
33
+ "externalRepoConfig": {
34
+ "targets": [
35
+ "everdawn-externalization",
36
+ "gasolina-audit",
37
+ "lz-labs-sidecar",
38
+ "monorepo-external",
39
+ "onesig-client"
40
+ ]
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "lint": "eslint . --max-warnings 0 || (eslint . --fix --max-warnings 0 && false)",
45
+ "test": "vitest --run --pass-with-no-tests --typecheck"
46
+ }
6
47
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.