@metamask-previews/profile-sync-controller 32.1.1-preview-db287901b → 32.1.1-preview-d3f9964be

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.ts +38 -1
  3. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.ts.map +1 -1
  4. package/dist/controllers/authentication/AuthenticationController-method-action-types.js.map +1 -1
  5. package/dist/controllers/authentication/AuthenticationController.d.ts +38 -2
  6. package/dist/controllers/authentication/AuthenticationController.d.ts.map +1 -1
  7. package/dist/controllers/authentication/AuthenticationController.js +185 -7
  8. package/dist/controllers/authentication/AuthenticationController.js.map +1 -1
  9. package/dist/controllers/authentication/index.d.ts +1 -1
  10. package/dist/controllers/authentication/index.d.ts.map +1 -1
  11. package/dist/controllers/authentication/index.js.map +1 -1
  12. package/dist/controllers/authentication/mocks/mockResponses.d.ts +5 -0
  13. package/dist/controllers/authentication/mocks/mockResponses.d.ts.map +1 -1
  14. package/dist/controllers/authentication/mocks/mockResponses.js +26 -1
  15. package/dist/controllers/authentication/mocks/mockResponses.js.map +1 -1
  16. package/dist/controllers/user-storage/UserStorageController.d.ts.map +1 -1
  17. package/dist/controllers/user-storage/UserStorageController.js +6 -5
  18. package/dist/controllers/user-storage/UserStorageController.js.map +1 -1
  19. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts +56 -1
  20. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +1 -1
  21. package/dist/sdk/authentication-jwt-bearer/flow-srp.js +119 -1
  22. package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +1 -1
  23. package/dist/sdk/authentication-jwt-bearer/mfa/schemas.d.ts +691 -0
  24. package/dist/sdk/authentication-jwt-bearer/mfa/schemas.d.ts.map +1 -0
  25. package/dist/sdk/authentication-jwt-bearer/mfa/schemas.js +265 -0
  26. package/dist/sdk/authentication-jwt-bearer/mfa/schemas.js.map +1 -0
  27. package/dist/sdk/authentication-jwt-bearer/mfa/services.d.ts +104 -0
  28. package/dist/sdk/authentication-jwt-bearer/mfa/services.d.ts.map +1 -0
  29. package/dist/sdk/authentication-jwt-bearer/mfa/services.js +363 -0
  30. package/dist/sdk/authentication-jwt-bearer/mfa/services.js.map +1 -0
  31. package/dist/sdk/authentication-jwt-bearer/mfa/types.d.ts +125 -0
  32. package/dist/sdk/authentication-jwt-bearer/mfa/types.d.ts.map +1 -0
  33. package/dist/sdk/authentication-jwt-bearer/mfa/types.js +3 -0
  34. package/dist/sdk/authentication-jwt-bearer/mfa/types.js.map +1 -0
  35. package/dist/sdk/authentication.d.ts +15 -6
  36. package/dist/sdk/authentication.d.ts.map +1 -1
  37. package/dist/sdk/authentication.js +24 -0
  38. package/dist/sdk/authentication.js.map +1 -1
  39. package/dist/sdk/constants.d.ts +2 -0
  40. package/dist/sdk/constants.d.ts.map +1 -1
  41. package/dist/sdk/constants.js +2 -0
  42. package/dist/sdk/constants.js.map +1 -1
  43. package/dist/sdk/errors.d.ts +91 -0
  44. package/dist/sdk/errors.d.ts.map +1 -1
  45. package/dist/sdk/errors.js +161 -0
  46. package/dist/sdk/errors.js.map +1 -1
  47. package/dist/sdk/index.d.ts +3 -0
  48. package/dist/sdk/index.d.ts.map +1 -1
  49. package/dist/sdk/index.js +1 -0
  50. package/dist/sdk/index.js.map +1 -1
  51. package/dist/sdk/mocks/auth.d.ts +63 -0
  52. package/dist/sdk/mocks/auth.d.ts.map +1 -1
  53. package/dist/sdk/mocks/auth.js +90 -0
  54. package/dist/sdk/mocks/auth.js.map +1 -1
  55. package/dist/sdk/utils/as-record.d.ts +10 -0
  56. package/dist/sdk/utils/as-record.d.ts.map +1 -0
  57. package/dist/sdk/utils/as-record.js +14 -0
  58. package/dist/sdk/utils/as-record.js.map +1 -0
  59. package/dist/sdk/utils/jwt.d.ts +13 -0
  60. package/dist/sdk/utils/jwt.d.ts.map +1 -0
  61. package/dist/sdk/utils/jwt.js +21 -0
  62. package/dist/sdk/utils/jwt.js.map +1 -0
  63. package/dist/sdk/utils/to-error-message.d.ts +8 -0
  64. package/dist/sdk/utils/to-error-message.d.ts.map +1 -0
  65. package/dist/sdk/utils/to-error-message.js +10 -0
  66. package/dist/sdk/utils/to-error-message.js.map +1 -0
  67. package/dist/sdk/utils/validate-login-response.d.ts.map +1 -1
  68. package/dist/sdk/utils/validate-login-response.js +5 -7
  69. package/dist/sdk/utils/validate-login-response.js.map +1 -1
  70. package/dist/shared/utils/entropy-source.d.ts +3 -12
  71. package/dist/shared/utils/entropy-source.d.ts.map +1 -1
  72. package/dist/shared/utils/entropy-source.js +4 -17
  73. package/dist/shared/utils/entropy-source.js.map +1 -1
  74. package/package.json +4 -1
package/CHANGELOG.md CHANGED
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Added
11
11
 
12
+ - Add `refreshEnrolledCredentials`, `beginCredentialEnrollment` and `completeCredentialEnrollment` to `AuthenticationController`, backed by a memory-only `enrolledCredentials` state and an optional `trace` callback ([#10266](https://github.com/MetaMask/core/pull/10266))
13
+ - Add passkey and email OTP enrollment, verification, credential-list, and elevated-token exchange SDK methods ([#10265](https://github.com/MetaMask/core/pull/10265))
14
+ - Add validated MFA domain types and structured `MfaError` classes with a serialization-safe `mfaCode` ([#10264](https://github.com/MetaMask/core/pull/10264))
12
15
  - Add `rampsOrders` to `USER_STORAGE_FEATURE_NAMES` ([#10227](https://github.com/MetaMask/core/pull/10227))
13
16
 
14
17
  ## [32.1.1]
@@ -16,6 +16,43 @@ export type AuthenticationControllerRequestProfilePairingAction = {
16
16
  type: `AuthenticationController:requestProfilePairing`;
17
17
  handler: AuthenticationController['requestProfilePairing'];
18
18
  };
19
+ /**
20
+ * Refreshes credentials enrolled on the canonical profile.
21
+ *
22
+ * @returns The current supported credentials.
23
+ */
24
+ export type AuthenticationControllerRefreshEnrolledCredentialsAction = {
25
+ type: `AuthenticationController:refreshEnrolledCredentials`;
26
+ handler: AuthenticationController['refreshEnrolledCredentials'];
27
+ };
28
+ /**
29
+ * Begins enrollment of a passkey or email OTP credential.
30
+ *
31
+ * @param request - Credential, optional email address, and trace reason.
32
+ * @returns A challenge for the client-owned ceremony.
33
+ */
34
+ export type AuthenticationControllerBeginCredentialEnrollmentAction = {
35
+ type: `AuthenticationController:beginCredentialEnrollment`;
36
+ handler: AuthenticationController['beginCredentialEnrollment'];
37
+ };
38
+ /**
39
+ * Completes credential enrollment and refreshes the credential cache.
40
+ *
41
+ * A cache-refresh failure does not undo successful enrollment. Email
42
+ * enrollment invalidates the primary SRP session *after* refresh so the
43
+ * credentials call can reuse the still-valid access token; the next token
44
+ * fetch then includes the newly verified email claim. That invalidation
45
+ * happens even if the session ends mid-request: the enrollment succeeded
46
+ * on the server, so a token cached across a lock must not be reused
47
+ * without the new claim.
48
+ *
49
+ * @param request - Flow identifier, platform or email proof, and trace reason.
50
+ * @returns The refreshed credentials, or the existing cache if refresh fails.
51
+ */
52
+ export type AuthenticationControllerCompleteCredentialEnrollmentAction = {
53
+ type: `AuthenticationController:completeCredentialEnrollment`;
54
+ handler: AuthenticationController['completeCredentialEnrollment'];
55
+ };
19
56
  export type AuthenticationControllerPerformSignOutAction = {
20
57
  type: `AuthenticationController:performSignOut`;
21
58
  handler: AuthenticationController['performSignOut'];
@@ -123,5 +160,5 @@ export type AuthenticationControllerIsSignedInAction = {
123
160
  /**
124
161
  * Union of all AuthenticationController action types.
125
162
  */
126
- export type AuthenticationControllerMethodActions = AuthenticationControllerPerformSignInAction | AuthenticationControllerRequestProfilePairingAction | AuthenticationControllerPerformSignOutAction | AuthenticationControllerClearStateAction | AuthenticationControllerGetBearerTokenAction | AuthenticationControllerGetSessionProfileAction | AuthenticationControllerRefreshCanonicalProfileIdAction | AuthenticationControllerGetUserProfileLineageAction | AuthenticationControllerGetCustomerServiceTokenAction | AuthenticationControllerGetPartnerIdentityTokenAction | AuthenticationControllerIsSignedInAction;
163
+ export type AuthenticationControllerMethodActions = AuthenticationControllerPerformSignInAction | AuthenticationControllerRequestProfilePairingAction | AuthenticationControllerRefreshEnrolledCredentialsAction | AuthenticationControllerBeginCredentialEnrollmentAction | AuthenticationControllerCompleteCredentialEnrollmentAction | AuthenticationControllerPerformSignOutAction | AuthenticationControllerClearStateAction | AuthenticationControllerGetBearerTokenAction | AuthenticationControllerGetSessionProfileAction | AuthenticationControllerRefreshCanonicalProfileIdAction | AuthenticationControllerGetUserProfileLineageAction | AuthenticationControllerGetCustomerServiceTokenAction | AuthenticationControllerGetPartnerIdentityTokenAction | AuthenticationControllerIsSignedInAction;
127
164
  //# sourceMappingURL=AuthenticationController-method-action-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthenticationController-method-action-types.d.ts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC;CACpD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mDAAmD,GAAG;IAChE,IAAI,EAAE,gDAAgD,CAAC;IACvD,OAAO,EAAE,wBAAwB,CAAC,uBAAuB,CAAC,CAAC;CAC5D,CAAC;AAEF,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;CACrD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,wBAAwB,CAAC,YAAY,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,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":"AuthenticationController-method-action-types.d.ts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC;CACpD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mDAAmD,GAAG;IAChE,IAAI,EAAE,gDAAgD,CAAC;IACvD,OAAO,EAAE,wBAAwB,CAAC,uBAAuB,CAAC,CAAC;CAC5D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,wDAAwD,GAAG;IACrE,IAAI,EAAE,qDAAqD,CAAC;IAC5D,OAAO,EAAE,wBAAwB,CAAC,4BAA4B,CAAC,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,wBAAwB,CAAC,2BAA2B,CAAC,CAAC;CAChE,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,0DAA0D,GAAG;IACvE,IAAI,EAAE,uDAAuD,CAAC;IAC9D,OAAO,EAAE,wBAAwB,CAAC,8BAA8B,CAAC,CAAC;CACnE,CAAC;AAEF,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;CACrD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,wBAAwB,CAAC,YAAY,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE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
1
- {"version":3,"file":"AuthenticationController-method-action-types.js","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AuthenticationController } from './AuthenticationController.js';\n\nexport type AuthenticationControllerPerformSignInAction = {\n type: `AuthenticationController:performSignIn`;\n handler: AuthenticationController['performSignIn'];\n};\n\n/**\n * Marks profile pairing as needed. Clients call this when the SRP set\n * changes (e.g. a new keyring was added) so the next auto-sign-in cycle\n * re-runs `performSignIn` and re-pairs.\n */\nexport type AuthenticationControllerRequestProfilePairingAction = {\n type: `AuthenticationController:requestProfilePairing`;\n handler: AuthenticationController['requestProfilePairing'];\n};\n\nexport type AuthenticationControllerPerformSignOutAction = {\n type: `AuthenticationController:performSignOut`;\n handler: AuthenticationController['performSignOut'];\n};\n\n/**\n * Resets the controller to `defaultState`. Clients call this on wallet reset\n * so the next wallet starts unsigned with both pairing gates re-armed.\n */\nexport type AuthenticationControllerClearStateAction = {\n type: `AuthenticationController:clearState`;\n handler: AuthenticationController['clearState'];\n};\n\n/**\n * Returns a bearer token for the specified SRP, logging in if needed.\n *\n * When called without `entropySourceId`, returns the primary (first) SRP's\n * access token, which is effectively the canonical\n * profile's token that can be used by alias-aware consumers for cross-SRP\n * operations.\n *\n * @param entropySourceId - The entropy source ID. Omit for the primary SRP.\n * @returns The OIDC access token.\n */\nexport type AuthenticationControllerGetBearerTokenAction = {\n type: `AuthenticationController:getBearerToken`;\n handler: AuthenticationController['getBearerToken'];\n};\n\n/**\n * Returns the cached session profile, logging in if no session exists.\n *\n * The returned `canonicalProfileId` reflects the value from the most recent\n * login or pairing. In the rare event where a canonical changed because of\n * a pairing that happened on another device, the cached value may be stale\n * until the next login. For guaranteed freshness, call\n * `refreshCanonicalProfileId()` before reading `canonicalProfileId`.\n *\n * @param entropySourceId - The entropy source ID used to derive the key,\n * when multiple sources are available (Multi-SRP).\n * @returns profile for the session.\n */\nexport type AuthenticationControllerGetSessionProfileAction = {\n type: `AuthenticationController:getSessionProfile`;\n handler: AuthenticationController['getSessionProfile'];\n};\n\n/**\n * Forces a fresh retrieval of the canonical profile ID from the server\n * and propagates it to all cached SRP sessions.\n *\n * This method invalidates the primary SRP's cached session and forces a\n * re-login. Use it before operations that require a guaranteed-fresh\n * canonical (e.g. storage key derivation for Accounts ADR 0005). For\n * best-effort reads, use\n * `getSessionProfile().canonicalProfileId` instead.\n *\n * Only the primary SRP is re-logged-in regardless of how many SRPs exist —\n * the server returns the current canonical for the entire pairing group\n * from any single SRP login.\n *\n * @returns The refreshed canonical profile ID.\n */\nexport type AuthenticationControllerRefreshCanonicalProfileIdAction = {\n type: `AuthenticationController:refreshCanonicalProfileId`;\n handler: AuthenticationController['refreshCanonicalProfileId'];\n};\n\nexport type AuthenticationControllerGetUserProfileLineageAction = {\n type: `AuthenticationController:getUserProfileLineage`;\n handler: AuthenticationController['getUserProfileLineage'];\n};\n\n/**\n * Returns a Customer Service specific access token for the specified SRP,\n * logging in if needed.\n *\n * Exchanges the OIDC access token for a short-lived token scoped to the\n * customer-service audience. Customer Service tooling consumes this token to\n * identify and authenticate the user.\n *\n * @param entropySourceId - The entropy source ID. Omit for the primary SRP.\n * @returns The customer-service access token.\n */\nexport type AuthenticationControllerGetCustomerServiceTokenAction = {\n type: `AuthenticationController:getCustomerServiceToken`;\n handler: AuthenticationController['getCustomerServiceToken'];\n};\n\n/**\n * Mints a partner identity token for the specified SRP, logging in if needed.\n *\n * Calls `POST /api/v2/oidc/token` with the Hydra login bearer and returns\n * the minted `access_token`. Email on live tokens is under JWT `ext`.\n * HTTP 422 throws `EmailRequiredError` when this profile has no\n * verified email.\n *\n * @param claims - Claim names to embed. Only `email` is supported.\n * @param audience - Partner audience (`kyc` or `iron`).\n * @param entropySourceId - The entropy source ID. Omit for the primary SRP.\n * @returns The partner identity access token.\n */\nexport type AuthenticationControllerGetPartnerIdentityTokenAction = {\n type: `AuthenticationController:getPartnerIdentityToken`;\n handler: AuthenticationController['getPartnerIdentityToken'];\n};\n\nexport type AuthenticationControllerIsSignedInAction = {\n type: `AuthenticationController:isSignedIn`;\n handler: AuthenticationController['isSignedIn'];\n};\n\n/**\n * Union of all AuthenticationController action types.\n */\nexport type AuthenticationControllerMethodActions =\n | AuthenticationControllerPerformSignInAction\n | AuthenticationControllerRequestProfilePairingAction\n | AuthenticationControllerPerformSignOutAction\n | AuthenticationControllerClearStateAction\n | AuthenticationControllerGetBearerTokenAction\n | AuthenticationControllerGetSessionProfileAction\n | AuthenticationControllerRefreshCanonicalProfileIdAction\n | AuthenticationControllerGetUserProfileLineageAction\n | AuthenticationControllerGetCustomerServiceTokenAction\n | AuthenticationControllerGetPartnerIdentityTokenAction\n | AuthenticationControllerIsSignedInAction;\n"]}
1
+ {"version":3,"file":"AuthenticationController-method-action-types.js","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AuthenticationController } from './AuthenticationController.js';\n\nexport type AuthenticationControllerPerformSignInAction = {\n type: `AuthenticationController:performSignIn`;\n handler: AuthenticationController['performSignIn'];\n};\n\n/**\n * Marks profile pairing as needed. Clients call this when the SRP set\n * changes (e.g. a new keyring was added) so the next auto-sign-in cycle\n * re-runs `performSignIn` and re-pairs.\n */\nexport type AuthenticationControllerRequestProfilePairingAction = {\n type: `AuthenticationController:requestProfilePairing`;\n handler: AuthenticationController['requestProfilePairing'];\n};\n\n/**\n * Refreshes credentials enrolled on the canonical profile.\n *\n * @returns The current supported credentials.\n */\nexport type AuthenticationControllerRefreshEnrolledCredentialsAction = {\n type: `AuthenticationController:refreshEnrolledCredentials`;\n handler: AuthenticationController['refreshEnrolledCredentials'];\n};\n\n/**\n * Begins enrollment of a passkey or email OTP credential.\n *\n * @param request - Credential, optional email address, and trace reason.\n * @returns A challenge for the client-owned ceremony.\n */\nexport type AuthenticationControllerBeginCredentialEnrollmentAction = {\n type: `AuthenticationController:beginCredentialEnrollment`;\n handler: AuthenticationController['beginCredentialEnrollment'];\n};\n\n/**\n * Completes credential enrollment and refreshes the credential cache.\n *\n * A cache-refresh failure does not undo successful enrollment. Email\n * enrollment invalidates the primary SRP session *after* refresh so the\n * credentials call can reuse the still-valid access token; the next token\n * fetch then includes the newly verified email claim. That invalidation\n * happens even if the session ends mid-request: the enrollment succeeded\n * on the server, so a token cached across a lock must not be reused\n * without the new claim.\n *\n * @param request - Flow identifier, platform or email proof, and trace reason.\n * @returns The refreshed credentials, or the existing cache if refresh fails.\n */\nexport type AuthenticationControllerCompleteCredentialEnrollmentAction = {\n type: `AuthenticationController:completeCredentialEnrollment`;\n handler: AuthenticationController['completeCredentialEnrollment'];\n};\n\nexport type AuthenticationControllerPerformSignOutAction = {\n type: `AuthenticationController:performSignOut`;\n handler: AuthenticationController['performSignOut'];\n};\n\n/**\n * Resets the controller to `defaultState`. Clients call this on wallet reset\n * so the next wallet starts unsigned with both pairing gates re-armed.\n */\nexport type AuthenticationControllerClearStateAction = {\n type: `AuthenticationController:clearState`;\n handler: AuthenticationController['clearState'];\n};\n\n/**\n * Returns a bearer token for the specified SRP, logging in if needed.\n *\n * When called without `entropySourceId`, returns the primary (first) SRP's\n * access token, which is effectively the canonical\n * profile's token that can be used by alias-aware consumers for cross-SRP\n * operations.\n *\n * @param entropySourceId - The entropy source ID. Omit for the primary SRP.\n * @returns The OIDC access token.\n */\nexport type AuthenticationControllerGetBearerTokenAction = {\n type: `AuthenticationController:getBearerToken`;\n handler: AuthenticationController['getBearerToken'];\n};\n\n/**\n * Returns the cached session profile, logging in if no session exists.\n *\n * The returned `canonicalProfileId` reflects the value from the most recent\n * login or pairing. In the rare event where a canonical changed because of\n * a pairing that happened on another device, the cached value may be stale\n * until the next login. For guaranteed freshness, call\n * `refreshCanonicalProfileId()` before reading `canonicalProfileId`.\n *\n * @param entropySourceId - The entropy source ID used to derive the key,\n * when multiple sources are available (Multi-SRP).\n * @returns profile for the session.\n */\nexport type AuthenticationControllerGetSessionProfileAction = {\n type: `AuthenticationController:getSessionProfile`;\n handler: AuthenticationController['getSessionProfile'];\n};\n\n/**\n * Forces a fresh retrieval of the canonical profile ID from the server\n * and propagates it to all cached SRP sessions.\n *\n * This method invalidates the primary SRP's cached session and forces a\n * re-login. Use it before operations that require a guaranteed-fresh\n * canonical (e.g. storage key derivation for Accounts ADR 0005). For\n * best-effort reads, use\n * `getSessionProfile().canonicalProfileId` instead.\n *\n * Only the primary SRP is re-logged-in regardless of how many SRPs exist —\n * the server returns the current canonical for the entire pairing group\n * from any single SRP login.\n *\n * @returns The refreshed canonical profile ID.\n */\nexport type AuthenticationControllerRefreshCanonicalProfileIdAction = {\n type: `AuthenticationController:refreshCanonicalProfileId`;\n handler: AuthenticationController['refreshCanonicalProfileId'];\n};\n\nexport type AuthenticationControllerGetUserProfileLineageAction = {\n type: `AuthenticationController:getUserProfileLineage`;\n handler: AuthenticationController['getUserProfileLineage'];\n};\n\n/**\n * Returns a Customer Service specific access token for the specified SRP,\n * logging in if needed.\n *\n * Exchanges the OIDC access token for a short-lived token scoped to the\n * customer-service audience. Customer Service tooling consumes this token to\n * identify and authenticate the user.\n *\n * @param entropySourceId - The entropy source ID. Omit for the primary SRP.\n * @returns The customer-service access token.\n */\nexport type AuthenticationControllerGetCustomerServiceTokenAction = {\n type: `AuthenticationController:getCustomerServiceToken`;\n handler: AuthenticationController['getCustomerServiceToken'];\n};\n\n/**\n * Mints a partner identity token for the specified SRP, logging in if needed.\n *\n * Calls `POST /api/v2/oidc/token` with the Hydra login bearer and returns\n * the minted `access_token`. Email on live tokens is under JWT `ext`.\n * HTTP 422 throws `EmailRequiredError` when this profile has no\n * verified email.\n *\n * @param claims - Claim names to embed. Only `email` is supported.\n * @param audience - Partner audience (`kyc` or `iron`).\n * @param entropySourceId - The entropy source ID. Omit for the primary SRP.\n * @returns The partner identity access token.\n */\nexport type AuthenticationControllerGetPartnerIdentityTokenAction = {\n type: `AuthenticationController:getPartnerIdentityToken`;\n handler: AuthenticationController['getPartnerIdentityToken'];\n};\n\nexport type AuthenticationControllerIsSignedInAction = {\n type: `AuthenticationController:isSignedIn`;\n handler: AuthenticationController['isSignedIn'];\n};\n\n/**\n * Union of all AuthenticationController action types.\n */\nexport type AuthenticationControllerMethodActions =\n | AuthenticationControllerPerformSignInAction\n | AuthenticationControllerRequestProfilePairingAction\n | AuthenticationControllerRefreshEnrolledCredentialsAction\n | AuthenticationControllerBeginCredentialEnrollmentAction\n | AuthenticationControllerCompleteCredentialEnrollmentAction\n | AuthenticationControllerPerformSignOutAction\n | AuthenticationControllerClearStateAction\n | AuthenticationControllerGetBearerTokenAction\n | AuthenticationControllerGetSessionProfileAction\n | AuthenticationControllerRefreshCanonicalProfileIdAction\n | AuthenticationControllerGetUserProfileLineageAction\n | AuthenticationControllerGetCustomerServiceTokenAction\n | AuthenticationControllerGetPartnerIdentityTokenAction\n | AuthenticationControllerIsSignedInAction;\n"]}
@@ -1,9 +1,10 @@
1
1
  import { BaseController } from '@metamask/base-controller';
2
2
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
3
+ import type { TraceCallback } from '@metamask/controller-utils';
3
4
  import type { KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent, KeyringControllerWithKeyringV2UnsafeAction } from '@metamask/keyring-controller';
4
5
  import type { Messenger } from '@metamask/messenger';
5
6
  import type { SeedlessOnboardingControllerGetAccessTokenAction, SeedlessOnboardingControllerGetStateAction } from '@metamask/seedless-onboarding-controller';
6
- import type { LoginResponse, ProfileAlias, UserProfile, UserProfileLineage, OidcTokenAudience, OidcTokenClaims } from '../../sdk/index.js';
7
+ import type { LoginResponse, ProfileAlias, UserProfile, UserProfileLineage, OidcTokenAudience, OidcTokenClaims, BeginEnrollmentRequest, CompleteEnrollmentRequest, EnrolledCredential, EnrollmentChallenge } from '../../sdk/index.js';
7
8
  import { Env } from '../../sdk/index.js';
8
9
  import type { MetaMetricsAuth } from '../../shared/types/services.js';
9
10
  import { AuthenticationControllerMethodActions } from './AuthenticationController-method-action-types.js';
@@ -11,6 +12,12 @@ declare const controllerName = "AuthenticationController";
11
12
  export type AuthenticationControllerState = {
12
13
  isSignedIn: boolean;
13
14
  srpSessionData?: Record<string, LoginResponse>;
15
+ /**
16
+ * Credentials fetched for the current profile. The controller always seeds
17
+ * this to an empty array; it remains optional so partial-state selectors stay
18
+ * assignable to the controller state type.
19
+ */
20
+ enrolledCredentials?: EnrolledCredential[];
14
21
  /**
15
22
  * Client gate for profile pairing. Defaults to `true` (fresh install /
16
23
  * upgrade), set to `false` after a successful `performSignIn` pair, set
@@ -69,7 +76,7 @@ export type AuthenticationControllerMessenger = Messenger<typeof controllerName,
69
76
  */
70
77
  export declare class AuthenticationController extends BaseController<typeof controllerName, AuthenticationControllerState, AuthenticationControllerMessenger> {
71
78
  #private;
72
- constructor({ messenger, state, config, metametrics, }: {
79
+ constructor({ messenger, state, config, metametrics, trace, }: {
73
80
  messenger: AuthenticationControllerMessenger;
74
81
  state?: AuthenticationControllerState;
75
82
  config?: Partial<ControllerConfig>;
@@ -78,6 +85,7 @@ export declare class AuthenticationController extends BaseController<typeof cont
78
85
  * do not want to tie this strictly to extension
79
86
  */
80
87
  metametrics: MetaMetricsAuth;
88
+ trace?: TraceCallback;
81
89
  });
82
90
  performSignIn(): Promise<string[]>;
83
91
  /**
@@ -86,6 +94,34 @@ export declare class AuthenticationController extends BaseController<typeof cont
86
94
  * re-runs `performSignIn` and re-pairs.
87
95
  */
88
96
  requestProfilePairing(): void;
97
+ /**
98
+ * Refreshes credentials enrolled on the canonical profile.
99
+ *
100
+ * @returns The current supported credentials.
101
+ */
102
+ refreshEnrolledCredentials(): Promise<EnrolledCredential[]>;
103
+ /**
104
+ * Begins enrollment of a passkey or email OTP credential.
105
+ *
106
+ * @param request - Credential, optional email address, and trace reason.
107
+ * @returns A challenge for the client-owned ceremony.
108
+ */
109
+ beginCredentialEnrollment(request: BeginEnrollmentRequest): Promise<EnrollmentChallenge>;
110
+ /**
111
+ * Completes credential enrollment and refreshes the credential cache.
112
+ *
113
+ * A cache-refresh failure does not undo successful enrollment. Email
114
+ * enrollment invalidates the primary SRP session *after* refresh so the
115
+ * credentials call can reuse the still-valid access token; the next token
116
+ * fetch then includes the newly verified email claim. That invalidation
117
+ * happens even if the session ends mid-request: the enrollment succeeded
118
+ * on the server, so a token cached across a lock must not be reused
119
+ * without the new claim.
120
+ *
121
+ * @param request - Flow identifier, platform or email proof, and trace reason.
122
+ * @returns The refreshed credentials, or the existing cache if refresh fails.
123
+ */
124
+ completeCredentialEnrollment(request: CompleteEnrollmentRequest): Promise<EnrolledCredential[]>;
89
125
  performSignOut(): void;
90
126
  /**
91
127
  * Resets the controller to `defaultState`. Clients call this on wallet reset
@@ -1 +1 @@
1
- {"version":3,"file":"AuthenticationController.d.ts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC5B,0CAA0C,EAC3C,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,gDAAgD,EAChD,0CAA0C,EAC3C,MAAM,0CAA0C,CAAC;AAGlD,OAAO,KAAK,EAEV,aAAa,EACb,YAAY,EAGZ,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAGL,GAAG,EAGJ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCA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AAE,iBAAiB,EAC3B,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAQjB;IAEM,UAAU,IAAI,OAAO,CAE3B;CA8EF"}
1
+ {"version":3,"file":"AuthenticationController.d.ts","sourceRoot":"","sources":["../../../src/controllers/authentication/AuthenticationController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,KAAK,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAC5B,0CAA0C,EAC3C,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,gDAAgD,EAChD,0CAA0C,EAC3C,MAAM,0CAA0C,CAAC;AAQlD,OAAO,KAAK,EAEV,aAAa,EACb,YAAY,EAGZ,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAGL,GAAG,EAIJ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAOtE,OAAO,EAAE,qCAAqC,EAAE,MAAM,mDAAmD,CAAC;AAE1G,QAAA,MAAM,cAAc,6BAA6B,CAAC;AAGlD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC/C;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC3C;;;;;;;;;;OAUG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ED;;;;;;;;;;;;OAYG;IACU,uBAAuB,CAClC,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,iBAAiB,EAC3B,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAQjB;IAEM,UAAU,IAAI,OAAO,CAE3B;CA8EF"}
@@ -1,11 +1,14 @@
1
1
  import { BaseController } from '@metamask/base-controller';
2
- import { assertMessageStartsWithMetamask, AuthType, Env, JwtBearerAuth, PairConflictError, } from '../../sdk/index.js';
3
- import { getHdKeyringEntropySourceIds, getPrimaryHdKeyringEntropySourceId, } from '../../shared/utils/entropy-source.js';
2
+ import { selectHdKeyringEntropySourceIds } from '@metamask/keyring-controller';
3
+ import { BeginEnrollmentRequestStruct, CompleteEnrollmentRequestStruct, assertValidMfaRequest, } from '../../sdk/authentication-jwt-bearer/mfa/schemas.js';
4
+ import { assertMessageStartsWithMetamask, AuthType, Env, JwtBearerAuth, PairConflictError, getMfaErrorCode, } from '../../sdk/index.js';
5
+ import { getPrimaryHdKeyringEntropySourceId } from '../../shared/utils/entropy-source.js';
4
6
  import { getHdKeyringSeed } from '../../shared/utils/hd-keyring-seed.js';
5
7
  import { getMessageSigningPublicKey, signMessageWithMessageSigningKey, } from '../../shared/utils/message-signing.js';
6
8
  const controllerName = 'AuthenticationController';
7
9
  export const defaultState = {
8
10
  isSignedIn: false,
11
+ enrolledCredentials: [],
9
12
  needsProfilePairing: true,
10
13
  needsSocialPairing: true,
11
14
  };
@@ -52,6 +55,17 @@ const metadata = {
52
55
  includeInDebugSnapshot: false,
53
56
  usedInUi: true,
54
57
  },
58
+ enrolledCredentials: {
59
+ // Allow-list so new credential types cannot leak identifiers by default.
60
+ includeInStateLogs: (credentials) => credentials?.map(({ type, status, enrolledAt }) => ({
61
+ type,
62
+ status,
63
+ ...(enrolledAt === undefined ? {} : { enrolledAt }),
64
+ })) ?? null,
65
+ persist: false,
66
+ includeInDebugSnapshot: false,
67
+ usedInUi: true,
68
+ },
55
69
  };
56
70
  const MESSENGER_EXPOSED_METHODS = [
57
71
  'performSignIn',
@@ -65,6 +79,9 @@ const MESSENGER_EXPOSED_METHODS = [
65
79
  'isSignedIn',
66
80
  'requestProfilePairing',
67
81
  'clearState',
82
+ 'refreshEnrolledCredentials',
83
+ 'beginCredentialEnrollment',
84
+ 'completeCredentialEnrollment',
68
85
  ];
69
86
  /**
70
87
  * Controller that enables authentication for restricted endpoints.
@@ -73,11 +90,24 @@ const MESSENGER_EXPOSED_METHODS = [
73
90
  export class AuthenticationController extends BaseController {
74
91
  #metametrics;
75
92
  #auth;
93
+ #trace;
76
94
  #config = {
77
95
  env: Env.PRD,
78
96
  isSocialPairingEnabled: () => false,
79
97
  };
80
98
  #isUnlocked = false;
99
+ /**
100
+ * Bumped whenever the authenticated session ends, so an in-flight MFA
101
+ * ceremony started under the previous session cannot apply its result.
102
+ */
103
+ #authSessionEpoch = 0;
104
+ /**
105
+ * Sequence number of the most recently started credentials refresh. Only
106
+ * that refresh may write the cache, so a slower, earlier request cannot
107
+ * overwrite a newer list (e.g. an explicit refresh landing after an
108
+ * enrollment's refresh).
109
+ */
110
+ #credentialsRefreshSeq = 0;
81
111
  /**
82
112
  * Bumped by `requestProfilePairing` and `clearState` so an in-flight
83
113
  * `performSignIn` can't clear `needsProfilePairing` afterwards.
@@ -91,11 +121,12 @@ export class AuthenticationController extends BaseController {
91
121
  this.#isUnlocked = true;
92
122
  });
93
123
  this.messenger.subscribe('KeyringController:lock', () => {
124
+ this.#authSessionEpoch += 1;
94
125
  this.#isUnlocked = false;
95
126
  });
96
127
  },
97
128
  };
98
- constructor({ messenger, state, config, metametrics, }) {
129
+ constructor({ messenger, state, config, metametrics, trace, }) {
99
130
  super({
100
131
  messenger,
101
132
  metadata,
@@ -111,6 +142,7 @@ export class AuthenticationController extends BaseController {
111
142
  isSocialPairingEnabled: config?.isSocialPairingEnabled ?? this.#config.isSocialPairingEnabled,
112
143
  };
113
144
  this.#metametrics = metametrics;
145
+ this.#trace = trace ?? ((_request, fn) => fn?.());
114
146
  this.#auth = new JwtBearerAuth({
115
147
  env: this.#config.env,
116
148
  platform: metametrics.agent,
@@ -160,14 +192,19 @@ export class AuthenticationController extends BaseController {
160
192
  throw new Error(`${methodName} - unable to proceed, wallet is locked`);
161
193
  }
162
194
  }
195
+ #assertAuthSessionEpoch(epoch, methodName) {
196
+ if (!this.#isUnlocked || this.#authSessionEpoch !== epoch) {
197
+ throw new Error(`${methodName} - unable to proceed, the authenticated session ended`);
198
+ }
199
+ }
163
200
  /**
164
201
  * Reads the HD keyring entropy source IDs from KeyringController.
165
202
  *
166
203
  * @returns The HD keyring metadata IDs, primary first.
167
204
  */
168
205
  #getHdKeyringEntropySourceIds() {
169
- const { keyrings } = this.messenger.call('KeyringController:getState');
170
- return getHdKeyringEntropySourceIds(keyrings);
206
+ const keyringState = this.messenger.call('KeyringController:getState');
207
+ return selectHdKeyringEntropySourceIds(keyringState);
171
208
  }
172
209
  /**
173
210
  * Resolves the primary SRP's entropy source ID from KeyringController rather
@@ -179,8 +216,8 @@ export class AuthenticationController extends BaseController {
179
216
  * the wallet is unlocked.
180
217
  */
181
218
  #getPrimaryEntropySourceId() {
182
- const { keyrings } = this.messenger.call('KeyringController:getState');
183
- return getPrimaryHdKeyringEntropySourceId(keyrings);
219
+ const keyringState = this.messenger.call('KeyringController:getState');
220
+ return getPrimaryHdKeyringEntropySourceId(keyringState);
184
221
  }
185
222
  /**
186
223
  * Resolves the SRP login tag for `raw_message`.
@@ -490,7 +527,146 @@ export class AuthenticationController extends BaseController {
490
527
  return (this.state.srpSessionData?.[primaryEntropySourceId]?.profile
491
528
  ?.canonicalProfileId ?? null);
492
529
  }
530
+ /**
531
+ * Runs one MFA network step inside a trace span tagged with the caller's
532
+ * operation and the credential type, recording the outcome and MFA error
533
+ * code.
534
+ *
535
+ * @param name - Span name.
536
+ * @param operation - Caller-supplied `reason.operation`.
537
+ * @param credentialType - Credential type the step concerns.
538
+ * @param fn - The network step.
539
+ * @returns The step's result.
540
+ */
541
+ async #runMfaRequest(name, operation, credentialType, fn) {
542
+ const data = { outcome: 'pending' };
543
+ return await this.#trace({
544
+ name,
545
+ tags: { operation, credentialType },
546
+ data,
547
+ }, async () => {
548
+ try {
549
+ const result = await fn();
550
+ data.outcome = 'success';
551
+ return result;
552
+ }
553
+ catch (error) {
554
+ data.outcome = 'error';
555
+ const mfaCode = getMfaErrorCode(error);
556
+ if (mfaCode) {
557
+ data.mfaErrorCode = mfaCode;
558
+ }
559
+ throw error;
560
+ }
561
+ });
562
+ }
563
+ /**
564
+ * Refreshes credentials enrolled on the canonical profile.
565
+ *
566
+ * @returns The current supported credentials.
567
+ */
568
+ async refreshEnrolledCredentials() {
569
+ this.#assertIsUnlocked('refreshEnrolledCredentials');
570
+ const sessionEpoch = this.#authSessionEpoch;
571
+ this.#credentialsRefreshSeq += 1;
572
+ const refreshSeq = this.#credentialsRefreshSeq;
573
+ const primaryEntropySourceId = this.#getPrimaryEntropySourceId();
574
+ const credentials = await this.#runMfaRequest('MFA Credentials Refresh', 'credentials.refresh', 'all', async () => await this.#auth.getMfaCredentials(primaryEntropySourceId));
575
+ this.#assertAuthSessionEpoch(sessionEpoch, 'refreshEnrolledCredentials');
576
+ // A newer refresh started while this one was in flight; its result is at
577
+ // least as fresh, so defer to it rather than overwrite with older data.
578
+ if (refreshSeq !== this.#credentialsRefreshSeq) {
579
+ return this.#getEnrolledCredentials();
580
+ }
581
+ // Skip the write when nothing changed so subscribers are not woken up by
582
+ // a fresh-but-identical array.
583
+ if (JSON.stringify(credentials) !==
584
+ JSON.stringify(this.#getEnrolledCredentials())) {
585
+ this.update((state) => {
586
+ state.enrolledCredentials = credentials;
587
+ });
588
+ }
589
+ return credentials;
590
+ }
591
+ /**
592
+ * Begins enrollment of a passkey or email OTP credential.
593
+ *
594
+ * @param request - Credential, optional email address, and trace reason.
595
+ * @returns A challenge for the client-owned ceremony.
596
+ */
597
+ async beginCredentialEnrollment(request) {
598
+ this.#assertIsUnlocked('beginCredentialEnrollment');
599
+ const sessionEpoch = this.#authSessionEpoch;
600
+ assertValidMfaRequest(request, BeginEnrollmentRequestStruct);
601
+ const primaryEntropySourceId = this.#getPrimaryEntropySourceId();
602
+ const challenge = await this.#runMfaRequest('MFA Enroll Begin', request.reason.operation, request.type, async () => await this.#auth.beginMfaEnrollment(request.type, {
603
+ email: request.email,
604
+ entropySourceId: primaryEntropySourceId,
605
+ }));
606
+ this.#assertAuthSessionEpoch(sessionEpoch, 'beginCredentialEnrollment');
607
+ return challenge;
608
+ }
609
+ /**
610
+ * Completes credential enrollment and refreshes the credential cache.
611
+ *
612
+ * A cache-refresh failure does not undo successful enrollment. Email
613
+ * enrollment invalidates the primary SRP session *after* refresh so the
614
+ * credentials call can reuse the still-valid access token; the next token
615
+ * fetch then includes the newly verified email claim. That invalidation
616
+ * happens even if the session ends mid-request: the enrollment succeeded
617
+ * on the server, so a token cached across a lock must not be reused
618
+ * without the new claim.
619
+ *
620
+ * @param request - Flow identifier, platform or email proof, and trace reason.
621
+ * @returns The refreshed credentials, or the existing cache if refresh fails.
622
+ */
623
+ async completeCredentialEnrollment(request) {
624
+ this.#assertIsUnlocked('completeCredentialEnrollment');
625
+ const sessionEpoch = this.#authSessionEpoch;
626
+ assertValidMfaRequest(request, CompleteEnrollmentRequestStruct);
627
+ const { type } = request.proof;
628
+ const primaryEntropySourceId = this.#getPrimaryEntropySourceId();
629
+ await this.#runMfaRequest('MFA Enroll Complete', request.reason.operation, type, async () => await this.#auth.completeMfaEnrollment(request.flowId, request.proof, primaryEntropySourceId));
630
+ try {
631
+ this.#assertAuthSessionEpoch(sessionEpoch, 'completeCredentialEnrollment');
632
+ }
633
+ catch (error) {
634
+ if (type === 'email_otp') {
635
+ this.#invalidateSrpSession(primaryEntropySourceId);
636
+ }
637
+ throw error;
638
+ }
639
+ try {
640
+ return await this.refreshEnrolledCredentials();
641
+ }
642
+ catch {
643
+ return this.#getEnrolledCredentials();
644
+ }
645
+ finally {
646
+ if (type === 'email_otp') {
647
+ this.#invalidateSrpSession(primaryEntropySourceId);
648
+ }
649
+ }
650
+ }
651
+ /**
652
+ * Drops the cached credential list. Callers that wipe profile state must go
653
+ * through this so subscribers never keep credentials belonging to a profile
654
+ * that is no longer active.
655
+ */
656
+ #clearEnrolledCredentials() {
657
+ if (this.#getEnrolledCredentials().length === 0) {
658
+ return;
659
+ }
660
+ this.update((state) => {
661
+ state.enrolledCredentials = [];
662
+ });
663
+ }
664
+ #getEnrolledCredentials() {
665
+ return this.state.enrolledCredentials ?? [];
666
+ }
493
667
  performSignOut() {
668
+ this.#authSessionEpoch += 1;
669
+ this.#clearEnrolledCredentials();
494
670
  this.update((state) => {
495
671
  state.isSignedIn = false;
496
672
  state.srpSessionData = undefined;
@@ -502,6 +678,8 @@ export class AuthenticationController extends BaseController {
502
678
  */
503
679
  clearState() {
504
680
  this.#profilePairingRequestEpoch += 1;
681
+ this.#authSessionEpoch += 1;
682
+ this.#clearEnrolledCredentials();
505
683
  this.update(() => ({ ...defaultState }));
506
684
  }
507
685
  /**