-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial impl of hasher and ECC key pair (#1)
- Loading branch information
Showing
12 changed files
with
1,041 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Clippy Check | ||
|
||
on: [ pull_request ] | ||
|
||
jobs: | ||
clippy_check: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- run: rustup component add clippy | ||
|
||
- name: rust-clippy-check | ||
uses: actions-rs/clippy-check@v1.0.7 | ||
with: | ||
token: ${{ github.token }} | ||
args: --all-features --all-targets -- -D warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
[workspace] | ||
members = [ | ||
"fuel-asm", | ||
"fuel-storage", | ||
"fuel-types", | ||
"fuel-tx", | ||
"fuel-tx/test-helpers", | ||
"fuel-types", | ||
"fuel-vm", | ||
] | ||
[package] | ||
name = "fuel-crypto" | ||
version = "0.1.0" | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
categories = ["cryptography::cryptocurrencies", "data-structures"] | ||
edition = "2021" | ||
homepage = "https://fuel.network/" | ||
keywords = ["blockchain", "cryptocurrencies"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/FuelLabs/fuel-crypto" | ||
description = "Fuel cryptographic primitives." | ||
|
||
# We have a dependency cycle between repositories where `fuel-crypto` depends | ||
# on `fuel-types`, while `fuel-tx` depends on both `fuel-crypto` and | ||
# `fuel-types`. This temporarily works around the issue by forcing all | ||
# instances of `fuel-types` within the graph to point to our local copy. | ||
[patch.crates-io] | ||
fuel-types = { path = "./fuel-types" } | ||
[dependencies] | ||
fuel-types = { version = "0.2", default-features = false } | ||
rand = { version = "0.8", default-features = false, features = ["std_rng"], optional = true } | ||
secp256k1 = { version = "0.20", features = ["recovery"], optional = true } | ||
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true } | ||
sha2 = { version = "0.9", default-features = false } | ||
|
||
[dev-dependencies] | ||
fuel-crypto = { path = ".", default-features = false, features = ["random"] } | ||
rand = { version = "0.8", default-features = false, features = ["std_rng"] } | ||
|
||
[features] | ||
default = ["fuel-types/default", "std"] | ||
random = ["fuel-types/random", "rand"] | ||
serde-types = ["fuel-types/serde-types", "secp256k1/serde", "serde-types-minimal", "serde/default", "std"] | ||
serde-types-minimal = ["fuel-types/serde-types-minimal", "serde"] | ||
std = ["fuel-types/default", "secp256k1"] | ||
|
||
[[test]] | ||
name = "test-signature" | ||
path = "tests/signature.rs" | ||
required-features = ["std"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# fuel-crypto | ||
# Fuel Crypto | ||
|
||
[![build](https://github.com/FuelLabs/fuel-crypto/actions/workflows/ci.yml/badge.svg)](https://github.com/FuelLabs/fuel-crypto/actions/workflows/ci.yml) | ||
[![crates.io](https://img.shields.io/crates/v/fuel-crypto?label=latest)](https://crates.io/crates/fuel-crypto) | ||
[![docs](https://docs.rs/fuel-crypto/badge.svg)](https://docs.rs/fuel-crypto/) | ||
[![discord](https://img.shields.io/badge/chat%20on-discord-orange?&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/xfpK4Pe) | ||
|
||
Fuel cryptographic primitives. | ||
|
||
## Compile features | ||
|
||
- `std`: Unless set, the crate will link to the core-crate instead of the std-crate. More info [here](https://docs.rust-embedded.org/book/intro/no-std.html). | ||
- `random`: Implement `no-std` [rand](https://crates.io/crates/rand) features for the provided types. | ||
- `serde-types`: Add support for [serde](https://crates.io/crates/serde) for the provided types. | ||
- `serde-types-minimal`: Add support for `no-std` [serde](https://crates.io/crates/serde) for the provided types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/// Crypto error variants | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
#[cfg_attr( | ||
feature = "serde-types-minimal", | ||
derive(serde::Serialize, serde::Deserialize) | ||
)] | ||
pub enum Error { | ||
/// Invalid secp256k1 secret key | ||
InvalidSecretKey, | ||
|
||
/// Invalid secp256k1 public key | ||
InvalidPublicKey, | ||
|
||
/// Invalid secp256k1 signature message | ||
InvalidMessage, | ||
|
||
/// Invalid secp256k1 signature | ||
InvalidSignature, | ||
|
||
/// Out of preallocated memory | ||
NotEnoughMemory, | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
mod use_std { | ||
use super::*; | ||
use secp256k1::Error as Secp256k1Error; | ||
use std::{error, fmt}; | ||
|
||
impl From<Secp256k1Error> for Error { | ||
fn from(secp: Secp256k1Error) -> Self { | ||
match secp { | ||
Secp256k1Error::IncorrectSignature | ||
| Secp256k1Error::InvalidSignature | ||
| Secp256k1Error::InvalidTweak | ||
| Secp256k1Error::TweakCheckFailed | ||
| Secp256k1Error::InvalidRecoveryId => Self::InvalidSignature, | ||
Secp256k1Error::InvalidMessage => Self::InvalidMessage, | ||
Secp256k1Error::InvalidPublicKey => Self::InvalidPublicKey, | ||
Secp256k1Error::InvalidSecretKey => Self::InvalidSecretKey, | ||
Secp256k1Error::NotEnoughMemory => Self::NotEnoughMemory, | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{:?}", self) | ||
} | ||
} | ||
|
||
impl error::Error for Error { | ||
fn source(&self) -> Option<&(dyn error::Error + 'static)> { | ||
None | ||
} | ||
} | ||
} |
Oops, something went wrong.