@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,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
19
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
+
function step(op) {
|
|
22
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
+
switch (op[0]) {
|
|
27
|
+
case 0: case 1: t = op; break;
|
|
28
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
+
default:
|
|
32
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
+
if (t[2]) _.ops.pop();
|
|
37
|
+
_.trys.pop(); continue;
|
|
38
|
+
}
|
|
39
|
+
op = body.call(thisArg, _);
|
|
40
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.OfferCredentialMessageResult = exports.ProposeCredentialHandler = void 0;
|
|
46
|
+
var register_handler_decorator_1 = require("../decorators/register-handler.decorator");
|
|
47
|
+
var types_1 = require("../../types");
|
|
48
|
+
var utils_1 = require("../../utils");
|
|
49
|
+
var problem_report_1 = require("../../types/problem-report");
|
|
50
|
+
var ProposeCredentialHandler = /** @class */ (function () {
|
|
51
|
+
function ProposeCredentialHandler() {
|
|
52
|
+
}
|
|
53
|
+
ProposeCredentialHandler.prototype.handle = function (messageThread, callbacks) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var message, holderDID, issuerDID, invitationId, credentialManifestParams, credentialManifest, problemReport;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
message = messageThread[messageThread.length - 1];
|
|
60
|
+
holderDID = message.from;
|
|
61
|
+
issuerDID = message.to[0];
|
|
62
|
+
invitationId = message.pthid;
|
|
63
|
+
return [4 /*yield*/, callbacks[types_1.Actor.Issuer].getCredentialManifest({
|
|
64
|
+
invitationId: invitationId,
|
|
65
|
+
holderDid: holderDID,
|
|
66
|
+
message: message,
|
|
67
|
+
})];
|
|
68
|
+
case 1:
|
|
69
|
+
credentialManifestParams = _a.sent();
|
|
70
|
+
credentialManifestParams.result =
|
|
71
|
+
credentialManifestParams.result || OfferCredentialMessageResult.Succeded;
|
|
72
|
+
if (credentialManifestParams.result == OfferCredentialMessageResult.Succeded) {
|
|
73
|
+
credentialManifest = this.createMessage(credentialManifestParams);
|
|
74
|
+
return [2 /*return*/, {
|
|
75
|
+
responseType: 1 /* WACIMessageResponseType.ReplyThread */,
|
|
76
|
+
message: {
|
|
77
|
+
type: types_1.WACIMessageType.OfferCredential,
|
|
78
|
+
id: (0, utils_1.createUUID)(),
|
|
79
|
+
thid: message.id,
|
|
80
|
+
from: issuerDID,
|
|
81
|
+
to: [holderDID],
|
|
82
|
+
body: {},
|
|
83
|
+
attachments: credentialManifest,
|
|
84
|
+
},
|
|
85
|
+
}];
|
|
86
|
+
}
|
|
87
|
+
else if (credentialManifestParams.result == OfferCredentialMessageResult.Failed) {
|
|
88
|
+
problemReport = new problem_report_1.ProblemReportMessage();
|
|
89
|
+
return [2 /*return*/, {
|
|
90
|
+
responseType: 1 /* WACIMessageResponseType.ReplyThread */,
|
|
91
|
+
message: {
|
|
92
|
+
type: types_1.WACIMessageType.ProblemReport,
|
|
93
|
+
id: (0, utils_1.createUUID)(),
|
|
94
|
+
thid: message.id,
|
|
95
|
+
from: issuerDID,
|
|
96
|
+
to: [holderDID],
|
|
97
|
+
body: problemReport.presentProofMessage("credential_issuance_error", credentialManifestParams.errorMessage),
|
|
98
|
+
},
|
|
99
|
+
}];
|
|
100
|
+
}
|
|
101
|
+
return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
ProposeCredentialHandler.prototype.createMessage = function (params) {
|
|
107
|
+
var _a;
|
|
108
|
+
var manifestId = (0, utils_1.createUUID)();
|
|
109
|
+
var presentationDefinition = ((_a = params.input) === null || _a === void 0 ? void 0 : _a.length)
|
|
110
|
+
? {
|
|
111
|
+
id: (0, utils_1.createUUID)(),
|
|
112
|
+
input_descriptors: params.input,
|
|
113
|
+
frame: params.frame,
|
|
114
|
+
}
|
|
115
|
+
: undefined;
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
id: (0, utils_1.createUUID)(),
|
|
119
|
+
media_type: 'application/json',
|
|
120
|
+
format: 'dif/credential-manifest/manifest@v1.0',
|
|
121
|
+
data: {
|
|
122
|
+
json: {
|
|
123
|
+
options: {
|
|
124
|
+
challenge: (0, utils_1.createUUID)(),
|
|
125
|
+
},
|
|
126
|
+
credential_manifest: {
|
|
127
|
+
id: manifestId,
|
|
128
|
+
version: '0.1.0',
|
|
129
|
+
issuer: {
|
|
130
|
+
id: params.issuerDid,
|
|
131
|
+
name: params.issuerName,
|
|
132
|
+
styles: params.issuerStyles
|
|
133
|
+
},
|
|
134
|
+
presentation_definition: presentationDefinition,
|
|
135
|
+
output_descriptors: params.output.map(function (descriptors) { return descriptors.outputDescriptor; }),
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: (0, utils_1.createUUID)(),
|
|
142
|
+
media_type: 'application/json',
|
|
143
|
+
format: 'dif/credential-manifest/fulfillment@v1.0',
|
|
144
|
+
data: {
|
|
145
|
+
json: {
|
|
146
|
+
'@context': [
|
|
147
|
+
'https://extrimian.blob.core.windows.net/rskec/credentialsv1.jsonld',
|
|
148
|
+
'https://extrimian.blob.core.windows.net/rskec/credential-manifestfulfillmentv1.jsonld',
|
|
149
|
+
],
|
|
150
|
+
type: ['VerifiablePresentation', 'CredentialFulfillment'],
|
|
151
|
+
credential_fulfillment: {
|
|
152
|
+
id: (0, utils_1.createUUID)(),
|
|
153
|
+
manifest_id: manifestId,
|
|
154
|
+
descriptor_map: params.output.map(function (descriptor, index) {
|
|
155
|
+
return {
|
|
156
|
+
id: descriptor.outputDescriptor.id,
|
|
157
|
+
format: descriptor.format || 'ldp_vp',
|
|
158
|
+
path: "$.verifiableCredential[".concat(index, "]"),
|
|
159
|
+
};
|
|
160
|
+
}),
|
|
161
|
+
},
|
|
162
|
+
verifiableCredential: params.output.map(function (vcData) { return vcData.verifiableCredential; }),
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
};
|
|
168
|
+
ProposeCredentialHandler = __decorate([
|
|
169
|
+
(0, register_handler_decorator_1.RegisterHandler)(types_1.Actor.Issuer, types_1.WACIMessageType.ProposeCredential)
|
|
170
|
+
], ProposeCredentialHandler);
|
|
171
|
+
return ProposeCredentialHandler;
|
|
172
|
+
}());
|
|
173
|
+
exports.ProposeCredentialHandler = ProposeCredentialHandler;
|
|
174
|
+
var OfferCredentialMessageResult;
|
|
175
|
+
(function (OfferCredentialMessageResult) {
|
|
176
|
+
OfferCredentialMessageResult[OfferCredentialMessageResult["Succeded"] = 0] = "Succeded";
|
|
177
|
+
OfferCredentialMessageResult[OfferCredentialMessageResult["Failed"] = 1] = "Failed";
|
|
178
|
+
OfferCredentialMessageResult[OfferCredentialMessageResult["AsyncProcess"] = 2] = "AsyncProcess";
|
|
179
|
+
})(OfferCredentialMessageResult = exports.OfferCredentialMessageResult || (exports.OfferCredentialMessageResult = {}));
|
|
180
|
+
//# sourceMappingURL=step-3-propose-credential.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-3-propose-credential.handler.js","sourceRoot":"","sources":["../../../src/handlers/issuance/step-3-propose-credential.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uFAA2E;AAC3E,qCAaqB;AACrB,qCAAyC;AACzC,6DAAkE;AAiClE;IAAA;IAkIA,CAAC;IAjIO,yCAAM,GAAZ,UACE,aAA4B,EAC5B,SAAc;;;;;;wBAER,OAAO,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;wBAClD,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;wBACzB,SAAS,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;wBAC1B,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;wBACF,qBAAM,SAAS,CAC9C,aAAK,CAAC,MAAM,CACb,CAAC,qBAAqB,CAAC;gCACtB,YAAY,EAAE,YAAY;gCAC1B,SAAS,EAAE,SAAS;gCACpB,OAAO,SAAA;6BACR,CAAC,EAAA;;wBANI,wBAAwB,GAAG,SAM/B;wBAEF,wBAAwB,CAAC,MAAM;4BAC7B,wBAAwB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yBACH;wBACD,oBAAoB,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CACrC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,oBAAoB,EAA3B,CAA2B,CACxC;qBACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAjIU,wBAAwB;QADpC,IAAA,4CAAe,EAAC,aAAK,CAAC,MAAM,EAAE,uBAAe,CAAC,iBAAiB,CAAC;OACpD,wBAAwB,CAkIpC;IAAD,+BAAC;CAAA,AAlID,IAkIC;AAlIY,4DAAwB;AAoIrC,IAAY,4BAIX;AAJD,WAAY,4BAA4B;IACtC,uFAAQ,CAAA;IACR,mFAAM,CAAA;IACN,+FAAY,CAAA;AACd,CAAC,EAJW,4BAA4B,GAA5B,oCAA4B,KAA5B,oCAA4B,QAIvC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { WACIMessage, WACIMessageHandlerResponse } from '../../types';
|
|
2
|
+
export declare class OfferCredentialProceed {
|
|
3
|
+
static handle(messageThread: WACIMessage[], credentialsToPresent: any[], presentationProofTypes: string[], callbacks: any): Promise<WACIMessageHandlerResponse>;
|
|
4
|
+
private static createMessage;
|
|
5
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.OfferCredentialProceed = void 0;
|
|
40
|
+
var types_1 = require("../../types");
|
|
41
|
+
var utils_1 = require("../../utils");
|
|
42
|
+
var lodash_1 = require("lodash");
|
|
43
|
+
var OfferCredentialProceed = /** @class */ (function () {
|
|
44
|
+
function OfferCredentialProceed() {
|
|
45
|
+
}
|
|
46
|
+
OfferCredentialProceed.handle = function (messageThread, credentialsToPresent, presentationProofTypes, callbacks) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
var message, holderDID, issuerDID, credentialApplicationParams, credentialApplication;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
message = messageThread[messageThread.length - 1];
|
|
53
|
+
holderDID = message.to[0];
|
|
54
|
+
issuerDID = message.from;
|
|
55
|
+
credentialApplicationParams = {
|
|
56
|
+
manifest: message.attachments.find(function (attachment) { var _a, _b; return !(0, lodash_1.isNil)((_b = (_a = attachment === null || attachment === void 0 ? void 0 : attachment.data) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.credential_manifest); }),
|
|
57
|
+
fulfillment: message.attachments.find(function (attachment) { var _a, _b; return !(0, lodash_1.isNil)((_b = (_a = attachment === null || attachment === void 0 ? void 0 : attachment.data) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.credential_fulfillment); }),
|
|
58
|
+
message: message
|
|
59
|
+
};
|
|
60
|
+
if (!credentialApplicationParams.manifest)
|
|
61
|
+
throw new Error('Malformed offer credential message');
|
|
62
|
+
return [4 /*yield*/, this.createMessage(credentialsToPresent, presentationProofTypes, credentialApplicationParams.manifest, message, callbacks)];
|
|
63
|
+
case 1:
|
|
64
|
+
credentialApplication = _a.sent();
|
|
65
|
+
return [2 /*return*/, {
|
|
66
|
+
responseType: 1 /* WACIMessageResponseType.ReplyThread */,
|
|
67
|
+
message: {
|
|
68
|
+
type: types_1.WACIMessageType.RequestCredential,
|
|
69
|
+
id: (0, utils_1.createUUID)(),
|
|
70
|
+
thid: message.thid,
|
|
71
|
+
from: holderDID,
|
|
72
|
+
to: [issuerDID],
|
|
73
|
+
body: {},
|
|
74
|
+
attachments: credentialApplication ? [credentialApplication] : [],
|
|
75
|
+
},
|
|
76
|
+
}];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
OfferCredentialProceed.createMessage = function (verifiableCredential, proofTypes, manifest, message, callbacks) {
|
|
82
|
+
var _a, _b, _c, _d, _e;
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var credential_manifest, manifest_id, presentation_definition, definition_id, input_descriptors, challenge, descriptor_map, messageData, signedData;
|
|
85
|
+
return __generator(this, function (_f) {
|
|
86
|
+
switch (_f.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
credential_manifest = (_b = (_a = manifest === null || manifest === void 0 ? void 0 : manifest.data) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.credential_manifest;
|
|
89
|
+
manifest_id = credential_manifest === null || credential_manifest === void 0 ? void 0 : credential_manifest.id;
|
|
90
|
+
presentation_definition = credential_manifest === null || credential_manifest === void 0 ? void 0 : credential_manifest.presentation_definition;
|
|
91
|
+
definition_id = presentation_definition === null || presentation_definition === void 0 ? void 0 : presentation_definition.id;
|
|
92
|
+
input_descriptors = presentation_definition === null || presentation_definition === void 0 ? void 0 : presentation_definition.input_descriptors;
|
|
93
|
+
challenge = (_e = (_d = (_c = manifest === null || manifest === void 0 ? void 0 : manifest.data) === null || _c === void 0 ? void 0 : _c.json) === null || _d === void 0 ? void 0 : _d.options) === null || _e === void 0 ? void 0 : _e.challenge;
|
|
94
|
+
if (!challenge)
|
|
95
|
+
throw new Error('No challenge defined');
|
|
96
|
+
if (!(input_descriptors === null || input_descriptors === void 0 ? void 0 : input_descriptors.length))
|
|
97
|
+
return [2 /*return*/];
|
|
98
|
+
descriptor_map = input_descriptors === null || input_descriptors === void 0 ? void 0 : input_descriptors.map(function (descriptor, index) { return ({
|
|
99
|
+
id: descriptor.id,
|
|
100
|
+
format: 'ldp_vp',
|
|
101
|
+
path: "$.verifiableCredential[".concat(index, "]"),
|
|
102
|
+
}); });
|
|
103
|
+
if (!(proofTypes === null || proofTypes === void 0 ? void 0 : proofTypes.length))
|
|
104
|
+
throw new Error('Proof types need to be defined');
|
|
105
|
+
if (!manifest_id)
|
|
106
|
+
throw new Error('Malformed credential manifest');
|
|
107
|
+
messageData = {
|
|
108
|
+
'@context': [
|
|
109
|
+
'https://extrimian.blob.core.windows.net/rskec/securityv1.jsonld',
|
|
110
|
+
'https://extrimian.blob.core.windows.net/rskec/credentialsv1.jsonld',
|
|
111
|
+
'https://extrimian.blob.core.windows.net/rskec/credential-manifestapplicationv1.jsonld',
|
|
112
|
+
],
|
|
113
|
+
type: ['VerifiablePresentation', 'CredentialApplication'],
|
|
114
|
+
credential_application: {
|
|
115
|
+
id: (0, utils_1.createUUID)(),
|
|
116
|
+
manifest_id: manifest_id,
|
|
117
|
+
format: {
|
|
118
|
+
ldp_vc: {
|
|
119
|
+
proof_type: proofTypes,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
presentation_submission: {
|
|
124
|
+
id: (0, utils_1.createUUID)(),
|
|
125
|
+
definition_id: definition_id,
|
|
126
|
+
descriptor_map: descriptor_map,
|
|
127
|
+
},
|
|
128
|
+
verifiableCredential: verifiableCredential,
|
|
129
|
+
};
|
|
130
|
+
return [4 /*yield*/, callbacks[types_1.Actor.Holder].signPresentation({
|
|
131
|
+
contentToSign: messageData,
|
|
132
|
+
challenge: challenge,
|
|
133
|
+
message: message
|
|
134
|
+
})];
|
|
135
|
+
case 1:
|
|
136
|
+
signedData = _f.sent();
|
|
137
|
+
return [2 /*return*/, {
|
|
138
|
+
id: (0, utils_1.createUUID)(),
|
|
139
|
+
media_type: 'application/json',
|
|
140
|
+
format: 'dif/credential-manifest/application@v1.0',
|
|
141
|
+
data: {
|
|
142
|
+
json: signedData,
|
|
143
|
+
},
|
|
144
|
+
}];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
return OfferCredentialProceed;
|
|
150
|
+
}());
|
|
151
|
+
exports.OfferCredentialProceed = OfferCredentialProceed;
|
|
152
|
+
//# sourceMappingURL=step-4-1-offer-credential-proceed.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-4-1-offer-credential-proceed.handler.js","sourceRoot":"","sources":["../../../src/handlers/issuance/step-4-1-offer-credential-proceed.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAUqB;AACrB,qCAAyC;AACzC,iCAA+B;AAE/B;IAAA;IAiHA,CAAC;IAhHc,6BAAM,GAAnB,UACE,aAA4B,EAC5B,oBAA2B,EAC3B,sBAAgC,EAChC,SAAc;;;;;;wBAER,OAAO,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;wBAClD,SAAS,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;wBAC1B,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;wBAEzB,2BAA2B,GAAG;4BAClC,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAChC,UAAC,UAAU,gBAAK,OAAA,CAAC,IAAA,cAAK,EAAC,MAAA,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,0CAAE,IAAI,0CAAE,mBAAmB,CAAC,CAAA,EAAA,CAC9C;4BACvB,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CACnC,UAAC,UAAU,gBAAK,OAAA,CAAC,IAAA,cAAK,EAAC,MAAA,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,0CAAE,IAAI,0CAAE,sBAAsB,C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AC,MAAM,CAAC,CAAC,gBAAgB,CAAC;gCAChE,aAAa,EAAE,WAAW;gCAC1B,SAAS,WAAA;gCACT,OAAO,SAAA;6BACR,CAAC,EAAA;;wBAJI,UAAU,GAAG,SAIjB;wBAEF,sBAAO;gCACL,EAAE,EAAE,IAAA,kBAAU,GAAE;gCAChB,UAAU,EAAE,kBAAkB;gCAC9B,MAAM,EAAE,0CAA0C;gCAClD,IAAI,EAAE;oCACJ,IAAI,EAAE,UAAU;iCACjB;6BACuB,EAAC;;;;KAC5B;IACH,6BAAC;AAAD,CAAC,AAjHD,IAiHC;AAjHY,wDAAsB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { WACIMessage, WACIMessageHandler, WACIMessageHandlerResponse } from '../../types';
|
|
2
|
+
export declare class OfferCredentialHandler implements WACIMessageHandler {
|
|
3
|
+
handle(messageThread: WACIMessage[], callbacks: any): Promise<WACIMessageHandlerResponse>;
|
|
4
|
+
private createMessage;
|
|
5
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
19
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
+
function step(op) {
|
|
22
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
+
switch (op[0]) {
|
|
27
|
+
case 0: case 1: t = op; break;
|
|
28
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
+
default:
|
|
32
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
+
if (t[2]) _.ops.pop();
|
|
37
|
+
_.trys.pop(); continue;
|
|
38
|
+
}
|
|
39
|
+
op = body.call(thisArg, _);
|
|
40
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.OfferCredentialHandler = void 0;
|
|
46
|
+
var register_handler_decorator_1 = require("../decorators/register-handler.decorator");
|
|
47
|
+
var types_1 = require("../../types");
|
|
48
|
+
var utils_1 = require("../../utils");
|
|
49
|
+
var callbacks_1 = require("../../callbacks");
|
|
50
|
+
var lodash_1 = require("lodash");
|
|
51
|
+
var OfferCredentialHandler = /** @class */ (function () {
|
|
52
|
+
function OfferCredentialHandler() {
|
|
53
|
+
}
|
|
54
|
+
OfferCredentialHandler.prototype.handle = function (messageThread, callbacks) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var message, holderDID, issuerDID, credentialApplicationParams, response, credentialApplication;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
message = messageThread[messageThread.length - 1];
|
|
61
|
+
holderDID = message.to[0];
|
|
62
|
+
issuerDID = message.from;
|
|
63
|
+
credentialApplicationParams = {
|
|
64
|
+
manifest: message.attachments.find(function (attachment) { var _a, _b; return !(0, lodash_1.isNil)((_b = (_a = attachment === null || attachment === void 0 ? void 0 : attachment.data) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.credential_manifest); }),
|
|
65
|
+
fulfillment: message.attachments.find(function (attachment) { var _a, _b; return !(0, lodash_1.isNil)((_b = (_a = attachment === null || attachment === void 0 ? void 0 : attachment.data) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.credential_fulfillment); }),
|
|
66
|
+
message: message
|
|
67
|
+
};
|
|
68
|
+
if (!credentialApplicationParams.manifest)
|
|
69
|
+
throw new Error('Malformed offer credential message');
|
|
70
|
+
return [4 /*yield*/, callbacks[types_1.Actor.Holder].getCredentialApplication(credentialApplicationParams)];
|
|
71
|
+
case 1:
|
|
72
|
+
response = _a.sent();
|
|
73
|
+
if (response == callbacks_1.CredentialPresentationResponse.AsyncProcess) {
|
|
74
|
+
return [2 /*return*/];
|
|
75
|
+
}
|
|
76
|
+
return [4 /*yield*/, this.createMessage(response.credentialsToPresent, response.presentationProofTypes, credentialApplicationParams.manifest, message, callbacks)];
|
|
77
|
+
case 2:
|
|
78
|
+
credentialApplication = _a.sent();
|
|
79
|
+
return [2 /*return*/, {
|
|
80
|
+
responseType: 1 /* WACIMessageResponseType.ReplyThread */,
|
|
81
|
+
message: {
|
|
82
|
+
type: types_1.WACIMessageType.RequestCredential,
|
|
83
|
+
id: (0, utils_1.createUUID)(),
|
|
84
|
+
thid: message.thid,
|
|
85
|
+
from: holderDID,
|
|
86
|
+
to: [issuerDID],
|
|
87
|
+
body: {},
|
|
88
|
+
attachments: credentialApplication ? [credentialApplication] : [],
|
|
89
|
+
},
|
|
90
|
+
}];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
OfferCredentialHandler.prototype.createMessage = function (verifiableCredential, proofTypes, manifest, message, callbacks) {
|
|
96
|
+
var _a, _b, _c, _d, _e;
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var credential_manifest, manifest_id, presentation_definition, definition_id, input_descriptors, challenge, descriptor_map, messageData, signedData;
|
|
99
|
+
return __generator(this, function (_f) {
|
|
100
|
+
switch (_f.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
credential_manifest = (_b = (_a = manifest === null || manifest === void 0 ? void 0 : manifest.data) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.credential_manifest;
|
|
103
|
+
manifest_id = credential_manifest === null || credential_manifest === void 0 ? void 0 : credential_manifest.id;
|
|
104
|
+
presentation_definition = credential_manifest === null || credential_manifest === void 0 ? void 0 : credential_manifest.presentation_definition;
|
|
105
|
+
definition_id = presentation_definition === null || presentation_definition === void 0 ? void 0 : presentation_definition.id;
|
|
106
|
+
input_descriptors = presentation_definition === null || presentation_definition === void 0 ? void 0 : presentation_definition.input_descriptors;
|
|
107
|
+
challenge = (_e = (_d = (_c = manifest === null || manifest === void 0 ? void 0 : manifest.data) === null || _c === void 0 ? void 0 : _c.json) === null || _d === void 0 ? void 0 : _d.options) === null || _e === void 0 ? void 0 : _e.challenge;
|
|
108
|
+
if (!challenge)
|
|
109
|
+
throw new Error('No challenge defined');
|
|
110
|
+
if (!(input_descriptors === null || input_descriptors === void 0 ? void 0 : input_descriptors.length))
|
|
111
|
+
return [2 /*return*/];
|
|
112
|
+
descriptor_map = input_descriptors === null || input_descriptors === void 0 ? void 0 : input_descriptors.map(function (descriptor, index) { return ({
|
|
113
|
+
id: descriptor.id,
|
|
114
|
+
format: 'ldp_vp',
|
|
115
|
+
path: "$.verifiableCredential[".concat(index, "]"),
|
|
116
|
+
}); });
|
|
117
|
+
if (!(proofTypes === null || proofTypes === void 0 ? void 0 : proofTypes.length))
|
|
118
|
+
throw new Error('Proof types need to be defined');
|
|
119
|
+
if (!manifest_id)
|
|
120
|
+
throw new Error('Malformed credential manifest');
|
|
121
|
+
messageData = {
|
|
122
|
+
'@context': [
|
|
123
|
+
'https://extrimian.blob.core.windows.net/rskec/securityv1.jsonld',
|
|
124
|
+
'https://extrimian.blob.core.windows.net/rskec/credentialsv1.jsonld',
|
|
125
|
+
'https://extrimian.blob.core.windows.net/rskec/credential-manifestapplicationv1.jsonld',
|
|
126
|
+
],
|
|
127
|
+
type: ['VerifiablePresentation', 'CredentialApplication'],
|
|
128
|
+
credential_application: {
|
|
129
|
+
id: (0, utils_1.createUUID)(),
|
|
130
|
+
manifest_id: manifest_id,
|
|
131
|
+
format: {
|
|
132
|
+
ldp_vc: {
|
|
133
|
+
proof_type: proofTypes,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
presentation_submission: {
|
|
138
|
+
id: (0, utils_1.createUUID)(),
|
|
139
|
+
definition_id: definition_id,
|
|
140
|
+
descriptor_map: descriptor_map,
|
|
141
|
+
},
|
|
142
|
+
verifiableCredential: verifiableCredential,
|
|
143
|
+
};
|
|
144
|
+
return [4 /*yield*/, callbacks[types_1.Actor.Holder].signPresentation({
|
|
145
|
+
contentToSign: messageData,
|
|
146
|
+
challenge: challenge,
|
|
147
|
+
message: message
|
|
148
|
+
})];
|
|
149
|
+
case 1:
|
|
150
|
+
signedData = _f.sent();
|
|
151
|
+
return [2 /*return*/, {
|
|
152
|
+
id: (0, utils_1.createUUID)(),
|
|
153
|
+
media_type: 'application/json',
|
|
154
|
+
format: 'dif/credential-manifest/application@v1.0',
|
|
155
|
+
data: {
|
|
156
|
+
json: signedData,
|
|
157
|
+
},
|
|
158
|
+
}];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
OfferCredentialHandler = __decorate([
|
|
164
|
+
(0, register_handler_decorator_1.RegisterHandler)(types_1.Actor.Holder, types_1.WACIMessageType.OfferCredential)
|
|
165
|
+
], OfferCredentialHandler);
|
|
166
|
+
return OfferCredentialHandler;
|
|
167
|
+
}());
|
|
168
|
+
exports.OfferCredentialHandler = OfferCredentialHandler;
|
|
169
|
+
//# sourceMappingURL=step-4-offer-credential.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-4-offer-credential.handler.js","sourceRoot":"","sources":["../../../src/handlers/issuance/step-4-offer-credential.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uFAA2E;AAC3E,qCAUqB;AACrB,qCAAyC;AACzC,6CAAiE;AACjE,iCAA+B;AAG/B;IAAA;IAuHA,CAAC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QADlC,IAAA,4CAAe,EAAC,aAAK,CAAC,MAAM,EAAE,uBAAe,CAAC,eAAe,CAAC;OAClD,sBAAsB,CAuHlC;IAAD,6BAAC;CAAA,AAvHD,IAuHC;AAvHY,wDAAsB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { WACIMessage, WACIMessageHandler, WACIMessageHandlerResponse } from '../../types';
|
|
2
|
+
export declare class RequestCredentialHandler implements WACIMessageHandler {
|
|
3
|
+
handle(messageThread: WACIMessage[], callbacks: any): Promise<WACIMessageHandlerResponse | void>;
|
|
4
|
+
}
|