Skip to content

Commit

Permalink
Allow @context array values in multikeys.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Mar 18, 2024
1 parent 2b73cfc commit f06e984
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}".`);
Expand Down
17 changes: 17 additions & 0 deletions test/EcdsaMultikey.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f06e984

Please sign in to comment.