Files
pubky-core/pubky
SHAcollision 6386f1ae43 feat: signup tokens (#80)
* Add admin and signup config

* Add signup tokens API, db, admin endpoint

* Add client api for signup codes

* Add tests and fixes

* Fix wasm build

* Lint

* enable and use same admin pswd on all test homeservers

* fix pr review comments

* Add nodejs and browser signup token to tests

* update signup example

* admin authing as layer

* Update pubky-homeserver/src/core/routes/auth.rs

Co-authored-by: Severin Alexander Bühler <8782386+SeverinAlexB@users.noreply.github.com>

* Update pubky-homeserver/src/core/routes/auth.rs

Co-authored-by: Severin Alexander Bühler <8782386+SeverinAlexB@users.noreply.github.com>

* rename getSignupToken util

* add is_used() SignupToken method

---------

Co-authored-by: Severin Alexander Bühler <8782386+SeverinAlexB@users.noreply.github.com>
2025-03-17 15:58:58 -04:00
..
2025-03-17 15:58:58 -04:00
2025-03-17 15:58:58 -04:00
2025-02-20 09:07:38 -04:00
2025-03-17 15:58:58 -04:00

Pubky

Rust implementation implementation of Pubky client.

Quick Start

use pubky_testnet::Testnet;
use pubky::{Client, Keypair};

#[tokio::main]
async fn main () {
  // Mainline Dht testnet and a temporary homeserver for unit testing.
  let testnet = Testnet::run_with_hardcoded_configurations().await.unwrap();
  let homeserver = testnet.run_homeserver().await.unwrap();

  let client = Client::builder().testnet().build().unwrap();

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

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

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

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

  let data = [0, 1, 2, 3, 4].to_vec();

  // The client has the same familiar API of a reqwest client
  client.put(url).body(data.clone()).send().await.unwrap();

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

  assert_eq!(response_data, data);

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

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

  assert_eq!(response.status(), 404);
}

Example code

Check more examples for using the Pubky client.