Skip to content

Commit

Permalink
fix: Remove static Credential.credentialStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed May 5, 2020
1 parent 8347b1f commit 719fddc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 52 deletions.
3 changes: 0 additions & 3 deletions packages/daf-core/src/entities/credential.ts
Expand Up @@ -83,9 +83,6 @@ export class Credential extends BaseEntity {
@Column({ nullable: true })
expirationDate?: Date

@Column('simple-json', { nullable: true })
credentialStatus?: object

@Column('simple-array')
context: string[]

Expand Down
44 changes: 29 additions & 15 deletions packages/daf-core/src/graphql/graphql-core.ts
Expand Up @@ -119,7 +119,10 @@ function decorateQB(

if (input?.order) {
for (const item of input.order) {
qb = qb.orderBy(`${qb.connection.driver.escape(tablename)}.${qb.connection.driver.escape(item.column)}`, item.direction)
qb = qb.orderBy(
`${qb.connection.driver.escape(tablename)}.${qb.connection.driver.escape(item.column)}`,
item.direction,
)
}
}
return qb
Expand Down Expand Up @@ -234,9 +237,12 @@ const credentials = async (_: any, args: FindArgs, ctx: Context) => {
if (ctx.authenticatedDid) {
qb = qb.andWhere(
new Brackets(qb => {
qb.where('credential.subject = :ident', { ident: ctx.authenticatedDid }).orWhere('credential.issuer = :ident', {
ident: ctx.authenticatedDid,
})
qb.where('credential.subject = :ident', { ident: ctx.authenticatedDid }).orWhere(
'credential.issuer = :ident',
{
ident: ctx.authenticatedDid,
},
)
}),
)
}
Expand All @@ -255,9 +261,12 @@ const credentialsCount = async (_: any, args: FindArgs, ctx: Context) => {
if (ctx.authenticatedDid) {
qb = qb.andWhere(
new Brackets(qb => {
qb.where('credential.subject = :ident', { ident: ctx.authenticatedDid }).orWhere('credential.issuer = :ident', {
ident: ctx.authenticatedDid,
})
qb.where('credential.subject = :ident', { ident: ctx.authenticatedDid }).orWhere(
'credential.issuer = :ident',
{
ident: ctx.authenticatedDid,
},
)
}),
)
}
Expand Down Expand Up @@ -321,7 +330,7 @@ export const resolvers = {

Query: {
identity: async (_: any, { did }, ctx: Context) =>
(checkAuthIdentity(did, ctx.authenticatedDid)) &&
checkAuthIdentity(did, ctx.authenticatedDid) &&
(await ctx.agent.dbConnection).getRepository(Identity).findOne(did),
identities: async (_: any, { input }, ctx: Context) => {
if (ctx.authenticatedDid) {
Expand All @@ -339,9 +348,12 @@ export const resolvers = {
if (ctx.authenticatedDid) {
qb = qb.andWhere(
new Brackets(qb => {
qb.where('message.to = :ident', { ident: ctx.authenticatedDid }).orWhere('message.from = :ident', {
ident: ctx.authenticatedDid,
})
qb.where('message.to = :ident', { ident: ctx.authenticatedDid }).orWhere(
'message.from = :ident',
{
ident: ctx.authenticatedDid,
},
)
}),
)
}
Expand Down Expand Up @@ -400,9 +412,12 @@ export const resolvers = {
if (ctx.authenticatedDid) {
qb = qb.andWhere(
new Brackets(qb => {
qb.where('claim.subject = :ident', { ident: ctx.authenticatedDid }).orWhere('claim.issuer = :ident', {
ident: ctx.authenticatedDid,
})
qb.where('claim.subject = :ident', { ident: ctx.authenticatedDid }).orWhere(
'claim.issuer = :ident',
{
ident: ctx.authenticatedDid,
},
)
}),
)
}
Expand Down Expand Up @@ -735,7 +750,6 @@ export const typeDefs = `
context: [String]
type: [String]
credentialSubject: Object
credentialStatus: Object
claims: [Claim]
presentations: [Presentation]
messages: [Message]
Expand Down
23 changes: 0 additions & 23 deletions packages/daf-core/src/migrations/CredentialStatus1587985317000.ts

This file was deleted.

4 changes: 1 addition & 3 deletions packages/daf-core/src/migrations/index.ts
@@ -1,3 +1 @@
import { CredentialStatus1587985317000 } from './CredentialStatus1587985317000'

export const migrations = [CredentialStatus1587985317000]
export const migrations = []
9 changes: 6 additions & 3 deletions packages/daf-w3c/src/__tests__/credentialStatus.test.ts
@@ -1,7 +1,8 @@
import { W3cActionHandler, ActionTypes, ActionSignW3cVc } from '../index'
import { SimpleSigner } from 'did-jwt'
import { SimpleSigner, decodeJWT } from 'did-jwt'
import { Resolver } from 'did-resolver'
import { ActionSignW3cVp } from '../action-handler'
import { Credential } from 'daf-core'

const privateKey = 'a285ab66393c5fdda46d6fbad9e27fafd438254ab72ad5acb681a0e9f20f5d7b'
const signerAddress = '0x2036c6cd85692f0fb2c26e6c6b2eced9e4478dfd'
Expand Down Expand Up @@ -92,14 +93,16 @@ describe('daf-w3c', () => {
},
}

let result = await actionHandler.handleAction(
let result: Credential = await actionHandler.handleAction(
{
type: ActionTypes.signCredentialJwt,
data,
} as ActionSignW3cVc,
mockAgent as any,
)

expect(result.credentialStatus).toMatchObject({ type: 'TestStatusMethod', id: 'local' })
const decoded = decodeJWT(result.raw)

expect(decoded.payload.credentialStatus).toMatchObject({ type: 'TestStatusMethod', id: 'local' })
})
})
1 change: 0 additions & 1 deletion packages/daf-w3c/src/__tests__/message-handler.test.ts
Expand Up @@ -136,6 +136,5 @@ describe('daf-w3c', () => {
expect(handled.type).toEqual(MessageTypes.vc)
expect(handled.from.did).toEqual('did:ethr:0x54d59e3ffd76917f62db702ac354b17f3842955e')
expect(handled.to.did).toEqual('did:web:uport.me')
expect(handled.credentials[0].credentialStatus).toEqual(message.data['credentialStatus'])
})
})
4 changes: 0 additions & 4 deletions packages/daf-w3c/src/message-handler.ts
Expand Up @@ -106,10 +106,6 @@ export function createCredential(payload: VerifiableCredentialPayload, jwt: stri
vc.expirationDate = timestampToDate(payload.exp)
}

if (payload.credentialStatus) {
vc.credentialStatus = payload.credentialStatus
}

vc.context = payload.vc['@context']
vc.type = payload.vc.type

Expand Down

0 comments on commit 719fddc

Please sign in to comment.