From df74001ca7096c3a18460bcc4bb3c76bfcefd1d0 Mon Sep 17 00:00:00 2001 From: James Chartrand Date: Mon, 7 Oct 2024 12:23:46 -0400 Subject: [PATCH] handle issuer property as string --- src/issue.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/issue.js b/src/issue.js index 3f8fab4..8fdedfd 100644 --- a/src/issue.js +++ b/src/issue.js @@ -44,13 +44,24 @@ const getIssuerInstance = async (instanceId) => { return ISSUER_INSTANCES[instanceId] } -const issue = async (unsignedVerifiableCredential, issuerId) => { - const { issuerInstance, didDocument } = await getIssuerInstance(issuerId) - unsignedVerifiableCredential.issuer.id = didDocument.id - const signedCredential = await issuerInstance.issueCredential({ +const issue = async (unsignedVerifiableCredential, instanceId) => { + const { + issuerInstance, + didDocument: { id: issuerId } + } = await getIssuerInstance(instanceId) + addIssuerId(unsignedVerifiableCredential, issuerId) + const signedVerifiableCredential = await issuerInstance.issueCredential({ credential: unsignedVerifiableCredential }) - return signedCredential + return signedVerifiableCredential +} + +const addIssuerId = (vc, issuerId) => { + if (vc.issuer && typeof vc.issuer === 'string') { + vc.issuer = issuerId + } else { + ;(vc.issuer ??= {}).id = issuerId + } } const buildIssuerInstance = async (seed, method, url) => {