-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement into ecdsa, identity handle, send job
- Loading branch information
Showing
19 changed files
with
170 additions
and
97 deletions.
There are no files selected for viewing
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
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,35 @@ | ||
use starknet::{core::types::FieldElement, signers::SigningKey}; | ||
|
||
pub struct IdentityHandler { | ||
/// Key pair for the p2p network. | ||
/// This represents the identity of the node in the network. | ||
pub p2p_keypair: libp2p::identity::Keypair, | ||
/// The signing key for the StarkNet network. | ||
/// This is used to sign messages and transactions. | ||
pub signing_key: SigningKey, | ||
} | ||
|
||
impl IdentityHandler { | ||
pub fn new(private_key: FieldElement) -> Self { | ||
let secret_key = libp2p::identity::ecdsa::SecretKey::try_from_bytes( | ||
private_key.to_bytes_be().as_slice(), | ||
) | ||
.expect("Failed to create secret key from private key."); | ||
let p2p_keypair = | ||
libp2p::identity::Keypair::from(libp2p::identity::ecdsa::Keypair::from(secret_key)); | ||
let signing_key = SigningKey::from_secret_scalar(private_key); | ||
Self { p2p_keypair, signing_key } | ||
} | ||
|
||
pub fn get_keypair(&self) -> libp2p::identity::Keypair { | ||
self.p2p_keypair.clone() | ||
} | ||
|
||
pub fn get_ecdsa_keypair(&self) -> libp2p::identity::ecdsa::Keypair { | ||
<libp2p::identity::Keypair as Clone>::clone(&self.p2p_keypair).try_into_ecdsa().unwrap() | ||
} | ||
|
||
pub fn get_signing_key(&self) -> SigningKey { | ||
self.signing_key.clone() | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
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.