pub struct AgentWrapper { /* private fields */ }Expand description
Thread-safe wrapper around a JACS Agent.
This provides the core agent functionality that all bindings share. Bindings wrap this in their own types and convert errors appropriately.
Implementations§
Source§impl AgentWrapper
impl AgentWrapper
Sourcepub fn from_inner(inner: Arc<Mutex<Agent>>) -> Self
pub fn from_inner(inner: Arc<Mutex<Agent>>) -> Self
Create an agent wrapper from an existing Arc<Mutex
This is used by the Go FFI to share the agent handle’s inner agent with binding-core’s attestation methods.
Sourcepub fn inner_arc(&self) -> Arc<Mutex<Agent>>
pub fn inner_arc(&self) -> Arc<Mutex<Agent>>
Get the inner Arc<Mutex<Agent>>.
Used to share the agent handle with DocumentServiceWrapper and other
components that need direct access to the underlying agent.
Sourcepub fn set_private_key_password(
&self,
password: Option<String>,
) -> BindingResult<()>
pub fn set_private_key_password( &self, password: Option<String>, ) -> BindingResult<()>
Configure a per-wrapper private-key password for load/sign operations.
This lets higher-level bindings keep per-instance passwords out of
process-global environment management while the current core library
still resolves decryption passwords through JACS_PRIVATE_KEY_PASSWORD.
Sourcepub fn load(&self, config_path: String) -> BindingResult<String>
pub fn load(&self, config_path: String) -> BindingResult<String>
Load agent configuration from a file path.
Uses Config::from_file + apply_env_overrides + Agent::from_config
to avoid deprecated load_by_config and env var side-channels.
Sourcepub fn load_file_only(&self, config_path: String) -> BindingResult<String>
pub fn load_file_only(&self, config_path: String) -> BindingResult<String>
Load agent configuration from file only, without applying env/jenv
overrides. This is the isolation-safe counterpart of [load] — the
caller constructs a pristine config file and does not want ambient JACS_*
environment variables to pollute it (Issue 008).
Sourcepub fn load_with_info(&self, config_path: String) -> BindingResult<String>
pub fn load_with_info(&self, config_path: String) -> BindingResult<String>
Load agent configuration and return canonical loaded-agent metadata.
Sourcepub fn set_storage_root(&self, root: PathBuf) -> BindingResult<()>
pub fn set_storage_root(&self, root: PathBuf) -> BindingResult<()>
Re-root the internal file storage at root.
By default load_by_config roots the FS backend at the current
working directory. verify_document_standalone uses this to
re-root at / so that absolute data/key directory paths work
regardless of CWD.
Sourcepub fn sign_agent(
&self,
agent_string: &str,
public_key: Vec<u8>,
public_key_enc_type: String,
) -> BindingResult<String>
pub fn sign_agent( &self, agent_string: &str, public_key: Vec<u8>, public_key_enc_type: String, ) -> BindingResult<String>
Sign an external agent’s document with this agent’s registration signature.
Sourcepub fn verify_string(
&self,
data: &str,
signature_base64: &str,
public_key: Vec<u8>,
public_key_enc_type: String,
) -> BindingResult<bool>
pub fn verify_string( &self, data: &str, signature_base64: &str, public_key: Vec<u8>, public_key_enc_type: String, ) -> BindingResult<bool>
Verify a signature on arbitrary string data.
Sourcepub fn sign_string(&self, data: &str) -> BindingResult<String>
pub fn sign_string(&self, data: &str) -> BindingResult<String>
Sign arbitrary string data with this agent’s private key.
Sourcepub fn sign_batch(&self, messages: Vec<String>) -> BindingResult<Vec<String>>
pub fn sign_batch(&self, messages: Vec<String>) -> BindingResult<Vec<String>>
Sign multiple messages in a single batch, decrypting the private key only once.
Sourcepub fn verify_agent(&self, agentfile: Option<String>) -> BindingResult<bool>
pub fn verify_agent(&self, agentfile: Option<String>) -> BindingResult<bool>
Verify this agent’s signature and hash.
Sourcepub fn update_agent(&self, new_agent_string: &str) -> BindingResult<String>
pub fn update_agent(&self, new_agent_string: &str) -> BindingResult<String>
Update the agent document with new data.
Sourcepub fn verify_document(&self, document_string: &str) -> BindingResult<bool>
pub fn verify_document(&self, document_string: &str) -> BindingResult<bool>
Verify a document’s signature and hash.
Sourcepub fn update_document(
&self,
document_key: &str,
new_document_string: &str,
attachments: Option<Vec<String>>,
embed: Option<bool>,
) -> BindingResult<String>
pub fn update_document( &self, document_key: &str, new_document_string: &str, attachments: Option<Vec<String>>, embed: Option<bool>, ) -> BindingResult<String>
Update an existing document.
Sourcepub fn verify_signature(
&self,
document_string: &str,
signature_field: Option<String>,
) -> BindingResult<bool>
pub fn verify_signature( &self, document_string: &str, signature_field: Option<String>, ) -> BindingResult<bool>
Verify a document’s signature with an optional custom signature field.
Sourcepub fn create_agreement(
&self,
document_string: &str,
agentids: Vec<String>,
question: Option<String>,
context: Option<String>,
agreement_fieldname: Option<String>,
) -> BindingResult<String>
pub fn create_agreement( &self, document_string: &str, agentids: Vec<String>, question: Option<String>, context: Option<String>, agreement_fieldname: Option<String>, ) -> BindingResult<String>
Create an agreement on a document.
Sourcepub fn create_agreement_with_options(
&self,
document_string: &str,
agentids: Vec<String>,
question: Option<String>,
context: Option<String>,
agreement_fieldname: Option<String>,
timeout: Option<String>,
quorum: Option<u32>,
required_algorithms: Option<Vec<String>>,
minimum_strength: Option<String>,
) -> BindingResult<String>
pub fn create_agreement_with_options( &self, document_string: &str, agentids: Vec<String>, question: Option<String>, context: Option<String>, agreement_fieldname: Option<String>, timeout: Option<String>, quorum: Option<u32>, required_algorithms: Option<Vec<String>>, minimum_strength: Option<String>, ) -> BindingResult<String>
Create an agreement with extended options (timeout, quorum, algorithm constraints).
All option parameters are optional:
timeout: ISO 8601 deadline after which the agreement expiresquorum: minimum number of signatures required (M-of-N)required_algorithms: only accept signatures from these algorithmsminimum_strength: “classical” or “post-quantum”
Sourcepub fn sign_agreement(
&self,
document_string: &str,
agreement_fieldname: Option<String>,
) -> BindingResult<String>
pub fn sign_agreement( &self, document_string: &str, agreement_fieldname: Option<String>, ) -> BindingResult<String>
Sign an agreement on a document.
Sourcepub fn create_document(
&self,
document_string: &str,
custom_schema: Option<String>,
outputfilename: Option<String>,
no_save: bool,
attachments: Option<&str>,
embed: Option<bool>,
) -> BindingResult<String>
pub fn create_document( &self, document_string: &str, custom_schema: Option<String>, outputfilename: Option<String>, no_save: bool, attachments: Option<&str>, embed: Option<bool>, ) -> BindingResult<String>
Create a new JACS document.
Sourcepub fn save_signed_document(
&self,
document_string: &str,
outputfilename: Option<String>,
export_embedded: Option<bool>,
extract_only: Option<bool>,
) -> BindingResult<String>
pub fn save_signed_document( &self, document_string: &str, outputfilename: Option<String>, export_embedded: Option<bool>, extract_only: Option<bool>, ) -> BindingResult<String>
Persist an already-signed JACS document and return its lookup key.
Stores the document both in the agent’s data directory (for file-based
access) and in the storage index (documents/) so that
list_document_keys() can find it.
Sourcepub fn list_document_keys(&self) -> BindingResult<Vec<String>>
pub fn list_document_keys(&self) -> BindingResult<Vec<String>>
Return all known document lookup keys from the agent’s configured storage.
Sourcepub fn check_agreement(
&self,
document_string: &str,
agreement_fieldname: Option<String>,
) -> BindingResult<String>
pub fn check_agreement( &self, document_string: &str, agreement_fieldname: Option<String>, ) -> BindingResult<String>
Check an agreement on a document.
Sourcepub fn sign_request(&self, payload_value: Value) -> BindingResult<String>
pub fn sign_request(&self, payload_value: Value) -> BindingResult<String>
Sign a request payload (wraps in a JACS document).
Sourcepub fn verify_response(&self, document_string: String) -> BindingResult<Value>
pub fn verify_response(&self, document_string: String) -> BindingResult<Value>
Verify a response payload and return the payload value.
Sourcepub fn verify_response_with_agent_id(
&self,
document_string: String,
) -> BindingResult<(Value, String)>
pub fn verify_response_with_agent_id( &self, document_string: String, ) -> BindingResult<(Value, String)>
Verify a response payload and return (payload, agent_id).
Sourcepub fn verify_document_by_id(&self, document_id: &str) -> BindingResult<bool>
pub fn verify_document_by_id(&self, document_id: &str) -> BindingResult<bool>
Verify a document looked up by its ID from storage.
This is a convenience method for when you have a document ID rather than the full JSON string. The document ID should be in “uuid:version” format.
Sourcepub fn get_document_by_id(&self, document_id: &str) -> BindingResult<String>
pub fn get_document_by_id(&self, document_id: &str) -> BindingResult<String>
Load a document by ID from the agent’s configured storage.
The document ID should be in “uuid:version” format.
Sourcepub fn get_agent_id(&self) -> BindingResult<String>
pub fn get_agent_id(&self) -> BindingResult<String>
Get the loaded agent’s canonical JACS identifier.
Sourcepub fn reencrypt_key(
&self,
old_password: &str,
new_password: &str,
) -> BindingResult<()>
pub fn reencrypt_key( &self, old_password: &str, new_password: &str, ) -> BindingResult<()>
Re-encrypt the agent’s private key with a new password.
Reads the encrypted private key file, decrypts with old_password, validates new_password, re-encrypts, and writes the updated file.
Sourcepub fn ephemeral(&self, algorithm: Option<&str>) -> BindingResult<String>
pub fn ephemeral(&self, algorithm: Option<&str>) -> BindingResult<String>
Create an ephemeral in-memory agent. No config, no files, no env vars needed.
Replaces the inner agent with a freshly created ephemeral agent that
lives entirely in memory. Returns a JSON string with agent info
(agent_id, name, version, algorithm). Default algorithm is pq2025.
Sourcepub fn diagnostics(&self) -> String
pub fn diagnostics(&self) -> String
Returns diagnostic information including loaded agent details as a JSON string.
Sourcepub fn get_setup_instructions(
&self,
domain: &str,
ttl: u32,
) -> BindingResult<String>
pub fn get_setup_instructions( &self, domain: &str, ttl: u32, ) -> BindingResult<String>
Returns setup instructions for publishing DNS records and enabling DNSSEC.
Requires a loaded agent (call load() first).
Sourcepub fn export_agent(&self) -> BindingResult<String>
pub fn export_agent(&self) -> BindingResult<String>
Export the loaded agent’s full JSON document.
Sourcepub fn get_public_key_pem(&self) -> BindingResult<String>
pub fn get_public_key_pem(&self) -> BindingResult<String>
Get the loaded agent’s public key as a PEM string.
Sourcepub fn get_agent_json(&self) -> BindingResult<String>
pub fn get_agent_json(&self) -> BindingResult<String>
Get the agent’s JSON representation as a string.
Returns the agent’s full JSON document.
Source§impl AgentWrapper
impl AgentWrapper
Sourcepub fn build_auth_header(&self) -> BindingResult<String>
pub fn build_auth_header(&self) -> BindingResult<String>
Build the JACS Authorization header value.
Format: "JACS {jacs_id}:{unix_timestamp}:{base64_signature}".
Requires a loaded agent with keys.
Sourcepub fn canonicalize_json(&self, json_string: &str) -> BindingResult<String>
pub fn canonicalize_json(&self, json_string: &str) -> BindingResult<String>
Deterministically serialize a JSON string per RFC 8785 (JCS).
Accepts a JSON string, parses it, and returns the canonicalized form.
Sourcepub fn sign_response(&self, payload_json: &str) -> BindingResult<String>
pub fn sign_response(&self, payload_json: &str) -> BindingResult<String>
Build and sign a JACS response envelope.
Accepts a JSON payload string, returns a signed envelope JSON string
containing version, document_type, data, metadata, and
jacsSignature.
Sourcepub fn encode_verify_payload(&self, document: &str) -> BindingResult<String>
pub fn encode_verify_payload(&self, document: &str) -> BindingResult<String>
Encode a document as URL-safe base64 (no padding) for verification.
SDK clients use this to build verification URLs. JACS does not impose any URL structure — that is the SDK’s responsibility.
Sourcepub fn decode_verify_payload(&self, encoded: &str) -> BindingResult<String>
pub fn decode_verify_payload(&self, encoded: &str) -> BindingResult<String>
Decode a URL-safe base64 verification payload back to the original document string.
Sourcepub fn extract_document_id(&self, document: &str) -> BindingResult<String>
pub fn extract_document_id(&self, document: &str) -> BindingResult<String>
Extract the document ID from a JACS-signed document.
Checks jacsDocumentId, document_id, id in priority order.
SDK clients use this to build hosted verification URLs.
Sourcepub fn unwrap_signed_event(
&self,
event_json: &str,
server_keys_json: &str,
) -> BindingResult<String>
pub fn unwrap_signed_event( &self, event_json: &str, server_keys_json: &str, ) -> BindingResult<String>
Unwrap a JACS-signed event, verifying the signature when the signer’s public key is known.
event_json is the signed event as a JSON string.
server_keys_json is a JSON object mapping agent IDs to base64-encoded
public key bytes: {"agent_id": "base64_key", ...}.
Returns a JSON string: {"data": <unwrapped>, "verified": <bool>}.
Trait Implementations§
Source§impl Clone for AgentWrapper
impl Clone for AgentWrapper
Source§fn clone(&self) -> AgentWrapper
fn clone(&self) -> AgentWrapper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AgentWrapper
impl RefUnwindSafe for AgentWrapper
impl Send for AgentWrapper
impl Sync for AgentWrapper
impl Unpin for AgentWrapper
impl UnsafeUnpin for AgentWrapper
impl UnwindSafe for AgentWrapper
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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