Generalize keypath parsing over account id.
This commit is contained in:
parent
f65d6f63ee
commit
7860d6ede3
|
@ -133,9 +133,9 @@ TEST(ZIP32, TestVectors) {
|
|||
testing::ElementsAreArray({ 0x03, 0x0f, 0xfb, 0x26, 0x3a, 0x93, 0x9e, 0x23, 0x0e, 0x96, 0xdd }));
|
||||
}
|
||||
|
||||
TEST(ZIP32, ParseZip32KeypathAccount) {
|
||||
TEST(ZIP32, ParseHDKeypathAccount) {
|
||||
auto expect_account = [](std::string sAccount, long expected) {
|
||||
auto result = libzcash::ParseZip32KeypathAccount(sAccount);
|
||||
auto result = libzcash::ParseHDKeypathAccount(32, sAccount);
|
||||
EXPECT_TRUE(result.has_value());
|
||||
EXPECT_EQ(result.value(), expected);
|
||||
};
|
||||
|
|
|
@ -365,8 +365,8 @@ std::optional<ZcashdUnifiedAddress> ZcashdUnifiedFullViewingKey::Address(diversi
|
|||
return ua;
|
||||
}
|
||||
|
||||
std::optional<unsigned long> ParseZip32KeypathAccount(const std::string& keyPath) {
|
||||
std::regex pattern("m/32'/[0-9]+'/([0-9]+)'.*");
|
||||
std::optional<unsigned long> ParseHDKeypathAccount(uint32_t accountId, const std::string& keyPath) {
|
||||
std::regex pattern("m/" + std::to_string(accountId) + "'/[0-9]+'/([0-9]+)'.*");
|
||||
std::smatch matches;
|
||||
if (std::regex_match(keyPath, matches, pattern)) {
|
||||
return stoul(matches[1]);
|
||||
|
|
|
@ -382,7 +382,7 @@ public:
|
|||
ZcashdUnifiedFullViewingKey ToFullViewingKey() const;
|
||||
};
|
||||
|
||||
std::optional<unsigned long> ParseZip32KeypathAccount(const std::string& keyPath);
|
||||
std::optional<unsigned long> ParseHDKeypathAccount(uint32_t accountId, const std::string& keyPath);
|
||||
|
||||
class Bip44AccountChains {
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue