
    Lf>                     :   d dl Z d dlZd dlmZmZmZmZ d dlmZm	Z	 d dl
Z
d dlZd dlmZ d dlmZ d dlmZ ddlmZmZmZmZmZmZmZmZ dd	lmZ d
ededededededede fdZ!ded
edededededededefdZ"d
ededededededededefdZ# G d de      Z$y)    N)DictAnyOptionalList)a2b_hexb2a_hex)encode_typed_data)_URI_PAT_REALM_NAME_ETH)EthereumKey   )signrecoveris_chain_id
is_addressis_cs_pubkeyis_block_numberis_signatureis_eth_privkey)EIP712CertificatechainIdverifyingContract	validFromdelegatecsPubKeybootedAtmetareturnc                 V   t        |       sJ t        |      sJ t        |      sJ t        |      sJ t        |      sJ t	        |      t
        k(  sJ |t	        |      t        k(  sJ ddddddgddddddd	ddd
dddddddddddgddddd| ||||||xs ddd}|S )z
    Delegate certificate: dynamic/one-time, off-chain.

    :param chainId:
    :param verifyingContract:
    :param validFrom:
    :param delegate:
    :param csPubKey:
    :param bootedAt:
    :param meta:
    :return:
    namestring)r   typeversionr   uint256r   addressr   r   r   bytes32r   uint64r   )EIP712DomainEIP712DelegateCertificater(   WMP1)r   r"    r   r   r   r   r   r   r   )typesprimaryTypedomainmessage)r   r   r   r   r!   intstr)r   r   r   r   r   r   r   datas           d/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/autobahn/xbr/_eip712_delegate_certificate.py"create_eip712_delegate_certificater5   -   s8   & w'(((9%%%h!!!>S   <4:,,, #$
 &$	 &%
 0%
 (%
 '%
 '%
 '$
 #$3*)
T 3

 !2"   JB
a9Dv K    eth_privkeyc           	      V    t        |       sJ t        |||||||      }t        | |      S )a]  
    Sign the given data using a EIP712 based signature with the provided private key.

    :param eth_privkey: Signing key.
    :param chainId:
    :param verifyingContract:
    :param validFrom:
    :param delegate:
    :param csPubKey:
    :param bootedAt:
    :param meta:
    :return: The signature according to EIP712 (32+32+1 raw bytes).
    )r   r5   r   )	r7   r   r   r   r   r   r   r   r3   s	            r4    sign_eip712_delegate_certificater9      s;    * +&&&-g7H)U].6$HDT""r6   	signaturec           	      V    t        |      sJ t        | ||||||      }t        ||      S )aI  
    Recover the signer address the given EIP712 signature was signed with.

    :param chainId:
    :param verifyingContract:
    :param validFrom:
    :param delegate:
    :param csPubKey:
    :param bootedAt:
    :param signature:
    :param meta:
    :return: The (computed) signer address the signature was signed with.
    )r   r5   r   )	r   r   r   r   r   r   r   r:   r3   s	            r4   #recover_eip712_delegate_certificater<      s;    * 	"""-g7H)U].6$HD4##r6   c                        e Zd ZdZ	 ddededededededed	eee      f fd
Z	de
defdZde
defdZdefdZddededefdZdedefdZddedeee
f   fdZedd       ZdedefdZedd       Z xZS )r(   )	r   r   r   r   r   r   r   
signatureshashr   r   r   r   r   r   r   r>   c	           	          t         
|   |||       || _        || _        || _        || _        || _        t        |||||||      }	t        |	      | _	        y N)
super__init__r   r   r   r   r>   r5   r	   r?   )selfr   r   r   r   r   r   r   r>   eip712	__class__s             r4   rC   z"EIP712DelegateCertificate.__init__   sd    "3Y?   	$3G4E4=4<4<4<48: &f-	r6   otherr   c                 4   t        || j                        syt        j                  | |      sy|j                  | j                  k7  ry|j
                  | j
                  k7  ry|j                  | j                  k7  ry|j                  | j                  k7  ry|j                  | j                  k7  ry|j                  | j                  k7  ry|j                  | j                  k7  ry|j                  | j                  k7  ry|j                  | j                  k7  ryy)NFT)
isinstancerF   r(   __eq__r   r   r   r   r   r   r   r>   r?   rD   rG   s     r4   rJ   z EIP712DelegateCertificate.__eq__   s    %0(//e<==DLL(""d&<&<<??dnn,>>T]]*>>T]]*>>T]]*::"t.::"r6   c                 &    | j                  |       S rA   )rJ   rK   s     r4   __ne__z EIP712DelegateCertificate.__ne__   s    ;;u%%%r6   c                 H    t        j                  | j                               S rA   )pprintpformatmarshal)rD   s    r4   __str__z!EIP712DelegateCertificate.__str__   s    ~~dlln--r6   keybinaryc           	          t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                        }|j                  ||      S )NrT   )	r5   r   r   r   r   r   r   r   sign_typed_data)rD   rS   rT   rE   s       r4   r   zEIP712DelegateCertificate.sign   sV    3DLL484J4J48NN48MM48MM48MM48II? ""6&"99r6   r:   c           
          t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                  |      S rA   )r<   r   r   r   r   r   r   r   )rD   r:   s     r4   r   z!EIP712DelegateCertificate.recover  sD    24<<373I3I37>>37==37==37==37993<> 	>r6   c           	         t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                        }|s|d   d   r%t        j                  j                  |d   d         nd |d   d<   |d   d   r%t        j                  j                  |d   d         nd |d   d<   |d   d   rt        |d   d         j                         nd |d   d<   |S )Nr,   r0   r   r   r   )r5   r   r   r   r   r   r   r   web3Web3toChecksumAddressr   decode)rD   rT   objs      r4   rQ   z!EIP712DelegateCertificate.marshal  s	   0CGCYCY;?>>:>--:>--:>--6:iiA vy  {D  wE  FY  wZ$))2M2McR[n]pNq2r  `dC	N./dghqdrs}d~)D)DS^T^E_)`  EIC	N:&Y\]fYghrYsY
1K)L)S)S)Uy}C	N:&
r6   c           	      &   t        |       t        k7  r#t        dj                  t        |                   | j	                  dd       }|dk7  rt        dj                  |            | j	                  dd       }t        |      t        k7  r#t        dj                  t        |                  |D ]   }|dvst        dj                  |             |j	                  d	d       }|r|dk7  rt        d
j                  |            |j	                  dd       }|t        d      t        |      t
        k7  r#t        dj                  t        |                  |j	                  dd       }|t        d      t        |      t        k7  r#t        dj                  t        |                  t        j                  |      st        dj                  |            t        |dd        }|j	                  dd       }|t        d      t        |      t
        k7  r#t        dj                  t        |                  |j	                  dd       }|t        d      t        |      t        k7  r#t        dj                  t        |                  t        j                  |      st        dj                  |            t        |dd        }|j	                  dd       }	|	t        d      t        |	      t        k7  r#t        dj                  t        |	                  t        |	      dk7  rt        dj                  |	            t        |	      }	|j	                  dd       }
|
t        d      t        |
      t
        k7  r#t        d j                  t        |
                  |j	                  d!d       }|t        d"      t        |      t        k7  r#t        d#j                  t        |                  t        |||||	|
|$      } | S )%Nz=invalid type {} for object in EIP712DelegateCertificate.parser.   r(   z?invalid primaryType "{}" - expected "EIP712DelegateCertificate"r0   z-invalid type {} for EIP712DelegateCertificate)r!   r   r   r   r   r   r   r   z3invalid attribute "{}" in EIP712DelegateCertificater!   z1unexpected type "{}" in EIP712DelegateCertificater   z,missing chainId in EIP712DelegateCertificatez8invalid type {} for chainId in EIP712DelegateCertificater   z6missing verifyingContract in EIP712DelegateCertificatezBinvalid type {} for verifyingContract in EIP712DelegateCertificatezEinvalid value "{}" for verifyingContract in EIP712DelegateCertificate   r   z.missing validFrom in EIP712DelegateCertificatez:invalid type {} for validFrom in EIP712DelegateCertificater   z-missing delegate in EIP712DelegateCertificatez9invalid type {} for delegate in EIP712DelegateCertificater   z-missing csPubKey in EIP712DelegateCertificatez9invalid type {} for csPubKey in EIP712DelegateCertificate@   z<invalid value "{}" for csPubKey in EIP712DelegateCertificater   z-missing bootedAt in EIP712DelegateCertificatez9invalid type {} for bootedAt in EIP712DelegateCertificater   z)missing meta in EIP712DelegateCertificatez5invalid type {} for meta in EIP712DelegateCertificater,   )r!   dict
ValueErrorformatgetr1   r2   r
   matchr   lenr(   )r^   r.   r3   k_typer   r   r   r   r   r   r   s               r4   parsezEIP712DelegateCertificate.parse   s   9\ccdhildmnooggmT255^eefqrss wwy$':LSSTXY]T^_`` 	bAyy !V!]!]^_!`aa	b &U99PWWX]^__((9d+?KLL=CW^^_cdk_lmnn HH%8$?$UVV!"c)T[[\`ar\stv v&,,->?W^^_pqs s#$5ab$9:HH[$/	MNN	?c!Y``aefoapqrr88J-LMM>S X__`dem`nopp&,,X6dkkltuvv8AB<(88J-LMM>S X__`dem`noppx=B[bbcklmm8$88J-LMM>S X__`dem`noppxx%<HII:T[[\`ae\fghh'K\hq19HW_fjl
r6   filenamec                    | j                   | j                  d      | j                  xs g g}t        |d      5 }t	        j
                  |      }|j                  |       ddd       t        |      S # 1 sw Y   t              S xY w)z
        Save certificate to file. File format (serialized as CBOR):

            [cert_hash: bytes, cert_eip712: Dict[str, Any], cert_signatures: List[bytes]]

        :param filename:
        :return:
        TrV   wbN)r?   rQ   r>   opencbor2dumpswriterg   )rD   rk   cert_objfr3   s        r4   savezEIP712DelegateCertificate.saveo  su     IIt||4|8$//:ORP(D! 	Q;;x(DGGDM	 4y	 4ys   'A44Bc                 h   t         j                  j                  |       st        dj	                  |             t        | d      5 }t        j                  |j                               \  }}}t        j                  |d      }||j                  k(  sJ ||_        |cd d d        S # 1 sw Y   y xY w)NzFcannot create EIP712DelegateCertificate from filename "{}": not a filerbTrV   )ospathisfileRuntimeErrorrd   rn   ro   loadsreadr(   rj   r?   r>   )rk   rs   	cert_hashcert_eip712cert_signaturescerts         r4   loadzEIP712DelegateCertificate.load~  s    ww~~h'gnnowxyy(D! 	Q6;kk!&&(6K3I{O,22;t2LD		)))-DO	 	 	s   AB((B1rA   )F)r   r(   )__name__
__module____qualname__	__slots__r1   bytesr2   r   r   rC   r   boolrJ   rM   rR   r   r   r   r   rQ   staticmethodrj   rt   r   __classcell__)rF   s   @r4   r(   r(      s   I  PT. . .# .Y^ .jo ..&).7?U7L."C D 2&C &D &. .: :T :e :> >5 >d tCH~  L L\S S   r6   r(   )%rw   rO   typingr   r   r   r   binasciir   r   rZ   ro   py_eth_sig_utils.eip712r	   autobahn.wamp.messager
   autobahn.xbr._secmodr   _eip712_baser   r   r   r   r   r   r   r   _eip712_certificater   r1   r   r2   rb   r5   r9   r<   r(    r6   r4   <module>r      sO  6 
  , , %   5 9 ,2 2 2 2V V:?V25V 27V 27	V
 25V .1V 6:Vr#% #.1#8=# 14# 05	#
 05# 03# ,/# 49#8$ $;@$36$ 38$ 38	$
 36$ /2$ 49$ >C$8I 1 Ir6   