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

metamask: use metamask-style account path derivation #424

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 7 additions & 7 deletions integration/src/wallets/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function selfTest(get: () => core.HDWallet): void {
expect(await wallet.ethSupportsSecureTransfer()).toEqual(false);
});

it("uses correct eth bip44 paths", () => {
it("uses metamask-style account derivation paths", () => {
if (!wallet) return;
[0, 1, 3, 27].forEach((account) => {
const paths = wallet.ethGetAccountPaths({
Expand All @@ -85,9 +85,9 @@ export function selfTest(get: () => core.HDWallet): void {
});
expect(paths).toEqual([
{
addressNList: core.bip32ToAddressNList(`m/44'/60'/${account}'/0/0`),
hardenedPath: core.bip32ToAddressNList(`m/44'/60'/${account}'`),
relPath: [0, 0],
addressNList: core.bip32ToAddressNList(`m/44'/60'/0'/0/${account}`),
hardenedPath: core.bip32ToAddressNList(`m/44'/60'/0'`),
relPath: [0, account],
description: "MetaMask",
},
]);
Expand Down Expand Up @@ -120,7 +120,7 @@ export function selfTest(get: () => core.HDWallet): void {

expect(
wallet.describePath({
path: core.bip32ToAddressNList("m/44'/60'/3'/0/0"),
path: core.bip32ToAddressNList("m/44'/60'/0'/0/3"),
coin: "Ethereum",
})
).toEqual({
Expand All @@ -134,11 +134,11 @@ export function selfTest(get: () => core.HDWallet): void {

expect(
wallet.describePath({
path: core.bip32ToAddressNList("m/44'/60'/0'/0/3"),
path: core.bip32ToAddressNList("m/44'/60'/3'/0/0"),
coin: "Ethereum",
})
).toEqual({
verbose: "m/44'/60'/0'/0/3",
verbose: "m/44'/60'/3'/0/0",
coin: "Ethereum",
isKnown: false,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/hdwallet-metamask/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export function ethGetAccountPaths(msg: core.ETHGetAccountPath): Array<core.ETHA
if (slip44 === undefined) return [];
return [
{
addressNList: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx, 0, 0],
hardenedPath: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + msg.accountIdx],
relPath: [0, 0],
addressNList: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000, 0, msg.accountIdx],
hardenedPath: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000],
relPath: [0, msg.accountIdx],
description: "MetaMask",
},
];
Expand Down
2 changes: 1 addition & 1 deletion packages/hdwallet-metamask/src/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class MetaMaskHDWalletInfo implements core.HDWalletInfo, core.ETHWalletIn
}

public describePath(msg: core.DescribePath): core.PathDescription {
return core.describePath(msg);
return core.describePath(msg, core.ETHAddressDerivationScheme.Metamask);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down