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()
| Param | Type |
|---|---|
| return | PrivateKey |
Methods
from_seed_unchecked
Get a private key from a series of unchecked bytes
from_seed_unchecked(seed) ► PrivateKey
| Param | Type | Description |
|---|---|---|
| seed | Uint8Array | Unchecked 32 byte long Uint8Array acting as the seed for the private key |
| return | PrivateKey | Private key derived from the seed |
from_string
Get a private key from a string representation of a private key
from_string(seed) ► PrivateKey
| Param | Type | Description |
|---|---|---|
| seed | string | String representation of a private key |
| return | PrivateKey | Private 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
| Param | Type | Description |
|---|---|---|
| return | string | String representation of a private key |
to_view_key
Get the view key corresponding to the private key
to_view_key() ► ViewKey
| Param | Type |
|---|---|
| return | ViewKey |
to_address
Get the address corresponding to the private key
to_address() ► Address
| Param | Type |
|---|---|
| return | Address |
sign
Sign a message with the private key
sign(Byte) ► Signature
| Param | Type | Description |
|---|---|---|
| Byte | Uint8Array | array representing a message signed by the address |
| return | Signature | Signature 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
| Param | Type | Description |
|---|---|---|
| secret | string | Secret used to encrypt the private key |
| return | PrivateKeyCiphertext | Ciphertext 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
| Param | Type | Description |
|---|---|---|
| secret | string | Secret used to encrypt the private key |
| return | PrivateKeyCiphertext | Ciphertext 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
| Param | Type | Description |
|---|---|---|
| ciphertext | PrivateKeyCiphertext | Ciphertext representation of the private key |
| secret | string | Secret originally used to encrypt the private key |
| return | PrivateKey | Private key |