PublicKey
public final class PublicKey : XDRCodable, Sendable
Represents a Stellar Ed25519 public key.
A public key is a 32-byte value that represents the public component of an Ed25519 keypair. Public keys are used to identify accounts on the Stellar network and to verify signatures.
Public keys are encoded as Stellar account IDs (G-addresses) using base32 encoding with version byte and checksum. This encoding makes them human-readable and helps prevent transmission errors.
Usage:
- Creating from bytes: Construct from raw 32-byte public key
- Creating from account ID: Parse from G-address string
- Signature verification: Verify transaction signatures
- XDR encoding/decoding: For network protocol operations
Security considerations:
- Public keys can be safely shared and are meant to be public
- They do not grant access to accounts on their own
- Used to verify that operations were signed by the corresponding private key
-
Human readable Stellar account ID.
Declaration
Swift
public var accountId: String { get } -
Creates a new Stellar public key from the given bytes
Throws
Throws Ed25519Error.invalidPublicKeyLength if the lenght of the given byte array != 32
Declaration
Swift
public convenience init(_ bytes: [UInt8]) throwsParameters
bytesthe byte array of the key. The length of the byte array must be 32
-
Creates a new Stellar public key from the Stellar account ID
Throws
Throws Ed25519Error.invalidPublicKey if the accountId is invalid
Declaration
Swift
public convenience init(accountId: String) throwsParameters
accountIdThe Stellar account ID
-
Creates a new Stellar public key the given XDR Decoder
Throws
Throws errors if the key could not be created from the given decoder
Declaration
Swift
public required init(from decoder: Decoder) throwsParameters
decoderThe decoder
-
Byte array representation of the public key.
Declaration
Swift
public var bytes: [UInt8] { get } -
Wraps the public key bytes in a WrappedData32 structure for XDR encoding.
This method is used internally for encoding the public key in XDR format for network protocol operations.
Declaration
Swift
public func wrappedData32() -> WrappedData32Return Value
A WrappedData32 containing the 32-byte public key
-
Encodes the public key to the given XDR Encoder
Declaration
Swift
public func encode(to encoder: Encoder) throwsParameters
encoderthe xdr encoder
-
Verify the provided data and signature match this public key.
Throws
Ed25519Error.invalidSignatureLength if the signature length is not 64
Declaration
Swift
public func verify(signature: [UInt8], message: [UInt8]) throws -> BoolParameters
signatureThe signature. Byte array must have a lenght of 64.
messageThe data that was signed.
Return Value
True if they match, false otherwise.
View on GitHub
Install in Dash