You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 lines
2.0 KiB

const bs58check = require('bs58check');
const bitcoinZcash = require('bitcoinjs-lib-zcash');
const bitcoin = require('bitcoinjs-lib');
module.exports = (shepherd) => {
shepherd.post('/electrum/login', (req, res, next) => {
let _wifError = false;
for (let key in shepherd.electrumCoins) {
if (key !== 'auth') {
const _abbr = key;
const _seed = req.body.seed;
let keys;
let isWif = false;
try {
bs58check.decode(_seed);
isWif = true;
} catch (e) {}
if (isWif) {
try {
let key = shepherd.isZcash(_abbr.toLowerCase()) ? bitcoinZcash.ECPair.fromWIF(_seed, shepherd.getNetworkData(_abbr.toLowerCase()), true) : bitcoin.ECPair.fromWIF(_seed, shepherd.getNetworkData(_abbr.toLowerCase()), true);
keys = {
priv: key.toWIF(),
pub: key.getAddress(),
};
} catch (e) {
_wifError = true;
break;
}
} else {
keys = shepherd.seedToWif(_seed, shepherd.findNetworkObj(_abbr), req.body.iguana);
}
shepherd.electrumKeys[_abbr] = {
priv: keys.priv,
pub: keys.pub,
};
}
}
shepherd.electrumCoins.auth = true;
// shepherd.log(JSON.stringify(shepherd.electrumKeys, null, '\t'), true);
const successObj = {
msg: _wifError ? 'error' : 'success',
result: 'true',
};
res.end(JSON.stringify(successObj));
});
shepherd.post('/electrum/lock', (req, res, next) => {
shepherd.electrumCoins.auth = false;
shepherd.electrumKeys = {};
const successObj = {
msg: 'success',
result: 'true',
};
res.end(JSON.stringify(successObj));
});
shepherd.post('/electrum/logout', (req, res, next) => {
shepherd.electrumCoins = {
auth: false,
};
shepherd.electrumKeys = {};
const obj = {
msg: 'success',
result: 'result',
};
res.end(JSON.stringify(obj));
});
return shepherd;
};