Skip to content

Commit

Permalink
Make keygen easier for usage in scripts (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalabukdima authored May 29, 2024
1 parent 3735454 commit eb75ff4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ jobs:
tags: subsquid/bootnode:${{ inputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build & publish keygen
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/386
target: keygen
push: true
tags: subsquid/keygen:${{ inputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ ENV P2P_LISTEN_ADDRS="/ip4/0.0.0.0/udp/12345/quic-v1"
COPY p2p_healthcheck.sh ./healthcheck.sh
RUN chmod +x ./healthcheck.sh
HEALTHCHECK --interval=5s CMD ./healthcheck.sh


FROM --platform=$BUILDPLATFORM base as keygen
COPY --from=builder /app/target/release/keygen /usr/local/bin/keygen
ENTRYPOINT ["keygen"]
22 changes: 16 additions & 6 deletions transport/src/bin/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
use libp2p::{identity::ed25519, PeerId};
use std::io::Write;
use clap::{self, command, Parser};
use libp2p::PeerId;
use std::path::PathBuf;
use subsquid_network_transport::util;

fn main() -> std::io::Result<()> {
let keypair = ed25519::Keypair::generate();
#[derive(Parser)]
#[command(version)]
struct Cli {
/// Path to the generated key
filename: PathBuf,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let filename = Cli::parse().filename;
let keypair = util::get_keypair(Some(filename)).await?;
let peer_id = PeerId::from_public_key(&keypair.public().into());
eprintln!("Your peer ID: {peer_id}");
std::io::stdout().write_all(&keypair.to_bytes())?;
println!("{peer_id}");
Ok(())
}

0 comments on commit eb75ff4

Please sign in to comment.