This repository has been archived by the owner on Jun 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
cardano.h
139 lines (104 loc) · 4.68 KB
/
cardano.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
#ifndef CARDANO_RUST_H
# define CARDANO_RUST_H
/* Basic Types */
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
typedef int cardano_result;
/*********/
/* BIP39 */
/*********/
/* bip39 error definitions */
typedef enum _bip39_config_error
{
SUCCESS = 0,
INVALID_MNEMONIC = 1,
INVALID_CHECKSUM = 2,
INVALID_WORD_COUNT = 3
} cardano_bip39_error_t;
/* Error descriptions */
struct _errordesc {
int code;
char *message;
} errordesc[] = {
{ SUCCESS, "No error" },
{ INVALID_MNEMONIC, "Invalid mnemonic word" },
{ INVALID_CHECKSUM, "Invalid checksum" },
{ INVALID_WORD_COUNT, "The word count should be one of: 9, 12, 15, 18, 21, 24"}
};
typedef uint8_t* cardano_entropy;
cardano_bip39_error_t cardano_entropy_from_english_mnemonics(
const char *mnemonics,
cardano_entropy *entropy,
uint32_t *entropy_size
);
cardano_bip39_error_t cardano_generate_random_entropy(
uint8_t number_of_words,
uint8_t (*random_generator)(),
cardano_entropy *entropy,
uint32_t *entropy_size
);
void cardano_delete_entropy_array(uint8_t *entropy, uint32_t bytes);
cardano_result cardano_bip39_encode(const char * const entropy_raw, unsigned long entropy_size, unsigned short *mnemonic_index, unsigned long mnemonic_size);
/*********/
/* Keys */
/*********/
#define XPRV_SIZE 96
typedef struct cardano_xprv cardano_xprv;
typedef struct cardano_xpub cardano_xpub;
cardano_xpub *cardano_xprv_delete(cardano_xprv *privkey);
cardano_xpub *cardano_xprv_to_xpub(cardano_xprv *privkey);
uint8_t *cardano_xprv_to_bytes(cardano_xprv *privkey);
cardano_xprv *cardano_xprv_from_bytes(uint8_t bytes[XPRV_SIZE]);
cardano_xpub *cardano_xpub_delete(cardano_xpub *pubkey);
/*************/
/* addresses */
/*************/
typedef struct cardano_address cardano_address;
/* check if an address is a valid protocol address.
* return 0 on success, !0 on failure. */
int cardano_address_is_valid(const char * address_base58);
cardano_address *cardano_address_new_from_pubkey(cardano_xpub *publickey);
void cardano_address_delete(cardano_address *address);
char *cardano_address_export_base58(cardano_address *address);
cardano_address *cardano_address_import_base58(const char * address_bytes);
/***********/
/* Wallet */
/***********/
typedef struct cardano_wallet cardano_wallet;
typedef struct cardano_account cardano_account;
cardano_wallet *cardano_wallet_new(const uint8_t * const entropy_ptr, unsigned long entropy_size,
const char * const password_ptr, unsigned long password_size);
void cardano_wallet_delete(cardano_wallet *);
cardano_account *cardano_account_create(cardano_wallet *wallet, const char *alias, unsigned int index);
void cardano_account_delete(cardano_account *account);
unsigned long cardano_account_generate_addresses(cardano_account *account, int internal, unsigned int from_index, unsigned long num_indices, char *addresses_ptr[]);
/****************/
/* Transactions */
/****************/
typedef struct cardano_transaction_builder cardano_transaction_builder;
typedef struct cardano_transaction_finalized cardano_transaction_finalized;
typedef struct cardano_txoptr cardano_txoptr;
typedef struct cardano_txoutput cardano_txoutput;
typedef struct cardano_txoutput cardano_txoutput;
typedef struct cardano_transaction cardano_transaction;
typedef struct cardano_signed_transaction cardano_signed_transaction;
cardano_txoptr * cardano_transaction_output_ptr_new(uint8_t txid[32], uint32_t index);
void cardano_transaction_output_ptr_delete(cardano_txoptr *txo);
cardano_txoutput * cardano_transaction_output_new(cardano_address *c_addr, uint64_t value);
void cardano_transaction_output_delete(cardano_txoutput *output);
cardano_transaction_builder * cardano_transaction_builder_new(void);
void cardano_transaction_builder_delete(cardano_transaction_builder *tb);
void cardano_transaction_builder_add_output(cardano_transaction_builder *tb, cardano_txoptr *txo);
cardano_result cardano_transaction_builder_add_input(cardano_transaction_builder *tb, cardano_txoptr *c_txo, uint64_t value);
cardano_result cardano_transaction_builder_add_change_addr(cardano_transaction_builder *tb, cardano_address *change_addr);
uint64_t cardano_transaction_builder_fee(cardano_transaction_builder *tb);
cardano_transaction *cardano_transaction_builder_finalize(cardano_transaction_builder *tb);
cardano_transaction_finalized * cardano_transaction_finalized_new(cardano_transaction *c_tx);
cardano_result cardano_transaction_finalized_add_witness(cardano_transaction_finalized *tf, uint8_t c_xprv[96], uint32_t protocol_magic, uint8_t c_txid[32]);
cardano_signed_transaction *cardano_transaction_finalized_output(cardano_transaction_finalized *tf);
#ifdef __cplusplus
}
#endif
#endif