Skip to main content

PrivateKey

Overview

Private key class for an Aleo account. Provides methods for generating, importing, and using private keys for cryptographic operations including signing, encryption, and account derivation.

Constructor

PrivateKey

Generate a new private key using a cryptographically secure random number generator

PrivateKey()
ParamType
returnPrivateKey

Methods

from_seed_unchecked

Get a private key from a series of unchecked bytes

from_seed_unchecked(seed)PrivateKey
ParamTypeDescription
seedUint8ArrayUnchecked 32 byte long Uint8Array acting as the seed for the private key
returnPrivateKeyPrivate key derived from the seed

from_string

Get a private key from a string representation of a private key

from_string(seed)PrivateKey
ParamTypeDescription
seedstringString representation of a private key
returnPrivateKeyPrivate key object

to_string

Get a string representation of the private key. This function should be used very carefully as it exposes the private key plaintext

to_string() ► string
ParamTypeDescription
returnstringString representation of a private key

to_view_key

Get the view key corresponding to the private key

to_view_key()ViewKey
ParamType
returnViewKey

to_address

Get the address corresponding to the private key

to_address()Address
ParamType
returnAddress

sign

Sign a message with the private key

sign(Byte)Signature
ParamTypeDescription
ByteUint8Arrayarray representing a message signed by the address
returnSignatureSignature generated by signing the message with the address

newEncrypted

Get a new randomly generated private key ciphertext using a secret. The secret is sensitive and will be needed to decrypt the private key later, so it should be stored securely

newEncrypted(secret)PrivateKeyCiphertext
ParamTypeDescription
secretstringSecret used to encrypt the private key
returnPrivateKeyCiphertextCiphertext representation of the private key

toCiphertext

Encrypt an existing private key with a secret. The secret is sensitive and will be needed to decrypt the private key later, so it should be stored securely

toCiphertext(secret)PrivateKeyCiphertext
ParamTypeDescription
secretstringSecret used to encrypt the private key
returnPrivateKeyCiphertextCiphertext representation of the private key

fromPrivateKeyCiphertext

Get private key from a private key ciphertext and secret originally used to encrypt it

fromPrivateKeyCiphertext(ciphertext, secret)PrivateKey
ParamTypeDescription
ciphertextPrivateKeyCiphertextCiphertext representation of the private key
secretstringSecret originally used to encrypt the private key
returnPrivateKeyPrivate key