Offline Transaction Signing (OTS) 0.1.0
Loading...
Searching...
No Matches
ots.h
Go to the documentation of this file.
1#ifndef OTS_H
2#define OTS_H
3
4#include <stdbool.h>
5#include <stddef.h>
6#include <stdint.h>
7#include "ots-errors.h"
8
21/*******************************************************************************
22 * Constants and Defines
23 ******************************************************************************/
24
26#define OTS_MAX_ERROR_MESSAGE 256
28#define OTS_MAX_ERROR_LOCATION 64
30#define OTS_MAX_VERSION_STRING 32
31
33#define OTS_MONERO_SEED_WORDS 25
34#define OTS_POLYSEED_WORDS 16
35#define OTS_LEGACY_SEED_WORDS 13
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
49
58
66
76
80 typedef struct {
82 uint32_t version;
83 void* ptr;
85
87 typedef struct {
88 int32_t code;
89 char message[OTS_MAX_ERROR_MESSAGE];
90 char location[OTS_MAX_ERROR_LOCATION];
92
94 typedef struct {
95 union {
97 void* ptr;
98 bool boolean;
99 int64_t number;
100 } result;
102 } ots_result_t;
103
105 typedef struct {
106 char* data;
107 size_t length;
109
111 typedef struct {
112 uint16_t* indices;
113 size_t count;
115
117 typedef struct {
119 uint64_t amount;
120 uint64_t fee;
122 uint32_t unlock_time;
124
126 typedef struct {
127 char* message;
128 uint32_t severity;
130
134 static inline bool ots_handle_valid(ots_handle_t h, ots_handle_type expected) {
135 return h.type == expected && h.ptr != NULL;
136 }
137
142 void ots_error_init(ots_error_t* error);
143
149 bool ots_is_error(const ots_result_t* result);
150
156
162 ots_result_t ots_get_error_message(int32_t error_code);
163
167 void ots_clear_error(void);
168
174 bool ots_has_error(const ots_result_t* result);
175
176 /*******************************************************************************
177 * Memory Management Functions
178 ******************************************************************************/
179
185
191
196 void ots_free_string(char* str);
197
202 void ots_free_array(void* arr);
203
208 void ots_free_handle(ots_handle_t handle);
209
215
221 void ots_secure_free(void* buffer, size_t size);
222
229
237 const ots_wipeable_string_t* str1,
238 const ots_wipeable_string_t* str2
239 );
240
246
253
259
265
271
272 /*******************************************************************************
273 * Seed Management Functions
274 ******************************************************************************/
275
284 ots_handle_t handle,
285 const char* language_code,
286 const char* password
287 );
288
295
303 ots_handle_t handle,
304 const char* password
305 );
306
313
320
327
334
341
348
357 const ots_seed_indices_t* values1,
358 const ots_seed_indices_t* values2
359 );
360
369 const char* password,
370 const ots_seed_indices_t* values
371 );
372
382 const ots_seed_indices_t* values[],
383 size_t count
384 );
385
395 ots_seed_indices_t* values1,
396 ots_seed_indices_t* values2,
397 bool delete_after
398 );
399
409 char* password,
410 ots_seed_indices_t* values,
411 bool delete_after
412 );
413
424 ots_seed_indices_t* values[],
425 size_t count,
426 bool delete_after
427 );
428
429 /*******************************************************************************
430 * Legacy Seed Functions
431 ******************************************************************************/
432
443 const char* phrase,
444 uint64_t height,
445 uint64_t time,
446 OTS_NETWORK network
447 );
448
459 const ots_seed_indices_t* indices,
460 uint64_t height,
461 uint64_t time,
462 OTS_NETWORK network
463 );
464
465 /*******************************************************************************
466 * Monero Seed Functions
467 ******************************************************************************/
468
479 const uint8_t random[32],
480 uint64_t height,
481 uint64_t time,
482 OTS_NETWORK network
483 );
484
493 uint64_t height,
494 uint64_t time,
495 OTS_NETWORK network
496 );
497
509 const char* phrase,
510 uint64_t height,
511 uint64_t time,
512 OTS_NETWORK network,
513 const char* passphrase
514 );
515
527 const ots_seed_indices_t* indices,
528 uint64_t height,
529 uint64_t time,
530 OTS_NETWORK network,
531 const char* passphrase
532 );
533
534 /*******************************************************************************
535 * Polyseed Functions
536 ******************************************************************************/
537
548 const uint8_t random[19],
549 OTS_NETWORK network,
550 uint64_t time,
551 const char* passphrase
552 );
553
562 OTS_NETWORK network,
563 uint64_t time,
564 const char* passphrase
565 );
566
577 const char* phrase,
578 OTS_NETWORK network,
579 const char* password,
580 const char* passphrase
581 );
582
593 const ots_seed_indices_t* indices,
594 OTS_NETWORK network,
595 const char* password,
596 const char* passphrase
597 );
598
610 const char* phrase,
611 const char* language_code,
612 OTS_NETWORK network,
613 const char* password,
614 const char* passphrase
615 );
616
617 /*******************************************************************************
618 * Address Management Functions
619 ******************************************************************************/
620
627
635
644
652
661
670
678
685
694 ots_handle_t address1,
695 ots_handle_t address2
696 );
697
705 ots_handle_t address_handle,
706 const char* address_string
707 );
708
716 ots_result_t ots_address_create(const char* address);
717
723
730 ots_result_t ots_address_string_valid(const char* address, OTS_NETWORK network);
731
739
747
755
763
772
781
782
783 /*******************************************************************************
784 * Wallet Functions
785 ******************************************************************************/
786
795 const uint8_t key[32],
796 uint64_t height,
797 OTS_NETWORK network
798 );
799
806
814 ots_result_t ots_wallet_address(ots_handle_t wallet_handle, uint32_t account, uint32_t index);
815
824 ots_handle_t wallet_handle,
825 uint32_t max,
826 uint32_t offset
827 );
828
838 ots_handle_t wallet_handle,
839 uint32_t account,
840 uint32_t max,
841 uint32_t offset
842 );
843
853 ots_handle_t wallet_handle,
854 const char* address,
855 uint32_t max_account_depth,
856 uint32_t max_index_depth
857 );
858
868 ots_handle_t wallet_handle,
869 ots_handle_t address_handle,
870 uint32_t max_account_depth,
871 uint32_t max_index_depth
872 );
873
884 ots_handle_t wallet_handle,
885 const char* address,
886 uint32_t max_account_depth,
887 uint32_t max_index_depth
888 );
889
900 ots_handle_t wallet_handle,
901 ots_handle_t address_handle,
902 uint32_t max_account_depth,
903 uint32_t max_index_depth
904 );
905
912
919
926
933
942 ots_handle_t wallet_handle,
943 const char* outputs
944 );
945
953
960 ots_result_t ots_wallet_describe_tx(ots_handle_t wallet_handle, const char* unsigned_tx);
961
968 ots_result_t ots_wallet_check_tx(ots_handle_t wallet_handle, ots_handle_t unsigned_tx_handle);
969
977 ots_handle_t wallet_handle,
978 const char* unsigned_tx
979 );
980
989 ots_handle_t wallet_handle,
990 const char* unsigned_tx
991 );
992
999 ots_result_t ots_wallet_sign_data(ots_handle_t wallet_handle, const char* data);
1000
1010 ots_handle_t wallet_handle,
1011 const char* data,
1012 uint32_t account,
1013 uint32_t subaddr
1014 );
1015
1025 ots_handle_t wallet_handle,
1026 const char* data,
1027 ots_handle_t address_handle
1028 );
1029
1038 const char* data,
1039 const char* signature,
1040 bool legacy_fallback
1041 );
1042
1054 ots_handle_t wallet_handle,
1055 const char* data,
1056 uint32_t account,
1057 uint32_t subaddr,
1058 const char* signature,
1059 bool legacy_fallback
1060 );
1061
1073 ots_handle_t wallet_handle,
1074 const char* data,
1075 ots_handle_t address_handle,
1076 const char* signature,
1077 bool legacy_fallback
1078 );
1079
1080 /*******************************************************************************
1081 * OTS Utility Functions
1082 ******************************************************************************/
1083
1091 uint64_t timestamp,
1092 OTS_NETWORK network
1093 );
1094
1102 uint64_t height,
1103 OTS_NETWORK network
1104 );
1105
1114 uint8_t* buffer,
1115 size_t size
1116 );
1117
1124
1133 const uint8_t* data,
1134 size_t size,
1135 double min_entropy
1136 );
1137
1142 void ots_set_enforce_entropy(bool enforce);
1143
1148 void ots_set_max_account_depth(uint32_t depth);
1149
1154 void ots_set_max_index_depth(uint32_t depth);
1155
1161 void ots_set_max_depth(uint32_t account_depth, uint32_t index_depth);
1162
1167
1173 uint32_t ots_max_account_depth(uint32_t depth);
1174
1180 uint32_t ots_max_index_depth(uint32_t depth);
1181
1189 ots_result_t ots_verify_data(const char* data, const char* address, const char* signature);
1190
1191#ifdef __cplusplus
1192}
1193#endif
1194
1195#endif // OTS_H
Error codes for the C ABI.
ots_result_t ots_wallet_accounts(ots_handle_t wallet_handle, uint32_t max, uint32_t offset)
Get list of accounts in wallet.
ots_result_t ots_address_is_integrated(ots_handle_t address)
Check if address is an integrated address.
void ots_reset_max_depth(void)
Reset maximum depths to defaults.
ots_result_t ots_get_last_error(void)
Get error message for last error.
Definition ots-abi.cpp:56
ots_result_t ots_wallet_secret_view_key(ots_handle_t wallet_handle)
Get secret view key.
void ots_error_init(ots_error_t *error)
Initialize error structure.
Definition ots-abi.cpp:41
ots_result_t ots_monero_seed_decode(const char *phrase, uint64_t height, uint64_t time, OTS_NETWORK network, const char *passphrase)
Decode a Monero seed from phrase.
ots_result_t ots_address_create(const char *address)
Create address object from string.
ots_result_t ots_polyseed_generate(OTS_NETWORK network, uint64_t time, const char *passphrase)
Generate a new Polyseed.
ots_result_t ots_seed_timestamp(ots_handle_t handle)
Get seed creation timestamp.
ots_result_t ots_wallet_sign_transaction(ots_handle_t wallet_handle, const char *unsigned_tx)
Sign unsigned transaction.
ots_result_t ots_address_string_type(const char *address)
Get type for an address string.
void ots_free_handle(ots_handle_t handle)
Free a handle.
Definition ots-abi.cpp:80
ots_result_t ots_version(void)
Get library version string.
Definition ots-abi.cpp:106
void ots_wipeable_string_clear(ots_wipeable_string_t *str)
Clear wipeable string content.
ots_result_t ots_seed_merge_multiple_values_and_zero(ots_seed_indices_t *values[], size_t count, bool delete_after)
Merge multiple sets of seed values and zero.
void ots_secure_free(void *buffer, size_t size)
Securely wipe and free a buffer.
ots_result_t ots_seed_network(ots_handle_t handle)
Get seed network type.
ots_result_t ots_wallet_public_spend_key(ots_handle_t wallet_handle)
Get public spend key.
void ots_set_max_account_depth(uint32_t depth)
Set maximum account depth for searching.
ots_result_t ots_verify_data(const char *data, const char *address, const char *signature)
Verify signed data.
ots_result_t ots_monero_seed_generate(uint64_t height, uint64_t time, OTS_NETWORK network)
Generate a new Monero seed.
ots_result_t ots_wallet_verify_data_with_address(ots_handle_t wallet_handle, const char *data, ots_handle_t address_handle, const char *signature, bool legacy_fallback)
Verify signed data with specific address.
void ots_wipeable_string_free(ots_wipeable_string_t *str)
Free a wipeable string, securely wiping memory.
Definition ots-abi.cpp:86
ots_result_t ots_polyseed_decode_indices(const ots_seed_indices_t *indices, OTS_NETWORK network, const char *password, const char *passphrase)
Decode a Polyseed from indices.
void ots_address_free(ots_handle_t handle)
Free address handle.
static bool ots_handle_valid(ots_handle_t h, ots_handle_type expected)
Validate handle type.
Definition ots.h:134
ots_result_t ots_wallet_sign_data_with_address(ots_handle_t wallet_handle, const char *data, ots_handle_t address_handle)
Sign data with specific address.
ots_result_t ots_address_string_valid(const char *address, OTS_NETWORK network)
Validate a Monero address.
ots_result_t ots_address_string_integrated(const char *address)
Get base address from integrated address string.
ots_result_t ots_check_entropy(const uint8_t *data, size_t size, double min_entropy)
Check data entropy level.
ots_result_t ots_wallet_secret_spend_key(ots_handle_t wallet_handle)
Get secret spend key.
ots_result_t ots_wallet_export_key_images(ots_handle_t wallet_handle)
Export key images.
ots_result_t ots_wallet_check_tx_string(ots_handle_t wallet_handle, const char *unsigned_tx)
Check transaction string for warnings.
ots_result_t ots_wipeable_string_compare(const ots_wipeable_string_t *str1, const ots_wipeable_string_t *str2)
Compare two wipeable strings.
ots_result_t ots_random_bytes(uint8_t *buffer, size_t size)
Generate random bytes.
ots_result_t ots_wallet_describe_tx(ots_handle_t wallet_handle, const char *unsigned_tx)
Describe unsigned transaction.
void ots_free_tx_description(ots_tx_description_t *desc)
Free transaction description.
Definition ots-abi.cpp:101
ots_result_t ots_wallet_verify_data(const char *data, const char *signature, bool legacy_fallback)
Verify signed data for the wallet address with legacy support.
void ots_free_array(void *arr)
Free an array allocated by the library.
Definition ots-abi.cpp:76
ots_result_t ots_address_string_is_integrated(const char *address)
Check if address string is integrated.
ots_result_t ots_wallet_height(ots_handle_t wallet_handle)
Get wallet restore height.
ots_result_t ots_monero_seed_decode_indices(const ots_seed_indices_t *indices, uint64_t height, uint64_t time, OTS_NETWORK network, const char *passphrase)
Decode a Monero seed from indices.
#define OTS_MAX_ERROR_LOCATION
Maximum length for error location strings.
Definition ots.h:28
ots_result_t ots_seed_merge_values_and_zero(ots_seed_indices_t *values1, ots_seed_indices_t *values2, bool delete_after)
Merge and zero two sets of seed values.
ots_result_t ots_wallet_check_tx(ots_handle_t wallet_handle, ots_handle_t unsigned_tx_handle)
Check transaction for warnings.
ots_result_t ots_address_string_fingerprint(const char *address)
Generate fingerprint for an address string.
ots_result_t ots_seed_languages(OTS_SEED_TYPE type)
Get supported languages for seed type.
ots_result_t ots_seed_fingerprint(ots_handle_t handle)
Get seed fingerprint.
ots_result_t ots_address_base58_string(ots_handle_t address_handle)
Get base58 string representation of address.
ots_result_t ots_seed_wallet(ots_handle_t handle)
Get wallet from seed.
ots_result_t ots_seed_merge_multiple_values(const ots_seed_indices_t *values[], size_t count)
Merge multiple sets of seed values.
OTS_ADDRESS_TYPE
Address types matching ots::AddressType.
Definition ots.h:53
@ OTS_ADDRESS_TYPE_STANDARD
Definition ots.h:54
@ OTS_ADDRESS_TYPE_SUBADDRESS
Definition ots.h:55
@ OTS_ADDRESS_TYPE_INTEGRATED
Definition ots.h:56
ots_result_t ots_legacy_seed_decode_indices(const ots_seed_indices_t *indices, uint64_t height, uint64_t time, OTS_NETWORK network)
Decode a legacy seed from indices.
ots_result_t ots_wallet_import_outputs(ots_handle_t wallet_handle, const char *outputs)
Import outputs from string.
ots_result_t ots_address_length(ots_handle_t address)
Get address length.
void ots_clear_error(void)
Clear last error state.
Definition ots-abi.cpp:68
void ots_seed_indices_free(ots_seed_indices_t *indices)
Free seed indices, securely wiping memory.
Definition ots-abi.cpp:94
ots_result_t ots_seed_height(ots_handle_t handle)
Get seed blockchain height.
ots_result_t ots_address_equal(ots_handle_t address1, ots_handle_t address2)
Compare two addresses for equality.
ots_result_t ots_wallet_create(const uint8_t key[32], uint64_t height, OTS_NETWORK network)
Create wallet from secret key.
ots_result_t ots_timestamp_from_height(uint64_t height, OTS_NETWORK network)
Convert block height to estimated timestamp.
void ots_set_max_depth(uint32_t account_depth, uint32_t index_depth)
Set maximum depths for searching.
ots_result_t ots_address_network(ots_handle_t address)
Get network type for an address.
ots_result_t ots_legacy_seed_decode(const char *phrase, uint64_t height, uint64_t time, OTS_NETWORK network)
Decode a legacy (13 word) seed from phrase.
ots_result_t ots_random_32(void)
Generate 32 random bytes.
#define OTS_MAX_ERROR_MESSAGE
Maximum length for error messages.
Definition ots.h:26
bool ots_is_error(const ots_result_t *result)
Check if result contains an error.
Definition ots-abi.cpp:48
ots_result_t ots_polyseed_create(const uint8_t random[19], OTS_NETWORK network, uint64_t time, const char *passphrase)
Create a Polyseed from random data.
void ots_free_string(char *str)
Free a string allocated by the library.
Definition ots-abi.cpp:72
ots_handle_type
Types of handles for type safety.
Definition ots.h:70
@ OTS_HANDLE_SEED
Definition ots.h:72
@ OTS_HANDLE_INVALID
Definition ots.h:71
@ OTS_HANDLE_WALLET
Definition ots.h:73
@ OTS_HANDLE_TX
Definition ots.h:74
ots_result_t ots_address_fingerprint(ots_handle_t address)
Generate fingerprint for an address.
ots_result_t ots_wipeable_string_create(const char *str)
Create a new wipeable string.
ots_result_t ots_polyseed_decode(const char *phrase, OTS_NETWORK network, const char *password, const char *passphrase)
Decode a Polyseed from phrase.
OTS_NETWORK
Network types matching ots::Network.
Definition ots.h:44
@ OTS_NETWORK_STAGE
Definition ots.h:47
@ OTS_NETWORK_MAIN
Definition ots.h:45
@ OTS_NETWORK_TEST
Definition ots.h:46
ots_result_t ots_wallet_sign_data(ots_handle_t wallet_handle, const char *data)
Sign arbitrary data.
OTS_SEED_TYPE
Seed types matching ots::SeedType.
Definition ots.h:62
@ OTS_SEED_TYPE_MONERO
Definition ots.h:63
@ OTS_SEED_TYPE_POLYSEED
Definition ots.h:64
ots_result_t ots_wallet_address_index(ots_handle_t wallet_handle, const char *address, uint32_t max_account_depth, uint32_t max_index_depth)
Get account and index for address in wallet.
ots_result_t ots_wallet_public_view_key(ots_handle_t wallet_handle)
Get public view key.
ots_result_t ots_wallet_address(ots_handle_t wallet_handle, uint32_t account, uint32_t index)
Generate address for wallet.
ots_result_t ots_seed_merge_with_password(const char *password, const ots_seed_indices_t *values)
Merge seed values with password.
ots_result_t ots_get_error_message(int32_t error_code)
Get error message for specific error code.
Definition ots-abi.cpp:62
ots_result_t ots_wallet_address_index_handle(ots_handle_t wallet_handle, ots_handle_t address_handle, uint32_t max_account_depth, uint32_t max_index_depth)
Get account and index for address handle in wallet.
ots_result_t ots_address_string_network(const char *address)
Get network type for an address string.
uint32_t ots_max_index_depth(uint32_t depth)
Get maximum index depth.
ots_result_t ots_address_from_integrated(ots_handle_t address)
Get base address from integrated address.
ots_result_t ots_address_string_payment_id(const char *address)
Extract payment ID from integrated address string.
uint32_t ots_max_account_depth(uint32_t depth)
Get maximum account depth.
ots_result_t ots_wallet_verify_data_with_index(ots_handle_t wallet_handle, const char *data, uint32_t account, uint32_t subaddr, const char *signature, bool legacy_fallback)
Verify signed data with specific subaddress.
ots_result_t ots_polyseed_decode_with_language(const char *phrase, const char *language_code, OTS_NETWORK network, const char *password, const char *passphrase)
Decode a Polyseed from phrase with specific language.
ots_result_t ots_seed_address(ots_handle_t handle)
Get seed address.
bool ots_has_error(const ots_result_t *result)
Check if result contains an error.
Definition ots-abi.cpp:52
ots_result_t ots_height_from_timestamp(uint64_t timestamp, OTS_NETWORK network)
Convert timestamp to estimated block height.
ots_result_t ots_wallet_sign_data_with_index(ots_handle_t wallet_handle, const char *data, uint32_t account, uint32_t subaddr)
Sign data with specific subaddress.
ots_result_t ots_address_equal_string(ots_handle_t address_handle, const char *address_string)
Compare address handle with string.
ots_result_t ots_monero_seed_create(const uint8_t random[32], uint64_t height, uint64_t time, OTS_NETWORK network)
Create a Monero seed from random data.
ots_result_t ots_address_type(ots_handle_t address)
Get address type.
void ots_set_max_index_depth(uint32_t depth)
Set maximum index depth for searching.
ots_result_t ots_seed_indices_create(size_t size)
Create seed indices container.
ots_result_t ots_version_components(void)
Get version components [major, minor, patch].
Definition ots-abi.cpp:118
ots_result_t ots_seed_merge_values_with_password_and_zero(char *password, ots_seed_indices_t *values, bool delete_after)
Merge seed values with password and zero.
ots_result_t ots_seed_phrase(ots_handle_t handle, const char *language_code, const char *password)
Get seed phrase in specified language.
ots_result_t ots_wallet_has_address_handle(ots_handle_t wallet_handle, ots_handle_t address_handle, uint32_t max_account_depth, uint32_t max_index_depth)
Check if address belongs to wallet using Address handle.
ots_result_t ots_seed_indices(ots_handle_t handle, const char *password)
Get seed indices.
void ots_seed_indices_clear(ots_seed_indices_t *indices)
Clear seed indices content.
ots_result_t ots_wallet_subaddresses(ots_handle_t wallet_handle, uint32_t account, uint32_t max, uint32_t offset)
Get list of subaddresses for an account.
ots_result_t ots_wallet_has_address(ots_handle_t wallet_handle, const char *address, uint32_t max_account_depth, uint32_t max_index_depth)
Check if address belongs to wallet.
ots_result_t ots_address_payment_id(ots_handle_t address)
Extract payment ID from integrated address.
void ots_set_enforce_entropy(bool enforce)
Set entropy enforcement.
ots_result_t ots_seed_merge_values(const ots_seed_indices_t *values1, const ots_seed_indices_t *values2)
Merge two sets of seed values.
Error structure for exception handling.
Definition ots.h:87
int32_t code
Definition ots.h:88
Handle structure for C objects.
Definition ots.h:80
uint32_t version
Definition ots.h:82
void * ptr
Definition ots.h:83
ots_handle_type type
Definition ots.h:81
Result structure combining handle and error.
Definition ots.h:94
void * ptr
Definition ots.h:97
ots_handle_t handle
Definition ots.h:96
bool boolean
Definition ots.h:98
ots_error_t error
Definition ots.h:101
int64_t number
Definition ots.h:99
Seed indices container.
Definition ots.h:111
size_t count
Definition ots.h:113
uint16_t * indices
Definition ots.h:112
Transaction description.
Definition ots.h:117
uint64_t fee
Definition ots.h:120
char * destination
Definition ots.h:121
char * description
Definition ots.h:118
uint32_t unlock_time
Definition ots.h:122
uint64_t amount
Definition ots.h:119
Transaction warning.
Definition ots.h:126
char * message
Definition ots.h:127
uint32_t severity
Definition ots.h:128
Wipeable string for sensitive data.
Definition ots.h:105
char * data
Definition ots.h:106
size_t length
Definition ots.h:107