Remove deprecated test files and optimize encryption functions
Some checks failed
Go / build (push) Has been cancelled
Go / release (push) Has been cancelled

- Deleted `testresults.txt` and `testmain_test.go` as they were no longer needed.
- Updated the Go workflow to streamline the build process by removing commented-out build steps for various platforms.
- Refactored encryption benchmarks to improve performance and clarity in the `benchmark_test.go` file.
- Introduced a new LICENSE file for the encryption package, specifying the MIT License.
- Enhanced the README with usage instructions and links to the NIP-44 specification.
- Bumped version to v0.25.3 to reflect these changes.
This commit is contained in:
2025-11-05 13:28:17 +00:00
parent 256537ba86
commit 7af08f9fd2
15 changed files with 699 additions and 1104 deletions

View File

@@ -58,13 +58,13 @@ func (cl *Client) Request(
return
}
var content []byte
if content, err = encryption.Encrypt(req, cl.conversationKey); chk.E(err) {
var content string
if content, err = encryption.Encrypt(cl.conversationKey, req, nil); chk.E(err) {
return
}
ev := &event.E{
Content: content,
Content: []byte(content),
CreatedAt: time.Now().Unix(),
Kind: 23194,
Tags: tag.NewS(
@@ -111,9 +111,9 @@ func (cl *Client) Request(
if len(e.Content) == 0 {
return fmt.Errorf("empty response content")
}
var raw []byte
var raw string
if raw, err = encryption.Decrypt(
e.Content, cl.conversationKey,
cl.conversationKey, string(e.Content),
); chk.E(err) {
return fmt.Errorf(
"decryption failed (invalid conversation key): %w", err,
@@ -121,7 +121,7 @@ func (cl *Client) Request(
}
var resp map[string]any
if err = json.Unmarshal(raw, &resp); chk.E(err) {
if err = json.Unmarshal([]byte(raw), &resp); chk.E(err) {
return
}
@@ -235,16 +235,16 @@ func (cl *Client) processNotificationEvent(
ev *event.E, handler NotificationHandler,
) (err error) {
// Decrypt the notification content
var decrypted []byte
var decrypted string
if decrypted, err = encryption.Decrypt(
ev.Content, cl.conversationKey,
cl.conversationKey, string(ev.Content),
); err != nil {
return fmt.Errorf("failed to decrypt notification: %w", err)
}
// Parse the notification JSON
var notification map[string]any
if err = json.Unmarshal(decrypted, &notification); err != nil {
if err = json.Unmarshal([]byte(decrypted), &notification); err != nil {
return fmt.Errorf("failed to parse notification JSON: %w", err)
}

View File

@@ -70,7 +70,7 @@ func TestNWCEncryptionDecryption(t *testing.T) {
testMessage := `{"method":"get_info","params":null}`
// Test encryption
encrypted, err := encryption.Encrypt([]byte(testMessage), convKey)
encrypted, err := encryption.Encrypt(convKey, []byte(testMessage), nil)
if err != nil {
t.Fatalf("encryption failed: %v", err)
}
@@ -80,14 +80,14 @@ func TestNWCEncryptionDecryption(t *testing.T) {
}
// Test decryption
decrypted, err := encryption.Decrypt(encrypted, convKey)
decrypted, err := encryption.Decrypt(convKey, encrypted)
if err != nil {
t.Fatalf("decryption failed: %v", err)
}
if string(decrypted) != testMessage {
if decrypted != testMessage {
t.Fatalf(
"decrypted message mismatch: got %s, want %s", string(decrypted),
"decrypted message mismatch: got %s, want %s", decrypted,
testMessage,
)
}
@@ -111,8 +111,8 @@ func TestNWCEventCreation(t *testing.T) {
t.Fatal(err)
}
convKey, err := encryption.GenerateConversationKeyWithSigner(
clientKey, walletPubkey,
convKey, err := encryption.GenerateConversationKey(
clientKey.Sec(), walletPubkey,
)
if err != nil {
t.Fatal(err)
@@ -124,14 +124,14 @@ func TestNWCEventCreation(t *testing.T) {
t.Fatal(err)
}
encrypted, err := encryption.Encrypt(reqBytes, convKey)
encrypted, err := encryption.Encrypt(convKey, reqBytes, nil)
if err != nil {
t.Fatal(err)
}
// Create NWC event
ev := &event.E{
Content: encrypted,
Content: []byte(encrypted),
CreatedAt: time.Now().Unix(),
Kind: 23194,
Tags: tag.NewS(

View File

@@ -181,8 +181,9 @@ func (m *MockWalletService) processRequestEvent(ev *event.E) (err error) {
if existingKey, exists := m.connectedClients[clientPubkeyHex]; exists {
conversationKey = existingKey
} else {
if conversationKey, err = encryption.GenerateConversationKeyWithSigner(
m.walletSecretKey, clientPubkey,
// Generate conversation key using the wallet's secret key and client's public key
if conversationKey, err = encryption.GenerateConversationKey(
m.walletSecretKey.Sec(), clientPubkey,
); chk.E(err) {
m.clientsMutex.Unlock()
return
@@ -192,15 +193,15 @@ func (m *MockWalletService) processRequestEvent(ev *event.E) (err error) {
m.clientsMutex.Unlock()
// Decrypt request content
var decrypted []byte
var decrypted string
if decrypted, err = encryption.Decrypt(
ev.Content, conversationKey,
conversationKey, string(ev.Content),
); chk.E(err) {
return
}
var request map[string]any
if err = json.Unmarshal(decrypted, &request); chk.E(err) {
if err = json.Unmarshal([]byte(decrypted), &request); chk.E(err) {
return
}
@@ -394,15 +395,15 @@ func (m *MockWalletService) sendErrorResponse(
func (m *MockWalletService) sendEncryptedResponse(
clientPubkey []byte, conversationKey []byte, content []byte,
) (err error) {
var encrypted []byte
var encrypted string
if encrypted, err = encryption.Encrypt(
content, conversationKey,
conversationKey, content, nil,
); chk.E(err) {
return
}
ev := &event.E{
Content: encrypted,
Content: []byte(encrypted),
CreatedAt: time.Now().Unix(),
Kind: 23195,
Tags: tag.NewS(
@@ -442,15 +443,15 @@ func (m *MockWalletService) emitPaymentNotification(
continue
}
var encrypted []byte
var encrypted string
if encrypted, err = encryption.Encrypt(
content, conversationKey,
conversationKey, content, nil,
); chk.E(err) {
continue
}
ev := &event.E{
Content: encrypted,
Content: []byte(encrypted),
CreatedAt: time.Now().Unix(),
Kind: 23197,
Tags: tag.NewS(

View File

@@ -75,8 +75,8 @@ func ParseConnectionURI(nwcUri string) (parts *ConnectionParams, err error) {
return
}
parts.clientSecretKey = clientKey
if parts.conversationKey, err = encryption.GenerateConversationKeyWithSigner(
clientKey,
if parts.conversationKey, err = encryption.GenerateConversationKey(
clientKey.Sec(),
parts.walletPublicKey,
); chk.E(err) {
return