logic/auth.js
// Registers the the user to the device. Returns an error if a user already exists.
Registers the the user to the device. Returns an error if a user already exists.
Registers the the user to the device . Returns an error if a user already exists .
async function register(user, seed) {
    if ((await isRegistered()).registered) {
        throw new NodeError('User already exists', 400); 
    }
    let encryptedSeed;
    try {
        encryptedSeed = await iocane.createSession().encrypt(seed.join(), user.plainTextPassword);
    } catch (error) {
        throw new NodeError('Unable to encrypt mnemonic seed');
    }
    try {
        await diskLogic.writeUserFile({ name: user.name, password: user.password, seed: encryptedSeed });
    } catch (error) {
        throw new NodeError('Unable to register user');
    }
    try {
        await setSystemPassword(user.plainTextPassword);
    } catch (error) {
        throw new NodeError('Unable to set system password');
    }
    try {
        await deriveUmbrelSeed(user);
    } catch (error) {
        throw new NodeError('Unable to create Umbrel seed');
    }
    let jwt;
    try {
        jwt = await JWTHelper.generateJWT(user.username);
    } catch (error) {
        await diskLogic.deleteUserFile();
        throw new NodeError('Unable to generate JWT');
    }
    try {
        await lndApiService.initializeWallet(constants.LND_WALLET_PASSWORD, seed, jwt);
    } catch (error) {
        await diskLogic.deleteUserFile();
        throw new NodeError(error.response.data);
    }
    return { jwt: jwt };
}
async function register ( user , seed ) { if ( ( await isRegistered ( ) ) . registered ) { throw new NodeError ( 'User already exists' , 400 ) ; } let encryptedSeed ; try { encryptedSeed = await iocane . createSession ( ) . encrypt ( seed . join ( ) , user . plainTextPassword ) ; } catch ( error ) { throw new NodeError ( 'Unable to encrypt mnemonic seed' ) ; } try { await diskLogic . writeUserFile ( { name : user . name , password : user . password , seed : encryptedSeed } ) ; } catch ( error ) { throw new NodeError ( 'Unable to register user' ) ; } try { await setSystemPassword ( user . plainTextPassword ) ; } catch ( error ) { throw new NodeError ( 'Unable to set system password' ) ; } try { await deriveUmbrelSeed ( user ) ; } catch ( error ) { throw new NodeError ( 'Unable to create Umbrel seed' ) ; } let jwt ; try { jwt = await JWTHelper . generateJWT ( user . username ) ; } catch ( error ) { await diskLogic . deleteUserFile ( ) ; throw new NodeError ( 'Unable to generate JWT' ) ; } try { await lndApiService . initializeWallet ( constants . LND_WALLET_PASSWORD , seed , jwt ) ; } catch ( error ) { await diskLogic . deleteUserFile ( ) ; throw new NodeError ( error . response . data ) ; } return { jwt : jwt } ; }
Registers the the user to the device.
Registers the the user to the device .
// eslint-disable-line no-magic-numbers //Encrypt mnemonic seed for storage //save user //update system password //derive Umbrel seed //generate JWt //initialize lnd wallet //return token