vael:age
X25519 binary age v1 encryption, decryption, and keypair utilities.
Available in the vjs (vaeljs) runtime only; absent in vjs-lite.
Supports single-recipient binary age v1 encryption and authenticated
decryption up to 8 MiB of plaintext.
import ... from "vael:age"
vaeljs-core (absent in vaeljs-lite-core)Example
Section titled “Example”import { decrypt, encrypt, generateIdentity } from "vael:age";
const { identity, recipient } = generateIdentity();const plaintext = new Uint8Array([115, 101, 99, 114, 101, 116]);const ciphertext = encrypt(recipient, plaintext);const recovered = decrypt(identity, ciphertext);console.log(recovered.length === plaintext.length);generateIdentityvjs onlyv0.0.0-alpha.0identityToRecipientvjs onlyv0.0.0-alpha.0age1... recipient for an AGE-SECRET-KEY-1... identity.encryptvjs onlyv0.0.0-alpha.0plaintext to one X25519 recipient as a binary age v1 file.decryptvjs onlyv0.0.0-alpha.0identity.Functions
Section titled “Functions”generateIdentity
Section titled “generateIdentity”export function generateIdentity(): AgeIdentity;
Generate a new X25519 identity and its matching recipient using the OS CSPRNG.
TypeError— when any argument is supplied.Error— withcode = "VAEL_AGE_RANDOM"when the OS CSPRNG fails.
import { generateIdentity } from "vael:age";
const keypair = generateIdentity();console.log(keypair.recipient.startsWith("age1"));identityToRecipient
Section titled “identityToRecipient”export function identityToRecipient(identity: string): string;
Derive the Bech32 X25519 age1... recipient for an AGE-SECRET-KEY-1...
identity.
Leading and trailing whitespace is trimmed; input is bounded to 512 bytes.
Non-X25519 identities (such as post-quantum keys) fail with
VAEL_AGE_UNSUPPORTED.
| Name | Type | Description |
|---|---|---|
identity | string | Bech32 X25519 identity string (max 512 bytes). |
string — The corresponding age1... Bech32 public recipient string.TypeError— whenidentityis not a string or arity is wrong.Error— withcode"VAEL_AGE_IDENTITY","VAEL_AGE_UNSUPPORTED", or"VAEL_AGE_INTERNAL".
import { generateIdentity, identityToRecipient } from "vael:age";
const { identity, recipient } = generateIdentity();console.log(identityToRecipient(identity) === recipient);encrypt
Section titled “encrypt”export function encrypt(recipient: string, plaintext: Uint8Array): Uint8Array;
Synchronously encrypt plaintext to one X25519 recipient as a binary
age v1 file.
Limits: plaintext is at most 8 MiB (8_388_608 bytes) and ciphertext at
most 9 MiB (9_437_184 bytes). ASCII armor, passphrases, and SSH keys are
not supported.
| Name | Type | Description |
|---|---|---|
recipient | string | Bech32 X25519 recipient string (age1...). |
plaintext | Uint8Array | Attached Uint8Array of at most 8 MiB. |
Uint8Array — Binary age v1 ciphertext bytes.TypeError— when an argument has the wrong type or arity is wrong.Error— withcode"VAEL_AGE_RECIPIENT","VAEL_AGE_UNSUPPORTED","VAEL_AGE_LIMIT","VAEL_AGE_RANDOM","VAEL_AGE_DETACHED", or"VAEL_AGE_INTERNAL".
import { encrypt, generateIdentity } from "vael:age";
const { recipient } = generateIdentity();const ciphertext = encrypt(recipient, new Uint8Array([1, 2, 3, 4]));console.log(ciphertext.byteLength > 0);decrypt
Section titled “decrypt”export function decrypt(identity: string, ciphertext: Uint8Array): Uint8Array;
Synchronously verify and decrypt a binary age v1 file using one X25519
identity.
Authenticates the header MAC and every payload chunk tag before returning
plaintext. Limits: ciphertext is at most 9 MiB and recovered plaintext
at most 8 MiB.
| Name | Type | Description |
|---|---|---|
identity | string | Bech32 X25519 identity string (AGE-SECRET-KEY-1...). |
ciphertext | Uint8Array | Attached Uint8Array containing a binary age v1 file. |
Uint8Array — Authenticated plaintext bytes.TypeError— when an argument has the wrong type or arity is wrong.Error— withcode"VAEL_AGE_AUTH","VAEL_AGE_FORMAT","VAEL_AGE_IDENTITY","VAEL_AGE_IDENTITY_MISMATCH","VAEL_AGE_UNSUPPORTED","VAEL_AGE_LIMIT","VAEL_AGE_DETACHED", or"VAEL_AGE_INTERNAL".
import { decrypt, encrypt, generateIdentity } from "vael:age";
const { identity, recipient } = generateIdentity();const sealed = encrypt(recipient, new Uint8Array([42]));const plain = decrypt(identity, sealed);console.log(plain[0]);Interfaces
Section titled “Interfaces”AgeIdentity
Section titled “AgeIdentity”export interface AgeIdentity {
identity: string;
recipient: string;
}
Generated X25519 age keypair in standard Bech32 text form.
| Property | Type | Description | Since |
|---|---|---|---|
identity | string | Secret identity string (AGE-SECRET-KEY-1...). Keep confidential. | v0.0.0-alpha.0 |
recipient | string | Public recipient string (age1...). | v0.0.0-alpha.0 |
Type Aliases
Section titled “Type Aliases”AgeErrorCode
Section titled “AgeErrorCode”export type AgeErrorCode =
| "VAEL_AGE_IDENTITY"
| "VAEL_AGE_RECIPIENT"
| "VAEL_AGE_UNSUPPORTED"
| "VAEL_AGE_FORMAT"
| "VAEL_AGE_IDENTITY_MISMATCH"
| "VAEL_AGE_AUTH"
| "VAEL_AGE_DETACHED"
| "VAEL_AGE_LIMIT"
| "VAEL_AGE_RANDOM"
| "VAEL_AGE_INTERNAL";
Error codes thrown by vael:age operations on Error.code.
