Struct Matcher

Source
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: bool

Implementations§

Source§

impl<'a, 'b> Matcher<'a, 'b>

Source

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.
Source

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.
Source

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.

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for Matcher<'a, 'b>

§

impl<'a, 'b> RefUnwindSafe for Matcher<'a, 'b>

§

impl<'a, 'b> Send for Matcher<'a, 'b>

§

impl<'a, 'b> Sync for Matcher<'a, 'b>

§

impl<'a, 'b> Unpin for Matcher<'a, 'b>

§

impl<'a, 'b> UnwindSafe for Matcher<'a, 'b>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.