Skip to content
You are reading the Ratify Protocol v2 beta documentation. Protocol v1 remains available at the site root.

Rust SDK (v2)

Terminal window

Package: crate ratify-protocol 2.x, module ratify_protocol::v2. API documentation: docs.rs.

  • The 2.x crate keeps the v1 API next to ratify_protocol::v2.
  • Every published crate is a prerelease, so an unpinned cargo add ratify-protocol resolves to the v2 beta. Pin the version you mean.
  • One source change for v1 code in the 2.x crate: the fields of the root HybridPrivateKey are private. Build a key with HybridPrivateKey::from_components(ed25519, ml_dsa_65) and read it with .ed25519() and .ml_dsa_65(); both buffers are wiped on drop.
  • Released decisions have private fields; release_v2_decision is the only constructor.

Production verifiers implement the claim store, rate reservations, receipt publisher, independent checkpoint, and journal store durably. The in-memory implementations in ratify_protocol::v2::reference (every type ends in TestOnly) are for tests only. See Deployment profiles.

Delegate, present, verify, and release: Rust quickstart (development only).

An issuer’s status publisher signs revocation lists and pushes under a separate status key; the verifier applies them to its journal. See Status from signed evidence.

examples/v2/rust/src/bin/signed_status.rs
//! Ratify Protocol v2 signed status: a status publisher under a separate
//! status key, journal ingestion, and a revocation that turns a later
//! verification into deny.
//!
//! DEVELOPMENT ONLY. This program uses the in-memory reference stores from
//! `ratify_protocol::v2::reference`. A production verifier supplies durable
//! Part B stores, an anchored journal store and an independent checkpoint
//! (SPEC-v2 §7).
//!
//! Run from examples/v2/rust: cargo run --bin signed_status
use std::collections::BTreeMap;
use std::error::Error;
use std::sync::{Arc, Mutex};
use ratify_protocol::v2::reference::{JournalStore, Store, TestOnlyChallengeIssuanceStore};
use ratify_protocol::v2::*;
use ratify_protocol::{generate_hybrid_keypair, HybridPublicKey, HybridSignature};
const START: i64 = 1_800_000_000;
const NAMESPACE: &str = "signed-status";
const EPOCH: i64 = 1;
const LOG_ID: &str = "00000000000000000000000000000002";
const CERT_ID: &str = "status-demo-cert-1";
fn unsigned() -> HybridSignature {
HybridSignature {
ed25519: Vec::new(),
ml_dsa_65: Vec::new(),
}
}
fn main() {
if let Err(e) = run() {
eprintln!("error: {e}");
std::process::exit(1);
}
}
fn run() -> Result<(), Box<dyn Error>> {
let ctx = V2Context::background();
println!("Ratify Protocol v2 signed status");
println!("development only: in-memory reference stores");
let (root_pub, root_priv) = generate_hybrid_keypair();
let (agent_pub, agent_priv) = generate_hybrid_keypair();
let (status_pub, status_priv) = generate_hybrid_keypair();
let (verifier_pub, verifier_priv) = generate_hybrid_keypair();
let root_id = key_id_v2(&root_pub)?;
let agent_id = key_id_v2(&agent_pub)?;
let verifier_id = key_id_v2(&verifier_pub)?;
let cert = sign_delegation_cert_v2(
&DelegationCertV2 {
version: 2,
cert_id: CERT_ID.into(),
issuer_id: root_id.clone(),
issuer_pub_key: root_pub.clone(),
subject_id: agent_id.clone(),
subject_pub_key: agent_pub.clone(),
scope: vec!["data:read".into()],
constraints: Vec::new(),
issued_at: START,
expires_at: START + 86400,
signature: unsigned(),
},
&root_priv,
)?;
println!("delegation: {CERT_ID} scope=data:read");
// The journal is the verifier's anchored record of key roles, status-key
// epochs and accepted status. Roles are recorded once, when the
// deployment authenticates its trust configuration.
let journal = Arc::new(JournalStore::new()?);
for (role, public) in [
("issuer", &root_pub),
("delegation", &agent_pub),
("verifier", &verifier_pub),
] {
record_security_key_role_v2(&ctx, journal.as_ref(), role, public)?;
}
configure_status_key_epoch_v2(&ctx, journal.as_ref(), &root_id, 1, &status_pub)?;
println!("journal: key roles recorded; status key configured for the root at epoch 1");
// Role separation: the root key can never sign status for itself.
let refused =
new_v2_status_publisher_with_key(&ctx, journal.as_ref(), &root_pub, &root_priv, 3600);
println!(
"publisher with the root key as status key: refused ({})",
v2_error_class_of(&refused)
.map(|c| c.as_str())
.unwrap_or("none")
);
let publisher =
new_v2_status_publisher_with_key(&ctx, journal.as_ref(), &root_pub, &status_priv, 3600)?;
let policy = RevocationStatusPolicyV2 {
max_list_lifetime_seconds: 3600,
max_status_age_seconds: 3600,
clock_skew_seconds: 5,
};
// Genesis: sequence 1, nothing revoked. The caller persists the returned
// state before publishing the signed list.
let genesis = publisher.genesis(&ctx, START)?;
let genesis_wire = encode_revocation_list_v2(&genesis.list)?;
println!("publisher: genesis list sequence {}", genesis.list.sequence);
apply_revocation_list_to_journal_v2(
&ctx,
journal.as_ref(),
&genesis.list,
&root_id,
1,
&status_pub,
&policy,
START,
)?;
let status = revocation_status_from_journal_v2(
&ctx,
journal.as_ref(),
&root_id,
CERT_ID,
1,
&status_pub,
&policy,
START,
)?;
println!(
"journal: ingested list sequence {}; {CERT_ID} is {}",
genesis.list.sequence, status.status
);
let store = Arc::new(Store::new(START, 30, LOG_ID, &verifier_priv)?);
let issuance = Arc::new(TestOnlyChallengeIssuanceStore::new());
let evidence: Arc<Mutex<Vec<V2StatusEvidenceObject>>> =
Arc::new(Mutex::new(vec![V2StatusEvidenceObject {
object_type: 3,
wire: genesis_wire,
}]));
// verify_and_release runs one complete live verification at the store's
// current time and returns the released decision.
let verify_and_release = |label: &str| -> Result<(), Box<dyn Error>> {
let challenge = V2ChallengeIssuer {
clock: store.clone(),
store: issuance.clone(),
random: None,
}
.issue_challenge_v2(
&ctx,
&V2ChallengeIssueRequest {
verifier_namespace: NAMESPACE.into(),
replay_epoch: EPOCH,
verifier_id: verifier_id.clone(),
lifetime_seconds: 120,
expected_agent_id: agent_id.clone(),
expected_agent_public_key: Some(agent_pub.clone()),
..Default::default()
},
)?;
let bundle = sign_proof_bundle_v2(
&ProofBundleV2 {
version: 2,
verifier_id: verifier_id.clone(),
agent_id: agent_id.clone(),
agent_pub_key: agent_pub.clone(),
delegations: vec![cert.clone()],
delegation_digest: Vec::new(),
challenge: challenge.value.clone(),
challenge_at: challenge.issued_at,
challenge_sig: unsigned(),
session_context: None,
stream_id: None,
stream_seq: None,
},
&agent_priv,
)?;
let wire = encode_proof_bundle_v2(&bundle)?;
let expected = load_expected_challenge_v2(
&ctx,
issuance.as_ref(),
NAMESPACE,
EPOCH,
&bundle.challenge,
)?;
let context_policy = V2ContextPolicy::new("example.signed-status/v1", false, &[], &[])?;
let (trusted_id, trusted_key) = (root_id.clone(), root_pub.clone());
let provided = evidence.clone();
let outcome = verify_proof_bundle_v2(
&ctx,
&V2VerifyRequest {
bundle: wire,
expected: Some(expected),
context_policy: Some(context_policy),
required_scope: "data:read".into(),
verifier_namespace: NAMESPACE.into(),
replay_epoch: EPOCH,
verifier_id: verifier_id.clone(),
now: store.now(),
max_challenge_age_seconds: 300,
future_skew_seconds: 5,
tzdb_version: TZDB_VERSION_V2.into(),
status_keys: BTreeMap::from([(
root_id.clone(),
V2StatusKeyConfig {
epoch: 1,
key: status_pub.clone(),
},
)]),
status_policy: policy,
..Default::default()
},
&V2VerifyCallbacks {
claim_store: Some(store.clone()),
trust: Some(Arc::new(
move |_ctx: &V2Context, chain: &[DelegationCertV2]| {
Ok(match chain.last() {
Some(last) if last.issuer_id == trusted_id => V2TrustResolution {
outcome: V2TrustOutcome::Trusted,
root_key: trusted_key.clone(),
},
_ => V2TrustResolution {
outcome: V2TrustOutcome::Untrusted,
root_key: HybridPublicKey {
ed25519: Vec::new(),
ml_dsa_65: Vec::new(),
},
},
})
},
)),
// The provider returns signed objects only; the verifier checks
// each signature against the configured status key and applies
// it to the journal before it derives a status.
status_evidence: Some(Arc::new(
move |_ctx: &V2Context, _req: &V2StatusEvidenceRequest| {
Ok(V2StatusEvidenceBatch {
objects: provided.lock().expect("evidence").clone(),
})
},
)),
status_journal: Some(journal.clone()),
..Default::default()
},
);
let committed = match (outcome.stage, outcome.committed) {
(V2VerifyStage::Committed, Some(c)) => c,
(stage, _) => {
return Err(
format!("verify stopped at {}: {:?}", stage.as_str(), outcome.error).into(),
)
}
};
let receipt_wire =
store.publish_v2_receipt(&ctx, &committed.claim_id(), &committed.receipt_body())?;
let result = release_v2_decision(
&ctx,
&committed,
Some(&receipt_wire),
V2ReleaseConfig {
verifier_public_key: &verifier_pub,
log_id: LOG_ID,
claim_store: store.as_ref(),
checkpoint: store.as_ref(),
},
);
let (status, reason) = (result.status, result.reason.clone());
let decision = result
.into_decision()
.ok_or_else(|| format!("release {}: {}", status.as_str(), reason))?;
let receipt = decision.receipt()?;
println!(
"{label}: decision={} reason={} status_assessment={} allowed={}",
decision.decision(),
decision.reason(),
receipt.status_assessment,
decision.allowed(&ctx, store.as_ref())
);
Ok(())
};
store.set_time(START + 5);
verify_and_release("verify before revocation")?;
// Revoke: a push with the newly revoked ID and the cumulative list, both
// at sequence 2.
let revoked = publisher.revoke(&ctx, &genesis.state, &[CERT_ID.to_string()], START + 10)?;
let push = revoked.push.clone().ok_or("revocation produced no push")?;
let push_wire = encode_revocation_push_v2(&push)?;
let list_wire = encode_revocation_list_v2(&revoked.list)?;
println!(
"publisher: revoked {CERT_ID} (push sequence {}, list sequence {})",
push.sequence, revoked.list.sequence
);
apply_revocation_push_to_journal_v2(
&ctx,
journal.as_ref(),
&push,
&root_id,
1,
&status_pub,
&policy,
START + 10,
)?;
let status = revocation_status_from_journal_v2(
&ctx,
journal.as_ref(),
&root_id,
CERT_ID,
1,
&status_pub,
&policy,
START + 10,
)?;
println!(
"journal: ingested push sequence {}; {CERT_ID} is {}",
push.sequence, status.status
);
*evidence.lock().expect("evidence") = vec![
V2StatusEvidenceObject {
object_type: 5,
wire: push_wire,
},
V2StatusEvidenceObject {
object_type: 3,
wire: list_wire,
},
];
store.set_time(START + 15);
verify_and_release("verify after revocation")
}

Source: examples/v2/rust/signed_status at commit 5ca7585c2c1d, SHA-256 checked at build time.

An exact custom: required scope and a registered evaluator profile. See Delegation and constraints.

examples/v2/rust/src/bin/custom_scope.rs
//! Ratify Protocol v2 custom scope and the standard max_count evaluator
//! profile (com.ratifyprotocol.max_count/v1).
//!
//! DEVELOPMENT ONLY. This program uses the in-memory reference stores from
//! `ratify_protocol::v2::reference`. A production verifier supplies durable
//! Part B stores and an independent checkpoint (SPEC-v2 §7).
//!
//! Run from examples/v2/rust: cargo run --bin custom_scope
use std::collections::BTreeMap;
use std::error::Error;
use std::sync::Arc;
use std::time::Duration;
use ratify_protocol::v2::reference::{JournalStore, Store, TestOnlyChallengeIssuanceStore};
use ratify_protocol::v2::*;
use ratify_protocol::{generate_hybrid_keypair, HybridPublicKey, HybridSignature, ParamsValue};
const START: i64 = 1_800_000_000;
const NAMESPACE: &str = "custom-scope";
const EPOCH: i64 = 1;
const LOG_ID: &str = "00000000000000000000000000000003";
const CUSTOM_SCOPE: &str = "custom:acme:deploy";
fn unsigned() -> HybridSignature {
HybridSignature {
ed25519: Vec::new(),
ml_dsa_65: Vec::new(),
}
}
fn main() {
if let Err(e) = run() {
eprintln!("error: {e}");
std::process::exit(1);
}
}
fn run() -> Result<(), Box<dyn Error>> {
let ctx = V2Context::background();
println!("Ratify Protocol v2 custom scope and max_count profile");
println!("development only: in-memory reference stores");
let (root_pub, root_priv) = generate_hybrid_keypair();
let (agent_pub, agent_priv) = generate_hybrid_keypair();
let (status_pub, status_priv) = generate_hybrid_keypair();
let (verifier_pub, verifier_priv) = generate_hybrid_keypair();
let root_id = key_id_v2(&root_pub)?;
let agent_id = key_id_v2(&agent_pub)?;
let verifier_id = key_id_v2(&verifier_pub)?;
let mut template = DelegationCertV2 {
version: 2,
cert_id: "custom-scope-cert-1".into(),
issuer_id: root_id.clone(),
issuer_pub_key: root_pub.clone(),
subject_id: agent_id.clone(),
subject_pub_key: agent_pub.clone(),
scope: vec!["custom:*".into()],
constraints: Vec::new(),
issued_at: START,
expires_at: START + 86400,
signature: unsigned(),
};
// A custom scope is one exact name. Wildcards are invalid.
let refused = sign_delegation_cert_v2(&template, &root_priv);
println!(
"issue scope custom:*: refused ({})",
refused.err().map(|e| e.class().as_str()).unwrap_or("none")
);
// The certificate carries an extension constraint. Only a verifier that
// registered the max_count/v1 profile for this type can evaluate it.
template.scope = vec![CUSTOM_SCOPE.into()];
template.constraints = vec![ConstraintV2 {
kind: CONSTRAINT_MAX_COUNT_V2.into(),
params: Some(BTreeMap::from([
("counter".into(), ParamsValue::Str("nodes".into())),
("max".into(), ParamsValue::Int(5)),
])),
..Default::default()
}];
let cert = sign_delegation_cert_v2(&template, &root_priv)?;
println!("delegation: scope={CUSTOM_SCOPE} constraint={CONSTRAINT_MAX_COUNT_V2}(counter=nodes, max=5)");
let max_count = standard_max_count_evaluator_v2();
let digest = constraint_profile_digest_v2(&max_count.descriptor)?;
println!("profile: {PROFILE_MAX_COUNT_V2} digest={digest}");
let registry = ConstraintEvaluatorRegistryV2::new(Duration::from_secs(1), vec![max_count])?;
let journal = Arc::new(JournalStore::new()?);
record_security_key_role_v2(&ctx, journal.as_ref(), "issuer", &root_pub)?;
configure_status_key_epoch_v2(&ctx, journal.as_ref(), &root_id, 1, &status_pub)?;
let publisher =
new_v2_status_publisher_with_key(&ctx, journal.as_ref(), &root_pub, &status_priv, 3600)?;
let genesis = publisher.genesis(&ctx, START)?;
let status_wire = encode_revocation_list_v2(&genesis.list)?;
let store = Arc::new(Store::new(START, 30, LOG_ID, &verifier_priv)?);
let issuance = Arc::new(TestOnlyChallengeIssuanceStore::new());
// attempt verifies one request for `nodes` nodes and releases the result.
let attempt = |label: &str,
nodes: i64,
evaluators: Option<ConstraintEvaluatorRegistryV2>|
-> Result<(), Box<dyn Error>> {
store.set_time(store.now() + 1);
let challenge = V2ChallengeIssuer {
clock: store.clone(),
store: issuance.clone(),
random: None,
}
.issue_challenge_v2(
&ctx,
&V2ChallengeIssueRequest {
verifier_namespace: NAMESPACE.into(),
replay_epoch: EPOCH,
verifier_id: verifier_id.clone(),
lifetime_seconds: 120,
expected_agent_id: agent_id.clone(),
expected_agent_public_key: Some(agent_pub.clone()),
..Default::default()
},
)?;
let bundle = sign_proof_bundle_v2(
&ProofBundleV2 {
version: 2,
verifier_id: verifier_id.clone(),
agent_id: agent_id.clone(),
agent_pub_key: agent_pub.clone(),
delegations: vec![cert.clone()],
delegation_digest: Vec::new(),
challenge: challenge.value.clone(),
challenge_at: challenge.issued_at,
challenge_sig: unsigned(),
session_context: None,
stream_id: None,
stream_seq: None,
},
&agent_priv,
)?;
let wire = encode_proof_bundle_v2(&bundle)?;
let expected = load_expected_challenge_v2(
&ctx,
issuance.as_ref(),
NAMESPACE,
EPOCH,
&bundle.challenge,
)?;
let context_policy = V2ContextPolicy::new("example.custom-scope/v1", false, &[], &[])?;
let (trusted_id, trusted_key) = (root_id.clone(), root_pub.clone());
let evidence = status_wire.clone();
let outcome = verify_proof_bundle_v2(
&ctx,
&V2VerifyRequest {
bundle: wire,
expected: Some(expected),
context_policy: Some(context_policy),
required_scope: CUSTOM_SCOPE.into(),
verifier_namespace: NAMESPACE.into(),
replay_epoch: EPOCH,
verifier_id: verifier_id.clone(),
now: store.now(),
max_challenge_age_seconds: 300,
future_skew_seconds: 5,
tzdb_version: TZDB_VERSION_V2.into(),
// The requested quantity comes from the authenticated request,
// never from the proof.
context: ConstraintContextV2 {
extension_counts: BTreeMap::from([("nodes".to_string(), nodes)]),
..Default::default()
},
constraint_evaluators: evaluators,
status_keys: BTreeMap::from([(
root_id.clone(),
V2StatusKeyConfig {
epoch: 1,
key: status_pub.clone(),
},
)]),
status_policy: RevocationStatusPolicyV2 {
max_list_lifetime_seconds: 3600,
max_status_age_seconds: 3600,
clock_skew_seconds: 5,
},
},
&V2VerifyCallbacks {
claim_store: Some(store.clone()),
trust: Some(Arc::new(
move |_ctx: &V2Context, chain: &[DelegationCertV2]| {
Ok(match chain.last() {
Some(last) if last.issuer_id == trusted_id => V2TrustResolution {
outcome: V2TrustOutcome::Trusted,
root_key: trusted_key.clone(),
},
_ => V2TrustResolution {
outcome: V2TrustOutcome::Untrusted,
root_key: HybridPublicKey {
ed25519: Vec::new(),
ml_dsa_65: Vec::new(),
},
},
})
},
)),
status_evidence: Some(Arc::new(
move |_ctx: &V2Context, _req: &V2StatusEvidenceRequest| {
Ok(V2StatusEvidenceBatch {
objects: vec![V2StatusEvidenceObject {
object_type: 3,
wire: evidence.clone(),
}],
})
},
)),
status_journal: Some(journal.clone()),
..Default::default()
},
);
let committed = match (outcome.stage, outcome.committed) {
(V2VerifyStage::Committed, Some(c)) => c,
(stage, _) => {
return Err(
format!("verify stopped at {}: {:?}", stage.as_str(), outcome.error).into(),
)
}
};
let receipt_wire =
store.publish_v2_receipt(&ctx, &committed.claim_id(), &committed.receipt_body())?;
let result = release_v2_decision(
&ctx,
&committed,
Some(&receipt_wire),
V2ReleaseConfig {
verifier_public_key: &verifier_pub,
log_id: LOG_ID,
claim_store: store.as_ref(),
checkpoint: store.as_ref(),
},
);
let (status, reason) = (result.status, result.reason.clone());
let decision = result
.into_decision()
.ok_or_else(|| format!("release {}: {}", status.as_str(), reason))?;
let receipt = decision.receipt()?;
println!(
"{label}: decision={} reason={} allowed={}",
decision.decision(),
decision.reason(),
decision.allowed(&ctx, store.as_ref())
);
for reference in &receipt.constraint_evaluators {
println!(
" receipt constraint_evaluators: {} {}",
reference.kind, reference.profile_digest
);
}
Ok(())
};
attempt("request nodes=3", 3, Some(registry.clone()))?;
attempt("request nodes=8", 8, Some(registry))?;
attempt("request nodes=3 without the profile registered", 3, None)
}

Source: examples/v2/rust/custom_scope at commit 5ca7585c2c1d, SHA-256 checked at build time.

Signing through a key held outside the SDK, with verify-before-use. See Typed signing and key IDs.

examples/v2/rust/src/bin/external_signer.rs
//! Ratify Protocol v2 external signer: a signing provider holds the private
//! key; the SDK prepares each typed statement and verifies every returned
//! signature before using it.
//!
//! The provider here is an in-process stand-in for a remote signing service.
//! The interface makes no claim about any particular KMS or HSM.
//!
//! Run from examples/v2/rust: cargo run --bin external_signer
use std::error::Error;
use std::sync::Mutex;
use ed25519_dalek::{Signer as _, SigningKey};
use fips204::ml_dsa_65;
use fips204::traits::{SerDes, Signer as _};
use rand_core::OsRng;
use ratify_protocol::v2::*;
use ratify_protocol::{generate_hybrid_keypair, HybridPublicKey, HybridSignature};
const START: i64 = 1_800_000_000;
/// A signing service. Its private key never leaves it. It signs in direct
/// mode: Ed25519 over the 77-byte message M and ML-DSA-65 over M with the
/// SDK-chosen context string.
struct Provider {
name: String,
public: HybridPublicKey,
ed: SigningKey,
ml: Mutex<ml_dsa_65::PrivateKey>,
log: Mutex<Vec<String>>,
}
impl Provider {
fn new(name: &str) -> Result<Self, Box<dyn Error>> {
let ed = SigningKey::generate(&mut OsRng);
let (ml_pub, ml_priv) = ml_dsa_65::try_keygen()?;
Ok(Provider {
name: name.into(),
public: HybridPublicKey {
ed25519: ed.verifying_key().to_bytes().to_vec(),
ml_dsa_65: ml_pub.into_bytes().to_vec(),
},
ed,
ml: Mutex::new(ml_priv),
log: Mutex::new(Vec::new()),
})
}
fn first_log(&self) -> String {
self.log
.lock()
.expect("log")
.first()
.cloned()
.unwrap_or_default()
}
}
impl SignerV2 for Provider {
fn public_key_v2(&self) -> HybridPublicKey {
self.public.clone()
}
fn mode_v2(&self) -> SignerModeV2 {
SignerModeV2::Direct
}
fn sign_v2(&self, _ctx: &V2Context, req: &SignRequestV2) -> V2SignResult<HybridSignature> {
// A provider refuses any request for a key it does not hold.
if req.public_key != self.public {
return Err(V2SignError::Provider(format!(
"{}: request names a key this provider does not hold",
self.name
)));
}
let context = req
.ml_dsa_context
.clone()
.ok_or_else(|| V2SignError::Provider("direct mode requires a context".into()))?;
self.log.lock().expect("log").push(format!(
"{} signed: mode=direct message={} bytes context={}",
self.name,
req.message.len(),
String::from_utf8_lossy(&context)
));
let ml = self
.ml
.lock()
.expect("key")
.try_sign(&req.message, &context)
.map_err(|e| V2SignError::Provider(e.to_string()))?;
Ok(HybridSignature {
ed25519: self.ed.sign(&req.message).to_bytes().to_vec(),
ml_dsa_65: ml.to_vec(),
})
}
}
fn unsigned() -> HybridSignature {
HybridSignature {
ed25519: Vec::new(),
ml_dsa_65: Vec::new(),
}
}
fn main() {
if let Err(e) = run() {
eprintln!("error: {e}");
std::process::exit(1);
}
}
fn run() -> Result<(), Box<dyn Error>> {
let ctx = V2Context::background();
println!("Ratify Protocol v2 external signer");
let issuer = Provider::new("issuer provider")?;
let agent = Provider::new("agent provider")?;
let (verifier_pub, _) = generate_hybrid_keypair();
let issuer_id = key_id_v2(&issuer.public)?;
let agent_id = key_id_v2(&agent.public)?;
let verifier_id = key_id_v2(&verifier_pub)?;
let cert = sign_delegation_cert_v2_with_signer(
&ctx,
&DelegationCertV2 {
version: 2,
cert_id: "external-signer-cert-1".into(),
issuer_id,
issuer_pub_key: issuer.public.clone(),
subject_id: agent_id.clone(),
subject_pub_key: agent.public.clone(),
scope: vec!["files:read".into()],
constraints: Vec::new(),
issued_at: START,
expires_at: START + 86400,
signature: unsigned(),
},
&issuer,
)?;
println!("{}", issuer.first_log());
println!(
"delegation: signature verified by the SDK ({})",
verify_delegation_cert_v2_signature(&cert).is_ok()
);
let unsigned_bundle = ProofBundleV2 {
version: 2,
verifier_id,
agent_id,
agent_pub_key: agent.public.clone(),
delegations: vec![cert],
delegation_digest: Vec::new(),
challenge: vec![0x42; 32],
challenge_at: START,
challenge_sig: unsigned(),
session_context: None,
stream_id: None,
stream_seq: None,
};
let bundle = sign_proof_bundle_v2_with_signer(&ctx, &unsigned_bundle, &agent)?;
println!("{}", agent.first_log());
println!(
"proof bundle: signatures verified by the SDK ({})",
verify_proof_bundle_v2_signatures(&bundle).is_ok()
);
// A faulty provider returns an ML-DSA-65 signature from a different key.
// The SDK verifies before use, so nothing is signed.
let (_, wrong) = ml_dsa_65::try_keygen()?;
*agent.ml.lock().expect("key") = wrong;
let refused = sign_proof_bundle_v2_with_signer(&ctx, &unsigned_bundle, &agent);
println!(
"faulty provider: refused ({})",
refused.err().map(|e| e.class().as_str()).unwrap_or("none")
);
Ok(())
}

Source: examples/v2/rust/external_signer at commit 5ca7585c2c1d, SHA-256 checked at build time.

The SDK runs the shared corpus in testvectors/v2. Which files each SDK runs, and the results at the tag, are recorded in the release notes and in docs/V2_REFERENCE_COMPATIBILITY.md.