@sovrahq/waci 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -0
- package/.eslintrc.js +21 -0
- package/.prettierrc +4 -0
- package/LICENSE +201 -0
- package/dist/callbacks/index.d.ts +108 -0
- package/dist/callbacks/index.js +9 -0
- package/dist/callbacks/index.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +5 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/handlers/common/problem-report.handler.d.ts +4 -0
- package/dist/handlers/common/problem-report.handler.js +72 -0
- package/dist/handlers/common/problem-report.handler.js.map +1 -0
- package/dist/handlers/common/step-2-oob-invitation.handler.d.ts +4 -0
- package/dist/handlers/common/step-2-oob-invitation.handler.js +93 -0
- package/dist/handlers/common/step-2-oob-invitation.handler.js.map +1 -0
- package/dist/handlers/decorators/register-handler.decorator.d.ts +2 -0
- package/dist/handlers/decorators/register-handler.decorator.js +13 -0
- package/dist/handlers/decorators/register-handler.decorator.js.map +1 -0
- package/dist/handlers/index.d.ts +6 -0
- package/dist/handlers/index.js +11 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/issuance/step-3-propose-credential.handler.d.ts +32 -0
- package/dist/handlers/issuance/step-3-propose-credential.handler.js +180 -0
- package/dist/handlers/issuance/step-3-propose-credential.handler.js.map +1 -0
- package/dist/handlers/issuance/step-4-1-offer-credential-proceed.handler.d.ts +5 -0
- package/dist/handlers/issuance/step-4-1-offer-credential-proceed.handler.js +152 -0
- package/dist/handlers/issuance/step-4-1-offer-credential-proceed.handler.js.map +1 -0
- package/dist/handlers/issuance/step-4-offer-credential.handler.d.ts +5 -0
- package/dist/handlers/issuance/step-4-offer-credential.handler.js +169 -0
- package/dist/handlers/issuance/step-4-offer-credential.handler.js.map +1 -0
- package/dist/handlers/issuance/step-5-request-credential.handler.d.ts +4 -0
- package/dist/handlers/issuance/step-5-request-credential.handler.js +275 -0
- package/dist/handlers/issuance/step-5-request-credential.handler.js.map +1 -0
- package/dist/handlers/issuance/step-6-issue-credential.handler.d.ts +4 -0
- package/dist/handlers/issuance/step-6-issue-credential.handler.js +106 -0
- package/dist/handlers/issuance/step-6-issue-credential.handler.js.map +1 -0
- package/dist/handlers/issuance/step-7-ack-message.handler.d.ts +4 -0
- package/dist/handlers/issuance/step-7-ack-message.handler.js +78 -0
- package/dist/handlers/issuance/step-7-ack-message.handler.js.map +1 -0
- package/dist/handlers/presentation/step-3-propose-presentation.handler.d.ts +5 -0
- package/dist/handlers/presentation/step-3-propose-presentation.handler.js +107 -0
- package/dist/handlers/presentation/step-3-propose-presentation.handler.js.map +1 -0
- package/dist/handlers/presentation/step-4-1-presentation-proceed.handler.d.ts +5 -0
- package/dist/handlers/presentation/step-4-1-presentation-proceed.handler.js +130 -0
- package/dist/handlers/presentation/step-4-1-presentation-proceed.handler.js.map +1 -0
- package/dist/handlers/presentation/step-4-request-presentation.handler.d.ts +5 -0
- package/dist/handlers/presentation/step-4-request-presentation.handler.js +151 -0
- package/dist/handlers/presentation/step-4-request-presentation.handler.js.map +1 -0
- package/dist/handlers/presentation/step-5-present-proof.handler.d.ts +4 -0
- package/dist/handlers/presentation/step-5-present-proof.handler.js +211 -0
- package/dist/handlers/presentation/step-5-present-proof.handler.js.map +1 -0
- package/dist/handlers/presentation/step-6-ack-message.handler.d.ts +4 -0
- package/dist/handlers/presentation/step-6-ack-message.handler.js +72 -0
- package/dist/handlers/presentation/step-6-ack-message.handler.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/services/waci-interpreter.d.ts +17 -0
- package/dist/services/waci-interpreter.js +222 -0
- package/dist/services/waci-interpreter.js.map +1 -0
- package/dist/types/actor.d.ts +5 -0
- package/dist/types/actor.js +10 -0
- package/dist/types/actor.js.map +1 -0
- package/dist/types/credential-application.d.ts +36 -0
- package/dist/types/credential-application.js +3 -0
- package/dist/types/credential-application.js.map +1 -0
- package/dist/types/credential-manifest.d.ts +173 -0
- package/dist/types/credential-manifest.js +3 -0
- package/dist/types/credential-manifest.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/problem-report.d.ts +13 -0
- package/dist/types/problem-report.js +18 -0
- package/dist/types/problem-report.js.map +1 -0
- package/dist/types/waci-message.d.ts +106 -0
- package/dist/types/waci-message.js +106 -0
- package/dist/types/waci-message.js.map +1 -0
- package/dist/utils/erros.d.ts +15 -0
- package/dist/utils/erros.js +42 -0
- package/dist/utils/erros.js.map +1 -0
- package/dist/utils/index.d.ts +22 -0
- package/dist/utils/index.js +356 -0
- package/dist/utils/index.js.map +1 -0
- package/jest.config.json +17 -0
- package/package.json +39 -0
- package/readme.md +1 -0
- package/src/callbacks/index.ts +75 -0
- package/src/constants/index.ts +1 -0
- package/src/handlers/common/problem-report.handler.ts +15 -0
- package/src/handlers/common/step-2-oob-invitation.handler.ts +45 -0
- package/src/handlers/decorators/register-handler.decorator.ts +10 -0
- package/src/handlers/index.ts +7 -0
- package/src/handlers/issuance/step-3-propose-credential.handler.ts +186 -0
- package/src/handlers/issuance/step-4-1-offer-credential-proceed.handler.ts +129 -0
- package/src/handlers/issuance/step-4-offer-credential.handler.ts +137 -0
- package/src/handlers/issuance/step-5-request-credential.handler.ts +205 -0
- package/src/handlers/issuance/step-6-issue-credential.handler.ts +63 -0
- package/src/handlers/issuance/step-7-ack-message.handler.ts +21 -0
- package/src/handlers/presentation/step-3-propose-presentation.handler.ts +67 -0
- package/src/handlers/presentation/step-4-1-presentation-proceed.handler.ts +100 -0
- package/src/handlers/presentation/step-4-request-presentation.handler.ts +115 -0
- package/src/handlers/presentation/step-5-present-proof.handler.ts +159 -0
- package/src/handlers/presentation/step-6-ack-message.handler.ts +15 -0
- package/src/index.ts +18 -0
- package/src/services/waci-interpreter.ts +161 -0
- package/src/types/actor.ts +5 -0
- package/src/types/credential-application.ts +38 -0
- package/src/types/credential-manifest.ts +184 -0
- package/src/types/index.ts +4 -0
- package/src/types/problem-report.ts +29 -0
- package/src/types/waci-message.ts +148 -0
- package/src/utils/erros.ts +21 -0
- package/src/utils/index.ts +272 -0
- package/test/handlers/issuance/step-3-propose-credential.handler.spec.ts +43 -0
- package/test/handlers/issuance/step-4-offer-credential.handler.spec.ts +53 -0
- package/test/handlers/issuance/step-5-request-credential.handler.spec.ts +102 -0
- package/test/handlers/presentation/step-5-present-proof.handler.spec.ts +142 -0
- package/test/handlers/shared/step-2-oob-invitation.handler.spec.ts +55 -0
- package/test/stubs/index.ts +842 -0
- package/test/waci-interpreter.spec.ts +113 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { handlers } from '../handlers';
|
|
2
|
+
import { InputCallbacks } from '../callbacks';
|
|
3
|
+
import {
|
|
4
|
+
WACIMessageType,
|
|
5
|
+
WACIMessageTypeV1,
|
|
6
|
+
WACIMessage,
|
|
7
|
+
GoalCode,
|
|
8
|
+
Actor,
|
|
9
|
+
CredentialManifest,
|
|
10
|
+
CredentialFulfillment,
|
|
11
|
+
WACIResponse,
|
|
12
|
+
WACIMessageHandlerResponse,
|
|
13
|
+
DIDCommVersion,
|
|
14
|
+
detectDIDCommVersion,
|
|
15
|
+
normalizeToV2,
|
|
16
|
+
convertToVersion,
|
|
17
|
+
} from '../types';
|
|
18
|
+
import { createUUID, getObjectValues } from '../utils';
|
|
19
|
+
import { SUPPORTED_ALGORITHMS } from '../constants';
|
|
20
|
+
import { PresentationProceed } from '../handlers/presentation/step-4-1-presentation-proceed.handler';
|
|
21
|
+
import { OfferCredentialProceed } from '../handlers/issuance/step-4-1-offer-credential-proceed.handler';
|
|
22
|
+
|
|
23
|
+
export class WACIInterpreter {
|
|
24
|
+
private readonly enabledActors: Actor[];
|
|
25
|
+
private callbacks: InputCallbacks;
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
this.enabledActors = [];
|
|
29
|
+
this.callbacks = {};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
setUpFor<T extends Actor>(
|
|
33
|
+
params: InputCallbacks[T],
|
|
34
|
+
actor: T,
|
|
35
|
+
): WACIInterpreter {
|
|
36
|
+
this.enabledActors.push(actor);
|
|
37
|
+
this.callbacks[actor] = params;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
isWACIMessage(messageToCheck: any): messageToCheck is WACIMessage {
|
|
42
|
+
try {
|
|
43
|
+
const allTypes = [
|
|
44
|
+
...getObjectValues(WACIMessageType),
|
|
45
|
+
...getObjectValues(WACIMessageTypeV1),
|
|
46
|
+
];
|
|
47
|
+
return allTypes.includes(messageToCheck.type);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async createOOBInvitation(
|
|
54
|
+
senderDID: string,
|
|
55
|
+
goalCode: GoalCode,
|
|
56
|
+
body = {},
|
|
57
|
+
version?: DIDCommVersion,
|
|
58
|
+
): Promise<WACIMessage> {
|
|
59
|
+
const type = version === DIDCommVersion.V1
|
|
60
|
+
? convertToVersion(WACIMessageType.OutOfBandInvitation, DIDCommVersion.V1) as any
|
|
61
|
+
: WACIMessageType.OutOfBandInvitation;
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
type,
|
|
65
|
+
id: createUUID(),
|
|
66
|
+
from: senderDID,
|
|
67
|
+
body: {
|
|
68
|
+
...body,
|
|
69
|
+
goal_code: goalCode,
|
|
70
|
+
accept: SUPPORTED_ALGORITHMS,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async createOfferCredentialMessage(
|
|
76
|
+
issuerDID: string,
|
|
77
|
+
holderDID: string,
|
|
78
|
+
manifest: CredentialManifest,
|
|
79
|
+
fulfillment: CredentialFulfillment,
|
|
80
|
+
): Promise<WACIMessage> {
|
|
81
|
+
return {
|
|
82
|
+
type: WACIMessageType.OfferCredential,
|
|
83
|
+
id: createUUID(),
|
|
84
|
+
from: issuerDID,
|
|
85
|
+
to: [issuerDID],
|
|
86
|
+
body: {},
|
|
87
|
+
attachments: [manifest, fulfillment],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async processMessage(
|
|
92
|
+
messageThread: WACIMessage[],
|
|
93
|
+
): Promise<WACIResponse | void> {
|
|
94
|
+
const message = messageThread[messageThread.length - 1];
|
|
95
|
+
|
|
96
|
+
// Detect incoming version and normalize v1 → v2 for handler lookup
|
|
97
|
+
const incomingVersion = detectDIDCommVersion(message.type as string);
|
|
98
|
+
const normalizedType = normalizeToV2(message.type as string) as any;
|
|
99
|
+
|
|
100
|
+
for await (const enabledActor of this.enabledActors) {
|
|
101
|
+
const messageHandler = handlers[enabledActor].get(normalizedType);
|
|
102
|
+
if (messageHandler) {
|
|
103
|
+
// Temporarily set normalized type for the handler
|
|
104
|
+
const originalType = message.type;
|
|
105
|
+
message.type = normalizedType;
|
|
106
|
+
|
|
107
|
+
const response = await messageHandler.handle(messageThread, this.callbacks);
|
|
108
|
+
|
|
109
|
+
// Restore original type
|
|
110
|
+
message.type = originalType;
|
|
111
|
+
|
|
112
|
+
if (response) {
|
|
113
|
+
// Convert response type back to v1 if the interlocutor speaks v1
|
|
114
|
+
if (incomingVersion === DIDCommVersion.V1) {
|
|
115
|
+
response.message.type = convertToVersion(
|
|
116
|
+
response.message.type as string,
|
|
117
|
+
DIDCommVersion.V1,
|
|
118
|
+
) as any;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
...response,
|
|
122
|
+
target: response.message.to[0],
|
|
123
|
+
message: response.message,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
throw Error(`No handler found for message of type '${message.type}'`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async presentationProceed(
|
|
134
|
+
messageThread: WACIMessage[],
|
|
135
|
+
credentialsToPresent: any[],
|
|
136
|
+
presentationProofTypes?: string[]) {
|
|
137
|
+
|
|
138
|
+
let response: WACIMessageHandlerResponse = null;
|
|
139
|
+
|
|
140
|
+
// Normalize last message type for comparison
|
|
141
|
+
const lastType = normalizeToV2(
|
|
142
|
+
messageThread[messageThread.length - 1].type as string,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (lastType == WACIMessageType.OfferCredential) {
|
|
146
|
+
response = await OfferCredentialProceed.handle(messageThread, credentialsToPresent, presentationProofTypes, this.callbacks)
|
|
147
|
+
} else if (lastType == WACIMessageType.RequestPresentation) {
|
|
148
|
+
response = await PresentationProceed.presentCredentials(messageThread, credentialsToPresent, this.callbacks);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!response) {
|
|
152
|
+
throw new Error("To call this process, the message thread must end with a message of type OfferCredential or RequestPresentation.");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
...response,
|
|
157
|
+
target: response.message.to[0],
|
|
158
|
+
message: response.message,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ClaimFormat } from './credential-manifest';
|
|
2
|
+
|
|
3
|
+
export type CredentialApplication = {
|
|
4
|
+
id: string;
|
|
5
|
+
media_type: 'application/json';
|
|
6
|
+
format: 'dif/credential-manifest/application@v1.0';
|
|
7
|
+
data: {
|
|
8
|
+
json: {
|
|
9
|
+
'@context': string[];
|
|
10
|
+
type: string[];
|
|
11
|
+
credential_application: {
|
|
12
|
+
id: string;
|
|
13
|
+
manifest_id: string;
|
|
14
|
+
format?: ClaimFormat;
|
|
15
|
+
};
|
|
16
|
+
presentation_submission: PresentationSubmission;
|
|
17
|
+
verifiableCredential: any[];
|
|
18
|
+
proof: {
|
|
19
|
+
type: string;
|
|
20
|
+
verificationMethod: string;
|
|
21
|
+
created: string;
|
|
22
|
+
proofPurpose: string;
|
|
23
|
+
challenge: string;
|
|
24
|
+
jws: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type PresentationSubmission = {
|
|
31
|
+
id: string;
|
|
32
|
+
definition_id: string;
|
|
33
|
+
descriptor_map: {
|
|
34
|
+
id: string;
|
|
35
|
+
format: string;
|
|
36
|
+
path: string;
|
|
37
|
+
}[];
|
|
38
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { PresentationSubmission } from './credential-application';
|
|
2
|
+
|
|
3
|
+
export type CredentialManifest = {
|
|
4
|
+
id: string;
|
|
5
|
+
media_type: string;
|
|
6
|
+
format: 'dif/credential-manifest/manifest@v1.0';
|
|
7
|
+
data: {
|
|
8
|
+
json: {
|
|
9
|
+
options: {
|
|
10
|
+
challenge: string;
|
|
11
|
+
domain?: string;
|
|
12
|
+
};
|
|
13
|
+
credential_manifest: {
|
|
14
|
+
id: string;
|
|
15
|
+
version: string;
|
|
16
|
+
issuer: {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
styles?: CredentialManifestStyles;
|
|
20
|
+
};
|
|
21
|
+
format?: ClaimFormat;
|
|
22
|
+
output_descriptors: OutputDescriptor[];
|
|
23
|
+
presentation_definition?: PresentationDefinition;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type CredentialFulfillment = {
|
|
30
|
+
id: string;
|
|
31
|
+
media_type: 'application/json';
|
|
32
|
+
format: 'dif/credential-manifest/fulfillment@v1.0';
|
|
33
|
+
data: {
|
|
34
|
+
json: {
|
|
35
|
+
'@context': string[];
|
|
36
|
+
type: string[];
|
|
37
|
+
credential_fulfillment: {
|
|
38
|
+
id: string;
|
|
39
|
+
manifest_id: string;
|
|
40
|
+
descriptor_map: {
|
|
41
|
+
id: string;
|
|
42
|
+
format: string;
|
|
43
|
+
path: string;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
verifiableCredential: any[];
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type CredentialRequest = {
|
|
52
|
+
id: string;
|
|
53
|
+
media_type: string;
|
|
54
|
+
format: 'dif/presentation-exchange/definitions@v1.0';
|
|
55
|
+
data: {
|
|
56
|
+
json: {
|
|
57
|
+
options: {
|
|
58
|
+
challenge: string;
|
|
59
|
+
domain?: string;
|
|
60
|
+
};
|
|
61
|
+
presentation_definition?: PresentationDefinition;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type CredentialPresentation = {
|
|
67
|
+
id: string;
|
|
68
|
+
media_type: string;
|
|
69
|
+
format: 'dif/presentation-exchange/submission@v1.0';
|
|
70
|
+
data: {
|
|
71
|
+
json: {
|
|
72
|
+
'@context': string[];
|
|
73
|
+
type: string[];
|
|
74
|
+
holder: string;
|
|
75
|
+
verifiableCredential: any[];
|
|
76
|
+
presentation_submission: PresentationSubmission;
|
|
77
|
+
proof: {
|
|
78
|
+
type: string;
|
|
79
|
+
verificationMethod: string;
|
|
80
|
+
created: string;
|
|
81
|
+
proofPurpose: string;
|
|
82
|
+
challenge: string;
|
|
83
|
+
jws: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type OutputDescriptor = {
|
|
90
|
+
id: string;
|
|
91
|
+
schema?: string;
|
|
92
|
+
display?: {
|
|
93
|
+
title?: DisplayMappingObject;
|
|
94
|
+
subtitle?: DisplayMappingObject;
|
|
95
|
+
description?: DisplayMappingObject;
|
|
96
|
+
properties?: (DisplayMappingObject & { label?: string })[];
|
|
97
|
+
};
|
|
98
|
+
styles: CredentialManifestStyles;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type DisplayMappingObject =
|
|
102
|
+
| {
|
|
103
|
+
path?: string[];
|
|
104
|
+
schema?: {
|
|
105
|
+
type?: string;
|
|
106
|
+
};
|
|
107
|
+
fallback?: string;
|
|
108
|
+
}
|
|
109
|
+
| { text: string };
|
|
110
|
+
|
|
111
|
+
export type ClaimFormat = {
|
|
112
|
+
jwt?: {
|
|
113
|
+
alg: string[];
|
|
114
|
+
};
|
|
115
|
+
jwt_vc?: {
|
|
116
|
+
alg: string[];
|
|
117
|
+
};
|
|
118
|
+
jwt_vp?: {
|
|
119
|
+
alg: string[];
|
|
120
|
+
};
|
|
121
|
+
ldp_vc?: {
|
|
122
|
+
proof_type: string[];
|
|
123
|
+
};
|
|
124
|
+
ldp_vp?: {
|
|
125
|
+
proof_type: string[];
|
|
126
|
+
};
|
|
127
|
+
ldp?: {
|
|
128
|
+
proof_type: string[];
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type PresentationDefinitionFrame = {
|
|
133
|
+
'@context': string[];
|
|
134
|
+
type: string[];
|
|
135
|
+
credentialSubject: {
|
|
136
|
+
"@explicit": boolean;
|
|
137
|
+
type: string[];
|
|
138
|
+
[key: string]: {};
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type PresentationDefinition = {
|
|
143
|
+
id: string;
|
|
144
|
+
input_descriptors: InputDescriptor[];
|
|
145
|
+
frame?: PresentationDefinitionFrame;
|
|
146
|
+
name?: string;
|
|
147
|
+
purpose?: string;
|
|
148
|
+
format?: ClaimFormat;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export type InputDescriptor = {
|
|
152
|
+
id: string;
|
|
153
|
+
constraints: {
|
|
154
|
+
fields: {
|
|
155
|
+
path: string[];
|
|
156
|
+
id?: string;
|
|
157
|
+
purpose?: string;
|
|
158
|
+
filter?: {
|
|
159
|
+
type: string;
|
|
160
|
+
const?: any;
|
|
161
|
+
};
|
|
162
|
+
}[];
|
|
163
|
+
limit_disclosure?: 'required' | 'preferred';
|
|
164
|
+
};
|
|
165
|
+
name?: string;
|
|
166
|
+
purpose?: string;
|
|
167
|
+
format?: ClaimFormat;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export type CredentialManifestStyles = {
|
|
171
|
+
thumbnail?: ThumbnailImage;
|
|
172
|
+
hero?: ThumbnailImage;
|
|
173
|
+
background?: ColorDefinition;
|
|
174
|
+
text?: ColorDefinition;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type ColorDefinition = {
|
|
178
|
+
color: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type ThumbnailImage = {
|
|
182
|
+
uri: string;
|
|
183
|
+
alt: string;
|
|
184
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export interface ProblemReportBody {
|
|
5
|
+
code: string;
|
|
6
|
+
comment?: string;
|
|
7
|
+
args?: string[];
|
|
8
|
+
escalate_to?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ProblemReportMessage{
|
|
12
|
+
code: string;
|
|
13
|
+
comment?: string;
|
|
14
|
+
args?: string[];
|
|
15
|
+
escalate_to?: string;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
presentProofMessage(code: string, comment?:string, args?: string[], escalate_to?: string): ProblemReportBody{
|
|
20
|
+
return {
|
|
21
|
+
code: code,
|
|
22
|
+
comment: comment,
|
|
23
|
+
args: args,
|
|
24
|
+
escalate_to: escalate_to
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
enum SharedMessageType {
|
|
2
|
+
OutOfBandInvitation = 'https://didcomm.org/out-of-band/2.0/invitation',
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
enum IssuanceMessageType {
|
|
6
|
+
ProposeCredential = 'https://didcomm.org/issue-credential/3.0/propose-credential',
|
|
7
|
+
OfferCredential = 'https://didcomm.org/issue-credential/3.0/offer-credential',
|
|
8
|
+
RequestCredential = 'https://didcomm.org/issue-credential/3.0/request-credential',
|
|
9
|
+
IssueCredential = 'https://didcomm.org/issue-credential/3.0/issue-credential',
|
|
10
|
+
IssuanceAck = 'https://didcomm.org/issue-credential/3.0/ack',
|
|
11
|
+
ProblemReport = 'https://didcomm.org/report-problem/2.0/problem-report',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
enum PresentationMessageType {
|
|
15
|
+
ProposePresentation = 'https://didcomm.org/present-proof/3.0/propose-presentation',
|
|
16
|
+
RequestPresentation = 'https://didcomm.org/present-proof/3.0/request-presentation',
|
|
17
|
+
PresentProof = 'https://didcomm.org/present-proof/3.0/presentation',
|
|
18
|
+
PresentationAck = 'https://didcomm.org/present-proof/3.0/ack',
|
|
19
|
+
ProblemReport = 'https://didcomm.org/report-problem/2.0/problem-report',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// --- DIDComm v1 message types ---
|
|
23
|
+
|
|
24
|
+
enum SharedMessageTypeV1 {
|
|
25
|
+
OutOfBandInvitation = 'https://didcomm.org/out-of-band/1.0/invitation',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
enum IssuanceMessageTypeV1 {
|
|
29
|
+
ProposeCredential = 'https://didcomm.org/issue-credential/1.0/propose-credential',
|
|
30
|
+
OfferCredential = 'https://didcomm.org/issue-credential/1.0/offer-credential',
|
|
31
|
+
RequestCredential = 'https://didcomm.org/issue-credential/1.0/request-credential',
|
|
32
|
+
IssueCredential = 'https://didcomm.org/issue-credential/1.0/issue-credential',
|
|
33
|
+
IssuanceAck = 'https://didcomm.org/issue-credential/1.0/ack',
|
|
34
|
+
ProblemReport = 'https://didcomm.org/report-problem/1.0/problem-report',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
enum PresentationMessageTypeV1 {
|
|
38
|
+
ProposePresentation = 'https://didcomm.org/present-proof/1.0/propose-presentation',
|
|
39
|
+
RequestPresentation = 'https://didcomm.org/present-proof/1.0/request-presentation',
|
|
40
|
+
PresentProof = 'https://didcomm.org/present-proof/1.0/presentation',
|
|
41
|
+
PresentationAck = 'https://didcomm.org/present-proof/1.0/ack',
|
|
42
|
+
ProblemReport = 'https://didcomm.org/report-problem/1.0/problem-report',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const WACIMessageTypeV1 = {
|
|
46
|
+
...SharedMessageTypeV1,
|
|
47
|
+
...IssuanceMessageTypeV1,
|
|
48
|
+
...PresentationMessageTypeV1,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// --- Version detection & normalization ---
|
|
52
|
+
|
|
53
|
+
export enum DIDCommVersion {
|
|
54
|
+
V1 = 'v1',
|
|
55
|
+
V2 = 'v2',
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const V1_TO_V2_MAP: Record<string, string> = {
|
|
59
|
+
[SharedMessageTypeV1.OutOfBandInvitation]: SharedMessageType.OutOfBandInvitation,
|
|
60
|
+
[IssuanceMessageTypeV1.ProposeCredential]: IssuanceMessageType.ProposeCredential,
|
|
61
|
+
[IssuanceMessageTypeV1.OfferCredential]: IssuanceMessageType.OfferCredential,
|
|
62
|
+
[IssuanceMessageTypeV1.RequestCredential]: IssuanceMessageType.RequestCredential,
|
|
63
|
+
[IssuanceMessageTypeV1.IssueCredential]: IssuanceMessageType.IssueCredential,
|
|
64
|
+
[IssuanceMessageTypeV1.IssuanceAck]: IssuanceMessageType.IssuanceAck,
|
|
65
|
+
[IssuanceMessageTypeV1.ProblemReport]: IssuanceMessageType.ProblemReport,
|
|
66
|
+
[PresentationMessageTypeV1.ProposePresentation]: PresentationMessageType.ProposePresentation,
|
|
67
|
+
[PresentationMessageTypeV1.RequestPresentation]: PresentationMessageType.RequestPresentation,
|
|
68
|
+
[PresentationMessageTypeV1.PresentProof]: PresentationMessageType.PresentProof,
|
|
69
|
+
[PresentationMessageTypeV1.PresentationAck]: PresentationMessageType.PresentationAck,
|
|
70
|
+
// ProblemReport v1 already mapped via IssuanceMessageTypeV1.ProblemReport (same URI)
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const V2_TO_V1_MAP: Record<string, string> = Object.fromEntries(
|
|
74
|
+
Object.entries(V1_TO_V2_MAP).map(([k, v]) => [v, k]),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
export function detectDIDCommVersion(type: string): DIDCommVersion {
|
|
78
|
+
if (/\/1\.0\//.test(type)) return DIDCommVersion.V1;
|
|
79
|
+
return DIDCommVersion.V2;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function normalizeToV2(type: string): string {
|
|
83
|
+
return V1_TO_V2_MAP[type] || type;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function convertToVersion(type: string, target: DIDCommVersion): string {
|
|
87
|
+
if (target === DIDCommVersion.V1) {
|
|
88
|
+
return V2_TO_V1_MAP[type] || type;
|
|
89
|
+
}
|
|
90
|
+
return V1_TO_V2_MAP[type] || type;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const WACIMessageType = {
|
|
94
|
+
...SharedMessageType,
|
|
95
|
+
...IssuanceMessageType,
|
|
96
|
+
...PresentationMessageType,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// eslint-disable-next-line no-redeclare
|
|
100
|
+
export type WACIMessageType =
|
|
101
|
+
| SharedMessageType
|
|
102
|
+
| IssuanceMessageType
|
|
103
|
+
| PresentationMessageType;
|
|
104
|
+
|
|
105
|
+
export enum GoalCode {
|
|
106
|
+
Issuance = 'streamlined-vc',
|
|
107
|
+
Presentation = 'streamlined-vp',
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const enum AckStatus {
|
|
111
|
+
Ok = 'OK',
|
|
112
|
+
Fail = 'FAIL',
|
|
113
|
+
Pending = 'PENDING',
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type WACIMessage = {
|
|
117
|
+
type: WACIMessageType;
|
|
118
|
+
id: string;
|
|
119
|
+
from: string;
|
|
120
|
+
to?: string[];
|
|
121
|
+
body?: any;
|
|
122
|
+
pthid?: string;
|
|
123
|
+
thid?: string;
|
|
124
|
+
attachments?: any[];
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const enum WACIMessageResponseType {
|
|
128
|
+
CreateThread,
|
|
129
|
+
ReplyThread,
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type WACIMessageHandlerResponse = {
|
|
133
|
+
message: WACIMessage;
|
|
134
|
+
responseType: WACIMessageResponseType;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type WACIResponse = {
|
|
138
|
+
message: WACIMessage;
|
|
139
|
+
target: string;
|
|
140
|
+
responseType: WACIMessageResponseType;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export interface WACIMessageHandler {
|
|
144
|
+
handle(
|
|
145
|
+
messageThread: WACIMessage[],
|
|
146
|
+
callbacks: any,
|
|
147
|
+
): Promise<WACIMessageHandlerResponse | void>;
|
|
148
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export enum WaciErrorCode {
|
|
2
|
+
InputDescriptorError = 30
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export class WaciMessageError {
|
|
6
|
+
code: number;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
|
|
10
|
+
constructor(description?: string) { this.description = description; }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class InputDescriptorError extends WaciMessageError {
|
|
14
|
+
code = WaciErrorCode.InputDescriptorError;
|
|
15
|
+
name = "input-descriptor-not-found";
|
|
16
|
+
|
|
17
|
+
constructor(private messageError?: string) {
|
|
18
|
+
super(messageError);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|