Skip to main content

Crypto Utilities

These are the low-level cryptographic functions used internally by the CDR SDK. You typically won’t need to call these directly unless you’re building custom decryption flows.
All crypto functions require WASM to be initialized first via initWasm().
The current Aeneid release also includes SGX attestation verification utilities, including verifyAttestation(), for checking validator attestations against expected enclave measurements and security version values.

Functions

  • initWasm
  • tdh2Encrypt
  • tdh2Verify
  • tdh2Combine
  • decryptPartial
  • parseSgxQuote
  • verifyAttestation
  • uuidToLabel

initWasm

Initializes the WebAssembly module required for all TDH2 cryptographic operations. Must be called once before any other crypto function.
Example
Throws WasmNotInitializedError if you call any TDH2 function before initWasm() completes.

tdh2Encrypt

Encrypts plaintext using TDH2 threshold encryption against the DKG global public key. Parameters:
  • params.plaintext: Uint8Array - The data to encrypt
  • params.globalPubKey: Uint8Array - DKG global public key (34 bytes with Ed25519 prefix)
  • params.label: Uint8Array - 32-byte label binding ciphertext to a specific vault
Example
TDH2Ciphertext

tdh2Verify

Validates a TDH2 ciphertext without decrypting. Useful for checking integrity. Parameters:
  • params.ciphertext: Uint8Array - The raw ciphertext bytes
  • params.globalPubKey: Uint8Array - DKG global public key
  • params.label: Uint8Array - The 32-byte label used during encryption
Example

tdh2Combine

Combines threshold partial decryptions to recover the original plaintext. Parameters:
  • params.ciphertext: TDH2Ciphertext - The encrypted data ({ raw, label })
  • params.partials: DecryptedPartial[] - Array of decrypted partials (must have >= threshold)
  • params.globalPubKey: Uint8Array - DKG global public key
  • params.label: Uint8Array - 32-byte label
  • params.threshold: number - Minimum number of partials required
Example
DecryptedPartial

decryptPartial

Decrypts a single encrypted partial decryption from a validator using ECIES (ECDH + HKDF + AES-256-GCM). Parameters:
  • params.encryptedPartial: Uint8Array - The encrypted partial (nonce || ciphertext || tag)
  • params.ephemeralPubKey: Uint8Array - Validator’s ephemeral public key (65 bytes, uncompressed secp256k1)
  • params.recipientPrivKey: Uint8Array - Your ephemeral private key (32 bytes, secp256k1)
Example
ECIES Protocol:
  1. ECDH: sharedPoint = secp256k1(recipientPrivKey, ephemeralPubKey)
  2. HKDF-SHA256: aesKey = hkdf(sha256, sharedSecret, info="dkg-tdh2-partial", 32)
  3. AES-256-GCM: decrypt with 12-byte nonce from the encrypted partial

verifyAttestation

Verifies a validator SGX attestation document against the expected enclave measurements and minimum security version checks. Use it with the data returned by observer.getValidatorAttestations() when your application wants an explicit MRENCLAVE, MRSIGNER, and SVN trust check. Parameters:
  • report: Uint8Array - Raw SGX DCAP Quote v3 bytes
  • config.expectedMrEnclave (optional): `0x${string}` - Expected enclave measurement
  • config.expectedMrSigner (optional): `0x${string}` - Expected signer measurement
  • config.minSecurityVersion (optional): number - Minimum allowed ISV SVN
Example
verifyAttestation() performs client-side field checks. The quote signature chain itself is verified on-chain; this helper is an extra allowlist / policy check for SDK consumers.

parseSgxQuote

Parses the key fields from an SGX DCAP Quote v3 without applying any policy. Parameters:
  • report: Uint8Array - Raw SGX DCAP Quote v3 bytes
Returns:
  • mrEnclave: `0x${string}` - Parsed enclave measurement
  • mrSigner: `0x${string}` - Parsed signer measurement
  • securityVersion: number - Parsed ISV SVN
Example

uuidToLabel

Derives a deterministic 32-byte label from a vault UUID. Used to bind ciphertext to a specific vault. Parameters:
  • uuid: number - The vault UUID (uint32)
Returns a 32-byte Uint8Array: 28 zero bytes followed by the 4-byte big-endian UUID.
Example