Skip to content

Commit

Permalink
metamask: derive metamask-style account paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnerdhair committed Feb 12, 2022
1 parent e967407 commit fe49b46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions integration/src/wallets/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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) => {
let paths = wallet.ethGetAccountPaths({
Expand All @@ -62,9 +62,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 @@ -97,7 +97,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 @@ -111,11 +111,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 @@ -11,9 +11,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 @@ -297,7 +297,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);
}

public ethNextAccountPath(msg: core.ETHAccountPath): core.ETHAccountPath | undefined {
Expand Down

0 comments on commit fe49b46

Please sign in to comment.