|
| 1 | +#ifndef LIBWALLY_CORE_DESCRIPTOR_H |
| 2 | +#define LIBWALLY_CORE_DESCRIPTOR_H |
| 3 | + |
| 4 | +#include "wally_core.h" |
| 5 | + |
| 6 | +#ifdef __cplusplus |
| 7 | +extern "C" { |
| 8 | +#endif |
| 9 | + |
| 10 | +struct wally_map; |
| 11 | + |
| 12 | +/* Miniscript type flag */ |
| 13 | +#define WALLY_MINISCRIPT_WITNESS_SCRIPT 0x00 /** Witness script */ |
| 14 | +#define WALLY_MINISCRIPT_TAPSCRIPT 0x01 /** Tapscript */ |
| 15 | + |
| 16 | +/** |
| 17 | + * Canonicalize a descriptor. |
| 18 | + * |
| 19 | + * :param descriptor: Output descriptor. |
| 20 | + * :param vars_in: Map of variable names to values, or NULL. |
| 21 | + * :param flags: For future use. Must be 0. |
| 22 | + * :param output: Destination for the resulting canonical descriptor. |
| 23 | + *| The string returned should be freed using `wally_free_string`. |
| 24 | + * |
| 25 | + * Replaces any variables from ``vars_in`` with their mapped values, |
| 26 | + * and adds a checksum if required. Key names for ``vars_in`` must be 16 |
| 27 | + * characters or less and start with a letter. |
| 28 | + * |
| 29 | + * .. note:: Other canonicalization (hardened derivation indicator |
| 30 | + * mapping, and private to public key mapping) is not yet implemented. |
| 31 | + */ |
| 32 | +WALLY_CORE_API int wally_descriptor_canonicalize( |
| 33 | + const char *descriptor, |
| 34 | + const struct wally_map *vars_in, |
| 35 | + uint32_t flags, |
| 36 | + char **output); |
| 37 | + |
| 38 | +/** |
| 39 | + * Get the length of a script corresponding to a miniscript string. |
| 40 | + * |
| 41 | + * :param miniscript: Miniscript string. |
| 42 | + * :param vars_in: Map of variable names to values, or NULL. |
| 43 | + * :param child_num: The BIP32 child number to derive. |
| 44 | + * :param flags: Flags controlling the type of script to create. Use one of |
| 45 | + *| ``WALLY_MINISCRIPT_WITNESS_SCRIPT`` or ``WALLY_MINISCRIPT_TAPSCRIPT``. |
| 46 | + * :param written: Destination for the resulting script length. |
| 47 | + * |
| 48 | + * .. note:: Computing this length is expensive. Prefer to pass a large |
| 49 | + *| buffer to `wally_miniscript_to_script` and retry only if the |
| 50 | + *| buffer is too small. |
| 51 | + */ |
| 52 | +WALLY_CORE_API int wally_miniscript_to_script_len( |
| 53 | + const char *miniscript, |
| 54 | + const struct wally_map *vars_in, |
| 55 | + uint32_t child_num, |
| 56 | + uint32_t flags, |
| 57 | + size_t *written); |
| 58 | + |
| 59 | +/** |
| 60 | + * Create a script corresponding to a miniscript string. |
| 61 | + * |
| 62 | + * :param miniscript: Miniscript string. |
| 63 | + * :param vars_in: Map of variable names to values, or NULL. |
| 64 | + * :param child_num: The BIP32 child number to derive. |
| 65 | + * :param flags: Flags controlling the type of script to create. Use one of |
| 66 | + *| ``WALLY_MINISCRIPT_WITNESS_SCRIPT`` or ``WALLY_MINISCRIPT_TAPSCRIPT``. |
| 67 | + * :param bytes_out: Destination for the resulting scriptPubKey. |
| 68 | + * :param len: The length of ``bytes_out`` in bytes. |
| 69 | + * :param written: Destination for the number of bytes written to ``bytes_out``. |
| 70 | + */ |
| 71 | +WALLY_CORE_API int wally_miniscript_to_script( |
| 72 | + const char *miniscript, |
| 73 | + const struct wally_map *vars_in, |
| 74 | + uint32_t child_num, |
| 75 | + uint32_t flags, |
| 76 | + unsigned char *bytes_out, |
| 77 | + size_t len, |
| 78 | + size_t *written); |
| 79 | + |
| 80 | +/** |
| 81 | + * Get the length of a scriptPubKey corresponding to an output descriptor. |
| 82 | + * |
| 83 | + * :param descriptor: Output descriptor. |
| 84 | + * :param vars_in: Map of variable names to values, or NULL. |
| 85 | + * :param child_num: The BIP32 child number to derive. |
| 86 | + * :param network: ``WALLY_NETWORK_`` constant descripting the network to generate for. |
| 87 | + * :param depth: Number of the descriptor depth. Default is 0. |
| 88 | + * :param index: Number of the descriptor index. Default is 0. |
| 89 | + * :param flags: For future use. Must be 0. |
| 90 | + * :param written: Destination for the resulting scriptPubKey length. |
| 91 | + * |
| 92 | + * .. note:: Computing this length is expensive. Prefer to pass a large |
| 93 | + *| buffer to `wally_descriptor_to_scriptpubkey` and retry only if the |
| 94 | + *| buffer is too small. |
| 95 | + */ |
| 96 | +WALLY_CORE_API int wally_descriptor_to_scriptpubkey_len( |
| 97 | + const char *descriptor, |
| 98 | + const struct wally_map *vars_in, |
| 99 | + uint32_t child_num, |
| 100 | + uint32_t network, |
| 101 | + uint32_t depth, |
| 102 | + uint32_t index, |
| 103 | + uint32_t flags, |
| 104 | + size_t *written); |
| 105 | + |
| 106 | +/** |
| 107 | + * Create a scriptPubKey corresponding to an output descriptor. |
| 108 | + * |
| 109 | + * :param descriptor: Output descriptor. |
| 110 | + * :param vars_in: Map of variable names to values, or NULL. |
| 111 | + * :param child_num: The BIP32 child number to derive. |
| 112 | + * :param network: ``WALLY_NETWORK_`` constant descripting the network to generate for. |
| 113 | + * :param depth: Number of the descriptor depth. Default is 0. |
| 114 | + * :param index: Number of the descriptor index. Default is 0. |
| 115 | + * :param flags: For future use. Must be 0. |
| 116 | + * :param bytes_out: Destination for the resulting scriptPubKey. |
| 117 | + * :param len: The length of ``bytes_out`` in bytes. |
| 118 | + * :param written: Destination for the number of bytes written to ``bytes_out``. |
| 119 | + */ |
| 120 | +WALLY_CORE_API int wally_descriptor_to_scriptpubkey( |
| 121 | + const char *descriptor, |
| 122 | + const struct wally_map *vars_in, |
| 123 | + uint32_t child_num, |
| 124 | + uint32_t network, |
| 125 | + uint32_t depth, |
| 126 | + uint32_t index, |
| 127 | + uint32_t flags, |
| 128 | + unsigned char *bytes_out, |
| 129 | + size_t len, |
| 130 | + size_t *written); |
| 131 | + |
| 132 | +/** |
| 133 | + * Create an address corresponding to an output descriptor. |
| 134 | + * |
| 135 | + * :param descriptor: Output descriptor. |
| 136 | + * :param vars_in: Map of variable names to values, or NULL. |
| 137 | + * :param child_num: The BIP32 child number to derive. |
| 138 | + * :param network: ``WALLY_NETWORK_`` constant descripting the network to generate for. |
| 139 | + * :param flags: For future use. Must be 0. |
| 140 | + * :param output: Destination for the resulting addresss. |
| 141 | + *| The string returned should be freed using `wally_free_string`. |
| 142 | + */ |
| 143 | +WALLY_CORE_API int wally_descriptor_to_address( |
| 144 | + const char *descriptor, |
| 145 | + const struct wally_map *vars_in, |
| 146 | + uint32_t child_num, |
| 147 | + uint32_t network, |
| 148 | + uint32_t flags, |
| 149 | + char **output); |
| 150 | + |
| 151 | +/** |
| 152 | + * Create addresses that correspond to the derived range of an output descriptor. |
| 153 | + * |
| 154 | + * :param descriptor: Output descriptor. |
| 155 | + * :param vars_in: Map of variable names to values, or NULL. |
| 156 | + * :param child_num: The first BIP32 child number to derive. |
| 157 | + * :param network: ``WALLY_NETWORK_`` constant descripting the network to generate for. |
| 158 | + * :param flags: For future use. Must be 0. |
| 159 | + * :param output: Destination for the resulting addresses. |
| 160 | + * :param num_outputs: The number of items in ``output``. Addresses will be |
| 161 | + *| generated into this array starting from child_num, incrementing by 1. |
| 162 | + *| The addresses returned should be freed using `wally_free_string`. |
| 163 | + */ |
| 164 | +WALLY_CORE_API int wally_descriptor_to_addresses( |
| 165 | + const char *descriptor, |
| 166 | + const struct wally_map *vars_in, |
| 167 | + uint32_t child_num, |
| 168 | + uint32_t network, |
| 169 | + uint32_t flags, |
| 170 | + char **output, |
| 171 | + size_t num_outputs); |
| 172 | + |
| 173 | +/** |
| 174 | + * Create an output descriptor checksum. |
| 175 | + * |
| 176 | + * :param descriptor: Output descriptor. |
| 177 | + * :param vars_in: Map of variable names to values, or NULL. |
| 178 | + * :param flags: For future use. Must be 0. |
| 179 | + * :param output: Destination for the resulting descriptor checksum. |
| 180 | + *| The string returned should be freed using `wally_free_string`. |
| 181 | + */ |
| 182 | +WALLY_CORE_API int wally_descriptor_get_checksum( |
| 183 | + const char *descriptor, |
| 184 | + const struct wally_map *vars_in, |
| 185 | + uint32_t flags, |
| 186 | + char **output); |
| 187 | + |
| 188 | +#ifdef __cplusplus |
| 189 | +} |
| 190 | +#endif |
| 191 | + |
| 192 | +#endif /* LIBWALLY_CORE_DESCRIPTOR_H */ |
0 commit comments