Bitcoin Core 31.99.0
P2P Digital Currency
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
15static constexpr uint32_t BIP32_UNHARDENED_FLAG = 0x0;
17static constexpr uint32_t BIP32_HARDENED_FLAG = 0x80000000;
18
21 uint32_t index;
23
26};
27
31
33[[nodiscard]] bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath);
34
36std::string WriteHDKeypath(const std::vector<uint32_t>& keypath, bool apostrophe = false);
37std::string FormatHDKeypath(const std::vector<uint32_t>& path, bool apostrophe = false);
38
40bool HasHardenedDerivation(std::span<const uint32_t> keypath);
41
42#endif // BITCOIN_UTIL_BIP32_H
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
std::string WriteHDKeypath(const std::vector< uint32_t > &keypath, bool apostrophe=false)
Write HD keypaths as strings.
Definition: bip32.cpp:72
std::string FormatHDKeypath(const std::vector< uint32_t > &path, bool apostrophe=false)
Definition: bip32.cpp:62
static constexpr uint32_t BIP32_HARDENED_FLAG
BIP32 hardened derivation flag (2^31)
Definition: bip32.h:17
static constexpr uint32_t BIP32_UNHARDENED_FLAG
BIP32 unhardened derivation index (no high bit set)
Definition: bip32.h:15
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
bool HasHardenedDerivation(std::span< const uint32_t > keypath)
Whether a parsed HD keypath contains at least one hardened derivation step.
Definition: bip32.cpp:77
The util::Expected class provides a standard way for low-level functions to return either error value...
Definition: expected.h:44
bool is_hardened
Definition: bip32.h:22
uint32_t ChildNumber() const
Derivation index with the hardened flag applied.
Definition: bip32.h:25
uint32_t index
Derivation index, without the hardened flag.
Definition: bip32.h:21