This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export account json rpc (#234)
contains changes from #233 new rpc returns stringified json of keyring pair example implements file saver and json passphrase encoding field
- Loading branch information
Showing
12 changed files
with
143 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getKeyPair } from '../polkadot/account'; | ||
import { showConfirmationDialog } from '../util/confirmation'; | ||
|
||
export async function exportAccount(jsonPassphrase?: string): Promise<string> { | ||
const confirmation = await showConfirmationDialog({ | ||
prompt: 'Do you want to export your account?' | ||
}); | ||
|
||
if (confirmation) { | ||
const keyPair = await getKeyPair(); | ||
return JSON.stringify(keyPair.toJson(jsonPassphrase)); | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import chai, { expect } from 'chai'; | ||
import sinonChai from 'sinon-chai'; | ||
import { getWalletMock } from '../wallet.mock'; | ||
import { exportAccount } from "../../../src/rpc/exportAccount" | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('Test rpc handler function: exportAccount', function () { | ||
const walletStub = getWalletMock(); | ||
|
||
const privateKey = 'aba2dd1a12eeafda3fda62aa6dfa21ca2aa6dfaba13fda6a22ea2dd1eafda1ca' | ||
const nonEncodedResult = '{"encoded":"MFMCAQEwBQYDK2VwBCIEIGFiYTJkZDFhMTJlZWFmZGEzZmRhNjJhYTZkZmEyMWNhzwQ+E9kijYqTHOTMWO+9GtbF4vGTLDF06xUN+vkWW3OhIwMhAM8EPhPZIo2KkxzkzFjvvRrWxeLxkywxdOsVDfr5Fltz","encoding":{"content":["pkcs8","ed25519"],"type":["none"],"version":"3"},"address":"5Gk92fkWPUg6KNHSfP93UcPFhwGurM9RKAKU62Dg6upaCfH7","meta":{}}'; | ||
afterEach(function () { | ||
walletStub.reset(); | ||
}); | ||
|
||
it('should return stringified json account on positive prompt', async function () { | ||
walletStub.request.onFirstCall().returns(true); | ||
walletStub.request | ||
.onThirdCall() | ||
.returns({ privateKey }); | ||
const result = await exportAccount(); | ||
expect(result).to.be.eq(nonEncodedResult); | ||
}); | ||
|
||
it('returned encoded json should be different from non encoded json', async function () { | ||
walletStub.request.onFirstCall().returns(true); | ||
walletStub.request | ||
.onThirdCall() | ||
.returns({ privateKey: 'aba2dd1a12eeafda3fda62aa6dfa21ca2aa6dfaba13fda6a22ea2dd1eafda1ca' }); | ||
const encodedResult = await exportAccount("password"); | ||
|
||
expect(encodedResult).not.to.be.eq(nonEncodedResult) | ||
}); | ||
|
||
it('should return null on negative prompt', async function () { | ||
walletStub.request.onFirstCall().returns(false); | ||
const result = await exportAccount(); | ||
expect(result).to.be.eq(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters