Files
pubky-core/pubky-client/README.md
Severin Alexander Bühler 55d52ec4b8 chore(homeserver): Refactor Core (#96)
* first draft

* config2 for the time being

* more refactoring

* write default config if it doesnt exist

* added relays to config

* some refactor

* proper bootstrap nodes and relay config validation

* small comments

* rename module

* renamings

* turn listen_ports to listen_socket

* connected config with homeserver

* cleaned up old config

* cleaned up config_old

* removed old config.example.toml

* cleanup tryfrom conversions

* removed dirs-next

* review cleanup

* extracted default config to its own toml file

* use hostname_validator for rfc1123 domain verification

* Domain struct

* fmt

* small config restructure

* use SignupMode in config and moved it to config dir

* moved and simplified lmdb

* save to switch branches

* lots done already

* missin lock file

* pkarr config

* constants

* app context

* used context in more places

* made homeserver independant

* testing feature

* added datadirmock

* getting the hang about testing

* fixed homeserver core tests

* added HandleHolder

* make the homeserver tasks stop when its dropped

* make server handles optional

* properly cleanup all background tasks

* moved logs

* fixed config default toml

* fmt, clippy

* moved stuff around

* lots of moving and readme

* fixed pkarr republisher tests

* removed docs from include

* fixed and refactored testnet

* make simple_testnet work

* httprelay shutdown

* different testnets

* fixing tests1

* fixing tests

* fixing more tests

* unified pkarr versions

* fixed config with bootstrap nodes and relays

* split up test_republish_on_signin to prevent timing issues

* fixed all tests in e2e?

* fixed multi publisher tests

* fixed pubky-client readme

* fixed testnet readme

* added better errors

* admin error

* fixed tests

* format

* clippy

* cllippy

* fixed testnet ports

* fixed client future issue

* improved testnet

* fixed cache_size pkarr relay issue

* small improvements

* fixed low prio dns record

* removed fixed testnet test due to port conflicts

* fixed browserify issues

* fmt

* clippy

* changed wait for testnet hs admin

* fixed docs clippy issues

* added comments

* moved icann_domain

* renamed datadirs

* implemented default for MockDataDir

* renamed run() to start()

* removed unwraps

* fmt

* fixed rename test

* cleaned up admin trace

* added santity values for periodic backup conf and user keys republisher

* fmt

* fmt

* fixed readme lint

* removed println

* fixed admin server edge to anyhow

* added ipv6 support

* removed unnecessary expects

* renamed testnet

* fmt

* renamed me

* changed import

* fmt
2025-04-18 10:00:43 +03:00

2.3 KiB

Pubky

Rust implementation implementation of Pubky client.

Quick Start

use pubky_testnet::EphemeralTestnet;
use pubky::Keypair;

#[tokio::main]
async fn main () {
  // Mainline Dht testnet and a temporary homeserver for unit testing.
  let testnet = EphemeralTestnet::start().await.unwrap();
  let client = testnet.pubky_client_builder().build().unwrap();

  let homeserver = testnet.homeserver_suite();

  // 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.

Wasm Rust Analyzer

In vscode with the rust-analyzer, wasm behind the #[cfg(wasm_browser)] guard is not type checked. To fix this, add a .vscode/settings.json file in the root of this project with the following content:

{
    "rust-analyzer.cargo.target": "wasm32-unknown-unknown"
}

If not done already, you need to add the wasm target: cargo target add wasm32-unknown-unknown.

This is just a workaround because it enables the wasm feature in all workspace member which creates problems. So it is best to enable this settings only temporarily for wasm development and then turn it off again before commiting the changes. This is a rust-analyzer issue.

How To Build/Test the NPM Package

  1. Go to pubky-client/pkg.
  2. Run npm run build.
  3. Run a testnet mainline DHT, Pkarr relay and Homeserver npm run testnet
  4. Run tests with npm run test.