Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

fix: exportSeed coin type fix #233

Merged
merged 2 commits into from
Jun 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions packages/snap/src/rpc/exportSeed.ts
Original file line number Diff line number Diff line change
@@ -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<string | null> {
const configuration = await getConfiguration();
const coinType = getCoinTypeByNetwork(configuration.networkName);

// ask for confirmation
const confirmation = await showConfirmationDialog({
prompt: 'Do you want to export your seed?'
Expand All @@ -12,7 +15,7 @@ export async function exportSeed(): Promise<string | null> {
if (confirmation) {
const bip44Node = (await snap.request({
method: 'snap_getBip44Entropy',
params: { coinType: kusamaCoinType }
params: { coinType: coinType }
})) as JsonBIP44CoinTypeNode;
return bip44Node.privateKey.slice(0, 32);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/snap/test/unit/rpc/exportSeed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
});
});
Loading