CryptoConstants
in package
Cryptographic Constants for Stellar StrKey Encoding
This class contains constants related to Stellar's strkey encoding format, which is used for encoding public keys, secret seeds, and other identifiers in a human-readable base32 format with checksums.
Strkey Format: version byte + payload + 2-byte CRC16 checksum, then base32 encoded
References:
- SEP-0023 (Strkeys): https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md
- Stellar Protocol: https://github.com/stellar/stellar-protocol
Note: This class cannot be instantiated. All constants are static and should be accessed directly via the class name.
Table of Contents
Constants
- BIP32_HARDENED_MINIMUM_INDEX = 0x80000000
- BIP32 hardened derivation minimum index.
- CHAIN_CODE_LENGTH_BYTES = 32
- Length of BIP32 chain code in bytes.
- CRC16_INITIAL = 0x0
- CRC16 initial value.
- CRC16_MASK = 0xffff
- CRC16 mask for 16-bit values.
- CRC16_POLYNOMIAL = 0x1021
- CRC16 polynomial for checksum calculation.
- HMAC_CHAIN_PART_OFFSET = 32
- Offset for HMAC chain part in HD wallet derivation.
- HMAC_KEY_PART_LENGTH = 32
- Length of HMAC key part in HD wallet derivation.
- KEY_PADDING_BYTE = 0x0
- BIP32 key padding byte for hardened derivation.
- SIGNED_PAYLOAD_LENGTH_PREFIX_BYTES = 4
- Length of the payload length prefix in signed payloads.
- STRKEY_ACCOUNT_ID_LENGTH = 56
- Length of a Stellar account ID in strkey format (G...).
- STRKEY_CLAIMABLE_BALANCE_LENGTH = 58
- Length of a claimable balance ID in strkey format (B... or encoded hex).
- STRKEY_MUXED_ACCOUNT_ID_LENGTH = 69
- Length of a muxed account ID in strkey format (M...).
- STRKEY_SIGNED_PAYLOAD_MAX_LENGTH = 165
- Maximum length of a signed payload in strkey format (P...).
- STRKEY_SIGNED_PAYLOAD_MIN_LENGTH = 69
- Minimum length of a signed payload in strkey format (P...).
Constants
BIP32_HARDENED_MINIMUM_INDEX
BIP32 hardened derivation minimum index.
public
mixed
BIP32_HARDENED_MINIMUM_INDEX
= 0x80000000
In BIP32 HD wallets, indices >= 2^31 (0x80000000) indicate hardened key derivation. Hardened derivation prevents child public keys from being derived from the parent public key, providing additional security.
Hexadecimal: 0x80000000 Decimal: 2147483648 Binary: 10000000 00000000 00000000 00000000
Reference: BIP32 specification - Hardened keys
Tags
CHAIN_CODE_LENGTH_BYTES
Length of BIP32 chain code in bytes.
public
mixed
CHAIN_CODE_LENGTH_BYTES
= 32
Chain codes are used in HD wallet key derivation and are always 32 bytes as defined by BIP32. The chain code is combined with the private key to derive child keys.
Unit: bytes
Reference: BIP32 specification
Tags
CRC16_INITIAL
CRC16 initial value.
public
mixed
CRC16_INITIAL
= 0x0
The starting value for CRC16 checksum calculation. The algorithm begins with this value and XORs/shifts through the input data.
Hexadecimal: 0x0000 Decimal: 0
CRC16_MASK
CRC16 mask for 16-bit values.
public
mixed
CRC16_MASK
= 0xffff
Used to ensure CRC16 intermediate values remain within 16-bit range by masking off higher bits during calculation. This ensures the checksum is always 2 bytes (16 bits).
Hexadecimal: 0xFFFF Decimal: 65535 Binary: 1111 1111 1111 1111
CRC16_POLYNOMIAL
CRC16 polynomial for checksum calculation.
public
mixed
CRC16_POLYNOMIAL
= 0x1021
This is the CRC16-CCITT polynomial used by Stellar for strkey checksums. The polynomial defines the bit pattern used in the CRC algorithm.
Hexadecimal: 0x1021 Decimal: 4129 Binary: 0001 0000 0010 0001
Reference: CRC16-CCITT (XModem) polynomial
HMAC_CHAIN_PART_OFFSET
Offset for HMAC chain part in HD wallet derivation.
public
mixed
HMAC_CHAIN_PART_OFFSET
= 32
When performing HMAC-SHA512 during BIP32 key derivation, the 64-byte output is split into two 32-byte parts. The second 32 bytes (at offset 32) are used as the child chain code.
Unit: bytes (offset)
Reference: BIP32 specification - Key derivation
Tags
HMAC_KEY_PART_LENGTH
Length of HMAC key part in HD wallet derivation.
public
mixed
HMAC_KEY_PART_LENGTH
= 32
When performing HMAC-SHA512 during BIP32 key derivation, the 64-byte output is split into two 32-byte parts. The first 32 bytes are used as the child key material.
Unit: bytes
Reference: BIP32 specification - Key derivation
Tags
KEY_PADDING_BYTE
BIP32 key padding byte for hardened derivation.
public
mixed
KEY_PADDING_BYTE
= 0x0
When deriving hardened child keys in BIP32, a 0x00 byte is prepended to the private key before HMAC hashing. This ensures hardened keys cannot be derived from the public key.
Hexadecimal: 0x00 Decimal: 0
Reference: BIP32 specification - Hardened key derivation
Tags
SIGNED_PAYLOAD_LENGTH_PREFIX_BYTES
Length of the payload length prefix in signed payloads.
public
mixed
SIGNED_PAYLOAD_LENGTH_PREFIX_BYTES
= 4
Signed payloads include a 4-byte length prefix that specifies the size of the following payload data. This allows variable-length payloads up to the maximum size.
Unit: bytes
STRKEY_ACCOUNT_ID_LENGTH
Length of a Stellar account ID in strkey format (G...).
public
mixed
STRKEY_ACCOUNT_ID_LENGTH
= 56
Format: 1 byte version + 32 bytes public key + 2 bytes checksum = 35 bytes Base32 encoded: ceil(35 × 8 ÷ 5) = 56 characters
Account IDs are Ed25519 public keys encoded with the 'G' prefix.
Example: GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H
Unit: characters (base32 encoded)
Tags
STRKEY_CLAIMABLE_BALANCE_LENGTH
Length of a claimable balance ID in strkey format (B... or encoded hex).
public
mixed
STRKEY_CLAIMABLE_BALANCE_LENGTH
= 58
Format: 1 byte discriminant + 32 bytes balance ID + 2 bytes checksum = 35 bytes Base32 encoded: 58 characters (due to encoding specifics with the balance ID structure)
Claimable balances are defined in CAP-0023. Note that this length is different from other strkey formats due to the balance ID structure.
Example: 00000000178826fbfe339e1f5c53417c6fedfe2c05e8bec14303143ec46b38981b09c3f9
Unit: characters
Reference: CAP-0023 (Claimable Balances)
Tags
STRKEY_MUXED_ACCOUNT_ID_LENGTH
Length of a muxed account ID in strkey format (M...).
public
mixed
STRKEY_MUXED_ACCOUNT_ID_LENGTH
= 69
Format: 1 byte version + 32 bytes public key + 8 bytes ID + 2 bytes checksum = 43 bytes Base32 encoded: ceil(43 × 8 ÷ 5) = 69 characters
Muxed accounts allow multiple virtual accounts to share the same underlying Stellar account. Defined in CAP-0027.
Example: MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK
Unit: characters (base32 encoded)
Reference: CAP-0027 (Muxed Accounts)
Tags
STRKEY_SIGNED_PAYLOAD_MAX_LENGTH
Maximum length of a signed payload in strkey format (P...).
public
mixed
STRKEY_SIGNED_PAYLOAD_MAX_LENGTH
= 165
Format: 1 byte version + 32 bytes public key + 4 bytes length prefix + 64 bytes max payload + 2 bytes checksum = 103 bytes Base32 encoded: ceil(103 × 8 ÷ 5) = 165 characters
The payload can be up to 64 bytes as defined in CAP-0040.
Unit: characters (base32 encoded)
Reference: CAP-0040 (Signed Payload Signer)
Tags
STRKEY_SIGNED_PAYLOAD_MIN_LENGTH
Minimum length of a signed payload in strkey format (P...).
public
mixed
STRKEY_SIGNED_PAYLOAD_MIN_LENGTH
= 69
Format: 1 byte version + 32 bytes public key + 4 bytes length prefix + 4 bytes min payload + 2 bytes checksum = 43 bytes Base32 encoded minimum: ceil(43 × 8 ÷ 5) = 69 characters
Signed payloads combine a public key with arbitrary data (4-64 bytes). They are used for per-signature authorization data in Soroban contracts.
IMPORTANT: This was incorrectly set to 56 in the previous implementation. The correct value is 69 characters.
Example: PA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAOQCAQDAQCQMBYIBEFAWDANBYHRAEISCMKBKFQXDAMRUGY4DUPB6IBZGM
Unit: characters (base32 encoded)
Reference: CAP-0040 (Signed Payload Signer)