diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d7a1d..0ca2998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Added - Add conversion from `publicKeyJwk` feature via `from()`. +### Fixed +- Allow `@context` array values in multikeys. + ## 1.6.0 - 2023-11-07 ### Added diff --git a/lib/index.js b/lib/index.js index ce5368b..8bdc624 100644 --- a/lib/index.js +++ b/lib/index.js @@ -190,7 +190,9 @@ function _assertMultikey(key) { if(key.type !== 'Multikey') { throw new TypeError('"key" must be a Multikey with type "Multikey".'); } - if(key['@context'] !== MULTIKEY_CONTEXT_V1_URL) { + if(!(key['@context'] === MULTIKEY_CONTEXT_V1_URL || + (Array.isArray(key['@context']) && + key['@context'].includes(MULTIKEY_CONTEXT_V1_URL)))) { throw new TypeError( '"key" must be a Multikey with context ' + `"${MULTIKEY_CONTEXT_V1_URL}".`); diff --git a/test/EcdsaMultikey.spec.js b/test/EcdsaMultikey.spec.js index 031bd83..ec12ef0 100644 --- a/test/EcdsaMultikey.spec.js +++ b/test/EcdsaMultikey.spec.js @@ -202,6 +202,23 @@ describe('EcdsaMultikey', () => { .to.eql(keyPairExported); }); + it('should import with `@context` array', async () => { + const keyPair = await EcdsaMultikey.generate({ + id: '4e0db4260c87cc200df3', + curve: 'P-256' + }); + const keyPairExported = await keyPair.export({ + publicKey: true, secretKey: true + }); + const keyPairImported = await EcdsaMultikey.from({ + ...keyPairExported, + '@context': [{}, keyPairExported['@context']] + }); + + expect(await keyPairImported.export({publicKey: true, secretKey: true})) + .to.eql(keyPairExported); + }); + it('should load `publicKeyJwk`', async () => { const keyPair = await EcdsaMultikey.generate({ id: '4e0db4260c87cc200df3',