Skip to main content

sign

Function sign 

Source
pub fn sign(identity: &NodeIdentity, domain: Domain, body: Value) -> Signed
Expand description

Sign body as a message of domain. The signature is taken over the domain separator followed by the canonical JSON of the body, so two peers that serialize the same facts in different key orders still agree about what was signed, and nothing signed for one exchange verifies as part of another.

use majordomus_cli::mesh::identity::NodeIdentity;
use majordomus_cli::mesh::link::{sign, verify_signed, Domain};

let node = NodeIdentity::ephemeral().unwrap();
let signed = sign(&node, Domain::Welcome, serde_json::json!({ "link": "abc" }));
assert!(verify_signed(&node.public.public_key, Domain::Welcome, &signed));

// the body travels as given; the signature is what is derived
assert_eq!(signed.body["link"], "abc");