OpenPay (1 crate, 3751 LOC, 83 tests)
op-crypto-extra Extended crypto rails. Stablecoin catalog (USDC, USDT,
PYUSD, DAI, RLUSD, EURC, FDUSD — 26 deployments). L2
catalog (12 chains incl. Optimism, Arbitrum, Base,
zkSync Era, Polygon zkEVM, Linea, Scroll, Starknet).
CCTP v2 BurnMessage encode/decode + domain ids +
attestation. ERC-4337 UserOperation v0.7 +
PackedUserOperation. EIP-7702 set-EOA-code with RLP
signing preimage. Uniswap Permit2 single + batch
transfer EIP-712 hashes. EIP-2612 ERC-20 permit.
BOLT-11 bech32 invoices + LNURL decode. Bitcoin
PSBT v2 (BIP-370). Atomic-swap HTLC. Solana SPL /
Aleo / Aztec confidential-transfer sketches.
Smart Byte (1 crate, 2304 LOC, 30 tests)
smart-byte-acdc Authentic Chained Data Containers (KERI ecosystem).
Acdc + AcdcBuilder (targeted + untargeted) with SAID
derivation. JSON Schema 2020-12 validator with
oneOf partial-disclosure. TEL (RIP/VRT/ISS/REV)
with hash-chained verification. IPEX (apply/offer/
agree/grant/admit/spurn) chained by SAID. Edge
records (I2I/NI2I/DI2I) + EdgeGraph BFS traversal
with cycle detection. Selective disclosure with
full/none/subset plans + compact packing.
CredentialRegistry trait + InMemoryRegistry over
TEL. Composes with smart-byte-core + smart-byte-keri-witness.
EOC (1 crate, 1764 LOC, 16 tests)
eoc-memory Long-term memory primitives. Memory trait + MemoryKind +
EpisodeId. Episodic event log with TimeIndex range
queries. RDF-style Triple store with S/P/O indices.
Bounded attention-budget Scratchpad with
salience-weighted eviction. Rolling SummaryBuffer +
FIFO SlidingWindow. Dream-cycle consolidate()
(episodic → semantic). Ebbinghaus forgetting curve
with reinforcement. Retriever blending cosine
similarity + recency + saturating frequency.
MemGpt three-tier shape (Main/Recall/Archival).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
173 lines
5.3 KiB
Rust
173 lines
5.3 KiB
Rust
//! Credential registry trait + in-memory implementation.
|
|
//!
|
|
//! A registry ties together (a) a credential body, (b) the TEL events
|
|
//! anchoring its lifecycle, and (c) the issuer/holder bookkeeping a
|
|
//! verifier needs. The [`CredentialRegistry`] trait is the abstract
|
|
//! surface; [`InMemoryRegistry`] is the reference implementation used
|
|
//! by tests and by downstream callers that do not need persistence.
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use smart_byte_core::Said;
|
|
|
|
use crate::acdc::Acdc;
|
|
use crate::error::{AcdcError, Result};
|
|
use crate::tel::{CredentialTelState, Tel};
|
|
|
|
/// Combined runtime state for a credential held in a registry.
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum RegistryState {
|
|
/// Issued and currently valid.
|
|
Active,
|
|
/// Issued and later revoked.
|
|
Revoked,
|
|
/// Not present in this registry.
|
|
Absent,
|
|
}
|
|
|
|
/// Storage and lifecycle operations for a credential registry.
|
|
pub trait CredentialRegistry {
|
|
/// SAID of the registry (the TEL's inception event).
|
|
fn registry_said(&self) -> Said;
|
|
|
|
/// Issuer AID owning this registry.
|
|
fn issuer(&self) -> &str;
|
|
|
|
/// Issue a credential. The credential must already be SAID-sealed
|
|
/// (built via [`crate::acdc::AcdcBuilder`]). The registry both
|
|
/// stores the body and appends an `iss` event to the TEL.
|
|
fn issue(&mut self, credential: Acdc) -> Result<()>;
|
|
|
|
/// Revoke a previously issued credential by SAID.
|
|
fn revoke(&mut self, credential: &Said) -> Result<()>;
|
|
|
|
/// Look up the runtime state of a credential.
|
|
fn state(&self, credential: &Said) -> RegistryState;
|
|
|
|
/// Retrieve the credential body if present.
|
|
fn get(&self, credential: &Said) -> Option<&Acdc>;
|
|
}
|
|
|
|
/// In-memory registry combining a TEL with a SAID->ACDC map.
|
|
#[derive(Clone, Debug)]
|
|
pub struct InMemoryRegistry {
|
|
tel: Tel,
|
|
credentials: HashMap<Said, Acdc>,
|
|
}
|
|
|
|
impl InMemoryRegistry {
|
|
/// Open a new registry rooted at a freshly created TEL.
|
|
pub fn open(issuer: impl Into<String>) -> Result<Self> {
|
|
let tel = Tel::open(issuer)?;
|
|
Ok(Self {
|
|
tel,
|
|
credentials: HashMap::new(),
|
|
})
|
|
}
|
|
|
|
/// Borrow the underlying TEL.
|
|
pub fn tel(&self) -> &Tel {
|
|
&self.tel
|
|
}
|
|
}
|
|
|
|
impl CredentialRegistry for InMemoryRegistry {
|
|
fn registry_said(&self) -> Said {
|
|
self.tel.registry()
|
|
}
|
|
|
|
fn issuer(&self) -> &str {
|
|
// The first event of any TEL is the RIP, which carries the
|
|
// issuer AID. Borrow it from there.
|
|
self.tel
|
|
.events()
|
|
.first()
|
|
.map(|e| e.i.as_str())
|
|
.unwrap_or("")
|
|
}
|
|
|
|
fn issue(&mut self, credential: Acdc) -> Result<()> {
|
|
credential.verify_said()?;
|
|
// Reject if the credential's `ri` field, when present,
|
|
// disagrees with this registry.
|
|
if let Some(ri) = credential.ri {
|
|
if ri != self.registry_said() {
|
|
return Err(AcdcError::Registry(format!(
|
|
"credential anchored to registry {ri}, not {}",
|
|
self.registry_said()
|
|
)));
|
|
}
|
|
}
|
|
if self.credentials.contains_key(&credential.d) {
|
|
return Err(AcdcError::Registry(format!(
|
|
"credential {} already issued",
|
|
credential.d
|
|
)));
|
|
}
|
|
self.tel.issue(credential.d)?;
|
|
self.credentials.insert(credential.d, credential);
|
|
Ok(())
|
|
}
|
|
|
|
fn revoke(&mut self, credential: &Said) -> Result<()> {
|
|
if !self.credentials.contains_key(credential) {
|
|
return Err(AcdcError::Registry(format!(
|
|
"credential {credential} not present in registry"
|
|
)));
|
|
}
|
|
self.tel.revoke(*credential)?;
|
|
Ok(())
|
|
}
|
|
|
|
fn state(&self, credential: &Said) -> RegistryState {
|
|
match self.tel.credential_state(credential) {
|
|
CredentialTelState::Issued => RegistryState::Active,
|
|
CredentialTelState::Revoked => RegistryState::Revoked,
|
|
CredentialTelState::Unknown => RegistryState::Absent,
|
|
}
|
|
}
|
|
|
|
fn get(&self, credential: &Said) -> Option<&Acdc> {
|
|
self.credentials.get(credential)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::acdc::{AcdcBuilder, AttributeSection, SchemaSection};
|
|
use serde_json::json;
|
|
|
|
fn cred(reg: Said) -> Acdc {
|
|
let mut s = serde_json::Map::new();
|
|
s.insert("$id".into(), json!("schema"));
|
|
let mut a = serde_json::Map::new();
|
|
a.insert("name".into(), json!("Alice"));
|
|
AcdcBuilder::new()
|
|
.issuer("Bissuer")
|
|
.registry(reg)
|
|
.schema(SchemaSection::Inline(s))
|
|
.attributes(AttributeSection::Inline(a))
|
|
.build()
|
|
.expect("build")
|
|
}
|
|
|
|
#[test]
|
|
fn lifecycle() {
|
|
let mut r = InMemoryRegistry::open("Bissuer").expect("open");
|
|
let c = cred(r.registry_said());
|
|
let id = c.d;
|
|
r.issue(c).expect("issue");
|
|
assert_eq!(r.state(&id), RegistryState::Active);
|
|
r.revoke(&id).expect("revoke");
|
|
assert_eq!(r.state(&id), RegistryState::Revoked);
|
|
}
|
|
|
|
#[test]
|
|
fn rejects_credential_for_other_registry() {
|
|
let mut r = InMemoryRegistry::open("Bissuer").expect("open");
|
|
let other = Said([0xAB; 32]);
|
|
let c = cred(other);
|
|
assert!(matches!(r.issue(c), Err(AcdcError::Registry(_))));
|
|
}
|
|
}
|