Delete ** * 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/find-address.js
This commit is contained in:
parent
4b7f86b68f
commit
ecc4b47dff
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* 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 SEARCH_ADDRESS = 'hs1q3tlnmk9sp2luxdvkdcyvtj8ucj5pa4hwvr8ql6';
|
||||
|
||||
const [START, END] = [0, 0x7fffffff];
|
||||
// const [START, END] = [0, 100];
|
||||
|
||||
(() => {
|
||||
const account = HDPublicKey.fromBase58(ACCOUNT_XPUB, NETWORK);
|
||||
console.log('[*] Using account public key:', account.xpubkey(NETWORK));
|
||||
|
||||
const expectedAddr = new Address(SEARCH_ADDRESS, NETWORK);
|
||||
console.log('[*] Searching for address:', expectedAddr.toString(NETWORK));
|
||||
|
||||
const len = END - START;
|
||||
assert((len >>> 0) > 0);
|
||||
|
||||
for (let i = START; i <= END; i++) {
|
||||
if (i % 1e3 === 0) {
|
||||
console.log(`[${i}/${len}] searching...`);
|
||||
}
|
||||
|
||||
/** @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);
|
||||
if (expectedAddr.equals(addr)) {
|
||||
console.log('Found address', {
|
||||
address: addr,
|
||||
branch: branch,
|
||||
index: i,
|
||||
publicKey: key.toString('hex'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Searched index from ${START} to ${END}. Address not found.`);
|
||||
})();
|
Loading…
Reference in New Issue
Block a user