Skip to main content

Crypto Types

PacketKeyPair

A raw key pair used for encryption and decryption.

type PacketKeyPair = {
publicKey: Bytes; // Uint8Array
privateKey: Bytes; // Uint8Array
};

The interpretation of each field depends on the key algorithm:

AlgorithmpublicKeyprivateKey
X25519X25519 public key (32 bytes)X25519 private key (32 bytes)
SOLANA_ED25519_X25519Solana wallet public key (32 bytes)Ed25519 seed or TweetNaCl secretKey (32 or 64 bytes)

PacketCryptoIdentity

The active identity used for encryption and decryption.

type PacketCryptoIdentity = {
ownerWallet: PublicKey | string;
keyAlg: AsymmetricEncryptionAlgorithm;
keyPair: PacketKeyPair;
};

PacketCryptoIdentityInput

Accepted wherever an identity is required. Can be a full PacketCryptoIdentity or a flat object.

type PacketCryptoIdentityInput =
| PacketCryptoIdentity
| {
ownerWallet?: PublicKey | string;
keyAlg: AsymmetricEncryptionAlgorithm;
publicKey: Uint8Array;
privateKey: Uint8Array;
};

DerivePacketSeedInput

Input for useWalletPasswordCrypto / PacketEncryptionClient.useWalletPassword.

type DerivePacketSeedInput = {
password: string;
walletAddress: PublicKey | string;
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
origin?: string;
argon2?: {
parallelism?: number;
iterations?: number;
memorySize?: number;
hashLength?: number;
};
};

PacketDerivedCryptoIdentity

Returned by useWalletPasswordCrypto. Contains the derived identity and seed material.

type PacketDerivedCryptoIdentity = {
identity: PacketCryptoIdentity;
seed: DerivedPacketSeed;
};

PacketReaderInput

Describes a recipient when encrypting a message.

type PacketReaderInput = {
ownerWallet: string; // base58 wallet address
keyAlg: AsymmetricEncryptionAlgorithm; // which key algorithm
publicKey: Bytes; // recipient's public key
};

PacketEncryptParams

Passed to client.crypto.encrypt() and friends.

type PacketEncryptParams = {
plaintext: string;
readers?: PacketReaderInput[];
} & PacketEncryptionOptions;

PacketEncryptionOptions

Algorithm options shared by all encrypt methods.

type PacketEncryptionOptions = {
encoding?: BodyEncoding; // default "base64"
contentEnc?: SymmetricEncryptionAlgorithm;
keyKdf?: KeyDerivationAlgorithm;
keyEnc?: SymmetricEncryptionAlgorithm;
includeSelf?: boolean; // default true
maxInlineBytes?: number;
};

PacketDecryptParams

Passed to client.crypto.decrypt().

type PacketDecryptParams = {
body: PacketEncryptedBody | string;
identity?: PacketCryptoIdentityInput;
};

PacketMaybeDecryptResult

Returned by client.crypto.maybeDecrypt().

type PacketMaybeDecryptResult =
| { encrypted: true; plaintext: string; body: PacketEncryptedBody }
| { encrypted: false; plaintext: string };

PacketEncryptedBody

The serialized output of encrypt. Store this as a content string in message fields.

type PacketEncryptedBody = {
ver: 1;
content: EncryptedContent; // ciphertext + key hash
readers: ReaderEntry[]; // one per recipient
};

AsymmetricEncryptionAlgorithm

Identifies which asymmetric algorithm was used to wrap the content key.

enum AsymmetricEncryptionAlgorithm {
X25519 = "X25519",
SOLANA_ED25519_X25519 = "SOLANA-ED25519-X25519",
}

KeyDerivationAlgorithm

enum KeyDerivationAlgorithm {
HKDF_SHA256 = "HKDF-SHA256",
NACL_BOX_BEFORE = "NACL-BOX-BEFORE",
}

SymmetricEncryptionAlgorithm

enum SymmetricEncryptionAlgorithm {
A256GCM = "A256GCM",
XSALSA20_POLY1305 = "XSALSA20-POLY1305",
}

BodyEncoding

type BodyEncoding = "base64" | "utf8";

Controls how ciphertext bytes are serialized inside PacketEncryptedBody. "base64" is the default.