developer

SDK Reference

Core library API documentation

SDK Not Yet Published

The @mini-veil/core and @mini-veil/relayer packages are not yet available on npm. All code examples below are provided for reference and will work once the SDK is published. For now, the source code lives in the packages/core and packages/relayer directories of the Mini Veil repository and can be consumed directly via workspace imports.

Coming Soonnpm install @mini-veil/core

Overview#

The @mini-veil/core package provides all cryptographic primitives and protocol operations as a TypeScript library. It is organized into four modules.

Installation#

npm install @mini-veil/core   # coming soon — see callout above

Module: keys#

Key generation and management.

generateVeilKeys(seed?)#

Derives the full protocol key hierarchy from an optional seed.

import { generateVeilKeys } from "@mini-veil/core";

const keys = generateVeilKeys();
// {
//   l1: { low, high },        // Ed25519 keypair (field elements)
//   x25519: { publicKey, secretKey },
//   spendingKey: bigint,
//   viewingKey: bigint,
//   spendingBlinding: bigint,
//   viewingBlinding: bigint,
//   commitment: bigint,
// }

poseidonHash(inputs)#

Unified Poseidon hash supporting 1-3 inputs.

import { poseidonHash } from "@mini-veil/core";

poseidonHash([a]);              // Poseidon(1)(a)
poseidonHash([a, b]);           // Poseidon(2)(a, b)
poseidonHash([a, b, c]);        // Poseidon(3)(a, b, c)

deriveMixerNullifier(spendingKey, counter)#

Derives the nullifier for a given spending key and counter.

import { deriveMixerNullifier } from "@mini-veil/core";

const nullifier = deriveMixerNullifier(spendingKey, counter);

Field Utilities#

import { modField, fieldToBytesLE, bytesToField } from "@mini-veil/core";

modField(value);            // Reduce modulo BN254 field
fieldToBytesLE(field);      // 32-byte little-endian
bytesToField(bytes);        // Big-endian bytes to field element

Module: mixer#

Deposit creation and proof generation.

createDeposit(spendingKey, denomination, counter, secret)#

Creates a deposit note with nullifier, nullifierHash, and leaf commitment.

import { createDeposit } from "@mini-veil/core";

const deposit = createDeposit(spendingKey, DENOM_0_1, 0n, randomSecret());
// { nullifier, nullifierHash, leaf, commitment }

generateWithdrawalProof(root, pathElements, pathIndices, spendingKey, counter, secret, recipient, denomination, wasmPath, zkeyPath)#

Generates a Groth16 withdrawal proof via snarkjs.

const result = await generateWithdrawalProof(
  root, pathElements, pathIndices,
  spendingKey, counter, secret,
  recipient, denomination,
  "mixer_withdraw.wasm",
  "mixer_withdraw_final.zkey",
);
// { proof, publicSignals }

packG1(point) / packG2(point) / packPublicSignals(publicSignals)#

Packs proof components into Solana-compatible byte arrays.

import { packG1, packG2, packPublicSignals } from "@mini-veil/core";

const proofA = packG1(proof.pi_a);
const proofB = packG2(proof.pi_b);
const proofC = packG1(proof.pi_c);
const pubInputs = packPublicSignals(publicSignals);

withdrawCompressed(...)#

Combined proof generation and packing.

import { withdrawCompressed } from "@mini-veil/core";

const packed = await withdrawCompressed(
  root, pathElements, pathIndices,
  spendingKey, counter, secret,
  recipient, denomination,
  "mixer_withdraw.wasm",
  "mixer_withdraw_final.zkey",
);
// { proofA, proofB, proofC, publicInputs, nullifierHashBytes }

Module: stealth#

Stealth address generation and scanning.

generateStealthAddress(metaAddress)#

Generates a one-time stealth address for a recipient.

import { generateStealthAddress } from "@mini-veil/core";

const stealth = generateStealthAddress({
  spendingPubKey: recipientSpendingKey,
  viewingPubKey: recipientViewingKey,
});
// { address, ephemeralPubKey, encryptedEphemeralKey, viewTag }

scanForStealthPayments(viewingPrivKey, spendingPrivKey, announcements, connection)#

Scans announcements for stealth payments to this key holder.

import { scanForStealthPayments } from "@mini-veil/core";

const payments = await scanForStealthPayments(
  viewingPrivKey, spendingPrivKey,
  announcements, connection,
);
// [{ stealthAddress, stealthPrivateKey, amount, ... }]

createScalarSigner(scalar)#

Creates a transaction signer from a raw Ed25519 scalar (used for claiming stealth payments).

import { createScalarSigner } from "@mini-veil/core";

const signer = createScalarSigner(stealthPrivKeyScalar);

Module: eta#

Coming Soon

ETA (Encrypted Transfer Amount) is not yet implemented. The module will enable confidential balance states where transfer amounts are encrypted on-chain and only decryptable by the sender and recipient.

Encrypted Transfer Amount (ETA) operations for confidential balance states.

import {
  generateEtaKeyPair,
  encryptAmount,
  decryptAmount,
  generateEtaProof,
} from "@mini-veil/core";   // coming soon

const keyPair = generateEtaKeyPair();
const ct = encryptAmount(keyPair.key, nonce, amount);
const decrypted = decryptAmount(keyPair.key, nonce, ct);

Relayer SDK#

Coming Soon

The @mini-veil/relayer package is not yet published to npm. For now the relayer source lives in the packages/relayer directory of the Mini Veil repository.

The relayer package (@mini-veil/relayer) exposes:

import { DepositRelayer, PoseidonMerkleTree, multisigPda } from "@mini-veil/relayer";   // coming soon

const tree = new PoseidonMerkleTree(20, poseidon2);
const relayer = new DepositRelayer(connection, program, admin, oracles, tree, denomination);