-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: daf-cli credential sending, receiving
- Loading branch information
1 parent
4e35414
commit 7ca187e
Showing
8 changed files
with
189 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import program from 'commander' | ||
import './identity-manager' | ||
import './did-resolver' | ||
import './credential' | ||
import './services' | ||
|
||
program.parse(process.argv) | ||
|
||
if (!process.argv.slice(2).length) { | ||
program.outputHelp() | ||
} |
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,96 @@ | ||
import * as W3c from 'daf-w3c' | ||
import * as DIDComm from 'daf-did-comm' | ||
import { core, dataStore } from './setup' | ||
import program from 'commander' | ||
import inquirer from 'inquirer' | ||
import qrcode from 'qrcode-terminal' | ||
|
||
program | ||
.command('credential') | ||
.description('Manage W3C Verifiable Credentials') | ||
.option('-c, --create', 'Create new credential') | ||
.option('-s, --send', 'Send') | ||
.option('-q, --qrcode', 'Show qrcode') | ||
.option('-r, --receiver <did>', 'Credential subject') | ||
.action(async (cmd) => { | ||
if (cmd.create) { | ||
const myDids = await core.identityManager.listDids() | ||
if (myDids.length === 0) { | ||
console.error('No dids') | ||
process.exit() | ||
} | ||
const answers = await inquirer.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'iss', | ||
choices: myDids, | ||
message: 'Issuer DID' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'sub', | ||
message: 'Subject DID', | ||
default: cmd.receiver | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'claimType', | ||
message: 'Claim Type', | ||
default: 'name' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'claimValue', | ||
message: 'Claim Value', | ||
default: 'Alice' | ||
}, | ||
]) | ||
|
||
const credentialSubject: any = {} | ||
const type: string = answers.claimType | ||
credentialSubject[ type ] = answers.claimValue | ||
|
||
const signAction: W3c.ActionSignW3cVc = { | ||
type: W3c.ActionTypes.signVc, | ||
did: answers.iss, | ||
data: { | ||
sub: answers.sub, | ||
vc: { | ||
'@context': ['https://www.w3.org/2018/credentials/v1'], | ||
type: ['VerifiableCredential'], | ||
credentialSubject | ||
}, | ||
} | ||
} | ||
|
||
const jwt = await core.handleAction(signAction) | ||
|
||
if (!cmd.send) { | ||
await dataStore.initialize() | ||
await core.onRawMessage({raw: jwt}) | ||
} else { | ||
|
||
const sendAction: DIDComm.ActionSendJWT = { | ||
type: DIDComm.ActionTypes.sendJwt, | ||
data: { | ||
from: answers.iss, | ||
to: answers.sub, | ||
jwt | ||
} | ||
} | ||
try { | ||
const result = await core.handleAction(sendAction) | ||
console.log('Sent:', result) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
|
||
if (cmd.qrcode) { | ||
qrcode.generate(jwt) | ||
} | ||
|
||
} | ||
|
||
}) | ||
|
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 { EventTypes, Types } from 'daf-core' | ||
import { core, dataStore } from './setup' | ||
import program from 'commander' | ||
|
||
program | ||
.command('listen') | ||
.description('Receive new messages and listen for new ones') | ||
.action(async (did) => { | ||
await dataStore.initialize() | ||
|
||
core.on(EventTypes.validatedMessage, (type, msg: Types.ValidatedMessage) => { | ||
console.log('New message type:', msg.type) | ||
}) | ||
|
||
await core.startServices() | ||
await core.syncServices( | ||
await dataStore.latestMessageTimestamps() | ||
) | ||
}) | ||
|
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,4 @@ | ||
declare module 'qrcode-terminal'{ | ||
export const generate: (text: string, options?: any) => void | ||
|
||
} |