From e452de144799b013c5a8f437caaa48b0da1f1715 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Wed, 2 Oct 2024 18:58:50 -0400 Subject: [PATCH] Include `id` and `controller` when importing JWK types. --- CHANGELOG.md | 6 ++++++ lib/index.js | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7663e0..b5c8a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/index.js b/lib/index.js index 8bdc624..8559ac2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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}); @@ -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}); }