Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Apr 3, 2024
1 parent b5c8d08 commit 917fc7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 51 deletions.
8 changes: 2 additions & 6 deletions src/iden3comm/handlers/credential-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ export function createProposalRequest(
to: receiver.string(),
typ: MediaType.PlainMessage,
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE,
body: {
credentials: opts.credentials,
metadata: opts.metadata,
did_doc: opts.did_doc
}
body: opts
};
return request;
}
Expand Down Expand Up @@ -227,7 +223,7 @@ export class CredentialProposalHandler implements ICredentialProposalHandler {
}
}

if (credsFromWallet?.length) {
if (credsFromWallet.length) {
const guid = uuid.v4();
if (!credOfferMessage) {
credOfferMessage = {
Expand Down
55 changes: 10 additions & 45 deletions tests/handlers/credential-proposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ import {
import { expect } from 'chai';
import path from 'path';
import { PROTOCOL_MESSAGE_TYPE } from '../../src/iden3comm/constants';
import { DID } from '@iden3/js-iden3-core';

describe('proposal-request handler', () => {
let packageMgr: IPackageManager;
let idWallet: IdentityWallet;
let credWallet: ICredentialWallet;
let proposalRequestHandler: ICredentialProposalHandler;
const agentUrl = 'http://localhost:8001/api/v1/agent';
let userDID, issuerDID: DID;

const proposalResolverFn = (context: string, type: string): Promise<Proposal> => {
if (
Expand Down Expand Up @@ -91,21 +93,21 @@ describe('proposal-request handler', () => {
agentUrl,
proposalResolverFn
);
});

it('proposal-request handle request with cred exists in wallet (returns credential offer)', async () => {
const { did: userDID, credential: cred } = await createIdentity(idWallet, {
const userIdentity = await createIdentity(idWallet, {
seed: SEED_USER
});

expect(cred).not.to.be.undefined;
userDID = userIdentity.did;

const { did: issuerDID, credential: issuerAuthCredential } = await createIdentity(idWallet, {
const issuerIdentity = await createIdentity(idWallet, {
seed: SEED_ISSUER
});

expect(issuerAuthCredential).not.to.be.undefined;
issuerDID = issuerIdentity.did;
});

it('proposal-request handle request with cred exists in wallet (returns credential offer)', async () => {
const claimReq: CredentialRequest = {
credentialSchema:
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/kyc-nonmerklized.json',
Expand Down Expand Up @@ -139,27 +141,13 @@ describe('proposal-request handler', () => {

const response = await proposalRequestHandler.handleProposalRequest(msgBytesRequest);
expect(response).not.to.be.undefined;
const credentialOffer = JSON.parse(
byteDecoder.decode(response)
) as unknown as CredentialsOfferMessage;
const credentialOffer = JSON.parse(byteDecoder.decode(response)) as CredentialsOfferMessage;
expect(credentialOffer.type).to.be.eq(PROTOCOL_MESSAGE_TYPE.CREDENTIAL_OFFER_MESSAGE_TYPE);
expect(credentialOffer.body.credentials.length).to.be.eq(1);
expect(credentialOffer.body.credentials[0].id).to.be.eq(issuerCred.id);
});

it('proposal-request handle request with cred NOT exists in wallet (returns proposal message)', async () => {
const { did: userDID, credential: cred } = await createIdentity(idWallet, {
seed: SEED_USER
});

expect(cred).not.to.be.undefined;

const { did: issuerDID, credential: issuerAuthCredential } = await createIdentity(idWallet, {
seed: SEED_ISSUER
});

expect(issuerAuthCredential).not.to.be.undefined;

const proposalRequest = createProposalRequest(userDID, issuerDID, {
credentials: [
{
Expand All @@ -174,7 +162,7 @@ describe('proposal-request handler', () => {

const response = await proposalRequestHandler.handleProposalRequest(msgBytesRequest);
expect(response).not.to.be.undefined;
const credentialOffer = JSON.parse(byteDecoder.decode(response)) as unknown as ProposalMessage;
const credentialOffer = JSON.parse(byteDecoder.decode(response)) as ProposalMessage;
expect(credentialOffer.type).to.be.eq(PROTOCOL_MESSAGE_TYPE.PROPOSAL_MESSAGE_TYPE);
expect(credentialOffer.body?.proposals.length).to.be.eq(1);
expect(credentialOffer.body?.proposals[0].type).to.be.eq('WebVerificationForm');
Expand All @@ -184,18 +172,6 @@ describe('proposal-request handler', () => {
});

it('proposal-request handle not supported credential type in the request', async () => {
const { did: userDID, credential: cred } = await createIdentity(idWallet, {
seed: SEED_USER
});

expect(cred).not.to.be.undefined;

const { did: issuerDID, credential: issuerAuthCredential } = await createIdentity(idWallet, {
seed: SEED_ISSUER
});

expect(issuerAuthCredential).not.to.be.undefined;

const proposalRequest = createProposalRequest(userDID, issuerDID, {
credentials: [
{
Expand Down Expand Up @@ -224,17 +200,6 @@ describe('proposal-request handler', () => {
});

it('proposal-request handle response: wrong sender', async () => {
const { did: userDID, credential: cred } = await createIdentity(idWallet, {
seed: SEED_USER
});

expect(cred).not.to.be.undefined;

const { did: issuerDID, credential: issuerAuthCredential } = await createIdentity(idWallet, {
seed: SEED_ISSUER
});

expect(issuerAuthCredential).not.to.be.undefined;
const proposalRequest = createProposalRequest(userDID, issuerDID, {
credentials: [{ type: 'KycAgeCredential', context: 'https://test.com' }]
});
Expand Down

0 comments on commit 917fc7a

Please sign in to comment.