forked from breadwallet/breadwallet-core
-
Notifications
You must be signed in to change notification settings - Fork 46
/
BRBIP39Mnemonic.h
65 lines (53 loc) · 2.86 KB
/
BRBIP39Mnemonic.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
//
// BRBIP39Mnemonic.h
//
// Created by Aaron Voisine on 9/7/15.
// Copyright (c) 2015 breadwallet LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef BRBIP39Mnemonic_h
#define BRBIP39Mnemonic_h
#include <stddef.h>
#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
#endif
// BIP39 is method for generating a deterministic wallet seed from a mnemonic phrase
// https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
// Starting TIME Sync block Notes
// 1618643881 2036160 Sync starts in April 2018
// 1619999000 Sync starts in April 2021
#define BIP39_CREATION_TIME 1464739200 // oldest possible BIP39 phrase creation time, Wednesday, June 1, 2016 12:00:00 AM
#define MID_BLOCK_TIME 1524838967 // 4/27/2018 2:22:47 PM - Blockheight: 1411200
#define RECENT_BLOCK_TIME 1618643881 // 4/17/2021 7:18:01 AM - Blockheight: 2036160
#define BIP39_WORDLIST_COUNT 2048 // number of words in a BIP39 wordlist
// returns number of bytes written to phrase including NULL terminator, or phraseLen needed if phrase is NULL
size_t BRBIP39Encode(char *phrase, size_t phraseLen, const char *wordList[], const uint8_t *data, size_t dataLen);
// returns number of bytes written to data, or dataLen needed if data is NULL
size_t BRBIP39Decode(uint8_t *data, size_t dataLen, const char *wordList[], const char *phrase);
// verifies that all phrase words are contained in wordlist and checksum is valid
int BRBIP39PhraseIsValid(const char *wordList[], const char *phrase);
// key64 must hold 64 bytes (512 bits), phrase and passphrase must be unicode NFKD normalized
// http://www.unicode.org/reports/tr15/#Norm_Forms
// BUG: does not currently support passphrases containing NULL characters
void BRBIP39DeriveKey(void *key64, const char *phrase, const char *passphrase);
#ifdef __cplusplus
}
#endif
#endif // BRBIP39Mnemonic_h