From ceccfdbefb3dfa925c818691b38033eb988bfa02 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 12 Nov 2024 15:50:02 -0300 Subject: [PATCH] nip46: better error messages on decrypt failure. --- nip46/bunker_session.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nip46/bunker_session.go b/nip46/bunker_session.go index a7dcd3f..74c1fd2 100644 --- a/nip46/bunker_session.go +++ b/nip46/bunker_session.go @@ -23,15 +23,16 @@ type RelayReadWrite struct { func (s Session) ParseRequest(event *nostr.Event) (Request, error) { var req Request - plain, err := nip44.Decrypt(event.Content, s.ConversationKey) - if err != nil { - plain, err = nip04.Decrypt(event.Content, s.SharedKey) - if err != nil { - return req, fmt.Errorf("failed to decrypt event from %s: %w", event.PubKey, err) + 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) } } - err = json.Unmarshal([]byte(plain), &req) + err := json.Unmarshal([]byte(plain), &req) return req, err }