Skip to content

Commit

Permalink
fix: CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Oct 19, 2020
1 parent 864de97 commit 86b6f9e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 32 deletions.
4 changes: 4 additions & 0 deletions packages/daf-cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
32 changes: 23 additions & 9 deletions packages/daf-cli/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -137,9 +143,10 @@ program

const identities = [
{
name: 'Enter manualy',
name: 'Enter manually',
value: 'manual',
},
...ids.map((id) => id.did),
]

let aud = null
Expand All @@ -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',
},
])

Expand All @@ -172,7 +186,7 @@ program
{
type: 'input',
name: 'aud',
message: 'Enter audience DID',
message: 'Enter Verifier DID',
},
])
aud = audAnswer.aud
Expand All @@ -192,7 +206,7 @@ program
JSON.stringify(credential.verifiableCredential.credentialSubject) +
' | Issuer: ' +
credential.verifiableCredential.issuer.id,
value: credential,
value: credential.verifiableCredential,
})
}

Expand Down Expand Up @@ -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,
},
Expand Down
15 changes: 9 additions & 6 deletions packages/daf-cli/src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}
Expand Down
38 changes: 28 additions & 10 deletions packages/daf-cli/src/sdr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)',
},
])

Expand Down Expand Up @@ -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) {
Expand All @@ -215,6 +232,7 @@ program
if (cmd.qrcode) {
qrcode.generate(jwt)
} else {
console.dir(data, { depth: 10 })
console.log(`jwt: ${jwt}`)
}
})
15 changes: 8 additions & 7 deletions packages/daf-selective-disclosure/src/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 (
Expand Down

0 comments on commit 86b6f9e

Please sign in to comment.