Skip to content

Commit

Permalink
feat: PublicProfile VP in CLI server
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Sep 17, 2020
1 parent fe286e3 commit 6d6b710
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 96 deletions.
80 changes: 9 additions & 71 deletions packages/daf-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,89 +6,27 @@
npm -g i daf-cli
```

## Functionality

- [x] Identity manager
- [x] List managed identities
- [x] Create identity
- [x] Delete identity
- [x] List available identity controller types
- [x] DID Document resolver
- [x] Resolve using internal (JS) resolver
- [x] Resolve using external universal resolver
- [x] Services
- [x] Sync latest messages (Trust Graph)
- [x] Subscribe to new messages (Trust Graph)
- [x] Verifiable Credentials
- [x] Create Verifiable Credential
- [x] Send Verifiable Credential (DIDComm / TrustGraph)
- [x] Create Verifiable Presentation
- [x] Send Verifiable Presentation (DIDComm / TrustGraph)
- [x] Data Store Explorer
- [x] List known identities
- [x] List messages
- [x] List credentials
- [ ] Selective Disclosure Request
- [x] Create and send SDR
- [ ] Display received SDR
- [ ] Create and send VP as a selective disclosure response

## Usage

```
Usage: daf [options] [command]
Usage: [options] [command]
Options:
-h, --help output usage information
--config <path> Configuration file (default: "$HOME/.daf/config.yml")
-v, --version output the version number
-h, --help display help for command
Commands:
identity-manager [options] Manage identities
resolve <did> Resolve DID Document
resolve <didUrl> Resolve DID Document
credential [options] Create W3C Verifiable Credential
presentation [options] Create W3C Verifiable Presentation
listen [options] Receive new messages and listen for new ones
data-explorer [options] Explore data store
graphql [options] GraphQL server
sdr [options] Create Selective Disclosure Request
msg <raw> Handle raw message (JWT)
crypto [options] Crypto
execute [options] Executes agent method
server [options] Launch OpenAPI server
help [command] display help for command
```

#### Using custom TGE

Send:

```
DAF_TG_URI=https://custom-tge.eu.ngrok.io/graphql daf credential -s
```

Receive:

```
DEBUG=* DAF_TG_URI=https://custom-tge.eu.ngrok.io/graphql DAF_TG_WSURI=wss://custom-tge.eu.ngrok.io/graphql daf listen
```

### DID Document resolver

Internal resolver (`did-resolver`)

```
daf resolve did:web:uport.me
```

Universal resolver

```
DAF_UNIVERSAL_RESOLVER_URL=https://uniresolver.io/1.0/identifiers/ daf resolve did:github:gjgd
```

## Configuration

| ENV | Default | Description |
| ---------------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `DEBUG` | `undefined` | Use `*` to see all debug info. [More options](https://github.com/visionmedia/debug#environment-variables) |
| `DAF_IDENTITY_STORE` | `~/.daf/identity-store.json` | Identity keyPair storage |
| `DAF_DATA_STORE` | `~/.daf/data-store.sqlite3` | Sqlite3 database containing messages, credentials, presentations, etc. |
| `DAF_INFURA_ID` | `5ffc47f65c4042ce847ef66a3fa70d4c` | Used for calls to the Ethereum blockchain |
| `DAF_UNIVERSAL_RESOLVER_URL` | `undefined` | Example `https://uniresolver.io/1.0/identifiers/`. If not provided - will use internal resolver |
| `DAF_TG_URI` | `https://edge.uport.me/graphql` | Trust Graph Endpoint URL |
| `DAF_TG_WSURI` | `undefined` | Trust Graph Endpoint WebSocket URL |
117 changes: 92 additions & 25 deletions packages/daf-cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ program
.option('--ngrokRegion <string>', 'ngrok region')
.option('--createDefaultIdentity <boolean>', 'Should the agent create default web did', true)
.option('--messagingServiceEndpoint <path>', 'Path of the messaging service endpoint', '/messaging')
.option(
'--publicProfileServiceEndpoint <path>',
'Path of the public profile service endpoint',
'/public-profile',
)
.option('--publicName <string>', 'Public name', 'Service')
.option('--publicPicture <string>', 'Public picture', 'https://picsum.photos/200')
.option(
'--exposedMethods <string>',
'Comma separated list of exposed agent methods (example: "resolveDid,handleMessage")',
Expand Down Expand Up @@ -60,31 +67,91 @@ program
})
console.log('🆔', serverIdentity.did)

if (options.messagingServiceEndpoint) {
const serviceEndpoint = 'https://' + hostname + options.messagingServiceEndpoint

await agent.identityManagerAddService({
did: serverIdentity.did,
service: {
id: serverIdentity.did + '#msg',
type: 'Messaging',
description: 'Handles incoming POST messages',
serviceEndpoint,
},
})
console.log('📨 Messaging endpoint', serviceEndpoint)

app.post(options.messagingServiceEndpoint, express.text({ type: '*/*' }), async (req, res) => {
try {
const message = await agent.handleMessage({ raw: req.body, save: true })
console.log('Received message', message.type, message.id)
res.json({ id: message.id })
} catch (e) {
console.log(e)
res.send(e.message)
}
})
}
const messagingServiceEndpoint = 'https://' + hostname + options.messagingServiceEndpoint

await agent.identityManagerAddService({
did: serverIdentity.did,
service: {
id: serverIdentity.did + '#msg',
type: 'Messaging',
description: 'Handles incoming POST messages',
serviceEndpoint: messagingServiceEndpoint,
},
})
console.log('📨 Messaging endpoint', messagingServiceEndpoint)

app.post(options.messagingServiceEndpoint, express.text({ type: '*/*' }), async (req, res) => {
try {
const message = await agent.handleMessage({ raw: req.body, save: true })
console.log('Received message', message.type, message.id)
res.json({ id: message.id })
} catch (e) {
console.log(e)
res.send(e.message)
}
})

const publicProfileServiceEndpoint = 'https://' + hostname + options.publicProfileServiceEndpoint

await agent.identityManagerAddService({
did: serverIdentity.did,
service: {
id: serverIdentity.did + '#pub',
type: 'PublicProfile',
description: 'Public profile verifiable presentation',
serviceEndpoint: publicProfileServiceEndpoint,
},
})
console.log('🌍 Public Profile', publicProfileServiceEndpoint)

app.get(options.publicProfileServiceEndpoint, async (req, res) => {
try {
const nameCredential = await agent.createVerifiableCredential({
credential: {
issuer: { id: serverIdentity.did },
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
issuanceDate: new Date().toISOString(),
credentialSubject: {
id: serverIdentity.did,
name: options.publicName,
},
},
proofFormat: 'jwt',
})

const pictureCredential = await agent.createVerifiableCredential({
credential: {
issuer: { id: serverIdentity.did },
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
issuanceDate: new Date().toISOString(),
credentialSubject: {
id: serverIdentity.did,
picture: options.publicPicture,
},
},
proofFormat: 'jwt',
})

const publicProfile = await agent.createVerifiablePresentation({
presentation: {
verifier: [],
holder: serverIdentity.did,
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiablePresentation', 'PublicProfile'],
issuanceDate: new Date().toISOString(),
verifiableCredential: [nameCredential, pictureCredential],
},
proofFormat: 'jwt',
})

res.json(publicProfile)
} catch (e) {
console.log(e)
res.send(e.message)
}
})

const didDocEndpoint = '/.well-known/did.json'
app.get(didDocEndpoint, async (req, res) => {
Expand Down

0 comments on commit 6d6b710

Please sign in to comment.