
    tf>                     B   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$dS )    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                    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| ||||||p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:
    N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           h/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/autobahn/xbr/_eip712_delegate_certificate.py"create_eip712_delegate_certificater5   -   s   & w'(((((9%%%%%h!!!!!>>S    <4::,,,, #$ 
 &$ 	 &% 
 0% 
 (% 
 '% 
 '% 
 '$ 
 #$ 3*)
 )
T 3
 

 !2"   JB
 
a9 9Dv K    eth_privkeyc           	      n    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      sJ    * +&&&&&-g7H)U].6$H HDT"""r6   	signaturec           	      n    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<      sJ    * 	"""""-g7H)U].6$H 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hashNr   r   r   r   r   r   r   r>   c	           	          t                                          |||           || _        || _        || _        || _        || _        t          |||||||          }	t          |	          | _	        d S 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__   s{    "3Y???   	$3G4E4=4<4<4<48: : &f--			r6   otherr   c                    t          || j                  sdS t                              | |          sdS |j        | j        k    rdS |j        | j        k    rdS |j        | j        k    rdS |j        | j        k    rdS |j        | j        k    rdS |j	        | j	        k    rdS |j
        | j
        k    rdS |j        | j        k    rdS |j        | j        k    rdS dS )NFT)
isinstancerF   r(   __eq__r   r   r   r   r   r   r   r>   r?   rD   rG   s     r4   rJ   z EIP712DelegateCertificate.__eq__   s    %00 	5(//e<< 	5=DL((5"d&<<<5?dn,,5>T]**5>T]**5>T]**5:""5t..5:""5tr6   c                 .    |                      |           S rA   )rJ   rK   s     r4   __ne__z EIP712DelegateCertificate.__ne__   s    ;;u%%%%r6   c                 N    t          j        |                                           S rA   )pprintpformatmarshal)rD   s    r4   __str__z!EIP712DelegateCertificate.__str__   s    ~dllnn---r6   Fkeybinaryc           	          t          | 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   sO    3DL484J48N48M48M48M48I? ? ""6&"999r6   r:   c           
      t    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  s:    24<373I37>37=37=37=3793<> > 	>r6   c           	         t          | j        | j        | j        | j        | j        | j        | j                  }|s|d         d         r+t          j	        
                    |d         d                   nd |d         d<   |d         d         r+t          j	        
                    |d         d                   nd |d         d<   |d         d         r-t          |d         d                                                   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CGCY;?>:>-:>-:>-6:iA A A  	~vy  {D  wE  FY  wZ  3d$)2M2McR[n]pNq2r2r2r  `dC	N./dghqdrs}d~  *I)D)DS^T^E_)`)`)`  EIC	N:&Y\]fYghrYs)}Y
1K)L)L)S)S)U)U)Uy}C	N:&
r6   c           	      
   t          |           t          k    r/t          d                    t          |                               |                     dd           }|dk    r"t          d                    |                    |                     dd           }t          |          t          k    r/t          d                    t          |                              |D ](}|dvr"t          d                    |                    )|                    d	d           }|r(|dk    r"t          d
                    |                    |                    dd           }|t          d          t          |          t
          k    r/t          d                    t          |                              |                    dd           }|t          d          t          |          t          k    r/t          d                    t          |                              t          j        |          s"t          d                    |                    t          |dd                    }|                    dd           }|t          d          t          |          t
          k    r/t          d                    t          |                              |                    dd           }|t          d          t          |          t          k    r/t          d                    t          |                              t          j        |          s"t          d                    |                    t          |dd                    }|                    dd           }	|	t          d          t          |	          t          k    r/t          d                    t          |	                              t          |	          dk    r"t          d                    |	                    t          |	          }	|                    dd           }
|
t          d          t          |
          t
          k    r/t          d                     t          |
                              |                    d!d           }|t          d"          t          |          t          k    r/t          d#                    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   99\ccdhildmdmnnoooggmT22555^eefqrrsss wwy$''::LSSTXY]T^T^__``` 	b 	bAyyy !V!]!]^_!`!`aaa z && 	`U999PWWX]^^___((9d++?KLLL==CW^^_cdk_l_lmmnnn HH%8$??$UVVV!""c))T[[\`ar\s\sttv v v&,->?? 	sW^^_pqqs s s#$5abb$9::HH[$//	MNNN	??c!!Y``aefoapapqqrrr88J--LMMM>>S  X__`dem`n`nooppp&,X66 	wdkkltuuvvv8ABB<((88J--LMMM>>S  X__`dem`n`noopppx==B[bbckllmmm8$$88J--LMMM>>S  X__`dem`n`noopppxx%%<HIII::T[[\`ae\f\fgghhh'K\hq19HW_fjl l l
r6   filenamec                    | j         |                     d          | j        pg g}t          |d          5 }t	          j        |          }|                    |           ddd           n# 1 swxY w Y   t          |          S )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  s     It||4|88$/:ORP(D!! 	Q;x((DGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 4yys   *A,,A03A0c                    t           j                            |           s"t          d                    |                     t          | d          5 }t          j        |                                          \  }}}t          
                    |d          }||j        k    sJ ||_        |cd d d            S # 1 swxY w Y   d S )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    w~~h'' 	zgnnowxxyyy(D!! 	Q6;k!&&((6K6K3I{O,22;t2LLD	))))-DO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AB;;B?B?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 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      s  6 
			  , , , , , , , , , , , , % % % % % % % %   5 5 5 5 5 5 9 9 9 9 9 9 , , , , , ,2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2V V:?V25V 27V 27	V
 25V .1V 6:V V V Vr#% #.1#8=# 14# 05	#
 05# 03# ,/# 49# # # #8$ $;@$36$ 38$ 38	$
 36$ /2$ 49$ >C$ $ $ $8I I I I I 1 I I I I Ir6   