Skip to content

Commit

Permalink
fix: allow importing the self key (#2700)
Browse files Browse the repository at this point in the history
Because the keychain doesn't create keys, only accepts them, allow
importing the "self" key.

If the key already exists it will fail, and you still can't remove
or rename it.
  • Loading branch information
achingbrain committed Sep 13, 2024
1 parent 62ce7b2 commit 34455b5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
2 changes: 1 addition & 1 deletion packages/keychain/src/keychain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class Keychain implements KeychainInterface {
}

async importKey (name: string, key: PrivateKey): Promise<KeyInfo> {
if (!validateKeyName(name) || name === 'self') {
if (!validateKeyName(name)) {
await randomDelay()
throw new InvalidParametersError(`Invalid key name '${name}'`)
}
Expand Down
12 changes: 0 additions & 12 deletions packages/keychain/test/keychain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,6 @@ describe('keychain', () => {
const importedKey = await ks.importKey(keyName, exportedKey)
expect(importedKey.id).to.eql(keyInfo.id)
})

it('cannot create the "self" key', async () => {
const key = await generateKeyPair('Ed25519')

await expect(ks.importKey('self', key)).to.eventually.be.rejected
.with.property('name', 'InvalidParametersError')
})
})

describe('query', () => {
Expand Down Expand Up @@ -268,11 +261,6 @@ describe('keychain', () => {
.with.property('name', 'InvalidParametersError')
})

it('cannot create the "self" key', async () => {
await expect(ks.renameKey(rsaKeyName, 'self')).to.eventually.be.rejected
.with.property('name', 'InvalidParametersError')
})

it('removes the existing key name', async () => {
const key = await ks.renameKey(rsaKeyName, renamedRsaKeyName)
expect(key).to.exist()
Expand Down

0 comments on commit 34455b5

Please sign in to comment.