C# How to determine if a bitcoin address was generated by a BIP32 pub key?

1

I want to create a boolean result method WasGeneratedBy that takes two params, a bitcoin address, and a BIP32 pub key. Is there an efficient algorithm (and library, NBitcoin?) to accomplish this?

EDIT:

I'm showing my BIP32 newbieness.. Based upon the first response I received, I would like to modify my desired method such that all required parameters are present (including path). This method gets its information from public web service so obviously that precludes any private keys or other that the user would be unlikely to submit.

I believe this should be possible given this blockchain.info example

https://blockchain.info/xpub/xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWKiKrhko4egpiMZbpiaQL2jkwSB1icqYh2cfDfVxdx4df189oLKnC5fSwqPfgyP3hooxujYzAu3fDVmz

Sean

Posted 2015-10-15T19:57:40.957

Reputation: 13

Answers

1

If you know the path and the xpubkey, you can just generate the address and see if it matches with what you expect.

If you don't know the (entire) path you can simply start trying a lot of different paths, but in principle you could spend an infinite amount of time, so in that case your function would never return false.

Jannes

Posted 2015-10-15T19:57:40.957

Reputation: 5 823

In practice, do most/all implementations of wallets using xpubkey generated addresses follow a default path? or is there really no reliable serialized means by which to exhaustively search for an address?Sean 2015-10-15T20:33:56.083

1

@Sean There isn't a widely followed standard, but one of our users made a list of common path formats: http://bitcoin.stackexchange.com/questions/36955/what-bip32-derivation-path-does-electrum-use#comment43246_36956

Nick ODell 2015-10-16T06:36:57.730

@Nick Ok, I see how different wallets could conceivably produce different series' of addresses based upon their proprietary preference for paths, however, I discovered BIP-44 defines an interrogation algorithm that assumes all your valid addresses lie before the first unused 20 addresses in a branch, and all valid branches lie before the first empty branch. So assuming the address-from-path generation formula is strictly defined, is it possible to rapidly generate the entire list of users addresses by cross-referencing generated addresses against the addresses represented in the blockchain?Sean 2015-10-16T22:16:44.297

@Sean Yes, assuming those things are true, you can enumerate the user's addresses that way.Nick ODell 2015-10-16T22:24:07.277

1

There is no such algorithm.

You need to know the path.

Pieter Wuille

Posted 2015-10-15T19:57:40.957

Reputation: 54 032

I updated the question if you wouldn't mind revisiting it :)Sean 2015-10-15T20:15:25.973