Merge pull request #45 from shocknet/onboarding-improvs

Onboarding improvs
This commit is contained in:
Daniel Lugo 2020-03-13 16:56:06 -04:00 committed by GitHub
commit d9186b066a
3 changed files with 72 additions and 103 deletions

View file

@ -5,7 +5,7 @@
"main": "src/server.js",
"scripts": {
"start": "node --experimental-modules src/server.js",
"dev": "node main.js -h 0.0.0.0",
"dev": "node --trace-warnings main.js -h 0.0.0.0",
"dev:watch": "nodemon main.js -- -h 0.0.0.0",
"test": "jest --no-cache",
"test:watch": "jest --no-cache --watch",

View file

@ -13,8 +13,9 @@ const Encryption = require('../../../utils/encryptionStore')
/** @type {import('../contact-api/SimpleGUN').ISEA} */
// @ts-ignore
const SEAx = require('gun/sea')
// @ts-ignore
SEAx.throw = true
// Re-enable in the future, when SEA errors inside user.auth/etc actually
// propagate up.
// SEAx.throw = true
/** @type {import('../contact-api/SimpleGUN').ISEA} */
const mySEA = {}
@ -315,7 +316,10 @@ const authenticate = async (alias, pass, __user) => {
return ack.sea.pub
} else {
throw new Error('Unknown error.')
logger.error(
`Unknown error, wrong password? Ack looks like: ${JSON.stringify(ack)}`
)
throw new Error(`Didn't work, bad password?`)
}
}

View file

@ -443,47 +443,6 @@ module.exports = async (
}
});
app.post("/api/lnd/connect", (req, res) => {
const { lightning, walletUnlocker } = LightningServices.services;
const args = {
wallet_password: Buffer.from(req.body.password, "utf-8")
};
lightning.getInfo({}, async err => {
if (err) {
// try to unlock wallet
await recreateLnServices();
return walletUnlocker.unlockWallet(args, async unlockErr => {
if (unlockErr) {
unlockErr.error = unlockErr.message;
logger.error("Unlock Error:", unlockErr);
const health = await checkHealth();
if (health.LNDStatus.success) {
res.status(400);
res.json({ field: "WalletUnlocker", errorMessage: unlockErr.message });
} else {
res.status(500);
res.json({ errorMessage: "LND is down" });
}
} else {
await recreateLnServices();
mySocketsEvents.emit("updateLightning");
const token = await auth.generateToken();
res.json({
authorization: token
});
}
});
}
const token = await auth.generateToken();
return res.json({
authorization: token
});
});
});
app.post("/api/lnd/wallet", async (req, res) => {
try {
const { walletUnlocker } = LightningServices.services;
@ -640,66 +599,72 @@ module.exports = async (
});
app.post("/api/lnd/wallet/existing", async (req, res) => {
const { password, alias } = req.body;
const healthResponse = await checkHealth();
const exists = await walletExists();
if (!exists) {
return res.status(500).json({
field: "wallet",
errorMessage: "LND wallet does not exist, please create a new one"
});
}
if (!alias) {
return res.status(400).json({
field: "alias",
errorMessage: "Please specify an alias for your wallet"
});
}
if (!password) {
return res.status(400).json({
field: "password",
errorMessage: "Please specify a password for your wallet alias"
});
}
if (password.length < 8) {
return res.status(400).json({
field: "password",
errorMessage: "Please specify a password that's longer than 8 characters"
});
}
if (healthResponse.LNDStatus.service !== "walletUnlocker") {
return res.status(400).json({
field: "wallet",
errorMessage: "Wallet is already unlocked. Please restart your LND instance and try again."
});
}
try {
await unlockWallet(password);
} catch(err) {
return res.status(401).json({
field: "wallet",
errorMessage: "Invalid LND wallet password"
});
}
// Register user after verifying wallet password
const publicKey = await GunDB.register(alias, password);
// Generate Access Token
const token = await auth.generateToken();
res.json({
authorization: token,
user: {
alias,
publicKey
const { password, alias } = req.body;
const healthResponse = await checkHealth();
const exists = await walletExists();
if (!exists) {
return res.status(500).json({
field: "wallet",
errorMessage: "LND wallet does not exist, please create a new one"
});
}
})
if (!alias) {
return res.status(400).json({
field: "alias",
errorMessage: "Please specify an alias for your wallet"
});
}
if (!password) {
return res.status(400).json({
field: "password",
errorMessage: "Please specify a password for your wallet alias"
});
}
if (password.length < 8) {
return res.status(400).json({
field: "password",
errorMessage: "Please specify a password that's longer than 8 characters"
});
}
if (healthResponse.LNDStatus.service !== "walletUnlocker") {
return res.status(400).json({
field: "wallet",
errorMessage: "Wallet is already unlocked. Please restart your LND instance and try again."
});
}
try {
await unlockWallet(password);
} catch(err) {
return res.status(401).json({
field: "wallet",
errorMessage: "Invalid LND wallet password"
});
}
// Register user after verifying wallet password
const publicKey = await GunDB.register(alias, password);
// Generate Access Token
const token = await auth.generateToken();
res.json({
authorization: token,
user: {
alias,
publicKey
}
})
} catch (err) {
return res.status(500).json({
errorMessage: err.message,
})
}
});
// get lnd info