use chrono::Duration;
use vta_sdk::provision_integration::{
BootstrapAsk, BootstrapRequest, DidTemplateRef, TemplateBootstrapAsk,
};
use vta_sdk::sealed_transfer::generate_ed25519_keypair;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (holder_seed, holder_ed_pub) = generate_ed25519_keypair();
let holder_did = affinidi_crypto::did_key::ed25519_pub_to_did_key(&holder_ed_pub);
let mut bundle_id = [0u8; 16];
getrandom::fill(&mut bundle_id)?;
let ask = BootstrapAsk::TemplateBootstrap(TemplateBootstrapAsk {
context_hint: Some("prod-mediator".to_string()),
template: DidTemplateRef {
name: "didcomm-mediator".to_string(),
vars: Default::default(),
},
admin_template: None,
note: Some("Demo run from vta-sdk/examples/bootstrap_request.rs".to_string()),
});
let request = BootstrapRequest::sign(
&holder_seed,
&holder_did,
bundle_id,
Duration::hours(1),
Some("demo-mediator".to_string()),
ask,
)
.await?;
let wire = serde_json::to_string_pretty(&request)?;
println!("BootstrapRequest wire form:\n{wire}");
let verified = request.verify()?;
println!("\nVerified holder: {}", verified.holder());
let nonce = verified.decode_nonce()?;
println!("Verified nonce: {}", hex_lower(&nonce));
Ok(())
}
fn hex_lower(bytes: &[u8]) -> String {
const TABLE: &[u8; 16] = b"0123456789abcdef";
let mut s = String::with_capacity(bytes.len() * 2);
for &b in bytes {
s.push(TABLE[(b >> 4) as usize] as char);
s.push(TABLE[(b & 0xf) as usize] as char);
}
s
}