#forge #signer #sign #ed25519 #secp256k1 #language

forge_signer

The rust language implementation of forge_signer

4 releases

0.1.3 Oct 21, 2019
0.1.2 Oct 16, 2019
0.1.1 Oct 14, 2019
0.1.0 Oct 12, 2019

#17 in #forge

25 downloads per month
Used in 4 crates

Apache-2.0

11KB
181 lines

Intro

forge_signer implement by Rust.

sign algorithms support ed25519,secp256k1 currently.

trait Signer

    trait Signer {
        fn get_key_pair() -> Self;
        fn get_public_key(sk: &[u8]) -> Vec<u8>;
        fn sign(sk: &[u8], message: &[u8]) -> Vec<u8>;
        fn verify(pk: &[u8], message: &[u8], signature: &[u8]) -> bool;
    }

API

    get_key_pair(sign_type: Option<SignType>) -> (Vec<u8>, Vec<u8>)
    get_pk_by_sk(sk: &[u8], sign_type: &Option<SignType>) -> Vec<u8>
    sign(sk: &[u8], message: &[u8], sign_type: Option<SignType>) -> Vec<u8>
    verify(pk: &[u8], message: &[u8], signature: &[u8], sign_type: Option<SignType>) -> bool

Usage

    let ed25519_key_pair = get_key_pair(Some(SignType::Ed25519));
    let expect_pk = get_pk_by_sk(&ed25519_key_pair.0, &Some(SignType::Ed25519));
    assert_eq!(ed25519_key_pair.1, expect_pk);

    let message = b"hello rust";
    let signature = sign(&ed25519_key_pair.0, message, Some(SignType::Ed25519));
    assert!(verify(&ed25519_key_pair.1, message, &signature, Some(SignType::Ed25519)));

Dependencies

~6MB
~97K SLoC