hns-address/generate-address.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2025-01-27 18:23:04 +11:00
/**
* 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());
}
}
})();