more conversions.
This commit is contained in:
+9
-15
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user