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CAAC,OAAO,YAAY,YAAY,CAAC,KAAK,EAAE,CAC5E,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,0BAA0B;QAC1B,MAAM,YAAY,GAChB,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3D,MAAM,IAAI,yBAAgB,CACxB,iDAAiD,IAAI,MAAM,YAAY,EAAE,CAC1E,CAAC;IACJ,CAAC;AACH,CAAC,qEAEe,GAAW,EAAE,UAAkB;IAC7C,OAAO,IAAA,6BAAgB,EAAC,GAAG,GAAG,UAAU,CAAC,CAAC;AAC5C,CAAC,wCAED,KAAK,8CACH,eAAwB;IAExB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAC3E,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport { NotFoundError, UserStorageError } from './errors';\nimport encryption, { createSHA256Hash } from '../shared/encryption';\nimport { SHARED_SALT } from '../shared/encryption/constants';\nimport type { Env } from '../shared/env';\nimport { getEnvUrls } from '../shared/env';\nimport type {\n  UserStorageGenericFeatureKey,\n  UserStorageGenericFeatureName,\n  UserStorageGenericPathWithFeatureAndKey,\n  UserStorageGenericPathWithFeatureOnly,\n} from '../shared/storage-schema';\nimport { createEntryPath } from '../shared/storage-schema';\nimport type { NativeScrypt } from '../shared/types/encryption';\n\nexport const STORAGE_URL = (env: Env, encryptedPath: string) =>\n  `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;\n\nexport type UserStorageConfig = {\n  env: Env;\n  auth: Pick<IBaseAuth, 'getAccessToken' | 'getUserProfile' | 'signMessage'>;\n};\n\nexport type StorageOptions = {\n  getStorageKey: (message: `metamask:${string}`) => Promise<string | null>;\n  setStorageKey: (message: `metamask:${string}`, val: string) => Promise<void>;\n};\n\nexport type UserStorageOptions = {\n  storage?: StorageOptions;\n};\n\nexport type GetUserStorageAllFeatureEntriesResponse = {\n  HashedKey: string;\n\n  Data: string;\n}[];\n\nexport type UserStorageMethodOptions = {\n  nativeScryptCrypto?: NativeScrypt;\n  entropySourceId?: string;\n};\n\ntype ErrorMessage = {\n  message: string;\n  error: string;\n};\n\nexport class UserStorage {\n  protected config: UserStorageConfig;\n\n  public options: UserStorageOptions;\n\n  protected env: Env;\n\n  constructor(config: UserStorageConfig, options: UserStorageOptions) {\n    this.env = config.env;\n    this.config = config;\n    this.options = options;\n  }\n\n  async setItem(\n    path: UserStorageGenericPathWithFeatureAndKey,\n    value: string,\n    options?: UserStorageMethodOptions,\n  ): Promise<void> {\n    await this.#upsertUserStorage(path, value, options);\n  }\n\n  async batchSetItems(\n    path: UserStorageGenericFeatureName,\n    values: [UserStorageGenericFeatureKey, string][],\n    options?: UserStorageMethodOptions,\n  ) {\n    await this.#batchUpsertUserStorage(path, values, options);\n  }\n\n  async getItem(\n    path: UserStorageGenericPathWithFeatureAndKey,\n    options?: UserStorageMethodOptions,\n  ): Promise<string | null> {\n    return this.#getUserStorage(path, options);\n  }\n\n  async getAllFeatureItems(\n    path: UserStorageGenericFeatureName,\n    options?: UserStorageMethodOptions,\n  ): Promise<string[] | null> {\n    return this.#getUserStorageAllFeatureEntries(path, options);\n  }\n\n  async deleteItem(\n    path: UserStorageGenericPathWithFeatureAndKey,\n    options?: UserStorageMethodOptions,\n  ): Promise<void> {\n    return this.#deleteUserStorage(path, options);\n  }\n\n  async deleteAllFeatureItems(\n    path: UserStorageGenericFeatureName,\n    options?: UserStorageMethodOptions,\n  ): Promise<void> {\n    return this.#deleteUserStorageAllFeatureEntries(path, options);\n  }\n\n  async batchDeleteItems(\n    path: UserStorageGenericFeatureName,\n    values: UserStorageGenericFeatureKey[],\n    options?: UserStorageMethodOptions,\n  ) {\n    return this.#batchDeleteUserStorage(path, values, options);\n  }\n\n  async getStorageKey(entropySourceId?: string): Promise<string> {\n    const userProfile = await this.config.auth.getUserProfile(entropySourceId);\n    const message = `metamask:${userProfile.profileId}` as const;\n\n    const storageKey = await this.options.storage?.getStorageKey(message);\n    if (storageKey) {\n      return storageKey;\n    }\n\n    const storageKeySignature = await this.config.auth.signMessage(\n      message,\n      entropySourceId,\n    );\n    const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);\n    await this.options.storage?.setStorageKey(\n      message,\n      hashedStorageKeySignature,\n    );\n    return hashedStorageKeySignature;\n  }\n\n  async #upsertUserStorage(\n    path: UserStorageGenericPathWithFeatureAndKey,\n    data: string,\n    options?: UserStorageMethodOptions,\n  ): Promise<void> {\n    const entropySourceId = options?.entropySourceId;\n    try {\n      const headers = await this.#getAuthorizationHeader(entropySourceId);\n      const storageKey = await this.getStorageKey(entropySourceId);\n      const encryptedData = await encryption.encryptString(\n        data,\n        storageKey,\n        options?.nativeScryptCrypto,\n      );\n      const encryptedPath = createEntryPath(path, storageKey);\n\n      const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n      const response = await fetch(url.toString(), {\n        method: 'PUT',\n        headers: {\n          'Content-Type': 'application/json',\n          ...headers,\n        },\n        body: JSON.stringify({ data: encryptedData }),\n      });\n\n      if (!response.ok) {\n        const responseBody: ErrorMessage = await response.json().catch(() => ({\n          message: 'unknown',\n          error: 'unknown',\n        }));\n        throw new Error(\n          `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n        );\n      }\n    } catch (e) {\n      /* istanbul ignore next */\n      const errorMessage =\n        e instanceof Error ? e.message : JSON.stringify(e ?? '');\n      throw new UserStorageError(\n        `failed to upsert user storage for path '${path}'. ${errorMessage}`,\n      );\n    }\n  }\n\n  async #batchUpsertUserStorage(\n    path: UserStorageGenericPathWithFeatureOnly,\n    data: [string, string][],\n    options?: UserStorageMethodOptions,\n  ): Promise<void> {\n    const entropySourceId = options?.entropySourceId;\n    try {\n      if (!data.length) {\n        return;\n      }\n\n      const headers = await this.#getAuthorizationHeader(entropySourceId);\n      const storageKey = await this.getStorageKey(entropySourceId);\n\n      const encryptedData = await Promise.all(\n        data.map(async (d) => {\n          return [\n            this.#createEntryKey(d[0], storageKey),\n            await encryption.encryptString(\n              d[1],\n              storageKey,\n              options?.nativeScryptCrypto,\n            ),\n          ];\n        }),\n      );\n\n      const url = new URL(STORAGE_URL(this.env, path));\n\n      const response = await fetch(url.toString(), {\n        method: 'PUT',\n        headers: {\n          'Content-Type': 'application/json',\n          ...headers,\n        },\n        body: JSON.stringify({ data: Object.fromEntries(encryptedData) }),\n      });\n\n      if (!response.ok) {\n        const responseBody: ErrorMessage = await response.json().catch(() => ({\n          message: 'unknown',\n          error: 'unknown',\n        }));\n        throw new Error(\n          `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n        );\n      }\n    } catch (e) {\n      /* istanbul ignore next */\n      const errorMessage =\n        e instanceof Error ? e.message : JSON.stringify(e ?? '');\n      throw new UserStorageError(\n        `failed to batch upsert user storage for path '${path}'. ${errorMessage}`,\n      );\n    }\n  }\n\n  async #batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n    path: UserStorageGenericPathWithFeatureOnly,\n    encryptedData: [string, string][],\n    entropySourceId?: string,\n  ): Promise<void> {\n    try {\n      const headers = await this.#getAuthorizationHeader(entropySourceId);\n\n      const url = new URL(STORAGE_URL(this.env, path));\n\n      const response = await fetch(url.toString(), {\n        method: 'PUT',\n        headers: {\n          'Content-Type': 'application/json',\n          ...headers,\n        },\n        body: JSON.stringify({ data: Object.fromEntries(encryptedData) }),\n      });\n\n      // istanbul ignore next\n      if (!response.ok) {\n        const responseBody: ErrorMessage = await response.json().catch(() => ({\n          message: 'unknown',\n          error: 'unknown',\n        }));\n        throw new Error(\n          `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n        );\n      }\n    } catch (e) {\n      /* istanbul ignore next */\n      const errorMessage =\n        e instanceof Error ? e.message : JSON.stringify(e ?? '');\n      // istanbul ignore next\n      throw new UserStorageError(\n        `failed to batch upsert user storage for path '${path}'. ${errorMessage}`,\n      );\n    }\n  }\n\n  async #getUserStorage(\n    path: UserStorageGenericPathWithFeatureAndKey,\n    options?: UserStorageMethodOptions,\n  ): Promise<string | null> {\n    const entropySourceId = options?.entropySourceId;\n    try {\n      const headers = await this.#getAuthorizationHeader(entropySourceId);\n      const storageKey = await this.getStorageKey(entropySourceId);\n      const encryptedPath = createEntryPath(path, storageKey);\n\n      const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n      const response = await fetch(url.toString(), {\n        headers: {\n          'Content-Type': 'application/json',\n          ...headers,\n        },\n      });\n\n      if (response.status === 404) {\n        return null;\n      }\n\n      if (!response.ok) {\n        const responseBody = (await response.json()) as ErrorMessage;\n        throw new Error(\n          `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n        );\n      }\n\n      const userStorage = await response.json();\n      const encryptedData = userStorage?.Data ?? null;\n\n      if (!encryptedData) {\n        return null;\n      }\n\n      const decryptedData = await encryption.decryptString(\n        encryptedData,\n        storageKey,\n        options?.nativeScryptCrypto,\n      );\n\n      // Re-encrypt the entry if it was encrypted with a random salt\n      const salt = encryption.getSalt(encryptedData);\n      if (salt.toString() !== SHARED_SALT.toString()) {\n        await this.#upsertUserStorage(path, decryptedData, options);\n      }\n\n      return decryptedData;\n    } catch (e) {\n      /* istanbul ignore next */\n      const errorMessage =\n        e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n      throw new UserStorageError(\n        `failed to get user storage for path '${path}'. ${errorMessage}`,\n      );\n    }\n  }\n\n  async #getUserStorageAllFeatureEntries(\n    path: UserStorageGenericPathWithFeatureOnly,\n    options?: UserStorageMethodOptions,\n  ): Promise<string[] | null> {\n    const entropySourceId = options?.entropySourceId;\n    try {\n      const headers = await this.#getAuthorizationHeader(entropySourceId);\n      const storageKey = await this.getStorageKey(entropySourceId);\n\n      const url = new URL(STORAGE_URL(this.env, path));\n\n      const response = await fetch(url.toString(), {\n        headers: {\n          'Content-Type': 'application/json',\n          ...headers,\n        },\n      });\n\n      if (response.status === 404) {\n        return null;\n      }\n\n      if (!response.ok) {\n        const responseBody = (await response.json()) as ErrorMessage;\n        throw new Error(\n          `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n        );\n      }\n\n      const userStorage: GetUserStorageAllFeatureEntriesResponse | null =\n        await response.json();\n\n      if (!Array.isArray(userStorage)) {\n        return null;\n      }\n\n      const decryptedData: string[] = [];\n      const reEncryptedEntries: [string, string][] = [];\n\n      for (const entry of userStorage) {\n        if (!entry.Data) {\n          continue;\n        }\n\n        try {\n          const data = await encryption.decryptString(\n            entry.Data,\n            storageKey,\n            options?.nativeScryptCrypto,\n          );\n          decryptedData.push(data);\n\n          // Re-encrypt the entry was encrypted with a random salt\n          const salt = encryption.getSalt(entry.Data);\n          if (salt.toString() !== SHARED_SALT.toString()) {\n            reEncryptedEntries.push([\n              entry.HashedKey,\n              await encryption.encryptString(\n                data,\n                storageKey,\n                options?.nativeScryptCrypto,\n              ),\n            ]);\n          }\n        } catch {\n          // do nothing\n        }\n      }\n\n      // Re-upload the re-encrypted entries\n      if (reEncryptedEntries.length) {\n        await this.#batchUpsertUserStorageWithAlreadyHashedAndEncryptedEntries(\n          path,\n          reEncryptedEntries,\n          entropySourceId,\n        );\n      }\n\n      return decryptedData;\n    } catch (e) {\n      /* istanbul ignore next */\n      const errorMessage =\n        e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n      throw new UserStorageError(\n        `failed to get user storage for path '${path}'. ${errorMessage}`,\n      );\n    }\n  }\n\n  async #deleteUserStorage(\n    path: UserStorageGenericPathWithFeatureAndKey,\n    options?: UserStorageMethodOptions,\n  ): Promise<void> {\n    const entropySourceId = options?.entropySourceId;\n    try {\n      const headers = await this.#getAuthorizationHeader(entropySourceId);\n      const storageKey = await this.getStorageKey(entropySourceId);\n      const encryptedPath = createEntryPath(path, storageKey);\n\n      const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n      const response = await fetch(url.toString(), {\n        method: 'DELETE',\n        headers: {\n          'Content-Type': 'application/json',\n          ...headers,\n        },\n      });\n\n      if (response.status === 404) {\n        throw new NotFoundError(\n          `feature/key set not found for path '${path}'.`,\n        );\n      }\n\n      if (!response.ok) {\n        const responseBody = (await response.json()) as ErrorMessage;\n        throw new Error(\n          `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n        );\n      }\n    } catch (e) {\n      if (e instanceof NotFoundError) {\n        throw e;\n      }\n\n      /* istanbul ignore next */\n      const errorMessage =\n        e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n      throw new UserStorageError(\n        `failed to delete user storage for path '${path}'. ${errorMessage}`,\n      );\n    }\n  }\n\n  async #deleteUserStorageAllFeatureEntries(\n    path: UserStorageGenericPathWithFeatureOnly,\n    options?: UserStorageMethodOptions,\n  ): Promise<void> {\n    try {\n      const entropySourceId = options?.entropySourceId;\n      const headers = await this.#getAuthorizationHeader(entropySourceId);\n\n      const url = new URL(STORAGE_URL(this.env, path));\n\n      const response = await fetch(url.toString(), {\n        method: 'DELETE',\n        headers: {\n          'Content-Type': 'application/json',\n          ...headers,\n        },\n      });\n\n      if (response.status === 404) {\n        throw new NotFoundError(`feature not found for path '${path}'.`);\n      }\n\n      if (!response.ok) {\n        const responseBody = (await response.json()) as ErrorMessage;\n        throw new Error(\n          `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n        );\n      }\n    } catch (e) {\n      if (e instanceof NotFoundError) {\n        throw e;\n      }\n\n      /* istanbul ignore next */\n      const errorMessage =\n        e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n      throw new UserStorageError(\n        `failed to delete user storage for path '${path}'. ${errorMessage}`,\n      );\n    }\n  }\n\n  async #batchDeleteUserStorage(\n    path: UserStorageGenericPathWithFeatureOnly,\n    keysToDelete: string[],\n    options?: UserStorageMethodOptions,\n  ): Promise<void> {\n    try {\n      if (!keysToDelete.length) {\n        return;\n      }\n\n      const entropySourceId = options?.entropySourceId;\n      const headers = await this.#getAuthorizationHeader(entropySourceId);\n      const storageKey = await this.getStorageKey(entropySourceId);\n\n      const rawEntryKeys = keysToDelete.map((d) =>\n        this.#createEntryKey(d, storageKey),\n      );\n\n      const url = new URL(STORAGE_URL(this.env, path));\n\n      const response = await fetch(url.toString(), {\n        method: 'PUT',\n        headers: {\n          'Content-Type': 'application/json',\n          ...headers,\n        },\n\n        body: JSON.stringify({ batch_delete: rawEntryKeys }),\n      });\n\n      if (!response.ok) {\n        const responseBody: ErrorMessage = await response.json().catch(() => ({\n          message: 'unknown',\n          error: 'unknown',\n        }));\n        throw new Error(\n          `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n        );\n      }\n    } catch (e) {\n      /* istanbul ignore next */\n      const errorMessage =\n        e instanceof Error ? e.message : JSON.stringify(e ?? '');\n      throw new UserStorageError(\n        `failed to batch delete user storage for path '${path}'. ${errorMessage}`,\n      );\n    }\n  }\n\n  #createEntryKey(key: string, storageKey: string): string {\n    return createSHA256Hash(key + storageKey);\n  }\n\n  async #getAuthorizationHeader(\n    entropySourceId?: string,\n  ): Promise<{ Authorization: string }> {\n    const accessToken = await this.config.auth.getAccessToken(entropySourceId);\n    return { Authorization: `Bearer ${accessToken}` };\n  }\n}\n"]}