mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-02 23:00:14 +02:00
nip46: support decrypting with nip44.
This commit is contained in:
parent
abe84f9089
commit
7578bf6c71
@ -104,6 +104,12 @@ func (p *DynamicSigner) HandleRequest(event *nostr.Event) (
|
||||
if err != nil {
|
||||
return req, resp, eventResponse, fmt.Errorf("failed to compute shared secret: %w", err)
|
||||
}
|
||||
|
||||
session.SharedKey, err = nip04.ComputeSharedSecret(event.PubKey, privateKey)
|
||||
if err != nil {
|
||||
return req, resp, eventResponse, fmt.Errorf("failed to compute shared secret: %w", err)
|
||||
}
|
||||
|
||||
p.setSession(event.PubKey, session)
|
||||
|
||||
req, err = session.ParseRequest(event)
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nip04"
|
||||
"github.com/nbd-wtf/go-nostr/nip44"
|
||||
)
|
||||
|
||||
var BUNKER_REGEX = regexp.MustCompile(`^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$`)
|
||||
@ -29,7 +30,8 @@ type Signer interface {
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
SharedKey []byte
|
||||
SharedKey []byte // nip04
|
||||
ConversationKey []byte // nip44
|
||||
}
|
||||
|
||||
type RelayReadWrite struct {
|
||||
@ -40,9 +42,12 @@ type RelayReadWrite struct {
|
||||
func (s Session) ParseRequest(event *nostr.Event) (Request, error) {
|
||||
var req Request
|
||||
|
||||
plain, err := nip04.Decrypt(event.Content, s.SharedKey)
|
||||
plain, err := nip44.Decrypt(event.Content, s.ConversationKey)
|
||||
if err != nil {
|
||||
return req, fmt.Errorf("failed to decrypt event from %s: %w", event.PubKey, err)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(plain), &req)
|
||||
|
@ -56,8 +56,14 @@ func (p *StaticKeySigner) getOrCreateSession(clientPubkey string) (Session, erro
|
||||
return Session{}, fmt.Errorf("failed to compute shared secret: %w", err)
|
||||
}
|
||||
|
||||
ck, err := nip44.GenerateConversationKey(clientPubkey, p.secretKey)
|
||||
if err != nil {
|
||||
return Session{}, fmt.Errorf("failed to compute shared secret: %w", err)
|
||||
}
|
||||
|
||||
session := Session{
|
||||
SharedKey: shared,
|
||||
SharedKey: shared,
|
||||
ConversationKey: ck,
|
||||
}
|
||||
|
||||
// add to pool
|
||||
|
Loading…
x
Reference in New Issue
Block a user