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
feat: export account json rpc #234
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
jsonPassphrase
there is no usage of it in snapThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left it optional because polkadot js extension must have a passphrase to successfully import account.
![Screenshot from 2024-06-18 13-20-33](https://private-user-images.githubusercontent.com/51483483/340654897-e2903416-7d0e-4706-b59b-b50e6040b64b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTUzODMsIm5iZiI6MTczODk5NTA4MywicGF0aCI6Ii81MTQ4MzQ4My8zNDA2NTQ4OTctZTI5MDM0MTYtN2QwZS00NzA2LWI1OWItYjUwZTYwNDBiNjRiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA2MTEyM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBmYmRiMmUyOTc3NzEwMjA2NTdjYzE3ZDkyYWNkYmIxNDYxNDYyZGRhYzk3NDVhYzFlYjEyNDZlNjYwYjEwOTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.dc0uh78UBwbICWoPS0zmOyNAyX8A8RqNC1QVjS9ilx4)
Leaving it as empty field does not allow restoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but like reviewing exportAccount.test.ts seems like there is no point of using it
If the extension uses a password field that is not used anywhere (bad U, itX) should not affect our API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we wouldn't allow this option, we lose nothing extending the already existing
KeyringPair.toJson(passphrase?: string)
method.