Merge pull request #45 from shocknet/onboarding-improvs
Onboarding improvs
This commit is contained in:
commit
d9186b066a
3 changed files with 72 additions and 103 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
"main": "src/server.js",
|
"main": "src/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node --experimental-modules src/server.js",
|
"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",
|
"dev:watch": "nodemon main.js -- -h 0.0.0.0",
|
||||||
"test": "jest --no-cache",
|
"test": "jest --no-cache",
|
||||||
"test:watch": "jest --no-cache --watch",
|
"test:watch": "jest --no-cache --watch",
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,9 @@ const Encryption = require('../../../utils/encryptionStore')
|
||||||
/** @type {import('../contact-api/SimpleGUN').ISEA} */
|
/** @type {import('../contact-api/SimpleGUN').ISEA} */
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const SEAx = require('gun/sea')
|
const SEAx = require('gun/sea')
|
||||||
// @ts-ignore
|
// Re-enable in the future, when SEA errors inside user.auth/etc actually
|
||||||
SEAx.throw = true
|
// propagate up.
|
||||||
|
// SEAx.throw = true
|
||||||
|
|
||||||
/** @type {import('../contact-api/SimpleGUN').ISEA} */
|
/** @type {import('../contact-api/SimpleGUN').ISEA} */
|
||||||
const mySEA = {}
|
const mySEA = {}
|
||||||
|
|
@ -315,7 +316,10 @@ const authenticate = async (alias, pass, __user) => {
|
||||||
|
|
||||||
return ack.sea.pub
|
return ack.sea.pub
|
||||||
} else {
|
} 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?`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
163
src/routes.js
163
src/routes.js
|
|
@ -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) => {
|
app.post("/api/lnd/wallet", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { walletUnlocker } = LightningServices.services;
|
const { walletUnlocker } = LightningServices.services;
|
||||||
|
|
@ -640,66 +599,72 @@ module.exports = async (
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/api/lnd/wallet/existing", async (req, res) => {
|
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 {
|
try {
|
||||||
await unlockWallet(password);
|
const { password, alias } = req.body;
|
||||||
} catch(err) {
|
const healthResponse = await checkHealth();
|
||||||
return res.status(401).json({
|
const exists = await walletExists();
|
||||||
field: "wallet",
|
if (!exists) {
|
||||||
errorMessage: "Invalid LND wallet password"
|
return res.status(500).json({
|
||||||
});
|
field: "wallet",
|
||||||
}
|
errorMessage: "LND wallet does not exist, please create a new one"
|
||||||
|
});
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
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
|
// get lnd info
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue