@metamask/profile-sync-controller 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -1
- package/auth/mocks/package.json +2 -2
- package/auth/package.json +2 -2
- package/dist/controllers/authentication/AuthenticationController.cjs +211 -0
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -0
- package/dist/{types/controllers/authentication/AuthenticationController.d.ts → controllers/authentication/AuthenticationController.d.cts} +5 -5
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.d.mts +78 -0
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.mjs +206 -11
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/authentication/__fixtures__/index.cjs +18 -0
- package/dist/controllers/authentication/__fixtures__/index.cjs.map +1 -0
- package/dist/controllers/authentication/__fixtures__/index.d.cts +2 -0
- package/dist/controllers/authentication/__fixtures__/index.d.cts.map +1 -0
- package/dist/controllers/authentication/__fixtures__/index.d.mts +2 -0
- package/dist/controllers/authentication/__fixtures__/index.d.mts.map +1 -0
- package/dist/controllers/authentication/__fixtures__/index.mjs +2 -0
- package/dist/controllers/authentication/__fixtures__/index.mjs.map +1 -0
- package/dist/controllers/authentication/__fixtures__/mockResponses.cjs +52 -0
- package/dist/controllers/authentication/__fixtures__/mockResponses.cjs.map +1 -0
- package/dist/{types/controllers/authentication/__fixtures__/mockResponses.d.ts → controllers/authentication/__fixtures__/mockResponses.d.cts} +2 -2
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts.map +1 -0
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts +23 -0
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts.map +1 -0
- package/dist/controllers/authentication/__fixtures__/mockResponses.mjs +46 -0
- package/dist/controllers/authentication/__fixtures__/mockResponses.mjs.map +1 -0
- package/dist/controllers/authentication/__fixtures__/mockServices.cjs +37 -0
- package/dist/controllers/authentication/__fixtures__/mockServices.cjs.map +1 -0
- package/dist/{types/controllers/authentication/__fixtures__/mockServices.d.ts → controllers/authentication/__fixtures__/mockServices.d.cts} +2 -2
- package/dist/controllers/authentication/__fixtures__/mockServices.d.cts.map +1 -0
- package/dist/controllers/authentication/__fixtures__/mockServices.d.mts +10 -0
- package/dist/controllers/authentication/__fixtures__/mockServices.d.mts.map +1 -0
- package/dist/controllers/authentication/__fixtures__/mockServices.mjs +35 -0
- package/dist/controllers/authentication/__fixtures__/mockServices.mjs.map +1 -0
- package/dist/controllers/authentication/auth-snap-requests.cjs +39 -0
- package/dist/controllers/authentication/auth-snap-requests.cjs.map +1 -0
- package/dist/{types/controllers/authentication/auth-snap-requests.d.ts → controllers/authentication/auth-snap-requests.d.cts} +2 -2
- package/dist/controllers/authentication/auth-snap-requests.d.cts.map +1 -0
- package/dist/controllers/authentication/auth-snap-requests.d.mts +17 -0
- package/dist/controllers/authentication/auth-snap-requests.d.mts.map +1 -0
- package/dist/controllers/authentication/auth-snap-requests.mjs +33 -9
- package/dist/controllers/authentication/auth-snap-requests.mjs.map +1 -1
- package/dist/controllers/authentication/index.cjs +39 -0
- package/dist/controllers/authentication/index.cjs.map +1 -0
- package/dist/controllers/authentication/index.d.cts +7 -0
- package/dist/controllers/authentication/index.d.cts.map +1 -0
- package/dist/controllers/authentication/index.d.mts +7 -0
- package/dist/controllers/authentication/index.d.mts.map +1 -0
- package/dist/controllers/authentication/index.mjs +6 -18
- package/dist/controllers/authentication/index.mjs.map +1 -1
- package/dist/controllers/authentication/services.cjs +127 -0
- package/dist/controllers/authentication/services.cjs.map +1 -0
- package/dist/{types/controllers/authentication/services.d.ts → controllers/authentication/services.d.cts} +1 -1
- package/dist/controllers/authentication/services.d.cts.map +1 -0
- package/dist/controllers/authentication/services.d.mts +70 -0
- package/dist/controllers/authentication/services.d.mts.map +1 -0
- package/dist/controllers/authentication/services.mjs +118 -19
- package/dist/controllers/authentication/services.mjs.map +1 -1
- package/dist/controllers/index.cjs +29 -0
- package/dist/controllers/index.cjs.map +1 -0
- package/dist/controllers/index.d.cts +3 -0
- package/dist/controllers/index.d.cts.map +1 -0
- package/dist/controllers/index.d.mts +3 -0
- package/dist/controllers/index.d.mts.map +1 -0
- package/dist/controllers/index.mjs +2 -24
- package/dist/controllers/index.mjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.cjs +462 -0
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/UserStorageController.d.ts → controllers/user-storage/UserStorageController.d.cts} +44 -15
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.d.mts +156 -0
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.mjs +457 -18
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/index.cjs +19 -0
- package/dist/controllers/user-storage/__fixtures__/index.cjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/index.d.cts +3 -0
- package/dist/controllers/user-storage/__fixtures__/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/index.d.mts +3 -0
- package/dist/controllers/user-storage/__fixtures__/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/index.mjs +3 -0
- package/dist/controllers/user-storage/__fixtures__/index.mjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs +127 -0
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/__fixtures__/mockAccounts.d.ts → controllers/user-storage/__fixtures__/mockAccounts.d.cts} +6 -6
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.cts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts +63 -0
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.d.mts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs +123 -0
- package/dist/controllers/user-storage/__fixtures__/mockAccounts.mjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs +48 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/__fixtures__/mockResponses.d.ts → controllers/user-storage/__fixtures__/mockResponses.d.cts} +6 -4
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts +21 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs +39 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockServices.cjs +41 -0
- package/dist/controllers/user-storage/__fixtures__/mockServices.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/__fixtures__/mockServices.d.ts → controllers/user-storage/__fixtures__/mockServices.d.cts} +3 -3
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts +11 -0
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockServices.mjs +39 -0
- package/dist/controllers/user-storage/__fixtures__/mockServices.mjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockStorage.cjs +36 -0
- package/dist/controllers/user-storage/__fixtures__/mockStorage.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/__fixtures__/mockStorage.d.ts → controllers/user-storage/__fixtures__/mockStorage.d.cts} +2 -2
- package/dist/controllers/user-storage/__fixtures__/mockStorage.d.cts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockStorage.d.mts +5 -0
- package/dist/controllers/user-storage/__fixtures__/mockStorage.d.mts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockStorage.mjs +9 -0
- package/dist/controllers/user-storage/__fixtures__/mockStorage.mjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +31 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +14 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +14 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +27 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +1 -0
- package/dist/controllers/user-storage/accounts/constants.cjs +51 -0
- package/dist/controllers/user-storage/accounts/constants.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/accounts/constants.d.ts → controllers/user-storage/accounts/constants.d.cts} +1 -1
- package/dist/controllers/user-storage/accounts/constants.d.cts.map +1 -0
- package/dist/controllers/user-storage/accounts/constants.d.mts +4 -0
- package/dist/controllers/user-storage/accounts/constants.d.mts.map +1 -0
- package/dist/controllers/user-storage/accounts/constants.mjs +47 -11
- package/dist/controllers/user-storage/accounts/constants.mjs.map +1 -1
- package/dist/controllers/user-storage/accounts/user-storage.cjs +34 -0
- package/dist/controllers/user-storage/accounts/user-storage.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/accounts/user-storage.d.ts → controllers/user-storage/accounts/user-storage.d.cts} +3 -3
- package/dist/controllers/user-storage/accounts/user-storage.d.cts.map +1 -0
- package/dist/controllers/user-storage/accounts/user-storage.d.mts +32 -0
- package/dist/controllers/user-storage/accounts/user-storage.d.mts.map +1 -0
- package/dist/controllers/user-storage/accounts/user-storage.mjs +27 -9
- package/dist/controllers/user-storage/accounts/user-storage.mjs.map +1 -1
- package/dist/controllers/user-storage/encryption/cache.cjs +79 -0
- package/dist/controllers/user-storage/encryption/cache.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/encryption/cache.d.ts → controllers/user-storage/encryption/cache.d.cts} +1 -1
- package/dist/controllers/user-storage/encryption/cache.d.cts.map +1 -0
- package/dist/controllers/user-storage/encryption/cache.d.mts +31 -0
- package/dist/controllers/user-storage/encryption/cache.d.mts.map +1 -0
- package/dist/controllers/user-storage/encryption/cache.mjs +71 -11
- package/dist/controllers/user-storage/encryption/cache.mjs.map +1 -1
- package/dist/controllers/user-storage/encryption/encryption.cjs +151 -0
- package/dist/controllers/user-storage/encryption/encryption.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/encryption/encryption.d.ts → controllers/user-storage/encryption/encryption.d.cts} +2 -2
- package/dist/controllers/user-storage/encryption/encryption.d.cts.map +1 -0
- package/dist/controllers/user-storage/encryption/encryption.d.mts +27 -0
- package/dist/controllers/user-storage/encryption/encryption.d.mts.map +1 -0
- package/dist/controllers/user-storage/encryption/encryption.mjs +145 -10
- package/dist/controllers/user-storage/encryption/encryption.mjs.map +1 -1
- package/dist/controllers/user-storage/encryption/index.cjs +25 -0
- package/dist/controllers/user-storage/encryption/index.cjs.map +1 -0
- package/dist/controllers/user-storage/encryption/index.d.cts +5 -0
- package/dist/controllers/user-storage/encryption/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/encryption/index.d.mts +5 -0
- package/dist/controllers/user-storage/encryption/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/encryption/index.mjs +4 -15
- package/dist/controllers/user-storage/encryption/index.mjs.map +1 -1
- package/dist/controllers/user-storage/encryption/utils.cjs +17 -0
- package/dist/controllers/user-storage/encryption/utils.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/encryption/utils.d.ts → controllers/user-storage/encryption/utils.d.cts} +1 -1
- package/dist/controllers/user-storage/encryption/utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/encryption/utils.d.mts +4 -0
- package/dist/controllers/user-storage/encryption/utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/encryption/utils.mjs +9 -10
- package/dist/controllers/user-storage/encryption/utils.mjs.map +1 -1
- package/dist/controllers/user-storage/index.cjs +40 -0
- package/dist/controllers/user-storage/index.cjs.map +1 -0
- package/dist/controllers/user-storage/index.d.cts +8 -0
- package/dist/controllers/user-storage/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/index.d.mts +8 -0
- package/dist/controllers/user-storage/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/index.mjs +7 -30
- package/dist/controllers/user-storage/index.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs +25 -0
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts +4 -0
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts +4 -0
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs +20 -0
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +65 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +13 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +13 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +65 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/services.cjs +64 -0
- package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/services.d.cts +21 -0
- package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/services.d.mts +21 -0
- package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/services.mjs +58 -0
- package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/sync-all.cjs +171 -0
- package/dist/controllers/user-storage/network-syncing/sync-all.cjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/sync-all.d.cts +35 -0
- package/dist/controllers/user-storage/network-syncing/sync-all.d.cts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/sync-all.d.mts +35 -0
- package/dist/controllers/user-storage/network-syncing/sync-all.d.mts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/sync-all.mjs +162 -0
- package/dist/controllers/user-storage/network-syncing/sync-all.mjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs +28 -0
- package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts +9 -0
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts +9 -0
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs +22 -0
- package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/types.cjs +16 -0
- package/dist/controllers/user-storage/network-syncing/types.cjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/types.d.cts +18 -0
- package/dist/controllers/user-storage/network-syncing/types.d.cts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/types.d.mts +18 -0
- package/dist/controllers/user-storage/network-syncing/types.d.mts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/types.mjs +11 -0
- package/dist/controllers/user-storage/network-syncing/types.mjs.map +1 -0
- package/dist/controllers/user-storage/schema.cjs +56 -0
- package/dist/controllers/user-storage/schema.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/schema.d.ts → controllers/user-storage/schema.d.cts} +2 -1
- package/dist/controllers/user-storage/schema.d.cts.map +1 -0
- package/dist/controllers/user-storage/schema.d.mts +38 -0
- package/dist/controllers/user-storage/schema.d.mts.map +1 -0
- package/dist/controllers/user-storage/schema.mjs +48 -16
- package/dist/controllers/user-storage/schema.mjs.map +1 -1
- package/dist/controllers/user-storage/services.cjs +119 -0
- package/dist/controllers/user-storage/services.cjs.map +1 -0
- package/dist/{types/controllers/user-storage/services.d.ts → controllers/user-storage/services.d.cts} +4 -5
- package/dist/controllers/user-storage/services.d.cts.map +1 -0
- package/dist/controllers/user-storage/services.d.mts +48 -0
- package/dist/controllers/user-storage/services.d.mts.map +1 -0
- package/dist/controllers/user-storage/services.mjs +116 -21
- package/dist/controllers/user-storage/services.mjs.map +1 -1
- package/dist/controllers/user-storage/utils.cjs +30 -0
- package/dist/controllers/user-storage/utils.cjs.map +1 -0
- package/dist/controllers/user-storage/utils.d.cts +17 -0
- package/dist/controllers/user-storage/utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/utils.d.mts +17 -0
- package/dist/controllers/user-storage/utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/utils.mjs +25 -0
- package/dist/controllers/user-storage/utils.mjs.map +1 -0
- package/dist/index.cjs +30 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -39
- package/dist/index.mjs.map +1 -1
- package/dist/sdk/__fixtures__/mock-auth.cjs +139 -0
- package/dist/sdk/__fixtures__/mock-auth.cjs.map +1 -0
- package/dist/{types/sdk/__fixtures__/mock-auth.d.ts → sdk/__fixtures__/mock-auth.d.cts} +2 -2
- package/dist/sdk/__fixtures__/mock-auth.d.cts.map +1 -0
- package/dist/sdk/__fixtures__/mock-auth.d.mts +42 -0
- package/dist/sdk/__fixtures__/mock-auth.d.mts.map +1 -0
- package/dist/sdk/__fixtures__/mock-auth.mjs +134 -0
- package/dist/sdk/__fixtures__/mock-auth.mjs.map +1 -0
- package/dist/sdk/__fixtures__/mock-userstorage.cjs +58 -0
- package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +1 -0
- package/dist/{types/sdk/__fixtures__/mock-userstorage.d.ts → sdk/__fixtures__/mock-userstorage.d.cts} +2 -2
- package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +1 -0
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts +19 -0
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +1 -0
- package/dist/sdk/__fixtures__/mock-userstorage.mjs +54 -0
- package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +1 -0
- package/dist/sdk/__fixtures__/test-utils.cjs +74 -0
- package/dist/sdk/__fixtures__/test-utils.cjs.map +1 -0
- package/dist/{types/sdk/__fixtures__/test-utils.d.ts → sdk/__fixtures__/test-utils.d.cts} +6 -6
- package/dist/sdk/__fixtures__/test-utils.d.cts.map +1 -0
- package/dist/sdk/__fixtures__/test-utils.d.mts +25 -0
- package/dist/sdk/__fixtures__/test-utils.d.mts.map +1 -0
- package/dist/sdk/__fixtures__/test-utils.mjs +69 -0
- package/dist/sdk/__fixtures__/test-utils.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +106 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -0
- package/dist/{types/sdk/authentication-jwt-bearer/flow-siwe.d.ts → sdk/authentication-jwt-bearer/flow-siwe.d.cts} +2 -2
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +23 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +101 -11
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +125 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -0
- package/dist/{types/sdk/authentication-jwt-bearer/flow-srp.d.ts → sdk/authentication-jwt-bearer/flow-srp.d.cts} +4 -2
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +19 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +119 -13
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs +180 -0
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -0
- package/dist/{types/sdk/authentication-jwt-bearer/services.d.ts → sdk/authentication-jwt-bearer/services.d.cts} +4 -4
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +63 -0
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/services.mjs +166 -25
- package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.cjs +12 -0
- package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -0
- package/dist/{types/sdk/authentication-jwt-bearer/types.d.ts → sdk/authentication-jwt-bearer/types.d.cts} +2 -2
- package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/types.d.mts +67 -0
- package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/types.mjs +8 -7
- package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
- package/dist/sdk/authentication.cjs +124 -0
- package/dist/sdk/authentication.cjs.map +1 -0
- package/dist/{types/sdk/authentication.d.ts → sdk/authentication.d.cts} +7 -7
- package/dist/sdk/authentication.d.cts.map +1 -0
- package/dist/sdk/authentication.d.mts +32 -0
- package/dist/sdk/authentication.d.mts.map +1 -0
- package/dist/sdk/authentication.mjs +102 -24
- package/dist/sdk/authentication.mjs.map +1 -1
- package/dist/sdk/encryption.cjs +23 -0
- package/dist/sdk/encryption.cjs.map +1 -0
- package/dist/sdk/encryption.d.cts +4 -0
- package/dist/sdk/encryption.d.cts.map +1 -0
- package/dist/sdk/encryption.d.mts +4 -0
- package/dist/sdk/encryption.d.mts.map +1 -0
- package/dist/sdk/encryption.mjs +3 -13
- package/dist/sdk/encryption.mjs.map +1 -1
- package/dist/sdk/env.cjs +85 -0
- package/dist/sdk/env.cjs.map +1 -0
- package/dist/{types/sdk/env.d.ts → sdk/env.d.cts} +1 -1
- package/dist/sdk/env.d.cts.map +1 -0
- package/dist/sdk/env.d.mts +34 -0
- package/dist/sdk/env.d.mts.map +1 -0
- package/dist/sdk/env.mjs +78 -12
- package/dist/sdk/env.mjs.map +1 -1
- package/dist/sdk/errors.cjs +53 -0
- package/dist/sdk/errors.cjs.map +1 -0
- package/dist/{types/sdk/errors.d.ts → sdk/errors.d.cts} +1 -1
- package/dist/sdk/errors.d.cts.map +1 -0
- package/dist/sdk/errors.d.mts +22 -0
- package/dist/sdk/errors.d.mts.map +1 -0
- package/dist/sdk/errors.mjs +42 -19
- package/dist/sdk/errors.mjs.map +1 -1
- package/dist/sdk/index.cjs +23 -0
- package/dist/sdk/index.cjs.map +1 -0
- package/dist/sdk/index.d.cts +7 -0
- package/dist/sdk/index.d.cts.map +1 -0
- package/dist/sdk/index.d.mts +7 -0
- package/dist/sdk/index.d.mts.map +1 -0
- package/dist/sdk/index.mjs +6 -78
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/sdk/user-storage.cjs +176 -0
- package/dist/sdk/user-storage.cjs.map +1 -0
- package/dist/{types/sdk/user-storage.d.ts → sdk/user-storage.d.cts} +4 -4
- package/dist/sdk/user-storage.d.cts.map +1 -0
- package/dist/sdk/user-storage.d.mts +27 -0
- package/dist/sdk/user-storage.d.mts.map +1 -0
- package/dist/sdk/user-storage.mjs +146 -16
- package/dist/sdk/user-storage.mjs.map +1 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.cjs +70 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.cjs.map +1 -0
- package/dist/{types/sdk/utils/eip-6963-metamask-provider.d.ts → sdk/utils/eip-6963-metamask-provider.d.cts} +2 -2
- package/dist/sdk/utils/eip-6963-metamask-provider.d.cts.map +1 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.d.mts +25 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.d.mts.map +1 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.mjs +64 -8
- package/dist/sdk/utils/eip-6963-metamask-provider.mjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs +73 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -0
- package/dist/{types/sdk/utils/messaging-signing-snap-requests.d.ts → sdk/utils/messaging-signing-snap-requests.d.cts} +2 -7
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +35 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs +65 -16
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
- package/dist/sdk/utils/validate-login-response.cjs +22 -0
- package/dist/sdk/utils/validate-login-response.cjs.map +1 -0
- package/dist/{types/sdk/utils/validate-login-response.d.ts → sdk/utils/validate-login-response.d.cts} +2 -2
- package/dist/sdk/utils/validate-login-response.d.cts.map +1 -0
- package/dist/sdk/utils/validate-login-response.d.mts +10 -0
- package/dist/sdk/utils/validate-login-response.d.mts.map +1 -0
- package/dist/sdk/utils/validate-login-response.mjs +17 -7
- package/dist/sdk/utils/validate-login-response.mjs.map +1 -1
- package/package.json +62 -30
- package/sdk/package.json +9 -0
- package/user-storage/mocks/package.json +2 -2
- package/user-storage/package.json +2 -2
- package/dist/chunk-2CWF7ZTL.mjs +0 -129
- package/dist/chunk-2CWF7ZTL.mjs.map +0 -1
- package/dist/chunk-2VEMA6OE.mjs +0 -47
- package/dist/chunk-2VEMA6OE.mjs.map +0 -1
- package/dist/chunk-4LMFZDL4.js +0 -114
- package/dist/chunk-4LMFZDL4.js.map +0 -1
- package/dist/chunk-4TMLEABQ.js +0 -79
- package/dist/chunk-4TMLEABQ.js.map +0 -1
- package/dist/chunk-5MQUI24U.js +0 -47
- package/dist/chunk-5MQUI24U.js.map +0 -1
- package/dist/chunk-5XSXZTED.mjs +0 -57
- package/dist/chunk-5XSXZTED.mjs.map +0 -1
- package/dist/chunk-6DAK2U35.mjs +0 -11
- package/dist/chunk-6DAK2U35.mjs.map +0 -1
- package/dist/chunk-76NMME23.mjs +0 -114
- package/dist/chunk-76NMME23.mjs.map +0 -1
- package/dist/chunk-76VRE4BI.mjs +0 -18
- package/dist/chunk-76VRE4BI.mjs.map +0 -1
- package/dist/chunk-BKQE7DB5.js +0 -170
- package/dist/chunk-BKQE7DB5.js.map +0 -1
- package/dist/chunk-CAIIVJAO.mjs +0 -11
- package/dist/chunk-CAIIVJAO.mjs.map +0 -1
- package/dist/chunk-COBJUBZE.mjs +0 -170
- package/dist/chunk-COBJUBZE.mjs.map +0 -1
- package/dist/chunk-D4SNJOID.mjs +0 -269
- package/dist/chunk-D4SNJOID.mjs.map +0 -1
- package/dist/chunk-DF24ZX4H.js +0 -76
- package/dist/chunk-DF24ZX4H.js.map +0 -1
- package/dist/chunk-DRB2MN4T.js +0 -16
- package/dist/chunk-DRB2MN4T.js.map +0 -1
- package/dist/chunk-EHZFPUJH.mjs +0 -53
- package/dist/chunk-EHZFPUJH.mjs.map +0 -1
- package/dist/chunk-F6BAOSH2.js +0 -269
- package/dist/chunk-F6BAOSH2.js.map +0 -1
- package/dist/chunk-GQXYWBFK.js +0 -28
- package/dist/chunk-GQXYWBFK.js.map +0 -1
- package/dist/chunk-H25EBXG5.mjs +0 -58
- package/dist/chunk-H25EBXG5.mjs.map +0 -1
- package/dist/chunk-IGY2S5BC.js +0 -36
- package/dist/chunk-IGY2S5BC.js.map +0 -1
- package/dist/chunk-JAQ5TPSZ.js +0 -53
- package/dist/chunk-JAQ5TPSZ.js.map +0 -1
- package/dist/chunk-KHASG4H3.mjs +0 -11
- package/dist/chunk-KHASG4H3.mjs.map +0 -1
- package/dist/chunk-KIVBL6OM.js +0 -129
- package/dist/chunk-KIVBL6OM.js.map +0 -1
- package/dist/chunk-KTCSRECK.mjs +0 -76
- package/dist/chunk-KTCSRECK.mjs.map +0 -1
- package/dist/chunk-LGXQBALM.mjs +0 -106
- package/dist/chunk-LGXQBALM.mjs.map +0 -1
- package/dist/chunk-LLG4D2SC.js +0 -157
- package/dist/chunk-LLG4D2SC.js.map +0 -1
- package/dist/chunk-M7AUA5W7.mjs +0 -79
- package/dist/chunk-M7AUA5W7.mjs.map +0 -1
- package/dist/chunk-MBTBE4P5.js +0 -54
- package/dist/chunk-MBTBE4P5.js.map +0 -1
- package/dist/chunk-MK7ABX2V.mjs +0 -186
- package/dist/chunk-MK7ABX2V.mjs.map +0 -1
- package/dist/chunk-NEBLEB3X.mjs +0 -107
- package/dist/chunk-NEBLEB3X.mjs.map +0 -1
- package/dist/chunk-NIUQ34PY.js +0 -11
- package/dist/chunk-NIUQ34PY.js.map +0 -1
- package/dist/chunk-NMIF3LSX.mjs +0 -29
- package/dist/chunk-NMIF3LSX.mjs.map +0 -1
- package/dist/chunk-OLFO6R7Z.mjs +0 -546
- package/dist/chunk-OLFO6R7Z.mjs.map +0 -1
- package/dist/chunk-PBRUOBEQ.js +0 -11
- package/dist/chunk-PBRUOBEQ.js.map +0 -1
- package/dist/chunk-PCOIRDTO.js +0 -18
- package/dist/chunk-PCOIRDTO.js.map +0 -1
- package/dist/chunk-PQMPSEVJ.js +0 -546
- package/dist/chunk-PQMPSEVJ.js.map +0 -1
- package/dist/chunk-PRYLTXW4.js +0 -92
- package/dist/chunk-PRYLTXW4.js.map +0 -1
- package/dist/chunk-PU7MAIST.mjs +0 -129
- package/dist/chunk-PU7MAIST.mjs.map +0 -1
- package/dist/chunk-QCQU4BQL.js +0 -68
- package/dist/chunk-QCQU4BQL.js.map +0 -1
- package/dist/chunk-QDGLIUUS.mjs +0 -16
- package/dist/chunk-QDGLIUUS.mjs.map +0 -1
- package/dist/chunk-RG4II6WH.js +0 -57
- package/dist/chunk-RG4II6WH.js.map +0 -1
- package/dist/chunk-TFFQFIJV.mjs +0 -54
- package/dist/chunk-TFFQFIJV.mjs.map +0 -1
- package/dist/chunk-TP7SP3AG.mjs +0 -133
- package/dist/chunk-TP7SP3AG.mjs.map +0 -1
- package/dist/chunk-U5UIDVOO.mjs +0 -36
- package/dist/chunk-U5UIDVOO.mjs.map +0 -1
- package/dist/chunk-UAXWZN5J.js +0 -58
- package/dist/chunk-UAXWZN5J.js.map +0 -1
- package/dist/chunk-UEHMUVQQ.js +0 -133
- package/dist/chunk-UEHMUVQQ.js.map +0 -1
- package/dist/chunk-UEWCUBMX.mjs +0 -68
- package/dist/chunk-UEWCUBMX.mjs.map +0 -1
- package/dist/chunk-UHP2Y32K.mjs +0 -92
- package/dist/chunk-UHP2Y32K.mjs.map +0 -1
- package/dist/chunk-UHX7HJAI.js +0 -11
- package/dist/chunk-UHX7HJAI.js.map +0 -1
- package/dist/chunk-UIRAMHNM.js +0 -186
- package/dist/chunk-UIRAMHNM.js.map +0 -1
- package/dist/chunk-VWDRFRJU.js +0 -107
- package/dist/chunk-VWDRFRJU.js.map +0 -1
- package/dist/chunk-Y45XUW33.js +0 -129
- package/dist/chunk-Y45XUW33.js.map +0 -1
- package/dist/chunk-YHGWG3EQ.js +0 -29
- package/dist/chunk-YHGWG3EQ.js.map +0 -1
- package/dist/chunk-YLURF2PF.mjs +0 -157
- package/dist/chunk-YLURF2PF.mjs.map +0 -1
- package/dist/chunk-ZUPTMFEA.mjs +0 -28
- package/dist/chunk-ZUPTMFEA.mjs.map +0 -1
- package/dist/chunk-ZX2KHPXG.js +0 -106
- package/dist/chunk-ZX2KHPXG.js.map +0 -1
- package/dist/controllers/authentication/AuthenticationController.js +0 -13
- package/dist/controllers/authentication/AuthenticationController.js.map +0 -1
- package/dist/controllers/authentication/auth-snap-requests.js +0 -10
- package/dist/controllers/authentication/auth-snap-requests.js.map +0 -1
- package/dist/controllers/authentication/index.js +0 -19
- package/dist/controllers/authentication/index.js.map +0 -1
- package/dist/controllers/authentication/services.js +0 -21
- package/dist/controllers/authentication/services.js.map +0 -1
- package/dist/controllers/index.js +0 -25
- package/dist/controllers/index.js.map +0 -1
- package/dist/controllers/user-storage/UserStorageController.js +0 -20
- package/dist/controllers/user-storage/UserStorageController.js.map +0 -1
- package/dist/controllers/user-storage/accounts/constants.js +0 -12
- package/dist/controllers/user-storage/accounts/constants.js.map +0 -1
- package/dist/controllers/user-storage/accounts/user-storage.js +0 -11
- package/dist/controllers/user-storage/accounts/user-storage.js.map +0 -1
- package/dist/controllers/user-storage/encryption/cache.js +0 -13
- package/dist/controllers/user-storage/encryption/cache.js.map +0 -1
- package/dist/controllers/user-storage/encryption/encryption.js +0 -12
- package/dist/controllers/user-storage/encryption/encryption.js.map +0 -1
- package/dist/controllers/user-storage/encryption/index.js +0 -16
- package/dist/controllers/user-storage/encryption/index.js.map +0 -1
- package/dist/controllers/user-storage/encryption/utils.js +0 -12
- package/dist/controllers/user-storage/encryption/utils.js.map +0 -1
- package/dist/controllers/user-storage/index.js +0 -31
- package/dist/controllers/user-storage/index.js.map +0 -1
- package/dist/controllers/user-storage/schema.js +0 -18
- package/dist/controllers/user-storage/schema.js.map +0 -1
- package/dist/controllers/user-storage/services.js +0 -22
- package/dist/controllers/user-storage/services.js.map +0 -1
- package/dist/index.js +0 -40
- package/dist/index.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +0 -13
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js +0 -15
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/services.js +0 -27
- package/dist/sdk/authentication-jwt-bearer/services.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/types.js +0 -8
- package/dist/sdk/authentication-jwt-bearer/types.js.map +0 -1
- package/dist/sdk/authentication.js +0 -26
- package/dist/sdk/authentication.js.map +0 -1
- package/dist/sdk/encryption.js +0 -14
- package/dist/sdk/encryption.js.map +0 -1
- package/dist/sdk/env.js +0 -14
- package/dist/sdk/env.js.map +0 -1
- package/dist/sdk/errors.js +0 -20
- package/dist/sdk/errors.js.map +0 -1
- package/dist/sdk/index.js +0 -79
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/user-storage.js +0 -18
- package/dist/sdk/user-storage.js.map +0 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.js +0 -10
- package/dist/sdk/utils/eip-6963-metamask-provider.js.map +0 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.js +0 -18
- package/dist/sdk/utils/messaging-signing-snap-requests.js.map +0 -1
- package/dist/sdk/utils/validate-login-response.js +0 -8
- package/dist/sdk/utils/validate-login-response.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/controllers/authentication/AuthenticationController.d.ts.map +0 -1
- package/dist/types/controllers/authentication/__fixtures__/index.d.ts +0 -2
- package/dist/types/controllers/authentication/__fixtures__/index.d.ts.map +0 -1
- package/dist/types/controllers/authentication/__fixtures__/mockResponses.d.ts.map +0 -1
- package/dist/types/controllers/authentication/__fixtures__/mockServices.d.ts.map +0 -1
- package/dist/types/controllers/authentication/auth-snap-requests.d.ts.map +0 -1
- package/dist/types/controllers/authentication/index.d.ts +0 -7
- package/dist/types/controllers/authentication/index.d.ts.map +0 -1
- package/dist/types/controllers/authentication/services.d.ts.map +0 -1
- package/dist/types/controllers/index.d.ts +0 -3
- package/dist/types/controllers/index.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/__fixtures__/index.d.ts +0 -3
- package/dist/types/controllers/user-storage/__fixtures__/index.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/__fixtures__/mockAccounts.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/__fixtures__/mockResponses.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/__fixtures__/mockServices.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/__fixtures__/mockStorage.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/accounts/constants.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/accounts/user-storage.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/encryption/cache.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/encryption/encryption.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/encryption/index.d.ts +0 -5
- package/dist/types/controllers/user-storage/encryption/index.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/encryption/utils.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/index.d.ts +0 -8
- package/dist/types/controllers/user-storage/index.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/schema.d.ts.map +0 -1
- package/dist/types/controllers/user-storage/services.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/sdk/__fixtures__/mock-auth.d.ts.map +0 -1
- package/dist/types/sdk/__fixtures__/mock-userstorage.d.ts.map +0 -1
- package/dist/types/sdk/__fixtures__/test-utils.d.ts.map +0 -1
- package/dist/types/sdk/authentication-jwt-bearer/flow-siwe.d.ts.map +0 -1
- package/dist/types/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +0 -1
- package/dist/types/sdk/authentication-jwt-bearer/services.d.ts.map +0 -1
- package/dist/types/sdk/authentication-jwt-bearer/types.d.ts.map +0 -1
- package/dist/types/sdk/authentication.d.ts.map +0 -1
- package/dist/types/sdk/encryption.d.ts +0 -4
- package/dist/types/sdk/encryption.d.ts.map +0 -1
- package/dist/types/sdk/env.d.ts.map +0 -1
- package/dist/types/sdk/errors.d.ts.map +0 -1
- package/dist/types/sdk/index.d.ts +0 -7
- package/dist/types/sdk/index.d.ts.map +0 -1
- package/dist/types/sdk/user-storage.d.ts.map +0 -1
- package/dist/types/sdk/utils/eip-6963-metamask-provider.d.ts.map +0 -1
- package/dist/types/sdk/utils/messaging-signing-snap-requests.d.ts.map +0 -1
- package/dist/types/sdk/utils/validate-login-response.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/cache.ts"],"names":[],"mappings":";;;AAAA,uCAA+D;AAQ/D,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAQ3B,IAAI,cAAc,GAAyB,EAAE,CAAC;AAC9C,MAAM,gBAAgB,GAAG,CAAC,cAAsB,EAAE,EAAE;IAClD,cAAc,CAAC,cAAc,MAA7B,cAAc,CAAC,cAAc,IAAM,IAAI,GAAG,EAAE,EAAC;IAC7C,OAAO,cAAc,CAAC,cAAc,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,cAAsB,EACtB,IAAgB;IAEhB,MAAM,KAAK,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAA,yBAAiB,EAAC,IAAI,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,IAAI;QACJ,UAAU;QACV,GAAG,EAAE,SAAS;KACf,CAAC;AACJ,CAAC;AAhBD,gDAgBC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAC7B,cAAsB;IAEtB,MAAM,KAAK,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAE/C,kDAAkD;IAClD,MAAM,WAAW,GAAqC,KAAK;SACxD,OAAO,EAAE;SACT,IAAI,EAAE,CAAC,KAAK,CAAC;IAEhB,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,IAAA,yBAAiB,EAAC,UAAU,CAAC,CAAC;IAChD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,UAAU;QACV,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;KACpB,CAAC;AACJ,CAAC;AArBD,0CAqBC;AAED;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,cAAsB,EACtB,IAAgB,EAChB,GAAe;IAEf,sBAAsB;IACtB,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,mBAAmB,EAAE;QAC5D,cAAc,GAAG,EAAE,CAAC;KACrB;IAED,MAAM,KAAK,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAA,yBAAiB,EAAC,IAAI,CAAC,CAAC;IAE3C,kBAAkB;IAClB,IAAI,KAAK,CAAC,IAAI,GAAG,eAAe,EAAE;QAChC,KAAK,CAAC,KAAK,EAAE,CAAC;KACf;IAED,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC;AAnBD,oCAmBC","sourcesContent":["import { base64ToByteArray, byteArrayToBase64 } from './utils';\n\ntype CachedEntry = {\n salt: Uint8Array;\n base64Salt: string;\n key: Uint8Array;\n};\n\nconst MAX_PASSWORD_CACHES = 3;\nconst MAX_SALT_CACHES = 10;\n\n/**\n * In-Memory Caching derived keys based from a given salt and password.\n */\ntype PasswordMemCachedKDF = {\n [hashedPassword: string]: Map<string, Uint8Array>;\n};\nlet inMemCachedKDF: PasswordMemCachedKDF = {};\nconst getPasswordCache = (hashedPassword: string) => {\n inMemCachedKDF[hashedPassword] ??= new Map();\n return inMemCachedKDF[hashedPassword];\n};\n\n/**\n * Returns a given cached derived key from a hashed password and salt\n *\n * @param hashedPassword - hashed password for cache lookup\n * @param salt - provide salt to receive cached key\n * @returns cached key\n */\nexport function getCachedKeyBySalt(\n hashedPassword: string,\n salt: Uint8Array,\n): CachedEntry | undefined {\n const cache = getPasswordCache(hashedPassword);\n const base64Salt = byteArrayToBase64(salt);\n const cachedKey = cache.get(base64Salt);\n if (!cachedKey) {\n return undefined;\n }\n\n return {\n salt,\n base64Salt,\n key: cachedKey,\n };\n}\n\n/**\n * Gets any cached key for a given hashed password\n *\n * @param hashedPassword - hashed password for cache lookup\n * @returns any (the first) cached key\n */\nexport function getAnyCachedKey(\n hashedPassword: string,\n): CachedEntry | undefined {\n const cache = getPasswordCache(hashedPassword);\n\n // Takes 1 item from an Iterator via Map.entries()\n const cachedEntry: [string, Uint8Array] | undefined = cache\n .entries()\n .next().value;\n\n if (!cachedEntry) {\n return undefined;\n }\n\n const base64Salt = cachedEntry[0];\n const bytesSalt = base64ToByteArray(base64Salt);\n return {\n salt: bytesSalt,\n base64Salt,\n key: cachedEntry[1],\n };\n}\n\n/**\n * Sets a key to the in memory cache.\n * We have set an arbitrary size of 10 cached keys per hashed password.\n *\n * @param hashedPassword - hashed password for cache lookup\n * @param salt - salt to set new derived key\n * @param key - derived key we are setting\n */\nexport function setCachedKey(\n hashedPassword: string,\n salt: Uint8Array,\n key: Uint8Array,\n): void {\n // Max password caches\n if (Object.keys(inMemCachedKDF).length > MAX_PASSWORD_CACHES) {\n inMemCachedKDF = {};\n }\n\n const cache = getPasswordCache(hashedPassword);\n const base64Salt = byteArrayToBase64(salt);\n\n // Max salt caches\n if (cache.size > MAX_SALT_CACHES) {\n cache.clear();\n }\n\n cache.set(base64Salt, key);\n}\n"]}
|
|
@@ -28,4 +28,4 @@ export declare function getAnyCachedKey(hashedPassword: string): CachedEntry | u
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function setCachedKey(hashedPassword: string, salt: Uint8Array, key: Uint8Array): void;
|
|
30
30
|
export {};
|
|
31
|
-
//# sourceMappingURL=cache.d.
|
|
31
|
+
//# sourceMappingURL=cache.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/cache.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,UAAU,CAAC;CACjB,CAAC;AAiBF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,UAAU,GACf,WAAW,GAAG,SAAS,CAazB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,GACrB,WAAW,GAAG,SAAS,CAmBzB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,GACd,IAAI,CAeN"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type CachedEntry = {
|
|
2
|
+
salt: Uint8Array;
|
|
3
|
+
base64Salt: string;
|
|
4
|
+
key: Uint8Array;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Returns a given cached derived key from a hashed password and salt
|
|
8
|
+
*
|
|
9
|
+
* @param hashedPassword - hashed password for cache lookup
|
|
10
|
+
* @param salt - provide salt to receive cached key
|
|
11
|
+
* @returns cached key
|
|
12
|
+
*/
|
|
13
|
+
export declare function getCachedKeyBySalt(hashedPassword: string, salt: Uint8Array): CachedEntry | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Gets any cached key for a given hashed password
|
|
16
|
+
*
|
|
17
|
+
* @param hashedPassword - hashed password for cache lookup
|
|
18
|
+
* @returns any (the first) cached key
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAnyCachedKey(hashedPassword: string): CachedEntry | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Sets a key to the in memory cache.
|
|
23
|
+
* We have set an arbitrary size of 10 cached keys per hashed password.
|
|
24
|
+
*
|
|
25
|
+
* @param hashedPassword - hashed password for cache lookup
|
|
26
|
+
* @param salt - salt to set new derived key
|
|
27
|
+
* @param key - derived key we are setting
|
|
28
|
+
*/
|
|
29
|
+
export declare function setCachedKey(hashedPassword: string, salt: Uint8Array, key: Uint8Array): void;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=cache.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/cache.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,UAAU,CAAC;CACjB,CAAC;AAiBF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,UAAU,GACf,WAAW,GAAG,SAAS,CAazB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,GACrB,WAAW,GAAG,SAAS,CAmBzB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,GACd,IAAI,CAeN"}
|
|
@@ -1,13 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
getAnyCachedKey,
|
|
10
|
-
getCachedKeyBySalt,
|
|
11
|
-
setCachedKey
|
|
1
|
+
import { base64ToByteArray, byteArrayToBase64 } from "./utils.mjs";
|
|
2
|
+
const MAX_PASSWORD_CACHES = 3;
|
|
3
|
+
const MAX_SALT_CACHES = 10;
|
|
4
|
+
let inMemCachedKDF = {};
|
|
5
|
+
const getPasswordCache = (hashedPassword) => {
|
|
6
|
+
inMemCachedKDF[hashedPassword] ?? (inMemCachedKDF[hashedPassword] = new Map());
|
|
7
|
+
return inMemCachedKDF[hashedPassword];
|
|
12
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Returns a given cached derived key from a hashed password and salt
|
|
11
|
+
*
|
|
12
|
+
* @param hashedPassword - hashed password for cache lookup
|
|
13
|
+
* @param salt - provide salt to receive cached key
|
|
14
|
+
* @returns cached key
|
|
15
|
+
*/
|
|
16
|
+
export function getCachedKeyBySalt(hashedPassword, salt) {
|
|
17
|
+
const cache = getPasswordCache(hashedPassword);
|
|
18
|
+
const base64Salt = byteArrayToBase64(salt);
|
|
19
|
+
const cachedKey = cache.get(base64Salt);
|
|
20
|
+
if (!cachedKey) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
salt,
|
|
25
|
+
base64Salt,
|
|
26
|
+
key: cachedKey,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets any cached key for a given hashed password
|
|
31
|
+
*
|
|
32
|
+
* @param hashedPassword - hashed password for cache lookup
|
|
33
|
+
* @returns any (the first) cached key
|
|
34
|
+
*/
|
|
35
|
+
export function getAnyCachedKey(hashedPassword) {
|
|
36
|
+
const cache = getPasswordCache(hashedPassword);
|
|
37
|
+
// Takes 1 item from an Iterator via Map.entries()
|
|
38
|
+
const cachedEntry = cache
|
|
39
|
+
.entries()
|
|
40
|
+
.next().value;
|
|
41
|
+
if (!cachedEntry) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const base64Salt = cachedEntry[0];
|
|
45
|
+
const bytesSalt = base64ToByteArray(base64Salt);
|
|
46
|
+
return {
|
|
47
|
+
salt: bytesSalt,
|
|
48
|
+
base64Salt,
|
|
49
|
+
key: cachedEntry[1],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sets a key to the in memory cache.
|
|
54
|
+
* We have set an arbitrary size of 10 cached keys per hashed password.
|
|
55
|
+
*
|
|
56
|
+
* @param hashedPassword - hashed password for cache lookup
|
|
57
|
+
* @param salt - salt to set new derived key
|
|
58
|
+
* @param key - derived key we are setting
|
|
59
|
+
*/
|
|
60
|
+
export function setCachedKey(hashedPassword, salt, key) {
|
|
61
|
+
// Max password caches
|
|
62
|
+
if (Object.keys(inMemCachedKDF).length > MAX_PASSWORD_CACHES) {
|
|
63
|
+
inMemCachedKDF = {};
|
|
64
|
+
}
|
|
65
|
+
const cache = getPasswordCache(hashedPassword);
|
|
66
|
+
const base64Salt = byteArrayToBase64(salt);
|
|
67
|
+
// Max salt caches
|
|
68
|
+
if (cache.size > MAX_SALT_CACHES) {
|
|
69
|
+
cache.clear();
|
|
70
|
+
}
|
|
71
|
+
cache.set(base64Salt, key);
|
|
72
|
+
}
|
|
13
73
|
//# sourceMappingURL=cache.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"cache.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAgB;AAQ/D,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAQ3B,IAAI,cAAc,GAAyB,EAAE,CAAC;AAC9C,MAAM,gBAA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E;QAC5D,cAAc,GAAG,EAAE,CAAC;KACrB;IAED,MAAM,KAAK,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAE3C,kBAAkB;IAClB,IAAI,KAAK,CAAC,IAAI,GAAG,eAAe,EAAE;QAChC,KAAK,CAAC,KAAK,EAAE,CAAC;KACf;IAED,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { base64ToByteArray, byteArrayToBase64 } from './utils';\n\ntype CachedEntry = {\n salt: Uint8Array;\n base64Salt: string;\n key: Uint8Array;\n};\n\nconst MAX_PASSWORD_CACHES = 3;\nconst MAX_SALT_CACHES = 10;\n\n/**\n * In-Memory Caching derived keys based from a given salt and password.\n */\ntype PasswordMemCachedKDF = {\n [hashedPassword: string]: Map<string, Uint8Array>;\n};\nlet inMemCachedKDF: PasswordMemCachedKDF = {};\nconst getPasswordCache = (hashedPassword: string) => {\n inMemCachedKDF[hashedPassword] ??= new Map();\n return inMemCachedKDF[hashedPassword];\n};\n\n/**\n * Returns a given cached derived key from a hashed password and salt\n *\n * @param hashedPassword - hashed password for cache lookup\n * @param salt - provide salt to receive cached key\n * @returns cached key\n */\nexport function getCachedKeyBySalt(\n hashedPassword: string,\n salt: Uint8Array,\n): CachedEntry | undefined {\n const cache = getPasswordCache(hashedPassword);\n const base64Salt = byteArrayToBase64(salt);\n const cachedKey = cache.get(base64Salt);\n if (!cachedKey) {\n return undefined;\n }\n\n return {\n salt,\n base64Salt,\n key: cachedKey,\n };\n}\n\n/**\n * Gets any cached key for a given hashed password\n *\n * @param hashedPassword - hashed password for cache lookup\n * @returns any (the first) cached key\n */\nexport function getAnyCachedKey(\n hashedPassword: string,\n): CachedEntry | undefined {\n const cache = getPasswordCache(hashedPassword);\n\n // Takes 1 item from an Iterator via Map.entries()\n const cachedEntry: [string, Uint8Array] | undefined = cache\n .entries()\n .next().value;\n\n if (!cachedEntry) {\n return undefined;\n }\n\n const base64Salt = cachedEntry[0];\n const bytesSalt = base64ToByteArray(base64Salt);\n return {\n salt: bytesSalt,\n base64Salt,\n key: cachedEntry[1],\n };\n}\n\n/**\n * Sets a key to the in memory cache.\n * We have set an arbitrary size of 10 cached keys per hashed password.\n *\n * @param hashedPassword - hashed password for cache lookup\n * @param salt - salt to set new derived key\n * @param key - derived key we are setting\n */\nexport function setCachedKey(\n hashedPassword: string,\n salt: Uint8Array,\n key: Uint8Array,\n): void {\n // Max password caches\n if (Object.keys(inMemCachedKDF).length > MAX_PASSWORD_CACHES) {\n inMemCachedKDF = {};\n }\n\n const cache = getPasswordCache(hashedPassword);\n const base64Salt = byteArrayToBase64(salt);\n\n // Max salt caches\n if (cache.size > MAX_SALT_CACHES) {\n cache.clear();\n }\n\n cache.set(base64Salt, key);\n}\n"]}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _EncryptorDecryptor_instances, _EncryptorDecryptor_encryptStringV1, _EncryptorDecryptor_decryptStringV1, _EncryptorDecryptor_encrypt, _EncryptorDecryptor_decrypt, _EncryptorDecryptor_getOrGenerateScryptKey;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createSHA256Hash = void 0;
|
|
10
|
+
const aes_1 = require("@noble/ciphers/aes");
|
|
11
|
+
const webcrypto_1 = require("@noble/ciphers/webcrypto");
|
|
12
|
+
const scrypt_1 = require("@noble/hashes/scrypt");
|
|
13
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
14
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
15
|
+
const cache_1 = require("./cache.cjs");
|
|
16
|
+
const utils_2 = require("./utils.cjs");
|
|
17
|
+
// Nonce/Key Sizes
|
|
18
|
+
const ALGORITHM_NONCE_SIZE = 12; // 12 bytes
|
|
19
|
+
const ALGORITHM_KEY_SIZE = 16; // 16 bytes
|
|
20
|
+
// Scrypt settings
|
|
21
|
+
// see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt
|
|
22
|
+
const SCRYPT_SALT_SIZE = 16; // 16 bytes
|
|
23
|
+
const SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
25
|
+
const SCRYPT_r = 8; // Block size parameter
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
27
|
+
const SCRYPT_p = 1; // Parallelization parameter
|
|
28
|
+
class EncryptorDecryptor {
|
|
29
|
+
constructor() {
|
|
30
|
+
_EncryptorDecryptor_instances.add(this);
|
|
31
|
+
}
|
|
32
|
+
async encryptString(plaintext, password, nativeScryptCrypto) {
|
|
33
|
+
try {
|
|
34
|
+
return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encryptStringV1).call(this, plaintext, password, nativeScryptCrypto);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
38
|
+
throw new Error(`Unable to encrypt string - ${errorMessage}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async decryptString(encryptedDataStr, password, nativeScryptCrypto) {
|
|
42
|
+
try {
|
|
43
|
+
const encryptedData = JSON.parse(encryptedDataStr);
|
|
44
|
+
if (encryptedData.v === '1') {
|
|
45
|
+
if (encryptedData.t === 'scrypt') {
|
|
46
|
+
return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decryptStringV1).call(this, encryptedData, password, nativeScryptCrypto);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Unsupported encrypted data payload - ${encryptedDataStr}`);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
53
|
+
throw new Error(`Unable to decrypt string - ${errorMessage}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
_EncryptorDecryptor_instances = new WeakSet(), _EncryptorDecryptor_encryptStringV1 = async function _EncryptorDecryptor_encryptStringV1(plaintext, password, nativeScryptCrypto) {
|
|
58
|
+
const { key, salt } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
|
|
59
|
+
N: SCRYPT_N,
|
|
60
|
+
r: SCRYPT_r,
|
|
61
|
+
p: SCRYPT_p,
|
|
62
|
+
dkLen: ALGORITHM_KEY_SIZE,
|
|
63
|
+
}, (0, webcrypto_1.randomBytes)(SCRYPT_SALT_SIZE), nativeScryptCrypto);
|
|
64
|
+
// Encrypt and prepend salt.
|
|
65
|
+
const plaintextRaw = (0, utils_1.utf8ToBytes)(plaintext);
|
|
66
|
+
const ciphertextAndNonceAndSalt = (0, utils_1.concatBytes)(salt, __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encrypt).call(this, plaintextRaw, key));
|
|
67
|
+
// Convert to Base64
|
|
68
|
+
const encryptedData = (0, utils_2.byteArrayToBase64)(ciphertextAndNonceAndSalt);
|
|
69
|
+
const encryptedPayload = {
|
|
70
|
+
v: '1',
|
|
71
|
+
t: 'scrypt',
|
|
72
|
+
d: encryptedData,
|
|
73
|
+
o: {
|
|
74
|
+
N: SCRYPT_N,
|
|
75
|
+
r: SCRYPT_r,
|
|
76
|
+
p: SCRYPT_p,
|
|
77
|
+
dkLen: ALGORITHM_KEY_SIZE,
|
|
78
|
+
},
|
|
79
|
+
saltLen: SCRYPT_SALT_SIZE,
|
|
80
|
+
};
|
|
81
|
+
return JSON.stringify(encryptedPayload);
|
|
82
|
+
}, _EncryptorDecryptor_decryptStringV1 = async function _EncryptorDecryptor_decryptStringV1(data, password, nativeScryptCrypto) {
|
|
83
|
+
const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
|
|
84
|
+
// Decode the base64.
|
|
85
|
+
const ciphertextAndNonceAndSalt = (0, utils_2.base64ToByteArray)(base64CiphertextAndNonceAndSalt);
|
|
86
|
+
// Create buffers of salt and ciphertextAndNonce.
|
|
87
|
+
const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
|
|
88
|
+
const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(saltLen, ciphertextAndNonceAndSalt.length);
|
|
89
|
+
// Derive the key.
|
|
90
|
+
const { key } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
|
|
91
|
+
N: o.N,
|
|
92
|
+
r: o.r,
|
|
93
|
+
p: o.p,
|
|
94
|
+
dkLen: o.dkLen,
|
|
95
|
+
}, salt, nativeScryptCrypto);
|
|
96
|
+
// Decrypt and return result.
|
|
97
|
+
return (0, utils_2.bytesToUtf8)(__classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decrypt).call(this, ciphertextAndNonce, key));
|
|
98
|
+
}, _EncryptorDecryptor_encrypt = function _EncryptorDecryptor_encrypt(plaintext, key) {
|
|
99
|
+
const nonce = (0, webcrypto_1.randomBytes)(ALGORITHM_NONCE_SIZE);
|
|
100
|
+
// Encrypt and prepend nonce.
|
|
101
|
+
const ciphertext = (0, aes_1.gcm)(key, nonce).encrypt(plaintext);
|
|
102
|
+
return (0, utils_1.concatBytes)(nonce, ciphertext);
|
|
103
|
+
}, _EncryptorDecryptor_decrypt = function _EncryptorDecryptor_decrypt(ciphertextAndNonce, key) {
|
|
104
|
+
// Create buffers of nonce and ciphertext.
|
|
105
|
+
const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);
|
|
106
|
+
const ciphertext = ciphertextAndNonce.slice(ALGORITHM_NONCE_SIZE, ciphertextAndNonce.length);
|
|
107
|
+
// Decrypt and return result.
|
|
108
|
+
return (0, aes_1.gcm)(key, nonce).decrypt(ciphertext);
|
|
109
|
+
}, _EncryptorDecryptor_getOrGenerateScryptKey = async function _EncryptorDecryptor_getOrGenerateScryptKey(password, o, salt, nativeScryptCrypto) {
|
|
110
|
+
const hashedPassword = createSHA256Hash(password);
|
|
111
|
+
const cachedKey = salt
|
|
112
|
+
? (0, cache_1.getCachedKeyBySalt)(hashedPassword, salt)
|
|
113
|
+
: (0, cache_1.getAnyCachedKey)(hashedPassword);
|
|
114
|
+
if (cachedKey) {
|
|
115
|
+
return {
|
|
116
|
+
key: cachedKey.key,
|
|
117
|
+
salt: cachedKey.salt,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const newSalt = salt ?? (0, webcrypto_1.randomBytes)(SCRYPT_SALT_SIZE);
|
|
121
|
+
let newKey;
|
|
122
|
+
if (nativeScryptCrypto) {
|
|
123
|
+
newKey = await nativeScryptCrypto(password, newSalt, o.N, o.r, o.p, o.dkLen);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
newKey = await (0, scrypt_1.scryptAsync)(password, newSalt, {
|
|
127
|
+
N: o.N,
|
|
128
|
+
r: o.r,
|
|
129
|
+
p: o.p,
|
|
130
|
+
dkLen: o.dkLen,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
(0, cache_1.setCachedKey)(hashedPassword, newSalt, newKey);
|
|
134
|
+
return {
|
|
135
|
+
key: newKey,
|
|
136
|
+
salt: newSalt,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
const encryption = new EncryptorDecryptor();
|
|
140
|
+
exports.default = encryption;
|
|
141
|
+
/**
|
|
142
|
+
* Receive a SHA256 hash from a given string
|
|
143
|
+
* @param data - input
|
|
144
|
+
* @returns sha256 hash
|
|
145
|
+
*/
|
|
146
|
+
function createSHA256Hash(data) {
|
|
147
|
+
const hashedData = (0, sha256_1.sha256)(data);
|
|
148
|
+
return (0, utils_1.bytesToHex)(hashedData);
|
|
149
|
+
}
|
|
150
|
+
exports.createSHA256Hash = createSHA256Hash;
|
|
151
|
+
//# sourceMappingURL=encryption.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4CAAyC;AACzC,wDAAuD;AACvD,iDAAmD;AACnD,iDAA8C;AAC9C,+CAA2E;AAG3E,uCAA4E;AAC5E,uCAA4E;AAyB5E,kBAAkB;AAClB,MAAM,oBAAoB,GAAG,EAAE,CAAC,CAAC,WAAW;AAC5C,MAAM,kBAAkB,GAAG,EAAE,CAAC,CAAC,WAAW;AAE1C,kBAAkB;AAClB,+FAA+F;AAC/F,MAAM,gBAAgB,GAAG,EAAE,CAAC,CAAC,WAAW;AACxC,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,wDAAwD;AAClF,gEAAgE;AAChE,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,uBAAuB;AAC3C,gEAAgE;AAChE,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,4BAA4B;AAEhD,MAAM,kBAAkB;IAAxB;;IA6LA,CAAC;IA5LC,KAAK,CAAC,aAAa,CACjB,SAAiB,EACjB,QAAgB,EAChB,kBAAiC;QAEjC,IAAI;YACF,OAAO,MAAM,uBAAA,IAAI,0EAAiB,MAArB,IAAI,EACf,SAAS,EACT,QAAQ,EACR,kBAAkB,CACnB,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,YAAY,GAAG,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;KACH;IAED,MAAM,OAAO,GAAG,IAAI,IAAI,IAAA,uBAAW,EAAC,gBAAgB,CAAC,CAAC;IAEtD,IAAI,MAAkB,CAAC;IAEvB,IAAI,kBAAkB,EAAE;QACtB,MAAM,GAAG,MAAM,kBAAkB,CAC/B,QAAQ,EACR,OAAO,EACP,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,KAAK,CACR,CAAC;KACH;SAAM;QACL,MAAM,GAAG,MAAM,IAAA,oBAAW,EAAC,QAAQ,EAAE,OAAO,EAAE;YAC5C,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,KAAK,EAAE,CAAC,CAAC,KAAK;SACf,CAAC,CAAC;KACJ;IACD,IAAA,oBAAY,EAAC,cAAc,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAE9C,OAAO;QACL,GAAG,EAAE,MAAM;QACX,IAAI,EAAE,OAAO;KACd,CAAC;AACJ,CAAC;AAGH,MAAM,UAAU,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAC5C,kBAAe,UAAU,CAAC;AAE1B;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,MAAM,UAAU,GAAG,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC;IAChC,OAAO,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;AAChC,CAAC;AAHD,4CAGC","sourcesContent":["import { gcm } from '@noble/ciphers/aes';\nimport { randomBytes } from '@noble/ciphers/webcrypto';\nimport { scryptAsync } from '@noble/hashes/scrypt';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { utf8ToBytes, concatBytes, bytesToHex } from '@noble/hashes/utils';\n\nimport type { NativeScrypt } from '../UserStorageController';\nimport { getAnyCachedKey, getCachedKeyBySalt, setCachedKey } from './cache';\nimport { base64ToByteArray, byteArrayToBase64, bytesToUtf8 } from './utils';\n\nexport type EncryptedPayload = {\n // version\n v: '1';\n\n // key derivation function algorithm - scrypt\n t: 'scrypt';\n\n // data\n d: string;\n\n // encryption options - scrypt\n o: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n N: number;\n r: number;\n p: number;\n dkLen: number;\n };\n\n // Salt options\n saltLen: number;\n};\n\n// Nonce/Key Sizes\nconst ALGORITHM_NONCE_SIZE = 12; // 12 bytes\nconst ALGORITHM_KEY_SIZE = 16; // 16 bytes\n\n// Scrypt settings\n// see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt\nconst SCRYPT_SALT_SIZE = 16; // 16 bytes\nconst SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_r = 8; // Block size parameter\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_p = 1; // Parallelization parameter\n\nclass EncryptorDecryptor {\n async encryptString(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n return await this.#encryptStringV1(\n plaintext,\n password,\n nativeScryptCrypto,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to encrypt string - ${errorMessage}`);\n }\n }\n\n async decryptString(\n encryptedDataStr: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n const encryptedData: EncryptedPayload = JSON.parse(encryptedDataStr);\n if (encryptedData.v === '1') {\n if (encryptedData.t === 'scrypt') {\n return await this.#decryptStringV1(\n encryptedData,\n password,\n nativeScryptCrypto,\n );\n }\n }\n throw new Error(\n `Unsupported encrypted data payload - ${encryptedDataStr}`,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to decrypt string - ${errorMessage}`);\n }\n }\n\n async #encryptStringV1(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { key, salt } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n randomBytes(SCRYPT_SALT_SIZE),\n nativeScryptCrypto,\n );\n\n // Encrypt and prepend salt.\n const plaintextRaw = utf8ToBytes(plaintext);\n const ciphertextAndNonceAndSalt = concatBytes(\n salt,\n this.#encrypt(plaintextRaw, key),\n );\n\n // Convert to Base64\n const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);\n\n const encryptedPayload: EncryptedPayload = {\n v: '1',\n t: 'scrypt',\n d: encryptedData,\n o: {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n saltLen: SCRYPT_SALT_SIZE,\n };\n\n return JSON.stringify(encryptedPayload);\n }\n\n async #decryptStringV1(\n data: EncryptedPayload,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;\n\n // Decode the base64.\n const ciphertextAndNonceAndSalt = base64ToByteArray(\n base64CiphertextAndNonceAndSalt,\n );\n\n // Create buffers of salt and ciphertextAndNonce.\n const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);\n const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(\n saltLen,\n ciphertextAndNonceAndSalt.length,\n );\n\n // Derive the key.\n const { key } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n },\n salt,\n nativeScryptCrypto,\n );\n\n // Decrypt and return result.\n return bytesToUtf8(this.#decrypt(ciphertextAndNonce, key));\n }\n\n #encrypt(plaintext: Uint8Array, key: Uint8Array): Uint8Array {\n const nonce = randomBytes(ALGORITHM_NONCE_SIZE);\n\n // Encrypt and prepend nonce.\n const ciphertext = gcm(key, nonce).encrypt(plaintext);\n\n return concatBytes(nonce, ciphertext);\n }\n\n #decrypt(ciphertextAndNonce: Uint8Array, key: Uint8Array): Uint8Array {\n // Create buffers of nonce and ciphertext.\n const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);\n const ciphertext = ciphertextAndNonce.slice(\n ALGORITHM_NONCE_SIZE,\n ciphertextAndNonce.length,\n );\n\n // Decrypt and return result.\n return gcm(key, nonce).decrypt(ciphertext);\n }\n\n async #getOrGenerateScryptKey(\n password: string,\n o: EncryptedPayload['o'],\n salt?: Uint8Array,\n nativeScryptCrypto?: NativeScrypt,\n ) {\n const hashedPassword = createSHA256Hash(password);\n const cachedKey = salt\n ? getCachedKeyBySalt(hashedPassword, salt)\n : getAnyCachedKey(hashedPassword);\n\n if (cachedKey) {\n return {\n key: cachedKey.key,\n salt: cachedKey.salt,\n };\n }\n\n const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);\n\n let newKey: Uint8Array;\n\n if (nativeScryptCrypto) {\n newKey = await nativeScryptCrypto(\n password,\n newSalt,\n o.N,\n o.r,\n o.p,\n o.dkLen,\n );\n } else {\n newKey = await scryptAsync(password, newSalt, {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n });\n }\n setCachedKey(hashedPassword, newSalt, newKey);\n\n return {\n key: newKey,\n salt: newSalt,\n };\n }\n}\n\nconst encryption = new EncryptorDecryptor();\nexport default encryption;\n\n/**\n * Receive a SHA256 hash from a given string\n * @param data - input\n * @returns sha256 hash\n */\nexport function createSHA256Hash(data: string): string {\n const hashedData = sha256(data);\n return bytesToHex(hashedData);\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NativeScrypt } from
|
|
1
|
+
import type { NativeScrypt } from "../UserStorageController.cjs";
|
|
2
2
|
export type EncryptedPayload = {
|
|
3
3
|
v: '1';
|
|
4
4
|
t: 'scrypt';
|
|
@@ -24,4 +24,4 @@ export default encryption;
|
|
|
24
24
|
* @returns sha256 hash
|
|
25
25
|
*/
|
|
26
26
|
export declare function createSHA256Hash(data: string): string;
|
|
27
|
-
//# sourceMappingURL=encryption.d.
|
|
27
|
+
//# sourceMappingURL=encryption.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAiC;AAI7D,MAAM,MAAM,gBAAgB,GAAG;IAE7B,CAAC,EAAE,GAAG,CAAC;IAGP,CAAC,EAAE,QAAQ,CAAC;IAGZ,CAAC,EAAE,MAAM,CAAC;IAGV,CAAC,EAAE;QAED,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAGF,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAeF,cAAM,kBAAkB;;IAChB,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,YAAY,GAChC,OAAO,CAAC,MAAM,CAAC;IAaZ,aAAa,CACjB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,YAAY,GAChC,OAAO,CAAC,MAAM,CAAC;CAuKnB;AAED,QAAA,MAAM,UAAU,oBAA2B,CAAC;AAC5C,eAAe,UAAU,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { NativeScrypt } from "../UserStorageController.mjs";
|
|
2
|
+
export type EncryptedPayload = {
|
|
3
|
+
v: '1';
|
|
4
|
+
t: 'scrypt';
|
|
5
|
+
d: string;
|
|
6
|
+
o: {
|
|
7
|
+
N: number;
|
|
8
|
+
r: number;
|
|
9
|
+
p: number;
|
|
10
|
+
dkLen: number;
|
|
11
|
+
};
|
|
12
|
+
saltLen: number;
|
|
13
|
+
};
|
|
14
|
+
declare class EncryptorDecryptor {
|
|
15
|
+
#private;
|
|
16
|
+
encryptString(plaintext: string, password: string, nativeScryptCrypto?: NativeScrypt): Promise<string>;
|
|
17
|
+
decryptString(encryptedDataStr: string, password: string, nativeScryptCrypto?: NativeScrypt): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
declare const encryption: EncryptorDecryptor;
|
|
20
|
+
export default encryption;
|
|
21
|
+
/**
|
|
22
|
+
* Receive a SHA256 hash from a given string
|
|
23
|
+
* @param data - input
|
|
24
|
+
* @returns sha256 hash
|
|
25
|
+
*/
|
|
26
|
+
export declare function createSHA256Hash(data: string): string;
|
|
27
|
+
//# sourceMappingURL=encryption.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAiC;AAI7D,MAAM,MAAM,gBAAgB,GAAG;IAE7B,CAAC,EAAE,GAAG,CAAC;IAGP,CAAC,EAAE,QAAQ,CAAC;IAGZ,CAAC,EAAE,MAAM,CAAC;IAGV,CAAC,EAAE;QAED,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IAGF,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAeF,cAAM,kBAAkB;;IAChB,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,YAAY,GAChC,OAAO,CAAC,MAAM,CAAC;IAaZ,aAAa,CACjB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,YAAY,GAChC,OAAO,CAAC,MAAM,CAAC;CAuKnB;AAED,QAAA,MAAM,UAAU,oBAA2B,CAAC;AAC5C,eAAe,UAAU,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD"}
|
|
@@ -1,12 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import "../../../chunk-H25EBXG5.mjs";
|
|
6
|
-
import "../../../chunk-76VRE4BI.mjs";
|
|
7
|
-
import "../../../chunk-U5UIDVOO.mjs";
|
|
8
|
-
export {
|
|
9
|
-
createSHA256Hash,
|
|
10
|
-
encryption_default as default
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
5
|
};
|
|
6
|
+
var _EncryptorDecryptor_instances, _EncryptorDecryptor_encryptStringV1, _EncryptorDecryptor_decryptStringV1, _EncryptorDecryptor_encrypt, _EncryptorDecryptor_decrypt, _EncryptorDecryptor_getOrGenerateScryptKey;
|
|
7
|
+
import { gcm } from "@noble/ciphers/aes";
|
|
8
|
+
import { randomBytes } from "@noble/ciphers/webcrypto";
|
|
9
|
+
import { scryptAsync } from "@noble/hashes/scrypt";
|
|
10
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
11
|
+
import { utf8ToBytes, concatBytes, bytesToHex } from "@noble/hashes/utils";
|
|
12
|
+
import { getAnyCachedKey, getCachedKeyBySalt, setCachedKey } from "./cache.mjs";
|
|
13
|
+
import { base64ToByteArray, byteArrayToBase64, bytesToUtf8 } from "./utils.mjs";
|
|
14
|
+
// Nonce/Key Sizes
|
|
15
|
+
const ALGORITHM_NONCE_SIZE = 12; // 12 bytes
|
|
16
|
+
const ALGORITHM_KEY_SIZE = 16; // 16 bytes
|
|
17
|
+
// Scrypt settings
|
|
18
|
+
// see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt
|
|
19
|
+
const SCRYPT_SALT_SIZE = 16; // 16 bytes
|
|
20
|
+
const SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22
|
+
const SCRYPT_r = 8; // Block size parameter
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
24
|
+
const SCRYPT_p = 1; // Parallelization parameter
|
|
25
|
+
class EncryptorDecryptor {
|
|
26
|
+
constructor() {
|
|
27
|
+
_EncryptorDecryptor_instances.add(this);
|
|
28
|
+
}
|
|
29
|
+
async encryptString(plaintext, password, nativeScryptCrypto) {
|
|
30
|
+
try {
|
|
31
|
+
return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encryptStringV1).call(this, plaintext, password, nativeScryptCrypto);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
35
|
+
throw new Error(`Unable to encrypt string - ${errorMessage}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async decryptString(encryptedDataStr, password, nativeScryptCrypto) {
|
|
39
|
+
try {
|
|
40
|
+
const encryptedData = JSON.parse(encryptedDataStr);
|
|
41
|
+
if (encryptedData.v === '1') {
|
|
42
|
+
if (encryptedData.t === 'scrypt') {
|
|
43
|
+
return await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decryptStringV1).call(this, encryptedData, password, nativeScryptCrypto);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`Unsupported encrypted data payload - ${encryptedDataStr}`);
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
50
|
+
throw new Error(`Unable to decrypt string - ${errorMessage}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
_EncryptorDecryptor_instances = new WeakSet(), _EncryptorDecryptor_encryptStringV1 = async function _EncryptorDecryptor_encryptStringV1(plaintext, password, nativeScryptCrypto) {
|
|
55
|
+
const { key, salt } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
|
|
56
|
+
N: SCRYPT_N,
|
|
57
|
+
r: SCRYPT_r,
|
|
58
|
+
p: SCRYPT_p,
|
|
59
|
+
dkLen: ALGORITHM_KEY_SIZE,
|
|
60
|
+
}, randomBytes(SCRYPT_SALT_SIZE), nativeScryptCrypto);
|
|
61
|
+
// Encrypt and prepend salt.
|
|
62
|
+
const plaintextRaw = utf8ToBytes(plaintext);
|
|
63
|
+
const ciphertextAndNonceAndSalt = concatBytes(salt, __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_encrypt).call(this, plaintextRaw, key));
|
|
64
|
+
// Convert to Base64
|
|
65
|
+
const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);
|
|
66
|
+
const encryptedPayload = {
|
|
67
|
+
v: '1',
|
|
68
|
+
t: 'scrypt',
|
|
69
|
+
d: encryptedData,
|
|
70
|
+
o: {
|
|
71
|
+
N: SCRYPT_N,
|
|
72
|
+
r: SCRYPT_r,
|
|
73
|
+
p: SCRYPT_p,
|
|
74
|
+
dkLen: ALGORITHM_KEY_SIZE,
|
|
75
|
+
},
|
|
76
|
+
saltLen: SCRYPT_SALT_SIZE,
|
|
77
|
+
};
|
|
78
|
+
return JSON.stringify(encryptedPayload);
|
|
79
|
+
}, _EncryptorDecryptor_decryptStringV1 = async function _EncryptorDecryptor_decryptStringV1(data, password, nativeScryptCrypto) {
|
|
80
|
+
const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
|
|
81
|
+
// Decode the base64.
|
|
82
|
+
const ciphertextAndNonceAndSalt = base64ToByteArray(base64CiphertextAndNonceAndSalt);
|
|
83
|
+
// Create buffers of salt and ciphertextAndNonce.
|
|
84
|
+
const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
|
|
85
|
+
const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(saltLen, ciphertextAndNonceAndSalt.length);
|
|
86
|
+
// Derive the key.
|
|
87
|
+
const { key } = await __classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_getOrGenerateScryptKey).call(this, password, {
|
|
88
|
+
N: o.N,
|
|
89
|
+
r: o.r,
|
|
90
|
+
p: o.p,
|
|
91
|
+
dkLen: o.dkLen,
|
|
92
|
+
}, salt, nativeScryptCrypto);
|
|
93
|
+
// Decrypt and return result.
|
|
94
|
+
return bytesToUtf8(__classPrivateFieldGet(this, _EncryptorDecryptor_instances, "m", _EncryptorDecryptor_decrypt).call(this, ciphertextAndNonce, key));
|
|
95
|
+
}, _EncryptorDecryptor_encrypt = function _EncryptorDecryptor_encrypt(plaintext, key) {
|
|
96
|
+
const nonce = randomBytes(ALGORITHM_NONCE_SIZE);
|
|
97
|
+
// Encrypt and prepend nonce.
|
|
98
|
+
const ciphertext = gcm(key, nonce).encrypt(plaintext);
|
|
99
|
+
return concatBytes(nonce, ciphertext);
|
|
100
|
+
}, _EncryptorDecryptor_decrypt = function _EncryptorDecryptor_decrypt(ciphertextAndNonce, key) {
|
|
101
|
+
// Create buffers of nonce and ciphertext.
|
|
102
|
+
const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);
|
|
103
|
+
const ciphertext = ciphertextAndNonce.slice(ALGORITHM_NONCE_SIZE, ciphertextAndNonce.length);
|
|
104
|
+
// Decrypt and return result.
|
|
105
|
+
return gcm(key, nonce).decrypt(ciphertext);
|
|
106
|
+
}, _EncryptorDecryptor_getOrGenerateScryptKey = async function _EncryptorDecryptor_getOrGenerateScryptKey(password, o, salt, nativeScryptCrypto) {
|
|
107
|
+
const hashedPassword = createSHA256Hash(password);
|
|
108
|
+
const cachedKey = salt
|
|
109
|
+
? getCachedKeyBySalt(hashedPassword, salt)
|
|
110
|
+
: getAnyCachedKey(hashedPassword);
|
|
111
|
+
if (cachedKey) {
|
|
112
|
+
return {
|
|
113
|
+
key: cachedKey.key,
|
|
114
|
+
salt: cachedKey.salt,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);
|
|
118
|
+
let newKey;
|
|
119
|
+
if (nativeScryptCrypto) {
|
|
120
|
+
newKey = await nativeScryptCrypto(password, newSalt, o.N, o.r, o.p, o.dkLen);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
newKey = await scryptAsync(password, newSalt, {
|
|
124
|
+
N: o.N,
|
|
125
|
+
r: o.r,
|
|
126
|
+
p: o.p,
|
|
127
|
+
dkLen: o.dkLen,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
setCachedKey(hashedPassword, newSalt, newKey);
|
|
131
|
+
return {
|
|
132
|
+
key: newKey,
|
|
133
|
+
salt: newSalt,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
const encryption = new EncryptorDecryptor();
|
|
137
|
+
export default encryption;
|
|
138
|
+
/**
|
|
139
|
+
* Receive a SHA256 hash from a given string
|
|
140
|
+
* @param data - input
|
|
141
|
+
* @returns sha256 hash
|
|
142
|
+
*/
|
|
143
|
+
export function createSHA256Hash(data) {
|
|
144
|
+
const hashedData = sha256(data);
|
|
145
|
+
return bytesToHex(hashedData);
|
|
146
|
+
}
|
|
12
147
|
//# sourceMappingURL=encryption.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"encryption.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,2BAA2B;AACzC,OAAO,EAAE,WAAW,EAAE,iCAAiC;AACvD,OAAO,EAAE,WAAW,EAAE,6BAA6B;AACnD,OAAO,EAAE,MAAM,EAAE,6BAA6B;AAC9C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,4BAA4B;AAG3E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,YAAY,EAAE,oBAAgB;AAC5E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,WAAW,EAAE,oBAAgB;AAyB5E,kBAAkB;AAClB,MAAM,oBAAoB,GAAG,EAAE,CAAC,CAAC,WAAW;AAC5C,MAAM,kBAAkB,GAAG,EAAE,CAAC,CAAC,WAAW;AAE1C,kBAAkB;AAClB,+FAA+F;AAC/F,MAAM,gBAAgB,GAAG,EAAE,CAAC,CAAC,WAAW;AACxC,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,wDAAwD;AAClF,gEAAgE;AAChE,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,uBAAuB;AAC3C,gEAAgE;AAChE,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,4BAA4B;AAEhD,MAAM,kBAAkB;IAAxB;;IA6LA,CAAC;IA5LC,KAAK,CAAC,aAAa,CACjB,SAAiB,EACjB,QAAgB,EAChB,kBAAiC;QAEjC,IAAI;YACF,OAAO,MAAM,uBAAA,IAAI,0EAAiB,MAArB,IAAI,EACf,SAAS,EACT,QAAQ,EACR,kBAAkB,CACnB,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CA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M,GAAG,MAAM,kBAAkB,CAC/B,QAAQ,EACR,OAAO,EACP,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,CAAC,EACH,CAAC,CAAC,KAAK,CACR,CAAC;KACH;SAAM;QACL,MAAM,GAAG,MAAM,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE;YAC5C,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,CAAC,EAAE,CAAC,CAAC,CAAC;YACN,KAAK,EAAE,CAAC,CAAC,KAAK;SACf,CAAC,CAAC;KACJ;IACD,YAAY,CAAC,cAAc,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAE9C,OAAO;QACL,GAAG,EAAE,MAAM;QACX,IAAI,EAAE,OAAO;KACd,CAAC;AACJ,CAAC;AAGH,MAAM,UAAU,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAC5C,eAAe,UAAU,CAAC;AAE1B;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { gcm } from '@noble/ciphers/aes';\nimport { randomBytes } from '@noble/ciphers/webcrypto';\nimport { scryptAsync } from '@noble/hashes/scrypt';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { utf8ToBytes, concatBytes, bytesToHex } from '@noble/hashes/utils';\n\nimport type { NativeScrypt } from '../UserStorageController';\nimport { getAnyCachedKey, getCachedKeyBySalt, setCachedKey } from './cache';\nimport { base64ToByteArray, byteArrayToBase64, bytesToUtf8 } from './utils';\n\nexport type EncryptedPayload = {\n // version\n v: '1';\n\n // key derivation function algorithm - scrypt\n t: 'scrypt';\n\n // data\n d: string;\n\n // encryption options - scrypt\n o: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n N: number;\n r: number;\n p: number;\n dkLen: number;\n };\n\n // Salt options\n saltLen: number;\n};\n\n// Nonce/Key Sizes\nconst ALGORITHM_NONCE_SIZE = 12; // 12 bytes\nconst ALGORITHM_KEY_SIZE = 16; // 16 bytes\n\n// Scrypt settings\n// see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt\nconst SCRYPT_SALT_SIZE = 16; // 16 bytes\nconst SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_r = 8; // Block size parameter\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_p = 1; // Parallelization parameter\n\nclass EncryptorDecryptor {\n async encryptString(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n return await this.#encryptStringV1(\n plaintext,\n password,\n nativeScryptCrypto,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to encrypt string - ${errorMessage}`);\n }\n }\n\n async decryptString(\n encryptedDataStr: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n try {\n const encryptedData: EncryptedPayload = JSON.parse(encryptedDataStr);\n if (encryptedData.v === '1') {\n if (encryptedData.t === 'scrypt') {\n return await this.#decryptStringV1(\n encryptedData,\n password,\n nativeScryptCrypto,\n );\n }\n }\n throw new Error(\n `Unsupported encrypted data payload - ${encryptedDataStr}`,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to decrypt string - ${errorMessage}`);\n }\n }\n\n async #encryptStringV1(\n plaintext: string,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { key, salt } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n randomBytes(SCRYPT_SALT_SIZE),\n nativeScryptCrypto,\n );\n\n // Encrypt and prepend salt.\n const plaintextRaw = utf8ToBytes(plaintext);\n const ciphertextAndNonceAndSalt = concatBytes(\n salt,\n this.#encrypt(plaintextRaw, key),\n );\n\n // Convert to Base64\n const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);\n\n const encryptedPayload: EncryptedPayload = {\n v: '1',\n t: 'scrypt',\n d: encryptedData,\n o: {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n saltLen: SCRYPT_SALT_SIZE,\n };\n\n return JSON.stringify(encryptedPayload);\n }\n\n async #decryptStringV1(\n data: EncryptedPayload,\n password: string,\n nativeScryptCrypto?: NativeScrypt,\n ): Promise<string> {\n const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;\n\n // Decode the base64.\n const ciphertextAndNonceAndSalt = base64ToByteArray(\n base64CiphertextAndNonceAndSalt,\n );\n\n // Create buffers of salt and ciphertextAndNonce.\n const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);\n const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(\n saltLen,\n ciphertextAndNonceAndSalt.length,\n );\n\n // Derive the key.\n const { key } = await this.#getOrGenerateScryptKey(\n password,\n {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n },\n salt,\n nativeScryptCrypto,\n );\n\n // Decrypt and return result.\n return bytesToUtf8(this.#decrypt(ciphertextAndNonce, key));\n }\n\n #encrypt(plaintext: Uint8Array, key: Uint8Array): Uint8Array {\n const nonce = randomBytes(ALGORITHM_NONCE_SIZE);\n\n // Encrypt and prepend nonce.\n const ciphertext = gcm(key, nonce).encrypt(plaintext);\n\n return concatBytes(nonce, ciphertext);\n }\n\n #decrypt(ciphertextAndNonce: Uint8Array, key: Uint8Array): Uint8Array {\n // Create buffers of nonce and ciphertext.\n const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);\n const ciphertext = ciphertextAndNonce.slice(\n ALGORITHM_NONCE_SIZE,\n ciphertextAndNonce.length,\n );\n\n // Decrypt and return result.\n return gcm(key, nonce).decrypt(ciphertext);\n }\n\n async #getOrGenerateScryptKey(\n password: string,\n o: EncryptedPayload['o'],\n salt?: Uint8Array,\n nativeScryptCrypto?: NativeScrypt,\n ) {\n const hashedPassword = createSHA256Hash(password);\n const cachedKey = salt\n ? getCachedKeyBySalt(hashedPassword, salt)\n : getAnyCachedKey(hashedPassword);\n\n if (cachedKey) {\n return {\n key: cachedKey.key,\n salt: cachedKey.salt,\n };\n }\n\n const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);\n\n let newKey: Uint8Array;\n\n if (nativeScryptCrypto) {\n newKey = await nativeScryptCrypto(\n password,\n newSalt,\n o.N,\n o.r,\n o.p,\n o.dkLen,\n );\n } else {\n newKey = await scryptAsync(password, newSalt, {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n });\n }\n setCachedKey(hashedPassword, newSalt, newKey);\n\n return {\n key: newKey,\n salt: newSalt,\n };\n }\n}\n\nconst encryption = new EncryptorDecryptor();\nexport default encryption;\n\n/**\n * Receive a SHA256 hash from a given string\n * @param data - input\n * @returns sha256 hash\n */\nexport function createSHA256Hash(data: string): string {\n const hashedData = sha256(data);\n return bytesToHex(hashedData);\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Encryption = void 0;
|
|
21
|
+
const encryption_1 = __importDefault(require("./encryption.cjs"));
|
|
22
|
+
exports.Encryption = encryption_1.default;
|
|
23
|
+
__exportStar(require("./encryption.cjs"), exports);
|
|
24
|
+
exports.default = encryption_1.default;
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,kEAAsC;AAE7B,qBAFF,oBAAU,CAEE;AACnB,mDAA6B;AAC7B,kBAAe,oBAAU,CAAC","sourcesContent":["import Encryption from './encryption';\n\nexport { Encryption };\nexport * from './encryption';\nexport default Encryption;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,yBAAqB;AAEtC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,iCAA6B;AAC7B,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,yBAAqB;AAEtC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,iCAA6B;AAC7B,eAAe,UAAU,CAAC"}
|