@fgv/ts-web-extras 5.1.0-19 → 5.1.0-20

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 (393) hide show
  1. package/package.json +10 -10
  2. package/.rush/temp/42a7a953924ae898114e7b6231a2408228d92433.tar.log +0 -243
  3. package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +0 -57
  4. package/.rush/temp/operation/build/all.log +0 -57
  5. package/.rush/temp/operation/build/log-chunks.jsonl +0 -57
  6. package/.rush/temp/operation/build/state.json +0 -3
  7. package/.rush/temp/shrinkwrap-deps.json +0 -692
  8. package/CHANGELOG.md +0 -23
  9. package/config/api-extractor.json +0 -343
  10. package/config/jest.config.json +0 -19
  11. package/config/rig.json +0 -16
  12. package/config/typedoc.json +0 -7
  13. package/dist/test/mocks/idb-keyval.js +0 -6
  14. package/dist/test/mocks/idb-keyval.js.map +0 -1
  15. package/dist/test/setupTests.js +0 -74
  16. package/dist/test/setupTests.js.map +0 -1
  17. package/dist/test/unit/browserCryptoProvider.wrapBytes.test.js +0 -221
  18. package/dist/test/unit/browserCryptoProvider.wrapBytes.test.js.map +0 -1
  19. package/dist/test/unit/browserHashProvider.test.js +0 -140
  20. package/dist/test/unit/browserHashProvider.test.js.map +0 -1
  21. package/dist/test/unit/directoryHandleStore.test.js +0 -190
  22. package/dist/test/unit/directoryHandleStore.test.js.map +0 -1
  23. package/dist/test/unit/fileApiTreeAccessors.test.js +0 -1188
  24. package/dist/test/unit/fileApiTreeAccessors.test.js.map +0 -1
  25. package/dist/test/unit/fileApiTypes.test.js +0 -472
  26. package/dist/test/unit/fileApiTypes.test.js.map +0 -1
  27. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js +0 -622
  28. package/dist/test/unit/fileSystemAccessTreeAccessors.test.js.map +0 -1
  29. package/dist/test/unit/fileTreeHelpers.test.js +0 -590
  30. package/dist/test/unit/fileTreeHelpers.test.js.map +0 -1
  31. package/dist/test/unit/httpTreeAccessors.test.js +0 -1364
  32. package/dist/test/unit/httpTreeAccessors.test.js.map +0 -1
  33. package/dist/test/unit/localStorageTreeAccessors.test.js +0 -812
  34. package/dist/test/unit/localStorageTreeAccessors.test.js.map +0 -1
  35. package/dist/test/unit/urlParams.test.js +0 -393
  36. package/dist/test/unit/urlParams.test.js.map +0 -1
  37. package/dist/test/utils/fileSystemAccessMocks.js +0 -271
  38. package/dist/test/utils/fileSystemAccessMocks.js.map +0 -1
  39. package/dist/test/utils/testHelpers.js +0 -124
  40. package/dist/test/utils/testHelpers.js.map +0 -1
  41. package/docs/CryptoUtils/README.md +0 -60
  42. package/docs/CryptoUtils/classes/BrowserCryptoProvider.decrypt.md +0 -27
  43. package/docs/CryptoUtils/classes/BrowserCryptoProvider.deriveKey.md +0 -26
  44. package/docs/CryptoUtils/classes/BrowserCryptoProvider.encrypt.md +0 -25
  45. package/docs/CryptoUtils/classes/BrowserCryptoProvider.exportPublicKeyJwk.md +0 -24
  46. package/docs/CryptoUtils/classes/BrowserCryptoProvider.fromBase64.md +0 -24
  47. package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateKey.md +0 -17
  48. package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateKeyPair.md +0 -25
  49. package/docs/CryptoUtils/classes/BrowserCryptoProvider.generateRandomBytes.md +0 -24
  50. package/docs/CryptoUtils/classes/BrowserCryptoProvider.importPublicKeyJwk.md +0 -25
  51. package/docs/CryptoUtils/classes/BrowserCryptoProvider.md +0 -231
  52. package/docs/CryptoUtils/classes/BrowserCryptoProvider.sha256.md +0 -24
  53. package/docs/CryptoUtils/classes/BrowserCryptoProvider.toBase64.md +0 -24
  54. package/docs/CryptoUtils/classes/BrowserCryptoProvider.unwrapBytes.md +0 -27
  55. package/docs/CryptoUtils/classes/BrowserCryptoProvider.wrapBytes.md +0 -28
  56. package/docs/CryptoUtils/classes/BrowserHashProvider.hashParts.md +0 -26
  57. package/docs/CryptoUtils/classes/BrowserHashProvider.hashString.md +0 -25
  58. package/docs/CryptoUtils/classes/BrowserHashProvider.md +0 -81
  59. package/docs/CryptoUtils/functions/createBrowserCryptoProvider.md +0 -12
  60. package/docs/FileTreeHelpers/README.md +0 -85
  61. package/docs/FileTreeHelpers/functions/extractFileListMetadata.md +0 -11
  62. package/docs/FileTreeHelpers/functions/extractFileMetadata.md +0 -11
  63. package/docs/FileTreeHelpers/functions/fromDirectoryUpload.md +0 -12
  64. package/docs/FileTreeHelpers/functions/fromFileList.md +0 -12
  65. package/docs/FileTreeHelpers/functions/getOriginalFile.md +0 -11
  66. package/docs/FileTreeHelpers/variables/defaultFileApiTreeInitParams.md +0 -9
  67. package/docs/README.md +0 -524
  68. package/docs/classes/BrowserCryptoProvider.decrypt.md +0 -27
  69. package/docs/classes/BrowserCryptoProvider.deriveKey.md +0 -26
  70. package/docs/classes/BrowserCryptoProvider.encrypt.md +0 -25
  71. package/docs/classes/BrowserCryptoProvider.exportPublicKeyJwk.md +0 -24
  72. package/docs/classes/BrowserCryptoProvider.fromBase64.md +0 -24
  73. package/docs/classes/BrowserCryptoProvider.generateKey.md +0 -17
  74. package/docs/classes/BrowserCryptoProvider.generateKeyPair.md +0 -25
  75. package/docs/classes/BrowserCryptoProvider.generateRandomBytes.md +0 -24
  76. package/docs/classes/BrowserCryptoProvider.importPublicKeyJwk.md +0 -25
  77. package/docs/classes/BrowserCryptoProvider.md +0 -231
  78. package/docs/classes/BrowserCryptoProvider.sha256.md +0 -24
  79. package/docs/classes/BrowserCryptoProvider.toBase64.md +0 -24
  80. package/docs/classes/BrowserCryptoProvider.unwrapBytes.md +0 -27
  81. package/docs/classes/BrowserCryptoProvider.wrapBytes.md +0 -28
  82. package/docs/classes/BrowserHashProvider.hashParts.md +0 -26
  83. package/docs/classes/BrowserHashProvider.hashString.md +0 -25
  84. package/docs/classes/BrowserHashProvider.md +0 -81
  85. package/docs/classes/DirectoryHandleStore.getAll.md +0 -17
  86. package/docs/classes/DirectoryHandleStore.getAllLabels.md +0 -17
  87. package/docs/classes/DirectoryHandleStore.load.md +0 -24
  88. package/docs/classes/DirectoryHandleStore.md +0 -120
  89. package/docs/classes/DirectoryHandleStore.remove.md +0 -24
  90. package/docs/classes/DirectoryHandleStore.save.md +0 -25
  91. package/docs/classes/FileApiTreeAccessors.create.md +0 -25
  92. package/docs/classes/FileApiTreeAccessors.createFromHttp.md +0 -24
  93. package/docs/classes/FileApiTreeAccessors.createFromLocalStorage.md +0 -25
  94. package/docs/classes/FileApiTreeAccessors.createPersistent.md +0 -26
  95. package/docs/classes/FileApiTreeAccessors.createPersistentFromFile.md +0 -27
  96. package/docs/classes/FileApiTreeAccessors.extractFileMetadata.md +0 -24
  97. package/docs/classes/FileApiTreeAccessors.fromDirectoryUpload.md +0 -25
  98. package/docs/classes/FileApiTreeAccessors.fromFileList.md +0 -25
  99. package/docs/classes/FileApiTreeAccessors.getOriginalFile.md +0 -27
  100. package/docs/classes/FileApiTreeAccessors.md +0 -172
  101. package/docs/classes/FileSystemAccessTreeAccessors.deleteFile.md +0 -22
  102. package/docs/classes/FileSystemAccessTreeAccessors.fileIsMutable.md +0 -22
  103. package/docs/classes/FileSystemAccessTreeAccessors.fromDirectoryHandle.md +0 -25
  104. package/docs/classes/FileSystemAccessTreeAccessors.fromFileHandle.md +0 -29
  105. package/docs/classes/FileSystemAccessTreeAccessors.getDirtyPaths.md +0 -15
  106. package/docs/classes/FileSystemAccessTreeAccessors.isDirty.md +0 -15
  107. package/docs/classes/FileSystemAccessTreeAccessors.md +0 -275
  108. package/docs/classes/FileSystemAccessTreeAccessors.saveFileContents.md +0 -23
  109. package/docs/classes/FileSystemAccessTreeAccessors.syncToDisk.md +0 -15
  110. package/docs/classes/HttpTreeAccessors.deleteFile.md +0 -24
  111. package/docs/classes/HttpTreeAccessors.fileIsMutable.md +0 -24
  112. package/docs/classes/HttpTreeAccessors.fromHttp.md +0 -24
  113. package/docs/classes/HttpTreeAccessors.getDirtyPaths.md +0 -17
  114. package/docs/classes/HttpTreeAccessors.isDirty.md +0 -17
  115. package/docs/classes/HttpTreeAccessors.md +0 -261
  116. package/docs/classes/HttpTreeAccessors.saveFileContents.md +0 -25
  117. package/docs/classes/HttpTreeAccessors.syncToDisk.md +0 -22
  118. package/docs/classes/LocalStorageTreeAccessors.deleteFile.md +0 -24
  119. package/docs/classes/LocalStorageTreeAccessors.fileIsMutable.md +0 -24
  120. package/docs/classes/LocalStorageTreeAccessors.fromStorage.md +0 -25
  121. package/docs/classes/LocalStorageTreeAccessors.getDirtyPaths.md +0 -17
  122. package/docs/classes/LocalStorageTreeAccessors.isDirty.md +0 -17
  123. package/docs/classes/LocalStorageTreeAccessors.md +0 -270
  124. package/docs/classes/LocalStorageTreeAccessors.saveFileContents.md +0 -25
  125. package/docs/classes/LocalStorageTreeAccessors.syncToDisk.md +0 -17
  126. package/docs/functions/createBrowserCryptoProvider.md +0 -12
  127. package/docs/functions/exportAsJson.md +0 -12
  128. package/docs/functions/exportUsingFileSystemAPI.md +0 -11
  129. package/docs/functions/extractDirectoryPath.md +0 -13
  130. package/docs/functions/extractFileListMetadata.md +0 -11
  131. package/docs/functions/extractFileMetadata.md +0 -11
  132. package/docs/functions/fromDirectoryUpload.md +0 -12
  133. package/docs/functions/fromFileList.md +0 -12
  134. package/docs/functions/getOriginalFile.md +0 -11
  135. package/docs/functions/isDirectoryHandle.md +0 -11
  136. package/docs/functions/isFileHandle.md +0 -11
  137. package/docs/functions/isFilePath.md +0 -11
  138. package/docs/functions/parseContextFilter.md +0 -12
  139. package/docs/functions/parseQualifierDefaults.md +0 -12
  140. package/docs/functions/parseResourceTypes.md +0 -12
  141. package/docs/functions/parseUrlParameters.md +0 -11
  142. package/docs/functions/safeShowDirectoryPicker.md +0 -11
  143. package/docs/functions/safeShowOpenFilePicker.md +0 -11
  144. package/docs/functions/safeShowSaveFilePicker.md +0 -11
  145. package/docs/functions/supportsFileSystemAccess.md +0 -11
  146. package/docs/interfaces/FilePickerAcceptType.accept.md +0 -9
  147. package/docs/interfaces/FilePickerAcceptType.description.md +0 -9
  148. package/docs/interfaces/FilePickerAcceptType.md +0 -61
  149. package/docs/interfaces/FileSystemCreateWritableOptions.keepExistingData.md +0 -9
  150. package/docs/interfaces/FileSystemCreateWritableOptions.md +0 -44
  151. package/docs/interfaces/FileSystemDirectoryHandle._asyncIterator_.md +0 -13
  152. package/docs/interfaces/FileSystemDirectoryHandle.entries.md +0 -13
  153. package/docs/interfaces/FileSystemDirectoryHandle.getDirectoryHandle.md +0 -21
  154. package/docs/interfaces/FileSystemDirectoryHandle.getFileHandle.md +0 -21
  155. package/docs/interfaces/FileSystemDirectoryHandle.keys.md +0 -13
  156. package/docs/interfaces/FileSystemDirectoryHandle.kind.md +0 -9
  157. package/docs/interfaces/FileSystemDirectoryHandle.md +0 -224
  158. package/docs/interfaces/FileSystemDirectoryHandle.removeEntry.md +0 -21
  159. package/docs/interfaces/FileSystemDirectoryHandle.resolve.md +0 -20
  160. package/docs/interfaces/FileSystemDirectoryHandle.values.md +0 -13
  161. package/docs/interfaces/FileSystemFileHandle.createWritable.md +0 -20
  162. package/docs/interfaces/FileSystemFileHandle.getFile.md +0 -13
  163. package/docs/interfaces/FileSystemFileHandle.kind.md +0 -9
  164. package/docs/interfaces/FileSystemFileHandle.md +0 -146
  165. package/docs/interfaces/FileSystemGetDirectoryOptions.create.md +0 -9
  166. package/docs/interfaces/FileSystemGetDirectoryOptions.md +0 -44
  167. package/docs/interfaces/FileSystemGetFileOptions.create.md +0 -9
  168. package/docs/interfaces/FileSystemGetFileOptions.md +0 -44
  169. package/docs/interfaces/FileSystemHandle.isSameEntry.md +0 -20
  170. package/docs/interfaces/FileSystemHandle.kind.md +0 -9
  171. package/docs/interfaces/FileSystemHandle.md +0 -118
  172. package/docs/interfaces/FileSystemHandle.name.md +0 -9
  173. package/docs/interfaces/FileSystemHandle.queryPermission.md +0 -20
  174. package/docs/interfaces/FileSystemHandle.requestPermission.md +0 -20
  175. package/docs/interfaces/FileSystemHandlePermissionDescriptor.md +0 -44
  176. package/docs/interfaces/FileSystemHandlePermissionDescriptor.mode.md +0 -9
  177. package/docs/interfaces/FileSystemRemoveOptions.md +0 -44
  178. package/docs/interfaces/FileSystemRemoveOptions.recursive.md +0 -9
  179. package/docs/interfaces/FileSystemWritableFileStream.md +0 -142
  180. package/docs/interfaces/FileSystemWritableFileStream.seek.md +0 -20
  181. package/docs/interfaces/FileSystemWritableFileStream.truncate.md +0 -20
  182. package/docs/interfaces/FileSystemWritableFileStream.write.md +0 -20
  183. package/docs/interfaces/IDirectoryHandleTreeInitializer.dirHandles.md +0 -9
  184. package/docs/interfaces/IDirectoryHandleTreeInitializer.md +0 -78
  185. package/docs/interfaces/IDirectoryHandleTreeInitializer.nonRecursive.md +0 -9
  186. package/docs/interfaces/IDirectoryHandleTreeInitializer.prefix.md +0 -9
  187. package/docs/interfaces/IFileHandleTreeInitializer.fileHandles.md +0 -9
  188. package/docs/interfaces/IFileHandleTreeInitializer.md +0 -61
  189. package/docs/interfaces/IFileHandleTreeInitializer.prefix.md +0 -9
  190. package/docs/interfaces/IFileListTreeInitializer.fileList.md +0 -9
  191. package/docs/interfaces/IFileListTreeInitializer.md +0 -44
  192. package/docs/interfaces/IFileMetadata.lastModified.md +0 -9
  193. package/docs/interfaces/IFileMetadata.md +0 -112
  194. package/docs/interfaces/IFileMetadata.name.md +0 -9
  195. package/docs/interfaces/IFileMetadata.path.md +0 -9
  196. package/docs/interfaces/IFileMetadata.size.md +0 -9
  197. package/docs/interfaces/IFileMetadata.type.md +0 -9
  198. package/docs/interfaces/IFileSystemAccessTreeParams.autoSync.md +0 -12
  199. package/docs/interfaces/IFileSystemAccessTreeParams.filePath.md +0 -13
  200. package/docs/interfaces/IFileSystemAccessTreeParams.logger.md +0 -11
  201. package/docs/interfaces/IFileSystemAccessTreeParams.md +0 -148
  202. package/docs/interfaces/IFileSystemAccessTreeParams.requireWritePermission.md +0 -13
  203. package/docs/interfaces/IFsAccessApis.md +0 -62
  204. package/docs/interfaces/IFsAccessApis.showDirectoryPicker.md +0 -20
  205. package/docs/interfaces/IFsAccessApis.showOpenFilePicker.md +0 -20
  206. package/docs/interfaces/IFsAccessApis.showSaveFilePicker.md +0 -20
  207. package/docs/interfaces/IHttpTreeParams.autoSync.md +0 -9
  208. package/docs/interfaces/IHttpTreeParams.baseUrl.md +0 -9
  209. package/docs/interfaces/IHttpTreeParams.fetchImpl.md +0 -9
  210. package/docs/interfaces/IHttpTreeParams.logger.md +0 -9
  211. package/docs/interfaces/IHttpTreeParams.md +0 -182
  212. package/docs/interfaces/IHttpTreeParams.namespace.md +0 -9
  213. package/docs/interfaces/IHttpTreeParams.userId.md +0 -9
  214. package/docs/interfaces/ILocalStorageTreeParams.autoSync.md +0 -12
  215. package/docs/interfaces/ILocalStorageTreeParams.md +0 -131
  216. package/docs/interfaces/ILocalStorageTreeParams.pathToKeyMap.md +0 -13
  217. package/docs/interfaces/ILocalStorageTreeParams.storage.md +0 -12
  218. package/docs/interfaces/IUrlConfigOptions.config.md +0 -11
  219. package/docs/interfaces/IUrlConfigOptions.configStartDir.md +0 -11
  220. package/docs/interfaces/IUrlConfigOptions.contextFilter.md +0 -11
  221. package/docs/interfaces/IUrlConfigOptions.input.md +0 -11
  222. package/docs/interfaces/IUrlConfigOptions.inputStartDir.md +0 -11
  223. package/docs/interfaces/IUrlConfigOptions.interactive.md +0 -11
  224. package/docs/interfaces/IUrlConfigOptions.loadZip.md +0 -11
  225. package/docs/interfaces/IUrlConfigOptions.maxDistance.md +0 -11
  226. package/docs/interfaces/IUrlConfigOptions.md +0 -248
  227. package/docs/interfaces/IUrlConfigOptions.qualifierDefaults.md +0 -11
  228. package/docs/interfaces/IUrlConfigOptions.reduceQualifiers.md +0 -11
  229. package/docs/interfaces/IUrlConfigOptions.resourceTypes.md +0 -11
  230. package/docs/interfaces/IUrlConfigOptions.zipFile.md +0 -11
  231. package/docs/interfaces/IUrlConfigOptions.zipPath.md +0 -11
  232. package/docs/interfaces/ShowDirectoryPickerOptions.id.md +0 -9
  233. package/docs/interfaces/ShowDirectoryPickerOptions.md +0 -78
  234. package/docs/interfaces/ShowDirectoryPickerOptions.mode.md +0 -9
  235. package/docs/interfaces/ShowDirectoryPickerOptions.startIn.md +0 -9
  236. package/docs/interfaces/ShowOpenFilePickerOptions.excludeAcceptAllOption.md +0 -9
  237. package/docs/interfaces/ShowOpenFilePickerOptions.id.md +0 -9
  238. package/docs/interfaces/ShowOpenFilePickerOptions.md +0 -112
  239. package/docs/interfaces/ShowOpenFilePickerOptions.multiple.md +0 -9
  240. package/docs/interfaces/ShowOpenFilePickerOptions.startIn.md +0 -9
  241. package/docs/interfaces/ShowOpenFilePickerOptions.types.md +0 -9
  242. package/docs/interfaces/ShowSaveFilePickerOptions.excludeAcceptAllOption.md +0 -9
  243. package/docs/interfaces/ShowSaveFilePickerOptions.id.md +0 -9
  244. package/docs/interfaces/ShowSaveFilePickerOptions.md +0 -112
  245. package/docs/interfaces/ShowSaveFilePickerOptions.startIn.md +0 -9
  246. package/docs/interfaces/ShowSaveFilePickerOptions.suggestedName.md +0 -9
  247. package/docs/interfaces/ShowSaveFilePickerOptions.types.md +0 -9
  248. package/docs/type-aliases/TreeInitializer.md +0 -11
  249. package/docs/type-aliases/WellKnownDirectory.md +0 -11
  250. package/docs/type-aliases/WindowWithFsAccess.md +0 -11
  251. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_DB.md +0 -9
  252. package/docs/variables/DEFAULT_DIRECTORY_HANDLE_STORE.md +0 -9
  253. package/docs/variables/defaultFileApiTreeInitParams.md +0 -9
  254. package/etc/ts-web-extras.api.md +0 -439
  255. package/lib/test/mocks/idb-keyval.d.ts +0 -6
  256. package/lib/test/mocks/idb-keyval.d.ts.map +0 -1
  257. package/lib/test/mocks/idb-keyval.js +0 -9
  258. package/lib/test/mocks/idb-keyval.js.map +0 -1
  259. package/lib/test/setupTests.d.ts +0 -2
  260. package/lib/test/setupTests.d.ts.map +0 -1
  261. package/lib/test/setupTests.js +0 -76
  262. package/lib/test/setupTests.js.map +0 -1
  263. package/lib/test/unit/browserCryptoProvider.wrapBytes.test.d.ts +0 -2
  264. package/lib/test/unit/browserCryptoProvider.wrapBytes.test.d.ts.map +0 -1
  265. package/lib/test/unit/browserCryptoProvider.wrapBytes.test.js +0 -223
  266. package/lib/test/unit/browserCryptoProvider.wrapBytes.test.js.map +0 -1
  267. package/lib/test/unit/browserHashProvider.test.d.ts +0 -2
  268. package/lib/test/unit/browserHashProvider.test.d.ts.map +0 -1
  269. package/lib/test/unit/browserHashProvider.test.js +0 -142
  270. package/lib/test/unit/browserHashProvider.test.js.map +0 -1
  271. package/lib/test/unit/directoryHandleStore.test.d.ts +0 -2
  272. package/lib/test/unit/directoryHandleStore.test.d.ts.map +0 -1
  273. package/lib/test/unit/directoryHandleStore.test.js +0 -192
  274. package/lib/test/unit/directoryHandleStore.test.js.map +0 -1
  275. package/lib/test/unit/fileApiTreeAccessors.test.d.ts +0 -2
  276. package/lib/test/unit/fileApiTreeAccessors.test.d.ts.map +0 -1
  277. package/lib/test/unit/fileApiTreeAccessors.test.js +0 -1190
  278. package/lib/test/unit/fileApiTreeAccessors.test.js.map +0 -1
  279. package/lib/test/unit/fileApiTypes.test.d.ts +0 -2
  280. package/lib/test/unit/fileApiTypes.test.d.ts.map +0 -1
  281. package/lib/test/unit/fileApiTypes.test.js +0 -474
  282. package/lib/test/unit/fileApiTypes.test.js.map +0 -1
  283. package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts +0 -2
  284. package/lib/test/unit/fileSystemAccessTreeAccessors.test.d.ts.map +0 -1
  285. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js +0 -624
  286. package/lib/test/unit/fileSystemAccessTreeAccessors.test.js.map +0 -1
  287. package/lib/test/unit/fileTreeHelpers.test.d.ts +0 -2
  288. package/lib/test/unit/fileTreeHelpers.test.d.ts.map +0 -1
  289. package/lib/test/unit/fileTreeHelpers.test.js +0 -592
  290. package/lib/test/unit/fileTreeHelpers.test.js.map +0 -1
  291. package/lib/test/unit/httpTreeAccessors.test.d.ts +0 -2
  292. package/lib/test/unit/httpTreeAccessors.test.d.ts.map +0 -1
  293. package/lib/test/unit/httpTreeAccessors.test.js +0 -1366
  294. package/lib/test/unit/httpTreeAccessors.test.js.map +0 -1
  295. package/lib/test/unit/localStorageTreeAccessors.test.d.ts +0 -2
  296. package/lib/test/unit/localStorageTreeAccessors.test.d.ts.map +0 -1
  297. package/lib/test/unit/localStorageTreeAccessors.test.js +0 -814
  298. package/lib/test/unit/localStorageTreeAccessors.test.js.map +0 -1
  299. package/lib/test/unit/urlParams.test.d.ts +0 -2
  300. package/lib/test/unit/urlParams.test.d.ts.map +0 -1
  301. package/lib/test/unit/urlParams.test.js +0 -395
  302. package/lib/test/unit/urlParams.test.js.map +0 -1
  303. package/lib/test/utils/fileSystemAccessMocks.d.ts +0 -53
  304. package/lib/test/utils/fileSystemAccessMocks.d.ts.map +0 -1
  305. package/lib/test/utils/fileSystemAccessMocks.js +0 -277
  306. package/lib/test/utils/fileSystemAccessMocks.js.map +0 -1
  307. package/lib/test/utils/testHelpers.d.ts +0 -51
  308. package/lib/test/utils/testHelpers.d.ts.map +0 -1
  309. package/lib/test/utils/testHelpers.js +0 -133
  310. package/lib/test/utils/testHelpers.js.map +0 -1
  311. package/rush-logs/ts-web-extras.build.cache.log +0 -3
  312. package/rush-logs/ts-web-extras.build.log +0 -57
  313. package/src/index.browser.ts +0 -24
  314. package/src/index.ts +0 -47
  315. package/src/packlets/crypto-utils/browserCryptoProvider.ts +0 -553
  316. package/src/packlets/crypto-utils/browserHashProvider.ts +0 -73
  317. package/src/packlets/crypto-utils/index.ts +0 -29
  318. package/src/packlets/file-api-types/index.ts +0 -366
  319. package/src/packlets/file-tree/directoryHandleStore.ts +0 -136
  320. package/src/packlets/file-tree/fileApiTreeAccessors.ts +0 -528
  321. package/src/packlets/file-tree/fileSystemAccessTreeAccessors.ts +0 -519
  322. package/src/packlets/file-tree/httpTreeAccessors.ts +0 -478
  323. package/src/packlets/file-tree/index.ts +0 -32
  324. package/src/packlets/file-tree/localStorageTreeAccessors.ts +0 -430
  325. package/src/packlets/helpers/fileTreeHelpers.ts +0 -107
  326. package/src/packlets/helpers/index.ts +0 -28
  327. package/src/packlets/url-utils/index.ts +0 -28
  328. package/src/packlets/url-utils/urlParams.ts +0 -245
  329. package/src/test/mocks/idb-keyval.ts +0 -5
  330. package/src/test/setupTests.ts +0 -87
  331. package/src/test/unit/browserCryptoProvider.wrapBytes.test.ts +0 -325
  332. package/src/test/unit/browserHashProvider.test.ts +0 -155
  333. package/src/test/unit/browserHashProvider.test.ts.bak +0 -376
  334. package/src/test/unit/directoryHandleStore.test.ts +0 -251
  335. package/src/test/unit/fileApiTreeAccessors.test.ts +0 -1387
  336. package/src/test/unit/fileApiTypes.test.ts +0 -587
  337. package/src/test/unit/fileSystemAccessTreeAccessors.test.ts +0 -885
  338. package/src/test/unit/fileTreeHelpers.test.ts +0 -694
  339. package/src/test/unit/httpTreeAccessors.test.ts +0 -1750
  340. package/src/test/unit/localStorageTreeAccessors.test.ts +0 -1014
  341. package/src/test/unit/urlParams.test.ts +0 -464
  342. package/src/test/utils/fileSystemAccessMocks.ts +0 -353
  343. package/src/test/utils/testHelpers.ts +0 -155
  344. package/temp/build/typescript/ts_8nwakTlr.json +0 -1
  345. package/temp/coverage/base.css +0 -224
  346. package/temp/coverage/block-navigation.js +0 -87
  347. package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +0 -1744
  348. package/temp/coverage/crypto-utils/browserHashProvider.ts.html +0 -304
  349. package/temp/coverage/crypto-utils/index.html +0 -131
  350. package/temp/coverage/favicon.png +0 -0
  351. package/temp/coverage/file-tree/directoryHandleStore.ts.html +0 -493
  352. package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +0 -1669
  353. package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +0 -1642
  354. package/temp/coverage/file-tree/httpTreeAccessors.ts.html +0 -1519
  355. package/temp/coverage/file-tree/index.html +0 -176
  356. package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +0 -1375
  357. package/temp/coverage/helpers/fileTreeHelpers.ts.html +0 -406
  358. package/temp/coverage/helpers/index.html +0 -116
  359. package/temp/coverage/index.html +0 -161
  360. package/temp/coverage/lcov-report/base.css +0 -224
  361. package/temp/coverage/lcov-report/block-navigation.js +0 -87
  362. package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +0 -1744
  363. package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +0 -304
  364. package/temp/coverage/lcov-report/crypto-utils/index.html +0 -131
  365. package/temp/coverage/lcov-report/favicon.png +0 -0
  366. package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +0 -493
  367. package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +0 -1669
  368. package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +0 -1642
  369. package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +0 -1519
  370. package/temp/coverage/lcov-report/file-tree/index.html +0 -176
  371. package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +0 -1375
  372. package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +0 -406
  373. package/temp/coverage/lcov-report/helpers/index.html +0 -116
  374. package/temp/coverage/lcov-report/index.html +0 -161
  375. package/temp/coverage/lcov-report/prettify.css +0 -1
  376. package/temp/coverage/lcov-report/prettify.js +0 -2
  377. package/temp/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  378. package/temp/coverage/lcov-report/sorter.js +0 -210
  379. package/temp/coverage/lcov-report/url-utils/index.html +0 -116
  380. package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +0 -820
  381. package/temp/coverage/lcov.info +0 -3924
  382. package/temp/coverage/prettify.css +0 -1
  383. package/temp/coverage/prettify.js +0 -2
  384. package/temp/coverage/sort-arrow-sprite.png +0 -0
  385. package/temp/coverage/sorter.js +0 -210
  386. package/temp/coverage/url-utils/index.html +0 -116
  387. package/temp/coverage/url-utils/urlParams.ts.html +0 -820
  388. package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
  389. package/temp/test/jest/jest-transform-cache-7492f1b44480e0cdd1f220078fb3afd8-79ef2876fae7ca75eedb2aa53dc48338/8a/package_8a7abbb163935a14e582220d11872de3 +0 -53
  390. package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +0 -1
  391. package/temp/ts-web-extras.api.json +0 -9373
  392. package/temp/ts-web-extras.api.md +0 -439
  393. package/tsconfig.json +0 -7
@@ -1,553 +0,0 @@
1
- // Copyright (c) 2024 Erik Fortune
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- // SOFTWARE.
20
-
21
- import { captureAsyncResult, captureResult, fail, Failure, Result, succeed, Success } from '@fgv/ts-utils';
22
- import { CryptoUtils } from '@fgv/ts-extras';
23
-
24
- /* c8 ignore start - Used only by browser-only methods that cannot be tested in Node.js environment */
25
- /**
26
- * Extracts an `ArrayBuffer` from a Uint8Array, handling the potential SharedArrayBuffer case.
27
- * @param arr - The Uint8Array to extract from
28
- * @returns An `ArrayBuffer` containing a copy of the data.
29
- */
30
- function toArrayBuffer(arr: Uint8Array): ArrayBuffer {
31
- // Create a new ArrayBuffer and copy the data - this handles both ArrayBuffer and SharedArrayBuffer
32
- const buffer = new ArrayBuffer(arr.byteLength);
33
- new Uint8Array(buffer).set(arr);
34
- return buffer;
35
- }
36
- /* c8 ignore stop */
37
-
38
- /**
39
- * Returns a fresh Uint8Array view over a non-shared ArrayBuffer copy of `arr`.
40
- * Used by {@link BrowserCryptoProvider.wrapBytes | wrapBytes} and
41
- * {@link BrowserCryptoProvider.unwrapBytes | unwrapBytes}: Node 20's
42
- * webcrypto.subtle rejects raw `ArrayBuffer` for several `BufferSource`
43
- * parameters with "is not instance of ArrayBuffer, Buffer, TypedArray, or
44
- * DataView" even though `ArrayBuffer` should be valid per the spec; a
45
- * TypedArray view is accepted on Node 20+ and on browsers, and the explicit
46
- * `Uint8Array<ArrayBuffer>` return type also satisfies TypeScript's `BufferSource`
47
- * (which excludes the `SharedArrayBuffer` branch of `Uint8Array`'s buffer type).
48
- */
49
- function toBufferView(arr: Uint8Array): Uint8Array<ArrayBuffer> {
50
- const buffer = new ArrayBuffer(arr.byteLength);
51
- const view = new Uint8Array(buffer);
52
- view.set(arr);
53
- return view;
54
- }
55
-
56
- /**
57
- * Browser implementation of `ICryptoProvider` using the Web Crypto API.
58
- * Uses AES-256-GCM for authenticated encryption.
59
- *
60
- * Note: This provider requires a browser environment with Web Crypto API support.
61
- * In Node.js 15+, Web Crypto is available via globalThis.crypto or require('crypto').webcrypto.
62
- *
63
- * @public
64
- */
65
- export class BrowserCryptoProvider implements CryptoUtils.ICryptoProvider {
66
- private readonly _crypto: Crypto;
67
-
68
- /* c8 ignore start - Existing browser-only methods cannot be tested in Node.js environment */
69
- /**
70
- * Creates a new {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider}.
71
- * @param cryptoApi - Optional Crypto instance (defaults to globalThis.crypto)
72
- */
73
- public constructor(cryptoApi?: Crypto) {
74
- if (cryptoApi) {
75
- this._crypto = cryptoApi;
76
- } else if (typeof globalThis !== 'undefined' && globalThis.crypto) {
77
- this._crypto = globalThis.crypto;
78
- } else if (typeof window !== 'undefined' && window.crypto) {
79
- this._crypto = window.crypto;
80
- } else {
81
- throw new Error('Web Crypto API not available');
82
- }
83
- }
84
-
85
- /**
86
- * Encrypts plaintext using AES-256-GCM.
87
- * @param plaintext - UTF-8 string to encrypt
88
- * @param key - 32-byte encryption key
89
- * @returns `Success` with encryption result, or `Failure` with an error.
90
- */
91
- public async encrypt(plaintext: string, key: Uint8Array): Promise<Result<CryptoUtils.IEncryptionResult>> {
92
- if (key.length !== CryptoUtils.Constants.AES_256_KEY_SIZE) {
93
- return Failure.with(`Key must be ${CryptoUtils.Constants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
94
- }
95
-
96
- try {
97
- // Generate random IV
98
- const iv = this._crypto.getRandomValues(new Uint8Array(CryptoUtils.Constants.GCM_IV_SIZE));
99
-
100
- // Import the key
101
- const cryptoKey = await this._crypto.subtle.importKey(
102
- 'raw',
103
- toArrayBuffer(key),
104
- { name: 'AES-GCM' },
105
- false,
106
- ['encrypt']
107
- );
108
-
109
- // Encode plaintext to bytes
110
- const encoder = new TextEncoder();
111
- const plaintextBytes = encoder.encode(plaintext);
112
-
113
- // Encrypt (Web Crypto appends auth tag to ciphertext)
114
- const encryptedWithTag = await this._crypto.subtle.encrypt(
115
- {
116
- name: 'AES-GCM',
117
- iv: iv,
118
- tagLength: CryptoUtils.Constants.GCM_AUTH_TAG_SIZE * 8 // bits
119
- },
120
- cryptoKey,
121
- plaintextBytes
122
- );
123
-
124
- // Split ciphertext and auth tag (auth tag is last 16 bytes)
125
- const encryptedArray = new Uint8Array(encryptedWithTag);
126
- const encryptedData = encryptedArray.slice(
127
- 0,
128
- encryptedArray.length - CryptoUtils.Constants.GCM_AUTH_TAG_SIZE
129
- );
130
- const authTag = encryptedArray.slice(encryptedArray.length - CryptoUtils.Constants.GCM_AUTH_TAG_SIZE);
131
- return Success.with({
132
- iv,
133
- authTag,
134
- encryptedData
135
- });
136
- } catch (e) {
137
- const message = e instanceof Error ? e.message : String(e);
138
- return Failure.with(`Encryption failed: ${message}`);
139
- }
140
- }
141
-
142
- /**
143
- * Decrypts ciphertext using AES-256-GCM.
144
- * @param encryptedData - Encrypted bytes
145
- * @param key - 32-byte decryption key
146
- * @param iv - Initialization vector (12 bytes)
147
- * @param authTag - GCM authentication tag (16 bytes)
148
- * @returns `Success` with decrypted UTF-8 string, or `Failure` with an error.
149
- */
150
- public async decrypt(
151
- encryptedData: Uint8Array,
152
- key: Uint8Array,
153
- iv: Uint8Array,
154
- authTag: Uint8Array
155
- ): Promise<Result<string>> {
156
- if (key.length !== CryptoUtils.Constants.AES_256_KEY_SIZE) {
157
- return Failure.with(`Key must be ${CryptoUtils.Constants.AES_256_KEY_SIZE} bytes, got ${key.length}`);
158
- }
159
- if (iv.length !== CryptoUtils.Constants.GCM_IV_SIZE) {
160
- return Failure.with(`IV must be ${CryptoUtils.Constants.GCM_IV_SIZE} bytes, got ${iv.length}`);
161
- }
162
- if (authTag.length !== CryptoUtils.Constants.GCM_AUTH_TAG_SIZE) {
163
- return Failure.with(
164
- `Auth tag must be ${CryptoUtils.Constants.GCM_AUTH_TAG_SIZE} bytes, got ${authTag.length}`
165
- );
166
- }
167
-
168
- try {
169
- // Import the key
170
- const cryptoKey = await this._crypto.subtle.importKey(
171
- 'raw',
172
- toArrayBuffer(key),
173
- { name: 'AES-GCM' },
174
- false,
175
- ['decrypt']
176
- );
177
-
178
- // Web Crypto expects ciphertext + auth tag concatenated
179
- const encryptedWithTag = new Uint8Array(encryptedData.length + authTag.length);
180
- encryptedWithTag.set(encryptedData);
181
- encryptedWithTag.set(authTag, encryptedData.length);
182
-
183
- // Decrypt
184
- const decrypted = await this._crypto.subtle.decrypt(
185
- {
186
- name: 'AES-GCM',
187
- iv: toArrayBuffer(iv),
188
- tagLength: CryptoUtils.Constants.GCM_AUTH_TAG_SIZE * 8 // bits
189
- },
190
- cryptoKey,
191
- encryptedWithTag
192
- );
193
-
194
- // Decode to string
195
- const decoder = new TextDecoder();
196
- return Success.with(decoder.decode(decrypted));
197
- } catch (e) {
198
- const message = e instanceof Error ? e.message : String(e);
199
- return Failure.with(`Decryption failed: ${message}`);
200
- }
201
- }
202
-
203
- /**
204
- * Generates a random 32-byte key suitable for AES-256.
205
- * @returns Success with generated key, or Failure with error
206
- */
207
- public async generateKey(): Promise<Result<Uint8Array>> {
208
- try {
209
- return Success.with(
210
- this._crypto.getRandomValues(new Uint8Array(CryptoUtils.Constants.AES_256_KEY_SIZE))
211
- );
212
- } catch (e) {
213
- const message = e instanceof Error ? e.message : String(e);
214
- return Failure.with(`Key generation failed: ${message}`);
215
- }
216
- }
217
-
218
- /**
219
- * Derives a key from a password using PBKDF2.
220
- * @param password - Password string
221
- * @param salt - Salt bytes (should be at least 16 bytes)
222
- * @param iterations - Number of iterations (recommend 100000+)
223
- * @returns Success with derived 32-byte key, or Failure with error
224
- */
225
- public async deriveKey(
226
- password: string,
227
- salt: Uint8Array,
228
- iterations: number
229
- ): Promise<Result<Uint8Array>> {
230
- if (iterations < 1) {
231
- return Failure.with('Iterations must be at least 1');
232
- }
233
- if (salt.length < 8) {
234
- return Failure.with('Salt should be at least 8 bytes');
235
- }
236
-
237
- try {
238
- // Encode password
239
- const encoder = new TextEncoder();
240
- const passwordBytes = encoder.encode(password);
241
-
242
- // Import password as key material
243
- const keyMaterial = await this._crypto.subtle.importKey('raw', passwordBytes, 'PBKDF2', false, [
244
- 'deriveBits'
245
- ]);
246
-
247
- // Derive key bits
248
- const derivedBits = await this._crypto.subtle.deriveBits(
249
- {
250
- name: 'PBKDF2',
251
- salt: toArrayBuffer(salt),
252
- iterations: iterations,
253
- hash: 'SHA-256'
254
- },
255
- keyMaterial,
256
- CryptoUtils.Constants.AES_256_KEY_SIZE * 8 // bits
257
- );
258
-
259
- return Success.with(new Uint8Array(derivedBits));
260
- } catch (e) {
261
- const message = e instanceof Error ? e.message : String(e);
262
- return Failure.with(`Key derivation failed: ${message}`);
263
- }
264
- }
265
-
266
- /**
267
- * Computes a SHA-256 hash of the given data.
268
- * @param data - UTF-8 string to hash
269
- * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
270
- */
271
- public async sha256(data: string): Promise<Result<string>> {
272
- try {
273
- const encoder = new TextEncoder();
274
- const dataBuffer = encoder.encode(data);
275
- const hashBuffer = await this._crypto.subtle.digest('SHA-256', dataBuffer);
276
- const hashArray = new Uint8Array(hashBuffer);
277
- const hashHex = Array.from(hashArray)
278
- .map((b) => b.toString(16).padStart(2, '0'))
279
- .join('');
280
- return succeed(hashHex);
281
- } catch (e) {
282
- const message = e instanceof Error ? e.message : String(e);
283
- return fail(`SHA-256 hash failed: ${message}`);
284
- }
285
- }
286
-
287
- // ============================================================================
288
- // Platform Utility Methods
289
- // ============================================================================
290
-
291
- /**
292
- * Generates cryptographically secure random bytes.
293
- * @param length - Number of bytes to generate
294
- * @returns Success with random bytes, or Failure with error
295
- */
296
- public generateRandomBytes(length: number): Result<Uint8Array> {
297
- if (length < 1) {
298
- return Failure.with('Length must be at least 1');
299
- }
300
- try {
301
- return Success.with(this._crypto.getRandomValues(new Uint8Array(length)));
302
- } catch (e) {
303
- const message = e instanceof Error ? e.message : String(e);
304
- return Failure.with(`Random bytes generation failed: ${message}`);
305
- }
306
- }
307
-
308
- /**
309
- * Encodes binary data to base64 string.
310
- * @param data - Binary data to encode
311
- * @returns Base64-encoded string
312
- */
313
- public toBase64(data: Uint8Array): string {
314
- // Convert Uint8Array to binary string, then to base64
315
- let binary = '';
316
- for (let i = 0; i < data.length; i++) {
317
- binary += String.fromCharCode(data[i]);
318
- }
319
- return btoa(binary);
320
- }
321
-
322
- /**
323
- * Decodes base64 string to binary data.
324
- * @param base64 - Base64-encoded string
325
- * @returns Success with decoded bytes, or Failure if invalid base64
326
- */
327
- public fromBase64(base64: string): Result<Uint8Array> {
328
- try {
329
- const binary = atob(base64);
330
- const bytes = new Uint8Array(binary.length);
331
- for (let i = 0; i < binary.length; i++) {
332
- bytes[i] = binary.charCodeAt(i);
333
- }
334
- return Success.with(bytes);
335
- } catch (e) {
336
- return Failure.with('Invalid base64 string');
337
- }
338
- }
339
-
340
- // ============================================================================
341
- // Asymmetric Key Operations
342
- // ============================================================================
343
-
344
- /**
345
- * Generates a new asymmetric keypair via Web Crypto.
346
- * @param algorithm - The algorithm to use.
347
- * @param extractable - Whether the resulting keys may be exported.
348
- * @returns `Success` with the generated `CryptoKeyPair`, or `Failure` with an error.
349
- */
350
- public async generateKeyPair(
351
- algorithm: CryptoUtils.KeyPairAlgorithm,
352
- extractable: boolean
353
- ): Promise<Result<CryptoKeyPair>> {
354
- const params = CryptoUtils.keyPairAlgorithmParams[algorithm];
355
- const result = await captureAsyncResult(() =>
356
- this._crypto.subtle.generateKey(params.generateKey, extractable, params.keyPairUsages)
357
- );
358
- return result.withErrorFormat((e) => `Failed to generate ${algorithm} keypair: ${e}`);
359
- }
360
-
361
- /**
362
- * Exports a public `CryptoKey` as a JSON Web Key.
363
- * @remarks
364
- * Rejects non-public keys at runtime. WebCrypto's `exportKey('jwk', ...)`
365
- * does not enforce public-vs-private; without this guard a caller that
366
- * passed an extractable private key would receive its private fields
367
- * (`d`, `p`, `q`, ...) as JWK, defeating the method's name.
368
- * @param publicKey - Extractable public key to export.
369
- * @returns `Success` with the JWK, or `Failure` if not a public key or if export fails.
370
- */
371
- public async exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>> {
372
- if (publicKey.type !== 'public') {
373
- return Failure.with(`exportPublicKeyJwk requires a public CryptoKey, got '${publicKey.type}'`);
374
- }
375
- const result = await captureAsyncResult(() => this._crypto.subtle.exportKey('jwk', publicKey));
376
- return result.withErrorFormat((e) => `Failed to export public key as JWK: ${e}`);
377
- }
378
-
379
- /**
380
- * Imports a public-key JWK as a `CryptoKey` for the requested algorithm.
381
- * @param jwk - The JSON Web Key produced by a prior export.
382
- * @param algorithm - The algorithm the key was generated for.
383
- * @returns `Success` with the imported public `CryptoKey`, or `Failure` with an error.
384
- */
385
- public async importPublicKeyJwk(
386
- jwk: JsonWebKey,
387
- algorithm: CryptoUtils.KeyPairAlgorithm
388
- ): Promise<Result<CryptoKey>> {
389
- const params = CryptoUtils.keyPairAlgorithmParams[algorithm];
390
- const result = await captureAsyncResult(() =>
391
- this._crypto.subtle.importKey('jwk', jwk, params.importPublicKey, true, params.publicKeyUsages)
392
- );
393
- return result.withErrorFormat((e) => `Failed to import ${algorithm} public key from JWK: ${e}`);
394
- }
395
- /* c8 ignore stop */
396
-
397
- /**
398
- * Wraps `plaintext` for the holder of `recipientPublicKey` using
399
- * ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
400
- * {@link CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes}.
401
- * @param plaintext - The bytes to wrap.
402
- * @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
403
- * @param options - HKDF salt and info; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
404
- * @returns `Success` with the wrapped payload, or `Failure` with an error.
405
- */
406
- public async wrapBytes(
407
- plaintext: Uint8Array,
408
- recipientPublicKey: CryptoKey,
409
- options: CryptoUtils.IWrapBytesOptions
410
- ): Promise<Result<CryptoUtils.IWrappedBytes>> {
411
- const recipientCheck = checkEcdhP256(recipientPublicKey, 'public', 'recipient public key');
412
- if (recipientCheck.isFailure()) {
413
- return Failure.with(`wrapBytes failed: ${recipientCheck.message}`);
414
- }
415
- const subtle = this._crypto.subtle;
416
- const result = await captureAsyncResult(async () => {
417
- const ephemeral = (await subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, [
418
- 'deriveKey'
419
- ])) as CryptoKeyPair;
420
- const hkdfBase = await subtle.deriveKey(
421
- { name: 'ECDH', public: recipientPublicKey },
422
- ephemeral.privateKey,
423
- { name: 'HKDF' },
424
- false,
425
- ['deriveKey']
426
- );
427
- const wrapKey = await subtle.deriveKey(
428
- { name: 'HKDF', salt: toBufferView(options.salt), info: toBufferView(options.info), hash: 'SHA-256' },
429
- hkdfBase,
430
- { name: 'AES-GCM', length: 256 },
431
- false,
432
- ['encrypt']
433
- );
434
- const nonce = this._crypto.getRandomValues(new Uint8Array(CryptoUtils.Constants.GCM_IV_SIZE));
435
- const ctBuf = await subtle.encrypt({ name: 'AES-GCM', iv: nonce }, wrapKey, toBufferView(plaintext));
436
- const ephemeralPublicKey = await subtle.exportKey('jwk', ephemeral.publicKey);
437
- return {
438
- ephemeralPublicKey,
439
- nonce: this.toBase64(nonce),
440
- ciphertext: this.toBase64(new Uint8Array(ctBuf))
441
- };
442
- });
443
- return result.withErrorFormat((e) => `wrapBytes failed: ${e}`);
444
- }
445
-
446
- /**
447
- * Unwraps a payload produced by `wrapBytes` using the recipient's private
448
- * key. See {@link CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes}.
449
- * @param wrapped - The wrapped payload.
450
- * @param recipientPrivateKey - The recipient's ECDH P-256 private `CryptoKey`.
451
- * @param options - HKDF salt and info matching the wrap call.
452
- * @returns `Success` with the original `plaintext`, or `Failure` with an error.
453
- */
454
- public async unwrapBytes(
455
- wrapped: CryptoUtils.IWrappedBytes,
456
- recipientPrivateKey: CryptoKey,
457
- options: CryptoUtils.IWrapBytesOptions
458
- ): Promise<Result<Uint8Array>> {
459
- const recipientCheck = checkEcdhP256(recipientPrivateKey, 'private', 'recipient private key');
460
- if (recipientCheck.isFailure()) {
461
- return Failure.with(`unwrapBytes failed: ${recipientCheck.message}`);
462
- }
463
- const nonceResult = this.fromBase64(wrapped.nonce);
464
- if (nonceResult.isFailure()) {
465
- return Failure.with(`unwrapBytes failed: nonce: ${nonceResult.message}`);
466
- }
467
- if (nonceResult.value.length !== CryptoUtils.Constants.GCM_IV_SIZE) {
468
- return Failure.with(
469
- `unwrapBytes failed: nonce must be ${CryptoUtils.Constants.GCM_IV_SIZE} bytes (got ${nonceResult.value.length})`
470
- );
471
- }
472
- const ciphertextResult = this.fromBase64(wrapped.ciphertext);
473
- if (ciphertextResult.isFailure()) {
474
- return Failure.with(`unwrapBytes failed: ciphertext: ${ciphertextResult.message}`);
475
- }
476
- if (ciphertextResult.value.length < CryptoUtils.Constants.GCM_AUTH_TAG_SIZE) {
477
- return Failure.with(
478
- `unwrapBytes failed: ciphertext must be at least ${CryptoUtils.Constants.GCM_AUTH_TAG_SIZE} bytes (got ${ciphertextResult.value.length})`
479
- );
480
- }
481
- const subtle = this._crypto.subtle;
482
- const result = await captureAsyncResult(async () => {
483
- const ephemeralPub = await subtle.importKey(
484
- 'jwk',
485
- wrapped.ephemeralPublicKey,
486
- { name: 'ECDH', namedCurve: 'P-256' },
487
- false,
488
- []
489
- );
490
- const hkdfBase = await subtle.deriveKey(
491
- { name: 'ECDH', public: ephemeralPub },
492
- recipientPrivateKey,
493
- { name: 'HKDF' },
494
- false,
495
- ['deriveKey']
496
- );
497
- const wrapKey = await subtle.deriveKey(
498
- { name: 'HKDF', salt: toBufferView(options.salt), info: toBufferView(options.info), hash: 'SHA-256' },
499
- hkdfBase,
500
- { name: 'AES-GCM', length: 256 },
501
- false,
502
- ['decrypt']
503
- );
504
- const ptBuf = await subtle.decrypt(
505
- { name: 'AES-GCM', iv: toBufferView(nonceResult.value) },
506
- wrapKey,
507
- toBufferView(ciphertextResult.value)
508
- );
509
- return new Uint8Array(ptBuf);
510
- });
511
- return result.withErrorFormat((e) => `unwrapBytes failed: ${e}`);
512
- }
513
- }
514
-
515
- /**
516
- * Verifies that `key` is an ECDH P-256 `CryptoKey` of the expected `keyType`
517
- * (public or private). Used by the wrap/unwrap methods to surface a clean
518
- * `Failure` instead of letting the WebCrypto deriveKey call throw a less
519
- * informative error later in the pipeline. Key usages are intentionally not
520
- * checked here: WebCrypto already produces a specific error if `deriveKey` is
521
- * not in `usages`, and `deriveBits` is an equally valid alternative usage that
522
- * an explicit check would have to track.
523
- * @param key - The CryptoKey to validate.
524
- * @param keyType - The required `key.type` ('public' for wrap, 'private' for unwrap).
525
- * @param label - Human-readable role label included in the failure message.
526
- * @returns `Success` with the key (unchanged) when the algorithm, curve, and
527
- * type all match; otherwise `Failure` with `<label> must be ECDH P-256 (...)`.
528
- */
529
- function checkEcdhP256(key: CryptoKey, keyType: 'public' | 'private', label: string): Result<CryptoKey> {
530
- if (key.algorithm.name !== 'ECDH') {
531
- return Failure.with(`${label} must be ECDH P-256 (got algorithm '${key.algorithm.name}')`);
532
- }
533
- const namedCurve = (key.algorithm as EcKeyAlgorithm).namedCurve;
534
- if (namedCurve !== 'P-256') {
535
- return Failure.with(`${label} must be ECDH P-256 (got curve '${namedCurve}')`);
536
- }
537
- if (key.type !== keyType) {
538
- return Failure.with(`${label} must be a ${keyType} CryptoKey (got '${key.type}')`);
539
- }
540
- return succeed(key);
541
- }
542
-
543
- /* c8 ignore start - Constructs a provider; only meaningful in a real browser environment */
544
- /**
545
- * Creates a {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider} if Web
546
- * Crypto API is available.
547
- * @returns `Success` with provider, or `Failure` if not available
548
- * @public
549
- */
550
- export function createBrowserCryptoProvider(): Result<BrowserCryptoProvider> {
551
- return captureResult(() => new BrowserCryptoProvider());
552
- }
553
- /* c8 ignore stop */
@@ -1,73 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { Result, succeed, fail } from '@fgv/ts-utils';
24
-
25
- /**
26
- * Browser-compatible hash provider using the Web Crypto API.
27
- * Supports common hash algorithms available in browsers.
28
- * @public
29
- */
30
- export class BrowserHashProvider {
31
- /**
32
- * Hash a string using the specified algorithm.
33
- * @param data - The string to hash
34
- * @param algorithm - The hash algorithm to use
35
- * @returns Promise resolving to the hex-encoded hash
36
- */
37
- public static async hashString(data: string, algorithm: string = 'SHA-256'): Promise<Result<string>> {
38
- try {
39
- /* c8 ignore next 3 - defense in depth */
40
- if (!crypto.subtle) {
41
- return fail('Web Crypto API not available in this environment');
42
- }
43
-
44
- const encoder = new TextEncoder();
45
- const dataBuffer = encoder.encode(data);
46
- const hashBuffer = await crypto.subtle.digest(algorithm, dataBuffer);
47
- const hashArray = new Uint8Array(hashBuffer);
48
- const hashHex = Array.from(hashArray)
49
- .map((b) => b.toString(16).padStart(2, '0'))
50
- .join('');
51
-
52
- return succeed(hashHex);
53
- } catch (error) {
54
- return fail(`Hash computation failed: ${error instanceof Error ? error.message : String(error)}`);
55
- }
56
- }
57
-
58
- /**
59
- * Hash multiple strings concatenated with a separator.
60
- * @param parts - Array of strings to concatenate and hash
61
- * @param algorithm - The hash algorithm to use
62
- * @param separator - Separator to use between parts (default: '|')
63
- * @returns Promise resolving to the hex-encoded hash
64
- */
65
- public static async hashParts(
66
- parts: string[],
67
- algorithm: string = 'SHA-256',
68
- separator: string = '|'
69
- ): Promise<Result<string>> {
70
- const combined = parts.join(separator);
71
- return this.hashString(combined, algorithm);
72
- }
73
- }
@@ -1,29 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- /**
24
- * Browser-compatible cryptographic utilities using the Web Crypto API.
25
- * @packageDocumentation
26
- */
27
-
28
- export * from './browserHashProvider';
29
- export * from './browserCryptoProvider';