2 unstable releases

0.3.0 Oct 25, 2024
0.1.0 Sep 6, 2024

#1571 in Network programming

Download history 123/week @ 2024-09-02 24/week @ 2024-09-16 13/week @ 2024-09-23 3/week @ 2024-09-30 119/week @ 2024-10-21 40/week @ 2024-10-28 122/week @ 2024-11-04 27/week @ 2024-11-11 116/week @ 2024-11-18 75/week @ 2024-11-25 80/week @ 2024-12-02 104/week @ 2024-12-09

376 downloads per month
Used in pubky-app-specs

MIT license

95KB
2K SLoC

Rust 2K SLoC // 0.0% comments JavaScript 372 SLoC // 0.1% comments

Pubky

Rust implementation implementation of Pubky client.

Quick Start

use pkarr::mainline::Testnet;
use pkarr::Keypair;
use pubky_homeserver::Homeserver;
use pubky::PubkyClient;

#[tokio::main]
async fn main () {
  // Mainline Dht testnet and a temporary homeserver for unit testing.
  let testnet = Testnet::new(10);
  let server = Homeserver::start_test(&testnet).await.unwrap();

  let client = PubkyClient::test(&testnet);

  // Uncomment the following line instead if you are not just testing.
  // let client PubkyClient::builder().build(); 

  // Generate a keypair
  let keypair = Keypair::random();

  // Signup to a Homeserver
  let keypair = Keypair::random();
  client.signup(&keypair, &server.public_key()).await.unwrap();

  // Write data.
  let url = format!("pubky://{}/pub/foo.txt", keypair.public_key());
  let url = url.as_str();

  client.put(url, &[0, 1, 2, 3, 4]).await.unwrap();

  // Read using a Public key based link
  let response = client.get(url).await.unwrap().unwrap();

  assert_eq!(response, bytes::Bytes::from(vec![0, 1, 2, 3, 4]));

  // Delet an entry.
  client.delete(url).await.unwrap();

  let response = client.get(url).await.unwrap();

  assert_eq!(response, None);
}

Example code

Check more examples for using the Pubky client.

Dependencies

~8–21MB
~319K SLoC