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 agent creation #1126

Merged
merged 2 commits into from
Feb 17, 2023
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: 1 addition & 1 deletion packages/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ config
.option('-f, --filename <string>', 'Config file name', './agent.yml')
.option('-m, --method <string>', 'Check that a specific method is exposed by the agent.', 'execute')
.action(async (options) => {
const agent = getAgent(options.filename)
const agent = await getAgent(options.filename)
if (!agent) {
console.error(
'unknown error while creating the agent from your config. Consider running `veramo config create` to generate a new configuration file, or to manually compare differences.',
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ credential
.option('-j, --json', 'Output in JSON')
.option('-q, --qrcode', 'Show qrcode')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)
const identifiers = await agent.didManagerFind()

const knownDids = await agent.dataStoreORMGetIdentifiers()
Expand Down Expand Up @@ -170,7 +170,7 @@ credential
.option('-f, --filename <string>', 'Optional. Read the credential from a file instead of stdin')
.option('-r, --raw <string>', 'Optional. Specify the credential as a parameter instead of file or stdin')
.action(async (options) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)
let raw: string = ''
if (options.raw) {
raw = options.raw
Expand Down Expand Up @@ -206,7 +206,7 @@ credential
.command('output')
.description('Print W3C Verifiable Credential to stdout')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

const credentials = await agent.dataStoreORMGetVerifiableCredentials()

Expand Down
22 changes: 11 additions & 11 deletions packages/cli/src/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ did
.command('providers')
.description('list available identifier providers')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

const providers = await agent.didManagerGetProviders()
const list = providers.map((provider) => ({ provider }))
Expand All @@ -26,7 +26,7 @@ did
.command('list', { isDefault: true })
.description('list managed identifiers')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

const list = await agent.didManagerFind()

Expand All @@ -42,7 +42,7 @@ did
.command('create')
.description('create an identifier')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
const providers = await agent.didManagerGetProviders()
Expand Down Expand Up @@ -80,7 +80,7 @@ did
.command('delete')
.description('delete an identifier')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
const identifiers = await agent.didManagerFind()
Expand All @@ -107,7 +107,7 @@ did
.command('add-service')
.description('add a service endpoint to did document')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
const identifiers = await agent.didManagerFind()
Expand Down Expand Up @@ -155,7 +155,7 @@ did
.command('remove-service')
.description('remove a service endpoint from did document')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
const identifiers = await agent.didManagerFind()
Expand Down Expand Up @@ -188,7 +188,7 @@ did
.command('add-key')
.description('create and add a public key to did document')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
const identifiers = await agent.didManagerFind()
Expand Down Expand Up @@ -234,7 +234,7 @@ did
.command('remove-key')
.description('remove a key from did document')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
const identifiers = await agent.didManagerFind()
Expand Down Expand Up @@ -267,7 +267,7 @@ did
.command('export')
.description('export an identifier')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
const identifiers = await agent.didManagerFind()
Expand Down Expand Up @@ -295,7 +295,7 @@ did
.command('import')
.description('import an identifier')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
const answers = await inquirer.prompt([
Expand All @@ -317,7 +317,7 @@ did
.command('resolve <didUrl>')
.description('Resolve DID Document')
.action(async (didUrl) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)
try {
const ddo = await agent.resolveDid({ didUrl })
console.log(JSON.stringify(ddo, null, 2))
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ discover
.option('-q, --query <string>', 'Query string')

.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

const response = await agent.discoverDid({ query: cmd.query })
const list: any = []
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ program
.option('-a, --argsJSON <string>', 'Method arguments')
.option('-f, --argsFile <string>', 'Path to a file containing method arguments in a JSON string')
.action(async (options) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

try {
let method = options.method
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/explore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ program
.command('explore')
.description('launch Verifiable Data explorer')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await (program.opts().config)
await renderMainScreen(agent)
})
4 changes: 2 additions & 2 deletions packages/cli/src/lib/agentCreator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TAgent, IPluginMethodMap } from '@veramo/core-types'
import { createObjects } from './objectCreator.js'

export function createAgentFromConfig<T extends IPluginMethodMap>(config: object): TAgent<T> {
export async function createAgentFromConfig<T extends IPluginMethodMap>(config: object): Promise<TAgent<T>> {
//@ts-ignore
const { agent } = createObjects(config, { agent: '/agent' })
const { agent } = await createObjects(config, { agent: '/agent' })
return agent
}
2 changes: 1 addition & 1 deletion packages/cli/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ message
.option('--save <boolean>', 'Save message', true)

.action(async (options) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)
try {
let raw

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ presentation
.option('-s, --send', 'Send')
.option('-q, --qrcode', 'Show qrcode')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)
const myIdentifiers = await agent.didManagerFind()
if (myIdentifiers.length === 0) {
console.error('No dids')
Expand Down Expand Up @@ -179,7 +179,7 @@ presentation
.option('-f, --filename <string>', 'Optional. Read the presentation from a file instead of stdin')
.option('-r, --raw <string>', 'Optional. Presentation as a parameter string instead of a file or stdin.')
.action(async (options) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)
let raw: string = ''
if (options.raw) {
raw = options.raw
Expand Down Expand Up @@ -216,7 +216,7 @@ presentation
.description('Print W3C Verifiable Presentation to stdout')
.option('-t, --tag <string>', 'Optional. Specify the tag for the presentation.')
.action(async (options) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)

const presentations: UniqueVerifiablePresentation[] = await agent.dataStoreORMGetVerifiablePresentations({})

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/sdr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sdr
.command('create', { isDefault: true })
.description('create Selective Disclosure Request')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)
const identifiers = await agent.didManagerFind()

const knownDids = await agent.dataStoreORMGetIdentifiers()
Expand Down Expand Up @@ -265,7 +265,7 @@ sdr
.command('respond')
.description('respond to Selective Disclosure Request')
.action(async (cmd) => {
const agent = getAgent(program.opts().config)
const agent = await getAgent(program.opts().config)
const sdrMessages = await agent.dataStoreORMGetMessages({
where: [{ column: 'type', value: ['sdr'] }],
order: [{ column: 'createdAt', direction: 'DESC' }],
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export type EnabledInterfaces = IDIDManager &

export type ConfiguredAgent = TAgent<EnabledInterfaces>

export function getAgent(fileName: string): ConfiguredAgent {
export async function getAgent(fileName: string): Promise<ConfiguredAgent> {
try {
return createAgentFromConfig<EnabledInterfaces>(getConfig(fileName))
return await createAgentFromConfig<EnabledInterfaces>(getConfig(fileName))
} catch (e: any) {
console.log('Unable to create agent from ' + fileName + '.', e.message)
process.exit(1)
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@veramo/core-types": "^5.0.0",
"debug": "^4.3.4",
"events": "^3.2.0",
"z-schema": "^5.0.5"
},
Expand Down
4 changes: 3 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.