-
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.
Refactor of
fuel-crypto
for clarity around safety
This removes many of the unsafe constructors exposed in the `fuel- crypto` API, some due to the implementations not actually being unsafe, and some due to a revised implementation that safely encapsulates the unsafe behaviour. The `Message` and `Signature` `from_bytes` and `from_bytes_ref` constructors have been documented to clarify expectations that they expect signature or cryptographically hashed data respectively. The `PublicKey` and `SecretKey` `from_bytes_unchecked` constructors have been made private in order to ensure holding an instance of one of these types guarantees their inner byte arrays at least satisfies the curve. The original, custom curve-checking functions have been removed in favour of using the secp256k1 library constructors directly which share the same implementation but with an added range check that is likely to get optimised out due to the use of const-sized arrays anyway. Adds some missing `#[repr(transparent)]` decorators to `fuel-types`. The `FuelMnemonic` type provided unnecessary indirection between the user and the free function, and has been removed in favour of exposing the function directly from the crate root.
- Loading branch information
1 parent
bc789b1
commit c387305
Showing
11 changed files
with
98 additions
and
284 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
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,21 +1,11 @@ | ||
/// FuelMnemonic is a simple mnemonic phrase generator. | ||
pub struct FuelMnemonic; | ||
#![cfg(all(feature = "std", feature = "random"))] | ||
|
||
#[cfg(all(feature = "std", feature = "random"))] | ||
mod use_std { | ||
use super::FuelMnemonic; | ||
use crate::Error; | ||
use coins_bip39::{English, Mnemonic}; | ||
use crate::Error; | ||
use coins_bip39::{English, Mnemonic}; | ||
use rand::Rng; | ||
|
||
pub type W = English; | ||
|
||
use rand::Rng; | ||
|
||
impl FuelMnemonic { | ||
/// Generates a random mnemonic phrase given a random number generator and | ||
/// the number of words to generate, `count`. | ||
pub fn generate_mnemonic_phrase<R: Rng>(rng: &mut R, count: usize) -> Result<String, Error> { | ||
Ok(Mnemonic::<W>::new_with_count(rng, count)?.to_phrase()?) | ||
} | ||
} | ||
/// Generates a random mnemonic phrase given a random number generator and | ||
/// the number of words to generate, `count`. | ||
pub fn generate_mnemonic_phrase<R: Rng>(rng: &mut R, count: usize) -> Result<String, Error> { | ||
Ok(Mnemonic::<English>::new_with_count(rng, count)?.to_phrase()?) | ||
} |
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
Oops, something went wrong.