more conversions.

This commit is contained in:
fiatjaf
2025-04-15 00:00:03 -03:00
parent f9e4a5efa3
commit 376834cbf9
117 changed files with 450 additions and 1019 deletions
+9 -15
View File
@@ -3,15 +3,13 @@ package nip46
import (
"fmt"
"fiatjaf.com/nostrlib"
"fiatjaf.com/nostrlib/nip04"
"fiatjaf.com/nostrlib/nip44"
"fiatjaf.com/nostr"
"fiatjaf.com/nostr/nip44"
)
type Session struct {
PublicKey string
SharedKey []byte // nip04
ConversationKey [32]byte // nip44
PublicKey nostr.PubKey
ConversationKey [32]byte
}
type RelayReadWrite struct {
@@ -22,22 +20,18 @@ type RelayReadWrite struct {
func (s Session) ParseRequest(event *nostr.Event) (Request, error) {
var req Request
plain, err1 := nip44.Decrypt(event.Content, s.ConversationKey)
if err1 != nil {
var err2 error
plain, err2 = nip04.Decrypt(event.Content, s.SharedKey)
if err2 != nil {
return req, fmt.Errorf("failed to decrypt event from %s: (nip44: %w, nip04: %w)", event.PubKey, err1, err2)
}
plain, err := nip44.Decrypt(event.Content, s.ConversationKey)
if err != nil {
return req, fmt.Errorf("failed to decrypt event from %s: (nip44: %w)", event.PubKey, err)
}
err := json.Unmarshal([]byte(plain), &req)
err = json.Unmarshal([]byte(plain), &req)
return req, err
}
func (s Session) MakeResponse(
id string,
requester string,
requester nostr.PubKey,
result string,
err error,
) (resp Response, evt nostr.Event, error error) {