EncryptionState
Holds AES key and encryption keypair derived from ECDH
Holds the AES-GCM key and encryption keypair derived from ECDH key exchange.
Overview
EncryptionState encapsulates all cryptographic material needed for shielded transactions and signed reads. It's created by get_encryption() during wallet client setup and attached to w3.seismic.encryption.
The class provides encrypt() and decrypt() methods that handle AES-GCM encryption with metadata-bound Additional Authenticated Data (AAD).
Definition
@dataclass
class EncryptionState:
"""Holds the AES key and encryption keypair derived from ECDH.
Created by :func:`get_encryption` during client setup. Pure
computation - works in both sync and async contexts.
Attributes:
aes_key: 32-byte AES-256 key derived from ECDH + HKDF.
encryption_pubkey: Client's compressed secp256k1 public key.
encryption_private_key: Client's secp256k1 private key.
"""
aes_key: Bytes32
encryption_pubkey: CompressedPublicKey
encryption_private_key: PrivateKeyAttributes
Methods
encrypt()
Encrypt plaintext calldata with metadata-bound AAD.
Signature
Parameters
plaintext
HexBytes
Raw calldata to encrypt
Returns
HexBytes
Ciphertext with 16-byte authentication tag appended
Example
decrypt()
Decrypt a signed-read response with metadata-bound AAD.
The node draws a fresh IV for every response and prepends it behind a one-byte format version, so the response is version || iv || ciphertext || tag and no nonce argument is needed.
Signature
Parameters
ciphertext
HexBytes
Response bytes of the form version || iv || ciphertext || tag
Returns
HexBytes
Decrypted plaintext
Raises
ValueError- If the response is shorter than the 29-byte minimum envelope, or carries an unrecognised format versioncryptography.exceptions.InvalidTag- If authentication fails (wrong key, tampered data, or mismatched metadata)
Example
Examples
Access from Client
Manual Encryption Workflow
Custom Encryption Key
Verify Encryption/Decryption
How It Works
Initialization
When created, EncryptionState automatically initializes an internal AesGcmCrypto instance:
Encryption
Encode metadata as AAD using
encode_metadata_as_aad()Call
AesGcmCrypto.encrypt(plaintext, nonce, aad)Return ciphertext with 16-byte authentication tag
Decryption
Encode metadata as AAD
Check the format version byte, split off the 12-byte IV, then call
AesGcmCrypto.decrypt(body, iv, aad)with the version appended to the AADVerify authentication tag (raises
InvalidTagif fails)Return plaintext
AAD Binding
The Additional Authenticated Data (AAD) ensures that ciphertext is cryptographically bound to transaction metadata:
message_versionchain_idclient_pubkeynonce_seedrecent_block_hashexpires_at_block
If any metadata field changes, decryption will fail even with the correct key and nonce.
Notes
Pure computation - no I/O operations
Works in both sync and async contexts
Created automatically by
create_wallet_client()andcreate_async_wallet_client()The internal
_cryptofield is excluded fromrepr()and comparisonAuthentication tag is always 16 bytes (AES-GCM standard)
Security Considerations
AAD binding - Metadata binding prevents ciphertext reuse or manipulation
Nonce uniqueness - Nonces must be unique per encryption; SDK generates fresh nonces automatically
Key storage -
encryption_private_keyshould be stored securely if deterministic keys are used
See Also
get_encryption - Derive encryption state from TEE public key
create_wallet_client - Sync client factory (creates EncryptionState)
create_async_wallet_client - Async client factory
EncryptionNonce - 12-byte nonce type
TxSeismicMetadata - Metadata structure
Shielded Write Guide - How shielded transactions work
Last updated

