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