diff --git a/CHANGELOG.md b/CHANGELOG.md index efac757..1738227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/index.js b/lib/index.js index 51420d9..e8d8a53 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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}); } }; diff --git a/test/EcdsaMultikey.spec.js b/test/EcdsaMultikey.spec.js index c056986..41ecf52 100644 --- a/test/EcdsaMultikey.spec.js +++ b/test/EcdsaMultikey.spec.js @@ -44,7 +44,7 @@ describe('EcdsaMultikey', () => { let err; try { - await keyPair.deriveSecret({remotePublicKey: keyPair}); + await keyPair.deriveSecret({publicKey: keyPair}); } catch(e) { err = e; } @@ -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); });