Keys, Base58, and mnemonic utilities
The SDK provides one set of value types and conversion rules for Solana identities, signatures, hashes, and byte data. It keeps key material in binary form for signing and address work, then uses Base58 at human and JSON boundaries. Mnemonics provide a repeatable path from wallet words to the same private-key type.
Core key model
Public identities
PublicKey is the fixed 32-byte value used as an account identity, program identity, or derived address. Its normal text form is Base58, so the same value can move between byte-oriented account and message data and the text-oriented RPC and JSON worlds. A public key may be accepted even when it is not on the Ed25519 curve; callers can check curve membership when a curve-backed key is required.
Public keys also act as the shared identity type across account metadata, hashes, wallet views, and program-address helpers. Hash uses the same 32-byte shape and Base58 form but keeps hash values distinct in the API. The related core data model page describes where these values sit in accounts and other SDK data.
References: keys.go• L166-209 keys.go• L301-327 nativetypes.go• L34-106
Private signing keys
PrivateKey holds a 64-byte Ed25519 private key. The value contains a 32-byte seed and its matching public-key bytes. The SDK validates both the size and the seed-to-public-key relationship before it signs or derives a public key. This prevents malformed key material from reaching signing operations.
Keys can come from a Base58 string, a Solana keygen JSON file, or secure random generation. A Wallet groups a private key with its derived public key and can also be built from a mnemonic. Treat the Base58 and keygen-file forms as secret input even though they are text or JSON.
References: keys.go• L37-151 account.go• L28-55
Derived addresses
The SDK derives addresses from public keys and seed bytes when a program needs a stable address that does not represent a signing key. A program-derived address is accepted only when its result is off the Ed25519 curve. Seeded address creation enforces Solana's seed limits and rejects an owner value that could collide with the program-derived-address domain.
The search form adds a bump value and returns the address with the value needed to reproduce it. It treats the caller's seed set as read-only, so the same seeds can be reused by later or concurrent address searches. The same address service covers ordinary seeded addresses and common token-related addresses. This makes the curve check an address rule rather than a general rule for parsing every PublicKey.
This diagram shows how seed data becomes a usable program-derived address.
flowchart LR
Seeds[Seed bytes and program ID] --> Hash[Derived address candidate]
Hash --> Curve{On Ed25519 curve?}
Curve -->|Yes| Bump[Try another bump value]
Curve -->|No| Address[Program-derived address and bump]
Bump --> Hash
References: keys.go• L305-308 keys.go• L632-715 keys.go• L718-766 keys_test.go• L490-512 keys_test.go• L725-763
Base58 boundary
Codec contract
Base58 is the SDK's compact text form for Solana public keys, hashes, signatures, private keys, and selected raw byte fields. The codec preserves leading zero bytes as leading 1 characters. Empty input maps to an empty string and back to an empty byte slice.
The general codec accepts byte slices of any length. It rejects characters outside the Solana Base58 alphabet and reports values that cannot fit the requested fixed-size output. Fixed-size callers can use the 32-byte or 64-byte forms when the value type defines an exact size.
| Value | Binary size | Text boundary |
|---|---|---|
| Public key or hash | 32 bytes | Base58 text, with a 32-byte decode check |
| Signature or private key | 64 bytes | Base58 text, with a 64-byte decode check |
| General byte data | Any length | Base58 through Base58 or the general codec |
References: base58/encode.go• L8-25 base58/decode.go• L16-91 base58/tables.go• L13-18 nativetypes.go• L108-242
Fixed-size acceleration
The codec gives the common 32-byte and 64-byte paths dedicated handling because keys, hashes, and signatures use those sizes often. On supported amd64 builds it can use AVX2 kernels. Other builds and explicit pure-Go builds use the portable path. Both paths share the same Base58 contract.
Callers that already own an output buffer can use append-style encoding for fewer allocations. The public-key and signature JSON and text methods use these fixed-size paths, so serialization follows the same value rules without exposing the fast-path choice to callers.
References: base58/encode.go• L76-181 base58/decode.go• L94-172 base58/avx2_amd64.go• L1-19 base58/avx2_amd64_v1.go• L1-7 base58/avx2_amd64_v3.go• L1-6 base58/avx2_other.go• L1-10
Mnemonic derivation
Wallet key recovery
A BIP-39 mnemonic is a human-readable source for deterministic wallet key material. PrivateKeyFromMnemonic validates the words, combines them with the optional passphrase, and uses the default Solana path m/44'/501'/0'/0'. The passphrase is part of the input, so a different passphrase produces a different private key.
The path-specific API supports other SLIP-0010 paths for Ed25519. Every path segment must be hardened because Ed25519 does not define non-hardened derivation in this flow. The result is the same validated private-key shape used by random and Base58-loaded wallets.
This diagram shows how a mnemonic and its recovery settings become a wallet identity.
flowchart LR
Words[BIP-39 mnemonic] --> Seed[Mnemonic seed and passphrase]
Seed --> Path[Hardened SLIP-0010 path]
Path --> Key[Ed25519 private key]
Key --> Wallet[Wallet and public key]
References: mnemonic.go• L30-80 mnemonic.go• L83-144 account.go• L43-55
Mnemonic wordlists
The BIP-39 package supplies the standard word lists for English, Chinese simplified, Chinese traditional, Czech, French, Italian, Japanese, Korean, and Spanish. English is active when the package starts. Applications can select another list with SetWordList before they validate or convert mnemonic words.
The active word list is package-wide. It is therefore part of the recovery context, together with the mnemonic, passphrase, and derivation path. A wallet restored with a different list can fail validation or produce a different seed from the same-looking word sequence.
References: bip39/bip39.go• L46-92 bip39/…/english.go• L9-22 bip39/…/chinese_simplified.go• L9-22 bip39/…/chinese_traditional.go• L9-22 bip39/…/czech.go• L9-22 bip39/…/french.go• L9-22 bip39/…/italian.go• L9-22 bip39/…/japanese.go• L9-22 bip39/…/korean.go• L9-22 bip39/…/spanish.go• L9-22
Derivation inputs
The derivation boundary accepts a seed of 16 to 64 bytes and a path beginning with m, or an empty path for the master key. Invalid words, malformed path segments, out-of-range indexes, and non-hardened segments return errors before key material is produced.
The default path is a compatibility choice for common Solana wallets. Applications that must recover keys created by another wallet should use the explicit path API and preserve the original passphrase and path together with the recovery record.
References: mnemonic.go• L43-70 mnemonic.go• L85-127 mnemonic_test.go• L71-145
Shared encoding boundary
Typed value serialization
Public keys, hashes, and signatures serialize as quoted Base58 strings in JSON and as Base58 text through text marshaling. Their unmarshaling paths decode the text and enforce the value's fixed binary size. This keeps maps, RPC response fields, command-line values, and stored text representations aligned.
Raw byte data uses explicit wrapper types. Base58 represents a byte slice whose JSON form is a Base58 string, while Base64 represents the common alternative for larger or protocol-selected byte data. These wrappers keep transport encoding separate from the binary value used by account, instruction, and message processing.
References: keys.go• L212-280 nativetypes.go• L56-92 nativetypes.go• L154-242
RPC data encodings
Data carries content together with its declared encoding. JSON represents it as a two-item value containing the text and the encoding name. Base58, Base64, and Base64 plus Zstandard are supported for decoded content. JSON-parsed data is a service-level response mode rather than a byte codec.
The encoding choice is part of the boundary contract. Base58 is suited to small account data and familiar Solana text values, while Base64 supports data of any account size and the compressed form reduces larger payloads. Callers must preserve the declared encoding when passing data between RPC responses and transaction or account workflows. For instruction and message assembly, see core instruction and message.
References: nativetypes.go• L244-330 nativetypes.go• L333-387 rpc/getTransaction.go• L90-97
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the 32-byte and 64-byte size contracts aligned across key, hash, signature, and Base58 decode entry points.
- Keep JSON and text marshaling aligned with the Base58 forms expected by RPC fields and command-line inputs.
- If a new data encoding is added, update the
Datavalue contract and every RPC request or response path that names the encoding. - If mnemonic defaults or path rules change, check compatibility with wallets that use
m/44'/501'/0'/0'and with explicit-path recovery. - If a word list changes or becomes selectable, keep the active-list rule aligned with mnemonic validation and preserve the list choice in recovery flows.
- Keep portable and accelerated Base58 paths behaviorally equivalent, including leading-zero handling and error results.
- Keep seeded-address limits, the program-derived-address marker boundary, and the read-only seed-input contract aligned across direct and bump-search address derivation.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Private-key text decodes to a value other than 64 bytes | Key loading fails before signing | PrivateKeyFromBase58 validates size and key structure |
| Private-key seed and public half do not match | The key is rejected as invalid | ValidatePrivateKey derives and compares the public half |
| Public-key or signature text uses an invalid Base58 character or size | JSON, text, or RPC decoding returns an error | Fixed-size Base58 decoders validate alphabet, length, and leading zeros |
| A mnemonic uses the wrong word list, passphrase, or derivation path | Validation fails or a different wallet key is recovered | Preserve the word list, passphrase, and path used to create the wallet |
| A derived address remains on the curve | The candidate cannot serve as a program-derived address | Address search retries with another bump value |
| A seeded address exceeds Solana limits or uses a forbidden owner suffix | Address creation returns an error | Enforce seed bounds and reject the program-derived-address marker collision |
Data names an unsupported encoding | RPC data cannot be decoded | Restrict the value to the supported encoding names |
Key files
| File | Why to read it |
|---|---|
| keys.go | Defines the public and private key contracts, signing, verification, key loading, and derived-address behavior. |
| account.go | Shows how a private key becomes a wallet identity. |
| mnemonic.go | Defines mnemonic recovery, the Solana default path, and hardened Ed25519 derivation. |
| bip39/bip39.go | Defines mnemonic validation, entropy and seed conversion, and the active word-list contract. |
| bip39/…/english.go | Illustrates the checked-in standard BIP-39 word-list data. The sibling word-list files provide the other supported languages. |
| nativetypes.go | Defines hashes, signatures, Base58 and Base64 wrappers, and the shared data encoding boundary. |
| base58/encode.go | Shows the general, fixed-size, and append-style encoding interfaces. |
| base58/decode.go | Shows fixed-size validation, general decoding, and Base58 error behavior. |
| base58/avx2_amd64.go | Shows when the accelerated fixed-size codec is available. |
| rpc/getTransaction.go | Illustrates how an RPC encoding choice reaches transaction data. |