Skip to content

Commit

Permalink
feat: Constructing agent from YAML config
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Sep 10, 2020
1 parent 7f0a92d commit 7a2498f
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 355 deletions.
79 changes: 0 additions & 79 deletions packages/daf-cli/default/config.js

This file was deleted.

118 changes: 118 additions & 0 deletions packages/daf-cli/default/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
constants:
secretKey: 29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c
databaseFile: ./database.sqlite
dbConnection:
$require: typeorm?t=function#createConnection
$args:
- type: sqlite
database:
$ref: /constants/databaseFile
synchronize: false
logging: false
entities:
$require: daf-typeorm?t=object#Entities
messageHandler:
$require: daf-message-handler#MessageHandler
$args:
- messageHandlers:
- $require: daf-did-comm#DIDCommMessageHandler
- $require: daf-did-jwt#JwtMessageHandler
- $require: daf-w3c#W3cMessageHandler
- $require: daf-selective-disclosure#SdrMessageHandler
agent:
$require: daf-core#Agent
$args:
- plugins:
- $require: daf-key-manager#KeyManager
$args:
- store:
$require: daf-typeorm#KeyStore
$args:
- $ref: /dbConnection
- $require: daf-libsodium#SecretBox
$args:
- $ref: /constants/secretKey
kms:
local:
$require: daf-libsodium#KeyManagementSystem
- $require: daf-identity-manager#IdentityManager
$args:
- store:
$require: daf-typeorm#IdentityStore
$args:
- $ref: /dbConnection
defaultProvider: did:ethr:rinkeby
providers:
did:ethr:
$require: daf-ethr-did#EthrIdentityProvider
$args:
- defaultKms: local
network: mainnet
rpcUrl: https://mainnet.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
gas: 10001
ttl: 31104001
did:ethr:rinkeby:
$require: daf-ethr-did#EthrIdentityProvider
$args:
- defaultKms: local
network: rinkeby
rpcUrl: https://rinkeby.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
gas: 10001
ttl: 31104001
did:ethr:ropsten:
$require: daf-ethr-did#EthrIdentityProvider
$args:
- defaultKms: local
network: ropsten
rpcUrl: https://ropsten.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
gas: 10001
ttl: 31104001
did:ethr:kovan:
$require: daf-ethr-did#EthrIdentityProvider
$args:
- defaultKms: local
network: kovan
rpcUrl: https://kovan.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
gas: 10001
ttl: 31104001
did:ethr:goerli:
$require: daf-ethr-did#EthrIdentityProvider
$args:
- defaultKms: local
network: goerli
rpcUrl: https://goerli.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
gas: 10001
ttl: 31104001
did:web:
$require: daf-web-did#WebIdentityProvider
$args:
- defaultKms: local
- $require: daf-resolver#DafResolver
$args:
- networks:
- name: mainnet
rpcUrl: https://mainnet.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
- name: rinkeby
rpcUrl: https://rinkeby.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
- name: ropsten
rpcUrl: https://ropsten.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
- name: kovan
rpcUrl: https://kovan.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
- name: goerli
rpcUrl: https://goerli.infura.io/v3/5ffc47f65c4042ce847ef66a3fa70d4c
- name: private
rpcUrl: http://localhost:8545/
registry: '0x05cc574b19a3c11308f761b3d7263bd8608bc532'
# - $require: daf-resolver-universal
# $args:
# - url: https://uniresolver.io/1.0/identifiers/
- $require: daf-typeorm#DataStore
$args:
- $ref: /dbConnection
- $require: daf-typeorm#DataStoreORM
$args:
- $ref: /dbConnection
- $ref: /messageHandler
- $require: daf-did-comm#DIDComm
- $require: daf-w3c#CredentialIssuer
- $require: daf-selective-disclosure#SelectiveDisclosure
4 changes: 3 additions & 1 deletion packages/daf-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
"graphql": "^15.0.0",
"graphql-tools": "^6.0.0",
"inquirer": "^7.0.0",
"jsonpointer": "^4.1.0",
"lodash.merge": "^4.6.2",
"pg": "^8.2.0",
"qrcode-terminal": "^0.12.0",
"sqlite3": "^5.0.0",
"typeorm": "0.2.24",
"ws": "^7.2.0"
"ws": "^7.2.0",
"yaml": "^1.10.0"
},
"devDependencies": {
"@types/debug": "4.1.5",
Expand Down
43 changes: 0 additions & 43 deletions packages/daf-cli/src/config.ts

This file was deleted.

20 changes: 9 additions & 11 deletions packages/daf-cli/src/credential.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { W3CCredential, VerifiableCredential } from 'daf-core'
import * as W3c from 'daf-w3c'
import * as DIDComm from 'daf-did-comm'
import { W3CCredential } from 'daf-core'
import { agent } from './setup'
import program from 'commander'
import inquirer from 'inquirer'
Expand All @@ -12,7 +10,7 @@ program
.option('-s, --send', 'Send')
.option('-q, --qrcode', 'Show qrcode')
.action(async (cmd) => {
const identities = await (await agent).identityManagerGetIdentities()
const identities = await agent.identityManagerGetIdentities()
if (identities.length === 0) {
console.error('No dids')
process.exit()
Expand Down Expand Up @@ -91,15 +89,15 @@ program
}
}

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

if (cmd.send) {
try {
const message = await (await agent).sendMessageDIDCommAlpha1({
const message = await agent.sendMessageDIDCommAlpha1({
save: true,
data: {
from: answers.iss,
Expand Down Expand Up @@ -127,13 +125,13 @@ program
.option('-s, --send', 'Send')
.option('-q, --qrcode', 'Show qrcode')
.action(async (cmd) => {
const myIdentities = await (await agent).identityManagerGetIdentities()
const myIdentities = await agent.identityManagerGetIdentities()
if (myIdentities.length === 0) {
console.error('No dids')
process.exit()
}

const ids = await (await agent).dataStoreORMGetIdentities()
const ids = await agent.dataStoreORMGetIdentities()

const identities = [
{
Expand Down Expand Up @@ -180,7 +178,7 @@ program
aud = answers.aud
}

const credentials = await (await agent).dataStoreORMGetVerifiableCredentials({
const credentials = await agent.dataStoreORMGetVerifiableCredentials({
where: [{ column: 'subject', value: [answers.iss] }],
})

Expand Down Expand Up @@ -218,7 +216,7 @@ program
addMoreCredentials = answers2.addMore
}

const verifiablePresentation = await (await agent).createVerifiablePresentation({
const verifiablePresentation = await agent.createVerifiablePresentation({
save: true,
presentation: {
holder: answers.iss,
Expand All @@ -234,7 +232,7 @@ program

if (cmd.send) {
try {
const message = await (await agent).sendMessageDIDCommAlpha1({
const message = await agent.sendMessageDIDCommAlpha1({
save: true,
data: {
from: answers.iss,
Expand Down
11 changes: 5 additions & 6 deletions packages/daf-cli/src/data-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { IMessage } from 'daf-core'
import { agent } from './setup'
import program from 'commander'
import inquirer from 'inquirer'
import { formatDistanceToNow } from 'date-fns'
import { printTable } from 'console-table-printer'

program
Expand All @@ -12,7 +11,7 @@ program
.option('-m, --messages', 'List messages')
.action(async (cmd) => {
if (cmd.identities) {
const ids = await (await agent).identityManagerGetIdentities()
const ids = await agent.identityManagerGetIdentities()
if (ids.length === 0) {
console.error('No dids')
process.exit()
Expand All @@ -39,14 +38,14 @@ program
switch (answers.type) {
case 'Sent Messages':
showMessageList(
await (await agent).dataStoreORMGetMessages({
await agent.dataStoreORMGetMessages({
where: [{ column: 'from', value: [answers.did] }],
}),
)
break
case 'Received Messages':
showMessageList(
await (await agent).dataStoreORMGetMessages({
await agent.dataStoreORMGetMessages({
where: [{ column: 'to', value: [answers.did] }],
}),
)
Expand All @@ -58,7 +57,7 @@ program
}

if (cmd.messages) {
showMessageList(await (await agent).dataStoreORMGetMessages())
showMessageList(await agent.dataStoreORMGetMessages())
}
})

Expand Down Expand Up @@ -102,7 +101,7 @@ const showMessage = async (message: IMessage) => {
const showCredentials = async (did: string) => {
const table = []

const credentials = await (await agent).dataStoreORMGetVerifiableCredentials({
const credentials = await agent.dataStoreORMGetVerifiableCredentials({
where: [{ column: 'subject', value: [did] }],
})

Expand Down
2 changes: 1 addition & 1 deletion packages/daf-cli/src/did-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ program
.description('Resolve DID Document')
.action(async (didUrl) => {
try {
const ddo = await (await agent).resolveDid({ didUrl })
const ddo = await agent.resolveDid({ didUrl })
console.log(ddo)
} catch (e) {
console.error(e)
Expand Down
Loading

0 comments on commit 7a2498f

Please sign in to comment.