diff --git a/README.md b/README.md index 08ea05e..3cbbf31 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ # hns-address +## Setup + +```bash +git clone https://git.woodburn.au/nathanwoodburn/hns-address.git +cd hns-address +npm install hsd +``` + +## Find an address + +Edit `find-address.js` and fill in these fields: + +- `ACCOUNT_XPUB`: the account extended public key +- `SEARCH_ADDRESS`: the address to search for + + +```bash +node find-address.js +``` + +## Generate addresses + +Edit `generate-address.js` and fill in these fields: + +- `ACCOUNT_XPUB`: the account extended public key +- `START`: the starting index +- `END`: the ending index + +```bash +node generate-address.js +``` +Probably best to save the output to a file. +```bash +node generate-address.js > addresses.txt +``` \ No newline at end of file diff --git a/generate-address.js b/generate-address.js new file mode 100644 index 0000000..87cfcc3 --- /dev/null +++ b/generate-address.js @@ -0,0 +1,39 @@ +/** + * This script finds an address given an account extended public key + * Usage: edit these fields below and run it like `node find-address.js` + */ + +const assert = require('node:assert/strict'); +const HDPublicKey = require('hsd/lib/hd/public'); +const Address = require('hsd/lib/primitives/address'); + +// ********** +// FILL THESE +// ********** +const NETWORK = 'main'; +const ACCOUNT_XPUB = 'xpub6BvF6DnLZRV6my62FuQ8nw5TRebL8qr9Wa7u2tE1aEedHWBt4XAfSaNTmP1SM2nXErGWSzxRAHVwqstPzRrsXtA2vn1a4KzLwAVEgLNmfca'; // should start with: xpub, rpub, etc. + +const [START, END] = [0, 1000]; + +(() => { + const account = HDPublicKey.fromBase58(ACCOUNT_XPUB, NETWORK); + console.log('[*] Using account public key:', account.xpubkey(NETWORK)); + console.log('[*] Generating addresses', START, 'to', END); + + const len = END - START; + assert((len >>> 0) > 0); + + for (let i = START; i <= END; i++) { + + /** @type {Buffer[]} */ + const keys = [ + account.derive(0).derive(i).publicKey, // receive + account.derive(1).derive(i).publicKey, // change + ]; + + for (const [branch, key] of keys.entries()) { + const addr = Address.fromPubkey(key); + console.log(addr.toString()); + } + } +})(); \ No newline at end of file