zkcrypto / merlin

Composable proof transcripts for public-coin arguments of knowledge
MIT License
47 stars 16 forks source link

Sample code in README #4

Open oleganza opened 2 years ago

oleganza commented 2 years ago

We need to add a couple samples to help people see how Merlin is used. I just had a conversation with David Vorick who said those examples really help make sense of Merlin.

Example 1: hashing structured data

How HMAC(key, data) would look like on a structured data:

t = Transcript::new(b"Example domain");
t.append_bytes(b"key", b"secretpassword");
t.append_bytes(b"name", b"Merlin");
t.append_bytes(b"job", b"Magic");
hash = t.challenge_bytes(32);

Example 2: use in a ZKP protocol

t = Transcript::new(b"My protocol");
...
t.append_bytes(b"message", ...);
...
t.append_bytes(b"domain-separator", "schnorr-v1");
t.append_bytes(b"X", pubkey.as_point());
t.append_point(b"R", &self.R);
challenge = t.challenge_scalar(b"c");
...

Example 3: generating randomness with TranscriptRNG

...