@fgv/ts-web-extras 5.1.0-4 → 5.1.0-41

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 (424) hide show
  1. package/dist/packlets/crypto-utils/browserCryptoProvider.js +413 -18
  2. package/dist/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
  3. package/dist/packlets/crypto-utils/idbPrivateKeyStorage.js +238 -0
  4. package/dist/packlets/crypto-utils/idbPrivateKeyStorage.js.map +1 -0
  5. package/dist/packlets/crypto-utils/index.js +13 -0
  6. package/dist/packlets/crypto-utils/index.js.map +1 -1
  7. package/dist/packlets/file-tree/directoryHandleStore.js.map +1 -1
  8. package/dist/packlets/file-tree/fileApiTreeAccessors.js +1 -1
  9. package/dist/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  10. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js +2 -2
  11. package/dist/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
  12. package/dist/packlets/file-tree/httpTreeAccessors.js +74 -44
  13. package/dist/packlets/file-tree/httpTreeAccessors.js.map +1 -1
  14. package/dist/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
  15. package/dist/packlets/helpers/fileTreeHelpers.js +1 -1
  16. package/dist/packlets/helpers/fileTreeHelpers.js.map +1 -1
  17. package/dist/ts-web-extras.d.ts +259 -10
  18. package/dist/tsdoc-metadata.json +1 -1
  19. package/eslint.config.js +32 -0
  20. package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts +145 -6
  21. package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts.map +1 -1
  22. package/lib/packlets/crypto-utils/browserCryptoProvider.js +412 -17
  23. package/lib/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
  24. package/lib/packlets/crypto-utils/idbPrivateKeyStorage.d.ts +87 -0
  25. package/lib/packlets/crypto-utils/idbPrivateKeyStorage.d.ts.map +1 -0
  26. package/lib/packlets/crypto-utils/idbPrivateKeyStorage.js +242 -0
  27. package/lib/packlets/crypto-utils/idbPrivateKeyStorage.js.map +1 -0
  28. package/lib/packlets/crypto-utils/index.d.ts +14 -0
  29. package/lib/packlets/crypto-utils/index.d.ts.map +1 -1
  30. package/lib/packlets/crypto-utils/index.js +14 -0
  31. package/lib/packlets/crypto-utils/index.js.map +1 -1
  32. package/lib/packlets/file-tree/directoryHandleStore.d.ts +2 -2
  33. package/lib/packlets/file-tree/directoryHandleStore.d.ts.map +1 -1
  34. package/lib/packlets/file-tree/directoryHandleStore.js.map +1 -1
  35. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts +2 -2
  36. package/lib/packlets/file-tree/fileApiTreeAccessors.d.ts.map +1 -1
  37. package/lib/packlets/file-tree/fileApiTreeAccessors.js +1 -1
  38. package/lib/packlets/file-tree/fileApiTreeAccessors.js.map +1 -1
  39. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.d.ts.map +1 -1
  40. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js +2 -2
  41. package/lib/packlets/file-tree/fileSystemAccessTreeAccessors.js.map +1 -1
  42. package/lib/packlets/file-tree/httpTreeAccessors.d.ts +6 -0
  43. package/lib/packlets/file-tree/httpTreeAccessors.d.ts.map +1 -1
  44. package/lib/packlets/file-tree/httpTreeAccessors.js +74 -44
  45. package/lib/packlets/file-tree/httpTreeAccessors.js.map +1 -1
  46. package/lib/packlets/file-tree/localStorageTreeAccessors.js.map +1 -1
  47. package/lib/packlets/helpers/fileTreeHelpers.d.ts +1 -1
  48. package/lib/packlets/helpers/fileTreeHelpers.d.ts.map +1 -1
  49. package/lib/packlets/helpers/fileTreeHelpers.js +6 -6
  50. package/lib/packlets/helpers/fileTreeHelpers.js.map +1 -1
  51. package/package.json +15 -14
  52. package/.rush/temp/44b0369e8112f3c6f4248af466a3f35ad626d9d7.tar.log +0 -237
  53. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +0 -55
  54. package/.rush/temp/operation/build/all.log +0 -55
  55. package/.rush/temp/operation/build/log-chunks.jsonl +0 -55
  56. package/.rush/temp/operation/build/state.json +0 -3
  57. package/.rush/temp/shrinkwrap-deps.json +0 -692
  58. package/CHANGELOG.md +0 -23
  59. package/config/api-extractor.json +0 -343
  60. package/config/jest.config.json +0 -19
  61. package/config/rig.json +0 -16
  62. package/config/typedoc.json +0 -7
  63. package/dist/test/mocks/idb-keyval.js +0 -6
  64. package/dist/test/mocks/idb-keyval.js.map +0 -1
  65. package/dist/test/setupTests.js +0 -74
  66. package/dist/test/setupTests.js.map +0 -1
  67. package/dist/test/unit/browserHashProvider.test.js +0 -140
  68. package/dist/test/unit/browserHashProvider.test.js.map +0 -1
  69. package/dist/test/unit/directoryHandleStore.test.js +0 -190
  70. package/dist/test/unit/directoryHandleStore.test.js.map +0 -1
  71. package/dist/test/unit/fileApiTreeAccessors.test.js +0 -1188
  72. package/dist/test/unit/fileApiTreeAccessors.test.js.map +0 -1
  73. package/dist/test/unit/fileApiTypes.test.js +0 -472
  74. package/dist/test/unit/fileApiTypes.test.js.map +0 -1
  75. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +0 -622
  76. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +0 -1
  77. package/dist/test/unit/fileTreeHelpers.test.js +0 -590
  78. package/dist/test/unit/fileTreeHelpers.test.js.map +0 -1
  79. package/dist/test/unit/httpTreeAccessors.test.js +0 -1229
  80. package/dist/test/unit/httpTreeAccessors.test.js.map +0 -1
  81. package/dist/test/unit/localStorageTreeAccessors.test.js +0 -812
  82. package/dist/test/unit/localStorageTreeAccessors.test.js.map +0 -1
  83. package/dist/test/unit/urlParams.test.js +0 -393
  84. package/dist/test/unit/urlParams.test.js.map +0 -1
  85. package/dist/test/utils/fileSystemAccessMocks.js +0 -271
  86. package/dist/test/utils/fileSystemAccessMocks.js.map +0 -1
  87. package/dist/test/utils/testHelpers.js +0 -124
  88. package/dist/test/utils/testHelpers.js.map +0 -1
  89. package/docs/CryptoUtils/README.md +0 -60
  90. package/docs/CryptoUtils/classes/BrowserCryptoProvider.decrypt.md +0 -27
  91. package/docs/CryptoUtils/classes/BrowserCryptoProvider.deriveKey.md +0 -26
  92. package/docs/CryptoUtils/classes/BrowserCryptoProvider.encrypt.md +0 -25
  93. package/docs/CryptoUtils/classes/BrowserCryptoProvider.fromBase64.md +0 -24
  94. package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateKey.md +0 -17
  95. package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateRandomBytes.md +0 -24
  96. package/docs/CryptoUtils/classes/BrowserCryptoProvider.md +0 -151
  97. package/docs/CryptoUtils/classes/BrowserCryptoProvider.toBase64.md +0 -24
  98. package/docs/CryptoUtils/classes/BrowserHashProvider.hashParts.md +0 -26
  99. package/docs/CryptoUtils/classes/BrowserHashProvider.hashString.md +0 -25
  100. package/docs/CryptoUtils/classes/BrowserHashProvider.md +0 -81
  101. package/docs/CryptoUtils/functions/createBrowserCryptoProvider.md +0 -12
  102. package/docs/FileTreeHelpers/README.md +0 -85
  103. package/docs/FileTreeHelpers/functions/extractFileListMetadata.md +0 -11
  104. package/docs/FileTreeHelpers/functions/extractFileMetadata.md +0 -11
  105. package/docs/FileTreeHelpers/functions/fromDirectoryUpload.md +0 -12
  106. package/docs/FileTreeHelpers/functions/fromFileList.md +0 -12
  107. package/docs/FileTreeHelpers/functions/getOriginalFile.md +0 -11
  108. package/docs/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +0 -9
  109. package/docs/README.md +0 -524
  110. package/docs/classes/BrowserCryptoProvider.decrypt.md +0 -27
  111. package/docs/classes/BrowserCryptoProvider.deriveKey.md +0 -26
  112. package/docs/classes/BrowserCryptoProvider.encrypt.md +0 -25
  113. package/docs/classes/BrowserCryptoProvider.fromBase64.md +0 -24
  114. package/docs/classes/BrowserCryptoProvider.generateKey.md +0 -17
  115. package/docs/classes/BrowserCryptoProvider.generateRandomBytes.md +0 -24
  116. package/docs/classes/BrowserCryptoProvider.md +0 -151
  117. package/docs/classes/BrowserCryptoProvider.toBase64.md +0 -24
  118. package/docs/classes/BrowserHashProvider.hashParts.md +0 -26
  119. package/docs/classes/BrowserHashProvider.hashString.md +0 -25
  120. package/docs/classes/BrowserHashProvider.md +0 -81
  121. package/docs/classes/DirectoryHandleStore.getAll.md +0 -17
  122. package/docs/classes/DirectoryHandleStore.getAllLabels.md +0 -17
  123. package/docs/classes/DirectoryHandleStore.load.md +0 -24
  124. package/docs/classes/DirectoryHandleStore.md +0 -120
  125. package/docs/classes/DirectoryHandleStore.remove.md +0 -24
  126. package/docs/classes/DirectoryHandleStore.save.md +0 -25
  127. package/docs/classes/FileApiTreeAccessors.create.md +0 -25
  128. package/docs/classes/FileApiTreeAccessors.createFromHttp.md +0 -24
  129. package/docs/classes/FileApiTreeAccessors.createFromLocalStorage.md +0 -25
  130. package/docs/classes/FileApiTreeAccessors.createPersistent.md +0 -26
  131. package/docs/classes/FileApiTreeAccessors.createPersistentFromFile.md +0 -27
  132. package/docs/classes/FileApiTreeAccessors.extractFileMetadata.md +0 -24
  133. package/docs/classes/FileApiTreeAccessors.fromDirectoryUpload.md +0 -25
  134. package/docs/classes/FileApiTreeAccessors.fromFileList.md +0 -25
  135. package/docs/classes/FileApiTreeAccessors.getOriginalFile.md +0 -27
  136. package/docs/classes/FileApiTreeAccessors.md +0 -172
  137. package/docs/classes/FileSystemAccessTreeAccessors.deleteFile.md +0 -22
  138. package/docs/classes/FileSystemAccessTreeAccessors.fileIsMutable.md +0 -22
  139. package/docs/classes/FileSystemAccessTreeAccessors.fromDirectoryHandle.md +0 -25
  140. package/docs/classes/FileSystemAccessTreeAccessors.fromFileHandle.md +0 -29
  141. package/docs/classes/FileSystemAccessTreeAccessors.getDirtyPaths.md +0 -15
  142. package/docs/classes/FileSystemAccessTreeAccessors.isDirty.md +0 -15
  143. package/docs/classes/FileSystemAccessTreeAccessors.md +0 -275
  144. package/docs/classes/FileSystemAccessTreeAccessors.saveFileContents.md +0 -23
  145. package/docs/classes/FileSystemAccessTreeAccessors.syncToDisk.md +0 -15
  146. package/docs/classes/HttpTreeAccessors.deleteFile.md +0 -22
  147. package/docs/classes/HttpTreeAccessors.fileIsMutable.md +0 -24
  148. package/docs/classes/HttpTreeAccessors.fromHttp.md +0 -24
  149. package/docs/classes/HttpTreeAccessors.getDirtyPaths.md +0 -17
  150. package/docs/classes/HttpTreeAccessors.isDirty.md +0 -17
  151. package/docs/classes/HttpTreeAccessors.md +0 -261
  152. package/docs/classes/HttpTreeAccessors.saveFileContents.md +0 -25
  153. package/docs/classes/HttpTreeAccessors.syncToDisk.md +0 -22
  154. package/docs/classes/LocalStorageTreeAccessors.deleteFile.md +0 -24
  155. package/docs/classes/LocalStorageTreeAccessors.fileIsMutable.md +0 -24
  156. package/docs/classes/LocalStorageTreeAccessors.fromStorage.md +0 -25
  157. package/docs/classes/LocalStorageTreeAccessors.getDirtyPaths.md +0 -17
  158. package/docs/classes/LocalStorageTreeAccessors.isDirty.md +0 -17
  159. package/docs/classes/LocalStorageTreeAccessors.md +0 -270
  160. package/docs/classes/LocalStorageTreeAccessors.saveFileContents.md +0 -25
  161. package/docs/classes/LocalStorageTreeAccessors.syncToDisk.md +0 -17
  162. package/docs/functions/createBrowserCryptoProvider.md +0 -12
  163. package/docs/functions/exportAsJson.md +0 -12
  164. package/docs/functions/exportUsingFileSystemAPI.md +0 -11
  165. package/docs/functions/extractDirectoryPath.md +0 -13
  166. package/docs/functions/extractFileListMetadata.md +0 -11
  167. package/docs/functions/extractFileMetadata.md +0 -11
  168. package/docs/functions/fromDirectoryUpload.md +0 -12
  169. package/docs/functions/fromFileList.md +0 -12
  170. package/docs/functions/getOriginalFile.md +0 -11
  171. package/docs/functions/isDirectoryHandle.md +0 -11
  172. package/docs/functions/isFileHandle.md +0 -11
  173. package/docs/functions/isFilePath.md +0 -11
  174. package/docs/functions/parseContextFilter.md +0 -12
  175. package/docs/functions/parseQualifierDefaults.md +0 -12
  176. package/docs/functions/parseResourceTypes.md +0 -12
  177. package/docs/functions/parseUrlParameters.md +0 -11
  178. package/docs/functions/safeShowDirectoryPicker.md +0 -11
  179. package/docs/functions/safeShowOpenFilePicker.md +0 -11
  180. package/docs/functions/safeShowSaveFilePicker.md +0 -11
  181. package/docs/functions/supportsFileSystemAccess.md +0 -11
  182. package/docs/interfaces/FilePickerAcceptType.accept.md +0 -9
  183. package/docs/interfaces/FilePickerAcceptType.description.md +0 -9
  184. package/docs/interfaces/FilePickerAcceptType.md +0 -61
  185. package/docs/interfaces/FileSystemCreateWritableOptions.keepExistingData.md +0 -9
  186. package/docs/interfaces/FileSystemCreateWritableOptions.md +0 -44
  187. package/docs/interfaces/FileSystemDirectoryHandle._asyncIterator_.md +0 -13
  188. package/docs/interfaces/FileSystemDirectoryHandle.entries.md +0 -13
  189. package/docs/interfaces/FileSystemDirectoryHandle.getDirectoryHandle.md +0 -21
  190. package/docs/interfaces/FileSystemDirectoryHandle.getFileHandle.md +0 -21
  191. package/docs/interfaces/FileSystemDirectoryHandle.keys.md +0 -13
  192. package/docs/interfaces/FileSystemDirectoryHandle.kind.md +0 -9
  193. package/docs/interfaces/FileSystemDirectoryHandle.md +0 -224
  194. package/docs/interfaces/FileSystemDirectoryHandle.removeEntry.md +0 -21
  195. package/docs/interfaces/FileSystemDirectoryHandle.resolve.md +0 -20
  196. package/docs/interfaces/FileSystemDirectoryHandle.values.md +0 -13
  197. package/docs/interfaces/FileSystemFileHandle.createWritable.md +0 -20
  198. package/docs/interfaces/FileSystemFileHandle.getFile.md +0 -13
  199. package/docs/interfaces/FileSystemFileHandle.kind.md +0 -9
  200. package/docs/interfaces/FileSystemFileHandle.md +0 -146
  201. package/docs/interfaces/FileSystemGetDirectoryOptions.create.md +0 -9
  202. package/docs/interfaces/FileSystemGetDirectoryOptions.md +0 -44
  203. package/docs/interfaces/FileSystemGetFileOptions.create.md +0 -9
  204. package/docs/interfaces/FileSystemGetFileOptions.md +0 -44
  205. package/docs/interfaces/FileSystemHandle.isSameEntry.md +0 -20
  206. package/docs/interfaces/FileSystemHandle.kind.md +0 -9
  207. package/docs/interfaces/FileSystemHandle.md +0 -118
  208. package/docs/interfaces/FileSystemHandle.name.md +0 -9
  209. package/docs/interfaces/FileSystemHandle.queryPermission.md +0 -20
  210. package/docs/interfaces/FileSystemHandle.requestPermission.md +0 -20
  211. package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +0 -44
  212. package/docs/interfaces/FileSystemHandlePermissionDescriptor.mode.md +0 -9
  213. package/docs/interfaces/FileSystemRemoveOptions.md +0 -44
  214. package/docs/interfaces/FileSystemRemoveOptions.recursive.md +0 -9
  215. package/docs/interfaces/FileSystemWritableFileStream.md +0 -142
  216. package/docs/interfaces/FileSystemWritableFileStream.seek.md +0 -20
  217. package/docs/interfaces/FileSystemWritableFileStream.truncate.md +0 -20
  218. package/docs/interfaces/FileSystemWritableFileStream.write.md +0 -20
  219. package/docs/interfaces/IDirectoryHandleTreeInitializer.dirHandles.md +0 -9
  220. package/docs/interfaces/IDirectoryHandleTreeInitializer.md +0 -78
  221. package/docs/interfaces/IDirectoryHandleTreeInitializer.nonRecursive.md +0 -9
  222. package/docs/interfaces/IDirectoryHandleTreeInitializer.prefix.md +0 -9
  223. package/docs/interfaces/IFileHandleTreeInitializer.fileHandles.md +0 -9
  224. package/docs/interfaces/IFileHandleTreeInitializer.md +0 -61
  225. package/docs/interfaces/IFileHandleTreeInitializer.prefix.md +0 -9
  226. package/docs/interfaces/IFileListTreeInitializer.fileList.md +0 -9
  227. package/docs/interfaces/IFileListTreeInitializer.md +0 -44
  228. package/docs/interfaces/IFileMetadata.lastModified.md +0 -9
  229. package/docs/interfaces/IFileMetadata.md +0 -112
  230. package/docs/interfaces/IFileMetadata.name.md +0 -9
  231. package/docs/interfaces/IFileMetadata.path.md +0 -9
  232. package/docs/interfaces/IFileMetadata.size.md +0 -9
  233. package/docs/interfaces/IFileMetadata.type.md +0 -9
  234. package/docs/interfaces/IFileSystemAccessTreeParams.autoSync.md +0 -12
  235. package/docs/interfaces/IFileSystemAccessTreeParams.filePath.md +0 -13
  236. package/docs/interfaces/IFileSystemAccessTreeParams.logger.md +0 -11
  237. package/docs/interfaces/IFileSystemAccessTreeParams.md +0 -148
  238. package/docs/interfaces/IFileSystemAccessTreeParams.requireWritePermission.md +0 -13
  239. package/docs/interfaces/IFsAccessApis.md +0 -62
  240. package/docs/interfaces/IFsAccessApis.showDirectoryPicker.md +0 -20
  241. package/docs/interfaces/IFsAccessApis.showOpenFilePicker.md +0 -20
  242. package/docs/interfaces/IFsAccessApis.showSaveFilePicker.md +0 -20
  243. package/docs/interfaces/IHttpTreeParams.autoSync.md +0 -9
  244. package/docs/interfaces/IHttpTreeParams.baseUrl.md +0 -9
  245. package/docs/interfaces/IHttpTreeParams.fetchImpl.md +0 -9
  246. package/docs/interfaces/IHttpTreeParams.logger.md +0 -9
  247. package/docs/interfaces/IHttpTreeParams.md +0 -182
  248. package/docs/interfaces/IHttpTreeParams.namespace.md +0 -9
  249. package/docs/interfaces/IHttpTreeParams.userId.md +0 -9
  250. package/docs/interfaces/ILocalStorageTreeParams.autoSync.md +0 -12
  251. package/docs/interfaces/ILocalStorageTreeParams.md +0 -131
  252. package/docs/interfaces/ILocalStorageTreeParams.pathToKeyMap.md +0 -13
  253. package/docs/interfaces/ILocalStorageTreeParams.storage.md +0 -12
  254. package/docs/interfaces/IUrlConfigOptions.config.md +0 -11
  255. package/docs/interfaces/IUrlConfigOptions.configStartDir.md +0 -11
  256. package/docs/interfaces/IUrlConfigOptions.contextFilter.md +0 -11
  257. package/docs/interfaces/IUrlConfigOptions.input.md +0 -11
  258. package/docs/interfaces/IUrlConfigOptions.inputStartDir.md +0 -11
  259. package/docs/interfaces/IUrlConfigOptions.interactive.md +0 -11
  260. package/docs/interfaces/IUrlConfigOptions.loadZip.md +0 -11
  261. package/docs/interfaces/IUrlConfigOptions.maxDistance.md +0 -11
  262. package/docs/interfaces/IUrlConfigOptions.md +0 -248
  263. package/docs/interfaces/IUrlConfigOptions.qualifierDefaults.md +0 -11
  264. package/docs/interfaces/IUrlConfigOptions.reduceQualifiers.md +0 -11
  265. package/docs/interfaces/IUrlConfigOptions.resourceTypes.md +0 -11
  266. package/docs/interfaces/IUrlConfigOptions.zipFile.md +0 -11
  267. package/docs/interfaces/IUrlConfigOptions.zipPath.md +0 -11
  268. package/docs/interfaces/ShowDirectoryPickerOptions.id.md +0 -9
  269. package/docs/interfaces/ShowDirectoryPickerOptions.md +0 -78
  270. package/docs/interfaces/ShowDirectoryPickerOptions.mode.md +0 -9
  271. package/docs/interfaces/ShowDirectoryPickerOptions.startIn.md +0 -9
  272. package/docs/interfaces/ShowOpenFilePickerOptions.excludeAcceptAllOption.md +0 -9
  273. package/docs/interfaces/ShowOpenFilePickerOptions.id.md +0 -9
  274. package/docs/interfaces/ShowOpenFilePickerOptions.md +0 -112
  275. package/docs/interfaces/ShowOpenFilePickerOptions.multiple.md +0 -9
  276. package/docs/interfaces/ShowOpenFilePickerOptions.startIn.md +0 -9
  277. package/docs/interfaces/ShowOpenFilePickerOptions.types.md +0 -9
  278. package/docs/interfaces/ShowSaveFilePickerOptions.excludeAcceptAllOption.md +0 -9
  279. package/docs/interfaces/ShowSaveFilePickerOptions.id.md +0 -9
  280. package/docs/interfaces/ShowSaveFilePickerOptions.md +0 -112
  281. package/docs/interfaces/ShowSaveFilePickerOptions.startIn.md +0 -9
  282. package/docs/interfaces/ShowSaveFilePickerOptions.suggestedName.md +0 -9
  283. package/docs/interfaces/ShowSaveFilePickerOptions.types.md +0 -9
  284. package/docs/type-aliases/TreeInitializer.md +0 -11
  285. package/docs/type-aliases/WellKnownDirectory.md +0 -11
  286. package/docs/type-aliases/WindowWithFsAccess.md +0 -11
  287. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +0 -9
  288. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +0 -9
  289. package/docs/variables/defaultFileApiTreeInitParams.md +0 -9
  290. package/etc/ts-web-extras.api.md +0 -433
  291. package/lib/test/mocks/idb-keyval.d.ts +0 -6
  292. package/lib/test/mocks/idb-keyval.d.ts.map +0 -1
  293. package/lib/test/mocks/idb-keyval.js +0 -9
  294. package/lib/test/mocks/idb-keyval.js.map +0 -1
  295. package/lib/test/setupTests.d.ts +0 -2
  296. package/lib/test/setupTests.d.ts.map +0 -1
  297. package/lib/test/setupTests.js +0 -76
  298. package/lib/test/setupTests.js.map +0 -1
  299. package/lib/test/unit/browserHashProvider.test.d.ts +0 -2
  300. package/lib/test/unit/browserHashProvider.test.d.ts.map +0 -1
  301. package/lib/test/unit/browserHashProvider.test.js +0 -142
  302. package/lib/test/unit/browserHashProvider.test.js.map +0 -1
  303. package/lib/test/unit/directoryHandleStore.test.d.ts +0 -2
  304. package/lib/test/unit/directoryHandleStore.test.d.ts.map +0 -1
  305. package/lib/test/unit/directoryHandleStore.test.js +0 -192
  306. package/lib/test/unit/directoryHandleStore.test.js.map +0 -1
  307. package/lib/test/unit/fileApiTreeAccessors.test.d.ts +0 -2
  308. package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +0 -1
  309. package/lib/test/unit/fileApiTreeAccessors.test.js +0 -1190
  310. package/lib/test/unit/fileApiTreeAccessors.test.js.map +0 -1
  311. package/lib/test/unit/fileApiTypes.test.d.ts +0 -2
  312. package/lib/test/unit/fileApiTypes.test.d.ts.map +0 -1
  313. package/lib/test/unit/fileApiTypes.test.js +0 -474
  314. package/lib/test/unit/fileApiTypes.test.js.map +0 -1
  315. package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts +0 -2
  316. package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts.map +0 -1
  317. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +0 -624
  318. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +0 -1
  319. package/lib/test/unit/fileTreeHelpers.test.d.ts +0 -2
  320. package/lib/test/unit/fileTreeHelpers.test.d.ts.map +0 -1
  321. package/lib/test/unit/fileTreeHelpers.test.js +0 -592
  322. package/lib/test/unit/fileTreeHelpers.test.js.map +0 -1
  323. package/lib/test/unit/httpTreeAccessors.test.d.ts +0 -2
  324. package/lib/test/unit/httpTreeAccessors.test.d.ts.map +0 -1
  325. package/lib/test/unit/httpTreeAccessors.test.js +0 -1231
  326. package/lib/test/unit/httpTreeAccessors.test.js.map +0 -1
  327. package/lib/test/unit/localStorageTreeAccessors.test.d.ts +0 -2
  328. package/lib/test/unit/localStorageTreeAccessors.test.d.ts.map +0 -1
  329. package/lib/test/unit/localStorageTreeAccessors.test.js +0 -814
  330. package/lib/test/unit/localStorageTreeAccessors.test.js.map +0 -1
  331. package/lib/test/unit/urlParams.test.d.ts +0 -2
  332. package/lib/test/unit/urlParams.test.d.ts.map +0 -1
  333. package/lib/test/unit/urlParams.test.js +0 -395
  334. package/lib/test/unit/urlParams.test.js.map +0 -1
  335. package/lib/test/utils/fileSystemAccessMocks.d.ts +0 -53
  336. package/lib/test/utils/fileSystemAccessMocks.d.ts.map +0 -1
  337. package/lib/test/utils/fileSystemAccessMocks.js +0 -277
  338. package/lib/test/utils/fileSystemAccessMocks.js.map +0 -1
  339. package/lib/test/utils/testHelpers.d.ts +0 -51
  340. package/lib/test/utils/testHelpers.d.ts.map +0 -1
  341. package/lib/test/utils/testHelpers.js +0 -133
  342. package/lib/test/utils/testHelpers.js.map +0 -1
  343. package/rush-logs/ts-web-extras.build.cache.log +0 -3
  344. package/rush-logs/ts-web-extras.build.log +0 -55
  345. package/src/index.browser.ts +0 -24
  346. package/src/index.ts +0 -47
  347. package/src/packlets/crypto-utils/browserCryptoProvider.ts +0 -311
  348. package/src/packlets/crypto-utils/browserHashProvider.ts +0 -73
  349. package/src/packlets/crypto-utils/index.ts +0 -29
  350. package/src/packlets/file-api-types/index.ts +0 -366
  351. package/src/packlets/file-tree/directoryHandleStore.ts +0 -136
  352. package/src/packlets/file-tree/fileApiTreeAccessors.ts +0 -528
  353. package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +0 -519
  354. package/src/packlets/file-tree/httpTreeAccessors.ts +0 -448
  355. package/src/packlets/file-tree/index.ts +0 -32
  356. package/src/packlets/file-tree/localStorageTreeAccessors.ts +0 -430
  357. package/src/packlets/helpers/fileTreeHelpers.ts +0 -107
  358. package/src/packlets/helpers/index.ts +0 -28
  359. package/src/packlets/url-utils/index.ts +0 -28
  360. package/src/packlets/url-utils/urlParams.ts +0 -245
  361. package/src/test/mocks/idb-keyval.ts +0 -5
  362. package/src/test/setupTests.ts +0 -87
  363. package/src/test/unit/browserHashProvider.test.ts +0 -155
  364. package/src/test/unit/browserHashProvider.test.ts.bak +0 -376
  365. package/src/test/unit/directoryHandleStore.test.ts +0 -251
  366. package/src/test/unit/fileApiTreeAccessors.test.ts +0 -1387
  367. package/src/test/unit/fileApiTypes.test.ts +0 -587
  368. package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +0 -885
  369. package/src/test/unit/fileTreeHelpers.test.ts +0 -694
  370. package/src/test/unit/httpTreeAccessors.test.ts +0 -1571
  371. package/src/test/unit/localStorageTreeAccessors.test.ts +0 -1014
  372. package/src/test/unit/urlParams.test.ts +0 -464
  373. package/src/test/utils/fileSystemAccessMocks.ts +0 -353
  374. package/src/test/utils/testHelpers.ts +0 -155
  375. package/temp/build/typescript/ts_8nwakTlr.json +0 -1
  376. package/temp/coverage/base.css +0 -224
  377. package/temp/coverage/block-navigation.js +0 -87
  378. package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +0 -1018
  379. package/temp/coverage/crypto-utils/browserHashProvider.ts.html +0 -304
  380. package/temp/coverage/crypto-utils/index.html +0 -131
  381. package/temp/coverage/favicon.png +0 -0
  382. package/temp/coverage/file-tree/directoryHandleStore.ts.html +0 -493
  383. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +0 -1669
  384. package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +0 -1642
  385. package/temp/coverage/file-tree/httpTreeAccessors.ts.html +0 -1429
  386. package/temp/coverage/file-tree/index.html +0 -176
  387. package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +0 -1375
  388. package/temp/coverage/helpers/fileTreeHelpers.ts.html +0 -406
  389. package/temp/coverage/helpers/index.html +0 -116
  390. package/temp/coverage/index.html +0 -161
  391. package/temp/coverage/lcov-report/base.css +0 -224
  392. package/temp/coverage/lcov-report/block-navigation.js +0 -87
  393. package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +0 -1018
  394. package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +0 -304
  395. package/temp/coverage/lcov-report/crypto-utils/index.html +0 -131
  396. package/temp/coverage/lcov-report/favicon.png +0 -0
  397. package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +0 -493
  398. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +0 -1669
  399. package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +0 -1642
  400. package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +0 -1429
  401. package/temp/coverage/lcov-report/file-tree/index.html +0 -176
  402. package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +0 -1375
  403. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +0 -406
  404. package/temp/coverage/lcov-report/helpers/index.html +0 -116
  405. package/temp/coverage/lcov-report/index.html +0 -161
  406. package/temp/coverage/lcov-report/prettify.css +0 -1
  407. package/temp/coverage/lcov-report/prettify.js +0 -2
  408. package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  409. package/temp/coverage/lcov-report/sorter.js +0 -210
  410. package/temp/coverage/lcov-report/url-utils/index.html +0 -116
  411. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +0 -820
  412. package/temp/coverage/lcov.info +0 -3597
  413. package/temp/coverage/prettify.css +0 -1
  414. package/temp/coverage/prettify.js +0 -2
  415. package/temp/coverage/sort-arrow-sprite.png +0 -0
  416. package/temp/coverage/sorter.js +0 -210
  417. package/temp/coverage/url-utils/index.html +0 -116
  418. package/temp/coverage/url-utils/urlParams.ts.html +0 -820
  419. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  420. package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/7c/package_7c16afc8299e635d80273763175c7a50 +0 -53
  421. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
  422. package/temp/ts-web-extras.api.json +0 -8850
  423. package/temp/ts-web-extras.api.md +0 -433
  424. package/tsconfig.json +0 -7
@@ -21,10 +21,9 @@
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.BrowserCryptoProvider = void 0;
23
23
  exports.createBrowserCryptoProvider = createBrowserCryptoProvider;
24
- /* c8 ignore start - Browser-only implementation cannot be tested in Node.js environment */
25
24
  const ts_utils_1 = require("@fgv/ts-utils");
26
25
  const ts_extras_1 = require("@fgv/ts-extras");
27
- const CryptoConstants = ts_extras_1.CryptoUtils.Constants;
26
+ /* c8 ignore start - Used only by browser-only methods that cannot be tested in Node.js environment */
28
27
  /**
29
28
  * Extracts an `ArrayBuffer` from a Uint8Array, handling the potential SharedArrayBuffer case.
30
29
  * @param arr - The Uint8Array to extract from
@@ -36,6 +35,24 @@ function toArrayBuffer(arr) {
36
35
  new Uint8Array(buffer).set(arr);
37
36
  return buffer;
38
37
  }
38
+ /* c8 ignore stop */
39
+ /**
40
+ * Returns a fresh Uint8Array view over a non-shared ArrayBuffer copy of `arr`.
41
+ * Used by {@link BrowserCryptoProvider.wrapBytes | wrapBytes} and
42
+ * {@link BrowserCryptoProvider.unwrapBytes | unwrapBytes}: Node 20's
43
+ * webcrypto.subtle rejects raw `ArrayBuffer` for several `BufferSource`
44
+ * parameters with "is not instance of ArrayBuffer, Buffer, TypedArray, or
45
+ * DataView" even though `ArrayBuffer` should be valid per the spec; a
46
+ * TypedArray view is accepted on Node 20+ and on browsers, and the explicit
47
+ * `Uint8Array<ArrayBuffer>` return type also satisfies TypeScript's `BufferSource`
48
+ * (which excludes the `SharedArrayBuffer` branch of `Uint8Array`'s buffer type).
49
+ */
50
+ function toBufferView(arr) {
51
+ const buffer = new ArrayBuffer(arr.byteLength);
52
+ const view = new Uint8Array(buffer);
53
+ view.set(arr);
54
+ return view;
55
+ }
39
56
  /**
40
57
  * Browser implementation of `ICryptoProvider` using the Web Crypto API.
41
58
  * Uses AES-256-GCM for authenticated encryption.
@@ -46,6 +63,7 @@ function toArrayBuffer(arr) {
46
63
  * @public
47
64
  */
48
65
  class BrowserCryptoProvider {
66
+ /* c8 ignore start - Existing browser-only methods cannot be tested in Node.js environment */
49
67
  /**
50
68
  * Creates a new {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider}.
51
69
  * @param cryptoApi - Optional Crypto instance (defaults to globalThis.crypto)
@@ -71,12 +89,12 @@ class BrowserCryptoProvider {
71
89
  * @returns `Success` with encryption result, or `Failure` with an error.
72
90
  */
73
91
  async encrypt(plaintext, key) {
74
- if (key.length !== CryptoConstants.AES_256_KEY_SIZE) {
75
- return ts_utils_1.Failure.with(`Key must be ${CryptoConstants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
92
+ if (key.length !== ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE) {
93
+ return ts_utils_1.Failure.with(`Key must be ${ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
76
94
  }
77
95
  try {
78
96
  // Generate random IV
79
- const iv = this._crypto.getRandomValues(new Uint8Array(CryptoConstants.GCM_IV_SIZE));
97
+ const iv = this._crypto.getRandomValues(new Uint8Array(ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE));
80
98
  // Import the key
81
99
  const cryptoKey = await this._crypto.subtle.importKey('raw', toArrayBuffer(key), { name: 'AES-GCM' }, false, ['encrypt']);
82
100
  // Encode plaintext to bytes
@@ -86,12 +104,12 @@ class BrowserCryptoProvider {
86
104
  const encryptedWithTag = await this._crypto.subtle.encrypt({
87
105
  name: 'AES-GCM',
88
106
  iv: iv,
89
- tagLength: CryptoConstants.GCM_AUTH_TAG_SIZE * 8 // bits
107
+ tagLength: ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE * 8 // bits
90
108
  }, cryptoKey, plaintextBytes);
91
109
  // Split ciphertext and auth tag (auth tag is last 16 bytes)
92
110
  const encryptedArray = new Uint8Array(encryptedWithTag);
93
- const encryptedData = encryptedArray.slice(0, encryptedArray.length - CryptoConstants.GCM_AUTH_TAG_SIZE);
94
- const authTag = encryptedArray.slice(encryptedArray.length - CryptoConstants.GCM_AUTH_TAG_SIZE);
111
+ const encryptedData = encryptedArray.slice(0, encryptedArray.length - ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE);
112
+ const authTag = encryptedArray.slice(encryptedArray.length - ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE);
95
113
  return ts_utils_1.Success.with({
96
114
  iv,
97
115
  authTag,
@@ -112,14 +130,14 @@ class BrowserCryptoProvider {
112
130
  * @returns `Success` with decrypted UTF-8 string, or `Failure` with an error.
113
131
  */
114
132
  async decrypt(encryptedData, key, iv, authTag) {
115
- if (key.length !== CryptoConstants.AES_256_KEY_SIZE) {
116
- return ts_utils_1.Failure.with(`Key must be ${CryptoConstants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
133
+ if (key.length !== ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE) {
134
+ return ts_utils_1.Failure.with(`Key must be ${ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
117
135
  }
118
- if (iv.length !== CryptoConstants.GCM_IV_SIZE) {
119
- return ts_utils_1.Failure.with(`IV must be ${CryptoConstants.GCM_IV_SIZE} bytes, got ${iv.length}`);
136
+ if (iv.length !== ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE) {
137
+ return ts_utils_1.Failure.with(`IV must be ${ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE} bytes, got ${iv.length}`);
120
138
  }
121
- if (authTag.length !== CryptoConstants.GCM_AUTH_TAG_SIZE) {
122
- return ts_utils_1.Failure.with(`Auth tag must be ${CryptoConstants.GCM_AUTH_TAG_SIZE} bytes, got ${authTag.length}`);
139
+ if (authTag.length !== ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE) {
140
+ return ts_utils_1.Failure.with(`Auth tag must be ${ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE} bytes, got ${authTag.length}`);
123
141
  }
124
142
  try {
125
143
  // Import the key
@@ -132,7 +150,7 @@ class BrowserCryptoProvider {
132
150
  const decrypted = await this._crypto.subtle.decrypt({
133
151
  name: 'AES-GCM',
134
152
  iv: toArrayBuffer(iv),
135
- tagLength: CryptoConstants.GCM_AUTH_TAG_SIZE * 8 // bits
153
+ tagLength: ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE * 8 // bits
136
154
  }, cryptoKey, encryptedWithTag);
137
155
  // Decode to string
138
156
  const decoder = new TextDecoder();
@@ -149,7 +167,7 @@ class BrowserCryptoProvider {
149
167
  */
150
168
  async generateKey() {
151
169
  try {
152
- return ts_utils_1.Success.with(this._crypto.getRandomValues(new Uint8Array(CryptoConstants.AES_256_KEY_SIZE)));
170
+ return ts_utils_1.Success.with(this._crypto.getRandomValues(new Uint8Array(ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE)));
153
171
  }
154
172
  catch (e) {
155
173
  const message = e instanceof Error ? e.message : String(e);
@@ -184,7 +202,7 @@ class BrowserCryptoProvider {
184
202
  salt: toArrayBuffer(salt),
185
203
  iterations: iterations,
186
204
  hash: 'SHA-256'
187
- }, keyMaterial, CryptoConstants.AES_256_KEY_SIZE * 8 // bits
205
+ }, keyMaterial, ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE * 8 // bits
188
206
  );
189
207
  return ts_utils_1.Success.with(new Uint8Array(derivedBits));
190
208
  }
@@ -193,6 +211,27 @@ class BrowserCryptoProvider {
193
211
  return ts_utils_1.Failure.with(`Key derivation failed: ${message}`);
194
212
  }
195
213
  }
214
+ /**
215
+ * Computes a SHA-256 hash of the given data.
216
+ * @param data - UTF-8 string to hash
217
+ * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
218
+ */
219
+ async sha256(data) {
220
+ try {
221
+ const encoder = new TextEncoder();
222
+ const dataBuffer = encoder.encode(data);
223
+ const hashBuffer = await this._crypto.subtle.digest('SHA-256', dataBuffer);
224
+ const hashArray = new Uint8Array(hashBuffer);
225
+ const hashHex = Array.from(hashArray)
226
+ .map((b) => b.toString(16).padStart(2, '0'))
227
+ .join('');
228
+ return (0, ts_utils_1.succeed)(hashHex);
229
+ }
230
+ catch (e) {
231
+ const message = e instanceof Error ? e.message : String(e);
232
+ return (0, ts_utils_1.fail)(`SHA-256 hash failed: ${message}`);
233
+ }
234
+ }
196
235
  // ============================================================================
197
236
  // Platform Utility Methods
198
237
  // ============================================================================
@@ -213,6 +252,21 @@ class BrowserCryptoProvider {
213
252
  return ts_utils_1.Failure.with(`Random bytes generation failed: ${message}`);
214
253
  }
215
254
  }
255
+ /* c8 ignore stop */
256
+ /**
257
+ * Generates a cryptographically random UUIDv4 using the injected
258
+ * `Crypto` instance.
259
+ * @returns `Success` with the generated UUID, or `Failure` if the underlying
260
+ * `Crypto` instance does not expose `randomUUID`.
261
+ */
262
+ generateUuid() {
263
+ /* c8 ignore next 3 - randomUUID is always available in supported runtimes (Node 22+, modern browsers) */
264
+ if (typeof this._crypto.randomUUID !== 'function') {
265
+ return ts_utils_1.Failure.with('Crypto instance does not expose randomUUID');
266
+ }
267
+ return (0, ts_utils_1.captureResult)(() => this._crypto.randomUUID());
268
+ }
269
+ /* c8 ignore start - browser-only methods continue */
216
270
  /**
217
271
  * Encodes binary data to base64 string.
218
272
  * @param data - Binary data to encode
@@ -244,8 +298,349 @@ class BrowserCryptoProvider {
244
298
  return ts_utils_1.Failure.with('Invalid base64 string');
245
299
  }
246
300
  }
301
+ // ============================================================================
302
+ // Asymmetric Key Operations
303
+ // ============================================================================
304
+ /**
305
+ * Generates a new asymmetric keypair via Web Crypto.
306
+ * @param algorithm - The algorithm to use.
307
+ * @param extractable - Whether the resulting keys may be exported.
308
+ * @returns `Success` with the generated `CryptoKeyPair`, or `Failure` with an error.
309
+ */
310
+ async generateKeyPair(algorithm, extractable) {
311
+ const params = ts_extras_1.CryptoUtils.keyPairAlgorithmParams[algorithm];
312
+ // Widening upcast to `AlgorithmIdentifier` steers TS to subtle.generateKey's
313
+ // broad overload, which accepts the Ed25519 `{ name: 'Ed25519' }` shape and
314
+ // returns `CryptoKey | CryptoKeyPair`. The narrowing back to `CryptoKeyPair`
315
+ // is a runtime check via the `in` operator, not a type assertion.
316
+ const result = await (0, ts_utils_1.captureAsyncResult)(async () => {
317
+ const generated = await this._crypto.subtle.generateKey(params.generateKey, extractable, [...params.keyPairUsages]);
318
+ if ('privateKey' in generated && 'publicKey' in generated) {
319
+ return generated;
320
+ }
321
+ /* c8 ignore next - unreachable: every entry in keyPairAlgorithmParams produces a keypair */
322
+ throw new Error(`${algorithm} unexpectedly produced a single CryptoKey`);
323
+ });
324
+ return result.withErrorFormat((e) => `Failed to generate ${algorithm} keypair: ${e}`);
325
+ }
326
+ /**
327
+ * Exports a public `CryptoKey` as a JSON Web Key.
328
+ * @remarks
329
+ * Rejects non-public keys at runtime. WebCrypto's `exportKey('jwk', ...)`
330
+ * does not enforce public-vs-private; without this guard a caller that
331
+ * passed an extractable private key would receive its private fields
332
+ * (`d`, `p`, `q`, ...) as JWK, defeating the method's name.
333
+ * @param publicKey - Extractable public key to export.
334
+ * @returns `Success` with the JWK, or `Failure` if not a public key or if export fails.
335
+ */
336
+ async exportPublicKeyJwk(publicKey) {
337
+ if (publicKey.type !== 'public') {
338
+ return ts_utils_1.Failure.with(`exportPublicKeyJwk requires a public CryptoKey, got '${publicKey.type}'`);
339
+ }
340
+ const result = await (0, ts_utils_1.captureAsyncResult)(() => this._crypto.subtle.exportKey('jwk', publicKey));
341
+ return result.withErrorFormat((e) => `Failed to export public key as JWK: ${e}`);
342
+ }
343
+ /**
344
+ * Imports a public-key JWK as a `CryptoKey` for the requested algorithm.
345
+ * @param jwk - The JSON Web Key produced by a prior export.
346
+ * @param algorithm - The algorithm the key was generated for.
347
+ * @returns `Success` with the imported public `CryptoKey`, or `Failure` with an error.
348
+ */
349
+ async importPublicKeyJwk(jwk, algorithm) {
350
+ const params = ts_extras_1.CryptoUtils.keyPairAlgorithmParams[algorithm];
351
+ const result = await (0, ts_utils_1.captureAsyncResult)(() => this._crypto.subtle.importKey('jwk', jwk, params.importPublicKey, true, params.publicKeyUsages));
352
+ return result.withErrorFormat((e) => `Failed to import ${algorithm} public key from JWK: ${e}`);
353
+ }
354
+ /**
355
+ * Exports a public `CryptoKey` as a DER-encoded SPKI blob.
356
+ * @param publicKey - The public `CryptoKey` to export.
357
+ * @returns `Success` with the raw SPKI bytes, or `Failure` with error context.
358
+ */
359
+ async exportPublicKeySpki(publicKey) {
360
+ if (publicKey.type !== 'public') {
361
+ return ts_utils_1.Failure.with(`exportPublicKeySpki requires a public CryptoKey, got '${publicKey.type}'`);
362
+ }
363
+ const result = await (0, ts_utils_1.captureAsyncResult)(() => this._crypto.subtle.exportKey('spki', publicKey));
364
+ return result
365
+ .withErrorFormat((e) => `exportPublicKeySpki: failed to export key: ${e}`)
366
+ .onSuccess((buf) => (0, ts_utils_1.succeed)(new Uint8Array(buf)));
367
+ }
368
+ /**
369
+ * Imports a public key from a DER-encoded SPKI blob.
370
+ * @param spkiBytes - The raw SPKI bytes.
371
+ * @param algorithm - The algorithm the key was generated for.
372
+ * @returns `Success` with the imported public `CryptoKey`, or `Failure` with error context.
373
+ */
374
+ async importPublicKeySpki(spkiBytes, algorithm) {
375
+ const params = ts_extras_1.CryptoUtils.keyPairAlgorithmParams[algorithm];
376
+ const result = await (0, ts_utils_1.captureAsyncResult)(() => this._crypto.subtle.importKey('spki', toBufferView(spkiBytes), params.importPublicKey, true, [...params.publicKeyUsages]));
377
+ return result.withErrorFormat((e) => `importPublicKeySpki: failed to import ${algorithm} public key from SPKI: ${e}`);
378
+ }
379
+ /* c8 ignore stop */
380
+ /**
381
+ * Signs `data` with `privateKey` using the algorithm inferred from the key.
382
+ * @param privateKey - A signing `CryptoKey` (`'ecdsa-p256'` or `'ed25519'`).
383
+ * @param data - The bytes to sign.
384
+ * @returns `Success` with the raw signature bytes, or `Failure` with error context.
385
+ */
386
+ async sign(privateKey, data) {
387
+ const algorithm = signAlgorithmFromKey(privateKey);
388
+ const result = await (0, ts_utils_1.captureAsyncResult)(() => this._crypto.subtle.sign(algorithm, privateKey, toBufferView(data)));
389
+ return result
390
+ .withErrorFormat((e) => `sign failed: ${e}`)
391
+ .onSuccess((buf) => (0, ts_utils_1.succeed)(new Uint8Array(buf)));
392
+ }
393
+ /**
394
+ * Verifies a signature produced by {@link BrowserCryptoProvider.sign}.
395
+ * @param publicKey - A verify `CryptoKey` (`'ecdsa-p256'` or `'ed25519'`).
396
+ * @param signature - The raw signature bytes.
397
+ * @param data - The original data that was signed.
398
+ * @returns `Success` with `true` if valid, `false` if not, or `Failure` with error context.
399
+ */
400
+ async verify(publicKey, signature, data) {
401
+ const algorithm = signAlgorithmFromKey(publicKey);
402
+ const result = await (0, ts_utils_1.captureAsyncResult)(() => this._crypto.subtle.verify(algorithm, publicKey, toBufferView(signature), toBufferView(data)));
403
+ return result.withErrorFormat((e) => `verify failed: ${e}`);
404
+ }
405
+ /**
406
+ * Compares two byte arrays in constant time.
407
+ *
408
+ * Accumulates XOR differences with bitwise-OR; no early-return is possible
409
+ * once the length check passes, making timing independent of the byte
410
+ * values. Returns `false` immediately on length mismatch (length is not
411
+ * secret in normal use).
412
+ * @param a - First byte array.
413
+ * @param b - Second byte array.
414
+ * @returns `true` if lengths match and all bytes are equal, `false` otherwise.
415
+ */
416
+ timingSafeEqual(a, b) {
417
+ if (a.length !== b.length)
418
+ return false;
419
+ let diff = 0;
420
+ for (let i = 0; i < a.length; i++) {
421
+ // eslint-disable-next-line no-bitwise
422
+ diff |= a[i] ^ b[i];
423
+ }
424
+ return diff === 0;
425
+ }
426
+ /**
427
+ * Computes an HMAC-SHA256 MAC for `data` using `key`.
428
+ * @param key - An HMAC `CryptoKey` with `'sign'` usage.
429
+ * @param data - The bytes to authenticate.
430
+ * @returns `Success` with the 32-byte MAC, or `Failure` with error context.
431
+ */
432
+ async hmacSha256(key, data) {
433
+ const result = await (0, ts_utils_1.captureAsyncResult)(() => this._crypto.subtle.sign({ name: 'HMAC' }, key, toBufferView(data)));
434
+ return result
435
+ .withErrorFormat((e) => `hmacSha256 failed: ${e}`)
436
+ .onSuccess((buf) => (0, ts_utils_1.succeed)(new Uint8Array(buf)));
437
+ }
438
+ /**
439
+ * Verifies an HMAC-SHA256 MAC in constant time.
440
+ * @param key - An HMAC `CryptoKey` with `'sign'` usage.
441
+ * @param signature - The MAC bytes to verify.
442
+ * @param data - The original data that was authenticated.
443
+ * @returns `Success` with `true` if valid, `false` if not, or `Failure` with error context.
444
+ */
445
+ async verifyHmacSha256(key, signature, data) {
446
+ return (await this.hmacSha256(key, data))
447
+ .withErrorFormat((e) => `verifyHmacSha256 failed: ${e}`)
448
+ .onSuccess((mac) => (0, ts_utils_1.succeed)(this.timingSafeEqual(mac, signature)));
449
+ }
450
+ /**
451
+ * Encrypts raw bytes using AES-256-GCM with a caller-supplied nonce and
452
+ * optional AAD. See {@link CryptoUtils.ICryptoProvider.encryptBytes | ICryptoProvider.encryptBytes}
453
+ * — in particular the caller's responsibility to use a unique `nonce` per
454
+ * message under a given `key`.
455
+ *
456
+ * Byte-identical to {@link CryptoUtils.NodeCryptoProvider.encryptBytes} for
457
+ * identical `(key, nonce, plaintext, aad)`: Web Crypto appends the 16-byte tag
458
+ * to the ciphertext, and this method splits it off so the returned
459
+ * `ciphertext`/`authTag` match Node's separated-tag layout exactly.
460
+ * @param key - 32-byte AES-256 key.
461
+ * @param nonce - 12-byte GCM nonce (must be unique per message under `key`).
462
+ * @param plaintext - The bytes to encrypt (empty permitted).
463
+ * @param aad - Optional additional authenticated data bound into the tag.
464
+ * @returns `Success` with the ciphertext and 16-byte auth tag, or `Failure` with an error.
465
+ */
466
+ async encryptBytes(key, nonce, plaintext, aad) {
467
+ if (key.length !== ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE) {
468
+ return ts_utils_1.Failure.with(`encryptBytes: key must be ${ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
469
+ }
470
+ if (nonce.length !== ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE) {
471
+ return ts_utils_1.Failure.with(`encryptBytes: nonce must be ${ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE} bytes, got ${nonce.length}`);
472
+ }
473
+ const result = await (0, ts_utils_1.captureAsyncResult)(async () => {
474
+ const cryptoKey = await this._crypto.subtle.importKey('raw', toBufferView(key), { name: 'AES-GCM' }, false, ['encrypt']);
475
+ const algorithm = {
476
+ name: 'AES-GCM',
477
+ iv: toBufferView(nonce),
478
+ tagLength: ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE * 8 // bits
479
+ };
480
+ if (aad !== undefined) {
481
+ algorithm.additionalData = toBufferView(aad);
482
+ }
483
+ const encryptedWithTag = new Uint8Array(await this._crypto.subtle.encrypt(algorithm, cryptoKey, toBufferView(plaintext)));
484
+ const tagStart = encryptedWithTag.length - ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE;
485
+ return {
486
+ ciphertext: encryptedWithTag.slice(0, tagStart),
487
+ authTag: encryptedWithTag.slice(tagStart)
488
+ };
489
+ });
490
+ return result.withErrorFormat((e) => `encryptBytes failed: ${e}`);
491
+ }
492
+ /**
493
+ * Decrypts raw bytes produced by {@link BrowserCryptoProvider.encryptBytes}
494
+ * using AES-256-GCM. See
495
+ * {@link CryptoUtils.ICryptoProvider.decryptBytes | ICryptoProvider.decryptBytes}.
496
+ * Fails (never throws) on any authentication failure, including a mismatched `aad`.
497
+ * @param key - 32-byte AES-256 key.
498
+ * @param nonce - 12-byte GCM nonce (the same one used to encrypt).
499
+ * @param ciphertext - The ciphertext from the `encryptBytes` result.
500
+ * @param authTag - The 16-byte GCM auth tag from the `encryptBytes` result.
501
+ * @param aad - The identical AAD supplied at encrypt time (or absent).
502
+ * @returns `Success` with the decrypted plaintext bytes, or `Failure` with an error.
503
+ */
504
+ async decryptBytes(key, nonce, ciphertext, authTag, aad) {
505
+ if (key.length !== ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE) {
506
+ return ts_utils_1.Failure.with(`decryptBytes: key must be ${ts_extras_1.CryptoUtils.Constants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
507
+ }
508
+ if (nonce.length !== ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE) {
509
+ return ts_utils_1.Failure.with(`decryptBytes: nonce must be ${ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE} bytes, got ${nonce.length}`);
510
+ }
511
+ if (authTag.length !== ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE) {
512
+ return ts_utils_1.Failure.with(`decryptBytes: auth tag must be ${ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE} bytes, got ${authTag.length}`);
513
+ }
514
+ const result = await (0, ts_utils_1.captureAsyncResult)(async () => {
515
+ const cryptoKey = await this._crypto.subtle.importKey('raw', toBufferView(key), { name: 'AES-GCM' }, false, ['decrypt']);
516
+ // Web Crypto expects ciphertext + auth tag concatenated.
517
+ const encryptedWithTag = new Uint8Array(ciphertext.length + authTag.length);
518
+ encryptedWithTag.set(ciphertext);
519
+ encryptedWithTag.set(authTag, ciphertext.length);
520
+ const algorithm = {
521
+ name: 'AES-GCM',
522
+ iv: toBufferView(nonce),
523
+ tagLength: ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE * 8 // bits
524
+ };
525
+ if (aad !== undefined) {
526
+ algorithm.additionalData = toBufferView(aad);
527
+ }
528
+ const decrypted = await this._crypto.subtle.decrypt(algorithm, cryptoKey, encryptedWithTag);
529
+ return new Uint8Array(decrypted);
530
+ });
531
+ return result.withErrorFormat((e) => `decryptBytes failed: ${e}`);
532
+ }
533
+ /**
534
+ * Wraps `plaintext` for the holder of `recipientPublicKey` using
535
+ * ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
536
+ * {@link CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes}.
537
+ * @param plaintext - The bytes to wrap.
538
+ * @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
539
+ * @param options - HKDF salt and info; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
540
+ * @returns `Success` with the wrapped payload, or `Failure` with an error.
541
+ */
542
+ async wrapBytes(plaintext, recipientPublicKey, options) {
543
+ const recipientCheck = checkEcdhP256(recipientPublicKey, 'public', 'recipient public key');
544
+ if (recipientCheck.isFailure()) {
545
+ return ts_utils_1.Failure.with(`wrapBytes failed: ${recipientCheck.message}`);
546
+ }
547
+ const subtle = this._crypto.subtle;
548
+ const result = await (0, ts_utils_1.captureAsyncResult)(async () => {
549
+ const ephemeral = (await subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, [
550
+ 'deriveKey'
551
+ ]));
552
+ const hkdfBase = await subtle.deriveKey({ name: 'ECDH', public: recipientPublicKey }, ephemeral.privateKey, { name: 'HKDF' }, false, ['deriveKey']);
553
+ const wrapKey = await subtle.deriveKey({ name: 'HKDF', salt: toBufferView(options.salt), info: toBufferView(options.info), hash: 'SHA-256' }, hkdfBase, { name: 'AES-GCM', length: 256 }, false, ['encrypt']);
554
+ const nonce = this._crypto.getRandomValues(new Uint8Array(ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE));
555
+ const ctBuf = await subtle.encrypt({ name: 'AES-GCM', iv: nonce }, wrapKey, toBufferView(plaintext));
556
+ const ephemeralPublicKey = await subtle.exportKey('jwk', ephemeral.publicKey);
557
+ return {
558
+ ephemeralPublicKey,
559
+ nonce: this.toBase64(nonce),
560
+ ciphertext: this.toBase64(new Uint8Array(ctBuf))
561
+ };
562
+ });
563
+ return result.withErrorFormat((e) => `wrapBytes failed: ${e}`);
564
+ }
565
+ /**
566
+ * Unwraps a payload produced by `wrapBytes` using the recipient's private
567
+ * key. See {@link CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes}.
568
+ * @param wrapped - The wrapped payload.
569
+ * @param recipientPrivateKey - The recipient's ECDH P-256 private `CryptoKey`.
570
+ * @param options - HKDF salt and info matching the wrap call.
571
+ * @returns `Success` with the original `plaintext`, or `Failure` with an error.
572
+ */
573
+ async unwrapBytes(wrapped, recipientPrivateKey, options) {
574
+ const recipientCheck = checkEcdhP256(recipientPrivateKey, 'private', 'recipient private key');
575
+ if (recipientCheck.isFailure()) {
576
+ return ts_utils_1.Failure.with(`unwrapBytes failed: ${recipientCheck.message}`);
577
+ }
578
+ const nonceResult = this.fromBase64(wrapped.nonce);
579
+ if (nonceResult.isFailure()) {
580
+ return ts_utils_1.Failure.with(`unwrapBytes failed: nonce: ${nonceResult.message}`);
581
+ }
582
+ if (nonceResult.value.length !== ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE) {
583
+ return ts_utils_1.Failure.with(`unwrapBytes failed: nonce must be ${ts_extras_1.CryptoUtils.Constants.GCM_IV_SIZE} bytes (got ${nonceResult.value.length})`);
584
+ }
585
+ const ciphertextResult = this.fromBase64(wrapped.ciphertext);
586
+ if (ciphertextResult.isFailure()) {
587
+ return ts_utils_1.Failure.with(`unwrapBytes failed: ciphertext: ${ciphertextResult.message}`);
588
+ }
589
+ if (ciphertextResult.value.length < ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE) {
590
+ return ts_utils_1.Failure.with(`unwrapBytes failed: ciphertext must be at least ${ts_extras_1.CryptoUtils.Constants.GCM_AUTH_TAG_SIZE} bytes (got ${ciphertextResult.value.length})`);
591
+ }
592
+ const subtle = this._crypto.subtle;
593
+ const result = await (0, ts_utils_1.captureAsyncResult)(async () => {
594
+ const ephemeralPub = await subtle.importKey('jwk', wrapped.ephemeralPublicKey, { name: 'ECDH', namedCurve: 'P-256' }, false, []);
595
+ const hkdfBase = await subtle.deriveKey({ name: 'ECDH', public: ephemeralPub }, recipientPrivateKey, { name: 'HKDF' }, false, ['deriveKey']);
596
+ const wrapKey = await subtle.deriveKey({ name: 'HKDF', salt: toBufferView(options.salt), info: toBufferView(options.info), hash: 'SHA-256' }, hkdfBase, { name: 'AES-GCM', length: 256 }, false, ['decrypt']);
597
+ const ptBuf = await subtle.decrypt({ name: 'AES-GCM', iv: toBufferView(nonceResult.value) }, wrapKey, toBufferView(ciphertextResult.value));
598
+ return new Uint8Array(ptBuf);
599
+ });
600
+ return result.withErrorFormat((e) => `unwrapBytes failed: ${e}`);
601
+ }
247
602
  }
248
603
  exports.BrowserCryptoProvider = BrowserCryptoProvider;
604
+ /**
605
+ * Derives the algorithm identifier needed by `crypto.subtle.sign/verify`
606
+ * from the key's embedded `algorithm` property. ECDSA requires an explicit
607
+ * `hash` parameter that is not stored on the key object itself; all other
608
+ * supported signing algorithms (`Ed25519`) use the key algorithm as-is.
609
+ */
610
+ function signAlgorithmFromKey(key) {
611
+ if (key.algorithm.name === 'ECDSA') {
612
+ return { name: 'ECDSA', hash: 'SHA-256' };
613
+ }
614
+ return key.algorithm;
615
+ }
616
+ /**
617
+ * Verifies that `key` is an ECDH P-256 `CryptoKey` of the expected `keyType`
618
+ * (public or private). Used by the wrap/unwrap methods to surface a clean
619
+ * `Failure` instead of letting the WebCrypto deriveKey call throw a less
620
+ * informative error later in the pipeline. Key usages are intentionally not
621
+ * checked here: WebCrypto already produces a specific error if `deriveKey` is
622
+ * not in `usages`, and `deriveBits` is an equally valid alternative usage that
623
+ * an explicit check would have to track.
624
+ * @param key - The CryptoKey to validate.
625
+ * @param keyType - The required `key.type` ('public' for wrap, 'private' for unwrap).
626
+ * @param label - Human-readable role label included in the failure message.
627
+ * @returns `Success` with the key (unchanged) when the algorithm, curve, and
628
+ * type all match; otherwise `Failure` with `<label> must be ECDH P-256 (...)`.
629
+ */
630
+ function checkEcdhP256(key, keyType, label) {
631
+ if (key.algorithm.name !== 'ECDH') {
632
+ return ts_utils_1.Failure.with(`${label} must be ECDH P-256 (got algorithm '${key.algorithm.name}')`);
633
+ }
634
+ const namedCurve = key.algorithm.namedCurve;
635
+ if (namedCurve !== 'P-256') {
636
+ return ts_utils_1.Failure.with(`${label} must be ECDH P-256 (got curve '${namedCurve}')`);
637
+ }
638
+ if (key.type !== keyType) {
639
+ return ts_utils_1.Failure.with(`${label} must be a ${keyType} CryptoKey (got '${key.type}')`);
640
+ }
641
+ return (0, ts_utils_1.succeed)(key);
642
+ }
643
+ /* c8 ignore start - Constructs a provider; only meaningful in a real browser environment */
249
644
  /**
250
645
  * Creates a {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider} if Web
251
646
  * Crypto API is available.