aries-askar 0.4.6

Askar cryptographic primitives and secure storage
Documentation
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

enum class ErrorCode : int64_t {
  Success = 0,
  Backend = 1,
  Busy = 2,
  Duplicate = 3,
  Encryption = 4,
  Input = 5,
  NotFound = 6,
  Unexpected = 7,
  Unsupported = 8,
  Custom = 100,
};

template<typename R = void>
struct FfiResultList;

/// A stored key entry
struct KeyEntry;

/// A stored key entry
struct LocalKey;

template<typename T = void>
struct Option;

struct String;

template<typename T>
struct ArcHandle {
  const T *_0;
};

using LocalKeyHandle = ArcHandle<LocalKey>;

struct SecretBuffer {
  int64_t len;
  uint8_t *data;
};

struct AeadParams {
  int32_t nonce_length;
  int32_t tag_length;
};

struct EncryptedBuffer {
  SecretBuffer buffer;
  int64_t tag_pos;
  int64_t nonce_pos;
};

using LogCallback = void(*)(const void *context, int32_t level, const char *target, const char *message, const char *module_path, const char *file, int32_t line);

using EnabledCallback = int8_t(*)(const void *context, int32_t level);

using FlushCallback = void(*)(const void *context);

using FfiEntryList = FfiResultList<Entry>;

using EntryListHandle = ArcHandle<FfiEntryList>;

using FfiKeyEntryList = FfiResultList<KeyEntry>;

using KeyEntryListHandle = ArcHandle<FfiKeyEntryList>;

using FfiStringList = FfiResultList<String>;

using StringListHandle = ArcHandle<FfiStringList>;

using CallbackId = int64_t;

extern "C" {

void askar_terminate();

char *askar_version();

ErrorCode askar_get_current_error(const char **error_json_p);

ErrorCode askar_key_generate(FfiStr alg, int8_t ephemeral, LocalKeyHandle *out);

ErrorCode askar_key_from_seed(FfiStr alg, ByteBuffer seed, FfiStr method, LocalKeyHandle *out);

ErrorCode askar_key_from_jwk(ByteBuffer jwk, LocalKeyHandle *out);

ErrorCode askar_key_from_public_bytes(FfiStr alg, ByteBuffer public_, LocalKeyHandle *out);

ErrorCode askar_key_get_public_bytes(LocalKeyHandle handle, SecretBuffer *out);

ErrorCode askar_key_from_secret_bytes(FfiStr alg, ByteBuffer secret, LocalKeyHandle *out);

ErrorCode askar_key_get_secret_bytes(LocalKeyHandle handle, SecretBuffer *out);

ErrorCode askar_key_convert(LocalKeyHandle handle, FfiStr alg, LocalKeyHandle *out);

ErrorCode askar_key_from_key_exchange(FfiStr alg,
                                      LocalKeyHandle sk_handle,
                                      LocalKeyHandle pk_handle,
                                      LocalKeyHandle *out);

void askar_key_free(LocalKeyHandle handle);

ErrorCode askar_key_get_algorithm(LocalKeyHandle handle, const char **out);

ErrorCode askar_key_get_ephemeral(LocalKeyHandle handle, int8_t *out);

ErrorCode askar_key_get_jwk_public(LocalKeyHandle handle, FfiStr alg, const char **out);

ErrorCode askar_key_get_jwk_secret(LocalKeyHandle handle, SecretBuffer *out);

ErrorCode askar_key_get_jwk_thumbprint(LocalKeyHandle handle, FfiStr alg, const char **out);

ErrorCode askar_key_aead_random_nonce(LocalKeyHandle handle, SecretBuffer *out);

ErrorCode askar_key_aead_get_params(LocalKeyHandle handle, AeadParams *out);

ErrorCode askar_key_aead_get_padding(LocalKeyHandle handle, int64_t msg_len, int32_t *out);

ErrorCode askar_key_aead_encrypt(LocalKeyHandle handle,
                                 ByteBuffer message,
                                 ByteBuffer nonce,
                                 ByteBuffer aad,
                                 EncryptedBuffer *out);

ErrorCode askar_key_aead_decrypt(LocalKeyHandle handle,
                                 ByteBuffer ciphertext,
                                 ByteBuffer nonce,
                                 ByteBuffer tag,
                                 ByteBuffer aad,
                                 SecretBuffer *out);

ErrorCode askar_key_sign_message(LocalKeyHandle handle,
                                 ByteBuffer message,
                                 FfiStr sig_type,
                                 SecretBuffer *out);

ErrorCode askar_key_verify_signature(LocalKeyHandle handle,
                                     ByteBuffer message,
                                     ByteBuffer signature,
                                     FfiStr sig_type,
                                     int8_t *out);

ErrorCode askar_key_wrap_key(LocalKeyHandle handle,
                             LocalKeyHandle other,
                             ByteBuffer nonce,
                             EncryptedBuffer *out);

ErrorCode askar_key_unwrap_key(LocalKeyHandle handle,
                               FfiStr alg,
                               ByteBuffer ciphertext,
                               ByteBuffer nonce,
                               ByteBuffer tag,
                               LocalKeyHandle *out);

ErrorCode askar_key_crypto_box_random_nonce(SecretBuffer *out);

ErrorCode askar_key_crypto_box(LocalKeyHandle recip_key,
                               LocalKeyHandle sender_key,
                               ByteBuffer message,
                               ByteBuffer nonce,
                               SecretBuffer *out);

ErrorCode askar_key_crypto_box_open(LocalKeyHandle recip_key,
                                    LocalKeyHandle sender_key,
                                    ByteBuffer message,
                                    ByteBuffer nonce,
                                    SecretBuffer *out);

ErrorCode askar_key_crypto_box_seal(LocalKeyHandle handle, ByteBuffer message, SecretBuffer *out);

ErrorCode askar_key_crypto_box_seal_open(LocalKeyHandle handle,
                                         ByteBuffer ciphertext,
                                         SecretBuffer *out);

ErrorCode askar_key_derive_ecdh_es(FfiStr alg,
                                   LocalKeyHandle ephem_key,
                                   LocalKeyHandle recip_key,
                                   ByteBuffer alg_id,
                                   ByteBuffer apu,
                                   ByteBuffer apv,
                                   int8_t receive,
                                   LocalKeyHandle *out);

ErrorCode askar_key_derive_ecdh_1pu(FfiStr alg,
                                    LocalKeyHandle ephem_key,
                                    LocalKeyHandle sender_key,
                                    LocalKeyHandle recip_key,
                                    ByteBuffer alg_id,
                                    ByteBuffer apu,
                                    ByteBuffer apv,
                                    ByteBuffer cc_tag,
                                    int8_t receive,
                                    LocalKeyHandle *out);

ErrorCode askar_set_custom_logger(const void *context,
                                  LogCallback log,
                                  Option<EnabledCallback> enabled,
                                  Option<FlushCallback> flush,
                                  int32_t max_level);

void askar_clear_custom_logger();

ErrorCode askar_set_default_logger();

ErrorCode askar_set_max_log_level(int32_t max_level);

ErrorCode askar_entry_list_count(EntryListHandle handle, int32_t *count);

ErrorCode askar_entry_list_get_category(EntryListHandle handle,
                                        int32_t index,
                                        const char **category);

ErrorCode askar_entry_list_get_name(EntryListHandle handle, int32_t index, const char **name);

ErrorCode askar_entry_list_get_value(EntryListHandle handle, int32_t index, SecretBuffer *value);

ErrorCode askar_entry_list_get_tags(EntryListHandle handle, int32_t index, const char **tags);

void askar_entry_list_free(EntryListHandle handle);

ErrorCode askar_key_entry_list_count(KeyEntryListHandle handle, int32_t *count);

void askar_key_entry_list_free(KeyEntryListHandle handle);

ErrorCode askar_key_entry_list_get_algorithm(KeyEntryListHandle handle,
                                             int32_t index,
                                             const char **alg);

ErrorCode askar_key_entry_list_get_name(KeyEntryListHandle handle,
                                        int32_t index,
                                        const char **name);

ErrorCode askar_key_entry_list_get_metadata(KeyEntryListHandle handle,
                                            int32_t index,
                                            const char **metadata);

ErrorCode askar_key_entry_list_get_tags(KeyEntryListHandle handle,
                                        int32_t index,
                                        const char **tags);

ErrorCode askar_key_entry_list_load_local(KeyEntryListHandle handle,
                                          int32_t index,
                                          LocalKeyHandle *out);

ErrorCode askar_string_list_count(StringListHandle handle, int32_t *count);

ErrorCode askar_string_list_get_item(StringListHandle handle, int32_t index, const char **item);

void askar_string_list_free(StringListHandle handle);

void askar_buffer_free(SecretBuffer buffer);

ErrorCode askar_store_generate_raw_key(ByteBuffer seed, const char **out);

ErrorCode askar_store_provision(FfiStr spec_uri,
                                FfiStr key_method,
                                FfiStr pass_key,
                                FfiStr profile,
                                int8_t recreate,
                                void (*cb)(CallbackId cb_id, ErrorCode err, StoreHandle handle),
                                CallbackId cb_id);

ErrorCode askar_store_open(FfiStr spec_uri,
                           FfiStr key_method,
                           FfiStr pass_key,
                           FfiStr profile,
                           void (*cb)(CallbackId cb_id, ErrorCode err, StoreHandle handle),
                           CallbackId cb_id);

ErrorCode askar_store_remove(FfiStr spec_uri,
                             void (*cb)(CallbackId cb_id, ErrorCode err, int8_t),
                             CallbackId cb_id);

ErrorCode askar_store_create_profile(StoreHandle handle,
                                     FfiStr profile,
                                     void (*cb)(CallbackId cb_id, ErrorCode err, const char *result_p),
                                     CallbackId cb_id);

ErrorCode askar_store_get_profile_name(StoreHandle handle,
                                       void (*cb)(CallbackId cb_id, ErrorCode err, const char *name),
                                       CallbackId cb_id);

ErrorCode askar_store_list_profiles(StoreHandle handle,
                                    void (*cb)(CallbackId cb_id, ErrorCode err, StringListHandle results),
                                    CallbackId cb_id);

ErrorCode askar_store_remove_profile(StoreHandle handle,
                                     FfiStr profile,
                                     void (*cb)(CallbackId cb_id, ErrorCode err, int8_t removed),
                                     CallbackId cb_id);

ErrorCode askar_store_get_default_profile(StoreHandle handle,
                                          void (*cb)(CallbackId cb_id, ErrorCode err, const char *profile),
                                          CallbackId cb_id);

ErrorCode askar_store_set_default_profile(StoreHandle handle,
                                          FfiStr profile,
                                          void (*cb)(CallbackId cb_id, ErrorCode err),
                                          CallbackId cb_id);

ErrorCode askar_store_rekey(StoreHandle handle,
                            FfiStr key_method,
                            FfiStr pass_key,
                            void (*cb)(CallbackId cb_id, ErrorCode err),
                            CallbackId cb_id);

ErrorCode askar_store_copy(StoreHandle handle,
                           FfiStr target_uri,
                           FfiStr key_method,
                           FfiStr pass_key,
                           int8_t recreate,
                           void (*cb)(CallbackId cb_id, ErrorCode err, StoreHandle handle),
                           CallbackId cb_id);

ErrorCode askar_store_close(StoreHandle handle,
                            void (*cb)(CallbackId cb_id, ErrorCode err),
                            CallbackId cb_id);

ErrorCode askar_scan_start(StoreHandle handle,
                           FfiStr profile,
                           FfiStr category,
                           FfiStr tag_filter,
                           int64_t offset,
                           int64_t limit,
                           void (*cb)(CallbackId cb_id, ErrorCode err, ScanHandle handle),
                           CallbackId cb_id);

ErrorCode askar_scan_next(ScanHandle handle,
                          void (*cb)(CallbackId cb_id, ErrorCode err, EntryListHandle results),
                          CallbackId cb_id);

ErrorCode askar_scan_free(ScanHandle handle);

ErrorCode askar_session_start(StoreHandle handle,
                              FfiStr profile,
                              int8_t as_transaction,
                              void (*cb)(CallbackId cb_id, ErrorCode err, SessionHandle handle),
                              CallbackId cb_id);

ErrorCode askar_session_count(SessionHandle handle,
                              FfiStr category,
                              FfiStr tag_filter,
                              void (*cb)(CallbackId cb_id, ErrorCode err, int64_t count),
                              CallbackId cb_id);

ErrorCode askar_session_fetch(SessionHandle handle,
                              FfiStr category,
                              FfiStr name,
                              int8_t for_update,
                              void (*cb)(CallbackId cb_id, ErrorCode err, EntryListHandle results),
                              CallbackId cb_id);

ErrorCode askar_session_fetch_all(SessionHandle handle,
                                  FfiStr category,
                                  FfiStr tag_filter,
                                  int64_t limit,
                                  int8_t for_update,
                                  void (*cb)(CallbackId cb_id, ErrorCode err, EntryListHandle results),
                                  CallbackId cb_id);

ErrorCode askar_session_remove_all(SessionHandle handle,
                                   FfiStr category,
                                   FfiStr tag_filter,
                                   void (*cb)(CallbackId cb_id, ErrorCode err, int64_t removed),
                                   CallbackId cb_id);

ErrorCode askar_session_update(SessionHandle handle,
                               int8_t operation,
                               FfiStr category,
                               FfiStr name,
                               ByteBuffer value,
                               FfiStr tags,
                               int64_t expiry_ms,
                               void (*cb)(CallbackId cb_id, ErrorCode err),
                               CallbackId cb_id);

ErrorCode askar_session_insert_key(SessionHandle handle,
                                   LocalKeyHandle key_handle,
                                   FfiStr name,
                                   FfiStr metadata,
                                   FfiStr tags,
                                   int64_t expiry_ms,
                                   void (*cb)(CallbackId cb_id, ErrorCode err),
                                   CallbackId cb_id);

ErrorCode askar_session_fetch_key(SessionHandle handle,
                                  FfiStr name,
                                  int8_t for_update,
                                  void (*cb)(CallbackId cb_id, ErrorCode err, KeyEntryListHandle results),
                                  CallbackId cb_id);

ErrorCode askar_session_fetch_all_keys(SessionHandle handle,
                                       FfiStr alg,
                                       FfiStr thumbprint,
                                       FfiStr tag_filter,
                                       int64_t limit,
                                       int8_t for_update,
                                       void (*cb)(CallbackId cb_id, ErrorCode err, KeyEntryListHandle results),
                                       CallbackId cb_id);

ErrorCode askar_session_update_key(SessionHandle handle,
                                   FfiStr name,
                                   FfiStr metadata,
                                   FfiStr tags,
                                   int64_t expiry_ms,
                                   void (*cb)(CallbackId cb_id, ErrorCode err),
                                   CallbackId cb_id);

ErrorCode askar_session_remove_key(SessionHandle handle,
                                   FfiStr name,
                                   void (*cb)(CallbackId cb_id, ErrorCode err),
                                   CallbackId cb_id);

ErrorCode askar_session_close(SessionHandle handle,
                              int8_t commit,
                              void (*cb)(CallbackId cb_id, ErrorCode err),
                              CallbackId cb_id);

/// Migrate an sqlite wallet from an indy-sdk structure to an aries-askar structure.
/// It is important to note that this does not do any post-processing. If the record values, tags,
/// names, etc. have changed, it must be processed manually afterwards. This script does the following:
///
/// 1. Create and rename the required tables
/// 2. Fetch the indy key from the wallet
/// 3. Create a new configuration
/// 4. Initialize a profile
/// 5. Update the items from the indy-sdk
/// 6. Clean up (drop tables and add a version of "1")
ErrorCode askar_migrate_indy_sdk(FfiStr spec_uri,
                                 FfiStr wallet_name,
                                 FfiStr wallet_key,
                                 FfiStr kdf_level,
                                 void (*cb)(CallbackId cb_id, ErrorCode err),
                                 CallbackId cb_id);

} // extern "C"