]>
Commit | Line | Data |
---|---|---|
47e6618e JN |
1 | #ifndef SECP256K1_EXTRAKEYS_H |
2 | #define SECP256K1_EXTRAKEYS_H | |
3 | ||
4 | #include "secp256k1.h" | |
5 | ||
6 | #ifdef __cplusplus | |
7 | extern "C" { | |
8 | #endif | |
9 | ||
4cd2ee47 JN |
10 | /** Opaque data structure that holds a parsed and valid "x-only" public key. |
11 | * An x-only pubkey encodes a point whose Y coordinate is even. It is | |
12 | * serialized using only its X coordinate (32 bytes). See BIP-340 for more | |
13 | * information about x-only pubkeys. | |
14 | * | |
15 | * The exact representation of data inside is implementation defined and not | |
16 | * guaranteed to be portable between different platforms or versions. It is | |
17 | * however guaranteed to be 64 bytes in size, and can be safely copied/moved. | |
18 | * If you need to convert to a format suitable for storage, transmission, or | |
19 | * comparison, use secp256k1_xonly_pubkey_serialize and | |
20 | * secp256k1_xonly_pubkey_parse. | |
21 | */ | |
22 | typedef struct { | |
23 | unsigned char data[64]; | |
24 | } secp256k1_xonly_pubkey; | |
25 | ||
26 | /** Parse a 32-byte sequence into a xonly_pubkey object. | |
27 | * | |
28 | * Returns: 1 if the public key was fully valid. | |
29 | * 0 if the public key could not be parsed or is invalid. | |
30 | * | |
31 | * Args: ctx: a secp256k1 context object (cannot be NULL). | |
32 | * Out: pubkey: pointer to a pubkey object. If 1 is returned, it is set to a | |
33 | * parsed version of input. If not, it's set to an invalid value. | |
34 | * (cannot be NULL). | |
35 | * In: input32: pointer to a serialized xonly_pubkey (cannot be NULL) | |
36 | */ | |
37 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_parse( | |
38 | const secp256k1_context* ctx, | |
39 | secp256k1_xonly_pubkey* pubkey, | |
40 | const unsigned char *input32 | |
41 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); | |
42 | ||
43 | /** Serialize an xonly_pubkey object into a 32-byte sequence. | |
44 | * | |
45 | * Returns: 1 always. | |
46 | * | |
47 | * Args: ctx: a secp256k1 context object (cannot be NULL). | |
48 | * Out: output32: a pointer to a 32-byte array to place the serialized key in | |
49 | * (cannot be NULL). | |
50 | * In: pubkey: a pointer to a secp256k1_xonly_pubkey containing an | |
51 | * initialized public key (cannot be NULL). | |
52 | */ | |
53 | SECP256K1_API int secp256k1_xonly_pubkey_serialize( | |
54 | const secp256k1_context* ctx, | |
55 | unsigned char *output32, | |
56 | const secp256k1_xonly_pubkey* pubkey | |
57 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); | |
58 | ||
59 | /** Converts a secp256k1_pubkey into a secp256k1_xonly_pubkey. | |
60 | * | |
61 | * Returns: 1 if the public key was successfully converted | |
62 | * 0 otherwise | |
63 | * | |
64 | * Args: ctx: pointer to a context object (cannot be NULL) | |
65 | * Out: xonly_pubkey: pointer to an x-only public key object for placing the | |
66 | * converted public key (cannot be NULL) | |
67 | * pk_parity: pointer to an integer that will be set to 1 if the point | |
68 | * encoded by xonly_pubkey is the negation of the pubkey and | |
69 | * set to 0 otherwise. (can be NULL) | |
70 | * In: pubkey: pointer to a public key that is converted (cannot be NULL) | |
71 | */ | |
72 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_from_pubkey( | |
73 | const secp256k1_context* ctx, | |
74 | secp256k1_xonly_pubkey *xonly_pubkey, | |
75 | int *pk_parity, | |
76 | const secp256k1_pubkey *pubkey | |
77 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4); | |
78 | ||
47e6618e JN |
79 | #ifdef __cplusplus |
80 | } | |
81 | #endif | |
82 | ||
83 | #endif /* SECP256K1_EXTRAKEYS_H */ |