sync

package
v0.0.0-...-df0449a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 8 Imported by: 0

README

This sync package contains the code related to negentropy (event-set-reconciliation) and using the BitTorrent / Mainline DHT for broadcast and discovery of relays.

BEP44: BitTorrent DHT Token Management

BEP44 is a BitTorrent protocol that enables posting arbitrary signed data to hashes derived from a BitTorrent public key.

How It Works

  1. DHT Key: Nestr users that supply a dht_key can declare their list of known relays (urls) to the DHT
  2. Target: The input to the DHT for BEP44 is SHA1(pubkey + salt) where the salt is optional bytes (we use empty salt)
  3. Periodic Upload: The RelayStore object periodically re-uploads the users' relay lists to the DHT, which holds it for about 2 hours
  4. Relay Retrieval: Other users can query the DHT using the dht_key to retrieve the relay list
  5. Negentropy Sync: The RelayStore object periodically tries to sync with all relays that it is aware of
  6. Sync Store: There is a sqlite db that stores info about relays for uploading to dht and syncing

For more detailed information, please refer to the official BEP44 specification.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDHTKeyFromPrivateKey

func CreateDHTKeyFromPrivateKey(privateKey *btcec.PrivateKey) (string, error)

CreateDHTKeyFromPrivateKey creates a DHT key from a btcec.PrivateKey

func CreateDHTKeyFromPublicKey

func CreateDHTKeyFromPublicKey(publicKey *btcec.PublicKey) (string, error)

CreateDHTKeyFromPublicKey creates a DHT key from a btcec.PublicKey

func DeriveKeyFromNsec

func DeriveKeyFromNsec(nsec string) (string, error)

DeriveKeyFromNsec derives a DHT key from a user's nsec (private key) This provides a consistent way to generate DHT keys from private keys using the same approach as GenerateDHTKey for consistency

func GenerateDHTKey

func GenerateDHTKey(privateKeyHex string) (string, error)

GenerateDHTKey generates a DHT key from a private key hex string

func GetDHTKeyForPubkey

func GetDHTKeyForPubkey(pubkey string) (string, error)

GetDHTKeyForPubkey derives a DHT key for a given public key This is useful when you only have the public key and need to find the corresponding DHT key to retrieve data

func SignRelayList

func SignRelayList(relayList []string, nsec string) (string, error)

SignRelayList signs a relay list with the user's private key The signature can be verified to ensure the relay list was created by the owner

func VerifyRelayList

func VerifyRelayList(relayList []string, signature string, pubkey string) (bool, error)

VerifyRelayList verifies the signature on a relay list Returns true if the signature is valid, false otherwise

Types

type RelayList

type RelayList struct {
	Pubkey    string   `json:"pubkey"`
	Relays    []string `json:"relays"`
	CreatedAt int64    `json:"created_at"`
	Signature string   `json:"signature,omitempty"`
}

RelayList represents a user's list of preferred relays

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL