Skip to content
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

chore(identity): remove unused code and dependecies #393

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,002 changes: 50 additions & 952 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ hex = "0.4.3"
libp2p = "0.53.2"
libp2p-stream = "0.1.0-alpha.1"
multiaddr = "0.18.1"
multibase = "0.9.1"
# multibase = "0.9.1"
near-jsonrpc-client = "0.8.0"
near-jsonrpc-primitives = "0.20.0"
near-primitives = "0.20.0"
Expand Down
6 changes: 1 addition & 5 deletions crates/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ license.workspace = true
bs58.workspace = true
eyre.workspace = true
hex.workspace = true
libp2p = { workspace = true, features = ["full"] }
serde_json.workspace = true
sha2.workspace = true
multibase.workspace = true
serde.workspace = true
libp2p = { workspace = true }
web3.workspace = true
36 changes: 2 additions & 34 deletions crates/identity/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use libp2p::identity::{Keypair, PublicKey};
use libp2p::identity::PublicKey;
use web3::signing::{keccak256, recover};

pub fn verify_peer_auth(keypair: &Keypair, msg: &[u8], signature: &[u8]) -> bool {
keypair.public().verify(msg, signature)
}

pub fn verify_near_public_key(
public_key: &str,
msg: &[u8],
Expand Down Expand Up @@ -50,7 +46,7 @@ pub fn verify_eth_signature(account: &str, message: &str, signature: &str) -> ey
}
}

pub fn eth_message(message: &str) -> [u8; 32] {
fn eth_message(message: &str) -> [u8; 32] {
keccak256(
format!(
"{}{}{}",
Expand Down Expand Up @@ -81,32 +77,4 @@ mod tests {
let pubkey = format!("{:02X?}", pubkey);
assert_eq!(account, pubkey)
}

#[test]
fn valid_headers() {
let keypair = get_peer_keypair().unwrap();
let msg = "blabla";
println!("challenge header= {:?}", bs58::encode(msg).into_string());

let signature = keypair.sign(msg.as_bytes()).unwrap();
let signature_header = bs58::encode(&signature).into_string();
println!("signature header = {:?}", signature_header);

assert_eq!(
verify_peer_auth(&keypair, msg.as_bytes(), signature.as_slice()),
true
);
}

pub fn get_peer_keypair() -> Result<Keypair, String> {
let private_key = "23jhTekjBHR2wvqeGe5kHwJAzoYbhRoqN1YHL9jSsSeqDFwdTJevSnYQ2hcWsBPjGeVMFaTPAX3bPkc2yzyGJQ6AMfCEo";

let private_key = bs58::decode(private_key)
.into_vec()
.map_err(|_| "Invalid PrivKey base 58".to_string())?;

let keypair = Keypair::from_protobuf_encoding(&private_key)
.map_err(|_| "Decoding PrivKey failed.".to_string())?;
Ok(keypair)
}
}
42 changes: 0 additions & 42 deletions crates/identity/src/dht.rs

This file was deleted.

71 changes: 0 additions & 71 deletions crates/identity/src/identity_provider.rs

This file was deleted.

6 changes: 1 addition & 5 deletions crates/identity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
pub mod auth;
pub mod dht;
pub mod identity_provider;
pub mod types;
pub mod vc;
pub mod vp;
// pub mod types;
80 changes: 0 additions & 80 deletions crates/identity/src/main.rs

This file was deleted.

85 changes: 0 additions & 85 deletions crates/identity/src/types.rs

This file was deleted.

Loading