Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0f7263
commit 9e61006
Showing
22 changed files
with
7,303 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ identity-store.json | |
key-store.json | ||
*.sqlite | ||
|
||
.vscode/ | ||
.vscode/ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'cross-fetch/polyfill' | ||
import { IAgentPlugin, TMethodMap } from 'daf-core' | ||
import { GraphQLClient } from 'graphql-request' | ||
import * as SupportedMethods from './methods' | ||
|
||
export class DafGraphQL implements IAgentPlugin { | ||
private client: GraphQLClient | ||
readonly methods: TMethodMap = {} | ||
|
||
constructor(options: { url: string; apiKey?: string; methods: string[] }) { | ||
this.client = new GraphQLClient(options.url) | ||
|
||
for (const method of options.methods) { | ||
this.methods[method] = async (args: any) => { | ||
const { result } = await this.client.request(SupportedMethods[method], args) | ||
return result | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export const resolve = ` | ||
query resolve($did: String!) { | ||
result: resolve(did: $did) | ||
} | ||
` | ||
|
||
export const getIdentityProviders = ` | ||
{ | ||
result: getIdentityProviders { | ||
type | ||
description | ||
} | ||
} | ||
` | ||
|
||
export const getIdentities = ` | ||
{ | ||
result: getIdentities { | ||
did | ||
provider | ||
} | ||
} | ||
` | ||
export const getIdentity = ` | ||
query getIdentity($did: String!) { | ||
result: getIdentity(did: $did) { | ||
did | ||
provider | ||
} | ||
} | ||
` | ||
|
||
export const createIdentity = ` | ||
mutation createIdentity($type: String) { | ||
result: createIdentity(type: $type) { | ||
did | ||
} | ||
} | ||
` | ||
|
||
export const deleteIdentity = ` | ||
mutation deleteIdentity($did: String!) { | ||
result: deleteIdentity(did: $did) | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IAgentPlugin, TMethodMap } from 'daf-core' | ||
|
||
export class DafGrpc implements IAgentPlugin { | ||
readonly methods: TMethodMap = {} | ||
|
||
constructor(options: { url: string; methods: string[] }) { | ||
// TODO https://grpc.io/docs/languages/node/quickstart/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IAgentPlugin, TMethodMap } from 'daf-core' | ||
|
||
export class DafRest implements IAgentPlugin { | ||
readonly methods: TMethodMap = {} | ||
|
||
constructor(options: { url: string; methods: string[] }) { | ||
// TODO https://expressjs.com/en/guide/writing-middleware.html | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Agent } from 'daf-core' | ||
import { DafGraphQL } from './daf-graphql' | ||
import { DafGrpc } from './daf-grpc' | ||
import { DafRest } from './daf-rest' | ||
import { IAgent, IAgentIdentityManager } from 'daf-core' | ||
import { IAgentResolve } from 'daf-resolver' | ||
|
||
export type ConfiguredAgent = IAgent & IAgentIdentityManager & IAgentResolve | ||
|
||
const agent: ConfiguredAgent = new Agent({ | ||
plugins: [ | ||
new DafGraphQL({ | ||
url: 'http://localhost:3000', | ||
apiKey: 'example-token', | ||
methods: [ | ||
'resolve', | ||
'getIdentityProviders', | ||
'getIdentities', | ||
'getIdentity', | ||
'createIdentity', | ||
'deleteIdentity', | ||
], | ||
}), | ||
new DafGrpc({ | ||
url: 'http://localhost:3001', | ||
methods: [ | ||
// 'signCredentialJwt', | ||
], | ||
}), | ||
new DafRest({ | ||
url: 'http://localhost:3002', | ||
methods: [ | ||
// 'handleMessage', | ||
], | ||
}), | ||
], | ||
}) | ||
|
||
async function main() { | ||
const providers = await agent.getIdentityProviders() | ||
console.log({ providers }) | ||
|
||
const newIdentity = await agent.createIdentity({ identityProviderType: 'rinkeby-ethr-did' }) | ||
console.log({ newIdentity }) | ||
|
||
const identities = await agent.getIdentities() | ||
console.log({ identities }) | ||
|
||
const identity = await agent.getIdentity({ did: identities[0].did }) | ||
console.log({ identity }) | ||
|
||
const doc = await agent.resolve({ did: 'did:ethr:rinkeby:0x79292ba5a516f04c3de11e8f06642c7bec16c490' }) | ||
console.log(doc) | ||
} | ||
|
||
main().catch(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "daf-graphql-client", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "DEBUG=daf:* ts-node index.ts" | ||
}, | ||
"dependencies": { | ||
"cross-fetch": "^3.0.4", | ||
"daf-core": "../../../packages/daf-core", | ||
"daf-did-comm": "../../../packages/daf-did-comm", | ||
"daf-did-jwt": "../../../packages/daf-did-jwt", | ||
"daf-ethr-did": "../../../packages/daf-ethr-did", | ||
"daf-libsodium": "../../../packages/daf-libsodium", | ||
"daf-resolver": "../../../packages/daf-resolver", | ||
"daf-w3c": "../../../packages/daf-w3c", | ||
"graphql-request": "^2.0.0", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"compilerOptions": { | ||
"preserveConstEnums": true, | ||
"sourceMap": true, | ||
"target": "es5", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"downlevelIteration": true, | ||
"declarationMap": true, | ||
"declaration": true, | ||
"composite": true, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true | ||
}, | ||
"exclude": ["**/__tests__/**/*", "**/build/**/*"], | ||
"references": [ | ||
{ "path": "../../../packages/daf-core" }, | ||
{ "path": "../../../packages/daf-did-comm" }, | ||
{ "path": "../../../packages/daf-did-jwt" }, | ||
{ "path": "../../../packages/daf-ethr-did" }, | ||
{ "path": "../../../packages/daf-fs" }, | ||
{ "path": "../../../packages/daf-libsodium" }, | ||
{ "path": "../../../packages/daf-resolver" }, | ||
{ "path": "../../../packages/daf-resolver-universal" }, | ||
{ "path": "../../../packages/daf-selective-disclosure" }, | ||
{ "path": "../../../packages/daf-trust-graph" }, | ||
{ "path": "../../../packages/daf-url" }, | ||
{ "path": "../../../packages/daf-w3c" } | ||
] | ||
} |
Oops, something went wrong.