Skip to content

Commit

Permalink
fix: Dockerfile permission && credential verification [CU-85zt6ng2p] (#…
Browse files Browse the repository at this point in the history
…239)

* fix: Dockerfile permission && credential verification

* fix: Update Credential output to contain vc

* feat: Remove vc original fields
  • Loading branch information
DaevMithran authored Jun 1, 2023
1 parent cf10b28 commit 45bb6d7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,6 @@ cython_debug/
#.idea/
cred.json
_wrangler.toml

# verida
v[0-9,a-z]*
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ ENV VERIDA_PRIVATE_KEY ${VERIDA_PRIVATE_KEY}
ENV POLYGON_PRIVATE_KEY ${POLYGON_PRIVATE_KEY}
ENV VERIDA_NETWORK ${VERIDA_NETWORK}

RUN chown -R node:node /home/node/app

# Specify default port
EXPOSE ${PORT}

Expand Down
3 changes: 0 additions & 3 deletions src/controllers/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ export class CredentialController {
return response.status(400).json({ error: result.array()[0].msg })
}
try {
if(request.body.credential.proof.jws) {
return response.status(200).json(await Credentials.instance.verifyCredentialLd(request.body.credential, response.locals.customerId))
}
return response.status(200).json(await Credentials.instance.verify_credentials(request.body.credential, response.locals.customerId))
} catch (error) {
return response.status(500).json({
Expand Down
49 changes: 13 additions & 36 deletions src/services/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,20 @@ export class Credentials {

const agent = await Identity.instance.create_agent(agentId)
let verifiable_credential: VerifiableCredential
if (request.format == 'jsonld') {
verifiable_credential = await agent.createVerifiableCredentialLD({
verifiable_credential = await agent.createVerifiableCredential(
{
save: false,
credential,
fetchRemoteContexts: true
})
} else {
verifiable_credential = await agent.execute(
'createVerifiableCredential',
{
save: false,
credential,
proofFormat: VC_PROOF_FORMAT,
removeOriginalFields: VC_REMOVE_ORIGINAL_FIELDS
}
)
}
proofFormat: request.format == 'jsonld' ? 'lds' : VC_PROOF_FORMAT,
removeOriginalFields: VC_REMOVE_ORIGINAL_FIELDS
}
)

if (verifiable_credential?.vc) delete verifiable_credential.vc
if (verifiable_credential?.sub) delete verifiable_credential.sub
if (verifiable_credential?.iss) delete verifiable_credential.iss
if (verifiable_credential?.nbf) delete verifiable_credential.nbf
if (verifiable_credential?.exp) delete verifiable_credential.exp
// if (verifiable_credential?.vc) delete verifiable_credential.vc
// if (verifiable_credential?.sub) delete verifiable_credential.sub
// if (verifiable_credential?.iss) delete verifiable_credential.iss
// if (verifiable_credential?.nbf) delete verifiable_credential.nbf
// if (verifiable_credential?.exp) delete verifiable_credential.exp

if (USE_VERIDA_CONNECTOR && request.subjectDid.startsWith('did:vda')) {
await VeridaService.instance.sendCredential(
Expand All @@ -73,26 +65,11 @@ export class Credentials {

async verify_credentials(credential: W3CVerifiableCredential | string, agentId: string): Promise<IVerifyResult> {
const agent = await Identity.instance.create_agent(agentId)
const result = await agent.execute(
'verifyCredential',
{
credential
}
)
const result = await agent.verifyCredential({ credential, fetchRemoteContexts: true })
delete(result.payload)
return result
}

async verifyCredentialLd(credential: VerifiableCredential, agentId: string): Promise<boolean> {
const agent = await Identity.instance.create_agent(agentId)
const result = await agent.verifyCredentialLD({
credential,
fetchRemoteContexts: true
}
)
return result
}

async verify_presentation(presentation: W3CVerifiablePresentation, agentId: string): Promise<IVerifyResult> {
const agent = await Identity.instance.create_agent(agentId)
const result = await agent.execute(
Expand Down
12 changes: 11 additions & 1 deletion src/services/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
IKeyManager,
IResolver,
ICredentialIssuer,
ICredentialVerifier,
} from '@veramo/core'
import { CredentialPlugin } from '@veramo/credential-w3c'
import { DIDManager } from '@veramo/did-manager'
Expand Down Expand Up @@ -101,7 +102,16 @@ export class Identity {
}
)

return createAgent<IDIDManager & IKeyManager & IDataStore & IResolver & ICredentialIssuer & ICheqd & ICredentialIssuerLD>({
return createAgent<
IDIDManager &
IKeyManager &
IDataStore &
IResolver &
ICredentialIssuer &
ICredentialVerifier &
ICheqd &
ICredentialIssuerLD
>({
plugins: [
new KeyManager({
store: new KeyStore(dbConnection),
Expand Down
2 changes: 1 addition & 1 deletion src/types/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const HEADERS = {
export const VC_CONTEXT = ['https://www.w3.org/2018/credentials/v1', 'https://veramo.io/contexts/profile/v1']
export const VC_TYPE: string = 'VerifiableCredential'
export const VC_PROOF_FORMAT = 'jwt'
export const VC_REMOVE_ORIGINAL_FIELDS = false
export const VC_REMOVE_ORIGINAL_FIELDS = true
export const CORS_ERROR_MSG = 'The CORS policy for this site does not allow access from the specified Origin.'


Expand Down
2 changes: 1 addition & 1 deletion swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
"properties": {
"credential": {
"type": "string",
"example": "<Place the JWT here>"
"example": "<Place the credential object or JWT string here>"
}
}
}
Expand Down

0 comments on commit 45bb6d7

Please sign in to comment.