Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
util
bip32.h
Go to the documentation of this file.
1
// Copyright (c) 2019-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_UTIL_BIP32_H
6
#define BITCOIN_UTIL_BIP32_H
7
8
#include <cstdint>
9
#include <span>
10
#include <string>
11
#include <
util/expected.h
>
12
#include <vector>
13
15
static
constexpr
uint32_t
BIP32_UNHARDENED_FLAG
= 0x0;
17
static
constexpr
uint32_t
BIP32_HARDENED_FLAG
= 0x80000000;
18
19
struct
KeyPathElement
{
21
uint32_t
index
;
22
bool
is_hardened
;
23
25
uint32_t
ChildNumber
()
const
{
return
index
| (
is_hardened
?
BIP32_HARDENED_FLAG
:
BIP32_UNHARDENED_FLAG
); }
26
};
27
30
util::Expected<KeyPathElement, std::string>
ParseKeyPathElement
(std::span<const char> elem);
31
33
[[nodiscard]]
bool
ParseHDKeypath
(
const
std::string& keypath_str, std::vector<uint32_t>& keypath);
34
36
std::string
WriteHDKeypath
(
const
std::vector<uint32_t>& keypath,
bool
apostrophe =
false
);
37
std::string
FormatHDKeypath
(
const
std::vector<uint32_t>& path,
bool
apostrophe =
false
);
38
40
bool
HasHardenedDerivation
(std::span<const uint32_t> keypath);
41
42
#endif
// BITCOIN_UTIL_BIP32_H
ParseHDKeypath
bool ParseHDKeypath(const std::string &keypath_str, std::vector< uint32_t > &keypath)
Parse an HD keypaths like "m/7/0'/2000".
Definition
bip32.cpp:41
FormatHDKeypath
std::string FormatHDKeypath(const std::vector< uint32_t > &path, bool apostrophe)
Definition
bip32.cpp:62
WriteHDKeypath
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath, bool apostrophe)
Write HD keypaths as strings.
Definition
bip32.cpp:72
ParseKeyPathElement
util::Expected< KeyPathElement, std::string > ParseKeyPathElement(std::span< const char > elem)
Parse a single key path element like "0", "0'", or "0h".
Definition
bip32.cpp:17
HasHardenedDerivation
bool HasHardenedDerivation(std::span< const uint32_t > keypath)
Whether a parsed HD keypath contains at least one hardened derivation step.
Definition
bip32.cpp:77
BIP32_HARDENED_FLAG
static constexpr uint32_t BIP32_HARDENED_FLAG
BIP32 hardened derivation flag (2^31).
Definition
bip32.h:17
BIP32_UNHARDENED_FLAG
static constexpr uint32_t BIP32_UNHARDENED_FLAG
BIP32 unhardened derivation index (no high bit set).
Definition
bip32.h:15
util::Expected
The util::Expected class provides a standard way for low-level functions to return either error value...
Definition
expected.h:44
expected.h
KeyPathElement
Definition
bip32.h:19
KeyPathElement::is_hardened
bool is_hardened
Definition
bip32.h:22
KeyPathElement::ChildNumber
uint32_t ChildNumber() const
Derivation index with the hardened flag applied.
Definition
bip32.h:25
KeyPathElement::index
uint32_t index
Derivation index, without the hardened flag.
Definition
bip32.h:21
Generated on
for Bitcoin Core by
1.18.0