o
    "“iK  ã                   @   sV   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	Z	d dl
Z
G dd„ dƒZdS )é    )Úserialization)Údefault_backend)ÚSHA256)ÚECDSAÚEllipticCurvePrivateKeyNc                
   @   s\   e Zd ZU eed< eed< eed< dededefdd„Zd	ed
ededej	de
f
dd„ZdS )Ú PromotionalOfferSignatureCreatorÚ_signing_keyÚ_key_idÚ
_bundle_idÚsigning_keyÚkey_idÚ	bundle_idc                 C   s$   t j|d tƒ d�| _|| _|| _d S )N)ÚpasswordÚbackend)r   Úload_pem_private_keyr   r   r	   r
   )Úselfr   r   r   © r   úg/var/www/html/premium_crap/venv/lib/python3.10/site-packages/appstoreserverlibrary/promotional_offer.pyÚ__init__   s   
z)PromotionalOfferSignatureCreator.__init__Úproduct_identifierÚsubscription_offer_idÚapplication_usernameÚnonceÚ	timestampc                 C   sn   | j d | j d | d | d | ¡  d t|ƒ ¡  d t|ƒ }t | j | d¡t	t
ƒ ƒ¡¡ d¡S )a  
        Return the Base64 encoded signature

        https://developer.apple.com/documentation/storekit/in-app_purchase/original_api_for_in-app_purchase/subscriptions_and_offers/generating_a_signature_for_promotional_offers

        :param product_identifier: The subscription product identifier
        :param subscription_offer_id: The subscription discount identifier
        :param application_username: An optional string value that you define; may be an empty string
        :param nonce: A one-time UUID value that your server generates. Generate a new nonce for every signature.
        :param timestamp: A timestamp your server generates in UNIX time format, in milliseconds. The timestamp keeps the offer active for 24 hours.
        :return: The Base64 encoded signature
        u   â�£zutf-8)r
   r	   ÚlowerÚstrÚbase64Ú	b64encoder   ÚsignÚencoder   r   Údecode)r   r   r   r   r   r   Úpayloadr   r   r   Úcreate_signature   s8   ÿÿþþýýüü
ûûú
ÿþz1PromotionalOfferSignatureCreator.create_signatureN)Ú__name__Ú
__module__Ú__qualname__r   Ú__annotations__r   Úbytesr   ÚuuidÚUUIDÚintr"   r   r   r   r   r      s   
 $r   )Úcryptography.hazmat.primitivesr   Úcryptography.hazmat.backendsr   Ú%cryptography.hazmat.primitives.hashesr   Ú,cryptography.hazmat.primitives.asymmetric.ecr   r   r(   r   r   r   r   r   r   Ú<module>   s   