mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-07-16 10:49:32 +00:00
Rewrites the Keycard integration to talk to the LEE-flavored applet directly from Rust via keycard-rs (pinned git dependency), dropping the pyo3 shim, python_path.rs, and the vendored keycard-py Python library entirely. Verified end-to-end against real hardware: pairing, PIN verification, mnemonic loading, BIP340 Schnorr signing, and transfers between keycard and public/private accounts. Also cleans up the pyo3 usage that had leaked into wallet's signing path (signing.rs, account_manager.rs) beyond the keycard CLI itself, and trims wallet_with_keycard.sh's Python setup down to just pyscard, which is only needed by the force_unpower.py test helper now.
42 lines
1.3 KiB
Python
Executable File
42 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Forces the card in the first available reader into the unpowered state via
|
|
PC/SC SCARD_UNPOWER_CARD. Run immediately before a wallet command to simulate
|
|
the power-loss condition reported on some USB reader/driver combinations.
|
|
|
|
Either:
|
|
- pcscd re-powers the card on the next SCardConnect, so wallet
|
|
commands will succeed without triggering the retry path.
|
|
- the card stays unpowered, triggering a PC/SC transport error
|
|
(keycard_rs::Error::Io) and exercising the reconnect-and-retry wrapper in
|
|
KeycardWallet::pair() / KeycardWallet::setup_communication_with_pairing().
|
|
"""
|
|
import sys
|
|
from smartcard.scard import (
|
|
SCardEstablishContext, SCardListReaders, SCardConnect, SCardDisconnect,
|
|
SCARD_SCOPE_USER, SCARD_SHARE_SHARED,
|
|
SCARD_PROTOCOL_T0, SCARD_PROTOCOL_T1,
|
|
SCARD_UNPOWER_CARD,
|
|
)
|
|
|
|
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
|
|
hresult, reader_list = SCardListReaders(hcontext, [])
|
|
|
|
if not reader_list:
|
|
print("force_unpower: no readers found, skipping.")
|
|
sys.exit(0)
|
|
|
|
hresult, hcard, _ = SCardConnect(
|
|
hcontext,
|
|
reader_list[0],
|
|
SCARD_SHARE_SHARED,
|
|
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
|
|
)
|
|
|
|
if hresult != 0:
|
|
print(f"force_unpower: SCardConnect failed (hresult={hresult:#010x}), skipping.")
|
|
sys.exit(0)
|
|
|
|
SCardDisconnect(hcard, SCARD_UNPOWER_CARD)
|
|
print("force_unpower: card powered down.")
|