@yourself_id/siwys-api-js 0.0.11-sapp-107-external-km-support.7 → 0.0.11

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
@@ -47,47 +47,6 @@ function _create_class(Constructor, protoProps, staticProps) {
47
47
  if (staticProps) _defineProperties(Constructor, staticProps);
48
48
  return Constructor;
49
49
  }
50
- function _getRequireWildcardCache(nodeInterop) {
51
- if (typeof WeakMap !== "function") return null;
52
- var cacheBabelInterop = new WeakMap();
53
- var cacheNodeInterop = new WeakMap();
54
- return (_getRequireWildcardCache = function(nodeInterop) {
55
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
56
- })(nodeInterop);
57
- }
58
- function _interop_require_wildcard(obj, nodeInterop) {
59
- if (!nodeInterop && obj && obj.__esModule) {
60
- return obj;
61
- }
62
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
63
- return {
64
- default: obj
65
- };
66
- }
67
- var cache = _getRequireWildcardCache(nodeInterop);
68
- if (cache && cache.has(obj)) {
69
- return cache.get(obj);
70
- }
71
- var newObj = {
72
- __proto__: null
73
- };
74
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
75
- for(var key in obj){
76
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
77
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
78
- if (desc && (desc.get || desc.set)) {
79
- Object.defineProperty(newObj, key, desc);
80
- } else {
81
- newObj[key] = obj[key];
82
- }
83
- }
84
- }
85
- newObj.default = obj;
86
- if (cache) {
87
- cache.set(obj, newObj);
88
- }
89
- return newObj;
90
- }
91
50
  function _type_of(obj) {
92
51
  "@swc/helpers - typeof";
93
52
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -254,12 +213,24 @@ __export(src_exports, {
254
213
  });
255
214
  module.exports = __toCommonJS(src_exports);
256
215
  // src/keymaster.ts
216
+ var cipher = __toESM(require("@mdip/cipher/node"), 1);
217
+ var gatekeeper_sdk = __toESM(require("@mdip/gatekeeper/sdk"), 1);
218
+ var keymaster_lib = __toESM(require("@mdip/keymaster/lib"), 1);
257
219
  var Keymaster = /*#__PURE__*/ function() {
258
220
  function Keymaster(config) {
259
221
  _class_call_check(this, Keymaster);
260
- this.serviceStarted = false;
261
- this.validateConfig(config);
262
- this.config = config;
222
+ this._serviceStarted = false;
223
+ this._gatekeeperConfig = {
224
+ url: config.gatekeeperConfig.url,
225
+ waitUntilReady: true,
226
+ intervalSeconds: 5,
227
+ chatty: true
228
+ };
229
+ this._walletConfig = config.walletConfig;
230
+ this._walletDb = {
231
+ saveWallet: config.onSaveWallet,
232
+ loadWallet: config.onLoadWallet
233
+ };
263
234
  }
264
235
  _create_class(Keymaster, [
265
236
  {
@@ -267,98 +238,69 @@ var Keymaster = /*#__PURE__*/ function() {
267
238
  value: function start() {
268
239
  var _this = this;
269
240
  return _async_to_generator(function() {
241
+ var e, e1, e2;
270
242
  return _ts_generator(this, function(_state) {
271
243
  switch(_state.label){
272
244
  case 0:
273
- if (!_this.config.gatekeeperConfig) return [
274
- 3,
275
- 2
276
- ];
245
+ _state.trys.push([
246
+ 0,
247
+ 2,
248
+ ,
249
+ 3
250
+ ]);
277
251
  return [
278
252
  4,
279
- _this.startIntegratedKeymaster()
253
+ gatekeeper_sdk.start(_this._gatekeeperConfig)
280
254
  ];
281
255
  case 1:
282
- _this.serviceStarted = _state.sent();
256
+ _state.sent();
283
257
  return [
284
258
  3,
285
259
  3
286
260
  ];
287
261
  case 2:
288
- if (_this.config.keymasterConfig) {
289
- _this.serviceStarted = _this.startExternalKeymaster();
290
- } else {
291
- throw "Missing Gatekeeper or Keymaster config";
292
- }
293
- _state.label = 3;
294
- case 3:
262
+ e = _state.sent();
263
+ console.error("Error starting Gatekeeper service:", e);
295
264
  return [
296
- 2,
297
- _this.serviceStarted
265
+ 3,
266
+ 3
298
267
  ];
299
- }
300
- });
301
- })();
302
- }
303
- },
304
- {
305
- key: "startIntegratedKeymaster",
306
- value: function startIntegratedKeymaster() {
307
- var _this = this;
308
- return _async_to_generator(function() {
309
- var gatekeeper_sdk, cipher, e;
310
- return _ts_generator(this, function(_state) {
311
- switch(_state.label){
312
- case 0:
313
- console.log("Starting integrated Keymaster service");
314
- _state.label = 1;
315
- case 1:
268
+ case 3:
316
269
  _state.trys.push([
317
- 1,
318
- 8,
270
+ 3,
271
+ 5,
319
272
  ,
320
- 9
273
+ 6
321
274
  ]);
322
275
  return [
323
276
  4,
324
- Promise.resolve().then(function() {
325
- return /*#__PURE__*/ _interop_require_wildcard(require("@mdip/gatekeeper/sdk"));
326
- })
327
- ];
328
- case 2:
329
- gatekeeper_sdk = _state.sent();
330
- return [
331
- 4,
332
- gatekeeper_sdk.start(_this.config.gatekeeperConfig)
333
- ];
334
- case 3:
335
- _state.sent();
336
- return [
337
- 4,
338
- Promise.resolve().then(function() {
339
- return /*#__PURE__*/ _interop_require_wildcard(require("@mdip/cipher/node"));
277
+ keymaster_lib.start({
278
+ gatekeeper: gatekeeper_sdk,
279
+ wallet: _this._walletDb,
280
+ cipher: cipher
340
281
  })
341
282
  ];
342
283
  case 4:
343
- cipher = _state.sent();
284
+ _state.sent();
285
+ _this._serviceStarted = true;
344
286
  return [
345
- 4,
346
- Promise.resolve().then(function() {
347
- return /*#__PURE__*/ _interop_require_wildcard(require("@mdip/keymaster/lib"));
348
- })
287
+ 3,
288
+ 6
349
289
  ];
350
290
  case 5:
351
- _this.keymasterService = _state.sent();
291
+ e1 = _state.sent();
292
+ console.error("Error starting Keymaster service:", e1);
352
293
  return [
353
- 4,
354
- _this.keymasterService.start({
355
- cipher: cipher,
356
- gatekeeper: gatekeeper_sdk,
357
- wallet: _this.config.walletDb
358
- })
294
+ 3,
295
+ 6
359
296
  ];
360
297
  case 6:
361
- _state.sent();
298
+ _state.trys.push([
299
+ 6,
300
+ 8,
301
+ ,
302
+ 9
303
+ ]);
362
304
  return [
363
305
  4,
364
306
  _this.ensureWalletExists()
@@ -370,71 +312,16 @@ var Keymaster = /*#__PURE__*/ function() {
370
312
  9
371
313
  ];
372
314
  case 8:
373
- e = _state.sent();
374
- console.error("Error starting Keymaster service:", e);
375
- return [
376
- 2,
377
- false
378
- ];
379
- case 9:
380
- console.log("Started integrated Keymaster service");
381
- return [
382
- 2,
383
- true
384
- ];
385
- }
386
- });
387
- })();
388
- }
389
- },
390
- {
391
- key: "startExternalKeymaster",
392
- value: function startExternalKeymaster() {
393
- var _this = this;
394
- return _async_to_generator(function() {
395
- var e;
396
- return _ts_generator(this, function(_state) {
397
- switch(_state.label){
398
- case 0:
399
- console.log("Starting external Keymaster service");
400
- _state.label = 1;
401
- case 1:
402
- _state.trys.push([
403
- 1,
404
- 4,
405
- ,
406
- 5
407
- ]);
408
- return [
409
- 4,
410
- Promise.resolve().then(function() {
411
- return /*#__PURE__*/ _interop_require_wildcard(require("@mdip/keymaster/sdk"));
412
- })
413
- ];
414
- case 2:
415
- _this.keymasterService = _state.sent();
416
- return [
417
- 4,
418
- _this.keymasterService.start(_this.config.keymasterConfig)
419
- ];
420
- case 3:
421
- _state.sent();
315
+ e2 = _state.sent();
316
+ console.error("Error verifying existing wallet:", e2);
422
317
  return [
423
318
  3,
424
- 5
425
- ];
426
- case 4:
427
- e = _state.sent();
428
- console.error("Error starting Keymaster serivce:", e);
429
- return [
430
- 2,
431
- false
319
+ 9
432
320
  ];
433
- case 5:
434
- console.log("Started external Keymaster service");
321
+ case 9:
435
322
  return [
436
323
  2,
437
- true
324
+ _this._serviceStarted
438
325
  ];
439
326
  }
440
327
  });
@@ -460,7 +347,7 @@ var Keymaster = /*#__PURE__*/ function() {
460
347
  };
461
348
  return [
462
349
  4,
463
- _this.keymasterService.createChallenge(challengeSpec, options)
350
+ keymaster_lib.createChallenge(challengeSpec, options)
464
351
  ];
465
352
  case 1:
466
353
  challenge = _state.sent();
@@ -476,25 +363,6 @@ var Keymaster = /*#__PURE__*/ function() {
476
363
  })();
477
364
  }
478
365
  },
479
- {
480
- key: "showMnemonic",
481
- value: function showMnemonic() {
482
- var _this = this;
483
- return _async_to_generator(function() {
484
- return _ts_generator(this, function(_state) {
485
- if (!_this.serviceRunning()) {
486
- return [
487
- 2
488
- ];
489
- }
490
- return [
491
- 2,
492
- _this.keymasterService.decryptMnemonic()
493
- ];
494
- });
495
- })();
496
- }
497
- },
498
366
  {
499
367
  key: "verifyResponse",
500
368
  value: function verifyResponse(did, options) {
@@ -511,7 +379,7 @@ var Keymaster = /*#__PURE__*/ function() {
511
379
  }
512
380
  return [
513
381
  4,
514
- _this.keymasterService.verifyResponse(did, options)
382
+ keymaster_lib.verifyResponse(did, options)
515
383
  ];
516
384
  case 1:
517
385
  response = _state.sent();
@@ -529,13 +397,13 @@ var Keymaster = /*#__PURE__*/ function() {
529
397
  value: function ensureWalletExists() {
530
398
  var _this = this;
531
399
  return _async_to_generator(function() {
532
- var existing, walletConfig;
400
+ var existing;
533
401
  return _ts_generator(this, function(_state) {
534
402
  switch(_state.label){
535
403
  case 0:
536
404
  return [
537
405
  4,
538
- _this.config.walletDb.loadWallet()
406
+ _this._walletDb.loadWallet()
539
407
  ];
540
408
  case 1:
541
409
  existing = _state.sent();
@@ -545,15 +413,14 @@ var Keymaster = /*#__PURE__*/ function() {
545
413
  2
546
414
  ];
547
415
  }
548
- walletConfig = _this.config.walletConfig;
549
- console.log("Creating wallet with ID ".concat(walletConfig.id));
550
- if (!walletConfig.mnemonic) return [
416
+ console.log("Creating wallet with ID ".concat(_this._walletConfig.id));
417
+ if (!_this._walletConfig.mnemonic) return [
551
418
  3,
552
419
  3
553
420
  ];
554
421
  return [
555
422
  4,
556
- _this.keymasterService.newWallet(spec.mnenomic, true)
423
+ keymaster_lib.newWallet(spec.mnenomic, true)
557
424
  ];
558
425
  case 2:
559
426
  _state.sent();
@@ -561,11 +428,11 @@ var Keymaster = /*#__PURE__*/ function() {
561
428
  case 3:
562
429
  return [
563
430
  4,
564
- _this.keymasterService.createId(walletConfig.id, walletConfig.registry)
431
+ keymaster_lib.createId(_this._walletConfig.id, _this._walletConfig.registry)
565
432
  ];
566
433
  case 4:
567
434
  _state.sent();
568
- console.log("Created wallet with ID ".concat(walletConfig.id));
435
+ console.log("Created wallet with ID ".concat(_this._walletConfig.id));
569
436
  return [
570
437
  2
571
438
  ];
@@ -583,7 +450,7 @@ var Keymaster = /*#__PURE__*/ function() {
583
450
  return _ts_generator(this, function(_state) {
584
451
  switch(_state.label){
585
452
  case 0:
586
- _tmp = _this.serviceStarted;
453
+ _tmp = _this._serviceStarted;
587
454
  if (_tmp) return [
588
455
  3,
589
456
  2
@@ -604,26 +471,6 @@ var Keymaster = /*#__PURE__*/ function() {
604
471
  });
605
472
  })();
606
473
  }
607
- },
608
- {
609
- key: "validateConfig",
610
- value: function validateConfig(config) {
611
- if (config.gatekeeperConfig && config.keymasterConfig) {
612
- throw new Error("Cannot provide both a Gatekeeper and Keymaster config");
613
- }
614
- if (config.gatekeeperConfig) {
615
- var _config_walletDb, _config_walletDb1;
616
- if (!config.walletConfig) {
617
- throw new Error("Missing wallet config");
618
- }
619
- if (!((_config_walletDb = config.walletDb) === null || _config_walletDb === void 0 ? void 0 : _config_walletDb.loadWallet)) {
620
- throw new Error("Missing load wallet callback");
621
- }
622
- if (!((_config_walletDb1 = config.walletDb) === null || _config_walletDb1 === void 0 ? void 0 : _config_walletDb1.saveWallet)) {
623
- throw new Error("Missing save wallet callback");
624
- }
625
- }
626
- }
627
474
  }
628
475
  ]);
629
476
  return Keymaster;
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.cjs","../src/index.ts","../src/keymaster.ts"],"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","src_exports","Keymaster","module","exports","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper_sdk","cipher","e","console","log","keymasterService","gatekeeper","wallet","walletDb","ensureWalletExists","error","createChallenge","spec","options","challengeSpec","challenge","serviceRunning","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","mnenomic","createId","registry","Error","saveWallet"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAIA,WAAWC,OAAOC,MAAM;AAC5B,IAAIC,YAAYF,OAAOG,cAAc;AACrC,IAAIC,mBAAmBJ,OAAOK,wBAAwB;AACtD,IAAIC,oBAAoBN,OAAOO,mBAAmB;AAClD,IAAIC,eAAeR,OAAOS,cAAc;AACxC,IAAIC,eAAeV,OAAOW,SAAS,CAACC,cAAc;AAClD,IAAIC,WAAW,SAACC,QAAQC;IACtB,IAAK,IAAIC,QAAQD,IACfb,UAAUY,QAAQE,MAAM;QAAEC,KAAKF,GAAG,CAACC,KAAK;QAAEE,YAAY;IAAK;AAC/D;AACA,IAAIC,cAAc,SAACC,IAAIC,MAAMC,QAAQC;IACnC,IAAIF,QAAQ,CAAA,OAAOA,qCAAP,SAAOA,KAAG,MAAM,YAAY,OAAOA,SAAS,YAAY;YAC7D,kCAAA,2BAAA;;;gBAAA,IAAIG,MAAJ;gBACH,IAAI,CAACd,aAAae,IAAI,CAACL,IAAII,QAAQA,QAAQF,QACzCpB,UAAUkB,IAAII,KAAK;oBAAEP,KAAK;+BAAM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;;;;;;gBACvD;;;;YAEcZ,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKvB,cAAA;0CAAL;;;;gCAAwB;;oCAAM,MAAKE,KAAA;;;uCAAX;;;gCAA/B;;;;;;gBACF;;;;YAEQD,KAAAA;mBAAAA,SAAAA,eAAeF,MAAA;gBACrB,IAAIA,OAAOI,gBAAA,IAAoBJ,OAAOM,eAAA,EAAiB;oBACrD,MAAM,IAAIoC,MAAM;gBAClB;gBAEA,IAAI1C,OAAOI,gBAAA,EAAkB;wBAItBJ,kBAGAA;oBANL,IAAI,CAACA,OAAOiC,YAAA,EAAc;wBACxB,MAAM,IAAIS,MAAM;oBAClB;oBACA,IAAI,GAAC1C,mBAAAA,OAAOgB,QAAA,cAAPhB,uCAAAA,iBAAiBkC,UAAA,GAAY;wBAChC,MAAM,IAAIQ,MAAM;oBAClB;oBACA,IAAI,GAAC1C,oBAAAA,OAAOgB,QAAA,cAAPhB,wCAAAA,kBAAiB2C,UAAA,GAAY;wBAChC,MAAM,IAAID,MAAM;oBAClB;gBACF;YACF;;;;;AFvFF,6DAA6D;AAC7D,KAAM5C,CAAAA,OAAOC,OAAO,GAAG;IACrBF,WAAAA;AACF,CAAA","sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/index.ts\nvar src_exports = {};\n__export(src_exports, {\n Keymaster: () => Keymaster\n});\nmodule.exports = __toCommonJS(src_exports);\n\n// src/keymaster.ts\nvar Keymaster = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n const gatekeeper_sdk = await import(\"@mdip/gatekeeper/sdk\");\n await gatekeeper_sdk.start(this.config.gatekeeperConfig);\n const cipher = await import(\"@mdip/cipher/node\");\n this.keymasterService = await import(\"@mdip/keymaster/lib\");\n await this.keymasterService.start({\n cipher,\n gatekeeper: gatekeeper_sdk,\n wallet: this.config.walletDb\n });\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n async startExternalKeymaster() {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = await import(\"@mdip/keymaster/sdk\");\n await this.keymasterService.start(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster serivce:`, e);\n return false;\n }\n console.log(`Started external Keymaster service`);\n return true;\n }\n async createChallenge(spec2, options) {\n if (!this.serviceRunning()) {\n return;\n }\n const challengeSpec = { challenge: spec2 };\n const challenge = await this.keymasterService.createChallenge(\n challengeSpec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec2.callback}?challenge=${challenge}`\n };\n }\n async showMnemonic() {\n if (!this.serviceRunning()) {\n return;\n }\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n return;\n }\n const response = await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n async ensureWalletExists() {\n const existing = await this.config.walletDb.loadWallet();\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n const walletConfig = this.config.walletConfig;\n console.log(`Creating wallet with ID ${walletConfig.id}`);\n if (walletConfig.mnemonic) {\n await this.keymasterService.newWallet(spec.mnenomic, true);\n }\n await this.keymasterService.createId(\n walletConfig.id,\n walletConfig.registry\n );\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n async serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n};\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n Keymaster\n});\n","export {\n CreateChallengeOptions,\n CreateChallengeResponse,\n CreateChallengeSpec,\n Keymaster,\n KeymasterConfig,\n SdkConfig,\n VerifyResponseOptions,\n VerifyResponseResponse,\n Wallet,\n WalletConfig,\n WalletDb,\n WalletSeed,\n} from \"./keymaster\";\n","// @ts-ignore\n// @ts-nocheck\nimport { initalizeWalletDb, DbType } from \"./db\";\nimport * as wallet_db from \"./db/test\";\n\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: [];\n}\n\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\n\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\n\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\n\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n}\n\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\n\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\n}\n\n// config for connecting to an external Gatekeeper or Keymaster\nexport interface SdkConfig {\n url: string;\n waitUntilReady?: boolean;\n intervalSeconds?: number;\n chatty?: boolean;\n}\n\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\n}\n\nexport interface WalletDb {\n loadWallet: () => Promise<Wallet | null>;\n saveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;\n}\n\nexport interface KeymasterConfig {\n /**\n * Config for connecting to an external Keymaster service\n * when the consuming applciation is connecting to an external Keymaster.\n */\n keymasterConfig?: SdkConfig;\n /**\n * Config for connecting to an external Keymaster service when\n * the consuming applciation is acting as its own (integrated) Keymaster service.\n */\n gatekeeperConfig?: SdkConfig;\n /**\n * Config for custom user-defined values of the underlying wallet.\n *\n * Required for an integrated Keymaster.\n */\n walletConfig?: WalletConfig;\n /**\n * Config that contains the callbacks for persisting a\n * wallet to a backing Database.\n */\n walletDb?: WalletDb;\n}\n\nexport class Keymaster {\n private config: KeymasterConfig;\n /**\n * Underlying Keymaster libray based on the use-case:\n *\n * Integrated Keymaster = keymaster_lib\n *\n * External Keymaster = keymaster_sdk\n */\n private keymasterService;\n private serviceStarted = false;\n\n constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public async start(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n private async startIntegratedKeymaster(): Promise<boolean> {\n console.log(`Starting integrated Keymaster service`);\n\n try {\n const gatekeeper_sdk = await import(\"@mdip/gatekeeper/sdk\");\n await gatekeeper_sdk.start(this.config.gatekeeperConfig);\n\n const cipher = await import(\"@mdip/cipher/node\");\n\n this.keymasterService = await import(\"@mdip/keymaster/lib\");\n await this.keymasterService.start({\n cipher: cipher,\n gatekeeper: gatekeeper_sdk,\n wallet: this.config.walletDb,\n });\n\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n\n private async startExternalKeymaster(): Promise<boolean> {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = await import(\"@mdip/keymaster/sdk\");\n await this.keymasterService.start(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster serivce:`, e);\n return false;\n }\n\n console.log(`Started external Keymaster service`);\n return true;\n }\n\n async createChallenge(\n spec: CreateChallengeSpec,\n options?: CreateChallengeOptions\n ): Promise<CreateChallengeResponse> {\n if (!this.serviceRunning()) {\n return;\n }\n const challengeSpec = { challenge: spec };\n const challenge: string = await this.keymasterService.createChallenge(\n challengeSpec,\n options\n );\n return {\n challenge: challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`,\n };\n }\n\n async showMnemonic(): Promise<string> {\n if (!this.serviceRunning()) {\n return;\n }\n return this.keymasterService.decryptMnemonic();\n }\n\n async verifyResponse(\n did: string,\n options?: VerifyResponseOptions\n ): Promise<VerifyResponseResponse> {\n if (!this.serviceRunning()) {\n return;\n }\n const response: VerifyResponseResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n const existing: Wallet | null = await this.config.walletDb.loadWallet();\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n\n const walletConfig = this.config.walletConfig;\n console.log(`Creating wallet with ID ${walletConfig.id}`);\n // wallet was just created, recreate based on config\n if (walletConfig.mnemonic) {\n // create the wallet with a custom mnemonic first\n await this.keymasterService.newWallet(spec.mnenomic, true);\n }\n // create ID and set as current, createId() will save wallet\n await this.keymasterService.createId(\n walletConfig.id,\n walletConfig.registry\n );\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.start());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.cjs","../src/index.ts","../src/keymaster.ts"],"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","src_exports","Keymaster","module","exports","cipher","require","gatekeeper_sdk","keymaster_lib","config","_serviceStarted","_gatekeeperConfig","url","gatekeeperConfig","waitUntilReady","intervalSeconds","chatty","_walletConfig","walletConfig","_walletDb","saveWallet","onSaveWallet","loadWallet","onLoadWallet","start","e","console","error","gatekeeper","wallet","ensureWalletExists","createChallenge","spec","options","challengeSpec","challenge","serviceRunning","challengeUrl","callback","verifyResponse","did","response","existing","current","log","id","mnemonic","newWallet","mnenomic","createId","registry"],"mappings":"AAAA;;;;;;;;;;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AoBxC,cAAAyC,QAAA,CAClB,MAAKhC,aAAA,CAAc4B,EAAA,EACnB,MAAK5B,aAAA,CAAciC,QAAA;;;gCAFrB;gCAIAxB,QAAQkB,GAAA,CAAI,0BAA+C,OAArB,MAAK3B,aAAA,CAAc4B,EAAE;;;;;;gBAC7D;;;;YAEcT,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAK1B,eAAA;0CAAL;;;;gCAAyB;;oCAAM,MAAKc,KAAA;;;uCAAX;;;gCAAhC;;;;;;gBACF;;;;;;AFlDF,6DAA6D;AAC7D,KAAMrB,CAAAA,OAAOC,OAAO,GAAG;IACrBF,WAAAA;AACF,CAAA","sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/index.ts\nvar src_exports = {};\n__export(src_exports, {\n Keymaster: () => Keymaster\n});\nmodule.exports = __toCommonJS(src_exports);\n\n// src/keymaster.ts\nvar cipher = __toESM(require(\"@mdip/cipher/node\"), 1);\nvar gatekeeper_sdk = __toESM(require(\"@mdip/gatekeeper/sdk\"), 1);\nvar keymaster_lib = __toESM(require(\"@mdip/keymaster/lib\"), 1);\nvar Keymaster = class {\n constructor(config) {\n this._serviceStarted = false;\n this._gatekeeperConfig = {\n url: config.gatekeeperConfig.url,\n waitUntilReady: true,\n intervalSeconds: 5,\n chatty: true\n };\n this._walletConfig = config.walletConfig;\n this._walletDb = {\n saveWallet: config.onSaveWallet,\n loadWallet: config.onLoadWallet\n };\n }\n async start() {\n try {\n await gatekeeper_sdk.start(this._gatekeeperConfig);\n } catch (e) {\n console.error(\"Error starting Gatekeeper service:\", e);\n }\n try {\n await keymaster_lib.start({\n gatekeeper: gatekeeper_sdk,\n wallet: this._walletDb,\n cipher\n });\n this._serviceStarted = true;\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n }\n try {\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error verifying existing wallet:\", e);\n }\n return this._serviceStarted;\n }\n async createChallenge(spec2, options) {\n if (!this.serviceRunning()) {\n return;\n }\n const challengeSpec = { challenge: spec2 };\n const challenge = await keymaster_lib.createChallenge(\n challengeSpec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec2.callback}?challenge=${challenge}`\n };\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n return;\n }\n const response = await keymaster_lib.verifyResponse(\n did,\n options\n );\n return response;\n }\n async ensureWalletExists() {\n const existing = await this._walletDb.loadWallet();\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n console.log(`Creating wallet with ID ${this._walletConfig.id}`);\n if (this._walletConfig.mnemonic) {\n await keymaster_lib.newWallet(spec.mnenomic, true);\n }\n await keymaster_lib.createId(\n this._walletConfig.id,\n this._walletConfig.registry\n );\n console.log(`Created wallet with ID ${this._walletConfig.id}`);\n }\n async serviceRunning() {\n return this._serviceStarted || await this.start();\n }\n};\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n Keymaster\n});\n","export {\n GatekeeperConfig,\n Keymaster,\n KeymasterConfig,\n CreateChallengeOptions,\n CreateChallengeResponse,\n CreateChallengeSpec,\n VerifyResponseOptions,\n VerifyResponseResponse,\n Wallet,\n WalletConfig,\n WalletSeed,\n} from \"./keymaster\";\n","// @ts-ignore\n// @ts-nocheck\nimport * as cipher from \"@mdip/cipher/node\";\nimport * as gatekeeper_sdk from \"@mdip/gatekeeper/sdk\";\nimport * as keymaster_lib from \"@mdip/keymaster/lib\";\n\nimport { initalizeWalletDb, DbType } from \"./db\";\nimport * as wallet_db from \"./db/test\";\n\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: [];\n}\n\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\n\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\n\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\n\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n}\n\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\n\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\n}\n\nexport interface GatekeeperConfig {\n url: string;\n waitUntilReady?: boolean;\n intervalSeconds?: number;\n chatty?: boolean;\n}\n\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\n}\n\nexport interface KeymasterConfig {\n gatekeeperConfig: GatekeeperConfig;\n walletConfig: WalletConfig;\n onSaveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;\n onLoadWallet: () => Promise<Wallet | null>;\n}\n\nexport class Keymaster {\n private _gatekeeperConfig;\n private _walletConfig;\n private _walletDb;\n private _serviceStarted = false;\n\n constructor(config: KeymasterConfig) {\n this._gatekeeperConfig = {\n url: config.gatekeeperConfig.url,\n waitUntilReady: true,\n intervalSeconds: 5,\n chatty: true,\n };\n this._walletConfig = config.walletConfig;\n this._walletDb = {\n saveWallet: config.onSaveWallet,\n loadWallet: config.onLoadWallet,\n };\n }\n\n public async start(): Promise<boolean> {\n try {\n await gatekeeper_sdk.start(this._gatekeeperConfig);\n } catch (e) {\n console.error(\"Error starting Gatekeeper service:\", e);\n }\n\n try {\n await keymaster_lib.start({\n gatekeeper: gatekeeper_sdk,\n wallet: this._walletDb,\n cipher: cipher,\n });\n this._serviceStarted = true;\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n }\n\n try {\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error verifying existing wallet:\", e);\n }\n\n return this._serviceStarted;\n }\n\n async createChallenge(\n spec: CreateChallengeSpec,\n options?: CreateChallengeOptions\n ): Promise<CreateChallengeResponse> {\n if (!this.serviceRunning()) {\n return;\n }\n const challengeSpec = { challenge: spec };\n const challenge: string = await keymaster_lib.createChallenge(\n challengeSpec,\n options\n );\n return {\n challenge: challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`,\n };\n }\n\n async verifyResponse(\n did: string,\n options?: VerifyResponseOptions\n ): Promise<VerifyResponseResponse> {\n if (!this.serviceRunning()) {\n return;\n }\n const response: VerifyResponseResponse = await keymaster_lib.verifyResponse(\n did,\n options\n );\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n const existing: Wallet | null = await this._walletDb.loadWallet();\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n\n console.log(`Creating wallet with ID ${this._walletConfig.id}`);\n // wallet was just created, recreate based on config\n if (this._walletConfig.mnemonic) {\n // create the wallet with a custom mnemonic first\n await keymaster_lib.newWallet(spec.mnenomic, true);\n }\n // create ID and set as current, createId() will save wallet\n await keymaster_lib.createId(\n this._walletConfig.id,\n this._walletConfig.registry\n );\n console.log(`Created wallet with ID ${this._walletConfig.id}`);\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this._serviceStarted || (await this.start());\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -32,7 +32,7 @@ interface Wallet {
32
32
  ids: any;
33
33
  current?: string;
34
34
  }
35
- interface SdkConfig {
35
+ interface GatekeeperConfig {
36
36
  url: string;
37
37
  waitUntilReady?: boolean;
38
38
  intervalSeconds?: number;
@@ -43,54 +43,23 @@ interface WalletConfig {
43
43
  mnemonic?: string;
44
44
  registry?: string;
45
45
  }
46
- interface WalletDb {
47
- loadWallet: () => Promise<Wallet | null>;
48
- saveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;
49
- }
50
46
  interface KeymasterConfig {
51
- /**
52
- * Config for connecting to an external Keymaster service
53
- * when the consuming applciation is connecting to an external Keymaster.
54
- */
55
- keymasterConfig?: SdkConfig;
56
- /**
57
- * Config for connecting to an external Keymaster service when
58
- * the consuming applciation is acting as its own (integrated) Keymaster service.
59
- */
60
- gatekeeperConfig?: SdkConfig;
61
- /**
62
- * Config for custom user-defined values of the underlying wallet.
63
- *
64
- * Required for an integrated Keymaster.
65
- */
66
- walletConfig?: WalletConfig;
67
- /**
68
- * Config that contains the callbacks for persisting a
69
- * wallet to a backing Database.
70
- */
71
- walletDb?: WalletDb;
47
+ gatekeeperConfig: GatekeeperConfig;
48
+ walletConfig: WalletConfig;
49
+ onSaveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;
50
+ onLoadWallet: () => Promise<Wallet | null>;
72
51
  }
73
52
  declare class Keymaster {
74
- private config;
75
- /**
76
- * Underlying Keymaster libray based on the use-case:
77
- *
78
- * Integrated Keymaster = keymaster_lib
79
- *
80
- * External Keymaster = keymaster_sdk
81
- */
82
- private keymasterService;
83
- private serviceStarted;
53
+ private _gatekeeperConfig;
54
+ private _walletConfig;
55
+ private _walletDb;
56
+ private _serviceStarted;
84
57
  constructor(config: KeymasterConfig);
85
58
  start(): Promise<boolean>;
86
- private startIntegratedKeymaster;
87
- private startExternalKeymaster;
88
59
  createChallenge(spec: CreateChallengeSpec, options?: CreateChallengeOptions): Promise<CreateChallengeResponse>;
89
- showMnemonic(): Promise<string>;
90
60
  verifyResponse(did: string, options?: VerifyResponseOptions): Promise<VerifyResponseResponse>;
91
61
  private ensureWalletExists;
92
62
  private serviceRunning;
93
- private validateConfig;
94
63
  }
95
64
 
96
- export { type CreateChallengeOptions, type CreateChallengeResponse, type CreateChallengeSpec, Keymaster, type KeymasterConfig, type SdkConfig, type VerifyResponseOptions, type VerifyResponseResponse, type Wallet, type WalletConfig, type WalletDb, type WalletSeed };
65
+ export { type CreateChallengeOptions, type CreateChallengeResponse, type CreateChallengeSpec, type GatekeeperConfig, Keymaster, type KeymasterConfig, type VerifyResponseOptions, type VerifyResponseResponse, type Wallet, type WalletConfig, type WalletSeed };
package/dist/index.d.ts CHANGED
@@ -32,7 +32,7 @@ interface Wallet {
32
32
  ids: any;
33
33
  current?: string;
34
34
  }
35
- interface SdkConfig {
35
+ interface GatekeeperConfig {
36
36
  url: string;
37
37
  waitUntilReady?: boolean;
38
38
  intervalSeconds?: number;
@@ -43,54 +43,23 @@ interface WalletConfig {
43
43
  mnemonic?: string;
44
44
  registry?: string;
45
45
  }
46
- interface WalletDb {
47
- loadWallet: () => Promise<Wallet | null>;
48
- saveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;
49
- }
50
46
  interface KeymasterConfig {
51
- /**
52
- * Config for connecting to an external Keymaster service
53
- * when the consuming applciation is connecting to an external Keymaster.
54
- */
55
- keymasterConfig?: SdkConfig;
56
- /**
57
- * Config for connecting to an external Keymaster service when
58
- * the consuming applciation is acting as its own (integrated) Keymaster service.
59
- */
60
- gatekeeperConfig?: SdkConfig;
61
- /**
62
- * Config for custom user-defined values of the underlying wallet.
63
- *
64
- * Required for an integrated Keymaster.
65
- */
66
- walletConfig?: WalletConfig;
67
- /**
68
- * Config that contains the callbacks for persisting a
69
- * wallet to a backing Database.
70
- */
71
- walletDb?: WalletDb;
47
+ gatekeeperConfig: GatekeeperConfig;
48
+ walletConfig: WalletConfig;
49
+ onSaveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;
50
+ onLoadWallet: () => Promise<Wallet | null>;
72
51
  }
73
52
  declare class Keymaster {
74
- private config;
75
- /**
76
- * Underlying Keymaster libray based on the use-case:
77
- *
78
- * Integrated Keymaster = keymaster_lib
79
- *
80
- * External Keymaster = keymaster_sdk
81
- */
82
- private keymasterService;
83
- private serviceStarted;
53
+ private _gatekeeperConfig;
54
+ private _walletConfig;
55
+ private _walletDb;
56
+ private _serviceStarted;
84
57
  constructor(config: KeymasterConfig);
85
58
  start(): Promise<boolean>;
86
- private startIntegratedKeymaster;
87
- private startExternalKeymaster;
88
59
  createChallenge(spec: CreateChallengeSpec, options?: CreateChallengeOptions): Promise<CreateChallengeResponse>;
89
- showMnemonic(): Promise<string>;
90
60
  verifyResponse(did: string, options?: VerifyResponseOptions): Promise<VerifyResponseResponse>;
91
61
  private ensureWalletExists;
92
62
  private serviceRunning;
93
- private validateConfig;
94
63
  }
95
64
 
96
- export { type CreateChallengeOptions, type CreateChallengeResponse, type CreateChallengeSpec, Keymaster, type KeymasterConfig, type SdkConfig, type VerifyResponseOptions, type VerifyResponseResponse, type Wallet, type WalletConfig, type WalletDb, type WalletSeed };
65
+ export { type CreateChallengeOptions, type CreateChallengeResponse, type CreateChallengeSpec, type GatekeeperConfig, Keymaster, type KeymasterConfig, type VerifyResponseOptions, type VerifyResponseResponse, type Wallet, type WalletConfig, type WalletSeed };
package/dist/index.js CHANGED
@@ -142,13 +142,25 @@ function _ts_generator(thisArg, body) {
142
142
  };
143
143
  }
144
144
  }
145
+ import * as cipher from "@mdip/cipher/node";
146
+ import * as gatekeeper_sdk from "@mdip/gatekeeper/sdk";
147
+ import * as keymaster_lib from "@mdip/keymaster/lib";
145
148
  var Keymaster = /*#__PURE__*/ function() {
146
149
  "use strict";
147
150
  function Keymaster(config) {
148
151
  _class_call_check(this, Keymaster);
149
- this.serviceStarted = false;
150
- this.validateConfig(config);
151
- this.config = config;
152
+ this._serviceStarted = false;
153
+ this._gatekeeperConfig = {
154
+ url: config.gatekeeperConfig.url,
155
+ waitUntilReady: true,
156
+ intervalSeconds: 5,
157
+ chatty: true
158
+ };
159
+ this._walletConfig = config.walletConfig;
160
+ this._walletDb = {
161
+ saveWallet: config.onSaveWallet,
162
+ loadWallet: config.onLoadWallet
163
+ };
152
164
  }
153
165
  _create_class(Keymaster, [
154
166
  {
@@ -156,92 +168,69 @@ var Keymaster = /*#__PURE__*/ function() {
156
168
  value: function start() {
157
169
  var _this = this;
158
170
  return _async_to_generator(function() {
171
+ var e, e1, e2;
159
172
  return _ts_generator(this, function(_state) {
160
173
  switch(_state.label){
161
174
  case 0:
162
- if (!_this.config.gatekeeperConfig) return [
163
- 3,
164
- 2
165
- ];
175
+ _state.trys.push([
176
+ 0,
177
+ 2,
178
+ ,
179
+ 3
180
+ ]);
166
181
  return [
167
182
  4,
168
- _this.startIntegratedKeymaster()
183
+ gatekeeper_sdk.start(_this._gatekeeperConfig)
169
184
  ];
170
185
  case 1:
171
- _this.serviceStarted = _state.sent();
186
+ _state.sent();
172
187
  return [
173
188
  3,
174
189
  3
175
190
  ];
176
191
  case 2:
177
- if (_this.config.keymasterConfig) {
178
- _this.serviceStarted = _this.startExternalKeymaster();
179
- } else {
180
- throw "Missing Gatekeeper or Keymaster config";
181
- }
182
- _state.label = 3;
183
- case 3:
192
+ e = _state.sent();
193
+ console.error("Error starting Gatekeeper service:", e);
184
194
  return [
185
- 2,
186
- _this.serviceStarted
195
+ 3,
196
+ 3
187
197
  ];
188
- }
189
- });
190
- })();
191
- }
192
- },
193
- {
194
- key: "startIntegratedKeymaster",
195
- value: function startIntegratedKeymaster() {
196
- var _this = this;
197
- return _async_to_generator(function() {
198
- var gatekeeper_sdk, cipher, e;
199
- return _ts_generator(this, function(_state) {
200
- switch(_state.label){
201
- case 0:
202
- console.log("Starting integrated Keymaster service");
203
- _state.label = 1;
204
- case 1:
198
+ case 3:
205
199
  _state.trys.push([
206
- 1,
207
- 8,
200
+ 3,
201
+ 5,
208
202
  ,
209
- 9
203
+ 6
210
204
  ]);
211
205
  return [
212
206
  4,
213
- import("@mdip/gatekeeper/sdk")
214
- ];
215
- case 2:
216
- gatekeeper_sdk = _state.sent();
217
- return [
218
- 4,
219
- gatekeeper_sdk.start(_this.config.gatekeeperConfig)
220
- ];
221
- case 3:
222
- _state.sent();
223
- return [
224
- 4,
225
- import("@mdip/cipher/node")
207
+ keymaster_lib.start({
208
+ gatekeeper: gatekeeper_sdk,
209
+ wallet: _this._walletDb,
210
+ cipher: cipher
211
+ })
226
212
  ];
227
213
  case 4:
228
- cipher = _state.sent();
214
+ _state.sent();
215
+ _this._serviceStarted = true;
229
216
  return [
230
- 4,
231
- import("@mdip/keymaster/lib")
217
+ 3,
218
+ 6
232
219
  ];
233
220
  case 5:
234
- _this.keymasterService = _state.sent();
221
+ e1 = _state.sent();
222
+ console.error("Error starting Keymaster service:", e1);
235
223
  return [
236
- 4,
237
- _this.keymasterService.start({
238
- cipher: cipher,
239
- gatekeeper: gatekeeper_sdk,
240
- wallet: _this.config.walletDb
241
- })
224
+ 3,
225
+ 6
242
226
  ];
243
227
  case 6:
244
- _state.sent();
228
+ _state.trys.push([
229
+ 6,
230
+ 8,
231
+ ,
232
+ 9
233
+ ]);
245
234
  return [
246
235
  4,
247
236
  _this.ensureWalletExists()
@@ -253,69 +242,16 @@ var Keymaster = /*#__PURE__*/ function() {
253
242
  9
254
243
  ];
255
244
  case 8:
256
- e = _state.sent();
257
- console.error("Error starting Keymaster service:", e);
258
- return [
259
- 2,
260
- false
261
- ];
262
- case 9:
263
- console.log("Started integrated Keymaster service");
264
- return [
265
- 2,
266
- true
267
- ];
268
- }
269
- });
270
- })();
271
- }
272
- },
273
- {
274
- key: "startExternalKeymaster",
275
- value: function startExternalKeymaster() {
276
- var _this = this;
277
- return _async_to_generator(function() {
278
- var e;
279
- return _ts_generator(this, function(_state) {
280
- switch(_state.label){
281
- case 0:
282
- console.log("Starting external Keymaster service");
283
- _state.label = 1;
284
- case 1:
285
- _state.trys.push([
286
- 1,
287
- 4,
288
- ,
289
- 5
290
- ]);
291
- return [
292
- 4,
293
- import("@mdip/keymaster/sdk")
294
- ];
295
- case 2:
296
- _this.keymasterService = _state.sent();
297
- return [
298
- 4,
299
- _this.keymasterService.start(_this.config.keymasterConfig)
300
- ];
301
- case 3:
302
- _state.sent();
245
+ e2 = _state.sent();
246
+ console.error("Error verifying existing wallet:", e2);
303
247
  return [
304
248
  3,
305
- 5
306
- ];
307
- case 4:
308
- e = _state.sent();
309
- console.error("Error starting Keymaster serivce:", e);
310
- return [
311
- 2,
312
- false
249
+ 9
313
250
  ];
314
- case 5:
315
- console.log("Started external Keymaster service");
251
+ case 9:
316
252
  return [
317
253
  2,
318
- true
254
+ _this._serviceStarted
319
255
  ];
320
256
  }
321
257
  });
@@ -341,7 +277,7 @@ var Keymaster = /*#__PURE__*/ function() {
341
277
  };
342
278
  return [
343
279
  4,
344
- _this.keymasterService.createChallenge(challengeSpec, options)
280
+ keymaster_lib.createChallenge(challengeSpec, options)
345
281
  ];
346
282
  case 1:
347
283
  challenge = _state.sent();
@@ -357,25 +293,6 @@ var Keymaster = /*#__PURE__*/ function() {
357
293
  })();
358
294
  }
359
295
  },
360
- {
361
- key: "showMnemonic",
362
- value: function showMnemonic() {
363
- var _this = this;
364
- return _async_to_generator(function() {
365
- return _ts_generator(this, function(_state) {
366
- if (!_this.serviceRunning()) {
367
- return [
368
- 2
369
- ];
370
- }
371
- return [
372
- 2,
373
- _this.keymasterService.decryptMnemonic()
374
- ];
375
- });
376
- })();
377
- }
378
- },
379
296
  {
380
297
  key: "verifyResponse",
381
298
  value: function verifyResponse(did, options) {
@@ -392,7 +309,7 @@ var Keymaster = /*#__PURE__*/ function() {
392
309
  }
393
310
  return [
394
311
  4,
395
- _this.keymasterService.verifyResponse(did, options)
312
+ keymaster_lib.verifyResponse(did, options)
396
313
  ];
397
314
  case 1:
398
315
  response = _state.sent();
@@ -410,13 +327,13 @@ var Keymaster = /*#__PURE__*/ function() {
410
327
  value: function ensureWalletExists() {
411
328
  var _this = this;
412
329
  return _async_to_generator(function() {
413
- var existing, walletConfig;
330
+ var existing;
414
331
  return _ts_generator(this, function(_state) {
415
332
  switch(_state.label){
416
333
  case 0:
417
334
  return [
418
335
  4,
419
- _this.config.walletDb.loadWallet()
336
+ _this._walletDb.loadWallet()
420
337
  ];
421
338
  case 1:
422
339
  existing = _state.sent();
@@ -426,15 +343,14 @@ var Keymaster = /*#__PURE__*/ function() {
426
343
  2
427
344
  ];
428
345
  }
429
- walletConfig = _this.config.walletConfig;
430
- console.log("Creating wallet with ID ".concat(walletConfig.id));
431
- if (!walletConfig.mnemonic) return [
346
+ console.log("Creating wallet with ID ".concat(_this._walletConfig.id));
347
+ if (!_this._walletConfig.mnemonic) return [
432
348
  3,
433
349
  3
434
350
  ];
435
351
  return [
436
352
  4,
437
- _this.keymasterService.newWallet(spec.mnenomic, true)
353
+ keymaster_lib.newWallet(spec.mnenomic, true)
438
354
  ];
439
355
  case 2:
440
356
  _state.sent();
@@ -442,11 +358,11 @@ var Keymaster = /*#__PURE__*/ function() {
442
358
  case 3:
443
359
  return [
444
360
  4,
445
- _this.keymasterService.createId(walletConfig.id, walletConfig.registry)
361
+ keymaster_lib.createId(_this._walletConfig.id, _this._walletConfig.registry)
446
362
  ];
447
363
  case 4:
448
364
  _state.sent();
449
- console.log("Created wallet with ID ".concat(walletConfig.id));
365
+ console.log("Created wallet with ID ".concat(_this._walletConfig.id));
450
366
  return [
451
367
  2
452
368
  ];
@@ -464,7 +380,7 @@ var Keymaster = /*#__PURE__*/ function() {
464
380
  return _ts_generator(this, function(_state) {
465
381
  switch(_state.label){
466
382
  case 0:
467
- _tmp = _this.serviceStarted;
383
+ _tmp = _this._serviceStarted;
468
384
  if (_tmp) return [
469
385
  3,
470
386
  2
@@ -485,26 +401,6 @@ var Keymaster = /*#__PURE__*/ function() {
485
401
  });
486
402
  })();
487
403
  }
488
- },
489
- {
490
- key: "validateConfig",
491
- value: function validateConfig(config) {
492
- if (config.gatekeeperConfig && config.keymasterConfig) {
493
- throw new Error("Cannot provide both a Gatekeeper and Keymaster config");
494
- }
495
- if (config.gatekeeperConfig) {
496
- var _config_walletDb, _config_walletDb1;
497
- if (!config.walletConfig) {
498
- throw new Error("Missing wallet config");
499
- }
500
- if (!((_config_walletDb = config.walletDb) === null || _config_walletDb === void 0 ? void 0 : _config_walletDb.loadWallet)) {
501
- throw new Error("Missing load wallet callback");
502
- }
503
- if (!((_config_walletDb1 = config.walletDb) === null || _config_walletDb1 === void 0 ? void 0 : _config_walletDb1.saveWallet)) {
504
- throw new Error("Missing save wallet callback");
505
- }
506
- }
507
- }
508
404
  }
509
405
  ]);
510
406
  return Keymaster;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.js","../src/keymaster.ts"],"names":["Keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper_sdk","cipher","e","console","log","keymasterService","gatekeeper","wallet","walletDb","ensureWalletExists","error","createChallenge","spec","options","challengeSpec","challenge","serviceRunning","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","mnenomic","createId","registry","Error","saveWallet"],"mappings":"AAAA,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACyFZ,IAAMA,0BAAN;;aAAMA,UAYCC,MAAA;gCAZDD;QAUX,IAAA,CAAQE,cAAA,GAAiB;QAGvB,IAAA,CAAKC,cAAA,CAAeF;QACpB,IAAA,CAAK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AI,2BAA0C,OAAfqB,aAAaG,EAAE;qCAElDH,aAAaI,QAAA,EAAbJ;;;;gCAEF;;oCAAM,MAAKpB,gBAAA,CAAiByB,SAAA,CAAUlB,KAAKmB,QAAA,EAAU;;;gCAArD;;;gCAGF;;oCAAM,MAAK1B,gBAAA,CAAiB2B,QAAA,CAC1BP,aAAaG,EAAA,EACbH,aAAaQ,QAAA;;;gCAFf;gCAIA9B,QAAQC,GAAA,CAAI,0BAAyC,OAAfqB,aAAaG,EAAE;;;;;;gBACvD;;;;YAEcZ,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKvB,cAAA;0CAAL;;;;gCAAwB;;oCAAM,MAAKE,KAAA;;;uCAAX;;;gCAA/B;;;;;;gBACF;;;;YAEQD,KAAAA;mBAAAA,SAAAA,eAAeF,MAAA;gBACrB,IAAIA,OAAOI,gBAAA,IAAoBJ,OAAOM,eAAA,EAAiB;oBACrD,MAAM,IAAIoC,MAAM;gBAClB;gBAEA,IAAI1C,OAAOI,gBAAA,EAAkB;wBAItBJ,kBAGAA;oBANL,IAAI,CAACA,OAAOiC,YAAA,EAAc;wBACxB,MAAM,IAAIS,MAAM;oBAClB;oBACA,IAAI,GAAC1C,mBAAAA,OAAOgB,QAAA,cAAPhB,uCAAAA,iBAAiBkC,UAAA,GAAY;wBAChC,MAAM,IAAIQ,MAAM;oBAClB;oBACA,IAAI,GAAC1C,oBAAAA,OAAOgB,QAAA,cAAPhB,wCAAAA,kBAAiB2C,UAAA,GAAY;wBAChC,MAAM,IAAID,MAAM;oBAClB;gBACF;YACF;;;;;AD3HF,SACE3C,SAAS,GACT","sourcesContent":["// src/keymaster.ts\nvar Keymaster = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n const gatekeeper_sdk = await import(\"@mdip/gatekeeper/sdk\");\n await gatekeeper_sdk.start(this.config.gatekeeperConfig);\n const cipher = await import(\"@mdip/cipher/node\");\n this.keymasterService = await import(\"@mdip/keymaster/lib\");\n await this.keymasterService.start({\n cipher,\n gatekeeper: gatekeeper_sdk,\n wallet: this.config.walletDb\n });\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n async startExternalKeymaster() {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = await import(\"@mdip/keymaster/sdk\");\n await this.keymasterService.start(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster serivce:`, e);\n return false;\n }\n console.log(`Started external Keymaster service`);\n return true;\n }\n async createChallenge(spec2, options) {\n if (!this.serviceRunning()) {\n return;\n }\n const challengeSpec = { challenge: spec2 };\n const challenge = await this.keymasterService.createChallenge(\n challengeSpec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec2.callback}?challenge=${challenge}`\n };\n }\n async showMnemonic() {\n if (!this.serviceRunning()) {\n return;\n }\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n return;\n }\n const response = await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n async ensureWalletExists() {\n const existing = await this.config.walletDb.loadWallet();\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n const walletConfig = this.config.walletConfig;\n console.log(`Creating wallet with ID ${walletConfig.id}`);\n if (walletConfig.mnemonic) {\n await this.keymasterService.newWallet(spec.mnenomic, true);\n }\n await this.keymasterService.createId(\n walletConfig.id,\n walletConfig.registry\n );\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n async serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n};\nexport {\n Keymaster\n};\n","// @ts-ignore\n// @ts-nocheck\nimport { initalizeWalletDb, DbType } from \"./db\";\nimport * as wallet_db from \"./db/test\";\n\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: [];\n}\n\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\n\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\n\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\n\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n}\n\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\n\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\n}\n\n// config for connecting to an external Gatekeeper or Keymaster\nexport interface SdkConfig {\n url: string;\n waitUntilReady?: boolean;\n intervalSeconds?: number;\n chatty?: boolean;\n}\n\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\n}\n\nexport interface WalletDb {\n loadWallet: () => Promise<Wallet | null>;\n saveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;\n}\n\nexport interface KeymasterConfig {\n /**\n * Config for connecting to an external Keymaster service\n * when the consuming applciation is connecting to an external Keymaster.\n */\n keymasterConfig?: SdkConfig;\n /**\n * Config for connecting to an external Keymaster service when\n * the consuming applciation is acting as its own (integrated) Keymaster service.\n */\n gatekeeperConfig?: SdkConfig;\n /**\n * Config for custom user-defined values of the underlying wallet.\n *\n * Required for an integrated Keymaster.\n */\n walletConfig?: WalletConfig;\n /**\n * Config that contains the callbacks for persisting a\n * wallet to a backing Database.\n */\n walletDb?: WalletDb;\n}\n\nexport class Keymaster {\n private config: KeymasterConfig;\n /**\n * Underlying Keymaster libray based on the use-case:\n *\n * Integrated Keymaster = keymaster_lib\n *\n * External Keymaster = keymaster_sdk\n */\n private keymasterService;\n private serviceStarted = false;\n\n constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public async start(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n private async startIntegratedKeymaster(): Promise<boolean> {\n console.log(`Starting integrated Keymaster service`);\n\n try {\n const gatekeeper_sdk = await import(\"@mdip/gatekeeper/sdk\");\n await gatekeeper_sdk.start(this.config.gatekeeperConfig);\n\n const cipher = await import(\"@mdip/cipher/node\");\n\n this.keymasterService = await import(\"@mdip/keymaster/lib\");\n await this.keymasterService.start({\n cipher: cipher,\n gatekeeper: gatekeeper_sdk,\n wallet: this.config.walletDb,\n });\n\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n\n private async startExternalKeymaster(): Promise<boolean> {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = await import(\"@mdip/keymaster/sdk\");\n await this.keymasterService.start(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster serivce:`, e);\n return false;\n }\n\n console.log(`Started external Keymaster service`);\n return true;\n }\n\n async createChallenge(\n spec: CreateChallengeSpec,\n options?: CreateChallengeOptions\n ): Promise<CreateChallengeResponse> {\n if (!this.serviceRunning()) {\n return;\n }\n const challengeSpec = { challenge: spec };\n const challenge: string = await this.keymasterService.createChallenge(\n challengeSpec,\n options\n );\n return {\n challenge: challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`,\n };\n }\n\n async showMnemonic(): Promise<string> {\n if (!this.serviceRunning()) {\n return;\n }\n return this.keymasterService.decryptMnemonic();\n }\n\n async verifyResponse(\n did: string,\n options?: VerifyResponseOptions\n ): Promise<VerifyResponseResponse> {\n if (!this.serviceRunning()) {\n return;\n }\n const response: VerifyResponseResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n const existing: Wallet | null = await this.config.walletDb.loadWallet();\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n\n const walletConfig = this.config.walletConfig;\n console.log(`Creating wallet with ID ${walletConfig.id}`);\n // wallet was just created, recreate based on config\n if (walletConfig.mnemonic) {\n // create the wallet with a custom mnemonic first\n await this.keymasterService.newWallet(spec.mnenomic, true);\n }\n // create ID and set as current, createId() will save wallet\n await this.keymasterService.createId(\n walletConfig.id,\n walletConfig.registry\n );\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.start());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.js","../src/keymaster.ts"],"names":["cipher","gatekeeper_sdk","keymaster_lib","Keymaster","config","_serviceStarted","_gatekeeperConfig","url","gatekeeperConfig","waitUntilReady","intervalSeconds","chatty","_walletConfig","walletConfig","_walletDb","saveWallet","onSaveWallet","loadWallet","onLoadWallet","start","e","console","error","gatekeeper","wallet","ensureWalletExists","createChallenge","spec","options","challengeSpec","challenge","serviceRunning","challengeUrl","callback","verifyResponse","did","response","existing","current","log","id","mnemonic","newWallet","mnenomic","createId","registry"],"mappings":"AAAA,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACEnB,YAAYA,YAAY,oBAAA;AACxB,YAAYC,oBAAoB,uBAAA;AAChC,YAAYC,mBAAmB,sBAAA;AAkExB,IAAMC,0BAAN;;aAAMA,UAMCC,MAAA;gCANDD;QAIX,IAAA,CAAQE,eAAA,GAAkB;QAGxB,IAAA,CAAKC,iBAAA,GAAoB;YACvBC,KAAKH,OAAOI,gBAAA,CAAiBD,GAAA;YAC7BE,gBAAgB;YAChBC,iBAAiB;YACjBC,QAAQ;QACV;QACA,IAAA,CAAKC,aAAA,GAAgBR,OAAOS,YAAA;QAC5B,IAAA,CAAKC,SAAA,GAAY;YACfC,YAAYX,OAAOY,YAAA;YACnBC,YAAYb,OAAOc,YAAA;QACrB;;;;YAGWC,KAAAA;mBAAb,SAAaA;;uBAAb,oBAAA;wBAGWC,GAWAA,IAMAA;;;;;;;;;;gCAlBP;;oCAAqBnB,eAAAkB,KAAA,CAAM,MAAKb,iBAAiB;;;gCAAjD;;;;;;gCACOc;gCACPC,QAAQC,KAAA,CAAM,sCAAsCF;;;;;;;;;;;;gCAIpD;;oCAAoBlB,cAAAiB,KAAA,CAAM;wCACxBI,YAAYtB;wCACZuB,QAAQ,MAAKV,SAAA;wCACbd,QAAAA;oCACF;;;gCAJA;gCAKA,MAAKK,eAAA,GAAkB;;;;;;gCAChBe;gCACPC,QAAQC,KAAA,CAAM,qCAAqCF;;;;;;;;;;;;gCAInD;;oC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4B,EAAA,EACnB,MAAK5B,aAAA,CAAciC,QAAA;;;gCAFrB;gCAIAxB,QAAQkB,GAAA,CAAI,0BAA+C,OAArB,MAAK3B,aAAA,CAAc4B,EAAE;;;;;;gBAC7D;;;;YAEcT,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAK1B,eAAA;0CAAL;;;;gCAAyB;;oCAAM,MAAKc,KAAA;;;uCAAX;;;gCAAhC;;;;;;gBACF;;;;;;ADtFF,SACEhB,SAAS,GACT","sourcesContent":["// src/keymaster.ts\nimport * as cipher from \"@mdip/cipher/node\";\nimport * as gatekeeper_sdk from \"@mdip/gatekeeper/sdk\";\nimport * as keymaster_lib from \"@mdip/keymaster/lib\";\nvar Keymaster = class {\n constructor(config) {\n this._serviceStarted = false;\n this._gatekeeperConfig = {\n url: config.gatekeeperConfig.url,\n waitUntilReady: true,\n intervalSeconds: 5,\n chatty: true\n };\n this._walletConfig = config.walletConfig;\n this._walletDb = {\n saveWallet: config.onSaveWallet,\n loadWallet: config.onLoadWallet\n };\n }\n async start() {\n try {\n await gatekeeper_sdk.start(this._gatekeeperConfig);\n } catch (e) {\n console.error(\"Error starting Gatekeeper service:\", e);\n }\n try {\n await keymaster_lib.start({\n gatekeeper: gatekeeper_sdk,\n wallet: this._walletDb,\n cipher\n });\n this._serviceStarted = true;\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n }\n try {\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error verifying existing wallet:\", e);\n }\n return this._serviceStarted;\n }\n async createChallenge(spec2, options) {\n if (!this.serviceRunning()) {\n return;\n }\n const challengeSpec = { challenge: spec2 };\n const challenge = await keymaster_lib.createChallenge(\n challengeSpec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec2.callback}?challenge=${challenge}`\n };\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n return;\n }\n const response = await keymaster_lib.verifyResponse(\n did,\n options\n );\n return response;\n }\n async ensureWalletExists() {\n const existing = await this._walletDb.loadWallet();\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n console.log(`Creating wallet with ID ${this._walletConfig.id}`);\n if (this._walletConfig.mnemonic) {\n await keymaster_lib.newWallet(spec.mnenomic, true);\n }\n await keymaster_lib.createId(\n this._walletConfig.id,\n this._walletConfig.registry\n );\n console.log(`Created wallet with ID ${this._walletConfig.id}`);\n }\n async serviceRunning() {\n return this._serviceStarted || await this.start();\n }\n};\nexport {\n Keymaster\n};\n","// @ts-ignore\n// @ts-nocheck\nimport * as cipher from \"@mdip/cipher/node\";\nimport * as gatekeeper_sdk from \"@mdip/gatekeeper/sdk\";\nimport * as keymaster_lib from \"@mdip/keymaster/lib\";\n\nimport { initalizeWalletDb, DbType } from \"./db\";\nimport * as wallet_db from \"./db/test\";\n\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: [];\n}\n\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\n\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\n\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\n\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n}\n\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\n\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\n}\n\nexport interface GatekeeperConfig {\n url: string;\n waitUntilReady?: boolean;\n intervalSeconds?: number;\n chatty?: boolean;\n}\n\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\n}\n\nexport interface KeymasterConfig {\n gatekeeperConfig: GatekeeperConfig;\n walletConfig: WalletConfig;\n onSaveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;\n onLoadWallet: () => Promise<Wallet | null>;\n}\n\nexport class Keymaster {\n private _gatekeeperConfig;\n private _walletConfig;\n private _walletDb;\n private _serviceStarted = false;\n\n constructor(config: KeymasterConfig) {\n this._gatekeeperConfig = {\n url: config.gatekeeperConfig.url,\n waitUntilReady: true,\n intervalSeconds: 5,\n chatty: true,\n };\n this._walletConfig = config.walletConfig;\n this._walletDb = {\n saveWallet: config.onSaveWallet,\n loadWallet: config.onLoadWallet,\n };\n }\n\n public async start(): Promise<boolean> {\n try {\n await gatekeeper_sdk.start(this._gatekeeperConfig);\n } catch (e) {\n console.error(\"Error starting Gatekeeper service:\", e);\n }\n\n try {\n await keymaster_lib.start({\n gatekeeper: gatekeeper_sdk,\n wallet: this._walletDb,\n cipher: cipher,\n });\n this._serviceStarted = true;\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n }\n\n try {\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error verifying existing wallet:\", e);\n }\n\n return this._serviceStarted;\n }\n\n async createChallenge(\n spec: CreateChallengeSpec,\n options?: CreateChallengeOptions\n ): Promise<CreateChallengeResponse> {\n if (!this.serviceRunning()) {\n return;\n }\n const challengeSpec = { challenge: spec };\n const challenge: string = await keymaster_lib.createChallenge(\n challengeSpec,\n options\n );\n return {\n challenge: challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`,\n };\n }\n\n async verifyResponse(\n did: string,\n options?: VerifyResponseOptions\n ): Promise<VerifyResponseResponse> {\n if (!this.serviceRunning()) {\n return;\n }\n const response: VerifyResponseResponse = await keymaster_lib.verifyResponse(\n did,\n options\n );\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n const existing: Wallet | null = await this._walletDb.loadWallet();\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n\n console.log(`Creating wallet with ID ${this._walletConfig.id}`);\n // wallet was just created, recreate based on config\n if (this._walletConfig.mnemonic) {\n // create the wallet with a custom mnemonic first\n await keymaster_lib.newWallet(spec.mnenomic, true);\n }\n // create ID and set as current, createId() will save wallet\n await keymaster_lib.createId(\n this._walletConfig.id,\n this._walletConfig.registry\n );\n console.log(`Created wallet with ID ${this._walletConfig.id}`);\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this._serviceStarted || (await this.start());\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yourself_id/siwys-api-js",
3
- "version": "0.0.11-sapp-107-external-km-support.7+3b2469a",
3
+ "version": "0.0.11",
4
4
  "description": "A React component library",
5
5
  "repository": "https://github.com/selfidhq/siwys-js",
6
6
  "main": "dist/index.js",
@@ -35,5 +35,5 @@
35
35
  "tsup": "^8.3.0",
36
36
  "typescript": "4.9.4"
37
37
  },
38
- "gitHead": "3b2469a11184b5a5c8e41fd0d56f8f2e09e9ea61"
38
+ "gitHead": "7363720ff07c9621db3ad67ef782d5a5e76343ea"
39
39
  }