Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update event types and builder APIs to prevent building events that dont align with the protocol spec #357

Merged
merged 26 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
683de4c
feat: Enforce no unexpected fields in events
stbrody May 15, 2024
d15af99
chore: pass StreamID to Header factory
stbrody May 16, 2024
7efcd7d
chore: StreamId.to_vec cannot fail
stbrody May 16, 2024
cb53168
chore: Add comment clarifying that SignedEvent is only for the rust j…
stbrody May 16, 2024
c7bd39f
Revert "chore: Add comment clarifying that SignedEvent is only for th…
stbrody May 16, 2024
39c2edc
chore: Rename signed::Payload to signed::Envelope for clarity
stbrody May 16, 2024
352f76e
wip
stbrody May 16, 2024
6213d06
WIP builder API
stbrody May 16, 2024
defebd5
feat: event builder passes tests, type state pattern
nathanielc May 16, 2024
fe78bdc
chore: make model required in init event header
stbrody May 16, 2024
aafdd56
add data event builder
stbrody May 16, 2024
5cee5e3
chore: rename Event to RawEvent
stbrody May 16, 2024
881d690
Add function to sign events
stbrody May 16, 2024
31c1752
fix it
stbrody May 16, 2024
ec1b3e4
make private
stbrody May 16, 2024
f68bbd4
add car file encoding
stbrody May 16, 2024
5e0cf04
cache cids
stbrody May 16, 2024
c1e7dd2
wip: remove jws and related types
nathanielc May 16, 2024
22219e0
comments and small cleanups
stbrody May 17, 2024
2da119c
remove deny_unknown_fields directive (for now)
stbrody May 17, 2024
a4e6b9f
comment out unused constants
stbrody May 17, 2024
56b35c8
fix clippy
stbrody May 17, 2024
9dc6a41
Merge remote-tracking branch 'origin/main' into add-builder
stbrody May 17, 2024
48c22c7
fix test
stbrody May 17, 2024
b17185f
rm unused deps
stbrody May 17, 2024
d3fe21e
rm unusued value type
stbrody May 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async-trait = "0.1"
asynchronous-codec = "0.7"
axum = "0.6"
backoff = "0.4"
base64 = "0.20.0"
base64 = "0.21"
bincode = "1.3.3"
bs58 = "0.4"
bytecheck = "0.6.7"
Expand Down
20 changes: 10 additions & 10 deletions api/src/server/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use anyhow::{anyhow, bail, Context, Result};
use ceramic_core::{Cid, EventId, Network};
use ceramic_event::{unvalidated, unvalidated::CeramicExt};
use ceramic_event::unvalidated;
use ipld_core::ipld::Ipld;
use iroh_car::CarReader;
use tokio::io::AsyncRead;
Expand Down Expand Up @@ -31,15 +31,15 @@ where
car_blocks.insert(cid, bytes);
}
let event_bytes = get_block(&event_cid, &car_blocks, store).await?;
let event: unvalidated::Event<Ipld> =
let event: unvalidated::RawEvent<Ipld> =
serde_ipld_dagcbor::from_slice(&event_bytes).context("decoding event")?;

let (init_id, init_payload) = match event {
unvalidated::Event::Time(event) => (
unvalidated::RawEvent::Time(event) => (
event.id(),
get_init_event_payload(&event.id(), &car_blocks, store).await?,
),
unvalidated::Event::Signed(event) => {
unvalidated::RawEvent::Signed(event) => {
let link = event
.link()
.ok_or_else(|| anyhow!("event should have a link"))?;
Expand All @@ -56,7 +56,7 @@ where
get_init_event_payload(&init_id, &car_blocks, store).await?,
)
}
unvalidated::Event::Unsigned(event) => (event_cid, event),
unvalidated::RawEvent::Unsigned(event) => (event_cid, event),
};

let controller = init_payload
Expand All @@ -67,7 +67,7 @@ where
Ok(EventId::new(
&network,
init_payload.header().sep(),
init_payload.model()?.as_slice(),
init_payload.header().model(),
controller,
&init_id,
&event_cid,
Expand All @@ -80,10 +80,10 @@ async fn get_init_event_payload(
store: &impl AccessModelStore,
) -> Result<unvalidated::init::Payload<Ipld>> {
let init_bytes = get_block(init_id, car_blocks, store).await?;
let init_event: unvalidated::Event<Ipld> =
let init_event: unvalidated::RawEvent<Ipld> =
serde_ipld_dagcbor::from_slice(&init_bytes).context("decoding init event")?;
match init_event {
unvalidated::Event::Signed(event) => {
unvalidated::RawEvent::Signed(event) => {
let link = event
.link()
.ok_or_else(|| anyhow!("init event should have a link"))?;
Expand All @@ -97,8 +97,8 @@ async fn get_init_event_payload(
bail!("init event payload is not well formed")
}
}
unvalidated::Event::Unsigned(event) => Ok(event),
unvalidated::Event::Time(_) => {
unvalidated::RawEvent::Unsigned(event) => Ok(event),
unvalidated::RawEvent::Time(_) => {
bail!("init event payload can't be a time event")
}
}
Expand Down
5 changes: 1 addition & 4 deletions api/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ pub const SIGNED_INIT_EVENT: &str = "
wVnRoYml5U2NtZnU4bjVWN2JvWGd4eW81cTNTWlJSI3o2TWt0QnluQVBMckV5ZVM3cFZ0aGJpeVNjbWZ
1OG41Vjdib1hneHlvNXEzU1pSUiJ9aXNpZ25hdHVyZVhAJAOOXHx9PyttNHjTzwe04TbsskxzfwNK5_X
9e0rXiEOnVDq-Eeqe6KhuqnkSo06nS80UILPCAb4OyOZ6z2MnDA";
pub const SIGNED_INIT_EVENT_PAYLOAD: &str = "
uomRkYXRhoWVzdGVwaBkBTWZoZWFkZXKkY3NlcGVtb2RlbGVtb2RlbFgozgECAYUBEiCg6DKjNeOL00C
0Og8Cmb88UVoPwz3kzXkQpD6Lkx6NWGZ1bmlxdWVMRKbxOrJBC7tqhWjea2NvbnRyb2xsZXJzgXg4ZGl
kOmtleTp6Nk1rdEJ5bkFQTHJFeWVTN3BWdGhiaXlTY21mdThuNVY3Ym9YZ3h5bzVxM1NaUlI";
pub const SIGNED_INIT_EVENT_PAYLOAD: &str = "uomRkYXRhoWVzdGVwaBkBTWZoZWFkZXKkY3NlcGVtb2RlbGVtb2RlbFgozgECAYUBEiCg6DKjNeOL00C0Og8Cmb88UVoPwz3kzXkQpD6Lkx6NWGZ1bmlxdWVMRKbxOrJBC7tqhWjea2NvbnRyb2xsZXJzgXg4ZGlkOmtleTp6Nk1rdEJ5bkFQTHJFeWVTN3BWdGhiaXlTY21mdThuNVY3Ym9YZ3h5bzVxM1NaUlI";

pub const UNSIGNED_INIT_EVENT_CID: &str =
"bafyreiakimdaub7m6inx2nljypdhvhu5vozjhylqukif4hjxt65qnkv6my";
Expand Down
1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ publish = false

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
base64 = "0.21.2"
cid.workspace = true
did-method-key = "0.2.1"
Expand Down
172 changes: 0 additions & 172 deletions core/src/jws.rs

This file was deleted.

6 changes: 1 addition & 5 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ mod bytes;
pub mod event_id;
pub mod interest;
mod jwk;
mod jws;
mod network;
mod range;
mod signer;
mod stream_id;

pub use bytes::Bytes;
pub use event_id::EventId;
pub use interest::{Interest, PeerId};
pub use jwk::Jwk;
pub use jws::{Jws, JwsSignature};
pub use network::Network;
pub use range::RangeOpen;
pub use signer::{JwkSigner, Signer};
pub use stream_id::{StreamId, StreamIdType};

pub use cid::Cid;
Expand Down Expand Up @@ -49,7 +45,7 @@ macro_rules! impl_multi_base {
type Error = anyhow::Error;

fn try_from(v: &StreamId) -> Result<Self, Self::Error> {
let v = v.to_vec()?;
let v = v.to_vec();
Ok(Self::from(v))
}
}
Expand Down
62 changes: 0 additions & 62 deletions core/src/signer.rs

This file was deleted.

Loading
Loading