diff --git a/nip46/dynamic-signer.go b/nip46/dynamic-signer.go index 07a372a..57f26c6 100644 --- a/nip46/dynamic-signer.go +++ b/nip46/dynamic-signer.go @@ -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) diff --git a/nip46/nip46.go b/nip46/nip46.go index 3a075f6..0b50517 100644 --- a/nip46/nip46.go +++ b/nip46/nip46.go @@ -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) diff --git a/nip46/static-key-signer.go b/nip46/static-key-signer.go index 68b79b1..148220d 100644 --- a/nip46/static-key-signer.go +++ b/nip46/static-key-signer.go @@ -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