This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcitadel.h
333 lines (247 loc) · 9.43 KB
/
citadel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#ifndef citadel_h
#define citadel_h
/* Generated with cbindgen:0.16.0 */
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define BECH32_OK 0
#define BECH32_ERR_HRP 1
#define BECH32_ERR_CHECKSUM 2
#define BECH32_ERR_ENCODING 3
#define BECH32_ERR_PAYLOAD 4
#define BECH32_ERR_UNSUPPORTED 5
#define BECH32_ERR_INTERNAL 6
#define BECH32_ERR_NULL 7
#define BECH32_UNKNOWN 0
#define BECH32_URL 1
#define BECH32_BC_ADDRESS 256
#define BECH32_LN_BOLT11 257
#define BECH32_LNPBP_ID 512
#define BECH32_LNPBP_DATA 513
#define BECH32_LNPBP_ZDATA 514
#define BECH32_LNPBP_INVOICE 528
#define BECH32_RGB_SCHEMA_ID 768
#define BECH32_RGB_CONTRACT_ID 769
#define BECH32_RGB_SCHEMA 784
#define BECH32_RGB_GENESIS 785
#define BECH32_RGB_CONSIGNMENT 800
#define BECH32_RGB20_ASSET 816
#define SUCCESS 0
#define ERRNO_IO 1
#define ERRNO_RPC 2
#define ERRNO_NET 3
#define ERRNO_TRANSPORT 4
#define ERRNO_NOTSUPPORTED 5
#define ERRNO_STORAGE 6
#define ERRNO_SERVERFAIL 7
#define ERRNO_EMBEDDEDFAIL 8
#define ERRNO_UNINIT 100
#define ERRNO_CHAIN 101
#define ERRNO_JSON 102
#define ERRNO_BECH32 103
#define ERRNO_PARSE 104
#define ERRNO_NULL 105
typedef enum bip39_mnemonic_type {
BIP39_MNEMONIC_TYPE_WORDS_12,
BIP39_MNEMONIC_TYPE_WORDS_15,
BIP39_MNEMONIC_TYPE_WORDS_18,
BIP39_MNEMONIC_TYPE_WORDS_21,
BIP39_MNEMONIC_TYPE_WORDS_24,
} bip39_mnemonic_type;
typedef enum descriptor_type {
DESCRIPTOR_TYPE_BARE,
DESCRIPTOR_TYPE_HASHED,
DESCRIPTOR_TYPE_SEGWIT,
DESCRIPTOR_TYPE_TAPROOT,
} descriptor_type;
typedef enum err_type {
ERR_TYPE_SUCCESS = 0,
/**
* general parse error
*/
ERR_TYPE_PARSE_ERROR,
/**
* JSON encoding error
*/
ERR_TYPE_ENCODING_ERROR,
/**
* got a null pointer as one of the function arguments
*/
ERR_TYPE_NULL_POINTER,
/**
* result data must be a valid string which does not contain zero bytes
*/
ERR_TYPE_INVALID_RESULT_DATA,
/**
* invalid mnemonic string
*/
ERR_TYPE_INVALID_MNEMONIC,
/**
* invalid UTF-8 string
*/
ERR_TYPE_INVALID_UTF8_STRING,
/**
* wrong BIP32 extended public or private key data
*/
ERR_TYPE_WRONG_EXTENDED_KEY,
/**
* unable to derive hardened path from a public key
*/
ERR_TYPE_UNABLE_TO_DERIVE_HARDENED,
/**
* invalid derivation path
*/
ERR_TYPE_INVALID_DERIVATION_PATH,
/**
* general BIP32-specific failure
*/
ERR_TYPE_BIP32_FAILURE,
/**
* error in encoding of PSBT data
*/
ERR_TYPE_PSBT_FAILURE,
/**
* signature error
*/
ERR_TYPE_SIGNATURE,
} err_type;
typedef enum invoice_type {
INVOICE_TYPE_ADDRESS_UTXO,
INVOICE_TYPE_DESCRIPTOR,
INVOICE_TYPE_PSBT,
} invoice_type;
typedef enum validity_t {
VALIDITY_T_UNABLE_TO_VALIDATE,
VALIDITY_T_VALID,
VALIDITY_T_UNRESOLVED_TX,
VALIDITY_T_INVALID,
} validity_t;
typedef struct bech32_info_t {
int status;
int category;
bool bech32m;
const char *details;
} bech32_info_t;
typedef union result_details_t {
const char *data;
const char *error;
} result_details_t;
typedef struct string_result_t {
enum err_type code;
union result_details_t details;
} string_result_t;
typedef struct citadel_client_t {
void *opaque;
const char *message;
int err_no;
} citadel_client_t;
typedef struct prepared_transfer_t {
bool success;
const char *consignment_bech32;
const char *psbt_base64;
} prepared_transfer_t;
typedef struct validation_status_t {
enum validity_t validity;
uint32_t info_len;
const char *const *info;
uint32_t warn_len;
const char *const *warn;
uint32_t failures_len;
const char *const *failures;
} validation_status_t;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void lnpbp_bech32_release(struct bech32_info_t info);
struct bech32_info_t lnpbp_bech32_info(const char *bech_str);
struct string_result_t lnpbp_address_parse(const char *address);
struct string_result_t lnpbp_descriptor_parse(const char *descriptor);
struct citadel_client_t *citadel_run_embedded(const char *chain,
const char *data_dir,
const char *electrum_server);
const char *citadel_contract_list(struct citadel_client_t *client);
const char *citadel_single_sig_create(struct citadel_client_t *client,
const char *name,
const char *keychain,
enum descriptor_type category);
const char *citadel_contract_operations(struct citadel_client_t *client,
const char *contract_id);
const char *citadel_contract_rename(struct citadel_client_t *client,
const char *contract_id,
const char *new_name);
const char *citadel_contract_delete(struct citadel_client_t *client,
const char *contract_id);
const char *citadel_contract_balance(struct citadel_client_t *client,
const char *contract_id,
bool rescan,
uint8_t lookup_depth);
const char *citadel_address_list(struct citadel_client_t *client,
const char *contract_id,
bool rescan,
uint8_t lookup_depth);
const char *citadel_address_create(struct citadel_client_t *client,
const char *contract_id,
bool mark_used,
bool legacy);
const char *citadel_invoice_create(struct citadel_client_t *client,
enum invoice_type category,
const char *contract_id,
const char *asset_id,
uint64_t amount,
const char *merchant,
const char *purpose,
bool mark_used,
bool legacy);
const char *citadel_invoice_list(struct citadel_client_t *client,
const char *contract_id);
const char *citadel_address_pay(struct citadel_client_t *client,
const char *address,
uint64_t amount,
uint64_t fee);
struct prepared_transfer_t citadel_invoice_pay(struct citadel_client_t *client,
const char *contract_id,
const char *invoice,
uint64_t amount,
uint64_t fee,
uint64_t giveaway);
const char *citadel_psbt_publish(struct citadel_client_t *client,
const char *psbt);
struct validation_status_t citadel_invoice_accept(struct citadel_client_t *client,
const char *consignment);
const char *citadel_asset_list(struct citadel_client_t *client);
const char *citadel_asset_import(struct citadel_client_t *client,
const char *genesis_b32);
bool is_success(struct string_result_t result);
void result_destroy(struct string_result_t result);
/**
* Creates a rust-owned mnemonic string. You MUSt always call
* [`string_destroy`] right after storing the mnemonic string and
* do not call other methods from this library on that mnemonic. If you need
* to call [`bip39_master_xpriv`] you MUST read mnemonic again and provide
* unowned string to the rust.
*/
struct string_result_t bip39_mnemonic_create(const uint8_t *entropy,
enum bip39_mnemonic_type mnemonic_type);
struct string_result_t bip39_master_xpriv(char *seed_phrase,
char *passwd,
bool wipe,
bool testnet);
struct string_result_t bip32_scoped_xpriv(const char *master,
bool clean,
const char *derivation);
struct string_result_t bip32_xpriv_to_xpub(char *xpriv, bool wipe);
struct string_result_t bip32_pubkey_chain_create(char *master_xpriv,
bool clean,
const char *derivation);
struct string_result_t psbt_sign(const char *psbt,
const char *master_xpriv_str,
bool wipe);
void release_string(char *s);
bool citadel_is_ok(struct citadel_client_t *client);
bool citadel_has_err(struct citadel_client_t *client);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif /* citadel_h */