Documentation Index
Fetch the complete documentation index at: https://mintlify.com/provablehq/snarkvm/llms.txt
Use this file to discover all available pages before exploring further.
The account module provides cryptographic account types for the Aleo blockchain. All account types are generic over a Network parameter.
PrivateKey
The root secret for an Aleo account, derived from a random seed.
Structure
pub struct PrivateKey<N: Network> {
seed: Field<N>,
sk_sig: Scalar<N>,
r_sig: Scalar<N>,
}
The account seed that derives the full private key
The derived signature secret key
The derived signature randomizer
Methods
new
fn new<R: Rng + CryptoRng>(rng: &mut R) -> Result<Self>
Samples a new random private key
seed
fn seed(&self) -> Field<N>
Returns the account seed
sk_sig
fn sk_sig(&self) -> Scalar<N>
Returns the signature secret key
r_sig
fn r_sig(&self) -> Scalar<N>
Returns the signature randomizer
sign_bits
fn sign_bits<R: Rng + CryptoRng>(&self, message: &[bool], rng: &mut R) -> Result<Signature<N>>
Signs a message represented as bits
Example
use snarkvm_console::account::PrivateKey;
use snarkvm_console::network::MainnetV0;
type CurrentNetwork = MainnetV0;
// Generate a new private key
let private_key = PrivateKey::<CurrentNetwork>::new(&mut rng)?;
// Access components
let seed = private_key.seed();
let sk_sig = private_key.sk_sig();
let r_sig = private_key.r_sig();
// Sign a message
let message = "Hello, Aleo!".as_bytes().to_bits_le();
let signature = private_key.sign_bits(&message, &mut rng)?;
Serialization
Private keys are serialized in Bech32 format with prefix APrivateKey1:
APrivateKey1zkp8cC4jgHEBnbtu3xxs1Ndja2EMizcvTRDq5Nikdkukg1p
ViewKey
The account view key used to decrypt records and ciphertext.
Structure
pub struct ViewKey<N: Network>(Scalar<N>);
The view key scalar value
Methods
from_scalar
fn from_scalar(view_key: Scalar<N>) -> Self
Initializes the account view key from a scalar
Derivation
The view key is derived from a private key:
let private_key = PrivateKey::<CurrentNetwork>::new(&mut rng)?;
let view_key = ViewKey::try_from(&private_key)?;
Serialization
View keys use Bech32 format with prefix AViewKey1:
AViewKey1n1n3ZbnVEtXVe3La2xWkUvY3EY7XaCG6RZJJ3tbvrrrD
ComputeKey
The compute key used for program execution and record encryption.
Structure
pub struct ComputeKey<N: Network> {
pk_sig: Group<N>,
pr_sig: Group<N>,
sk_prf: Scalar<N>,
}
The signature public key (G^sk_sig)
The signature public randomizer (G^r_sig)
The PRF secret key derived from pk_sig and pr_sig
Methods
pk_sig
fn pk_sig(&self) -> Group<N>
Returns the signature public key
pr_sig
fn pr_sig(&self) -> Group<N>
Returns the signature public randomizer
sk_prf
fn sk_prf(&self) -> Scalar<N>
Returns the PRF secret key
to_address
fn to_address(&self) -> Address<N>
Derives the address from this compute key
Example
let private_key = PrivateKey::<CurrentNetwork>::new(&mut rng)?;
let compute_key = ComputeKey::try_from(&private_key)?;
let address = compute_key.to_address();
Serialization
Compute keys use Bech32 format with prefix AComputeKey1.
Address
The unique ID of an Aleo account, derived from its view key.
Structure
pub struct Address<N: Network> {
address: Group<N>,
}
The underlying group element representing the address
Methods
new
fn new(group: Group<N>) -> Self
Initializes an address from a group element
Initializes a zero address (for testing)
Derivation
Addresses are derived from private keys, view keys, or compute keys:
let private_key = PrivateKey::<CurrentNetwork>::new(&mut rng)?;
let address = Address::try_from(&private_key)?;
// Or from a view key
let view_key = ViewKey::try_from(&private_key)?;
let address = Address::try_from(&view_key)?;
// Or from a compute key
let compute_key = ComputeKey::try_from(&private_key)?;
let address = compute_key.to_address();
Serialization
Addresses use Bech32 format with prefix aleo1:
aleo1wvgwnqvy46qq0zemj0k6sfp3zv0mp77rw97khvwuhac05yuwscxqmfyhwf
Signature
A digital signature proving knowledge of a private key.
Structure
pub struct Signature<N: Network> {
challenge: Scalar<N>,
response: Scalar<N>,
compute_key: ComputeKey<N>,
}
The verifier challenge to check against
The prover response to the challenge
The compute key of the prover
Methods
sign
fn sign<R: Rng>(private_key: &PrivateKey<N>, message: &[Field<N>], rng: &mut R) -> Result<Self>
Signs a message with a private key
verify
fn verify(&self, address: &Address<N>, message: &[Field<N>]) -> bool
Verifies the signature against an address and message
verify_bits
fn verify_bits(&self, address: &Address<N>, message: &[bool]) -> bool
Verifies the signature against an address and message in bit representation
challenge
fn challenge(&self) -> Scalar<N>
Returns the verifier challenge
response
fn response(&self) -> Scalar<N>
Returns the prover response
compute_key
fn compute_key(&self) -> ComputeKey<N>
Returns the signer compute key
to_address
fn to_address(&self) -> Address<N>
Returns the signer address
Example
use snarkvm_console::account::{PrivateKey, Address, Signature};
use snarkvm_console::types::Field;
use snarkvm_console::network::MainnetV0;
type CurrentNetwork = MainnetV0;
// Generate key and address
let private_key = PrivateKey::<CurrentNetwork>::new(&mut rng)?;
let address = Address::try_from(&private_key)?;
// Sign a message
let message: Vec<Field<CurrentNetwork>> = vec![
Field::from_u64(1),
Field::from_u64(2),
Field::from_u64(3),
];
let signature = Signature::sign(&private_key, &message, &mut rng)?;
// Verify the signature
assert!(signature.verify(&address, &message));
// Verify with bits
let message_bits = "Hello, Aleo!".as_bytes().to_bits_le();
let signature_bits = private_key.sign_bits(&message_bits, &mut rng)?;
assert!(signature_bits.verify_bits(&address, &message_bits));
Serialization
Signatures use Bech32 format with prefix sign1 (216 characters total).
Account Derivation Chain
The complete account derivation chain:
PrivateKey (seed: Field<N>)
↓
├─→ ViewKey (Scalar<N>)
│ ↓
│ └─→ Address (Group<N>)
│
└─→ ComputeKey (pk_sig, pr_sig, sk_prf)
↓
└─→ Address (Group<N>)
All keys derive the same address:
let private_key = PrivateKey::<CurrentNetwork>::new(&mut rng)?;
let view_key = ViewKey::try_from(&private_key)?;
let compute_key = ComputeKey::try_from(&private_key)?;
let addr1 = Address::try_from(&private_key)?;
let addr2 = Address::try_from(&view_key)?;
let addr3 = compute_key.to_address();
assert_eq!(addr1, addr2);
assert_eq!(addr2, addr3);
See Also