mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 15:20:19 +00:00
fix(keypair): deserialize libp2p keypair from secret key (#116)
* fix: Ed25519 keypair * Update keypair/src/key_pair.rs Co-authored-by: folex <0xdxdy@gmail.com> --------- Co-authored-by: folex <0xdxdy@gmail.com>
This commit is contained in:
parent
c22eab38c1
commit
ee330a715a
@ -201,6 +201,7 @@ pub struct Signature(pub Vec<u8>);
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::KeyPair;
|
||||||
use quickcheck::*;
|
use quickcheck::*;
|
||||||
|
|
||||||
fn eq_keypairs(kp1: &Keypair, kp2: &Keypair) -> bool {
|
fn eq_keypairs(kp1: &Keypair, kp2: &Keypair) -> bool {
|
||||||
@ -218,6 +219,17 @@ mod tests {
|
|||||||
QuickCheck::new().tests(10).quickcheck(prop as fn() -> _);
|
QuickCheck::new().tests(10).quickcheck(prop as fn() -> _);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ed25519_keypair_convert() {
|
||||||
|
fn prop() -> bool {
|
||||||
|
let kp1 = KeyPair::generate_ed25519();
|
||||||
|
let libp2p_kp: libp2p_identity::Keypair = kp1.clone().into();
|
||||||
|
let kp2: KeyPair = libp2p_kp.into();
|
||||||
|
kp1.public() == kp2.public() && kp1.secret().unwrap() == kp2.secret().unwrap()
|
||||||
|
}
|
||||||
|
QuickCheck::new().tests(10).quickcheck(prop as fn() -> _);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ed25519_keypair_from_secret() {
|
fn ed25519_keypair_from_secret() {
|
||||||
fn prop() -> bool {
|
fn prop() -> bool {
|
||||||
|
@ -283,7 +283,9 @@ impl From<KeyPair> for libp2p_identity::Keypair {
|
|||||||
fn convert_keypair(key: KeyPair) -> eyre::Result<libp2p_identity::Keypair> {
|
fn convert_keypair(key: KeyPair) -> eyre::Result<libp2p_identity::Keypair> {
|
||||||
match key {
|
match key {
|
||||||
KeyPair::Ed25519(kp) => {
|
KeyPair::Ed25519(kp) => {
|
||||||
let kp = Keypair::ed25519_from_bytes(kp.encode().to_vec().as_mut_slice())?;
|
// for some reason, libp2p takes SecretKey's 32 bytes here instead of Keypair's 64 bytes
|
||||||
|
let secret_bytes = kp.secret().0.to_bytes();
|
||||||
|
let kp = libp2p_identity::Keypair::ed25519_from_bytes(secret_bytes)?;
|
||||||
Ok(kp)
|
Ok(kp)
|
||||||
}
|
}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user