Skip to content

Commit

Permalink
add graph
Browse files Browse the repository at this point in the history
  • Loading branch information
OR13 committed Aug 11, 2024
1 parent b2f1cc7 commit dbfcecb
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 4 deletions.
133 changes: 132 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"@transmute/verifiable-credentials": "^0.3.3",
"axios": "^1.7.3",
"jose": "^5.6.3",
"jsonld": "^8.3.2"
"jsonld": "^8.3.2",
"neo4j-driver": "^5.23.0"
},
"devDependencies": {
"@types/jest": "^29.2.6",
Expand Down
6 changes: 5 additions & 1 deletion src/action/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export type CommonOptions = {
}

export type VcwgOptions = {
'graph-type'?: string
'credential-type'?: string
'presentation-type'?: string
gql?: boolean
push?: boolean
}

export type ScittOptions = {
Expand Down Expand Up @@ -57,6 +58,9 @@ export const args = (prompt: string) => {
type: 'string' as "string",
short: 'o'
},
push: {
type: 'boolean' as "boolean",
},
'credential-type': {
type: 'string' as "string",
},
Expand Down
12 changes: 11 additions & 1 deletion src/vcwg/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs'
import * as jose from 'jose'
import { Arguments } from "../types"
import neo4j from 'neo4j-driver'

import yaml from 'yaml'

Expand All @@ -14,7 +15,6 @@ import * as vc from '@transmute/verifiable-credentials'
import { jsongraph } from './graph/jsongraph'
import { query, injection } from './graph/gql'


export const handler = async function ({ positionals, values }: Arguments) {
positionals = positionals.slice(1)
const operation = positionals.shift()
Expand Down Expand Up @@ -341,6 +341,16 @@ export const handler = async function ({ positionals, values }: Arguments) {
const components = await query(graph)
const dangerousQuery = await injection(components)
graphText = dangerousQuery
if (values.push) {
const driver = neo4j.driver(
`${process.env.NEO4J_URI}`,
neo4j.auth.basic(`${process.env.NEO4J_USERNAME}`, `${process.env.NEO4J_PASSWORD}`)
)
const session = driver.session()
await session
.run({ text: `${components.query}`, parameters: components.params })
await driver.close()
}
}
if (output) {
fs.writeFileSync(output, JSON.stringify(graphText, null, 2))
Expand Down
6 changes: 6 additions & 0 deletions tests/vcwg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ it('graph gql', async () => {
expect(output).toHaveBeenCalledTimes(1)
})

it('graph gql neo4j', async () => {
await facade(`vcwg graph ./tests/fixtures/issuer-claims.json --verbose --credential-type application/vc --graph-type application/gql --push`)
expect(debug).toHaveBeenCalledTimes(1)
expect(output).toHaveBeenCalledTimes(1)
})

0 comments on commit dbfcecb

Please sign in to comment.