Documentation
¶
Index ¶
- Constants
- Variables
- func CheckSig(relay *ws.NIP11RelayInfo) error
- func CreateDHTKeyFromPrivateKey(privateKey *btcec.PrivateKey) (string, error)
- func CreateDHTKeyFromPublicKey(publicKey *btcec.PublicKey) (string, error)
- func CreateMutableTarget(pubKey []byte, salt []byte) krpc.ID
- func CreateMutableTargetFromHex(hexString string) (krpc.ID, error)
- func DefaultDHTServer() *dht.Server
- func DeriveKeyFromNsec(nsec string) (string, error)
- func DoGet(server *dht.Server, target bep44.Target, salt []byte) ([]byte, error)
- func DownloadDag(root string)
- func Equals(nr *ws.NIP11RelayInfo, other *ws.NIP11RelayInfo) bool
- func GenerateDHTKey(privateKeyHex string) (string, error)
- func GetDHTKeyForPubkey(pubkey string) (string, error)
- func GetScionicRoot(event *nostr.Event) (string, bool)
- func HandleMissingNoteRequest(requestJSON []byte, eventStore stores.Store, relayStore *RelayStore) ([]byte, error)
- func InitSyncDB() (*gorm.DB, error)
- func InitiateEventSync(stream network.Stream, filter nostr.Filter, hostId string, store stores.Store) error
- func LoadEventVector(events []*nostr.Event) (*negentropy.Vector, error)
- func MarshalRelay(nr ws.NIP11RelayInfo) ([]byte, error)
- func ParseURLs(input []byte) []string
- func PerformNIP11Request(url string) *ws.NIP11RelayInfo
- func PutDHTUploadable(db *gorm.DB, payload []byte, pubkey []byte, signature []byte) error
- func PutSyncAuthor(db *gorm.DB, publicKey string) error
- func PutSyncRelay(db *gorm.DB, publicKey string, relayInfo interface{}) error
- func SearchForRelays(d *dht.Server, maxRelays int, minIndex int, maxIndex int) ([]ws.NIP11RelayInfo, []int)
- func SendNegentropyMessage(hostId string, stream network.Stream, msgType string, filter nostr.Filter, ...) error
- func SetupNegentropyEventHandler(h host.Host, hostId string, store stores.Store)
- func SignPut(put *bep44.Put, privKey ed25519.PrivateKey) error
- func SignRelayList(relayList []string, nsec string) (string, error)
- func VerifyRelayList(relayList []string, signature string, pubkey string) (bool, error)
- type DHTUploadable
- type KeyPair
- type MissingNoteRequest
- type MissingNoteResponse
- type RelayList
- type RelayStore
- func (rs *RelayStore) AddAuthor(authorPubkey string)
- func (rs *RelayStore) AddRelay(relay *ws.NIP11RelayInfo)
- func (rs *RelayStore) AddUploadable(payload string, pubkey string, signature string, uploadNow bool) error
- func (rs *RelayStore) DoPut(uploadable DHTUploadable) (krpc.ID, error)
- func (rs *RelayStore) GetRelayListFromDHT(dhtKey *string) ([]*ws.NIP11RelayInfo, error)
- func (rs *RelayStore) RetrieveRelayList(dhtKey string) ([]string, error)
- func (rs *RelayStore) StoreRelayList(dhtKey string, relayList []string, pubkey string, signature string) error
- func (rs *RelayStore) SyncWithRelay(relay *ws.NIP11RelayInfo, filter nostr.Filter)
- type SyncAuthor
- type SyncRelay
Constants ¶
const FrameSizeLimit = 4096
const IdSize = 32
const NegentropyProtocol = "/negentropy/1.0.0"
Variables ¶
var HardcodedKey = KeyPair{ PrivKey: []byte{ 0x51, 0x8d, 0x31, 0x74, 0x5e, 0x17, 0x14, 0x28, 0xf4, 0xbc, 0x5e, 0x2c, 0x88, 0xae, 0x2f, 0x36, 0x37, 0x7a, 0xc2, 0xf4, 0xd3, 0xe1, 0x38, 0x68, 0xac, 0xc6, 0x9f, 0x3f, 0x88, 0x99, 0x2b, 0xdb, 0x6b, 0x9f, 0x74, 0x78, 0x36, 0x89, 0x4f, 0xc2, 0xc6, 0xcd, 0xbe, 0x8d, 0xce, 0x52, 0xc1, 0xaf, 0xc1, 0xc9, 0x48, 0xb5, 0x72, 0xf0, 0xc6, 0x62, 0x3a, 0x07, 0xcf, 0x77, 0xb5, 0xb8, 0xf8, 0x7f, }, PubKey: []byte{ 0x6b, 0x9f, 0x74, 0x78, 0x36, 0x89, 0x4f, 0xc2, 0xc6, 0xcd, 0xbe, 0x8d, 0xce, 0x52, 0xc1, 0xaf, 0xc1, 0xc9, 0x48, 0xb5, 0x72, 0xf0, 0xc6, 0x62, 0x3a, 0x07, 0xcf, 0x77, 0xb5, 0xb8, 0xf8, 0x7f, }, }
used to make targets predictable
Functions ¶
func CheckSig ¶
func CheckSig(relay *ws.NIP11RelayInfo) error
func CreateDHTKeyFromPrivateKey ¶
func CreateDHTKeyFromPrivateKey(privateKey *btcec.PrivateKey) (string, error)
CreateDHTKeyFromPrivateKey creates a DHT key from a private key This is a convenience function for creating a DHT key from a btcec.PrivateKey using the same approach as GenerateDHTKey for consistency
func CreateDHTKeyFromPublicKey ¶
CreateDHTKeyFromPublicKey creates a DHT key from a public key This is a convenience function for creating a DHT key from a btcec.PublicKey
func CreateMutableTarget ¶
CreateMutableTarget derives the target (dht-input) for a given pubKey and salt
func CreateMutableTargetFromHex ¶
CreateMutableTargetFromHex creates a mutable target from a hex string This is a convenience function for creating a target from a hex string
func DefaultDHTServer ¶
func DeriveKeyFromNsec ¶
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 DownloadDag ¶
func DownloadDag(root string)
func Equals ¶
func Equals(nr *ws.NIP11RelayInfo, other *ws.NIP11RelayInfo) bool
func GenerateDHTKey ¶
GenerateDHTKey generates a DHT key from a private key hex string This is the implementation that was previously in services/server/port/main.go
func GetDHTKeyForPubkey ¶
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 HandleMissingNoteRequest ¶
func HandleMissingNoteRequest(requestJSON []byte, eventStore stores.Store, relayStore *RelayStore) ([]byte, error)
HandleMissingNoteRequest processes a request for a missing note This is called when a relay receives a request for a missing note
func InitSyncDB ¶
Helper function to initialize database connection
func InitiateEventSync ¶
func LoadEventVector ¶
func LoadEventVector(events []*nostr.Event) (*negentropy.Vector, error)
func MarshalRelay ¶
func MarshalRelay(nr ws.NIP11RelayInfo) ([]byte, error)
func PerformNIP11Request ¶
func PerformNIP11Request(url string) *ws.NIP11RelayInfo
PerformNIP11Request attempts to get NIP11 info from a given url
func PutDHTUploadable ¶
PutDHTUploadable adds or updates a DHTUploadable
func PutSyncAuthor ¶
PutSyncAuthor adds or updates a SyncAuthor
func PutSyncRelay ¶
PutSyncRelay adds or updates a SyncRelay
func SearchForRelays ¶
func SearchForRelays(d *dht.Server, maxRelays int, minIndex int, maxIndex int) ([]ws.NIP11RelayInfo, []int)
SearchForRelays searches salt-space for relays to sync with The target is derived from a hardcoded key (because it needs to be predictable) and an enumeration of possible salts "nostr:relay:%d" NOTE: this is not currently used outside of tests
func SendNegentropyMessage ¶
func SignPut ¶
func SignPut(put *bep44.Put, privKey ed25519.PrivateKey) error
SignPut takes a bep44 put object and formats it and signs it, putting the signature in put.Sig
func SignRelayList ¶
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
Types ¶
type DHTUploadable ¶
func GetDHTUploadables ¶
func GetDHTUploadables(db *gorm.DB) ([]DHTUploadable, error)
type MissingNoteRequest ¶
type MissingNoteRequest struct {
EventID string `json:"event_id"` // ID of the missing event
AuthorPubkey string `json:"author_pubkey"` // Pubkey of the event author
DHTKey string `json:"dht_key"` // DHT key for the author's relay list
}
MissingNoteRequest represents a request to retrieve a missing note
type MissingNoteResponse ¶
type MissingNoteResponse struct {
Event *nostr.Event `json:"event"` // The retrieved event, if found
Found bool `json:"found"` // Whether the event was found
RelayURL string `json:"relay_url"` // URL of the relay where the event was found
Timestamp int64 `json:"timestamp"` // Timestamp of when the event was found
}
MissingNoteResponse represents a response to a missing note request
func RequestMissingNoteFromRelay ¶
func RequestMissingNoteFromRelay(request *MissingNoteRequest, targetRelayURL string) (*MissingNoteResponse, error)
RequestMissingNoteFromRelay sends a request to another relay to retrieve a missing note This is used when a relay needs to request a note from another relay
func RetrieveMissingNote ¶
func RetrieveMissingNote(eventID string, authorPubkey string, relayStore *RelayStore, eventStore stores.Store) (*MissingNoteResponse, error)
RetrieveMissingNote retrieves a missing note from relays associated with a user It uses the DHT to find the user's relay list, then queries those relays for the note
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 This structure is used for storing and retrieving relay lists from the DHT
type RelayStore ¶
type RelayStore struct {
// contains filtered or unexported fields
}
RelayStore struct encapsulates the connection to the dht and the db where we store relay info It also handles syncing with other relays
func GetRelayStore ¶
func GetRelayStore() *RelayStore
func NewRelayStore ¶
func (*RelayStore) AddAuthor ¶
func (rs *RelayStore) AddAuthor(authorPubkey string)
AddAuthor adds a pubkey to the relay db
func (*RelayStore) AddRelay ¶
func (rs *RelayStore) AddRelay(relay *ws.NIP11RelayInfo)
AddRelay adds a given relay to the relay db
func (*RelayStore) AddUploadable ¶
func (rs *RelayStore) AddUploadable(payload string, pubkey string, signature string, uploadNow bool) error
AddUploadable saves an DHTUploadable to the relay db
func (*RelayStore) DoPut ¶
func (rs *RelayStore) DoPut(uploadable DHTUploadable) (krpc.ID, error)
DoPut takes a DHTUploadable and puts it on the DHT
func (*RelayStore) GetRelayListFromDHT ¶
func (rs *RelayStore) GetRelayListFromDHT(dhtKey *string) ([]*ws.NIP11RelayInfo, error)
GetRelayListFromDHT takes a dhtKey and asks the DHT for any data at the corresponding target It expects this data to be in the form of relay URLs, which we can later sync to
func (*RelayStore) RetrieveRelayList ¶
func (rs *RelayStore) RetrieveRelayList(dhtKey string) ([]string, error)
RetrieveRelayList retrieves a relay list from the DHT Returns the relay list and any error that occurred
func (*RelayStore) StoreRelayList ¶
func (rs *RelayStore) StoreRelayList(dhtKey string, relayList []string, pubkey string, signature string) error
StoreRelayList stores a signed relay list in the DHT This extends the existing RelayStore to support relay list storage
func (*RelayStore) SyncWithRelay ¶
func (rs *RelayStore) SyncWithRelay(relay *ws.NIP11RelayInfo, filter nostr.Filter)
SyncWithRelay will attempt to do a negentropy event sync with a relay specified by NIP11RelayInfo if the specified relay is not a hornet relay, then we do not try to sync
type SyncAuthor ¶
GORM models for sync / dht related structs
func GetSyncAuthors ¶
func GetSyncAuthors(db *gorm.DB) ([]SyncAuthor, error)