Browse Source

unecrypted wallet.dat keys reader

v0.25
pbca26 7 years ago
parent
commit
15e6cf599d
  1. 3
      package.json
  2. 1
      routes/appConfig.js
  3. 1
      routes/shepherd.js
  4. 99
      routes/shepherd/coindWalletKeys.js

3
package.json

@ -45,6 +45,7 @@
"remote-file-size": "^3.0.3",
"request": "^2.80.0",
"sha256": "^0.2.0",
"socket.io": "^1.7.3"
"socket.io": "^1.7.3",
"wif": "^2.0.6"
}
}

1
routes/appConfig.js

@ -15,7 +15,6 @@ const appConfig = {
walletUnlockTimeout: 3600,
},
cliStopTimeout: 1000,
disableKomododDownModal: false,
failedRPCAttemptsThreshold: 10,
stopNativeDaemonsOnQuit: true,
},

1
routes/shepherd.js

@ -107,6 +107,7 @@ shepherd = require('./shepherd/appInfo.js')(shepherd);
shepherd = require('./shepherd/daemonControl.js')(shepherd);
shepherd = require('./shepherd/auth.js')(shepherd);
shepherd = require('./shepherd/coins.js')(shepherd);
shepherd = require('./shepherd/coindWalletKeys.js')(shepherd);
shepherd.printDirs();

99
routes/shepherd/coindWalletKeys.js

@ -0,0 +1,99 @@
module.exports = (shepherd) => {
/*
* type: GET
*
*/
shepherd.get('/coindwalletkeys', (req, res, next) => {
const wif = require('wif');
const fs = require('fs');
const chain = req.query.chain;
// ref: https://gist.github.com/kendricktan/1e62495150ad236b38616d733aac4eb9
let _walletDatLocation = chain === 'komodo' ? `${shepherd.komodoDir}/wallet.dat` : `${shepherd.komodoDir}/${chain}/wallet.dat`;
_walletDatLocation = chain === 'CHIPS' ? `${shepherd.chipsDir}/wallet.dat` : _walletDatLocation;
try {
shepherd._fs.access(_walletDatLocation, shepherd.fs.constants.R_OK, (err) => {
if (err) {
shepherd.log(`error reading ${_walletDatLocation}`);
successObj = {
msg: 'error',
result: `error reading ${_walletDatLocation}`,
};
res.end(JSON.stringify(successObj));
} else {
shepherd.log(`reading ${_walletDatLocation}`);
fs.readFile(_walletDatLocation, (err, data) => {
if (err) {
shepherd.log(`read wallet.dat err: ${err}`);
successObj = {
msg: 'error',
result: `error reading ${_walletDatLocation}`,
};
res.end(JSON.stringify(successObj));
} else {
const re = /\x30\x81\xD3\x02\x01\x01\x04\x20(.{32})/gm;
const dataHexStr = data.toString('latin1');
privateKeys = dataHexStr.match(re);
if (!privateKeys) {
shepherd.log('wallet is encrypted?');
successObj = {
msg: 'error',
result: 'wallet is encrypted?',
};
res.end(JSON.stringify(successObj));
} else {
let _keys = [];
privateKeys = privateKeys.map(x => x.replace('\x30\x81\xD3\x02\x01\x01\x04\x20', ''));
privateKeys = privateKeys.filter((v, i, a) => a.indexOf(v) === i);
shepherd.log(`found ${privateKeys.length} keys`);
for (let i = 0; i < privateKeys.length; i++) {
const privateKey = new Buffer(Buffer.from(privateKeys[i], 'latin1').toString('hex'), 'hex');
const key = wif.encode(0xbc, privateKey, true);
const keyObj = wif.decode(key);
const wifKey = wif.encode(keyObj);
const keyPair = shepherd.bitcoinJS.ECPair.fromWIF(wifKey, shepherd.electrumJSNetworks.komodo);
const _keyPair = {
priv: keyPair.toWIF(),
pub: keyPair.getAddress(),
};
if (req.query.search) {
if (_keyPair.pub.indexOf(req.query.search) > -1) {
_keys.push(_keyPair);
}
} else {
_keys.push(_keyPair);
}
}
successObj = {
msg: 'success',
result: _keys,
};
res.end(JSON.stringify(successObj));
}
}
});
}
});
} catch (e) {
successObj = {
msg: 'error',
result: `error reading ${_walletDatLocation}`,
};
res.end(JSON.stringify(successObj));
}
});
return shepherd;
};
Loading…
Cancel
Save