Rand Stats

EC

zef:grondilu

SparrowCI

Elliptic Curves Cryptography in raku

secp256k1 and ed25519 in raku

Synopsis

{
    use secp256k1;

    say key-range;
    say $_*G for 1..10;

    use Test;
    is 35*G + 5*G, 40*G;
}

{
    use ed25519;

    # create a key
    # - randomly :
    my ed25519::Key $key .= new;
    # - from a seed :
    my blob8 $secret-seed .= new: ^256 .roll: 32;
    my ed25519::Key $key .= new: $secret-seed;

    # use key to sign a message
    my $signature = $key.sign: "Hello world!";

    # verify signature
    use Test;
    lives-ok { ed25519::verify "foo", $key.sign("foo"), $key.point };
    dies-ok  { ed25519::verify "foo", $key.sign("bar"), $key.point };
}

References