diff --git a/packages/daf-cli/src/cli.ts b/packages/daf-cli/src/cli.ts index c798adc55..93b27ab52 100644 --- a/packages/daf-cli/src/cli.ts +++ b/packages/daf-cli/src/cli.ts @@ -1,4 +1,8 @@ import program from 'commander' +import inquirer from 'inquirer' + +inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt')) + import './identity-manager' import './did-resolver' import './credential' diff --git a/packages/daf-cli/src/credential.ts b/packages/daf-cli/src/credential.ts index 1050eff26..21ae11528 100644 --- a/packages/daf-cli/src/credential.ts +++ b/packages/daf-cli/src/credential.ts @@ -32,6 +32,12 @@ program message: 'Subject DID', default: identities[0].did, }, + { + type: 'input', + name: 'type', + message: 'Credential Type', + default: 'VerifiableCredential,Profile', + }, { type: 'input', name: 'claimType', @@ -63,7 +69,7 @@ program const credential: W3CCredential = { issuer: { id: answers.iss }, '@context': ['https://www.w3.org/2018/credentials/v1'], - type: ['VerifiableCredential'], + type: answers.type.split(','), issuanceDate: new Date().toISOString(), credentialSubject, } @@ -137,9 +143,10 @@ program const identities = [ { - name: 'Enter manualy', + name: 'Enter manually', value: 'manual', }, + ...ids.map((id) => id.did), ] let aud = null @@ -152,18 +159,25 @@ program value: item.did, })), - message: 'Issuer DID', + message: 'Holder DID', }, { type: 'input', name: 'tag', - message: 'Tag', + message: 'Tag (threadId)', + default: 'xyz123', }, { type: 'list', name: 'aud', - message: 'Audience DID', - choices: ids.map((id) => id.did), + message: 'Verifier DID', + choices: identities, + }, + { + type: 'input', + name: 'type', + message: 'Presentation type', + default: 'VerifiablePresentation,Profile', }, ]) @@ -172,7 +186,7 @@ program { type: 'input', name: 'aud', - message: 'Enter audience DID', + message: 'Enter Verifier DID', }, ]) aud = audAnswer.aud @@ -192,7 +206,7 @@ program JSON.stringify(credential.verifiableCredential.credentialSubject) + ' | Issuer: ' + credential.verifiableCredential.issuer.id, - value: credential, + value: credential.verifiableCredential, }) } @@ -228,7 +242,7 @@ program verifier: [aud], tag: answers.tag, '@context': ['https://www.w3.org/2018/credentials/v1'], - type: ['VerifiablePresentation'], + type: answers.type.split(','), issuanceDate: new Date().toISOString(), verifiableCredential, }, diff --git a/packages/daf-cli/src/execute.ts b/packages/daf-cli/src/execute.ts index 0d9dd1813..68a6bdf8d 100644 --- a/packages/daf-cli/src/execute.ts +++ b/packages/daf-cli/src/execute.ts @@ -7,8 +7,6 @@ const fs = require('fs') const OasResolver = require('oas-resolver') const fuzzy = require('fuzzy') -inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt')) - program .command('execute') .description('Executes agent method') @@ -64,6 +62,7 @@ program case 'object': question.type = 'input' question.filter = (input: string) => JSON.parse(input === '' ? '{}' : input) + question.transformer = (input: object) => JSON.stringify(input) break case 'string': question.type = 'input' @@ -100,12 +99,16 @@ program argsObj = JSON.parse(argsString) } + console.log('\nMethod: ', method) + console.log('\nArguments: ', JSON.stringify(argsObj, null, 2)) + const result = await agent.execute(method, argsObj) - if (methodApi.returnType.description) { - console.log(methodApi.returnType.description + '\n') - } - console.log(result) + console.log( + '\nResult', + methodApi.returnType.description ? `(${methodApi.returnType.description}):` : ':', + JSON.stringify(result, null, 2), + ) } catch (e) { console.error(e.message) } diff --git a/packages/daf-cli/src/sdr.ts b/packages/daf-cli/src/sdr.ts index 66825b91b..63bc7126c 100644 --- a/packages/daf-cli/src/sdr.ts +++ b/packages/daf-cli/src/sdr.ts @@ -12,6 +12,17 @@ program .action(async (cmd) => { const agent = getAgent(program.config) const identities = await agent.identityManagerGetIdentities() + + const knownDids = await agent.dataStoreORMGetIdentities() + + const subjects = [ + { + name: 'None', + value: '', + }, + ...knownDids.map((id) => id.did), + ] + if (identities.length === 0) { console.error('No dids') process.exit() @@ -24,14 +35,15 @@ program message: 'Issuer DID', }, { - type: 'input', + type: 'list', name: 'sub', - message: 'Subject DID (can be empty)', + message: 'Subject DID', + choices: subjects, }, { type: 'input', name: 'tag', - message: 'Tag', + message: 'Tag (threadId)', }, ]) @@ -182,14 +194,19 @@ program } } + const data: any = { + issuer: answers.iss, + claims, + credentials, + } + if (answers.tag !== '') { + data.tag = answers.tag + } + if (answers.sub !== '') { + data.subject = answers.sub + } const jwt = await agent.createSelectiveDisclosureRequest({ - data: { - issuer: answers.iss, - subject: answers.sub === '' ? undefined : answers.sub, - tag: answers.tag === '' ? undefined : answers.tag, - claims, - credentials, - }, + data, }) if (!cmd.send) { @@ -215,6 +232,7 @@ program if (cmd.qrcode) { qrcode.generate(jwt) } else { + console.dir(data, { depth: 10 }) console.log(`jwt: ${jwt}`) } }) diff --git a/packages/daf-selective-disclosure/src/message-handler.ts b/packages/daf-selective-disclosure/src/message-handler.ts index 2e6e9b0b0..3e1f8ea77 100644 --- a/packages/daf-selective-disclosure/src/message-handler.ts +++ b/packages/daf-selective-disclosure/src/message-handler.ts @@ -38,14 +38,13 @@ export class SdrMessageHandler extends AbstractMessageHandler { message.from = message.data.iss if (message.data.replyTo) { - message.replyTo = Array.isArray(message.data.replyTo) - ? message.data.replyTo - : message.data.replyTo - ? [message.data.replyTo] - : undefined + ? message.data.replyTo + : message.data.replyTo + ? [message.data.replyTo] + : undefined } - + if (message.data.replyUrl) { message.replyUrl = message.data.replyUrl } @@ -54,7 +53,9 @@ export class SdrMessageHandler extends AbstractMessageHandler { message.to = message.data.subject } - message.threadId = message.data.tag + if (message.data.tag) { + message.threadId = message.data.tag + } message.createdAt = this.timestampToDate(message.data.nbf || message.data.iat).toISOString() if (