Updates for signatures with keycard

This commit is contained in:
jonesmarvin8
2026-04-23 17:45:43 -04:00
parent 9f1c8bdf29
commit fac4e86e40
11 changed files with 331 additions and 126 deletions
+10 -1
View File
@@ -2,13 +2,22 @@ import keycard_wallet as keycard_wallet
import time # For testing
pin = '111111'
path0 = "m/44'/60'/0'/0/0"
path1 = "m/44'/61'/0'/0/0"
path2 = "m/44'/62'/0'/0/0"
path3 = "m/44'/63'/0'/0/0"
path4 = "m/44'/64'/0'/0/0"
my_wallet = keycard_wallet.KeycardWallet()
print("Setup communication with card...", my_wallet.setup_communication(pin))
print("Load mnemonic...", my_wallet.load_mnemonic())
print("Public key", my_wallet.get_public_key_for_path())
print("Public key", my_wallet.get_public_key_for_path(path0))
print("Public key", my_wallet.get_public_key_for_path(path1))
print("Public key", my_wallet.get_public_key_for_path(path2))
print("Public key", my_wallet.get_public_key_for_path(path3))
print("Public key", my_wallet.get_public_key_for_path(path4))
print("Signature", my_wallet.sign_message_for_path())
+8 -4
View File
@@ -96,7 +96,7 @@ class KeycardWallet:
print(f"Error during unpair: {e}")
return False
def get_public_key_for_path(self, path: str = "m/44'/60'/0'/0/0") -> str | None:
def get_public_key_for_path(self, path: str = "m/44'/60'/0'/0/0") -> bytes | None:
try:
if not self.card.is_secure_channel_open or not self.card.is_pin_verified:
return None
@@ -106,14 +106,18 @@ class KeycardWallet:
public_only = True,
keypath = path
)
# TODO (marvin) clean this up
public_key = public_key.public_key
public_key = VerifyingKey.from_string(public_key[1:], curve=SECP256k1)
public_key = public_key.to_string("compressed")[1:]
return public_key.public_key.hex()
return public_key
except Exception as e:
print(f"Error getting public key: {e}")
return None
def sign_message_for_path(self, message: bytes = b"DefaultMessageTestDefaultMessage", path: str = "m/44'/60'/0'/0/0") -> str | None:
def sign_message_for_path(self, message: bytes = b"DefaultMessageTestDefaultMessage", path: str = "m/44'/60'/0'/0/0") -> bytes | None:
try:
if not self.card.is_secure_channel_open or not self.card.is_pin_verified:
return None
@@ -125,7 +129,7 @@ class KeycardWallet:
make_current = False
)
return signature.signature.hex()
return signature.signature
except Exception as e:
print(f"Error signing message: {e}")