
    afxK                     F   d dl Zd dlZd dlmZ d dlmZmZ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 dd	lm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defdZ!d
e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)a2b_hex)DictAnyOptionalList)encode_typed_data)_URI_PAT_REALM_NAME_ETH)EthereumKey   )signrecoveris_chain_id
is_addressis_block_numberis_signatureis_eth_privkey)EIP712CertificatechainIdverifyingContract	validFromissuersubjectrealmcapabilitiesmetareturnc                    t          |           sJ t          |          sJ t          |          sJ t          |          sJ t          |          sJ t          |          sJ t          |          t          k    rd|cxk    rdk    sn 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dddgddddd| |||||||pddd}|S )z
    Authority certificate: long-lived, on-chain L2.

    :param chainId:
    :param verifyingContract:
    :param validFrom:
    :param issuer:
    :param subject:
    :param realm:
    :param capabilities:
    :param meta:
    :return:
    r   l          Nnamestring)r   typeversionr   uint256r   addressr   r   r   r   r   uint64r   )EIP712DomainEIP712AuthorityCertificater&   WMP1)r   r!    r   r   r   r   r   r   r   r   )typesprimaryTypedomainmessage)r   r   r   r    intstr)	r   r   r   r   r   r   r   r   datas	            \/var/www/html/env/lib/python3.11/site-packages/autobahn/xbr/_eip712_authority_certificate.py#create_eip712_authority_certificater3   +   s   * w'(((((9%%%%%fge$$l)E)E)E)Eg)E)E)E)E)EE<4::,,,, #$ 
 &$ 	 &% 
 0% 
 (% 
 %% 
 &% 
 $% 
 +$ 
 #$ ;!+-
 -
\ 4
 

 !2"(JB	
 	
i> >D@ K    eth_privkeyc	           
      p    t          |           sJ t          ||||||||          }	t          | |	          S )a,  
    Sign the given data using a EIP712 based signature with the provided private key.

    :param eth_privkey:
    :param chainId:
    :param verifyingContract:
    :param validFrom:
    :param issuer:
    :param subject:
    :param realm:
    :param capabilities:
    :param meta:
    :return:
    )r   r3   r   )
r5   r   r   r   r   r   r   r   r   r1   s
             r2   !sign_eip712_authority_certificater7      sL    . +&&&&&.w8I9V\/6|TS SDT"""r4   	signaturec	           
      p    t          |          sJ t          | |||||||          }	t          |	|          S )a\  
    Recover the signer address the given EIP712 signature was signed with.

    :param chainId:
    :param verifyingContract:
    :param validFrom:
    :param issuer:
    :param subject:
    :param realm:
    :param capabilities:
    :param meta:
    :param signature:
    :return: The (computed) signer address the signature was signed with.
    )r   r3   r   )
r   r   r   r   r   r   r   r   r8   r1   s
             r2   $recover_eip712_authority_certificater:      sL    . 	""""".w8I9V\/6|TS SD4###r4   c                   :    e Zd ZdZdZdZdZdZdZdZ		 d#d	e
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edd fd            Zd ede
fd!Zed%d"            Z xZS )&r&   r                   )
r   r   r   r   r   r   r   r   
signatureshashNr   r   r   r   r   r   r   r   rA   c
           
          t                                          |||           || _        || _        || _        || _        || _        |	| _        t          ||||||||          }
t          |
          | _
        d S N)super__init__r   r   r   r   r   rA   r3   r   rB   )selfr   r   r   r   r   r   r   r   rA   eip712	__class__s              r2   rF   z#EIP712AuthorityCertificate.__init__   s     	"3Y???
(	$4W5F5>5;5<5:5A59; ; &f--			r4   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 |j        | j        k    rdS dS )NFT)
isinstancerI   r&   __eq__r   r   r   r   r   r   r   r   rA   rB   rG   rJ   s     r2   rM   z!EIP712AuthorityCertificate.__eq__   s
   %00 	5)00u== 	5=DL((5"d&<<<5?dn,,5<4;&&5=DL((5;$*$$5!2225:""5t..5:""5tr4   c                 .    |                      |           S rD   )rM   rN   s     r2   __ne__z!EIP712AuthorityCertificate.__ne__  s    ;;u%%%%r4   c                 N    t          j        |                                           S rD   )pprintpformatmarshal)rG   s    r2   __str__z"EIP712AuthorityCertificate.__str__  s    ~dllnn---r4   Fkeybinaryc           
          t          | j        | j        | j        | j        | j        | j        | j        | j                  }|	                    ||          S )NrW   )
r3   r   r   r   r   r   r   r   r   sign_typed_data)rG   rV   rW   rH   s       r2   r   zEIP712AuthorityCertificate.sign  sW    4T\595K59^59[59\59Z595F59Y@ @ ""6&"999r4   r8   c                     t          | j        | j        | j        | j        | j        | j        | j        | j        |	  	        S rD   )	r:   r   r   r   r   r   r   r   r   )rG   r8   s     r2   r   z"EIP712AuthorityCertificate.recover   s@    3DL484J48N48K48L48J484E48I4=? ? 	?r4   c           
         t          | j        | 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          j
                            |d         d                   nd |d         d<   |d         d         r+t          j
                            |d         d                   nd |d         d<   |S )Nr*   r.   r   r   r   r   )r3   r   r   r   r   r   r   r   r   web3Web3toChecksumAddress)rG   rW   objs      r2   rT   z"EIP712AuthorityCertificate.marshal+  su   1$,DHDZ<@N9=:>,8<
?C?P7;yB B B  	@vy  {D  wE  FY  wZ  3d$)2M2McR[n]pNq2r2r2r  `dC	N./`cdm`now`x  (Cty'B'B3y>RZC['\'\'\  CC	N8$befobpqzb{  )F	(C(CC	NS\D](^(^(^  BFC	N9%^abk^lmt^u&di&A&A#i.QXBY&Z&Z&Z{C	N7#
r4   c           
      v   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          |rt          |          t          k    r/t          d                    t          |                              t          |          dk    r/t          d                    t          |                              nt          |          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          |rt          |	          t          k    r/t          d                    t          |	                              t          |	          dk    r/t          d                    t          |	                              nt          |	          t          k    r/t          d                    t          |	                              t          j
        |	          s"t          d                    |	                    t          |	dd                    }	|                    dd           }
|
t          d          |rt          |
          t          k    r/t          d                    t          |
                              t          |
          dk    r/t          d                    t          |
                              nt          |
          t          k    r/t          d                    t          |
                              t          j
        |
          s"t          d                     |
                    t          |
dd                    }
|                    d!d           }|t          d"          |rt          |          t          k    r/t          d#                    t          |                              t          |          dk    r/t          d$                    t          |                              nt          |          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          ||||	|
|||,          } | S )-Nz>invalid type {} for object in EIP712AuthorityCertificate.parser,   r&   z@invalid primaryType "{}" - expected "EIP712AuthorityCertificate"r.   z.invalid type {} for EIP712AuthorityCertificate)	r    r   r   r   r   r   r   r   r   z4invalid attribute "{}" in EIP712AuthorityCertificater    z2unexpected type "{}" in EIP712AuthorityCertificater   z-missing chainId in EIP712AuthorityCertificatez9invalid type {} for chainId in EIP712AuthorityCertificater   z7missing verifyingContract in EIP712AuthorityCertificatezCinvalid type {} for verifyingContract in EIP712AuthorityCertificate   z,invalid value length {} of verifyingContractzFinvalid value "{}" for verifyingContract in EIP712AuthorityCertificater<   r   z/missing validFrom in EIP712AuthorityCertificatez;invalid type {} for validFrom in EIP712AuthorityCertificater   z,missing issuer in EIP712AuthorityCertificatez8invalid type {} for issuer in EIP712AuthorityCertificatez!invalid value length {} of issuerz;invalid value "{}" for issuer in EIP712AuthorityCertificater   z-missing subject in EIP712AuthorityCertificatez9invalid type {} for subject in EIP712AuthorityCertificatez<invalid value "{}" for subject in EIP712AuthorityCertificater   z+missing realm in EIP712AuthorityCertificatez7invalid type {} for realm in EIP712AuthorityCertificatez invalid value length {} of realmz:invalid value "{}" for realm in EIP712AuthorityCertificater   z2missing capabilities in EIP712AuthorityCertificatez>invalid type {} for capabilities in EIP712AuthorityCertificater   z*missing meta in EIP712AuthorityCertificatez6invalid type {} for meta in EIP712AuthorityCertificater*   )r    dict
ValueErrorformatgetr/   byteslenr0   r	   matchr   r&   )r`   rW   r,   r1   k_typer   r   r   r   r   r   r   r   s                 r2   parsez EIP712AuthorityCertificate.parse;  s   99]ddeijmenenoopppggmT22666_ffgrssttt wwy$''::MTTUYZ^U_U_``aaa 	c 	cA : : : !W!^!^_`!a!abbb: && 	aU:::QXXY^__```((9d++?LMMM==CX__`del`m`mnnooo HH%8$??$VWWW 	?%&&%// Y``aefwaxaxyy{ { {$%%++ !O!V!VWZ[lWmWm!n!nooo , %&&#-- Y``aefwaxaxyy{ { {*01BCC x \ccduvvx x x '(9!""(= > >HH[$//	NOOO	??c!!Zaabfgpbqbqrrsss(D))>KLLL 	)F||u$$ NUUVZ[aVbVbcce e e6{{b   !D!K!KCPVKK!X!XYYY ! F||s"" ![!b!bcghncoco!p!pqqq*088 o !^!e!efl!m!mnnnVABBZ((F((9d++?LMMM 	+G}}%% OVVW[\cWdWdeeg g g7||r!! !O!V!VWZ[bWcWc!d!deee " G}}## !\!c!cdhipdqdq!r!rsss*099 q !_!f!fgn!o!opppgabbk**G$''=JKKK 	'E{{e## MTTUYZ_U`U`aac c c5zzR !C!J!J3u::!V!VWWW   E{{c!! !Z!a!abfglbmbm!n!nooo*077 m !]!d!dej!k!klllE!""I&&Exx55QRRR$$]ddeijvewewxxyyyxx%%<IJJJ::U\\]abf]g]ghhiii(L]ir06ucovz| | |
r4   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:
        TrY   wbN)rB   rT   rA   opencbor2dumpswriterh   )rG   rm   cert_objfr1   s        r2   savezEIP712AuthorityCertificate.save  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 )zX
        Load certificate from file.

        :param filename:
        :return:
        zGcannot create EIP712AuthorityCertificate from filename "{}": not a filerbTrY   N)ospathisfileRuntimeErrorre   rp   rq   loadsreadr&   rl   rB   rA   )rm   ru   	cert_hashcert_eip712cert_signaturescerts         r2   loadzEIP712AuthorityCertificate.load  s     w~~h'' 	{hoopxyyzzz(D!! 	Q6;k!&&((6K6K3I{O-33K3MMD	))))-DO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AB;;B?B?rD   )F)r   r&   )__name__
__module____qualname__CAPABILITY_ROOT_CACAPABILITY_INTERMEDIATE_CACAPABILITY_PUBLIC_RELAYCAPABILITY_PRIVATE_RELAYCAPABILITY_PROVIDERCAPABILITY_CONSUMER	__slots__r/   rg   r0   r   r   rF   r   boolrM   rP   rU   r
   r   r   r   rT   staticmethodrl   rv   r   __classcell__)rI   s   @r2   r&   r&      s       !" I$ 6:. . . .# .W\ .gl ..-0.8;.%d5k2. . . . . .(C D    6&C &D & & & &. . . . .	: 	: 	:T 	:e 	: 	: 	: 	:	? 	?5 	? 	? 	? 	? d tCH~      r r4 r,H r r r \rhS S        \    r4   r&   )$os.pathry   rR   binasciir   typingr   r   r   r   r]   rq   py_eth_sig_utils.eip712r   autobahn.wamp.messager	   autobahn.xbr._secmodr
   _eip712_baser   r   r   r   r   r   r   _eip712_certificater   r/   rg   r0   rc   r3   r7   r:   r&    r4   r2   <module>r      sv  4         , , , , , , , , , , , ,   5 5 5 5 5 5 9 9 9 9 9 9 , , , , , , o o o o o o o o o o o o o o o o o o 2 2 2 2 2 2^ ^;@^36^ 16^ 27	^
 05^ 7:^ /2^ 7;^ ^ ^ ^B#5 #/2#9># 25# /4	#
 05# .3# 58# -0# 5:# # # #<$# $<A$47$ 27$ 38	$
 16$ 8;$ 03$ 5:$ ?D$ $ $ $<F F F F F!2 F F F F Fr4   