-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* temporarily switch tofn/protos to forks supporting ed25519 * add ed25519 support * switch dependant repos back
- Loading branch information
Showing
10 changed files
with
514 additions
and
157 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 +1,19 @@ | ||
use super::service::MultisigService; | ||
use crate::{proto::KeygenRequest, TofndResult}; | ||
use tofn::ecdsa::keygen; | ||
|
||
use super::{keypair::KeyPair, service::MultisigService}; | ||
use crate::{ | ||
proto::{Algorithm, KeygenRequest}, | ||
TofndResult, | ||
}; | ||
use anyhow::anyhow; | ||
|
||
impl MultisigService { | ||
pub(super) async fn handle_keygen(&self, request: &KeygenRequest) -> TofndResult<Vec<u8>> { | ||
let algorithm = Algorithm::from_i32(request.algorithm) | ||
.ok_or(anyhow!("Invalid algorithm: {}", request.algorithm))?; | ||
let secret_recovery_key = self.kv_manager.seed().await?; | ||
|
||
let key_pair = keygen(&secret_recovery_key, request.key_uid.as_bytes()) | ||
.map_err(|_| anyhow!("Cannot generate keypair"))?; | ||
|
||
Ok(key_pair.encoded_verifying_key().to_vec()) | ||
Ok( | ||
KeyPair::generate(&secret_recovery_key, request.key_uid.as_bytes(), algorithm)? | ||
.encoded_verifying_key(), | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::{proto::Algorithm, TofndResult}; | ||
use anyhow::anyhow; | ||
use tofn::{ | ||
ecdsa, ed25519, | ||
multisig::{keygen::SecretRecoveryKey, sign::MessageDigest}, | ||
}; | ||
|
||
pub enum KeyPair { | ||
Ecdsa(ecdsa::KeyPair), | ||
Ed25519(ed25519::KeyPair), | ||
} | ||
|
||
impl KeyPair { | ||
pub fn generate( | ||
secret_recovery_key: &SecretRecoveryKey, | ||
session_nonce: &[u8], | ||
algorithm: Algorithm, | ||
) -> TofndResult<Self> { | ||
Ok(match algorithm { | ||
Algorithm::Ecdsa => { | ||
let key_pair = ecdsa::keygen(&secret_recovery_key, session_nonce) | ||
.map_err(|_| anyhow!("Cannot generate keypair"))?; | ||
|
||
Self::Ecdsa(key_pair) | ||
} | ||
|
||
Algorithm::Ed25519 => { | ||
let key_pair = ed25519::keygen(&secret_recovery_key, session_nonce) | ||
.map_err(|_| anyhow!("Cannot generate keypair"))?; | ||
|
||
Self::Ed25519(key_pair) | ||
} | ||
}) | ||
} | ||
|
||
pub fn encoded_verifying_key(&self) -> Vec<u8> { | ||
match self { | ||
Self::Ecdsa(key_pair) => key_pair.encoded_verifying_key().to_vec(), | ||
Self::Ed25519(key_pair) => key_pair.encoded_verifying_key().to_vec(), | ||
} | ||
} | ||
|
||
pub fn sign(&self, msg_to_sign: &MessageDigest) -> TofndResult<Vec<u8>> { | ||
match self { | ||
Self::Ecdsa(key_pair) => ecdsa::sign(key_pair.signing_key(), msg_to_sign) | ||
.map_err(|_| anyhow!("signing failed")), | ||
Self::Ed25519(key_pair) => { | ||
ed25519::sign(key_pair, msg_to_sign).map_err(|_| anyhow!("signing failed")) | ||
} | ||
} | ||
} | ||
} |
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,5 +1,6 @@ | ||
mod key_presence; | ||
mod keygen; | ||
mod keypair; | ||
pub mod service; | ||
mod sign; | ||
|
||
|
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.