fix caps by hashing JSON-ified params (to avoid, eg, whitespace diffs)

This commit is contained in:
hosted-fornet 2024-07-08 16:56:14 -07:00
parent 6ae6fb24fc
commit 7413646fc4

View File

@ -3,6 +3,7 @@ use ring::signature;
use rusqlite::types::{FromSql, FromSqlError, ToSql, ValueRef};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::hash::{Hash, Hasher};
use thiserror::Error;
lazy_static::lazy_static! {
@ -470,7 +471,7 @@ pub enum Message {
Response((Response, Option<Context>)),
}
#[derive(Clone, Debug, Hash, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Capability {
pub issuer: Address,
pub params: String,
@ -488,6 +489,15 @@ impl PartialEq for Capability {
}
}
impl Hash for Capability {
fn hash<H: Hasher>(&self, state: &mut H) {
self.issuer.hash(state);
let params: serde_json::Value =
serde_json::from_str(&self.params).unwrap_or_default();
params.hash(state);
}
}
impl Capability {
pub fn new<T, U>(issuer: T, params: U) -> Self
where