forked from ElementsProject/libwally-core
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwally_bip38.h
125 lines (112 loc) · 4.02 KB
/
wally_bip38.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
#ifndef LIBWALLY_CORE_BIP38_H
#define LIBWALLY_CORE_BIP38_H
#include "wally_core.h"
#ifdef __cplusplus
extern "C" {
#endif
/*** bip38-flags BIP38 conversion flags */
#define BIP38_KEY_NETWORK_MASK 0xff /** Mask for the bottom 8 bitflags which hold the network */
#define BIP38_KEY_MAINNET 0 /** Address is for main network */
#define BIP38_KEY_TESTNET 111 /** Address is for test network */
#define BIP38_KEY_COMPRESSED 256 /** Public key is compressed */
#define BIP38_KEY_EC_MULT 512 /** EC-Multiplied key (FIXME: Not implemented) */
#define BIP38_KEY_QUICK_CHECK 1024 /** Check structure only (no password required) */
#define BIP38_KEY_RAW_MODE 2048 /** Treat bytes in as raw data */
#define BIP38_KEY_SWAP_ORDER 4096 /** Hash comes after encrypted key */
#define BIP38_SERIALIZED_LEN 39 /** Length of a raw BIP38 key in bytes */
/**
* Encode a private key in raw BIP 38 address format.
*
* :param bytes: Private key to use.
* :param bytes_len: Size of ``bytes`` in bytes. Must be `EC_PRIVATE_KEY_LEN`.
* :param pass: Password for the encoded private key.
* :param pass_len: Length of ``pass`` in bytes.
* :param flags: :ref:`bip38-flags` indicating desired behavior.
* :param bytes_out: Destination for the resulting raw BIP38 address.
* FIXED_SIZED_OUTPUT(len, bytes_out, BIP38_SERIALIZED_LEN)
*/
WALLY_CORE_API int bip38_raw_from_private_key(
const unsigned char *bytes,
size_t bytes_len,
const unsigned char *pass,
size_t pass_len,
uint32_t flags,
unsigned char *bytes_out,
size_t len);
/**
* Encode a private key in BIP 38 address format.
*
* :param bytes: Private key to use.
* :param bytes_len: Size of ``bytes`` in bytes. Must be `EC_PRIVATE_KEY_LEN`.
* :param pass: Password for the encoded private key.
* :param pass_len: Length of ``pass`` in bytes.
* :param flags: :ref:`bip38-flags` indicating desired behavior.
* :param output: Destination for the resulting BIP38 address.
*/
WALLY_CORE_API int bip38_from_private_key(
const unsigned char *bytes,
size_t bytes_len,
const unsigned char *pass,
size_t pass_len,
uint32_t flags,
char **output);
/**
* Decode a raw BIP 38 address to a private key.
*
* :param bytes: Raw BIP 38 address to decode.
* :param bytes_len: Size of ``bytes`` in bytes. Must be `BIP38_SERIALIZED_LEN`.
* :param pass: Password for the encoded private key.
* :param pass_len: Length of ``pass`` in bytes.
* :param flags: :ref:`bip38-flags` indicating desired behavior.
* :param bytes_out: Destination for the resulting private key.
* FIXED_SIZED_OUTPUT(len, bytes_out, EC_PRIVATE_KEY_LEN)
*/
WALLY_CORE_API int bip38_raw_to_private_key(
const unsigned char *bytes,
size_t bytes_len,
const unsigned char *pass,
size_t pass_len,
uint32_t flags,
unsigned char *bytes_out,
size_t len);
/**
* Decode a BIP 38 address to a private key.
*
* :param bip38: BIP 38 address to decode.
* :param pass: Password for the encoded private key.
* :param pass_len: Length of ``pass`` in bytes.
* :param flags: :ref:`bip38-flags` indicating desired behavior.
* :param bytes_out: Destination for the resulting private key.
* FIXED_SIZED_OUTPUT(len, bytes_out, EC_PRIVATE_KEY_LEN)
*/
WALLY_CORE_API int bip38_to_private_key(
const char *bip38,
const unsigned char *pass,
size_t pass_len,
uint32_t flags,
unsigned char *bytes_out,
size_t len);
/**
* Get compression and/or EC mult flags.
*
* :param bytes: Raw BIP 38 address to get the flags from.
* :param bytes_len: Size of ``bytes`` in bytes. Must be `BIP38_SERIALIZED_LEN`.
* :param written: :ref:`bip38-flags` indicating behavior.
*/
WALLY_CORE_API int bip38_raw_get_flags(
const unsigned char *bytes,
size_t bytes_len,
size_t *written);
/**
* Get compression and/or EC mult flags.
*
* :param bip38: BIP 38 address to get the flags from.
* :param written: :ref:`bip38-flags` indicating behavior.
*/
WALLY_CORE_API int bip38_get_flags(
const char *bip38,
size_t *written);
#ifdef __cplusplus
}
#endif
#endif /* LIBWALLY_CORE_BIP38_H */