Skip to content

Commit

Permalink
feat: Add credentialSchema attribute (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran authored Jun 13, 2023
1 parent d0ed63c commit 0e4268a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/services/connectors/verida.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class VeridaService {
messageSubject: string,
credential: VerifiableCredential,
credentialName: string,
credentialSchema: string,
credentialSummary?: string
) {
// The Credential record is how Verida wrap the credential to store it on the Network. Check the JSdoc of the type and each property. They are following the Verida Credential Record schema.
Expand All @@ -127,7 +128,7 @@ export class VeridaService {
summary: credentialSummary,
schema: VERIDA_CREDENTIAL_RECORD_SCHEMA,
didJwtVc: credential.proof.jwt,
credentialSchema: (credential['@context'] as string[]).find(e => !VC_CONTEXT.includes(e)) || VC_CONTEXT[0],
credentialSchema,
credentialData: credential,
}
await this.sendData(recipientDid, messageSubject, credentialRecord)
Expand Down
5 changes: 4 additions & 1 deletion src/services/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
VC_CONTEXT,
VC_TYPE
} from '../types/constants.js'
import { CredentialRequest, StatusOptions, VerifyStatusOptions } from '../types/types.js'
import { CredentialRequest, VerifyStatusOptions } from '../types/types.js'
import { Identity } from './identity/index.js'
import { VeridaService } from '../services/connectors/verida.js'
import { v4 } from 'uuid'
Expand All @@ -21,6 +21,7 @@ export class Credentials {
'@context': [ ...request['@context'] || [], ...VC_CONTEXT ],
type: [ ...request.type || [], VC_TYPE ],
issuer: { id: request.issuerDid },
credentialSchema: request.credentialSchema,
credentialSubject: {
id: request.subjectDid,
...request.attributes
Expand All @@ -37,11 +38,13 @@ export class Credentials {
let verifiable_credential = await Identity.instance.createCredential(credential, request.format, statusOptions, agentId)

if (ENABLE_VERIDA_CONNECTOR === 'true' && request.subjectDid.startsWith('did:vda')) {
if(!request.credentialSchema) throw new Error('Credential schema is required')
await VeridaService.instance.sendCredential(
request.subjectDid,
"New Verifiable Credential",
verifiable_credential,
request.credentialName || v4(),
request.credentialSchema,
request.credentialSummary
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/identity/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class PostgresIdentity implements IIdentity {
try {
const did = typeof(credential.issuer) == 'string' ? credential.issuer : credential.issuer.id
if (!await CustomerService.instance.find(agentId, {did})) {
throw new Error('Customer not found')
throw new Error(`${did} not found in wallet`)
}
const agent = await this.createAgent(agentId)
return await Veramo.instance.createCredential(agent, credential, format, statusListOptions)
Expand Down

0 comments on commit 0e4268a

Please sign in to comment.