Skip to main content

Crate quai_crypto

Crate quai_crypto 

Source
Expand description

Cryptographic building blocks for Quai applications.

This crate has no wallet storage or transaction wire-format assumptions. Secret keys redact diagnostics and zeroize on drop. Imported input buffers remain the caller’s responsibility. Browser entropy uses Web Crypto and is exercised in the SDK’s actual Chromium worker tests.

Modules§

curve
Validated secp256k1 arithmetic for protocol integrations.

Structs§

OrderedKeyAggregate
Ordered, untweaked MuSig key aggregation for one process owning every key.
PublicKey
A validated nonidentity secp256k1 point, represented independently of its encoding.
RecoverableSignature
A validated low-S ECDSA signature paired with its full recovery identifier.
SchnorrPublicKey
A validated BIP340 x-only public key; its implied Y coordinate is even.
SchnorrSignature
A parsed 64-byte BIP340 signature. Parsing alone does not verify a message.
SecretBytes
Explicitly exposed fixed-size secret material with redacted diagnostics. The default size is 32 bytes; full shared SEC1 points use 65 bytes.
SecretKey
A validated secret scalar, zeroized on drop and redacted in diagnostics.
SignatureMetadata
Validated parity signature with optional retained legacy EIP-155 metadata. Quai protobuf signatures use explicit chain IDs separately; this wrapper never changes their wire format or infers authorization from a legacy V.

Enums§

CryptoError
Errors never include secret input or backend diagnostic strings.

Constants§

MAX_AGGREGATE_KEYS
Resource policy for one local ordered aggregation, not a consensus input limit.
MAX_RANDOM_BYTES
Maximum entropy request, shared by native and Web Crypto callers.
MESSAGE_PREFIX
The actual personal-message prefix in pinned quais.js, despite its Quai name.

Functions§

fill_random
Fill caller-owned bytes using the operating system or browser Web Crypto. No fallback PRNG is used. Oversize requests fail before touching the buffer; a backend failure erases the destination so partial entropy cannot be used. Callers own the secrecy and erasure of successfully filled bytes.
hash_message
Hash exact message bytes with the pinned quais.js personal-sign prefix.
hmac_sha256
Compute HMAC-SHA256. Treat the returned bytes as secret when used as key material.
hmac_sha512
Compute HMAC-SHA512, used in BIP32 derivation. Derived key bytes are caller-owned secrets.
keccak256
Compute Keccak-256, which differs from standardized SHA3-256.
legacy_chain_id
Extract an EIP-155 chain ID from V. Legacy 27/28 returns zero (unspecified); parity-only 0/1 and other values below 35 reject, matching the published helper.
legacy_chain_v
Compute EIP-155 V = 2*chain_id + 35 + parity from normalized 27/28. Invalid normalized V and U256 overflow reject. No active signer policy changes.
normalized_v
Normalize parity 0/1, legacy 27/28 or EIP-155 V >= 35 to 27/28. This parses metadata only and does not establish a transaction chain.
recover_message_signer
Recover the address signing exact personal-message bytes. Text callers pass UTF-8 bytes; hex-looking text is not decoded. Recovery does not authenticate an expected signer: compare the returned address with the authorized address.
ripemd160
Compute the RIPEMD-160 digest of exact bytes, matching the pinned reference.
sha256
Compute SHA-256.
sha512
Compute SHA-512.
verify_hmac_sha256
Verify a full HMAC-SHA256 tag using the backend’s constant-time comparison.
verify_hmac_sha512
Verify a full HMAC-SHA512 tag using the backend’s constant-time comparison.

Type Aliases§

U256
Exact unsigned integer used by legacy signature metadata helpers. Uint for 256 bits.