From 7bef7c2b3f99ad5f45a6a411c044667a773e78c8 Mon Sep 17 00:00:00 2001 From: Ivan Rubido <51483483+irubido@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:18:39 +0200 Subject: [PATCH] fix: exportSeed coin type fix (#233) remove hardcoded kusama coinType, uses `coinType` based on configuration --- packages/snap/snap.manifest.json | 2 +- packages/snap/src/rpc/exportSeed.ts | 9 ++++++--- packages/snap/test/unit/rpc/exportSeed.test.ts | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index 1babcfa1..11e7bd33 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "git+https://github.com/chainsafe/metamask-snap-polkadot.git" }, "source": { - "shasum": "tetP/U2cSxYl1CqUrLT+d1HD74GQyUy/MDUQ7h7qlEQ=", + "shasum": "VLA9zcJiR3GjrTia+9M5lgWjqwSZ8pCrAPrH39BUTrU=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/rpc/exportSeed.ts b/packages/snap/src/rpc/exportSeed.ts index 86a9d900..ea432a3a 100644 --- a/packages/snap/src/rpc/exportSeed.ts +++ b/packages/snap/src/rpc/exportSeed.ts @@ -1,9 +1,12 @@ import type { JsonBIP44CoinTypeNode } from '@metamask/key-tree'; import { showConfirmationDialog } from '../util/confirmation'; - -const kusamaCoinType = 434; +import { getConfiguration } from '../configuration'; +import { getCoinTypeByNetwork } from '../polkadot/account'; export async function exportSeed(): Promise { + const configuration = await getConfiguration(); + const coinType = getCoinTypeByNetwork(configuration.networkName); + // ask for confirmation const confirmation = await showConfirmationDialog({ prompt: 'Do you want to export your seed?' @@ -12,7 +15,7 @@ export async function exportSeed(): Promise { if (confirmation) { const bip44Node = (await snap.request({ method: 'snap_getBip44Entropy', - params: { coinType: kusamaCoinType } + params: { coinType: coinType } })) as JsonBIP44CoinTypeNode; return bip44Node.privateKey.slice(0, 32); } diff --git a/packages/snap/test/unit/rpc/exportSeed.test.ts b/packages/snap/test/unit/rpc/exportSeed.test.ts index bcfd9cf1..4650cbd3 100644 --- a/packages/snap/test/unit/rpc/exportSeed.test.ts +++ b/packages/snap/test/unit/rpc/exportSeed.test.ts @@ -13,9 +13,9 @@ describe('Test rpc handler function: exportSeed', function () { }); it('should return seed on positive prompt confirmation and keyring saved in state', async function () { - walletStub.request.onFirstCall().returns(true); + walletStub.request.onSecondCall().returns(true); walletStub.request - .onSecondCall() + .onThirdCall() .returns({ privateKey: 'aba2dd1a12eeafda3fda62aa6dfa21ca2aa6dfaba13fda6a22ea2dd1eafda1ca' }); const result = await exportSeed(); expect(result).to.be.eq('aba2dd1a12eeafda3fda62aa6dfa21ca'); @@ -24,7 +24,7 @@ describe('Test rpc handler function: exportSeed', function () { it('should not return seed on negative prompt confirmation', async function () { walletStub.request.returns(false); const result = await exportSeed(); - expect(walletStub.request).to.have.been.calledOnce; + expect(walletStub.request).to.have.been.calledTwice; expect(result).to.be.eq(null); }); });