Skip to content

Commit

Permalink
feat: default masterkey generation (#2988)
Browse files Browse the repository at this point in the history
* feat: default masterkey generation

* chore: params in generate mnemonic

* feat: generate mnemonic for existing account which don't have yet

* chore: not to generate master key for existing account
  • Loading branch information
pavanjoshi914 authored Jan 30, 2024
1 parent 409f52a commit 26356ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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({
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

0 comments on commit 26356ca

Please sign in to comment.