SpruceID
Search…
Implementing New Schemas
It is very simple to implement a new schema on its own (implementing the witness flow is a separate concern covered shortly). The most basic Schema supported by Rebase is the basic_post credential. It is not expected to be witnessed, but rather self-produced and self-signed, so it is a very simple credential. It looks like:
// src/schema/basic_post
#[derive(Deserialize, Serialize)]
pub struct BasicPost {
pub title: String,
pub body: String,
pub subject_id: String,
}
​
impl SchemaType for BasicPost {
fn context(&self) -> Result<serde_json::Value, SchemaError> {
// TODO: MAKE THESE URLS MORE ACCURATE.
Ok(json!([
"https://www.w3.org/2018/credentials/v1",
{
"title": "https://schema.org/name",
"body": "https://schema.org/articleBody",
"BasicPost": "https://schema.org/BlogPosting"
},
]))
}
​
fn types(&self) -> Result<Vec<String>, SchemaError> {
Ok(vec![
"VerifiableCredential".to_string(),
"BasicPost".to_string(),
])
}
​
fn subject(&self) -> Result<serde_json::Value, SchemaError> {
Ok(json!({
"id": self.subject_id,
"title": self.title,
"body": self.body,
}))
}
​
fn evidence(&self) -> Result<Option<OneOrMany<Evidence>>, SchemaError> {
Ok(None)
}
}
The required functions return portions of the VC to be constructed (the other portions are supplied by the given SignerType) relating to the @context, types, credentialSubject, and evidence entries. Once these are defined, the schema can be mixed and matched with all implemented SignerTypes.
Copy link