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

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
@@ -480,6 +480,52 @@ var _Keymaster = /*#__PURE__*/ function() {
480
480
  })();
481
481
  }
482
482
  },
483
+ {
484
+ key: "createResponseInternal",
485
+ value: function createResponseInternal(challengeDID, options) {
486
+ var _this = this;
487
+ return _async_to_generator(function() {
488
+ return _ts_generator(this, function(_state) {
489
+ switch(_state.label){
490
+ case 0:
491
+ return [
492
+ 4,
493
+ _this.ensureServiceIsRunning()
494
+ ];
495
+ case 1:
496
+ _state.sent();
497
+ return [
498
+ 2,
499
+ _this.keymasterService.createResponse(challengeDID, options)
500
+ ];
501
+ }
502
+ });
503
+ })();
504
+ }
505
+ },
506
+ {
507
+ key: "backupWalletInternal",
508
+ value: function backupWalletInternal(registry) {
509
+ var _this = this;
510
+ return _async_to_generator(function() {
511
+ return _ts_generator(this, function(_state) {
512
+ switch(_state.label){
513
+ case 0:
514
+ return [
515
+ 4,
516
+ _this.ensureServiceIsRunning()
517
+ ];
518
+ case 1:
519
+ _state.sent();
520
+ return [
521
+ 2,
522
+ _this.keymasterService.backupWallet(registry)
523
+ ];
524
+ }
525
+ });
526
+ })();
527
+ }
528
+ },
483
529
  {
484
530
  key: "issueCredentialInternal",
485
531
  value: function issueCredentialInternal(credential) {
@@ -1095,6 +1141,42 @@ var _Keymaster = /*#__PURE__*/ function() {
1095
1141
  })();
1096
1142
  }
1097
1143
  },
1144
+ {
1145
+ key: "backupWallet",
1146
+ value: function backupWallet() {
1147
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1148
+ args[_key] = arguments[_key];
1149
+ }
1150
+ return _async_to_generator(function() {
1151
+ var _Keymaster_getInstance;
1152
+ return _ts_generator(this, function(_state) {
1153
+ _Keymaster.getInstance().ensureInitialized();
1154
+ return [
1155
+ 2,
1156
+ (_Keymaster_getInstance = _Keymaster.getInstance()).backupWalletInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1157
+ ];
1158
+ });
1159
+ })();
1160
+ }
1161
+ },
1162
+ {
1163
+ key: "createResponse",
1164
+ value: function createResponse() {
1165
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1166
+ args[_key] = arguments[_key];
1167
+ }
1168
+ return _async_to_generator(function() {
1169
+ var _Keymaster_getInstance;
1170
+ return _ts_generator(this, function(_state) {
1171
+ _Keymaster.getInstance().ensureInitialized();
1172
+ return [
1173
+ 2,
1174
+ (_Keymaster_getInstance = _Keymaster.getInstance()).createResponseInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1175
+ ];
1176
+ });
1177
+ })();
1178
+ }
1179
+ },
1098
1180
  {
1099
1181
  key: "issueCredential",
1100
1182
  value: function issueCredential() {
@@ -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","../src/keymasterClient.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","__reExport","mod","secondTarget","__toESM","isNodeMode","__esModule","value","__toCommonJS","src_exports","Keymaster","KeymasterExternalClient","module","exports","import_client","require","import_node","import_keymaster","_Keymaster","config","serviceStarted","validateConfig","ensureInitialized","instance","Error","ensureServiceIsRunning","serviceRunning","startInternal","gatekeeperConfig","startIntegratedKeymaster","gatekeeper","cipher","e","console","log","walletDb","GatekeeperClient","connect","CipherNode","keymasterService","KeymasterLib","wallet","ensureWalletExists","error","createChallengeInternal","spec","options","challenge","createChallenge","challengeUrl","callback","bindCredentialInternal","schemaId","subjectId","bindCredential","issueCredentialInternal","credential","issueCredential","publishCredentialInternal","did","publishCredential","acceptCredentialInternal","acceptCredential","showMnemonicInternal","decryptMnemonic","verifyResponseInternal","verifyResponse","decryptMessageInternal","args","decryptMessage","decryptMnemonicInternal","getCredentialInternal","getCredential","removeCredentialInternal","removeCredential","updateCredentialInternal","updateCredential","createIdInternal","createId","removeIdInternal","removeId","resolveDIDInternal","resolveDID","setCurrentIdInternal","setCurrentId","createSchemaInternal","createSchema","newWalletInternal","newWallet","recoverWalletInternal","recoverWallet","existing","walletConfig","loadWallet","current","id","mnemonic","registry","saveWallet","initialize","warn","start","getInstance","showMnemonic","keymasterConfig","startExternalKeymaster","startExternal","import_client2","KeymasterClient","response"],"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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5C+D,WACJ;gCACF;;oCAAOA;;;;gBACT;;;;YAEcnF,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKN,cAAA;0CAAL;;;;gCAAwB;;oCAAM,MAAKiF,KAAA;;;uCAAX;;;gCAA/B;;;;;;gBACF;;;;YAEQhF,KAAAA;mBAAAA,SAAAA,eAAeF,MAAA;gBACrB,IAAI,CAACA,OAAOqF,eAAA,EAAiB;oBAC3B,MAAM,IAAIhF,MAAM;gBAClB;YACF;;;;;AHqQF,eAAe;AClZfvB,WAAAQ,aAAcM,QAAA,0BAXdH,OAAAC,OAAA;AD+ZA,6DAA6D;AAC7D,KAAMD,CAAAA,OAAOC,OAAO,GAAG;IACrBH,WAAAA;IACAC,yBAAAA;GACGI,QAAQ,yBACb","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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, \"default\"), secondTarget && __copyProps(secondTarget, mod, \"default\"));\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 KeymasterExternalClient: () => KeymasterExternalClient\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_keymaster = __toESM(require(\"@mdip/keymaster\"), 1);\nvar _Keymaster = class _Keymaster {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n static initialize(config) {\n if (!_Keymaster.instance) {\n _Keymaster.instance = new _Keymaster(config);\n console.log(\"\\u2705 Keymaster initialized\");\n } else {\n console.warn(\n \"Keymaster already initialized, ignoring re-initialization.\"\n );\n }\n }\n ensureInitialized() {\n if (!_Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n }\n // Delegated STATIC methods\n static async start() {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().startInternal();\n }\n static async createChallenge(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createChallengeInternal(...args);\n }\n static async bindCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().bindCredentialInternal(...args);\n }\n static async issueCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().issueCredentialInternal(...args);\n }\n static async publishCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().publishCredentialInternal(...args);\n }\n static async acceptCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().acceptCredentialInternal(...args);\n }\n static async showMnemonic(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().showMnemonicInternal(...args);\n }\n static async verifyResponse(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().verifyResponseInternal(...args);\n }\n static async decryptMessage(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().decryptMessageInternal(...args);\n }\n static async decryptMnemonic(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().decryptMnemonicInternal(...args);\n }\n static async getCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().getCredentialInternal(...args);\n }\n static async removeCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().removeCredentialInternal(...args);\n }\n static async updateCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().updateCredentialInternal(...args);\n }\n static async createId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createIdInternal(...args);\n }\n static async removeId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().removeIdInternal(...args);\n }\n static async resolveDID(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().resolveDIDInternal(...args);\n }\n static async setCurrentId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().setCurrentIdInternal(...args);\n }\n static async createSchema(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createSchemaInternal(...args);\n }\n static async newWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().newWalletInternal(...args);\n }\n static async recoverWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().recoverWalletInternal(...args);\n }\n static getInstance() {\n if (!_Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n return _Keymaster.instance;\n }\n // -------- Internal instance methods (originals renamed with Internal) -------\n async ensureServiceIsRunning() {\n if (!await this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n }\n async startInternal() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else {\n throw \"Missing Gatekeeper config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n if (this.config.walletDb) {\n const gatekeeper = new import_client.default();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new import_node.default();\n this.keymasterService = new import_keymaster.default({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\n });\n await this.ensureWalletExists();\n } else {\n return false;\n }\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 createChallengeInternal(spec, options) {\n await this.ensureServiceIsRunning();\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 bindCredentialInternal(schemaId, subjectId, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n async issueCredentialInternal(credential, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.issueCredential(credential, options);\n }\n async publishCredentialInternal(did, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.publishCredential(did, options);\n }\n async acceptCredentialInternal(did) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.acceptCredential(did);\n }\n async showMnemonicInternal() {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponseInternal(did, options) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.verifyResponse(did, options);\n }\n async decryptMessageInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMessage(...args);\n }\n async decryptMnemonicInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic(...args);\n }\n async getCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.getCredential(...args);\n }\n async removeCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeCredential(...args);\n }\n async updateCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.updateCredential(...args);\n }\n async createIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createId(...args);\n }\n async removeIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeId(...args);\n }\n async resolveDIDInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.resolveDID(...args);\n }\n async setCurrentIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.setCurrentId(...args);\n }\n async createSchemaInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createSchema(...args);\n }\n async newWalletInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.newWallet(...args);\n }\n async recoverWalletInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.recoverWallet(...args);\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\n if (existing && \"current\" in existing) {\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(walletConfig.mnemonic, true);\n }\n if (walletConfig?.id) {\n const did = await this.keymasterService.createId(walletConfig.id, {\n registry: walletConfig.registry\n });\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n }\n async serviceRunning() {\n return this.serviceStarted || await this.startInternal();\n }\n validateConfig(config) {\n if (!config.gatekeeperConfig) {\n throw new Error(\"Missing Gatekeeper 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_Keymaster.instance = null;\nvar Keymaster = _Keymaster;\n\n// src/keymasterClient.ts\nvar import_client2 = __toESM(require(\"@mdip/keymaster/client\"), 1);\nvar KeymasterExternalClient = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startExternal() {\n 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 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 bindCredential(schemaId, subjectId, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n async issueCredential(credential, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.issueCredential(credential, options);\n }\n async publishCredential(did, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.publishCredential(did, options);\n }\n async acceptCredential(did) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.acceptCredential(did);\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 serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (!config.keymasterConfig) {\n throw new Error(\"Missing Keymaster config\");\n }\n }\n};\n\n// src/index.ts\n__reExport(src_exports, require(\"@mdip/keymaster/types\"), module.exports);\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n Keymaster,\n KeymasterExternalClient,\n ...require(\"@mdip/keymaster/types\")\n});\n","export { Keymaster, KeymasterConfig } from \"./keymaster.js\";\n\nexport { KeymasterExternalClient } from \"./keymasterClient.js\";\n\nexport {\n SdkConfig,\n WalletConfig,\n CreateChallengeResponse,\n CreateChallengeSpec,\n} from \"./types/index.js\";\n\nexport * from \"@mdip/keymaster/types\";\n","import GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterLib from \"@mdip/keymaster\";\nimport {\n CreateChallengeResponse,\n CreateChallengeSpec,\n SdkConfig,\n WalletConfig,\n} from \"./types/index.js\";\nimport {\n ChallengeResponse,\n CreateAssetOptions,\n IssueCredentialsOptions,\n StoredWallet,\n VerifiableCredential,\n WalletBase,\n} from \"@mdip/keymaster/types\";\n\nexport interface KeymasterConfig {\n gatekeeperConfig?: SdkConfig;\n walletDb?: WalletBase;\n walletConfig?: WalletConfig;\n}\n\nexport class Keymaster {\n private static instance: Keymaster | null = null;\n\n private config: KeymasterConfig;\n private keymasterService!: KeymasterLib;\n private serviceStarted = false;\n\n private constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public static initialize(config: KeymasterConfig) {\n if (!Keymaster.instance) {\n Keymaster.instance = new Keymaster(config);\n console.log(\"✅ Keymaster initialized\");\n } else {\n console.warn(\n \"Keymaster already initialized, ignoring re-initialization.\"\n );\n }\n }\n\n private ensureInitialized() {\n if (!Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n }\n\n // Delegated STATIC methods\n\n public static async start() {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().startInternal();\n }\n\n public static async createChallenge(\n ...args: Parameters<Keymaster[\"createChallengeInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createChallengeInternal(...args);\n }\n\n public static async bindCredential(\n ...args: Parameters<Keymaster[\"bindCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().bindCredentialInternal(...args);\n }\n\n public static async issueCredential(\n ...args: Parameters<Keymaster[\"issueCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().issueCredentialInternal(...args);\n }\n\n public static async publishCredential(\n ...args: Parameters<Keymaster[\"publishCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().publishCredentialInternal(...args);\n }\n\n public static async acceptCredential(\n ...args: Parameters<Keymaster[\"acceptCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().acceptCredentialInternal(...args);\n }\n\n public static async showMnemonic(\n ...args: Parameters<Keymaster[\"showMnemonicInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().showMnemonicInternal(...args);\n }\n\n public static async verifyResponse(\n ...args: Parameters<Keymaster[\"verifyResponseInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().verifyResponseInternal(...args);\n }\n\n public static async decryptMessage(\n ...args: Parameters<Keymaster[\"decryptMessageInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().decryptMessageInternal(...args);\n }\n\n public static async decryptMnemonic(\n ...args: Parameters<Keymaster[\"decryptMnemonicInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().decryptMnemonicInternal(...args);\n }\n\n public static async getCredential(\n ...args: Parameters<Keymaster[\"getCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().getCredentialInternal(...args);\n }\n\n public static async removeCredential(\n ...args: Parameters<Keymaster[\"removeCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().removeCredentialInternal(...args);\n }\n\n public static async updateCredential(\n ...args: Parameters<Keymaster[\"updateCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().updateCredentialInternal(...args);\n }\n\n public static async createId(\n ...args: Parameters<Keymaster[\"createIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createIdInternal(...args);\n }\n\n public static async removeId(\n ...args: Parameters<Keymaster[\"removeIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().removeIdInternal(...args);\n }\n\n public static async resolveDID(\n ...args: Parameters<Keymaster[\"resolveDIDInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().resolveDIDInternal(...args);\n }\n\n public static async setCurrentId(\n ...args: Parameters<Keymaster[\"setCurrentIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().setCurrentIdInternal(...args);\n }\n\n public static async createSchema(\n ...args: Parameters<Keymaster[\"createSchemaInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createSchemaInternal(...args);\n }\n\n public static async newWallet(\n ...args: Parameters<Keymaster[\"newWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().newWalletInternal(...args);\n }\n\n public static async recoverWallet(\n ...args: Parameters<Keymaster[\"recoverWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().recoverWalletInternal(...args);\n }\n\n private static getInstance(): Keymaster {\n if (!Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n return Keymaster.instance;\n }\n\n // -------- Internal instance methods (originals renamed with Internal) -------\n\n private async ensureServiceIsRunning() {\n if (!(await this.serviceRunning())) {\n throw new Error(\"Keymaster service not running\");\n }\n }\n\n private async startInternal(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else {\n throw \"Missing Gatekeeper 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 if (this.config.walletDb) {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\n });\n\n await this.ensureWalletExists();\n } else {\n return false;\n }\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 createChallengeInternal(\n spec: CreateChallengeSpec,\n options?: CreateAssetOptions\n ): Promise<CreateChallengeResponse> {\n await this.ensureServiceIsRunning();\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 private async bindCredentialInternal(\n schemaId: string,\n subjectId: string,\n options: {\n validFrom?: string;\n validUntil?: string;\n credential?: Record<string, unknown>;\n } = {}\n ): Promise<VerifiableCredential> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n\n private async issueCredentialInternal(\n credential: Partial<VerifiableCredential>,\n options: IssueCredentialsOptions = {}\n ): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.issueCredential(credential, options);\n }\n\n private async publishCredentialInternal(\n did: string,\n options: { reveal?: boolean } = {}\n ): Promise<VerifiableCredential> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.publishCredential(did, options);\n }\n\n private async acceptCredentialInternal(did: string): Promise<boolean> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.acceptCredential(did);\n }\n\n private async showMnemonicInternal(): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic();\n }\n\n private async verifyResponseInternal(\n did: string,\n options?: { retries?: number; delay?: number }\n ): Promise<ChallengeResponse> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.verifyResponse(did, options);\n }\n\n private async decryptMessageInternal(\n ...args: Parameters<KeymasterLib[\"decryptMessage\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMessage(...args);\n }\n\n private async decryptMnemonicInternal(\n ...args: Parameters<KeymasterLib[\"decryptMnemonic\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic(...args);\n }\n\n private async getCredentialInternal(\n ...args: Parameters<KeymasterLib[\"getCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.getCredential(...args);\n }\n\n private async removeCredentialInternal(\n ...args: Parameters<KeymasterLib[\"removeCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeCredential(...args);\n }\n\n private async updateCredentialInternal(\n ...args: Parameters<KeymasterLib[\"updateCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.updateCredential(...args);\n }\n\n private async createIdInternal(\n ...args: Parameters<KeymasterLib[\"createId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createId(...args);\n }\n\n private async removeIdInternal(\n ...args: Parameters<KeymasterLib[\"removeId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeId(...args);\n }\n\n private async resolveDIDInternal(\n ...args: Parameters<KeymasterLib[\"resolveDID\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.resolveDID(...args);\n }\n\n private async setCurrentIdInternal(\n ...args: Parameters<KeymasterLib[\"setCurrentId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.setCurrentId(...args);\n }\n\n private async createSchemaInternal(\n ...args: Parameters<KeymasterLib[\"createSchema\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createSchema(...args);\n }\n\n private async newWalletInternal(\n ...args: Parameters<KeymasterLib[\"newWallet\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.newWallet(...args);\n }\n\n private async recoverWalletInternal(\n ...args: Parameters<KeymasterLib[\"recoverWallet\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.recoverWallet(...args);\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: StoredWallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\n if (existing && \"current\" in existing) {\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 if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n\n if (walletConfig?.id) {\n const did = await this.keymasterService.createId(walletConfig.id, {\n registry: walletConfig.registry,\n });\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.startInternal());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (!config.gatekeeperConfig) {\n throw new Error(\"Missing Gatekeeper 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","import KeymasterClient from \"@mdip/keymaster/client\";\nimport {\n ChallengeResponse,\n CreateAssetOptions,\n IssueCredentialsOptions,\n VerifiableCredential,\n} from \"@mdip/keymaster/types\";\nimport {\n CreateChallengeResponse,\n CreateChallengeSpec,\n SdkConfig,\n} from \"./types/index.js\";\n\nexport interface KeymasterConfig {\n keymasterConfig?: SdkConfig;\n}\n\nexport class KeymasterExternalClient {\n private config: KeymasterConfig;\n private keymasterService!: KeymasterClient;\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.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n public async startExternal(): Promise<boolean> {\n 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 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?: CreateAssetOptions\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 bindCredential(\n schemaId: string,\n subjectId: string,\n options: {\n validFrom?: string;\n validUntil?: string;\n credential?: Record<string, unknown>;\n } = {}\n ): Promise<VerifiableCredential> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n\n async issueCredential(\n credential: Partial<VerifiableCredential>,\n options: IssueCredentialsOptions = {}\n ): Promise<string> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.issueCredential(credential, options);\n }\n\n async publishCredential(\n did: string,\n options: { reveal?: boolean } = {}\n ): Promise<boolean> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.publishCredential(did, options);\n }\n\n async acceptCredential(did: string): Promise<boolean> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.acceptCredential(did);\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?: {\n retries?: number;\n delay?: number;\n }\n ): Promise<ChallengeResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response: ChallengeResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\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.keymasterConfig) {\n throw new Error(\"Missing Keymaster config\");\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","../src/keymasterClient.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","__reExport","mod","secondTarget","__toESM","isNodeMode","__esModule","value","__toCommonJS","src_exports","Keymaster","KeymasterExternalClient","module","exports","import_client","require","import_node","import_keymaster","_Keymaster","config","serviceStarted","validateConfig","ensureInitialized","instance","Error","ensureServiceIsRunning","serviceRunning","startInternal","gatekeeperConfig","startIntegratedKeymaster","gatekeeper","cipher","e","console","log","walletDb","GatekeeperClient","connect","CipherNode","keymasterService","KeymasterLib","wallet","ensureWalletExists","error","createChallengeInternal","spec","options","challenge","createChallenge","challengeUrl","callback","bindCredentialInternal","schemaId","subjectId","bindCredential","createResponseInternal","challengeDID","createResponse","backupWalletInternal","registry","backupWallet","issueCredentialInternal","credential","issueCredential","publishCredentialInternal","did","publishCredential","acceptCredentialInternal","acceptCredential","showMnemonicInternal","decryptMnemonic","verifyResponseInternal","verifyResponse","decryptMessageInternal","args","decryptMessage","decryptMnemonicInternal","getCredentialInternal","getCredential","removeCredentialInternal","removeCredential","updateCredentialInternal","updateCredential","createIdInternal","createId","removeIdInternal","removeId","resolveDIDInternal","resolveDID","setCurrentIdInternal","setCurrentId","createSchemaInternal","createSchema","newWalletInternal","newWallet","recoverWalletInternal","recoverWallet","existing","walletConfig","loadWallet","current","id","mnemonic","saveWallet","initialize","warn","start","getInstance","showMnemonic","keymasterConfig","startExternalKeymaster","startExternal","import_client2","KeymasterClient","response"],"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;IA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5CoE,WACJ;gCACF;;oCAAOA;;;;gBACT;;;;YAEcxF,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKN,cAAA;0CAAL;;;;gCAAwB;;oCAAM,MAAKsF,KAAA;;;uCAAX;;;gCAA/B;;;;;;gBACF;;;;YAEQrF,KAAAA;mBAAAA,SAAAA,eAAeF,MAAA;gBACrB,IAAI,CAACA,OAAO0F,eAAA,EAAiB;oBAC3B,MAAM,IAAIrF,MAAM;gBAClB;YACF;;;;;AHqRF,eAAe;AClafvB,WAAAQ,aAAcM,QAAA,0BAXdH,OAAAC,OAAA;AD+aA,6DAA6D;AAC7D,KAAMD,CAAAA,OAAOC,OAAO,GAAG;IACrBH,WAAAA;IACAC,yBAAAA;GACGI,QAAQ,yBACb","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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, \"default\"), secondTarget && __copyProps(secondTarget, mod, \"default\"));\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 KeymasterExternalClient: () => KeymasterExternalClient\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_keymaster = __toESM(require(\"@mdip/keymaster\"), 1);\nvar _Keymaster = class _Keymaster {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n static initialize(config) {\n if (!_Keymaster.instance) {\n _Keymaster.instance = new _Keymaster(config);\n console.log(\"\\u2705 Keymaster initialized\");\n } else {\n console.warn(\n \"Keymaster already initialized, ignoring re-initialization.\"\n );\n }\n }\n ensureInitialized() {\n if (!_Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n }\n // Delegated STATIC methods\n static async start() {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().startInternal();\n }\n static async createChallenge(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createChallengeInternal(...args);\n }\n static async bindCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().bindCredentialInternal(...args);\n }\n static async backupWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().backupWalletInternal(...args);\n }\n static async createResponse(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createResponseInternal(...args);\n }\n static async issueCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().issueCredentialInternal(...args);\n }\n static async publishCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().publishCredentialInternal(...args);\n }\n static async acceptCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().acceptCredentialInternal(...args);\n }\n static async showMnemonic(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().showMnemonicInternal(...args);\n }\n static async verifyResponse(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().verifyResponseInternal(...args);\n }\n static async decryptMessage(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().decryptMessageInternal(...args);\n }\n static async decryptMnemonic(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().decryptMnemonicInternal(...args);\n }\n static async getCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().getCredentialInternal(...args);\n }\n static async removeCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().removeCredentialInternal(...args);\n }\n static async updateCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().updateCredentialInternal(...args);\n }\n static async createId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createIdInternal(...args);\n }\n static async removeId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().removeIdInternal(...args);\n }\n static async resolveDID(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().resolveDIDInternal(...args);\n }\n static async setCurrentId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().setCurrentIdInternal(...args);\n }\n static async createSchema(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createSchemaInternal(...args);\n }\n static async newWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().newWalletInternal(...args);\n }\n static async recoverWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().recoverWalletInternal(...args);\n }\n static getInstance() {\n if (!_Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n return _Keymaster.instance;\n }\n // -------- Internal instance methods (originals renamed with Internal) -------\n async ensureServiceIsRunning() {\n if (!await this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n }\n async startInternal() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else {\n throw \"Missing Gatekeeper config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n if (this.config.walletDb) {\n const gatekeeper = new import_client.default();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new import_node.default();\n this.keymasterService = new import_keymaster.default({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\n });\n await this.ensureWalletExists();\n } else {\n return false;\n }\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 createChallengeInternal(spec, options) {\n await this.ensureServiceIsRunning();\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 bindCredentialInternal(schemaId, subjectId, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n async createResponseInternal(challengeDID, options) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createResponse(challengeDID, options);\n }\n async backupWalletInternal(registry) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.backupWallet(registry);\n }\n async issueCredentialInternal(credential, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.issueCredential(credential, options);\n }\n async publishCredentialInternal(did, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.publishCredential(did, options);\n }\n async acceptCredentialInternal(did) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.acceptCredential(did);\n }\n async showMnemonicInternal() {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponseInternal(did, options) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.verifyResponse(did, options);\n }\n async decryptMessageInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMessage(...args);\n }\n async decryptMnemonicInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic(...args);\n }\n async getCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.getCredential(...args);\n }\n async removeCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeCredential(...args);\n }\n async updateCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.updateCredential(...args);\n }\n async createIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createId(...args);\n }\n async removeIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeId(...args);\n }\n async resolveDIDInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.resolveDID(...args);\n }\n async setCurrentIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.setCurrentId(...args);\n }\n async createSchemaInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createSchema(...args);\n }\n async newWalletInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.newWallet(...args);\n }\n async recoverWalletInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.recoverWallet(...args);\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\n if (existing && \"current\" in existing) {\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(walletConfig.mnemonic, true);\n }\n if (walletConfig?.id) {\n const did = await this.keymasterService.createId(walletConfig.id, {\n registry: walletConfig.registry\n });\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n }\n async serviceRunning() {\n return this.serviceStarted || await this.startInternal();\n }\n validateConfig(config) {\n if (!config.gatekeeperConfig) {\n throw new Error(\"Missing Gatekeeper 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_Keymaster.instance = null;\nvar Keymaster = _Keymaster;\n\n// src/keymasterClient.ts\nvar import_client2 = __toESM(require(\"@mdip/keymaster/client\"), 1);\nvar KeymasterExternalClient = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startExternal() {\n 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 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 bindCredential(schemaId, subjectId, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n async issueCredential(credential, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.issueCredential(credential, options);\n }\n async publishCredential(did, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.publishCredential(did, options);\n }\n async acceptCredential(did) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.acceptCredential(did);\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 serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (!config.keymasterConfig) {\n throw new Error(\"Missing Keymaster config\");\n }\n }\n};\n\n// src/index.ts\n__reExport(src_exports, require(\"@mdip/keymaster/types\"), module.exports);\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n Keymaster,\n KeymasterExternalClient,\n ...require(\"@mdip/keymaster/types\")\n});\n","export { Keymaster, KeymasterConfig } from \"./keymaster.js\";\n\nexport { KeymasterExternalClient } from \"./keymasterClient.js\";\n\nexport {\n SdkConfig,\n WalletConfig,\n CreateChallengeResponse,\n CreateChallengeSpec,\n} from \"./types/index.js\";\n\nexport * from \"@mdip/keymaster/types\";\n","import GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterLib from \"@mdip/keymaster\";\nimport {\n CreateChallengeResponse,\n CreateChallengeSpec,\n SdkConfig,\n WalletConfig,\n} from \"./types/index.js\";\nimport {\n ChallengeResponse,\n CreateAssetOptions,\n CreateResponseOptions,\n IssueCredentialsOptions,\n StoredWallet,\n VerifiableCredential,\n WalletBase,\n} from \"@mdip/keymaster/types\";\n\nexport interface KeymasterConfig {\n gatekeeperConfig?: SdkConfig;\n walletDb?: WalletBase;\n walletConfig?: WalletConfig;\n}\n\nexport class Keymaster {\n private static instance: Keymaster | null = null;\n\n private config: KeymasterConfig;\n private keymasterService!: KeymasterLib;\n private serviceStarted = false;\n\n private constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public static initialize(config: KeymasterConfig) {\n if (!Keymaster.instance) {\n Keymaster.instance = new Keymaster(config);\n console.log(\"✅ Keymaster initialized\");\n } else {\n console.warn(\n \"Keymaster already initialized, ignoring re-initialization.\"\n );\n }\n }\n\n private ensureInitialized() {\n if (!Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n }\n\n // Delegated STATIC methods\n\n public static async start() {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().startInternal();\n }\n\n public static async createChallenge(\n ...args: Parameters<Keymaster[\"createChallengeInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createChallengeInternal(...args);\n }\n\n public static async bindCredential(\n ...args: Parameters<Keymaster[\"bindCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().bindCredentialInternal(...args);\n }\n\n public static async backupWallet(\n ...args: Parameters<Keymaster[\"backupWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().backupWalletInternal(...args);\n }\n\n public static async createResponse(\n ...args: Parameters<Keymaster[\"createResponseInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createResponseInternal(...args);\n }\n\n public static async issueCredential(\n ...args: Parameters<Keymaster[\"issueCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().issueCredentialInternal(...args);\n }\n\n public static async publishCredential(\n ...args: Parameters<Keymaster[\"publishCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().publishCredentialInternal(...args);\n }\n\n public static async acceptCredential(\n ...args: Parameters<Keymaster[\"acceptCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().acceptCredentialInternal(...args);\n }\n\n public static async showMnemonic(\n ...args: Parameters<Keymaster[\"showMnemonicInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().showMnemonicInternal(...args);\n }\n\n public static async verifyResponse(\n ...args: Parameters<Keymaster[\"verifyResponseInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().verifyResponseInternal(...args);\n }\n\n public static async decryptMessage(\n ...args: Parameters<Keymaster[\"decryptMessageInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().decryptMessageInternal(...args);\n }\n\n public static async decryptMnemonic(\n ...args: Parameters<Keymaster[\"decryptMnemonicInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().decryptMnemonicInternal(...args);\n }\n\n public static async getCredential(\n ...args: Parameters<Keymaster[\"getCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().getCredentialInternal(...args);\n }\n\n public static async removeCredential(\n ...args: Parameters<Keymaster[\"removeCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().removeCredentialInternal(...args);\n }\n\n public static async updateCredential(\n ...args: Parameters<Keymaster[\"updateCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().updateCredentialInternal(...args);\n }\n\n public static async createId(\n ...args: Parameters<Keymaster[\"createIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createIdInternal(...args);\n }\n\n public static async removeId(\n ...args: Parameters<Keymaster[\"removeIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().removeIdInternal(...args);\n }\n\n public static async resolveDID(\n ...args: Parameters<Keymaster[\"resolveDIDInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().resolveDIDInternal(...args);\n }\n\n public static async setCurrentId(\n ...args: Parameters<Keymaster[\"setCurrentIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().setCurrentIdInternal(...args);\n }\n\n public static async createSchema(\n ...args: Parameters<Keymaster[\"createSchemaInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createSchemaInternal(...args);\n }\n\n public static async newWallet(\n ...args: Parameters<Keymaster[\"newWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().newWalletInternal(...args);\n }\n\n public static async recoverWallet(\n ...args: Parameters<Keymaster[\"recoverWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().recoverWalletInternal(...args);\n }\n\n private static getInstance(): Keymaster {\n if (!Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n return Keymaster.instance;\n }\n\n // -------- Internal instance methods (originals renamed with Internal) -------\n\n private async ensureServiceIsRunning() {\n if (!(await this.serviceRunning())) {\n throw new Error(\"Keymaster service not running\");\n }\n }\n\n private async startInternal(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else {\n throw \"Missing Gatekeeper 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 if (this.config.walletDb) {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\n });\n\n await this.ensureWalletExists();\n } else {\n return false;\n }\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 createChallengeInternal(\n spec: CreateChallengeSpec,\n options?: CreateAssetOptions\n ): Promise<CreateChallengeResponse> {\n await this.ensureServiceIsRunning();\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 private async bindCredentialInternal(\n schemaId: string,\n subjectId: string,\n options: {\n validFrom?: string;\n validUntil?: string;\n credential?: Record<string, unknown>;\n } = {}\n ): Promise<VerifiableCredential> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n\n private async createResponseInternal(\n challengeDID: string,\n options?: CreateResponseOptions\n ): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createResponse(challengeDID, options);\n }\n\n private async backupWalletInternal(registry?: string): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.backupWallet(registry);\n }\n\n private async issueCredentialInternal(\n credential: Partial<VerifiableCredential>,\n options: IssueCredentialsOptions = {}\n ): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.issueCredential(credential, options);\n }\n\n private async publishCredentialInternal(\n did: string,\n options: { reveal?: boolean } = {}\n ): Promise<VerifiableCredential> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.publishCredential(did, options);\n }\n\n private async acceptCredentialInternal(did: string): Promise<boolean> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.acceptCredential(did);\n }\n\n private async showMnemonicInternal(): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic();\n }\n\n private async verifyResponseInternal(\n did: string,\n options?: { retries?: number; delay?: number }\n ): Promise<ChallengeResponse> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.verifyResponse(did, options);\n }\n\n private async decryptMessageInternal(\n ...args: Parameters<KeymasterLib[\"decryptMessage\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMessage(...args);\n }\n\n private async decryptMnemonicInternal(\n ...args: Parameters<KeymasterLib[\"decryptMnemonic\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic(...args);\n }\n\n private async getCredentialInternal(\n ...args: Parameters<KeymasterLib[\"getCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.getCredential(...args);\n }\n\n private async removeCredentialInternal(\n ...args: Parameters<KeymasterLib[\"removeCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeCredential(...args);\n }\n\n private async updateCredentialInternal(\n ...args: Parameters<KeymasterLib[\"updateCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.updateCredential(...args);\n }\n\n private async createIdInternal(\n ...args: Parameters<KeymasterLib[\"createId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createId(...args);\n }\n\n private async removeIdInternal(\n ...args: Parameters<KeymasterLib[\"removeId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeId(...args);\n }\n\n private async resolveDIDInternal(\n ...args: Parameters<KeymasterLib[\"resolveDID\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.resolveDID(...args);\n }\n\n private async setCurrentIdInternal(\n ...args: Parameters<KeymasterLib[\"setCurrentId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.setCurrentId(...args);\n }\n\n private async createSchemaInternal(\n ...args: Parameters<KeymasterLib[\"createSchema\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createSchema(...args);\n }\n\n private async newWalletInternal(\n ...args: Parameters<KeymasterLib[\"newWallet\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.newWallet(...args);\n }\n\n private async recoverWalletInternal(\n ...args: Parameters<KeymasterLib[\"recoverWallet\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.recoverWallet(...args);\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: StoredWallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\n if (existing && \"current\" in existing) {\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 if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n\n if (walletConfig?.id) {\n const did = await this.keymasterService.createId(walletConfig.id, {\n registry: walletConfig.registry,\n });\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.startInternal());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (!config.gatekeeperConfig) {\n throw new Error(\"Missing Gatekeeper 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","import KeymasterClient from \"@mdip/keymaster/client\";\nimport {\n ChallengeResponse,\n CreateAssetOptions,\n IssueCredentialsOptions,\n VerifiableCredential,\n} from \"@mdip/keymaster/types\";\nimport {\n CreateChallengeResponse,\n CreateChallengeSpec,\n SdkConfig,\n} from \"./types/index.js\";\n\nexport interface KeymasterConfig {\n keymasterConfig?: SdkConfig;\n}\n\nexport class KeymasterExternalClient {\n private config: KeymasterConfig;\n private keymasterService!: KeymasterClient;\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.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n public async startExternal(): Promise<boolean> {\n 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 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?: CreateAssetOptions\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 bindCredential(\n schemaId: string,\n subjectId: string,\n options: {\n validFrom?: string;\n validUntil?: string;\n credential?: Record<string, unknown>;\n } = {}\n ): Promise<VerifiableCredential> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n\n async issueCredential(\n credential: Partial<VerifiableCredential>,\n options: IssueCredentialsOptions = {}\n ): Promise<string> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.issueCredential(credential, options);\n }\n\n async publishCredential(\n did: string,\n options: { reveal?: boolean } = {}\n ): Promise<boolean> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.publishCredential(did, options);\n }\n\n async acceptCredential(did: string): Promise<boolean> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.acceptCredential(did);\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?: {\n retries?: number;\n delay?: number;\n }\n ): Promise<ChallengeResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response: ChallengeResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\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.keymasterConfig) {\n throw new Error(\"Missing Keymaster config\");\n }\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -42,6 +42,8 @@ declare class Keymaster {
42
42
  static start(): Promise<boolean>;
43
43
  static createChallenge(...args: Parameters<Keymaster["createChallengeInternal"]>): Promise<CreateChallengeResponse>;
44
44
  static bindCredential(...args: Parameters<Keymaster["bindCredentialInternal"]>): Promise<VerifiableCredential>;
45
+ static backupWallet(...args: Parameters<Keymaster["backupWalletInternal"]>): Promise<string>;
46
+ static createResponse(...args: Parameters<Keymaster["createResponseInternal"]>): Promise<string>;
45
47
  static issueCredential(...args: Parameters<Keymaster["issueCredentialInternal"]>): Promise<string>;
46
48
  static publishCredential(...args: Parameters<Keymaster["publishCredentialInternal"]>): Promise<VerifiableCredential>;
47
49
  static acceptCredential(...args: Parameters<Keymaster["acceptCredentialInternal"]>): Promise<boolean>;
@@ -65,6 +67,8 @@ declare class Keymaster {
65
67
  private startIntegratedKeymaster;
66
68
  private createChallengeInternal;
67
69
  private bindCredentialInternal;
70
+ private createResponseInternal;
71
+ private backupWalletInternal;
68
72
  private issueCredentialInternal;
69
73
  private publishCredentialInternal;
70
74
  private acceptCredentialInternal;
package/dist/index.d.ts CHANGED
@@ -42,6 +42,8 @@ declare class Keymaster {
42
42
  static start(): Promise<boolean>;
43
43
  static createChallenge(...args: Parameters<Keymaster["createChallengeInternal"]>): Promise<CreateChallengeResponse>;
44
44
  static bindCredential(...args: Parameters<Keymaster["bindCredentialInternal"]>): Promise<VerifiableCredential>;
45
+ static backupWallet(...args: Parameters<Keymaster["backupWalletInternal"]>): Promise<string>;
46
+ static createResponse(...args: Parameters<Keymaster["createResponseInternal"]>): Promise<string>;
45
47
  static issueCredential(...args: Parameters<Keymaster["issueCredentialInternal"]>): Promise<string>;
46
48
  static publishCredential(...args: Parameters<Keymaster["publishCredentialInternal"]>): Promise<VerifiableCredential>;
47
49
  static acceptCredential(...args: Parameters<Keymaster["acceptCredentialInternal"]>): Promise<boolean>;
@@ -65,6 +67,8 @@ declare class Keymaster {
65
67
  private startIntegratedKeymaster;
66
68
  private createChallengeInternal;
67
69
  private bindCredentialInternal;
70
+ private createResponseInternal;
71
+ private backupWalletInternal;
68
72
  private issueCredentialInternal;
69
73
  private publishCredentialInternal;
70
74
  private acceptCredentialInternal;
package/dist/index.js CHANGED
@@ -376,6 +376,52 @@ var _Keymaster = /*#__PURE__*/ function() {
376
376
  })();
377
377
  }
378
378
  },
379
+ {
380
+ key: "createResponseInternal",
381
+ value: function createResponseInternal(challengeDID, options) {
382
+ var _this = this;
383
+ return _async_to_generator(function() {
384
+ return _ts_generator(this, function(_state) {
385
+ switch(_state.label){
386
+ case 0:
387
+ return [
388
+ 4,
389
+ _this.ensureServiceIsRunning()
390
+ ];
391
+ case 1:
392
+ _state.sent();
393
+ return [
394
+ 2,
395
+ _this.keymasterService.createResponse(challengeDID, options)
396
+ ];
397
+ }
398
+ });
399
+ })();
400
+ }
401
+ },
402
+ {
403
+ key: "backupWalletInternal",
404
+ value: function backupWalletInternal(registry) {
405
+ var _this = this;
406
+ return _async_to_generator(function() {
407
+ return _ts_generator(this, function(_state) {
408
+ switch(_state.label){
409
+ case 0:
410
+ return [
411
+ 4,
412
+ _this.ensureServiceIsRunning()
413
+ ];
414
+ case 1:
415
+ _state.sent();
416
+ return [
417
+ 2,
418
+ _this.keymasterService.backupWallet(registry)
419
+ ];
420
+ }
421
+ });
422
+ })();
423
+ }
424
+ },
379
425
  {
380
426
  key: "issueCredentialInternal",
381
427
  value: function issueCredentialInternal(credential) {
@@ -991,6 +1037,42 @@ var _Keymaster = /*#__PURE__*/ function() {
991
1037
  })();
992
1038
  }
993
1039
  },
1040
+ {
1041
+ key: "backupWallet",
1042
+ value: function backupWallet() {
1043
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1044
+ args[_key] = arguments[_key];
1045
+ }
1046
+ return _async_to_generator(function() {
1047
+ var _Keymaster_getInstance;
1048
+ return _ts_generator(this, function(_state) {
1049
+ _Keymaster.getInstance().ensureInitialized();
1050
+ return [
1051
+ 2,
1052
+ (_Keymaster_getInstance = _Keymaster.getInstance()).backupWalletInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1053
+ ];
1054
+ });
1055
+ })();
1056
+ }
1057
+ },
1058
+ {
1059
+ key: "createResponse",
1060
+ value: function createResponse() {
1061
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
1062
+ args[_key] = arguments[_key];
1063
+ }
1064
+ return _async_to_generator(function() {
1065
+ var _Keymaster_getInstance;
1066
+ return _ts_generator(this, function(_state) {
1067
+ _Keymaster.getInstance().ensureInitialized();
1068
+ return [
1069
+ 2,
1070
+ (_Keymaster_getInstance = _Keymaster.getInstance()).createResponseInternal.apply(_Keymaster_getInstance, _to_consumable_array(args))
1071
+ ];
1072
+ });
1073
+ })();
1074
+ }
1075
+ },
994
1076
  {
995
1077
  key: "issueCredential",
996
1078
  value: function issueCredential() {
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","../src/keymasterClient.ts","../src/index.ts"],"names":["GatekeeperClient","CipherNode","KeymasterLib","_Keymaster","config","serviceStarted","validateConfig","ensureInitialized","instance","Error","ensureServiceIsRunning","serviceRunning","startInternal","gatekeeperConfig","startIntegratedKeymaster","gatekeeper","cipher","e","console","log","walletDb","connect","keymasterService","wallet","ensureWalletExists","error","createChallengeInternal","spec","options","challenge","createChallenge","challengeUrl","callback","bindCredentialInternal","schemaId","subjectId","bindCredential","issueCredentialInternal","credential","issueCredential","publishCredentialInternal","did","publishCredential","acceptCredentialInternal","acceptCredential","showMnemonicInternal","decryptMnemonic","verifyResponseInternal","verifyResponse","decryptMessageInternal","args","decryptMessage","decryptMnemonicInternal","getCredentialInternal","getCredential","removeCredentialInternal","removeCredential","updateCredentialInternal","updateCredential","createIdInternal","createId","removeIdInternal","removeId","resolveDIDInternal","resolveDID","setCurrentIdInternal","setCurrentId","createSchemaInternal","createSchema","newWalletInternal","newWallet","recoverWalletInternal","recoverWallet","existing","walletConfig","loadWallet","current","id","mnemonic","registry","saveWallet","initialize","warn","start","getInstance","showMnemonic","Keymaster","KeymasterClient","KeymasterExternalClient","keymasterConfig","startExternalKeymaster","startExternal","response"],"mappings":"AAAA,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAnB,OAAOA,sBAAsB,0BAAA;AAC7B,OAAOC,gBAAgB,oBAAA;AACvB,OAAOC,kBAAkB,kBAAA;AAsBlB,IAAMC,2BAAN;;aAAMA,WAOSC,MAAA;gCAPTD;QAKX,IAAA,CAAQE,cAAA,GAAiB;QAGvB,IAAA,CAAKC,cAAA,CAAeF;QACpB,IAAA,CAAKA,MAAA,GAASA;;;;YAcRG,KAAAA;mBAAAA,SAAAA;gBACN,IAAI,CAACJ,WAAUK,QAAA,EAAU;oBACvB,MAAM,IAAIC,MACR;gBAEJ;YACF;;;YAyJcC,KAAAA;mBAJd,AAIA,+EAJA;YAIA,SAAcA;;uBAAd,oBAAA;;;;gCACQ;;oCAAM,MAAKC,cAAA;;;gCAAjB,IAAI,CAAE,eAA8B;oCAClC,MAAM,IAAIF,MAAM;gCAClB;;;;;;gBACF;;;;YAEcG,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;qCACM,MAAKR,MAA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Client from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterLib from \"@mdip/keymaster\";\nvar _Keymaster = class _Keymaster {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n static initialize(config) {\n if (!_Keymaster.instance) {\n _Keymaster.instance = new _Keymaster(config);\n console.log(\"\\u2705 Keymaster initialized\");\n } else {\n console.warn(\n \"Keymaster already initialized, ignoring re-initialization.\"\n );\n }\n }\n ensureInitialized() {\n if (!_Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n }\n // Delegated STATIC methods\n static async start() {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().startInternal();\n }\n static async createChallenge(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createChallengeInternal(...args);\n }\n static async bindCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().bindCredentialInternal(...args);\n }\n static async issueCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().issueCredentialInternal(...args);\n }\n static async publishCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().publishCredentialInternal(...args);\n }\n static async acceptCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().acceptCredentialInternal(...args);\n }\n static async showMnemonic(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().showMnemonicInternal(...args);\n }\n static async verifyResponse(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().verifyResponseInternal(...args);\n }\n static async decryptMessage(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().decryptMessageInternal(...args);\n }\n static async decryptMnemonic(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().decryptMnemonicInternal(...args);\n }\n static async getCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().getCredentialInternal(...args);\n }\n static async removeCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().removeCredentialInternal(...args);\n }\n static async updateCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().updateCredentialInternal(...args);\n }\n static async createId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createIdInternal(...args);\n }\n static async removeId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().removeIdInternal(...args);\n }\n static async resolveDID(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().resolveDIDInternal(...args);\n }\n static async setCurrentId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().setCurrentIdInternal(...args);\n }\n static async createSchema(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createSchemaInternal(...args);\n }\n static async newWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().newWalletInternal(...args);\n }\n static async recoverWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().recoverWalletInternal(...args);\n }\n static getInstance() {\n if (!_Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n return _Keymaster.instance;\n }\n // -------- Internal instance methods (originals renamed with Internal) -------\n async ensureServiceIsRunning() {\n if (!await this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n }\n async startInternal() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else {\n throw \"Missing Gatekeeper config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n if (this.config.walletDb) {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new CipherNode();\n this.keymasterService = new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\n });\n await this.ensureWalletExists();\n } else {\n return false;\n }\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 createChallengeInternal(spec, options) {\n await this.ensureServiceIsRunning();\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 bindCredentialInternal(schemaId, subjectId, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n async issueCredentialInternal(credential, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.issueCredential(credential, options);\n }\n async publishCredentialInternal(did, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.publishCredential(did, options);\n }\n async acceptCredentialInternal(did) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.acceptCredential(did);\n }\n async showMnemonicInternal() {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponseInternal(did, options) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.verifyResponse(did, options);\n }\n async decryptMessageInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMessage(...args);\n }\n async decryptMnemonicInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic(...args);\n }\n async getCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.getCredential(...args);\n }\n async removeCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeCredential(...args);\n }\n async updateCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.updateCredential(...args);\n }\n async createIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createId(...args);\n }\n async removeIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeId(...args);\n }\n async resolveDIDInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.resolveDID(...args);\n }\n async setCurrentIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.setCurrentId(...args);\n }\n async createSchemaInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createSchema(...args);\n }\n async newWalletInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.newWallet(...args);\n }\n async recoverWalletInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.recoverWallet(...args);\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\n if (existing && \"current\" in existing) {\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(walletConfig.mnemonic, true);\n }\n if (walletConfig?.id) {\n const did = await this.keymasterService.createId(walletConfig.id, {\n registry: walletConfig.registry\n });\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n }\n async serviceRunning() {\n return this.serviceStarted || await this.startInternal();\n }\n validateConfig(config) {\n if (!config.gatekeeperConfig) {\n throw new Error(\"Missing Gatekeeper 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_Keymaster.instance = null;\nvar Keymaster = _Keymaster;\n\n// src/keymasterClient.ts\nimport KeymasterClient from \"@mdip/keymaster/client\";\nvar KeymasterExternalClient = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startExternal() {\n 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 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 bindCredential(schemaId, subjectId, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n async issueCredential(credential, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.issueCredential(credential, options);\n }\n async publishCredential(did, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.publishCredential(did, options);\n }\n async acceptCredential(did) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.acceptCredential(did);\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 serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (!config.keymasterConfig) {\n throw new Error(\"Missing Keymaster config\");\n }\n }\n};\n\n// src/index.ts\nexport * from \"@mdip/keymaster/types\";\nexport {\n Keymaster,\n KeymasterExternalClient\n};\n","import GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterLib from \"@mdip/keymaster\";\nimport {\n CreateChallengeResponse,\n CreateChallengeSpec,\n SdkConfig,\n WalletConfig,\n} from \"./types/index.js\";\nimport {\n ChallengeResponse,\n CreateAssetOptions,\n IssueCredentialsOptions,\n StoredWallet,\n VerifiableCredential,\n WalletBase,\n} from \"@mdip/keymaster/types\";\n\nexport interface KeymasterConfig {\n gatekeeperConfig?: SdkConfig;\n walletDb?: WalletBase;\n walletConfig?: WalletConfig;\n}\n\nexport class Keymaster {\n private static instance: Keymaster | null = null;\n\n private config: KeymasterConfig;\n private keymasterService!: KeymasterLib;\n private serviceStarted = false;\n\n private constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public static initialize(config: KeymasterConfig) {\n if (!Keymaster.instance) {\n Keymaster.instance = new Keymaster(config);\n console.log(\"✅ Keymaster initialized\");\n } else {\n console.warn(\n \"Keymaster already initialized, ignoring re-initialization.\"\n );\n }\n }\n\n private ensureInitialized() {\n if (!Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n }\n\n // Delegated STATIC methods\n\n public static async start() {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().startInternal();\n }\n\n public static async createChallenge(\n ...args: Parameters<Keymaster[\"createChallengeInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createChallengeInternal(...args);\n }\n\n public static async bindCredential(\n ...args: Parameters<Keymaster[\"bindCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().bindCredentialInternal(...args);\n }\n\n public static async issueCredential(\n ...args: Parameters<Keymaster[\"issueCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().issueCredentialInternal(...args);\n }\n\n public static async publishCredential(\n ...args: Parameters<Keymaster[\"publishCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().publishCredentialInternal(...args);\n }\n\n public static async acceptCredential(\n ...args: Parameters<Keymaster[\"acceptCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().acceptCredentialInternal(...args);\n }\n\n public static async showMnemonic(\n ...args: Parameters<Keymaster[\"showMnemonicInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().showMnemonicInternal(...args);\n }\n\n public static async verifyResponse(\n ...args: Parameters<Keymaster[\"verifyResponseInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().verifyResponseInternal(...args);\n }\n\n public static async decryptMessage(\n ...args: Parameters<Keymaster[\"decryptMessageInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().decryptMessageInternal(...args);\n }\n\n public static async decryptMnemonic(\n ...args: Parameters<Keymaster[\"decryptMnemonicInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().decryptMnemonicInternal(...args);\n }\n\n public static async getCredential(\n ...args: Parameters<Keymaster[\"getCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().getCredentialInternal(...args);\n }\n\n public static async removeCredential(\n ...args: Parameters<Keymaster[\"removeCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().removeCredentialInternal(...args);\n }\n\n public static async updateCredential(\n ...args: Parameters<Keymaster[\"updateCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().updateCredentialInternal(...args);\n }\n\n public static async createId(\n ...args: Parameters<Keymaster[\"createIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createIdInternal(...args);\n }\n\n public static async removeId(\n ...args: Parameters<Keymaster[\"removeIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().removeIdInternal(...args);\n }\n\n public static async resolveDID(\n ...args: Parameters<Keymaster[\"resolveDIDInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().resolveDIDInternal(...args);\n }\n\n public static async setCurrentId(\n ...args: Parameters<Keymaster[\"setCurrentIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().setCurrentIdInternal(...args);\n }\n\n public static async createSchema(\n ...args: Parameters<Keymaster[\"createSchemaInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createSchemaInternal(...args);\n }\n\n public static async newWallet(\n ...args: Parameters<Keymaster[\"newWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().newWalletInternal(...args);\n }\n\n public static async recoverWallet(\n ...args: Parameters<Keymaster[\"recoverWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().recoverWalletInternal(...args);\n }\n\n private static getInstance(): Keymaster {\n if (!Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n return Keymaster.instance;\n }\n\n // -------- Internal instance methods (originals renamed with Internal) -------\n\n private async ensureServiceIsRunning() {\n if (!(await this.serviceRunning())) {\n throw new Error(\"Keymaster service not running\");\n }\n }\n\n private async startInternal(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else {\n throw \"Missing Gatekeeper 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 if (this.config.walletDb) {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\n });\n\n await this.ensureWalletExists();\n } else {\n return false;\n }\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 createChallengeInternal(\n spec: CreateChallengeSpec,\n options?: CreateAssetOptions\n ): Promise<CreateChallengeResponse> {\n await this.ensureServiceIsRunning();\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 private async bindCredentialInternal(\n schemaId: string,\n subjectId: string,\n options: {\n validFrom?: string;\n validUntil?: string;\n credential?: Record<string, unknown>;\n } = {}\n ): Promise<VerifiableCredential> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n\n private async issueCredentialInternal(\n credential: Partial<VerifiableCredential>,\n options: IssueCredentialsOptions = {}\n ): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.issueCredential(credential, options);\n }\n\n private async publishCredentialInternal(\n did: string,\n options: { reveal?: boolean } = {}\n ): Promise<VerifiableCredential> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.publishCredential(did, options);\n }\n\n private async acceptCredentialInternal(did: string): Promise<boolean> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.acceptCredential(did);\n }\n\n private async showMnemonicInternal(): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic();\n }\n\n private async verifyResponseInternal(\n did: string,\n options?: { retries?: number; delay?: number }\n ): Promise<ChallengeResponse> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.verifyResponse(did, options);\n }\n\n private async decryptMessageInternal(\n ...args: Parameters<KeymasterLib[\"decryptMessage\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMessage(...args);\n }\n\n private async decryptMnemonicInternal(\n ...args: Parameters<KeymasterLib[\"decryptMnemonic\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic(...args);\n }\n\n private async getCredentialInternal(\n ...args: Parameters<KeymasterLib[\"getCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.getCredential(...args);\n }\n\n private async removeCredentialInternal(\n ...args: Parameters<KeymasterLib[\"removeCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeCredential(...args);\n }\n\n private async updateCredentialInternal(\n ...args: Parameters<KeymasterLib[\"updateCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.updateCredential(...args);\n }\n\n private async createIdInternal(\n ...args: Parameters<KeymasterLib[\"createId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createId(...args);\n }\n\n private async removeIdInternal(\n ...args: Parameters<KeymasterLib[\"removeId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeId(...args);\n }\n\n private async resolveDIDInternal(\n ...args: Parameters<KeymasterLib[\"resolveDID\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.resolveDID(...args);\n }\n\n private async setCurrentIdInternal(\n ...args: Parameters<KeymasterLib[\"setCurrentId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.setCurrentId(...args);\n }\n\n private async createSchemaInternal(\n ...args: Parameters<KeymasterLib[\"createSchema\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createSchema(...args);\n }\n\n private async newWalletInternal(\n ...args: Parameters<KeymasterLib[\"newWallet\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.newWallet(...args);\n }\n\n private async recoverWalletInternal(\n ...args: Parameters<KeymasterLib[\"recoverWallet\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.recoverWallet(...args);\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: StoredWallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\n if (existing && \"current\" in existing) {\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 if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n\n if (walletConfig?.id) {\n const did = await this.keymasterService.createId(walletConfig.id, {\n registry: walletConfig.registry,\n });\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.startInternal());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (!config.gatekeeperConfig) {\n throw new Error(\"Missing Gatekeeper 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","import KeymasterClient from \"@mdip/keymaster/client\";\nimport {\n ChallengeResponse,\n CreateAssetOptions,\n IssueCredentialsOptions,\n VerifiableCredential,\n} from \"@mdip/keymaster/types\";\nimport {\n CreateChallengeResponse,\n CreateChallengeSpec,\n SdkConfig,\n} from \"./types/index.js\";\n\nexport interface KeymasterConfig {\n keymasterConfig?: SdkConfig;\n}\n\nexport class KeymasterExternalClient {\n private config: KeymasterConfig;\n private keymasterService!: KeymasterClient;\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.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n public async startExternal(): Promise<boolean> {\n 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 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?: CreateAssetOptions\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 bindCredential(\n schemaId: string,\n subjectId: string,\n options: {\n validFrom?: string;\n validUntil?: string;\n credential?: Record<string, unknown>;\n } = {}\n ): Promise<VerifiableCredential> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n\n async issueCredential(\n credential: Partial<VerifiableCredential>,\n options: IssueCredentialsOptions = {}\n ): Promise<string> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.issueCredential(credential, options);\n }\n\n async publishCredential(\n did: string,\n options: { reveal?: boolean } = {}\n ): Promise<boolean> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.publishCredential(did, options);\n }\n\n async acceptCredential(did: string): Promise<boolean> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.acceptCredential(did);\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?: {\n retries?: number;\n delay?: number;\n }\n ): Promise<ChallengeResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response: ChallengeResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\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.keymasterConfig) {\n throw new Error(\"Missing Keymaster config\");\n }\n }\n}\n","export { Keymaster, KeymasterConfig } from \"./keymaster.js\";\n\nexport { KeymasterExternalClient } from \"./keymasterClient.js\";\n\nexport {\n SdkConfig,\n WalletConfig,\n CreateChallengeResponse,\n CreateChallengeSpec,\n} from \"./types/index.js\";\n\nexport * from \"@mdip/keymaster/types\";\n"]}
1
+ {"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.js","../src/keymaster.ts","../src/keymasterClient.ts","../src/index.ts"],"names":["GatekeeperClient","CipherNode","KeymasterLib","_Keymaster","config","serviceStarted","validateConfig","ensureInitialized","instance","Error","ensureServiceIsRunning","serviceRunning","startInternal","gatekeeperConfig","startIntegratedKeymaster","gatekeeper","cipher","e","console","log","walletDb","connect","keymasterService","wallet","ensureWalletExists","error","createChallengeInternal","spec","options","challenge","createChallenge","challengeUrl","callback","bindCredentialInternal","schemaId","subjectId","bindCredential","createResponseInternal","challengeDID","createResponse","backupWalletInternal","registry","backupWallet","issueCredentialInternal","credential","issueCredential","publishCredentialInternal","did","publishCredential","acceptCredentialInternal","acceptCredential","showMnemonicInternal","decryptMnemonic","verifyResponseInternal","verifyResponse","decryptMessageInternal","args","decryptMessage","decryptMnemonicInternal","getCredentialInternal","getCredential","removeCredentialInternal","removeCredential","updateCredentialInternal","updateCredential","createIdInternal","createId","removeIdInternal","removeId","resolveDIDInternal","resolveDID","setCurrentIdInternal","setCurrentId","createSchemaInternal","createSchema","newWalletInternal","newWallet","recoverWalletInternal","recoverWallet","existing","walletConfig","loadWallet","current","id","mnemonic","saveWallet","initialize","warn","start","getInstance","showMnemonic","Keymaster","KeymasterClient","KeymasterExternalClient","keymasterConfig","startExternalKeymaster","startExternal","response"],"mappings":"AA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AAA,IAAkB;oCAC1B,MAAM,IAAIF,MAAM;gCAClB;gCAEE;;oCAAM,MAAKa,gBAAA,CAAiBgC,cAAA,CAAeP,KAAKnB;;;gCAD5CqE,WACJ;gCACF;;oCAAOA;;;;gBACT;;;;YAEctF,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKN,cAAA;0CAAL;;;;gCAAwB;;oCAAM,MAAKmF,KAAA;;;uCAAX;;;gCAA/B;;;;;;gBACF;;;;YAEQlF,KAAAA;mBAAAA,SAAAA,eAAeF,MAAA;gBACrB,IAAI,CAACA,OAAO0F,eAAA,EAAiB;oBAC3B,MAAM,IAAIrF,MAAM;gBAClB;YACF;;;;;AF+OF,eAAe;AG5Xf,cAAc,wBAAA;AH8Xd,SACEkF,SAAS,EACTE,uBAAuB,GACvB","sourcesContent":["// src/keymaster.ts\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterLib from \"@mdip/keymaster\";\nvar _Keymaster = class _Keymaster {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n static initialize(config) {\n if (!_Keymaster.instance) {\n _Keymaster.instance = new _Keymaster(config);\n console.log(\"\\u2705 Keymaster initialized\");\n } else {\n console.warn(\n \"Keymaster already initialized, ignoring re-initialization.\"\n );\n }\n }\n ensureInitialized() {\n if (!_Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n }\n // Delegated STATIC methods\n static async start() {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().startInternal();\n }\n static async createChallenge(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createChallengeInternal(...args);\n }\n static async bindCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().bindCredentialInternal(...args);\n }\n static async backupWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().backupWalletInternal(...args);\n }\n static async createResponse(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createResponseInternal(...args);\n }\n static async issueCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().issueCredentialInternal(...args);\n }\n static async publishCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().publishCredentialInternal(...args);\n }\n static async acceptCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().acceptCredentialInternal(...args);\n }\n static async showMnemonic(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().showMnemonicInternal(...args);\n }\n static async verifyResponse(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().verifyResponseInternal(...args);\n }\n static async decryptMessage(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().decryptMessageInternal(...args);\n }\n static async decryptMnemonic(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().decryptMnemonicInternal(...args);\n }\n static async getCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().getCredentialInternal(...args);\n }\n static async removeCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().removeCredentialInternal(...args);\n }\n static async updateCredential(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().updateCredentialInternal(...args);\n }\n static async createId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createIdInternal(...args);\n }\n static async removeId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().removeIdInternal(...args);\n }\n static async resolveDID(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().resolveDIDInternal(...args);\n }\n static async setCurrentId(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().setCurrentIdInternal(...args);\n }\n static async createSchema(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().createSchemaInternal(...args);\n }\n static async newWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().newWalletInternal(...args);\n }\n static async recoverWallet(...args) {\n _Keymaster.getInstance().ensureInitialized();\n return _Keymaster.getInstance().recoverWalletInternal(...args);\n }\n static getInstance() {\n if (!_Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n return _Keymaster.instance;\n }\n // -------- Internal instance methods (originals renamed with Internal) -------\n async ensureServiceIsRunning() {\n if (!await this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n }\n async startInternal() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else {\n throw \"Missing Gatekeeper config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n if (this.config.walletDb) {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new CipherNode();\n this.keymasterService = new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\n });\n await this.ensureWalletExists();\n } else {\n return false;\n }\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 createChallengeInternal(spec, options) {\n await this.ensureServiceIsRunning();\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 bindCredentialInternal(schemaId, subjectId, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n async createResponseInternal(challengeDID, options) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createResponse(challengeDID, options);\n }\n async backupWalletInternal(registry) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.backupWallet(registry);\n }\n async issueCredentialInternal(credential, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.issueCredential(credential, options);\n }\n async publishCredentialInternal(did, options = {}) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.publishCredential(did, options);\n }\n async acceptCredentialInternal(did) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.acceptCredential(did);\n }\n async showMnemonicInternal() {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponseInternal(did, options) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.verifyResponse(did, options);\n }\n async decryptMessageInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMessage(...args);\n }\n async decryptMnemonicInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic(...args);\n }\n async getCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.getCredential(...args);\n }\n async removeCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeCredential(...args);\n }\n async updateCredentialInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.updateCredential(...args);\n }\n async createIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createId(...args);\n }\n async removeIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeId(...args);\n }\n async resolveDIDInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.resolveDID(...args);\n }\n async setCurrentIdInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.setCurrentId(...args);\n }\n async createSchemaInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createSchema(...args);\n }\n async newWalletInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.newWallet(...args);\n }\n async recoverWalletInternal(...args) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.recoverWallet(...args);\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\n if (existing && \"current\" in existing) {\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(walletConfig.mnemonic, true);\n }\n if (walletConfig?.id) {\n const did = await this.keymasterService.createId(walletConfig.id, {\n registry: walletConfig.registry\n });\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n }\n async serviceRunning() {\n return this.serviceStarted || await this.startInternal();\n }\n validateConfig(config) {\n if (!config.gatekeeperConfig) {\n throw new Error(\"Missing Gatekeeper 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_Keymaster.instance = null;\nvar Keymaster = _Keymaster;\n\n// src/keymasterClient.ts\nimport KeymasterClient from \"@mdip/keymaster/client\";\nvar KeymasterExternalClient = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startExternal() {\n 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 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 bindCredential(schemaId, subjectId, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n async issueCredential(credential, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.issueCredential(credential, options);\n }\n async publishCredential(did, options = {}) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.publishCredential(did, options);\n }\n async acceptCredential(did) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.acceptCredential(did);\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 serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (!config.keymasterConfig) {\n throw new Error(\"Missing Keymaster config\");\n }\n }\n};\n\n// src/index.ts\nexport * from \"@mdip/keymaster/types\";\nexport {\n Keymaster,\n KeymasterExternalClient\n};\n","import GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterLib from \"@mdip/keymaster\";\nimport {\n CreateChallengeResponse,\n CreateChallengeSpec,\n SdkConfig,\n WalletConfig,\n} from \"./types/index.js\";\nimport {\n ChallengeResponse,\n CreateAssetOptions,\n CreateResponseOptions,\n IssueCredentialsOptions,\n StoredWallet,\n VerifiableCredential,\n WalletBase,\n} from \"@mdip/keymaster/types\";\n\nexport interface KeymasterConfig {\n gatekeeperConfig?: SdkConfig;\n walletDb?: WalletBase;\n walletConfig?: WalletConfig;\n}\n\nexport class Keymaster {\n private static instance: Keymaster | null = null;\n\n private config: KeymasterConfig;\n private keymasterService!: KeymasterLib;\n private serviceStarted = false;\n\n private constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public static initialize(config: KeymasterConfig) {\n if (!Keymaster.instance) {\n Keymaster.instance = new Keymaster(config);\n console.log(\"✅ Keymaster initialized\");\n } else {\n console.warn(\n \"Keymaster already initialized, ignoring re-initialization.\"\n );\n }\n }\n\n private ensureInitialized() {\n if (!Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n }\n\n // Delegated STATIC methods\n\n public static async start() {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().startInternal();\n }\n\n public static async createChallenge(\n ...args: Parameters<Keymaster[\"createChallengeInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createChallengeInternal(...args);\n }\n\n public static async bindCredential(\n ...args: Parameters<Keymaster[\"bindCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().bindCredentialInternal(...args);\n }\n\n public static async backupWallet(\n ...args: Parameters<Keymaster[\"backupWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().backupWalletInternal(...args);\n }\n\n public static async createResponse(\n ...args: Parameters<Keymaster[\"createResponseInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createResponseInternal(...args);\n }\n\n public static async issueCredential(\n ...args: Parameters<Keymaster[\"issueCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().issueCredentialInternal(...args);\n }\n\n public static async publishCredential(\n ...args: Parameters<Keymaster[\"publishCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().publishCredentialInternal(...args);\n }\n\n public static async acceptCredential(\n ...args: Parameters<Keymaster[\"acceptCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().acceptCredentialInternal(...args);\n }\n\n public static async showMnemonic(\n ...args: Parameters<Keymaster[\"showMnemonicInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().showMnemonicInternal(...args);\n }\n\n public static async verifyResponse(\n ...args: Parameters<Keymaster[\"verifyResponseInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().verifyResponseInternal(...args);\n }\n\n public static async decryptMessage(\n ...args: Parameters<Keymaster[\"decryptMessageInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().decryptMessageInternal(...args);\n }\n\n public static async decryptMnemonic(\n ...args: Parameters<Keymaster[\"decryptMnemonicInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().decryptMnemonicInternal(...args);\n }\n\n public static async getCredential(\n ...args: Parameters<Keymaster[\"getCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().getCredentialInternal(...args);\n }\n\n public static async removeCredential(\n ...args: Parameters<Keymaster[\"removeCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().removeCredentialInternal(...args);\n }\n\n public static async updateCredential(\n ...args: Parameters<Keymaster[\"updateCredentialInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().updateCredentialInternal(...args);\n }\n\n public static async createId(\n ...args: Parameters<Keymaster[\"createIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createIdInternal(...args);\n }\n\n public static async removeId(\n ...args: Parameters<Keymaster[\"removeIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().removeIdInternal(...args);\n }\n\n public static async resolveDID(\n ...args: Parameters<Keymaster[\"resolveDIDInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().resolveDIDInternal(...args);\n }\n\n public static async setCurrentId(\n ...args: Parameters<Keymaster[\"setCurrentIdInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().setCurrentIdInternal(...args);\n }\n\n public static async createSchema(\n ...args: Parameters<Keymaster[\"createSchemaInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().createSchemaInternal(...args);\n }\n\n public static async newWallet(\n ...args: Parameters<Keymaster[\"newWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().newWalletInternal(...args);\n }\n\n public static async recoverWallet(\n ...args: Parameters<Keymaster[\"recoverWalletInternal\"]>\n ) {\n Keymaster.getInstance().ensureInitialized();\n return Keymaster.getInstance().recoverWalletInternal(...args);\n }\n\n private static getInstance(): Keymaster {\n if (!Keymaster.instance) {\n throw new Error(\n \"Keymaster not initialized. Call Keymaster.initialize() first.\"\n );\n }\n return Keymaster.instance;\n }\n\n // -------- Internal instance methods (originals renamed with Internal) -------\n\n private async ensureServiceIsRunning() {\n if (!(await this.serviceRunning())) {\n throw new Error(\"Keymaster service not running\");\n }\n }\n\n private async startInternal(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else {\n throw \"Missing Gatekeeper 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 if (this.config.walletDb) {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\n });\n\n await this.ensureWalletExists();\n } else {\n return false;\n }\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 createChallengeInternal(\n spec: CreateChallengeSpec,\n options?: CreateAssetOptions\n ): Promise<CreateChallengeResponse> {\n await this.ensureServiceIsRunning();\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 private async bindCredentialInternal(\n schemaId: string,\n subjectId: string,\n options: {\n validFrom?: string;\n validUntil?: string;\n credential?: Record<string, unknown>;\n } = {}\n ): Promise<VerifiableCredential> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n\n private async createResponseInternal(\n challengeDID: string,\n options?: CreateResponseOptions\n ): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createResponse(challengeDID, options);\n }\n\n private async backupWalletInternal(registry?: string): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.backupWallet(registry);\n }\n\n private async issueCredentialInternal(\n credential: Partial<VerifiableCredential>,\n options: IssueCredentialsOptions = {}\n ): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.issueCredential(credential, options);\n }\n\n private async publishCredentialInternal(\n did: string,\n options: { reveal?: boolean } = {}\n ): Promise<VerifiableCredential> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.publishCredential(did, options);\n }\n\n private async acceptCredentialInternal(did: string): Promise<boolean> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.acceptCredential(did);\n }\n\n private async showMnemonicInternal(): Promise<string> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic();\n }\n\n private async verifyResponseInternal(\n did: string,\n options?: { retries?: number; delay?: number }\n ): Promise<ChallengeResponse> {\n await this.ensureServiceIsRunning();\n return this.keymasterService.verifyResponse(did, options);\n }\n\n private async decryptMessageInternal(\n ...args: Parameters<KeymasterLib[\"decryptMessage\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMessage(...args);\n }\n\n private async decryptMnemonicInternal(\n ...args: Parameters<KeymasterLib[\"decryptMnemonic\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.decryptMnemonic(...args);\n }\n\n private async getCredentialInternal(\n ...args: Parameters<KeymasterLib[\"getCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.getCredential(...args);\n }\n\n private async removeCredentialInternal(\n ...args: Parameters<KeymasterLib[\"removeCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeCredential(...args);\n }\n\n private async updateCredentialInternal(\n ...args: Parameters<KeymasterLib[\"updateCredential\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.updateCredential(...args);\n }\n\n private async createIdInternal(\n ...args: Parameters<KeymasterLib[\"createId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createId(...args);\n }\n\n private async removeIdInternal(\n ...args: Parameters<KeymasterLib[\"removeId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.removeId(...args);\n }\n\n private async resolveDIDInternal(\n ...args: Parameters<KeymasterLib[\"resolveDID\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.resolveDID(...args);\n }\n\n private async setCurrentIdInternal(\n ...args: Parameters<KeymasterLib[\"setCurrentId\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.setCurrentId(...args);\n }\n\n private async createSchemaInternal(\n ...args: Parameters<KeymasterLib[\"createSchema\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.createSchema(...args);\n }\n\n private async newWalletInternal(\n ...args: Parameters<KeymasterLib[\"newWallet\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.newWallet(...args);\n }\n\n private async recoverWalletInternal(\n ...args: Parameters<KeymasterLib[\"recoverWallet\"]>\n ) {\n await this.ensureServiceIsRunning();\n return this.keymasterService.recoverWallet(...args);\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: StoredWallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\n if (existing && \"current\" in existing) {\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 if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n\n if (walletConfig?.id) {\n const did = await this.keymasterService.createId(walletConfig.id, {\n registry: walletConfig.registry,\n });\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig.id}`);\n }\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.startInternal());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (!config.gatekeeperConfig) {\n throw new Error(\"Missing Gatekeeper 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","import KeymasterClient from \"@mdip/keymaster/client\";\nimport {\n ChallengeResponse,\n CreateAssetOptions,\n IssueCredentialsOptions,\n VerifiableCredential,\n} from \"@mdip/keymaster/types\";\nimport {\n CreateChallengeResponse,\n CreateChallengeSpec,\n SdkConfig,\n} from \"./types/index.js\";\n\nexport interface KeymasterConfig {\n keymasterConfig?: SdkConfig;\n}\n\nexport class KeymasterExternalClient {\n private config: KeymasterConfig;\n private keymasterService!: KeymasterClient;\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.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n public async startExternal(): Promise<boolean> {\n 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 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?: CreateAssetOptions\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 bindCredential(\n schemaId: string,\n subjectId: string,\n options: {\n validFrom?: string;\n validUntil?: string;\n credential?: Record<string, unknown>;\n } = {}\n ): Promise<VerifiableCredential> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.bindCredential(schemaId, subjectId, options);\n }\n\n async issueCredential(\n credential: Partial<VerifiableCredential>,\n options: IssueCredentialsOptions = {}\n ): Promise<string> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.issueCredential(credential, options);\n }\n\n async publishCredential(\n did: string,\n options: { reveal?: boolean } = {}\n ): Promise<boolean> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.publishCredential(did, options);\n }\n\n async acceptCredential(did: string): Promise<boolean> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n\n return this.keymasterService.acceptCredential(did);\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?: {\n retries?: number;\n delay?: number;\n }\n ): Promise<ChallengeResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response: ChallengeResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\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.keymasterConfig) {\n throw new Error(\"Missing Keymaster config\");\n }\n }\n}\n","export { Keymaster, KeymasterConfig } from \"./keymaster.js\";\n\nexport { KeymasterExternalClient } from \"./keymasterClient.js\";\n\nexport {\n SdkConfig,\n WalletConfig,\n CreateChallengeResponse,\n CreateChallengeSpec,\n} from \"./types/index.js\";\n\nexport * from \"@mdip/keymaster/types\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yourself_id/siwys-api-js",
3
- "version": "0.10.1-SAPP-221-mdipUpdate.3+17b17f5",
3
+ "version": "0.10.1-SAPP-221-mdipUpdate.4+bf53fe3",
4
4
  "description": "A React component library",
5
5
  "repository": "https://github.com/selfidhq/siwys-js",
6
6
  "type": "module",
@@ -41,5 +41,5 @@
41
41
  "tsup": "^8.3.0",
42
42
  "typescript": "4.9.4"
43
43
  },
44
- "gitHead": "17b17f5055f750a06eee180ddd9e07d28b7fa88f"
44
+ "gitHead": "bf53fe305833b0f63f8160f795b868ad1ff965bd"
45
45
  }