|
| 1 | + |
| 2 | +# |
| 3 | +# Python-slip39 -- Ethereum SLIP-39 Account Generation and Recovery |
| 4 | +# |
| 5 | +# Copyright (c) 2022, Dominion Research & Development Corp. |
| 6 | +# |
| 7 | +# Python-slip39 is free software: you can redistribute it and/or modify it under |
| 8 | +# the terms of the GNU General Public License as published by the Free Software |
| 9 | +# Foundation, either version 3 of the License, or (at your option) any later |
| 10 | +# version. It is also available under alternative (eg. Commercial) licenses, at |
| 11 | +# your option. See the LICENSE file at the top of the source tree. |
| 12 | +# |
| 13 | +# Python-slip39 is distributed in the hope that it will be useful, but WITHOUT |
| 14 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 16 | +# |
| 17 | + |
1 | 18 | import base58 |
2 | 19 | import codecs |
3 | 20 | import hashlib |
@@ -226,7 +243,7 @@ def p2pkh_address( self ): |
226 | 243 |
|
227 | 244 | class Account: |
228 | 245 | """A Cryptocurrency "Account" / Wallet, based on a variety of underlying Python crypto-asset |
229 | | - support modules. Presently, only meherett/python-hdwallet is used |
| 246 | + support modules. Presently, only meherett/python-hdwallet is used. |
230 | 247 |
|
231 | 248 | An appropriate hdwallet-like wrapper is built, for any crypto-asset supported using another |
232 | 249 | module. The required hdwallet API calls are: |
@@ -441,11 +458,15 @@ def from_path( self, path: str = None ) -> "Account": |
441 | 458 |
|
442 | 459 | @property |
443 | 460 | def address( self ): |
444 | | - if self.format == "legacy": |
| 461 | + """Returns the 1..., 3... or bc1... address, depending on whether format is legacy, segwit or bech32""" |
| 462 | + return self.formatted_address() |
| 463 | + |
| 464 | + def formatted_address( self, format=None ): |
| 465 | + if ( format or self.format or '' ).lower() == "legacy": |
445 | 466 | return self.legacy_address() |
446 | | - elif self.format == "segwit": |
| 467 | + elif ( format or self.format or '' ).lower() == "segwit": |
447 | 468 | return self.segwit_address() |
448 | | - elif self.format == "bech32": |
| 469 | + elif ( format or self.format or '' ).lower() == "bech32": |
449 | 470 | return self.bech32_address() |
450 | 471 | raise ValueError( f"Unknown addresses semantic: {self.format}" ) |
451 | 472 |
|
@@ -495,10 +516,19 @@ def path( self ): |
495 | 516 | def key( self ): |
496 | 517 | return self.hdwallet.private_key() |
497 | 518 |
|
| 519 | + @property |
| 520 | + def xkey( self ): |
| 521 | + return self.hdwallet.xprivate_key() |
| 522 | + |
498 | 523 | @property |
499 | 524 | def pubkey( self ): |
500 | 525 | return self.hdwallet.public_key() |
501 | 526 |
|
| 527 | + @property |
| 528 | + def xpubkey( self ): |
| 529 | + """Returns the xpub, ypub or zpub, depending on whether format is legacy, segwit or bech32""" |
| 530 | + return self.hdwallet.xpublic_key() |
| 531 | + |
502 | 532 | def from_private_key( self, private_key ): |
503 | 533 | self.hdwallet.from_private_key( private_key ) |
504 | 534 | return self |
@@ -976,8 +1006,8 @@ def accountgroups( |
976 | 1006 | yield from zip( *[ |
977 | 1007 | accounts( |
978 | 1008 | master_secret = master_secret, |
979 | | - paths = paths, |
980 | 1009 | crypto = crypto, |
| 1010 | + paths = paths, |
981 | 1011 | allow_unbounded = allow_unbounded, |
982 | 1012 | ) |
983 | 1013 | for crypto,paths in cryptopaths_parser( cryptopaths ) |
|
0 commit comments