pub struct KeyVault { /* private fields */ }Expand description
High-level Key Management module for the Qualia Node.
Implementations§
Source§impl KeyVault
impl KeyVault
pub fn open_native_secure( _storage_dir: &str, _create: bool, ) -> Result<Self, String>
pub fn is_native_secure(&self) -> bool
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an in-memory KeyVault with a fresh ephemeral key (for tests/stubs only).
Sourcepub fn load_or_generate(storage_dir: &str) -> Result<Self, String>
pub fn load_or_generate(storage_dir: &str) -> Result<Self, String>
Loads an existing vault or generates one.
Sourcepub fn derive_key(&self, context_id: &str) -> SigningKey
pub fn derive_key(&self, context_id: &str) -> SigningKey
Derives a deterministic Pairwise or Front Door key from the Master Key. This ensures we can recover all DIDs from the single master root.
Sourcepub fn derive_key_for_role(&self, role: KeyRole) -> SigningKey
pub fn derive_key_for_role(&self, role: KeyRole) -> SigningKey
Purpose-separated child key for a closed KeyRole.
Host paths request this (or Self::request_role_seed) at use-time.
Agents never hold the returned material — only the vault does.
Sourcepub fn request_role_seed(&self, role: KeyRole) -> Result<[u8; 32], String>
pub fn request_role_seed(&self, role: KeyRole) -> Result<[u8; 32], String>
Request 32-byte seed for role (host-only). Never log or put in Quins.
Returns Err when the vault is locked. Callers must zeroize after use when the seed is no longer needed for the active operation.
Sourcepub fn agent_request_role(&self, role: KeyRole) -> KeyRoleGrant
pub fn agent_request_role(&self, role: KeyRole) -> KeyRoleGrant
Agent-facing grant: purpose metadata only — never key material.
Sourcepub fn sign_payload(
&self,
signing_key: &SigningKey,
payload: &[u8],
) -> Signature
pub fn sign_payload( &self, signing_key: &SigningKey, payload: &[u8], ) -> Signature
Computes an Ed25519 signature over a generic byte payload
Sourcepub fn get_master_key_bytes(&self) -> [u8; 32]
pub fn get_master_key_bytes(&self) -> [u8; 32]
Exposes the raw bytes of the master key for libp2p identity bindings
Sourcepub fn public_key_bytes_for_context(&self, context_id: &str) -> [u8; 32]
pub fn public_key_bytes_for_context(&self, context_id: &str) -> [u8; 32]
Ed25519 verifying key bytes for a context-derived pairwise key.
Sourcepub fn verify_signature(
public_key_bytes: &[u8; 32],
payload: &[u8],
signature_bytes: &[u8; 64],
) -> Result<(), String>
pub fn verify_signature( public_key_bytes: &[u8; 32], payload: &[u8], signature_bytes: &[u8; 64], ) -> Result<(), String>
Verifies a payload against a given public key bytes
Sourcepub fn generate_webid_tls_cert(
&self,
key: &SigningKey,
did_uri: &str,
) -> Result<(String, String), String>
pub fn generate_webid_tls_cert( &self, key: &SigningKey, did_uri: &str, ) -> Result<(String, String), String>
Generates a WebID-TLS / mTLS compatible self-signed X.509 certificate.
The DID URI is placed in the Subject Alternative Name URI extension so
transport identity can be bound to the Qualia principal. Uses real rcgen
PEM output (not a mock). Private key material is the provided Ed25519 seed
encoded as PKCS#8 PEM.
Source§impl KeyVault
impl KeyVault
Sourcepub fn issue_qapp_token(
&self,
qapp_did: &str,
audience: &str,
expiry_epoch: u64,
nonce: &str,
capabilities: Vec<String>,
sensitivity_clearance: SubgraphLayer,
) -> Result<String, String>
pub fn issue_qapp_token( &self, qapp_did: &str, audience: &str, expiry_epoch: u64, nonce: &str, capabilities: Vec<String>, sensitivity_clearance: SubgraphLayer, ) -> Result<String, String>
Issues a cryptographically signed Semantic Token for an installed qapp. The token enforces gatekeeper boundary policies (which shapes the qapp can access).
Sourcepub fn verify_qapp_token(
&self,
token: &str,
expected_audience: &str,
) -> Result<QappSessionTokenV2, String>
pub fn verify_qapp_token( &self, token: &str, expected_audience: &str, ) -> Result<QappSessionTokenV2, String>
Verifies a qapp token’s signature using the Master Key, and checks expiry and audience.
Source§impl KeyVault
impl KeyVault
Sourcepub fn generate_layer_key(&self, layer: SubgraphLayer) -> SubgraphKey
pub fn generate_layer_key(&self, layer: SubgraphLayer) -> SubgraphKey
Derive a deterministic AES-256-GCM key for layer using HKDF-SHA-256.
IKM = master ed25519 secret key bytes (32 bytes)
Salt = b“qualia:subgraph:salt:v1“
Info = layer.label() bytes
Sourcepub fn encapsulate_for_recipient(
&self,
layer_key: &SubgraphKey,
recipient_x25519_pub: &[u8; 32],
nonce_entropy: &[u8; 32],
) -> Result<EncapsulatedKey, String>
pub fn encapsulate_for_recipient( &self, layer_key: &SubgraphKey, recipient_x25519_pub: &[u8; 32], nonce_entropy: &[u8; 32], ) -> Result<EncapsulatedKey, String>
Encapsulate layer_key for a recipient identified by their X25519 public key bytes.
Uses ephemeral X25519 ECDH + AES-256-GCM to wrap the 32-byte layer key.
The recipient_x25519_pub is typically derived from the recipient’s DID key material.
§Errors
Returns Err if the recipient public key bytes are invalid.
Sourcepub fn decapsulate(
&self,
encapsulated: &EncapsulatedKey,
recipient_x25519_secret: &[u8; 32],
) -> Result<SubgraphKey, String>
pub fn decapsulate( &self, encapsulated: &EncapsulatedKey, recipient_x25519_secret: &[u8; 32], ) -> Result<SubgraphKey, String>
Decapsulate an EncapsulatedKey using the recipient’s X25519 static secret key bytes.
Returns the 32-byte layer key on success.
Sourcepub fn derive_x25519_secret(&self) -> [u8; 32]
pub fn derive_x25519_secret(&self) -> [u8; 32]
Derive the X25519 static secret for this node from the master Ed25519 key.
Used when the node itself is a VC recipient.
Auto Trait Implementations§
impl Freeze for KeyVault
impl RefUnwindSafe for KeyVault
impl Send for KeyVault
impl Sync for KeyVault
impl Unpin for KeyVault
impl UnsafeUnpin for KeyVault
impl UnwindSafe for KeyVault
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more