Skip to content

Commit

Permalink
Rename remotePublicKey param to publicKey.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Nov 5, 2023
1 parent 0405db3 commit 52ac415
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @digitalbazaar/ecdsa-multikey ChangeLog

## 1.5.0 - 2023-11-dd

### Added
- Rename `remotePublicKey` param to `publicKey` for `deriveSecret()` to get
better compatibility with WebKMS Client KeyAgreementKey interface. The
param can still be passed as `remotePublicKey` but this is considered
deprecated.

## 1.4.0 - 2023-11-05

### Added
Expand Down
10 changes: 8 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,20 @@ async function _createKeyPairInterface({keyPair, keyAgreement = false}) {
const {id, publicKey} = keyPair;
return createVerifier({id, publicKey});
},
async deriveSecret({remotePublicKey} = {}) {
// pass `publicKey`, as `remotePublicKey` is just a backwards compatible
// alias
async deriveSecret({publicKey, remotePublicKey} = {}) {
if(remotePublicKey && publicKey) {
throw new Error(
'Only one of "remotePublicKey" and "publicKey" must be given.');
}
if(!keyPair.keyAgreement) {
const error = Error('"keyAgreement" is not supported by this keypair.');
error.name = 'NotSupportedError';
throw error;
}
return _deriveSecret(
{localKeyPair: this, remoteKeyPair: remotePublicKey});
{localKeyPair: this, remoteKeyPair: remotePublicKey || publicKey});
}
};

Expand Down
6 changes: 3 additions & 3 deletions test/EcdsaMultikey.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('EcdsaMultikey', () => {

let err;
try {
await keyPair.deriveSecret({remotePublicKey: keyPair});
await keyPair.deriveSecret({publicKey: keyPair});
} catch(e) {
err = e;
}
Expand All @@ -58,8 +58,8 @@ describe('EcdsaMultikey', () => {
const keyPair2 = await EcdsaMultikey.generate(
{curve: 'P-256', keyAgreement: true});

const secret1 = await keyPair1.deriveSecret({remotePublicKey: keyPair2});
const secret2 = await keyPair2.deriveSecret({remotePublicKey: keyPair1});
const secret1 = await keyPair1.deriveSecret({publicKey: keyPair2});
const secret2 = await keyPair2.deriveSecret({publicKey: keyPair1});

expect(secret1).to.deep.eql(secret2);
});
Expand Down

0 comments on commit 52ac415

Please sign in to comment.