Skip to content

Commit

Permalink
fix: Remove postinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Apr 27, 2020
1 parent f910731 commit 9fad446
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 124 deletions.
1 change: 0 additions & 1 deletion packages/daf-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"daf": "bin/daf.js"
},
"scripts": {
"postinstall": "scripts/postinstall.js",
"build": "tsc",
"watch": "tsc -b --watch"
},
Expand Down
28 changes: 0 additions & 28 deletions packages/daf-cli/scripts/postinstall.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/daf-cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { config } from 'dotenv'
config({ path: process.env.HOME + '/.daf/.env'})

import program from 'commander'
import './identity-manager'
import './did-resolver'
Expand Down
14 changes: 7 additions & 7 deletions packages/daf-cli/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ program
.option('-s, --send', 'Send')
.option('-q, --qrcode', 'Show qrcode')
.action(async cmd => {
const identities = await agent.identityManager.getIdentities()
const identities = await (await agent).identityManager.getIdentities()
if (identities.length === 0) {
console.error('No dids')
process.exit()
Expand Down Expand Up @@ -59,7 +59,7 @@ program
},
}

const credential: Daf.Credential = await agent.handleAction(signAction)
const credential: Daf.Credential = await (await agent).handleAction(signAction)

if (cmd.send) {
const sendAction: DIDComm.ActionSendDIDComm = {
Expand All @@ -72,7 +72,7 @@ program
},
}
try {
const message: Daf.Message = await agent.handleAction(sendAction)
const message: Daf.Message = await (await agent).handleAction(sendAction)
console.log('Sent:', message)
} catch (e) {
console.error(e)
Expand All @@ -92,7 +92,7 @@ program
.option('-s, --send', 'Send')
.option('-q, --qrcode', 'Show qrcode')
.action(async cmd => {
const myIdentities = await agent.identityManager.getIdentities()
const myIdentities = await (await agent).identityManager.getIdentities()
if (myIdentities.length === 0) {
console.error('No dids')
process.exit()
Expand All @@ -107,7 +107,7 @@ program
},
]
for (const id of ids) {
const name = await id.getLatestClaimValue(agent.dbConnection, { type: 'name'})
const name = await id.getLatestClaimValue((await agent).dbConnection, { type: 'name'})
identities.push({
value: id.did,
name: `${id.did} - ${name}`,
Expand Down Expand Up @@ -204,7 +204,7 @@ program
},
}

const presentation: Daf.Presentation = await agent.handleAction(signAction)
const presentation: Daf.Presentation = await (await agent).handleAction(signAction)

if (cmd.send) {
const sendAction: DIDComm.ActionSendDIDComm = {
Expand All @@ -217,7 +217,7 @@ program
},
}
try {
const message: Daf.Message = await agent.handleAction(sendAction)
const message: Daf.Message = await (await agent).handleAction(sendAction)
console.log('Sent:', message)
} catch (e) {
console.error(e)
Expand Down
10 changes: 5 additions & 5 deletions packages/daf-cli/src/data-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ program
.option('-m, --messages', 'List messages')
.action(async cmd => {
if (cmd.identities) {
const dbConnection = await agent.dbConnection
const dbConnection = await (await agent).dbConnection
const ids = await dbConnection.getRepository(Daf.Identity).find()
if (ids.length === 0) {
console.error('No dids')
Expand All @@ -21,7 +21,7 @@ program

const identities = []
for (const id of ids) {
const name = await id.getLatestClaimValue(agent.dbConnection, {type: 'name'})
const name = await id.getLatestClaimValue((await agent).dbConnection, {type: 'name'})
identities.push({
value: id.did,
name: `${id.did} - ${name || id.shortDid()}`,
Expand Down Expand Up @@ -57,7 +57,7 @@ program
}

if (cmd.messages) {
const dbConnection = await agent.dbConnection
const dbConnection = await (await agent).dbConnection
showMessageList(await dbConnection.getRepository(Daf.Message).find())
}
})
Expand Down Expand Up @@ -85,7 +85,7 @@ const showMessageList = async (messages: Daf.Message[]) => {
}

const showMessage = async (id: string) => {
const dbConnection = await agent.dbConnection
const dbConnection = await (await agent).dbConnection
const message = await dbConnection.getRepository(Daf.Message)
.findOne(id, {relations: ['credentials', 'credentials.claims']})
console.log(message)
Expand All @@ -112,7 +112,7 @@ const showMessage = async (id: string) => {

const showCredentials = async (did: string) => {
const table = []
const dbConnection = await agent.dbConnection
const dbConnection = await (await agent).dbConnection

const credentials = await dbConnection.getRepository(Daf.Credential)
.find({ where: { subject: 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 (did) => {
try {
const ddo = await agent.didResolver.resolve(did)
const ddo = await (await agent).didResolver.resolve(did)
console.log(ddo)
} catch (e) {
console.error(e)
Expand Down
2 changes: 1 addition & 1 deletion packages/daf-cli/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ program
W3cGql.resolvers,
SdrGql.resolvers,
),
context: () => ({ agent }),
context: async () => ({ agent: (await agent) }),
introspection: true,
})
// await core.setupServices()
Expand Down
42 changes: 21 additions & 21 deletions packages/daf-cli/src/identity-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ program
.option('--decrypt', 'Decrypt data')
.action(async cmd => {
if (cmd.types) {
const providers = await agent.identityManager.getIdentityProviders()
const providers = (await agent).identityManager.getIdentityProviders()
const list = providers.map(provider => ({
type: provider.type,
description: provider.description,
Expand All @@ -32,7 +32,7 @@ program
}

if (cmd.list) {
const list = await agent.identityManager.getIdentities()
const list = await (await agent).identityManager.getIdentities()

if (list.length > 0) {
const dids = list.map(item => ({ type: item.identityProviderType, did: item.did }))
Expand All @@ -44,7 +44,7 @@ program

if (cmd.create) {
try {
const providers = await agent.identityManager.getIdentityProviders()
const providers = await (await agent).identityManager.getIdentityProviders()
let type
if (providers.length > 1) {
const answers = await inquirer.prompt([
Expand All @@ -61,7 +61,7 @@ program

type = answers.type
}
const identity = await agent.identityManager.createIdentity(type)
const identity = await (await agent).identityManager.createIdentity(type)
printTable([{ type: identity.identityProviderType, did: identity.did }])
} catch (e) {
console.error(e)
Expand All @@ -70,7 +70,7 @@ program

if (cmd.delete) {
try {
const identities = await agent.identityManager.getIdentities()
const identities = await (await agent).identityManager.getIdentities()
const answers = await inquirer.prompt([
{
type: 'list',
Expand All @@ -80,9 +80,9 @@ program
},
])

const identity = await agent.identityManager.getIdentity(answers.did)
const identity = await (await agent).identityManager.getIdentity(answers.did)

const result = await agent.identityManager.deleteIdentity(identity.identityProviderType, identity.did)
const result = await (await agent).identityManager.deleteIdentity(identity.identityProviderType, identity.did)
console.log('Success:', result)
} catch (e) {
console.error(e)
Expand All @@ -91,7 +91,7 @@ program

if (cmd.service) {
try {
const identities = await agent.identityManager.getIdentities()
const identities = await (await agent).identityManager.getIdentities()
const answers = await inquirer.prompt([
{
type: 'list',
Expand All @@ -112,7 +112,7 @@ program
},
])

const identity = await agent.identityManager.getIdentity(answers.did)
const identity = await (await agent).identityManager.getIdentity(answers.did)
const result = await identity.identityController.addService({
type: answers.type,
serviceEndpoint: answers.endpoint,
Expand All @@ -126,7 +126,7 @@ program

if (cmd.publicKey) {
try {
const identities = await agent.identityManager.getIdentities()
const identities = await (await agent).identityManager.getIdentities()
const answers = await inquirer.prompt([
{
type: 'list',
Expand All @@ -142,7 +142,7 @@ program
},
])

const identity = await agent.identityManager.getIdentity(answers.did)
const identity = await (await agent).identityManager.getIdentity(answers.did)
const result = await identity.identityController.addPublicKey(answers.type)
console.log('Success:', result)
} catch (e) {
Expand All @@ -152,7 +152,7 @@ program

if (cmd.encrypt) {
try {
const identities = await agent.identityManager.getIdentities()
const identities = await (await agent).identityManager.getIdentities()
const answers = await inquirer.prompt([
{
type: 'list',
Expand All @@ -172,9 +172,9 @@ program
},
])

const identity = await agent.identityManager.getIdentity(answers.did)
const identity = await (await agent).identityManager.getIdentity(answers.did)
const key = await identity.keyByType('Ed25519')
const didDoc = await agent.didResolver.resolve(answers.to)
const didDoc = await (await agent).didResolver.resolve(answers.to)
const publicKey = didDoc?.publicKey.find(item => item.type == 'Ed25519VerificationKey2018')
if (!publicKey?.publicKeyHex) throw Error('Recipient does not have encryption publicKey')

Expand All @@ -194,7 +194,7 @@ program

if (cmd.decrypt) {
try {
const identities = await agent.identityManager.getIdentities()
const identities = await (await agent).identityManager.getIdentities()
const answers = await inquirer.prompt([
{
type: 'list',
Expand All @@ -209,7 +209,7 @@ program
},
])

const identity = await agent.identityManager.getIdentity(answers.did)
const identity = await (await agent).identityManager.getIdentity(answers.did)
const key = await identity.keyByType('Ed25519')
const result = await key.decrypt(answers.message)
console.log('Success:', result)
Expand All @@ -220,7 +220,7 @@ program

if (cmd.export) {
try {
const identities = await agent.identityManager.getIdentities()
const identities = await (await agent).identityManager.getIdentities()
const answers = await inquirer.prompt([
{
type: 'list',
Expand All @@ -230,8 +230,8 @@ program
},
])

const identity = await agent.identityManager.getIdentity(answers.did)
const secret = await agent.identityManager.exportIdentity(identity.identityProviderType, identity.did)
const identity = await (await agent).identityManager.getIdentity(answers.did)
const secret = await (await agent).identityManager.exportIdentity(identity.identityProviderType, identity.did)
console.log(secret)
} catch (e) {
console.error(e)
Expand All @@ -240,7 +240,7 @@ program

if (cmd.import) {
try {
const providers = await agent.identityManager.getIdentityProviders()
const providers = await (await agent).identityManager.getIdentityProviders()

const answers = await inquirer.prompt([
{
Expand All @@ -256,7 +256,7 @@ program
},
])

const identity = await agent.identityManager.importIdentity(answers.provider, answers.secret)
const identity = await (await agent).identityManager.importIdentity(answers.provider, answers.secret)
console.log(identity)
} catch (e) {
console.error(e)
Expand Down
2 changes: 1 addition & 1 deletion packages/daf-cli/src/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ program
.description('Handle raw message (JWT)')
.action(async raw => {
try {
const message = await agent.handleMessage({ raw, metaData: [{ type: 'cli' }] })
const message = await (await agent).handleMessage({ raw, metaData: [{ type: 'cli' }] })
console.log(message)
} catch (e) {
console.error(e.message)
Expand Down
8 changes: 4 additions & 4 deletions packages/daf-cli/src/sdr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ program
.option('-s, --send', 'Send')
.option('-q, --qrcode', 'Show qrcode')
.action(async cmd => {
const identities = await agent.identityManager.getIdentities()
const identities = await (await agent).identityManager.getIdentities()
if (identities.length === 0) {
console.error('No dids')
process.exit()
Expand Down Expand Up @@ -196,10 +196,10 @@ program
},
}

const jwt = await agent.handleAction(signAction)
const jwt = await (await agent).handleAction(signAction)

if (!cmd.send) {
await agent.handleMessage({ raw: jwt, metaData: [{ type: 'cli' }] })
await (await agent).handleMessage({ raw: jwt, metaData: [{ type: 'cli' }] })
} else if (answers.sub !== '') {
const sendAction: DIDComm.ActionSendDIDComm = {
type: DIDComm.ActionTypes.sendMessageDIDCommAlpha1,
Expand All @@ -211,7 +211,7 @@ program
},
}
try {
const result = await agent.handleAction(sendAction)
const result = await (await agent).handleAction(sendAction)
console.log('Sent:', result)
} catch (e) {
console.error(e)
Expand Down
Loading

0 comments on commit 9fad446

Please sign in to comment.