@yourself_id/siwys-api-js 0.4.0 → 0.4.1-SAPP-127-netki-molecule-5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.cjs","../src/index.ts","../src/keymaster.ts"],"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","src_exports","Keymaster","module","exports","import_client","require","import_node","import_keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper","cipher","e","console","log","GatekeeperClient","connect","CipherNode","KeymasterLib","wallet","walletDb","keymasterService","ensureWalletExists","error","import_client2","KeymasterClient","createChallenge","spec","options","challenge","serviceRunning","Error","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","createId","registry","saveWallet"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAIA,WAAWC,OAAOC,MAAM;AAC5B,IAAIC,YAAYF,OAAOG,cAAc;AACrC,IAAIC,mBAAmBJ,OAAOK,wBAAwB;AACtD,IAAIC,oBAA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,CAACA,OAAOsC,YAAA,EAAc;wBACxB,MAAM,IAAIT,MAAM;oBAClB;oBACA,IAAI,GAAC7B,mBAAAA,OAAOkB,QAAA,cAAPlB,uCAAAA,iBAAiBuC,UAAA,GAAY;wBAChC,MAAM,IAAIV,MAAM;oBAClB;oBACA,IAAI,GAAC7B,oBAAAA,OAAOkB,QAAA,cAAPlB,wCAAAA,kBAAiB8C,UAAA,GAAY;wBAChC,MAAM,IAAIjB,MAAM;oBAClB;gBACF;YACF;;;;;AF5EF,6DAA6D;AAC7D,KAAMnC,CAAAA,OAAOC,OAAO,GAAG;IACrBF,WAAAA;AACF,CAAA","sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/index.ts\nvar src_exports = {};\n__export(src_exports, {\n Keymaster: () => Keymaster\n});\nmodule.exports = __toCommonJS(src_exports);\n\n// src/keymaster.ts\nvar import_client = __toESM(require(\"@mdip/gatekeeper/client\"), 1);\nvar import_node = __toESM(require(\"@mdip/cipher/node\"), 1);\nvar import_client2 = __toESM(require(\"@mdip/keymaster/client\"), 1);\nvar import_keymaster = __toESM(require(\"@mdip/keymaster\"), 1);\nvar Keymaster = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n const gatekeeper = new import_client.default();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new import_node.default();\n this.keymasterService = await new import_keymaster.default({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\n });\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n async startExternalKeymaster() {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = new import_client2.default();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n console.log(`Started external Keymaster service`);\n return true;\n }\n async createChallenge(spec, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`\n };\n }\n async showMnemonic() {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response = await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n const walletConfig = this.config.walletConfig;\n console.log(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig?.id}`);\n }\n async serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n};\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n Keymaster\n});\n","export {\n CreateChallengeOptions,\n CreateChallengeResponse,\n CreateChallengeSpec,\n Keymaster,\n KeymasterConfig,\n SdkConfig,\n VerifyResponseOptions,\n VerifyResponseResponse,\n Wallet,\n WalletConfig,\n WalletDb,\n WalletSeed,\n} from \"./keymaster\";\n","// @ts-ignore\n// @ts-nocheck\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: { schema: string; issuers: string[] }[];\n}\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n}\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\n}\n// config for connecting to an external Gatekeeper or Keymaster\nexport interface SdkConfig {\n url: string;\n waitUntilReady?: boolean;\n intervalSeconds?: number;\n chatty?: boolean;\n}\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\n}\nexport interface WalletDb {\n loadWallet: () => Promise<Wallet | null>;\n saveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;\n}\n\nexport interface KeymasterConfig {\n /**\n * Config for connecting to an external Keymaster service\n * when the consuming applciation is connecting to an external Keymaster.\n */\n keymasterConfig?: SdkConfig;\n /**\n * Config for connecting to an external Keymaster service when\n * the consuming applciation is acting as its own (integrated) Keymaster service.\n */\n gatekeeperConfig?: SdkConfig;\n /**\n * Config for custom user-defined values of the underlying wallet.\n *\n * Required for an integrated Keymaster.\n */\n walletConfig?: WalletConfig;\n /**\n * Config that contains the callbacks for persisting a\n * wallet to a backing Database.\n */\n walletDb?: WalletDb;\n}\n\nexport class Keymaster {\n private config: KeymasterConfig;\n /**\n * Underlying Keymaster libray based on the use-case:\n *\n * Integrated Keymaster = keymaster_lib\n *\n * External Keymaster = keymaster_sdk\n */\n private keymasterService;\n private serviceStarted = false;\n\n constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public async start(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n private async startIntegratedKeymaster(): Promise<boolean> {\n console.log(`Starting integrated Keymaster service`);\n\n try {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\n });\n\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n\n private async startExternalKeymaster(): Promise<boolean> {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n\n console.log(`Started external Keymaster service`);\n return true;\n }\n\n async createChallenge(\n spec: CreateChallengeSpec,\n options?: CreateChallengeOptions\n ): Promise<CreateChallengeResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge: string = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge: challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`,\n };\n }\n\n async showMnemonic(): Promise<string> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n\n async verifyResponse(\n did: string,\n options?: VerifyResponseOptions\n ): Promise<VerifyResponseResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response: VerifyResponseResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: Wallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n\n const walletConfig = this.config.walletConfig;\n console.log(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n // wallet was just created, recreate based on config\n if (walletConfig?.mnemonic) {\n // create the wallet with a custom mnemonic first\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n // create ID and set as current, createId() will save wallet\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig?.id}`);\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.start());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.cjs","../src/index.ts","../src/keymaster.ts"],"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","src_exports","Keymaster","module","exports","import_client","require","import_node","import_keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper","cipher","e","console","log","GatekeeperClient","connect","CipherNode","KeymasterLib","wallet","walletDb","keymasterService","ensureWalletExists","error","import_client2","KeymasterClient","createChallenge","spec","options","challenge","serviceRunning","Error","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","createId","registry","saveWallet"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B;;;;;;gBACF;;;;YAEQD,KAAAA;mBAAAA,SAAAA,eAAeF,MAAA;gBACrB,IAAIA,OAAOI,gBAAA,IAAoBJ,OAAOM,eAAA,EAAiB;oBACrD,MAAM,IAAIuB,MAAM;gBAClB;gBAEA,IAAI7B,OAAOI,gBAAA,EAAkB;wBAItBJ,kBAGAA;oBANL,IAAI,CAACA,OAAOsC,YAAA,EAAc;wBACxB,MAAM,IAAIT,MAAM;oBAClB;oBACA,IAAI,GAAC7B,mBAAAA,OAAOkB,QAAA,cAAPlB,uCAAAA,iBAAiBuC,UAAA,GAAY;wBAChC,MAAM,IAAIV,MAAM;oBAClB;oBACA,IAAI,GAAC7B,oBAAAA,OAAOkB,QAAA,cAAPlB,wCAAAA,kBAAiB8C,UAAA,GAAY;wBAChC,MAAM,IAAIjB,MAAM;oBAClB;gBACF;YACF;;;;;AFjFF,6DAA6D;AAC7D,KAAMnC,CAAAA,OAAOC,OAAO,GAAG;IACrBF,WAAAA;AACF,CAAA","sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/index.ts\nvar src_exports = {};\n__export(src_exports, {\n Keymaster: () => Keymaster\n});\nmodule.exports = __toCommonJS(src_exports);\n\n// src/keymaster.ts\nvar import_client = __toESM(require(\"@mdip/gatekeeper/client\"), 1);\nvar import_node = __toESM(require(\"@mdip/cipher/node\"), 1);\nvar import_client2 = __toESM(require(\"@mdip/keymaster/client\"), 1);\nvar import_keymaster = __toESM(require(\"@mdip/keymaster\"), 1);\nvar Keymaster = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n const gatekeeper = new import_client.default();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new import_node.default();\n this.keymasterService = await new import_keymaster.default({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\n });\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n async startExternalKeymaster() {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = new import_client2.default();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n console.log(`Started external Keymaster service`);\n return true;\n }\n async createChallenge(spec, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`\n };\n }\n async showMnemonic() {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response = await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n const walletConfig = this.config.walletConfig;\n console.log(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig?.id}`);\n }\n async serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n};\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n Keymaster\n});\n","export {\n CreateChallengeOptions,\n CreateChallengeResponse,\n CreateChallengeSpec,\n Keymaster,\n KeymasterConfig,\n SdkConfig,\n VerifyResponseOptions,\n VerifyResponseResponse,\n Wallet,\n WalletConfig,\n WalletDb,\n WalletSeed,\n} from \"./keymaster\";\n","// @ts-ignore\n// @ts-nocheck\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: { schema: string; issuers: string[] }[];\n}\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\n\nexport interface Credential {\n vp: string;\n}\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n credentials?: Credential[];\n}\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\n}\n// config for connecting to an external Gatekeeper or Keymaster\nexport interface SdkConfig {\n url: string;\n waitUntilReady?: boolean;\n intervalSeconds?: number;\n chatty?: boolean;\n}\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\n}\nexport interface WalletDb {\n loadWallet: () => Promise<Wallet | null>;\n saveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;\n}\n\nexport interface KeymasterConfig {\n /**\n * Config for connecting to an external Keymaster service\n * when the consuming applciation is connecting to an external Keymaster.\n */\n keymasterConfig?: SdkConfig;\n /**\n * Config for connecting to an external Keymaster service when\n * the consuming applciation is acting as its own (integrated) Keymaster service.\n */\n gatekeeperConfig?: SdkConfig;\n /**\n * Config for custom user-defined values of the underlying wallet.\n *\n * Required for an integrated Keymaster.\n */\n walletConfig?: WalletConfig;\n /**\n * Config that contains the callbacks for persisting a\n * wallet to a backing Database.\n */\n walletDb?: WalletDb;\n}\n\nexport class Keymaster {\n private config: KeymasterConfig;\n /**\n * Underlying Keymaster libray based on the use-case:\n *\n * Integrated Keymaster = keymaster_lib\n *\n * External Keymaster = keymaster_sdk\n */\n private keymasterService;\n private serviceStarted = false;\n\n constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public async start(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n private async startIntegratedKeymaster(): Promise<boolean> {\n console.log(`Starting integrated Keymaster service`);\n\n try {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\n });\n\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n\n private async startExternalKeymaster(): Promise<boolean> {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n\n console.log(`Started external Keymaster service`);\n return true;\n }\n\n async createChallenge(\n spec: CreateChallengeSpec,\n options?: CreateChallengeOptions\n ): Promise<CreateChallengeResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge: string = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge: challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`,\n };\n }\n\n async showMnemonic(): Promise<string> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n\n async verifyResponse(\n did: string,\n options?: VerifyResponseOptions\n ): Promise<VerifyResponseResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response: VerifyResponseResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: Wallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n\n const walletConfig = this.config.walletConfig;\n console.log(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n // wallet was just created, recreate based on config\n if (walletConfig?.mnemonic) {\n // create the wallet with a custom mnemonic first\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n // create ID and set as current, createId() will save wallet\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig?.id}`);\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.start());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -17,10 +17,14 @@ interface VerifyResponseOptions {
|
|
|
17
17
|
retries?: number;
|
|
18
18
|
delay?: number;
|
|
19
19
|
}
|
|
20
|
+
interface Credential {
|
|
21
|
+
vp: string;
|
|
22
|
+
}
|
|
20
23
|
interface VerifyResponseResponse {
|
|
21
24
|
match: boolean;
|
|
22
25
|
challenge: string;
|
|
23
26
|
responder: string;
|
|
27
|
+
credentials?: Credential[];
|
|
24
28
|
}
|
|
25
29
|
interface WalletSeed {
|
|
26
30
|
mnemonic: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,10 +17,14 @@ interface VerifyResponseOptions {
|
|
|
17
17
|
retries?: number;
|
|
18
18
|
delay?: number;
|
|
19
19
|
}
|
|
20
|
+
interface Credential {
|
|
21
|
+
vp: string;
|
|
22
|
+
}
|
|
20
23
|
interface VerifyResponseResponse {
|
|
21
24
|
match: boolean;
|
|
22
25
|
challenge: string;
|
|
23
26
|
responder: string;
|
|
27
|
+
credentials?: Credential[];
|
|
24
28
|
}
|
|
25
29
|
interface WalletSeed {
|
|
26
30
|
mnemonic: string;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.js","../src/keymaster.ts"],"names":["GatekeeperClient","CipherNode","KeymasterClient","default","KeymasterLib","Keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper","cipher","e","console","log","connect","wallet","walletDb","keymasterService","ensureWalletExists","error","createChallenge","spec","options","challenge","serviceRunning","Error","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","createId","registry","saveWallet"],"mappings":"AAAA,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACEnB,OAAOA,sBAAsB,0BAAA;AAC7B,OAAOC,gBAAgB,oBAAA;AACvB,OAAOC,qBAAqB,yBAAA;AAC5B,SAASC,WAAWC,YAAA,QAAoB,kBAAA;AA4EjC,IAAMC,0BAAN;;aAAMA,UAYCC,MAAA;gCAZDD;QAUX,IAAA,CAAQE,cAAA,GAAiB;QAGvB,IAAA,CAAKC,cAAA,CAAeF;QACpB,IAAA,CAAKA,MAAA,GAASA;;;;YAGHG,KAAAA;mBAAb,SAAaA;;uBAAb,oBAAA;;;;qCACM,MAAKH,MAAA,CAAOI,gBAAA,EAAZ;;;;gC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,SAAA,CAAUL,aAAaI,QAAA,EAAU;;;gCAA7D;;;gCAGU;;oCAAM,MAAKrB,gBAAA,CAAiBuB,QAAA,CACtCN,yBAAAA,mCAAAA,aAAcG,EAAA,EACdH,yBAAAA,mCAAAA,aAAcO,QAAA;;;gCAFVV,MAAM;gCAIZnB,QAAQC,GAAA,CAAI,QAAQkB;gCACpBnB,QAAQC,GAAA,CAAI,0BAA0C,OAAhBqB,yBAAAA,mCAAAA,aAAcG,EAAE;;;;;;gBACxD;;;;YAEcb,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKtB,cAAA;0CAAL;;;;gCAAwB;;oCAAM,MAAKE,KAAA;;;uCAAX;;;gCAA/B;;;;;;gBACF;;;;YAEQD,KAAAA;mBAAAA,SAAAA,eAAeF,MAAA;gBACrB,IAAIA,OAAOI,gBAAA,IAAoBJ,OAAOM,eAAA,EAAiB;oBACrD,MAAM,IAAIkB,MAAM;gBAClB;gBAEA,IAAIxB,OAAOI,gBAAA,EAAkB;wBAItBJ,kBAGAA;oBANL,IAAI,CAACA,OAAOiC,YAAA,EAAc;wBACxB,MAAM,IAAIT,MAAM;oBAClB;oBACA,IAAI,GAACxB,mBAAAA,OAAOe,QAAA,cAAPf,uCAAAA,iBAAiBkC,UAAA,GAAY;wBAChC,MAAM,IAAIV,MAAM;oBAClB;oBACA,IAAI,GAACxB,oBAAAA,OAAOe,QAAA,cAAPf,wCAAAA,kBAAiByC,UAAA,GAAY;wBAChC,MAAM,IAAIjB,MAAM;oBAClB;gBACF;YACF;;;;;ADhHF,SACEzB,SAAS,GACT","sourcesContent":["// src/keymaster.ts\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\nvar Keymaster = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new CipherNode();\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\n });\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n async startExternalKeymaster() {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n console.log(`Started external Keymaster service`);\n return true;\n }\n async createChallenge(spec, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`\n };\n }\n async showMnemonic() {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response = await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n const walletConfig = this.config.walletConfig;\n console.log(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig?.id}`);\n }\n async serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n};\nexport {\n Keymaster\n};\n","// @ts-ignore\n// @ts-nocheck\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: { schema: string; issuers: string[] }[];\n}\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n}\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\n}\n// config for connecting to an external Gatekeeper or Keymaster\nexport interface SdkConfig {\n url: string;\n waitUntilReady?: boolean;\n intervalSeconds?: number;\n chatty?: boolean;\n}\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\n}\nexport interface WalletDb {\n loadWallet: () => Promise<Wallet | null>;\n saveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;\n}\n\nexport interface KeymasterConfig {\n /**\n * Config for connecting to an external Keymaster service\n * when the consuming applciation is connecting to an external Keymaster.\n */\n keymasterConfig?: SdkConfig;\n /**\n * Config for connecting to an external Keymaster service when\n * the consuming applciation is acting as its own (integrated) Keymaster service.\n */\n gatekeeperConfig?: SdkConfig;\n /**\n * Config for custom user-defined values of the underlying wallet.\n *\n * Required for an integrated Keymaster.\n */\n walletConfig?: WalletConfig;\n /**\n * Config that contains the callbacks for persisting a\n * wallet to a backing Database.\n */\n walletDb?: WalletDb;\n}\n\nexport class Keymaster {\n private config: KeymasterConfig;\n /**\n * Underlying Keymaster libray based on the use-case:\n *\n * Integrated Keymaster = keymaster_lib\n *\n * External Keymaster = keymaster_sdk\n */\n private keymasterService;\n private serviceStarted = false;\n\n constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public async start(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n private async startIntegratedKeymaster(): Promise<boolean> {\n console.log(`Starting integrated Keymaster service`);\n\n try {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\n });\n\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n\n private async startExternalKeymaster(): Promise<boolean> {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n\n console.log(`Started external Keymaster service`);\n return true;\n }\n\n async createChallenge(\n spec: CreateChallengeSpec,\n options?: CreateChallengeOptions\n ): Promise<CreateChallengeResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge: string = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge: challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`,\n };\n }\n\n async showMnemonic(): Promise<string> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n\n async verifyResponse(\n did: string,\n options?: VerifyResponseOptions\n ): Promise<VerifyResponseResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response: VerifyResponseResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: Wallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n\n const walletConfig = this.config.walletConfig;\n console.log(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n // wallet was just created, recreate based on config\n if (walletConfig?.mnemonic) {\n // create the wallet with a custom mnemonic first\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n // create ID and set as current, createId() will save wallet\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig?.id}`);\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.start());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/siwys-js/siwys-js/packages/api-js/dist/index.js","../src/keymaster.ts"],"names":["GatekeeperClient","CipherNode","KeymasterClient","default","KeymasterLib","Keymaster","config","serviceStarted","validateConfig","start","gatekeeperConfig","startIntegratedKeymaster","keymasterConfig","startExternalKeymaster","gatekeeper","cipher","e","console","log","connect","wallet","walletDb","keymasterService","ensureWalletExists","error","createChallenge","spec","options","challenge","serviceRunning","Error","challengeUrl","callback","showMnemonic","decryptMnemonic","verifyResponse","did","response","existing","walletConfig","loadWallet","current","id","mnemonic","newWallet","createId","registry","saveWallet"],"mappings":"AAAA,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACEnB,OAAOA,sBAAsB,0BAAA;AAC7B,OAAOC,gBAAgB,oBAAA;AACvB,OAAOC,qBAAqB,yBAAA;AAC5B,SAASC,WAAWC,YAAA,QAAoB,kBAAA;AAiFjC,IAAMC,0BAAN;;aAAMA,UAYCC,MAAA;gCAZDD;QAUX,IAAA,CAAQE,cAAA,GAAiB;QAGvB,IAAA,CAAKC,cAAA,CAAeF;QACpB,IAAA,CAAKA,MAAA,GAASA;;;;YAGHG,KAAAA;mBAAb,SAAaA;;uBAAb,oBAAA;;;;qCACM,MAAKH,MAAA,CAAOI,gBAAA,EAAZ;;;;gCACoB;;oCAAM,MAAKC,wBAAA;;;gCAAjC,MAAKJ,cAAA,GAAiB;;;;;;qCACb,MAAKD,MAAA,CAAOM,eAAA,EAAZ;;;;gCACa;;oCAAM,MAAKC,sBAAA;;;gCAAjC,MAAKN,cAAA,GAAiB;;;;;;gCAEtB,MAAM;;gCAER;;oCAAO,MAAKA,cAAA;;;;gBACd;;;;YAEcI,KAAAA;mBAAd,SAAcA;;uBA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B,yBAAAA,mCAAAA,aAAcG,EAAE;;;;;;gBACxD;;;;YAEcb,KAAAA;mBAAd,SAAcA;;uBAAd,oBAAA;;;;;uCACS,MAAKtB,cAAA;0CAAL;;;;gCAAwB;;oCAAM,MAAKE,KAAA;;;uCAAX;;;gCAA/B;;;;;;gBACF;;;;YAEQD,KAAAA;mBAAAA,SAAAA,eAAeF,MAAA;gBACrB,IAAIA,OAAOI,gBAAA,IAAoBJ,OAAOM,eAAA,EAAiB;oBACrD,MAAM,IAAIkB,MAAM;gBAClB;gBAEA,IAAIxB,OAAOI,gBAAA,EAAkB;wBAItBJ,kBAGAA;oBANL,IAAI,CAACA,OAAOiC,YAAA,EAAc;wBACxB,MAAM,IAAIT,MAAM;oBAClB;oBACA,IAAI,GAACxB,mBAAAA,OAAOe,QAAA,cAAPf,uCAAAA,iBAAiBkC,UAAA,GAAY;wBAChC,MAAM,IAAIV,MAAM;oBAClB;oBACA,IAAI,GAACxB,oBAAAA,OAAOe,QAAA,cAAPf,wCAAAA,kBAAiByC,UAAA,GAAY;wBAChC,MAAM,IAAIjB,MAAM;oBAClB;gBACF;YACF;;;;;ADrHF,SACEzB,SAAS,GACT","sourcesContent":["// src/keymaster.ts\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\nvar Keymaster = class {\n constructor(config) {\n this.serviceStarted = false;\n this.validateConfig(config);\n this.config = config;\n }\n async start() {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n async startIntegratedKeymaster() {\n console.log(`Starting integrated Keymaster service`);\n try {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n const cipher = new CipherNode();\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher\n });\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n async startExternalKeymaster() {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n console.log(`Started external Keymaster service`);\n return true;\n }\n async createChallenge(spec, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`\n };\n }\n async showMnemonic() {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n async verifyResponse(did, options) {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response = await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n async ensureWalletExists() {\n console.log(\"Ensuring wallet exists\");\n const existing = await this.config?.walletDb?.loadWallet() || null;\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n const walletConfig = this.config.walletConfig;\n console.log(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n if (walletConfig?.mnemonic) {\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig?.id}`);\n }\n async serviceRunning() {\n return this.serviceStarted || await this.start();\n }\n validateConfig(config) {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n};\nexport {\n Keymaster\n};\n","// @ts-ignore\n// @ts-nocheck\nimport GatekeeperClient from \"@mdip/gatekeeper/client\";\nimport CipherNode from \"@mdip/cipher/node\";\nimport KeymasterClient from \"@mdip/keymaster/client\";\nimport { default as KeymasterLib } from \"@mdip/keymaster\";\nexport interface CreateChallengeSpec {\n callback: string;\n credentials?: { schema: string; issuers: string[] }[];\n}\nexport interface CreateChallengeOptions {\n registry?: string;\n validUntil?: string; // ISO string\n}\nexport interface CreateChallengeResponse {\n challenge: string; // DID\n challengeUrl: string;\n}\nexport interface VerifyResponseOptions {\n retries?: number;\n delay?: number;\n}\n\nexport interface Credential {\n vp: string;\n}\nexport interface VerifyResponseResponse {\n match: boolean;\n challenge: string;\n responder: string;\n credentials?: Credential[];\n}\nexport interface WalletSeed {\n mnemonic: string;\n hdkey: {\n xpriv: string;\n xpub: string;\n };\n}\nexport interface Wallet {\n seed: WalletSeed;\n counter: number;\n ids: any;\n current?: string;\n}\n// config for connecting to an external Gatekeeper or Keymaster\nexport interface SdkConfig {\n url: string;\n waitUntilReady?: boolean;\n intervalSeconds?: number;\n chatty?: boolean;\n}\nexport interface WalletConfig {\n id: string;\n mnemonic?: string;\n registry?: string;\n}\nexport interface WalletDb {\n loadWallet: () => Promise<Wallet | null>;\n saveWallet: (w: Wallet, overwrite?: boolean) => Promise<boolean>;\n}\n\nexport interface KeymasterConfig {\n /**\n * Config for connecting to an external Keymaster service\n * when the consuming applciation is connecting to an external Keymaster.\n */\n keymasterConfig?: SdkConfig;\n /**\n * Config for connecting to an external Keymaster service when\n * the consuming applciation is acting as its own (integrated) Keymaster service.\n */\n gatekeeperConfig?: SdkConfig;\n /**\n * Config for custom user-defined values of the underlying wallet.\n *\n * Required for an integrated Keymaster.\n */\n walletConfig?: WalletConfig;\n /**\n * Config that contains the callbacks for persisting a\n * wallet to a backing Database.\n */\n walletDb?: WalletDb;\n}\n\nexport class Keymaster {\n private config: KeymasterConfig;\n /**\n * Underlying Keymaster libray based on the use-case:\n *\n * Integrated Keymaster = keymaster_lib\n *\n * External Keymaster = keymaster_sdk\n */\n private keymasterService;\n private serviceStarted = false;\n\n constructor(config: KeymasterConfig) {\n this.validateConfig(config);\n this.config = config;\n }\n\n public async start(): Promise<boolean> {\n if (this.config.gatekeeperConfig) {\n this.serviceStarted = await this.startIntegratedKeymaster();\n } else if (this.config.keymasterConfig) {\n this.serviceStarted = await this.startExternalKeymaster();\n } else {\n throw \"Missing Gatekeeper or Keymaster config\";\n }\n return this.serviceStarted;\n }\n\n private async startIntegratedKeymaster(): Promise<boolean> {\n console.log(`Starting integrated Keymaster service`);\n\n try {\n const gatekeeper = new GatekeeperClient();\n await gatekeeper.connect(this.config.gatekeeperConfig);\n\n const cipher = new CipherNode();\n\n this.keymasterService = await new KeymasterLib({\n gatekeeper,\n wallet: this.config.walletDb,\n cipher,\n });\n\n await this.ensureWalletExists();\n } catch (e) {\n console.error(\"Error starting Keymaster service:\", e);\n return false;\n }\n\n console.log(`Started integrated Keymaster service`);\n return true;\n }\n\n private async startExternalKeymaster(): Promise<boolean> {\n console.log(`Starting external Keymaster service`);\n try {\n this.keymasterService = new KeymasterClient();\n await this.keymasterService.connect(this.config.keymasterConfig);\n } catch (e) {\n console.error(`Error starting Keymaster service:`, e);\n return false;\n }\n\n console.log(`Started external Keymaster service`);\n return true;\n }\n\n async createChallenge(\n spec: CreateChallengeSpec,\n options?: CreateChallengeOptions\n ): Promise<CreateChallengeResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const challenge: string = await this.keymasterService.createChallenge(\n spec,\n options\n );\n return {\n challenge: challenge,\n challengeUrl: `${spec.callback}?challenge=${challenge}`,\n };\n }\n\n async showMnemonic(): Promise<string> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n return this.keymasterService.decryptMnemonic();\n }\n\n async verifyResponse(\n did: string,\n options?: VerifyResponseOptions\n ): Promise<VerifyResponseResponse> {\n if (!this.serviceRunning()) {\n throw new Error(\"Keymaster service not running\");\n }\n const response: VerifyResponseResponse =\n await this.keymasterService.verifyResponse(did, options);\n return response;\n }\n\n private async ensureWalletExists(): Promise<void> {\n console.log(\"Ensuring wallet exists\");\n const existing: Wallet | null =\n (await this.config?.walletDb?.loadWallet()) || null;\n if (existing?.current) {\n console.log(`Using existing wallet with ID ${existing.current}`);\n return;\n }\n\n const walletConfig = this.config.walletConfig;\n console.log(\n `Creating Creating Creating wallet with ID ${walletConfig?.id}`\n );\n // wallet was just created, recreate based on config\n if (walletConfig?.mnemonic) {\n // create the wallet with a custom mnemonic first\n await this.keymasterService.newWallet(walletConfig.mnemonic, true);\n }\n // create ID and set as current, createId() will save wallet\n const did = await this.keymasterService.createId(\n walletConfig?.id,\n walletConfig?.registry\n );\n console.log(\"Did \", did);\n console.log(`Created wallet with ID ${walletConfig?.id}`);\n }\n\n private async serviceRunning(): Promise<boolean> {\n return this.serviceStarted || (await this.start());\n }\n\n private validateConfig(config: KeymasterConfig): void {\n if (config.gatekeeperConfig && config.keymasterConfig) {\n throw new Error(\"Cannot provide both a Gatekeeper and Keymaster config\");\n }\n\n if (config.gatekeeperConfig) {\n if (!config.walletConfig) {\n throw new Error(\"Missing wallet config\");\n }\n if (!config.walletDb?.loadWallet) {\n throw new Error(\"Missing load wallet callback\");\n }\n if (!config.walletDb?.saveWallet) {\n throw new Error(\"Missing save wallet callback\");\n }\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yourself_id/siwys-api-js",
|
|
3
|
-
"version": "0.4.0",
|
|
3
|
+
"version": "0.4.1-SAPP-127-netki-molecule-5.0+a0b22bc",
|
|
4
4
|
"description": "A React component library",
|
|
5
5
|
"repository": "https://github.com/selfidhq/siwys-js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"tsup": "^8.3.0",
|
|
36
36
|
"typescript": "4.9.4"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "a0b22bc6bbf4949ae0aeebca45dcabb3526e0e7f"
|
|
39
39
|
}
|