Skip to content

Commit

Permalink
fix: exportSeed coin type fix (#233)
Browse files Browse the repository at this point in the history
remove hardcoded kusama coinType, uses `coinType` based on configuration
  • Loading branch information
irubido authored Jun 18, 2024
1 parent 3c78592 commit 7bef7c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
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);
});
});

0 comments on commit 7bef7c2

Please sign in to comment.