Crypto Adapter API Reference¶
The DilithiaCryptoAdapter is the core cryptographic interface shared across all Dilithia SDKs. It provides 25 methods covering mnemonic management, HD wallet derivation, signing, verification, address handling, key generation, and hashing -- all backed by dilithia-core using the ML-DSA-65 (Dilithium) post-quantum signature scheme.
Tip
In TypeScript and Python, each method is available in both sync and async variants. See Sync vs Async for details.
Java package changes (v0.3.0)
Java crypto classes have moved to org.dilithia.sdk.crypto.*. All methods now declare throws CryptoException (from org.dilithia.sdk.crypto.CryptoException) instead of throwing unchecked exceptions.
Mnemonic Operations¶
generateMnemonic¶
Generate a new BIP-39 mnemonic phrase for wallet creation.
Returns: A space-separated mnemonic phrase (typically 24 words).
validateMnemonic¶
Validate that a mnemonic phrase is well-formed according to BIP-39 rules.
| Parameter | Type | Description |
|---|---|---|
mnemonic |
string |
The mnemonic phrase to check |
Returns: Nothing on success. Throws/returns an error if the mnemonic is invalid.
seedFromMnemonic¶
Derive a 32-byte seed from a mnemonic phrase. This seed can be used for deterministic key generation.
| Parameter | Type | Description |
|---|---|---|
mnemonic |
string |
A valid BIP-39 mnemonic |
Returns: Hex-encoded 32-byte seed.
Wallet Operations¶
recoverHdWallet¶
Recover the root HD wallet account (index 0) from a mnemonic.
| Parameter | Type | Description |
|---|---|---|
mnemonic |
string |
A valid BIP-39 mnemonic |
Returns: A DilithiaAccount with address, public key, secret key, and accountIndex = 0.
recoverHdWalletAccount¶
Recover a specific HD wallet account by index from a mnemonic.
| Parameter | Type | Description |
|---|---|---|
mnemonic |
string |
A valid BIP-39 mnemonic |
accountIndex |
uint |
The HD derivation index (0-based) |
Returns: A DilithiaAccount for the specified derivation index.
createHdWalletFileFromMnemonic¶
Create an encrypted wallet file for the root account (index 0) from a mnemonic and password.
| Parameter | Type | Description |
|---|---|---|
mnemonic |
string |
A valid BIP-39 mnemonic |
password |
string |
Encryption password for the wallet file |
Returns: A DilithiaAccount whose walletFile field contains the encrypted wallet data.
createHdWalletAccountFromMnemonic¶
Create an encrypted wallet file for a specific HD account index.
| Parameter | Type | Description |
|---|---|---|
mnemonic |
string |
A valid BIP-39 mnemonic |
password |
string |
Encryption password for the wallet file |
accountIndex |
uint |
HD derivation index |
Returns: A DilithiaAccount with an encrypted walletFile for the given index.
recoverWalletFile¶
Recover an account from a previously saved encrypted wallet file.
| Parameter | Type | Description |
|---|---|---|
walletFile |
WalletFile |
The encrypted wallet file object |
mnemonic |
string |
The mnemonic used when creating the wallet |
password |
string |
The password used when creating the wallet |
Returns: A DilithiaAccount with decrypted keys and the wallet file attached.
HD Wallet Derivation¶
deriveChildSeed¶
Derive a child seed from a parent seed at a given index. Used for hierarchical deterministic key derivation.
| Parameter | Type | Description |
|---|---|---|
parentSeedHex |
string |
Hex-encoded 32-byte parent seed |
index |
uint |
Child derivation index |
Returns: Hex-encoded 32-byte child seed.
Address Operations¶
addressFromPublicKey¶
Derive a Dilithia address from a public key.
| Parameter | Type | Description |
|---|---|---|
publicKeyHex |
string |
Hex-encoded ML-DSA-65 public key |
Returns: The derived Dilithia address string.
addressFromPkChecksummed¶
Derive a checksummed Dilithia address from a public key.
| Parameter | Type | Description |
|---|---|---|
publicKeyHex |
string |
Hex-encoded ML-DSA-65 public key |
Returns: Checksummed Dilithia address.
addressWithChecksum¶
Add a checksum to a raw (un-checksummed) Dilithia address.
| Parameter | Type | Description |
|---|---|---|
rawAddr |
string |
Raw Dilithia address |
Returns: Address with an embedded checksum.
validateAddress¶
Validate a Dilithia address (including checksum verification).
| Parameter | Type | Description |
|---|---|---|
addr |
string |
Address to validate |
Returns: The normalized address on success. Throws/returns error if invalid.
Signing Operations¶
signMessage¶
Sign a message using an ML-DSA-65 secret key.
| Parameter | Type | Description |
|---|---|---|
secretKeyHex |
string |
Hex-encoded ML-DSA-65 secret key |
message |
string |
The message to sign |
Returns: A DilithiaSignature containing the algorithm identifier ("mldsa65") and the hex-encoded signature.
verifyMessage¶
Verify a signature against a public key and message.
| Parameter | Type | Description |
|---|---|---|
publicKeyHex |
string |
Hex-encoded ML-DSA-65 public key |
message |
string |
The original message |
signatureHex |
string |
Hex-encoded signature to verify |
Returns: true if the signature is valid, false otherwise.
Validation Operations¶
validatePublicKey¶
Validate that a hex string represents a well-formed ML-DSA-65 public key.
| Parameter | Type | Description |
|---|---|---|
publicKeyHex |
string |
Hex-encoded public key to check |
Returns: Nothing on success. Throws/returns error if invalid.
validateSecretKey¶
Validate that a hex string represents a well-formed ML-DSA-65 secret key.
| Parameter | Type | Description |
|---|---|---|
secretKeyHex |
string |
Hex-encoded secret key to check |
Returns: Nothing on success. Throws/returns error if invalid.
validateSignature¶
Validate that a hex string represents a well-formed ML-DSA-65 signature (structural check only -- does not verify against a message).
| Parameter | Type | Description |
|---|---|---|
signatureHex |
string |
Hex-encoded signature to validate |
Returns: Nothing on success. Throws/returns error if structurally invalid.
Key Generation¶
keygen¶
Generate a new random ML-DSA-65 keypair using a secure random source.
Returns: A DilithiaKeypair containing the secret key, public key, and derived address.
keygenFromSeed¶
Generate a deterministic ML-DSA-65 keypair from a 32-byte seed.
| Parameter | Type | Description |
|---|---|---|
seedHex |
string |
Hex-encoded 32-byte seed |
Returns: A deterministic DilithiaKeypair. The same seed always produces the same keypair.
Warning
The seed must be exactly 32 bytes (64 hex characters). Using a shorter or longer value will produce an error.
Hash Operations¶
hashHex¶
Hash hex-encoded data using the currently configured hash algorithm.
| Parameter | Type | Description |
|---|---|---|
dataHex |
string |
Hex-encoded data to hash |
Returns: Hex-encoded hash digest.
setHashAlg¶
Set the hash algorithm used by hashHex and related operations.
| Parameter | Type | Description |
|---|---|---|
alg |
string |
One of: "sha3_512", "blake2b512", "blake3_256" |
Returns: Nothing on success. Throws/returns error for unknown algorithms.
currentHashAlg¶
Return the name of the currently active hash algorithm.
Returns: The active algorithm name (e.g. "sha3_512").
hashLenHex¶
Return the output length (in hex characters) of the current hash algorithm.
Returns: The number of hex characters in a hash digest for the current algorithm.
constantTimeEq¶
Compare two hex-encoded byte strings in constant time, preventing timing side-channel attacks.
| Parameter | Type | Description |
|---|---|---|
aHex |
string |
First hex-encoded value |
bHex |
string |
Second hex-encoded value |
Returns: true if the decoded byte sequences are equal, false otherwise. The comparison runs in constant time regardless of where the values differ.
Tip
Always use constantTimeEq when comparing secrets, signatures, or hashes to avoid leaking information through timing.