Skip to content

Commit

Permalink
Refine computeId method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kezike committed Oct 20, 2023
1 parent d753c37 commit b9fde7c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/DidJwkDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ or a valid encryption value (${DidJwk.encryptionAlgorithms.join(', ')}) .`);
* @returns {string} Returns the key's id.
*/
async computeId({keyPair}) {
return `${keyPair.controller}#0`;
if(!keyPair?.id) {
throw new TypeError('"keyPair" must have an "id" property.');
}

const [didAuthority, keyIdFragment] = keyPair.id.split('#');
if(didAuthority) {
if(keyIdFragment) {
return keyPair.id;
}
return didAuthority;
}
return `${keyPair.controller}#${keyPair.id}`;
}
}

0 comments on commit b9fde7c

Please sign in to comment.