-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Signer module - kairos-crypto
#35
Conversation
c9f3997
to
9ba8cdc
Compare
9ba8cdc
to
d12f91e
Compare
Rebased and ready for review. |
kairos-crypto/src/lib.rs
Outdated
fn from_public_key(bytes: &[u8]) -> Result<Self, CryptoError> | ||
where | ||
Self: Sized; | ||
|
||
fn sign(&self, data: &[u8]) -> Result<Vec<u8>, CryptoError>; | ||
fn verify(&self, data: &[u8], signature_bytes: &[u8]) -> Result<(), CryptoError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer AsRef<[u8]>
instead of &[u8]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 9792ee3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine.
I don't love traits with a single impl, but since we are planing on adding more it's good to merge.
.private_key | ||
.as_ref() | ||
.ok_or(CryptoError::MissingPrivateKey)?; | ||
let signature = crypto::sign(data, private_key, &self.public_key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned elsewhere, casper_types::crypto::sign
has an unused public_key
.
Here is the crypto signing code that litmus
uses (which has been unit tested and exhaustively tested against casper_types
for compatibility).
// Signs the given message using the given key.
pub fn sign<T: AsRef<[u8]>>(secret_key: &SecretKey, message: T) -> Signature {
match secret_key {
SecretKey::System => Signature::System,
SecretKey::Ed25519(secret_key) => {
let signature = secret_key.sign(message.as_ref());
Signature::Ed25519(signature)
}
SecretKey::Secp256k1(secret_key) => {
let signature = secret_key
.try_sign(message.as_ref())
.expect("should create signature");
Signature::Secp256k1(signature)
}
_ => panic!("SecretKey is marked as non-exhaustive, but this should never happen"),
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to go
This PR moves cryptography from
kairos-cli
- introduced temporarily in Base CLI parsing #12 - into a separate package namedkairos-crypto
.There are few major improvements, mainly:
CryptoSigner
trait to provide implementation-agnostic interface.crypto-casper
(enabled by default).sign()
andverify()
methods - it will be used for signature checking, once Deterministic payload format: ASN.1 schema with DER encoding #30 is merged.CryptoError::Serialization
andCryptoError::Deserialization
.