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

Multi srp mvp #29794

Draft
wants to merge 51 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ce87824
feat: multip SRP PoC
PatrykLucka Dec 5, 2024
5b9bf58
feat(multi-srp): add keyring id
PatrykLucka Dec 9, 2024
cc9cd94
chore(multi-srp): add code fences
PatrykLucka Dec 9, 2024
ae06ccf
chore(multi-srp): add import codefence, tests and story
PatrykLucka Dec 9, 2024
9771fe5
chore(multi-srp): change js component to tsx + use accountController …
PatrykLucka Dec 10, 2024
33740d1
feat(multi-srp): add more accounts from imported SRP if they have any…
PatrykLucka Dec 10, 2024
ef4d9e2
Apply suggestions from code review
PatrykLucka Dec 11, 2024
a2a07db
chore: Apply suggestions from code review
PatrykLucka Dec 11, 2024
8c01287
feat(multi-srp): use toast as success message
PatrykLucka Dec 11, 2024
c169e2b
chore: use preview build for keyring-controller
PatrykLucka Dec 11, 2024
a5cfec3
fix: update to pass typeIndex as param
montelaidev Dec 12, 2024
c26ac36
feat(multi-srp): add select srp UI
PatrykLucka Dec 12, 2024
4648cd9
feat: add test for reveal seed
montelaidev Dec 12, 2024
491e3bb
feat: add `generateNewHdKeyring`
montelaidev Dec 13, 2024
b62d838
feat(multi-srp): create account from srp UI
PatrykLucka Dec 17, 2024
edc978f
Merge branch 'mmmsrp-9' into multi-srp-mvp
PatrykLucka Dec 17, 2024
ff891e0
refactor: use keyring index instead of id and typeIndex
PatrykLucka Jan 8, 2025
2e69c3b
feat: add import srp word list ui
montelaidev Jan 13, 2025
b3b1522
feat: multip SRP PoC
PatrykLucka Dec 5, 2024
6824d52
feat(multi-srp): add keyring id
PatrykLucka Dec 9, 2024
6fc4744
chore(multi-srp): add code fences
PatrykLucka Dec 9, 2024
e904582
chore(multi-srp): add import codefence, tests and story
PatrykLucka Dec 9, 2024
c5d819a
chore(multi-srp): change js component to tsx + use accountController …
PatrykLucka Dec 10, 2024
1cd827b
feat(multi-srp): add more accounts from imported SRP if they have any…
PatrykLucka Dec 10, 2024
d18fd69
Apply suggestions from code review
PatrykLucka Dec 11, 2024
f16ae0a
chore: Apply suggestions from code review
PatrykLucka Dec 11, 2024
a26d104
feat(multi-srp): use toast as success message
PatrykLucka Dec 11, 2024
8e612fc
chore: use preview build for keyring-controller
PatrykLucka Dec 11, 2024
2013282
feat(multi-srp): add select srp UI
PatrykLucka Dec 12, 2024
079bffe
feat(multi-srp): create account from srp UI
PatrykLucka Dec 17, 2024
5c47583
fix: update to pass typeIndex as param
montelaidev Dec 12, 2024
c1adf77
feat: add test for reveal seed
montelaidev Dec 12, 2024
3992ba1
feat: add `generateNewHdKeyring`
montelaidev Dec 13, 2024
315d3fe
refactor: use keyring index instead of id and typeIndex
PatrykLucka Jan 8, 2025
8c7fc6a
feat: multip SRP PoC
PatrykLucka Dec 5, 2024
6eb0458
feat(multi-srp): add keyring id
PatrykLucka Dec 9, 2024
50f0adf
chore(multi-srp): add code fences
PatrykLucka Dec 9, 2024
5c4c6af
chore(multi-srp): add import codefence, tests and story
PatrykLucka Dec 9, 2024
8a09e41
chore(multi-srp): change js component to tsx + use accountController …
PatrykLucka Dec 10, 2024
f51517f
feat(multi-srp): add more accounts from imported SRP if they have any…
PatrykLucka Dec 10, 2024
b62fb4d
Apply suggestions from code review
PatrykLucka Dec 11, 2024
d47b04f
chore: Apply suggestions from code review
PatrykLucka Dec 11, 2024
1c5c968
feat(multi-srp): use toast as success message
PatrykLucka Dec 11, 2024
c9f121c
chore: use preview build for keyring-controller
PatrykLucka Dec 11, 2024
b940893
feat(multi-srp): create account from srp UI
PatrykLucka Dec 17, 2024
39e66a0
fix: update to pass typeIndex as param
montelaidev Dec 12, 2024
4019541
refactor: use keyring index instead of id and typeIndex
PatrykLucka Jan 8, 2025
816069a
feat: add reveal srp to hd accounts.
montelaidev Jan 14, 2025
2470ec7
fix: multisrp fence
montelaidev Jan 16, 2025
55e184b
Merge branch 'multi-srp-mvp-import-srp-ui' into multi-srp-mvp
PatrykLucka Jan 16, 2025
3332a8d
feat(multi-srp): use keyringId instead of indexes
PatrykLucka Jan 18, 2025
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
43 changes: 43 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions app/scripts/controllers/preferences-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ describe('preferences controller', () => {
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: 'ULID01234567890ABCDEFGHIJKLMN',
name: '',
},
],
},
[],
);
Expand Down Expand Up @@ -186,6 +192,12 @@ describe('preferences controller', () => {
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: 'ULID01234567890ABCDEFGHIJKLMN',
name: '',
},
],
},
[],
);
Expand Down Expand Up @@ -237,6 +249,12 @@ describe('preferences controller', () => {
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: 'ULID01234567890ABCDEFGHIJKLMN',
name: '',
},
],
},
[],
);
Expand Down Expand Up @@ -272,6 +290,12 @@ describe('preferences controller', () => {
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: 'ULID01234567890ABCDEFGHIJKLMN',
name: '',
},
],
},
[],
);
Expand Down Expand Up @@ -524,6 +548,12 @@ describe('preferences controller', () => {
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: 'ULID01234567890ABCDEFGHIJKLMN',
name: '',
},
],
},
[],
);
Expand Down
78 changes: 71 additions & 7 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { providerAsMiddleware } from '@metamask/eth-json-rpc-middleware';
import { debounce, throttle, memoize, wrap } from 'lodash';
import {
KeyringController,
///: BEGIN:ONLY_INCLUDE_IF(multi-srp)
KeyringTypes,
///: END:ONLY_INCLUDE_IF
keyringBuilderFactory,
} from '@metamask/keyring-controller';
import createFilterMiddleware from '@metamask/eth-json-rpc-filters';
Expand Down Expand Up @@ -3858,6 +3861,11 @@ export default class MetamaskController extends EventEmitter {
setLocked: this.setLocked.bind(this),
createNewVaultAndKeychain: this.createNewVaultAndKeychain.bind(this),
createNewVaultAndRestore: this.createNewVaultAndRestore.bind(this),
///: BEGIN:ONLY_INCLUDE_IF(multi-srp)
generateNewMnemonicAndAddToVault:
this.generateNewMnemonicAndAddToVault.bind(this),
addNewMnemonicToVault: this.addNewMnemonicToVault.bind(this),
///: END:ONLY_INCLUDE_IF
exportAccount: this.exportAccount.bind(this),

// txController
Expand Down Expand Up @@ -4605,6 +4613,57 @@ export default class MetamaskController extends EventEmitter {
}
}

/**
* Adds a new mnemonic to the vault.
*
* @param {string} mnemonic
* @returns {object} new account address
*/
///: BEGIN:ONLY_INCLUDE_IF(multi-srp)
async addNewMnemonicToVault(mnemonic) {
const releaseLock = await this.createVaultMutex.acquire();
try {
const newKeyring = await this.keyringController.addNewKeyring(
KeyringTypes.hd,
{
mnemonic,
numberOfAccounts: 1,
},
);
const newAccountAddress = (await newKeyring.getAccounts())[0];
const account =
this.accountsController.getAccountByAddress(newAccountAddress);
this.accountsController.setSelectedAccount(account.id);

const keyringId =
this.keyringController.state.keyringsMetadata[
this.keyringController.state.keyrings.length - 1
].id;
await this._addAccountsWithBalance(keyringId);

return newAccountAddress;
} finally {
releaseLock();
}
}

async generateNewMnemonicAndAddToVault() {
const releaseLock = await this.createVaultMutex.acquire();
try {
const newHdkeyring = await this.keyringController.addNewKeyring(
KeyringTypes.hd,
);
const newAccount = (await newHdkeyring.getAccounts())[0];
const account = this.accountsController.getAccountByAddress(newAccount);
this.accountsController.setSelectedAccount(account.id);

return newAccount;
} finally {
releaseLock();
}
}
///: END:ONLY_INCLUDE_IF

/**
* Create a new Vault and restore an existent keyring.
*
Expand Down Expand Up @@ -4654,11 +4713,11 @@ export default class MetamaskController extends EventEmitter {
}
}

async _addAccountsWithBalance() {
async _addAccountsWithBalance(keyringId) {
try {
// Scan accounts until we find an empty one
const chainId = this.#getGlobalChainId();
const accounts = await this.keyringController.getAccounts();
const accounts = await this.keyringController.getAccounts(keyringId);
let address = accounts[accounts.length - 1];

for (let count = accounts.length; ; count++) {
Expand Down Expand Up @@ -4689,7 +4748,7 @@ export default class MetamaskController extends EventEmitter {
}

// This account has assets, so check the next one
address = await this.keyringController.addNewAccount(count);
address = await this.keyringController.addNewAccount(count, keyringId);
}
} catch (e) {
log.warn(`Failed to add accounts with balance. Error: ${e}`);
Expand Down Expand Up @@ -5141,14 +5200,18 @@ export default class MetamaskController extends EventEmitter {
/**
* Adds a new account to the default (first) HD seed phrase Keyring.
*
* @param accountCount
* @param {number} accountCount
* @param {string} keyringId
* @returns {Promise<string>} The address of the newly-created account.
*/
async addNewAccount(accountCount) {
async addNewAccount(accountCount, keyringId) {
const oldAccounts = await this.keyringController.getAccounts();

const addedAccountAddress = await this.keyringController.addNewAccount(
accountCount,
///: BEGIN:ONLY_INCLUDE_IF(multi-srp)
keyringId,
///: END:ONLY_INCLUDE_IF
);

if (!oldAccounts.includes(addedAccountAddress)) {
Expand All @@ -5166,12 +5229,13 @@ export default class MetamaskController extends EventEmitter {
* Called when the first account is created and on unlocking the vault.
*
* @param password
* @param keyringId - This is the identifier for the hd keyring.
* @returns {Promise<number[]>} The seed phrase to be confirmed by the user,
* encoded as an array of UTF-8 bytes.
*/
async getSeedPhrase(password) {
async getSeedPhrase(password, keyringId) {
return this._convertEnglishWordlistIndicesToCodepoints(
await this.keyringController.exportSeedPhrase(password),
await this.keyringController.exportSeedPhrase(password, keyringId),
);
}

Expand Down
2 changes: 2 additions & 0 deletions app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,8 @@ describe('MetaMaskController', () => {

describe('forgetDevice', () => {
it('should throw if it receives an unknown device name', async () => {
// mock keyringController.update
jest.spyOn(metamaskController.keyringController, 'update');
const result = metamaskController.forgetDevice(
'Some random device name',
);
Expand Down
4 changes: 4 additions & 0 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ buildTypes:
- build-flask
- keyring-snaps
- solana
- multi-srp
env:
- INFURA_FLASK_PROJECT_ID
- SEGMENT_FLASK_WRITE_KEY
Expand Down Expand Up @@ -139,6 +140,9 @@ features:
solana:
assets:
- ./{app,shared,ui}/**/solana/**
multi-srp:
assets:
- ./{app,shared,ui}/**/multi-srp/**

# Env variables that are required for all types of builds
#
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
"@metamask/json-rpc-engine": "^10.0.0",
"@metamask/json-rpc-middleware-stream": "^8.0.4",
"@metamask/keyring-api": "^12.0.0",
"@metamask/keyring-controller": "^19.0.2",
"@metamask/keyring-controller": "npm:@metamask-previews/keyring-controller@19.0.3-preview-83c8a21",
"@metamask/keyring-internal-api": "^1.0.0",
"@metamask/keyring-snap-client": "^1.0.0",
"@metamask/logging-controller": "^6.0.0",
Expand Down
14 changes: 14 additions & 0 deletions test/data/mock-send-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,20 @@
"accounts": ["0xeb9e64b93097bc15f01f13eae97015c57ab64823"]
}
],
"keyringsMetadata": [
{
"id": "ULID01234567890ABCDEFGHIJKLMN",
"name": ""
},
{
"id": "ULID01234567890ABCDEFGHIJKLMN",
"name": ""
},
{
"id": "ULID01234567890ABCDEFGHIJKLMN",
"name": ""
}
],
"identities": {
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": {
"address": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
Expand Down
22 changes: 22 additions & 0 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,28 @@
"accounts": ["0xca8f1F0245530118D0cf14a06b01Daf8f76Cf281"]
}
],
"keyringsMetadata": [
{
"id": "ULID01234567890ABCDEFGHIJKLMN",
"name": ""
},
{
"id": "ULID01234567890ABCDEFGHIJKLMN",
"name": ""
},
{
"id": "ULID01234567890ABCDEFGHIJKLMN",
"name": ""
},
{
"id": "ULID01234567890ABCDEFGHIJKLMN",
"name": ""
},
{
"id": "ULID01234567890ABCDEFGHIJKLMN",
"name": ""
}
],
"identities": {
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": {
"address": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
Expand Down
10 changes: 10 additions & 0 deletions test/jest/mock-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ export const createSwapsMockStore = () => {
accounts: ['0xd85a4b6a394794842887b8284293d69163007bbb'],
},
],
keyringsMetadata: [
{
id: 'ULID01234567890ABCDEFGHIJKLMN',
name: '',
},
{
id: 'ULID01234567890ABCDEFGHIJKLMN',
name: '',
},
],
...mockNetworkState({
chainId: CHAIN_IDS.MAINNET,
ticker: CURRENCY_SYMBOLS.ETH,
Expand Down
Loading
Loading