@yourself_id/siwys-api-js 0.10.0 → 0.10.1-SAPP-221-mdipUpdate.1

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/dist/index.js CHANGED
@@ -1,4 +1,12 @@
1
1
  // src/keymaster.ts
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_without_holes(arr) {
8
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
9
+ }
2
10
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3
11
  try {
4
12
  var info = gen[key](arg);
@@ -47,6 +55,23 @@ function _create_class(Constructor, protoProps, staticProps) {
47
55
  if (staticProps) _defineProperties(Constructor, staticProps);
48
56
  return Constructor;
49
57
  }
58
+ function _iterable_to_array(iter) {
59
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
60
+ }
61
+ function _non_iterable_spread() {
62
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
63
+ }
64
+ function _to_consumable_array(arr) {
65
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
66
+ }
67
+ function _unsupported_iterable_to_array(o, minLen) {
68
+ if (!o) return;
69
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
70
+ var n = Object.prototype.toString.call(o).slice(8, -1);
71
+ if (n === "Object" && o.constructor) n = o.constructor.name;
72
+ if (n === "Map" || n === "Set") return Array.from(n);
73
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
74
+ }
50
75
  function _ts_generator(thisArg, body) {
51
76
  var f, y, t, g, _ = {
52
77
  label: 0,
@@ -144,57 +169,74 @@ function _ts_generator(thisArg, body) {
144
169
  }
145
170
  import GatekeeperClient from "@mdip/gatekeeper/client";
146
171
  import CipherNode from "@mdip/cipher/node";
147
- import KeymasterClient from "@mdip/keymaster/client";
148
- import { default as KeymasterLib } from "@mdip/keymaster";
149
- var Keymaster = /*#__PURE__*/ function() {
172
+ import KeymasterLib from "@mdip/keymaster";
173
+ var _Keymaster = /*#__PURE__*/ function() {
150
174
  "use strict";
151
- function Keymaster(config) {
152
- _class_call_check(this, Keymaster);
175
+ function _Keymaster(config) {
176
+ _class_call_check(this, _Keymaster);
153
177
  this.serviceStarted = false;
154
178
  this.validateConfig(config);
155
179
  this.config = config;
156
180
  }
157
- _create_class(Keymaster, [
181
+ _create_class(_Keymaster, [
158
182
  {
159
- key: "start",
160
- value: function start() {
183
+ key: "ensureInitialized",
184
+ value: function ensureInitialized() {
185
+ if (!_Keymaster.instance) {
186
+ throw new Error("Keymaster not initialized. Call Keymaster.initialize() first.");
187
+ }
188
+ }
189
+ },
190
+ {
191
+ key: "ensureServiceIsRunning",
192
+ value: // -------- Internal instance methods (originals renamed with Internal) -------
193
+ function ensureServiceIsRunning() {
161
194
  var _this = this;
162
195
  return _async_to_generator(function() {
163
196
  return _ts_generator(this, function(_state) {
164
197
  switch(_state.label){
165
198
  case 0:
166
- if (!_this.config.gatekeeperConfig) return [
167
- 3,
168
- 2
169
- ];
170
199
  return [
171
200
  4,
172
- _this.startIntegratedKeymaster()
201
+ _this.serviceRunning()
173
202
  ];
174
203
  case 1:
175
- _this.serviceStarted = _state.sent();
204
+ if (!_state.sent()) {
205
+ throw new Error("Keymaster service not running");
206
+ }
176
207
  return [
177
- 3,
178
- 5
208
+ 2
179
209
  ];
180
- case 2:
181
- if (!_this.config.keymasterConfig) return [
210
+ }
211
+ });
212
+ })();
213
+ }
214
+ },
215
+ {
216
+ key: "startInternal",
217
+ value: function startInternal() {
218
+ var _this = this;
219
+ return _async_to_generator(function() {
220
+ return _ts_generator(this, function(_state) {
221
+ switch(_state.label){
222
+ case 0:
223
+ if (!_this.config.gatekeeperConfig) return [
182
224
  3,
183
- 4
225
+ 2
184
226
  ];
185
227
  return [
186
228
  4,
187
- _this.startExternalKeymaster()
229
+ _this.startIntegratedKeymaster()
188
230
  ];
189
- case 3:
231
+ case 1:
190
232
  _this.serviceStarted = _state.sent();
191
233
  return [
192
234
  3,
193
- 5
235
+ 3
194
236
  ];
195
- case 4:
196
- throw "Missing Gatekeeper or Keymaster config";
197
- case 5:
237
+ case 2:
238
+ throw "Missing Gatekeeper config";
239
+ case 3:
198
240
  return [
199
241
  2,
200
242
  _this.serviceStarted
@@ -218,10 +260,14 @@ var Keymaster = /*#__PURE__*/ function() {
218
260
  case 1:
219
261
  _state.trys.push([
220
262
  1,
221
- 5,
263
+ 6,
222
264
  ,
223
- 6
265
+ 7
224
266
  ]);
267
+ if (!_this.config.walletDb) return [
268
+ 3,
269
+ 4
270
+ ];
225
271
  gatekeeper = new GatekeeperClient();
226
272
  return [
227
273
  4,
@@ -230,34 +276,39 @@ var Keymaster = /*#__PURE__*/ function() {
230
276
  case 2:
231
277
  _state.sent();
232
278
  cipher = new CipherNode();
279
+ _this.keymasterService = new KeymasterLib({
280
+ gatekeeper: gatekeeper,
281
+ wallet: _this.config.walletDb,
282
+ cipher: cipher
283
+ });
233
284
  return [
234
285
  4,
235
- new KeymasterLib({
236
- gatekeeper: gatekeeper,
237
- wallet: _this.config.walletDb,
238
- cipher: cipher
239
- })
286
+ _this.ensureWalletExists()
240
287
  ];
241
288
  case 3:
242
- _this.keymasterService = _state.sent();
289
+ _state.sent();
243
290
  return [
244
- 4,
245
- _this.ensureWalletExists()
291
+ 3,
292
+ 5
246
293
  ];
247
294
  case 4:
248
- _state.sent();
249
295
  return [
250
- 3,
251
- 6
296
+ 2,
297
+ false
252
298
  ];
253
299
  case 5:
300
+ return [
301
+ 3,
302
+ 7
303
+ ];
304
+ case 6:
254
305
  e = _state.sent();
255
306
  console.error("Error starting Keymaster service:", e);
256
307
  return [
257
308
  2,
258
309
  false
259
310
  ];
260
- case 6:
311
+ case 7:
261
312
  console.log("Started integrated Keymaster service");
262
313
  return [
263
314
  2,
@@ -269,46 +320,32 @@ var Keymaster = /*#__PURE__*/ function() {
269
320
  }
270
321
  },
271
322
  {
272
- key: "startExternalKeymaster",
273
- value: function startExternalKeymaster() {
323
+ key: "createChallengeInternal",
324
+ value: function createChallengeInternal(spec, options) {
274
325
  var _this = this;
275
326
  return _async_to_generator(function() {
276
- var e;
327
+ var challenge;
277
328
  return _ts_generator(this, function(_state) {
278
329
  switch(_state.label){
279
330
  case 0:
280
- console.log("Starting external Keymaster service");
281
- _state.label = 1;
282
- case 1:
283
- _state.trys.push([
284
- 1,
285
- 3,
286
- ,
287
- 4
288
- ]);
289
- _this.keymasterService = new KeymasterClient();
290
331
  return [
291
332
  4,
292
- _this.keymasterService.connect(_this.config.keymasterConfig)
333
+ _this.ensureServiceIsRunning()
293
334
  ];
294
- case 2:
335
+ case 1:
295
336
  _state.sent();
296
337
  return [
297
- 3,
298
- 4
299
- ];
300
- case 3:
301
- e = _state.sent();
302
- console.error("Error starting Keymaster service:", e);
303
- return [
304
- 2,
305
- false
338
+ 4,
339
+ _this.keymasterService.createChallenge(spec, options)
306
340
  ];
307
- case 4:
308
- console.log("Started external Keymaster service");
341
+ case 2:
342
+ challenge = _state.sent();
309
343
  return [
310
344
  2,
311
- true
345
+ {
346
+ challenge: challenge,
347
+ challengeUrl: "".concat(spec.callback, "?challenge=").concat(challenge)
348
+ }
312
349
  ];
313
350
  }
314
351
  });
@@ -316,29 +353,23 @@ var Keymaster = /*#__PURE__*/ function() {
316
353
  }
317
354
  },
318
355
  {
319
- key: "createChallenge",
320
- value: function createChallenge(spec, options) {
356
+ key: "bindCredentialInternal",
357
+ value: function bindCredentialInternal(schemaId, subjectId) {
358
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
321
359
  var _this = this;
322
360
  return _async_to_generator(function() {
323
- var challenge;
324
361
  return _ts_generator(this, function(_state) {
325
362
  switch(_state.label){
326
363
  case 0:
327
- if (!_this.serviceRunning()) {
328
- throw new Error("Keymaster service not running");
329
- }
330
364
  return [
331
365
  4,
332
- _this.keymasterService.createChallenge(spec, options)
366
+ _this.ensureServiceIsRunning()
333
367
  ];
334
368
  case 1:
335
- challenge = _state.sent();
369
+ _state.sent();
336
370
  return [
337
371
  2,
338
- {
339
- challenge: challenge,
340
- challengeUrl: "".concat(spec.callback, "?challenge=").concat(challenge)
341
- }
372
+ _this.keymasterService.bindCredential(schemaId, subjectId, options)
342
373
  ];
343
374
  }
344
375
  });
@@ -346,114 +377,143 @@ var Keymaster = /*#__PURE__*/ function() {
346
377
  }
347
378
  },
348
379
  {
349
- key: "bindCredential",
350
- value: function bindCredential(schemaId, subjectId) {
351
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
380
+ key: "issueCredentialInternal",
381
+ value: function issueCredentialInternal(credential) {
382
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
352
383
  var _this = this;
353
384
  return _async_to_generator(function() {
354
385
  return _ts_generator(this, function(_state) {
355
- if (!_this.serviceRunning()) {
356
- throw new Error("Keymaster service not running");
386
+ switch(_state.label){
387
+ case 0:
388
+ return [
389
+ 4,
390
+ _this.ensureServiceIsRunning()
391
+ ];
392
+ case 1:
393
+ _state.sent();
394
+ return [
395
+ 2,
396
+ _this.keymasterService.issueCredential(credential, options)
397
+ ];
357
398
  }
358
- return [
359
- 2,
360
- _this.keymasterService.bindCredential(schemaId, subjectId, options)
361
- ];
362
399
  });
363
400
  })();
364
401
  }
365
402
  },
366
403
  {
367
- key: "issueCredential",
368
- value: function issueCredential(credential) {
404
+ key: "publishCredentialInternal",
405
+ value: function publishCredentialInternal(did) {
369
406
  var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
370
407
  var _this = this;
371
408
  return _async_to_generator(function() {
372
409
  return _ts_generator(this, function(_state) {
373
- if (!_this.serviceRunning()) {
374
- throw new Error("Keymaster service not running");
410
+ switch(_state.label){
411
+ case 0:
412
+ return [
413
+ 4,
414
+ _this.ensureServiceIsRunning()
415
+ ];
416
+ case 1:
417
+ _state.sent();
418
+ return [
419
+ 2,
420
+ _this.keymasterService.publishCredential(did, options)
421
+ ];
375
422
  }
376
- return [
377
- 2,
378
- _this.keymasterService.issueCredential(credential, options)
379
- ];
380
423
  });
381
424
  })();
382
425
  }
383
426
  },
384
427
  {
385
- key: "publishCredential",
386
- value: function publishCredential(did) {
387
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
428
+ key: "acceptCredentialInternal",
429
+ value: function acceptCredentialInternal(did) {
388
430
  var _this = this;
389
431
  return _async_to_generator(function() {
390
432
  return _ts_generator(this, function(_state) {
391
- if (!_this.serviceRunning()) {
392
- throw new Error("Keymaster service not running");
433
+ switch(_state.label){
434
+ case 0:
435
+ return [
436
+ 4,
437
+ _this.ensureServiceIsRunning()
438
+ ];
439
+ case 1:
440
+ _state.sent();
441
+ return [
442
+ 2,
443
+ _this.keymasterService.acceptCredential(did)
444
+ ];
393
445
  }
394
- return [
395
- 2,
396
- _this.keymasterService.publishCredential(did, options)
397
- ];
398
446
  });
399
447
  })();
400
448
  }
401
449
  },
402
450
  {
403
- key: "acceptCredential",
404
- value: function acceptCredential(did) {
451
+ key: "showMnemonicInternal",
452
+ value: function showMnemonicInternal() {
405
453
  var _this = this;
406
454
  return _async_to_generator(function() {
407
455
  return _ts_generator(this, function(_state) {
408
- if (!_this.serviceRunning()) {
409
- throw new Error("Keymaster service not running");
456
+ switch(_state.label){
457
+ case 0:
458
+ return [
459
+ 4,
460
+ _this.ensureServiceIsRunning()
461
+ ];
462
+ case 1:
463
+ _state.sent();
464
+ return [
465
+ 2,
466
+ _this.keymasterService.decryptMnemonic()
467
+ ];
410
468
  }
411
- return [
412
- 2,
413
- _this.keymasterService.acceptCredential(did)
414
- ];
415
469
  });
416
470
  })();
417
471
  }
418
472
  },
419
473
  {
420
- key: "showMnemonic",
421
- value: function showMnemonic() {
474
+ key: "verifyResponseInternal",
475
+ value: function verifyResponseInternal(did, options) {
422
476
  var _this = this;
423
477
  return _async_to_generator(function() {
424
478
  return _ts_generator(this, function(_state) {
425
- if (!_this.serviceRunning()) {
426
- throw new Error("Keymaster service not running");
479
+ switch(_state.label){
480
+ case 0:
481
+ return [
482
+ 4,
483
+ _this.ensureServiceIsRunning()
484
+ ];
485
+ case 1:
486
+ _state.sent();
487
+ return [
488
+ 2,
489
+ _this.keymasterService.verifyResponse(did, options)
490
+ ];
427
491
  }
428
- return [
429
- 2,
430
- _this.keymasterService.decryptMnemonic()
431
- ];
432
492
  });
433
493
  })();
434
494
  }
435
495
  },
436
496
  {
437
- key: "verifyResponse",
438
- value: function verifyResponse(did, options) {
497
+ key: "decryptMessageInternal",
498
+ value: function decryptMessageInternal() {
499
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
500
+ args[_key] = arguments[_key];
501
+ }
439
502
  var _this = this;
440
503
  return _async_to_generator(function() {
441
- var response;
504
+ var _this_keymasterService;
442
505
  return _ts_generator(this, function(_state) {
443
506
  switch(_state.label){
444
507
  case 0:
445
- if (!_this.serviceRunning()) {
446
- throw new Error("Keymaster service not running");
447
- }
448
508
  return [
449
509
  4,
450
- _this.keymasterService.verifyResponse(did, options)
510
+ _this.ensureServiceIsRunning()
451
511
  ];
452
512
  case 1:
453
- response = _state.sent();
513
+ _state.sent();
454
514
  return [
455
515
  2,
456
- response
516
+ (_this_keymasterService = _this.keymasterService).decryptMessage.apply(_this_keymasterService, _to_consumable_array(args))
457
517
  ];
458
518
  }
459
519
  });
@@ -461,50 +521,355 @@ var Keymaster = /*#__PURE__*/ function() {
461
521
  }
462
522
  },
463
523
  {
464
- key: "ensureWalletExists",
465
- value: function ensureWalletExists() {
524
+ key: "decryptMnemonicInternal",
525
+ value: function decryptMnemonicInternal() {
526
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
527
+ args[_key] = arguments[_key];
528
+ }
466
529
  var _this = this;
467
530
  return _async_to_generator(function() {
468
- var _this_config_walletDb, _this_config, existing, walletConfig, did;
531
+ var _this_keymasterService;
469
532
  return _ts_generator(this, function(_state) {
470
533
  switch(_state.label){
471
534
  case 0:
472
- console.log("Ensuring wallet exists");
473
535
  return [
474
536
  4,
475
- (_this_config = _this.config) === null || _this_config === void 0 ? void 0 : (_this_config_walletDb = _this_config.walletDb) === null || _this_config_walletDb === void 0 ? void 0 : _this_config_walletDb.loadWallet()
537
+ _this.ensureServiceIsRunning()
476
538
  ];
477
539
  case 1:
478
- existing = _state.sent() || null;
479
- if (existing === null || existing === void 0 ? void 0 : existing.current) {
480
- console.log("Using existing wallet with ID ".concat(existing.current));
481
- return [
482
- 2
483
- ];
484
- }
485
- walletConfig = _this.config.walletConfig;
486
- console.log("Creating Creating Creating wallet with ID ".concat(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id));
487
- if (!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.mnemonic)) return [
488
- 3,
489
- 3
490
- ];
491
- return [
492
- 4,
493
- _this.keymasterService.newWallet(walletConfig.mnemonic, true)
494
- ];
495
- case 2:
496
540
  _state.sent();
497
- _state.label = 3;
498
- case 3:
499
541
  return [
500
- 4,
501
- _this.keymasterService.createId(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id, walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.registry)
542
+ 2,
543
+ (_this_keymasterService = _this.keymasterService).decryptMnemonic.apply(_this_keymasterService, _to_consumable_array(args))
502
544
  ];
503
- case 4:
504
- did = _state.sent();
505
- console.log("Did ", did);
506
- console.log("Created wallet with ID ".concat(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id));
507
- return [
545
+ }
546
+ });
547
+ })();
548
+ }
549
+ },
550
+ {
551
+ key: "getCredentialInternal",
552
+ value: function getCredentialInternal() {
553
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
554
+ args[_key] = arguments[_key];
555
+ }
556
+ var _this = this;
557
+ return _async_to_generator(function() {
558
+ var _this_keymasterService;
559
+ return _ts_generator(this, function(_state) {
560
+ switch(_state.label){
561
+ case 0:
562
+ return [
563
+ 4,
564
+ _this.ensureServiceIsRunning()
565
+ ];
566
+ case 1:
567
+ _state.sent();
568
+ return [
569
+ 2,
570
+ (_this_keymasterService = _this.keymasterService).getCredential.apply(_this_keymasterService, _to_consumable_array(args))
571
+ ];
572
+ }
573
+ });
574
+ })();
575
+ }
576
+ },
577
+ {
578
+ key: "removeCredentialInternal",
579
+ value: function removeCredentialInternal() {
580
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
581
+ args[_key] = arguments[_key];
582
+ }
583
+ var _this = this;
584
+ return _async_to_generator(function() {
585
+ var _this_keymasterService;
586
+ return _ts_generator(this, function(_state) {
587
+ switch(_state.label){
588
+ case 0:
589
+ return [
590
+ 4,
591
+ _this.ensureServiceIsRunning()
592
+ ];
593
+ case 1:
594
+ _state.sent();
595
+ return [
596
+ 2,
597
+ (_this_keymasterService = _this.keymasterService).removeCredential.apply(_this_keymasterService, _to_consumable_array(args))
598
+ ];
599
+ }
600
+ });
601
+ })();
602
+ }
603
+ },
604
+ {
605
+ key: "updateCredentialInternal",
606
+ value: function updateCredentialInternal() {
607
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
608
+ args[_key] = arguments[_key];
609
+ }
610
+ var _this = this;
611
+ return _async_to_generator(function() {
612
+ var _this_keymasterService;
613
+ return _ts_generator(this, function(_state) {
614
+ switch(_state.label){
615
+ case 0:
616
+ return [
617
+ 4,
618
+ _this.ensureServiceIsRunning()
619
+ ];
620
+ case 1:
621
+ _state.sent();
622
+ return [
623
+ 2,
624
+ (_this_keymasterService = _this.keymasterService).updateCredential.apply(_this_keymasterService, _to_consumable_array(args))
625
+ ];
626
+ }
627
+ });
628
+ })();
629
+ }
630
+ },
631
+ {
632
+ key: "createIdInternal",
633
+ value: function createIdInternal() {
634
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
635
+ args[_key] = arguments[_key];
636
+ }
637
+ var _this = this;
638
+ return _async_to_generator(function() {
639
+ var _this_keymasterService;
640
+ return _ts_generator(this, function(_state) {
641
+ switch(_state.label){
642
+ case 0:
643
+ return [
644
+ 4,
645
+ _this.ensureServiceIsRunning()
646
+ ];
647
+ case 1:
648
+ _state.sent();
649
+ return [
650
+ 2,
651
+ (_this_keymasterService = _this.keymasterService).createId.apply(_this_keymasterService, _to_consumable_array(args))
652
+ ];
653
+ }
654
+ });
655
+ })();
656
+ }
657
+ },
658
+ {
659
+ key: "removeIdInternal",
660
+ value: function removeIdInternal() {
661
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
662
+ args[_key] = arguments[_key];
663
+ }
664
+ var _this = this;
665
+ return _async_to_generator(function() {
666
+ var _this_keymasterService;
667
+ return _ts_generator(this, function(_state) {
668
+ switch(_state.label){
669
+ case 0:
670
+ return [
671
+ 4,
672
+ _this.ensureServiceIsRunning()
673
+ ];
674
+ case 1:
675
+ _state.sent();
676
+ return [
677
+ 2,
678
+ (_this_keymasterService = _this.keymasterService).removeId.apply(_this_keymasterService, _to_consumable_array(args))
679
+ ];
680
+ }
681
+ });
682
+ })();
683
+ }
684
+ },
685
+ {
686
+ key: "resolveDIDInternal",
687
+ value: function resolveDIDInternal() {
688
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
689
+ args[_key] = arguments[_key];
690
+ }
691
+ var _this = this;
692
+ return _async_to_generator(function() {
693
+ var _this_keymasterService;
694
+ return _ts_generator(this, function(_state) {
695
+ switch(_state.label){
696
+ case 0:
697
+ return [
698
+ 4,
699
+ _this.ensureServiceIsRunning()
700
+ ];
701
+ case 1:
702
+ _state.sent();
703
+ return [
704
+ 2,
705
+ (_this_keymasterService = _this.keymasterService).resolveDID.apply(_this_keymasterService, _to_consumable_array(args))
706
+ ];
707
+ }
708
+ });
709
+ })();
710
+ }
711
+ },
712
+ {
713
+ key: "setCurrentIdInternal",
714
+ value: function setCurrentIdInternal() {
715
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
716
+ args[_key] = arguments[_key];
717
+ }
718
+ var _this = this;
719
+ return _async_to_generator(function() {
720
+ var _this_keymasterService;
721
+ return _ts_generator(this, function(_state) {
722
+ switch(_state.label){
723
+ case 0:
724
+ return [
725
+ 4,
726
+ _this.ensureServiceIsRunning()
727
+ ];
728
+ case 1:
729
+ _state.sent();
730
+ return [
731
+ 2,
732
+ (_this_keymasterService = _this.keymasterService).setCurrentId.apply(_this_keymasterService, _to_consumable_array(args))
733
+ ];
734
+ }
735
+ });
736
+ })();
737
+ }
738
+ },
739
+ {
740
+ key: "createSchemaInternal",
741
+ value: function createSchemaInternal() {
742
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
743
+ args[_key] = arguments[_key];
744
+ }
745
+ var _this = this;
746
+ return _async_to_generator(function() {
747
+ var _this_keymasterService;
748
+ return _ts_generator(this, function(_state) {
749
+ switch(_state.label){
750
+ case 0:
751
+ return [
752
+ 4,
753
+ _this.ensureServiceIsRunning()
754
+ ];
755
+ case 1:
756
+ _state.sent();
757
+ return [
758
+ 2,
759
+ (_this_keymasterService = _this.keymasterService).createSchema.apply(_this_keymasterService, _to_consumable_array(args))
760
+ ];
761
+ }
762
+ });
763
+ })();
764
+ }
765
+ },
766
+ {
767
+ key: "newWalletInternal",
768
+ value: function newWalletInternal() {
769
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
770
+ args[_key] = arguments[_key];
771
+ }
772
+ var _this = this;
773
+ return _async_to_generator(function() {
774
+ var _this_keymasterService;
775
+ return _ts_generator(this, function(_state) {
776
+ switch(_state.label){
777
+ case 0:
778
+ return [
779
+ 4,
780
+ _this.ensureServiceIsRunning()
781
+ ];
782
+ case 1:
783
+ _state.sent();
784
+ return [
785
+ 2,
786
+ (_this_keymasterService = _this.keymasterService).newWallet.apply(_this_keymasterService, _to_consumable_array(args))
787
+ ];
788
+ }
789
+ });
790
+ })();
791
+ }
792
+ },
793
+ {
794
+ key: "recoverWalletInternal",
795
+ value: function recoverWalletInternal() {
796
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
797
+ args[_key] = arguments[_key];
798
+ }
799
+ var _this = this;
800
+ return _async_to_generator(function() {
801
+ var _this_keymasterService;
802
+ return _ts_generator(this, function(_state) {
803
+ switch(_state.label){
804
+ case 0:
805
+ return [
806
+ 4,
807
+ _this.ensureServiceIsRunning()
808
+ ];
809
+ case 1:
810
+ _state.sent();
811
+ return [
812
+ 2,
813
+ (_this_keymasterService = _this.keymasterService).recoverWallet.apply(_this_keymasterService, _to_consumable_array(args))
814
+ ];
815
+ }
816
+ });
817
+ })();
818
+ }
819
+ },
820
+ {
821
+ key: "ensureWalletExists",
822
+ value: function ensureWalletExists() {
823
+ var _this = this;
824
+ return _async_to_generator(function() {
825
+ var _this_config_walletDb, _this_config, existing, walletConfig, did;
826
+ return _ts_generator(this, function(_state) {
827
+ switch(_state.label){
828
+ case 0:
829
+ console.log("Ensuring wallet exists");
830
+ return [
831
+ 4,
832
+ (_this_config = _this.config) === null || _this_config === void 0 ? void 0 : (_this_config_walletDb = _this_config.walletDb) === null || _this_config_walletDb === void 0 ? void 0 : _this_config_walletDb.loadWallet()
833
+ ];
834
+ case 1:
835
+ existing = _state.sent() || null;
836
+ if (existing && "current" in existing) {
837
+ console.log("Using existing wallet with ID ".concat(existing.current));
838
+ return [
839
+ 2
840
+ ];
841
+ }
842
+ walletConfig = _this.config.walletConfig;
843
+ console.log("Creating wallet with ID ".concat(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id));
844
+ if (!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.mnemonic)) return [
845
+ 3,
846
+ 3
847
+ ];
848
+ return [
849
+ 4,
850
+ _this.keymasterService.newWallet(walletConfig.mnemonic, true)
851
+ ];
852
+ case 2:
853
+ _state.sent();
854
+ _state.label = 3;
855
+ case 3:
856
+ if (!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id)) return [
857
+ 3,
858
+ 5
859
+ ];
860
+ return [
861
+ 4,
862
+ _this.keymasterService.createId(walletConfig.id, {
863
+ registry: walletConfig.registry
864
+ })
865
+ ];
866
+ case 4:
867
+ did = _state.sent();
868
+ console.log("Did ", did);
869
+ console.log("Created wallet with ID ".concat(walletConfig.id));
870
+ _state.label = 5;
871
+ case 5:
872
+ return [
508
873
  2
509
874
  ];
510
875
  }
@@ -528,7 +893,7 @@ var Keymaster = /*#__PURE__*/ function() {
528
893
  ];
529
894
  return [
530
895
  4,
531
- _this.start()
896
+ _this.startInternal()
532
897
  ];
533
898
  case 1:
534
899
  _tmp = _state.sent();
@@ -546,8 +911,8 @@ var Keymaster = /*#__PURE__*/ function() {
546
911
  {
547
912
  key: "validateConfig",
548
913
  value: function validateConfig(config) {
549
- if (config.gatekeeperConfig && config.keymasterConfig) {
550
- throw new Error("Cannot provide both a Gatekeeper and Keymaster config");
914
+ if (!config.gatekeeperConfig) {
915
+ throw new Error("Missing Gatekeeper config");
551
916
  }
552
917
  if (config.gatekeeperConfig) {
553
918
  var _config_walletDb, _config_walletDb1;
@@ -563,8 +928,703 @@ var Keymaster = /*#__PURE__*/ function() {
563
928
  }
564
929
  }
565
930
  }
931
+ ], [
932
+ {
933
+ key: "initialize",
934
+ value: function initialize(config) {
935
+ if (!_Keymaster.instance) {
936
+ _Keymaster.instance = new _Keymaster(config);
937
+ console.log("\u2705 Keymaster initialized");
938
+ } else {
939
+ console.warn("Keymaster already initialized, ignoring re-initialization.");
940
+ }
941
+ }
942
+ },
943
+ {
944
+ key: "start",
945
+ value: // Delegated STATIC methods
946
+ function start() {
947
+ return _async_to_generator(function() {
948
+ return _ts_generator(this, function(_state) {
949
+ _Keymaster.getInstance().ensureInitialized();
950
+ return [
951
+ 2,
952
+ _Keymaster.getInstance().startInternal()
953
+ ];
954
+ });
955
+ })();
956
+ }
957
+ },
958
+ {
959
+ key: "createChallenge",
960
+ value: function createChallenge() {
961
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
962
+ args[_key] = arguments[_key];
963
+ }
964
+ return _async_to_generator(function() {
965
+ var _Keymaster_getInstance;
966
+ return _ts_generator(this, function(_state) {
967
+ _Keymaster.getInstance().ensureInitialized();
968
+ return [
969
+ 2,
970
+ (_Keymaster_getInstance = _Keymaster.getInstance()).createChallengeInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
971
+ ];
972
+ });
973
+ })();
974
+ }
975
+ },
976
+ {
977
+ key: "bindCredential",
978
+ value: function bindCredential() {
979
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
980
+ args[_key] = arguments[_key];
981
+ }
982
+ return _async_to_generator(function() {
983
+ var _Keymaster_getInstance;
984
+ return _ts_generator(this, function(_state) {
985
+ _Keymaster.getInstance().ensureInitialized();
986
+ return [
987
+ 2,
988
+ (_Keymaster_getInstance = _Keymaster.getInstance()).bindCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
989
+ ];
990
+ });
991
+ })();
992
+ }
993
+ },
994
+ {
995
+ key: "issueCredential",
996
+ value: function issueCredential() {
997
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
998
+ args[_key] = arguments[_key];
999
+ }
1000
+ return _async_to_generator(function() {
1001
+ var _Keymaster_getInstance;
1002
+ return _ts_generator(this, function(_state) {
1003
+ _Keymaster.getInstance().ensureInitialized();
1004
+ return [
1005
+ 2,
1006
+ (_Keymaster_getInstance = _Keymaster.getInstance()).issueCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1007
+ ];
1008
+ });
1009
+ })();
1010
+ }
1011
+ },
1012
+ {
1013
+ key: "publishCredential",
1014
+ value: function publishCredential() {
1015
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1016
+ args[_key] = arguments[_key];
1017
+ }
1018
+ return _async_to_generator(function() {
1019
+ var _Keymaster_getInstance;
1020
+ return _ts_generator(this, function(_state) {
1021
+ _Keymaster.getInstance().ensureInitialized();
1022
+ return [
1023
+ 2,
1024
+ (_Keymaster_getInstance = _Keymaster.getInstance()).publishCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1025
+ ];
1026
+ });
1027
+ })();
1028
+ }
1029
+ },
1030
+ {
1031
+ key: "acceptCredential",
1032
+ value: function acceptCredential() {
1033
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1034
+ args[_key] = arguments[_key];
1035
+ }
1036
+ return _async_to_generator(function() {
1037
+ var _Keymaster_getInstance;
1038
+ return _ts_generator(this, function(_state) {
1039
+ _Keymaster.getInstance().ensureInitialized();
1040
+ return [
1041
+ 2,
1042
+ (_Keymaster_getInstance = _Keymaster.getInstance()).acceptCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1043
+ ];
1044
+ });
1045
+ })();
1046
+ }
1047
+ },
1048
+ {
1049
+ key: "showMnemonic",
1050
+ value: function showMnemonic() {
1051
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1052
+ args[_key] = arguments[_key];
1053
+ }
1054
+ return _async_to_generator(function() {
1055
+ var _Keymaster_getInstance;
1056
+ return _ts_generator(this, function(_state) {
1057
+ _Keymaster.getInstance().ensureInitialized();
1058
+ return [
1059
+ 2,
1060
+ (_Keymaster_getInstance = _Keymaster.getInstance()).showMnemonicInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1061
+ ];
1062
+ });
1063
+ })();
1064
+ }
1065
+ },
1066
+ {
1067
+ key: "verifyResponse",
1068
+ value: function verifyResponse() {
1069
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1070
+ args[_key] = arguments[_key];
1071
+ }
1072
+ return _async_to_generator(function() {
1073
+ var _Keymaster_getInstance;
1074
+ return _ts_generator(this, function(_state) {
1075
+ _Keymaster.getInstance().ensureInitialized();
1076
+ return [
1077
+ 2,
1078
+ (_Keymaster_getInstance = _Keymaster.getInstance()).verifyResponseInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1079
+ ];
1080
+ });
1081
+ })();
1082
+ }
1083
+ },
1084
+ {
1085
+ key: "decryptMessage",
1086
+ value: function decryptMessage() {
1087
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1088
+ args[_key] = arguments[_key];
1089
+ }
1090
+ return _async_to_generator(function() {
1091
+ var _Keymaster_getInstance;
1092
+ return _ts_generator(this, function(_state) {
1093
+ _Keymaster.getInstance().ensureInitialized();
1094
+ return [
1095
+ 2,
1096
+ (_Keymaster_getInstance = _Keymaster.getInstance()).decryptMessageInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1097
+ ];
1098
+ });
1099
+ })();
1100
+ }
1101
+ },
1102
+ {
1103
+ key: "decryptMnemonic",
1104
+ value: function decryptMnemonic() {
1105
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1106
+ args[_key] = arguments[_key];
1107
+ }
1108
+ return _async_to_generator(function() {
1109
+ var _Keymaster_getInstance;
1110
+ return _ts_generator(this, function(_state) {
1111
+ _Keymaster.getInstance().ensureInitialized();
1112
+ return [
1113
+ 2,
1114
+ (_Keymaster_getInstance = _Keymaster.getInstance()).decryptMnemonicInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1115
+ ];
1116
+ });
1117
+ })();
1118
+ }
1119
+ },
1120
+ {
1121
+ key: "getCredential",
1122
+ value: function getCredential() {
1123
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1124
+ args[_key] = arguments[_key];
1125
+ }
1126
+ return _async_to_generator(function() {
1127
+ var _Keymaster_getInstance;
1128
+ return _ts_generator(this, function(_state) {
1129
+ _Keymaster.getInstance().ensureInitialized();
1130
+ return [
1131
+ 2,
1132
+ (_Keymaster_getInstance = _Keymaster.getInstance()).getCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1133
+ ];
1134
+ });
1135
+ })();
1136
+ }
1137
+ },
1138
+ {
1139
+ key: "removeCredential",
1140
+ value: function removeCredential() {
1141
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1142
+ args[_key] = arguments[_key];
1143
+ }
1144
+ return _async_to_generator(function() {
1145
+ var _Keymaster_getInstance;
1146
+ return _ts_generator(this, function(_state) {
1147
+ _Keymaster.getInstance().ensureInitialized();
1148
+ return [
1149
+ 2,
1150
+ (_Keymaster_getInstance = _Keymaster.getInstance()).removeCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1151
+ ];
1152
+ });
1153
+ })();
1154
+ }
1155
+ },
1156
+ {
1157
+ key: "updateCredential",
1158
+ value: function updateCredential() {
1159
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1160
+ args[_key] = arguments[_key];
1161
+ }
1162
+ return _async_to_generator(function() {
1163
+ var _Keymaster_getInstance;
1164
+ return _ts_generator(this, function(_state) {
1165
+ _Keymaster.getInstance().ensureInitialized();
1166
+ return [
1167
+ 2,
1168
+ (_Keymaster_getInstance = _Keymaster.getInstance()).updateCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1169
+ ];
1170
+ });
1171
+ })();
1172
+ }
1173
+ },
1174
+ {
1175
+ key: "createId",
1176
+ value: function createId() {
1177
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1178
+ args[_key] = arguments[_key];
1179
+ }
1180
+ return _async_to_generator(function() {
1181
+ var _Keymaster_getInstance;
1182
+ return _ts_generator(this, function(_state) {
1183
+ _Keymaster.getInstance().ensureInitialized();
1184
+ return [
1185
+ 2,
1186
+ (_Keymaster_getInstance = _Keymaster.getInstance()).createIdInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1187
+ ];
1188
+ });
1189
+ })();
1190
+ }
1191
+ },
1192
+ {
1193
+ key: "removeId",
1194
+ value: function removeId() {
1195
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1196
+ args[_key] = arguments[_key];
1197
+ }
1198
+ return _async_to_generator(function() {
1199
+ var _Keymaster_getInstance;
1200
+ return _ts_generator(this, function(_state) {
1201
+ _Keymaster.getInstance().ensureInitialized();
1202
+ return [
1203
+ 2,
1204
+ (_Keymaster_getInstance = _Keymaster.getInstance()).removeIdInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1205
+ ];
1206
+ });
1207
+ })();
1208
+ }
1209
+ },
1210
+ {
1211
+ key: "resolveDID",
1212
+ value: function resolveDID() {
1213
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1214
+ args[_key] = arguments[_key];
1215
+ }
1216
+ return _async_to_generator(function() {
1217
+ var _Keymaster_getInstance;
1218
+ return _ts_generator(this, function(_state) {
1219
+ _Keymaster.getInstance().ensureInitialized();
1220
+ return [
1221
+ 2,
1222
+ (_Keymaster_getInstance = _Keymaster.getInstance()).resolveDIDInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1223
+ ];
1224
+ });
1225
+ })();
1226
+ }
1227
+ },
1228
+ {
1229
+ key: "setCurrentId",
1230
+ value: function setCurrentId() {
1231
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1232
+ args[_key] = arguments[_key];
1233
+ }
1234
+ return _async_to_generator(function() {
1235
+ var _Keymaster_getInstance;
1236
+ return _ts_generator(this, function(_state) {
1237
+ _Keymaster.getInstance().ensureInitialized();
1238
+ return [
1239
+ 2,
1240
+ (_Keymaster_getInstance = _Keymaster.getInstance()).setCurrentIdInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1241
+ ];
1242
+ });
1243
+ })();
1244
+ }
1245
+ },
1246
+ {
1247
+ key: "createSchema",
1248
+ value: function createSchema() {
1249
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1250
+ args[_key] = arguments[_key];
1251
+ }
1252
+ return _async_to_generator(function() {
1253
+ var _Keymaster_getInstance;
1254
+ return _ts_generator(this, function(_state) {
1255
+ _Keymaster.getInstance().ensureInitialized();
1256
+ return [
1257
+ 2,
1258
+ (_Keymaster_getInstance = _Keymaster.getInstance()).createSchemaInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1259
+ ];
1260
+ });
1261
+ })();
1262
+ }
1263
+ },
1264
+ {
1265
+ key: "newWallet",
1266
+ value: function newWallet() {
1267
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1268
+ args[_key] = arguments[_key];
1269
+ }
1270
+ return _async_to_generator(function() {
1271
+ var _Keymaster_getInstance;
1272
+ return _ts_generator(this, function(_state) {
1273
+ _Keymaster.getInstance().ensureInitialized();
1274
+ return [
1275
+ 2,
1276
+ (_Keymaster_getInstance = _Keymaster.getInstance()).newWalletInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1277
+ ];
1278
+ });
1279
+ })();
1280
+ }
1281
+ },
1282
+ {
1283
+ key: "recoverWallet",
1284
+ value: function recoverWallet() {
1285
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1286
+ args[_key] = arguments[_key];
1287
+ }
1288
+ return _async_to_generator(function() {
1289
+ var _Keymaster_getInstance;
1290
+ return _ts_generator(this, function(_state) {
1291
+ _Keymaster.getInstance().ensureInitialized();
1292
+ return [
1293
+ 2,
1294
+ (_Keymaster_getInstance = _Keymaster.getInstance()).recoverWalletInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1295
+ ];
1296
+ });
1297
+ })();
1298
+ }
1299
+ },
1300
+ {
1301
+ key: "getInstance",
1302
+ value: function getInstance() {
1303
+ if (!_Keymaster.instance) {
1304
+ throw new Error("Keymaster not initialized. Call Keymaster.initialize() first.");
1305
+ }
1306
+ return _Keymaster.instance;
1307
+ }
1308
+ }
1309
+ ]);
1310
+ return _Keymaster;
1311
+ }();
1312
+ _Keymaster.instance = null;
1313
+ var Keymaster = _Keymaster;
1314
+ // src/keymasterClient.ts
1315
+ import KeymasterClient from "@mdip/keymaster/client";
1316
+ var KeymasterExternalClient = /*#__PURE__*/ function() {
1317
+ "use strict";
1318
+ function KeymasterExternalClient(config) {
1319
+ _class_call_check(this, KeymasterExternalClient);
1320
+ this.serviceStarted = false;
1321
+ this.validateConfig(config);
1322
+ this.config = config;
1323
+ }
1324
+ _create_class(KeymasterExternalClient, [
1325
+ {
1326
+ key: "start",
1327
+ value: function start() {
1328
+ var _this = this;
1329
+ return _async_to_generator(function() {
1330
+ return _ts_generator(this, function(_state) {
1331
+ switch(_state.label){
1332
+ case 0:
1333
+ if (!_this.config.keymasterConfig) return [
1334
+ 3,
1335
+ 2
1336
+ ];
1337
+ return [
1338
+ 4,
1339
+ _this.startExternalKeymaster()
1340
+ ];
1341
+ case 1:
1342
+ _this.serviceStarted = _state.sent();
1343
+ return [
1344
+ 3,
1345
+ 3
1346
+ ];
1347
+ case 2:
1348
+ throw "Missing Keymaster config";
1349
+ case 3:
1350
+ return [
1351
+ 2,
1352
+ _this.serviceStarted
1353
+ ];
1354
+ }
1355
+ });
1356
+ })();
1357
+ }
1358
+ },
1359
+ {
1360
+ key: "startExternal",
1361
+ value: function startExternal() {
1362
+ var _this = this;
1363
+ return _async_to_generator(function() {
1364
+ return _ts_generator(this, function(_state) {
1365
+ switch(_state.label){
1366
+ case 0:
1367
+ if (!_this.config.keymasterConfig) return [
1368
+ 3,
1369
+ 2
1370
+ ];
1371
+ return [
1372
+ 4,
1373
+ _this.startExternalKeymaster()
1374
+ ];
1375
+ case 1:
1376
+ _this.serviceStarted = _state.sent();
1377
+ return [
1378
+ 3,
1379
+ 3
1380
+ ];
1381
+ case 2:
1382
+ throw "Missing Gatekeeper or Keymaster config";
1383
+ case 3:
1384
+ return [
1385
+ 2,
1386
+ _this.serviceStarted
1387
+ ];
1388
+ }
1389
+ });
1390
+ })();
1391
+ }
1392
+ },
1393
+ {
1394
+ key: "startExternalKeymaster",
1395
+ value: function startExternalKeymaster() {
1396
+ var _this = this;
1397
+ return _async_to_generator(function() {
1398
+ var e;
1399
+ return _ts_generator(this, function(_state) {
1400
+ switch(_state.label){
1401
+ case 0:
1402
+ console.log("Starting external Keymaster service");
1403
+ _state.label = 1;
1404
+ case 1:
1405
+ _state.trys.push([
1406
+ 1,
1407
+ 3,
1408
+ ,
1409
+ 4
1410
+ ]);
1411
+ _this.keymasterService = new KeymasterClient();
1412
+ return [
1413
+ 4,
1414
+ _this.keymasterService.connect(_this.config.keymasterConfig)
1415
+ ];
1416
+ case 2:
1417
+ _state.sent();
1418
+ return [
1419
+ 3,
1420
+ 4
1421
+ ];
1422
+ case 3:
1423
+ e = _state.sent();
1424
+ console.error("Error starting Keymaster service:", e);
1425
+ return [
1426
+ 2,
1427
+ false
1428
+ ];
1429
+ case 4:
1430
+ console.log("Started external Keymaster service");
1431
+ return [
1432
+ 2,
1433
+ true
1434
+ ];
1435
+ }
1436
+ });
1437
+ })();
1438
+ }
1439
+ },
1440
+ {
1441
+ key: "createChallenge",
1442
+ value: function createChallenge(spec, options) {
1443
+ var _this = this;
1444
+ return _async_to_generator(function() {
1445
+ var _this_keymasterService, challenge;
1446
+ return _ts_generator(this, function(_state) {
1447
+ switch(_state.label){
1448
+ case 0:
1449
+ if (!_this.serviceRunning()) {
1450
+ throw new Error("Keymaster service not running");
1451
+ }
1452
+ return [
1453
+ 4,
1454
+ (_this_keymasterService = _this.keymasterService) === null || _this_keymasterService === void 0 ? void 0 : _this_keymasterService.createChallenge(spec, options)
1455
+ ];
1456
+ case 1:
1457
+ challenge = _state.sent();
1458
+ return [
1459
+ 2,
1460
+ {
1461
+ challenge: challenge,
1462
+ challengeUrl: "".concat(spec.callback, "?challenge=").concat(challenge)
1463
+ }
1464
+ ];
1465
+ }
1466
+ });
1467
+ })();
1468
+ }
1469
+ },
1470
+ {
1471
+ key: "bindCredential",
1472
+ value: function bindCredential(schemaId, subjectId) {
1473
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1474
+ var _this = this;
1475
+ return _async_to_generator(function() {
1476
+ return _ts_generator(this, function(_state) {
1477
+ if (!_this.serviceRunning()) {
1478
+ throw new Error("Keymaster service not running");
1479
+ }
1480
+ return [
1481
+ 2,
1482
+ _this.keymasterService.bindCredential(schemaId, subjectId, options)
1483
+ ];
1484
+ });
1485
+ })();
1486
+ }
1487
+ },
1488
+ {
1489
+ key: "issueCredential",
1490
+ value: function issueCredential(credential) {
1491
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1492
+ var _this = this;
1493
+ return _async_to_generator(function() {
1494
+ return _ts_generator(this, function(_state) {
1495
+ if (!_this.serviceRunning()) {
1496
+ throw new Error("Keymaster service not running");
1497
+ }
1498
+ return [
1499
+ 2,
1500
+ _this.keymasterService.issueCredential(credential, options)
1501
+ ];
1502
+ });
1503
+ })();
1504
+ }
1505
+ },
1506
+ {
1507
+ key: "publishCredential",
1508
+ value: function publishCredential(did) {
1509
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1510
+ var _this = this;
1511
+ return _async_to_generator(function() {
1512
+ return _ts_generator(this, function(_state) {
1513
+ if (!_this.serviceRunning()) {
1514
+ throw new Error("Keymaster service not running");
1515
+ }
1516
+ return [
1517
+ 2,
1518
+ _this.keymasterService.publishCredential(did, options)
1519
+ ];
1520
+ });
1521
+ })();
1522
+ }
1523
+ },
1524
+ {
1525
+ key: "acceptCredential",
1526
+ value: function acceptCredential(did) {
1527
+ var _this = this;
1528
+ return _async_to_generator(function() {
1529
+ return _ts_generator(this, function(_state) {
1530
+ if (!_this.serviceRunning()) {
1531
+ throw new Error("Keymaster service not running");
1532
+ }
1533
+ return [
1534
+ 2,
1535
+ _this.keymasterService.acceptCredential(did)
1536
+ ];
1537
+ });
1538
+ })();
1539
+ }
1540
+ },
1541
+ {
1542
+ key: "showMnemonic",
1543
+ value: function showMnemonic() {
1544
+ var _this = this;
1545
+ return _async_to_generator(function() {
1546
+ return _ts_generator(this, function(_state) {
1547
+ if (!_this.serviceRunning()) {
1548
+ throw new Error("Keymaster service not running");
1549
+ }
1550
+ return [
1551
+ 2,
1552
+ _this.keymasterService.decryptMnemonic()
1553
+ ];
1554
+ });
1555
+ })();
1556
+ }
1557
+ },
1558
+ {
1559
+ key: "verifyResponse",
1560
+ value: function verifyResponse(did, options) {
1561
+ var _this = this;
1562
+ return _async_to_generator(function() {
1563
+ var response;
1564
+ return _ts_generator(this, function(_state) {
1565
+ switch(_state.label){
1566
+ case 0:
1567
+ if (!_this.serviceRunning()) {
1568
+ throw new Error("Keymaster service not running");
1569
+ }
1570
+ return [
1571
+ 4,
1572
+ _this.keymasterService.verifyResponse(did, options)
1573
+ ];
1574
+ case 1:
1575
+ response = _state.sent();
1576
+ return [
1577
+ 2,
1578
+ response
1579
+ ];
1580
+ }
1581
+ });
1582
+ })();
1583
+ }
1584
+ },
1585
+ {
1586
+ key: "serviceRunning",
1587
+ value: function serviceRunning() {
1588
+ var _this = this;
1589
+ return _async_to_generator(function() {
1590
+ var _tmp;
1591
+ return _ts_generator(this, function(_state) {
1592
+ switch(_state.label){
1593
+ case 0:
1594
+ _tmp = _this.serviceStarted;
1595
+ if (_tmp) return [
1596
+ 3,
1597
+ 2
1598
+ ];
1599
+ return [
1600
+ 4,
1601
+ _this.start()
1602
+ ];
1603
+ case 1:
1604
+ _tmp = _state.sent();
1605
+ _state.label = 2;
1606
+ case 2:
1607
+ return [
1608
+ 2,
1609
+ _tmp
1610
+ ];
1611
+ }
1612
+ });
1613
+ })();
1614
+ }
1615
+ },
1616
+ {
1617
+ key: "validateConfig",
1618
+ value: function validateConfig(config) {
1619
+ if (!config.keymasterConfig) {
1620
+ throw new Error("Missing Keymaster config");
1621
+ }
1622
+ }
1623
+ }
566
1624
  ]);
567
- return Keymaster;
1625
+ return KeymasterExternalClient;
568
1626
  }();
569
- export { Keymaster };
1627
+ // src/index.ts
1628
+ export * from "@mdip/keymaster/types";
1629
+ export { Keymaster, KeymasterExternalClient };
570
1630
  //# sourceMappingURL=index.js.map