Skip to content

Commit

Permalink
Fixed DidDocument format, keys have index property
Browse files Browse the repository at this point in the history
  • Loading branch information
wigy-opensource-developer committed Jul 21, 2021
1 parent 863acb4 commit aa620d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 12 additions & 5 deletions morpheus-node/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ impl DidDocumentState {
.filter(|k| k.added_at_height.map(|h| h <= height).unwrap_or(true))
.collect();

let keys: Vec<KeyData> =
keys_at_height.iter().map(|k| self.key_entry_to_data(*k, height)).collect();
let keys: Vec<KeyData> = keys_at_height
.iter()
.enumerate()
.map(|(i, k)| self.key_entry_to_data(*k, i, height))
.collect();

let rights: HashMap<Right, Vec<KeyRightHistory>> = Right::map_all(|r| {
keys_at_height
Expand Down Expand Up @@ -105,14 +108,18 @@ impl DidDocumentState {
KeyRightHistory { state, derived }
}

fn key_entry_to_data(&self, key_entry: &KeyEntry, height: BlockHeight) -> KeyData {
fn key_entry_to_data(
&self, key_entry: &KeyEntry, index: usize, height: BlockHeight,
) -> KeyData {
let state = KeyState {
authentication: key_entry.auth.to_owned(),
valid_from_block: key_entry.added_at_height,
valid_until_block: key_entry.valid_until(self.tombstoned_at_height),
};
let derived =
KeyDataDerived { valid: key_entry.is_valid_at(self.tombstoned_at_height, height) };
let derived = KeyDataDerived {
index,
valid: key_entry.is_valid_at(self.tombstoned_at_height, height),
};
KeyData { state, derived }
}

Expand Down
7 changes: 6 additions & 1 deletion morpheus-proto/src/data/diddoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct KeyState {

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct KeyDataDerived {
pub index: usize,
pub valid: bool,
}

Expand All @@ -84,7 +85,7 @@ pub struct KeyData {
impl KeyData {
fn from_auth(authentication: Authentication) -> Self {
let state = KeyState { authentication, valid_from_block: None, valid_until_block: None };
let derived = KeyDataDerived { valid: true };
let derived = KeyDataDerived { index: 0, valid: true };
Self { state, derived }
}

Expand Down Expand Up @@ -343,10 +344,12 @@ mod test {
"did": "did:morpheus:ezbeWGSY2dqcUBqT8K7R14xr",
"keys": [
{
"index": 0,
"auth": "iezbeWGSY2dqcUBqT8K7R14xr",
"valid": true
},
{
"index": 1,
"auth": "iez25N5WZ1Q6TQpgpyYgiu9gTX",
"valid": true,
"validFromHeight": 120
Expand Down Expand Up @@ -461,10 +464,12 @@ mod test {
"did": "did:morpheus:ezbeWGSY2dqcUBqT8K7R14xr",
"keys": [
{
"index": 0,
"auth": "iezbeWGSY2dqcUBqT8K7R14xr",
"valid": true
},
{
"index": 1,
"auth": "iez25N5WZ1Q6TQpgpyYgiu9gTX",
"valid": true,
"validFromHeight": 10,
Expand Down

0 comments on commit aa620d0

Please sign in to comment.