@metamask-previews/profile-sync-controller 28.3.0-preview-0d2cbf546 → 28.3.0-preview-064aea96d

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 CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Add `authenticationControllerSelectors` for best-effort reads of cached session identity from `AuthenticationController` state ([#9604](https://github.com/MetaMask/core/pull/9604))
13
+ - `selectSrpSessionData` — raw `srpSessionData` map
14
+ - `selectSessionData` — primary (first) SRP session entry
15
+ - `selectCanonicalProfileId` — cached `canonicalProfileId`, treating `''` as missing
16
+ - Intended for sync consumers (e.g. Braze) that should not wait on `getSessionProfile()`. Same staleness as a valid cached session; use `refreshCanonicalProfileId()` when freshness is required.
17
+
10
18
  ## [28.3.0]
11
19
 
12
20
  ### Added
@@ -26,10 +26,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Mocks = exports.Controller = void 0;
29
+ exports.authenticationControllerSelectors = exports.Mocks = exports.Controller = void 0;
30
30
  const AuthenticationController_js_1 = require("./AuthenticationController.cjs");
31
31
  Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return AuthenticationController_js_1.AuthenticationController; } });
32
32
  exports.default = AuthenticationController_js_1.AuthenticationController;
33
33
  __exportStar(require("./AuthenticationController.cjs"), exports);
34
34
  exports.Mocks = __importStar(require("./mocks/index.cjs"));
35
+ var selectors_js_1 = require("./selectors.cjs");
36
+ Object.defineProperty(exports, "authenticationControllerSelectors", { enumerable: true, get: function () { return selectors_js_1.authenticationControllerSelectors; } });
35
37
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAyE;AAEpC,2FAF5B,sDAAwB,OAEc;AAC/C,kBAAe,sDAAwB,CAAC;AACxC,iEAA8C;AAC9C,2DAA0C","sourcesContent":["import { AuthenticationController } from './AuthenticationController.js';\n\nexport { AuthenticationController as Controller };\nexport default AuthenticationController;\nexport * from './AuthenticationController.js';\nexport * as Mocks from './mocks/index.js';\n\nexport type {\n AuthenticationControllerPerformSignInAction,\n AuthenticationControllerPerformSignOutAction,\n AuthenticationControllerGetBearerTokenAction,\n AuthenticationControllerGetSessionProfileAction,\n AuthenticationControllerRefreshCanonicalProfileIdAction,\n AuthenticationControllerGetUserProfileLineageAction,\n AuthenticationControllerIsSignedInAction,\n AuthenticationControllerRequestProfilePairingAction,\n} from './AuthenticationController-method-action-types.js';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAyE;AAEpC,2FAF5B,sDAAwB,OAEc;AAC/C,kBAAe,sDAAwB,CAAC;AACxC,iEAA8C;AAC9C,2DAA0C;AAC1C,gDAAmE;AAA1D,iIAAA,iCAAiC,OAAA","sourcesContent":["import { AuthenticationController } from './AuthenticationController.js';\n\nexport { AuthenticationController as Controller };\nexport default AuthenticationController;\nexport * from './AuthenticationController.js';\nexport * as Mocks from './mocks/index.js';\nexport { authenticationControllerSelectors } from './selectors.js';\n\nexport type {\n AuthenticationControllerPerformSignInAction,\n AuthenticationControllerPerformSignOutAction,\n AuthenticationControllerGetBearerTokenAction,\n AuthenticationControllerGetSessionProfileAction,\n AuthenticationControllerRefreshCanonicalProfileIdAction,\n AuthenticationControllerGetUserProfileLineageAction,\n AuthenticationControllerIsSignedInAction,\n AuthenticationControllerRequestProfilePairingAction,\n} from './AuthenticationController-method-action-types.js';\n"]}
@@ -3,5 +3,6 @@ export { AuthenticationController as Controller };
3
3
  export default AuthenticationController;
4
4
  export * from "./AuthenticationController.cjs";
5
5
  export * as Mocks from "./mocks/index.cjs";
6
+ export { authenticationControllerSelectors } from "./selectors.cjs";
6
7
  export type { AuthenticationControllerPerformSignInAction, AuthenticationControllerPerformSignOutAction, AuthenticationControllerGetBearerTokenAction, AuthenticationControllerGetSessionProfileAction, AuthenticationControllerRefreshCanonicalProfileIdAction, AuthenticationControllerGetUserProfileLineageAction, AuthenticationControllerIsSignedInAction, AuthenticationControllerRequestProfilePairingAction, } from "./AuthenticationController-method-action-types.cjs";
7
8
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,uCAAsC;AAEzE,OAAO,EAAE,wBAAwB,IAAI,UAAU,EAAE,CAAC;AAClD,eAAe,wBAAwB,CAAC;AACxC,+CAA8C;AAC9C,OAAO,KAAK,KAAK,0BAAyB;AAE1C,YAAY,EACV,2CAA2C,EAC3C,4CAA4C,EAC5C,4CAA4C,EAC5C,+CAA+C,EAC/C,uDAAuD,EACvD,mDAAmD,EACnD,wCAAwC,EACxC,mDAAmD,GACpD,2DAA0D"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,uCAAsC;AAEzE,OAAO,EAAE,wBAAwB,IAAI,UAAU,EAAE,CAAC;AAClD,eAAe,wBAAwB,CAAC;AACxC,+CAA8C;AAC9C,OAAO,KAAK,KAAK,0BAAyB;AAC1C,OAAO,EAAE,iCAAiC,EAAE,wBAAuB;AAEnE,YAAY,EACV,2CAA2C,EAC3C,4CAA4C,EAC5C,4CAA4C,EAC5C,+CAA+C,EAC/C,uDAAuD,EACvD,mDAAmD,EACnD,wCAAwC,EACxC,mDAAmD,GACpD,2DAA0D"}
@@ -3,5 +3,6 @@ export { AuthenticationController as Controller };
3
3
  export default AuthenticationController;
4
4
  export * from "./AuthenticationController.mjs";
5
5
  export * as Mocks from "./mocks/index.mjs";
6
+ export { authenticationControllerSelectors } from "./selectors.mjs";
6
7
  export type { AuthenticationControllerPerformSignInAction, AuthenticationControllerPerformSignOutAction, AuthenticationControllerGetBearerTokenAction, AuthenticationControllerGetSessionProfileAction, AuthenticationControllerRefreshCanonicalProfileIdAction, AuthenticationControllerGetUserProfileLineageAction, AuthenticationControllerIsSignedInAction, AuthenticationControllerRequestProfilePairingAction, } from "./AuthenticationController-method-action-types.mjs";
7
8
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,uCAAsC;AAEzE,OAAO,EAAE,wBAAwB,IAAI,UAAU,EAAE,CAAC;AAClD,eAAe,wBAAwB,CAAC;AACxC,+CAA8C;AAC9C,OAAO,KAAK,KAAK,0BAAyB;AAE1C,YAAY,EACV,2CAA2C,EAC3C,4CAA4C,EAC5C,4CAA4C,EAC5C,+CAA+C,EAC/C,uDAAuD,EACvD,mDAAmD,EACnD,wCAAwC,EACxC,mDAAmD,GACpD,2DAA0D"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,uCAAsC;AAEzE,OAAO,EAAE,wBAAwB,IAAI,UAAU,EAAE,CAAC;AAClD,eAAe,wBAAwB,CAAC;AACxC,+CAA8C;AAC9C,OAAO,KAAK,KAAK,0BAAyB;AAC1C,OAAO,EAAE,iCAAiC,EAAE,wBAAuB;AAEnE,YAAY,EACV,2CAA2C,EAC3C,4CAA4C,EAC5C,4CAA4C,EAC5C,+CAA+C,EAC/C,uDAAuD,EACvD,mDAAmD,EACnD,wCAAwC,EACxC,mDAAmD,GACpD,2DAA0D"}
@@ -3,4 +3,5 @@ export { AuthenticationController as Controller };
3
3
  export default AuthenticationController;
4
4
  export * from "./AuthenticationController.mjs";
5
5
  export * as Mocks from "./mocks/index.mjs";
6
+ export { authenticationControllerSelectors } from "./selectors.mjs";
6
7
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,uCAAsC;AAEzE,OAAO,EAAE,wBAAwB,IAAI,UAAU,EAAE,CAAC;AAClD,eAAe,wBAAwB,CAAC;AACxC,+CAA8C;AAC9C,OAAO,KAAK,KAAK,0BAAyB","sourcesContent":["import { AuthenticationController } from './AuthenticationController.js';\n\nexport { AuthenticationController as Controller };\nexport default AuthenticationController;\nexport * from './AuthenticationController.js';\nexport * as Mocks from './mocks/index.js';\n\nexport type {\n AuthenticationControllerPerformSignInAction,\n AuthenticationControllerPerformSignOutAction,\n AuthenticationControllerGetBearerTokenAction,\n AuthenticationControllerGetSessionProfileAction,\n AuthenticationControllerRefreshCanonicalProfileIdAction,\n AuthenticationControllerGetUserProfileLineageAction,\n AuthenticationControllerIsSignedInAction,\n AuthenticationControllerRequestProfilePairingAction,\n} from './AuthenticationController-method-action-types.js';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,uCAAsC;AAEzE,OAAO,EAAE,wBAAwB,IAAI,UAAU,EAAE,CAAC;AAClD,eAAe,wBAAwB,CAAC;AACxC,+CAA8C;AAC9C,OAAO,KAAK,KAAK,0BAAyB;AAC1C,OAAO,EAAE,iCAAiC,EAAE,wBAAuB","sourcesContent":["import { AuthenticationController } from './AuthenticationController.js';\n\nexport { AuthenticationController as Controller };\nexport default AuthenticationController;\nexport * from './AuthenticationController.js';\nexport * as Mocks from './mocks/index.js';\nexport { authenticationControllerSelectors } from './selectors.js';\n\nexport type {\n AuthenticationControllerPerformSignInAction,\n AuthenticationControllerPerformSignOutAction,\n AuthenticationControllerGetBearerTokenAction,\n AuthenticationControllerGetSessionProfileAction,\n AuthenticationControllerRefreshCanonicalProfileIdAction,\n AuthenticationControllerGetUserProfileLineageAction,\n AuthenticationControllerIsSignedInAction,\n AuthenticationControllerRequestProfilePairingAction,\n} from './AuthenticationController-method-action-types.js';\n"]}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authenticationControllerSelectors = void 0;
4
+ /**
5
+ * Selects the raw SRP session map from AuthenticationController state.
6
+ *
7
+ * @param state - The AuthenticationController state.
8
+ * @returns The `srpSessionData` map, or `undefined` when not signed in / cleared.
9
+ */
10
+ const selectSrpSessionData = (state) => state.srpSessionData;
11
+ /**
12
+ * Selects the primary (first) SRP session entry from cached `srpSessionData`.
13
+ *
14
+ * Uses the first `Object.entries` value — the same "primary / first written"
15
+ * convention as extension `selectSessionData`. During `performSignIn`, sessions
16
+ * are written sequentially with the primary SRP first.
17
+ *
18
+ * @param state - The AuthenticationController state.
19
+ * @returns The primary session login response, or `undefined` if unavailable.
20
+ */
21
+ const selectSessionData = (state) => {
22
+ const srpSessionData = selectSrpSessionData(state);
23
+ if (!srpSessionData) {
24
+ return undefined;
25
+ }
26
+ const firstEntry = Object.entries(srpSessionData)[0];
27
+ return firstEntry?.[1];
28
+ };
29
+ /**
30
+ * Selects the best-effort cached canonical profile ID.
31
+ *
32
+ * Reads from the primary SRP session in `srpSessionData` without triggering
33
+ * login or unlock checks. Suitable for non-security consumers.
34
+ *
35
+ * Empty string is treated as missing (`undefined`) because the controller sets
36
+ * `canonicalProfileId` to `''` when invalidating a session
37
+ * (`#invalidateSrpSession`).
38
+ *
39
+ * Staleness: same as a valid cached `getSessionProfile()` result. Cross-device
40
+ * pairing can change the canonical without updating this cache until the next
41
+ * login or pair. Use `refreshCanonicalProfileId()` when freshness is required.
42
+ *
43
+ * @param state - The AuthenticationController state.
44
+ * @returns The cached canonical profile ID, or `undefined` if unavailable.
45
+ */
46
+ const selectCanonicalProfileId = (state) => {
47
+ const canonicalProfileId = selectSessionData(state)?.profile?.canonicalProfileId;
48
+ // `''` is used by `#invalidateSrpSession` to mark the session as invalid.
49
+ if (!canonicalProfileId) {
50
+ return undefined;
51
+ }
52
+ return canonicalProfileId;
53
+ };
54
+ /**
55
+ * Selectors for AuthenticationController state.
56
+ * These take controller state (not client `RootState`) and can be composed
57
+ * with Redux `createSelector` in clients.
58
+ */
59
+ exports.authenticationControllerSelectors = {
60
+ selectSrpSessionData,
61
+ selectSessionData,
62
+ selectCanonicalProfileId,
63
+ };
64
+ //# sourceMappingURL=selectors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../../../src/controllers/authentication/selectors.ts"],"names":[],"mappings":";;;AAGA;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,CAC3B,KAAoC,EACa,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC;AAE3E;;;;;;;;;GASG;AACH,MAAM,iBAAiB,GAAG,CACxB,KAAoC,EACT,EAAE;IAC7B,MAAM,cAAc,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,OAAO,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,wBAAwB,GAAG,CAC/B,KAAoC,EAChB,EAAE;IACtB,MAAM,kBAAkB,GACtB,iBAAiB,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC;IACxD,0EAA0E;IAC1E,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC;AAEF;;;;GAIG;AACU,QAAA,iCAAiC,GAAG;IAC/C,oBAAoB;IACpB,iBAAiB;IACjB,wBAAwB;CACzB,CAAC","sourcesContent":["import type { LoginResponse } from '../../sdk/index.js';\nimport type { AuthenticationControllerState } from './AuthenticationController.js';\n\n/**\n * Selects the raw SRP session map from AuthenticationController state.\n *\n * @param state - The AuthenticationController state.\n * @returns The `srpSessionData` map, or `undefined` when not signed in / cleared.\n */\nconst selectSrpSessionData = (\n state: AuthenticationControllerState,\n): AuthenticationControllerState['srpSessionData'] => state.srpSessionData;\n\n/**\n * Selects the primary (first) SRP session entry from cached `srpSessionData`.\n *\n * Uses the first `Object.entries` value — the same \"primary / first written\"\n * convention as extension `selectSessionData`. During `performSignIn`, sessions\n * are written sequentially with the primary SRP first.\n *\n * @param state - The AuthenticationController state.\n * @returns The primary session login response, or `undefined` if unavailable.\n */\nconst selectSessionData = (\n state: AuthenticationControllerState,\n): LoginResponse | undefined => {\n const srpSessionData = selectSrpSessionData(state);\n if (!srpSessionData) {\n return undefined;\n }\n const firstEntry = Object.entries(srpSessionData)[0];\n return firstEntry?.[1];\n};\n\n/**\n * Selects the best-effort cached canonical profile ID.\n *\n * Reads from the primary SRP session in `srpSessionData` without triggering\n * login or unlock checks. Suitable for non-security consumers.\n *\n * Empty string is treated as missing (`undefined`) because the controller sets\n * `canonicalProfileId` to `''` when invalidating a session\n * (`#invalidateSrpSession`).\n *\n * Staleness: same as a valid cached `getSessionProfile()` result. Cross-device\n * pairing can change the canonical without updating this cache until the next\n * login or pair. Use `refreshCanonicalProfileId()` when freshness is required.\n *\n * @param state - The AuthenticationController state.\n * @returns The cached canonical profile ID, or `undefined` if unavailable.\n */\nconst selectCanonicalProfileId = (\n state: AuthenticationControllerState,\n): string | undefined => {\n const canonicalProfileId =\n selectSessionData(state)?.profile?.canonicalProfileId;\n // `''` is used by `#invalidateSrpSession` to mark the session as invalid.\n if (!canonicalProfileId) {\n return undefined;\n }\n return canonicalProfileId;\n};\n\n/**\n * Selectors for AuthenticationController state.\n * These take controller state (not client `RootState`) and can be composed\n * with Redux `createSelector` in clients.\n */\nexport const authenticationControllerSelectors = {\n selectSrpSessionData,\n selectSessionData,\n selectCanonicalProfileId,\n};\n"]}
@@ -0,0 +1,13 @@
1
+ import type { LoginResponse } from "../../sdk/index.cjs";
2
+ import type { AuthenticationControllerState } from "./AuthenticationController.cjs";
3
+ /**
4
+ * Selectors for AuthenticationController state.
5
+ * These take controller state (not client `RootState`) and can be composed
6
+ * with Redux `createSelector` in clients.
7
+ */
8
+ export declare const authenticationControllerSelectors: {
9
+ selectSrpSessionData: (state: AuthenticationControllerState) => AuthenticationControllerState['srpSessionData'];
10
+ selectSessionData: (state: AuthenticationControllerState) => LoginResponse | undefined;
11
+ selectCanonicalProfileId: (state: AuthenticationControllerState) => string | undefined;
12
+ };
13
+ //# sourceMappingURL=selectors.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../../../src/controllers/authentication/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,4BAA2B;AACxD,OAAO,KAAK,EAAE,6BAA6B,EAAE,uCAAsC;AA8DnF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC;kCA1DrC,6BAA6B,KACnC,6BAA6B,CAAC,gBAAgB,CAAC;+BAazC,6BAA6B,KACnC,aAAa,GAAG,SAAS;sCA2BnB,6BAA6B,KACnC,MAAM,GAAG,SAAS;CAmBpB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { LoginResponse } from "../../sdk/index.mjs";
2
+ import type { AuthenticationControllerState } from "./AuthenticationController.mjs";
3
+ /**
4
+ * Selectors for AuthenticationController state.
5
+ * These take controller state (not client `RootState`) and can be composed
6
+ * with Redux `createSelector` in clients.
7
+ */
8
+ export declare const authenticationControllerSelectors: {
9
+ selectSrpSessionData: (state: AuthenticationControllerState) => AuthenticationControllerState['srpSessionData'];
10
+ selectSessionData: (state: AuthenticationControllerState) => LoginResponse | undefined;
11
+ selectCanonicalProfileId: (state: AuthenticationControllerState) => string | undefined;
12
+ };
13
+ //# sourceMappingURL=selectors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../../../src/controllers/authentication/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,4BAA2B;AACxD,OAAO,KAAK,EAAE,6BAA6B,EAAE,uCAAsC;AA8DnF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC;kCA1DrC,6BAA6B,KACnC,6BAA6B,CAAC,gBAAgB,CAAC;+BAazC,6BAA6B,KACnC,aAAa,GAAG,SAAS;sCA2BnB,6BAA6B,KACnC,MAAM,GAAG,SAAS;CAmBpB,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Selects the raw SRP session map from AuthenticationController state.
3
+ *
4
+ * @param state - The AuthenticationController state.
5
+ * @returns The `srpSessionData` map, or `undefined` when not signed in / cleared.
6
+ */
7
+ const selectSrpSessionData = (state) => state.srpSessionData;
8
+ /**
9
+ * Selects the primary (first) SRP session entry from cached `srpSessionData`.
10
+ *
11
+ * Uses the first `Object.entries` value — the same "primary / first written"
12
+ * convention as extension `selectSessionData`. During `performSignIn`, sessions
13
+ * are written sequentially with the primary SRP first.
14
+ *
15
+ * @param state - The AuthenticationController state.
16
+ * @returns The primary session login response, or `undefined` if unavailable.
17
+ */
18
+ const selectSessionData = (state) => {
19
+ const srpSessionData = selectSrpSessionData(state);
20
+ if (!srpSessionData) {
21
+ return undefined;
22
+ }
23
+ const firstEntry = Object.entries(srpSessionData)[0];
24
+ return firstEntry?.[1];
25
+ };
26
+ /**
27
+ * Selects the best-effort cached canonical profile ID.
28
+ *
29
+ * Reads from the primary SRP session in `srpSessionData` without triggering
30
+ * login or unlock checks. Suitable for non-security consumers.
31
+ *
32
+ * Empty string is treated as missing (`undefined`) because the controller sets
33
+ * `canonicalProfileId` to `''` when invalidating a session
34
+ * (`#invalidateSrpSession`).
35
+ *
36
+ * Staleness: same as a valid cached `getSessionProfile()` result. Cross-device
37
+ * pairing can change the canonical without updating this cache until the next
38
+ * login or pair. Use `refreshCanonicalProfileId()` when freshness is required.
39
+ *
40
+ * @param state - The AuthenticationController state.
41
+ * @returns The cached canonical profile ID, or `undefined` if unavailable.
42
+ */
43
+ const selectCanonicalProfileId = (state) => {
44
+ const canonicalProfileId = selectSessionData(state)?.profile?.canonicalProfileId;
45
+ // `''` is used by `#invalidateSrpSession` to mark the session as invalid.
46
+ if (!canonicalProfileId) {
47
+ return undefined;
48
+ }
49
+ return canonicalProfileId;
50
+ };
51
+ /**
52
+ * Selectors for AuthenticationController state.
53
+ * These take controller state (not client `RootState`) and can be composed
54
+ * with Redux `createSelector` in clients.
55
+ */
56
+ export const authenticationControllerSelectors = {
57
+ selectSrpSessionData,
58
+ selectSessionData,
59
+ selectCanonicalProfileId,
60
+ };
61
+ //# sourceMappingURL=selectors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../../../src/controllers/authentication/selectors.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,CAC3B,KAAoC,EACa,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC;AAE3E;;;;;;;;;GASG;AACH,MAAM,iBAAiB,GAAG,CACxB,KAAoC,EACT,EAAE;IAC7B,MAAM,cAAc,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,OAAO,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,wBAAwB,GAAG,CAC/B,KAAoC,EAChB,EAAE;IACtB,MAAM,kBAAkB,GACtB,iBAAiB,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC;IACxD,0EAA0E;IAC1E,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG;IAC/C,oBAAoB;IACpB,iBAAiB;IACjB,wBAAwB;CACzB,CAAC","sourcesContent":["import type { LoginResponse } from '../../sdk/index.js';\nimport type { AuthenticationControllerState } from './AuthenticationController.js';\n\n/**\n * Selects the raw SRP session map from AuthenticationController state.\n *\n * @param state - The AuthenticationController state.\n * @returns The `srpSessionData` map, or `undefined` when not signed in / cleared.\n */\nconst selectSrpSessionData = (\n state: AuthenticationControllerState,\n): AuthenticationControllerState['srpSessionData'] => state.srpSessionData;\n\n/**\n * Selects the primary (first) SRP session entry from cached `srpSessionData`.\n *\n * Uses the first `Object.entries` value — the same \"primary / first written\"\n * convention as extension `selectSessionData`. During `performSignIn`, sessions\n * are written sequentially with the primary SRP first.\n *\n * @param state - The AuthenticationController state.\n * @returns The primary session login response, or `undefined` if unavailable.\n */\nconst selectSessionData = (\n state: AuthenticationControllerState,\n): LoginResponse | undefined => {\n const srpSessionData = selectSrpSessionData(state);\n if (!srpSessionData) {\n return undefined;\n }\n const firstEntry = Object.entries(srpSessionData)[0];\n return firstEntry?.[1];\n};\n\n/**\n * Selects the best-effort cached canonical profile ID.\n *\n * Reads from the primary SRP session in `srpSessionData` without triggering\n * login or unlock checks. Suitable for non-security consumers.\n *\n * Empty string is treated as missing (`undefined`) because the controller sets\n * `canonicalProfileId` to `''` when invalidating a session\n * (`#invalidateSrpSession`).\n *\n * Staleness: same as a valid cached `getSessionProfile()` result. Cross-device\n * pairing can change the canonical without updating this cache until the next\n * login or pair. Use `refreshCanonicalProfileId()` when freshness is required.\n *\n * @param state - The AuthenticationController state.\n * @returns The cached canonical profile ID, or `undefined` if unavailable.\n */\nconst selectCanonicalProfileId = (\n state: AuthenticationControllerState,\n): string | undefined => {\n const canonicalProfileId =\n selectSessionData(state)?.profile?.canonicalProfileId;\n // `''` is used by `#invalidateSrpSession` to mark the session as invalid.\n if (!canonicalProfileId) {\n return undefined;\n }\n return canonicalProfileId;\n};\n\n/**\n * Selectors for AuthenticationController state.\n * These take controller state (not client `RootState`) and can be composed\n * with Redux `createSelector` in clients.\n */\nexport const authenticationControllerSelectors = {\n selectSrpSessionData,\n selectSessionData,\n selectCanonicalProfileId,\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/profile-sync-controller",
3
- "version": "28.3.0-preview-0d2cbf546",
3
+ "version": "28.3.0-preview-064aea96d",
4
4
  "description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
5
5
  "keywords": [
6
6
  "Ethereum",