@@ -112,6 +112,10 @@ def __init__(self, symbol: str = "BTC", cryptocurrency: Any = None,
112112 self ._private_key : Optional [bytes ] = None
113113 self ._public_key : Optional [str ] = None
114114 self ._chain_code : Optional [bytes ] = None
115+
116+ self ._private_key_base58check : Optional [str ] = None
117+ self ._public_key_base58check : Optional [str ] = None
118+
115119 self ._depth : int = 0
116120 self ._index : int = 0
117121
@@ -211,6 +215,8 @@ def from_seed(self, seed: str) -> "HDWallet":
211215 if self ._use_default_path :
212216 self .from_path (path = self ._cryptocurrency .DEFAULT_PATH )
213217 self ._public_key = self .compressed ()
218+ self ._public_key_base58check = self .public_key_base58check ()
219+ self ._private_key_base58check = self .private_key_base58check ()
214220 if self ._from_class :
215221 self .from_path (path = self ._path_class )
216222 return self
@@ -251,6 +257,8 @@ def from_root_xprivate_key(self, xprivate_key: str, strict: bool = True) -> "HDW
251257 if self ._from_class :
252258 self .from_path (path = self ._path_class )
253259 self ._public_key = self .compressed ()
260+ self ._public_key_base58check = self .public_key_base58check ()
261+ self ._private_key_base58check = self .private_key_base58check ()
254262 return self
255263
256264 def from_root_xpublic_key (self , xpublic_key : str , strict : bool = True ) -> "HDWallet" :
@@ -289,6 +297,7 @@ def from_root_xpublic_key(self, xpublic_key: str, strict: bool = True) -> "HDWal
289297 if self ._from_class :
290298 self .from_path (path = self ._path_class )
291299 self ._public_key = self .compressed ()
300+ self ._public_key_base58check = self .public_key_base58check ()
292301 return self
293302
294303 def from_xprivate_key (self , xprivate_key : str ) -> "HDWallet" :
@@ -317,6 +326,8 @@ def from_xprivate_key(self, xprivate_key: str) -> "HDWallet":
317326 self ._key = ecdsa .SigningKey .from_string (_deserialize_xprivate_key [5 ], curve = SECP256k1 )
318327 self ._verified_key = self ._key .get_verifying_key ()
319328 self ._public_key = self .compressed ()
329+ self ._public_key_base58check = self .public_key_base58check ()
330+ self ._private_key_base58check = self .private_key_base58check ()
320331 return self
321332
322333 def from_xpublic_key (self , xpublic_key : str ) -> "HDWallet" :
@@ -346,6 +357,7 @@ def from_xpublic_key(self, xpublic_key: str) -> "HDWallet":
346357 _deserialize_xpublic_key [5 ], curve = SECP256k1
347358 )
348359 self ._public_key = self .compressed ()
360+ self ._public_key_base58check = self .public_key_base58check ()
349361 return self
350362
351363 def from_wif (self , wif : str ) -> "HDWallet" :
@@ -372,6 +384,8 @@ def from_wif(self, wif: str) -> "HDWallet":
372384 self ._key = ecdsa .SigningKey .from_string (self ._private_key , curve = SECP256k1 )
373385 self ._verified_key = self ._key .get_verifying_key ()
374386 self ._public_key = self .compressed ()
387+ self ._public_key_base58check = self .public_key_base58check ()
388+ self ._private_key_base58check = self .private_key_base58check ()
375389 return self
376390
377391 def from_private_key (self , private_key : str ) -> "HDWallet" :
@@ -394,6 +408,8 @@ def from_private_key(self, private_key: str) -> "HDWallet":
394408 self ._key = ecdsa .SigningKey .from_string (self ._private_key , curve = SECP256k1 )
395409 self ._verified_key = self ._key .get_verifying_key ()
396410 self ._public_key = self .compressed ()
411+ self ._public_key_base58check = self .public_key_base58check ()
412+ self ._private_key_base58check = self .private_key_base58check ()
397413 return self
398414
399415 def from_public_key (self , public_key : str ) -> "HDWallet" :
@@ -416,6 +432,7 @@ def from_public_key(self, public_key: str) -> "HDWallet":
416432 unhexlify (public_key ), curve = SECP256k1
417433 )
418434 self ._public_key = self .compressed ()
435+ self ._public_key_base58check = self .public_key_base58check ()
419436 return self
420437
421438 def from_path (self , path : Union [str , Derivation ]) -> "HDWallet" :
@@ -521,6 +538,7 @@ def _derive_key_by_index(self, index) -> Optional["HDWallet"]:
521538 )
522539 self ._key = ecdsa .SigningKey .from_string (self ._private_key , curve = SECP256k1 )
523540 self ._verified_key = self ._key .get_verifying_key ()
541+ self ._private_key_base58check = self .private_key_base58check ()
524542 else :
525543 key_point = S256Point .parse (unhexlify (self .public_key ()))
526544 left_point = il_int * G
@@ -730,6 +748,7 @@ def clean_derivation(self) -> "HDWallet":
730748 self ._private_key , self ._chain_code = self ._root_private_key
731749 self ._key = ecdsa .SigningKey .from_string (self ._private_key , curve = SECP256k1 )
732750 self ._verified_key = self ._key .get_verifying_key ()
751+ self ._private_key_base58check = self .private_key_base58check ()
733752 elif self ._root_public_key :
734753 self ._path , self ._depth , self ._parent_fingerprint , self ._index = (
735754 "m" , 0 , b"\0 \0 \0 \0 " , 0
@@ -847,6 +866,18 @@ def public_key(self, compressed: bool = True, private_key: Optional[str] = None)
847866 return hexlify (ck ).decode () if compressed else self .uncompressed (compressed = hexlify (ck ).decode ())
848867 return self .compressed () if compressed else self .uncompressed ()
849868
869+ def public_key_base58check (self ) -> str :
870+ return base58 .b58encode_check (
871+ _unhexlify (self ._cryptocurrency .PUBLIC_KEY_ADDRESS ) +
872+ unhexlify (self .public_key ())
873+ )
874+
875+ def private_key_base58check (self ) -> str :
876+ return base58 .b58encode_check (
877+ _unhexlify (self ._cryptocurrency .PRIVATE_KEY_ADDRESS ) +
878+ unhexlify (self .private_key ())
879+ )
880+
850881 def strength (self ) -> Optional [int ]:
851882 """
852883 Get Entropy strength.
@@ -1281,6 +1312,8 @@ def dumps(self) -> dict:
12811312 semantic = self .semantic (),
12821313 path = self .path (),
12831314 hash = self .hash (),
1315+ public_key_base58check = self .public_key_base58check (),
1316+ private_key_base58check = self .private_key_base58check (),
12841317 addresses = dict (
12851318 p2pkh = self .p2pkh_address (),
12861319 p2sh = self .p2sh_address (),
0 commit comments