Skip to content

Commit

Permalink
feat: Removing profile service CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Oct 19, 2020
1 parent a6509e9 commit dc93089
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 71 deletions.
2 changes: 1 addition & 1 deletion docs/api/daf-selective-disclosure.selectivedisclosure.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export declare class SelectiveDisclosure implements IAgentPlugin
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [methods](./daf-selective-disclosure.selectivedisclosure.methods.md) | | [ISelectiveDisclosure](./daf-selective-disclosure.iselectivedisclosure.md) | <b><i>(BETA)</i></b> |
| [schema](./daf-selective-disclosure.selectivedisclosure.schema.md) | | { components: { schemas: { ICreateProfileCredentialsArgs: { type: string; properties: { holder: { type: string; }; verifier: { type: string; }; name: { type: string; }; picture: { type: string; }; url: { type: string; }; save: { type: string; }; send: { type: string; }; }; required: string\[\]; description: string; }; VerifiablePresentation: { type: string; properties: { id: { type: string; }; holder: { type: string; }; issuanceDate: { type: string; }; expirationDate: { type: string; }; "@context": { type: string; items: { type: string; }; }; type: { type: string; items: { type: string; }; }; verifier: { type: string; items: { type: string; }; }; verifiableCredential: { type: string; items: { $ref: string; }; }; proof: { type: string; properties: { type: { type: string; }; }; }; }; required: string\[\]; description: string; }; VerifiableCredential: { type: string; properties: { "@context": { type: string; items: { type: string; }; }; id: { type: string; }; type: { type: string; items: { type: string; }; }; issuer: { type: string; properties: { id: { type: string; }; }; required: string\[\]; }; issuanceDate: { type: string; }; expirationDate: { type: string; }; credentialSubject: { type: string; properties: { id: { type: string; }; }; }; credentialStatus: { type: string; properties: { id: { type: string; }; type: { type: string; }; }; required: string\[\]; }; proof: { type: string; properties: { type: { type: string; }; }; }; }; required: string\[\]; description: string; }; ICreateSelectiveDisclosureRequestArgs: { type: string; properties: { data: { $ref: string; }; }; required: string\[\]; description: string; }; ISelectiveDisclosureRequest: { type: string; properties: { issuer: { type: string; description: string; }; subject: { type: string; description: string; }; replyUrl: { type: string; description: string; }; tag: { type: string; }; claims: { type: string; items: { $ref: string; }; description: string; }; credentials: { type: string; items: { type: string; }; description: string; }; }; required: string\[\]; description: string; }; ICredentialRequestInput: { type: string; properties: { reason: { type: string; description: string; }; essential: { type: string; description: string; }; credentialType: { type: string; description: string; }; credentialContext: { type: string; description: string; }; claimType: { type: string; description: string; }; claimValue: { type: string; description: string; }; issuers: { type: string; items: { $ref: string; }; description: string; }; }; required: string\[\]; description: string; }; Issuer: { type: string; properties: { did: { type: string; description: string; }; url: { type: string; description: string; }; }; required: string\[\]; description: string; }; IGetVerifiableCredentialsForSdrArgs: { type: string; properties: { sdr: { type: string; properties: { subject: { type: string; description: string; }; replyUrl: { type: string; description: string; }; tag: { type: string; }; claims: { type: string; items: { $ref: string; }; description: string; }; credentials: { type: string; items: { type: string; }; description: string; }; }; required: string\[\]; description: string; }; did: { type: string; description: string; }; }; required: string\[\]; description: string; }; ICredentialsForSdr: { type: string; properties: { reason: { type: string; description: string; }; essential: { type: string; description: string; }; credentialType: { type: string; description: string; }; credentialContext: { type: string; description: string; }; claimType: { type: string; description: string; }; claimValue: { type: string; description: string; }; issuers: { type: string; items: { $ref: string; }; description: string; }; credentials: { type: string; items: { $ref: string; }; }; }; required: string\[\]; description: string; }; IValidatePresentationAgainstSdrArgs: { type: string; properties: { presentation: { $ref: string; }; sdr: { $ref: string; }; }; required: string\[\]; description: string; }; IPresentationValidationResult: { type: string; properties: { valid: { type: string; }; claims: { type: string; items: { $ref: string; }; }; }; required: string\[\]; description: string; }; }; methods: { createProfilePresentation: { description: string; arguments: { $ref: string; }; returnType: { $ref: string; }; }; createSelectiveDisclosureRequest: { description: string; arguments: { $ref: string; }; returnType: { type: string; }; }; getVerifiableCredentialsForSdr: { description: string; arguments: { $ref: string; }; returnType: { type: string; items: { $ref: string; }; }; }; validatePresentationAgainstSdr: { description: string; arguments: { $ref: string; }; returnType: { $ref: string; }; }; }; }; } | <b><i>(BETA)</i></b> |
| [schema](./daf-selective-disclosure.selectivedisclosure.schema.md) | | { components: { schemas: { ICreateProfileCredentialsArgs: { type: string; properties: { holder: { type: string; description: string; }; verifier: { type: string; description: string; }; name: { type: string; description: string; }; picture: { type: string; description: string; }; url: { type: string; description: string; }; save: { type: string; description: string; }; send: { type: string; description: string; }; }; required: string\[\]; description: string; }; VerifiablePresentation: { type: string; properties: { id: { type: string; }; holder: { type: string; }; issuanceDate: { type: string; }; expirationDate: { type: string; }; '@context': { type: string; items: { type: string; }; }; type: { type: string; items: { type: string; }; /\*\* \* Creates a Selective disclosure request, encoded as a JWT. \* \* @remarks See {@link https://github.com/uport-project/specs/blob/develop/flows/selectivedisclosure.md \| Selective Disclosure} \* \* @param args - The param object with the properties necessary to create the request. See {@link ISelectiveDisclosureRequest} \* @param context - \*RESERVED\* This is filled by the framework when the method is called. \* \* @beta \*/ }; verifier: { type: string; items: { type: string; }; }; verifiableCredential: { type: string; items: { $ref: string; }; }; proof: { type: string; properties: { type: { type: string; }; }; }; }; required: string\[\]; description: string; }; VerifiableCredential: { type: string; properties: { '@context': { type: string; items: { type: string; }; }; id: { type: string; }; type: { type: string; items: { type: string; }; }; issuer: { type: string; properties: { id: { type: string; }; }; required: string\[\]; }; issuanceDate: { type: string; }; expirationDate: { type: string; }; credentialSubject: { type: string; properties: { id: { type: string; }; }; }; credentialStatus: { type: string; properties: { id: { type: string; }; type: { type: string; }; }; required: string\[\]; }; proof: { type: string; properties: { type: { type: string; }; }; }; }; required: string\[\]; description: string; }; ICreateSelectiveDisclosureRequestArgs: { type: string; properties: { data: { $ref: string; }; }; required: string\[\]; description: string; }; ISelectiveDisclosureRequest: { type: string; properties: { issuer: { type: string; description: string; }; subject: { type: string; description: string; }; replyUrl: { type: string; description: string; }; tag: { type: string; }; claims: { type: string; items: { $ref: string; }; description: string; }; credentials: { type: string; items: { type: string; }; description: string; }; }; required: string\[\]; description: string; }; ICredentialRequestInput: { type: string; properties: { reason: { type: string; description: string; }; essential: { type: string; description: string; }; credentialType: { type: string; description: string; }; credentialContext: { type: string; description: string; }; claimType: { type: string; description: string; }; claimValue: { type: string; description: string; }; issuers: { type: string; items: { $ref: string; }; description: string; }; }; required: string\[\]; description: string; }; Issuer: { type: string; properties: { did: { type: string; description: string; }; url: { type: string; description: string; }; }; required: string\[\]; description: string; }; IGetVerifiableCredentialsForSdrArgs: { type: string; properties: { sdr: { type: string; properties: { subject: { type: string; description: string; }; replyUrl: { type: string; description: string; }; tag: { type: string; }; claims: { type: string; items: { $ref: string; }; description: string; }; credentials: { type: string; items: { type: string; }; description: string; }; }; required: string\[\]; description: string; }; did: { type: string; description: string; }; }; required: string\[\]; description: string; }; ICredentialsForSdr: { type: string; properties: { reason: { type: string; description: string; }; essential: { type: string; description: string; }; credentialType: { type: string; description: string; }; credentialContext: { type: string; description: string; }; claimType: { type: string; description: string; }; claimValue: { type: string; description: string; }; issuers: { type: string; items: { $ref: string; }; description: string; }; credentials: { type: string; items: { $ref: string; }; }; }; required: string\[\]; description: string; }; IValidatePresentationAgainstSdrArgs: { type: string; properties: { presentation: { $ref: string; }; sdr: { $ref: string; }; }; required: string\[\]; description: string; }; IPresentationValidationResult: { type: string; properties: { valid: { type: string; }; claims: { type: string; items: { $ref: string; }; }; }; required: string\[\]; description: string; }; }; methods: { createProfilePresentation: { description: string; arguments: { $ref: string; }; returnType: { $ref: string; }; }; createSelectiveDisclosureRequest: { description: string; arguments: { $ref: string; }; returnType: { type: string; }; }; getVerifiableCredentialsForSdr: { description: string; arguments: { $ref: string; }; returnType: { type: string; items: { $ref: string; }; }; }; validatePresentationAgainstSdr: { description: string; arguments: { $ref: string; }; returnType: { $ref: string; }; }; }; }; } | <b><i>(BETA)</i></b> |
## Methods
Expand Down
22 changes: 19 additions & 3 deletions docs/api/daf-selective-disclosure.selectivedisclosure.schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,31 @@ readonly schema: {
properties: {
holder: {
type: string;
description: string;
};
verifier: {
type: string;
description: string;
};
name: {
type: string;
description: string;
};
picture: {
type: string;
description: string;
};
url: {
type: string;
description: string;
};
save: {
type: string;
description: string;
};
send: {
type: string;
description: string;
};
};
required: string[];
Expand All @@ -56,7 +63,7 @@ readonly schema: {
expirationDate: {
type: string;
};
"@context": {
'@context': {
type: string;
items: {
type: string;
Expand All @@ -66,7 +73,16 @@ readonly schema: {
type: string;
items: {
type: string;
};
}; /**
* Creates a Selective disclosure request, encoded as a JWT.
*
* @remarks See {@link https://github.com/uport-project/specs/blob/develop/flows/selectivedisclosure.md | Selective Disclosure}
*
* @param args - The param object with the properties necessary to create the request. See {@link ISelectiveDisclosureRequest}
* @param context - *RESERVED* This is filled by the framework when the method is called.
*
* @beta
*/
};
verifier: {
type: string;
Expand Down Expand Up @@ -95,7 +111,7 @@ readonly schema: {
VerifiableCredential: {
type: string;
properties: {
"@context": {
'@context': {
type: string;
items: {
type: string;
Expand Down
3 changes: 0 additions & 3 deletions packages/daf-cli/default/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ server:
defaultIdentity:
create: true
messagingServiceEndpoint: /messaging
publicProfileServiceEndpoint: /public-profile
publicName: Alice
publicPicture: https://picsum.photos/200
ngrok:
connect: true
# authtoken: XZY
Expand Down
98 changes: 97 additions & 1 deletion packages/daf-cli/src/sdr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { getAgent } from './setup'
import program from 'commander'
import inquirer from 'inquirer'
import qrcode from 'qrcode-terminal'
import { shortDate, shortDid } from './data-explorer/utils'
import { VerifiableCredential } from 'daf-core'

program
.command('sdr')
.command('sdr-create')
.description('Create Selective Disclosure Request')
.option('-s, --send', 'Send')
.option('-q, --qrcode', 'Show qrcode')
Expand Down Expand Up @@ -236,3 +238,97 @@ program
console.log(`jwt: ${jwt}`)
}
})

program
.command('sdr-reply')
.description('Reply to Selective Disclosure Request')
.action(async (cmd) => {
const agent = getAgent(program.config)
const sdrMessages = await agent.dataStoreORMGetMessages({
where: [{ column: 'type', value: ['sdr'] }],
order: [{ column: 'createdAt', direction: 'DESC' }],
})

const list = sdrMessages.map((message) => ({
//FIXME
//@ts-ignore
name:
shortDate(message.createdAt) +
' ' +
shortDid(message.from) +
' asking to share: ' +
message.data?.claims?.map((claim) => claim.claimType).join(','),
value: message,
}))

const { message } = await inquirer.prompt([
{
type: 'list',
name: 'message',
choices: list,
message: 'Selective disclosure request',
},
])
const args: any = {
sdr: message.data,
}
if (message.to) {
args.did = message.to
}
const credentialsForSdr = await agent.getVerifiableCredentialsForSdr(args)

const questions = []

for (const item of credentialsForSdr) {
questions.push({
type: 'checkbox',
name: item.claimType + ' ' + (item.essential ? '(essential)' : '') + item.reason,
choices: item.credentials.map((c) => ({
name:
c.credentialSubject[item.claimType] +
' (' +
c.type.join(',') +
') issued by: ' +
c.issuer.id +
' ' +
shortDate(c.issuanceDate) +
' ago',
value: c,
})),
})
}

const answers = await inquirer.prompt(questions)

let selectedCredentials: Array<VerifiableCredential> = []

for (const questionName of Object.keys(answers)) {
selectedCredentials = selectedCredentials.concat(answers[questionName])
}

const verifiablePresentation = await agent.createVerifiablePresentation({
save: false,
presentation: {
holder: message.to,
verifier: [message.from],
tag: message.tag,
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiablePresentation'],
issuanceDate: new Date().toISOString(),
verifiableCredential: selectedCredentials,
},
proofFormat: 'jwt',
})

await agent.sendMessageDIDCommAlpha1({
save: true,
data: {
from: message.to,
to: message.from,
type: 'jwt',
body: verifiablePresentation.proof.jwt,
},
})

console.dir(verifiablePresentation, { depth: 10 })
})
62 changes: 0 additions & 62 deletions packages/daf-cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,68 +94,6 @@ program
},
)

const publicProfileServiceEndpoint = baseUrl + options.defaultIdentity.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.defaultIdentity.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.defaultIdentity.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.defaultIdentity.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) => {
serverIdentity = await agent.identityManagerGetOrCreateIdentity({
Expand Down
Loading

0 comments on commit dc93089

Please sign in to comment.