|
4 | 4 | from .descriptor import Descriptor |
5 | 5 | from .serializations import PSBT |
6 | 6 |
|
| 7 | +from enum import IntEnum |
| 8 | + |
| 9 | +class DeviceFeature(IntEnum): |
| 10 | + SUPPORTED = 1 # The device supports the feature and so does HWI |
| 11 | + NOT_SUPPORTED = 2 # The device supports the feature but HWI has not implemented it yet |
| 12 | + FIRMWARE_NOT_SUPPORTED = 3 # The firmware does not support the feature so HWI cannot |
| 13 | + |
| 14 | +class SupportedFeatures(object): |
| 15 | + |
| 16 | + def __init__(self) -> None: |
| 17 | + self.getxpub = DeviceFeature.NOT_SUPPORTED |
| 18 | + self.signmessage = DeviceFeature.NOT_SUPPORTED |
| 19 | + self.setup = DeviceFeature.NOT_SUPPORTED |
| 20 | + self.wipe = DeviceFeature.NOT_SUPPORTED |
| 21 | + self.recover = DeviceFeature.NOT_SUPPORTED |
| 22 | + self.backup = DeviceFeature.NOT_SUPPORTED |
| 23 | + self.sign_p2pkh = DeviceFeature.NOT_SUPPORTED |
| 24 | + self.sign_p2sh_p2wpkh = DeviceFeature.NOT_SUPPORTED |
| 25 | + self.sign_p2wpkh = DeviceFeature.NOT_SUPPORTED |
| 26 | + self.sign_multi_p2sh = DeviceFeature.NOT_SUPPORTED |
| 27 | + self.sign_multi_p2sh_p2wsh = DeviceFeature.NOT_SUPPORTED |
| 28 | + self.sign_multi_p2wsh = DeviceFeature.NOT_SUPPORTED |
| 29 | + self.sign_multi_bare = DeviceFeature.NOT_SUPPORTED |
| 30 | + self.sign_arbitrary_bare = DeviceFeature.NOT_SUPPORTED |
| 31 | + self.sign_arbitrary_p2sh = DeviceFeature.NOT_SUPPORTED |
| 32 | + self.sign_arbitrary_p2sh_p2wsh = DeviceFeature.NOT_SUPPORTED |
| 33 | + self.sign_arbitrary_p2wsh = DeviceFeature.NOT_SUPPORTED |
| 34 | + self.sign_coinjoin = DeviceFeature.NOT_SUPPORTED |
| 35 | + self.sign_mixed_segwit = DeviceFeature.NOT_SUPPORTED |
| 36 | + self.display_address = DeviceFeature.NOT_SUPPORTED |
| 37 | + |
| 38 | + def get_printable_dict(self) -> Dict[str, DeviceFeature]: |
| 39 | + d = {} |
| 40 | + d['getxpub'] = self.getxpub |
| 41 | + d['signmessage'] = self.signmessage |
| 42 | + d['setup'] = self.setup |
| 43 | + d['wipe'] = self.wipe |
| 44 | + d['recover'] = self.recover |
| 45 | + d['backup'] = self.backup |
| 46 | + d['sign_p2pkh'] = self.sign_p2pkh |
| 47 | + d['sign_p2sh_p2wpkh'] = self.sign_p2sh_p2wpkh |
| 48 | + d['sign_p2wpkh'] = self.sign_p2wpkh |
| 49 | + d['sign_multi_p2sh'] = self.sign_multi_p2sh |
| 50 | + d['sign_multi_p2sh_p2wsh'] = self.sign_multi_p2sh_p2wsh |
| 51 | + d['sign_multi_p2wsh'] = self.sign_multi_p2wsh |
| 52 | + d['sign_multi_bare'] = self.sign_multi_bare |
| 53 | + d['sign_arbitrary_bare'] = self.sign_arbitrary_bare |
| 54 | + d['sign_arbitrary_p2sh'] = self.sign_arbitrary_p2sh |
| 55 | + d['sign_arbitrary_p2sh_p2wsh'] = self.sign_arbitrary_p2sh_p2wsh |
| 56 | + d['sign_arbitrary_p2wsh'] = self.sign_arbitrary_p2wsh |
| 57 | + d['sign_coinjoin'] = self.sign_coinjoin |
| 58 | + d['sign_mixed_segwit'] = self.sign_mixed_segwit |
| 59 | + d['display_address'] = self.display_address |
| 60 | + return d |
7 | 61 |
|
8 | 62 | class HardwareWalletClient(object): |
9 | 63 | """Create a client for a HID device that has already been opened. |
@@ -185,3 +239,13 @@ def toggle_passphrase(self) -> Dict[str, Union[bool, str, int]]: |
185 | 239 | """ |
186 | 240 | raise NotImplementedError("The HardwareWalletClient base class " |
187 | 241 | "does not implement this method") |
| 242 | + |
| 243 | + @classmethod |
| 244 | + def get_features(self) -> 'SupportedFeatures': |
| 245 | + """ |
| 246 | + Get features. |
| 247 | +
|
| 248 | + Returns an object with a listing of the features supported by this device. |
| 249 | + """ |
| 250 | + raise NotImplementedError("The HardwareWalletClient base class " |
| 251 | + "does not implement this method") |
0 commit comments