Browse Source

pin rename, delete

custom-ac-example
pbca26 7 years ago
parent
commit
a367009515
  1. 4
      main.js
  2. 6
      routes/shepherd/electrum/transactions.js
  3. 132
      routes/shepherd/pin.js

4
main.js

@ -255,8 +255,8 @@ function createWindow(status, hideLoadingWindow) {
shepherd.setVar('appBasicInfo', appBasicInfo);
shepherd.setVar('appSessionHash', appSessionHash);
// load our index.html (i.e. easyDEX GUI)
shepherd.writeLog('show edex gui');
// load our index.html (i.e. Agama GUI)
shepherd.writeLog('show agama gui');
mainWindow.appConfig = appConfig;
mainWindow.appConfigSchema = shepherd.appConfigSchema;
mainWindow.arch = arch();

6
routes/shepherd/electrum/transactions.js

@ -3,6 +3,8 @@ const Promise = require('bluebird');
const MAX_VIN_LENGTH = 150; // parse up to MAX_VIN_LENGTH vins
// TODO: add z -> pub, pub -> z flag for zcash forks
module.exports = (shepherd) => {
shepherd.sortTransactions = (transactions, sortBy) => {
return transactions.sort((b, a) => {
@ -244,10 +246,6 @@ module.exports = (shepherd) => {
}
});
} else {
/*if (_network.isZcash) {
} else {*/
const _parsedTx = {
network: decodedTx.network,
format: 'cant parse',

132
routes/shepherd/pin.js

@ -27,7 +27,7 @@ module.exports = (shepherd) => {
pub: keyPair.getAddress(),
priv: keyPair.toWIF(),
};
const pubkey = keyPair.getAddress();
let pubkey = req.body.pubkey ? req.body.pubkey : keyPair.getAddress();
if (passwdStrength(_pin) < 29) {
shepherd.log('seed storage weak pin!');
@ -39,20 +39,38 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(returnObj));
} else {
const encryptedString = aes256.encrypt(req.body.key, req.body.string);
const _customPinFilenameTest = /^[0-9a-zA-Z-_]+$/g;
fs.writeFile(`${shepherd.agamaDir}/shepherd/pin/${pubkey}.pin`, encryptedString, (err) => {
if (err) {
shepherd.log('error writing pin file');
}
if (_customPinFilenameTest.test(pubkey)) {
const encryptedString = aes256.encrypt(req.body.key, req.body.string);
fs.writeFile(`${shepherd.agamaDir}/shepherd/pin/${pubkey}.pin`, encryptedString, (err) => {
if (err) {
shepherd.log('error writing pin file');
const returnObj = {
msg: 'error',
result: 'error writing pin file',
};
res.end(JSON.stringify(returnObj));
} else {
const returnObj = {
msg: 'success',
result: pubkey,
};
res.end(JSON.stringify(returnObj));
}
});
} else {
const returnObj = {
msg: 'success',
result: pubkey,
msg: 'error',
result: 'pin file name can only contain alphanumeric characters, dash "-" and underscore "_"',
};
res.end(JSON.stringify(returnObj));
});
}
}
} else {
const _paramsList = [
@ -191,5 +209,101 @@ module.exports = (shepherd) => {
}
});
shepherd.post('/modifypin', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
const pubkey = req.body.pubkey;
if (pubkey) {
if (fs.existsSync(`${shepherd.agamaDir}/shepherd/pin/${pubkey}.pin`)) {
fs.readFile(`${shepherd.agamaDir}/shepherd/pin/${pubkey}.pin`, 'utf8', (err, data) => {
if (err) {
const errorObj = {
msg: 'error',
result: err,
};
res.end(JSON.stringify(errorObj));
} else {
if (req.body.delete) {
fs.unlinkSync(`${shepherd.agamaDir}/shepherd/pin/${pubkey}.pin`);
const returnObj = {
msg: 'success',
result: `${pubkey}.pin is removed`,
};
res.end(JSON.stringify(returnObj));
} else {
const pubkeynew = req.body.pubkeynew;
const _customPinFilenameTest = /^[0-9a-zA-Z-_]+$/g;
if (pubkeynew) {
if (_customPinFilenameTest.test(pubkeynew)) {
fs.writeFile(`${shepherd.agamaDir}/shepherd/pin/${pubkeynew}.pin`, data, (err) => {
if (err) {
shepherd.log('error writing pin file');
const returnObj = {
msg: 'error',
result: 'error writing pin file',
};
res.end(JSON.stringify(returnObj));
} else {
fs.unlinkSync(`${shepherd.agamaDir}/shepherd/pin/${pubkey}.pin`);
const returnObj = {
msg: 'success',
result: pubkeynew,
};
res.end(JSON.stringify(returnObj));
}
});
} else {
const returnObj = {
msg: 'error',
result: 'pin file name can only contain alphanumeric characters, dash "-" and underscore "_"',
};
res.end(JSON.stringify(returnObj));
}
} else {
const returnObj = {
msg: 'error',
result: 'missing param pubkeynew',
};
res.end(JSON.stringify(returnObj));
}
}
}
});
} else {
const errorObj = {
msg: 'error',
result: `file ${pubkey}.pin doesnt exist`,
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'missing pubkey param',
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;
};
Loading…
Cancel
Save