# Crypto services

> The cryptographic primitives the SDK builds on. Each is a service you can use independently or get via a session.

The cryptographic primitives the SDK builds on. Each is a service you can use independently or get via a session.

## PoseidonHashService

-   **Construct:** `await PoseidonHashService.create()`, async because it loads circomlibjs's WASM.
-   **Method:** `hash(inputs: Hex[])` returns `Hex`.
-   **Used by:** commitment derivation, nullifier derivation, every Merkle root inside circuits.
-   **Browser and Node:** same API both sides.

## CryptoService

-   **Construct:** `new CryptoService()`.
-   **Methods:**
    -   `generateEphemeralKeyPair()`: fresh X25519 keypair.
    -   `ecdh(privKey, pubKey)`: X25519 ECDH shared-secret derivation.
    -   `encrypt(plaintext, sharedSecret)` / `decrypt(ciphertext, sharedSecret)`: symmetric encryption layered over the ECDH output.
    -   `generateSecret()`: 48 random bytes reduced to a BN254 scalar (RFC 9380) (used for noteSecret, depositSecret).
    -   `deriveKeysFromSignature(config)`: the three account private keys plus the X25519 viewing public key, derived from a 65-byte ECDSA signature.
    -   `derivePaymentRequestKeyPair(viewingPrivateKey, ownerAddress, paymentId)`: deterministic X25519 keypair for a payment request (HKDF-SHA256). It is re-derivable on demand, so the private key never needs persisting.

## NoteComputationService

-   **Wraps:** PoseidonHashService and CryptoService for note-specific math.
-   **Methods:**
    -   `computeNoteAddressHash(ownerAddress, noteSecret)`
    -   `computePrecommitment(noteAddressHash, tokenId, value)`
    -   `computeLabel(precommitment, depositSecret)`
    -   `computeFullCommitment({noteAddressHash, tokenId, value, label})`
    -   `computeNullifier(privateNullifyingKey, commitment)`
    -   `computeAuthDigest(privateRevocableKey)`

## WitnessPreparationService

Builds the full input set the circuits need from your [note](/concepts/notes) and chain state. Used internally by `ProofService`, and rarely a direct dependency for callers.

## ProofService

Wraps a Groth16 prover (snarkjs under the hood) with a circuit-artifacts loader. Called by `TransactOrchestrator` to actually generate proofs.

Sources: `v2-monorepo/packages/sdk/src/services/`
