mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-13 09:31:42 +00:00
feat: add exporting/importing of non rsa keys in libp2p-key format (#179)
* feat: add exporting/importing of ed25519 keys in libp2p-key format * feat: add libp2p-key export/import support for rsa and secp keys * chore: dep bumps * chore: update aegir * refactor: import and export base64 strings * refactor: simplify api for now * chore: fix lint * refactor: remove extraneous param * refactor: clean up * fix: review patches
This commit is contained in:
@ -85,6 +85,26 @@ describe('ed25519', function () {
|
||||
expect(id).to.be.a('string')
|
||||
})
|
||||
|
||||
it('should export a password encrypted libp2p-key', async () => {
|
||||
const key = await crypto.keys.generateKeyPair('Ed25519')
|
||||
const encryptedKey = await key.export('my secret')
|
||||
// Import the key
|
||||
const importedKey = await crypto.keys.import(encryptedKey, 'my secret')
|
||||
expect(key.equals(importedKey)).to.equal(true)
|
||||
})
|
||||
|
||||
it('should fail to import libp2p-key with wrong password', async () => {
|
||||
const key = await crypto.keys.generateKeyPair('Ed25519')
|
||||
const encryptedKey = await key.export('my secret', 'libp2p-key')
|
||||
try {
|
||||
await crypto.keys.import(encryptedKey, 'not my secret')
|
||||
} catch (err) {
|
||||
expect(err).to.exist()
|
||||
return
|
||||
}
|
||||
expect.fail('should have thrown')
|
||||
})
|
||||
|
||||
describe('key equals', () => {
|
||||
it('equals itself', () => {
|
||||
expect(
|
||||
|
Reference in New Issue
Block a user