Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use static address #926

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/idl/wallet/configuration.djinni
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Configuration = interface +c {
const KEYCHAIN_DERIVATION_SCHEME: string = "KEYCHAIN_DERIVATION_SCHEME";
# Sets the observable range for HD keychains (BIP32 based).
const KEYCHAIN_OBSERVABLE_RANGE: string = "KEYCHAIN_OBSERVABLE_RANGE";
# Use a static address for receive & change.
const KEYCHAIN_STATIC_ADDRESS: string = "KEYCHAIN_STATIC_ADDRESS";

# Selects the blockchain explorer engine (Ledger's API, Electrum server, RPC):
const BLOCKCHAIN_EXPLORER_ENGINE: string = "BLOCKCHAIN_EXPLORER_ENGINE";
Expand Down
2 changes: 2 additions & 0 deletions core/src/api/Configuration.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions core/src/api/Configuration.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ namespace ledger {

BitcoinLikeKeychain::Address CommonBitcoinLikeKeychains::getFreshAddress(BitcoinLikeKeychain::KeyPurpose purpose) {
KeychainPersistentState state = getState();
if (getConfiguration()->getBoolean(api::Configuration::KEYCHAIN_STATIC_ADDRESS).value_or(false)) {
return derive(purpose, 0);
}
return derive(purpose, (purpose == KeyPurpose::RECEIVE ? state.maxConsecutiveReceiveIndex : state.maxConsecutiveChangeIndex));
}

Expand All @@ -214,6 +217,10 @@ namespace ledger {

std::vector<BitcoinLikeKeychain::Address>
CommonBitcoinLikeKeychains::getFreshAddresses(BitcoinLikeKeychain::KeyPurpose purpose, size_t n) {
if (getConfiguration()->getBoolean(api::Configuration::KEYCHAIN_STATIC_ADDRESS).value_or(false)) {
return {derive(purpose, 0)};
}

KeychainPersistentState state = getState();
auto startOffset = (purpose == KeyPurpose::RECEIVE) ? state.maxConsecutiveReceiveIndex : state.maxConsecutiveChangeIndex;
std::vector<BitcoinLikeKeychain::Address> result(n);
Expand Down