xtrace_sdk.x_vec.utils.execution_context¶
Attributes¶
Classes¶
Protocol describing all methods used by ExecutionContext on a homomorphic client. |
|
Bundles a homomorphic encryption client and an AES key under a single passphrase-protected object. |
Module Contents¶
- xtrace_sdk.x_vec.utils.execution_context._log¶
- class xtrace_sdk.x_vec.utils.execution_context.HomomorphicClient¶
Bases:
ProtocolProtocol describing all methods used by ExecutionContext on a homomorphic client.
- decode_hamming_client_batch(ciphers)¶
- class xtrace_sdk.x_vec.utils.execution_context.ExecutionContext(homomorphic_client, passphrase, context_id=None)¶
Bundles a homomorphic encryption client and an AES key under a single passphrase-protected object.
An
ExecutionContextis the root secret for a XTrace deployment. It holds:A homomorphic client (
PaillierClientorPaillierLookupClient) whose secret key is used to decrypt Hamming distances returned by the XTrace server.An AES key derived from
passphrase, used to encrypt chunk content before upload.
The secret key is never transmitted in plaintext — it is AES-encrypted with the passphrase before any remote storage. The passphrase itself is never sent anywhere.
- Parameters:
homomorphic_client (HomomorphicClient) – An initialised
PaillierClientorPaillierLookupClient.passphrase (str) – Secret passphrase used to derive the AES encryption key.
context_id (str | None) – Optional deterministic ID. If omitted, one is derived from a SHA-256 hash of the public key and configuration.
- homomorphic¶
- aes¶
- classmethod create(passphrase, homomorphic_client_type, embedding_length, key_len, path=None)¶
Create a new execution context and optionally save it to disk.
- Parameters:
passphrase (str) – Secret passphrase used to derive the AES encryption key and protect the homomorphic secret key at rest.
homomorphic_client_type (str) –
"paillier"or"paillier_lookup".embedding_length (int) – Dimension of the binary embedding vectors (must match the model).
key_len (int) – RSA modulus size in bits (minimum
1024).path (str | None) – If provided, persist the context to this file path via
save_to_disk().
- Returns:
Initialised
ExecutionContext.- Raises:
ValueError – If
homomorphic_client_typeis not recognised orembedding_length >= key_len.- Return type:
- to_dict_enc()¶
Return a serialisable dict with the secret key AES-encrypted under the passphrase.
- Return type:
- to_dict_plain()¶
Return a serialisable dict with the secret key in plaintext. Do not persist or transmit.
- Return type:
- hash()¶
Compute a deterministic SHA-256 fingerprint of this context’s cryptographic identity.
The
devicefield is excluded so that CPU and GPU contexts sharing the same keys compare as equal.- Returns:
Hex-encoded SHA-256 digest.
- Return type:
- serialize_exec_context()¶
Serialise the execution context to a JSON string suitable for storage or transmission.
The secret key is AES-encrypted under the passphrase before inclusion.
- Returns:
JSON string representing the encrypted execution context.
- Return type:
- Raises:
ValueError – If the homomorphic client type is not supported.
- classmethod _from_serialized_exec_context(passphrase, json_obj, context_id=None)¶
Reconstruct an
ExecutionContextfrom a previously serialised dict.- Parameters:
passphrase (str) – Passphrase used to decrypt the secret key.
json_obj (dict) – Dict produced by
to_dict_enc().context_id (str | None) – Optional context ID to attach; if
Noneone is recomputed from the keys.
- Returns:
Restored
ExecutionContext.- Raises:
ValueError – If the stored homomorphic client type is not supported.
- Return type:
- dump_tables()¶
Dump precomputed encryption tables (Paillier-Lookup only) for caching.
- Returns:
Dict containing
g_tableandnoise_table, or an empty dict if the underlying client does not support table export.- Return type:
- save_to_disk(path)¶
Persist the execution context to a local file.
The secret key is AES-encrypted before writing. The passphrase is not stored.
- Parameters:
path (str) – File path to write to.
- Return type:
None
- classmethod load_from_disk(passphrase, path)¶
Load an
ExecutionContextfrom a file previously saved withsave_to_disk().- Parameters:
- Returns:
Restored
ExecutionContext.- Return type:
- async save_to_remote(integration)¶
Upload the execution context to XTrace remote storage.
The secret key is AES-encrypted under the passphrase before upload — XTrace never sees the plaintext secret key or the passphrase.
- Parameters:
integration (xtrace_sdk.integrations.xtrace.XTraceIntegration) – Authenticated
XTraceIntegrationinstance.- Returns:
The
context_idassigned by the server.- Return type:
- classmethod load_from_remote(passphrase, context_id, integration)¶
- Async:
- Parameters:
passphrase (str)
context_id (str)
integration (xtrace_sdk.integrations.xtrace.XTraceIntegration)
- Return type:
Fetch and decrypt an
ExecutionContextfrom XTrace remote storage.- Parameters:
passphrase (str) – Passphrase used to decrypt the secret key.
context_id (str) – ID returned when the context was originally saved.
integration (xtrace_sdk.integrations.xtrace.XTraceIntegration) – Authenticated
XTraceIntegrationinstance.
- Returns:
Restored
ExecutionContext.- Return type: