2025-01-27 18:23:04 +11:00
/ * *
2025-01-27 18:24:47 +11:00
* This script generates addresses given an account extended public key
* Usage : edit these fields below and run it like ` node generate-address.js `
2025-01-27 18:23:04 +11:00
* /
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 ( ) ) ;
}
}
} ) ( ) ;