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   