Skip to content

Commit cda2586

Browse files
committed
feat(multi-srp): add keyringId to getMnemonic fn
1 parent 51ab913 commit cda2586

File tree

13 files changed

+37
-20
lines changed

13 files changed

+37
-20
lines changed

packages/snaps-controllers/src/snaps/SnapController.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,12 @@ type SnapControllerArgs = {
700700
encryptor: ExportableKeyEncryptor;
701701

702702
/**
703-
* A hook to access the mnemonic of the user's primary keyring.
703+
* A hook to access the mnemonic of the user's keyring, if the keyringId is not provided, it will return the mnemonic of the primary keyring.
704704
*
705+
* @param keyringId - The ID of the keyring to get the mnemonic for.
705706
* @returns The mnemonic as bytes.
706707
*/
707-
getMnemonic: () => Promise<Uint8Array>;
708+
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
708709

709710
/**
710711
* A hook to get dynamic feature flags at runtime.
@@ -803,7 +804,7 @@ export class SnapController extends BaseController<
803804

804805
#encryptor: ExportableKeyEncryptor;
805806

806-
#getMnemonic: () => Promise<Uint8Array>;
807+
#getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
807808

808809
#getFeatureFlags: () => DynamicFeatureFlags;
809810

packages/snaps-rpc-methods/src/restricted/getBip32Entropy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ const targetName = 'snap_getBip32Entropy';
2222

2323
export type GetBip32EntropyMethodHooks = {
2424
/**
25-
* @returns The mnemonic of the user's primary keyring.
25+
* @param keyringId - The ID of the keyring to get the mnemonic for.
26+
* @returns The mnemonic of the user's keyring, if the keyringId is not provided, it will return the mnemonic of the primary keyring.
2627
*/
27-
getMnemonic: () => Promise<Uint8Array>;
28+
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
2829

2930
/**
3031
* Waits for the extension to be unlocked.
@@ -128,7 +129,7 @@ export function getBip32EntropyImplementation({
128129
const node = await getNode({
129130
curve: params.curve,
130131
path: params.path,
131-
secretRecoveryPhrase: await getMnemonic(),
132+
secretRecoveryPhrase: await getMnemonic(params.keyringId),
132133
cryptographicFunctions: getClientCryptography(),
133134
});
134135

packages/snaps-rpc-methods/src/restricted/getBip32PublicKey.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ const targetName = 'snap_getBip32PublicKey';
2828

2929
export type GetBip32PublicKeyMethodHooks = {
3030
/**
31-
* @returns The mnemonic of the user's primary keyring.
31+
* @param keyringId - The ID of the keyring to get the mnemonic for.
32+
* @returns The mnemonic of the user's keyring, if the keyringId is not provided, it will return the mnemonic of the primary keyring.
3233
*/
33-
getMnemonic: () => Promise<Uint8Array>;
34+
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
3435

3536
/**
3637
* Waits for the extension to be unlocked.
@@ -147,7 +148,7 @@ export function getBip32PublicKeyImplementation({
147148
const node = await getNode({
148149
curve: params.curve,
149150
path: params.path,
150-
secretRecoveryPhrase: await getMnemonic(),
151+
secretRecoveryPhrase: await getMnemonic(params.keyringId),
151152
cryptographicFunctions: getClientCryptography(),
152153
});
153154

packages/snaps-rpc-methods/src/restricted/getBip44Entropy.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ const targetName = 'snap_getBip44Entropy';
2121

2222
export type GetBip44EntropyMethodHooks = {
2323
/**
24-
* @returns The mnemonic of the user's primary keyring.
24+
* @param keyringId - The ID of the keyring to get the mnemonic for.
25+
* @returns The mnemonic of the user's keyring, if the keyringId is not provided, it will return the mnemonic of the primary keyring.
2526
*/
26-
getMnemonic: () => Promise<Uint8Array>;
27+
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
2728

2829
/**
2930
* Waits for the extension to be unlocked.
@@ -128,7 +129,11 @@ export function getBip44EntropyImplementation({
128129
const params = args.params as GetBip44EntropyParams;
129130

130131
const node = await BIP44CoinTypeNode.fromDerivationPath(
131-
[await getMnemonic(), `bip32:44'`, `bip32:${params.coinType}'`],
132+
[
133+
await getMnemonic(params.keyringId),
134+
`bip32:44'`,
135+
`bip32:${params.coinType}'`,
136+
],
132137
'mainnet',
133138
getClientCryptography(),
134139
);

packages/snaps-rpc-methods/src/restricted/getEntropy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ export const getEntropyBuilder = Object.freeze({
7474

7575
export type GetEntropyHooks = {
7676
/**
77-
* @returns The mnemonic of the user's primary keyring.
77+
* @param keyringId - The ID of the keyring to get the mnemonic for.
78+
* @returns The mnemonic of the user's keyring, if the keyringId is not provided, it will return the mnemonic of the primary keyring.
7879
*/
79-
getMnemonic: () => Promise<Uint8Array>;
80+
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
8081

8182
/**
8283
* Waits for the extension to be unlocked.
@@ -130,7 +131,7 @@ function getEntropyImplementation({
130131
);
131132

132133
await getUnlockPromise(true);
133-
const mnemonicPhrase = await getMnemonic();
134+
const mnemonicPhrase = await getMnemonic(params.keyringId);
134135

135136
return deriveEntropy({
136137
input: origin,

packages/snaps-sdk/src/types/methods/get-bip32-public-key.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Bip32Entropy } from '../permissions';
99
* to `false`.
1010
*/
1111
export type GetBip32PublicKeyParams = Bip32Entropy & {
12+
keyringId?: string;
1213
compressed?: boolean;
1314
};
1415

packages/snaps-sdk/src/types/methods/get-entropy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import type { Hex } from '@metamask/utils';
66
* @property version - The version of the entropy to retrieve. This is used for
77
* backwards compatibility. As of now, only version 1 is supported.
88
* @property salt - The optional salt to use when deriving the entropy.
9+
* @property keyringId - The ID of the keyring to get the mnemonic for.
910
*/
1011
export type GetEntropyParams = {
1112
version: 1;
1213
salt?: string;
14+
keyringId?: string;
1315
};
1416

1517
/**

packages/snaps-sdk/src/types/permissions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ export type NameLookupMatchers =
2525
export type Bip32Entropy = {
2626
curve: SupportedCurve;
2727
path: string[];
28+
keyringId?: string;
2829
};
2930

3031
export type Bip44Entropy = {
3132
coinType: number;
33+
keyringId?: string;
3234
};
3335

3436
export type RequestedSnap = {

packages/snaps-simulation/src/methods/specifications.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export type PermissionSpecificationsHooks = {
3030
/**
3131
* A hook that returns the user's secret recovery phrase.
3232
*
33+
* @param keyringId - The ID of the keyring to get the mnemonic for.
3334
* @returns The user's secret recovery phrase.
3435
*/
35-
getMnemonic: () => Promise<Uint8Array>;
36+
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
3637
};
3738

3839
export type GetPermissionSpecificationsOptions = {

packages/snaps-simulation/src/middleware/internal-methods/accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
} from '@metamask/utils';
1111

1212
export type GetAccountsHandlerHooks = {
13-
getMnemonic: () => Promise<Uint8Array>;
13+
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
1414
};
1515

1616
/**

0 commit comments

Comments
 (0)