mirror of
https://github.com/fluencelabs/trust-graph
synced 2025-07-07 10:31:43 +00:00
Compare commits
3 Commits
lean-keypa
...
lean-keypa
Author | SHA1 | Date | |
---|---|---|---|
4e7a9b5a77 | |||
e5b8a9c011 | |||
f3bce3023a |
1335
Cargo.lock
generated
1335
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@ repository = "https://github.com/fluencelabs/trust-graph"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.118", features = ["derive"] }
|
serde = { version = "1.0.118", features = ["derive"] }
|
||||||
bs58 = "0.5.0"
|
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"
|
thiserror = "1.0.23"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
sha2 = "0.10.6"
|
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 fails to compile for restricted environments like NEAR contracts
|
||||||
rand = { version = "0.8.5", optional = true }
|
rand = { version = "0.8.5", optional = true }
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["rand"]
|
|
||||||
rand = ["dep:rand", "ed25519-dalek/rand_core", "libp2p-identity/rand"]
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "1.0.3"
|
quickcheck = "1.0.3"
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
[toolchain]
|
|
||||||
channel = "nightly-2022-08-30"
|
|
||||||
targets = [ "x86_64-apple-darwin", "x86_64-unknown-linux-gnu" ]
|
|
@ -53,12 +53,17 @@ impl Keypair {
|
|||||||
kp.zeroize();
|
kp.zeroize();
|
||||||
Keypair(k)
|
Keypair(k)
|
||||||
})
|
})
|
||||||
.map_err(DecodingError::Ed25519)
|
.map_err(|_| DecodingError::Ed25519())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sign a message using the private key of this keypair.
|
/// Sign a message using the private key of this keypair.
|
||||||
pub fn sign(&self, msg: &[u8]) -> Result<Vec<u8>, SigningError> {
|
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.
|
/// Get the public key of this keypair.
|
||||||
@ -128,9 +133,8 @@ impl PublicKey {
|
|||||||
pub fn verify(&self, msg: &[u8], sig: &[u8]) -> Result<(), VerificationError> {
|
pub fn verify(&self, msg: &[u8], sig: &[u8]) -> Result<(), VerificationError> {
|
||||||
ed25519::Signature::try_from(sig)
|
ed25519::Signature::try_from(sig)
|
||||||
.and_then(|s| self.0.verify(msg, &s))
|
.and_then(|s| self.0.verify(msg, &s))
|
||||||
.map_err(|e| {
|
.map_err(|_| {
|
||||||
VerificationError::Ed25519(
|
VerificationError::Ed25519(
|
||||||
e,
|
|
||||||
bs58::encode(sig).into_string(),
|
bs58::encode(sig).into_string(),
|
||||||
bs58::encode(self.0.as_bytes()).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`.
|
/// Decode a public key from a byte array as produced by `encode`.
|
||||||
pub fn decode(bytes: &[u8]) -> Result<Self, DecodingError> {
|
pub fn decode(bytes: &[u8]) -> Result<Self, DecodingError> {
|
||||||
ed25519::PublicKey::from_bytes(bytes)
|
ed25519::PublicKey::from_bytes(bytes)
|
||||||
.map_err(DecodingError::Ed25519)
|
.map_err(|_| DecodingError::Ed25519())
|
||||||
.map(PublicKey)
|
.map(PublicKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +196,8 @@ impl SecretKey {
|
|||||||
/// returned.
|
/// returned.
|
||||||
pub fn from_bytes(mut sk_bytes: impl AsMut<[u8]>) -> Result<Self, DecodingError> {
|
pub fn from_bytes(mut sk_bytes: impl AsMut<[u8]>) -> Result<Self, DecodingError> {
|
||||||
let sk_bytes = sk_bytes.as_mut();
|
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();
|
sk_bytes.zeroize();
|
||||||
Ok(SecretKey(secret))
|
Ok(SecretKey(secret))
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,8 @@ pub enum Error {
|
|||||||
/// An error during decoding of key material.
|
/// An error during decoding of key material.
|
||||||
#[derive(ThisError, Debug)]
|
#[derive(ThisError, Debug)]
|
||||||
pub enum DecodingError {
|
pub enum DecodingError {
|
||||||
#[error("Failed to decode with ed25519: {0}")]
|
#[error("Failed to decode with ed25519")]
|
||||||
Ed25519(
|
Ed25519(),
|
||||||
#[from]
|
|
||||||
#[source]
|
|
||||||
ed25519_dalek::ed25519::Error,
|
|
||||||
),
|
|
||||||
#[error("Invalid type prefix")]
|
#[error("Invalid type prefix")]
|
||||||
InvalidTypeByte,
|
InvalidTypeByte,
|
||||||
#[error("Cannot decode public key from base58 :{0}")]
|
#[error("Cannot decode public key from base58 :{0}")]
|
||||||
@ -50,17 +46,13 @@ pub enum DecodingError {
|
|||||||
/// An error during signing of a message.
|
/// An error during signing of a message.
|
||||||
#[derive(ThisError, Debug)]
|
#[derive(ThisError, Debug)]
|
||||||
pub enum SigningError {
|
pub enum SigningError {
|
||||||
#[error("Failed to sign with ed25519: {0}")]
|
#[error("Failed to sign with ed25519")]
|
||||||
Ed25519(
|
Ed25519(),
|
||||||
#[from]
|
|
||||||
#[source]
|
|
||||||
ed25519_dalek::ed25519::Error,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error during verification of a message.
|
/// An error during verification of a message.
|
||||||
#[derive(ThisError, Debug)]
|
#[derive(ThisError, Debug)]
|
||||||
pub enum VerificationError {
|
pub enum VerificationError {
|
||||||
#[error("Failed to verify signature {1} with {2} ed25519 public key: {0}")]
|
#[error("Failed to verify signature {0} with {1} ed25519 public key")]
|
||||||
Ed25519(#[source] ed25519_dalek::ed25519::Error, String, String),
|
Ed25519(String, String),
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user