Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): remove revocable and send options from credential create command #1345

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/default/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ credentialIssuerLD:
$args:
- suites:
- $require: '@veramo/credential-ld#VeramoEd25519Signature2018'
- $require: '@veramo/credential-ld#VeramoEd25519Signature2020'
- $require: '@veramo/credential-ld#VeramoJsonWebSignature2020'
- $require: '@veramo/credential-ld#VeramoEcdsaSecp256k1RecoverySignature2020'
contextMaps:
# The LdDefaultContext is a "catch-all" for now.
Expand Down
74 changes: 12 additions & 62 deletions packages/cli/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import { Command } from 'commander'
import inquirer from 'inquirer'
import qrcode from 'qrcode-terminal'
import * as fs from 'fs'
import * as json5 from 'json5'
import json5 from 'json5'
import { readStdin } from './util.js'
import { CredentialPayload } from '@veramo/core-types'
import Debug from 'debug'

import fuzzy from 'fuzzy'

const debug = Debug('veramo:cli:credential')
const credential = new Command('credential').description('W3C Verifiable Credential')

credential
.command('create', { isDefault: true })
.description('Create W3C Verifiable Credential')
.option('-s, --send', 'Send')
.command('create')
.description('Create W3C Verifiable Credential (for demo purposes)')
.option('-j, --json', 'Output in JSON')
.option('-q, --qrcode', 'Show qrcode')
.action(async (opts: { send: boolean; qrcode: boolean; json: boolean }, cmd: Command) => {
Expand Down Expand Up @@ -74,15 +75,6 @@ credential
message: 'Claim Value',
default: 'Alice',
},
{
type: 'list',
name: 'addStatus',
message: 'Is the credential revocable?',
choices: [
{ name: 'Yes', value: true },
{ name: 'No', value: false },
],
},
])

const credentialSubject: any = {}
Expand All @@ -98,66 +90,22 @@ credential
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',
// TODO(nickreynolds): deploy
default: 'goerli:0x97fd27892cdcD035dAe1fe71235c636044B59348',
},
])

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

const verifiableCredential = await agent.createVerifiableCredential({
save: true,
credential,
proofFormat: answers.proofFormat,
})

if (opts.send) {
let body
let type
if (answers.proofFormat == 'jwt') {
body = verifiableCredential.proof.jwt
type = 'jwt'
} else {
body = verifiableCredential
type = 'w3c.vc'
}
try {
const message = await agent.sendMessageDIDCommAlpha1({
save: true,
data: {
from: answers.iss,
to: answers.sub,
type,
body,
},
})
console.dir(message, { depth: 10 })
} catch (e) {
console.error(e)
}
try {
const saved = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential })
} catch (e: any) {
debug('could not save credential', e)
}

if (opts.qrcode) {
qrcode.generate(verifiableCredential.proof.jwt)
} else {
if (opts.json) {
console.log(JSON.stringify(verifiableCredential, null, 2))
console.log(JSON.stringify(verifiableCredential))
} else {
console.dir(verifiableCredential, { depth: 10 })
}
Expand All @@ -177,12 +125,14 @@ credential
} else if (options.filename) {
raw = await fs.promises.readFile(options.filename, 'utf-8')
} else {
console.log('Please provide the credential as a JWT or JSON string. Press Ctrl+D to finish.');
raw = await readStdin()
}
let parsedCredential: any
try {
parsedCredential = json5.parse(raw)
} catch (e: any) {
debug('Could not parse credential as JSON5', e.message)
parsedCredential = raw
}
try {
Expand Down
Loading