Skip to content

Commit 591100e

Browse files
add problem-report message type (#311)
* add problem-report message type
1 parent f51ded6 commit 591100e

File tree

7 files changed

+108
-2
lines changed

7 files changed

+108
-2
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
...spellcheckerRule,
1111
cspell: {
1212
...cspellConfig,
13-
ignoreWords: ['unmarshal', 'JUvpllMEYUZ2joO59UNui_XYDqxVqiFLLAJ8klWuPBw', 'gdwj', 'fwor', 'multichain', "ETHWEI", "ETHGWEI", "didcomm"]
13+
ignoreWords: ['unmarshal', 'JUvpllMEYUZ2joO59UNui_XYDqxVqiFLLAJ8klWuPBw', 'gdwj', 'fwor', 'multichain', "ETHWEI", "ETHGWEI", "didcomm", "pthid"]
1414
}
1515
}
1616
]

src/iden3comm/constants.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export const PROTOCOL_MESSAGE_TYPE = Object.freeze({
5555
`${DIDCOMM_PROTOCOL}discover-features/2.0/queries` as const,
5656
// DiscoveryProtocolDiscloseMessageType is type for didcomm discovery protocol disclose
5757
DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE:
58-
`${DIDCOMM_PROTOCOL}discover-features/2.0/disclose` as const
58+
`${DIDCOMM_PROTOCOL}discover-features/2.0/disclose` as const,
59+
// ProblemReportMessageType is type for didcomm problem report
60+
PROBLEM_REPORT_MESSAGE_TYPE: `${DIDCOMM_PROTOCOL}report-problem/2.0/problem-report` as const
5961
});
6062

6163
/**

src/iden3comm/handlers/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './credential-proposal';
88
export * from './message-handler';
99
export * from './payment';
1010
export * from './discovery-protocol';
11+
export * from './problem-report';
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as uuid from 'uuid';
2+
import { ProblemReportMessage } from '../types/protocol/problem-report';
3+
import { MediaType, PROTOCOL_MESSAGE_TYPE } from '../constants';
4+
5+
/**
6+
* @beta
7+
* createProblemReportMessage is a function to create didcomm protocol problem report message
8+
* @param pthid - parent thread id
9+
* @param code - problem report code
10+
* @param opts - problem report options
11+
* @returns `ProblemReportMessage`
12+
*/
13+
export function createProblemReportMessage(
14+
pthid: string,
15+
code: string,
16+
opts?: {
17+
comment?: string;
18+
ack?: string[];
19+
args?: string[];
20+
escalate_to?: string;
21+
from?: string;
22+
to?: string;
23+
}
24+
): ProblemReportMessage {
25+
const uuidv4 = uuid.v4();
26+
return {
27+
id: uuidv4,
28+
pthid: pthid,
29+
typ: MediaType.PlainMessage,
30+
type: PROTOCOL_MESSAGE_TYPE.PROBLEM_REPORT_MESSAGE_TYPE,
31+
ack: opts?.ack,
32+
body: {
33+
code: code,
34+
comment: opts?.comment,
35+
args: opts?.args,
36+
escalate_to: opts?.escalate_to
37+
},
38+
from: opts?.from,
39+
to: opts?.to
40+
};
41+
}

src/iden3comm/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './protocol/proposal-request';
88
export * from './protocol/payment';
99
export * from './protocol/accept-profile';
1010
export * from './protocol/discovery-protocol';
11+
export * from './protocol/problem-report';
1112

1213
export * from './packer';
1314
export * from './models';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PROTOCOL_MESSAGE_TYPE } from '../../constants';
2+
import { BasicMessage } from '../packer';
3+
4+
/** ProblemReportMessage is struct for problem report message */
5+
export type ProblemReportMessage = BasicMessage & {
6+
body: ProblemReportMessageBody;
7+
pthid: string;
8+
ack?: string[];
9+
type: typeof PROTOCOL_MESSAGE_TYPE.PROBLEM_REPORT_MESSAGE_TYPE;
10+
};
11+
12+
/** ProblemReportMessageBody is struct for problem report message body */
13+
export type ProblemReportMessageBody = {
14+
code: string;
15+
comment?: string;
16+
args?: string[];
17+
escalate_to?: string;
18+
};

tests/handlers/problem-report.test.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe } from 'mocha';
2+
import { createProblemReportMessage } from '../../src';
3+
import { expect } from 'chai';
4+
5+
describe('Problem Report Handler', () => {
6+
it('should create problem report', () => {
7+
const example = `{
8+
"typ": "application/iden3comm-plain-json",
9+
"type": "https://didcomm.org/report-problem/2.0/problem-report",
10+
"pthid": "5333207e-7338-4ab3-ac34-bf9a20dab6ab",
11+
"ack": [
12+
"23b610b3-aec8-4d1c-8a75-3b22e5483fb0",
13+
"86fe7cc6-adcd-4530-8e07-92c060b427c8"
14+
],
15+
"body": {
16+
"code": "e.me.remote-server-down",
17+
"comment": "Remote server {1} is down when connecting from {2}",
18+
"args": [
19+
"https://remote-server.org",
20+
"https://my-server.org"
21+
],
22+
"escalate_to": "[email protected]"
23+
},
24+
"from": "did:polygonid:polygon:mumbai:2qJG6RYgN1u6v7JAYSdfixSwktnZ7hMzd4t21SCdNu",
25+
"to": "did:polygonid:polygon:mumbai:2qFroxB5kwgCxgVrNGUM6EW3khJgCdHHnKTr3VnTcp"
26+
}`;
27+
const problemReport = createProblemReportMessage(
28+
'5333207e-7338-4ab3-ac34-bf9a20dab6ab',
29+
'e.me.remote-server-down',
30+
{
31+
from: 'did:polygonid:polygon:mumbai:2qJG6RYgN1u6v7JAYSdfixSwktnZ7hMzd4t21SCdNu',
32+
to: 'did:polygonid:polygon:mumbai:2qFroxB5kwgCxgVrNGUM6EW3khJgCdHHnKTr3VnTcp',
33+
args: ['https://remote-server.org', 'https://my-server.org'],
34+
escalate_to: '[email protected]',
35+
ack: ['23b610b3-aec8-4d1c-8a75-3b22e5483fb0', '86fe7cc6-adcd-4530-8e07-92c060b427c8'],
36+
comment: 'Remote server {1} is down when connecting from {2}'
37+
}
38+
);
39+
delete problemReport.id;
40+
const expected = JSON.parse(example);
41+
expect(problemReport).to.be.deep.equal(expected);
42+
});
43+
});

0 commit comments

Comments
 (0)