@docknetwork/wallet-sdk-relay-service 1.7.0 → 1.7.6

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/lib/didcomm.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as _asyncToGenerator, a as _regeneratorRuntime, b as _toConsumableArray, c as _objectSpread2 } from './_rollupPluginBabelHelpers-ea876378.js';
1
+ import { _ as _asyncToGenerator, a as _regenerator, b as _toConsumableArray, c as _objectSpread2 } from './_rollupPluginBabelHelpers-85237803.js';
2
2
  import { X25519KeyAgreementKey2020 } from '@digitalbazaar/x25519-key-agreement-key-2020';
3
3
  import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020';
4
4
  import { Cipher } from '@docknetwork/minimal-cipher';
@@ -28,23 +28,20 @@ function getKeydocFromDID(_x) {
28
28
  return _getKeydocFromDID.apply(this, arguments);
29
29
  }
30
30
  function _getKeydocFromDID() {
31
- _getKeydocFromDID = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(didUrl) {
31
+ _getKeydocFromDID = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(didUrl) {
32
32
  var didDocument, possibleKeys, keyDoc;
33
- return _regeneratorRuntime().wrap(function _callee$(_context) {
34
- while (1) switch (_context.prev = _context.next) {
33
+ return _regenerator().w(function (_context) {
34
+ while (1) switch (_context.n) {
35
35
  case 0:
36
- _context.next = 2;
36
+ _context.n = 1;
37
37
  return blockchainService.resolver.resolve(didUrl);
38
- case 2:
39
- didDocument = _context.sent;
38
+ case 1:
39
+ didDocument = _context.v;
40
40
  possibleKeys = [].concat(_toConsumableArray(potentialToArray(didDocument.verificationMethod)), _toConsumableArray(potentialToArray(didDocument.keyAgreement)), _toConsumableArray(potentialToArray(didDocument.publicKey)));
41
41
  keyDoc = possibleKeys.filter(function (key) {
42
42
  return key.id === didUrl;
43
43
  })[0];
44
- return _context.abrupt("return", keyDoc);
45
- case 6:
46
- case "end":
47
- return _context.stop();
44
+ return _context.a(2, keyDoc);
48
45
  }
49
46
  }, _callee);
50
47
  }));
@@ -58,29 +55,26 @@ function defaultKaKResolver(_x2) {
58
55
  return _defaultKaKResolver.apply(this, arguments);
59
56
  }
60
57
  function _defaultKaKResolver() {
61
- _defaultKaKResolver = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(keyId) {
58
+ _defaultKaKResolver = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(keyId) {
62
59
  var keyIdStr, keyDoc;
63
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
64
- while (1) switch (_context2.prev = _context2.next) {
60
+ return _regenerator().w(function (_context2) {
61
+ while (1) switch (_context2.n) {
65
62
  case 0:
66
63
  keyIdStr = keyId.id || keyId;
67
- _context2.next = 3;
64
+ _context2.n = 1;
68
65
  return getAgreementKeydocFromDID(keyIdStr);
69
- case 3:
70
- keyDoc = _context2.sent;
66
+ case 1:
67
+ keyDoc = _context2.v;
71
68
  if (keyDoc) {
72
- _context2.next = 6;
69
+ _context2.n = 2;
73
70
  break;
74
71
  }
75
72
  throw new Error("Cannot find key document with ID: ".concat(keyIdStr));
76
- case 6:
77
- _context2.next = 8;
73
+ case 2:
74
+ _context2.n = 3;
78
75
  return getKaKInstanceFromDocument(keyDoc);
79
- case 8:
80
- return _context2.abrupt("return", _context2.sent);
81
- case 9:
82
- case "end":
83
- return _context2.stop();
76
+ case 3:
77
+ return _context2.a(2, _context2.v);
84
78
  }
85
79
  }, _callee2);
86
80
  }));
@@ -90,31 +84,28 @@ function defaultVerificationKeyResolver(_x3) {
90
84
  return _defaultVerificationKeyResolver.apply(this, arguments);
91
85
  }
92
86
  function _defaultVerificationKeyResolver() {
93
- _defaultVerificationKeyResolver = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(keyId) {
87
+ _defaultVerificationKeyResolver = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(keyId) {
94
88
  var keyIdStr, keyDoc;
95
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
96
- while (1) switch (_context3.prev = _context3.next) {
89
+ return _regenerator().w(function (_context3) {
90
+ while (1) switch (_context3.n) {
97
91
  case 0:
98
92
  keyIdStr = keyId.id || keyId;
99
- _context3.next = 3;
93
+ _context3.n = 1;
100
94
  return getKeydocFromDID(keyIdStr);
101
- case 3:
102
- keyDoc = _context3.sent;
95
+ case 1:
96
+ keyDoc = _context3.v;
103
97
  if (keyDoc) {
104
- _context3.next = 6;
98
+ _context3.n = 2;
105
99
  break;
106
100
  }
107
101
  throw new Error("Cannot find key document with ID: ".concat(keyIdStr));
108
- case 6:
109
- _context3.next = 8;
102
+ case 2:
103
+ _context3.n = 3;
110
104
  return Ed25519VerificationKey2020.from(_objectSpread2(_objectSpread2({}, keyDoc), {}, {
111
105
  keyPair: keyDoc
112
106
  }));
113
- case 8:
114
- return _context3.abrupt("return", _context3.sent);
115
- case 9:
116
- case "end":
117
- return _context3.stop();
107
+ case 3:
108
+ return _context3.a(2, _context3.v);
118
109
  }
119
110
  }, _callee3);
120
111
  }));
@@ -124,7 +115,7 @@ function didcommCreateSignedJWT(_x4, _x5) {
124
115
  return _didcommCreateSignedJWT.apply(this, arguments);
125
116
  }
126
117
  function _didcommCreateSignedJWT() {
127
- _didcommCreateSignedJWT = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(payload, privateKeyDoc) {
118
+ _didcommCreateSignedJWT = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(payload, privateKeyDoc) {
128
119
  var generateJWK,
129
120
  privateKey,
130
121
  _privateKey$signer,
@@ -138,16 +129,16 @@ function _didcommCreateSignedJWT() {
138
129
  signPayload,
139
130
  signature,
140
131
  _args4 = arguments;
141
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
142
- while (1) switch (_context4.prev = _context4.next) {
132
+ return _regenerator().w(function (_context4) {
133
+ while (1) switch (_context4.n) {
143
134
  case 0:
144
135
  generateJWK = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : false;
145
- _context4.next = 3;
136
+ _context4.n = 1;
146
137
  return Ed25519VerificationKey2020.from(_objectSpread2(_objectSpread2({}, privateKeyDoc), {}, {
147
138
  keyPair: privateKeyDoc
148
139
  }));
149
- case 3:
150
- privateKey = _context4.sent;
140
+ case 1:
141
+ privateKey = _context4.v;
151
142
  _privateKey$signer = privateKey.signer(), sign = _privateKey$signer.sign;
152
143
  header = {
153
144
  alg: 'EdDSA',
@@ -161,16 +152,13 @@ function _didcommCreateSignedJWT() {
161
152
  payloadBase64URL = base64url(JSON.stringify(newPayload));
162
153
  headerAndPayloadBase64URL = "".concat(headerBase64URL, ".").concat(payloadBase64URL);
163
154
  signPayload = Buffer.from(headerAndPayloadBase64URL);
164
- _context4.next = 14;
155
+ _context4.n = 2;
165
156
  return sign({
166
157
  data: signPayload
167
158
  });
168
- case 14:
169
- signature = _context4.sent;
170
- return _context4.abrupt("return", "".concat(headerAndPayloadBase64URL, ".").concat(base64url.encode(signature)));
171
- case 16:
172
- case "end":
173
- return _context4.stop();
159
+ case 2:
160
+ signature = _context4.v;
161
+ return _context4.a(2, "".concat(headerAndPayloadBase64URL, ".").concat(base64url.encode(signature)));
174
162
  }
175
163
  }, _callee4);
176
164
  }));
@@ -180,136 +168,126 @@ function didcommDecodeSignedJWT(_x6, _x7) {
180
168
  return _didcommDecodeSignedJWT.apply(this, arguments);
181
169
  }
182
170
  function _didcommDecodeSignedJWT() {
183
- _didcommDecodeSignedJWT = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(jwt, keyResolver) {
171
+ _didcommDecodeSignedJWT = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(jwt, keyResolver) {
184
172
  var resolveKey, jwtSplit, header, alg, keyId, publicKey, _publicKey$verifier, verify, signature, signPayload, isVerified, body;
185
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
186
- while (1) switch (_context5.prev = _context5.next) {
173
+ return _regenerator().w(function (_context5) {
174
+ while (1) switch (_context5.n) {
187
175
  case 0:
188
176
  resolveKey = keyResolver || defaultVerificationKeyResolver;
189
177
  jwtSplit = jwt.split('.').map(function (s) {
190
178
  return s.trim();
191
179
  });
192
180
  if (!(jwtSplit.length !== 3)) {
193
- _context5.next = 4;
181
+ _context5.n = 1;
194
182
  break;
195
183
  }
196
184
  throw new Error("Malformed JWT, got split length: ".concat(jwtSplit.length));
197
- case 4:
185
+ case 1:
198
186
  header = JSON.parse(base64url.decode(jwtSplit[0]));
199
187
  alg = header.alg, keyId = header.kid;
200
188
  if (!(!alg || !keyId)) {
201
- _context5.next = 8;
189
+ _context5.n = 2;
202
190
  break;
203
191
  }
204
192
  throw new Error('Malformed JWT header, expected alg and kid');
205
- case 8:
206
- _context5.next = 10;
193
+ case 2:
194
+ _context5.n = 3;
207
195
  return resolveKey(keyId);
208
- case 10:
209
- publicKey = _context5.sent;
196
+ case 3:
197
+ publicKey = _context5.v;
210
198
  _publicKey$verifier = publicKey.verifier(), verify = _publicKey$verifier.verify;
211
199
  signature = decodeBase64Url(jwtSplit[2]);
212
200
  signPayload = Buffer.from("".concat(jwtSplit[0], ".").concat(jwtSplit[1]));
213
- _context5.next = 16;
201
+ _context5.n = 4;
214
202
  return verify({
215
203
  data: signPayload,
216
204
  signature: signature
217
205
  });
218
- case 16:
219
- isVerified = _context5.sent;
206
+ case 4:
207
+ isVerified = _context5.v;
220
208
  if (isVerified) {
221
- _context5.next = 19;
209
+ _context5.n = 5;
222
210
  break;
223
211
  }
224
212
  throw new Error('JWT cannot be verified');
225
- case 19:
213
+ case 5:
226
214
  body = JSON.parse(base64url.decode(jwtSplit[1]));
227
- return _context5.abrupt("return", body);
228
- case 21:
229
- case "end":
230
- return _context5.stop();
215
+ return _context5.a(2, body);
231
216
  }
232
217
  }, _callee5);
233
218
  }));
234
219
  return _didcommDecodeSignedJWT.apply(this, arguments);
235
220
  }
236
- function didcommEncrypt(_x8, _x9, _x10, _x11) {
221
+ function didcommEncrypt(_x8, _x9, _x0, _x1) {
237
222
  return _didcommEncrypt.apply(this, arguments);
238
223
  }
239
224
  function _didcommEncrypt() {
240
- _didcommEncrypt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(obj, recipients, keyResolver, senderKey) {
225
+ _didcommEncrypt = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(obj, recipients, keyResolver, senderKey) {
241
226
  var keyAgreementKey, encryptedJWE;
242
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
243
- while (1) switch (_context6.prev = _context6.next) {
227
+ return _regenerator().w(function (_context6) {
228
+ while (1) switch (_context6.n) {
244
229
  case 0:
245
230
  // If ed25519 is supplied, derive X25519 from it
246
231
  keyAgreementKey = senderKey;
247
232
  if (!(senderKey.type !== 'X25519KeyAgreementKey2020')) {
248
- _context6.next = 5;
233
+ _context6.n = 2;
249
234
  break;
250
235
  }
251
- _context6.next = 4;
236
+ _context6.n = 1;
252
237
  return getDerivedAgreementKey(senderKey);
253
- case 4:
254
- keyAgreementKey = _context6.sent;
255
- case 5:
256
- _context6.next = 7;
238
+ case 1:
239
+ keyAgreementKey = _context6.v;
240
+ case 2:
241
+ _context6.n = 3;
257
242
  return cipher.encryptObject({
258
243
  obj: obj,
259
244
  recipients: recipients,
260
245
  keyResolver: keyResolver || defaultKaKResolver,
261
246
  keyAgreementKey: keyAgreementKey
262
247
  });
263
- case 7:
264
- encryptedJWE = _context6.sent;
265
- return _context6.abrupt("return", _objectSpread2({
248
+ case 3:
249
+ encryptedJWE = _context6.v;
250
+ return _context6.a(2, _objectSpread2({
266
251
  typ: 'application/didcomm-encrypted+json'
267
252
  }, encryptedJWE));
268
- case 9:
269
- case "end":
270
- return _context6.stop();
271
253
  }
272
254
  }, _callee6);
273
255
  }));
274
256
  return _didcommEncrypt.apply(this, arguments);
275
257
  }
276
- function didcommDecrypt(_x12, _x13, _x14) {
258
+ function didcommDecrypt(_x10, _x11, _x12) {
277
259
  return _didcommDecrypt.apply(this, arguments);
278
260
  }
279
261
  function _didcommDecrypt() {
280
- _didcommDecrypt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(jwe, keyAgreementKey, keyResolver) {
281
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
282
- while (1) switch (_context7.prev = _context7.next) {
262
+ _didcommDecrypt = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(jwe, keyAgreementKey, keyResolver) {
263
+ return _regenerator().w(function (_context7) {
264
+ while (1) switch (_context7.n) {
283
265
  case 0:
284
- return _context7.abrupt("return", cipher.decryptObject({
266
+ return _context7.a(2, cipher.decryptObject({
285
267
  jwe: jwe,
286
268
  keyAgreementKey: keyAgreementKey,
287
269
  keyResolver: keyResolver || defaultKaKResolver
288
270
  }));
289
- case 1:
290
- case "end":
291
- return _context7.stop();
292
271
  }
293
272
  }, _callee7);
294
273
  }));
295
274
  return _didcommDecrypt.apply(this, arguments);
296
275
  }
297
- function didcommSendMessage(_x15, _x16) {
276
+ function didcommSendMessage(_x13, _x14) {
298
277
  return _didcommSendMessage.apply(this, arguments);
299
278
  }
300
279
  function _didcommSendMessage() {
301
- _didcommSendMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(to, message) {
302
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
303
- while (1) switch (_context8.prev = _context8.next) {
280
+ _didcommSendMessage = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(to, message) {
281
+ return _regenerator().w(function (_context8) {
282
+ while (1) switch (_context8.n) {
304
283
  case 0:
305
284
  if (!(!message.typ || !message.typ.startsWith('application/didcomm'))) {
306
- _context8.next = 2;
285
+ _context8.n = 1;
307
286
  break;
308
287
  }
309
288
  throw new Error('Only DIDComm messages can be sent with this service');
310
- case 2:
311
- case "end":
312
- return _context8.stop();
289
+ case 1:
290
+ return _context8.a(2);
313
291
  }
314
292
  }, _callee8);
315
293
  }));
@@ -324,69 +302,68 @@ function isDerivableKey(keyDoc) {
324
302
  function getDIDKeydocsFromDIDDocument(didDocument) {
325
303
  return [].concat(_toConsumableArray(potentialToArray(didDocument.verificationMethod)), _toConsumableArray(potentialToArray(didDocument.keyAgreement)), _toConsumableArray(potentialToArray(didDocument.publicKey)));
326
304
  }
327
- function getAgreementKeydocFromDID(_x17) {
305
+ function getAgreementKeydocFromDID(_x15) {
328
306
  return _getAgreementKeydocFromDID.apply(this, arguments);
329
307
  }
330
308
  function _getAgreementKeydocFromDID() {
331
- _getAgreementKeydocFromDID = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(did) {
309
+ _getAgreementKeydocFromDID = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(did) {
332
310
  var isDIDUrl, didDocument, keyAgreements, foundDoc, firstKeyAgreement, publicKeys, derivableKey;
333
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
334
- while (1) switch (_context9.prev = _context9.next) {
311
+ return _regenerator().w(function (_context9) {
312
+ while (1) switch (_context9.n) {
335
313
  case 0:
336
314
  if (did) {
337
- _context9.next = 2;
315
+ _context9.n = 1;
338
316
  break;
339
317
  }
340
- return _context9.abrupt("return", undefined);
341
- case 2:
318
+ return _context9.a(2, undefined);
319
+ case 1:
342
320
  if (!did.startsWith('did:polygon')) {
343
- _context9.next = 4;
321
+ _context9.n = 2;
344
322
  break;
345
323
  }
346
324
  throw new Error('PolygonID DIDs cannot be used for DIDComm purposes');
347
- case 4:
325
+ case 2:
348
326
  // Resolve actual DID document and get key agreement keys
349
327
  isDIDUrl = did.indexOf('#') !== -1;
350
- _context9.next = 7;
328
+ _context9.n = 3;
351
329
  return blockchainService.resolver.resolve(did);
352
- case 7:
353
- didDocument = _context9.sent;
330
+ case 3:
331
+ didDocument = _context9.v;
354
332
  keyAgreements = didDocument.keyAgreement ? Array.isArray(didDocument.keyAgreement) ? didDocument.keyAgreement : [didDocument.keyAgreement] : []; // User supplied full URL, use that if possible
355
333
  // if not it may still require derivation to be valid (such as dock DIDs)
356
334
  if (!isDIDUrl) {
357
- _context9.next = 13;
335
+ _context9.n = 4;
358
336
  break;
359
337
  }
360
338
  foundDoc = keyAgreements.filter(function (keyDoc) {
361
339
  return keyDoc.id === did && isValidKeyAgreementDoc(keyDoc);
362
340
  })[0];
363
341
  if (!foundDoc) {
364
- _context9.next = 13;
342
+ _context9.n = 4;
365
343
  break;
366
344
  }
367
- return _context9.abrupt("return", foundDoc);
368
- case 13:
345
+ return _context9.a(2, foundDoc);
346
+ case 4:
369
347
  // User supplied DID, find first supported keyagreement document
370
348
  firstKeyAgreement = keyAgreements.filter(isValidKeyAgreementDoc)[0];
371
349
  if (!firstKeyAgreement) {
372
- _context9.next = 16;
350
+ _context9.n = 5;
373
351
  break;
374
352
  }
375
- return _context9.abrupt("return", firstKeyAgreement);
376
- case 16:
353
+ return _context9.a(2, firstKeyAgreement);
354
+ case 5:
377
355
  // No valid key agreement found on resolution, lets derive one from a ED25519 key if we can
378
356
  publicKeys = getDIDKeydocsFromDIDDocument(didDocument); // See if DID document has any derivable keys
379
357
  derivableKey = publicKeys.filter(isDerivableKey)[0];
380
358
  if (!derivableKey) {
381
- _context9.next = 20;
359
+ _context9.n = 6;
382
360
  break;
383
361
  }
384
- return _context9.abrupt("return", getDerivedAgreementKey(derivableKey));
385
- case 20:
362
+ return _context9.a(2, getDerivedAgreementKey(derivableKey));
363
+ case 6:
386
364
  throw new Error("Unable to find or derive X25519 key agreement for DID: ".concat(did));
387
- case 21:
388
- case "end":
389
- return _context9.stop();
365
+ case 7:
366
+ return _context9.a(2);
390
367
  }
391
368
  }, _callee9);
392
369
  }));
@@ -401,21 +378,21 @@ function encodeMbKey(header, key) {
401
378
  mbKey.set(key, header.length);
402
379
  return MULTIBASE_BASE58BTC_HEADER + bs58.encode(mbKey);
403
380
  }
404
- function getDerivedAgreementKey(_x18) {
381
+ function getDerivedAgreementKey(_x16) {
405
382
  return _getDerivedAgreementKey.apply(this, arguments);
406
383
  }
407
384
  function _getDerivedAgreementKey() {
408
- _getDerivedAgreementKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(derivableKey) {
385
+ _getDerivedAgreementKey = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(derivableKey) {
409
386
  var publicKeyMultibase, privateKeyMultibase, derivedKeyAgreement;
410
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
411
- while (1) switch (_context10.prev = _context10.next) {
387
+ return _regenerator().w(function (_context0) {
388
+ while (1) switch (_context0.n) {
412
389
  case 0:
413
390
  if (isDerivableKey(derivableKey)) {
414
- _context10.next = 2;
391
+ _context0.n = 1;
415
392
  break;
416
393
  }
417
394
  throw new Error("Cannot derive X25519 KAK from type: ".concat(derivableKey.type));
418
- case 2:
395
+ case 1:
419
396
  publicKeyMultibase = derivableKey.publicKeyBase58 ? encodeMbKey(MULTICODEC_ED25519_PUB_HEADER, bs58.decode(derivableKey.publicKeyBase58)) : derivableKey.publicKeyMultibase;
420
397
  privateKeyMultibase = (derivableKey.privateKeyBase58 ? encodeMbKey(MULTICODEC_ED25519_PRIV_HEADER, bs58.decode(derivableKey.privateKeyBase58)) : undefined) || derivableKey.privateKeyMultibase; // Convert ed25519 2020 verification key into a key agreement key
421
398
  derivedKeyAgreement = X25519KeyAgreementKey2020.fromEd25519VerificationKey2020({
@@ -425,38 +402,32 @@ function _getDerivedAgreementKey() {
425
402
  controller: derivableKey.controller
426
403
  }
427
404
  });
428
- return _context10.abrupt("return", derivedKeyAgreement);
429
- case 6:
430
- case "end":
431
- return _context10.stop();
405
+ return _context0.a(2, derivedKeyAgreement);
432
406
  }
433
- }, _callee10);
407
+ }, _callee0);
434
408
  }));
435
409
  return _getDerivedAgreementKey.apply(this, arguments);
436
410
  }
437
- function getKaKInstanceFromDocument(_x19) {
411
+ function getKaKInstanceFromDocument(_x17) {
438
412
  return _getKaKInstanceFromDocument.apply(this, arguments);
439
413
  }
440
414
  function _getKaKInstanceFromDocument() {
441
- _getKaKInstanceFromDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(keyDoc) {
442
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
443
- while (1) switch (_context11.prev = _context11.next) {
415
+ _getKaKInstanceFromDocument = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(keyDoc) {
416
+ return _regenerator().w(function (_context1) {
417
+ while (1) switch (_context1.n) {
444
418
  case 0:
445
419
  if (isValidKeyAgreementDoc(keyDoc)) {
446
- _context11.next = 2;
420
+ _context1.n = 1;
447
421
  break;
448
422
  }
449
423
  throw new Error("Invalid key document type for key agreement key: ".concat(keyDoc.type));
450
- case 2:
451
- _context11.next = 4;
424
+ case 1:
425
+ _context1.n = 2;
452
426
  return X25519KeyAgreementKey2020.from(keyDoc);
453
- case 4:
454
- return _context11.abrupt("return", _context11.sent);
455
- case 5:
456
- case "end":
457
- return _context11.stop();
427
+ case 2:
428
+ return _context1.a(2, _context1.v);
458
429
  }
459
- }, _callee11);
430
+ }, _callee1);
460
431
  }));
461
432
  return _getKaKInstanceFromDocument.apply(this, arguments);
462
433
  }
@@ -490,95 +461,91 @@ function formatPayloadToDIDComm(to, msgType, from, body, replyUrl, replyTo) {
490
461
  }
491
462
  return msg;
492
463
  }
493
- function didcommCreateEncrypted(_x20) {
464
+ function didcommCreateEncrypted(_x18) {
494
465
  return _didcommCreateEncrypted.apply(this, arguments);
495
466
  }
496
467
  function _didcommCreateEncrypted() {
497
- _didcommCreateEncrypted = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(_ref) {
498
- var senderDid, _ref$recipientDids, recipientDids, payload, type, keyAgreementKey, algorithm, recipientKeyDocuments, recipients, keyResolver, didcommMessage, jweDoc;
499
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
500
- while (1) switch (_context13.prev = _context13.next) {
468
+ _didcommCreateEncrypted = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(_ref) {
469
+ var senderDid, _ref$recipientDids, recipientDids, payload, type, keyAgreementKey, algorithm, recipientKeyDocuments, recipients, keyResolver, didcommMessage, jweDoc, _t;
470
+ return _regenerator().w(function (_context11) {
471
+ while (1) switch (_context11.p = _context11.n) {
501
472
  case 0:
502
473
  senderDid = _ref.senderDid, _ref$recipientDids = _ref.recipientDids, recipientDids = _ref$recipientDids === void 0 ? [] : _ref$recipientDids, payload = _ref.payload, type = _ref.type, keyAgreementKey = _ref.keyAgreementKey, algorithm = _ref.algorithm;
503
474
  if (payload) {
504
- _context13.next = 3;
475
+ _context11.n = 1;
505
476
  break;
506
477
  }
507
478
  throw new Error('Requires payload to create encrypted didcomm message');
508
- case 3:
479
+ case 1:
509
480
  if (!(recipientDids.length === 0)) {
510
- _context13.next = 5;
481
+ _context11.n = 2;
511
482
  break;
512
483
  }
513
484
  throw new Error('Must supply atleast 1 recipient DID');
514
- case 5:
485
+ case 2:
515
486
  if (isValidDID(senderDid)) {
516
- _context13.next = 7;
487
+ _context11.n = 3;
517
488
  break;
518
489
  }
519
490
  throw new Error('Sender DID must be a valid DID');
520
- case 7:
491
+ case 3:
521
492
  if (recipientDids.every(isValidDID)) {
522
- _context13.next = 9;
493
+ _context11.n = 4;
523
494
  break;
524
495
  }
525
496
  throw new Error('Recipient DID is invalid');
526
- case 9:
527
- _context13.next = 11;
497
+ case 4:
498
+ _context11.n = 5;
528
499
  return Promise.all(recipientDids.map(getAgreementKeydocFromDID));
529
- case 11:
530
- recipientKeyDocuments = _context13.sent;
500
+ case 5:
501
+ recipientKeyDocuments = _context11.v;
531
502
  recipients = recipientKeyDocuments.map(function (keyDoc) {
532
503
  return getJWERecipientFromDocument(keyDoc, algorithm);
533
504
  });
534
505
  keyResolver = /*#__PURE__*/function () {
535
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(keyId) {
506
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(keyId) {
536
507
  var keyIdStr, keyDoc, result;
537
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
538
- while (1) switch (_context12.prev = _context12.next) {
508
+ return _regenerator().w(function (_context10) {
509
+ while (1) switch (_context10.n) {
539
510
  case 0:
540
511
  keyIdStr = keyId.id || keyId;
541
512
  keyDoc = recipientKeyDocuments.filter(function (k) {
542
513
  return k.id === keyIdStr;
543
514
  })[0];
544
515
  if (keyDoc) {
545
- _context12.next = 4;
516
+ _context10.n = 1;
546
517
  break;
547
518
  }
548
519
  throw new Error("Cannot find key document with ID: ".concat(keyIdStr));
549
- case 4:
550
- _context12.next = 6;
520
+ case 1:
521
+ _context10.n = 2;
551
522
  return getKaKInstanceFromDocument(keyDoc);
552
- case 6:
553
- result = _context12.sent;
554
- return _context12.abrupt("return", result);
555
- case 8:
556
- case "end":
557
- return _context12.stop();
523
+ case 2:
524
+ result = _context10.v;
525
+ return _context10.a(2, result);
558
526
  }
559
- }, _callee12);
527
+ }, _callee10);
560
528
  }));
561
- return function keyResolver(_x21) {
529
+ return function keyResolver(_x19) {
562
530
  return _ref2.apply(this, arguments);
563
531
  };
564
532
  }();
565
533
  didcommMessage = formatPayloadToDIDComm(recipientDids, type, senderDid, payload);
566
- _context13.prev = 15;
567
- _context13.next = 18;
534
+ _context11.p = 6;
535
+ _context11.n = 7;
568
536
  return didcommEncrypt(didcommMessage, recipients, keyResolver, keyAgreementKey);
569
- case 18:
570
- jweDoc = _context13.sent;
571
- return _context13.abrupt("return", jweDoc);
572
- case 22:
573
- _context13.prev = 22;
574
- _context13.t0 = _context13["catch"](15);
575
- console.error(_context13.t0);
537
+ case 7:
538
+ jweDoc = _context11.v;
539
+ return _context11.a(2, jweDoc);
540
+ case 8:
541
+ _context11.p = 8;
542
+ _t = _context11.v;
543
+ console.error(_t);
576
544
  throw new Error('Error encrypting message');
577
- case 26:
578
- case "end":
579
- return _context13.stop();
545
+ case 9:
546
+ return _context11.a(2);
580
547
  }
581
- }, _callee13, null, [[15, 22]]);
548
+ }, _callee11, null, [[6, 8]]);
582
549
  }));
583
550
  return _didcommCreateEncrypted.apply(this, arguments);
584
551
  }