@metamask/profile-sync-controller 9.0.0 → 10.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 +20 -1
- package/dist/controllers/authentication/AuthenticationController.cjs +53 -90
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts +11 -23
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts +11 -23
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs +53 -90
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.cjs +10 -23
- package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.cts +42 -10
- package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.mts +42 -10
- package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.mjs +9 -22
- package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.cjs +76 -127
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +10 -4
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +10 -4
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +76 -127
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.cjs +3 -3
- package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.cts +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.mts +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.mjs +3 -3
- package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +14 -14
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +3 -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 +3 -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 +14 -14
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.cjs +27 -23
- package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.cts +16 -7
- package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.mts +16 -7
- package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.mjs +27 -23
- package/dist/controllers/user-storage/network-syncing/services.mjs.map +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 +13 -5
- 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 +13 -5
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -1
- package/dist/controllers/user-storage/types.cjs +3 -0
- package/dist/controllers/user-storage/types.cjs.map +1 -0
- package/dist/controllers/user-storage/types.d.cts +23 -0
- package/dist/controllers/user-storage/types.d.cts.map +1 -0
- package/dist/controllers/user-storage/types.d.mts +23 -0
- package/dist/controllers/user-storage/types.d.mts.map +1 -0
- package/dist/controllers/user-storage/types.mjs +2 -0
- package/dist/controllers/user-storage/types.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +7 -8
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +2 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +2 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +8 -9
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs +10 -2
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts +3 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +3 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.mjs +10 -2
- package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
- package/dist/sdk/authentication.cjs.map +1 -1
- package/dist/sdk/authentication.d.cts +1 -1
- package/dist/sdk/authentication.d.cts.map +1 -1
- package/dist/sdk/authentication.d.mts +1 -1
- package/dist/sdk/authentication.d.mts.map +1 -1
- package/dist/sdk/authentication.mjs.map +1 -1
- package/dist/sdk/mocks/auth.cjs +44 -0
- package/dist/sdk/mocks/auth.cjs.map +1 -0
- package/dist/sdk/mocks/auth.d.cts +39 -0
- package/dist/sdk/mocks/auth.d.cts.map +1 -0
- package/dist/sdk/mocks/auth.d.mts +39 -0
- package/dist/sdk/mocks/auth.d.mts.map +1 -0
- package/dist/sdk/mocks/auth.mjs +41 -0
- package/dist/sdk/mocks/auth.mjs.map +1 -0
- package/dist/sdk/mocks/userstorage.cjs +43 -0
- package/dist/sdk/mocks/userstorage.cjs.map +1 -0
- package/dist/sdk/mocks/userstorage.d.cts +10 -0
- package/dist/sdk/mocks/userstorage.d.cts.map +1 -0
- package/dist/sdk/mocks/userstorage.d.mts +10 -0
- package/dist/sdk/mocks/userstorage.d.mts.map +1 -0
- package/dist/sdk/mocks/userstorage.mjs +15 -0
- package/dist/sdk/mocks/userstorage.mjs.map +1 -0
- package/dist/sdk/user-storage.cjs +39 -43
- package/dist/sdk/user-storage.cjs.map +1 -1
- package/dist/sdk/user-storage.d.cts +13 -8
- package/dist/sdk/user-storage.d.cts.map +1 -1
- package/dist/sdk/user-storage.d.mts +13 -8
- package/dist/sdk/user-storage.d.mts.map +1 -1
- package/dist/sdk/user-storage.mjs +39 -43
- package/dist/sdk/user-storage.mjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs +12 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts +6 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +6 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs +10 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
- package/dist/shared/types/services.cjs +3 -0
- package/dist/shared/types/services.cjs.map +1 -0
- package/dist/shared/types/services.d.cts +10 -0
- package/dist/shared/types/services.d.cts.map +1 -0
- package/dist/shared/types/services.d.mts +10 -0
- package/dist/shared/types/services.d.mts.map +1 -0
- package/dist/shared/types/services.mjs +2 -0
- package/dist/shared/types/services.mjs.map +1 -0
- package/package.json +6 -6
- package/dist/controllers/authentication/services.cjs +0 -132
- package/dist/controllers/authentication/services.cjs.map +0 -1
- package/dist/controllers/authentication/services.d.cts +0 -72
- package/dist/controllers/authentication/services.d.cts.map +0 -1
- package/dist/controllers/authentication/services.d.mts +0 -72
- package/dist/controllers/authentication/services.d.mts.map +0 -1
- package/dist/controllers/authentication/services.mjs +0 -129
- package/dist/controllers/authentication/services.mjs.map +0 -1
- package/dist/controllers/user-storage/services.cjs +0 -306
- package/dist/controllers/user-storage/services.cjs.map +0 -1
- package/dist/controllers/user-storage/services.d.cts +0 -85
- package/dist/controllers/user-storage/services.d.cts.map +0 -1
- package/dist/controllers/user-storage/services.d.mts +0 -85
- package/dist/controllers/user-storage/services.d.mts.map +0 -1
- package/dist/controllers/user-storage/services.mjs +0 -276
- package/dist/controllers/user-storage/services.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [10.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add primary SRP switching support for `AuthenticationController` and `UserStorageController` ([#5478](https://github.com/MetaMask/core/pull/5478))
|
|
15
|
+
|
|
16
|
+
## [10.0.0]
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- **BREAKING:** Bump `@metamask/keyring-controller` peer dependency to `^21.0.0` ([#5439](https://github.com/MetaMask/core/pull/5439))
|
|
21
|
+
- **BREAKING:** Bump `@metamask/accounts-controller` peer dependency to `^26.0.0` ([#5439](https://github.com/MetaMask/core/pull/5439))
|
|
22
|
+
- **BREAKING** `UserStorageController` and `AuthenticationController` now use the SDK under the hood ([#5413](https://github.com/MetaMask/core/pull/5413))
|
|
23
|
+
- **BREAKING** `AuthenticationController` state entry `sessionData` has changed shape to fully reflect the `LoginResponse` SDK type.
|
|
24
|
+
- **BREAKING** `UserStorageController` cannot use the `AuthenticationController:performSignOut` action anymore.
|
|
25
|
+
- **BREAKING:** Bump `@metamask/keyring-internal-api` from `^5.0.0` to `^6.0.0` ([#5347](https://github.com/MetaMask/core/pull/5347))
|
|
26
|
+
|
|
10
27
|
## [9.0.0]
|
|
11
28
|
|
|
12
29
|
### Changed
|
|
@@ -511,7 +528,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
511
528
|
|
|
512
529
|
- Initial release
|
|
513
530
|
|
|
514
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@
|
|
531
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@10.1.0...HEAD
|
|
532
|
+
[10.1.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@10.0.0...@metamask/profile-sync-controller@10.1.0
|
|
533
|
+
[10.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@9.0.0...@metamask/profile-sync-controller@10.0.0
|
|
515
534
|
[9.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@8.1.1...@metamask/profile-sync-controller@9.0.0
|
|
516
535
|
[8.1.1]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@8.1.0...@metamask/profile-sync-controller@8.1.1
|
|
517
536
|
[8.1.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@8.0.0...@metamask/profile-sync-controller@8.1.0
|
|
@@ -10,13 +10,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _AuthenticationController_instances, _AuthenticationController_metametrics, _AuthenticationController_isUnlocked, _AuthenticationController_keyringController, _AuthenticationController_registerMessageHandlers,
|
|
13
|
+
var _AuthenticationController_instances, _AuthenticationController_metametrics, _AuthenticationController_auth, _AuthenticationController_isUnlocked, _AuthenticationController_keyringController, _AuthenticationController_registerMessageHandlers, _AuthenticationController_getLoginResponseFromState, _AuthenticationController_setLoginResponseToState, _AuthenticationController_assertIsUnlocked, _AuthenticationController_snapGetPublicKey, _AuthenticationController__snapSignMessageCache, _AuthenticationController_snapSignMessage;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.defaultState = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
17
17
|
const auth_snap_requests_1 = require("./auth-snap-requests.cjs");
|
|
18
|
-
const
|
|
19
|
-
const THIRTY_MIN_MS = 1000 * 60 * 30;
|
|
18
|
+
const sdk_1 = require("../../sdk/index.cjs");
|
|
20
19
|
const controllerName = 'AuthenticationController';
|
|
21
20
|
exports.defaultState = {
|
|
22
21
|
isSignedIn: false,
|
|
@@ -45,6 +44,7 @@ class AuthenticationController extends base_controller_1.BaseController {
|
|
|
45
44
|
});
|
|
46
45
|
_AuthenticationController_instances.add(this);
|
|
47
46
|
_AuthenticationController_metametrics.set(this, void 0);
|
|
47
|
+
_AuthenticationController_auth.set(this, void 0);
|
|
48
48
|
_AuthenticationController_isUnlocked.set(this, false);
|
|
49
49
|
_AuthenticationController_keyringController.set(this, {
|
|
50
50
|
setupLockedStateSubscriptions: () => {
|
|
@@ -58,18 +58,32 @@ class AuthenticationController extends base_controller_1.BaseController {
|
|
|
58
58
|
});
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
|
-
_AuthenticationController__snapPublicKeyCache.set(this, void 0);
|
|
62
61
|
_AuthenticationController__snapSignMessageCache.set(this, {});
|
|
63
62
|
if (!metametrics) {
|
|
64
63
|
throw new Error('`metametrics` field is required');
|
|
65
64
|
}
|
|
66
65
|
__classPrivateFieldSet(this, _AuthenticationController_metametrics, metametrics, "f");
|
|
66
|
+
__classPrivateFieldSet(this, _AuthenticationController_auth, new sdk_1.JwtBearerAuth({
|
|
67
|
+
env: sdk_1.Env.PRD,
|
|
68
|
+
platform: metametrics.agent,
|
|
69
|
+
type: sdk_1.AuthType.SRP,
|
|
70
|
+
}, {
|
|
71
|
+
storage: {
|
|
72
|
+
getLoginResponse: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getLoginResponseFromState).bind(this),
|
|
73
|
+
setLoginResponse: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_setLoginResponseToState).bind(this),
|
|
74
|
+
},
|
|
75
|
+
signing: {
|
|
76
|
+
getIdentifier: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_snapGetPublicKey).bind(this),
|
|
77
|
+
signMessage: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_snapSignMessage).bind(this),
|
|
78
|
+
},
|
|
79
|
+
metametrics: __classPrivateFieldGet(this, _AuthenticationController_metametrics, "f"),
|
|
80
|
+
}), "f");
|
|
67
81
|
__classPrivateFieldGet(this, _AuthenticationController_keyringController, "f").setupLockedStateSubscriptions();
|
|
68
82
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_registerMessageHandlers).call(this);
|
|
69
83
|
}
|
|
70
84
|
async performSignIn() {
|
|
71
|
-
|
|
72
|
-
return
|
|
85
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'performSignIn');
|
|
86
|
+
return await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getAccessToken();
|
|
73
87
|
}
|
|
74
88
|
performSignOut() {
|
|
75
89
|
this.update((state) => {
|
|
@@ -77,101 +91,57 @@ class AuthenticationController extends base_controller_1.BaseController {
|
|
|
77
91
|
state.sessionData = undefined;
|
|
78
92
|
});
|
|
79
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Will return a bearer token.
|
|
96
|
+
* Logs a user in if a user is not logged in.
|
|
97
|
+
*
|
|
98
|
+
* @returns profile for the session.
|
|
99
|
+
*/
|
|
80
100
|
async getBearerToken() {
|
|
81
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
82
|
-
|
|
83
|
-
return this.state.sessionData.accessToken;
|
|
84
|
-
}
|
|
85
|
-
const { accessToken } = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_performAuthenticationFlow).call(this);
|
|
86
|
-
return accessToken;
|
|
101
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'getBearerToken');
|
|
102
|
+
return await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getAccessToken();
|
|
87
103
|
}
|
|
88
104
|
/**
|
|
89
105
|
* Will return a session profile.
|
|
90
|
-
*
|
|
106
|
+
* Logs a user in if a user is not logged in.
|
|
91
107
|
*
|
|
92
108
|
* @returns profile for the session.
|
|
93
109
|
*/
|
|
94
110
|
async getSessionProfile() {
|
|
95
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
96
|
-
|
|
97
|
-
return this.state.sessionData.profile;
|
|
98
|
-
}
|
|
99
|
-
const { profile } = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_performAuthenticationFlow).call(this);
|
|
100
|
-
return profile;
|
|
111
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'getSessionProfile');
|
|
112
|
+
return await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getUserProfile();
|
|
101
113
|
}
|
|
102
114
|
isSignedIn() {
|
|
103
115
|
return this.state.isSignedIn;
|
|
104
116
|
}
|
|
105
117
|
}
|
|
106
|
-
_AuthenticationController_metametrics = new WeakMap(),
|
|
118
|
+
_AuthenticationController_metametrics = new WeakMap(), _AuthenticationController_auth = new WeakMap(), _AuthenticationController_isUnlocked = new WeakMap(), _AuthenticationController_keyringController = new WeakMap(), _AuthenticationController__snapSignMessageCache = new WeakMap(), _AuthenticationController_instances = new WeakSet(), _AuthenticationController_registerMessageHandlers = function _AuthenticationController_registerMessageHandlers() {
|
|
107
119
|
this.messagingSystem.registerActionHandler('AuthenticationController:getBearerToken', this.getBearerToken.bind(this));
|
|
108
120
|
this.messagingSystem.registerActionHandler('AuthenticationController:getSessionProfile', this.getSessionProfile.bind(this));
|
|
109
121
|
this.messagingSystem.registerActionHandler('AuthenticationController:isSignedIn', this.isSignedIn.bind(this));
|
|
110
122
|
this.messagingSystem.registerActionHandler('AuthenticationController:performSignIn', this.performSignIn.bind(this));
|
|
111
123
|
this.messagingSystem.registerActionHandler('AuthenticationController:performSignOut', this.performSignOut.bind(this));
|
|
112
|
-
},
|
|
113
|
-
if (!this.state.
|
|
114
|
-
|
|
124
|
+
}, _AuthenticationController_getLoginResponseFromState = async function _AuthenticationController_getLoginResponseFromState() {
|
|
125
|
+
if (!this.state.sessionData) {
|
|
126
|
+
return null;
|
|
115
127
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const loginResponse = await (0, services_1.login)(rawMessage, signature, {
|
|
128
|
-
metametricsId: await __classPrivateFieldGet(this, _AuthenticationController_metametrics, "f").getMetaMetricsId(),
|
|
129
|
-
agent: __classPrivateFieldGet(this, _AuthenticationController_metametrics, "f").agent,
|
|
130
|
-
});
|
|
131
|
-
if (!loginResponse?.token) {
|
|
132
|
-
throw new Error(`Unable to login`);
|
|
133
|
-
}
|
|
134
|
-
const profile = {
|
|
135
|
-
identifierId: loginResponse.profile.identifier_id,
|
|
136
|
-
profileId: loginResponse.profile.profile_id,
|
|
137
|
-
};
|
|
138
|
-
// 3. Trade for Access Token
|
|
139
|
-
const accessToken = await (0, services_1.getAccessToken)(loginResponse.token, __classPrivateFieldGet(this, _AuthenticationController_metametrics, "f").agent);
|
|
140
|
-
if (!accessToken) {
|
|
141
|
-
throw new Error(`Unable to get Access Token`);
|
|
142
|
-
}
|
|
143
|
-
// Update Internal State
|
|
144
|
-
this.update((state) => {
|
|
145
|
-
state.isSignedIn = true;
|
|
146
|
-
const expiresIn = new Date();
|
|
147
|
-
expiresIn.setTime(expiresIn.getTime() + THIRTY_MIN_MS);
|
|
148
|
-
state.sessionData = {
|
|
149
|
-
profile,
|
|
150
|
-
accessToken,
|
|
151
|
-
expiresIn: expiresIn.toString(),
|
|
152
|
-
};
|
|
153
|
-
});
|
|
154
|
-
return {
|
|
155
|
-
profile,
|
|
156
|
-
accessToken,
|
|
128
|
+
return this.state.sessionData;
|
|
129
|
+
}, _AuthenticationController_setLoginResponseToState = async function _AuthenticationController_setLoginResponseToState(loginResponse) {
|
|
130
|
+
const metaMetricsId = await __classPrivateFieldGet(this, _AuthenticationController_metametrics, "f").getMetaMetricsId();
|
|
131
|
+
this.update((state) => {
|
|
132
|
+
state.isSignedIn = true;
|
|
133
|
+
state.sessionData = {
|
|
134
|
+
...loginResponse,
|
|
135
|
+
profile: {
|
|
136
|
+
...loginResponse.profile,
|
|
137
|
+
metaMetricsId,
|
|
138
|
+
},
|
|
157
139
|
};
|
|
140
|
+
});
|
|
141
|
+
}, _AuthenticationController_assertIsUnlocked = function _AuthenticationController_assertIsUnlocked(methodName) {
|
|
142
|
+
if (!__classPrivateFieldGet(this, _AuthenticationController_isUnlocked, "f")) {
|
|
143
|
+
throw new Error(`${methodName} - unable to proceed, wallet is locked`);
|
|
158
144
|
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
console.error('Failed to authenticate', e);
|
|
161
|
-
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? '');
|
|
162
|
-
throw new Error(`${controllerName}: Failed to authenticate - ${errorMessage}`);
|
|
163
|
-
}
|
|
164
|
-
}, _AuthenticationController_hasValidSession = function _AuthenticationController_hasValidSession(sessionData) {
|
|
165
|
-
if (!sessionData) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
const prevDate = Date.parse(sessionData.expiresIn);
|
|
169
|
-
if (isNaN(prevDate)) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
const currentDate = new Date();
|
|
173
|
-
const diffMs = Math.abs(currentDate.getTime() - prevDate);
|
|
174
|
-
return THIRTY_MIN_MS > diffMs;
|
|
175
145
|
}, _AuthenticationController_snapGetPublicKey =
|
|
176
146
|
/**
|
|
177
147
|
* Returns the auth snap public key.
|
|
@@ -179,14 +149,8 @@ _AuthenticationController_metametrics = new WeakMap(), _AuthenticationController
|
|
|
179
149
|
* @returns The snap public key.
|
|
180
150
|
*/
|
|
181
151
|
async function _AuthenticationController_snapGetPublicKey() {
|
|
182
|
-
|
|
183
|
-
return __classPrivateFieldGet(this, _AuthenticationController__snapPublicKeyCache, "f");
|
|
184
|
-
}
|
|
185
|
-
if (!__classPrivateFieldGet(this, _AuthenticationController_isUnlocked, "f")) {
|
|
186
|
-
throw new Error('#snapGetPublicKey - unable to call snap, wallet is locked');
|
|
187
|
-
}
|
|
152
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, '#snapGetPublicKey');
|
|
188
153
|
const result = (await this.messagingSystem.call('SnapController:handleRequest', (0, auth_snap_requests_1.createSnapPublicKeyRequest)()));
|
|
189
|
-
__classPrivateFieldSet(this, _AuthenticationController__snapPublicKeyCache, result, "f");
|
|
190
154
|
return result;
|
|
191
155
|
}, _AuthenticationController_snapSignMessage =
|
|
192
156
|
/**
|
|
@@ -196,12 +160,11 @@ async function _AuthenticationController_snapGetPublicKey() {
|
|
|
196
160
|
* @returns A Signature created by the snap.
|
|
197
161
|
*/
|
|
198
162
|
async function _AuthenticationController_snapSignMessage(message) {
|
|
163
|
+
(0, sdk_1.assertMessageStartsWithMetamask)(message);
|
|
199
164
|
if (__classPrivateFieldGet(this, _AuthenticationController__snapSignMessageCache, "f")[message]) {
|
|
200
165
|
return __classPrivateFieldGet(this, _AuthenticationController__snapSignMessageCache, "f")[message];
|
|
201
166
|
}
|
|
202
|
-
|
|
203
|
-
throw new Error('#snapSignMessage - unable to call snap, wallet is locked');
|
|
204
|
-
}
|
|
167
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, '#snapSignMessage');
|
|
205
168
|
const result = (await this.messagingSystem.call('SnapController:handleRequest', (0, auth_snap_requests_1.createSnapSignMessageRequest)(message)));
|
|
206
169
|
__classPrivateFieldGet(this, _AuthenticationController__snapSignMessageCache, "f")[message] = result;
|
|
207
170
|
return result;
|
|
@@ -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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3D,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 RestrictedMessenger,\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 = RestrictedMessenger<\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 readonly #metametrics: MetaMetricsAuth;\n\n #isUnlocked = false;\n\n readonly #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
|
+
{"version":3,"file":"AuthenticationController.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,+DAA2D;AAQ3D,iEAG8B;AAE9B,6CAKmB;AAGnB,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAOrC,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,M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AACH,CAAC;AAyCD;;;;GAIG;AACH,KAAK;IACH,uBAAA,IAAI,uFAAkB,MAAtB,IAAI,EAAmB,mBAAmB,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,IAAA,+CAA0B,GAAE,CAC7B,CAAW,CAAC;IAEb,OAAO,MAAM,CAAC;AAChB,CAAC;AAID;;;;;GAKG;AACH,KAAK,oDAAkB,OAAe;IACpC,IAAA,qCAA+B,EAAC,OAAO,CAAC,CAAC;IAEzC,IAAI,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAA,IAAI,uDAAuB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,uBAAA,IAAI,uFAAkB,MAAtB,IAAI,EAAmB,kBAAkB,CAAC,CAAC;IAE3C,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;kBAxNkB,wBAAwB","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\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 type { LoginResponse, SRPInterface, UserProfile } from '../../sdk';\nimport {\n assertMessageStartsWithMetamask,\n AuthType,\n Env,\n JwtBearerAuth,\n} from '../../sdk';\nimport type { MetaMetricsAuth } from '../../shared/types/services';\n\nconst controllerName = 'AuthenticationController';\n\n// State\nexport type AuthenticationControllerState = {\n isSignedIn: boolean;\n sessionData?: LoginResponse;\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 = RestrictedMessenger<\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 readonly #metametrics: MetaMetricsAuth;\n\n readonly #auth: SRPInterface;\n\n #isUnlocked = false;\n\n readonly #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.#auth = new JwtBearerAuth(\n {\n env: Env.PRD,\n platform: metametrics.agent,\n type: AuthType.SRP,\n },\n {\n storage: {\n getLoginResponse: this.#getLoginResponseFromState.bind(this),\n setLoginResponse: this.#setLoginResponseToState.bind(this),\n },\n signing: {\n getIdentifier: this.#snapGetPublicKey.bind(this),\n signMessage: this.#snapSignMessage.bind(this),\n },\n metametrics: this.#metametrics,\n },\n );\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 async #getLoginResponseFromState(): Promise<LoginResponse | null> {\n if (!this.state.sessionData) {\n return null;\n }\n\n return this.state.sessionData;\n }\n\n async #setLoginResponseToState(loginResponse: LoginResponse) {\n const metaMetricsId = await this.#metametrics.getMetaMetricsId();\n this.update((state) => {\n state.isSignedIn = true;\n state.sessionData = {\n ...loginResponse,\n profile: {\n ...loginResponse.profile,\n metaMetricsId,\n },\n };\n });\n }\n\n #assertIsUnlocked(methodName: string): void {\n if (!this.#isUnlocked) {\n throw new Error(`${methodName} - unable to proceed, wallet is locked`);\n }\n }\n\n public async performSignIn(): Promise<string> {\n this.#assertIsUnlocked('performSignIn');\n return await this.#auth.getAccessToken();\n }\n\n public performSignOut(): void {\n this.update((state) => {\n state.isSignedIn = false;\n state.sessionData = undefined;\n });\n }\n\n /**\n * Will return a bearer token.\n * Logs a user in if a user is not logged in.\n *\n * @returns profile for the session.\n */\n\n public async getBearerToken(): Promise<string> {\n this.#assertIsUnlocked('getBearerToken');\n return await this.#auth.getAccessToken();\n }\n\n /**\n * Will return a session profile.\n * Logs a user in if a user is not logged in.\n *\n * @returns profile for the session.\n */\n public async getSessionProfile(): Promise<UserProfile> {\n this.#assertIsUnlocked('getSessionProfile');\n return await this.#auth.getUserProfile();\n }\n\n public isSignedIn(): boolean {\n return this.state.isSignedIn;\n }\n\n /**\n * Returns the auth snap public key.\n *\n * @returns The snap public key.\n */\n async #snapGetPublicKey(): Promise<string> {\n this.#assertIsUnlocked('#snapGetPublicKey');\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapPublicKeyRequest(),\n )) as string;\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: string): Promise<string> {\n assertMessageStartsWithMetamask(message);\n\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n this.#assertIsUnlocked('#snapSignMessage');\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"]}
|
|
@@ -2,30 +2,12 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMe
|
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
|
|
4
4
|
import type { HandleSnapRequest } from "@metamask/snaps-controllers";
|
|
5
|
+
import type { LoginResponse, UserProfile } from "../../sdk/index.cjs";
|
|
6
|
+
import type { MetaMetricsAuth } from "../../shared/types/services.cjs";
|
|
5
7
|
declare const controllerName = "AuthenticationController";
|
|
6
|
-
type SessionProfile = {
|
|
7
|
-
identifierId: string;
|
|
8
|
-
profileId: string;
|
|
9
|
-
};
|
|
10
|
-
type SessionData = {
|
|
11
|
-
/** profile - anonymous profile data for the given logged in user */
|
|
12
|
-
profile: SessionProfile;
|
|
13
|
-
/** accessToken - used to make requests authorized endpoints */
|
|
14
|
-
accessToken: string;
|
|
15
|
-
/** expiresIn - string date to determine if new access token is required */
|
|
16
|
-
expiresIn: string;
|
|
17
|
-
};
|
|
18
|
-
type MetaMetricsAuth = {
|
|
19
|
-
getMetaMetricsId: () => string | Promise<string>;
|
|
20
|
-
agent: 'extension' | 'mobile';
|
|
21
|
-
};
|
|
22
8
|
export type AuthenticationControllerState = {
|
|
23
|
-
/**
|
|
24
|
-
* Global isSignedIn state.
|
|
25
|
-
* Can be used to determine if "Profile Syncing" is enabled.
|
|
26
|
-
*/
|
|
27
9
|
isSignedIn: boolean;
|
|
28
|
-
sessionData?:
|
|
10
|
+
sessionData?: LoginResponse;
|
|
29
11
|
};
|
|
30
12
|
export declare const defaultState: AuthenticationControllerState;
|
|
31
13
|
type CreateActionsObj<Controller extends keyof AuthenticationController> = {
|
|
@@ -64,14 +46,20 @@ export default class AuthenticationController extends BaseController<typeof cont
|
|
|
64
46
|
});
|
|
65
47
|
performSignIn(): Promise<string>;
|
|
66
48
|
performSignOut(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Will return a bearer token.
|
|
51
|
+
* Logs a user in if a user is not logged in.
|
|
52
|
+
*
|
|
53
|
+
* @returns profile for the session.
|
|
54
|
+
*/
|
|
67
55
|
getBearerToken(): Promise<string>;
|
|
68
56
|
/**
|
|
69
57
|
* Will return a session profile.
|
|
70
|
-
*
|
|
58
|
+
* Logs a user in if a user is not logged in.
|
|
71
59
|
*
|
|
72
60
|
* @returns profile for the session.
|
|
73
61
|
*/
|
|
74
|
-
getSessionProfile(): Promise<
|
|
62
|
+
getSessionProfile(): Promise<UserProfile>;
|
|
75
63
|
isSignedIn(): boolean;
|
|
76
64
|
}
|
|
77
65
|
export {};
|
|
@@ -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,mBAAmB,EAEpB,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;
|
|
1
|
+
{"version":3,"file":"AuthenticationController.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAk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M,MAAM,kCAAkC,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAE1E,MAAM,MAAM,wCAAwC,GAClD,0BAA0B,CACxB,OAAO,cAAc,EACrB,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,mBAAmB,CACjE,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;;gBAwBa,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;IAgGY,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAKtC,cAAc,IAAI,IAAI;IAO7B;;;;;OAKG;IAEU,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAK9C;;;;;OAKG;IACU,iBAAiB,IAAI,OAAO,CAAC,WAAW,CAAC;IAK/C,UAAU,IAAI,OAAO;CA8C7B"}
|
|
@@ -2,30 +2,12 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMe
|
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from "@metamask/keyring-controller";
|
|
4
4
|
import type { HandleSnapRequest } from "@metamask/snaps-controllers";
|
|
5
|
+
import type { LoginResponse, UserProfile } from "../../sdk/index.mjs";
|
|
6
|
+
import type { MetaMetricsAuth } from "../../shared/types/services.mjs";
|
|
5
7
|
declare const controllerName = "AuthenticationController";
|
|
6
|
-
type SessionProfile = {
|
|
7
|
-
identifierId: string;
|
|
8
|
-
profileId: string;
|
|
9
|
-
};
|
|
10
|
-
type SessionData = {
|
|
11
|
-
/** profile - anonymous profile data for the given logged in user */
|
|
12
|
-
profile: SessionProfile;
|
|
13
|
-
/** accessToken - used to make requests authorized endpoints */
|
|
14
|
-
accessToken: string;
|
|
15
|
-
/** expiresIn - string date to determine if new access token is required */
|
|
16
|
-
expiresIn: string;
|
|
17
|
-
};
|
|
18
|
-
type MetaMetricsAuth = {
|
|
19
|
-
getMetaMetricsId: () => string | Promise<string>;
|
|
20
|
-
agent: 'extension' | 'mobile';
|
|
21
|
-
};
|
|
22
8
|
export type AuthenticationControllerState = {
|
|
23
|
-
/**
|
|
24
|
-
* Global isSignedIn state.
|
|
25
|
-
* Can be used to determine if "Profile Syncing" is enabled.
|
|
26
|
-
*/
|
|
27
9
|
isSignedIn: boolean;
|
|
28
|
-
sessionData?:
|
|
10
|
+
sessionData?: LoginResponse;
|
|
29
11
|
};
|
|
30
12
|
export declare const defaultState: AuthenticationControllerState;
|
|
31
13
|
type CreateActionsObj<Controller extends keyof AuthenticationController> = {
|
|
@@ -64,14 +46,20 @@ export default class AuthenticationController extends BaseController<typeof cont
|
|
|
64
46
|
});
|
|
65
47
|
performSignIn(): Promise<string>;
|
|
66
48
|
performSignOut(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Will return a bearer token.
|
|
51
|
+
* Logs a user in if a user is not logged in.
|
|
52
|
+
*
|
|
53
|
+
* @returns profile for the session.
|
|
54
|
+
*/
|
|
67
55
|
getBearerToken(): Promise<string>;
|
|
68
56
|
/**
|
|
69
57
|
* Will return a session profile.
|
|
70
|
-
*
|
|
58
|
+
* Logs a user in if a user is not logged in.
|
|
71
59
|
*
|
|
72
60
|
* @returns profile for the session.
|
|
73
61
|
*/
|
|
74
|
-
getSessionProfile(): Promise<
|
|
62
|
+
getSessionProfile(): Promise<UserProfile>;
|
|
75
63
|
isSignedIn(): boolean;
|
|
76
64
|
}
|
|
77
65
|
export {};
|
|
@@ -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,mBAAmB,EAEpB,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;
|
|
1
|
+
{"version":3,"file":"AuthenticationController.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,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;AAMrE,OAAO,KAAK,EAAE,aAAa,EAAgB,WAAW,EAAE,4BAAkB;AAO1E,OAAO,KAAK,EAAE,eAAe,EAAE,wCAAoC;AAEnE,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,aAAa,CAAC;CAC7B,CAAC;AACF,eAAO,MAAM,YAAY,EAAE,6BAE1B,CAAC;AAaF,KAAK,gBAAgB,CAAC,UAAU,SAAS,MAAM,wBAA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