Skip to content

Commit

Permalink
Add payload seal
Browse files Browse the repository at this point in the history
  • Loading branch information
edytapawlak authored and mitfik committed Jun 2, 2023
1 parent 52ec239 commit 7029e21
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
8 changes: 6 additions & 2 deletions components/controller/src/identifier_controller/signing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cesrox::{ParsedData, group::Group};
use cesrox::{group::Group, ParsedData};
use keri::{
event::sections::seal::EventSeal,
event_message::signature::{Signature, SignerData},
Expand Down Expand Up @@ -30,7 +30,11 @@ impl IdentifierController {
Ok(Signature::Transferable(sig_data, vec![indexes_sig]))
}

pub fn to_cesr_signature(&self, sig: SelfSigningPrefix, index: u16) -> Result<String, ControllerError> {
pub fn to_cesr_signature(
&self,
sig: SelfSigningPrefix,
index: u16,
) -> Result<String, ControllerError> {
let signature: Signature = self.sign(sig, index).map(|s| s.into())?;
let group: Group = signature.into();
Ok(group.to_cesr_str())
Expand Down
4 changes: 3 additions & 1 deletion keriox_core/src/database/mailbox.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use sled::Db;

use crate::event_message::signed_event_message::{SignedNontransferableReceipt, SignedEventMessage};
use crate::event_message::signed_event_message::{
SignedEventMessage, SignedNontransferableReceipt,
};

use super::{tables::SledEventTreeVec, timestamped::TimestampedSignedEventMessage, DbError};

Expand Down
10 changes: 6 additions & 4 deletions keriox_core/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
pub mod escrow;
pub(crate) mod tables;
pub(crate) mod timestamped;
#[cfg(feature = "mailbox")]
pub mod mailbox;
pub(crate) mod tables;
pub(crate) mod timestamped;

use std::path::{Path, PathBuf};

use serde::{Deserialize, Serialize};

use self::{tables::{SledEventTree, SledEventTreeVec}, mailbox::MailboxData};
use self::{
mailbox::MailboxData,
tables::{SledEventTree, SledEventTreeVec},
};
#[cfg(feature = "query")]
use crate::query::reply_event::SignedReply;
use crate::{
Expand All @@ -25,7 +28,6 @@ use crate::{

use self::timestamped::TimestampedSignedEventMessage;


pub struct SledEventDatabase {
// "iids" tree
// this thing is expensive, but everything else is cheeeeeep
Expand Down
9 changes: 9 additions & 0 deletions keriox_core/src/event/sections/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum Seal {
Event(EventSeal),
Digest(DigestSeal),
Root(RootSeal),
Payload(PayloadSeal),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -72,6 +73,14 @@ impl SourceSeal {
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct PayloadSeal {
#[serde(rename = "t")]
pub payload_type: String,
#[serde(rename = "p")]
pub payload: String,
}

#[test]
fn test_seal_deserialization() {
// Event seal
Expand Down
36 changes: 34 additions & 2 deletions keriox_core/src/processor/event_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ use crate::{
database::{timestamped::TimestampedSignedEventMessage, SledEventDatabase},
error::Error,
event::{
event_data::EventData,
sections::{seal::EventSeal, KeyConfig},
event_data::{EventData, InteractionEvent},
sections::{
seal::{EventSeal, Seal},
KeyConfig,
},
},
event_message::{
signed_event_message::Notice, signed_event_message::SignedNontransferableReceipt,
Expand Down Expand Up @@ -106,6 +109,35 @@ impl EventStorage {
}
}

pub fn get_mailbox_location(&self, id: &IdentifierPrefix) -> Result<Option<String>, Error> {
match self.db.get_kel_finalized_events(id) {
Some(events) => Ok(events
.filter_map(|ev| {
let event = ev.signed_event_message.event_message.data;
match &event.event_data {
EventData::Ixn(InteractionEvent {
previous_event_hash: _,
data,
}) => data.iter().find_map(|seal| {
if let Seal::Payload(payload) = seal {
if payload.payload_type.eq("MBX") {
Some((event.sn, payload.clone()))
} else {
None
}
} else {
None
}
}),
_ => None,
}
})
.max_by(|x, y| x.0.cmp(&y.0))
.map(|payload| payload.1.payload)),
None => Ok(None),
}
}

pub fn get_event_at_sn(
&self,
id: &IdentifierPrefix,
Expand Down

0 comments on commit 7029e21

Please sign in to comment.