did_ion/sidetree/operation/
update.rs1use serde::{Deserialize, Serialize};
2
3use crate::sidetree::{json_canonicalization_scheme, DIDSuffix, Delta, PublicKeyJwk, Sidetree};
4
5use super::{jws_decode_verify_inner, PartialVerificationError, SidetreeOperation};
6
7#[derive(Debug, Serialize, Deserialize, Clone)]
13#[serde(rename_all = "camelCase")]
14#[serde(deny_unknown_fields)]
15pub struct UpdateOperation {
16 pub did_suffix: DIDSuffix,
17 pub reveal_value: String,
19 pub delta: Delta,
20 pub signed_data: String,
24}
25
26#[derive(Debug, Clone)]
30pub struct PartiallyVerifiedUpdateOperation {
31 pub reveal_value: String,
32 pub signed_delta: Delta,
33 pub signed_update_key: PublicKeyJwk,
34}
35
36impl SidetreeOperation for UpdateOperation {
37 type PartiallyVerifiedForm = PartiallyVerifiedUpdateOperation;
38
39 fn partial_verify<S: Sidetree>(
53 self,
54 ) -> Result<PartiallyVerifiedUpdateOperation, PartialVerificationError> {
55 let (header, claims) =
58 jws_decode_verify_inner(&self.signed_data, |claims: &UpdateClaims| {
59 &claims.update_key
60 })?;
61
62 if header.algorithm != S::SIGNATURE_ALGORITHM {
63 return Err(PartialVerificationError::InvalidSignatureAlgorithm);
64 }
65
66 let canonicalized_public_key = json_canonicalization_scheme(&claims.update_key).unwrap();
67 let computed_reveal_value = S::reveal_value(canonicalized_public_key.as_bytes());
68 if self.reveal_value != computed_reveal_value {
69 return Err(PartialVerificationError::RevealValueMismatch {
70 computed: computed_reveal_value,
71 found: self.reveal_value,
72 });
73 }
74 let delta_string = json_canonicalization_scheme(&self.delta).unwrap();
75 let delta_hash = S::hash(delta_string.as_bytes());
76 if claims.delta_hash != delta_hash {
77 return Err(PartialVerificationError::DeltaHashMismatch);
78 }
79 Ok(PartiallyVerifiedUpdateOperation {
81 reveal_value: self.reveal_value,
82 signed_delta: self.delta,
83 signed_update_key: claims.update_key,
84 })
85 }
86}
87
88#[derive(Debug, Serialize, Deserialize, Clone)]
90#[serde(rename_all = "camelCase")]
91pub struct UpdateClaims {
92 pub update_key: PublicKeyJwk,
94
95 pub delta_hash: String,
97}