Remove deprecated test files and optimize encryption functions
- 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:
@@ -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, ¬ification); err != nil {
|
||||
if err = json.Unmarshal([]byte(decrypted), ¬ification); err != nil {
|
||||
return fmt.Errorf("failed to parse notification JSON: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user