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().Functions
- initWasm
- tdh2Encrypt
- tdh2Verify
- tdh2Combine
- decryptPartial
- uuidToLabel
initWasm
Initializes the WebAssembly module required for all TDH2 cryptographic operations. Must be called once before any other crypto function.| Function | Type |
|---|---|
initWasm | () => Promise<void> |
Example
tdh2Encrypt
Encrypts plaintext using TDH2 threshold encryption against the DKG global public key.| Function | Type |
|---|---|
tdh2Encrypt | (params: TDH2EncryptParams) => Promise<TDH2Ciphertext> |
params.plaintext:Uint8Array- The data to encryptparams.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.| Function | Type |
|---|---|
tdh2Verify | (params: TDH2VerifyParams) => Promise<boolean> |
params.ciphertext:Uint8Array- The raw ciphertext bytesparams.globalPubKey:Uint8Array- DKG global public keyparams.label:Uint8Array- The 32-byte label used during encryption
Example
tdh2Combine
Combines threshold partial decryptions to recover the original plaintext.| Function | Type |
|---|---|
tdh2Combine | (params: TDH2CombineParams) => Promise<Uint8Array> |
params.ciphertext:TDH2Ciphertext- The encrypted data ({ raw, label })params.partials:DecryptedPartial[]- Array of decrypted partials (must have>= threshold)params.globalPubKey:Uint8Array- DKG global public keyparams.label:Uint8Array- 32-byte labelparams.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).| Function | Type |
|---|---|
decryptPartial | (params: DecryptPartialParams) => Promise<Uint8Array> |
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
- ECDH:
sharedPoint = secp256k1(recipientPrivKey, ephemeralPubKey) - HKDF-SHA256:
aesKey = hkdf(sha256, sharedSecret, info="dkg-tdh2-partial", 32) - AES-256-GCM: decrypt with 12-byte nonce from the encrypted partial
uuidToLabel
Derives a deterministic 32-byte label from a vault UUID. Used to bind ciphertext to a specific vault.| Function | Type |
|---|---|
uuidToLabel | (uuid: number) => Uint8Array |
uuid:number- The vault UUID (uint32)
Uint8Array: 28 zero bytes followed by the 4-byte big-endian UUID.
Example

