
    E#i@                         S r SSKJrJr  SSKJr  SSKJrJr  SSK	J
r
  SSKJrJr  SSKJr  \r " S	 S
5      r " S S5      r " S S5      rg)z!Module for WIF encoding/decoding.    )TupleUnion   )P2PKHPubKeyModes)Base58DecoderBase58Encoder)	CoinsConf)IPrivateKeySecp256k1PrivateKey)
BytesUtilsc                   (    \ rS rSr% SrSr\\S'   Srg)WifConst%   z"Class container for WIF constants.   COMPR_PUB_KEY_SUFFIX N)	__name__
__module____qualname____firstlineno____doc__r   bytes__annotations____static_attributes__r       ^/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/bip/wif/wif.pyr   r   %   s    , #*%)r   r   c            
           \ rS rSrSr\\R                  R                  S5      \	R                  4S\\\4   S\S\	S\4S jj5       rS	rg
)
WifEncoder,   D
WIF encoder class.
It provides methods for encoding to WIF format.
wif_net_verpriv_keynet_verpub_key_modereturnc                    [        U[        5      (       d  [        S5      e[        U [        5      (       a  [        R
                  " U 5      n O [        U [        5      (       d  [        S5      eU R                  5       R                  5       n U[        R                  :X  a  U [        R                  -  n X-   n [        R                  " U 5      $ )a  
Encode key bytes into a WIF string.

Args:
    priv_key (bytes or IPrivateKey)        : Private key bytes or object
    net_ver (bytes, optional)              : Net version (Bitcoin main net by default)
    pub_key_mode (WifPubKeyModes, optional): Specify if the private key corresponds to a compressed public key

Returns:
    str: WIF encoded string

Raises:
    TypeError: If pub_key_mode is not a WifPubKeyModes enum or
               the private key is not a valid Secp256k1PrivateKey
    ValueError: If the key is not valid
z7Public key mode is not an enumerative of WifPubKeyModesz#A secp256k1 private key is required)
isinstanceWifPubKeyModes	TypeErrorr   r   	FromBytesRawToBytes
COMPRESSEDr   r   r   CheckEncode)r"   r#   r$   s      r   EncodeWifEncoder.Encode2   s    ( ,77UVV h&&*44X>HH&9::ABB<<>))+ >444555H % ((22r   r   N)r   r   r   r   r   staticmethodr	   BitcoinMainNet
ParamByKeyr(   r-   r   r   r
   strr/   r   r   r   r   r   r   ,   sa    
  ) 8 8 C CM R.<.G.G&3uk12 &3&3+&3LO&3 &3r   r   c            
       z    \ rS rSrSr\\R                  R                  S5      4S\	S\
S\\
\4   4S jj5       rSrg	)

WifDecoder\   r    r!   wif_strr#   r%   c                 F   [         R                  " U 5      nUS   [        U5      :w  a   [        S[        U5      S SUS   S S35      eUSS n[        R
                  " USS 5      (       af  US   [        [        R                  5      :w  a.  [        S	[        [        R                  5      S SUS   S S35      eUSS n[        R                  nX#4$ [        R
                  " U5      (       d#  [        S
[        R                  " U5       S35      e[        R                  nX#4$ )ar  
Decode key bytes from a WIF string.

Args:
    wif_str (str)            : WIF string
    net_ver (bytes, optional): Net version (Bitcoin main net by default)

Returns:
    tuple[bytes, WifPubKeyModes]: Key bytes (index 0), public key mode (index 1)

Raises:
    Base58ChecksumError: If the base58 checksum is not valid
    ValueError: If the resulting key is not valid
r   z Invalid net version (expected 0x02Xz, got 0x)   Nz1Invalid compressed public key suffix (expected 0xzInvalid decoded key ()r   CheckDecodeord
ValueErrorr   IsValidBytesr   r   r(   r-   r   ToHexStringUNCOMPRESSED)r8   r#   priv_key_bytesr$   s       r   DecodeWifDecoder.Decodeb   sC   & '227; !G,23w<2DH^\]M^_bLccde 
 (+ ++N3B,?@@b!S)F)F%GG GHLiLiHjknGo p+B/4A7 
 ,CR0N)44L ++	 '33NCC #89O9OP^9_8``a!bcc)66L++r   r   N)r   r   r   r   r   r1   r	   r2   r3   r4   r   r   r(   rE   r   r   r   r   r6   r6   \   sR    
  ) 8 8 C CM R-, -,-,W\]bdr]rWs-, -,r   r6   N)r   typingr   r   addrr   base58r   r   	coin_confr	   eccr
   r   
utils.miscr   r(   r   r   r6   r   r   r   <module>rM      sD   * (   # 1 ! 2 # "* *-3 -3`4, 4,r   