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(multi-srp): add keyringId to getMnemonic fn #2983

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 4 additions & 3 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,12 @@ type SnapControllerArgs = {
encryptor: ExportableKeyEncryptor;

/**
* A hook to access the mnemonic of the user's primary keyring.
* 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.
*
* @param keyringId - The ID of the keyring to get the mnemonic for.
* @returns The mnemonic as bytes.
*/
getMnemonic: () => Promise<Uint8Array>;
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;

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

#encryptor: ExportableKeyEncryptor;

#getMnemonic: () => Promise<Uint8Array>;
#getMnemonic: (keyringId?: string) => Promise<Uint8Array>;

#getFeatureFlags: () => DynamicFeatureFlags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ const targetName = 'snap_getBip32Entropy';

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

/**
* Waits for the extension to be unlocked.
Expand Down Expand Up @@ -128,7 +129,7 @@ export function getBip32EntropyImplementation({
const node = await getNode({
curve: params.curve,
path: params.path,
secretRecoveryPhrase: await getMnemonic(),
secretRecoveryPhrase: await getMnemonic(params.keyringId),
cryptographicFunctions: getClientCryptography(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const targetName = 'snap_getBip32PublicKey';

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

/**
* Waits for the extension to be unlocked.
Expand Down Expand Up @@ -147,7 +148,7 @@ export function getBip32PublicKeyImplementation({
const node = await getNode({
curve: params.curve,
path: params.path,
secretRecoveryPhrase: await getMnemonic(),
secretRecoveryPhrase: await getMnemonic(params.keyringId),
cryptographicFunctions: getClientCryptography(),
});

Expand Down
11 changes: 8 additions & 3 deletions packages/snaps-rpc-methods/src/restricted/getBip44Entropy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const targetName = 'snap_getBip44Entropy';

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

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

const node = await BIP44CoinTypeNode.fromDerivationPath(
[await getMnemonic(), `bip32:44'`, `bip32:${params.coinType}'`],
[
await getMnemonic(params.keyringId),
`bip32:44'`,
`bip32:${params.coinType}'`,
],
'mainnet',
getClientCryptography(),
);
Expand Down
7 changes: 4 additions & 3 deletions packages/snaps-rpc-methods/src/restricted/getEntropy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ export const getEntropyBuilder = Object.freeze({

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

/**
* Waits for the extension to be unlocked.
Expand Down Expand Up @@ -130,7 +131,7 @@ function getEntropyImplementation({
);

await getUnlockPromise(true);
const mnemonicPhrase = await getMnemonic();
const mnemonicPhrase = await getMnemonic(params.keyringId);

return deriveEntropy({
input: origin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Bip32Entropy } from '../permissions';
* to `false`.
*/
export type GetBip32PublicKeyParams = Bip32Entropy & {
keyringId?: string;
compressed?: boolean;
};

Expand Down
2 changes: 2 additions & 0 deletions packages/snaps-sdk/src/types/methods/get-entropy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import type { Hex } from '@metamask/utils';
* @property version - The version of the entropy to retrieve. This is used for
* backwards compatibility. As of now, only version 1 is supported.
* @property salt - The optional salt to use when deriving the entropy.
* @property keyringId - The ID of the keyring to get the mnemonic for.
*/
export type GetEntropyParams = {
version: 1;
salt?: string;
keyringId?: string;
};

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/snaps-sdk/src/types/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export type NameLookupMatchers =
export type Bip32Entropy = {
curve: SupportedCurve;
path: string[];
keyringId?: string;
};

export type Bip44Entropy = {
coinType: number;
keyringId?: string;
};

export type RequestedSnap = {
Expand Down
3 changes: 2 additions & 1 deletion packages/snaps-simulation/src/methods/specifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export type PermissionSpecificationsHooks = {
/**
* A hook that returns the user's secret recovery phrase.
*
* @param keyringId - The ID of the keyring to get the mnemonic for.
* @returns The user's secret recovery phrase.
*/
getMnemonic: () => Promise<Uint8Array>;
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
};

export type GetPermissionSpecificationsOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from '@metamask/utils';

export type GetAccountsHandlerHooks = {
getMnemonic: () => Promise<Uint8Array>;
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export type InternalMethodsMiddlewareHooks = {
/**
* A hook that returns the user's secret recovery phrase.
*
* @param keyringId - The ID of the keyring to get the mnemonic for.
* @returns The user's secret recovery phrase.
*/
getMnemonic: () => Promise<Uint8Array>;
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
};

const methodHandlers = {
Expand Down
3 changes: 2 additions & 1 deletion packages/snaps-simulation/src/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ export type MiddlewareHooks = {
/**
* A hook that returns the user's secret recovery phrase.
*
* @param keyringId - The ID of the keyring to get the mnemonic for.
* @returns The user's secret recovery phrase.
*/
getMnemonic: () => Promise<Uint8Array>;
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;

/**
* A hook that returns the Snap's auxiliary file for the given path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const methodHandlers = {
/* eslint-enable @typescript-eslint/naming-convention */

export type MiscMiddlewareHooks = {
getMnemonic: () => Promise<Uint8Array>;
getMnemonic: (keyringId?: string) => Promise<Uint8Array>;
};

/**
Expand Down
Loading