1 unstable release
0.1.0 | Feb 9, 2022 |
---|
#2483 in Cryptography
20KB
283 lines
Elabs Crypto.
This crate provides a set of cryptographic helper functions.
It provide secp256k1
PublicKey, PrivateKey, signer, and hash
functions.
This crate is based on secp256k1
and tiny-keccak
.
Usage
[dependencies]
elabs-crypto = "0.1"
Example
use elabs_crypto::*;
fn main() {
let msg = b"hello world";
let hash = keccak256(msg);
let sk = PrivateKey::random();
let pk = sk.to_public().unwrap();
let sig = sign(msg, sk).unwrap();
let (recid, bsig) = sig.serialize_compact();
let pk2 = ecrecover(&hash, &bsig, recid.to_i32() as u8).unwrap();
assert_eq!(pk, pk2);
}
lib.rs
:
Elabs Crypto.
This crate provides a set of cryptographic helper functions.
It provide secp256k1
PublicKey, PrivateKey, signer, and hash
functions.
This crate is based on secp256k1
and tiny-keccak
.
Usage
[dependencies]
elabs-crypto = "0.1"
Example
use elabs_crypto::*;
fn main() {
let msg = b"hello world";
let hash = keccak256(msg);
let sk = PrivateKey::random();
let pk = sk.to_public().unwrap();
let sig = sign(msg, sk).unwrap();
let (recid, bsig) = sig.serialize_compact();
let pk2 = ecrecover(&hash, &bsig, recid.to_i32() as u8).unwrap();
assert_eq!(pk, pk2);
}
Dependencies
~5.5MB
~56K SLoC