Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ cython_debug/
.idea/

# testing/fidling script:

# MacOS
.DS_Store
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Aptos Python SDK will be captured in this file. This changelog is written by hand for now.

## Unreleased

- **[Breaking Change]**: `ed25519` and `secp256k1` private key's `__str__` will now return the AIP-80 compliant string

## 0.11.0

- `PrivateKey.format_private_key` can now format a AIP-80 compliant private key
Expand Down
9 changes: 8 additions & 1 deletion aptos_sdk/ed25519.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __eq__(self, other: object):
return self.key == other.key

def __str__(self):
return self.hex()
return self.aip80()

@staticmethod
def from_hex(value: str | bytes, strict: bool | None = None) -> PrivateKey:
Expand Down Expand Up @@ -325,6 +325,13 @@ def test_private_key_from_str(self):
private_key_bytes.hex(),
)

def test_private_key_aip80_formatting(self):
private_key_with_prefix = "ed25519-priv-0x4e5e3be60f4bbd5e98d086d932f3ce779ff4b58da99bf9e5241ae1212a29e5fe"
self.assertEqual(
str(PrivateKey.from_str(private_key_with_prefix, True)),
private_key_with_prefix,
)

def test_sign_and_verify(self):
in_value = b"test_message"

Expand Down
11 changes: 9 additions & 2 deletions aptos_sdk/secp256k1_ecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __eq__(self, other: object):
return self.key == other.key

def __str__(self):
return self.hex()
return self.aip80()

@staticmethod
def from_hex(value: str | bytes, strict: bool | None = None) -> PrivateKey:
Expand Down Expand Up @@ -63,7 +63,7 @@ def hex(self) -> str:

def aip80(self) -> str:
return PrivateKey.format_private_key(
self.hex(), asymmetric_crypto.PrivateKeyVariant.Ed25519
self.hex(), asymmetric_crypto.PrivateKeyVariant.Secp256k1
)

def public_key(self) -> PublicKey:
Expand Down Expand Up @@ -221,6 +221,13 @@ def test_private_key_from_str(self):
private_key_bytes.hex(),
)

def test_private_key_aip80_formatting(self):
private_key_with_prefix = "secp256k1-priv-0x306fa009600e27c09d2659145ce1785249360dd5fb992da01a578fe67ed607f4"
self.assertEqual(
str(PrivateKey.from_str(private_key_with_prefix, True)),
private_key_with_prefix,
)

def test_vectors(self):
private_key_hex = "secp256k1-priv-0x306fa009600e27c09d2659145ce1785249360dd5fb992da01a578fe67ed607f4"
public_key_hex = "0x04210c9129e35337ff5d6488f90f18d842cf985f06e0baeff8df4bfb2ac4221863e2631b971a237b5db0aa71188e33250732dd461d56ee623cbe0426a5c2db79ef"
Expand Down
Loading