Skip to content

Commit

Permalink
feat: Credential Status in data model
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Apr 27, 2020
1 parent 24ad82a commit 24e2d5d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/Docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ const data = {
id: 'did:example:1234',
name: 'Alice',
},
credentialStatus:{
type: "EthrStatusRegistry2019",
id:"rinkeby:0x97fd27892cdcD035dAe1fe71235c636044B59348"
}
}
```

Expand Down
48 changes: 41 additions & 7 deletions packages/daf-cli/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ program
type: 'input',
name: 'sub',
message: 'Subject DID',
default: identities[0].did
},
{
type: 'input',
Expand All @@ -41,22 +42,55 @@ program
message: 'Claim Value',
default: 'Alice',
},
{
type: 'list',
name: 'addStatus',
message: 'Add credential status info?',
choices: [
{ name: 'Yes', value: true },
{ name: 'No', value: false },
],
},
])

const credentialSubject: any = {}
credentialSubject.id = answers.sub
const type: string = answers.claimType
credentialSubject[type] = answers.claimValue

const data = {
issuer: answers.iss,
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
credentialSubject
}

if (answers.addStatus) {
const statusAnswers = await inquirer.prompt([
{
type: 'input',
name: 'type',
message: 'Credential status type',
default: 'EthrStatusRegistry2019',
},
{
type: 'input',
name: 'id',
message: 'Credential status ID',
default: 'rinkeby:0x97fd27892cdcD035dAe1fe71235c636044B59348',
},
])

data['credentialStatus'] = {
type: statusAnswers.type,
id: statusAnswers.id
}
}

const signAction: W3c.ActionSignW3cVc = {
type: W3c.ActionTypes.signCredentialJwt,
save: true,
data: {
issuer: answers.iss,
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
credentialSubject,
},
data
}

const credential: Daf.Credential = await agent.handleAction(signAction)
Expand Down Expand Up @@ -200,7 +234,7 @@ program
tag: answers.tag,
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiablePresentation'],
verifiableCredential,
verifiableCredential
},
}

Expand Down
3 changes: 3 additions & 0 deletions packages/daf-core/src/entities/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export class Credential extends BaseEntity {
@Column({ nullable: true })
expirationDate?: Date

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

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

Expand Down
1 change: 1 addition & 0 deletions packages/daf-core/src/graphql/graphql-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ export const typeDefs = `
context: [String]
type: [String]
credentialSubject: Object
credentialStatus: Object
claims: [Claim]
presentations: [Presentation]
messages: [Message]
Expand Down
6 changes: 6 additions & 0 deletions packages/daf-w3c/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ export const resolvers = {
export const typeDefs = `
scalar CredentialSubject
input CredentialStatusInput {
type: String!
id: String!
}
input SignCredentialInput {
id: String
expirationDate: Date
issuer: String!
context: [String]!
type: [String]!
credentialSubject: CredentialSubject!
credentialStatus: CredentialStatusInput
}
input SignPresentationInput {
Expand Down
4 changes: 4 additions & 0 deletions packages/daf-w3c/src/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export function createCredential(payload: VerifiableCredentialPayload, jwt: stri
vc.expirationDate = timestampToDate(payload.exp)
}

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

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

Expand Down

0 comments on commit 24e2d5d

Please sign in to comment.