Ë
    ²Œj¡  ã                   ó  — 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	m
Z
mZ erd dlZ G d„ de«      Z G d„ de«      Z G d	„ d
e«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de
«      Zy)é    N)Úsha256)ÚTYPE_CHECKINGÚDictÚOptionalÚoverload)Ú	NamespaceÚResourcec                   ó   — e Zd ZU dZeed<   y)ÚWebhookSigningSecretz#
    A webhook signing secret.
    ÚkeyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__© ó    ú[/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/replicate/webhook.pyr   r      s   … ñð 
„Hr   r   c                   ó   — e Zd ZdZy)ÚWebhookValidationErrorz-Base exception for webhook validation errors.N©r   r   r   r   r   r   r   r   r      s   „ Ú7r   r   c                   ó   — e Zd ZdZy)ÚMissingWebhookHeaderErrorz;Exception raised when a required webhook header is missing.Nr   r   r   r   r   r      s   „ ÚEr   r   c                   ó   — e Zd ZdZy)ÚInvalidSecretKeyErrorz7Exception raised when the secret key format is invalid.Nr   r   r   r   r   r   !   ó   „ ÚAr   r   c                   ó   — e Zd ZdZy)ÚMissingWebhookBodyErrorz2Exception raised when the webhook body is missing.Nr   r   r   r   r   r   %   s   „ Ú<r   r   c                   ó   — e Zd ZdZy)ÚInvalidTimestampErrorzPException raised when the webhook timestamp is invalid or outside the tolerance.Nr   r   r   r   r!   r!   )   s   „ ÚZr   r!   c                   ó   — e Zd ZdZy)ÚInvalidSignatureErrorz7Exception raised when the webhook signature is invalid.Nr   r   r   r   r#   r#   -   r   r   r#   c                   ó  — e Zd ZdZedd„«       Z G d„ de«      Zee		 dddd	e
d
ee   defd„«       «       Zee		 ddeeef   ded	e
d
ee   def
d„«       «       Ze		 	 	 	 	 dded   deeeef      dee   d	ee
   d
ee   ddfd„«       Zy)ÚWebhooksz7
    Namespace for operations related to webhooks.
    Úreturnc                 ó8   — | j                  | j                  «      S )úJ
        Namespace for operations related to the default webhook.
        )ÚDefaultÚ_client)Úselfs    r   ÚdefaultzWebhooks.default6   s   € ð �|‰|˜DŸL™LÓ)Ð)r   c                   ó(   — e Zd ZdZdefd„Zdefd„Zy)úWebhooks.Defaultr(   r&   c                 ól   — | j                   j                  dd«      }t        di |j                  «       ¤ŽS )ú¡
            Get the default webhook signing secret.

            Returns:
                WebhookSigningSecret: The default webhook signing secret.
            ÚGETú/v1/webhooks/default/secretr   )r*   Ú_requestr   Újson©r+   Úresps     r   ÚsecretzWebhooks.Default.secretC   s/   € ð —<‘<×(Ñ(¨Ð0MÓNˆDÜ'Ñ6¨$¯)©)«+Ñ6Ð6r   c              ƒ   óˆ   K  — | j                   j                  dd«      ƒ d{  –—† }t        di |j                  «       ¤ŽS 7 Œ­w)r0   r1   r2   Nr   )r*   Ú_async_requestr   r4   r5   s     r   Úasync_secretzWebhooks.Default.async_secretN   sB   è ø€ ð Ÿ™×4Ñ4ØÐ4ó÷ ˆDô (Ñ6¨$¯)©)«+Ñ6Ð6ðús   ‚ A¢A £AN)r   r   r   r   r   r7   r:   r   r   r   r)   zWebhooks.Default>   s!   „ ñ	ð		7Ð0ó 		7ð	7Ð(<ô 	7r   r)   NÚrequestzhttpx.Requestr7   Ú	tolerancec                  ó   — y ©Nr   )r;   r7   r<   s      r   ÚvalidatezWebhooks.validate[   s   € ð r   ÚheadersÚbodyc                  ó   — y r>   r   )r@   rA   r7   r<   s       r   r?   zWebhooks.validatec   s   € ð r   c                 ót  — |st        d«      ‚| rt        ||g«      rt        d«      ‚| ry| j                  rm| j                  j                  d«      }| j                  j                  d«      }| j                  j                  d«      }| j                  j                  d«      }nq|st        d«      ‚|j                  «       D ��	ci c]  \  }}	|j                  «       |	“Œ }}}	|j                  d«      }|j                  d«      }|j                  d«      }|st        d«      ‚|st        d	«      ‚|st        d
«      ‚|st        d«      ‚|�Jddl
}
t        |
j                  «       «      }t        |«      }t        ||z
  «      }||kD  rt        d|› d�«      ‚|› d|› d|› �}|j                  j                  d«      }t!        |«      dk7  rt#        d|j                  › �«      ‚t%        j&                  |d   «      }t)        j*                  ||j-                  «       t.        «      }|j1                  «       }d}|j                  «       D ]a  }|j                  d«      }t!        |«      dk  rt3        d|› �«      ‚t%        j&                  |d   «      }t)        j4                  ||«      sŒ_d} n |st3        d«      ‚yc c}	}w )a´  
        Validate the signature from an incoming webhook request using the provided secret.

        Args:
            request (httpx.Request): The request object.
            headers (Dict[str, str]): The request headers.
            body (str): The request body.
            secret (WebhookSigningSecret): The webhook signing secret.
            tolerance (Optional[int]): Maximum allowed time difference (in seconds) between the current time and the webhook timestamp.

        Returns:
            None: If the request is valid.

        Raises:
            MissingWebhookHeaderError: If required webhook headers are missing.
            InvalidSecretKeyError: If the secret key format is invalid.
            MissingWebhookBodyError: If the webhook body is missing.
            InvalidTimestampError: If the webhook timestamp is invalid or outside the tolerance.
            InvalidSignatureError: If the webhook signature is invalid.
        zMissing webhook signing secretz3Only one of request or headers/body can be providedz
webhook-idzwebhook-timestampzwebhook-signaturezutf-8zMissing webhook headerszMissing webhook idzMissing webhook timestampzMissing webhook signaturezMissing webhook bodyNr   z6Webhook timestamp is outside the allowed tolerance of z secondsÚ.Ú_é   zInvalid secret key format: é   FÚ,zInvalid signature format: TzWebhook signature is invalid)Ú
ValueErrorÚanyr@   ÚgetÚcontentÚdecoder   ÚitemsÚlowerr   ÚtimeÚintÚabsr!   r   ÚsplitÚlenr   Úbase64Ú	b64decodeÚhmacÚnewÚencoder   Údigestr#   Úcompare_digest)r;   r@   rA   r7   r<   Ú
webhook_idÚ	timestampÚ	signatureÚkÚvrP   Úcurrent_timeÚwebhook_timeÚtime_differenceÚsigned_contentÚ	key_partsÚsecret_bytesÚhÚcomputed_signatureÚvalidÚsigÚ	sig_partsÚ	sig_bytess                          r   r?   zWebhooks.validatel   s’  € ñ: ÜÐ=Ó>Ð>á”s˜G T˜?Ô+ÜÐRÓSÐSá�w—’Ø Ÿ™×,Ñ,¨\Ó:ˆJØŸ™×+Ñ+Ð,?Ó@ˆIØŸ™×+Ñ+Ð,?Ó@ˆIØ—?‘?×)Ñ)¨'Ó2‰DáÜ/Ð0IÓJÐJð 18·±´Ô@±©¨¨1�q—w‘w“y !‘|°ˆGÑ@à Ÿ™ \Ó2ˆJØŸ™Ð$7Ó8ˆIØŸ™Ð$7Ó8ˆIáÜ+Ð,@ÓAÐAÙÜ+Ð,GÓHÐHÙÜ+Ð,GÓHÐHÙÜ)Ð*@ÓAÐAàÐ Ûä˜tŸy™y›{Ó+ˆLÜ˜y›>ˆLÜ! ,°Ñ"=Ó>ˆOØ Ò*Ü+ØLÈYÈKÐW_Ð`óð ð '˜< q¨¨°1°T°FÐ;ˆà—J‘J×$Ñ$ SÓ)ˆ	Üˆy‹>˜QÒÜ'Ð*EÀfÇjÁjÀ\Ð(RÓSÐSä×'Ñ'¨	°!©Ó5ˆä�H‰H�\ >×#8Ñ#8Ó#:¼FÓCˆØŸX™X›ZÐàˆØ—?‘?Ö$ˆCØŸ	™	 #›ˆIÜ�9‹~ Ò!Ü+Ð.HÈÈÐ,NÓOÐOä×(Ñ(¨°1©Ó6ˆIä×"Ñ" 9Ð.@ÕAØ�Ùð %ñ Ü'Ð(FÓGÐGð ùóc As   ÃJ4)r&   r.   r>   )NNNNN)r   r   r   r   Úpropertyr,   r   r)   r   Ústaticmethodr   r   rQ   Úboolr?   r   r   r   r   r   r%   r%   1   sV  „ ñð ò*ó ð*ô7�)ô 7ð: Øð $(ñØ ðà$ðð ˜C‘=ðð 
ò	ó ó ðð Øð
 $(ñ	Ø�c˜3�h‘ðàðð %ðð ˜C‘=ð	ð
 
òó ó ðð à-1Ø,0Ø"Ø15Ø#'ñ^HØ˜/Ñ*ð^Hà˜$˜s C˜x™.Ñ)ð^Hð �s‰mð^Hð Ð-Ñ.ð	^Hð
 ˜C‘=ð^Hð 
ò^Hó ñ^Hr   r%   )rU   rW   Úhashlibr   Útypingr   r   r   r   Úreplicate.resourcer   r	   Úhttpxr   rI   r   r   r   r   r!   r#   r%   r   r   r   Ú<module>rt      s”   ðÛ Û Ý ÷ó ÷ 3áÛô˜8ô ô8˜Zô 8ôFÐ 6ô FôBÐ2ô Bô=Ð4ô =ô[Ð2ô [ôBÐ2ô BôZHˆyõ ZHr   