@metamask/profile-sync-controller 19.0.0 → 21.0.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.
Files changed (186) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/dist/controllers/authentication/AuthenticationController.cjs +21 -9
  3. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
  4. package/dist/controllers/authentication/AuthenticationController.d.cts +10 -3
  5. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
  6. package/dist/controllers/authentication/AuthenticationController.d.mts +10 -3
  7. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
  8. package/dist/controllers/authentication/AuthenticationController.mjs +21 -9
  9. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
  10. package/dist/controllers/user-storage/UserStorageController.cjs +24 -47
  11. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  12. package/dist/controllers/user-storage/UserStorageController.d.cts +16 -49
  13. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  14. package/dist/controllers/user-storage/UserStorageController.d.mts +16 -49
  15. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  16. package/dist/controllers/user-storage/UserStorageController.mjs +24 -47
  17. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  18. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +185 -166
  19. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
  20. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +3 -0
  21. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
  22. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +3 -0
  23. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
  24. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +185 -166
  25. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
  26. package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -1
  27. package/dist/controllers/user-storage/account-syncing/types.d.cts +2 -0
  28. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -1
  29. package/dist/controllers/user-storage/account-syncing/types.d.mts +2 -0
  30. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -1
  31. package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -1
  32. package/dist/controllers/user-storage/constants.cjs +14 -1
  33. package/dist/controllers/user-storage/constants.cjs.map +1 -1
  34. package/dist/controllers/user-storage/constants.d.cts +11 -0
  35. package/dist/controllers/user-storage/constants.d.cts.map +1 -1
  36. package/dist/controllers/user-storage/constants.d.mts +11 -0
  37. package/dist/controllers/user-storage/constants.d.mts.map +1 -1
  38. package/dist/controllers/user-storage/constants.mjs +13 -0
  39. package/dist/controllers/user-storage/constants.mjs.map +1 -1
  40. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +227 -162
  41. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +1 -1
  42. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts +3 -0
  43. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +1 -1
  44. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts +3 -0
  45. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +1 -1
  46. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs +227 -162
  47. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +1 -1
  48. package/dist/controllers/user-storage/contact-syncing/types.cjs.map +1 -1
  49. package/dist/controllers/user-storage/contact-syncing/types.d.cts +2 -0
  50. package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +1 -1
  51. package/dist/controllers/user-storage/contact-syncing/types.d.mts +2 -0
  52. package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +1 -1
  53. package/dist/controllers/user-storage/contact-syncing/types.mjs.map +1 -1
  54. package/dist/controllers/user-storage/mocks/mockResponses.cjs +1 -1
  55. package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -1
  56. package/dist/controllers/user-storage/mocks/mockResponses.d.cts +9 -9
  57. package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -1
  58. package/dist/controllers/user-storage/mocks/mockResponses.d.mts +9 -9
  59. package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -1
  60. package/dist/controllers/user-storage/mocks/mockResponses.mjs +1 -1
  61. package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -1
  62. package/dist/controllers/user-storage/types.cjs.map +1 -1
  63. package/dist/controllers/user-storage/types.d.cts +3 -3
  64. package/dist/controllers/user-storage/types.d.cts.map +1 -1
  65. package/dist/controllers/user-storage/types.d.mts +3 -3
  66. package/dist/controllers/user-storage/types.d.mts.map +1 -1
  67. package/dist/controllers/user-storage/types.mjs.map +1 -1
  68. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +4 -0
  69. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
  70. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts +2 -1
  71. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
  72. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +2 -1
  73. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
  74. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +5 -1
  75. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
  76. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +4 -0
  77. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
  78. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +2 -1
  79. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
  80. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +2 -1
  81. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
  82. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +5 -1
  83. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
  84. package/dist/sdk/authentication-jwt-bearer/services.cjs +33 -1
  85. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
  86. package/dist/sdk/authentication-jwt-bearer/services.d.cts +10 -1
  87. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
  88. package/dist/sdk/authentication-jwt-bearer/services.d.mts +10 -1
  89. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
  90. package/dist/sdk/authentication-jwt-bearer/services.mjs +30 -0
  91. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
  92. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
  93. package/dist/sdk/authentication-jwt-bearer/types.d.cts +11 -0
  94. package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -1
  95. package/dist/sdk/authentication-jwt-bearer/types.d.mts +11 -0
  96. package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -1
  97. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
  98. package/dist/sdk/authentication.cjs +3 -0
  99. package/dist/sdk/authentication.cjs.map +1 -1
  100. package/dist/sdk/authentication.d.cts +2 -1
  101. package/dist/sdk/authentication.d.cts.map +1 -1
  102. package/dist/sdk/authentication.d.mts +2 -1
  103. package/dist/sdk/authentication.d.mts.map +1 -1
  104. package/dist/sdk/authentication.mjs +3 -0
  105. package/dist/sdk/authentication.mjs.map +1 -1
  106. package/dist/sdk/mocks/auth.cjs +22 -1
  107. package/dist/sdk/mocks/auth.cjs.map +1 -1
  108. package/dist/sdk/mocks/auth.d.cts +13 -0
  109. package/dist/sdk/mocks/auth.d.cts.map +1 -1
  110. package/dist/sdk/mocks/auth.d.mts +13 -0
  111. package/dist/sdk/mocks/auth.d.mts.map +1 -1
  112. package/dist/sdk/mocks/auth.mjs +23 -2
  113. package/dist/sdk/mocks/auth.mjs.map +1 -1
  114. package/dist/sdk/user-storage.cjs +3 -9
  115. package/dist/sdk/user-storage.cjs.map +1 -1
  116. package/dist/sdk/user-storage.d.cts +0 -1
  117. package/dist/sdk/user-storage.d.cts.map +1 -1
  118. package/dist/sdk/user-storage.d.mts +0 -1
  119. package/dist/sdk/user-storage.d.mts.map +1 -1
  120. package/dist/sdk/user-storage.mjs +3 -9
  121. package/dist/sdk/user-storage.mjs.map +1 -1
  122. package/dist/shared/storage-schema.cjs +9 -32
  123. package/dist/shared/storage-schema.cjs.map +1 -1
  124. package/dist/shared/storage-schema.d.cts +10 -42
  125. package/dist/shared/storage-schema.d.cts.map +1 -1
  126. package/dist/shared/storage-schema.d.mts +10 -42
  127. package/dist/shared/storage-schema.d.mts.map +1 -1
  128. package/dist/shared/storage-schema.mjs +8 -31
  129. package/dist/shared/storage-schema.mjs.map +1 -1
  130. package/package.json +6 -8
  131. package/dist/controllers/user-storage/network-syncing/add-network-utils.cjs +0 -36
  132. package/dist/controllers/user-storage/network-syncing/add-network-utils.cjs.map +0 -1
  133. package/dist/controllers/user-storage/network-syncing/add-network-utils.d.cts +0 -22
  134. package/dist/controllers/user-storage/network-syncing/add-network-utils.d.cts.map +0 -1
  135. package/dist/controllers/user-storage/network-syncing/add-network-utils.d.mts +0 -22
  136. package/dist/controllers/user-storage/network-syncing/add-network-utils.d.mts.map +0 -1
  137. package/dist/controllers/user-storage/network-syncing/add-network-utils.mjs +0 -31
  138. package/dist/controllers/user-storage/network-syncing/add-network-utils.mjs.map +0 -1
  139. package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +0 -193
  140. package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +0 -1
  141. package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +0 -57
  142. package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +0 -1
  143. package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +0 -57
  144. package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +0 -1
  145. package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +0 -191
  146. package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +0 -1
  147. package/dist/controllers/user-storage/network-syncing/services.cjs +0 -79
  148. package/dist/controllers/user-storage/network-syncing/services.cjs.map +0 -1
  149. package/dist/controllers/user-storage/network-syncing/services.d.cts +0 -34
  150. package/dist/controllers/user-storage/network-syncing/services.d.cts.map +0 -1
  151. package/dist/controllers/user-storage/network-syncing/services.d.mts +0 -34
  152. package/dist/controllers/user-storage/network-syncing/services.d.mts.map +0 -1
  153. package/dist/controllers/user-storage/network-syncing/services.mjs +0 -73
  154. package/dist/controllers/user-storage/network-syncing/services.mjs.map +0 -1
  155. package/dist/controllers/user-storage/network-syncing/sync-all.cjs +0 -153
  156. package/dist/controllers/user-storage/network-syncing/sync-all.cjs.map +0 -1
  157. package/dist/controllers/user-storage/network-syncing/sync-all.d.cts +0 -32
  158. package/dist/controllers/user-storage/network-syncing/sync-all.d.cts.map +0 -1
  159. package/dist/controllers/user-storage/network-syncing/sync-all.d.mts +0 -32
  160. package/dist/controllers/user-storage/network-syncing/sync-all.d.mts.map +0 -1
  161. package/dist/controllers/user-storage/network-syncing/sync-all.mjs +0 -145
  162. package/dist/controllers/user-storage/network-syncing/sync-all.mjs.map +0 -1
  163. package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs +0 -28
  164. package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +0 -1
  165. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts +0 -17
  166. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +0 -1
  167. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts +0 -17
  168. package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +0 -1
  169. package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs +0 -22
  170. package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +0 -1
  171. package/dist/controllers/user-storage/network-syncing/types.cjs +0 -16
  172. package/dist/controllers/user-storage/network-syncing/types.cjs.map +0 -1
  173. package/dist/controllers/user-storage/network-syncing/types.d.cts +0 -15
  174. package/dist/controllers/user-storage/network-syncing/types.d.cts.map +0 -1
  175. package/dist/controllers/user-storage/network-syncing/types.d.mts +0 -15
  176. package/dist/controllers/user-storage/network-syncing/types.d.mts.map +0 -1
  177. package/dist/controllers/user-storage/network-syncing/types.mjs +0 -11
  178. package/dist/controllers/user-storage/network-syncing/types.mjs.map +0 -1
  179. package/dist/controllers/user-storage/network-syncing/update-network-utils.cjs +0 -129
  180. package/dist/controllers/user-storage/network-syncing/update-network-utils.cjs.map +0 -1
  181. package/dist/controllers/user-storage/network-syncing/update-network-utils.d.cts +0 -59
  182. package/dist/controllers/user-storage/network-syncing/update-network-utils.d.cts.map +0 -1
  183. package/dist/controllers/user-storage/network-syncing/update-network-utils.d.mts +0 -59
  184. package/dist/controllers/user-storage/network-syncing/update-network-utils.d.mts.map +0 -1
  185. package/dist/controllers/user-storage/network-syncing/update-network-utils.mjs +0 -122
  186. package/dist/controllers/user-storage/network-syncing/update-network-utils.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"user-storage.mjs","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,qBAAiB;AAC3D,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,uCAA6B;AACpE,OAAO,EAAE,WAAW,EAAE,2CAAuC;AAE7D,OAAO,EAAE,UAAU,EAAE,0BAAsB;AAO3C,OAAO,EAAE,eAAe,EAAE,qCAAiC;AAG3D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,aAAqB,EAAE,EAAE,CAC7D,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,iBAAiB,uBAAuB,aAAa,EAAE,CAAC;AAiC7E,MAAM,OAAO,WAAW;IAOtB,YAAY,MAAyB,EAAE,OAA2B;;QAChE,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O,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO;aACX;YAED,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;SACrD,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,MAAM,YAAY,GAAiB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;gBACpE,OAAO,EAAE,SAAS;gBAClB,KAAK,EAAE,SAAS;aACjB,CAAC,CAAC,CAAC;YACJ,MAAM,IAAI,KAAK,CACb,uBAAuB,YAAY,CAAC,OAAO,YAAY,YAAY,CAAC,KAAK,EAAE,CAC5E,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,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,gBAAgB,CACxB,iDAAiD,IAAI,MAAM,YAAY,EAAE,CAC1E,CAAC;KACH;AACH,CAAC,qEAEe,GAAW,EAAE,UAAkB;IAC7C,OAAO,gBAAgB,CAAC,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 validateAgainstSchema?: boolean;\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 validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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 validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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 validateAgainstSchema: Boolean(options?.validateAgainstSchema),\n });\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"]}
1
+ {"version":3,"file":"user-storage.mjs","sourceRoot":"","sources":["../../src/sdk/user-storage.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,qBAAiB;AAC3D,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,uCAA6B;AACpE,OAAO,EAAE,WAAW,EAAE,2CAAuC;AAE7D,OAAO,EAAE,UAAU,EAAE,0BAAsB;AAO3C,OAAO,EAAE,eAAe,EAAE,qCAAiC;AAG3D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,aAAqB,EAAE,EAAE,CAC7D,GAAG,UAAU,CAAC,GAAG,CAAC,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AY,EAAE,YAAY,EAAE,CAAC;SACrD,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,MAAM,YAAY,GAAiB,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;gBACpE,OAAO,EAAE,SAAS;gBAClB,KAAK,EAAE,SAAS;aACjB,CAAC,CAAC,CAAC;YACJ,MAAM,IAAI,KAAK,CACb,uBAAuB,YAAY,CAAC,OAAO,YAAY,YAAY,CAAC,KAAK,EAAE,CAC5E,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,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,gBAAgB,CACxB,iDAAiD,IAAI,MAAM,YAAY,EAAE,CAC1E,CAAC;KACH;AACH,CAAC,qEAEe,GAAW,EAAE,UAAkB;IAC7C,OAAO,gBAAgB,CAAC,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"]}
@@ -1,46 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEntryPath = exports.getFeatureAndKeyFromPath = exports.USER_STORAGE_SCHEMA = exports.USER_STORAGE_FEATURE_NAMES = void 0;
3
+ exports.createEntryPath = exports.getFeatureAndKeyFromPath = exports.USER_STORAGE_FEATURE_NAMES = void 0;
4
4
  const encryption_1 = require("./encryption/index.cjs");
5
5
  /**
6
6
  * The User Storage Endpoint requires a feature name and a namespace key.
7
- * Developers can provide additional features and keys by extending these types below.
8
- *
9
- * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.
10
- * This can be useful for features where keys are not deterministic (eg. accounts addresses).
7
+ * Any user storage path should be in the form of `feature.key`.
8
+ */
9
+ /**
10
+ * Helper object that contains the feature names used in the controllers and SDK.
11
+ * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.
11
12
  */
12
- const ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS';
13
13
  exports.USER_STORAGE_FEATURE_NAMES = {
14
14
  notifications: 'notifications',
15
15
  accounts: 'accounts_v2',
16
- networks: 'networks',
17
16
  addressBook: 'addressBook',
18
17
  };
19
- exports.USER_STORAGE_SCHEMA = {
20
- [exports.USER_STORAGE_FEATURE_NAMES.notifications]: ['notification_settings'],
21
- [exports.USER_STORAGE_FEATURE_NAMES.accounts]: [ALLOW_ARBITRARY_KEYS],
22
- [exports.USER_STORAGE_FEATURE_NAMES.networks]: [ALLOW_ARBITRARY_KEYS],
23
- [exports.USER_STORAGE_FEATURE_NAMES.addressBook]: [ALLOW_ARBITRARY_KEYS], // keyed by address_chainId
24
- };
25
- const getFeatureAndKeyFromPath = (path, options = { validateAgainstSchema: true }) => {
18
+ const getFeatureAndKeyFromPath = (path) => {
26
19
  const pathRegex = /^\w+\.\w+$/u;
27
20
  if (!pathRegex.test(path)) {
28
21
  throw new Error(`user-storage - path is not in the correct format. Correct format: 'feature.key'`);
29
22
  }
30
23
  const [feature, key] = path.split('.');
31
- if (options.validateAgainstSchema) {
32
- const featureToValidate = feature;
33
- const keyToValidate = key;
34
- if (!(featureToValidate in exports.USER_STORAGE_SCHEMA)) {
35
- throw new Error(`user-storage - invalid feature provided: ${featureToValidate}. Valid features: ${Object.keys(exports.USER_STORAGE_SCHEMA).join(', ')}`);
36
- }
37
- const validFeature = exports.USER_STORAGE_SCHEMA[featureToValidate];
38
- if (!validFeature.includes(keyToValidate) &&
39
- !validFeature.includes(ALLOW_ARBITRARY_KEYS)) {
40
- const validKeys = exports.USER_STORAGE_SCHEMA[featureToValidate].join(', ');
41
- throw new Error(`user-storage - invalid key provided for this feature: ${keyToValidate}. Valid keys: ${validKeys}`);
42
- }
43
- }
44
24
  return { feature, key };
45
25
  };
46
26
  exports.getFeatureAndKeyFromPath = getFeatureAndKeyFromPath;
@@ -51,13 +31,10 @@ exports.getFeatureAndKeyFromPath = getFeatureAndKeyFromPath;
51
31
  *
52
32
  * @param path - string in the form of `${feature}.${key}` that matches schema
53
33
  * @param storageKey - users storage key
54
- * @param options - options object
55
- * @param options.validateAgainstSchema - whether to validate the path against the schema.
56
- * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.
57
34
  * @returns path to store entry
58
35
  */
59
- function createEntryPath(path, storageKey, options = { validateAgainstSchema: true }) {
60
- const { feature, key } = (0, exports.getFeatureAndKeyFromPath)(path, options);
36
+ function createEntryPath(path, storageKey) {
37
+ const { feature, key } = (0, exports.getFeatureAndKeyFromPath)(path);
61
38
  const hashedKey = (0, encryption_1.createSHA256Hash)(key + storageKey);
62
39
  return `${feature}/${hashedKey}`;
63
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"storage-schema.cjs","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAEhD;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,sBAA+B,CAAC;AAEhD,QAAA,0BAA0B,GAAG;IACxC,aAAa,EAAE,eAAe;IAC9B,QAAQ,EAAE,aAAa;IACvB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;CAClB,CAAC;AAKE,QAAA,mBAAmB,GAAG;IACjC,CAAC,kCAA0B,CAAC,aAAa,CAAC,EAAE,CAAC,uBAAuB,CAAC;IACrE,CAAC,kCAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC,oBAAoB,CAAC;IAC7D,CAAC,kCAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC,oBAAoB,CAAC;IAC7D,CAAC,kCAA0B,CAAC,WAAW,CAAC,EAAE,CAAC,oBAAoB,CAAC,EAAE,2BAA2B;CACrF,CAAC;AAuCJ,MAAM,wBAAwB,GAAG,CACtC,IAE2C,EAC3C,UAEI,EAAE,qBAAqB,EAAE,IAAS,EAAE,EAGN,EAAE;IACpC,MAAM,SAAS,GAAG,aAAa,CAAC;IAEhC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;KACH;IA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ash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Developers can provide additional features and keys by extending these types below.\n *\n * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.\n * This can be useful for features where keys are not deterministic (eg. accounts addresses).\n */\nconst ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS' as const;\n\nexport const USER_STORAGE_FEATURE_NAMES = {\n notifications: 'notifications',\n accounts: 'accounts_v2',\n networks: 'networks',\n addressBook: 'addressBook',\n} as const;\n\nexport type UserStorageFeatureNames =\n (typeof USER_STORAGE_FEATURE_NAMES)[keyof typeof USER_STORAGE_FEATURE_NAMES];\n\nexport const USER_STORAGE_SCHEMA = {\n [USER_STORAGE_FEATURE_NAMES.notifications]: ['notification_settings'],\n [USER_STORAGE_FEATURE_NAMES.accounts]: [ALLOW_ARBITRARY_KEYS], // keyed by account addresses\n [USER_STORAGE_FEATURE_NAMES.networks]: [ALLOW_ARBITRARY_KEYS], // keyed by chains/networks\n [USER_STORAGE_FEATURE_NAMES.addressBook]: [ALLOW_ARBITRARY_KEYS], // keyed by address_chainId\n} as const;\n\ntype UserStorageSchema = typeof USER_STORAGE_SCHEMA;\n\nexport type UserStorageFeatureKeys<Feature extends UserStorageFeatureNames> =\n UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS\n ? string\n : UserStorageSchema[Feature][number];\n\ntype UserStorageFeatureAndKey = {\n feature: UserStorageFeatureNames;\n key: UserStorageFeatureKeys<UserStorageFeatureNames>;\n};\n\nexport type UserStoragePathWithFeatureOnly = UserStorageFeatureNames;\nexport type UserStoragePathWithFeatureAndKey = {\n [K in UserStorageFeatureNames]: `${K}.${UserStorageFeatureKeys<K>}`;\n}[UserStoragePathWithFeatureOnly];\n\n/**\n * The below types are mainly used for the SDK.\n * These exist so that the SDK can be used with arbitrary feature names and keys.\n *\n * We only type enforce feature names and keys when using UserStorageController.\n * This is done so we don't end up with magic strings within the applications.\n */\n\nexport type UserStorageGenericFeatureName = string;\nexport type UserStorageGenericFeatureKey = string;\nexport type UserStorageGenericPathWithFeatureAndKey =\n `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;\nexport type UserStorageGenericPathWithFeatureOnly =\n UserStorageGenericFeatureName;\n\ntype UserStorageGenericFeatureAndKey = {\n feature: UserStorageGenericFeatureName;\n key: UserStorageGenericFeatureKey;\n};\n\nexport const getFeatureAndKeyFromPath = <T extends boolean>(\n path: T extends true\n ? UserStoragePathWithFeatureAndKey\n : UserStorageGenericPathWithFeatureAndKey,\n options: {\n validateAgainstSchema: T;\n } = { validateAgainstSchema: true as T },\n): T extends true\n ? UserStorageFeatureAndKey\n : UserStorageGenericFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.');\n\n if (options.validateAgainstSchema) {\n const featureToValidate = feature as UserStorageFeatureNames;\n const keyToValidate = key as UserStorageFeatureKeys<\n typeof featureToValidate\n >;\n\n if (!(featureToValidate in USER_STORAGE_SCHEMA)) {\n throw new Error(\n `user-storage - invalid feature provided: ${featureToValidate}. Valid features: ${Object.keys(\n USER_STORAGE_SCHEMA,\n ).join(', ')}`,\n );\n }\n\n const validFeature = USER_STORAGE_SCHEMA[\n featureToValidate\n ] as readonly string[];\n\n if (\n !validFeature.includes(keyToValidate) &&\n !validFeature.includes(ALLOW_ARBITRARY_KEYS)\n ) {\n const validKeys = USER_STORAGE_SCHEMA[featureToValidate].join(', ');\n\n throw new Error(\n `user-storage - invalid key provided for this feature: ${keyToValidate}. Valid keys: ${validKeys}`,\n );\n }\n }\n\n return { feature, key } as T extends true\n ? UserStorageFeatureAndKey\n : UserStorageGenericFeatureAndKey;\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @param options - options object\n * @param options.validateAgainstSchema - whether to validate the path against the schema.\n * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.\n * @returns path to store entry\n */\nexport function createEntryPath<T extends boolean>(\n path: T extends true\n ? UserStoragePathWithFeatureAndKey\n : UserStorageGenericPathWithFeatureAndKey,\n storageKey: string,\n options: {\n validateAgainstSchema: T;\n } = { validateAgainstSchema: true as T },\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path, options);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
1
+ {"version":3,"file":"storage-schema.cjs","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAEhD;;;GAGG;AAEH;;;GAGG;AACU,QAAA,0BAA0B,GAAG;IACxC,aAAa,EAAE,eAAe;IAC9B,QAAQ,EAAE,aAAa;IACvB,WAAW,EAAE,aAAa;CAC3B,CAAC;AAcK,MAAM,wBAAwB,GAAG,CACtC,IAA6C,EACZ,EAAE;IACnC,MAAM,SAAS,GAAG,aAAa,CAAC;IAEhC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;KACH;IAED,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEvC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAqC,CAAC;AAC7D,CAAC,CAAC;AAdW,QAAA,wBAAwB,4BAcnC;AAEF;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,IAA6C,EAC7C,UAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,IAAA,gCAAwB,EAAC,IAAI,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,IAAA,6BAAgB,EAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IAErD,OAAO,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC;AARD,0CAQC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Any user storage path should be in the form of `feature.key`.\n */\n\n/**\n * Helper object that contains the feature names used in the controllers and SDK.\n * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.\n */\nexport const USER_STORAGE_FEATURE_NAMES = {\n notifications: 'notifications',\n accounts: 'accounts_v2',\n addressBook: 'addressBook',\n};\n\nexport type UserStorageGenericFeatureName = string;\nexport type UserStorageGenericFeatureKey = string;\nexport type UserStorageGenericPathWithFeatureAndKey =\n `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;\nexport type UserStorageGenericPathWithFeatureOnly =\n UserStorageGenericFeatureName;\n\ntype UserStorageGenericFeatureAndKey = {\n feature: UserStorageGenericFeatureName;\n key: UserStorageGenericFeatureKey;\n};\n\nexport const getFeatureAndKeyFromPath = (\n path: UserStorageGenericPathWithFeatureAndKey,\n): UserStorageGenericFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.');\n\n return { feature, key } as UserStorageGenericFeatureAndKey;\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @returns path to store entry\n */\nexport function createEntryPath(\n path: UserStorageGenericPathWithFeatureAndKey,\n storageKey: string,\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
@@ -1,41 +1,16 @@
1
1
  /**
2
2
  * The User Storage Endpoint requires a feature name and a namespace key.
3
- * Developers can provide additional features and keys by extending these types below.
4
- *
5
- * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.
6
- * This can be useful for features where keys are not deterministic (eg. accounts addresses).
3
+ * Any user storage path should be in the form of `feature.key`.
7
4
  */
8
- declare const ALLOW_ARBITRARY_KEYS: "ALLOW_ARBITRARY_KEYS";
9
- export declare const USER_STORAGE_FEATURE_NAMES: {
10
- readonly notifications: "notifications";
11
- readonly accounts: "accounts_v2";
12
- readonly networks: "networks";
13
- readonly addressBook: "addressBook";
14
- };
15
- export type UserStorageFeatureNames = (typeof USER_STORAGE_FEATURE_NAMES)[keyof typeof USER_STORAGE_FEATURE_NAMES];
16
- export declare const USER_STORAGE_SCHEMA: {
17
- readonly notifications: readonly ["notification_settings"];
18
- readonly accounts_v2: readonly ["ALLOW_ARBITRARY_KEYS"];
19
- readonly networks: readonly ["ALLOW_ARBITRARY_KEYS"];
20
- readonly addressBook: readonly ["ALLOW_ARBITRARY_KEYS"];
21
- };
22
- type UserStorageSchema = typeof USER_STORAGE_SCHEMA;
23
- export type UserStorageFeatureKeys<Feature extends UserStorageFeatureNames> = UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS ? string : UserStorageSchema[Feature][number];
24
- type UserStorageFeatureAndKey = {
25
- feature: UserStorageFeatureNames;
26
- key: UserStorageFeatureKeys<UserStorageFeatureNames>;
27
- };
28
- export type UserStoragePathWithFeatureOnly = UserStorageFeatureNames;
29
- export type UserStoragePathWithFeatureAndKey = {
30
- [K in UserStorageFeatureNames]: `${K}.${UserStorageFeatureKeys<K>}`;
31
- }[UserStoragePathWithFeatureOnly];
32
5
  /**
33
- * The below types are mainly used for the SDK.
34
- * These exist so that the SDK can be used with arbitrary feature names and keys.
35
- *
36
- * We only type enforce feature names and keys when using UserStorageController.
37
- * This is done so we don't end up with magic strings within the applications.
6
+ * Helper object that contains the feature names used in the controllers and SDK.
7
+ * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.
38
8
  */
9
+ export declare const USER_STORAGE_FEATURE_NAMES: {
10
+ notifications: string;
11
+ accounts: string;
12
+ addressBook: string;
13
+ };
39
14
  export type UserStorageGenericFeatureName = string;
40
15
  export type UserStorageGenericFeatureKey = string;
41
16
  export type UserStorageGenericPathWithFeatureAndKey = `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;
@@ -44,9 +19,7 @@ type UserStorageGenericFeatureAndKey = {
44
19
  feature: UserStorageGenericFeatureName;
45
20
  key: UserStorageGenericFeatureKey;
46
21
  };
47
- export declare const getFeatureAndKeyFromPath: <T extends boolean>(path: T extends true ? UserStoragePathWithFeatureAndKey : `${string}.${string}`, options?: {
48
- validateAgainstSchema: T;
49
- }) => T extends true ? UserStorageFeatureAndKey : UserStorageGenericFeatureAndKey;
22
+ export declare const getFeatureAndKeyFromPath: (path: UserStorageGenericPathWithFeatureAndKey) => UserStorageGenericFeatureAndKey;
50
23
  /**
51
24
  * Constructs a unique entry path for a user.
52
25
  * This can be done due to the uniqueness of the storage key (no users will share the same storage key).
@@ -54,13 +27,8 @@ export declare const getFeatureAndKeyFromPath: <T extends boolean>(path: T exten
54
27
  *
55
28
  * @param path - string in the form of `${feature}.${key}` that matches schema
56
29
  * @param storageKey - users storage key
57
- * @param options - options object
58
- * @param options.validateAgainstSchema - whether to validate the path against the schema.
59
- * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.
60
30
  * @returns path to store entry
61
31
  */
62
- export declare function createEntryPath<T extends boolean>(path: T extends true ? UserStoragePathWithFeatureAndKey : UserStorageGenericPathWithFeatureAndKey, storageKey: string, options?: {
63
- validateAgainstSchema: T;
64
- }): string;
32
+ export declare function createEntryPath(path: UserStorageGenericPathWithFeatureAndKey, storageKey: string): string;
65
33
  export {};
66
34
  //# sourceMappingURL=storage-schema.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-schema.d.cts","sourceRoot":"","sources":["../../src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;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,OAAO,EAC/C,IAAI,EAAE,CAAC,SAAS,IAAI,GAChB,gCAAgC,GAChC,uCAAuC,EAC3C,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;IACP,qBAAqB,EAAE,CAAC,CAAC;CACa,GACvC,MAAM,CAKR"}
1
+ {"version":3,"file":"storage-schema.d.cts","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,0BAA0B;;;;CAItC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC;AACnD,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAClD,MAAM,MAAM,uCAAuC,GACjD,GAAG,6BAA6B,IAAI,4BAA4B,EAAE,CAAC;AACrE,MAAM,MAAM,qCAAqC,GAC/C,6BAA6B,CAAC;AAEhC,KAAK,+BAA+B,GAAG;IACrC,OAAO,EAAE,6BAA6B,CAAC;IACvC,GAAG,EAAE,4BAA4B,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,wBAAwB,SAC7B,uCAAuC,KAC5C,+BAYF,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,uCAAuC,EAC7C,UAAU,EAAE,MAAM,GACjB,MAAM,CAKR"}
@@ -1,41 +1,16 @@
1
1
  /**
2
2
  * The User Storage Endpoint requires a feature name and a namespace key.
3
- * Developers can provide additional features and keys by extending these types below.
4
- *
5
- * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.
6
- * This can be useful for features where keys are not deterministic (eg. accounts addresses).
3
+ * Any user storage path should be in the form of `feature.key`.
7
4
  */
8
- declare const ALLOW_ARBITRARY_KEYS: "ALLOW_ARBITRARY_KEYS";
9
- export declare const USER_STORAGE_FEATURE_NAMES: {
10
- readonly notifications: "notifications";
11
- readonly accounts: "accounts_v2";
12
- readonly networks: "networks";
13
- readonly addressBook: "addressBook";
14
- };
15
- export type UserStorageFeatureNames = (typeof USER_STORAGE_FEATURE_NAMES)[keyof typeof USER_STORAGE_FEATURE_NAMES];
16
- export declare const USER_STORAGE_SCHEMA: {
17
- readonly notifications: readonly ["notification_settings"];
18
- readonly accounts_v2: readonly ["ALLOW_ARBITRARY_KEYS"];
19
- readonly networks: readonly ["ALLOW_ARBITRARY_KEYS"];
20
- readonly addressBook: readonly ["ALLOW_ARBITRARY_KEYS"];
21
- };
22
- type UserStorageSchema = typeof USER_STORAGE_SCHEMA;
23
- export type UserStorageFeatureKeys<Feature extends UserStorageFeatureNames> = UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS ? string : UserStorageSchema[Feature][number];
24
- type UserStorageFeatureAndKey = {
25
- feature: UserStorageFeatureNames;
26
- key: UserStorageFeatureKeys<UserStorageFeatureNames>;
27
- };
28
- export type UserStoragePathWithFeatureOnly = UserStorageFeatureNames;
29
- export type UserStoragePathWithFeatureAndKey = {
30
- [K in UserStorageFeatureNames]: `${K}.${UserStorageFeatureKeys<K>}`;
31
- }[UserStoragePathWithFeatureOnly];
32
5
  /**
33
- * The below types are mainly used for the SDK.
34
- * These exist so that the SDK can be used with arbitrary feature names and keys.
35
- *
36
- * We only type enforce feature names and keys when using UserStorageController.
37
- * This is done so we don't end up with magic strings within the applications.
6
+ * Helper object that contains the feature names used in the controllers and SDK.
7
+ * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.
38
8
  */
9
+ export declare const USER_STORAGE_FEATURE_NAMES: {
10
+ notifications: string;
11
+ accounts: string;
12
+ addressBook: string;
13
+ };
39
14
  export type UserStorageGenericFeatureName = string;
40
15
  export type UserStorageGenericFeatureKey = string;
41
16
  export type UserStorageGenericPathWithFeatureAndKey = `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;
@@ -44,9 +19,7 @@ type UserStorageGenericFeatureAndKey = {
44
19
  feature: UserStorageGenericFeatureName;
45
20
  key: UserStorageGenericFeatureKey;
46
21
  };
47
- export declare const getFeatureAndKeyFromPath: <T extends boolean>(path: T extends true ? UserStoragePathWithFeatureAndKey : `${string}.${string}`, options?: {
48
- validateAgainstSchema: T;
49
- }) => T extends true ? UserStorageFeatureAndKey : UserStorageGenericFeatureAndKey;
22
+ export declare const getFeatureAndKeyFromPath: (path: UserStorageGenericPathWithFeatureAndKey) => UserStorageGenericFeatureAndKey;
50
23
  /**
51
24
  * Constructs a unique entry path for a user.
52
25
  * This can be done due to the uniqueness of the storage key (no users will share the same storage key).
@@ -54,13 +27,8 @@ export declare const getFeatureAndKeyFromPath: <T extends boolean>(path: T exten
54
27
  *
55
28
  * @param path - string in the form of `${feature}.${key}` that matches schema
56
29
  * @param storageKey - users storage key
57
- * @param options - options object
58
- * @param options.validateAgainstSchema - whether to validate the path against the schema.
59
- * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.
60
30
  * @returns path to store entry
61
31
  */
62
- export declare function createEntryPath<T extends boolean>(path: T extends true ? UserStoragePathWithFeatureAndKey : UserStorageGenericPathWithFeatureAndKey, storageKey: string, options?: {
63
- validateAgainstSchema: T;
64
- }): string;
32
+ export declare function createEntryPath(path: UserStorageGenericPathWithFeatureAndKey, storageKey: string): string;
65
33
  export {};
66
34
  //# sourceMappingURL=storage-schema.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-schema.d.mts","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,QAAA,MAAM,oBAAoB,wBAAkC,CAAC;AAE7D,eAAO,MAAM,0BAA0B;;;;;CAK7B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,OAAO,0BAA0B,CAAC,CAAC;AAE/E,eAAO,MAAM,mBAAmB;;;;;CAKtB,CAAC;AAEX,KAAK,iBAAiB,GAAG,OAAO,mBAAmB,CAAC;AAEpD,MAAM,MAAM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,0BAA0B;;;;CAItC,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC;AACnD,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAClD,MAAM,MAAM,uCAAuC,GACjD,GAAG,6BAA6B,IAAI,4BAA4B,EAAE,CAAC;AACrE,MAAM,MAAM,qCAAqC,GAC/C,6BAA6B,CAAC;AAEhC,KAAK,+BAA+B,GAAG;IACrC,OAAO,EAAE,6BAA6B,CAAC;IACvC,GAAG,EAAE,4BAA4B,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,wBAAwB,SAC7B,uCAAuC,KAC5C,+BAYF,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,uCAAuC,EAC7C,UAAU,EAAE,MAAM,GACjB,MAAM,CAKR"}
@@ -1,43 +1,23 @@
1
1
  import { createSHA256Hash } from "./encryption/index.mjs";
2
2
  /**
3
3
  * The User Storage Endpoint requires a feature name and a namespace key.
4
- * Developers can provide additional features and keys by extending these types below.
5
- *
6
- * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.
7
- * This can be useful for features where keys are not deterministic (eg. accounts addresses).
4
+ * Any user storage path should be in the form of `feature.key`.
5
+ */
6
+ /**
7
+ * Helper object that contains the feature names used in the controllers and SDK.
8
+ * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.
8
9
  */
9
- const ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS';
10
10
  export const USER_STORAGE_FEATURE_NAMES = {
11
11
  notifications: 'notifications',
12
12
  accounts: 'accounts_v2',
13
- networks: 'networks',
14
13
  addressBook: 'addressBook',
15
14
  };
16
- export const USER_STORAGE_SCHEMA = {
17
- [USER_STORAGE_FEATURE_NAMES.notifications]: ['notification_settings'],
18
- [USER_STORAGE_FEATURE_NAMES.accounts]: [ALLOW_ARBITRARY_KEYS],
19
- [USER_STORAGE_FEATURE_NAMES.networks]: [ALLOW_ARBITRARY_KEYS],
20
- [USER_STORAGE_FEATURE_NAMES.addressBook]: [ALLOW_ARBITRARY_KEYS], // keyed by address_chainId
21
- };
22
- export const getFeatureAndKeyFromPath = (path, options = { validateAgainstSchema: true }) => {
15
+ export const getFeatureAndKeyFromPath = (path) => {
23
16
  const pathRegex = /^\w+\.\w+$/u;
24
17
  if (!pathRegex.test(path)) {
25
18
  throw new Error(`user-storage - path is not in the correct format. Correct format: 'feature.key'`);
26
19
  }
27
20
  const [feature, key] = path.split('.');
28
- if (options.validateAgainstSchema) {
29
- const featureToValidate = feature;
30
- const keyToValidate = key;
31
- if (!(featureToValidate in USER_STORAGE_SCHEMA)) {
32
- throw new Error(`user-storage - invalid feature provided: ${featureToValidate}. Valid features: ${Object.keys(USER_STORAGE_SCHEMA).join(', ')}`);
33
- }
34
- const validFeature = USER_STORAGE_SCHEMA[featureToValidate];
35
- if (!validFeature.includes(keyToValidate) &&
36
- !validFeature.includes(ALLOW_ARBITRARY_KEYS)) {
37
- const validKeys = USER_STORAGE_SCHEMA[featureToValidate].join(', ');
38
- throw new Error(`user-storage - invalid key provided for this feature: ${keyToValidate}. Valid keys: ${validKeys}`);
39
- }
40
- }
41
21
  return { feature, key };
42
22
  };
43
23
  /**
@@ -47,13 +27,10 @@ export const getFeatureAndKeyFromPath = (path, options = { validateAgainstSchema
47
27
  *
48
28
  * @param path - string in the form of `${feature}.${key}` that matches schema
49
29
  * @param storageKey - users storage key
50
- * @param options - options object
51
- * @param options.validateAgainstSchema - whether to validate the path against the schema.
52
- * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.
53
30
  * @returns path to store entry
54
31
  */
55
- export function createEntryPath(path, storageKey, options = { validateAgainstSchema: true }) {
56
- const { feature, key } = getFeatureAndKeyFromPath(path, options);
32
+ export function createEntryPath(path, storageKey) {
33
+ const { feature, key } = getFeatureAndKeyFromPath(path);
57
34
  const hashedKey = createSHA256Hash(key + storageKey);
58
35
  return `${feature}/${hashedKey}`;
59
36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b,4CAA4C,iBAAiB,qBAAqB,MAAM,CAAC,IAAI,CAC3F,mBAAmB,CACpB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACf,CAAC;SACH;QAED,MAAM,YAAY,GAAG,mBAAmB,CACtC,iBAAiB,CACG,CAAC;QAEvB,IACE,CAAC,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC;YACrC,CAAC,YAAY,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAC5C;YACA,MAAM,SAAS,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEpE,MAAM,IAAI,KAAK,CACb,yDAAyD,aAAa,iBAAiB,SAAS,EAAE,CACnG,CAAC;SACH;KACF;IAED,OAAO,EAAE,OAAO,EAAE,GAAG,EAEc,CAAC;AACtC,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,IAE2C,EAC3C,UAAkB,EAClB,UAEI,EAAE,qBAAqB,EAAE,IAAS,EAAE;IAExC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,wBAAwB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IAErD,OAAO,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Developers can provide additional features and keys by extending these types below.\n *\n * Adding ALLOW_ARBITRARY_KEYS as the first key in the array allows for any key to be used for this feature.\n * This can be useful for features where keys are not deterministic (eg. accounts addresses).\n */\nconst ALLOW_ARBITRARY_KEYS = 'ALLOW_ARBITRARY_KEYS' as const;\n\nexport const USER_STORAGE_FEATURE_NAMES = {\n notifications: 'notifications',\n accounts: 'accounts_v2',\n networks: 'networks',\n addressBook: 'addressBook',\n} as const;\n\nexport type UserStorageFeatureNames =\n (typeof USER_STORAGE_FEATURE_NAMES)[keyof typeof USER_STORAGE_FEATURE_NAMES];\n\nexport const USER_STORAGE_SCHEMA = {\n [USER_STORAGE_FEATURE_NAMES.notifications]: ['notification_settings'],\n [USER_STORAGE_FEATURE_NAMES.accounts]: [ALLOW_ARBITRARY_KEYS], // keyed by account addresses\n [USER_STORAGE_FEATURE_NAMES.networks]: [ALLOW_ARBITRARY_KEYS], // keyed by chains/networks\n [USER_STORAGE_FEATURE_NAMES.addressBook]: [ALLOW_ARBITRARY_KEYS], // keyed by address_chainId\n} as const;\n\ntype UserStorageSchema = typeof USER_STORAGE_SCHEMA;\n\nexport type UserStorageFeatureKeys<Feature extends UserStorageFeatureNames> =\n UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS\n ? string\n : UserStorageSchema[Feature][number];\n\ntype UserStorageFeatureAndKey = {\n feature: UserStorageFeatureNames;\n key: UserStorageFeatureKeys<UserStorageFeatureNames>;\n};\n\nexport type UserStoragePathWithFeatureOnly = UserStorageFeatureNames;\nexport type UserStoragePathWithFeatureAndKey = {\n [K in UserStorageFeatureNames]: `${K}.${UserStorageFeatureKeys<K>}`;\n}[UserStoragePathWithFeatureOnly];\n\n/**\n * The below types are mainly used for the SDK.\n * These exist so that the SDK can be used with arbitrary feature names and keys.\n *\n * We only type enforce feature names and keys when using UserStorageController.\n * This is done so we don't end up with magic strings within the applications.\n */\n\nexport type UserStorageGenericFeatureName = string;\nexport type UserStorageGenericFeatureKey = string;\nexport type UserStorageGenericPathWithFeatureAndKey =\n `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;\nexport type UserStorageGenericPathWithFeatureOnly =\n UserStorageGenericFeatureName;\n\ntype UserStorageGenericFeatureAndKey = {\n feature: UserStorageGenericFeatureName;\n key: UserStorageGenericFeatureKey;\n};\n\nexport const getFeatureAndKeyFromPath = <T extends boolean>(\n path: T extends true\n ? UserStoragePathWithFeatureAndKey\n : UserStorageGenericPathWithFeatureAndKey,\n options: {\n validateAgainstSchema: T;\n } = { validateAgainstSchema: true as T },\n): T extends true\n ? UserStorageFeatureAndKey\n : UserStorageGenericFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.');\n\n if (options.validateAgainstSchema) {\n const featureToValidate = feature as UserStorageFeatureNames;\n const keyToValidate = key as UserStorageFeatureKeys<\n typeof featureToValidate\n >;\n\n if (!(featureToValidate in USER_STORAGE_SCHEMA)) {\n throw new Error(\n `user-storage - invalid feature provided: ${featureToValidate}. Valid features: ${Object.keys(\n USER_STORAGE_SCHEMA,\n ).join(', ')}`,\n );\n }\n\n const validFeature = USER_STORAGE_SCHEMA[\n featureToValidate\n ] as readonly string[];\n\n if (\n !validFeature.includes(keyToValidate) &&\n !validFeature.includes(ALLOW_ARBITRARY_KEYS)\n ) {\n const validKeys = USER_STORAGE_SCHEMA[featureToValidate].join(', ');\n\n throw new Error(\n `user-storage - invalid key provided for this feature: ${keyToValidate}. Valid keys: ${validKeys}`,\n );\n }\n }\n\n return { feature, key } as T extends true\n ? UserStorageFeatureAndKey\n : UserStorageGenericFeatureAndKey;\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @param options - options object\n * @param options.validateAgainstSchema - whether to validate the path against the schema.\n * This defaults to true, and should only be set to false when using the SDK with arbitrary feature names and keys.\n * @returns path to store entry\n */\nexport function createEntryPath<T extends boolean>(\n path: T extends true\n ? UserStoragePathWithFeatureAndKey\n : UserStorageGenericPathWithFeatureAndKey,\n storageKey: string,\n options: {\n validateAgainstSchema: T;\n } = { validateAgainstSchema: true as T },\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path, options);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
1
+ {"version":3,"file":"storage-schema.mjs","sourceRoot":"","sources":["../../src/shared/storage-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,+BAAqB;AAEhD;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,aAAa,EAAE,eAAe;IAC9B,QAAQ,EAAE,aAAa;IACvB,WAAW,EAAE,aAAa;CAC3B,CAAC;AAcF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,IAA6C,EACZ,EAAE;IACnC,MAAM,SAAS,GAAG,aAAa,CAAC;IAEhC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;KACH;IAED,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEvC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAqC,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,IAA6C,EAC7C,UAAkB;IAElB,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,GAAG,UAAU,CAAC,CAAC;IAErD,OAAO,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Any user storage path should be in the form of `feature.key`.\n */\n\n/**\n * Helper object that contains the feature names used in the controllers and SDK.\n * Developers don't need to add new feature names to this object anymore, as the schema enforcement has been deprecated.\n */\nexport const USER_STORAGE_FEATURE_NAMES = {\n notifications: 'notifications',\n accounts: 'accounts_v2',\n addressBook: 'addressBook',\n};\n\nexport type UserStorageGenericFeatureName = string;\nexport type UserStorageGenericFeatureKey = string;\nexport type UserStorageGenericPathWithFeatureAndKey =\n `${UserStorageGenericFeatureName}.${UserStorageGenericFeatureKey}`;\nexport type UserStorageGenericPathWithFeatureOnly =\n UserStorageGenericFeatureName;\n\ntype UserStorageGenericFeatureAndKey = {\n feature: UserStorageGenericFeatureName;\n key: UserStorageGenericFeatureKey;\n};\n\nexport const getFeatureAndKeyFromPath = (\n path: UserStorageGenericPathWithFeatureAndKey,\n): UserStorageGenericFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.');\n\n return { feature, key } as UserStorageGenericFeatureAndKey;\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @returns path to store entry\n */\nexport function createEntryPath(\n path: UserStorageGenericPathWithFeatureAndKey,\n storageKey: string,\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `${feature}/${hashedKey}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/profile-sync-controller",
3
- "version": "19.0.0",
3
+ "version": "21.0.0",
4
4
  "description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -101,8 +101,8 @@
101
101
  },
102
102
  "dependencies": {
103
103
  "@metamask/base-controller": "^8.0.1",
104
- "@metamask/snaps-sdk": "^7.1.0",
105
- "@metamask/snaps-utils": "^9.4.0",
104
+ "@metamask/snaps-sdk": "^9.0.0",
105
+ "@metamask/snaps-utils": "^11.0.0",
106
106
  "@noble/ciphers": "^0.5.2",
107
107
  "@noble/hashes": "^1.4.0",
108
108
  "immer": "^9.0.6",
@@ -115,11 +115,10 @@
115
115
  "@metamask/accounts-controller": "^31.0.0",
116
116
  "@metamask/auto-changelog": "^3.4.4",
117
117
  "@metamask/keyring-api": "^18.0.0",
118
- "@metamask/keyring-controller": "^22.0.2",
118
+ "@metamask/keyring-controller": "^22.1.0",
119
119
  "@metamask/keyring-internal-api": "^6.2.0",
120
- "@metamask/network-controller": "^24.0.0",
121
120
  "@metamask/providers": "^22.1.0",
122
- "@metamask/snaps-controllers": "^12.3.1",
121
+ "@metamask/snaps-controllers": "^14.0.1",
123
122
  "@types/jest": "^27.4.1",
124
123
  "deepmerge": "^4.2.2",
125
124
  "ethers": "^6.12.0",
@@ -135,9 +134,8 @@
135
134
  "peerDependencies": {
136
135
  "@metamask/accounts-controller": "^31.0.0",
137
136
  "@metamask/keyring-controller": "^22.0.0",
138
- "@metamask/network-controller": "^24.0.0",
139
137
  "@metamask/providers": "^22.0.0",
140
- "@metamask/snaps-controllers": "^12.0.0",
138
+ "@metamask/snaps-controllers": "^14.0.0",
141
139
  "webextension-polyfill": "^0.10.0 || ^0.11.0 || ^0.12.0"
142
140
  },
143
141
  "engines": {
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBoundedNetworksToAdd = exports.calculateAvailableSpaceToAdd = exports.MAX_NETWORKS_SIZE = void 0;
4
- exports.MAX_NETWORKS_SIZE = 50;
5
- /**
6
- * Calculates the available space to add new networks
7
- * exported for testability.
8
- *
9
- * @param originalListSize - size of original list
10
- * @param maxSize - max size
11
- * @returns a positive number on the available space
12
- */
13
- const calculateAvailableSpaceToAdd = (originalListSize, maxSize) => {
14
- return Math.max(0, maxSize - originalListSize);
15
- };
16
- exports.calculateAvailableSpaceToAdd = calculateAvailableSpaceToAdd;
17
- /**
18
- * Returns a bounded number of networks to add (set by a max bound)
19
- * The items will be ordered to give determinism on items to append (not random)
20
- *
21
- * @param originalNetworks - The original list of network configurations.
22
- * @param networksToAdd - The list of network configurations to add.
23
- * @param maxSize - The maximum allowed size of the list. Defaults to MAX_NETWORKS_SIZE.
24
- * @returns The networks to add, sorted by chainId.
25
- */
26
- const getBoundedNetworksToAdd = (originalNetworks, networksToAdd, maxSize = exports.MAX_NETWORKS_SIZE) => {
27
- const availableSpace = (0, exports.calculateAvailableSpaceToAdd)(originalNetworks.length, maxSize);
28
- const numberOfNetworksToAppend = Math.min(availableSpace, networksToAdd.length);
29
- // Order and slice the networks to append
30
- // Ordering so we have some determinism on the order of items
31
- return networksToAdd
32
- .sort((a, b) => a.chainId.localeCompare(b.chainId))
33
- .slice(0, numberOfNetworksToAppend);
34
- };
35
- exports.getBoundedNetworksToAdd = getBoundedNetworksToAdd;
36
- //# sourceMappingURL=add-network-utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"add-network-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/add-network-utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAAG,EAAE,CAAC;AAEpC;;;;;;;GAOG;AACI,MAAM,4BAA4B,GAAG,CAC1C,gBAAwB,EACxB,OAAe,EACf,EAAE;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC,CAAC;AACjD,CAAC,CAAC;AALW,QAAA,4BAA4B,gCAKvC;AAEF;;;;;;;;GAQG;AACI,MAAM,uBAAuB,GAAG,CACrC,gBAAwC,EACxC,aAAqC,EACrC,OAAO,GAAG,yBAAiB,EAC3B,EAAE;IACF,MAAM,cAAc,GAAG,IAAA,oCAA4B,EACjD,gBAAgB,CAAC,MAAM,EACvB,OAAO,CACR,CAAC;IACF,MAAM,wBAAwB,GAAG,IAAI,CAAC,GAAG,CACvC,cAAc,EACd,aAAa,CAAC,MAAM,CACrB,CAAC;IAEF,yCAAyC;IACzC,6DAA6D;IAC7D,OAAO,aAAa;SACjB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SAClD,KAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;AACxC,CAAC,CAAC;AAnBW,QAAA,uBAAuB,2BAmBlC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\n\nexport const MAX_NETWORKS_SIZE = 50;\n\n/**\n * Calculates the available space to add new networks\n * exported for testability.\n *\n * @param originalListSize - size of original list\n * @param maxSize - max size\n * @returns a positive number on the available space\n */\nexport const calculateAvailableSpaceToAdd = (\n originalListSize: number,\n maxSize: number,\n) => {\n return Math.max(0, maxSize - originalListSize);\n};\n\n/**\n * Returns a bounded number of networks to add (set by a max bound)\n * The items will be ordered to give determinism on items to append (not random)\n *\n * @param originalNetworks - The original list of network configurations.\n * @param networksToAdd - The list of network configurations to add.\n * @param maxSize - The maximum allowed size of the list. Defaults to MAX_NETWORKS_SIZE.\n * @returns The networks to add, sorted by chainId.\n */\nexport const getBoundedNetworksToAdd = (\n originalNetworks: NetworkConfiguration[],\n networksToAdd: NetworkConfiguration[],\n maxSize = MAX_NETWORKS_SIZE,\n) => {\n const availableSpace = calculateAvailableSpaceToAdd(\n originalNetworks.length,\n maxSize,\n );\n const numberOfNetworksToAppend = Math.min(\n availableSpace,\n networksToAdd.length,\n );\n\n // Order and slice the networks to append\n // Ordering so we have some determinism on the order of items\n return networksToAdd\n .sort((a, b) => a.chainId.localeCompare(b.chainId))\n .slice(0, numberOfNetworksToAppend);\n};\n"]}