libbtc
bitcoinclibrary
bip32.h
Go to the documentation of this file.
1 
27 #ifndef __LIBBTC_BIP32_H__
28 #define __LIBBTC_BIP32_H__
29 
30 #include "btc.h"
31 #include "chain.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <stdint.h>
38 
39 #define BTC_BIP32_CHAINCODE_SIZE 32
40 
41 typedef struct
42 {
43  uint32_t depth;
44  uint32_t fingerprint;
45  uint32_t child_num;
46  uint8_t chain_code[BTC_BIP32_CHAINCODE_SIZE];
47  uint8_t private_key[BTC_ECKEY_PKEY_LENGTH];
48  uint8_t public_key[BTC_ECKEY_COMPRESSED_LENGTH];
49 } btc_hdnode;
50 
51 
52 #define btc_hdnode_private_ckd_prime(X, I) btc_hdnode_private_ckd((X), ((I) | 0x80000000))
53 
54 
56 LIBBTC_API btc_bool btc_hdnode_from_seed(const uint8_t* seed, int seed_len, btc_hdnode* out);
59 LIBBTC_API void btc_hdnode_serialize_public(const btc_hdnode* node, const btc_chain* chain, char* str, int strsize);
60 LIBBTC_API void btc_hdnode_serialize_private(const btc_hdnode* node, const btc_chain* chain, char* str, int strsize);
61 LIBBTC_API btc_bool btc_hdnode_deserialize(const char* str, const btc_chain* chain, btc_hdnode* node);
62 
64 LIBBTC_API btc_bool btc_hd_generate_key(btc_hdnode* node, const char* keypath, const uint8_t* privkeymaster, const uint8_t* chaincode);
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 #endif // __LIBBTC_BIP32_H__
uint8_t btc_bool
Definition: btc.h:34
#define LIBBTC_API
Definition: btc.h:59
#define BTC_ECKEY_PKEY_LENGTH
Definition: btc.h:70
LIBBTC_API btc_bool btc_hdnode_deserialize(const char *str, const btc_chain *chain, btc_hdnode *node)
Definition: bip32.c:216
uint32_t child_num
Definition: bip32.h:45
#define BTC_ECKEY_COMPRESSED_LENGTH
Definition: btc.h:68
uint32_t depth
Definition: bip32.h:43
LIBBTC_API void btc_hdnode_serialize_private(const btc_hdnode *node, const btc_chain *chain, char *str, int strsize)
Definition: bip32.c:209
LIBBTC_API btc_bool btc_hdnode_from_seed(const uint8_t *seed, int seed_len, btc_hdnode *out)
Definition: bip32.c:61
LIBBTC_API void btc_hdnode_serialize_public(const btc_hdnode *node, const btc_chain *chain, char *str, int strsize)
Definition: bip32.c:203
uint32_t fingerprint
Definition: bip32.h:44
LIBBTC_API btc_bool btc_hdnode_private_ckd(btc_hdnode *inout, uint32_t i)
Definition: bip32.c:124
LIBBTC_API void btc_hdnode_fill_public_key(btc_hdnode *node)
Definition: bip32.c:178
LIBBTC_API btc_bool btc_hd_generate_key(btc_hdnode *node, const char *keypath, const uint8_t *privkeymaster, const uint8_t *chaincode)
derive btc_hdnode including private key from master private key
Definition: bip32.c:245
LIBBTC_API btc_bool btc_hdnode_public_ckd(btc_hdnode *inout, uint32_t i)
Definition: bip32.c:83
#define BTC_BIP32_CHAINCODE_SIZE
Definition: bip32.h:39