Skip to content

Commit

Permalink
feat(demo): add accept credential flow
Browse files Browse the repository at this point in the history
Signed-off-by: annelein <[email protected]>
  • Loading branch information
Annelein authored and karimStekelenburg committed Dec 30, 2021
1 parent acbc485 commit 9e3c47e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
20 changes: 1 addition & 19 deletions demo/src/annelein.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { new_proof_preview } from './proof_request';
import { send_message } from './send_message';
import inquirer from 'inquirer'
import { restart } from './restart';
import { accept_credential_offer } from './credential';

const bc_coverin = `{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1","client_ip":"138.197.138.255","client_port":9702,"node_ip":"138.197.138.255","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"},"metadata":{"from":"Th7MpTaRZVRYnPiabds81Y"},"type":"0"},"txnMetadata":{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"},"ver":"1"}
{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","blskey_pop":"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5","client_ip":"138.197.138.255","client_port":9704,"node_ip":"138.197.138.255","node_port":9703,"services":["VALIDATOR"]},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"},"metadata":{"from":"EbP4aYNeTHL6q385GuVpRV"},"type":"0"},"txnMetadata":{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"},"ver":"1"}
Expand All @@ -35,7 +36,6 @@ const ui = new inquirer.ui.BottomBar();

enum options {
Connection = "setup connection",
Credential = "accept credential",
Proof = "present proof",
Message = "send message",
Exit = "exit",
Expand All @@ -45,11 +45,8 @@ enum options {
export const process_answer_annelein = async (annelein: Agent, answers: any) => {
if (answers.options === options.Connection){
connectionRecord = await connection(annelein)
} else if (answers.options === options.Credential){
if (connectionRecord !== undefined){
accept_credential_offer(annelein, connectionRecord)
} else {
console.log("\x1b[31m", 'Something went wrong.. Could it be that you have not set up a connection yet?', "\x1b[0m")
}
} else if (answers.options == options.Proof){
ui.updateBottomBar('\x1b[36mRegistering a proof preview...\x1b[0m');
Expand Down Expand Up @@ -80,21 +77,6 @@ export const process_answer_annelein = async (annelein: Agent, answers: any) =>
process_answer_annelein(annelein, answer)
}

const accept_credential_offer = async (annelein: Agent, connectionRecord: ConnectionRecord) => {
//await annelein.credentials.acceptOffer(connectionRecord.id)
//ui.log.write("\x1b[32m\nCredential offer accepted!\n\x1b[0m");
annelein.events.on(
CredentialEventTypes.CredentialStateChanged,
async ({ payload }: CredentialStateChangedEvent) => {
if (payload.credentialRecord.state !== CredentialState.OfferReceived) {
return
}
ui.log.write("\x1b[32m\nCredential offer accepted!\n\x1b[0m");
await annelein.credentials.acceptOffer(payload.credentialRecord.id)
}
)
}

const createAgentAnnelein = async (bc_coverin: string): Promise<Agent> => {

const name = 'annelein'
Expand Down
1 change: 0 additions & 1 deletion demo/src/annelein_inquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const annelein_inquirer = async (annelein: Agent) =>{
message: 'Options:',
choices:
['Setup connection',
'Accept credential',
'Send proof request',
'Send Message',
'Exit',
Expand Down
32 changes: 32 additions & 0 deletions demo/src/issue_credential.ts → demo/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ import inquirer from 'inquirer'
// @ts-ignore
indy.setRuntimeConfig ( {collect_backtrace: true} )

const ui = new inquirer.ui.BottomBar();

export const accept_credential_offer = async (annelein: Agent, connectionRecord: ConnectionRecord) => {
annelein.events.on(
CredentialEventTypes.CredentialStateChanged,
async ({ payload }: CredentialStateChangedEvent) => {
if (payload.credentialRecord.state !== CredentialState.OfferReceived) {
return
}
const answer = await inquirer
.prompt([
{
type: 'list',
prefix: '',
name: 'options',
message: 'Credential offer received, do you want to accept it?',
choices:
['yes',
'no'],
filter(val) {
return val.toLowerCase();
},
},
])
if (answer.options == "yes"){
await annelein.credentials.acceptOffer(payload.credentialRecord.id)
ui.log.write("\x1b[32m\nCredential offer accepted!\n\x1b[0m");
}
}
)
}

export const issue_credential = async (klm: Agent, credentialDefenitionId: string, connectionRecord: ConnectionRecord) => {
klm.events.on(
CredentialEventTypes.CredentialStateChanged,
Expand Down
2 changes: 1 addition & 1 deletion demo/src/klm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { agentDependencies, HttpInboundTransport } from '@aries-framework/node'
import clear from 'clear';
import figlet from 'figlet';
import { accept_connection } from './connection';
import { issue_credential } from './issue_credential';
import { issue_credential } from './credential';
import { klm_inquirer } from './klm_inquirer';
import { register_schema } from './register';
import { send_message } from './send_message'
Expand Down

0 comments on commit 9e3c47e

Please sign in to comment.