Skip to content

Commit

Permalink
minor ecies helper update, merge input optimization branch
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Sep 9, 2024
1 parent 3654511 commit 19aa946
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compat/ecies/ecies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
16 changes: 14 additions & 2 deletions compat/ecies/ecies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 19aa946

Please sign in to comment.