PrivateKey

public final class PrivateKey : Sendable

Represents a Stellar Ed25519 private key.

A private key is a 64-byte value that represents the private component of an Ed25519 keypair. The first 32 bytes are the secret scalar, and the last 32 bytes are the precomputed public key. Private keys are used to sign transactions and messages on the Stellar network.

Security considerations:

  • Private keys must be kept absolutely secret and secure
  • Never transmit private keys over insecure channels
  • Store private keys using secure storage (iOS Keychain or equivalent)
  • Never commit private keys to version control
  • Use Seed class for human-readable secret seed representation
  • Clear sensitive data from memory when no longer needed

Note: For most use cases, use the Seed class which provides the 32-byte seed and can be encoded as a human-readable secret seed (S-address).

  • Creates a new Stellar private key from the given bytes

    Throws

    Throws Ed25519Error.invalidPrivateKeyLength if the lenght of the given byte array != 64

    Declaration

    Swift

    public init(_ bytes: [UInt8]) throws

    Parameters

    bytes

    the byte array of the key. The length of the byte array must be 64

  • The raw private key bytes (64 bytes).

    The first 32 bytes are the secret scalar, and the last 32 bytes are the precomputed public key for efficient signature operations.

    Declaration

    Swift

    public var bytes: [UInt8] { get }