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