Skip to content

Commit

Permalink
feat: Handling credentials in SDR message
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Apr 17, 2020
1 parent b741e72 commit 32d4a2c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
59 changes: 59 additions & 0 deletions packages/daf-cli/src/sdr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,72 @@ program
addMoreRequests = answers4.addMore
}

const answers5 = await inquirer.prompt([
{
type: 'list',
name: 'addCredentials',
message: 'Add profile credentials?',
choices: [
{ name: 'Yes', value: true },
{ name: 'No', value: false },
],
},
])

const credentials = []
if (answers5.addCredentials) {
const vcs = await Daf.Credential.find({
where: { subject: answers.iss },
relations: ['claims'],
})
const list: any = []
if (vcs.length > 0) {
for (const credential of vcs) {
const issuer = credential.issuer.shortDid()
const claims = []
for (const claim of credential.claims) {
claims.push(claim.type + ' = ' + claim.value)
}
list.push({
name: claims.join(', ') + ' | Issuer: ' + issuer,
value: credential.raw,
})
}

let addMoreCredentials = true

while (addMoreCredentials) {
const answers6 = await inquirer.prompt([
{
type: 'list',
name: 'credential',
choices: list,
message: 'Select credential',
},
{
type: 'list',
name: 'addMore',
message: 'Add another credential?',
choices: [
{ name: 'Yes', value: true },
{ name: 'No', value: false },
],
},
])
credentials.push(answers6.credential)
addMoreCredentials = answers6.addMore
}
}
}

const signAction: SD.ActionSignSdr = {
type: SD.ActionTypes.signSdr,
data: {
issuer: answers.iss,
subject: answers.sub === '' ? undefined : answers.sub,
tag: answers.tag === '' ? undefined : answers.tag,
claims,
credentials,
},
}

Expand Down
20 changes: 20 additions & 0 deletions packages/daf-selective-disclosure/src/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ export class SdrMessageHandler extends AbstractMessageHandler {

message.threadId = message.data.tag
message.createdAt = this.timestampToDate(message.data.nbf || message.data.iat)

if (
message.data.credentials &&
Array.isArray(message.data.credentials) &&
message.data.credentials.length > 0
) {
debug('Verifying included credentials')
message.credentials = []
for (const raw of message.data.credentials) {
try {
const tmpMessage = await agent.handleMessage({ raw, save: false })
if (tmpMessage.credentials) {
message.credentials = [...message.credentials, ...tmpMessage.credentials]
}
} catch (e) {
// Unsupported message type, or some other error
debug(e)
}
}
}
return message
}

Expand Down

0 comments on commit 32d4a2c

Please sign in to comment.