33import secrets
44from math import ceil , log2
55
6- from pactus .crypto import CryptoConfig
6+ from pactus .crypto . hrp import HRP
77from pactus .utils import utils
88
99from .bls12_381 .bls_sig_g1 import sign
1717
1818
1919class PrivateKey :
20- def __init__ (self , scalar : any ) -> None :
21- self .scalar = scalar
20+ def __init__ (self , scalar : int ) -> None :
21+ self .scalar = scalar % curve_order
2222
2323 @classmethod
2424 def from_bytes (cls , buffer : bytes ) -> PrivateKey :
25- return cls (int .from_bytes (buffer , "big" ) % curve_order )
25+ return cls (int .from_bytes (buffer , "big" ))
2626
2727 @classmethod
2828 def key_gen (cls , ikm : bytes = [], key_info : bytes = b"" ) -> PrivateKey :
@@ -47,7 +47,7 @@ def random(cls) -> PrivateKey:
4747 def from_string (cls , text : str ) -> PrivateKey :
4848 hrp , typ , data = utils .decode_to_base256_with_type (text )
4949
50- if hrp != CryptoConfig .PRIVATE_KEY_HRP :
50+ if hrp != HRP .PRIVATE_KEY_HRP :
5151 msg = f"Invalid hrp: { hrp } "
5252 raise ValueError (msg )
5353
@@ -67,7 +67,7 @@ def raw_bytes(self) -> bytes:
6767
6868 def string (self ) -> str :
6969 return utils .encode_from_base256_with_type (
70- CryptoConfig .PRIVATE_KEY_HRP ,
70+ HRP .PRIVATE_KEY_HRP ,
7171 SIGNATURE_TYPE_BLS ,
7272 self .raw_bytes (),
7373 )
0 commit comments