-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Added additional tool and cleanup (#360)
- Loading branch information
Showing
9 changed files
with
340 additions
and
20 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
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,28 @@ | ||
[package] | ||
name = "relay-server" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
rust-version.workspace = true | ||
repository.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rust-ipfs = { workspace = true } | ||
tokio = { workspace = true, features = ["full"] } | ||
tokio-util = { workspace = true, features = ["full"] } | ||
tokio-stream = { workspace = true, features = ["net"] } | ||
futures.workspace = true | ||
futures-timer.workspace = true | ||
async-trait.workspace = true | ||
async-stream.workspace = true | ||
anyhow.workspace = true | ||
serde.workspace = true | ||
serde_json.workspace = true | ||
void.workspace = true | ||
tracing.workspace = true | ||
clap = { version = "4.4", features = ["derive"] } | ||
zeroize = "1" | ||
dotenv = "0.15" | ||
base64 = "0.21" |
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,47 @@ | ||
use std::{error::Error, path::Path}; | ||
|
||
use base64::{ | ||
alphabet::STANDARD, | ||
engine::{general_purpose::PAD, GeneralPurpose}, | ||
Engine, | ||
}; | ||
use rust_ipfs::{Keypair, PeerId}; | ||
use serde::Deserialize; | ||
use zeroize::Zeroizing; | ||
|
||
#[derive(Clone, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct IpfsConfig { | ||
pub identity: Identity, | ||
} | ||
|
||
impl IpfsConfig { | ||
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, Box<dyn Error>> { | ||
let file = std::fs::File::open(path)?; | ||
let config = serde_json::from_reader(file)?; | ||
Ok(config) | ||
} | ||
} | ||
|
||
#[derive(Deserialize, Clone)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct Identity { | ||
#[serde(rename = "PeerID")] | ||
pub peer_id: PeerId, | ||
pub priv_key: String, | ||
} | ||
|
||
impl Identity { | ||
pub fn keypair(&self) -> Result<Keypair, Box<dyn Error>> { | ||
let engine = GeneralPurpose::new(&STANDARD, PAD); | ||
let keypair_bytes = Zeroizing::new(engine.decode(self.priv_key.as_bytes())?); | ||
let keypair = Keypair::from_protobuf_encoding(&keypair_bytes)?; | ||
Ok(keypair) | ||
} | ||
} | ||
|
||
impl zeroize::Zeroize for IpfsConfig { | ||
fn zeroize(&mut self) { | ||
self.identity.priv_key.zeroize(); | ||
} | ||
} |
Oops, something went wrong.