1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This file is part of the laron-crypto.
//
// Copyright (C) 2022 Ade M Ramdani
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! # Laron Crypto
//! Laron Crypto is a library for signing and verifying messages using Secp256k1 elliptic curve
//! algorithm.
//!
//! This library is a wrapper for [k256](https://docs.rs/crate/k256/0.11.5) crate.
//! This library also provides a simple way to generate a private key and a public key. and also a
//! valid ethereum address.
//!
//! ## Example
//! ```rust
//! use laron_crypto::{keys::*, common::*};
//!
//! // Generate a new private key and a public key
//! let sk = PrivateKey::new();
//! let pk = sk.public();
//!
//! // Generate a valid ethereum address from the public key
//! let addr = Address::from_public(&pk);
//!
//! // Sign a message
//! let msg = b"Hello World!";
//! let sig = sk.sign(msg);
//! assert!(pk.verify(msg, &sig));
//!
//! // or use other way
//! let sig = signer::sign(msg, &sk);
//! assert!(signer::verify(msg, &sig, &pk));
//!
//! // Recover the public key from the signature
//! let recovered_pk = signer::recover(msg, &sig).unwrap();
//! assert_eq!(pk, recovered_pk);
//! ```