Skip to content

Commit

Permalink
feat: Example id-hub
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 19, 2020
1 parent 210e898 commit 9187906
Show file tree
Hide file tree
Showing 7 changed files with 3,139 additions and 6 deletions.
3 changes: 3 additions & 0 deletions examples/id-hub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
identity-store.json
data-store.sqlite3
46 changes: 46 additions & 0 deletions examples/id-hub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Server

```
npm i
npm start
```

## Queries

Self signed credential (name = Alice):

```
mutation newMsg {
saveNewMessage(raw: "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1ODQ2MTkxMDQsInN1YiI6ImRpZDpldGhyOnJpbmtlYnk6MHgzNGU0YjRmMzUxMjIwMGU4NGVkZGIwNWMyNTMxMWI3ZjU4NGY3ODUzIiwidmMiOnsiQGNvbnRleHQiOlsiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvdjEiXSwidHlwZSI6WyJWZXJpZmlhYmxlQ3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJuYW1lIjoiQWxpY2UifX0sImlzcyI6ImRpZDpldGhyOnJpbmtlYnk6MHgzNGU0YjRmMzUxMjIwMGU4NGVkZGIwNWMyNTMxMWI3ZjU4NGY3ODUzIn0.TxNVe3DaU9yqsA8q0BFdtHUsqPlb2FuwExFWktAVBMY3HNXDfxm3h9Q4aSno5xfyvVDZupg7EovEYCAtQ0BKQwA") {
id
type
data
}
}
```

Skill = Developer

```
mutation newMsg {
saveNewMessage(raw: "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1ODQ2MTkzNjIsInN1YiI6ImRpZDpldGhyOnJpbmtlYnk6MHgxYzM4NmQ1NTAyNTZiMTdkOTA4ZDY2NDM2MjQ3ZGJlMzUxYzQzZW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nNVM1ZpYW1WamRDSTZleUp1WVcxbElqb2lRV3hwWTJVaWZYMHNJbWx6Y3lJNkltUnBaRHBsZEdoeU9uSnBibXRsWW5rNk1IZ3pOR1UwWWpSbU16VXhNakl3TUdVNE5HVmtaR0l3TldNeU5UTXhNV0kzWmpVNE5HWTNPRFV6SW4wLmZYWV9nU1BEbk1YY1gyUm9LMEpzYUs4c0ljSllscnBlb0dKeFRDMXhNdWw2N0lyVURyMWNYRVZyZGJ0V3h2Zmo5aGw0endRd0NDWTFFSXd1UlB4Z01RRSJdfSwiaXNzIjoiZGlkOmV0aHI6cmlua2VieToweDFjMzg2ZDU1MDI1NmIxN2Q5MDhkNjY0MzYyNDdkYmUzNTFjNDNlZGMifQ.HnZyQIqV9d2saNDo6a72jlplWuVGVLJe4ff30MIpr6bcgobW4gHEGnc-AXaPPOSH1ErYz2xor1oxq3TTWhyS7wE") {
id
type
data
}
}
```
33 changes: 33 additions & 0 deletions examples/id-hub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "daf-example-id-hub",
"private": true,
"version": "1.0.0",
"description": "",
"main": "index.ts",
"scripts": {
"start": "node build/index.js",
"build": "tsc",
"build:watch": "tsc -b --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server": "^2.11.0",
"daf-core": "../../packages/daf-core",
"daf-debug": "../../packages/daf-debug",
"daf-did-jwt": "../../packages/daf-did-jwt",
"daf-resolver": "../../packages/daf-resolver",
"daf-selective-disclosure": "../../packages/daf-selective-disclosure",
"daf-w3c": "../../packages/daf-w3c",
"graphql": "^14.6.0",
"lodash.merge": "^4.6.2",
"sqlite3": "^4.1.1",
"typeorm": "^0.2.24"
},
"devDependencies": {
"ts-node": "^8.7.0",
"typescript": "^3.8.3"
}
}
63 changes: 63 additions & 0 deletions examples/id-hub/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as Daf from 'daf-core'
import * as DidJwt from 'daf-did-jwt'
import * as W3c from 'daf-w3c'
import * as SD from 'daf-selective-disclosure'
import * as DBG from 'daf-debug'
import { DafResolver } from 'daf-resolver'
import { ApolloServer } from 'apollo-server'
import merge from 'lodash.merge'
import { createConnection } from 'typeorm'

const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c'

let didResolver = new DafResolver({ infuraProjectId })

const messageValidator = new DBG.MessageValidator()
messageValidator
.setNext(new DidJwt.MessageValidator())
.setNext(new W3c.MessageValidator())
.setNext(new SD.MessageValidator())

const actionHandler = new DBG.ActionHandler()
actionHandler.setNext(new W3c.ActionHandler()).setNext(new SD.ActionHandler())

export const core = new Daf.Core({
identityProviders: [],
serviceControllers: [],
didResolver,
messageValidator,
actionHandler,
})

const server = new ApolloServer({
typeDefs: [Daf.Gql.baseTypeDefs, Daf.Gql.Core.typeDefs],
resolvers: merge(Daf.Gql.Core.resolvers),
context: ({ req }) => {
const token = req.headers.authorization || ''
if (token !== 'Bearer hardcoded-example-token') {
throw Error('Auth error')
}

return { core }
},
introspection: true,
})

core.on(Daf.EventTypes.savedMessage, async (message: Daf.Message) => {
// Add your business logic
})

const main = async () => {
const c = await createConnection({
type: 'sqlite',
database: './database.sqlite',
synchronize: true,
logging: true,
entities: [...Daf.Entities],
})

const info = await server.listen()
console.log(`🚀 Server ready at ${info.url}`)
}

main().catch(console.log)
24 changes: 24 additions & 0 deletions examples/id-hub/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"preserveConstEnums": true,
"strict": true,
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"downlevelIteration": true,
"composite": true,
"rootDir": "src",
"outDir": "build"
},
"exclude": ["**/__tests__/**/*", "**/build/**/*"],
"references": [
{ "path": "../../packages/daf-core" },
{ "path": "../../packages/daf-debug" },
{ "path": "../../packages/daf-did-jwt" },
{ "path": "../../packages/daf-resolver" },
{ "path": "../../packages/daf-selective-disclosure" },
{ "path": "../../packages/daf-w3c" }
]
}
Loading

0 comments on commit 9187906

Please sign in to comment.