Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions pkgs/id/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ pub fn sign_genesis(
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)?)
}
Expand Down Expand Up @@ -227,6 +228,7 @@ pub fn sign_claim(
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)?)
}
Expand Down
30 changes: 30 additions & 0 deletions pkgs/id/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use serde::{Deserialize, Serialize};
use unicode_normalization::is_nfc;

use crate::documents::{DocumentRef, is_document_kind, is_removal_kind};
use crate::issuer_rotation::{IssuerRotation, is_rotation_kind};
use crate::note_links::{NoteLinkOp, check_note_link_op, is_note_link_kind};
use crate::notes::{NoteOp, check_note_op, is_note_kind};
use crate::session_checkpoint::{SessionCheckpoint, check_session_checkpoint, is_checkpoint_kind};
Expand Down Expand Up @@ -131,6 +132,11 @@ pub struct ChainExt {
/// the segment this checkpoint closes, signed with the header, so an
/// event carries its whole checkpoint, and sync needs no separate body.
pub checkpoint: Option<SessionCheckpoint>,
/// The issuer rotation of an `issuer.rotation` event, and `None` for every
/// other kind. It is the rotation record (#5526, design #2804 section 3.2): signed
/// with the header and persisted with it, because the event store keeps the
/// header but not an event body, so an event carries its whole rotation.
pub rotation: Option<IssuerRotation>,
}

/// The wire form of [`ChainExt`]: the same fields, plus the domain tag. Keys
Expand All @@ -155,6 +161,8 @@ struct Wire {
link: Option<NoteLinkOp>,
#[serde(default, skip_serializing_if = "Option::is_none")]
checkpoint: Option<SessionCheckpoint>,
#[serde(default, skip_serializing_if = "Option::is_none")]
rotation: Option<IssuerRotation>,
}

impl From<ChainExt> for Wire {
Expand All @@ -170,6 +178,7 @@ impl From<ChainExt> for Wire {
note: ext.note,
link: ext.link,
checkpoint: ext.checkpoint,
rotation: ext.rotation,
}
}
}
Expand All @@ -191,6 +200,7 @@ impl TryFrom<Wire> for ChainExt {
note: wire.note,
link: wire.link,
checkpoint: wire.checkpoint,
rotation: wire.rotation,
};
ext.validate()?;
Ok(ext)
Expand Down Expand Up @@ -339,6 +349,22 @@ impl ChainExt {
.map_err(|err| ChainError::Extension(err.to_string()))?;
}
}
match (is_rotation_kind(&self.kind), &self.rotation) {
(false, None) => {}
(false, Some(_)) => {
return Err(ChainError::Extension(format!(
"kind {:?} carries an issuer rotation",
self.kind
)));
}
(true, None) => {
return Err(ChainError::Extension(format!(
"kind {:?} needs its issuer rotation",
self.kind
)));
}
(true, Some(_)) => {}
}
Ok(())
}
}
Expand Down Expand Up @@ -494,6 +520,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
}
}

Expand Down Expand Up @@ -836,6 +863,7 @@ mod tests {
audit_blob: Some(hash(5)),
},
}),
rotation: None,
},
)
.unwrap()
Expand Down Expand Up @@ -1064,6 +1092,7 @@ mod golden {
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)
.unwrap();
Expand All @@ -1083,6 +1112,7 @@ mod golden {
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)
.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions pkgs/id/src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ pub fn sign_authorisation(
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)?)
}
Expand Down Expand Up @@ -380,6 +381,7 @@ pub fn sign_revoke(
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)?)
}
Expand Down
5 changes: 5 additions & 0 deletions pkgs/id/src/event_store/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
};
sign(key, seq, backlink, None, ext).unwrap()
}
Expand Down Expand Up @@ -1571,6 +1572,7 @@ mod tests {
audit_blob: None,
},
}),
rotation: None,
};
let y0 = sign(&y, 0, None, None, ext).unwrap();
assert_eq!(ingest(&mut store, &y0), Ingest::Waiting { id: y0.id });
Expand Down Expand Up @@ -1628,6 +1630,7 @@ mod tests {
audit_blob: None,
},
}),
rotation: None,
};
sign(key, seq, backlink, None, ext).unwrap()
}
Expand Down Expand Up @@ -1878,6 +1881,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
};
sign(&signer, seq, backlink, None, ext).unwrap()
};
Expand Down Expand Up @@ -1913,6 +1917,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
};
let event = sign(key, seq, backlink, Some(&body), ext).unwrap();
(event, body)
Expand Down
1 change: 1 addition & 0 deletions pkgs/id/src/event_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkgs/id/src/event_store/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
};
events.push(chain::sign(&key, seq, backlink, Some(body), ext).unwrap());
}
Expand Down Expand Up @@ -1111,6 +1112,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)
.unwrap();
Expand Down Expand Up @@ -1156,6 +1158,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)
.unwrap();
Expand Down Expand Up @@ -1205,6 +1208,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions pkgs/id/src/idset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ mod tests {
note: None,
link: None,
checkpoint: None,
rotation: None,
},
)
.unwrap();
Expand Down
Loading