Crates.io | forge_signer |
lib.rs | forge_signer |
version | 0.1.3 |
source | src |
created_at | 2019-10-12 02:21:20.129496 |
updated_at | 2019-10-21 00:20:30.946631 |
description | The rust language implementation of forge_signer |
homepage | https://github.com/ArcBlock/forge-rust-sdk |
repository | https://github.com/ArcBlock/forge-rust-sdk |
max_upload_size | |
id | 171821 |
size | 10,055 |
forge_signer
implement by Rust
.
sign algorithms support ed25519
,secp256k1
currently.
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;
}
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
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)));