pub struct VerifiedToken {
pub receipt: VerificationReceipt,
pub mac: String,
}Available on crate feature
wire only.Expand description
A VerificationReceipt authenticated with a shared HMAC key.
Allows an executing service to accept an authorization decision from a trusted verifying service without re-running the full Ed25519 chain verification. The HMAC is computed with Blake3 in keyed mode over the canonical binary encoding of the receipt fields.
§Security requirements
- The
mac_keymust be a 32-byte secret shared exclusively between the verifying service and the executing service. - Rotate the key regularly (recommended: every 24 hours).
- Transport tokens over a secure channel (TLS 1.3 minimum).
- Set a short expiry on tokens — the receipt’s
verified_at_unixfield lets executors enforce their own maximum age.
§Example
ⓘ
use a1::wire::VerifiedToken;
// Verifying service:
let mac_key: [u8; 32] = /* from secrets manager */;
let token = VerifiedToken::sign(&action.receipt, &mac_key);
let json = serde_json::to_string(&token)?;
// → send json over TLS to executing service
// Executing service:
let token: VerifiedToken = serde_json::from_str(&json)?;
let receipt = token.verify(&mac_key)?; // fails if tampered or wrong key
// Use receipt.intent, receipt.chain_fingerprint for audit logFields§
§receipt: VerificationReceiptThe receipt to transport.
mac: StringHex-encoded 32-byte Blake3 keyed MAC over the canonical receipt bytes.
Implementations§
Source§impl VerifiedToken
impl VerifiedToken
Sourcepub fn sign(receipt: &VerificationReceipt, mac_key: &[u8; 32]) -> Self
pub fn sign(receipt: &VerificationReceipt, mac_key: &[u8; 32]) -> Self
Produce a VerifiedToken by signing receipt with the given 32-byte key.
Sourcepub fn verify(
&self,
mac_key: &[u8; 32],
) -> Result<&VerificationReceipt, A1Error>
pub fn verify( &self, mac_key: &[u8; 32], ) -> Result<&VerificationReceipt, A1Error>
Verify the MAC and return a reference to the receipt on success.
Returns A1Error::InvalidSubScopeProof if the MAC is invalid
(tampered token, wrong key, or truncated hex). The specific error
variant is intentionally generic to avoid oracle attacks.
Trait Implementations§
Source§impl Clone for VerifiedToken
impl Clone for VerifiedToken
Source§fn clone(&self) -> VerifiedToken
fn clone(&self) -> VerifiedToken
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for VerifiedToken
impl Debug for VerifiedToken
Source§impl<'de> Deserialize<'de> for VerifiedToken
impl<'de> Deserialize<'de> for VerifiedToken
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for VerifiedToken
impl RefUnwindSafe for VerifiedToken
impl Send for VerifiedToken
impl Sync for VerifiedToken
impl Unpin for VerifiedToken
impl UnsafeUnpin for VerifiedToken
impl UnwindSafe for VerifiedToken
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
Mutably borrows from an owned value. Read more