-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Edwards Digital Signature Algorithm (EdDSA) over Curve25519. | ||
Check warning on line 1 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / stable / clippy
Check warning on line 1 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / beta / clippy
|
||
//! | ||
//! These functions can be used to implement ed25519 key generation, | ||
//! signing, and verification. | ||
use alloc::vec::Vec; | ||
|
||
use ed25519_zebra::{ | ||
ed25519::PublicKeyBytes, Signature, SigningKey, VerificationKey, | ||
}; | ||
|
||
type Seed = [u8; 32]; | ||
type Public = PublicKeyBytes; | ||
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / stable / clippy
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / wasm32-unknown-unknown
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / beta / clippy
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / beta
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / beta
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Check WASM binary
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / coverage
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / macos-latest / stable
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Gas usage report
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Gas usage report
Check warning on line 12 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / tests
|
||
|
||
/// A key pair. | ||
#[derive(Copy, Clone)] | ||
pub struct Pair { | ||
Check warning on line 16 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / stable / clippy
Check warning on line 16 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / beta / clippy
|
||
public: VerificationKey, | ||
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / wasm32-unknown-unknown
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / beta
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / beta
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Check WASM binary
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / coverage
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / macos-latest / stable
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Gas usage report
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Gas usage report
Check warning on line 17 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / tests
|
||
secret: SigningKey, | ||
} | ||
|
||
impl Pair { | ||
Check warning on line 21 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / stable / clippy
Check warning on line 21 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / beta / clippy
|
||
/// Get the seed for this key. | ||
pub fn seed(&self) -> Seed { | ||
Check warning on line 23 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / stable / clippy
Check warning on line 23 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / beta / clippy
|
||
self.secret.into() | ||
} | ||
|
||
/// Return a vec filled with raw data. | ||
fn to_raw_vec(&self) -> Vec<u8> { | ||
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / stable / clippy
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / wasm32-unknown-unknown
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / beta / clippy
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / beta
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / beta
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / features
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Check WASM binary
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / ubuntu / stable / coverage
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / macos-latest / stable
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Gas usage report
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / Gas usage report
Check warning on line 28 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / tests
|
||
self.seed().to_vec() | ||
} | ||
|
||
fn sign(&self, message: &[u8]) -> Signature { | ||
self.secret.sign(message) | ||
} | ||
|
||
fn verify<M: AsRef<[u8]>>( | ||
sig: &Signature, | ||
message: M, | ||
public: &Public, | ||
) -> bool { | ||
let Ok(public) = VerificationKey::try_from(public.to_bytes()) else { | ||
return false; | ||
}; | ||
public.verify(&sig, message.as_ref()).is_ok() | ||
Check warning on line 44 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / stable / clippy
Check warning on line 44 in contracts/src/utils/cryptography/ed25519.rs GitHub Actions / beta / clippy
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//! Smart Contracts with cryptography. | ||
pub mod ecdsa; | ||
pub mod ed25519; | ||
pub mod eip712; |