keri-dev 07/13/2023 #37
pfeairheller
started this conversation in
Meetings
Replies: 1 comment
-
Useful Please feel free to suggest improvements or corrections. The weird code regarding 'anonymized' which is less straightforward to understand adds a salt to the most internal SAD in a group of nested SADs. If you need further entropy at higher levels (maybe unnecessary) you can add it manually before passing the original SAD in. Saidify (nested) pub(crate) fn saidify(sad: &str, label: Option<&str>, anonymize: Option<bool>) -> Result<String> {
let value: serde_json::Value = serde_json::from_str(sad)?;
let mut sad = Value::from(&value);
crate::keri::saidify_value(&mut sad, label, anonymize, Some(false))?;
sad.to_json()
}
pub(crate) fn saidify_value(
sad: &mut Value,
label: Option<&str>,
anonymize: Option<bool>,
overwrite: Option<bool>,
) -> Result<(Value, bool)> {
let anonymize = anonymize.unwrap_or(false);
let label = label.unwrap_or(Ids::d);
let overwrite = overwrite.unwrap_or(false);
let mut anonymizations: Vec<bool> = vec![];
let mut anonymized;
if sad.to_vec().is_ok() {
for (index, val) in sad.to_vec()?.iter_mut().enumerate() {
(sad[index], anonymized) =
saidify_value(val, Some(label), Some(anonymize), Some(overwrite))?;
anonymizations.push(anonymized)
}
} else if sad.to_map().is_ok() {
for (key, val) in sad.to_map()?.iter_mut() {
(sad[key.as_str()], anonymized) =
saidify_value(val, Some(label), Some(anonymize), Some(overwrite))?;
anonymizations.push(anonymized)
}
}
// the name matched so we are reusing this mutable variable
anonymized = false;
let map_result = sad.to_map();
if map_result.is_ok() {
let map = map_result?;
if map.contains_key(&label.to_string())
&& map[label].to_string().is_ok()
&& (overwrite || map[label].to_string()?.is_empty())
{
if anonymize && !anonymizations.iter().any(|v| *v) {
sad["u"] = dat!(&Salter::new_with_defaults(None)?.qb64()?);
anonymized = true;
}
let saider = Saider::new_with_sad(sad, Some(label), None, None, None)?;
sad[label] = dat!(&saider.qb64()?);
}
}
Ok((sad.clone(), anonymized))
} pub(crate) fn compact_acdc(creder: &Creder) -> Result<(Creder, Vec<Value>)> {
let mut crd = creder.crd();
let mut sads = vec![];
compact_sad(&mut crd, &mut sads)?;
Ok((Creder::new_with_ked(&crd, Some(&creder.code()), Some(&creder.kind()))?, sads))
}
pub(crate) fn compact_sad(sad: &mut Value, sads: &mut Vec<Value>) -> Result<(Value, Vec<Value>)> {
let map = sad.to_map()?;
for (key, mut value) in map.clone() {
sad[key.as_str()] = if value.to_map().is_ok() {
compact_sad(&mut value, sads)?;
if value.to_map()?.contains_key("d") {
sads.push(value.clone());
value["d"].clone()
} else {
value
}
} else {
value
};
}
if map.contains_key("d") {
let (saider, _) = Saider::saidify(sad, None, None, None, None)?;
sad["d"] = dat!(&saider.qb64()?);
}
Ok((sad.clone(), sads.clone()))
}
pub(crate) fn expand_acdc(
creder: &Creder,
to_expand: &[Vec<&str>],
store: &impl KeriStore,
) -> Result<Creder> {
let mut crd = creder.crd();
for path in to_expand {
let mut value = &mut crd;
for (i, component) in path.iter().enumerate() {
if i == path.len() - 1 {
value[*component] = store.get_sad(&value[*component].to_string()?)?;
} else {
value = &mut value[*component];
}
}
}
super::saidify_value(&mut crd, Some(Ids::d), Some(false), Some(true))?;
Creder::new_with_ked(&crd, Some(&creder.code()), Some(&creder.kind()))
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Recording:
https://us06web.zoom.us/rec/share/rMllzyq1NJS_aEedmSOJ7VqHnDDAmcg3vXBhLv70ODEVb_cQiOP-78j-kiDiRUQQ.h65eU9bxLW29j7X-
Passcode: Gx9iK7^e
Reports:
keripy
keria
signify-ts
signify-py
cesride
parside
Jason: Code available to compaction and extraction of ACDCs and generation of SAIDs of most compact version.
Multisig Group Rotation
Beta Was this translation helpful? Give feedback.
All reactions