diff --git a/package-lock.json b/package-lock.json index f0c8d6e9..19ab3b2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,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" }, "bin": { "transmute": "dist/index.js" @@ -2233,6 +2234,26 @@ "dev": true, "license": "MIT" }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -2313,6 +2334,30 @@ "node-int64": "^0.4.0" } }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -3518,6 +3563,26 @@ "node": ">=10.17.0" } }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/ignore": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", @@ -4782,6 +4847,34 @@ "dev": true, "license": "MIT" }, + "node_modules/neo4j-driver": { + "version": "5.23.0", + "resolved": "https://registry.npmjs.org/neo4j-driver/-/neo4j-driver-5.23.0.tgz", + "integrity": "sha512-jqAyvIIpD1dl0+GuSXfF7Hzy+bscBIRvO2hrMqQji4Gq2baBaRMcsG/8CRhkF7Hm1bUeBUnnArnUNUGO/c+kow==", + "license": "Apache-2.0", + "dependencies": { + "neo4j-driver-bolt-connection": "5.23.0", + "neo4j-driver-core": "5.23.0", + "rxjs": "^7.8.1" + } + }, + "node_modules/neo4j-driver-bolt-connection": { + "version": "5.23.0", + "resolved": "https://registry.npmjs.org/neo4j-driver-bolt-connection/-/neo4j-driver-bolt-connection-5.23.0.tgz", + "integrity": "sha512-d8aLeeS33KMmUnGCGj/U07AUOch8IVc6hA8Lit/4ExaHnhRoSgEOPAK6/RAbYAfABlVqFfErtV85s1OnrJu64g==", + "license": "Apache-2.0", + "dependencies": { + "buffer": "^6.0.3", + "neo4j-driver-core": "5.23.0", + "string_decoder": "^1.3.0" + } + }, + "node_modules/neo4j-driver-core": { + "version": "5.23.0", + "resolved": "https://registry.npmjs.org/neo4j-driver-core/-/neo4j-driver-core-5.23.0.tgz", + "integrity": "sha512-kypv0cym8vB9t36MRKSt/mtNZuvCACg6S47yJMDjJx5XSWx69QbBaLNvoa/2//7NPCCj0Fn0i5HCKqBkcBRa2Q==", + "license": "Apache-2.0" + }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -5416,6 +5509,35 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/rxjs": { + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", + "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.1.0" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/semver": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", @@ -5533,6 +5655,15 @@ "node": ">=8" } }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", diff --git a/package.json b/package.json index 281e4a2d..1b2da8d7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/action/args.ts b/src/action/args.ts index 1ab403cd..b21381b9 100644 --- a/src/action/args.ts +++ b/src/action/args.ts @@ -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 = { @@ -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", }, diff --git a/src/vcwg/handler.ts b/src/vcwg/handler.ts index f1ab54dc..1ba3e53c 100644 --- a/src/vcwg/handler.ts +++ b/src/vcwg/handler.ts @@ -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' @@ -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() @@ -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)) diff --git a/tests/vcwg.test.ts b/tests/vcwg.test.ts index f8c929b7..09c17afa 100644 --- a/tests/vcwg.test.ts +++ b/tests/vcwg.test.ts @@ -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) +}) +