1 #ifndef LIBWALLY_CORE_BIP38_H 2 #define LIBWALLY_CORE_BIP38_H 3 4 #include "wally_core.h" 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 /** Flags for BIP38 conversion. The first 8 bits are reserved for the network */ 11 #define BIP38_KEY_MAINNET 0 /** Address is for main network */ 12 #define BIP38_KEY_TESTNET 111 /** Address is for test network */ 13 #define BIP38_KEY_COMPRESSED 256 /** Public key is compressed */ 14 #define BIP38_KEY_EC_MULT 512 /** EC-Multiplied key (FIXME: Not implemented) */ 15 #define BIP38_KEY_QUICK_CHECK 1024 /** Check structure only (no password required) */ 16 #define BIP38_KEY_RAW_MODE 2048 /** Treat bytes in as raw data */ 17 #define BIP38_KEY_SWAP_ORDER 4096 /** Hash comes after encrypted key */ 18 19 #define BIP38_SERIALIZED_LEN 39 /** Length of a raw BIP38 key in bytes */ 20 21 22 /** 23 * Encode a private key in raw BIP 38 address format. 24 * 25 * :param bytes: Private key to use. 26 * :param bytes_len: Size of ``bytes`` in bytes. Must be ``EC_PRIVATE_KEY_LEN``. 27 * :param pass: Password for the encoded private key. 28 * :param pass_len: Length of ``pass`` in bytes. 29 * :param flags: BIP38_KEY_ flags indicating desired behavior. 30 * :param bytes_out: Destination for the resulting raw BIP38 address. 31 * :param len: Size of ``bytes_out`` in bytes. Must be ``BIP38_SERIALIZED_LEN``. 32 */ 33 WALLY_CORE_API int bip38_raw_from_private_key( 34 const unsigned char *bytes, 35 size_t bytes_len, 36 const unsigned char *pass, 37 size_t pass_len, 38 uint32_t flags, 39 unsigned char *bytes_out, 40 size_t len); 41 42 /** 43 * Encode a private key in BIP 38 address format. 44 * 45 * :param bytes: Private key to use. 46 * :param bytes_len: Size of ``bytes`` in bytes. Must be ``EC_PRIVATE_KEY_LEN``. 47 * :param pass: Password for the encoded private key. 48 * :param pass_len: Length of ``pass`` in bytes. 49 * :param flags: BIP38_KEY_ flags indicating desired behavior. 50 * :param output: Destination for the resulting BIP38 address. 51 */ 52 WALLY_CORE_API int bip38_from_private_key( 53 const unsigned char *bytes, 54 size_t bytes_len, 55 const unsigned char *pass, 56 size_t pass_len, 57 uint32_t flags, 58 char **output); 59 60 /** 61 * Decode a raw BIP 38 address to a private key. 62 * 63 * :param bytes: Raw BIP 38 address to decode. 64 * :param bytes_len: Size of ``bytes`` in bytes. Must be ``BIP38_SERIALIZED_LEN``. 65 * :param pass: Password for the encoded private key. 66 * :param pass_len: Length of ``pass`` in bytes. 67 * :param flags: BIP38_KEY_ flags indicating desired behavior. 68 * :param bytes_out: Destination for the resulting private key. 69 * :param len: Size of ``bytes_out`` in bytes. Must be ``EC_PRIVATE_KEY_LEN``. 70 */ 71 WALLY_CORE_API int bip38_raw_to_private_key( 72 const unsigned char *bytes, 73 size_t bytes_len, 74 const unsigned char *pass, 75 size_t pass_len, 76 uint32_t flags, 77 unsigned char *bytes_out, 78 size_t len); 79 80 /** 81 * Decode a BIP 38 address to a private key. 82 * 83 * :param bip38: BIP 38 address to decode. 84 * :param pass: Password for the encoded private key. 85 * :param pass_len: Length of ``pass`` in bytes. 86 * :param flags: BIP38_KEY_ flags indicating desired behavior. 87 * :param bytes_out: Destination for the resulting private key. 88 * :param len: Size of ``bytes_out`` in bytes. Must be ``EC_PRIVATE_KEY_LEN``. 89 */ 90 WALLY_CORE_API int bip38_to_private_key( 91 const char *bip38, 92 const unsigned char *pass, 93 size_t pass_len, 94 uint32_t flags, 95 unsigned char *bytes_out, 96 size_t len); 97 98 /** 99 * Get compression and/or EC mult flags. 100 * 101 * :param bytes: Raw BIP 38 address to get the flags from. 102 * :param bytes_len: Size of ``bytes`` in bytes. Must be ``BIP38_SERIALIZED_LEN``. 103 * :param written: BIP38_KEY_ flags indicating behavior. 104 */ 105 WALLY_CORE_API int bip38_raw_get_flags( 106 const unsigned char *bytes, 107 size_t bytes_len, 108 size_t *written); 109 110 /** 111 * Get compression and/or EC mult flags. 112 * 113 * :param bip38: BIP 38 address to get the flags from. 114 * :param written: BIP38_KEY_ flags indicating behavior. 115 */ 116 WALLY_CORE_API int bip38_get_flags( 117 const char *bip38, 118 size_t *written); 119 120 #ifdef __cplusplus 121 } 122 #endif 123 124 #endif /* LIBWALLY_CORE_BIP38_H */ 125