
    E#i                        S r SSKJr  SSKJrJrJrJrJrJ	r	  SSK
Jr  SSKJr   " S S5      r " S	 S
5      r " S S5      rg)z,Module for BIP32 paths parsing and handling.    )annotations)IteratorListOptionalSequenceTupleUnion   )Bip32PathError)Bip32KeyIndexc                  6    \ rS rSr% SrSrS\S'   SrS\S'   S	rg
)Bip32PathConst    z)Class container for BIP32 path constants.)'hpzTuple[str, str, str]HARDENED_CHARSmstrMASTER_CHAR N)	__name__
__module____qualname____firstlineno____doc__r   __annotations__r   __static_attributes__r       g/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/bip/bip32/bip32_path.pyr   r       s    3 ,;N(:Kr   r   c                      \ rS rSr% SrS\S'   S\S'     S     SS jjr    SS	 jrSS
 jrSS jr	SS jr
SS jrSS jr    SS jrSS jrSrg)	Bip32Path)   z2
BIP32 path class.
It represents a BIP-0032 path.
zList[Bip32KeyIndex]m_elemsboolm_is_absoluteNc                     Uc  / O2U Vs/ s H%  n[        U[        5      (       a  [        U5      OUPM'     snU l        X l        gs  snf ! [         a  n[        S5      UeSnAff = f)z
Construct class.

Args:
    elems (list, optional)      : Path elements (default: empty)
    is_absolute (bool, optional): True if path is an absolute one, false otherwise (default: True)
Nz*The path contains some invalid key indexes)
isinstanceintr   r$   
ValueErrorr   r&   )selfelemsis_absoluteelemexs        r    __init__Bip32Path.__init__2   st    	W$} ej!kej]aD#9N9N-"5TX"Xej!k L )	 "l 	W !MNTVV	Ws'   	A ,AA A 
A&A!!A&c                    [        U[        5      (       a  [        U5      n[        U R                  U/-   U R
                  5      $ )z
Return a new path object with the specified element added.

Args:
    elem (str or Bip32KeyIndex): Path element

Returns:
    Bip32Path object: Bip32Path object

Raises:
    Bip32PathError: If the path element is not valid
)r(   r)   r   r"   r$   r&   r+   r.   s     r    AddElemBip32Path.AddElemE   s9     dC   &D.0B0BCCr   c                    U R                   $ )zR
Get if absolute path.

Returns:
    bool: True if absolute path, false otherwise
)r&   r+   s    r    
IsAbsoluteBip32Path.IsAbsoluteW   s     !!!r   c                ,    [        U R                  5      $ )zO
Get the number of elements of the path.

Returns:
    int: Number of elements
)lenr$   r7   s    r    LengthBip32Path.Length`   s     4<<  r   c                X    U R                    Vs/ s H  n[        U5      PM     sn$ s  snf )zY
Get the path as a list of integers.

Returns:
    list[int]: Path as a list of integers
)r$   r)   r3   s     r    ToListBip32Path.ToListi   s$     '+ll3ldD	l333s   'c                P   U R                   (       d  SO[        R                   S3nU R                   Hl  nUR	                  5       (       d!  U[        UR                  5       5       S3-  nM9  U[        [        R                  " UR                  5       5      5       S3-  nMn     USS $ )?
Get the path as a string.

Returns:
    str: Path as a string
 /z'/N)	r&   r   r   r$   
IsHardenedr   ToIntr   UnhardenIndex)r+   path_strr.   s      r    ToStrBip32Path.ToStrr   s     "//28R8R7SST5ULLD??$$s4::<0133s=#>#>tzz|#LMNbQQ	 ! }r   c                "    U R                  5       $ )rB   )rJ   r7   s    r    __str__Bip32Path.__str__   s     zz|r   c                     U R                   U   $ )z
Get the specified element index.

Args:
    idx (int): Element index

Returns:
    Bip32KeyIndex object: Bip32KeyIndex object
r$   )r+   idxs     r    __getitem__Bip32Path.__getitem__   s     ||C  r   c              #  8   #    U R                    Sh  vN   g N7f)zi
Get the iterator to the current element.

Returns:
    Iterator object: Iterator to the current element
NrP   r7   s    r    __iter__Bip32Path.__iter__   s      <<s   )r$   r&   )NT)r,   z-Optional[Sequence[Union[int, Bip32KeyIndex]]]r-   r%   returnNone)r.   zUnion[int, Bip32KeyIndex]rW   r"   )rW   r%   )rW   r)   )rW   z	List[int])rW   r   )rQ   r)   rW   r   )rW   zIterator[Bip32KeyIndex])r   r   r   r   r   r   r0   r4   r8   r<   r?   rJ   rM   rR   rU   r   r   r   r    r"   r"   )   s    
 !  IM%))E)").2)&D/D4=D$"!4 !!!.! r   r"   c                  T    \ rS rSrSr\SS j5       r\S	S j5       r\S
S j5       rSr	g)Bip32PathParser   zT
BIP32 path parser class.
It parses a BIP-0032 path and returns a Bip32Path object.
c           
         U R                  S5      (       a  U SS n [        R                  [        [	        SU R                  S5      5      5      5      $ )z
Parse a path and return a Bip32Path object.

Args:
    path (str): Path

Returns:
    Bip32Path object: Bip32Path object

Raises:
    Bip32PathError: If the path is not valid
rD   NrE   )endswithrZ   _Bip32PathParser__ParseElementslistfiltersplit)paths    r    ParseBip32PathParser.Parse   sJ      ==9D ..djjo./
 	
r   c                    [        U 5      S:  a  U S   [        R                  :X  a  U SS n SnOSn[        [	        [
        R                  U 5      5      n[        X!5      $ )z
Parse path elements and return a Bip32Path object.

Args:
    path_elems (list[str]): Path elements

Returns:
    Bip32Path object: Bip32Path object

Raises:
    Bip32PathError: If the path is not valid
r   r
   NTF)r;   r   r   r_   maprZ   _Bip32PathParser__ParseElemr"   )
path_elemsr-   parsed_elemss      r    __ParseElementsBip32PathParser.__ParseElements   sZ      z?Q:a=N4N4N#N#ABJKK C ; ;ZHI33r   c                "   U R                  5       n U R                  [        R                  5      nU(       a  U SS n U R	                  5       (       d  [        SU  S35      eU(       d  [        U 5      $ [        R                  " [        U 5      5      $ )z
Parse path element and get the correspondent index.

Args:
    path_elem (str): Path element

Returns:
    int: Index of the element, None if the element is not a valid index

Raises:
    Bip32PathError: If the path is not valid
NrE   zInvalid path element ())	stripr]   r   r   	isnumericr   r)   r   HardenIndex)	path_elemis_hardeneds     r    __ParseElemBip32PathParser.__ParseElem   s      OO%	  (()F)FG !#2I ""$$ #9)A!FGG%0s9~_m6O6OPST]P^6__r   r   N)rb   r   rW   r"   )rh   z	List[str]rW   r"   )rq   r   rW   r)   )
r   r   r   r   r   staticmethodrc   r^   rg   r   r   r   r    rZ   rZ      sE    
 
 
. 4 42 ` `r   rZ   N)r   
__future__r   typingr   r   r   r   r   r	   bip32_exr   bip32_key_datar   r   r"   rZ   r   r   r    <module>rz      s@   * 3 # C C $ ) v  v rU` U`r   