use crate::error::AppError;
use crate::sealed_nonce_store::PersistentNonceStore;
use vta_sdk::sealed_transfer::{
AssertionProof, ProducerAssertion, SealedPayloadV1, armor, bundle_digest, seal_payload,
};
use super::{AssertionMode, ProvisionIntegrationDeps, vta_keys};
pub(super) struct SealedProvisionBundle {
pub armored: String,
pub digest: String,
}
pub(super) async fn seal_provision_payload(
state: &ProvisionIntegrationDeps,
vta_did: &str,
assertion_mode: AssertionMode,
bundle_id: [u8; 16],
client_x25519_pub: &[u8; 32],
payload: SealedPayloadV1,
) -> Result<SealedProvisionBundle, AppError> {
let producer_assertion = match assertion_mode {
AssertionMode::DidSigned => {
let sealed_transfer_secret =
vta_keys::load_vta_sealed_transfer_secret(state, vta_did).await?;
vta_keys::build_did_signed_assertion(
&sealed_transfer_secret,
client_x25519_pub,
bundle_id,
)?
}
AssertionMode::PinnedOnly => ProducerAssertion {
producer_did: vta_did.to_string(),
proof: AssertionProof::PinnedOnly,
},
};
let nonce_store = PersistentNonceStore::new(state.sealed_nonces_ks.clone());
let bundle = seal_payload(
client_x25519_pub,
bundle_id,
producer_assertion,
&payload,
&nonce_store,
)
.await
.map_err(|e| AppError::Internal(format!("sealed-transfer seal failed: {e}")))?;
Ok(SealedProvisionBundle {
armored: armor::encode(&bundle),
digest: bundle_digest(&bundle),
})
}