Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: default masterkey generation #2988

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/extension/background-script/actions/accounts/add.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { v4 as uuidv4 } from "uuid";
import { encryptData } from "~/common/lib/crypto";
import { getUniqueAccountName } from "~/common/utils/validations";
import edit from "~/extension/background-script/actions/accounts/edit";
import {
generateMnemonic,
setMnemonic,
} from "~/extension/background-script/actions/mnemonic";
import state from "~/extension/background-script/state";
import type { MessageAccountAdd } from "~/types";
import { getUniqueAccountName } from "~/common/utils/validations";

const add = async (message: MessageAccountAdd) => {
const newAccount = message.args;
Expand All @@ -24,12 +29,34 @@ const add = async (message: MessageAccountAdd) => {
name,
};

const mnemonic = await generateMnemonic({
action: "generateMnemonic",
origin: { internal: true },
});
setMnemonic({
args: {
id: accountId,
mnemonic: mnemonic.data,
},
action: "setMnemonic",
origin: { internal: true },
});

state.setState({ accounts: tmpAccounts });

if (!currentAccountId) {
state.setState({ currentAccountId: accountId });
}

edit({
pavanjoshi914 marked this conversation as resolved.
Show resolved Hide resolved
args: {
id: accountId,
useMnemonicForLnurlAuth: true,
},
action: "editAccount",
origin: { internal: true },
});

// make sure we immediately persist the new account
await state.getState().saveToStorage();
return { data: { accountId: accountId } };
Expand Down
1 change: 1 addition & 0 deletions src/extension/background-script/actions/accounts/unlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const unlock = async (message: MessageAccountUnlock) => {

// if everything is fine we keep the password in memory
await state.getState().password(password);

// load the connector to make sure it is initialized for the future calls
// with this we prevent potentially multiple action calls trying to initialize the connector in parallel
// we have to be careful here: if the unlock fails (e.g. because of an error in getConnector() the user
Expand Down
Loading