pub struct Matcher<'a, 'b> {
pub addrs: &'a HashSet<String>,
pub mnems: &'b Vec<Mnemonic>,
pub logging: bool,
}Expand description
The Matcher struct holds references to a set of Bitcoin addresses and a collection of mnemonic phrases. It generates addresses from mnemonics using derivation standards and checks whether they match addresses in its stored set. This can be useful, for example, to verify wallet addresses or scan for address matches.
§Fields
addrs: A reference to a HashSet of Bitcoin addresses (each represented as a String).mnems: A reference to a Vec of mnemonic phrases (from bip39) used for key derivation.logging: A boolean flag to enable or disable logging during operations.
Fields§
§addrs: &'a HashSet<String>§mnems: &'b Vec<Mnemonic>§logging: boolImplementations§
Source§impl<'a, 'b> Matcher<'a, 'b>
impl<'a, 'b> Matcher<'a, 'b>
Sourcepub fn new(
addrs: &'a HashSet<String>,
mnems: &'b Vec<Mnemonic>,
logging: bool,
) -> Matcher<'a, 'b>
pub fn new( addrs: &'a HashSet<String>, mnems: &'b Vec<Mnemonic>, logging: bool, ) -> Matcher<'a, 'b>
Creates a new Matcher instance.
§Arguments
addrs- A reference to the set of Bitcoin addresses to match against.mnems- A reference to the vector of mnemonic phrases used for deriving keys.logging- A flag specifying whether logging should be enabled.
§Examples
use std::{
collections::HashSet,
str::FromStr,
};
use bip39::Mnemonic;
use bit_digger::matcher::Matcher;
let addresses: HashSet<String> = ["1BGLgRL7EiFxS9H616bfoJPjSugKudECCn"]
.iter()
.map(|s| s.to_string())
.collect();
let mnem = Mnemonic::from_str("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about").unwrap();
let mnems = vec![mnem];
let matcher = Matcher::new(&addresses, &mnems, false);
// matcher now holds references to the addresses set and mnemonic vector.Sourcepub fn match_in(
&self,
addr_to_gen_per_mnem: usize,
amount: Option<Vec<(DerivationStandard<'_, '_>, usize)>>,
) -> Result<HashMap<&Mnemonic, Vec<String>>, MatcherError>
pub fn match_in( &self, addr_to_gen_per_mnem: usize, amount: Option<Vec<(DerivationStandard<'_, '_>, usize)>>, ) -> Result<HashMap<&Mnemonic, Vec<String>>, MatcherError>
Matches generated addresses against the stored addresses.
This method generates addresses for each mnemonic by using the provided derivation amounts.
If amount is None, it automatically infers how many addresses to generate based on the
stored addresses and supported derivation standards. Then it returns a map of each mnemonic
reference to the vector of addresses (as Strings) that were found in the matcher’s address set.
§Arguments
addr_to_gen_per_mnem- The total number of addresses to generate per mnemonic.amount- An optional vector of tuples of the form(DerivationStandard, usize)specifying the number of addresses to generate for each derivation standard.
§Returns
A HashMap mapping each mnemonic (by reference) to a Vec of matching Bitcoin addresses.
§Errors
Returns a MatcherError if key derivation or address generation fails.
§Examples
use std::{
collections::HashSet,
str::FromStr,
};
use bip39::Mnemonic;
use bit_digger::matcher::{Matcher, DerivationStandard};
let addresses: HashSet<String> = ["1BGLgRL7EiFxS9H616bfoJPjSugKudECCn"].iter()
.map(|s| s.to_string())
.collect();
let mnem = Mnemonic::from_str("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about").unwrap();
let mnems = vec![mnem];
let matcher = Matcher::new(&addresses, &mnems, false);
let amount = vec![
(DerivationStandard::new("m/44'/0'/0'/0/", "1"), 10),
(DerivationStandard::new("m/49'/0'/0'/0/", "3"), 10),
(DerivationStandard::new("m/84'/0'/0'/0/", "bc1q"), 10),
];
let result = matcher.match_in(30, Some(amount)).unwrap();
// The result maps the mnemonic to its matched addresses.Sourcepub fn generate_addresses(
amount: &[(DerivationStandard<'_, '_>, usize)],
mnemonic: &Mnemonic,
) -> Result<Vec<String>, MatcherError>
pub fn generate_addresses( amount: &[(DerivationStandard<'_, '_>, usize)], mnemonic: &Mnemonic, ) -> Result<Vec<String>, MatcherError>
Generates Bitcoin addresses from a mnemonic seed using the specified derivation standards.
For each tuple in amount (which consists of a DerivationStandard and a count), this method
modifies the derivation path by appending the index and derives the corresponding Bitcoin address
using BIP32/BIP39. The generated addresses are returned as a vector of Strings.
§Arguments
amount- A slice of tuples specifying for each derivation standard (and its base path) how many addresses to generate.mnemonic- The mnemonic seed used to derive keys and generate addresses.
§Returns
A Vec of generated Bitcoin addresses (as Strings).
§Errors
Returns a MatcherError if key derivation or address generation fails.
/// # Examples
use bip39::Mnemonic;
use bit_digger::matcher::{Matcher, DerivationStandard};
use std::str::FromStr;
let mnemonic = Mnemonic::from_str("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about").unwrap();
let amount = vec![
(DerivationStandard::new("m/44'/0'/0'/0/", "1"), 10),
(DerivationStandard::new("m/49'/0'/0'/0/", "3"), 10),
(DerivationStandard::new("m/84'/0'/0'/0/", "bc1q"), 10),
];
let addresses = Matcher::generate_addresses(&amount, &mnemonic).unwrap();
// addresses now holds the generated Bitcoin addresses.