@metamask/profile-sync-controller 2.0.0 → 3.1.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 +45 -1
- package/dist/controllers/authentication/AuthenticationController.cjs +0 -1
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs +0 -1
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.cjs +55 -22
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +32 -15
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +32 -15
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +56 -23
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs +171 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts +102 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts +102 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs +166 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs.map +1 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs +7 -6
- package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs +7 -6
- package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs +20 -2
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts +8 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts +8 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs +17 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/add-network-utils.cjs +35 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.cjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.d.cts +21 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.d.mts +21 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.mjs +30 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.mjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +157 -29
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +45 -3
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +45 -3
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +154 -28
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.cjs +9 -4
- package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.mjs +10 -5
- package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.cjs +10 -28
- package/dist/controllers/user-storage/network-syncing/sync-all.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.d.cts +5 -8
- package/dist/controllers/user-storage/network-syncing/sync-all.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.d.mts +5 -8
- package/dist/controllers/user-storage/network-syncing/sync-all.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.mjs +9 -26
- package/dist/controllers/user-storage/network-syncing/sync-all.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/types.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/types.d.cts +1 -4
- package/dist/controllers/user-storage/network-syncing/types.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/types.d.mts +1 -4
- package/dist/controllers/user-storage/network-syncing/types.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/types.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/update-network-utils.cjs +126 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.cjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.d.cts +56 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.d.mts +56 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.mjs +119 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.mjs.map +1 -0
- package/dist/controllers/user-storage/services.cjs +49 -1
- package/dist/controllers/user-storage/services.cjs.map +1 -1
- package/dist/controllers/user-storage/services.d.cts +8 -0
- package/dist/controllers/user-storage/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/services.d.mts +8 -0
- package/dist/controllers/user-storage/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/services.mjs +47 -0
- package/dist/controllers/user-storage/services.mjs.map +1 -1
- package/dist/sdk/__fixtures__/mock-userstorage.cjs +29 -6
- package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +1 -1
- package/dist/sdk/__fixtures__/mock-userstorage.d.cts +4 -6
- package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +1 -1
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts +4 -6
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +1 -1
- package/dist/sdk/__fixtures__/mock-userstorage.mjs +6 -6
- package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +1 -2
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
- package/dist/sdk/user-storage.cjs +62 -9
- package/dist/sdk/user-storage.cjs.map +1 -1
- package/dist/sdk/user-storage.d.cts +5 -1
- package/dist/sdk/user-storage.d.cts.map +1 -1
- package/dist/sdk/user-storage.d.mts +5 -1
- package/dist/sdk/user-storage.d.mts.map +1 -1
- package/dist/sdk/user-storage.mjs +62 -9
- package/dist/sdk/user-storage.mjs.map +1 -1
- package/dist/shared/encryption/cache.cjs +12 -14
- package/dist/shared/encryption/cache.cjs.map +1 -1
- package/dist/shared/encryption/cache.d.cts +4 -3
- package/dist/shared/encryption/cache.d.cts.map +1 -1
- package/dist/shared/encryption/cache.d.mts +4 -3
- package/dist/shared/encryption/cache.d.mts.map +1 -1
- package/dist/shared/encryption/cache.mjs +11 -13
- package/dist/shared/encryption/cache.mjs.map +1 -1
- package/dist/shared/encryption/constants.cjs +18 -0
- package/dist/shared/encryption/constants.cjs.map +1 -0
- package/dist/shared/encryption/constants.d.cts +8 -0
- package/dist/shared/encryption/constants.d.cts.map +1 -0
- package/dist/shared/encryption/constants.d.mts +8 -0
- package/dist/shared/encryption/constants.d.mts.map +1 -0
- package/dist/shared/encryption/constants.mjs +15 -0
- package/dist/shared/encryption/constants.mjs.map +1 -0
- package/dist/shared/encryption/encryption.cjs +49 -25
- package/dist/shared/encryption/encryption.cjs.map +1 -1
- package/dist/shared/encryption/encryption.d.cts +2 -0
- package/dist/shared/encryption/encryption.d.cts.map +1 -1
- package/dist/shared/encryption/encryption.d.mts +2 -0
- package/dist/shared/encryption/encryption.d.mts.map +1 -1
- package/dist/shared/encryption/encryption.mjs +38 -14
- package/dist/shared/encryption/encryption.mjs.map +1 -1
- package/package.json +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,48 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.1.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Revamp user storage encryption process ([#4981](https://github.com/MetaMask/core/pull/4981))
|
|
15
|
+
- Stop using a random salt when generating scrypt keys and use a shared one
|
|
16
|
+
- Re-encrypt data fetched by `getUserStorageAllFeatureEntries` and `getUserStorage` with the shared salt if fetched entries were encrypted with random salts
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Remove `#assertLoggedIn()` assertion when signing out a user, ensuring `performSignOut` does not error when a user is already signed out ([#5013](https://github.com/MetaMask/core/pull/5013))
|
|
21
|
+
|
|
22
|
+
## [3.0.0]
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- Add optional constructor arguments for `config.networkSyncing` to UserStorageController: `maxNumberOfAccountsToAdd`, `onNetworkAdded`, `onNetworkUpdated`, `onNetworkRemoved` ([#4701](https://github.com/MetaMask/core/pull/4701))
|
|
27
|
+
- Add new UserStorageController method `syncNetworks`, which can be used to initiate the main network sync ([#4701](https://github.com/MetaMask/core/pull/4701))
|
|
28
|
+
- Add optional property `hasNetworkSyncingSyncedAtLeastOnce` to UserStorageController state ([#4701](https://github.com/MetaMask/core/pull/4701))
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- **BREAKING:** The controller messenger must now allow the actions `NetworkController:getState`, `NetworkController:addNetwork`, `NetworkController:removeNetwork`, and `NetworkController:updateNetwork` ([#4701](https://github.com/MetaMask/core/pull/4701))
|
|
33
|
+
- **BREAKING:** The controller messenger must now allow the event `NetworkController:networkRemoved` ([#4701](https://github.com/MetaMask/core/pull/4701))
|
|
34
|
+
- Bump `@metamask/keyring-controller` from `^19.0.0` to `^19.0.1` ([#5012](https://github.com/MetaMask/core/pull/5012))
|
|
35
|
+
- Bump `@metamask/network-controller` from `^22.0.2` to `^22.1.0` ([#5012](https://github.com/MetaMask/core/pull/5012))
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- Make implicit peer dependencies explicit ([#4974](https://github.com/MetaMask/core/pull/4974))
|
|
40
|
+
- Add the following packages as peer dependencies of this package to satisfy peer dependency requirements from other dependencies:
|
|
41
|
+
- `@metamask/providers` `^18.1.0` (required by `@metamask/keyring-api`)
|
|
42
|
+
- `webextension-polyfill` `^0.10.0 || ^0.11.0 || ^0.12.0` (required by `@metamask/providers`)
|
|
43
|
+
- These dependencies really should be present in projects that consume this package (e.g. MetaMask clients), and this change ensures that they now are.
|
|
44
|
+
- Furthermore, we are assuming that clients already use these dependencies, since otherwise it would be impossible to consume this package in its entirety or even create a working build. Hence, the addition of these peer dependencies is really a formality and should not be breaking.
|
|
45
|
+
- Fix user storage controller to use the user-storage batch API to upsert remote networks rather than upserting them one at a time ([#4701](https://github.com/MetaMask/core/pull/4701))
|
|
46
|
+
- Correct ESM-compatible build so that imports of the following packages that re-export other modules via `export *` are no longer corrupted: ([#5011](https://github.com/MetaMask/core/pull/5011))
|
|
47
|
+
- `@metamask/keyring-api`
|
|
48
|
+
- `loglevel`
|
|
49
|
+
- `nock`
|
|
50
|
+
- `siwe`
|
|
51
|
+
|
|
10
52
|
## [2.0.0]
|
|
11
53
|
|
|
12
54
|
### Changed
|
|
@@ -328,7 +370,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
328
370
|
|
|
329
371
|
- Initial release
|
|
330
372
|
|
|
331
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@
|
|
373
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@3.1.0...HEAD
|
|
374
|
+
[3.1.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@3.0.0...@metamask/profile-sync-controller@3.1.0
|
|
375
|
+
[3.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@2.0.0...@metamask/profile-sync-controller@3.0.0
|
|
332
376
|
[2.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@1.0.2...@metamask/profile-sync-controller@2.0.0
|
|
333
377
|
[1.0.2]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@1.0.1...@metamask/profile-sync-controller@1.0.2
|
|
334
378
|
[1.0.1]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@1.0.0...@metamask/profile-sync-controller@1.0.1
|
|
@@ -72,7 +72,6 @@ class AuthenticationController extends base_controller_1.BaseController {
|
|
|
72
72
|
return accessToken;
|
|
73
73
|
}
|
|
74
74
|
performSignOut() {
|
|
75
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertLoggedIn).call(this);
|
|
76
75
|
this.update((state) => {
|
|
77
76
|
state.isSignedIn = false;
|
|
78
77
|
state.sessionData = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticationController.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,+DAA2D;AAQ3D,iEAG8B;AAC9B,6CAKoB;AAEpB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;AAErC,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA8BrC,QAAA,YAAY,GAAkC;IACzD,UAAU,EAAE,KAAK;CAClB,CAAC;AACF,MAAM,QAAQ,GAAiD;IAC7D,UAAU,EAAE;QACV,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,WAAW,EAAE;QACX,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AA0DF;;;GAGG;AACH,MAAqB,wBAAyB,SAAQ,gCAIrD;IAsBC,YAAY,EACV,SAAS,EACT,KAAK,EACL,WAAW,GASZ;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ;YACR,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,EAAE,GAAG,oBAAY,EAAE,GAAG,KAAK,EAAE;SACrC,CAAC,CAAC;;QAvCL,wDAA8B;QAE9B,+CAAc,KAAK,EAAC;QAEpB,sDAAqB;YACnB,6BAA6B,EAAE,GAAG,EAAE;gBAClC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,C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AM,CAAC;AAChC,CAAC;AAID;;;;GAIG;AACH,KAAK;IACH,IAAI,uBAAA,IAAI,qDAAqB,EAAE;QAC7B,OAAO,uBAAA,IAAI,qDAAqB,CAAC;KAClC;IAED,IAAI,CAAC,uBAAA,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,IAAA,+CAA0B,GAAE,CAC7B,CAAW,CAAC;IAEb,uBAAA,IAAI,iDAAwB,MAAM,MAAA,CAAC;IAEnC,OAAO,MAAM,CAAC;AAChB,CAAC;AAID;;;;;GAKG;AACH,KAAK,oDAAkB,OAA6B;IAClD,IAAI,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,IAAI,CAAC,uBAAA,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,IAAA,iDAA4B,EAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC;kBArRkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport {\n createSnapPublicKeyRequest,\n createSnapSignMessageRequest,\n} from './auth-snap-requests';\nimport {\n createLoginRawMessage,\n getAccessToken,\n getNonce,\n login,\n} from './services';\n\nconst THIRTY_MIN_MS = 1000 * 60 * 30;\n\nconst controllerName = 'AuthenticationController';\n\n// State\ntype SessionProfile = {\n identifierId: string;\n profileId: string;\n};\n\ntype SessionData = {\n /** profile - anonymous profile data for the given logged in user */\n profile: SessionProfile;\n /** accessToken - used to make requests authorized endpoints */\n accessToken: string;\n /** expiresIn - string date to determine if new access token is required */\n expiresIn: string;\n};\n\ntype MetaMetricsAuth = {\n getMetaMetricsId: () => string | Promise<string>;\n agent: 'extension' | 'mobile';\n};\n\nexport type AuthenticationControllerState = {\n /**\n * Global isSignedIn state.\n * Can be used to determine if \"Profile Syncing\" is enabled.\n */\n isSignedIn: boolean;\n sessionData?: SessionData;\n};\nexport const defaultState: AuthenticationControllerState = {\n isSignedIn: false,\n};\nconst metadata: StateMetadata<AuthenticationControllerState> = {\n isSignedIn: {\n persist: true,\n anonymous: true,\n },\n sessionData: {\n persist: true,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof AuthenticationController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: AuthenticationController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performSignIn'\n | 'performSignOut'\n | 'getBearerToken'\n | 'getSessionProfile'\n | 'isSignedIn'\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | AuthenticationControllerGetStateAction;\nexport type AuthenticationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AuthenticationControllerState\n>;\nexport type AuthenticationControllerPerformSignIn = ActionsObj['performSignIn'];\nexport type AuthenticationControllerPerformSignOut =\n ActionsObj['performSignOut'];\nexport type AuthenticationControllerGetBearerToken =\n ActionsObj['getBearerToken'];\nexport type AuthenticationControllerGetSessionProfile =\n ActionsObj['getSessionProfile'];\nexport type AuthenticationControllerIsSignedIn = ActionsObj['isSignedIn'];\n\nexport type AuthenticationControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AuthenticationControllerState\n >;\n\nexport type Events = AuthenticationControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | KeyringControllerGetStateAction;\n\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Controller that enables authentication for restricted endpoints.\n * Used for Global Profile Syncing and Notifications\n */\nexport default class AuthenticationController extends BaseController<\n typeof controllerName,\n AuthenticationControllerState,\n AuthenticationControllerMessenger\n> {\n #metametrics: MetaMetricsAuth;\n\n #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n constructor({\n messenger,\n state,\n metametrics,\n }: {\n messenger: AuthenticationControllerMessenger;\n state?: AuthenticationControllerState;\n /**\n * Not using the Messaging System as we\n * do not want to tie this strictly to extension\n */\n metametrics: MetaMetricsAuth;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n if (!metametrics) {\n throw new Error('`metametrics` field is required');\n }\n\n this.#metametrics = metametrics;\n\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getBearerToken',\n this.getBearerToken.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getSessionProfile',\n this.getSessionProfile.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:isSignedIn',\n this.isSignedIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignIn',\n this.performSignIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignOut',\n this.performSignOut.bind(this),\n );\n }\n\n public async performSignIn(): Promise<string> {\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n public performSignOut(): void {\n this.#assertLoggedIn();\n\n this.update((state) => {\n state.isSignedIn = false;\n state.sessionData = undefined;\n });\n }\n\n public async getBearerToken(): Promise<string> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.accessToken;\n }\n\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n /**\n * Will return a session profile.\n * Throws if a user is not logged in.\n *\n * @returns profile for the session.\n */\n public async getSessionProfile(): Promise<SessionProfile> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.profile;\n }\n\n const { profile } = await this.#performAuthenticationFlow();\n return profile;\n }\n\n public isSignedIn(): boolean {\n return this.state.isSignedIn;\n }\n\n #assertLoggedIn(): void {\n if (!this.state.isSignedIn) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n async #performAuthenticationFlow(): Promise<{\n profile: SessionProfile;\n accessToken: string;\n }> {\n try {\n // 1. Nonce\n const publicKey = await this.#snapGetPublicKey();\n const nonce = await getNonce(publicKey);\n if (!nonce) {\n throw new Error(`Unable to get nonce`);\n }\n\n // 2. Login\n const rawMessage = createLoginRawMessage(nonce, publicKey);\n const signature = await this.#snapSignMessage(rawMessage);\n const loginResponse = await login(rawMessage, signature, {\n metametricsId: await this.#metametrics.getMetaMetricsId(),\n agent: this.#metametrics.agent,\n });\n if (!loginResponse?.token) {\n throw new Error(`Unable to login`);\n }\n\n const profile: SessionProfile = {\n identifierId: loginResponse.profile.identifier_id,\n profileId: loginResponse.profile.profile_id,\n };\n\n // 3. Trade for Access Token\n const accessToken = await getAccessToken(\n loginResponse.token,\n this.#metametrics.agent,\n );\n if (!accessToken) {\n throw new Error(`Unable to get Access Token`);\n }\n\n // Update Internal State\n this.update((state) => {\n state.isSignedIn = true;\n const expiresIn = new Date();\n expiresIn.setTime(expiresIn.getTime() + THIRTY_MIN_MS);\n state.sessionData = {\n profile,\n accessToken,\n expiresIn: expiresIn.toString(),\n };\n });\n\n return {\n profile,\n accessToken,\n };\n } catch (e) {\n console.error('Failed to authenticate', e);\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new Error(\n `${controllerName}: Failed to authenticate - ${errorMessage}`,\n );\n }\n }\n\n #hasValidSession(\n sessionData: SessionData | undefined,\n ): sessionData is SessionData {\n if (!sessionData) {\n return false;\n }\n\n const prevDate = Date.parse(sessionData.expiresIn);\n if (isNaN(prevDate)) {\n return false;\n }\n\n const currentDate = new Date();\n const diffMs = Math.abs(currentDate.getTime() - prevDate);\n\n return THIRTY_MIN_MS > diffMs;\n }\n\n #_snapPublicKeyCache: string | undefined;\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n if (this.#_snapPublicKeyCache) {\n return this.#_snapPublicKeyCache;\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapGetPublicKey - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\n\n this.#_snapPublicKeyCache = result;\n\n return result;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AuthenticationController.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,+DAA2D;AAQ3D,iEAG8B;AAC9B,6CAKoB;AAEpB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;AAErC,MAAM,cAAc,GAAG,0BAA0B,CAAC;AA8BrC,QAAA,YAAY,GAAkC;IACzD,UAAU,EAAE,KAAK;CAClB,CAAC;AACF,MAAM,QAAQ,GAAiD;IAC7D,UAAU,EAAE;QACV,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,WAAW,EAAE;QACX,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AA0DF;;;GAGG;AACH,MAAqB,wBAAyB,SAAQ,gCAIrD;IAsBC,YAAY,EACV,SAAS,EACT,KAAK,EACL,WAAW,GASZ;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ;YACR,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,EAAE,GAAG,oBAAY,EAAE,GAAG,KAAK,EAAE;SACrC,CAAC,CAAC;;QAvCL,wDAA8B;QAE9B,+CAAc,KAAK,EAAC;QAEpB,sDAAqB;YACnB,6BAA6B,EAAE,GAAG,EAAE;gBAClC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC9C,4BAA4B,CAC7B,CAAC;gBACF,uBAAA,IAAI,wCAAe,UAAU,MAAA,CAAC;gBAE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,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,IAAA,+CAA0B,GAAE,CAC7B,CAAW,CAAC;IAEb,uBAAA,IAAI,iDAAwB,MAAM,MAAA,CAAC;IAEnC,OAAO,MAAM,CAAC;AAChB,CAAC;AAID;;;;;GAKG;AACH,KAAK,oDAAkB,OAA6B;IAClD,IAAI,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,IAAI,CAAC,uBAAA,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,IAAA,iDAA4B,EAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC;kBAnRkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport {\n createSnapPublicKeyRequest,\n createSnapSignMessageRequest,\n} from './auth-snap-requests';\nimport {\n createLoginRawMessage,\n getAccessToken,\n getNonce,\n login,\n} from './services';\n\nconst THIRTY_MIN_MS = 1000 * 60 * 30;\n\nconst controllerName = 'AuthenticationController';\n\n// State\ntype SessionProfile = {\n identifierId: string;\n profileId: string;\n};\n\ntype SessionData = {\n /** profile - anonymous profile data for the given logged in user */\n profile: SessionProfile;\n /** accessToken - used to make requests authorized endpoints */\n accessToken: string;\n /** expiresIn - string date to determine if new access token is required */\n expiresIn: string;\n};\n\ntype MetaMetricsAuth = {\n getMetaMetricsId: () => string | Promise<string>;\n agent: 'extension' | 'mobile';\n};\n\nexport type AuthenticationControllerState = {\n /**\n * Global isSignedIn state.\n * Can be used to determine if \"Profile Syncing\" is enabled.\n */\n isSignedIn: boolean;\n sessionData?: SessionData;\n};\nexport const defaultState: AuthenticationControllerState = {\n isSignedIn: false,\n};\nconst metadata: StateMetadata<AuthenticationControllerState> = {\n isSignedIn: {\n persist: true,\n anonymous: true,\n },\n sessionData: {\n persist: true,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof AuthenticationController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: AuthenticationController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performSignIn'\n | 'performSignOut'\n | 'getBearerToken'\n | 'getSessionProfile'\n | 'isSignedIn'\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | AuthenticationControllerGetStateAction;\nexport type AuthenticationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AuthenticationControllerState\n>;\nexport type AuthenticationControllerPerformSignIn = ActionsObj['performSignIn'];\nexport type AuthenticationControllerPerformSignOut =\n ActionsObj['performSignOut'];\nexport type AuthenticationControllerGetBearerToken =\n ActionsObj['getBearerToken'];\nexport type AuthenticationControllerGetSessionProfile =\n ActionsObj['getSessionProfile'];\nexport type AuthenticationControllerIsSignedIn = ActionsObj['isSignedIn'];\n\nexport type AuthenticationControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AuthenticationControllerState\n >;\n\nexport type Events = AuthenticationControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | KeyringControllerGetStateAction;\n\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Controller that enables authentication for restricted endpoints.\n * Used for Global Profile Syncing and Notifications\n */\nexport default class AuthenticationController extends BaseController<\n typeof controllerName,\n AuthenticationControllerState,\n AuthenticationControllerMessenger\n> {\n #metametrics: MetaMetricsAuth;\n\n #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n constructor({\n messenger,\n state,\n metametrics,\n }: {\n messenger: AuthenticationControllerMessenger;\n state?: AuthenticationControllerState;\n /**\n * Not using the Messaging System as we\n * do not want to tie this strictly to extension\n */\n metametrics: MetaMetricsAuth;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n if (!metametrics) {\n throw new Error('`metametrics` field is required');\n }\n\n this.#metametrics = metametrics;\n\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getBearerToken',\n this.getBearerToken.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getSessionProfile',\n this.getSessionProfile.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:isSignedIn',\n this.isSignedIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignIn',\n this.performSignIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignOut',\n this.performSignOut.bind(this),\n );\n }\n\n public async performSignIn(): Promise<string> {\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n public performSignOut(): void {\n this.update((state) => {\n state.isSignedIn = false;\n state.sessionData = undefined;\n });\n }\n\n public async getBearerToken(): Promise<string> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.accessToken;\n }\n\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n /**\n * Will return a session profile.\n * Throws if a user is not logged in.\n *\n * @returns profile for the session.\n */\n public async getSessionProfile(): Promise<SessionProfile> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.profile;\n }\n\n const { profile } = await this.#performAuthenticationFlow();\n return profile;\n }\n\n public isSignedIn(): boolean {\n return this.state.isSignedIn;\n }\n\n #assertLoggedIn(): void {\n if (!this.state.isSignedIn) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n async #performAuthenticationFlow(): Promise<{\n profile: SessionProfile;\n accessToken: string;\n }> {\n try {\n // 1. Nonce\n const publicKey = await this.#snapGetPublicKey();\n const nonce = await getNonce(publicKey);\n if (!nonce) {\n throw new Error(`Unable to get nonce`);\n }\n\n // 2. Login\n const rawMessage = createLoginRawMessage(nonce, publicKey);\n const signature = await this.#snapSignMessage(rawMessage);\n const loginResponse = await login(rawMessage, signature, {\n metametricsId: await this.#metametrics.getMetaMetricsId(),\n agent: this.#metametrics.agent,\n });\n if (!loginResponse?.token) {\n throw new Error(`Unable to login`);\n }\n\n const profile: SessionProfile = {\n identifierId: loginResponse.profile.identifier_id,\n profileId: loginResponse.profile.profile_id,\n };\n\n // 3. Trade for Access Token\n const accessToken = await getAccessToken(\n loginResponse.token,\n this.#metametrics.agent,\n );\n if (!accessToken) {\n throw new Error(`Unable to get Access Token`);\n }\n\n // Update Internal State\n this.update((state) => {\n state.isSignedIn = true;\n const expiresIn = new Date();\n expiresIn.setTime(expiresIn.getTime() + THIRTY_MIN_MS);\n state.sessionData = {\n profile,\n accessToken,\n expiresIn: expiresIn.toString(),\n };\n });\n\n return {\n profile,\n accessToken,\n };\n } catch (e) {\n console.error('Failed to authenticate', e);\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new Error(\n `${controllerName}: Failed to authenticate - ${errorMessage}`,\n );\n }\n }\n\n #hasValidSession(\n sessionData: SessionData | undefined,\n ): sessionData is SessionData {\n if (!sessionData) {\n return false;\n }\n\n const prevDate = Date.parse(sessionData.expiresIn);\n if (isNaN(prevDate)) {\n return false;\n }\n\n const currentDate = new Date();\n const diffMs = Math.abs(currentDate.getTime() - prevDate);\n\n return THIRTY_MIN_MS > diffMs;\n }\n\n #_snapPublicKeyCache: string | undefined;\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n if (this.#_snapPublicKeyCache) {\n return this.#_snapPublicKeyCache;\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapGetPublicKey - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\n\n this.#_snapPublicKeyCache = result;\n\n return result;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticationController.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAerE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,oEAAoE;IACpE,OAAO,EAAE,cAAc,CAAC;IACxB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,gBAAgB,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;OAGG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,CAAC;AACF,eAAO,MAAM,YAAY,EAAE,6BAE1B,CAAC;AAaF,KAAK,gBAAgB,CAAC,UAAU,SAAS,MAAM,wBAAwB,IAAI;KACxE,CAAC,IAAI,UAAU,GAAG;QACjB,IAAI,EAAE,GAAG,OAAO,cAAc,IAAI,CAAC,EAAE,CAAC;QACtC,OAAO,EAAE,w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K,EACL,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,6BAA6B,CAAC;QACtC;;;WAGG;QACH,WAAW,EAAE,eAAe,CAAC;KAC9B;IAiDY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"AuthenticationController.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAerE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,oEAAoE;IACpE,OAAO,EAAE,cAAc,CAAC;IACxB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,gBAAgB,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;OAGG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,CAAC;AACF,eAAO,MAAM,YAAY,EAAE,6BAE1B,CAAC;AAaF,KAAK,gBAAgB,CAAC,UAAU,SAAS,MAAM,wBA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AC,OAAO,OAAO,wBAAyB,SAAQ,cAAc,CAClE,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAsBa,EACV,SAAS,EACT,KAAK,EACL,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,6BAA6B,CAAC;QACtC;;;WAGG;QACH,WAAW,EAAE,eAAe,CAAC;KAC9B;IAiDY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;IAOhB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAW9C;;;;;OAKG;IACU,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAWlD,UAAU,IAAI,OAAO;CAqJ7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticationController.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAerE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,oEAAoE;IACpE,OAAO,EAAE,cAAc,CAAC;IACxB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,gBAAgB,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAA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AA+B,CAAC;AAEpC,MAAM,MAAM,aAAa,GACrB,0BAA0B,GAC1B,4BAA4B,CAAC;AAGjC,MAAM,MAAM,iCAAiC,GAAG,6BAA6B,CAC3E,OAAO,cAAc,EACrB,OAAO,GAAG,cAAc,EACxB,MAAM,GAAG,aAAa,EACtB,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,cAAc,CAClE,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAsBa,EACV,SAAS,EACT,KAAK,EACL,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,6BAA6B,CAAC;QACtC;;;WAGG;QACH,WAAW,EAAE,eAAe,CAAC;KAC9B;IAiDY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"AuthenticationController.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAE9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC7B,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAerE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,oEAAoE;IACpE,OAAO,EAAE,cAAc,CAAC;IACxB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,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ACrB,6BAA6B,CAC9B,CAAC;AAEJ,MAAM,MAAM,MAAM,GAAG,wCAAwC,CAAC;AAG9D,MAAM,MAAM,cAAc,GACtB,iBAAiB,GACjB,+BAA+B,CAAC;AAEpC,MAAM,MAAM,aAAa,GACrB,0BAA0B,GAC1B,4BAA4B,CAAC;AAGjC,MAAM,MAAM,iCAAiC,GAAG,6BAA6B,CAC3E,OAAO,cAAc,EACrB,OAAO,GAAG,cAAc,EACxB,MAAM,GAAG,aAAa,EACtB,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,cAAc,CAClE,OAAO,cAAc,EACrB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAsBa,EACV,SAAS,EACT,KAAK,EACL,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,KAAK,CAAC,EAAE,6BAA6B,CAAC;QACtC;;;WAGG;QACH,WAAW,EAAE,eAAe,CAAC;KAC9B;IAiDY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;IAOhB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAW9C;;;;;OAKG;IACU,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAWlD,UAAU,IAAI,OAAO;CAqJ7B"}
|
|
@@ -69,7 +69,6 @@ class AuthenticationController extends BaseController {
|
|
|
69
69
|
return accessToken;
|
|
70
70
|
}
|
|
71
71
|
performSignOut() {
|
|
72
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertLoggedIn).call(this);
|
|
73
72
|
this.update((state) => {
|
|
74
73
|
state.isSignedIn = false;
|
|
75
74
|
state.sessionData = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticationController.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/Authentication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A0B,EAAE,CAC7B,CAAW,CAAC;IAEb,uBAAA,IAAI,iDAAwB,MAAM,MAAA,CAAC;IAEnC,OAAO,MAAM,CAAC;AAChB,CAAC;AAID;;;;;GAKG;AACH,KAAK,oDAAkB,OAA6B;IAClD,IAAI,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,IAAI,CAAC,uBAAA,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,4BAA4B,CAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC;eArRkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport {\n createSnapPublicKeyRequest,\n createSnapSignMessageRequest,\n} from './auth-snap-requests';\nimport {\n createLoginRawMessage,\n getAccessToken,\n getNonce,\n login,\n} from './services';\n\nconst THIRTY_MIN_MS = 1000 * 60 * 30;\n\nconst controllerName = 'AuthenticationController';\n\n// State\ntype SessionProfile = {\n identifierId: string;\n profileId: string;\n};\n\ntype SessionData = {\n /** profile - anonymous profile data for the given logged in user */\n profile: SessionProfile;\n /** accessToken - used to make requests authorized endpoints */\n accessToken: string;\n /** expiresIn - string date to determine if new access token is required */\n expiresIn: string;\n};\n\ntype MetaMetricsAuth = {\n getMetaMetricsId: () => string | Promise<string>;\n agent: 'extension' | 'mobile';\n};\n\nexport type AuthenticationControllerState = {\n /**\n * Global isSignedIn state.\n * Can be used to determine if \"Profile Syncing\" is enabled.\n */\n isSignedIn: boolean;\n sessionData?: SessionData;\n};\nexport const defaultState: AuthenticationControllerState = {\n isSignedIn: false,\n};\nconst metadata: StateMetadata<AuthenticationControllerState> = {\n isSignedIn: {\n persist: true,\n anonymous: true,\n },\n sessionData: {\n persist: true,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof AuthenticationController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: AuthenticationController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performSignIn'\n | 'performSignOut'\n | 'getBearerToken'\n | 'getSessionProfile'\n | 'isSignedIn'\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | AuthenticationControllerGetStateAction;\nexport type AuthenticationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AuthenticationControllerState\n>;\nexport type AuthenticationControllerPerformSignIn = ActionsObj['performSignIn'];\nexport type AuthenticationControllerPerformSignOut =\n ActionsObj['performSignOut'];\nexport type AuthenticationControllerGetBearerToken =\n ActionsObj['getBearerToken'];\nexport type AuthenticationControllerGetSessionProfile =\n ActionsObj['getSessionProfile'];\nexport type AuthenticationControllerIsSignedIn = ActionsObj['isSignedIn'];\n\nexport type AuthenticationControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AuthenticationControllerState\n >;\n\nexport type Events = AuthenticationControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | KeyringControllerGetStateAction;\n\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Controller that enables authentication for restricted endpoints.\n * Used for Global Profile Syncing and Notifications\n */\nexport default class AuthenticationController extends BaseController<\n typeof controllerName,\n AuthenticationControllerState,\n AuthenticationControllerMessenger\n> {\n #metametrics: MetaMetricsAuth;\n\n #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n constructor({\n messenger,\n state,\n metametrics,\n }: {\n messenger: AuthenticationControllerMessenger;\n state?: AuthenticationControllerState;\n /**\n * Not using the Messaging System as we\n * do not want to tie this strictly to extension\n */\n metametrics: MetaMetricsAuth;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n if (!metametrics) {\n throw new Error('`metametrics` field is required');\n }\n\n this.#metametrics = metametrics;\n\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getBearerToken',\n this.getBearerToken.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getSessionProfile',\n this.getSessionProfile.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:isSignedIn',\n this.isSignedIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignIn',\n this.performSignIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignOut',\n this.performSignOut.bind(this),\n );\n }\n\n public async performSignIn(): Promise<string> {\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n public performSignOut(): void {\n this.#assertLoggedIn();\n\n this.update((state) => {\n state.isSignedIn = false;\n state.sessionData = undefined;\n });\n }\n\n public async getBearerToken(): Promise<string> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.accessToken;\n }\n\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n /**\n * Will return a session profile.\n * Throws if a user is not logged in.\n *\n * @returns profile for the session.\n */\n public async getSessionProfile(): Promise<SessionProfile> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.profile;\n }\n\n const { profile } = await this.#performAuthenticationFlow();\n return profile;\n }\n\n public isSignedIn(): boolean {\n return this.state.isSignedIn;\n }\n\n #assertLoggedIn(): void {\n if (!this.state.isSignedIn) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n async #performAuthenticationFlow(): Promise<{\n profile: SessionProfile;\n accessToken: string;\n }> {\n try {\n // 1. Nonce\n const publicKey = await this.#snapGetPublicKey();\n const nonce = await getNonce(publicKey);\n if (!nonce) {\n throw new Error(`Unable to get nonce`);\n }\n\n // 2. Login\n const rawMessage = createLoginRawMessage(nonce, publicKey);\n const signature = await this.#snapSignMessage(rawMessage);\n const loginResponse = await login(rawMessage, signature, {\n metametricsId: await this.#metametrics.getMetaMetricsId(),\n agent: this.#metametrics.agent,\n });\n if (!loginResponse?.token) {\n throw new Error(`Unable to login`);\n }\n\n const profile: SessionProfile = {\n identifierId: loginResponse.profile.identifier_id,\n profileId: loginResponse.profile.profile_id,\n };\n\n // 3. Trade for Access Token\n const accessToken = await getAccessToken(\n loginResponse.token,\n this.#metametrics.agent,\n );\n if (!accessToken) {\n throw new Error(`Unable to get Access Token`);\n }\n\n // Update Internal State\n this.update((state) => {\n state.isSignedIn = true;\n const expiresIn = new Date();\n expiresIn.setTime(expiresIn.getTime() + THIRTY_MIN_MS);\n state.sessionData = {\n profile,\n accessToken,\n expiresIn: expiresIn.toString(),\n };\n });\n\n return {\n profile,\n accessToken,\n };\n } catch (e) {\n console.error('Failed to authenticate', e);\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new Error(\n `${controllerName}: Failed to authenticate - ${errorMessage}`,\n );\n }\n }\n\n #hasValidSession(\n sessionData: SessionData | undefined,\n ): sessionData is SessionData {\n if (!sessionData) {\n return false;\n }\n\n const prevDate = Date.parse(sessionData.expiresIn);\n if (isNaN(prevDate)) {\n return false;\n }\n\n const currentDate = new Date();\n const diffMs = Math.abs(currentDate.getTime() - prevDate);\n\n return THIRTY_MIN_MS > diffMs;\n }\n\n #_snapPublicKeyCache: string | undefined;\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n if (this.#_snapPublicKeyCache) {\n return this.#_snapPublicKeyCache;\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapGetPublicKey - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\n\n this.#_snapPublicKeyCache = result;\n\n return result;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AuthenticationController.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":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AAA,CAAC;IAEnC,OAAO,MAAM,CAAC;AAChB,CAAC;AAID;;;;;GAKG;AACH,KAAK,oDAAkB,OAA6B;IAClD,IAAI,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,IAAI,CAAC,uBAAA,IAAI,4CAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,4BAA4B,CAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC;eAnRkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport {\n createSnapPublicKeyRequest,\n createSnapSignMessageRequest,\n} from './auth-snap-requests';\nimport {\n createLoginRawMessage,\n getAccessToken,\n getNonce,\n login,\n} from './services';\n\nconst THIRTY_MIN_MS = 1000 * 60 * 30;\n\nconst controllerName = 'AuthenticationController';\n\n// State\ntype SessionProfile = {\n identifierId: string;\n profileId: string;\n};\n\ntype SessionData = {\n /** profile - anonymous profile data for the given logged in user */\n profile: SessionProfile;\n /** accessToken - used to make requests authorized endpoints */\n accessToken: string;\n /** expiresIn - string date to determine if new access token is required */\n expiresIn: string;\n};\n\ntype MetaMetricsAuth = {\n getMetaMetricsId: () => string | Promise<string>;\n agent: 'extension' | 'mobile';\n};\n\nexport type AuthenticationControllerState = {\n /**\n * Global isSignedIn state.\n * Can be used to determine if \"Profile Syncing\" is enabled.\n */\n isSignedIn: boolean;\n sessionData?: SessionData;\n};\nexport const defaultState: AuthenticationControllerState = {\n isSignedIn: false,\n};\nconst metadata: StateMetadata<AuthenticationControllerState> = {\n isSignedIn: {\n persist: true,\n anonymous: true,\n },\n sessionData: {\n persist: true,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof AuthenticationController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: AuthenticationController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performSignIn'\n | 'performSignOut'\n | 'getBearerToken'\n | 'getSessionProfile'\n | 'isSignedIn'\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | AuthenticationControllerGetStateAction;\nexport type AuthenticationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AuthenticationControllerState\n>;\nexport type AuthenticationControllerPerformSignIn = ActionsObj['performSignIn'];\nexport type AuthenticationControllerPerformSignOut =\n ActionsObj['performSignOut'];\nexport type AuthenticationControllerGetBearerToken =\n ActionsObj['getBearerToken'];\nexport type AuthenticationControllerGetSessionProfile =\n ActionsObj['getSessionProfile'];\nexport type AuthenticationControllerIsSignedIn = ActionsObj['isSignedIn'];\n\nexport type AuthenticationControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n AuthenticationControllerState\n >;\n\nexport type Events = AuthenticationControllerStateChangeEvent;\n\n// Allowed Actions\nexport type AllowedActions =\n | HandleSnapRequest\n | KeyringControllerGetStateAction;\n\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent;\n\n// Messenger\nexport type AuthenticationControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Controller that enables authentication for restricted endpoints.\n * Used for Global Profile Syncing and Notifications\n */\nexport default class AuthenticationController extends BaseController<\n typeof controllerName,\n AuthenticationControllerState,\n AuthenticationControllerMessenger\n> {\n #metametrics: MetaMetricsAuth;\n\n #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n constructor({\n messenger,\n state,\n metametrics,\n }: {\n messenger: AuthenticationControllerMessenger;\n state?: AuthenticationControllerState;\n /**\n * Not using the Messaging System as we\n * do not want to tie this strictly to extension\n */\n metametrics: MetaMetricsAuth;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n if (!metametrics) {\n throw new Error('`metametrics` field is required');\n }\n\n this.#metametrics = metametrics;\n\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getBearerToken',\n this.getBearerToken.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:getSessionProfile',\n this.getSessionProfile.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:isSignedIn',\n this.isSignedIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignIn',\n this.performSignIn.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'AuthenticationController:performSignOut',\n this.performSignOut.bind(this),\n );\n }\n\n public async performSignIn(): Promise<string> {\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n public performSignOut(): void {\n this.update((state) => {\n state.isSignedIn = false;\n state.sessionData = undefined;\n });\n }\n\n public async getBearerToken(): Promise<string> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.accessToken;\n }\n\n const { accessToken } = await this.#performAuthenticationFlow();\n return accessToken;\n }\n\n /**\n * Will return a session profile.\n * Throws if a user is not logged in.\n *\n * @returns profile for the session.\n */\n public async getSessionProfile(): Promise<SessionProfile> {\n this.#assertLoggedIn();\n\n if (this.#hasValidSession(this.state.sessionData)) {\n return this.state.sessionData.profile;\n }\n\n const { profile } = await this.#performAuthenticationFlow();\n return profile;\n }\n\n public isSignedIn(): boolean {\n return this.state.isSignedIn;\n }\n\n #assertLoggedIn(): void {\n if (!this.state.isSignedIn) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n async #performAuthenticationFlow(): Promise<{\n profile: SessionProfile;\n accessToken: string;\n }> {\n try {\n // 1. Nonce\n const publicKey = await this.#snapGetPublicKey();\n const nonce = await getNonce(publicKey);\n if (!nonce) {\n throw new Error(`Unable to get nonce`);\n }\n\n // 2. Login\n const rawMessage = createLoginRawMessage(nonce, publicKey);\n const signature = await this.#snapSignMessage(rawMessage);\n const loginResponse = await login(rawMessage, signature, {\n metametricsId: await this.#metametrics.getMetaMetricsId(),\n agent: this.#metametrics.agent,\n });\n if (!loginResponse?.token) {\n throw new Error(`Unable to login`);\n }\n\n const profile: SessionProfile = {\n identifierId: loginResponse.profile.identifier_id,\n profileId: loginResponse.profile.profile_id,\n };\n\n // 3. Trade for Access Token\n const accessToken = await getAccessToken(\n loginResponse.token,\n this.#metametrics.agent,\n );\n if (!accessToken) {\n throw new Error(`Unable to get Access Token`);\n }\n\n // Update Internal State\n this.update((state) => {\n state.isSignedIn = true;\n const expiresIn = new Date();\n expiresIn.setTime(expiresIn.getTime() + THIRTY_MIN_MS);\n state.sessionData = {\n profile,\n accessToken,\n expiresIn: expiresIn.toString(),\n };\n });\n\n return {\n profile,\n accessToken,\n };\n } catch (e) {\n console.error('Failed to authenticate', e);\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new Error(\n `${controllerName}: Failed to authenticate - ${errorMessage}`,\n );\n }\n }\n\n #hasValidSession(\n sessionData: SessionData | undefined,\n ): sessionData is SessionData {\n if (!sessionData) {\n return false;\n }\n\n const prevDate = Date.parse(sessionData.expiresIn);\n if (isNaN(prevDate)) {\n return false;\n }\n\n const currentDate = new Date();\n const diffMs = Math.abs(currentDate.getTime() - prevDate);\n\n return THIRTY_MIN_MS > diffMs;\n }\n\n #_snapPublicKeyCache: string | undefined;\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n if (this.#_snapPublicKeyCache) {\n return this.#_snapPublicKeyCache;\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapGetPublicKey - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\n\n this.#_snapPublicKeyCache = result;\n\n return result;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n}\n"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
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
|
+
};
|
|
2
7
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
8
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
9
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
11
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
12
|
};
|
|
8
|
-
var
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
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");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _UserStorageController_instances, _UserStorageController_auth, _UserStorageController_accounts, _UserStorageController_config, _UserStorageController_notificationServices, _UserStorageController_isUnlocked, _UserStorageController_keyringController, _UserStorageController_nativeScryptCrypto, _UserStorageController_registerMessageHandlers, _UserStorageController_assertProfileSyncingEnabled, _UserStorageController_getStorageKeyAndBearerToken, _UserStorageController_createStorageKey, _UserStorageController__snapSignMessageCache, _UserStorageController_snapSignMessage, _UserStorageController_setIsProfileSyncingUpdateLoading;
|
|
13
|
+
var _UserStorageController_instances, _UserStorageController_env, _UserStorageController_auth, _UserStorageController_accounts, _UserStorageController_config, _UserStorageController_notificationServices, _UserStorageController_isUnlocked, _UserStorageController_keyringController, _UserStorageController_nativeScryptCrypto, _UserStorageController_registerMessageHandlers, _UserStorageController_getStorageOptions, _UserStorageController_assertProfileSyncingEnabled, _UserStorageController_getStorageKeyAndBearerToken, _UserStorageController_createStorageKey, _UserStorageController__snapSignMessageCache, _UserStorageController_snapSignMessage, _UserStorageController_setIsProfileSyncingUpdateLoading;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.defaultState = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -40,12 +40,16 @@ const metadata = {
|
|
|
40
40
|
},
|
|
41
41
|
hasAccountSyncingSyncedAtLeastOnce: {
|
|
42
42
|
persist: true,
|
|
43
|
-
anonymous:
|
|
43
|
+
anonymous: false,
|
|
44
44
|
},
|
|
45
45
|
isAccountSyncingReadyToBeDispatched: {
|
|
46
46
|
persist: false,
|
|
47
47
|
anonymous: false,
|
|
48
48
|
},
|
|
49
|
+
hasNetworkSyncingSyncedAtLeastOnce: {
|
|
50
|
+
persist: true,
|
|
51
|
+
anonymous: false,
|
|
52
|
+
},
|
|
49
53
|
};
|
|
50
54
|
/**
|
|
51
55
|
* Reusable controller that allows any team to store synchronized data for a given user.
|
|
@@ -64,6 +68,12 @@ class UserStorageController extends base_controller_1.BaseController {
|
|
|
64
68
|
state: { ...exports.defaultState, ...state },
|
|
65
69
|
});
|
|
66
70
|
_UserStorageController_instances.add(this);
|
|
71
|
+
// This is replaced with the actual value in the constructor
|
|
72
|
+
// We will remove this once the feature will be released
|
|
73
|
+
_UserStorageController_env.set(this, {
|
|
74
|
+
isAccountSyncingEnabled: false,
|
|
75
|
+
isNetworkSyncingEnabled: false,
|
|
76
|
+
});
|
|
67
77
|
_UserStorageController_auth.set(this, {
|
|
68
78
|
getBearerToken: async () => {
|
|
69
79
|
return await this.messagingSystem.call('AuthenticationController:getBearerToken');
|
|
@@ -83,8 +93,6 @@ class UserStorageController extends base_controller_1.BaseController {
|
|
|
83
93
|
},
|
|
84
94
|
});
|
|
85
95
|
_UserStorageController_accounts.set(this, {
|
|
86
|
-
// This is replaced with the actual value in the constructor
|
|
87
|
-
isAccountSyncingEnabled: false,
|
|
88
96
|
isAccountSyncingInProgress: false,
|
|
89
97
|
maxNumberOfAccountsToAdd: 0,
|
|
90
98
|
canSync: () => {
|
|
@@ -93,7 +101,7 @@ class UserStorageController extends base_controller_1.BaseController {
|
|
|
93
101
|
if (__classPrivateFieldGet(this, _UserStorageController_accounts, "f").isAccountSyncingInProgress) {
|
|
94
102
|
return false;
|
|
95
103
|
}
|
|
96
|
-
if (!__classPrivateFieldGet(this,
|
|
104
|
+
if (!__classPrivateFieldGet(this, _UserStorageController_env, "f").isAccountSyncingEnabled) {
|
|
97
105
|
return false;
|
|
98
106
|
}
|
|
99
107
|
if (!__classPrivateFieldGet(this, _UserStorageController_auth, "f").isAuthEnabled()) {
|
|
@@ -141,7 +149,10 @@ class UserStorageController extends base_controller_1.BaseController {
|
|
|
141
149
|
saveInternalAccountToUserStorage: async (internalAccount) => {
|
|
142
150
|
// Map the internal account to the user storage account schema
|
|
143
151
|
const mappedAccount = (0, user_storage_1.mapInternalAccountToUserStorageAccount)(internalAccount);
|
|
144
|
-
await this.performSetStorage(
|
|
152
|
+
await this.performSetStorage(
|
|
153
|
+
// ESLint is confused here.
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
155
|
+
`${storage_schema_1.USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`, JSON.stringify(mappedAccount));
|
|
145
156
|
},
|
|
146
157
|
saveInternalAccountsListToUserStorage: async () => {
|
|
147
158
|
const internalAccountsList = await __classPrivateFieldGet(this, _UserStorageController_accounts, "f").getInternalAccountsList();
|
|
@@ -179,8 +190,9 @@ class UserStorageController extends base_controller_1.BaseController {
|
|
|
179
190
|
});
|
|
180
191
|
_UserStorageController_nativeScryptCrypto.set(this, undefined);
|
|
181
192
|
_UserStorageController__snapSignMessageCache.set(this, {});
|
|
193
|
+
__classPrivateFieldGet(this, _UserStorageController_env, "f").isAccountSyncingEnabled = Boolean(env?.isAccountSyncingEnabled);
|
|
194
|
+
__classPrivateFieldGet(this, _UserStorageController_env, "f").isNetworkSyncingEnabled = Boolean(env?.isNetworkSyncingEnabled);
|
|
182
195
|
__classPrivateFieldSet(this, _UserStorageController_config, config, "f");
|
|
183
|
-
__classPrivateFieldGet(this, _UserStorageController_accounts, "f").isAccountSyncingEnabled = Boolean(env?.isAccountSyncingEnabled);
|
|
184
196
|
__classPrivateFieldGet(this, _UserStorageController_accounts, "f").maxNumberOfAccountsToAdd =
|
|
185
197
|
config?.accountSyncing?.maxNumberOfAccountsToAdd ?? 100;
|
|
186
198
|
this.getMetaMetricsState = getMetaMetricsState;
|
|
@@ -189,17 +201,11 @@ class UserStorageController extends base_controller_1.BaseController {
|
|
|
189
201
|
__classPrivateFieldSet(this, _UserStorageController_nativeScryptCrypto, nativeScryptCrypto, "f");
|
|
190
202
|
__classPrivateFieldGet(this, _UserStorageController_accounts, "f").setupAccountSyncingSubscriptions();
|
|
191
203
|
// Network Syncing
|
|
192
|
-
if (
|
|
204
|
+
if (__classPrivateFieldGet(this, _UserStorageController_env, "f").isNetworkSyncingEnabled) {
|
|
193
205
|
(0, controller_integration_1.startNetworkSyncing)({
|
|
194
206
|
messenger,
|
|
195
|
-
getStorageConfig:
|
|
196
|
-
|
|
197
|
-
return {
|
|
198
|
-
storageKey,
|
|
199
|
-
bearerToken,
|
|
200
|
-
nativeScryptCrypto: __classPrivateFieldGet(this, _UserStorageController_nativeScryptCrypto, "f"),
|
|
201
|
-
};
|
|
202
|
-
},
|
|
207
|
+
getStorageConfig: () => __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageOptions).call(this),
|
|
208
|
+
isMutationSyncBlocked: () => !this.state.hasNetworkSyncingSyncedAtLeastOnce,
|
|
203
209
|
});
|
|
204
210
|
}
|
|
205
211
|
}
|
|
@@ -540,8 +546,25 @@ class UserStorageController extends base_controller_1.BaseController {
|
|
|
540
546
|
throw new Error(`${controllerName} - failed to save account to user storage - ${errorMessage}`);
|
|
541
547
|
}
|
|
542
548
|
}
|
|
549
|
+
async syncNetworks() {
|
|
550
|
+
if (!__classPrivateFieldGet(this, _UserStorageController_env, "f").isNetworkSyncingEnabled) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
const profileId = await __classPrivateFieldGet(this, _UserStorageController_auth, "f").getProfileId();
|
|
554
|
+
await (0, controller_integration_1.performMainNetworkSync)({
|
|
555
|
+
messenger: this.messagingSystem,
|
|
556
|
+
getStorageConfig: () => __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageOptions).call(this),
|
|
557
|
+
maxNetworksToAdd: __classPrivateFieldGet(this, _UserStorageController_config, "f")?.networkSyncing?.maxNumberOfNetworksToAdd,
|
|
558
|
+
onNetworkAdded: (cId) => __classPrivateFieldGet(this, _UserStorageController_config, "f")?.networkSyncing?.onNetworkAdded?.(profileId, cId),
|
|
559
|
+
onNetworkUpdated: (cId) => __classPrivateFieldGet(this, _UserStorageController_config, "f")?.networkSyncing?.onNetworkUpdated?.(profileId, cId),
|
|
560
|
+
onNetworkRemoved: (cId) => __classPrivateFieldGet(this, _UserStorageController_config, "f")?.networkSyncing?.onNetworkRemoved?.(profileId, cId),
|
|
561
|
+
});
|
|
562
|
+
this.update((s) => {
|
|
563
|
+
s.hasNetworkSyncingSyncedAtLeastOnce = true;
|
|
564
|
+
});
|
|
565
|
+
}
|
|
543
566
|
}
|
|
544
|
-
_UserStorageController_auth = new WeakMap(), _UserStorageController_accounts = new WeakMap(), _UserStorageController_config = new WeakMap(), _UserStorageController_notificationServices = new WeakMap(), _UserStorageController_isUnlocked = new WeakMap(), _UserStorageController_keyringController = new WeakMap(), _UserStorageController_nativeScryptCrypto = new WeakMap(), _UserStorageController__snapSignMessageCache = new WeakMap(), _UserStorageController_instances = new WeakSet(), _UserStorageController_registerMessageHandlers = function _UserStorageController_registerMessageHandlers() {
|
|
567
|
+
_UserStorageController_env = new WeakMap(), _UserStorageController_auth = new WeakMap(), _UserStorageController_accounts = new WeakMap(), _UserStorageController_config = new WeakMap(), _UserStorageController_notificationServices = new WeakMap(), _UserStorageController_isUnlocked = new WeakMap(), _UserStorageController_keyringController = new WeakMap(), _UserStorageController_nativeScryptCrypto = new WeakMap(), _UserStorageController__snapSignMessageCache = new WeakMap(), _UserStorageController_instances = new WeakSet(), _UserStorageController_registerMessageHandlers = function _UserStorageController_registerMessageHandlers() {
|
|
545
568
|
this.messagingSystem.registerActionHandler('UserStorageController:performGetStorage', this.performGetStorage.bind(this));
|
|
546
569
|
this.messagingSystem.registerActionHandler('UserStorageController:performGetStorageAllFeatureEntries', this.performGetStorageAllFeatureEntries.bind(this));
|
|
547
570
|
this.messagingSystem.registerActionHandler('UserStorageController:performSetStorage', this.performSetStorage.bind(this));
|
|
@@ -550,6 +573,16 @@ _UserStorageController_auth = new WeakMap(), _UserStorageController_accounts = n
|
|
|
550
573
|
this.messagingSystem.registerActionHandler('UserStorageController:disableProfileSyncing', this.disableProfileSyncing.bind(this));
|
|
551
574
|
this.messagingSystem.registerActionHandler('UserStorageController:syncInternalAccountsWithUserStorage', this.syncInternalAccountsWithUserStorage.bind(this));
|
|
552
575
|
this.messagingSystem.registerActionHandler('UserStorageController:saveInternalAccountToUserStorage', this.saveInternalAccountToUserStorage.bind(this));
|
|
576
|
+
}, _UserStorageController_getStorageOptions = async function _UserStorageController_getStorageOptions() {
|
|
577
|
+
if (!this.state.isProfileSyncingEnabled) {
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
const { storageKey, bearerToken } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
581
|
+
return {
|
|
582
|
+
storageKey,
|
|
583
|
+
bearerToken,
|
|
584
|
+
nativeScryptCrypto: __classPrivateFieldGet(this, _UserStorageController_nativeScryptCrypto, "f"),
|
|
585
|
+
};
|
|
553
586
|
}, _UserStorageController_assertProfileSyncingEnabled = function _UserStorageController_assertProfileSyncingEnabled() {
|
|
554
587
|
if (!this.state.isProfileSyncingEnabled) {
|
|
555
588
|
throw new Error(`${controllerName}: Unable to call method, user is not authenticated`);
|