@metamask/profile-sync-controller 29.0.0 → 30.0.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 +21 -1
- package/dist/controllers/authentication/AuthenticationController.cjs +185 -90
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts +22 -4
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts +22 -4
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs +186 -91
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.cjs +10 -1
- package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.cts +11 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.mts +11 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.mjs +9 -1
- package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.cjs +22 -23
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +2 -3
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +2 -3
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +22 -23
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +3 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +2 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +2 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +4 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs +44 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts +16 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +16 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.mjs +42 -1
- 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.d.cts +20 -1
- package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.d.mts +20 -1
- package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
- package/dist/sdk/authentication.cjs +4 -0
- package/dist/sdk/authentication.cjs.map +1 -1
- package/dist/sdk/authentication.d.cts +2 -1
- package/dist/sdk/authentication.d.cts.map +1 -1
- package/dist/sdk/authentication.d.mts +2 -1
- package/dist/sdk/authentication.d.mts.map +1 -1
- package/dist/sdk/authentication.mjs +4 -0
- package/dist/sdk/authentication.mjs.map +1 -1
- package/dist/sdk/constants.cjs +1 -0
- package/dist/sdk/constants.cjs.map +1 -1
- package/dist/sdk/constants.d.cts +1 -0
- package/dist/sdk/constants.d.cts.map +1 -1
- package/dist/sdk/constants.d.mts +1 -0
- package/dist/sdk/constants.d.mts.map +1 -1
- package/dist/sdk/constants.mjs +1 -0
- package/dist/sdk/constants.mjs.map +1 -1
- package/dist/sdk/errors.cjs +14 -1
- package/dist/sdk/errors.cjs.map +1 -1
- package/dist/sdk/errors.d.cts +9 -0
- package/dist/sdk/errors.d.cts.map +1 -1
- package/dist/sdk/errors.d.mts +9 -0
- package/dist/sdk/errors.d.mts.map +1 -1
- package/dist/sdk/errors.mjs +12 -0
- package/dist/sdk/errors.mjs.map +1 -1
- package/dist/sdk/mocks/auth.cjs +12 -1
- package/dist/sdk/mocks/auth.cjs.map +1 -1
- package/dist/sdk/mocks/auth.d.cts +11 -0
- package/dist/sdk/mocks/auth.d.cts.map +1 -1
- package/dist/sdk/mocks/auth.d.mts +11 -0
- package/dist/sdk/mocks/auth.d.mts.map +1 -1
- package/dist/sdk/mocks/auth.mjs +12 -1
- package/dist/sdk/mocks/auth.mjs.map +1 -1
- package/dist/shared/utils/entropy-source.cjs +37 -0
- package/dist/shared/utils/entropy-source.cjs.map +1 -0
- package/dist/shared/utils/entropy-source.d.cts +22 -0
- package/dist/shared/utils/entropy-source.d.cts.map +1 -0
- package/dist/shared/utils/entropy-source.d.mts +22 -0
- package/dist/shared/utils/entropy-source.d.mts.map +1 -0
- package/dist/shared/utils/entropy-source.mjs +32 -0
- package/dist/shared/utils/entropy-source.mjs.map +1 -0
- package/dist/shared/utils/hd-keyring-seed.cjs +49 -0
- package/dist/shared/utils/hd-keyring-seed.cjs.map +1 -0
- package/dist/shared/utils/hd-keyring-seed.d.cts +27 -0
- package/dist/shared/utils/hd-keyring-seed.d.cts.map +1 -0
- package/dist/shared/utils/hd-keyring-seed.d.mts +27 -0
- package/dist/shared/utils/hd-keyring-seed.d.mts.map +1 -0
- package/dist/shared/utils/hd-keyring-seed.mjs +45 -0
- package/dist/shared/utils/hd-keyring-seed.mjs.map +1 -0
- package/dist/shared/utils/message-signing.cjs +147 -0
- package/dist/shared/utils/message-signing.cjs.map +1 -0
- package/dist/shared/utils/message-signing.d.cts +73 -0
- package/dist/shared/utils/message-signing.d.cts.map +1 -0
- package/dist/shared/utils/message-signing.d.mts +73 -0
- package/dist/shared/utils/message-signing.d.mts.map +1 -0
- package/dist/shared/utils/message-signing.mjs +140 -0
- package/dist/shared/utils/message-signing.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/controllers/authentication/auth-snap-requests.cjs +0 -60
- package/dist/controllers/authentication/auth-snap-requests.cjs.map +0 -1
- package/dist/controllers/authentication/auth-snap-requests.d.cts +0 -27
- package/dist/controllers/authentication/auth-snap-requests.d.cts.map +0 -1
- package/dist/controllers/authentication/auth-snap-requests.d.mts +0 -27
- package/dist/controllers/authentication/auth-snap-requests.d.mts.map +0 -1
- package/dist/controllers/authentication/auth-snap-requests.mjs +0 -54
- package/dist/controllers/authentication/auth-snap-requests.mjs.map +0 -1
|
@@ -9,14 +9,17 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _AuthenticationController_instances, _AuthenticationController_metametrics, _AuthenticationController_auth, _AuthenticationController_config, _AuthenticationController_isUnlocked,
|
|
12
|
+
var _AuthenticationController_instances, _AuthenticationController_metametrics, _AuthenticationController_auth, _AuthenticationController_config, _AuthenticationController_isUnlocked, _AuthenticationController_profilePairingRequestEpoch, _AuthenticationController_keyringController, _AuthenticationController_getLoginResponseFromState, _AuthenticationController_setLoginResponseToState, _AuthenticationController_assertIsUnlocked, _AuthenticationController_getHdKeyringEntropySourceIds, _AuthenticationController_getPrimaryEntropySourceId, _AuthenticationController_getLoginTag, _AuthenticationController_getLoginIdentifierType, _AuthenticationController_resolveSocialIdentifierType, _AuthenticationController_identifierTypeFromSeedlessState, _AuthenticationController_trySocialPairing, _AuthenticationController_clearNeedsSocialPairing, _AuthenticationController_tryClearNeedsProfilePairing, _AuthenticationController_doPair, _AuthenticationController_pairSrpProfiles, _AuthenticationController_propagateCanonical, _AuthenticationController_getCanonicalProfileId, _AuthenticationController_invalidateSrpSession, _AuthenticationController_getHdKeyringSeed, _AuthenticationController_getPublicKey, _AuthenticationController__signMessageCache, _AuthenticationController_scopedCacheKey, _AuthenticationController_signMessage;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
|
-
import { assertMessageStartsWithMetamask, AuthType, Env, JwtBearerAuth } from "../../sdk/index.mjs";
|
|
15
|
-
import {
|
|
14
|
+
import { assertMessageStartsWithMetamask, AuthType, Env, JwtBearerAuth, PairConflictError } from "../../sdk/index.mjs";
|
|
15
|
+
import { getHdKeyringEntropySourceIds, getPrimaryHdKeyringEntropySourceId } from "../../shared/utils/entropy-source.mjs";
|
|
16
|
+
import { getHdKeyringSeed } from "../../shared/utils/hd-keyring-seed.mjs";
|
|
17
|
+
import { getMessageSigningPublicKey, signMessageWithMessageSigningKey } from "../../shared/utils/message-signing.mjs";
|
|
16
18
|
const controllerName = 'AuthenticationController';
|
|
17
19
|
export const defaultState = {
|
|
18
20
|
isSignedIn: false,
|
|
19
21
|
needsProfilePairing: true,
|
|
22
|
+
needsSocialPairing: true,
|
|
20
23
|
};
|
|
21
24
|
const metadata = {
|
|
22
25
|
isSignedIn: {
|
|
@@ -31,6 +34,12 @@ const metadata = {
|
|
|
31
34
|
includeInDebugSnapshot: true,
|
|
32
35
|
usedInUi: true,
|
|
33
36
|
},
|
|
37
|
+
needsSocialPairing: {
|
|
38
|
+
includeInStateLogs: true,
|
|
39
|
+
persist: true,
|
|
40
|
+
includeInDebugSnapshot: true,
|
|
41
|
+
usedInUi: true,
|
|
42
|
+
},
|
|
34
43
|
srpSessionData: {
|
|
35
44
|
// Remove access token from state logs
|
|
36
45
|
includeInStateLogs: (srpSessionData) => {
|
|
@@ -84,9 +93,9 @@ export class AuthenticationController extends BaseController {
|
|
|
84
93
|
_AuthenticationController_auth.set(this, void 0);
|
|
85
94
|
_AuthenticationController_config.set(this, {
|
|
86
95
|
env: Env.PRD,
|
|
96
|
+
isSocialPairingEnabled: () => false,
|
|
87
97
|
});
|
|
88
98
|
_AuthenticationController_isUnlocked.set(this, false);
|
|
89
|
-
_AuthenticationController_cachedPrimaryEntropySourceId.set(this, void 0);
|
|
90
99
|
// Bumped by `requestProfilePairing`. `performSignIn` snapshots this
|
|
91
100
|
// before its first await; if it changes mid-flight we must NOT clear
|
|
92
101
|
// `needsProfilePairing` (the rearm signal wins).
|
|
@@ -103,13 +112,14 @@ export class AuthenticationController extends BaseController {
|
|
|
103
112
|
});
|
|
104
113
|
},
|
|
105
114
|
});
|
|
106
|
-
|
|
115
|
+
_AuthenticationController__signMessageCache.set(this, {});
|
|
107
116
|
if (!metametrics) {
|
|
108
117
|
throw new Error('`metametrics` field is required');
|
|
109
118
|
}
|
|
110
119
|
__classPrivateFieldSet(this, _AuthenticationController_config, {
|
|
111
120
|
...__classPrivateFieldGet(this, _AuthenticationController_config, "f"),
|
|
112
121
|
...config,
|
|
122
|
+
isSocialPairingEnabled: config?.isSocialPairingEnabled ?? __classPrivateFieldGet(this, _AuthenticationController_config, "f").isSocialPairingEnabled,
|
|
113
123
|
}, "f");
|
|
114
124
|
__classPrivateFieldSet(this, _AuthenticationController_metametrics, metametrics, "f");
|
|
115
125
|
__classPrivateFieldSet(this, _AuthenticationController_auth, new JwtBearerAuth({
|
|
@@ -122,8 +132,8 @@ export class AuthenticationController extends BaseController {
|
|
|
122
132
|
setLoginResponse: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_setLoginResponseToState).bind(this),
|
|
123
133
|
},
|
|
124
134
|
signing: {
|
|
125
|
-
getIdentifier: __classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
126
|
-
signMessage: __classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
135
|
+
getIdentifier: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPublicKey).bind(this),
|
|
136
|
+
signMessage: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_signMessage).bind(this),
|
|
127
137
|
},
|
|
128
138
|
getLoginTag: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getLoginTag).bind(this),
|
|
129
139
|
getLoginIdentifierType: __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getLoginIdentifierType).bind(this),
|
|
@@ -135,15 +145,15 @@ export class AuthenticationController extends BaseController {
|
|
|
135
145
|
async performSignIn() {
|
|
136
146
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'performSignIn');
|
|
137
147
|
const epochAtStart = __classPrivateFieldGet(this, _AuthenticationController_profilePairingRequestEpoch, "f");
|
|
138
|
-
const
|
|
148
|
+
const entropySourceIds = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getHdKeyringEntropySourceIds).call(this);
|
|
139
149
|
const accessTokens = [];
|
|
140
150
|
// We iterate sequentially in order to be sure that the first entry
|
|
141
151
|
// is the primary SRP LoginResponse.
|
|
142
|
-
for (const
|
|
152
|
+
for (const entropySourceId of entropySourceIds) {
|
|
143
153
|
const accessToken = await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getAccessToken(entropySourceId);
|
|
144
154
|
accessTokens.push(accessToken);
|
|
145
155
|
}
|
|
146
|
-
if (
|
|
156
|
+
if (entropySourceIds.length < 2) {
|
|
147
157
|
// Single-SRP wallet: nothing to pair.
|
|
148
158
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_tryClearNeedsProfilePairing).call(this, epochAtStart);
|
|
149
159
|
}
|
|
@@ -156,6 +166,12 @@ export class AuthenticationController extends BaseController {
|
|
|
156
166
|
// noop
|
|
157
167
|
}
|
|
158
168
|
}
|
|
169
|
+
try {
|
|
170
|
+
await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_trySocialPairing).call(this, accessTokens[0]);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// noop
|
|
174
|
+
}
|
|
159
175
|
return accessTokens;
|
|
160
176
|
}
|
|
161
177
|
/**
|
|
@@ -172,7 +188,6 @@ export class AuthenticationController extends BaseController {
|
|
|
172
188
|
}
|
|
173
189
|
}
|
|
174
190
|
performSignOut() {
|
|
175
|
-
__classPrivateFieldSet(this, _AuthenticationController_cachedPrimaryEntropySourceId, undefined, "f");
|
|
176
191
|
this.update((state) => {
|
|
177
192
|
state.isSignedIn = false;
|
|
178
193
|
state.srpSessionData = undefined;
|
|
@@ -191,7 +206,7 @@ export class AuthenticationController extends BaseController {
|
|
|
191
206
|
*/
|
|
192
207
|
async getBearerToken(entropySourceId) {
|
|
193
208
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'getBearerToken');
|
|
194
|
-
const resolvedId = entropySourceId ??
|
|
209
|
+
const resolvedId = entropySourceId ?? __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
195
210
|
return await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getAccessToken(resolvedId);
|
|
196
211
|
}
|
|
197
212
|
/**
|
|
@@ -209,7 +224,7 @@ export class AuthenticationController extends BaseController {
|
|
|
209
224
|
*/
|
|
210
225
|
async getSessionProfile(entropySourceId) {
|
|
211
226
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'getSessionProfile');
|
|
212
|
-
const resolvedId = entropySourceId ??
|
|
227
|
+
const resolvedId = entropySourceId ?? __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
213
228
|
return await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getUserProfile(resolvedId);
|
|
214
229
|
}
|
|
215
230
|
/**
|
|
@@ -230,10 +245,10 @@ export class AuthenticationController extends BaseController {
|
|
|
230
245
|
*/
|
|
231
246
|
async refreshCanonicalProfileId() {
|
|
232
247
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'refreshCanonicalProfileId');
|
|
233
|
-
const primaryEntropySourceId =
|
|
248
|
+
const primaryEntropySourceId = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
234
249
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_invalidateSrpSession).call(this, primaryEntropySourceId);
|
|
235
250
|
await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getAccessToken(primaryEntropySourceId);
|
|
236
|
-
const canonical =
|
|
251
|
+
const canonical = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getCanonicalProfileId).call(this);
|
|
237
252
|
if (!canonical) {
|
|
238
253
|
throw new Error('refreshCanonicalProfileId - Unable to resolve canonical profile ID');
|
|
239
254
|
}
|
|
@@ -242,7 +257,7 @@ export class AuthenticationController extends BaseController {
|
|
|
242
257
|
}
|
|
243
258
|
async getUserProfileLineage(entropySourceId) {
|
|
244
259
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'getUserProfileLineage');
|
|
245
|
-
const resolvedId = entropySourceId ??
|
|
260
|
+
const resolvedId = entropySourceId ?? __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
246
261
|
return await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getUserProfileLineage(resolvedId);
|
|
247
262
|
}
|
|
248
263
|
/**
|
|
@@ -258,21 +273,21 @@ export class AuthenticationController extends BaseController {
|
|
|
258
273
|
*/
|
|
259
274
|
async getCustomerServiceToken(entropySourceId) {
|
|
260
275
|
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, 'getCustomerServiceToken');
|
|
261
|
-
const resolvedId = entropySourceId ??
|
|
276
|
+
const resolvedId = entropySourceId ?? __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
262
277
|
return await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").getCustomerServiceToken(resolvedId);
|
|
263
278
|
}
|
|
264
279
|
isSignedIn() {
|
|
265
280
|
return this.state.isSignedIn;
|
|
266
281
|
}
|
|
267
282
|
}
|
|
268
|
-
_AuthenticationController_metametrics = new WeakMap(), _AuthenticationController_auth = new WeakMap(), _AuthenticationController_config = new WeakMap(), _AuthenticationController_isUnlocked = new WeakMap(),
|
|
269
|
-
const resolvedId = entropySourceId ??
|
|
283
|
+
_AuthenticationController_metametrics = new WeakMap(), _AuthenticationController_auth = new WeakMap(), _AuthenticationController_config = new WeakMap(), _AuthenticationController_isUnlocked = new WeakMap(), _AuthenticationController_profilePairingRequestEpoch = new WeakMap(), _AuthenticationController_keyringController = new WeakMap(), _AuthenticationController__signMessageCache = new WeakMap(), _AuthenticationController_instances = new WeakSet(), _AuthenticationController_getLoginResponseFromState = async function _AuthenticationController_getLoginResponseFromState(entropySourceId) {
|
|
284
|
+
const resolvedId = entropySourceId ?? __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
270
285
|
if (!this.state.srpSessionData?.[resolvedId]) {
|
|
271
286
|
return null;
|
|
272
287
|
}
|
|
273
288
|
return this.state.srpSessionData[resolvedId];
|
|
274
289
|
}, _AuthenticationController_setLoginResponseToState = async function _AuthenticationController_setLoginResponseToState(loginResponse, entropySourceId) {
|
|
275
|
-
const resolvedId = entropySourceId ??
|
|
290
|
+
const resolvedId = entropySourceId ?? __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
276
291
|
const metaMetricsId = await __classPrivateFieldGet(this, _AuthenticationController_metametrics, "f").getMetaMetricsId();
|
|
277
292
|
this.update((state) => {
|
|
278
293
|
state.isSignedIn = true;
|
|
@@ -291,20 +306,12 @@ _AuthenticationController_metametrics = new WeakMap(), _AuthenticationController
|
|
|
291
306
|
if (!__classPrivateFieldGet(this, _AuthenticationController_isUnlocked, "f")) {
|
|
292
307
|
throw new Error(`${methodName} - unable to proceed, wallet is locked`);
|
|
293
308
|
}
|
|
294
|
-
},
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
throw new Error('#getPrimaryEntropySourceId - No entropy sources found from snap');
|
|
301
|
-
}
|
|
302
|
-
const primaryId = allPublicKeys[0][0];
|
|
303
|
-
if (!primaryId) {
|
|
304
|
-
throw new Error('#getPrimaryEntropySourceId - Primary entropy source ID is undefined');
|
|
305
|
-
}
|
|
306
|
-
__classPrivateFieldSet(this, _AuthenticationController_cachedPrimaryEntropySourceId, primaryId, "f");
|
|
307
|
-
return __classPrivateFieldGet(this, _AuthenticationController_cachedPrimaryEntropySourceId, "f");
|
|
309
|
+
}, _AuthenticationController_getHdKeyringEntropySourceIds = function _AuthenticationController_getHdKeyringEntropySourceIds() {
|
|
310
|
+
const { keyrings } = this.messenger.call('KeyringController:getState');
|
|
311
|
+
return getHdKeyringEntropySourceIds(keyrings);
|
|
312
|
+
}, _AuthenticationController_getPrimaryEntropySourceId = function _AuthenticationController_getPrimaryEntropySourceId() {
|
|
313
|
+
const { keyrings } = this.messenger.call('KeyringController:getState');
|
|
314
|
+
return getPrimaryHdKeyringEntropySourceId(keyrings);
|
|
308
315
|
}, _AuthenticationController_getLoginTag =
|
|
309
316
|
/**
|
|
310
317
|
* Resolves the SRP login tag for `raw_message`.
|
|
@@ -316,7 +323,7 @@ _AuthenticationController_metametrics = new WeakMap(), _AuthenticationController
|
|
|
316
323
|
* @returns The login tag to append to the signed message.
|
|
317
324
|
*/
|
|
318
325
|
async function _AuthenticationController_getLoginTag(entropySourceId) {
|
|
319
|
-
const primaryEntropySourceId =
|
|
326
|
+
const primaryEntropySourceId = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
320
327
|
const resolvedId = entropySourceId ?? primaryEntropySourceId;
|
|
321
328
|
return resolvedId === primaryEntropySourceId ? 'primary' : 'secondary';
|
|
322
329
|
}, _AuthenticationController_getLoginIdentifierType =
|
|
@@ -339,7 +346,7 @@ async function _AuthenticationController_getLoginTag(entropySourceId) {
|
|
|
339
346
|
* @returns The login identifier type.
|
|
340
347
|
*/
|
|
341
348
|
async function _AuthenticationController_getLoginIdentifierType(entropySourceId) {
|
|
342
|
-
const primaryEntropySourceId =
|
|
349
|
+
const primaryEntropySourceId = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
343
350
|
const resolvedId = entropySourceId ?? primaryEntropySourceId;
|
|
344
351
|
// Social vault authConnection is only associated with the primary source.
|
|
345
352
|
if (resolvedId !== primaryEntropySourceId) {
|
|
@@ -348,26 +355,118 @@ async function _AuthenticationController_getLoginIdentifierType(entropySourceId)
|
|
|
348
355
|
return __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_resolveSocialIdentifierType).call(this);
|
|
349
356
|
}, _AuthenticationController_resolveSocialIdentifierType = function _AuthenticationController_resolveSocialIdentifierType() {
|
|
350
357
|
try {
|
|
351
|
-
|
|
352
|
-
|
|
358
|
+
return __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_identifierTypeFromSeedlessState).call(this, this.messenger.call('SeedlessOnboardingController:getState'));
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
return 'SRP';
|
|
362
|
+
}
|
|
363
|
+
}, _AuthenticationController_identifierTypeFromSeedlessState = function _AuthenticationController_identifierTypeFromSeedlessState(state) {
|
|
364
|
+
if (state.vault === null || state.vault === undefined) {
|
|
365
|
+
return 'SRP';
|
|
366
|
+
}
|
|
367
|
+
// Match provider strings from SeedlessOnboarding state rather than
|
|
368
|
+
// importing AuthConnection — a value import would load that package
|
|
369
|
+
// (and its heavy deps) whenever this controller is imported.
|
|
370
|
+
switch (state.authConnection) {
|
|
371
|
+
case 'google':
|
|
372
|
+
return 'GOOGLE';
|
|
373
|
+
case 'apple':
|
|
374
|
+
return 'APPLE';
|
|
375
|
+
case 'telegram':
|
|
376
|
+
return 'TELEGRAM';
|
|
377
|
+
default:
|
|
353
378
|
return 'SRP';
|
|
379
|
+
}
|
|
380
|
+
}, _AuthenticationController_trySocialPairing =
|
|
381
|
+
/**
|
|
382
|
+
* Attaches a Google/Apple/Telegram social identifier to the primary SRP
|
|
383
|
+
* profile via `POST /api/v2/profile/pair/identifier`.
|
|
384
|
+
*
|
|
385
|
+
* Runs only when `isSocialPairingEnabled()` is true and
|
|
386
|
+
* `needsSocialPairing` is not `false` (`undefined` is treated as true).
|
|
387
|
+
* No social provider (`authConnection` unset) → clear the flag (nothing
|
|
388
|
+
* to pair). Social provider set but vault missing → skip (onboarding
|
|
389
|
+
* still in flight). Google without email → skip (API requires it).
|
|
390
|
+
* Telegram never sends `email` (the field holds a display name, not an
|
|
391
|
+
* address). Missing social JWT → skip. 409 Conflict → clear the flag
|
|
392
|
+
* (identifier already owned; retry is pointless). Other errors
|
|
393
|
+
* propagate so the caller can swallow them and leave the flag set for
|
|
394
|
+
* retry.
|
|
395
|
+
*
|
|
396
|
+
* @param primaryAccessToken - Primary SRP OIDC access token used as the
|
|
397
|
+
* Bearer credential. The profile associated with this JWT becomes the
|
|
398
|
+
* canonical owner of the social identifier.
|
|
399
|
+
*/
|
|
400
|
+
async function _AuthenticationController_trySocialPairing(primaryAccessToken) {
|
|
401
|
+
if (!__classPrivateFieldGet(this, _AuthenticationController_config, "f").isSocialPairingEnabled() ||
|
|
402
|
+
this.state.needsSocialPairing === false ||
|
|
403
|
+
!primaryAccessToken) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
let seedlessState;
|
|
407
|
+
try {
|
|
408
|
+
seedlessState = this.messenger.call('SeedlessOnboardingController:getState');
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
// Controller missing or getState failed — retry next performSignIn.
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
// `SRP` here does not describe the vault: it is the mapping's "no social
|
|
415
|
+
// identity" result, returned when there is no seedless vault or the
|
|
416
|
+
// provider is unrecognised. In both cases there is nothing to pair.
|
|
417
|
+
const identifierType = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_identifierTypeFromSeedlessState).call(this, seedlessState);
|
|
418
|
+
if (identifierType === 'SRP') {
|
|
419
|
+
const { vault, authConnection } = seedlessState;
|
|
420
|
+
// Vault not written yet but a social provider is already known —
|
|
421
|
+
// onboarding is still in flight. Do not clear; retry next sign-in.
|
|
422
|
+
if ((vault === null || vault === undefined) && Boolean(authConnection)) {
|
|
423
|
+
return;
|
|
354
424
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
425
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_clearNeedsSocialPairing).call(this);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
// Email policy follows the API contract: GOOGLE requires `email` (400
|
|
429
|
+
// without it), APPLE accepts it optionally, TELEGRAM must not send it
|
|
430
|
+
// (clients store a display name in `socialLoginEmail` for Telegram).
|
|
431
|
+
// Clients request the `email` scope for Google, so a missing value is a
|
|
432
|
+
// defensive case rather than an expected one; returning here leaves
|
|
433
|
+
// `needsSocialPairing` set so the next sign-in retries instead of
|
|
434
|
+
// sending a request that would fail.
|
|
435
|
+
const { socialLoginEmail } = seedlessState;
|
|
436
|
+
let email;
|
|
437
|
+
if (identifierType === 'GOOGLE') {
|
|
438
|
+
if (!socialLoginEmail) {
|
|
439
|
+
return;
|
|
367
440
|
}
|
|
441
|
+
email = socialLoginEmail;
|
|
368
442
|
}
|
|
369
|
-
|
|
370
|
-
|
|
443
|
+
else if (identifierType === 'APPLE') {
|
|
444
|
+
email = socialLoginEmail;
|
|
445
|
+
}
|
|
446
|
+
const socialJwt = await this.messenger.call('SeedlessOnboardingController:getAccessToken');
|
|
447
|
+
if (socialJwt === undefined || socialJwt === '') {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
try {
|
|
451
|
+
await __classPrivateFieldGet(this, _AuthenticationController_auth, "f").pairSocialIdentifier({
|
|
452
|
+
identifierType,
|
|
453
|
+
socialJwt,
|
|
454
|
+
...(email ? { email } : {}),
|
|
455
|
+
}, primaryAccessToken);
|
|
456
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_clearNeedsSocialPairing).call(this);
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
if (error instanceof PairConflictError) {
|
|
460
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_clearNeedsSocialPairing).call(this);
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
throw error;
|
|
464
|
+
}
|
|
465
|
+
}, _AuthenticationController_clearNeedsSocialPairing = function _AuthenticationController_clearNeedsSocialPairing() {
|
|
466
|
+
if (this.state.needsSocialPairing !== false) {
|
|
467
|
+
this.update((state) => {
|
|
468
|
+
state.needsSocialPairing = false;
|
|
469
|
+
});
|
|
371
470
|
}
|
|
372
471
|
}, _AuthenticationController_tryClearNeedsProfilePairing = function _AuthenticationController_tryClearNeedsProfilePairing(epochAtStart) {
|
|
373
472
|
if (__classPrivateFieldGet(this, _AuthenticationController_profilePairingRequestEpoch, "f") !== epochAtStart) {
|
|
@@ -391,9 +490,9 @@ async function _AuthenticationController_getLoginIdentifierType(entropySourceId)
|
|
|
391
490
|
* pair API call was in-flight.
|
|
392
491
|
*/
|
|
393
492
|
async function _AuthenticationController_doPair(accessTokens, epochAtStart) {
|
|
394
|
-
const previousCanonical =
|
|
493
|
+
const previousCanonical = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getCanonicalProfileId).call(this);
|
|
395
494
|
const profileAliases = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_pairSrpProfiles).call(this, accessTokens);
|
|
396
|
-
const newCanonical =
|
|
495
|
+
const newCanonical = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getCanonicalProfileId).call(this);
|
|
397
496
|
// If somehow we cannot compute the new canonical profile ID after pairing,
|
|
398
497
|
// we just return now and do not update the `needsProfilePairing` flag.
|
|
399
498
|
if (!newCanonical) {
|
|
@@ -429,18 +528,8 @@ async function _AuthenticationController_doPair(accessTokens, epochAtStart) {
|
|
|
429
528
|
}
|
|
430
529
|
}
|
|
431
530
|
});
|
|
432
|
-
}, _AuthenticationController_getCanonicalProfileId =
|
|
433
|
-
|
|
434
|
-
* Returns the canonical profile id from the primary SRP's cached session.
|
|
435
|
-
* Returns `null` when no session exists yet for the primary SRP.
|
|
436
|
-
*
|
|
437
|
-
* Always reads from the primary SRP because the canonical is shared across
|
|
438
|
-
* all paired SRPs after `#propagateCanonical`.
|
|
439
|
-
*
|
|
440
|
-
* @returns The canonical profile id, or `null` if unavailable.
|
|
441
|
-
*/
|
|
442
|
-
async function _AuthenticationController_getCanonicalProfileId() {
|
|
443
|
-
const primaryEntropySourceId = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
531
|
+
}, _AuthenticationController_getCanonicalProfileId = function _AuthenticationController_getCanonicalProfileId() {
|
|
532
|
+
const primaryEntropySourceId = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
444
533
|
return (this.state.srpSessionData?.[primaryEntropySourceId]?.profile
|
|
445
534
|
?.canonicalProfileId ?? null);
|
|
446
535
|
}, _AuthenticationController_invalidateSrpSession = function _AuthenticationController_invalidateSrpSession(entropySourceId) {
|
|
@@ -453,45 +542,51 @@ async function _AuthenticationController_getCanonicalProfileId() {
|
|
|
453
542
|
entry.profile.canonicalProfileId = '';
|
|
454
543
|
}
|
|
455
544
|
});
|
|
456
|
-
},
|
|
545
|
+
}, _AuthenticationController_getHdKeyringSeed =
|
|
457
546
|
/**
|
|
458
|
-
*
|
|
547
|
+
* Reads the BIP-39 seed for an HD entropy source from KeyringController.
|
|
459
548
|
*
|
|
460
|
-
* @param entropySourceId -
|
|
461
|
-
*
|
|
462
|
-
* @returns The
|
|
549
|
+
* @param entropySourceId - Entropy source ID. Defaults to the primary HD
|
|
550
|
+
* keyring.
|
|
551
|
+
* @returns The HD keyring seed.
|
|
463
552
|
*/
|
|
464
|
-
async function
|
|
465
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}, _AuthenticationController_snapGetAllPublicKeys =
|
|
553
|
+
async function _AuthenticationController_getHdKeyringSeed(entropySourceId) {
|
|
554
|
+
const resolvedId = entropySourceId ?? __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this);
|
|
555
|
+
return getHdKeyringSeed(this.messenger, resolvedId);
|
|
556
|
+
}, _AuthenticationController_getPublicKey =
|
|
469
557
|
/**
|
|
470
|
-
* Returns
|
|
558
|
+
* Returns the message-signing public key via native SIP-6 derivation
|
|
559
|
+
* (same key as `@metamask/message-signing-snap` with empty salt).
|
|
471
560
|
*
|
|
472
|
-
* @
|
|
561
|
+
* @param entropySourceId - The entropy source ID used to derive the key,
|
|
562
|
+
* when multiple sources are available (Multi-SRP).
|
|
563
|
+
* @returns The public key hex.
|
|
473
564
|
*/
|
|
474
|
-
async function
|
|
475
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, '#
|
|
476
|
-
const
|
|
477
|
-
return
|
|
478
|
-
},
|
|
565
|
+
async function _AuthenticationController_getPublicKey(entropySourceId) {
|
|
566
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, '#getPublicKey');
|
|
567
|
+
const seed = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getHdKeyringSeed).call(this, entropySourceId);
|
|
568
|
+
return getMessageSigningPublicKey(seed);
|
|
569
|
+
}, _AuthenticationController_scopedCacheKey = function _AuthenticationController_scopedCacheKey(message, entropySourceId) {
|
|
570
|
+
return `${entropySourceId ?? __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getPrimaryEntropySourceId).call(this)}:${message}`;
|
|
571
|
+
}, _AuthenticationController_signMessage =
|
|
479
572
|
/**
|
|
480
|
-
* Signs a
|
|
573
|
+
* Signs a `metamask:…` message with the native SIP-6 message-signing key.
|
|
481
574
|
*
|
|
482
575
|
* @param message - A specific tagged message to sign.
|
|
483
576
|
* @param entropySourceId - The entropy source ID used to derive the key,
|
|
484
577
|
* when multiple sources are available (Multi-SRP).
|
|
485
|
-
* @returns
|
|
578
|
+
* @returns Compact secp256k1 signature hex.
|
|
486
579
|
*/
|
|
487
|
-
async function
|
|
580
|
+
async function _AuthenticationController_signMessage(message, entropySourceId) {
|
|
488
581
|
assertMessageStartsWithMetamask(message);
|
|
489
|
-
|
|
490
|
-
|
|
582
|
+
__classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_assertIsUnlocked).call(this, '#signMessage');
|
|
583
|
+
const cacheKey = __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_scopedCacheKey).call(this, message, entropySourceId);
|
|
584
|
+
if (__classPrivateFieldGet(this, _AuthenticationController__signMessageCache, "f")[cacheKey]) {
|
|
585
|
+
return __classPrivateFieldGet(this, _AuthenticationController__signMessageCache, "f")[cacheKey];
|
|
491
586
|
}
|
|
492
|
-
__classPrivateFieldGet(this, _AuthenticationController_instances, "m",
|
|
493
|
-
const result =
|
|
494
|
-
__classPrivateFieldGet(this,
|
|
587
|
+
const seed = await __classPrivateFieldGet(this, _AuthenticationController_instances, "m", _AuthenticationController_getHdKeyringSeed).call(this, entropySourceId);
|
|
588
|
+
const result = await signMessageWithMessageSigningKey(message, seed);
|
|
589
|
+
__classPrivateFieldGet(this, _AuthenticationController__signMessageCache, "f")[cacheKey] = result;
|
|
495
590
|
return result;
|
|
496
591
|
};
|
|
497
592
|
//# sourceMappingURL=AuthenticationController.mjs.map
|