Skip to main content

cita_crypto_trait/
lib.rs

1// Copyright Rivtower Technologies LLC.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use cita_types::Address;
16
17pub trait Sign
18where
19    Self: Sized,
20{
21    type PrivKey;
22    type PubKey;
23    type Message;
24    type Error;
25
26    fn sign(privkey: &Self::PrivKey, message: &Self::Message) -> Result<Self, Self::Error>;
27    fn recover(&self, message: &Self::Message) -> Result<Self::PubKey, Self::Error>;
28    fn verify_public(
29        &self,
30        pubkey: &Self::PubKey,
31        message: &Self::Message,
32    ) -> Result<bool, Self::Error>;
33    fn verify_address(
34        &self,
35        address: &Address,
36        message: &Self::Message,
37    ) -> Result<bool, Self::Error>;
38}
39
40pub trait CreateKey
41where
42    Self: ::std::marker::Sized,
43{
44    type PrivKey;
45    type PubKey;
46    type Error;
47
48    fn from_privkey(privkey: Self::PrivKey) -> Result<Self, Self::Error>;
49    fn gen_keypair() -> Self;
50    fn privkey(&self) -> &Self::PrivKey;
51    fn pubkey(&self) -> &Self::PubKey;
52    fn address(&self) -> Address;
53}