Skip to content

PrivateKey

MarcoDotIO edited this page Apr 25, 2023 · 1 revision

PrivateKey

The ED25519 Private Key

public struct PrivateKey: Equatable, KeyProtocol, CustomStringConvertible 

Inheritance

CustomStringConvertible, Equatable, KeyProtocol

Initializers

init(key:)

public init(key: Data) 

Properties

LENGTH

The length of the key in bytes

public static let LENGTH: Int = 32

key

The key itself

public let key: Data

description

public var description: String 

Methods

hex()

Converts the private key to a hexadecimal string.

public func hex() -> String 

Returns

A string representation of the private key in hexadecimal format, with a "0x" prefix.

fromHex(_:)

Creates a PrivateKey instance from a hex string.

public static func fromHex(_ value: String) -> PrivateKey 

Parameters

  • value: A string representing the private key in hexadecimal format.

Returns

A PrivateKey instance representing the private key.

publicKey()

Calculates the corresponding public key for this private key instance using the Ed25519 algorithm.

public func publicKey() throws -> PublicKey 

Throws

An error if the calculation of the public key fails, or if the public key cannot be used to create a PublicKey instance.

Returns

A PublicKey instance representing the public key associated with this private key.

random()

Generates a new random private key using the Ed25519 algorithm.

public static func random() throws -> PrivateKey 

Throws

An error if the generation of the key pair fails or if the generated private key cannot be used to create a PrivateKey instance.

Returns

A new PrivateKey instance with a randomly generated private key.

sign(data:)

Signs a message using this private key and the Ed25519 algorithm.

public func sign(data: Data) throws -> Signature 

Parameters

  • data: The message to be signed.

Throws

An error if the signing operation fails or if the resulting signature cannot be used to create a Signature instance.

Returns

A Signature instance representing the signature for the message.

deserialize(from:)

public static func deserialize(from deserializer: Deserializer) throws -> PrivateKey 

serialize(_:)

public func serialize(_ serializer: Serializer) throws 

Operators

==

public static func == (lhs: PrivateKey, rhs: PrivateKey) -> Bool 
Types
Protocols
Global Variables
Global Functions
Extensions
Clone this wiki locally