Skip to content

Commit

Permalink
Include id and controller when importing JWK types.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Oct 2, 2024
1 parent e9b2c6e commit c550cc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @digitalbazaar/ecdsa-multikey ChangeLog

## 1.8.0 - 2024-10-dd

### Added
- Include `id` and `controller` properties when importing key types of
`JsonWebKey` or `JsonWebKey2020`.

## 1.7.0 - 2024-03-17

### Added
Expand Down
17 changes: 15 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ export async function from(key, options = {}) {
if(multikey.type !== 'Multikey') {
// attempt loading from JWK if `publicKeyJwk` is present
if(multikey.publicKeyJwk) {
return fromJwk({jwk: multikey.publicKeyJwk, secretKey: false});
let id;
let controller;
if(multikey.type === 'JsonWebKey' || multikey.type === 'JsonWebKey2020') {
({id, controller} = multikey);
}
return fromJwk({
jwk: multikey.publicKeyJwk, secretKey: false, id, controller
});
}
if(multikey.type) {
multikey = await toMultikey({keyPair: multikey});
Expand All @@ -81,12 +88,18 @@ export async function from(key, options = {}) {
}

// imports key pair from JWK
export async function fromJwk({jwk, secretKey = false} = {}) {
export async function fromJwk({jwk, secretKey = false, id, controller} = {}) {
const multikey = {
'@context': MULTIKEY_CONTEXT_V1_URL,
type: 'Multikey',
publicKeyMultibase: toPublicKeyMultibase({jwk})
};
if(typeof id === 'string') {
multikey.id = id;
}
if(typeof controller === 'string') {
multikey.controller = controller;
}
if(secretKey && jwk.d) {
multikey.secretKeyMultibase = toSecretKeyMultibase({jwk});
}
Expand Down

0 comments on commit c550cc6

Please sign in to comment.