diff --git a/packages/daf-cli/README.md b/packages/daf-cli/README.md index 1afe93752..2199585e9 100644 --- a/packages/daf-cli/README.md +++ b/packages/daf-cli/README.md @@ -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 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 Resolve DID Document + resolve 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 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 | diff --git a/packages/daf-cli/src/server.ts b/packages/daf-cli/src/server.ts index d6587a5bb..a32a67aa0 100644 --- a/packages/daf-cli/src/server.ts +++ b/packages/daf-cli/src/server.ts @@ -15,6 +15,13 @@ program .option('--ngrokRegion ', 'ngrok region') .option('--createDefaultIdentity ', 'Should the agent create default web did', true) .option('--messagingServiceEndpoint ', 'Path of the messaging service endpoint', '/messaging') + .option( + '--publicProfileServiceEndpoint ', + 'Path of the public profile service endpoint', + '/public-profile', + ) + .option('--publicName ', 'Public name', 'Service') + .option('--publicPicture ', 'Public picture', 'https://picsum.photos/200') .option( '--exposedMethods ', 'Comma separated list of exposed agent methods (example: "resolveDid,handleMessage")', @@ -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) => {