@yourself_id/siwys-api-js 0.2.0 → 0.2.1-SAPP-127-netki-molecule-3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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;
@@ -256,14 +215,16 @@ module.exports = __toCommonJS(src_exports);
256
215
  // src/keymaster.ts
257
216
  var import_client = __toESM(require("@mdip/gatekeeper/client"), 1);
258
217
  var import_node = __toESM(require("@mdip/cipher/node"), 1);
218
+ var import_client2 = __toESM(require("@mdip/keymaster/client"), 1);
219
+ var import_keymaster = __toESM(require("@mdip/keymaster"), 1);
259
220
  var Keymaster = /*#__PURE__*/ function() {
260
- function _Keymaster(config) {
261
- _class_call_check(this, _Keymaster);
221
+ function Keymaster(config) {
222
+ _class_call_check(this, Keymaster);
262
223
  this.serviceStarted = false;
263
224
  this.validateConfig(config);
264
225
  this.config = config;
265
226
  }
266
- _create_class(_Keymaster, [
227
+ _create_class(Keymaster, [
267
228
  {
268
229
  key: "start",
269
230
  value: function start() {
@@ -284,16 +245,26 @@ var Keymaster = /*#__PURE__*/ function() {
284
245
  _this.serviceStarted = _state.sent();
285
246
  return [
286
247
  3,
287
- 3
248
+ 5
288
249
  ];
289
250
  case 2:
290
- if (_this.config.keymasterConfig) {
291
- _this.serviceStarted = _this.startExternalKeymaster();
292
- } else {
293
- throw "Missing Gatekeeper or Keymaster config";
294
- }
295
- _state.label = 3;
251
+ if (!_this.config.keymasterConfig) return [
252
+ 3,
253
+ 4
254
+ ];
255
+ return [
256
+ 4,
257
+ _this.startExternalKeymaster()
258
+ ];
296
259
  case 3:
260
+ _this.serviceStarted = _state.sent();
261
+ return [
262
+ 3,
263
+ 5
264
+ ];
265
+ case 4:
266
+ throw "Missing Gatekeeper or Keymaster config";
267
+ case 5:
297
268
  return [
298
269
  2,
299
270
  _this.serviceStarted
@@ -308,7 +279,7 @@ var Keymaster = /*#__PURE__*/ function() {
308
279
  value: function startIntegratedKeymaster() {
309
280
  var _this = this;
310
281
  return _async_to_generator(function() {
311
- var gatekeeper_sdk, cipher, e;
282
+ var gatekeeper, cipher, e;
312
283
  return _ts_generator(this, function(_state) {
313
284
  switch(_state.label){
314
285
  case 0:
@@ -321,18 +292,18 @@ var Keymaster = /*#__PURE__*/ function() {
321
292
  ,
322
293
  6
323
294
  ]);
324
- gatekeeper_sdk = new import_client.default();
295
+ gatekeeper = new import_client.default();
325
296
  return [
326
297
  4,
327
- gatekeeper_sdk.connect(_this.config.gatekeeperConfig)
298
+ gatekeeper.connect(_this.config.gatekeeperConfig)
328
299
  ];
329
300
  case 2:
330
301
  _state.sent();
331
302
  cipher = new import_node.default();
332
303
  return [
333
304
  4,
334
- new _Keymaster({
335
- gatekeeper: gatekeeper_sdk,
305
+ new import_keymaster.default({
306
+ gatekeeper: gatekeeper,
336
307
  wallet: _this.config.walletDb,
337
308
  cipher: cipher
338
309
  })
@@ -381,36 +352,29 @@ var Keymaster = /*#__PURE__*/ function() {
381
352
  case 1:
382
353
  _state.trys.push([
383
354
  1,
384
- 4,
355
+ 3,
385
356
  ,
386
- 5
357
+ 4
387
358
  ]);
359
+ _this.keymasterService = new import_client2.default();
388
360
  return [
389
361
  4,
390
- Promise.resolve().then(function() {
391
- return /*#__PURE__*/ _interop_require_wildcard(require("@mdip/keymaster"));
392
- })
362
+ _this.keymasterService.connect(_this.config.keymasterConfig)
393
363
  ];
394
364
  case 2:
395
- _this.keymasterService = _state.sent();
396
- return [
397
- 4,
398
- _this.keymasterService.start(_this.config.keymasterConfig)
399
- ];
400
- case 3:
401
365
  _state.sent();
402
366
  return [
403
367
  3,
404
- 5
368
+ 4
405
369
  ];
406
- case 4:
370
+ case 3:
407
371
  e = _state.sent();
408
372
  console.error("Error starting Keymaster service:", e);
409
373
  return [
410
374
  2,
411
375
  false
412
376
  ];
413
- case 5:
377
+ case 4:
414
378
  console.log("Started external Keymaster service");
415
379
  return [
416
380
  2,
@@ -423,7 +387,7 @@ var Keymaster = /*#__PURE__*/ function() {
423
387
  },
424
388
  {
425
389
  key: "createChallenge",
426
- value: function createChallenge(spec2, options) {
390
+ value: function createChallenge(spec, options) {
427
391
  var _this = this;
428
392
  return _async_to_generator(function() {
429
393
  var challenge;
@@ -431,13 +395,11 @@ var Keymaster = /*#__PURE__*/ function() {
431
395
  switch(_state.label){
432
396
  case 0:
433
397
  if (!_this.serviceRunning()) {
434
- return [
435
- 2
436
- ];
398
+ throw new Error("Keymaster service not running");
437
399
  }
438
400
  return [
439
401
  4,
440
- _this.keymasterService.createChallenge(spec2, options)
402
+ _this.keymasterService.createChallenge(spec, options)
441
403
  ];
442
404
  case 1:
443
405
  challenge = _state.sent();
@@ -445,7 +407,7 @@ var Keymaster = /*#__PURE__*/ function() {
445
407
  2,
446
408
  {
447
409
  challenge: challenge,
448
- challengeUrl: "".concat(spec2.callback, "?challenge=").concat(challenge)
410
+ challengeUrl: "".concat(spec.callback, "?challenge=").concat(challenge)
449
411
  }
450
412
  ];
451
413
  }
@@ -460,9 +422,7 @@ var Keymaster = /*#__PURE__*/ function() {
460
422
  return _async_to_generator(function() {
461
423
  return _ts_generator(this, function(_state) {
462
424
  if (!_this.serviceRunning()) {
463
- return [
464
- 2
465
- ];
425
+ throw new Error("Keymaster service not running");
466
426
  }
467
427
  return [
468
428
  2,
@@ -482,9 +442,7 @@ var Keymaster = /*#__PURE__*/ function() {
482
442
  switch(_state.label){
483
443
  case 0:
484
444
  if (!_this.serviceRunning()) {
485
- return [
486
- 2
487
- ];
445
+ throw new Error("Keymaster service not running");
488
446
  }
489
447
  return [
490
448
  4,
@@ -506,16 +464,17 @@ var Keymaster = /*#__PURE__*/ function() {
506
464
  value: function ensureWalletExists() {
507
465
  var _this = this;
508
466
  return _async_to_generator(function() {
509
- var existing, walletConfig;
467
+ var _this_config_walletDb, _this_config, existing, walletConfig, did;
510
468
  return _ts_generator(this, function(_state) {
511
469
  switch(_state.label){
512
470
  case 0:
471
+ console.log("Ensuring wallet exists");
513
472
  return [
514
473
  4,
515
- _this.config.walletDb.loadWallet()
474
+ (_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()
516
475
  ];
517
476
  case 1:
518
- existing = _state.sent();
477
+ existing = _state.sent() || null;
519
478
  if (existing === null || existing === void 0 ? void 0 : existing.current) {
520
479
  console.log("Using existing wallet with ID ".concat(existing.current));
521
480
  return [
@@ -523,14 +482,14 @@ var Keymaster = /*#__PURE__*/ function() {
523
482
  ];
524
483
  }
525
484
  walletConfig = _this.config.walletConfig;
526
- console.log("Creating wallet with ID ".concat(walletConfig.id));
527
- if (!walletConfig.mnemonic) return [
485
+ console.log("Creating Creating Creating wallet with ID ".concat(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id));
486
+ if (!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.mnemonic)) return [
528
487
  3,
529
488
  3
530
489
  ];
531
490
  return [
532
491
  4,
533
- _this.keymasterService.newWallet(spec.mnenomic, true)
492
+ _this.keymasterService.newWallet(walletConfig.mnemonic, true)
534
493
  ];
535
494
  case 2:
536
495
  _state.sent();
@@ -538,11 +497,12 @@ var Keymaster = /*#__PURE__*/ function() {
538
497
  case 3:
539
498
  return [
540
499
  4,
541
- _this.keymasterService.createId(walletConfig.id, walletConfig.registry)
500
+ _this.keymasterService.createId(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id, walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.registry)
542
501
  ];
543
502
  case 4:
544
- _state.sent();
545
- console.log("Created wallet with ID ".concat(walletConfig.id));
503
+ did = _state.sent();
504
+ console.log("Did ", did);
505
+ console.log("Created wallet with ID ".concat(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id));
546
506
  return [
547
507
  2
548
508
  ];
@@ -603,7 +563,7 @@ var Keymaster = /*#__PURE__*/ function() {
603
563
  }
604
564
  }
605
565
  ]);
606
- return _Keymaster;
566
+ return Keymaster;
607
567
  }();
608
568
  // Annotate the CommonJS export names for ESM import in node:
609
569
  0 && (module.exports = {
@@ -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","import_client","require","import_node","_Keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper_sdk","cipher","e","console","log","GatekeeperClient","connect","CipherNode","gatekeeper","wallet","walletDb","keymasterService","ensureWalletExists","error","createChallenge","spec","options","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,2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,CAC1BP,aAAaG,EAAA,EACbH,aAAaQ,QAAA;;;gCAFf;gCAIAhC,QAAQC,GAAA,CAAI,0BAAyC,OAAfuB,aAAaG,EAAE;;;;;;gBACvD;;;;YAEcZ,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKzB,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,IAAIsC,MAAM;gBAClB;gBAEA,IAAI5C,OAAOI,gBAAA,EAAkB;wBAItBJ,kBAGAA;oBANL,IAAI,CAACA,OAAOmC,YAAA,EAAc;wBACxB,MAAM,IAAIS,MAAM;oBAClB;oBACA,IAAI,GAAC5C,mBAAAA,OAAOkB,QAAA,cAAPlB,uCAAAA,iBAAiBoC,UAAA,GAAY;wBAChC,MAAM,IAAIQ,MAAM;oBAClB;oBACA,IAAI,GAAC5C,oBAAAA,OAAOkB,QAAA,cAAPlB,wCAAAA,kBAAiB6C,UAAA,GAAY;wBAChC,MAAM,IAAID,MAAM;oBAClB;gBACF;YACF;;;;;AFxFF,6DAA6D;AAC7D,KAAMlD,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 import_client = __toESM(require(\"@mdip/gatekeeper/client\"), 1);\nvar import_node = __toESM(require(\"@mdip/cipher/node\"), 1);\nvar Keymaster = class _Keymaster {\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 = new import_client.default();\n await gatekeeper_sdk.connect(this.config.gatekeeperConfig);\n const cipher = new import_node.default();\n this.keymasterService = await new _Keymaster({\n gatekeeper: gatekeeper_sdk,\n wallet: this.config.walletDb,\n cipher\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\");\n await this.keymasterService.start(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, 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 challenge = await this.keymasterService.createChallenge(\n spec2,\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\";\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport WalletJson from \"@mdip/keymaster/wallet/json\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport Keymaster from \"@mdip/keymaster\";\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: { schema: string; issuers: string[] }[];\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 = new GatekeeperClient();\n await gatekeeper_sdk.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = await new Keymaster({\n gatekeeper: gatekeeper_sdk,\n wallet: this.config.walletDb,\n cipher,\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\");\n await this.keymasterService.start(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, 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 challenge: string = await this.keymasterService.createChallenge(\n spec,\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","import_client","require","import_node","import_keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper","cipher","e","console","log","GatekeeperClient","connect","CipherNode","KeymasterLib","wallet","walletDb","keymasterService","ensureWalletExists","error","import_client2","KeymasterClient","createChallenge","spec","options","challenge","serviceRunning","Error","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","createId","registry","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;+BAAMI,IAAI,CAACG,IAAI;;oBAAEN,YAAY,CAAEK,CAAAA,OAAOnB,iBAAiBiB,MAAMG,IAAG,KAAMD,KAAKL,UAAU;gBAAC;;YAFpH,QAAK,YAAWZ,kBAAkBe,0BAA7B,SAAA,6BAAA,QAAA,yBAAA;;YAAA;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;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CAIZxB,QAAQC,GAAA,CAAI,QAAQuB;gCACpBxB,QAAQC,GAAA,CAAI,0BAA0C,OAAhB0B,yBAAAA,mCAAAA,aAAcG,EAAE;;;;;;gBACxD;;;;YAEcb,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAK3B,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,IAAIuB,MAAM;gBAClB;gBAEA,IAAI7B,OAAOI,gBAAA,EAAkB;wBAItBJ,kBAGAA;oBANL,IAAI,CAACA,OAAOsC,YAAA,EAAc;wBACxB,MAAM,IAAIT,MAAM;oBAClB;oBACA,IAAI,GAAC7B,mBAAAA,OAAOkB,QAAA,cAAPlB,uCAAAA,iBAAiBuC,UAAA,GAAY;wBAChC,MAAM,IAAIV,MAAM;oBAClB;oBACA,IAAI,GAAC7B,oBAAAA,OAAOkB,QAAA,cAAPlB,wCAAAA,kBAAiB8C,UAAA,GAAY;wBAChC,MAAM,IAAIjB,MAAM;oBAClB;gBACF;YACF;;;;;AF5EF,6DAA6D;AAC7D,KAAMnC,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 import_client = __toESM(require(\"@mdip/gatekeeper/client\"), 1);\nvar import_node = __toESM(require(\"@mdip/cipher/node\"), 1);\nvar import_client2 = __toESM(require(\"@mdip/keymaster/client\"), 1);\nvar import_keymaster = __toESM(require(\"@mdip/keymaster\"), 1);\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 = await 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 = new import_client.default();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new import_node.default();\n this.keymasterService = await new import_keymaster.default({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\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 = new import_client2.default();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n console.log(`Started external Keymaster service`);\n return true;\n }\n async createChallenge(spec, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`\n };\n }\n async showMnemonic() {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response = await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\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(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\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 GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: { schema: string; issuers: string[] }[];\n}\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n}\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\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}\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\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 = await 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 = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\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 = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, 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 throw new Error(\"Keymaster service not running\");\n }\n const challenge: string = await this.keymasterService.createChallenge(\n spec,\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 throw new Error(\"Keymaster service not running\");\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 throw new Error(\"Keymaster service not running\");\n }\n const response: VerifyResponseResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: Wallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\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(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\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(walletConfig.mnemonic, true);\n }\n // create ID and set as current, createId() will save wallet\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\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"]}
package/dist/index.js CHANGED
@@ -144,15 +144,17 @@ function _ts_generator(thisArg, body) {
144
144
  }
145
145
  import GatekeeperClient from "@mdip/gatekeeper/client";
146
146
  import CipherNode from "@mdip/cipher/node";
147
+ import KeymasterClient from "@mdip/keymaster/client";
148
+ import { default as KeymasterLib } from "@mdip/keymaster";
147
149
  var Keymaster = /*#__PURE__*/ function() {
148
150
  "use strict";
149
- function _Keymaster(config) {
150
- _class_call_check(this, _Keymaster);
151
+ function Keymaster(config) {
152
+ _class_call_check(this, Keymaster);
151
153
  this.serviceStarted = false;
152
154
  this.validateConfig(config);
153
155
  this.config = config;
154
156
  }
155
- _create_class(_Keymaster, [
157
+ _create_class(Keymaster, [
156
158
  {
157
159
  key: "start",
158
160
  value: function start() {
@@ -173,16 +175,26 @@ var Keymaster = /*#__PURE__*/ function() {
173
175
  _this.serviceStarted = _state.sent();
174
176
  return [
175
177
  3,
176
- 3
178
+ 5
177
179
  ];
178
180
  case 2:
179
- if (_this.config.keymasterConfig) {
180
- _this.serviceStarted = _this.startExternalKeymaster();
181
- } else {
182
- throw "Missing Gatekeeper or Keymaster config";
183
- }
184
- _state.label = 3;
181
+ if (!_this.config.keymasterConfig) return [
182
+ 3,
183
+ 4
184
+ ];
185
+ return [
186
+ 4,
187
+ _this.startExternalKeymaster()
188
+ ];
185
189
  case 3:
190
+ _this.serviceStarted = _state.sent();
191
+ return [
192
+ 3,
193
+ 5
194
+ ];
195
+ case 4:
196
+ throw "Missing Gatekeeper or Keymaster config";
197
+ case 5:
186
198
  return [
187
199
  2,
188
200
  _this.serviceStarted
@@ -197,7 +209,7 @@ var Keymaster = /*#__PURE__*/ function() {
197
209
  value: function startIntegratedKeymaster() {
198
210
  var _this = this;
199
211
  return _async_to_generator(function() {
200
- var gatekeeper_sdk, cipher, e;
212
+ var gatekeeper, cipher, e;
201
213
  return _ts_generator(this, function(_state) {
202
214
  switch(_state.label){
203
215
  case 0:
@@ -210,18 +222,18 @@ var Keymaster = /*#__PURE__*/ function() {
210
222
  ,
211
223
  6
212
224
  ]);
213
- gatekeeper_sdk = new GatekeeperClient();
225
+ gatekeeper = new GatekeeperClient();
214
226
  return [
215
227
  4,
216
- gatekeeper_sdk.connect(_this.config.gatekeeperConfig)
228
+ gatekeeper.connect(_this.config.gatekeeperConfig)
217
229
  ];
218
230
  case 2:
219
231
  _state.sent();
220
232
  cipher = new CipherNode();
221
233
  return [
222
234
  4,
223
- new _Keymaster({
224
- gatekeeper: gatekeeper_sdk,
235
+ new KeymasterLib({
236
+ gatekeeper: gatekeeper,
225
237
  wallet: _this.config.walletDb,
226
238
  cipher: cipher
227
239
  })
@@ -270,34 +282,29 @@ var Keymaster = /*#__PURE__*/ function() {
270
282
  case 1:
271
283
  _state.trys.push([
272
284
  1,
273
- 4,
285
+ 3,
274
286
  ,
275
- 5
287
+ 4
276
288
  ]);
289
+ _this.keymasterService = new KeymasterClient();
277
290
  return [
278
291
  4,
279
- import("@mdip/keymaster")
292
+ _this.keymasterService.connect(_this.config.keymasterConfig)
280
293
  ];
281
294
  case 2:
282
- _this.keymasterService = _state.sent();
283
- return [
284
- 4,
285
- _this.keymasterService.start(_this.config.keymasterConfig)
286
- ];
287
- case 3:
288
295
  _state.sent();
289
296
  return [
290
297
  3,
291
- 5
298
+ 4
292
299
  ];
293
- case 4:
300
+ case 3:
294
301
  e = _state.sent();
295
302
  console.error("Error starting Keymaster service:", e);
296
303
  return [
297
304
  2,
298
305
  false
299
306
  ];
300
- case 5:
307
+ case 4:
301
308
  console.log("Started external Keymaster service");
302
309
  return [
303
310
  2,
@@ -310,7 +317,7 @@ var Keymaster = /*#__PURE__*/ function() {
310
317
  },
311
318
  {
312
319
  key: "createChallenge",
313
- value: function createChallenge(spec2, options) {
320
+ value: function createChallenge(spec, options) {
314
321
  var _this = this;
315
322
  return _async_to_generator(function() {
316
323
  var challenge;
@@ -318,13 +325,11 @@ var Keymaster = /*#__PURE__*/ function() {
318
325
  switch(_state.label){
319
326
  case 0:
320
327
  if (!_this.serviceRunning()) {
321
- return [
322
- 2
323
- ];
328
+ throw new Error("Keymaster service not running");
324
329
  }
325
330
  return [
326
331
  4,
327
- _this.keymasterService.createChallenge(spec2, options)
332
+ _this.keymasterService.createChallenge(spec, options)
328
333
  ];
329
334
  case 1:
330
335
  challenge = _state.sent();
@@ -332,7 +337,7 @@ var Keymaster = /*#__PURE__*/ function() {
332
337
  2,
333
338
  {
334
339
  challenge: challenge,
335
- challengeUrl: "".concat(spec2.callback, "?challenge=").concat(challenge)
340
+ challengeUrl: "".concat(spec.callback, "?challenge=").concat(challenge)
336
341
  }
337
342
  ];
338
343
  }
@@ -347,9 +352,7 @@ var Keymaster = /*#__PURE__*/ function() {
347
352
  return _async_to_generator(function() {
348
353
  return _ts_generator(this, function(_state) {
349
354
  if (!_this.serviceRunning()) {
350
- return [
351
- 2
352
- ];
355
+ throw new Error("Keymaster service not running");
353
356
  }
354
357
  return [
355
358
  2,
@@ -369,9 +372,7 @@ var Keymaster = /*#__PURE__*/ function() {
369
372
  switch(_state.label){
370
373
  case 0:
371
374
  if (!_this.serviceRunning()) {
372
- return [
373
- 2
374
- ];
375
+ throw new Error("Keymaster service not running");
375
376
  }
376
377
  return [
377
378
  4,
@@ -393,16 +394,17 @@ var Keymaster = /*#__PURE__*/ function() {
393
394
  value: function ensureWalletExists() {
394
395
  var _this = this;
395
396
  return _async_to_generator(function() {
396
- var existing, walletConfig;
397
+ var _this_config_walletDb, _this_config, existing, walletConfig, did;
397
398
  return _ts_generator(this, function(_state) {
398
399
  switch(_state.label){
399
400
  case 0:
401
+ console.log("Ensuring wallet exists");
400
402
  return [
401
403
  4,
402
- _this.config.walletDb.loadWallet()
404
+ (_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()
403
405
  ];
404
406
  case 1:
405
- existing = _state.sent();
407
+ existing = _state.sent() || null;
406
408
  if (existing === null || existing === void 0 ? void 0 : existing.current) {
407
409
  console.log("Using existing wallet with ID ".concat(existing.current));
408
410
  return [
@@ -410,14 +412,14 @@ var Keymaster = /*#__PURE__*/ function() {
410
412
  ];
411
413
  }
412
414
  walletConfig = _this.config.walletConfig;
413
- console.log("Creating wallet with ID ".concat(walletConfig.id));
414
- if (!walletConfig.mnemonic) return [
415
+ console.log("Creating Creating Creating wallet with ID ".concat(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id));
416
+ if (!(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.mnemonic)) return [
415
417
  3,
416
418
  3
417
419
  ];
418
420
  return [
419
421
  4,
420
- _this.keymasterService.newWallet(spec.mnenomic, true)
422
+ _this.keymasterService.newWallet(walletConfig.mnemonic, true)
421
423
  ];
422
424
  case 2:
423
425
  _state.sent();
@@ -425,11 +427,12 @@ var Keymaster = /*#__PURE__*/ function() {
425
427
  case 3:
426
428
  return [
427
429
  4,
428
- _this.keymasterService.createId(walletConfig.id, walletConfig.registry)
430
+ _this.keymasterService.createId(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id, walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.registry)
429
431
  ];
430
432
  case 4:
431
- _state.sent();
432
- console.log("Created wallet with ID ".concat(walletConfig.id));
433
+ did = _state.sent();
434
+ console.log("Did ", did);
435
+ console.log("Created wallet with ID ".concat(walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.id));
433
436
  return [
434
437
  2
435
438
  ];
@@ -490,7 +493,7 @@ var Keymaster = /*#__PURE__*/ function() {
490
493
  }
491
494
  }
492
495
  ]);
493
- return _Keymaster;
496
+ return Keymaster;
494
497
  }();
495
498
  export { Keymaster };
496
499
  //# sourceMappingURL=index.js.map
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":["GatekeeperClient","CipherNode","Keymaster","_Keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper_sdk","cipher","e","console","log","connect","gatekeeper","wallet","walletDb","keymasterService","ensureWalletExists","error","createChallenge","spec","options","challenge","serviceRunning","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","mnenomic","createId","registry","Error","sa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;gBACF;YACF;;;;;AD5HF,SACE5C,SAAS,GACT","sourcesContent":["// src/keymaster.ts\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nvar Keymaster = class _Keymaster {\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 = new GatekeeperClient();\n await gatekeeper_sdk.connect(this.config.gatekeeperConfig);\n const cipher = new CipherNode();\n this.keymasterService = await new _Keymaster({\n gatekeeper: gatekeeper_sdk,\n wallet: this.config.walletDb,\n cipher\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\");\n await this.keymasterService.start(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, 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 challenge = await this.keymasterService.createChallenge(\n spec2,\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\";\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport WalletJson from \"@mdip/keymaster/wallet/json\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport Keymaster from \"@mdip/keymaster\";\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: { schema: string; issuers: string[] }[];\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 = new GatekeeperClient();\n await gatekeeper_sdk.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = await new Keymaster({\n gatekeeper: gatekeeper_sdk,\n wallet: this.config.walletDb,\n cipher,\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\");\n await this.keymasterService.start(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, 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 challenge: string = await this.keymasterService.createChallenge(\n spec,\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":["GatekeeperClient","CipherNode","KeymasterClient","default","KeymasterLib","Keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper","cipher","e","console","log","connect","wallet","walletDb","keymasterService","ensureWalletExists","error","createChallenge","spec","options","challenge","serviceRunning","Error","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","createId","registry","saveWallet"],"mappings":"AAAA,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACEnB,OAAOA,sBAAsB,0BAAA;AAC7B,OAAOC,gBAAgB,oBAAA;AACvB,OAAOC,qBAAqB,yBAAA;AAC5B,SAASC,WAAWC,YAAA,QAAoB,kBAAA;AA4EjC,IAAMC,0BAAN;;aAAMA,UAYCC,MAAA;gCAZDD;QAUX,IAAA,CAAQE,cAAA,GAAiB;QAGvB,IAAA,CAAKC,cAAA,CAAeF;QACpB,IAAA,CAAKA,MAAA,GAASA;;;;YAGHG,KAAAA;mBAAb,SAAaA;;uBAAb,oBAAA;;;;qCACM,MAAKH,MAAA,CAAOI,gBAAA,EAAZ;;;;gCACoB;;oCAAM,MAAKC,wBAAA;;;gCAAjC,MAAKJ,cAAA,GAAiB;;;;;;qCACb,MAAKD,MAAA,CAAOM,eAAA,EAAZ;;;;gCACa;;oCAAM,MAAKC,sBAAA;;;gCAAjC,MAAKN,cAAA,GAAiB;;;;;;gCAEtB,MAA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IZnB,QAAQC,GAAA,CAAI,QAAQkB;gCACpBnB,QAAQC,GAAA,CAAI,0BAA0C,OAAhBqB,yBAAAA,mCAAAA,aAAcG,EAAE;;;;;;gBACxD;;;;YAEcb,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKtB,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,IAAIkB,MAAM;gBAClB;gBAEA,IAAIxB,OAAOI,gBAAA,EAAkB;wBAItBJ,kBAGAA;oBANL,IAAI,CAACA,OAAOiC,YAAA,EAAc;wBACxB,MAAM,IAAIT,MAAM;oBAClB;oBACA,IAAI,GAACxB,mBAAAA,OAAOe,QAAA,cAAPf,uCAAAA,iBAAiBkC,UAAA,GAAY;wBAChC,MAAM,IAAIV,MAAM;oBAClB;oBACA,IAAI,GAACxB,oBAAAA,OAAOe,QAAA,cAAPf,wCAAAA,kBAAiByC,UAAA,GAAY;wBAChC,MAAM,IAAIjB,MAAM;oBAClB;gBACF;YACF;;;;;ADhHF,SACEzB,SAAS,GACT","sourcesContent":["// src/keymaster.ts\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\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 = await 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 = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new CipherNode();\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\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 = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n console.log(`Started external Keymaster service`);\n return true;\n }\n async createChallenge(spec, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`\n };\n }\n async showMnemonic() {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response = await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\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(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\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 GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: { schema: string; issuers: string[] }[];\n}\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n}\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\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}\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\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 = await 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 = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\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 = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, 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 throw new Error(\"Keymaster service not running\");\n }\n const challenge: string = await this.keymasterService.createChallenge(\n spec,\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 throw new Error(\"Keymaster service not running\");\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 throw new Error(\"Keymaster service not running\");\n }\n const response: VerifyResponseResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: Wallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\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(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\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(walletConfig.mnemonic, true);\n }\n // create ID and set as current, createId() will save wallet\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yourself_id/siwys-api-js",
3
- "version": "0.2.0",
3
+ "version": "0.2.1-SAPP-127-netki-molecule-3.0+177ba2d",
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": "e22d16bc7cf2a1b77e5f6c0e8a2b2d793cf0441e"
38
+ "gitHead": "177ba2d152acaceba6436db52a112c6dc49c5ea7"
39
39
  }