commit
f7dc0bd1df
4 changed files with 43 additions and 3 deletions
|
|
@ -1043,5 +1043,6 @@ module.exports = {
|
|||
register,
|
||||
instantiateGun,
|
||||
getGun,
|
||||
getUser
|
||||
getUser,
|
||||
mySEA
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1022,6 +1022,35 @@ const setBio = (bio, user) =>
|
|||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @param {string[]} mnemonicPhrase
|
||||
* @param {UserGUNNode} user
|
||||
* @param {ISEA} SEA
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const saveSeedBackup = async (mnemonicPhrase, user, SEA) => {
|
||||
if (
|
||||
!Array.isArray(mnemonicPhrase) ||
|
||||
mnemonicPhrase.some(word => typeof word !== 'string') ||
|
||||
mnemonicPhrase.length === 0
|
||||
) {
|
||||
throw new TypeError('expected mnemonicPhrase to be an string array')
|
||||
}
|
||||
|
||||
const mySecret = await SEA.secret(user._.sea.epub, user._.sea)
|
||||
const encryptedSeed = await SEA.encrypt(mnemonicPhrase.join(' '), mySecret)
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
user.get(Key.SEED_BACKUP).put(encryptedSeed, ack => {
|
||||
if (ack.err) {
|
||||
rej(ack.err)
|
||||
} else {
|
||||
res()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
INITIAL_MSG,
|
||||
__createOutgoingFeed,
|
||||
|
|
@ -1037,5 +1066,6 @@ module.exports = {
|
|||
setDisplayName,
|
||||
sendPayment,
|
||||
generateOrderAddress,
|
||||
setBio
|
||||
setBio,
|
||||
saveSeedBackup
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,3 +32,5 @@ exports.ORDER_NODES = 'orderNodes'
|
|||
exports.ORDER_TO_RESPONSE = 'orderToResponse'
|
||||
|
||||
exports.BIO = 'bio'
|
||||
|
||||
exports.SEED_BACKUP = 'seedBackup'
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ const auth = require("../services/auth/auth");
|
|||
const FS = require("../utils/fs");
|
||||
const LightningServices = require("../utils/lightningServices");
|
||||
const GunDB = require("../services/gunDB/Mediator");
|
||||
const GunActions = require("../services/gunDB/contact-api/actions")
|
||||
const { unprotectedRoutes } = require("../utils/protectedRoutes");
|
||||
|
||||
const DEFAULT_MAX_NUM_ROUTES_TO_QUERY = 10;
|
||||
|
|
@ -440,7 +441,13 @@ module.exports = (
|
|||
|
||||
// Register user before creating wallet
|
||||
const publicKey = await GunDB.register(alias, password);
|
||||
|
||||
|
||||
await GunActions.saveSeedBackup(
|
||||
mnemonicPhrase,
|
||||
GunDB.getUser(),
|
||||
GunDB.mySEA
|
||||
)
|
||||
|
||||
walletUnlocker.initWallet(
|
||||
walletArgs,
|
||||
async (initWalletErr, initWalletResponse) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue