From 19aa9469e95ddc575b0c5ef7b99282392f2722d2 Mon Sep 17 00:00:00 2001 From: Satchmo Date: Mon, 9 Sep 2024 12:10:22 -0400 Subject: [PATCH] minor ecies helper update, merge input optimization branch --- CHANGELOG.md | 17 +++++++++++++---- compat/ecies/ecies.go | 2 +- compat/ecies/ecies_test.go | 16 ++++++++++++++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c5f86c..f9dd5f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,15 +5,24 @@ All notable changes to this project will be documented in this file. The format ## Table of Contents - [Unreleased](#unreleased) -- [1.1.5 - 2024-09-06](#113---2024-09-06) -- [1.1.4 - 2024-09-05](#113---2024-09-05) +- [1.1.6 - 2024-09-09](#116---2024-09-09) +- [1.1.5 - 2024-09-06](#115---2024-09-06) +- [1.1.4 - 2024-09-05](#114---2024-09-05) - [1.1.3 - 2024-09-04](#113---2024-09-04) - [1.1.2 - 2024-09-02](#112---2024-09-02) - [1.1.1 - 2024-08-28](#111---2024-08-28) - [1.1.0 - 2024-08-19](#110---2024-08-19) - [1.0.0 - 2024-06-06](#100---2024-06-06) -## [1.1.5] - 2025-09-06 +## [1.1.6] - 2024-09-09 + - Optimize handling of source transaction inputs. Avoid mocking up entire transaction when adding source inputs. + - Minor alignment in ECIES helper function + +### Changed + - `SetSourceTxFromOutput` changed to be `SetSourceTxOutput` + - Default behavior of `EncryptSingle` uses ephemeral key. Updated test. + +## [1.1.5] - 2024-09-06 - Add test for ephemeral private key in electrum encrypt ecies - Add support for compression for backward compatibility and alignment with ts @@ -23,7 +32,7 @@ All notable changes to this project will be documented in this file. The format ## [1.1.4] - 2024-09-05 - - Update ECIES implementation to align with + - Update ECIES implementation to align with the typescript library ### Added - `primitives/aescbc` directory diff --git a/compat/ecies/ecies.go b/compat/ecies/ecies.go index 33dde91..9250002 100644 --- a/compat/ecies/ecies.go +++ b/compat/ecies/ecies.go @@ -19,7 +19,7 @@ func EncryptSingle(message string, privateKey *ec.PrivateKey) (string, error) { if privateKey == nil { return "", errors.New("private key is required") } - decryptedBytes, _ := ElectrumEncrypt(messageBytes, privateKey.PubKey(), privateKey, false) + decryptedBytes, _ := ElectrumEncrypt(messageBytes, privateKey.PubKey(), nil, false) return base64.StdEncoding.EncodeToString(decryptedBytes), nil } diff --git a/compat/ecies/ecies_test.go b/compat/ecies/ecies_test.go index df21a8b..f51c8f9 100644 --- a/compat/ecies/ecies_test.go +++ b/compat/ecies/ecies_test.go @@ -20,7 +20,6 @@ func TestEncryptDecryptSingle(t *testing.T) { // Electrum Encrypt encryptedData, err := EncryptSingle(msgString, pk) require.NoError(t, err) - require.Equal(t, "QklFMQO7zpX/GS4XpthCy6/hT38ZKsBGbn8JKMGHOY5ifmaoT890Krt9cIRk/ULXaB5uC08owRICzenFbm31pZGu0gCM2uOxpofwHacKidwZ0Q7aEw==", encryptedData) // Electrum Decrypt decryptedData, _ := DecryptSingle(encryptedData, pk) @@ -133,7 +132,20 @@ func TestElectrumEncryptDecryptWithCounterpartyNoKey(t *testing.T) { require.Equal(t, msgString, string(decryptedData)) } -func TestBitcoreEncryptDecryptSolo(t *testing.T) { +func TestBitcoreEncryptDecryptSingle(t *testing.T) { + pk, _ := ec.PrivateKeyFromWif(wif) + + // Bitcore Encrypt + encryptedData, err := BitcoreEncrypt([]byte(msgString), pk.PubKey(), nil, nil) + require.NoError(t, err) + + // Bitcore Decrypt + decryptedData, err := BitcoreDecrypt(encryptedData, pk) + require.NoError(t, err) + require.Equal(t, msgString, string(decryptedData)) +} + +func TestBitcoreEncryptDecryptSingleWithPrivateKey(t *testing.T) { expectedEncryptedData := "A7vOlf8ZLhem2ELLr+FPfxkqwEZufwkowYc5jmJ+ZqhPAAAAAAAAAAAAAAAAAAAAAB27kUY/HpNbiwhYSpEoEZZDW+wEjMmPNcAAxnc0kiuQ73FpFzf6p6afe4wwVtKAAg==" decodedExpectedEncryptedData, _ := base64.StdEncoding.DecodeString(expectedEncryptedData) log.Printf("Decoded expected encrypted data: %x\n", decodedExpectedEncryptedData)