Compare commits

...

3 Commits

Author SHA1 Message Date
4e7a9b5a77 version update 2023-12-18 17:13:16 +03:00
e5b8a9c011 remove std feature, add u64_backend feature 2023-08-23 10:47:52 +02:00
f3bce3023a make ed25519-dalek compilable 2023-08-22 18:24:55 +02:00
5 changed files with 823 additions and 558 deletions

1335
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@ repository = "https://github.com/fluencelabs/trust-graph"
[dependencies]
serde = { version = "1.0.118", features = ["derive"] }
bs58 = "0.5.0"
ed25519-dalek = { version = "1.0.1", features = ["serde", "std"], default-features = false }
ed25519-dalek = { version = "1.0.1", features = ["serde", "u64_backend"], default-features = false }
thiserror = "1.0.23"
lazy_static = "1.4"
sha2 = "0.10.6"
@ -22,9 +22,5 @@ multihash = { version = "0.18.0", features = ["identity"] }
# rand fails to compile for restricted environments like NEAR contracts
rand = { version = "0.8.5", optional = true }
[features]
default = ["rand"]
rand = ["dep:rand", "ed25519-dalek/rand_core", "libp2p-identity/rand"]
[dev-dependencies]
quickcheck = "1.0.3"

View File

@ -1,3 +0,0 @@
[toolchain]
channel = "nightly-2022-08-30"
targets = [ "x86_64-apple-darwin", "x86_64-unknown-linux-gnu" ]

View File

@ -53,12 +53,17 @@ impl Keypair {
kp.zeroize();
Keypair(k)
})
.map_err(DecodingError::Ed25519)
.map_err(|_| DecodingError::Ed25519())
}
/// Sign a message using the private key of this keypair.
pub fn sign(&self, msg: &[u8]) -> Result<Vec<u8>, SigningError> {
Ok(self.0.try_sign(msg)?.to_bytes().to_vec())
Ok(self
.0
.try_sign(msg)
.map_err(|_| SigningError::Ed25519())?
.to_bytes()
.to_vec())
}
/// Get the public key of this keypair.
@ -128,9 +133,8 @@ impl PublicKey {
pub fn verify(&self, msg: &[u8], sig: &[u8]) -> Result<(), VerificationError> {
ed25519::Signature::try_from(sig)
.and_then(|s| self.0.verify(msg, &s))
.map_err(|e| {
.map_err(|_| {
VerificationError::Ed25519(
e,
bs58::encode(sig).into_string(),
bs58::encode(self.0.as_bytes()).into_string(),
)
@ -146,7 +150,7 @@ impl PublicKey {
/// Decode a public key from a byte array as produced by `encode`.
pub fn decode(bytes: &[u8]) -> Result<Self, DecodingError> {
ed25519::PublicKey::from_bytes(bytes)
.map_err(DecodingError::Ed25519)
.map_err(|_| DecodingError::Ed25519())
.map(PublicKey)
}
}
@ -192,7 +196,8 @@ impl SecretKey {
/// returned.
pub fn from_bytes(mut sk_bytes: impl AsMut<[u8]>) -> Result<Self, DecodingError> {
let sk_bytes = sk_bytes.as_mut();
let secret = ed25519::SecretKey::from_bytes(&*sk_bytes).map_err(DecodingError::Ed25519)?;
let secret =
ed25519::SecretKey::from_bytes(&*sk_bytes).map_err(|_| DecodingError::Ed25519())?;
sk_bytes.zeroize();
Ok(SecretKey(secret))
}

View File

@ -31,12 +31,8 @@ pub enum Error {
/// An error during decoding of key material.
#[derive(ThisError, Debug)]
pub enum DecodingError {
#[error("Failed to decode with ed25519: {0}")]
Ed25519(
#[from]
#[source]
ed25519_dalek::ed25519::Error,
),
#[error("Failed to decode with ed25519")]
Ed25519(),
#[error("Invalid type prefix")]
InvalidTypeByte,
#[error("Cannot decode public key from base58 :{0}")]
@ -50,17 +46,13 @@ pub enum DecodingError {
/// An error during signing of a message.
#[derive(ThisError, Debug)]
pub enum SigningError {
#[error("Failed to sign with ed25519: {0}")]
Ed25519(
#[from]
#[source]
ed25519_dalek::ed25519::Error,
),
#[error("Failed to sign with ed25519")]
Ed25519(),
}
/// An error during verification of a message.
#[derive(ThisError, Debug)]
pub enum VerificationError {
#[error("Failed to verify signature {1} with {2} ed25519 public key: {0}")]
Ed25519(#[source] ed25519_dalek::ed25519::Error, String, String),
#[error("Failed to verify signature {0} with {1} ed25519 public key")]
Ed25519(String, String),
}