@yourself_id/siwys-api-js 0.10.1-SAPP-221-mdipUpdate.4 → 0.10.1-SAPP-221-mdipUpdate.5

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.cjs CHANGED
@@ -1,1819 +1,441 @@
1
1
  "use strict";
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
- }
10
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
- try {
12
- var info = gen[key](arg);
13
- var value = info.value;
14
- } catch (error) {
15
- reject(error);
16
- return;
17
- }
18
- if (info.done) {
19
- resolve(value);
20
- } else {
21
- Promise.resolve(value).then(_next, _throw);
22
- }
23
- }
24
- function _async_to_generator(fn) {
25
- return function() {
26
- var self = this, args = arguments;
27
- return new Promise(function(resolve, reject) {
28
- var gen = fn.apply(self, args);
29
- function _next(value) {
30
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
31
- }
32
- function _throw(err) {
33
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
34
- }
35
- _next(undefined);
36
- });
37
- };
38
- }
39
- function _class_call_check(instance, Constructor) {
40
- if (!(instance instanceof Constructor)) {
41
- throw new TypeError("Cannot call a class as a function");
42
- }
43
- }
44
- function _defineProperties(target, props) {
45
- for(var i = 0; i < props.length; i++){
46
- var descriptor = props[i];
47
- descriptor.enumerable = descriptor.enumerable || false;
48
- descriptor.configurable = true;
49
- if ("value" in descriptor) descriptor.writable = true;
50
- Object.defineProperty(target, descriptor.key, descriptor);
51
- }
52
- }
53
- function _create_class(Constructor, protoProps, staticProps) {
54
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
55
- if (staticProps) _defineProperties(Constructor, staticProps);
56
- return Constructor;
57
- }
58
- function _define_property(obj, key, value) {
59
- if (key in obj) {
60
- Object.defineProperty(obj, key, {
61
- value: value,
62
- enumerable: true,
63
- configurable: true,
64
- writable: true
65
- });
66
- } else {
67
- obj[key] = value;
68
- }
69
- return obj;
70
- }
71
- function _iterable_to_array(iter) {
72
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
73
- }
74
- function _non_iterable_spread() {
75
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
76
- }
77
- function _object_spread(target) {
78
- for(var i = 1; i < arguments.length; i++){
79
- var source = arguments[i] != null ? arguments[i] : {};
80
- var ownKeys = Object.keys(source);
81
- if (typeof Object.getOwnPropertySymbols === "function") {
82
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
83
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
84
- }));
85
- }
86
- ownKeys.forEach(function(key) {
87
- _define_property(target, key, source[key]);
88
- });
89
- }
90
- return target;
91
- }
92
- function _to_consumable_array(arr) {
93
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
94
- }
95
- function _type_of(obj) {
96
- "@swc/helpers - typeof";
97
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
98
- }
99
- function _unsupported_iterable_to_array(o, minLen) {
100
- if (!o) return;
101
- if (typeof o === "string") return _array_like_to_array(o, minLen);
102
- var n = Object.prototype.toString.call(o).slice(8, -1);
103
- if (n === "Object" && o.constructor) n = o.constructor.name;
104
- if (n === "Map" || n === "Set") return Array.from(n);
105
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
106
- }
107
- function _ts_generator(thisArg, body) {
108
- var f, y, t, g, _ = {
109
- label: 0,
110
- sent: function() {
111
- if (t[0] & 1) throw t[1];
112
- return t[1];
113
- },
114
- trys: [],
115
- ops: []
116
- };
117
- return g = {
118
- next: verb(0),
119
- "throw": verb(1),
120
- "return": verb(2)
121
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
122
- return this;
123
- }), g;
124
- function verb(n) {
125
- return function(v) {
126
- return step([
127
- n,
128
- v
129
- ]);
130
- };
131
- }
132
- function step(op) {
133
- if (f) throw new TypeError("Generator is already executing.");
134
- while(_)try {
135
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
136
- if (y = 0, t) op = [
137
- op[0] & 2,
138
- t.value
139
- ];
140
- switch(op[0]){
141
- case 0:
142
- case 1:
143
- t = op;
144
- break;
145
- case 4:
146
- _.label++;
147
- return {
148
- value: op[1],
149
- done: false
150
- };
151
- case 5:
152
- _.label++;
153
- y = op[1];
154
- op = [
155
- 0
156
- ];
157
- continue;
158
- case 7:
159
- op = _.ops.pop();
160
- _.trys.pop();
161
- continue;
162
- default:
163
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
164
- _ = 0;
165
- continue;
166
- }
167
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
168
- _.label = op[1];
169
- break;
170
- }
171
- if (op[0] === 6 && _.label < t[1]) {
172
- _.label = t[1];
173
- t = op;
174
- break;
175
- }
176
- if (t && _.label < t[2]) {
177
- _.label = t[2];
178
- _.ops.push(op);
179
- break;
180
- }
181
- if (t[2]) _.ops.pop();
182
- _.trys.pop();
183
- continue;
184
- }
185
- op = body.call(thisArg, _);
186
- } catch (e) {
187
- op = [
188
- 6,
189
- e
190
- ];
191
- y = 0;
192
- } finally{
193
- f = t = 0;
194
- }
195
- if (op[0] & 5) throw op[1];
196
- return {
197
- value: op[0] ? op[1] : void 0,
198
- done: true
199
- };
200
- }
201
- }
202
2
  var __create = Object.create;
203
3
  var __defProp = Object.defineProperty;
204
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
205
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
206
6
  var __getProtoOf = Object.getPrototypeOf;
207
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
208
- var __export = function(target, all) {
209
- for(var name in all)__defProp(target, name, {
210
- get: all[name],
211
- enumerable: true
212
- });
213
- };
214
- var __copyProps = function(to, from, except, desc) {
215
- if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
216
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
217
- try {
218
- var _loop = function() {
219
- var key = _step.value;
220
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
221
- get: function() {
222
- return from[key];
223
- },
224
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
225
- });
226
- };
227
- for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
228
- } catch (err) {
229
- _didIteratorError = true;
230
- _iteratorError = err;
231
- } finally{
232
- try {
233
- if (!_iteratorNormalCompletion && _iterator.return != null) {
234
- _iterator.return();
235
- }
236
- } finally{
237
- if (_didIteratorError) {
238
- throw _iteratorError;
239
- }
240
- }
241
- }
242
- }
243
- return to;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
244
11
  };
245
- var __reExport = function(target, mod, secondTarget) {
246
- return __copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default");
247
- };
248
- var __toESM = function(mod, isNodeMode, target) {
249
- return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
250
- // file that has been converted to a CommonJS file using a Babel-
251
- // compatible transform (i.e. "__esModule" has not been set), then set
252
- // "default" to the CommonJS "module.exports" for node compatibility.
253
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
254
- value: mod,
255
- enumerable: true
256
- }) : target, mod);
257
- };
258
- var __toCommonJS = function(mod) {
259
- return __copyProps(__defProp({}, "__esModule", {
260
- value: true
261
- }), mod);
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
262
19
  };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
263
31
  // src/index.ts
264
32
  var src_exports = {};
265
33
  __export(src_exports, {
266
- Keymaster: function() {
267
- return Keymaster;
268
- },
269
- KeymasterExternalClient: function() {
270
- return KeymasterExternalClient;
271
- }
34
+ Keymaster: () => Keymaster,
35
+ KeymasterExternalClient: () => KeymasterExternalClient
272
36
  });
273
37
  module.exports = __toCommonJS(src_exports);
38
+
274
39
  // src/keymaster.ts
275
40
  var import_client = __toESM(require("@mdip/gatekeeper/client"), 1);
276
41
  var import_node = __toESM(require("@mdip/cipher/node"), 1);
277
42
  var import_keymaster = __toESM(require("@mdip/keymaster"), 1);
278
- var _Keymaster = /*#__PURE__*/ function() {
279
- function _Keymaster(config) {
280
- _class_call_check(this, _Keymaster);
281
- this.serviceStarted = false;
282
- this.validateConfig(config);
283
- this.config = config;
43
+ var Keymaster = class _Keymaster {
44
+ static instance = null;
45
+ config;
46
+ keymasterService;
47
+ serviceStarted = false;
48
+ constructor(config) {
49
+ this.validateConfig(config);
50
+ this.config = config;
51
+ }
52
+ static initialize(config) {
53
+ if (!_Keymaster.instance) {
54
+ _Keymaster.instance = new _Keymaster(config);
55
+ console.log("\u2705 Keymaster initialized");
56
+ } else {
57
+ console.warn(
58
+ "Keymaster already initialized, ignoring re-initialization."
59
+ );
60
+ }
61
+ }
62
+ ensureInitialized() {
63
+ if (!_Keymaster.instance) {
64
+ throw new Error(
65
+ "Keymaster not initialized. Call Keymaster.initialize() first."
66
+ );
67
+ }
68
+ }
69
+ // Delegated STATIC methods
70
+ static async start() {
71
+ _Keymaster.getInstance().ensureInitialized();
72
+ return _Keymaster.getInstance().startInternal();
73
+ }
74
+ static async createChallenge(...args) {
75
+ _Keymaster.getInstance().ensureInitialized();
76
+ return _Keymaster.getInstance().createChallengeInternal(...args);
77
+ }
78
+ static async bindCredential(...args) {
79
+ _Keymaster.getInstance().ensureInitialized();
80
+ return _Keymaster.getInstance().bindCredentialInternal(...args);
81
+ }
82
+ static async backupWallet(...args) {
83
+ _Keymaster.getInstance().ensureInitialized();
84
+ return _Keymaster.getInstance().backupWalletInternal(...args);
85
+ }
86
+ static async createResponse(...args) {
87
+ _Keymaster.getInstance().ensureInitialized();
88
+ return _Keymaster.getInstance().createResponseInternal(...args);
89
+ }
90
+ static async issueCredential(...args) {
91
+ _Keymaster.getInstance().ensureInitialized();
92
+ return _Keymaster.getInstance().issueCredentialInternal(...args);
93
+ }
94
+ static async publishCredential(...args) {
95
+ _Keymaster.getInstance().ensureInitialized();
96
+ return _Keymaster.getInstance().publishCredentialInternal(...args);
97
+ }
98
+ static async acceptCredential(...args) {
99
+ _Keymaster.getInstance().ensureInitialized();
100
+ return _Keymaster.getInstance().acceptCredentialInternal(...args);
101
+ }
102
+ static async showMnemonic(...args) {
103
+ _Keymaster.getInstance().ensureInitialized();
104
+ return _Keymaster.getInstance().showMnemonicInternal(...args);
105
+ }
106
+ static async verifyResponse(...args) {
107
+ _Keymaster.getInstance().ensureInitialized();
108
+ return _Keymaster.getInstance().verifyResponseInternal(...args);
109
+ }
110
+ static async decryptMessage(...args) {
111
+ _Keymaster.getInstance().ensureInitialized();
112
+ return _Keymaster.getInstance().decryptMessageInternal(...args);
113
+ }
114
+ static async decryptMnemonic(...args) {
115
+ _Keymaster.getInstance().ensureInitialized();
116
+ return _Keymaster.getInstance().decryptMnemonicInternal(...args);
117
+ }
118
+ static async getCredential(...args) {
119
+ _Keymaster.getInstance().ensureInitialized();
120
+ return _Keymaster.getInstance().getCredentialInternal(...args);
121
+ }
122
+ static async removeCredential(...args) {
123
+ _Keymaster.getInstance().ensureInitialized();
124
+ return _Keymaster.getInstance().removeCredentialInternal(...args);
125
+ }
126
+ static async updateCredential(...args) {
127
+ _Keymaster.getInstance().ensureInitialized();
128
+ return _Keymaster.getInstance().updateCredentialInternal(...args);
129
+ }
130
+ static async createId(...args) {
131
+ _Keymaster.getInstance().ensureInitialized();
132
+ return _Keymaster.getInstance().createIdInternal(...args);
133
+ }
134
+ static async removeId(...args) {
135
+ _Keymaster.getInstance().ensureInitialized();
136
+ return _Keymaster.getInstance().removeIdInternal(...args);
137
+ }
138
+ static async resolveDID(...args) {
139
+ _Keymaster.getInstance().ensureInitialized();
140
+ return _Keymaster.getInstance().resolveDIDInternal(...args);
141
+ }
142
+ static async setCurrentId(...args) {
143
+ _Keymaster.getInstance().ensureInitialized();
144
+ return _Keymaster.getInstance().setCurrentIdInternal(...args);
145
+ }
146
+ static async createSchema(...args) {
147
+ _Keymaster.getInstance().ensureInitialized();
148
+ return _Keymaster.getInstance().createSchemaInternal(...args);
149
+ }
150
+ static async newWallet(...args) {
151
+ _Keymaster.getInstance().ensureInitialized();
152
+ return _Keymaster.getInstance().newWalletInternal(...args);
153
+ }
154
+ static async recoverWallet(...args) {
155
+ _Keymaster.getInstance().ensureInitialized();
156
+ return _Keymaster.getInstance().recoverWalletInternal(...args);
157
+ }
158
+ static getInstance() {
159
+ if (!_Keymaster.instance) {
160
+ throw new Error(
161
+ "Keymaster not initialized. Call Keymaster.initialize() first."
162
+ );
163
+ }
164
+ return _Keymaster.instance;
165
+ }
166
+ // -------- Internal instance methods (originals renamed with Internal) -------
167
+ async ensureServiceIsRunning() {
168
+ if (!await this.serviceRunning()) {
169
+ throw new Error("Keymaster service not running");
170
+ }
171
+ }
172
+ async startInternal() {
173
+ if (this.config.gatekeeperConfig) {
174
+ this.serviceStarted = await this.startIntegratedKeymaster();
175
+ } else {
176
+ throw "Missing Gatekeeper config";
284
177
  }
285
- _create_class(_Keymaster, [
286
- {
287
- key: "ensureInitialized",
288
- value: function ensureInitialized() {
289
- if (!_Keymaster.instance) {
290
- throw new Error("Keymaster not initialized. Call Keymaster.initialize() first.");
291
- }
292
- }
293
- },
294
- {
295
- key: "ensureServiceIsRunning",
296
- value: // -------- Internal instance methods (originals renamed with Internal) -------
297
- function ensureServiceIsRunning() {
298
- var _this = this;
299
- return _async_to_generator(function() {
300
- return _ts_generator(this, function(_state) {
301
- switch(_state.label){
302
- case 0:
303
- return [
304
- 4,
305
- _this.serviceRunning()
306
- ];
307
- case 1:
308
- if (!_state.sent()) {
309
- throw new Error("Keymaster service not running");
310
- }
311
- return [
312
- 2
313
- ];
314
- }
315
- });
316
- })();
317
- }
318
- },
319
- {
320
- key: "startInternal",
321
- value: function startInternal() {
322
- var _this = this;
323
- return _async_to_generator(function() {
324
- return _ts_generator(this, function(_state) {
325
- switch(_state.label){
326
- case 0:
327
- if (!_this.config.gatekeeperConfig) return [
328
- 3,
329
- 2
330
- ];
331
- return [
332
- 4,
333
- _this.startIntegratedKeymaster()
334
- ];
335
- case 1:
336
- _this.serviceStarted = _state.sent();
337
- return [
338
- 3,
339
- 3
340
- ];
341
- case 2:
342
- throw "Missing Gatekeeper config";
343
- case 3:
344
- return [
345
- 2,
346
- _this.serviceStarted
347
- ];
348
- }
349
- });
350
- })();
351
- }
352
- },
353
- {
354
- key: "startIntegratedKeymaster",
355
- value: function startIntegratedKeymaster() {
356
- var _this = this;
357
- return _async_to_generator(function() {
358
- var gatekeeper, cipher, e;
359
- return _ts_generator(this, function(_state) {
360
- switch(_state.label){
361
- case 0:
362
- console.log("Starting integrated Keymaster service");
363
- _state.label = 1;
364
- case 1:
365
- _state.trys.push([
366
- 1,
367
- 6,
368
- ,
369
- 7
370
- ]);
371
- if (!_this.config.walletDb) return [
372
- 3,
373
- 4
374
- ];
375
- gatekeeper = new import_client.default();
376
- return [
377
- 4,
378
- gatekeeper.connect(_this.config.gatekeeperConfig)
379
- ];
380
- case 2:
381
- _state.sent();
382
- cipher = new import_node.default();
383
- _this.keymasterService = new import_keymaster.default({
384
- gatekeeper: gatekeeper,
385
- wallet: _this.config.walletDb,
386
- cipher: cipher
387
- });
388
- return [
389
- 4,
390
- _this.ensureWalletExists()
391
- ];
392
- case 3:
393
- _state.sent();
394
- return [
395
- 3,
396
- 5
397
- ];
398
- case 4:
399
- return [
400
- 2,
401
- false
402
- ];
403
- case 5:
404
- return [
405
- 3,
406
- 7
407
- ];
408
- case 6:
409
- e = _state.sent();
410
- console.error("Error starting Keymaster service:", e);
411
- return [
412
- 2,
413
- false
414
- ];
415
- case 7:
416
- console.log("Started integrated Keymaster service");
417
- return [
418
- 2,
419
- true
420
- ];
421
- }
422
- });
423
- })();
424
- }
425
- },
426
- {
427
- key: "createChallengeInternal",
428
- value: function createChallengeInternal(spec, options) {
429
- var _this = this;
430
- return _async_to_generator(function() {
431
- var challenge;
432
- return _ts_generator(this, function(_state) {
433
- switch(_state.label){
434
- case 0:
435
- return [
436
- 4,
437
- _this.ensureServiceIsRunning()
438
- ];
439
- case 1:
440
- _state.sent();
441
- return [
442
- 4,
443
- _this.keymasterService.createChallenge(spec, options)
444
- ];
445
- case 2:
446
- challenge = _state.sent();
447
- return [
448
- 2,
449
- {
450
- challenge: challenge,
451
- challengeUrl: "".concat(spec.callback, "?challenge=").concat(challenge)
452
- }
453
- ];
454
- }
455
- });
456
- })();
457
- }
458
- },
459
- {
460
- key: "bindCredentialInternal",
461
- value: function bindCredentialInternal(schemaId, subjectId) {
462
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
463
- var _this = this;
464
- return _async_to_generator(function() {
465
- return _ts_generator(this, function(_state) {
466
- switch(_state.label){
467
- case 0:
468
- return [
469
- 4,
470
- _this.ensureServiceIsRunning()
471
- ];
472
- case 1:
473
- _state.sent();
474
- return [
475
- 2,
476
- _this.keymasterService.bindCredential(schemaId, subjectId, options)
477
- ];
478
- }
479
- });
480
- })();
481
- }
482
- },
483
- {
484
- key: "createResponseInternal",
485
- value: function createResponseInternal(challengeDID, options) {
486
- var _this = this;
487
- return _async_to_generator(function() {
488
- return _ts_generator(this, function(_state) {
489
- switch(_state.label){
490
- case 0:
491
- return [
492
- 4,
493
- _this.ensureServiceIsRunning()
494
- ];
495
- case 1:
496
- _state.sent();
497
- return [
498
- 2,
499
- _this.keymasterService.createResponse(challengeDID, options)
500
- ];
501
- }
502
- });
503
- })();
504
- }
505
- },
506
- {
507
- key: "backupWalletInternal",
508
- value: function backupWalletInternal(registry) {
509
- var _this = this;
510
- return _async_to_generator(function() {
511
- return _ts_generator(this, function(_state) {
512
- switch(_state.label){
513
- case 0:
514
- return [
515
- 4,
516
- _this.ensureServiceIsRunning()
517
- ];
518
- case 1:
519
- _state.sent();
520
- return [
521
- 2,
522
- _this.keymasterService.backupWallet(registry)
523
- ];
524
- }
525
- });
526
- })();
527
- }
528
- },
529
- {
530
- key: "issueCredentialInternal",
531
- value: function issueCredentialInternal(credential) {
532
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
533
- var _this = this;
534
- return _async_to_generator(function() {
535
- return _ts_generator(this, function(_state) {
536
- switch(_state.label){
537
- case 0:
538
- return [
539
- 4,
540
- _this.ensureServiceIsRunning()
541
- ];
542
- case 1:
543
- _state.sent();
544
- return [
545
- 2,
546
- _this.keymasterService.issueCredential(credential, options)
547
- ];
548
- }
549
- });
550
- })();
551
- }
552
- },
553
- {
554
- key: "publishCredentialInternal",
555
- value: function publishCredentialInternal(did) {
556
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
557
- var _this = this;
558
- return _async_to_generator(function() {
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.publishCredential(did, options)
571
- ];
572
- }
573
- });
574
- })();
575
- }
576
- },
577
- {
578
- key: "acceptCredentialInternal",
579
- value: function acceptCredentialInternal(did) {
580
- var _this = this;
581
- return _async_to_generator(function() {
582
- return _ts_generator(this, function(_state) {
583
- switch(_state.label){
584
- case 0:
585
- return [
586
- 4,
587
- _this.ensureServiceIsRunning()
588
- ];
589
- case 1:
590
- _state.sent();
591
- return [
592
- 2,
593
- _this.keymasterService.acceptCredential(did)
594
- ];
595
- }
596
- });
597
- })();
598
- }
599
- },
600
- {
601
- key: "showMnemonicInternal",
602
- value: function showMnemonicInternal() {
603
- var _this = this;
604
- return _async_to_generator(function() {
605
- return _ts_generator(this, function(_state) {
606
- switch(_state.label){
607
- case 0:
608
- return [
609
- 4,
610
- _this.ensureServiceIsRunning()
611
- ];
612
- case 1:
613
- _state.sent();
614
- return [
615
- 2,
616
- _this.keymasterService.decryptMnemonic()
617
- ];
618
- }
619
- });
620
- })();
621
- }
622
- },
623
- {
624
- key: "verifyResponseInternal",
625
- value: function verifyResponseInternal(did, options) {
626
- var _this = this;
627
- return _async_to_generator(function() {
628
- return _ts_generator(this, function(_state) {
629
- switch(_state.label){
630
- case 0:
631
- return [
632
- 4,
633
- _this.ensureServiceIsRunning()
634
- ];
635
- case 1:
636
- _state.sent();
637
- return [
638
- 2,
639
- _this.keymasterService.verifyResponse(did, options)
640
- ];
641
- }
642
- });
643
- })();
644
- }
645
- },
646
- {
647
- key: "decryptMessageInternal",
648
- value: function decryptMessageInternal() {
649
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
650
- args[_key] = arguments[_key];
651
- }
652
- var _this = this;
653
- return _async_to_generator(function() {
654
- var _this_keymasterService;
655
- return _ts_generator(this, function(_state) {
656
- switch(_state.label){
657
- case 0:
658
- return [
659
- 4,
660
- _this.ensureServiceIsRunning()
661
- ];
662
- case 1:
663
- _state.sent();
664
- return [
665
- 2,
666
- (_this_keymasterService = _this.keymasterService).decryptMessage.apply(_this_keymasterService, _to_consumable_array(args))
667
- ];
668
- }
669
- });
670
- })();
671
- }
672
- },
673
- {
674
- key: "decryptMnemonicInternal",
675
- value: function decryptMnemonicInternal() {
676
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
677
- args[_key] = arguments[_key];
678
- }
679
- var _this = this;
680
- return _async_to_generator(function() {
681
- var _this_keymasterService;
682
- return _ts_generator(this, function(_state) {
683
- switch(_state.label){
684
- case 0:
685
- return [
686
- 4,
687
- _this.ensureServiceIsRunning()
688
- ];
689
- case 1:
690
- _state.sent();
691
- return [
692
- 2,
693
- (_this_keymasterService = _this.keymasterService).decryptMnemonic.apply(_this_keymasterService, _to_consumable_array(args))
694
- ];
695
- }
696
- });
697
- })();
698
- }
699
- },
700
- {
701
- key: "getCredentialInternal",
702
- value: function getCredentialInternal() {
703
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
704
- args[_key] = arguments[_key];
705
- }
706
- var _this = this;
707
- return _async_to_generator(function() {
708
- var _this_keymasterService;
709
- return _ts_generator(this, function(_state) {
710
- switch(_state.label){
711
- case 0:
712
- return [
713
- 4,
714
- _this.ensureServiceIsRunning()
715
- ];
716
- case 1:
717
- _state.sent();
718
- return [
719
- 2,
720
- (_this_keymasterService = _this.keymasterService).getCredential.apply(_this_keymasterService, _to_consumable_array(args))
721
- ];
722
- }
723
- });
724
- })();
725
- }
726
- },
727
- {
728
- key: "removeCredentialInternal",
729
- value: function removeCredentialInternal() {
730
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
731
- args[_key] = arguments[_key];
732
- }
733
- var _this = this;
734
- return _async_to_generator(function() {
735
- var _this_keymasterService;
736
- return _ts_generator(this, function(_state) {
737
- switch(_state.label){
738
- case 0:
739
- return [
740
- 4,
741
- _this.ensureServiceIsRunning()
742
- ];
743
- case 1:
744
- _state.sent();
745
- return [
746
- 2,
747
- (_this_keymasterService = _this.keymasterService).removeCredential.apply(_this_keymasterService, _to_consumable_array(args))
748
- ];
749
- }
750
- });
751
- })();
752
- }
753
- },
754
- {
755
- key: "updateCredentialInternal",
756
- value: function updateCredentialInternal() {
757
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
758
- args[_key] = arguments[_key];
759
- }
760
- var _this = this;
761
- return _async_to_generator(function() {
762
- var _this_keymasterService;
763
- return _ts_generator(this, function(_state) {
764
- switch(_state.label){
765
- case 0:
766
- return [
767
- 4,
768
- _this.ensureServiceIsRunning()
769
- ];
770
- case 1:
771
- _state.sent();
772
- return [
773
- 2,
774
- (_this_keymasterService = _this.keymasterService).updateCredential.apply(_this_keymasterService, _to_consumable_array(args))
775
- ];
776
- }
777
- });
778
- })();
779
- }
780
- },
781
- {
782
- key: "createIdInternal",
783
- value: function createIdInternal() {
784
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
785
- args[_key] = arguments[_key];
786
- }
787
- var _this = this;
788
- return _async_to_generator(function() {
789
- var _this_keymasterService;
790
- return _ts_generator(this, function(_state) {
791
- switch(_state.label){
792
- case 0:
793
- return [
794
- 4,
795
- _this.ensureServiceIsRunning()
796
- ];
797
- case 1:
798
- _state.sent();
799
- return [
800
- 2,
801
- (_this_keymasterService = _this.keymasterService).createId.apply(_this_keymasterService, _to_consumable_array(args))
802
- ];
803
- }
804
- });
805
- })();
806
- }
807
- },
808
- {
809
- key: "removeIdInternal",
810
- value: function removeIdInternal() {
811
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
812
- args[_key] = arguments[_key];
813
- }
814
- var _this = this;
815
- return _async_to_generator(function() {
816
- var _this_keymasterService;
817
- return _ts_generator(this, function(_state) {
818
- switch(_state.label){
819
- case 0:
820
- return [
821
- 4,
822
- _this.ensureServiceIsRunning()
823
- ];
824
- case 1:
825
- _state.sent();
826
- return [
827
- 2,
828
- (_this_keymasterService = _this.keymasterService).removeId.apply(_this_keymasterService, _to_consumable_array(args))
829
- ];
830
- }
831
- });
832
- })();
833
- }
834
- },
835
- {
836
- key: "resolveDIDInternal",
837
- value: function resolveDIDInternal() {
838
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
839
- args[_key] = arguments[_key];
840
- }
841
- var _this = this;
842
- return _async_to_generator(function() {
843
- var _this_keymasterService;
844
- return _ts_generator(this, function(_state) {
845
- switch(_state.label){
846
- case 0:
847
- return [
848
- 4,
849
- _this.ensureServiceIsRunning()
850
- ];
851
- case 1:
852
- _state.sent();
853
- return [
854
- 2,
855
- (_this_keymasterService = _this.keymasterService).resolveDID.apply(_this_keymasterService, _to_consumable_array(args))
856
- ];
857
- }
858
- });
859
- })();
860
- }
861
- },
862
- {
863
- key: "setCurrentIdInternal",
864
- value: function setCurrentIdInternal() {
865
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
866
- args[_key] = arguments[_key];
867
- }
868
- var _this = this;
869
- return _async_to_generator(function() {
870
- var _this_keymasterService;
871
- return _ts_generator(this, function(_state) {
872
- switch(_state.label){
873
- case 0:
874
- return [
875
- 4,
876
- _this.ensureServiceIsRunning()
877
- ];
878
- case 1:
879
- _state.sent();
880
- return [
881
- 2,
882
- (_this_keymasterService = _this.keymasterService).setCurrentId.apply(_this_keymasterService, _to_consumable_array(args))
883
- ];
884
- }
885
- });
886
- })();
887
- }
888
- },
889
- {
890
- key: "createSchemaInternal",
891
- value: function createSchemaInternal() {
892
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
893
- args[_key] = arguments[_key];
894
- }
895
- var _this = this;
896
- return _async_to_generator(function() {
897
- var _this_keymasterService;
898
- return _ts_generator(this, function(_state) {
899
- switch(_state.label){
900
- case 0:
901
- return [
902
- 4,
903
- _this.ensureServiceIsRunning()
904
- ];
905
- case 1:
906
- _state.sent();
907
- return [
908
- 2,
909
- (_this_keymasterService = _this.keymasterService).createSchema.apply(_this_keymasterService, _to_consumable_array(args))
910
- ];
911
- }
912
- });
913
- })();
914
- }
915
- },
916
- {
917
- key: "newWalletInternal",
918
- value: function newWalletInternal() {
919
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
920
- args[_key] = arguments[_key];
921
- }
922
- var _this = this;
923
- return _async_to_generator(function() {
924
- var _this_keymasterService;
925
- return _ts_generator(this, function(_state) {
926
- switch(_state.label){
927
- case 0:
928
- return [
929
- 4,
930
- _this.ensureServiceIsRunning()
931
- ];
932
- case 1:
933
- _state.sent();
934
- return [
935
- 2,
936
- (_this_keymasterService = _this.keymasterService).newWallet.apply(_this_keymasterService, _to_consumable_array(args))
937
- ];
938
- }
939
- });
940
- })();
941
- }
942
- },
943
- {
944
- key: "recoverWalletInternal",
945
- value: function recoverWalletInternal() {
946
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
947
- args[_key] = arguments[_key];
948
- }
949
- var _this = this;
950
- return _async_to_generator(function() {
951
- var _this_keymasterService;
952
- return _ts_generator(this, function(_state) {
953
- switch(_state.label){
954
- case 0:
955
- return [
956
- 4,
957
- _this.ensureServiceIsRunning()
958
- ];
959
- case 1:
960
- _state.sent();
961
- return [
962
- 2,
963
- (_this_keymasterService = _this.keymasterService).recoverWallet.apply(_this_keymasterService, _to_consumable_array(args))
964
- ];
965
- }
966
- });
967
- })();
968
- }
969
- },
970
- {
971
- key: "ensureWalletExists",
972
- value: function ensureWalletExists() {
973
- var _this = this;
974
- return _async_to_generator(function() {
975
- var _this_config_walletDb, _this_config, existing, walletConfig, did;
976
- return _ts_generator(this, function(_state) {
977
- switch(_state.label){
978
- case 0:
979
- console.log("Ensuring wallet exists");
980
- return [
981
- 4,
982
- (_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()
983
- ];
984
- case 1:
985
- existing = _state.sent() || null;
986
- if (existing && "current" in existing) {
987
- console.log("Using existing wallet with ID ".concat(existing.current));
988
- return [
989
- 2
990
- ];
991
- }
992
- walletConfig = _this.config.walletConfig;
993
- console.log("Creating wallet with ID ".concat(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id));
994
- if (!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.mnemonic)) return [
995
- 3,
996
- 3
997
- ];
998
- return [
999
- 4,
1000
- _this.keymasterService.newWallet(walletConfig.mnemonic, true)
1001
- ];
1002
- case 2:
1003
- _state.sent();
1004
- _state.label = 3;
1005
- case 3:
1006
- if (!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id)) return [
1007
- 3,
1008
- 5
1009
- ];
1010
- return [
1011
- 4,
1012
- _this.keymasterService.createId(walletConfig.id, {
1013
- registry: walletConfig.registry
1014
- })
1015
- ];
1016
- case 4:
1017
- did = _state.sent();
1018
- console.log("Did ", did);
1019
- console.log("Created wallet with ID ".concat(walletConfig.id));
1020
- _state.label = 5;
1021
- case 5:
1022
- return [
1023
- 2
1024
- ];
1025
- }
1026
- });
1027
- })();
1028
- }
1029
- },
1030
- {
1031
- key: "serviceRunning",
1032
- value: function serviceRunning() {
1033
- var _this = this;
1034
- return _async_to_generator(function() {
1035
- var _tmp;
1036
- return _ts_generator(this, function(_state) {
1037
- switch(_state.label){
1038
- case 0:
1039
- _tmp = _this.serviceStarted;
1040
- if (_tmp) return [
1041
- 3,
1042
- 2
1043
- ];
1044
- return [
1045
- 4,
1046
- _this.startInternal()
1047
- ];
1048
- case 1:
1049
- _tmp = _state.sent();
1050
- _state.label = 2;
1051
- case 2:
1052
- return [
1053
- 2,
1054
- _tmp
1055
- ];
1056
- }
1057
- });
1058
- })();
1059
- }
1060
- },
1061
- {
1062
- key: "validateConfig",
1063
- value: function validateConfig(config) {
1064
- if (!config.gatekeeperConfig) {
1065
- throw new Error("Missing Gatekeeper config");
1066
- }
1067
- if (config.gatekeeperConfig) {
1068
- var _config_walletDb, _config_walletDb1;
1069
- if (!config.walletConfig) {
1070
- throw new Error("Missing wallet config");
1071
- }
1072
- if (!((_config_walletDb = config.walletDb) === null || _config_walletDb === void 0 ? void 0 : _config_walletDb.loadWallet)) {
1073
- throw new Error("Missing load wallet callback");
1074
- }
1075
- if (!((_config_walletDb1 = config.walletDb) === null || _config_walletDb1 === void 0 ? void 0 : _config_walletDb1.saveWallet)) {
1076
- throw new Error("Missing save wallet callback");
1077
- }
1078
- }
1079
- }
1080
- }
1081
- ], [
1082
- {
1083
- key: "initialize",
1084
- value: function initialize(config) {
1085
- if (!_Keymaster.instance) {
1086
- _Keymaster.instance = new _Keymaster(config);
1087
- console.log("\u2705 Keymaster initialized");
1088
- } else {
1089
- console.warn("Keymaster already initialized, ignoring re-initialization.");
1090
- }
1091
- }
1092
- },
1093
- {
1094
- key: "start",
1095
- value: // Delegated STATIC methods
1096
- function start() {
1097
- return _async_to_generator(function() {
1098
- return _ts_generator(this, function(_state) {
1099
- _Keymaster.getInstance().ensureInitialized();
1100
- return [
1101
- 2,
1102
- _Keymaster.getInstance().startInternal()
1103
- ];
1104
- });
1105
- })();
1106
- }
1107
- },
1108
- {
1109
- key: "createChallenge",
1110
- value: function createChallenge() {
1111
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1112
- args[_key] = arguments[_key];
1113
- }
1114
- return _async_to_generator(function() {
1115
- var _Keymaster_getInstance;
1116
- return _ts_generator(this, function(_state) {
1117
- _Keymaster.getInstance().ensureInitialized();
1118
- return [
1119
- 2,
1120
- (_Keymaster_getInstance = _Keymaster.getInstance()).createChallengeInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1121
- ];
1122
- });
1123
- })();
1124
- }
1125
- },
1126
- {
1127
- key: "bindCredential",
1128
- value: function bindCredential() {
1129
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1130
- args[_key] = arguments[_key];
1131
- }
1132
- return _async_to_generator(function() {
1133
- var _Keymaster_getInstance;
1134
- return _ts_generator(this, function(_state) {
1135
- _Keymaster.getInstance().ensureInitialized();
1136
- return [
1137
- 2,
1138
- (_Keymaster_getInstance = _Keymaster.getInstance()).bindCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1139
- ];
1140
- });
1141
- })();
1142
- }
1143
- },
1144
- {
1145
- key: "backupWallet",
1146
- value: function backupWallet() {
1147
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1148
- args[_key] = arguments[_key];
1149
- }
1150
- return _async_to_generator(function() {
1151
- var _Keymaster_getInstance;
1152
- return _ts_generator(this, function(_state) {
1153
- _Keymaster.getInstance().ensureInitialized();
1154
- return [
1155
- 2,
1156
- (_Keymaster_getInstance = _Keymaster.getInstance()).backupWalletInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1157
- ];
1158
- });
1159
- })();
1160
- }
1161
- },
1162
- {
1163
- key: "createResponse",
1164
- value: function createResponse() {
1165
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1166
- args[_key] = arguments[_key];
1167
- }
1168
- return _async_to_generator(function() {
1169
- var _Keymaster_getInstance;
1170
- return _ts_generator(this, function(_state) {
1171
- _Keymaster.getInstance().ensureInitialized();
1172
- return [
1173
- 2,
1174
- (_Keymaster_getInstance = _Keymaster.getInstance()).createResponseInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1175
- ];
1176
- });
1177
- })();
1178
- }
1179
- },
1180
- {
1181
- key: "issueCredential",
1182
- value: function issueCredential() {
1183
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1184
- args[_key] = arguments[_key];
1185
- }
1186
- return _async_to_generator(function() {
1187
- var _Keymaster_getInstance;
1188
- return _ts_generator(this, function(_state) {
1189
- _Keymaster.getInstance().ensureInitialized();
1190
- return [
1191
- 2,
1192
- (_Keymaster_getInstance = _Keymaster.getInstance()).issueCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1193
- ];
1194
- });
1195
- })();
1196
- }
1197
- },
1198
- {
1199
- key: "publishCredential",
1200
- value: function publishCredential() {
1201
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1202
- args[_key] = arguments[_key];
1203
- }
1204
- return _async_to_generator(function() {
1205
- var _Keymaster_getInstance;
1206
- return _ts_generator(this, function(_state) {
1207
- _Keymaster.getInstance().ensureInitialized();
1208
- return [
1209
- 2,
1210
- (_Keymaster_getInstance = _Keymaster.getInstance()).publishCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1211
- ];
1212
- });
1213
- })();
1214
- }
1215
- },
1216
- {
1217
- key: "acceptCredential",
1218
- value: function acceptCredential() {
1219
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1220
- args[_key] = arguments[_key];
1221
- }
1222
- return _async_to_generator(function() {
1223
- var _Keymaster_getInstance;
1224
- return _ts_generator(this, function(_state) {
1225
- _Keymaster.getInstance().ensureInitialized();
1226
- return [
1227
- 2,
1228
- (_Keymaster_getInstance = _Keymaster.getInstance()).acceptCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1229
- ];
1230
- });
1231
- })();
1232
- }
1233
- },
1234
- {
1235
- key: "showMnemonic",
1236
- value: function showMnemonic() {
1237
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1238
- args[_key] = arguments[_key];
1239
- }
1240
- return _async_to_generator(function() {
1241
- var _Keymaster_getInstance;
1242
- return _ts_generator(this, function(_state) {
1243
- _Keymaster.getInstance().ensureInitialized();
1244
- return [
1245
- 2,
1246
- (_Keymaster_getInstance = _Keymaster.getInstance()).showMnemonicInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1247
- ];
1248
- });
1249
- })();
1250
- }
1251
- },
1252
- {
1253
- key: "verifyResponse",
1254
- value: function verifyResponse() {
1255
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1256
- args[_key] = arguments[_key];
1257
- }
1258
- return _async_to_generator(function() {
1259
- var _Keymaster_getInstance;
1260
- return _ts_generator(this, function(_state) {
1261
- _Keymaster.getInstance().ensureInitialized();
1262
- return [
1263
- 2,
1264
- (_Keymaster_getInstance = _Keymaster.getInstance()).verifyResponseInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1265
- ];
1266
- });
1267
- })();
1268
- }
1269
- },
1270
- {
1271
- key: "decryptMessage",
1272
- value: function decryptMessage() {
1273
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1274
- args[_key] = arguments[_key];
1275
- }
1276
- return _async_to_generator(function() {
1277
- var _Keymaster_getInstance;
1278
- return _ts_generator(this, function(_state) {
1279
- _Keymaster.getInstance().ensureInitialized();
1280
- return [
1281
- 2,
1282
- (_Keymaster_getInstance = _Keymaster.getInstance()).decryptMessageInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1283
- ];
1284
- });
1285
- })();
1286
- }
1287
- },
1288
- {
1289
- key: "decryptMnemonic",
1290
- value: function decryptMnemonic() {
1291
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1292
- args[_key] = arguments[_key];
1293
- }
1294
- return _async_to_generator(function() {
1295
- var _Keymaster_getInstance;
1296
- return _ts_generator(this, function(_state) {
1297
- _Keymaster.getInstance().ensureInitialized();
1298
- return [
1299
- 2,
1300
- (_Keymaster_getInstance = _Keymaster.getInstance()).decryptMnemonicInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1301
- ];
1302
- });
1303
- })();
1304
- }
1305
- },
1306
- {
1307
- key: "getCredential",
1308
- value: function getCredential() {
1309
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1310
- args[_key] = arguments[_key];
1311
- }
1312
- return _async_to_generator(function() {
1313
- var _Keymaster_getInstance;
1314
- return _ts_generator(this, function(_state) {
1315
- _Keymaster.getInstance().ensureInitialized();
1316
- return [
1317
- 2,
1318
- (_Keymaster_getInstance = _Keymaster.getInstance()).getCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1319
- ];
1320
- });
1321
- })();
1322
- }
1323
- },
1324
- {
1325
- key: "removeCredential",
1326
- value: function removeCredential() {
1327
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1328
- args[_key] = arguments[_key];
1329
- }
1330
- return _async_to_generator(function() {
1331
- var _Keymaster_getInstance;
1332
- return _ts_generator(this, function(_state) {
1333
- _Keymaster.getInstance().ensureInitialized();
1334
- return [
1335
- 2,
1336
- (_Keymaster_getInstance = _Keymaster.getInstance()).removeCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1337
- ];
1338
- });
1339
- })();
1340
- }
1341
- },
1342
- {
1343
- key: "updateCredential",
1344
- value: function updateCredential() {
1345
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1346
- args[_key] = arguments[_key];
1347
- }
1348
- return _async_to_generator(function() {
1349
- var _Keymaster_getInstance;
1350
- return _ts_generator(this, function(_state) {
1351
- _Keymaster.getInstance().ensureInitialized();
1352
- return [
1353
- 2,
1354
- (_Keymaster_getInstance = _Keymaster.getInstance()).updateCredentialInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1355
- ];
1356
- });
1357
- })();
1358
- }
1359
- },
1360
- {
1361
- key: "createId",
1362
- value: function createId() {
1363
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1364
- args[_key] = arguments[_key];
1365
- }
1366
- return _async_to_generator(function() {
1367
- var _Keymaster_getInstance;
1368
- return _ts_generator(this, function(_state) {
1369
- _Keymaster.getInstance().ensureInitialized();
1370
- return [
1371
- 2,
1372
- (_Keymaster_getInstance = _Keymaster.getInstance()).createIdInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1373
- ];
1374
- });
1375
- })();
1376
- }
1377
- },
1378
- {
1379
- key: "removeId",
1380
- value: function removeId() {
1381
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1382
- args[_key] = arguments[_key];
1383
- }
1384
- return _async_to_generator(function() {
1385
- var _Keymaster_getInstance;
1386
- return _ts_generator(this, function(_state) {
1387
- _Keymaster.getInstance().ensureInitialized();
1388
- return [
1389
- 2,
1390
- (_Keymaster_getInstance = _Keymaster.getInstance()).removeIdInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1391
- ];
1392
- });
1393
- })();
1394
- }
1395
- },
1396
- {
1397
- key: "resolveDID",
1398
- value: function resolveDID() {
1399
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1400
- args[_key] = arguments[_key];
1401
- }
1402
- return _async_to_generator(function() {
1403
- var _Keymaster_getInstance;
1404
- return _ts_generator(this, function(_state) {
1405
- _Keymaster.getInstance().ensureInitialized();
1406
- return [
1407
- 2,
1408
- (_Keymaster_getInstance = _Keymaster.getInstance()).resolveDIDInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1409
- ];
1410
- });
1411
- })();
1412
- }
1413
- },
1414
- {
1415
- key: "setCurrentId",
1416
- value: function setCurrentId() {
1417
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1418
- args[_key] = arguments[_key];
1419
- }
1420
- return _async_to_generator(function() {
1421
- var _Keymaster_getInstance;
1422
- return _ts_generator(this, function(_state) {
1423
- _Keymaster.getInstance().ensureInitialized();
1424
- return [
1425
- 2,
1426
- (_Keymaster_getInstance = _Keymaster.getInstance()).setCurrentIdInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1427
- ];
1428
- });
1429
- })();
1430
- }
1431
- },
1432
- {
1433
- key: "createSchema",
1434
- value: function createSchema() {
1435
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1436
- args[_key] = arguments[_key];
1437
- }
1438
- return _async_to_generator(function() {
1439
- var _Keymaster_getInstance;
1440
- return _ts_generator(this, function(_state) {
1441
- _Keymaster.getInstance().ensureInitialized();
1442
- return [
1443
- 2,
1444
- (_Keymaster_getInstance = _Keymaster.getInstance()).createSchemaInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1445
- ];
1446
- });
1447
- })();
1448
- }
1449
- },
1450
- {
1451
- key: "newWallet",
1452
- value: function newWallet() {
1453
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1454
- args[_key] = arguments[_key];
1455
- }
1456
- return _async_to_generator(function() {
1457
- var _Keymaster_getInstance;
1458
- return _ts_generator(this, function(_state) {
1459
- _Keymaster.getInstance().ensureInitialized();
1460
- return [
1461
- 2,
1462
- (_Keymaster_getInstance = _Keymaster.getInstance()).newWalletInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1463
- ];
1464
- });
1465
- })();
1466
- }
1467
- },
1468
- {
1469
- key: "recoverWallet",
1470
- value: function recoverWallet() {
1471
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1472
- args[_key] = arguments[_key];
1473
- }
1474
- return _async_to_generator(function() {
1475
- var _Keymaster_getInstance;
1476
- return _ts_generator(this, function(_state) {
1477
- _Keymaster.getInstance().ensureInitialized();
1478
- return [
1479
- 2,
1480
- (_Keymaster_getInstance = _Keymaster.getInstance()).recoverWalletInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1481
- ];
1482
- });
1483
- })();
1484
- }
1485
- },
1486
- {
1487
- key: "getInstance",
1488
- value: function getInstance() {
1489
- if (!_Keymaster.instance) {
1490
- throw new Error("Keymaster not initialized. Call Keymaster.initialize() first.");
1491
- }
1492
- return _Keymaster.instance;
1493
- }
1494
- }
1495
- ]);
1496
- return _Keymaster;
1497
- }();
1498
- _Keymaster.instance = null;
1499
- var Keymaster = _Keymaster;
178
+ return this.serviceStarted;
179
+ }
180
+ async startIntegratedKeymaster() {
181
+ console.log(`Starting integrated Keymaster service`);
182
+ try {
183
+ if (this.config.walletDb) {
184
+ const gatekeeper = new import_client.default();
185
+ await gatekeeper.connect(this.config.gatekeeperConfig);
186
+ const cipher = new import_node.default();
187
+ this.keymasterService = new import_keymaster.default({
188
+ gatekeeper,
189
+ wallet: this.config.walletDb,
190
+ cipher
191
+ });
192
+ await this.ensureWalletExists();
193
+ } else {
194
+ return false;
195
+ }
196
+ } catch (e) {
197
+ console.error("Error starting Keymaster service:", e);
198
+ return false;
199
+ }
200
+ console.log(`Started integrated Keymaster service`);
201
+ return true;
202
+ }
203
+ async createChallengeInternal(spec, options) {
204
+ await this.ensureServiceIsRunning();
205
+ const challenge = await this.keymasterService.createChallenge(
206
+ spec,
207
+ options
208
+ );
209
+ return {
210
+ challenge,
211
+ challengeUrl: `${spec.callback}?challenge=${challenge}`
212
+ };
213
+ }
214
+ async bindCredentialInternal(schemaId, subjectId, options = {}) {
215
+ await this.ensureServiceIsRunning();
216
+ return this.keymasterService.bindCredential(schemaId, subjectId, options);
217
+ }
218
+ async createResponseInternal(challengeDID, options) {
219
+ await this.ensureServiceIsRunning();
220
+ return this.keymasterService.createResponse(challengeDID, options);
221
+ }
222
+ async backupWalletInternal(registry) {
223
+ await this.ensureServiceIsRunning();
224
+ return this.keymasterService.backupWallet(registry);
225
+ }
226
+ async issueCredentialInternal(credential, options = {}) {
227
+ await this.ensureServiceIsRunning();
228
+ return this.keymasterService.issueCredential(credential, options);
229
+ }
230
+ async publishCredentialInternal(did, options = {}) {
231
+ await this.ensureServiceIsRunning();
232
+ return this.keymasterService.publishCredential(did, options);
233
+ }
234
+ async acceptCredentialInternal(did) {
235
+ await this.ensureServiceIsRunning();
236
+ return this.keymasterService.acceptCredential(did);
237
+ }
238
+ async showMnemonicInternal() {
239
+ await this.ensureServiceIsRunning();
240
+ return this.keymasterService.decryptMnemonic();
241
+ }
242
+ async verifyResponseInternal(did, options) {
243
+ await this.ensureServiceIsRunning();
244
+ return this.keymasterService.verifyResponse(did, options);
245
+ }
246
+ async decryptMessageInternal(...args) {
247
+ await this.ensureServiceIsRunning();
248
+ return this.keymasterService.decryptMessage(...args);
249
+ }
250
+ async decryptMnemonicInternal(...args) {
251
+ await this.ensureServiceIsRunning();
252
+ return this.keymasterService.decryptMnemonic(...args);
253
+ }
254
+ async getCredentialInternal(...args) {
255
+ await this.ensureServiceIsRunning();
256
+ return this.keymasterService.getCredential(...args);
257
+ }
258
+ async removeCredentialInternal(...args) {
259
+ await this.ensureServiceIsRunning();
260
+ return this.keymasterService.removeCredential(...args);
261
+ }
262
+ async updateCredentialInternal(...args) {
263
+ await this.ensureServiceIsRunning();
264
+ return this.keymasterService.updateCredential(...args);
265
+ }
266
+ async createIdInternal(...args) {
267
+ await this.ensureServiceIsRunning();
268
+ return this.keymasterService.createId(...args);
269
+ }
270
+ async removeIdInternal(...args) {
271
+ await this.ensureServiceIsRunning();
272
+ return this.keymasterService.removeId(...args);
273
+ }
274
+ async resolveDIDInternal(...args) {
275
+ await this.ensureServiceIsRunning();
276
+ return this.keymasterService.resolveDID(...args);
277
+ }
278
+ async setCurrentIdInternal(...args) {
279
+ await this.ensureServiceIsRunning();
280
+ return this.keymasterService.setCurrentId(...args);
281
+ }
282
+ async createSchemaInternal(...args) {
283
+ await this.ensureServiceIsRunning();
284
+ return this.keymasterService.createSchema(...args);
285
+ }
286
+ async newWalletInternal(...args) {
287
+ await this.ensureServiceIsRunning();
288
+ return this.keymasterService.newWallet(...args);
289
+ }
290
+ async recoverWalletInternal(...args) {
291
+ await this.ensureServiceIsRunning();
292
+ return this.keymasterService.recoverWallet(...args);
293
+ }
294
+ async ensureWalletExists() {
295
+ console.log("Ensuring wallet exists");
296
+ const existing = await this.config?.walletDb?.loadWallet() || null;
297
+ if (existing && "current" in existing) {
298
+ console.log(`Using existing wallet with ID ${existing.current}`);
299
+ return;
300
+ }
301
+ const walletConfig = this.config.walletConfig;
302
+ console.log(`Creating wallet with ID ${walletConfig?.id}`);
303
+ if (walletConfig?.mnemonic) {
304
+ await this.keymasterService.newWallet(walletConfig.mnemonic, true);
305
+ }
306
+ if (walletConfig?.id) {
307
+ const did = await this.keymasterService.createId(walletConfig.id, {
308
+ registry: walletConfig.registry
309
+ });
310
+ console.log("Did ", did);
311
+ console.log(`Created wallet with ID ${walletConfig.id}`);
312
+ }
313
+ }
314
+ async serviceRunning() {
315
+ return this.serviceStarted || await this.startInternal();
316
+ }
317
+ validateConfig(config) {
318
+ if (!config.gatekeeperConfig) {
319
+ throw new Error("Missing Gatekeeper config");
320
+ }
321
+ if (config.gatekeeperConfig) {
322
+ if (!config.walletConfig) {
323
+ throw new Error("Missing wallet config");
324
+ }
325
+ if (!config.walletDb?.loadWallet) {
326
+ throw new Error("Missing load wallet callback");
327
+ }
328
+ if (!config.walletDb?.saveWallet) {
329
+ throw new Error("Missing save wallet callback");
330
+ }
331
+ }
332
+ }
333
+ };
334
+
1500
335
  // src/keymasterClient.ts
1501
336
  var import_client2 = __toESM(require("@mdip/keymaster/client"), 1);
1502
- var KeymasterExternalClient = /*#__PURE__*/ function() {
1503
- function KeymasterExternalClient(config) {
1504
- _class_call_check(this, KeymasterExternalClient);
1505
- this.serviceStarted = false;
1506
- this.validateConfig(config);
1507
- this.config = config;
337
+ var KeymasterExternalClient = class {
338
+ config;
339
+ keymasterService;
340
+ serviceStarted = false;
341
+ constructor(config) {
342
+ this.validateConfig(config);
343
+ this.config = config;
344
+ }
345
+ async start() {
346
+ if (this.config.keymasterConfig) {
347
+ this.serviceStarted = await this.startExternalKeymaster();
348
+ } else {
349
+ throw "Missing Keymaster config";
350
+ }
351
+ return this.serviceStarted;
352
+ }
353
+ async startExternal() {
354
+ if (this.config.keymasterConfig) {
355
+ this.serviceStarted = await this.startExternalKeymaster();
356
+ } else {
357
+ throw "Missing Gatekeeper or Keymaster config";
1508
358
  }
1509
- _create_class(KeymasterExternalClient, [
1510
- {
1511
- key: "start",
1512
- value: function start() {
1513
- var _this = this;
1514
- return _async_to_generator(function() {
1515
- return _ts_generator(this, function(_state) {
1516
- switch(_state.label){
1517
- case 0:
1518
- if (!_this.config.keymasterConfig) return [
1519
- 3,
1520
- 2
1521
- ];
1522
- return [
1523
- 4,
1524
- _this.startExternalKeymaster()
1525
- ];
1526
- case 1:
1527
- _this.serviceStarted = _state.sent();
1528
- return [
1529
- 3,
1530
- 3
1531
- ];
1532
- case 2:
1533
- throw "Missing Keymaster config";
1534
- case 3:
1535
- return [
1536
- 2,
1537
- _this.serviceStarted
1538
- ];
1539
- }
1540
- });
1541
- })();
1542
- }
1543
- },
1544
- {
1545
- key: "startExternal",
1546
- value: function startExternal() {
1547
- var _this = this;
1548
- return _async_to_generator(function() {
1549
- return _ts_generator(this, function(_state) {
1550
- switch(_state.label){
1551
- case 0:
1552
- if (!_this.config.keymasterConfig) return [
1553
- 3,
1554
- 2
1555
- ];
1556
- return [
1557
- 4,
1558
- _this.startExternalKeymaster()
1559
- ];
1560
- case 1:
1561
- _this.serviceStarted = _state.sent();
1562
- return [
1563
- 3,
1564
- 3
1565
- ];
1566
- case 2:
1567
- throw "Missing Gatekeeper or Keymaster config";
1568
- case 3:
1569
- return [
1570
- 2,
1571
- _this.serviceStarted
1572
- ];
1573
- }
1574
- });
1575
- })();
1576
- }
1577
- },
1578
- {
1579
- key: "startExternalKeymaster",
1580
- value: function startExternalKeymaster() {
1581
- var _this = this;
1582
- return _async_to_generator(function() {
1583
- var e;
1584
- return _ts_generator(this, function(_state) {
1585
- switch(_state.label){
1586
- case 0:
1587
- console.log("Starting external Keymaster service");
1588
- _state.label = 1;
1589
- case 1:
1590
- _state.trys.push([
1591
- 1,
1592
- 3,
1593
- ,
1594
- 4
1595
- ]);
1596
- _this.keymasterService = new import_client2.default();
1597
- return [
1598
- 4,
1599
- _this.keymasterService.connect(_this.config.keymasterConfig)
1600
- ];
1601
- case 2:
1602
- _state.sent();
1603
- return [
1604
- 3,
1605
- 4
1606
- ];
1607
- case 3:
1608
- e = _state.sent();
1609
- console.error("Error starting Keymaster service:", e);
1610
- return [
1611
- 2,
1612
- false
1613
- ];
1614
- case 4:
1615
- console.log("Started external Keymaster service");
1616
- return [
1617
- 2,
1618
- true
1619
- ];
1620
- }
1621
- });
1622
- })();
1623
- }
1624
- },
1625
- {
1626
- key: "createChallenge",
1627
- value: function createChallenge(spec, options) {
1628
- var _this = this;
1629
- return _async_to_generator(function() {
1630
- var _this_keymasterService, challenge;
1631
- return _ts_generator(this, function(_state) {
1632
- switch(_state.label){
1633
- case 0:
1634
- if (!_this.serviceRunning()) {
1635
- throw new Error("Keymaster service not running");
1636
- }
1637
- return [
1638
- 4,
1639
- (_this_keymasterService = _this.keymasterService) === null || _this_keymasterService === void 0 ? void 0 : _this_keymasterService.createChallenge(spec, options)
1640
- ];
1641
- case 1:
1642
- challenge = _state.sent();
1643
- return [
1644
- 2,
1645
- {
1646
- challenge: challenge,
1647
- challengeUrl: "".concat(spec.callback, "?challenge=").concat(challenge)
1648
- }
1649
- ];
1650
- }
1651
- });
1652
- })();
1653
- }
1654
- },
1655
- {
1656
- key: "bindCredential",
1657
- value: function bindCredential(schemaId, subjectId) {
1658
- var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1659
- var _this = this;
1660
- return _async_to_generator(function() {
1661
- return _ts_generator(this, function(_state) {
1662
- if (!_this.serviceRunning()) {
1663
- throw new Error("Keymaster service not running");
1664
- }
1665
- return [
1666
- 2,
1667
- _this.keymasterService.bindCredential(schemaId, subjectId, options)
1668
- ];
1669
- });
1670
- })();
1671
- }
1672
- },
1673
- {
1674
- key: "issueCredential",
1675
- value: function issueCredential(credential) {
1676
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1677
- var _this = this;
1678
- return _async_to_generator(function() {
1679
- return _ts_generator(this, function(_state) {
1680
- if (!_this.serviceRunning()) {
1681
- throw new Error("Keymaster service not running");
1682
- }
1683
- return [
1684
- 2,
1685
- _this.keymasterService.issueCredential(credential, options)
1686
- ];
1687
- });
1688
- })();
1689
- }
1690
- },
1691
- {
1692
- key: "publishCredential",
1693
- value: function publishCredential(did) {
1694
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1695
- var _this = this;
1696
- return _async_to_generator(function() {
1697
- return _ts_generator(this, function(_state) {
1698
- if (!_this.serviceRunning()) {
1699
- throw new Error("Keymaster service not running");
1700
- }
1701
- return [
1702
- 2,
1703
- _this.keymasterService.publishCredential(did, options)
1704
- ];
1705
- });
1706
- })();
1707
- }
1708
- },
1709
- {
1710
- key: "acceptCredential",
1711
- value: function acceptCredential(did) {
1712
- var _this = this;
1713
- return _async_to_generator(function() {
1714
- return _ts_generator(this, function(_state) {
1715
- if (!_this.serviceRunning()) {
1716
- throw new Error("Keymaster service not running");
1717
- }
1718
- return [
1719
- 2,
1720
- _this.keymasterService.acceptCredential(did)
1721
- ];
1722
- });
1723
- })();
1724
- }
1725
- },
1726
- {
1727
- key: "showMnemonic",
1728
- value: function showMnemonic() {
1729
- var _this = this;
1730
- return _async_to_generator(function() {
1731
- return _ts_generator(this, function(_state) {
1732
- if (!_this.serviceRunning()) {
1733
- throw new Error("Keymaster service not running");
1734
- }
1735
- return [
1736
- 2,
1737
- _this.keymasterService.decryptMnemonic()
1738
- ];
1739
- });
1740
- })();
1741
- }
1742
- },
1743
- {
1744
- key: "verifyResponse",
1745
- value: function verifyResponse(did, options) {
1746
- var _this = this;
1747
- return _async_to_generator(function() {
1748
- var response;
1749
- return _ts_generator(this, function(_state) {
1750
- switch(_state.label){
1751
- case 0:
1752
- if (!_this.serviceRunning()) {
1753
- throw new Error("Keymaster service not running");
1754
- }
1755
- return [
1756
- 4,
1757
- _this.keymasterService.verifyResponse(did, options)
1758
- ];
1759
- case 1:
1760
- response = _state.sent();
1761
- return [
1762
- 2,
1763
- response
1764
- ];
1765
- }
1766
- });
1767
- })();
1768
- }
1769
- },
1770
- {
1771
- key: "serviceRunning",
1772
- value: function serviceRunning() {
1773
- var _this = this;
1774
- return _async_to_generator(function() {
1775
- var _tmp;
1776
- return _ts_generator(this, function(_state) {
1777
- switch(_state.label){
1778
- case 0:
1779
- _tmp = _this.serviceStarted;
1780
- if (_tmp) return [
1781
- 3,
1782
- 2
1783
- ];
1784
- return [
1785
- 4,
1786
- _this.start()
1787
- ];
1788
- case 1:
1789
- _tmp = _state.sent();
1790
- _state.label = 2;
1791
- case 2:
1792
- return [
1793
- 2,
1794
- _tmp
1795
- ];
1796
- }
1797
- });
1798
- })();
1799
- }
1800
- },
1801
- {
1802
- key: "validateConfig",
1803
- value: function validateConfig(config) {
1804
- if (!config.keymasterConfig) {
1805
- throw new Error("Missing Keymaster config");
1806
- }
1807
- }
1808
- }
1809
- ]);
1810
- return KeymasterExternalClient;
1811
- }();
359
+ return this.serviceStarted;
360
+ }
361
+ async startExternalKeymaster() {
362
+ console.log(`Starting external Keymaster service`);
363
+ try {
364
+ this.keymasterService = new import_client2.default();
365
+ await this.keymasterService.connect(this.config.keymasterConfig);
366
+ } catch (e) {
367
+ console.error(`Error starting Keymaster service:`, e);
368
+ return false;
369
+ }
370
+ console.log(`Started external Keymaster service`);
371
+ return true;
372
+ }
373
+ async createChallenge(spec, options) {
374
+ if (!this.serviceRunning()) {
375
+ throw new Error("Keymaster service not running");
376
+ }
377
+ const challenge = await this.keymasterService?.createChallenge(
378
+ spec,
379
+ options
380
+ );
381
+ return {
382
+ challenge,
383
+ challengeUrl: `${spec.callback}?challenge=${challenge}`
384
+ };
385
+ }
386
+ async bindCredential(schemaId, subjectId, options = {}) {
387
+ if (!this.serviceRunning()) {
388
+ throw new Error("Keymaster service not running");
389
+ }
390
+ return this.keymasterService.bindCredential(schemaId, subjectId, options);
391
+ }
392
+ async issueCredential(credential, options = {}) {
393
+ if (!this.serviceRunning()) {
394
+ throw new Error("Keymaster service not running");
395
+ }
396
+ return this.keymasterService.issueCredential(credential, options);
397
+ }
398
+ async publishCredential(did, options = {}) {
399
+ if (!this.serviceRunning()) {
400
+ throw new Error("Keymaster service not running");
401
+ }
402
+ return this.keymasterService.publishCredential(did, options);
403
+ }
404
+ async acceptCredential(did) {
405
+ if (!this.serviceRunning()) {
406
+ throw new Error("Keymaster service not running");
407
+ }
408
+ return this.keymasterService.acceptCredential(did);
409
+ }
410
+ async showMnemonic() {
411
+ if (!this.serviceRunning()) {
412
+ throw new Error("Keymaster service not running");
413
+ }
414
+ return this.keymasterService.decryptMnemonic();
415
+ }
416
+ async verifyResponse(did, options) {
417
+ if (!this.serviceRunning()) {
418
+ throw new Error("Keymaster service not running");
419
+ }
420
+ const response = await this.keymasterService.verifyResponse(did, options);
421
+ return response;
422
+ }
423
+ async serviceRunning() {
424
+ return this.serviceStarted || await this.start();
425
+ }
426
+ validateConfig(config) {
427
+ if (!config.keymasterConfig) {
428
+ throw new Error("Missing Keymaster config");
429
+ }
430
+ }
431
+ };
432
+
1812
433
  // src/index.ts
1813
434
  __reExport(src_exports, require("@mdip/keymaster/types"), module.exports);
1814
435
  // Annotate the CommonJS export names for ESM import in node:
1815
- 0 && (module.exports = _object_spread({
1816
- Keymaster: Keymaster,
1817
- KeymasterExternalClient: KeymasterExternalClient
1818
- }, require("@mdip/keymaster/types")));
436
+ 0 && (module.exports = {
437
+ Keymaster,
438
+ KeymasterExternalClient,
439
+ ...require("@mdip/keymaster/types")
440
+ });
1819
441
  //# sourceMappingURL=index.cjs.map