
    dii                       d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	m
Z
 d dlmZmZ d dlmZmZmZmZmZ d dlmZmZ d d	lmZmZmZmZmZmZmZmZm Z m!Z! erd d
l"m#Z#m$Z$  G d d          Z% G d d          Z& G d d          Z'dS )    )annotationsN)TYPE_CHECKING)ffilib)GLOBAL_CONTEXTContext)
decode_der
encode_der)cdata_to_derder_to_cdatadeserialize_recoverablerecoverserialize_recoverable)EC_COMPRESSEDEC_UNCOMPRESSED)
DEFAULT_NONCEbytes_to_int
der_to_pemget_valid_secrethex_to_bytesint_to_bytes_padded
pad_scalar
pem_to_dersha256validate_secret)HasherNoncec                     e Zd Zdefd,dZeefd-dZd.d/dZeefd-dZ	d0dZ
d1d2dZd1d2dZd3dZd4dZd5dZd5d Zeefd6d"            Zeefd7d$            Zeefd8d&            Zeefd9d(            Zd) Zd:d*Zd4d+ZdS );
PrivateKeyNsecretbytes | Nonecontextr   c                   |t          |          nt                      | _        || _        t                              | j        | j                  | _        t                              | j        | j                  | _        dS )z
        Initializes a private key.

        Parameters:
            secret: The secret used to initialize the private key.
                    If not provided, a new key will be generated.
            context: The context to use.
        N)	r   r   r    r"   	PublicKeyfrom_valid_secret
public_keyPublicKeyXOnlypublic_key_xonly)selfr    r"   s      L/var/www/html/volatility/venv/lib/python3.11/site-packages/coincurve/keys.py__init__zPrivateKey.__init__   sl     9?8J_V444P`PbPb%.%@%@dl%[%[0>0P0PQUQ\^b^j0k0k    messagebyteshasherr   custom_noncer   returnc                :   | ||          n|}t          |          dk    rd}t          |          t          j        d          }|\  }}t	          j        | j        j        ||| j        ||          }	|	sd}t          |          t          || j                  S )aZ  
        Creates an ECDSA signature.

        Parameters:
            message: The message to sign.
            hasher (collections.abc.Callable[[bytes], bytes] | None): The hash function to use, which must
                return 32 bytes. By default, the `sha256` algorithm is used. If `None`, no hashing occurs.
            custom_nonce (tuple[ffi.CData, ffi.CData]): Custom nonce data in the form `(nonce_function, input_data)`.
                For more information, refer to the `libsecp256k1` documentation
                [here](https://github.com/bitcoin-core/secp256k1/blob/v0.6.0/include/secp256k1.h#L637-L642).

        Returns:
            The ECDSA signature.

        Raises:
            ValueError: If the message hash was not 32 bytes long, the nonce generation
                        function failed, or the private key was invalid.
        N    #Message hash must be 32 bytes long.zsecp256k1_ecdsa_signature *EThe nonce generation function failed, or the private key was invalid.)
len
ValueErrorr   newr   secp256k1_ecdsa_signr"   ctxr    r   
r)   r-   r/   r0   msg_hashmsg	signaturenonce_fn
nonce_datasigneds
             r*   signzPrivateKey.sign+   s    & '-&866'???gx==B7CS//!G9::	+*)$,*:IxQUQ\^fhrss 	"YCS//!It|444r,   r,   aux_randomnessc                   t          |          dk    rd}t          |          |dk    rt          j        d          }n3|t          j        }n$t          |          dk    rd}t          |          t	          j        d          }t          j        | j	        j
        || j                  }|sd}t          |          t	          j        d          }t          j        | j	        j
        ||||          }|sd	}t          |          t          j        | j	        j
        ||t          |          | j        j                  }|sd
}t          |          t!          t	          j        |                    S )a  
        Creates a Schnorr signature.

        Parameters:
            message: The message to sign.
            aux_randomness: 32 bytes of fresh randomness, empty bytestring (auto-generated),
                or None (no randomness).

        Returns:
            The Schnorr signature.

        Raises:
            ValueError: If the message was not 32 bytes long, the optional auxiliary
                random data was not 32 bytes long, signing failed, or the signature was invalid.
        r3   zMessage must be 32 bytes long.r,   Nz,Auxiliary random data must be 32 bytes long.secp256k1_keypair *Secret was invalidzunsigned char[64]zSigning failedzInvalid signature)r6   r7   osurandomr   NULLr8   r   secp256k1_keypair_creater"   r:   r    secp256k1_schnorrsig_sign32secp256k1_schnorrsig_verifyr(   r&   r.   buffer)r)   r-   rC   r=   keypairresr>   s          r*   sign_schnorrzPrivateKey.sign_schnorrN   s`     w<<22CS//!S  Z^^NN# XNN  B&&@CS//!'/00*4<+;WdkRR 	"&CS//!G/00	-dl.>	7T[]kll 	""CS//!-Li#g,,@U@`
 
  	"%CS//!SZ	**+++r,   c                :   | ||          n|}t          |          dk    rd}t          |          t          j        d          }|\  }}t	          j        | j        j        ||| j        ||          }	|	sd}t          |          t          || j                  S )ai  
        Creates a recoverable ECDSA signature.

        Parameters:
            message: The message to sign.
            hasher (collections.abc.Callable[[bytes], bytes] | None): The hash function to use, which must
                return 32 bytes. By default, the `sha256` algorithm is used. If `None`, no hashing occurs.
            custom_nonce (tuple[ffi.CData, ffi.CData]): Custom nonce data in the form `(nonce_function, input_data)`.
                For more information, refer to the `libsecp256k1` documentation
                [here](https://github.com/bitcoin-core/secp256k1/blob/v0.6.0/include/secp256k1.h#L637-L642).

        Returns:
            The recoverable ECDSA signature.

        Raises:
            ValueError: If the message hash was not 32 bytes long, the nonce generation
                function failed, or the private key was invalid.
        Nr3   r4   z'secp256k1_ecdsa_recoverable_signature *r5   )
r6   r7   r   r8   r    secp256k1_ecdsa_sign_recoverabler"   r:   r    r   r;   s
             r*   sign_recoverablezPrivateKey.sign_recoverable~   s    & '-&866'???gx==B7CS//!GEFF	+*5Li4;*
 
  	"YCS//!$Y===r,   r&   c                
   t          j        d          }t          j        | j        j        |t          |          j        | j        t           j	        t           j	                   t          t          j        |d                    S )a  
        Computes an EC Diffie-Hellman secret in constant time.

        !!! note
            This prevents malleability by returning `sha256(compressed_public_key)` instead of the `x` coordinate
            directly.

        Parameters:
            public_key: The formatted public key.

        Returns:
            The 32-byte shared secret.

        Raises:
            ValueError: If the public key could not be parsed or was invalid.
        unsigned char [32]r3   )r   r8   r   secp256k1_ecdhr"   r:   r$   r&   r    rI   r.   rM   )r)   r&   r    s      r*   ecdhzPrivateKey.ecdh   se    " -..4<+VYz5J5J5UW[WbdgdlnqnvwwwSZ++,,,r,   Fscalarupdateboolc                f   t          |          }t          j        d| j                  }t	          j        | j        j        ||          }|sd}t          |          t          t          j
        |d                    }|r|| _        |                                  | S t          || j                  S )a  
        Adds a scalar to the private key.

        Parameters:
            scalar: The scalar with which to add.
            update: Whether to update the private key in-place.

        Returns:
            The new private key, or the modified private key if `update` is `True`.

        Raises:
            ValueError: If the tweak was out of range or the resulting private key was invalid.
        rU   zDThe tweak was out of range, or the resulting private key is invalid.r3   )r   r   r8   r    r   secp256k1_ec_seckey_tweak_addr"   r:   r7   r.   rM   _update_public_keyr   )r)   rX   rY   r    successr=   s         r*   addzPrivateKey.add   s     F##-t{;;3DL4DffUU 	"XCS//!sz&"--.. 	 DK##%%%K&$,///r,   c                @   t          |          }t          j        d| j                  }t	          j        | j        j        ||           t          t          j	        |d                    }|r|| _        | 
                                 | S t          || j                  S )a+  
        Multiplies the private key by a scalar.

        Parameters:
            scalar: The scalar with which to multiply.
            update: Whether to update the private key in-place.

        Returns:
            The new private key, or the modified private key if `update` is `True`.
        rU   r3   )r   r   r8   r    r   secp256k1_ec_seckey_tweak_mulr"   r:   r.   rM   r]   r   )r)   rX   rY   r    s       r*   multiplyzPrivateKey.multiply   s     !((-t{;;)$,*:FFKKKsz&"--.. 	 DK##%%%K&$,///r,   strc                4    | j                                         S )zB
        Returns the private key encoded as a hex string.
        )r    hexr)   s    r*   to_hexzPrivateKey.to_hex   s     {   r,   intc                *    t          | j                  S )z8
        Returns the private key as an integer.
        )r   r    rf   s    r*   to_intzPrivateKey.to_int   s     DK(((r,   c                D    t          |                                           S )z@
        Returns the private key encoded in PEM format.
        )r   to_derrf   s    r*   to_pemzPrivateKey.to_pem  s     $++--(((r,   c                ^    t          | j        | j                            d                    S )z@
        Returns the private key encoded in DER format.
        F
compressed)r
   r    r&   formatrf   s    r*   rl   zPrivateKey.to_der  s)     $+t'='='='O'OPPPr,   hexedc                <    t          t          |          |          S )z
        Creates a private key from a hex string.

        Parameters:
            hexed: The private key encoded as a hex string.
            context: The context to use.

        Returns:
            The private key.
        )r   r   )clsrr   r"   s      r*   from_hexzPrivateKey.from_hex  s     ,u--w777r,   numc                <    t          t          |          |          S )z
        Creates a private key from an integer.

        Parameters:
            num: The private key as an integer.
            context: The context to use.

        Returns:
            The private key.
        )r   r   )rt   rv   r"   s      r*   from_intzPrivateKey.from_int  s     -c22G<<<r,   pemc                V    t          t          t          |                    |          S )z
        Creates a private key from PEM format.

        Parameters:
            pem: The private key encoded in PEM format.
            context: The context to use.

        Returns:
            The private key.
        )r   r	   r   )rt   ry   r"   s      r*   from_pemzPrivateKey.from_pem)  s"     *Z__55w???r,   derc                <    t          t          |          |          S )z
        Creates a private key from DER format.

        Parameters:
            der: The private key encoded in DER format.
            context: The context to use.

        Returns:
            The private key.
        )r   r	   )rt   r|   r"   s      r*   from_derzPrivateKey.from_der7  s     *S//7333r,   c                    t          j        | j        j        | j        j        | j                  }|sd}t          |          d S )NInvalid secret.)r   secp256k1_ec_pubkey_creater"   r:   r&   r    r7   )r)   createdr=   s      r*   r]   zPrivateKey._update_public_keyE  sG    01A4?C]_c_jkk 	"#CS//!	" 	"r,   c                "    | j         |j         k    S N)r    r)   others     r*   __eq__zPrivateKey.__eq__L  s    {el**r,   c                *    t          | j                  S r   )hashr    rf   s    r*   __hash__zPrivateKey.__hash__O  s    DK   r,   )r    r!   r"   r   )r-   r.   r/   r   r0   r   r1   r.   )r,   )r-   r.   rC   r.   r1   r.   )r&   r.   r1   r.   F)rX   r.   rY   rZ   r1   r   )r1   rc   r1   rh   r1   r.   )rr   rc   r"   r   r1   r   )rv   rh   r"   r   r1   r   )ry   r.   r"   r   r1   r   )r|   r.   r"   r   r1   r   r1   rZ   )__name__
__module____qualname__r   r+   r   r   rB   rP   rS   rW   r_   rb   rg   rj   rm   rl   classmethodru   rx   r{   r~   r]   r   r    r,   r*   r   r      s       .2~ l l l l l 5;R_ !5 !5 !5 !5 !5F., ., ., ., .,` AG^k #> #> #> #> #>J- - - -.0 0 0 0 0B0 0 0 0 04! ! ! !) ) ) )) ) ) )Q Q Q Q 5C 8 8 8 8 [8 3A = = = = [= 5C @ @ @ @ [@ 5C 4 4 4 4 [4" " "+ + + +! ! ! ! ! !r,   r   c                      e Zd Zefd'dZeefd(d	            Zeefd(d
            Zeefd)d            Zee	efd*d            Z
eefd+d            Zd,d-dZd.dZe	fd/dZd0d1d!Zd0d1d"Zd0d2d#Zd3d$Zd4d%Zd&S )5r$   databytes | ffi.CDatar"   r   c                    t          |t                    s|| _        nWt          j        d          }t          j        |j        ||t          |                    }|sd}t          |          || _        || _
        dS )a  
        Initializes a public key.

        Parameters:
            data (bytes): The formatted public key. This class supports parsing
                compressed (33 bytes, header byte `0x02` or `0x03`),
                uncompressed (65 bytes, header byte `0x04`), or
                hybrid (65 bytes, header byte `0x06` or `0x07`) format public keys.
            context: The context to use.

        Raises:
            ValueError: If the public key could not be parsed or was invalid.
        secp256k1_pubkey *1The public key could not be parsed or is invalid.N)
isinstancer.   r&   r   r8   r   secp256k1_ec_pubkey_parser:   r6   r7   r"   )r)   r   r"   r&   parsedr=   s         r*   r+   zPublicKey.__init__T  s|     $&& 	)"DOO!566J27;
DRUVZR[R[\\F &I oo%(DOr,   r    r.   r1   c                    t          j        d          }t          j        |j        |t          |                    }|sd}t          |          t          ||          S )a!  
        Derives a public key from a private key secret.

        Parameters:
            secret: The private key secret.
            context: The context to use.

        Returns:
            The public key.

        Raises:
            ValueError: If an invalid secret was used.
        r   zuSomehow an invalid secret was used. Please submit this as an issue here: https://github.com/ofek/coincurve/issues/new)r   r8   r   r   r:   r   r7   r$   rt   r    r"   r&   r   r=   s         r*   from_secretzPublicKey.from_secretq  sc     W122
0j/Z`JaJabb 	"? 
 S//!W---r,   c                    t          j        d          }t          j        |j        ||          }|sd}t          |          t          ||          S )a:  
        Derives a public key from a valid private key secret, avoiding input checks.

        Parameters:
            secret: The private key secret.
            context: The context to use.

        Returns:
            The public key.

        Raises:
            ValueError: If the secret was invalid.
        r   r   )r   r8   r   r   r:   r7   r$   r   s         r*   r%   zPublicKey.from_valid_secret  sS     W122
0j&QQ 	"#CS//!W---r,   xrh   yc                b    t          dt          |          z   t          |          z   |          S )z
        Derives a public key from a coordinate point.

        Parameters:
            x: The x coordinate.
            y: The y coordinate.
            context: The context to use.

        Returns:
            The public key.
           )r$   r   )rt   r   r   r"   s       r*   
from_pointzPublicKey.from_point  s2     #6q#9#99<OPQ<R<RRT[\\\r,   r>   r-   r/   r   c           	     `    t          t          |t          ||          ||                    S )a  
        Recovers an ECDSA public key from a recoverable signature.

        Parameters:
            signature: The recoverable ECDSA signature.
            message: The message that was supposedly signed.
            hasher (collections.abc.Callable[[bytes], bytes] | None): The hash function to use, which must
                return 32 bytes. By default, the `sha256` algorithm is used. If `None`, no hashing occurs.
            context: The context to use.

        Returns:
            The public key that signed the message.

        Raises:
            ValueError: If the message hash was not 32 bytes long or recovery of the
                ECDSA public key failed.
        )r"   )r/   r"   )r$   r   r   )rt   r>   r-   r/   r"   s        r*   from_signature_and_messagez$PublicKey.from_signature_and_message  s:    * G4YPPPY_ipqqq
 
 	
r,   public_keyslist[PublicKey]c                    t          j        d          }t          j        |j        |d |D             t          |                    }|sd}t          |          t          ||          S )a5  
        Adds a number of public keys together.

        Parameters:
            public_keys: A sequence of public keys.
            context: The context to use.

        Returns:
            The combined public key.

        Raises:
            ValueError: If the sum of the public keys was invalid.
        r   c                    g | ]	}|j         
S r   r&   .0pks     r*   
<listcomp>z*PublicKey.combine_keys.<locals>.<listcomp>  s    %J%J%Jbm%J%J%Jr,   &The sum of the public keys is invalid.)r   r8   r   secp256k1_ec_pubkey_combiner:   r6   r7   r$   )rt   r   r"   r&   combinedr=   s         r*   combine_keyszPublicKey.combine_keys  st     W122
2K%J%Jk%J%J%JCP[L\L\
 
  	":CS//!W---r,   Trp   rZ   c                   |rdnd}t          j        d|z            }t          j        d|          }t          j        | j        j        ||| j        |rt          nt                     t          t          j
        ||                    S )a  
        Formats the public key.

        Parameters:
            compressed: Whether to use the compressed format.

        Returns:
            The 33 byte formatted public key, or the 65 byte formatted public key
            if `compressed` is `False`.
        !   A   zunsigned char [%d]zsize_t *)r   r8   r   secp256k1_ec_pubkey_serializer"   r:   r&   r   r   r.   rM   )r)   rp   length
serialized
output_lens        r*   rq   zPublicKey.format  s     ")rW1F:;;
WZ00
)Lj*doXbGw}}hw	
 	
 	
 SZ
F33444r,   tuple[int, int]c                    |                      d          }t          |dd                   t          |dd                   fS )z?
        Returns the public key as a coordinate point.
        Fro      r   N)rq   r   )r)   r&   s     r*   pointzPublicKey.point  sC     [[E[22
Jqt,--|JrssO/L/LLLr,   c                    | ||          n|}t          |          dk    rd}t          |          t          j        | j        j        t          |          || j                  }|  S )al  
        Verifies an ECDSA signature.

        Parameters:
            signature: The ECDSA signature.
            message: The message that was supposedly signed.
            hasher (collections.abc.Callable[[bytes], bytes] | None): The hash function to use, which must
                return 32 bytes. By default, the `sha256` algorithm is used. If `None`, no hashing occurs.

        Returns:
            A boolean indicating whether the signature is correct.

        Raises:
            ValueError: If the message hash was not 32 bytes long or the
                DER-encoded signature could not be parsed.
        Nr3   r4   )r6   r7   r   secp256k1_ecdsa_verifyr"   r:   r   r&   )r)   r>   r-   r/   r<   r=   verifieds          r*   verifyzPublicKey.verify  sq    " '-&866'???gx==B7CS//!-dl.>Y@W@WYacgcrss  <r,   FrX   rY   c                   t          |          }t          j        d| j        d                   }t	          j        | j        j        ||          }|sd}t          |          |r	|| _        | S t          || j                  S )a  
        Adds a scalar to the public key.

        Parameters:
            scalar: The scalar with which to add.
            update: Whether to update the public key in-place.

        Returns:
            The new public key, or the modified public key if `update` is `True`.

        Raises:
            ValueError: If the tweak was out of range or the resulting public key was invalid.
        r   r   zCThe tweak was out of range, or the resulting public key is invalid.)
r   r   r8   r&   r   secp256k1_ec_pubkey_tweak_addr"   r:   r7   r$   )r)   rX   rY   new_keyr^   r=   s         r*   r_   zPublicKey.add!  s     F##'.0BCC3DL4DgvVV 	"WCS//! 	%DOK$,///r,   c                    t          |          }t          j        d| j        d                   }t	          j        | j        j        ||           |r	|| _        | S t          || j                  S )a'  
        Multiplies the public key by a scalar.

        Parameters:
            scalar: The scalar with which to multiply.
            update: Whether to update the public key in-place.

        Returns:
            The new public key, or the modified public key if `update` is `True`.
        r   r   )	r   r   r8   r&   r   secp256k1_ec_pubkey_tweak_mulr"   r:   r$   )r)   rX   rY   r   s       r*   rb   zPublicKey.multiply?  sj     !(('.0BCC)$,*:GVLLL 	%DOK$,///r,   c                   t          j        d          }t          j        | j        j        |d | g|D             t          |          dz             }|sd}t          |          |r	|| _        | S t          || j                  S )a}  
        Adds a number of public keys together.

        Parameters:
            public_keys: A sequence of public keys.
            update: Whether to update the public key in-place.

        Returns:
            The combined public key, or the modified public key if `update` is `True`.

        Raises:
            ValueError: If the sum of the public keys was invalid.
        r   c                    g | ]	}|j         
S r   r   r   s     r*   r   z%PublicKey.combine.<locals>.<listcomp>g  s    'U'U'U"'U'U'Ur,   r   r   )
r   r8   r   r   r"   r:   r6   r7   r&   r$   )r)   r   rY   r   r   r=   s         r*   combinezPublicKey.combineV  s     './/2Lg'U'U@T@T'U'U'UWZ[fWgWgjkWk
 
  	":CS//! 	%DOK$,///r,   c                ^    |                      d          |                     d          k    S NFro   )rq   r   s     r*   r   zPublicKey.__eq__t  s)    {{e{,,0N0NNNr,   c                H    t          |                     d                    S r   r   rq   rf   s    r*   r   zPublicKey.__hash__w  s    DKK5K11222r,   N)r   r   r"   r   )r    r.   r"   r   r1   r$   )r   rh   r   rh   r"   r   r1   r$   )
r>   r.   r-   r.   r/   r   r"   r   r1   r$   )r   r   r"   r   r1   r$   )T)rp   rZ   r1   r.   )r1   r   )r>   r.   r-   r.   r/   r   r1   rZ   r   )rX   r.   rY   rZ   r1   r$   )r   r   rY   rZ   r1   r$   r   r   )r   r   r   r   r+   r   r   r%   r   r   r   r   rq   r   r   r_   rb   r   r   r   r   r,   r*   r$   r$   S  s       CQ     : ;I . . . . [.8 AO . . . . [.0 ;I ] ] ] ] [] @F[i
 
 
 
 [
0 KY . . . . [.45 5 5 5 5*M M M M IO          60 0 0 0 0<0 0 0 0 0.0 0 0 0 0<O O O O3 3 3 3 3 3r,   r$   c                  |    e Zd ZdefddZeefdd            Zeefdd            ZddZddZ	ddZ
ddZddZdS ) r'   Fr   r   parityrZ   r"   r   c                    t          |t                    s|| _        nIt          j        d          }t          j        |j        ||          }|sd}t          |          || _        || _	        || _
        dS )a\  
        Initializes a BIP340 `x-only` public key.

        Parameters:
            data (bytes): The formatted public key.
            parity: Whether the encoded point is the negation of the public key.
            context: The context to use.

        Raises:
            ValueError: If the public key could not be parsed or is invalid.
        secp256k1_xonly_pubkey *r   N)r   r.   r&   r   r8   r   secp256k1_xonly_pubkey_parser:   r7   r   r"   )r)   r   r   r"   r&   r   r=   s          r*   r+   zPublicKeyXOnly.__init__|  sw     $&& 		)"DOO!;<<J5gk:tTTF &I oo%(DOr,   r    r.   r1   c                T   t          j        d          }t          j        |j        |t          |                    }|sd}t          |          t          j        d          }t          j        d          }t          j        |j        |||          } | ||d           |          S )a,  
        Derives an x-only public key from a private key secret.

        Parameters:
            secret: The private key secret.
            context: The context to use.

        Returns:
            The x-only public key.

        Raises:
            ValueError: If the secret was invalid.
        rE   rF   r   int *r   r   r"   )r   r8   r   rJ   r:   r   r7   secp256k1_keypair_xonly_pubrt   r    r"   rN   rO   r=   xonly_pubkey	pk_paritys           r*   r   zPublicKeyXOnly.from_secret  s     '/00*7;QWAXAXYY 	"&CS//!w9::GG$$	-gk<T[\\s<	!,<(<gNNNNr,   c                :   t          j        d          }t          j        |j        ||          }|sd}t          |          t          j        d          }t          j        d          }t          j        |j        |||          } | ||d           |          S )aI  
        Derives an x-only public key from a valid private key secret, avoiding input checks.

        Parameters:
            secret: The private key secret.
            context: The context to use.

        Returns:
            The x-only public key.

        Raises:
            ValueError: If the secret was invalid.
        rE   rF   r   r   r   r   )r   r8   r   rJ   r:   r7   r   r   s           r*   r%   z PublicKeyXOnly.from_valid_secret  s     '/00*7;HH 	"&CS//!w9::GG$$	-gk<T[\\s<	!,<(<gNNNNr,   c                    t          j        d          }t          j        | j        j        || j                  }|sd}t          |          t          t          j	        |d                    S )z
        Serializes the public key.

        Returns:
            The public key serialized as 32 bytes.

        Raises:
            ValueError: If the public key in `self.public_key` is invalid.
        rU   z+Public key in self.public_key must be validr3   )
r   r8   r    secp256k1_xonly_pubkey_serializer"   r:   r&   r7   r.   rM   )r)   output32rO   r=   s       r*   rq   zPublicKeyXOnly.format  sb     7/0024<3CXt__ 	"?CS//!SZ"--...r,   r>   r-   c                    t          |          dk    rd}t          |          t          j        | j        j        ||t          |          | j                    S )ao  
        Verifies a Schnorr signature over a given message.

        Parameters:
            signature: The 64-byte Schnorr signature to verify.
            message: The message to be verified.

        Returns:
            A boolean indicating whether the signature is correct.

        Raises:
            ValueError: If the signature is not 64 bytes long.
        @   z Signature must be 64 bytes long.)r6   r7   r   rL   r"   r:   r&   )r)   r>   r-   r=   s       r*   r   zPublicKeyXOnly.verify  s]     y>>R4CS//!6Li#g,,
 
 
 
 	
r,   rX   Nonec                P   t          |          }t          j        d          }t          j        | j        j        || j        |          }|sd}t          |          t          j        d          }t          j	        | j        j        | j        ||           |d           | _
        dS )a%  
        Adds a scalar to the public key.

        Parameters:
            scalar: The scalar with which to add.

        Returns:
            The modified public key.

        Raises:
            ValueError: If the tweak was out of range or the resulting public key would be invalid.
        r   zHThe tweak was out of range, or the resulting public key would be invalidr   r   N)r   r   r8   r    secp256k1_xonly_pubkey_tweak_addr"   r:   r&   r7   "secp256k1_xonly_pubkey_from_pubkeyr   )r)   rX   
out_pubkeyrO   r=   r   s         r*   	tweak_addzPublicKeyXOnly.tweak_add  s     F##W122
24<3CZQUQ`bhii 	"\CS//!GG$$	.t|/?R[]ghhh'l**r,   c                b    t          j        | j        j        | j        |j                  }|dk    S )Nr   )r   secp256k1_xonly_pubkey_cmpr"   r:   r&   )r)   r   rO   s      r*   r   zPublicKeyXOnly.__eq__  s*    ,T\-=tPUP`aaaxr,   rh   c                D    t          |                                           S r   r   rf   s    r*   r   zPublicKeyXOnly.__hash__  s    DKKMM"""r,   N)r   r   r   rZ   r"   r   )r    r.   r"   r   r1   r'   r   )r>   r.   r-   r.   r1   rZ   )rX   r.   r1   r   r   r   )r   r   r   r   r+   r   r   r%   rq   r   r   r   r   r   r,   r*   r'   r'   {  s        ?DYg     4 ;I O O O O [O4 AO O O O O [O4/ / / /&
 
 
 
,+ + + +2   # # # # # #r,   r'   )(
__future__r   rG   typingr   coincurve._libsecp256k1r   r   coincurve.contextr   r   coincurve.derr	   r
   coincurve.ecdsar   r   r   r   r   coincurve.flagsr   r   coincurve.utilsr   r   r   r   r   r   r   r   r   r   coincurve.typesr   r   r   r$   r'   r   r,   r*   <module>r      s   " " " " " " 				             , , , , , , , , 5 5 5 5 5 5 5 5 0 0 0 0 0 0 0 0 o o o o o o o o o o o o o o : : : : : : : :                         .--------t! t! t! t! t! t! t! t!n	e3 e3 e3 e3 e3 e3 e3 e3P	X# X# X# X# X# X# X# X# X# X#r,   