Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set vc.issuer appropriately #32

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,39 @@ 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 = (credential, issuerId) => {
if (!credential.issuer) {
throw new SigningException(
420,
'An issuer property, either string or object, must be present.'
)
} else if (Array.isArray(credential.issuer)) {
throw new SigningException(
420,
'An issuer property cannot be an Array, only a string or object.'
)
} else if (typeof credential.issuer === 'string') {
credential.issuer = issuerId
} else if (typeof credential.issuer === 'object') {
credential.issuer.id = issuerId
} else {
throw new SigningException(
420,
'The issuer property must be either a string or an object.'
)
}
}

const buildIssuerInstance = async (seed, method, url) => {
Expand Down
Loading