Skip to content

Commit

Permalink
nip46: better error messages on decrypt failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Nov 12, 2024
1 parent f57ceef commit ceccfdb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions nip46/bunker_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ceccfdb

Please sign in to comment.