Skip to content

Commit

Permalink
Merge pull request #253 from docknetwork/DCKM-461-wallet-692-wallet-w…
Browse files Browse the repository at this point in the history
…allet-vc-verification-flow-is-broken-fix2

DCKM-461: fixing wallet to wallet verification issue
  • Loading branch information
maycon-mello authored Apr 25, 2024
2 parents 7706035 + 4bec663 commit 9936d87
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions integration-tests/wallet-to-wallet-verification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {

const waitFor = ms => new Promise(r => setTimeout(r, ms));

// TODO: We are currently using the same wallet as the holder and verifier
// We should create two separate wallets
// This way we can ensure that each wallet is able to handle the messages correctly and sending those to the right destination
// https://dock-team.atlassian.net/browse/DCKM-465
describe('Wallet to Wallet Verification', () => {
it('should get OOB message to be shared as QR code', async () => {
const wallet: IWallet = await getWallet();
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/messages/message-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {buildVerifiablePresentationMessage} from './message-helpers';

describe('message-helpers', () => {
it('should build a verifiable presentation message from the holder to the verifier', () => {
const message = buildVerifiablePresentationMessage({
holderDID: 'holderDID',
verifierDID: 'verifierDID',
presentation: 'presentation',
proofRequestId: 'proofRequestId',
});

expect(message.from).toBe('holderDID');
expect(message.to).toBe('verifierDID');
});
});
4 changes: 2 additions & 2 deletions packages/core/src/messages/message-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export function buildVerifiablePresentationMessage({
}) {
return {
type: MessageTypes.Presentation,
from: verifierDID,
to: holderDID,
from: holderDID,
to: verifierDID,
body: {
proofRequestId,
presentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {IWallet} from '../types';
import {IMessageProvider} from '../message-provider';
import {logger} from '@docknetwork/wallet-sdk-data-store/src/logger';
import { EventEmitter } from 'events';

const ProofRequestTemplateType = 'ProofRequestTemplate';

Expand All @@ -29,6 +30,12 @@ export interface IWalletToWalletVerificationProvider {
addProofRequestTemplate: (proofRequestTemplate: any) => Promise<any>;
getProofRequestTemplates: () => Promise<any[]>;
handleMessage: (message: any) => Promise<boolean>;
eventEmitter: EventEmitter;
}

export const Events = {
VerifierFlowStarted: 'VerifierFlowStarted',
HolderFlowStarted: 'HolderFlowStarted',
}

export function createWalletToWalletVerificationProvider({
Expand All @@ -47,7 +54,10 @@ export function createWalletToWalletVerificationProvider({
// Can be used by the HOLDER to render the verification results sent by the verifier
let presentationAckHandler;

const eventEmitter = new EventEmitter();

return {
eventEmitter,
getInvitationOOBMessage: async ({templateId}) => {
const defaultDID = await didProvider.getDefaultDID();
const template = await wallet.getDocumentById(templateId);
Expand Down Expand Up @@ -100,6 +110,9 @@ export function createWalletToWalletVerificationProvider({
verifierDID: message.from,
}),
);

eventEmitter.emit(Events.HolderFlowStarted);

return true;
}

Expand Down Expand Up @@ -132,6 +145,8 @@ export function createWalletToWalletVerificationProvider({
verifierDID: defaultDID,
}),
);

eventEmitter.emit(Events.VerifierFlowStarted);
}

process();
Expand Down

0 comments on commit 9936d87

Please sign in to comment.