Mayank
4 years ago
6 changed files with 139 additions and 25 deletions
@ -0,0 +1,21 @@ |
|||
/* eslint-disable no-unused-vars, no-magic-numbers */ |
|||
const constants = require('utils/const.js'); |
|||
const NodeError = require('models/errors.js').NodeError; |
|||
|
|||
function handleError(error, req, res, next) { |
|||
|
|||
// If a incorrect password was given, respond with 403 instead of 401.
|
|||
// Reasoning: sending 401 on a request such as when the user tries to
|
|||
// change password with an incorrect password or enters an incorrect
|
|||
// password to view seed will log him out due to interceptor on front-end
|
|||
if (error.message && error.message === 'Incorrect password') { |
|||
|
|||
return next(new NodeError('Incorrect password', 403)); |
|||
} else { |
|||
|
|||
return next(); |
|||
} |
|||
|
|||
} |
|||
|
|||
module.exports = handleError; |
@ -0,0 +1,73 @@ |
|||
const axios = require('axios'); |
|||
|
|||
// axios requires http
|
|||
const lnapiUrl = process.env.LND_API_URL || 'http://localhost'; |
|||
const lnapiPort = process.env.LND_API_URL || 3005; |
|||
|
|||
async function changePassword(currentPassword, newPassword, jwt) { |
|||
|
|||
const headers = { |
|||
headers: { |
|||
Authorization: 'JWT ' + jwt, |
|||
} |
|||
}; |
|||
|
|||
const body = { |
|||
currentPassword, |
|||
newPassword, |
|||
}; |
|||
|
|||
return axios |
|||
.post(lnapiUrl + ':' + lnapiPort + '/v1/lnd/wallet/changePassword', body, headers); |
|||
} |
|||
|
|||
async function initializeWallet(password, seed, jwt) { |
|||
const headers = { |
|||
headers: { |
|||
Authorization: 'JWT ' + jwt, |
|||
} |
|||
}; |
|||
|
|||
const body = { |
|||
password, |
|||
seed, |
|||
}; |
|||
|
|||
return axios |
|||
.post(lnapiUrl + ':' + lnapiPort + '/v1/lnd/wallet/init', body, headers); |
|||
} |
|||
|
|||
async function unlockLnd(password, jwt) { |
|||
|
|||
const headers = { |
|||
headers: { |
|||
Authorization: 'JWT ' + jwt, |
|||
} |
|||
}; |
|||
|
|||
const body = { |
|||
password, |
|||
}; |
|||
|
|||
return axios |
|||
.post(lnapiUrl + ':' + lnapiPort + '/v1/lnd/wallet/unlock', body, headers); |
|||
} |
|||
|
|||
async function getBitcoindAddresses(jwt) { |
|||
|
|||
const headers = { |
|||
headers: { |
|||
Authorization: 'JWT ' + jwt, |
|||
} |
|||
}; |
|||
|
|||
return axios |
|||
.get(lnapiUrl + ':' + lnapiPort + '/v1/bitcoind/info/addresses', headers); |
|||
} |
|||
|
|||
module.exports = { |
|||
changePassword, |
|||
initializeWallet, |
|||
unlockLnd, |
|||
getBitcoindAddresses, |
|||
}; |
Loading…
Reference in new issue