@metamask-previews/profile-sync-controller 8.1.1-preview-e951f896 → 9.0.0-preview-047d5b0a
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 +6 -1
- package/dist/controllers/authentication/AuthenticationController.cjs +86 -55
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts +23 -11
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts +23 -11
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs +86 -55
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.cjs +23 -10
- package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.cts +10 -42
- package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.mts +10 -42
- package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.mjs +22 -9
- package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -1
- package/dist/controllers/authentication/services.cjs +132 -0
- package/dist/controllers/authentication/services.cjs.map +1 -0
- package/dist/controllers/authentication/services.d.cts +72 -0
- package/dist/controllers/authentication/services.d.cts.map +1 -0
- package/dist/controllers/authentication/services.d.mts +72 -0
- package/dist/controllers/authentication/services.d.mts.map +1 -0
- package/dist/controllers/authentication/services.mjs +129 -0
- package/dist/controllers/authentication/services.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.cjs +127 -71
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +4 -5
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +4 -5
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +127 -71
- 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 +0 -1
- 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 +0 -1
- 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 +23 -27
- package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.cts +7 -16
- package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.mts +7 -16
- package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.mjs +23 -27
- 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 +5 -13
- 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 +5 -13
- 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/services.cjs +306 -0
- package/dist/controllers/user-storage/services.cjs.map +1 -0
- package/dist/controllers/user-storage/services.d.cts +85 -0
- package/dist/controllers/user-storage/services.d.cts.map +1 -0
- package/dist/controllers/user-storage/services.d.mts +85 -0
- package/dist/controllers/user-storage/services.d.mts.map +1 -0
- package/dist/controllers/user-storage/services.mjs +276 -0
- package/dist/controllers/user-storage/services.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +8 -7
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +0 -2
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +0 -2
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +9 -8
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs +2 -10
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts +1 -3
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +1 -3
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.mjs +2 -10
- 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/user-storage.cjs +39 -34
- package/dist/sdk/user-storage.cjs.map +1 -1
- package/dist/sdk/user-storage.d.cts +6 -11
- package/dist/sdk/user-storage.d.cts.map +1 -1
- package/dist/sdk/user-storage.d.mts +6 -11
- package/dist/sdk/user-storage.d.mts.map +1 -1
- package/dist/sdk/user-storage.mjs +39 -34
- package/dist/sdk/user-storage.mjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs +1 -12
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts +0 -6
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +0 -6
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs +0 -10
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/controllers/user-storage/types.cjs +0 -3
- package/dist/controllers/user-storage/types.cjs.map +0 -1
- package/dist/controllers/user-storage/types.d.cts +0 -23
- package/dist/controllers/user-storage/types.d.cts.map +0 -1
- package/dist/controllers/user-storage/types.d.mts +0 -23
- package/dist/controllers/user-storage/types.d.mts.map +0 -1
- package/dist/controllers/user-storage/types.mjs +0 -2
- package/dist/controllers/user-storage/types.mjs.map +0 -1
- package/dist/sdk/mocks/auth.cjs +0 -44
- package/dist/sdk/mocks/auth.cjs.map +0 -1
- package/dist/sdk/mocks/auth.d.cts +0 -39
- package/dist/sdk/mocks/auth.d.cts.map +0 -1
- package/dist/sdk/mocks/auth.d.mts +0 -39
- package/dist/sdk/mocks/auth.d.mts.map +0 -1
- package/dist/sdk/mocks/auth.mjs +0 -41
- package/dist/sdk/mocks/auth.mjs.map +0 -1
- package/dist/sdk/mocks/userstorage.cjs +0 -43
- package/dist/sdk/mocks/userstorage.cjs.map +0 -1
- package/dist/sdk/mocks/userstorage.d.cts +0 -10
- package/dist/sdk/mocks/userstorage.d.cts.map +0 -1
- package/dist/sdk/mocks/userstorage.d.mts +0 -10
- package/dist/sdk/mocks/userstorage.d.mts.map +0 -1
- package/dist/sdk/mocks/userstorage.mjs +0 -15
- package/dist/sdk/mocks/userstorage.mjs.map +0 -1
- package/dist/shared/types/services.cjs +0 -3
- package/dist/shared/types/services.cjs.map +0 -1
- package/dist/shared/types/services.d.cts +0 -10
- package/dist/shared/types/services.d.cts.map +0 -1
- package/dist/shared/types/services.d.mts +0 -10
- package/dist/shared/types/services.d.mts.map +0 -1
- package/dist/shared/types/services.mjs +0 -2
- package/dist/shared/types/services.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,8 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [9.0.0]
|
|
11
|
+
|
|
10
12
|
### Changed
|
|
11
13
|
|
|
14
|
+
- **BREAKING:** Bump `@metamask/keyring-controller` peer dependency to `^20.0.0` ([#5426](https://github.com/MetaMask/core/pull/5426))
|
|
15
|
+
- **BREAKING:** Bump `@metamask/accounts-controller` peer dependency to `^25.0.0` ([#5426](https://github.com/MetaMask/core/pull/5426))
|
|
12
16
|
- Bump `@metamask/keyring-internal-api` from `^4.0.3` to `^5.0.0` ([#5405](https://github.com/MetaMask/core/pull/5405))
|
|
13
17
|
|
|
14
18
|
## [8.1.1]
|
|
@@ -507,7 +511,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
507
511
|
|
|
508
512
|
- Initial release
|
|
509
513
|
|
|
510
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@
|
|
514
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@9.0.0...HEAD
|
|
515
|
+
[9.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@8.1.1...@metamask/profile-sync-controller@9.0.0
|
|
511
516
|
[8.1.1]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@8.1.0...@metamask/profile-sync-controller@8.1.1
|
|
512
517
|
[8.1.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@8.0.0...@metamask/profile-sync-controller@8.1.0
|
|
513
518
|
[8.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@7.0.1...@metamask/profile-sync-controller@8.0.0
|
|
@@ -10,12 +10,13 @@ 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,
|
|
13
|
+
var _AuthenticationController_instances, _AuthenticationController_metametrics, _AuthenticationController_isUnlocked, _AuthenticationController_keyringController, _AuthenticationController_registerMessageHandlers, _AuthenticationController_assertLoggedIn, _AuthenticationController_performAuthenticationFlow, _AuthenticationController_hasValidSession, _AuthenticationController__snapPublicKeyCache, _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
|
|
18
|
+
const services_1 = require("./services.cjs");
|
|
19
|
+
const THIRTY_MIN_MS = 1000 * 60 * 30;
|
|
19
20
|
const controllerName = 'AuthenticationController';
|
|
20
21
|
exports.defaultState = {
|
|
21
22
|
isSignedIn: false,
|
|
@@ -44,7 +45,6 @@ class AuthenticationController extends base_controller_1.BaseController {
|
|
|
44
45
|
});
|
|
45
46
|
_AuthenticationController_instances.add(this);
|
|
46
47
|
_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: () => {
|
|
@@ -64,86 +64,114 @@ class AuthenticationController extends base_controller_1.BaseController {
|
|
|
64
64
|
throw new Error('`metametrics` field is required');
|
|
65
65
|
}
|
|
66
66
|
__classPrivateFieldSet(this, _AuthenticationController_metametrics, metametrics, "f");
|
|
67
|
-
__classPrivateFieldSet(this, _AuthenticationController_auth, new sdk_1.JwtBearerAuth({
|
|
68
|
-
env: sdk_1.Env.PRD,
|
|
69
|
-
platform: metametrics.agent,
|
|
70
|
-
type: sdk_1.AuthType.SRP,
|
|
71
|
-
}, {
|
|
72
|
-
storage: {
|
|
73
|
-
getLoginResponse: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getLoginResponseFromState).bind(this),
|
|
74
|
-
setLoginResponse: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_setLoginResponseToState).bind(this),
|
|
75
|
-
},
|
|
76
|
-
signing: {
|
|
77
|
-
getIdentifier: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_snapGetPublicKey).bind(this),
|
|
78
|
-
signMessage: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_snapSignMessage).bind(this),
|
|
79
|
-
},
|
|
80
|
-
metametrics: __classPrivateFieldGet(this, _AuthenticationController_metametrics, "f"),
|
|
81
|
-
}), "f");
|
|
82
67
|
__classPrivateFieldGet(this, _AuthenticationController_keyringController, "f").setupLockedStateSubscriptions();
|
|
83
68
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_registerMessageHandlers).call(this);
|
|
84
69
|
}
|
|
85
70
|
async performSignIn() {
|
|
86
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
87
|
-
return
|
|
71
|
+
const { accessToken } = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_performAuthenticationFlow).call(this);
|
|
72
|
+
return accessToken;
|
|
88
73
|
}
|
|
89
74
|
performSignOut() {
|
|
90
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'performSignOut');
|
|
91
75
|
this.update((state) => {
|
|
92
76
|
state.isSignedIn = false;
|
|
93
77
|
state.sessionData = undefined;
|
|
94
78
|
});
|
|
95
79
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Will return a bearer token.
|
|
98
|
-
* Logs a user in if a user is not logged in.
|
|
99
|
-
*
|
|
100
|
-
* @returns profile for the session.
|
|
101
|
-
*/
|
|
102
80
|
async getBearerToken() {
|
|
103
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
104
|
-
|
|
81
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertLoggedIn).call(this);
|
|
82
|
+
if (__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_hasValidSession).call(this, this.state.sessionData)) {
|
|
83
|
+
return this.state.sessionData.accessToken;
|
|
84
|
+
}
|
|
85
|
+
const { accessToken } = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_performAuthenticationFlow).call(this);
|
|
86
|
+
return accessToken;
|
|
105
87
|
}
|
|
106
88
|
/**
|
|
107
89
|
* Will return a session profile.
|
|
108
|
-
*
|
|
90
|
+
* Throws if a user is not logged in.
|
|
109
91
|
*
|
|
110
92
|
* @returns profile for the session.
|
|
111
93
|
*/
|
|
112
94
|
async getSessionProfile() {
|
|
113
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
114
|
-
|
|
95
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertLoggedIn).call(this);
|
|
96
|
+
if (__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_hasValidSession).call(this, this.state.sessionData)) {
|
|
97
|
+
return this.state.sessionData.profile;
|
|
98
|
+
}
|
|
99
|
+
const { profile } = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_performAuthenticationFlow).call(this);
|
|
100
|
+
return profile;
|
|
115
101
|
}
|
|
116
102
|
isSignedIn() {
|
|
117
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'isSignedIn');
|
|
118
103
|
return this.state.isSignedIn;
|
|
119
104
|
}
|
|
120
105
|
}
|
|
121
|
-
_AuthenticationController_metametrics = new WeakMap(),
|
|
106
|
+
_AuthenticationController_metametrics = new WeakMap(), _AuthenticationController_isUnlocked = new WeakMap(), _AuthenticationController_keyringController = new WeakMap(), _AuthenticationController__snapPublicKeyCache = new WeakMap(), _AuthenticationController__snapSignMessageCache = new WeakMap(), _AuthenticationController_instances = new WeakSet(), _AuthenticationController_registerMessageHandlers = function _AuthenticationController_registerMessageHandlers() {
|
|
122
107
|
this.messagingSystem.registerActionHandler('AuthenticationController:getBearerToken', this.getBearerToken.bind(this));
|
|
123
108
|
this.messagingSystem.registerActionHandler('AuthenticationController:getSessionProfile', this.getSessionProfile.bind(this));
|
|
124
109
|
this.messagingSystem.registerActionHandler('AuthenticationController:isSignedIn', this.isSignedIn.bind(this));
|
|
125
110
|
this.messagingSystem.registerActionHandler('AuthenticationController:performSignIn', this.performSignIn.bind(this));
|
|
126
111
|
this.messagingSystem.registerActionHandler('AuthenticationController:performSignOut', this.performSignOut.bind(this));
|
|
127
|
-
},
|
|
128
|
-
if (!this.state.
|
|
129
|
-
|
|
112
|
+
}, _AuthenticationController_assertLoggedIn = function _AuthenticationController_assertLoggedIn() {
|
|
113
|
+
if (!this.state.isSignedIn) {
|
|
114
|
+
throw new Error(`${controllerName}: Unable to call method, user is not authenticated`);
|
|
130
115
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
116
|
+
}, _AuthenticationController_performAuthenticationFlow = async function _AuthenticationController_performAuthenticationFlow() {
|
|
117
|
+
try {
|
|
118
|
+
// 1. Nonce
|
|
119
|
+
const publicKey = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_snapGetPublicKey).call(this);
|
|
120
|
+
const nonce = await (0, services_1.getNonce)(publicKey);
|
|
121
|
+
if (!nonce) {
|
|
122
|
+
throw new Error(`Unable to get nonce`);
|
|
123
|
+
}
|
|
124
|
+
// 2. Login
|
|
125
|
+
const rawMessage = (0, services_1.createLoginRawMessage)(nonce, publicKey);
|
|
126
|
+
const signature = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_snapSignMessage).call(this, rawMessage);
|
|
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,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
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;
|
|
146
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;
|
|
147
175
|
}, _AuthenticationController_snapGetPublicKey =
|
|
148
176
|
/**
|
|
149
177
|
* Returns the auth snap public key.
|
|
@@ -154,7 +182,9 @@ async function _AuthenticationController_snapGetPublicKey() {
|
|
|
154
182
|
if (__classPrivateFieldGet(this, _AuthenticationController__snapPublicKeyCache, "f")) {
|
|
155
183
|
return __classPrivateFieldGet(this, _AuthenticationController__snapPublicKeyCache, "f");
|
|
156
184
|
}
|
|
157
|
-
__classPrivateFieldGet(this,
|
|
185
|
+
if (!__classPrivateFieldGet(this, _AuthenticationController_isUnlocked, "f")) {
|
|
186
|
+
throw new Error('#snapGetPublicKey - unable to call snap, wallet is locked');
|
|
187
|
+
}
|
|
158
188
|
const result = (await this.messagingSystem.call('SnapController:handleRequest', (0, auth_snap_requests_1.createSnapPublicKeyRequest)()));
|
|
159
189
|
__classPrivateFieldSet(this, _AuthenticationController__snapPublicKeyCache, result, "f");
|
|
160
190
|
return result;
|
|
@@ -166,11 +196,12 @@ async function _AuthenticationController_snapGetPublicKey() {
|
|
|
166
196
|
* @returns A Signature created by the snap.
|
|
167
197
|
*/
|
|
168
198
|
async function _AuthenticationController_snapSignMessage(message) {
|
|
169
|
-
(0, sdk_1.assertMessageStartsWithMetamask)(message);
|
|
170
199
|
if (__classPrivateFieldGet(this, _AuthenticationController__snapSignMessageCache, "f")[message]) {
|
|
171
200
|
return __classPrivateFieldGet(this, _AuthenticationController__snapSignMessageCache, "f")[message];
|
|
172
201
|
}
|
|
173
|
-
__classPrivateFieldGet(this,
|
|
202
|
+
if (!__classPrivateFieldGet(this, _AuthenticationController_isUnlocked, "f")) {
|
|
203
|
+
throw new Error('#snapSignMessage - unable to call snap, wallet is locked');
|
|
204
|
+
}
|
|
174
205
|
const result = (await this.messagingSystem.call('SnapController:handleRequest', (0, auth_snap_requests_1.createSnapSignMessageRequest)(message)));
|
|
175
206
|
__classPrivateFieldGet(this, _AuthenticationController__snapSignMessageCache, "f")[message] = result;
|
|
176
207
|
return result;
|
|
@@ -1 +1 @@
|
|
|
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,MAAqB,wBAAyB,SAAQ,gCAIrD;IAwBC,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;;QAzCI,wDAA8B;QAE9B,iDAAoB;QAE7B,+CAAc,KAAK,EAAC;QAEX,sDAAqB;YAC5B,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;gBAE9B,IAAI,CAAC,eAAe,CAAC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,MAAA,CAAC;IAEnC,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;kBAjOkB,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 {\n ...this.state.sessionData,\n profile: {\n ...this.state.sessionData.profile,\n metaMetricsId: await this.#metametrics.getMetaMetricsId(),\n },\n };\n }\n\n async #setLoginResponseToState(loginResponse: LoginResponse) {\n this.update((state) => {\n state.isSignedIn = true;\n state.sessionData = loginResponse;\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.#assertIsUnlocked('performSignOut');\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 this.#assertIsUnlocked('isSignedIn');\n return this.state.isSignedIn;\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 this.#assertIsUnlocked('#snapGetPublicKey');\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: 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"]}
|
|
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;;QAvCI,wDAA8B;QAEvC,+CAAc,KAAK,EAAC;QAEX,sDAAqB;YAC5B,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;gBAE9B,IAAI,CAAC,eAAe,CAA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,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 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"]}
|
|
@@ -2,12 +2,30 @@ 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";
|
|
7
5
|
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
|
+
};
|
|
8
22
|
export type AuthenticationControllerState = {
|
|
23
|
+
/**
|
|
24
|
+
* Global isSignedIn state.
|
|
25
|
+
* Can be used to determine if "Profile Syncing" is enabled.
|
|
26
|
+
*/
|
|
9
27
|
isSignedIn: boolean;
|
|
10
|
-
sessionData?:
|
|
28
|
+
sessionData?: SessionData;
|
|
11
29
|
};
|
|
12
30
|
export declare const defaultState: AuthenticationControllerState;
|
|
13
31
|
type CreateActionsObj<Controller extends keyof AuthenticationController> = {
|
|
@@ -46,20 +64,14 @@ export default class AuthenticationController extends BaseController<typeof cont
|
|
|
46
64
|
});
|
|
47
65
|
performSignIn(): Promise<string>;
|
|
48
66
|
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
|
-
*/
|
|
55
67
|
getBearerToken(): Promise<string>;
|
|
56
68
|
/**
|
|
57
69
|
* Will return a session profile.
|
|
58
|
-
*
|
|
70
|
+
* Throws if a user is not logged in.
|
|
59
71
|
*
|
|
60
72
|
* @returns profile for the session.
|
|
61
73
|
*/
|
|
62
|
-
getSessionProfile(): Promise<
|
|
74
|
+
getSessionProfile(): Promise<SessionProfile>;
|
|
63
75
|
isSignedIn(): boolean;
|
|
64
76
|
}
|
|
65
77
|
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,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,MA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C/B,MAAM,MAAM,yCAAyC,GACnD,UAAU,CAAC,mBAAmB,CAAC,CAAC;AAClC,MAAM,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;;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"}
|
|
@@ -2,12 +2,30 @@ 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";
|
|
7
5
|
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
|
+
};
|
|
8
22
|
export type AuthenticationControllerState = {
|
|
23
|
+
/**
|
|
24
|
+
* Global isSignedIn state.
|
|
25
|
+
* Can be used to determine if "Profile Syncing" is enabled.
|
|
26
|
+
*/
|
|
9
27
|
isSignedIn: boolean;
|
|
10
|
-
sessionData?:
|
|
28
|
+
sessionData?: SessionData;
|
|
11
29
|
};
|
|
12
30
|
export declare const defaultState: AuthenticationControllerState;
|
|
13
31
|
type CreateActionsObj<Controller extends keyof AuthenticationController> = {
|
|
@@ -46,20 +64,14 @@ export default class AuthenticationController extends BaseController<typeof cont
|
|
|
46
64
|
});
|
|
47
65
|
performSignIn(): Promise<string>;
|
|
48
66
|
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
|
-
*/
|
|
55
67
|
getBearerToken(): Promise<string>;
|
|
56
68
|
/**
|
|
57
69
|
* Will return a session profile.
|
|
58
|
-
*
|
|
70
|
+
* Throws if a user is not logged in.
|
|
59
71
|
*
|
|
60
72
|
* @returns profile for the session.
|
|
61
73
|
*/
|
|
62
|
-
getSessionProfile(): Promise<
|
|
74
|
+
getSessionProfile(): Promise<SessionProfile>;
|
|
63
75
|
isSignedIn(): boolean;
|
|
64
76
|
}
|
|
65
77
|
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;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;CAC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