feat: Add generator script
This commit is contained in:
parent
be688217c0
commit
85d8c13311
35
README.md
35
README.md
@ -1,2 +1,37 @@
|
|||||||
# hns-address
|
# 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
|
||||||
|
```
|
39
generate-address.js
Normal file
39
generate-address.js
Normal file
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user