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)));