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B,EAAU,OAAO,OAAO,CAAC,EAAG,CAAE,KA3Hd,WA2HmC,GAEnD,OADmB,IAAI,WAAW,GAChB,eAAe,EACnC,CAEA,kBAAO,CAAa,GAClB,OAAO,OAAO,KAAK,gBAAgB,SAAS,EAC9C,CAEA,0BAAO,CAAqB,GAC1B,IAAK,EACH,MAAM,IAAI,MAAM,yDAGlB,IAAK,EAAiB,MACa,iBAA1B,EAAiB,KACxB,MAAM,IAAI,MAAM,iGAGlB,eAAe,EAAiB,MAAQ,CAC1C,CAEA,6BAAO,CAAwB,UACtB,eAAe,EACxB,iBAGa","file":"/npm/orbit-db-identity-provider@0.5.0/src/identities.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/orbit-db-identity-provider@0.5.0/src/identities.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import Identity from './identity.js'\nimport IdentityProvider from './identity-providers/interface.js'\nimport OrbitDBIdentityProvider from './identity-providers/orbitdb.js'\nimport DIDIdentityProvider from './identity-providers/did.js'\nimport EthIdentityProvider from './identity-providers/ethereum.js'\nimport Keystore from 'orbit-db-keystore'\nimport LRU from 'lru'\nimport path from 'path'\n\nconst defaultType = 'orbitdb'\nconst identityKeysPath = path.join('./orbitdb', 'identity', 'identitykeys')\n\nconst supportedTypes = {\n  orbitdb: OrbitDBIdentityProvider,\n  [DIDIdentityProvider.type]: DIDIdentityProvider,\n  [EthIdentityProvider.type]: EthIdentityProvider\n}\n\nconst getHandlerFor = (type) => {\n  if (!Identities.isSupported(type)) {\n    throw new Error(`IdentityProvider type '${type}' is not supported`)\n  }\n  return supportedTypes[type]\n}\n\nclass Identities {\n  constructor (options) {\n    this._keystore = options.keystore\n    this._signingKeystore = options.signingKeystore || this._keystore\n    this._knownIdentities = options.cache || new LRU(options.cacheSize || 100)\n  }\n\n  static get IdentityProvider () { return IdentityProvider }\n\n  get keystore () { return this._keystore }\n\n  get signingKeystore () { return this._signingKeystore }\n\n  async sign (identity, data) {\n    const signingKey = await this.keystore.getKey(identity.id)\n    if (!signingKey) {\n      throw new Error('Private signing key not found from Keystore')\n    }\n    const sig = await this.keystore.sign(signingKey, data)\n    return sig\n  }\n\n  async verify (signature, publicKey, data, verifier = 'v1') {\n    return this.keystore.verify(signature, publicKey, data, verifier)\n  }\n\n  async createIdentity (options = {}) {\n    const keystore = options.keystore || this.keystore\n    const type = options.type || defaultType\n    const identityProvider = type === defaultType ? new OrbitDBIdentityProvider(options.signingKeystore || keystore) : new (getHandlerFor(type))(options)\n    const id = await identityProvider.getId(options)\n\n    if (options.migrate) {\n      await options.migrate({ targetStore: keystore._store, targetId: id })\n    }\n    const { publicKey, idSignature } = await this.signId(id)\n    const pubKeyIdSignature = await identityProvider.signIdentity(publicKey + idSignature, options)\n    return new Identity(id, publicKey, idSignature, pubKeyIdSignature, type, this)\n  }\n\n  async signId (id) {\n    const keystore = this.keystore\n    const key = await keystore.getKey(id) || await keystore.createKey(id)\n    const publicKey = keystore.getPublic(key)\n    const idSignature = await keystore.sign(key, id)\n    return { publicKey, idSignature }\n  }\n\n  async verifyIdentity (identity) {\n    if (!Identity.isIdentity(identity)) {\n      return false\n    }\n\n    const knownID = this._knownIdentities.get(identity.signatures.id)\n    if (knownID) {\n      return identity.id === knownID.id &&\n             identity.publicKey === knownID.publicKey &&\n             identity.signatures.id === knownID.signatures.id &&\n             identity.signatures.publicKey === knownID.signatures.publicKey\n    }\n\n    const verifyIdSig = await this.keystore.verify(\n      identity.signatures.id,\n      identity.publicKey,\n      identity.id\n    )\n    if (!verifyIdSig) return false\n\n    const IdentityProvider = getHandlerFor(identity.type)\n    const verified = await IdentityProvider.verifyIdentity(identity)\n    if (verified) {\n      this._knownIdentities.set(identity.signatures.id, Identity.toJSON(identity))\n    }\n\n    return verified\n  }\n\n  static async verifyIdentity (identity) {\n    if (!Identity.isIdentity(identity)) {\n      return false\n    }\n\n    const verifyIdSig = await Keystore.verify(\n      identity.signatures.id,\n      identity.publicKey,\n      identity.id\n    )\n\n    if (!verifyIdSig) return false\n\n    const IdentityProvider = getHandlerFor(identity.type)\n    return IdentityProvider.verifyIdentity(identity)\n  }\n\n  static async createIdentity (options = {}) {\n    if (!options.keystore) {\n      options.keystore = new Keystore(options.identityKeysPath || identityKeysPath)\n    }\n    if (!options.signingKeystore) {\n      if (options.signingKeysPath) {\n        options.signingKeystore = new Keystore(options.signingKeysPath)\n      } else {\n        options.signingKeystore = options.keystore\n      }\n    }\n    await options.keystore.open()\n    await options.signingKeystore.open()\n    options = Object.assign({}, { type: defaultType }, options)\n    const identities = new Identities(options)\n    return identities.createIdentity(options)\n  }\n\n  static isSupported (type) {\n    return Object.keys(supportedTypes).includes(type)\n  }\n\n  static addIdentityProvider (IdentityProvider) {\n    if (!IdentityProvider) {\n      throw new Error('IdentityProvider class needs to be given as an option')\n    }\n\n    if (!IdentityProvider.type ||\n      typeof IdentityProvider.type !== 'string') {\n      throw new Error('Given IdentityProvider class needs to implement: static get type() { /* return a string */ }.')\n    }\n\n    supportedTypes[IdentityProvider.type] = IdentityProvider\n  }\n\n  static removeIdentityProvider (type) {\n    delete supportedTypes[type]\n  }\n}\n\nexport default Identities\n"]}