
    E#ii                    
   S SK Jr  S SKrS SKJr  S SKJrJr  S SKJ	r	J
r
  S SKJrJr  S SKJrJrJrJrJr  S SKJrJr  S S	KJrJrJrJrJrJrJrJrJ r J!r!  \(       a  S S
K"J#r#J$r$   " S S5      r% " S S5      r& " S S5      r'g)    )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                  (   \ rS rSrS\4SS jjr\\4SS jjrSSS jjr	\\4SS jjr
SS jrSSS jjrSSS	 jjrSS
 jrSS jrSS jrSS jr\\4S S jj5       r\\4S!S jj5       r\\4S"S jj5       r\\4S#S jj5       rS rS$S jrSS jrSrg)%
PrivateKey   Nc                   Ub  [        U5      O	[        5       U l        X l        [        R                  U R                  U R                  5      U l        [        R                  U R                  U R                  5      U l        g)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   secretcontext	PublicKeyfrom_valid_secret
public_keyPublicKeyXOnlypublic_key_xonly)selfr"   r#   s      H/home/james-whalen/.local/lib/python3.13/site-packages/coincurve/keys.py__init__PrivateKey.__init__   s_     9?8J_V4P`Pb%.%@%@dll%[0>0P0PQUQ\Q\^b^j^j0k    c                H   Ub  U" U5      OUn[        U5      S:w  a  Sn[        U5      e[        R                  " S5      nUu  px[        R
                  " U R                  R                  XdU R                  Xx5      n	U	(       d  Sn[        U5      e[        X`R                  5      $ )a  
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.
    #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)   messagehashercustom_noncemsg_hashmsg	signaturenonce_fn
nonce_datasigneds
             r*   signPrivateKey.sign+   s    & '-&86'?gx=B7CS/!GG9:	+))$,,*:*:IQUQ\Q\^fsYCS/!I||44r-   c                8   [        U5      S:w  a  Sn[        U5      eUS:X  a  [        R                  " S5      nO0Uc  [        R
                  nO[        U5      S:w  a  Sn[        U5      e[        R                  " S5      n[        R                  " U R                  R                  X@R                  5      nU(       d  Sn[        U5      e[        R                  " S5      n[        R                  " U R                  R                  XaXB5      nU(       d  Sn[        U5      e[        R                  " U R                  R                  Xa[        U5      U R                  R                  5      nU(       d  S	n[        U5      e[!        [        R"                  " U5      5      $ )
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.
r/   zMessage must be 32 bytes long.r-   z,Auxiliary random data must be 32 bytes long.secp256k1_keypair *Secret was invalidzunsigned char[64]zSigning failedzInvalid signature)r2   r3   osurandomr   NULLr4   r   secp256k1_keypair_creater#   r6   r"   secp256k1_schnorrsig_sign32secp256k1_schnorrsig_verifyr(   r&   bytesbuffer)r)   r8   aux_randomnessr<   keypairresr=   s          r*   sign_schnorrPrivateKey.sign_schnorrN   s;     w<22CS/!S ZZ^N# XXN B&@CS/!''/0**4<<+;+;WkkR&CS/!GG/0	--dll.>.>	T[l"CS/!--LLi#g,@U@U@`@`
 %CS/!SZZ	*++r-   c                H   Ub  U" U5      OUn[        U5      S:w  a  Sn[        U5      e[        R                  " S5      nUu  px[        R
                  " U R                  R                  XdU R                  Xx5      n	U	(       d  Sn[        U5      e[        X`R                  5      $ )a  
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.
r/   r0   z'secp256k1_ecdsa_recoverable_signature *r1   )
r2   r3   r   r4   r    secp256k1_ecdsa_sign_recoverabler#   r6   r"   r   r7   s
             r*   sign_recoverablePrivateKey.sign_recoverable~   s    & '-&86'?gx=B7CS/!GGEF	+55LLi4;;
 YCS/!$Y==r-   c                >   [         R                  " S5      n[        R                  " U R                  R
                  U[        U5      R                  U R                  [         R                  [         R                  5        [        [         R                  " US5      5      $ )ai  
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]r/   )r   r4   r   secp256k1_ecdhr#   r6   r$   r&   r"   rH   rL   rM   )r)   r&   r"   s      r*   ecdhPrivateKey.ecdh   sk    " -.4<<++VYz5J5U5UW[WbWbdgdldlnqnvnvwSZZ+,,r-   c                   [        U5      n[        R                  " SU R                  5      n[        R
                  " U R                  R                  X15      nU(       d  Sn[        U5      e[        [        R                  " US5      5      nU(       a  X0l        U R                  5         U $ [        X0R                  5      $ )aI  
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.
rX   zDThe tweak was out of range, or the resulting private key is invalid.r/   )r   r   r4   r"   r   secp256k1_ec_seckey_tweak_addr#   r6   r3   rL   rM   _update_public_keyr   )r)   scalarupdater"   successr<   s         r*   addPrivateKey.add   s     F#-t{{;33DLL4D4DfUXCS/!szz&"-. K##%K&,,//r-   c                X   [        U5      n[        R                  " SU R                  5      n[        R
                  " U R                  R                  X15        [        [        R                  " US5      5      nU(       a  X0l        U R                  5         U $ [        X0R                  5      $ )z
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`.
rX   r/   )r   r   r4   r"   r   secp256k1_ec_seckey_tweak_mulr#   r6   rL   rM   r^   r   )r)   r_   r`   r"   s       r*   multiplyPrivateKey.multiply   sz     !(-t{{;))$,,*:*:FKszz&"-. K##%K&,,//r-   c                6    U R                   R                  5       $ )z2
Returns the private key encoded as a hex string.
)r"   hexr)   s    r*   to_hexPrivateKey.to_hex   s     {{  r-   c                ,    [        U R                  5      $ )z(
Returns the private key as an integer.
)r   r"   rj   s    r*   to_intPrivateKey.to_int   s     DKK((r-   c                4    [        U R                  5       5      $ )z0
Returns the private key encoded in PEM format.
)r   to_derrj   s    r*   to_pemPrivateKey.to_pem  s     $++-((r-   c                \    [        U R                  U R                  R                  SS95      $ )z0
Returns the private key encoded in DER format.
F
compressed)r
   r"   r&   formatrj   s    r*   rq   PrivateKey.to_der  s'     $++t'='='='OPPr-   c                ,    [        [        U5      U5      $ )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   )clshexedr#   s      r*   from_hexPrivateKey.from_hex  s     ,u-w77r-   c                ,    [        [        U5      U5      $ )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   )rz   numr#   s      r*   from_intPrivateKey.from_int  s     -c2G<<r-   c                >    [        [        [        U5      5      U5      $ )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   )rz   pemr#   s      r*   from_pemPrivateKey.from_pem)  s     *Z_5w??r-   c                ,    [        [        U5      U5      $ )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	   )rz   derr#   s      r*   from_derPrivateKey.from_der7  s     *S/733r-   c                    [         R                  " U R                  R                  U R                  R                  U R
                  5      nU(       d  Sn[        U5      eg )NInvalid secret.)r   secp256k1_ec_pubkey_creater#   r6   r&   r"   r3   )r)   createdr<   s      r*   r^   PrivateKey._update_public_keyE  sH    001A1A4??C]C]_c_j_jk#CS/! r-   c                4    U R                   UR                   :H  $ N)r"   r)   others     r*   __eq__PrivateKey.__eq__L  s    {{ell**r-   c                ,    [        U R                  5      $ r   )hashr"   rj   s    r*   __hash__PrivateKey.__hash__O  s    DKK  r-   )r#   r&   r(   r"   )r"   zbytes | Noner#   r   )r8   rL   r9   r   r:   r   returnrL   )r-   )r8   rL   rN   rL   r   rL   )r&   rL   r   rL   F)r_   rL   r`   boolr   r   )r   strr   intr   rL   )r{   r   r#   r   r   r   )r   r   r#   r   r   r   )r   rL   r#   r   r   r   )r   rL   r#   r   r   r   r   r   )__name__
__module____qualname____firstlineno__r   r+   r   r   rA   rQ   rU   rZ   rb   rf   rk   rn   rr   rq   classmethodr|   r   r   r   r^   r   r   __static_attributes__ r-   r*   r   r      s    .2~ l 5;R_ !5F.,` AG^k #>J-.0B04!))Q 5C 8 8 3A = = 5C @ @ 5C 4 4"+!r-   r   c                      \ rS rSr\4SS jjr\\4SS jj5       r\\4SS jj5       r\\4SS jj5       r	\\
\4         SS jj5       r\\4SS jj5       rSSS jjrSS	 jr\
4SS
 jjrSSS jjrSSS jjrSSS jjrSS jrSS jrSrg) r$   iS  c                    [        U[        5      (       d  Xl        O[[        R                  " S5      n[
        R                  " UR                  X1[        U5      5      nU(       d  Sn[        U5      eX0l        X l
        g)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)
isinstancerL   r&   r   r4   r   secp256k1_ec_pubkey_parser6   r2   r3   r#   )r)   datar#   r&   parsedr<   s         r*   r+   PublicKey.__init__T  s`     $&&"O!56J227;;
RUVZR[\FI o%(Or-   c                    [         R                  " S5      n[        R                  " UR                  U[        U5      5      nU(       d  Sn[        U5      e[        X25      $ )z
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   r4   r   r   r6   r   r3   r$   rz   r"   r#   r&   r   r<   s         r*   from_secretPublicKey.from_secretq  sU     WW12
00j/Z`Jab? 
 S/!--r-   c                    [         R                  " S5      n[        R                  " UR                  X15      nU(       d  Sn[        U5      e[        X25      $ )z
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   r4   r   r   r6   r3   r$   r   s         r*   r%   PublicKey.from_valid_secret  sF     WW12
00jQ#CS/!--r-   c                J    [        S[        U5      -   [        U5      -   U5      $ )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   )rz   xyr#   s       r*   
from_pointPublicKey.from_point  s)     #6q#99<OPQ<RRT[\\r-   c           
     8    [        [        U[        XS9X4S95      $ )aB  
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#   )r9   r#   )r$   r   r   )rz   r=   r8   r9   r#   s        r*   from_signature_and_message$PublicKey.from_signature_and_message  s$    * G4YPY_q
 	
r-   c                    [         R                  " S5      n[        R                  " UR                  X1 Vs/ s H  oDR
                  PM     sn[        U5      5      nU(       d  Sn[        U5      e[        X25      $ s  snf )z
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   &The sum of the public keys is invalid.)	r   r4   r   secp256k1_ec_pubkey_combiner6   r&   r2   r3   r$   )rz   public_keysr#   r&   pkcombinedr<   s          r*   combine_keysPublicKey.combine_keys  sl     WW12
22KKk%Jkmmk%JCP[L\
 :CS/!-- &Ks   A;c                F   U(       a  SOSn[         R                  " SU-  5      n[         R                  " SU5      n[        R                  " U R                  R
                  X4U R                  U(       a  [        O[        5        [        [         R                  " X25      5      $ )z
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   r4   r   secp256k1_ec_pubkey_serializer#   r6   r&   r   r   rL   rM   )r)   rv   length
serialized
output_lens        r*   rw   PublicKey.format  sr     "rWW1F:;
WWZ0
))LLjdooXb}hw	
 SZZ
344r-   c                X    U R                  SS9n[        USS 5      [        USS 5      4$ )z/
Returns the public key as a coordinate point.
Fru      r   N)rw   r   )r)   r&   s     r*   pointPublicKey.point  s6     [[E[2
Jq,-|JrsO/LLLr-   c                    Ub  U" U5      OUn[        U5      S:w  a  Sn[        U5      e[        R                  " U R                  R
                  [        U5      X@R                  5      nU(       $ )a  
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.
r/   r0   )r2   r3   r   secp256k1_ecdsa_verifyr#   r6   r   r&   )r)   r=   r8   r9   r;   r<   verifieds          r*   verifyPublicKey.verify  sc    " '-&86'?gx=B7CS/!--dll.>.>Y@WYacrcrs  <r-   c                &   [        U5      n[        R                  " SU R                  S   5      n[        R
                  " U R                  R                  X15      nU(       d  Sn[        U5      eU(       a  X0l        U $ [        X0R                  5      $ )aD  
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   r4   r&   r   secp256k1_ec_pubkey_tweak_addr#   r6   r3   r$   )r)   r_   r`   new_keyra   r<   s         r*   rb   PublicKey.add!  sr     F#''.0BC33DLL4D4DgVWCS/!%OK,,//r-   c                    [        U5      n[        R                  " SU R                  S   5      n[        R
                  " U R                  R                  X15        U(       a  X0l        U $ [        X0R                  5      $ )z
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   r4   r&   r   secp256k1_ec_pubkey_tweak_mulr#   r6   r$   )r)   r_   r`   r   s       r*   rf   PublicKey.multiply?  s^     !(''.0BC))$,,*:*:GL%OK,,//r-   c                R   [         R                  " S5      n[        R                  " U R                  R
                  X0/UQ Vs/ s H  oDR                  PM     sn[        U5      S-   5      nU(       d  Sn[        U5      eU(       a  X0l        U $ [        X0R                  5      $ s  snf )a5  
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   r   r   )
r   r4   r   r   r#   r6   r&   r2   r3   r$   )r)   r   r`   r   r   r   r<   s          r*   combinePublicKey.combineV  s     ''./22LLg@T@T'U@T"@T'UWZ[fWgjkWk
 :CS/!%OK,,// (Vs   B$c                @    U R                  SS9UR                  SS9:H  $ NFru   )rw   r   s     r*   r   PublicKey.__eq__t  s#    {{e{,0NNNr-   c                2    [        U R                  SS95      $ r   r   rw   rj   s    r*   r   PublicKey.__hash__w  s    DKK5K122r-   )r#   r&   N)r   bytes | ffi.CDatar#   r   )r"   rL   r#   r   r   r$   )r   r   r   r   r#   r   r   r$   )
r=   rL   r8   rL   r9   r   r#   r   r   r$   )r   list[PublicKey]r#   r   r   r$   )T)rv   r   r   rL   )r   ztuple[int, int])r=   rL   r8   rL   r9   r   r   r   r   )r_   rL   r`   r   r   r$   )r   r   r`   r   r   r$   r   r   )r   r   r   r   r   r+   r   r   r%   r   r   r   r   rw   r   r   rb   rf   r   r   r   r   r   r-   r*   r$   r$   S  s    CQ : ;I . .8 AO . .0 ;I ] ] @F[i

(-
7=
QX
	
 
0 KY . .45*M IO  60<0.0<O3r-   r$   c                      \ rS rSrS\4SS jjr\\4SS jj5       r\\4SS jj5       rSS jr	SS jr
SS jrSS	 jrSS
 jrSrg)r'   i{  Fc                    [        U[        5      (       d  Xl        OQ[        R                  " S5      n[
        R                  " UR                  XA5      nU(       d  Sn[        U5      eX@l        X l	        X0l
        g)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   rL   r&   r   r4   r   secp256k1_xonly_pubkey_parser6   r3   parityr#   )r)   r   r   r#   r&   r   r<   s          r*   r+   PublicKeyXOnly.__init__|  s\     $&&"O!;<J55gkk:TFI o%(Or-   c                d   [         R                  " S5      n[        R                  " UR                  U[        U5      5      nU(       d  Sn[        U5      e[         R                  " S5      n[         R                  " S5      n[        R                  " UR                  XgU5      nU " XgS   (       US9$ )z
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.
rD   rE   r   int *r   r   r#   )r   r4   r   rI   r6   r   r3   secp256k1_keypair_xonly_pubrz   r"   r#   rO   rP   r<   xonly_pubkey	pk_paritys           r*   r   PublicKeyXOnly.from_secret  s     ''/0**7;;QWAXY&CS/!ww9:GGG$	--gkk<T[\<!,<gNNr-   c                P   [         R                  " S5      n[        R                  " UR                  X15      nU(       d  Sn[        U5      e[         R                  " S5      n[         R                  " S5      n[        R                  " UR                  XgU5      nU " XgS   (       US9$ )a  
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.
rD   rE   r   r   r   r   )r   r4   r   rI   r6   r3   r   r   s           r*   r%    PublicKeyXOnly.from_valid_secret  s     ''/0**7;;H&CS/!ww9:GGG$	--gkk<T[\<!,<gNNr-   c                    [         R                  " S5      n[        R                  " U R                  R
                  XR                  5      nU(       d  Sn[        U5      e[        [         R                  " US5      5      $ )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.
rX   z+Public key in self.public_key must be validr/   )
r   r4   r    secp256k1_xonly_pubkey_serializer#   r6   r&   r3   rL   rM   )r)   output32rP   r<   s       r*   rw   PublicKeyXOnly.format  s[     77/0224<<3C3CX_?CS/!SZZ"-..r-   c                    [        U5      S:w  a  Sn[        U5      e[        R                  " U R                  R
                  X[        U5      U R                  5      (       $ )a'  
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.)r2   r3   r   rK   r#   r6   r&   )r)   r=   r8   r<   s       r*   r   PublicKeyXOnly.verify  sR     y>R4CS/!66LLi#g,
 
 	
r-   c                   [        U5      n[        R                  " S5      n[        R                  " U R
                  R                  X R                  U5      nU(       d  Sn[        U5      e[        R                  " S5      n[        R                  " U R
                  R                  U R                  XR5        US   (       U l
        g)z
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   r4   r    secp256k1_xonly_pubkey_tweak_addr#   r6   r&   r3   "secp256k1_xonly_pubkey_from_pubkeyr   )r)   r_   
out_pubkeyrP   r<   r   s         r*   	tweak_addPublicKeyXOnly.tweak_add  s     F#WW12
224<<3C3CZQ`Q`bhi\CS/!GGG$	..t||/?/?R[h'l*r-   c                    [         R                  " U R                  R                  U R                  UR                  5      nUS:H  $ )Nr   )r   secp256k1_xonly_pubkey_cmpr#   r6   r&   )r)   r   rP   s      r*   r   PublicKeyXOnly.__eq__  s4    ,,T\\-=-=tPUP`P`aaxr-   c                4    [        U R                  5       5      $ r   r   rj   s    r*   r   PublicKeyXOnly.__hash__  s    DKKM""r-   )r#   r   r&   N)r   r   r   r   r#   r   )r"   rL   r#   r   r   r'   r   )r=   rL   r8   rL   r   r   )r_   rL   r   Noner   r   )r   r   r   r   r   r+   r   r   r%   rw   r   r  r   r   r   r   r-   r*   r'   r'   {  sX    ?DYg 4 ;I O O4 AO O O4/&
,+2#r-   r'   )(
__future__r   rF   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 0 o o :   -t! t!n	e3 e3P	X# X#r-   