Skip to main content

Account

Overview

Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from an existing private key or seed, and message signing and verification functionality.

An Aleo Account is generated from a randomly generated seed (number) from which an account private key, view key, and a public account address are derived. The private key lies at the root of an Aleo account. It is a highly sensitive secret and should be protected as it allows for creation of Aleo Program executions and arbitrary value transfers. The View Key allows for decryption of a user's activity on the blockchain. The Address is the public address to which other users of Aleo can send Aleo credits and other records to. This class should only be used in environments where the safety of the underlying key material can be assured.

Kind: global class

account.encryptAccount(ciphertext) ⇒ PrivateKeyCiphertext

Encrypt the account's private key with a password

Kind: instance method of Account

ParamType
ciphertextstring

Example

let account = new Account();
let ciphertext = account.encryptAccount("password");

account.decryptRecord(ciphertext) ⇒ Record

Decrypts a Record in ciphertext form into plaintext

Kind: instance method of Account

ParamType
ciphertextstring

Example

let account = new Account();
let record = account.decryptRecord("record1ciphertext");

account.decryptRecords(ciphertexts) ⇒ Array.<Record>

Decrypts an array of Records in ciphertext form into plaintext

Kind: instance method of Account

ParamType
ciphertextsArray.<string>

Example

let account = new Account();
let record = account.decryptRecords(["record1ciphertext", "record2ciphertext"]);

account.ownsRecordCiphertext(ciphertext) ⇒ boolean

Determines whether the account owns a ciphertext record

Kind: instance method of Account

ParamType
ciphertextRecordCipherText | string

Example

// Create a connection to the Aleo network and an account
let connection = new NodeConnection("vm.aleo.org/api");
let account = Account.fromCiphertext("ciphertext", "password");

// Get a record from the network
let record = connection.getBlock(1234);
let recordCipherText = record.transactions[0].execution.transitions[0].id;

// Check if the account owns the record
if account.ownsRecord(recordCipherText) {
// Then one can do something like:
// Decrypt the record and check if it's spent
// Store the record in a local database
// Etc.
}

account.sign(message) ⇒ Signature

Signs a message with the account's private key. Returns a Signature.

Kind: instance method of Account

ParamType
messageUint8Array

Example

let account = new Account();
let message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
account.sign(message);

account.verify(message, signature) ⇒ boolean

Verifies the Signature on a message.

Kind: instance method of Account

ParamType
messageUint8Array
signatureSignature

Example

let account = new Account();
let message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
let signature = account.sign(message);
account.verify(message, signature);

Account.fromCiphertext(ciphertext, password) ⇒ PrivateKey | Error

Attempts to create an account from a private key ciphertext

Kind: static method of Account

ParamType
ciphertextPrivateKeyCiphertext | string
passwordstring

Example

let ciphertext = PrivateKey.newEncrypted("password");
let account = Account.fromCiphertext(ciphertext, "password");