Skip to content

Sample code in README #4

@oleganza

Description

@oleganza

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

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions