@metamask/profile-sync-controller 28.3.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.
Files changed (231) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/LICENSE +1 -0
  3. package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs.map +1 -1
  4. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.cts.map +1 -1
  5. package/dist/controllers/authentication/AuthenticationController-method-action-types.d.mts.map +1 -1
  6. package/dist/controllers/authentication/AuthenticationController-method-action-types.mjs.map +1 -1
  7. package/dist/controllers/authentication/AuthenticationController.cjs +236 -75
  8. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
  9. package/dist/controllers/authentication/AuthenticationController.d.cts +22 -3
  10. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
  11. package/dist/controllers/authentication/AuthenticationController.d.mts +22 -3
  12. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
  13. package/dist/controllers/authentication/AuthenticationController.mjs +231 -70
  14. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
  15. package/dist/controllers/authentication/index.cjs +3 -3
  16. package/dist/controllers/authentication/index.cjs.map +1 -1
  17. package/dist/controllers/authentication/index.d.cts.map +1 -1
  18. package/dist/controllers/authentication/index.d.mts.map +1 -1
  19. package/dist/controllers/authentication/index.mjs.map +1 -1
  20. package/dist/controllers/authentication/mocks/index.cjs.map +1 -1
  21. package/dist/controllers/authentication/mocks/index.d.cts.map +1 -1
  22. package/dist/controllers/authentication/mocks/index.d.mts.map +1 -1
  23. package/dist/controllers/authentication/mocks/index.mjs.map +1 -1
  24. package/dist/controllers/authentication/mocks/mockResponses.cjs +26 -15
  25. package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -1
  26. package/dist/controllers/authentication/mocks/mockResponses.d.cts +11 -0
  27. package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -1
  28. package/dist/controllers/authentication/mocks/mockResponses.d.mts +11 -0
  29. package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -1
  30. package/dist/controllers/authentication/mocks/mockResponses.mjs +13 -3
  31. package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -1
  32. package/dist/controllers/index.cjs.map +1 -1
  33. package/dist/controllers/index.d.cts.map +1 -1
  34. package/dist/controllers/index.d.mts.map +1 -1
  35. package/dist/controllers/index.mjs.map +1 -1
  36. package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs.map +1 -1
  37. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.cts.map +1 -1
  38. package/dist/controllers/user-storage/UserStorageController-method-action-types.d.mts.map +1 -1
  39. package/dist/controllers/user-storage/UserStorageController-method-action-types.mjs.map +1 -1
  40. package/dist/controllers/user-storage/UserStorageController.cjs +35 -36
  41. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  42. package/dist/controllers/user-storage/UserStorageController.d.cts +2 -3
  43. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  44. package/dist/controllers/user-storage/UserStorageController.d.mts +2 -3
  45. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  46. package/dist/controllers/user-storage/UserStorageController.mjs +22 -23
  47. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  48. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +23 -23
  49. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +1 -1
  50. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +1 -1
  51. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +1 -1
  52. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +1 -1
  53. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs +9 -9
  54. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs.map +1 -1
  55. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.cts.map +1 -1
  56. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts.map +1 -1
  57. package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.mjs.map +1 -1
  58. package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs.map +1 -1
  59. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.cts.map +1 -1
  60. package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts.map +1 -1
  61. package/dist/controllers/user-storage/contact-syncing/sync-utils.mjs.map +1 -1
  62. package/dist/controllers/user-storage/contact-syncing/types.cjs.map +1 -1
  63. package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +1 -1
  64. package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +1 -1
  65. package/dist/controllers/user-storage/contact-syncing/types.mjs.map +1 -1
  66. package/dist/controllers/user-storage/contact-syncing/utils.cjs +2 -2
  67. package/dist/controllers/user-storage/contact-syncing/utils.cjs.map +1 -1
  68. package/dist/controllers/user-storage/contact-syncing/utils.d.cts.map +1 -1
  69. package/dist/controllers/user-storage/contact-syncing/utils.d.mts.map +1 -1
  70. package/dist/controllers/user-storage/contact-syncing/utils.mjs.map +1 -1
  71. package/dist/controllers/user-storage/index.cjs +3 -3
  72. package/dist/controllers/user-storage/index.cjs.map +1 -1
  73. package/dist/controllers/user-storage/index.d.cts.map +1 -1
  74. package/dist/controllers/user-storage/index.d.mts.map +1 -1
  75. package/dist/controllers/user-storage/index.mjs.map +1 -1
  76. package/dist/controllers/user-storage/mocks/index.cjs.map +1 -1
  77. package/dist/controllers/user-storage/mocks/index.d.cts.map +1 -1
  78. package/dist/controllers/user-storage/mocks/index.d.mts.map +1 -1
  79. package/dist/controllers/user-storage/mocks/index.mjs.map +1 -1
  80. package/dist/controllers/user-storage/mocks/mockResponses.cjs +15 -15
  81. package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -1
  82. package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -1
  83. package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -1
  84. package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -1
  85. package/dist/controllers/user-storage/mocks/mockStorage.cjs +3 -3
  86. package/dist/controllers/user-storage/mocks/mockStorage.cjs.map +1 -1
  87. package/dist/controllers/user-storage/mocks/mockStorage.d.cts.map +1 -1
  88. package/dist/controllers/user-storage/mocks/mockStorage.d.mts.map +1 -1
  89. package/dist/controllers/user-storage/mocks/mockStorage.mjs.map +1 -1
  90. package/dist/controllers/user-storage/types.cjs.map +1 -1
  91. package/dist/controllers/user-storage/types.d.cts.map +1 -1
  92. package/dist/controllers/user-storage/types.d.mts.map +1 -1
  93. package/dist/controllers/user-storage/types.mjs.map +1 -1
  94. package/dist/index.cjs.map +1 -1
  95. package/dist/index.d.cts.map +1 -1
  96. package/dist/index.d.mts.map +1 -1
  97. package/dist/index.mjs.map +1 -1
  98. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +11 -11
  99. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
  100. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
  101. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
  102. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
  103. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +40 -26
  104. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
  105. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +12 -1
  106. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
  107. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +12 -1
  108. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
  109. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +20 -6
  110. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
  111. package/dist/sdk/authentication-jwt-bearer/services.cjs +85 -39
  112. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
  113. package/dist/sdk/authentication-jwt-bearer/services.d.cts +19 -2
  114. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
  115. package/dist/sdk/authentication-jwt-bearer/services.d.mts +19 -2
  116. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
  117. package/dist/sdk/authentication-jwt-bearer/services.mjs +46 -2
  118. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
  119. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
  120. package/dist/sdk/authentication-jwt-bearer/types.d.cts +36 -0
  121. package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -1
  122. package/dist/sdk/authentication-jwt-bearer/types.d.mts +36 -0
  123. package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -1
  124. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
  125. package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs +2 -2
  126. package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs.map +1 -1
  127. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.cts.map +1 -1
  128. package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts.map +1 -1
  129. package/dist/sdk/authentication-jwt-bearer/utils/identifier.mjs.map +1 -1
  130. package/dist/sdk/authentication.cjs +25 -21
  131. package/dist/sdk/authentication.cjs.map +1 -1
  132. package/dist/sdk/authentication.d.cts +2 -1
  133. package/dist/sdk/authentication.d.cts.map +1 -1
  134. package/dist/sdk/authentication.d.mts +2 -1
  135. package/dist/sdk/authentication.d.mts.map +1 -1
  136. package/dist/sdk/authentication.mjs +4 -0
  137. package/dist/sdk/authentication.mjs.map +1 -1
  138. package/dist/sdk/constants.cjs +1 -0
  139. package/dist/sdk/constants.cjs.map +1 -1
  140. package/dist/sdk/constants.d.cts +1 -0
  141. package/dist/sdk/constants.d.cts.map +1 -1
  142. package/dist/sdk/constants.d.mts +1 -0
  143. package/dist/sdk/constants.d.mts.map +1 -1
  144. package/dist/sdk/constants.mjs +1 -0
  145. package/dist/sdk/constants.mjs.map +1 -1
  146. package/dist/sdk/errors.cjs +17 -4
  147. package/dist/sdk/errors.cjs.map +1 -1
  148. package/dist/sdk/errors.d.cts +9 -0
  149. package/dist/sdk/errors.d.cts.map +1 -1
  150. package/dist/sdk/errors.d.mts +9 -0
  151. package/dist/sdk/errors.d.mts.map +1 -1
  152. package/dist/sdk/errors.mjs +12 -0
  153. package/dist/sdk/errors.mjs.map +1 -1
  154. package/dist/sdk/index.cjs.map +1 -1
  155. package/dist/sdk/index.d.cts.map +1 -1
  156. package/dist/sdk/index.d.mts.map +1 -1
  157. package/dist/sdk/index.mjs.map +1 -1
  158. package/dist/sdk/mocks/auth.cjs +24 -13
  159. package/dist/sdk/mocks/auth.cjs.map +1 -1
  160. package/dist/sdk/mocks/auth.d.cts +11 -0
  161. package/dist/sdk/mocks/auth.d.cts.map +1 -1
  162. package/dist/sdk/mocks/auth.d.mts +11 -0
  163. package/dist/sdk/mocks/auth.d.mts.map +1 -1
  164. package/dist/sdk/mocks/auth.mjs +12 -1
  165. package/dist/sdk/mocks/auth.mjs.map +1 -1
  166. package/dist/sdk/mocks/userstorage.cjs +8 -8
  167. package/dist/sdk/mocks/userstorage.cjs.map +1 -1
  168. package/dist/sdk/mocks/userstorage.mjs.map +1 -1
  169. package/dist/sdk/user-storage.cjs +32 -32
  170. package/dist/sdk/user-storage.cjs.map +1 -1
  171. package/dist/sdk/user-storage.d.cts.map +1 -1
  172. package/dist/sdk/user-storage.d.mts.map +1 -1
  173. package/dist/sdk/user-storage.mjs +1 -1
  174. package/dist/sdk/user-storage.mjs.map +1 -1
  175. package/dist/sdk/utils/validate-login-response.cjs.map +1 -1
  176. package/dist/sdk/utils/validate-login-response.d.cts.map +1 -1
  177. package/dist/sdk/utils/validate-login-response.d.mts.map +1 -1
  178. package/dist/sdk/utils/validate-login-response.mjs.map +1 -1
  179. package/dist/shared/encryption/cache.cjs +6 -6
  180. package/dist/shared/encryption/cache.cjs.map +1 -1
  181. package/dist/shared/encryption/cache.mjs.map +1 -1
  182. package/dist/shared/encryption/encryption.cjs +26 -26
  183. package/dist/shared/encryption/encryption.cjs.map +1 -1
  184. package/dist/shared/encryption/encryption.d.cts.map +1 -1
  185. package/dist/shared/encryption/encryption.d.mts.map +1 -1
  186. package/dist/shared/encryption/encryption.mjs.map +1 -1
  187. package/dist/shared/encryption/index.cjs +3 -3
  188. package/dist/shared/encryption/index.cjs.map +1 -1
  189. package/dist/shared/encryption/index.d.cts.map +1 -1
  190. package/dist/shared/encryption/index.d.mts.map +1 -1
  191. package/dist/shared/encryption/index.mjs.map +1 -1
  192. package/dist/shared/storage-schema.cjs +2 -2
  193. package/dist/shared/storage-schema.cjs.map +1 -1
  194. package/dist/shared/storage-schema.mjs.map +1 -1
  195. package/dist/shared/types/services.cjs.map +1 -1
  196. package/dist/shared/types/services.d.cts.map +1 -1
  197. package/dist/shared/types/services.d.mts.map +1 -1
  198. package/dist/shared/types/services.mjs.map +1 -1
  199. package/dist/shared/utils/entropy-source.cjs +37 -0
  200. package/dist/shared/utils/entropy-source.cjs.map +1 -0
  201. package/dist/shared/utils/entropy-source.d.cts +22 -0
  202. package/dist/shared/utils/entropy-source.d.cts.map +1 -0
  203. package/dist/shared/utils/entropy-source.d.mts +22 -0
  204. package/dist/shared/utils/entropy-source.d.mts.map +1 -0
  205. package/dist/shared/utils/entropy-source.mjs +32 -0
  206. package/dist/shared/utils/entropy-source.mjs.map +1 -0
  207. package/dist/shared/utils/hd-keyring-seed.cjs +49 -0
  208. package/dist/shared/utils/hd-keyring-seed.cjs.map +1 -0
  209. package/dist/shared/utils/hd-keyring-seed.d.cts +27 -0
  210. package/dist/shared/utils/hd-keyring-seed.d.cts.map +1 -0
  211. package/dist/shared/utils/hd-keyring-seed.d.mts +27 -0
  212. package/dist/shared/utils/hd-keyring-seed.d.mts.map +1 -0
  213. package/dist/shared/utils/hd-keyring-seed.mjs +45 -0
  214. package/dist/shared/utils/hd-keyring-seed.mjs.map +1 -0
  215. package/dist/shared/utils/message-signing.cjs +147 -0
  216. package/dist/shared/utils/message-signing.cjs.map +1 -0
  217. package/dist/shared/utils/message-signing.d.cts +73 -0
  218. package/dist/shared/utils/message-signing.d.cts.map +1 -0
  219. package/dist/shared/utils/message-signing.d.mts +73 -0
  220. package/dist/shared/utils/message-signing.d.mts.map +1 -0
  221. package/dist/shared/utils/message-signing.mjs +140 -0
  222. package/dist/shared/utils/message-signing.mjs.map +1 -0
  223. package/package.json +17 -14
  224. package/dist/controllers/authentication/auth-snap-requests.cjs +0 -60
  225. package/dist/controllers/authentication/auth-snap-requests.cjs.map +0 -1
  226. package/dist/controllers/authentication/auth-snap-requests.d.cts +0 -27
  227. package/dist/controllers/authentication/auth-snap-requests.d.cts.map +0 -1
  228. package/dist/controllers/authentication/auth-snap-requests.d.mts +0 -27
  229. package/dist/controllers/authentication/auth-snap-requests.d.mts.map +0 -1
  230. package/dist/controllers/authentication/auth-snap-requests.mjs +0 -54
  231. package/dist/controllers/authentication/auth-snap-requests.mjs.map +0 -1
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCustomerServiceToken = exports.getUserProfileLineage = exports.authenticate = exports.authorizeOIDC = exports.getNonce = exports.pairProfiles = exports.pairIdentifiers = exports.CUSTOMER_SERVICE_TOKEN_URL = exports.PROFILE_LINEAGE_URL = exports.PAIR_PROFILES_URL = exports.SIWE_LOGIN_URL = exports.SRP_LOGIN_URL = exports.OIDC_TOKEN_URL = exports.PAIR_IDENTIFIERS = exports.NONCE_URL = void 0;
4
- const env_1 = require("../../shared/env.cjs");
5
- const constants_1 = require("../constants.cjs");
6
- const errors_1 = require("../errors.cjs");
7
- const validate_pair_response_1 = require("../utils/validate-pair-response.cjs");
8
- const types_1 = require("./types.cjs");
3
+ exports.getCustomerServiceToken = exports.getUserProfileLineage = exports.authenticate = exports.authorizeOIDC = exports.getNonce = exports.pairSocialIdentifier = exports.pairProfiles = exports.pairIdentifiers = exports.CUSTOMER_SERVICE_TOKEN_URL = exports.PROFILE_LINEAGE_URL = exports.PAIR_SOCIAL_IDENTIFIER_URL = exports.PAIR_PROFILES_URL = exports.SIWE_LOGIN_URL = exports.SRP_LOGIN_URL = exports.OIDC_TOKEN_URL = exports.PAIR_IDENTIFIERS = exports.NONCE_URL = void 0;
4
+ const env_js_1 = require("../../shared/env.cjs");
5
+ const constants_js_1 = require("../constants.cjs");
6
+ const errors_js_1 = require("../errors.cjs");
7
+ const validate_pair_response_js_1 = require("../utils/validate-pair-response.cjs");
8
+ const types_js_1 = require("./types.cjs");
9
9
  /**
10
10
  * Parse Retry-After header into milliseconds if possible.
11
11
  * Supports seconds or HTTP-date formats.
@@ -84,7 +84,7 @@ const isErrorResponse = (obj) => typeof obj === 'object' &&
84
84
  */
85
85
  async function throwServiceError(error, errorPrefix, ErrorClass) {
86
86
  // Re-throw RateLimitedError or matching ErrorClass as-is (don't double-wrap)
87
- if (error instanceof errors_1.RateLimitedError || error instanceof ErrorClass) {
87
+ if (error instanceof errors_js_1.RateLimitedError || error instanceof ErrorClass) {
88
88
  throw error;
89
89
  }
90
90
  // Not a Response-like object - handle as regular error
@@ -96,38 +96,40 @@ async function throwServiceError(error, errorPrefix, ErrorClass) {
96
96
  const response = error;
97
97
  const { status } = response;
98
98
  const responseMessage = await getResponseErrorMessage(response);
99
- if (status === constants_1.HTTP_STATUS_CODES.TOO_MANY_REQUESTS) {
99
+ if (status === constants_js_1.HTTP_STATUS_CODES.TOO_MANY_REQUESTS) {
100
100
  const retryAfterHeader = response.headers.get('Retry-After');
101
101
  const retryAfterMs = parseRetryAfter(retryAfterHeader);
102
- throw new errors_1.RateLimitedError(`${errorPrefix}: ${responseMessage}`, retryAfterMs ?? undefined);
102
+ throw new errors_js_1.RateLimitedError(`${errorPrefix}: ${responseMessage}`, retryAfterMs ?? undefined);
103
103
  }
104
104
  throw new ErrorClass(`${errorPrefix}: ${responseMessage}`);
105
105
  }
106
- const NONCE_URL = (env) => `${(0, env_1.getEnvUrls)(env).authApiUrl}/api/v2/nonce`;
106
+ const NONCE_URL = (env) => `${(0, env_js_1.getEnvUrls)(env).authApiUrl}/api/v2/nonce`;
107
107
  exports.NONCE_URL = NONCE_URL;
108
- const PAIR_IDENTIFIERS = (env) => `${(0, env_1.getEnvUrls)(env).authApiUrl}/api/v2/identifiers/pair`;
108
+ const PAIR_IDENTIFIERS = (env) => `${(0, env_js_1.getEnvUrls)(env).authApiUrl}/api/v2/identifiers/pair`;
109
109
  exports.PAIR_IDENTIFIERS = PAIR_IDENTIFIERS;
110
- const OIDC_TOKEN_URL = (env) => `${(0, env_1.getEnvUrls)(env).oidcApiUrl}/oauth2/token`;
110
+ const OIDC_TOKEN_URL = (env) => `${(0, env_js_1.getEnvUrls)(env).oidcApiUrl}/oauth2/token`;
111
111
  exports.OIDC_TOKEN_URL = OIDC_TOKEN_URL;
112
- const SRP_LOGIN_URL = (env) => `${(0, env_1.getEnvUrls)(env).authApiUrl}/api/v2/srp/login`;
112
+ const SRP_LOGIN_URL = (env) => `${(0, env_js_1.getEnvUrls)(env).authApiUrl}/api/v2/srp/login`;
113
113
  exports.SRP_LOGIN_URL = SRP_LOGIN_URL;
114
- const SIWE_LOGIN_URL = (env) => `${(0, env_1.getEnvUrls)(env).authApiUrl}/api/v2/siwe/login`;
114
+ const SIWE_LOGIN_URL = (env) => `${(0, env_js_1.getEnvUrls)(env).authApiUrl}/api/v2/siwe/login`;
115
115
  exports.SIWE_LOGIN_URL = SIWE_LOGIN_URL;
116
- const PAIR_PROFILES_URL = (env) => `${(0, env_1.getEnvUrls)(env).authApiUrl}/api/v2/profile/pair`;
116
+ const PAIR_PROFILES_URL = (env) => `${(0, env_js_1.getEnvUrls)(env).authApiUrl}/api/v2/profile/pair`;
117
117
  exports.PAIR_PROFILES_URL = PAIR_PROFILES_URL;
118
- const PROFILE_LINEAGE_URL = (env) => `${(0, env_1.getEnvUrls)(env).authApiUrl}/api/v2/profile/lineage`;
118
+ const PAIR_SOCIAL_IDENTIFIER_URL = (env) => `${(0, env_js_1.getEnvUrls)(env).authApiUrl}/api/v2/profile/pair/identifier`;
119
+ exports.PAIR_SOCIAL_IDENTIFIER_URL = PAIR_SOCIAL_IDENTIFIER_URL;
120
+ const PROFILE_LINEAGE_URL = (env) => `${(0, env_js_1.getEnvUrls)(env).authApiUrl}/api/v2/profile/lineage`;
119
121
  exports.PROFILE_LINEAGE_URL = PROFILE_LINEAGE_URL;
120
- const CUSTOMER_SERVICE_TOKEN_URL = (env) => `${(0, env_1.getEnvUrls)(env).authApiUrl}/api/v2/customer-service/token`;
122
+ const CUSTOMER_SERVICE_TOKEN_URL = (env) => `${(0, env_js_1.getEnvUrls)(env).authApiUrl}/api/v2/customer-service/token`;
121
123
  exports.CUSTOMER_SERVICE_TOKEN_URL = CUSTOMER_SERVICE_TOKEN_URL;
122
124
  const getAuthenticationUrl = (authType, env) => {
123
125
  switch (authType) {
124
- case types_1.AuthType.SRP:
126
+ case types_js_1.AuthType.SRP:
125
127
  return (0, exports.SRP_LOGIN_URL)(env);
126
- case types_1.AuthType.SiWE:
128
+ case types_js_1.AuthType.SiWE:
127
129
  return (0, exports.SIWE_LOGIN_URL)(env);
128
130
  /* istanbul ignore next */
129
131
  default:
130
- throw new errors_1.ValidationError(`Invalid AuthType: ${authType} - unable to create Auth URL`);
132
+ throw new errors_js_1.ValidationError(`Invalid AuthType: ${authType} - unable to create Auth URL`);
131
133
  }
132
134
  };
133
135
  const parseProfileAliases = (raw) => {
@@ -161,12 +163,12 @@ async function pairIdentifiers(nonce, logins, accessToken, env) {
161
163
  }),
162
164
  });
163
165
  if (!response.ok) {
164
- return await throwServiceError(response, 'Failed to pair identifiers', errors_1.PairError);
166
+ return await throwServiceError(response, 'Failed to pair identifiers', errors_js_1.PairError);
165
167
  }
166
168
  return undefined;
167
169
  }
168
170
  catch (error) {
169
- return await throwServiceError(error, 'Failed to pair identifiers', errors_1.PairError);
171
+ return await throwServiceError(error, 'Failed to pair identifiers', errors_js_1.PairError);
170
172
  }
171
173
  }
172
174
  exports.pairIdentifiers = pairIdentifiers;
@@ -193,10 +195,10 @@ async function pairProfiles(accessTokens, authAccessToken, env) {
193
195
  }),
194
196
  });
195
197
  if (!response.ok) {
196
- return await throwServiceError(response, 'Failed to pair profiles', errors_1.PairError);
198
+ return await throwServiceError(response, 'Failed to pair profiles', errors_js_1.PairError);
197
199
  }
198
200
  const pairResponse = await response.json();
199
- (0, validate_pair_response_1.validatePairResponse)(pairResponse);
201
+ (0, validate_pair_response_js_1.validatePairResponse)(pairResponse);
200
202
  return {
201
203
  profile: {
202
204
  identifierId: pairResponse.profile.identifier_id,
@@ -208,10 +210,51 @@ async function pairProfiles(accessTokens, authAccessToken, env) {
208
210
  };
209
211
  }
210
212
  catch (error) {
211
- return await throwServiceError(error, 'Failed to pair profiles', errors_1.PairError);
213
+ return await throwServiceError(error, 'Failed to pair profiles', errors_js_1.PairError);
212
214
  }
213
215
  }
214
216
  exports.pairProfiles = pairProfiles;
217
+ /**
218
+ * Attach a Google/Apple/Telegram social identifier to the profile that
219
+ * owns `authAccessToken` (`POST /api/v2/profile/pair/identifier`).
220
+ *
221
+ * `email` is omitted from the body when undefined. 409 Conflict throws
222
+ * {@link PairConflictError} so callers can treat it as terminal. The
223
+ * response body (new token + profile) is not consumed: a 2xx status is the
224
+ * only success signal.
225
+ *
226
+ * @param params - Social identifier type, social JWT, and optional email
227
+ * @param authAccessToken - Bearer token of the canonical (primary SRP) profile
228
+ * @param env - server environment
229
+ */
230
+ async function pairSocialIdentifier(params, authAccessToken, env) {
231
+ const pairUrl = new URL((0, exports.PAIR_SOCIAL_IDENTIFIER_URL)(env));
232
+ const errorPrefix = 'Failed to pair social identifier';
233
+ try {
234
+ const response = await fetch(pairUrl, {
235
+ method: 'POST',
236
+ headers: {
237
+ 'Content-Type': 'application/json',
238
+ Authorization: `Bearer ${authAccessToken}`,
239
+ },
240
+ body: JSON.stringify({
241
+ identifier_type: params.identifierType,
242
+ social_jwt: params.socialJwt,
243
+ ...(params.email === undefined ? {} : { email: params.email }),
244
+ }),
245
+ });
246
+ if (!response.ok) {
247
+ if (response.status === constants_js_1.HTTP_STATUS_CODES.CONFLICT) {
248
+ await throwServiceError(response, errorPrefix, errors_js_1.PairConflictError);
249
+ }
250
+ await throwServiceError(response, errorPrefix, errors_js_1.PairError);
251
+ }
252
+ }
253
+ catch (error) {
254
+ await throwServiceError(error, errorPrefix, errors_js_1.PairError);
255
+ }
256
+ }
257
+ exports.pairSocialIdentifier = pairSocialIdentifier;
215
258
  /**
216
259
  * Service to Get Nonce for JWT Bearer Flow
217
260
  *
@@ -225,7 +268,7 @@ async function getNonce(id, env) {
225
268
  try {
226
269
  const nonceResponse = await fetch(nonceUrl.toString());
227
270
  if (!nonceResponse.ok) {
228
- return await throwServiceError(nonceResponse, 'Failed to get nonce', errors_1.NonceRetrievalError);
271
+ return await throwServiceError(nonceResponse, 'Failed to get nonce', errors_js_1.NonceRetrievalError);
229
272
  }
230
273
  const nonceJson = await nonceResponse.json();
231
274
  return {
@@ -235,7 +278,7 @@ async function getNonce(id, env) {
235
278
  };
236
279
  }
237
280
  catch (error) {
238
- return await throwServiceError(error, 'Failed to get nonce', errors_1.NonceRetrievalError);
281
+ return await throwServiceError(error, 'Failed to get nonce', errors_js_1.NonceRetrievalError);
239
282
  }
240
283
  }
241
284
  exports.getNonce = getNonce;
@@ -254,7 +297,7 @@ async function authorizeOIDC(jwtToken, env, platform) {
254
297
  };
255
298
  const urlEncodedBody = new URLSearchParams();
256
299
  urlEncodedBody.append('grant_type', grantType);
257
- urlEncodedBody.append('client_id', (0, env_1.getOidcClientId)(env, platform));
300
+ urlEncodedBody.append('client_id', (0, env_js_1.getOidcClientId)(env, platform));
258
301
  urlEncodedBody.append('assertion', jwtToken);
259
302
  try {
260
303
  const response = await fetch((0, exports.OIDC_TOKEN_URL)(env), {
@@ -263,7 +306,7 @@ async function authorizeOIDC(jwtToken, env, platform) {
263
306
  body: urlEncodedBody.toString(),
264
307
  });
265
308
  if (!response.ok) {
266
- return await throwServiceError(response, 'Failed to get access token', errors_1.SignInError);
309
+ return await throwServiceError(response, 'Failed to get access token', errors_js_1.SignInError);
267
310
  }
268
311
  const accessTokenResponse = await response.json();
269
312
  return {
@@ -273,7 +316,7 @@ async function authorizeOIDC(jwtToken, env, platform) {
273
316
  };
274
317
  }
275
318
  catch (error) {
276
- return await throwServiceError(error, 'Failed to get access token', errors_1.SignInError);
319
+ return await throwServiceError(error, 'Failed to get access token', errors_js_1.SignInError);
277
320
  }
278
321
  }
279
322
  exports.authorizeOIDC = authorizeOIDC;
@@ -285,16 +328,18 @@ exports.authorizeOIDC = authorizeOIDC;
285
328
  * @param authType - authentication type/flow used
286
329
  * @param env - server environment
287
330
  * @param metametrics - optional metametrics
331
+ * @param identifierType - login identifier type included in metametrics
332
+ * (defaults to `SRP` when metametrics is present)
288
333
  * @returns Authentication Token
289
334
  */
290
- async function authenticate(rawMessage, signature, authType, env, metametrics) {
335
+ async function authenticate(rawMessage, signature, authType, env, metametrics, identifierType = 'SRP') {
291
336
  const authenticationUrl = getAuthenticationUrl(authType, env);
292
337
  try {
293
338
  const response = await fetch(authenticationUrl, {
294
339
  method: 'POST',
295
340
  headers: {
296
341
  'Content-Type': 'application/json',
297
- ...(authType === types_1.AuthType.SRP
342
+ ...(authType === types_js_1.AuthType.SRP
298
343
  ? { 'X-MetaMask-Profile-Pairing': 'enabled' }
299
344
  : {}),
300
345
  },
@@ -307,13 +352,14 @@ async function authenticate(rawMessage, signature, authType, env, metametrics) {
307
352
  metametrics_id: await metametrics.getMetaMetricsId(),
308
353
  agent: metametrics.agent,
309
354
  app_version: await metametrics.getAppVersion?.(),
355
+ identifier_type: identifierType,
310
356
  },
311
357
  }
312
358
  : {}),
313
359
  }),
314
360
  });
315
361
  if (!response.ok) {
316
- return await throwServiceError(response, `Failed to login with ${authType}`, errors_1.SignInError);
362
+ return await throwServiceError(response, `Failed to login with ${authType}`, errors_js_1.SignInError);
317
363
  }
318
364
  const loginResponse = await response.json();
319
365
  return {
@@ -329,7 +375,7 @@ async function authenticate(rawMessage, signature, authType, env, metametrics) {
329
375
  };
330
376
  }
331
377
  catch (error) {
332
- return await throwServiceError(error, `Failed to login with ${authType}`, errors_1.SignInError);
378
+ return await throwServiceError(error, `Failed to login with ${authType}`, errors_js_1.SignInError);
333
379
  }
334
380
  }
335
381
  exports.authenticate = authenticate;
@@ -350,13 +396,13 @@ async function getUserProfileLineage(env, accessToken) {
350
396
  },
351
397
  });
352
398
  if (!response.ok) {
353
- return await throwServiceError(response, 'Failed to get profile lineage', errors_1.SignInError);
399
+ return await throwServiceError(response, 'Failed to get profile lineage', errors_js_1.SignInError);
354
400
  }
355
401
  const profileJson = await response.json();
356
402
  return profileJson;
357
403
  }
358
404
  catch (error) {
359
- return await throwServiceError(error, 'Failed to get profile lineage', errors_1.SignInError);
405
+ return await throwServiceError(error, 'Failed to get profile lineage', errors_js_1.SignInError);
360
406
  }
361
407
  }
362
408
  exports.getUserProfileLineage = getUserProfileLineage;
@@ -381,16 +427,16 @@ async function getCustomerServiceToken(env, accessToken) {
381
427
  },
382
428
  });
383
429
  if (!response.ok) {
384
- return await throwServiceError(response, 'Failed to get customer service token', errors_1.SignInError);
430
+ return await throwServiceError(response, 'Failed to get customer service token', errors_js_1.SignInError);
385
431
  }
386
432
  const tokenResponse = await response.json();
387
433
  if (typeof tokenResponse?.access_token !== 'string') {
388
- throw new errors_1.SignInError('Failed to get customer service token: missing access_token');
434
+ throw new errors_js_1.SignInError('Failed to get customer service token: missing access_token');
389
435
  }
390
436
  return tokenResponse.access_token;
391
437
  }
392
438
  catch (error) {
393
- return await throwServiceError(error, 'Failed to get customer service token', errors_1.SignInError);
439
+ return await throwServiceError(error, 'Failed to get customer service token', errors_js_1.SignInError);
394
440
  }
395
441
  }
396
442
  exports.getCustomerServiceToken = getCustomerServiceToken;
@@ -1 +1 @@
1
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K,UAAU,uBAAuB,CAC3C,GAAQ,EACR,WAAmB;IAEnB,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC,IAAA,kCAA0B,EAAC,GAAG,CAAC,CAAC,CAAC;IAEzE,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,uBAAuB,EAAE;YACpD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,WAAW,EAAE;aACvC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,OAAO,MAAM,iBAAiB,CAC5B,QAAQ,EACR,sCAAsC,EACtC,oBAAW,CACZ,CAAC;QACJ,CAAC;QAED,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,OAAO,aAAa,EAAE,YAAY,KAAK,QAAQ,EAAE,CAAC;YACpD,MAAM,IAAI,oBAAW,CACnB,4DAA4D,CAC7D,CAAC;QACJ,CAAC;QACD,OAAO,aAAa,CAAC,YAAY,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,MAAM,iBAAiB,CAC5B,KAAK,EACL,sCAAsC,EACtC,oBAAW,CACZ,CAAC;IACJ,CAAC;AACH,CAAC;AApCD,0DAoCC","sourcesContent":["import type { Env, Platform } from '../../shared/env';\nimport { getEnvUrls, getOidcClientId } from '../../shared/env';\nimport type { MetaMetricsAuth } from '../../shared/types/services';\nimport { HTTP_STATUS_CODES } from '../constants';\nimport {\n NonceRetrievalError,\n PairError,\n SignInError,\n ValidationError,\n RateLimitedError,\n} from '../errors';\nimport { validatePairResponse } from '../utils/validate-pair-response';\nimport type {\n AccessToken,\n ErrorMessage,\n ProfileAlias,\n UserProfile,\n UserProfileLineage,\n} from './types';\nimport { AuthType } from './types';\n\n/**\n * Parse Retry-After header into milliseconds if possible.\n * Supports seconds or HTTP-date formats.\n *\n * @param retryAfterHeader - The Retry-After header value (seconds or HTTP-date)\n * @returns The retry delay in milliseconds, or null if parsing fails\n */\nfunction parseRetryAfter(retryAfterHeader: string | null): number | null {\n if (!retryAfterHeader) {\n return null;\n }\n const seconds = Number(retryAfterHeader);\n if (!Number.isNaN(seconds)) {\n return seconds * 1000;\n }\n const date = Date.parse(retryAfterHeader);\n if (!Number.isNaN(date)) {\n const diff = date - Date.now();\n return diff > 0 ? diff : null;\n }\n return null;\n}\n\n/**\n * Extracts error details from a Response object.\n *\n * @param response - The HTTP response object\n * @returns Formatted error message with HTTP status and response body\n */\nasync function getResponseErrorMessage(response: Response): Promise<string> {\n const { status } = response;\n const clonedResponse = response.clone();\n\n let message = 'Unknown error';\n let error = 'unknown';\n\n try {\n const responseBody = (await response.json()) as\n | ErrorMessage\n // eslint-disable-next-line @typescript-eslint/naming-convention\n | { error_description: string; error: string };\n\n message =\n 'message' in responseBody\n ? responseBody.message\n : responseBody.error_description;\n error = responseBody.error ?? 'unknown';\n } catch {\n try {\n const textContent = await clonedResponse.text();\n message = textContent\n ? textContent.slice(0, 150)\n : 'Non-JSON error response';\n error = 'non_json_response';\n } catch {\n message = 'Unable to parse error response';\n error = 'unparseable_response';\n }\n }\n\n return `HTTP ${status} - ${message} (error: ${error})`;\n}\n\n/**\n * Type guard to check if an object is a Response-like object.\n *\n * @param obj - The object to check\n * @returns True if the object is a Response-like object, false otherwise\n */\nconst isErrorResponse = (obj: unknown): obj is Response =>\n typeof obj === 'object' &&\n obj !== null &&\n 'status' in obj &&\n 'headers' in obj;\n\n/**\n * Throws a domain-specific error for service failures.\n * Handles both HTTP error responses and regular errors (network failures, etc.).\n * For HTTP 429, throws RateLimitedError with Retry-After header parsing.\n *\n * @param error - The error (Response object or caught error)\n * @param errorPrefix - Context prefix for the error message\n * @param ErrorClass - The domain-specific error class to throw\n * @throws RateLimitedError for 429, otherwise ErrorClass\n */\nasync function throwServiceError(\n error: unknown,\n errorPrefix: string,\n ErrorClass: new (message: string) => Error,\n): Promise<never> {\n // Re-throw RateLimitedError or matching ErrorClass as-is (don't double-wrap)\n if (error instanceof RateLimitedError || error instanceof ErrorClass) {\n throw error;\n }\n\n // Not a Response-like object - handle as regular error\n if (!isErrorResponse(error)) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new ErrorClass(`${errorPrefix}: ${errorMessage}`);\n }\n\n // Handle HTTP error response\n const response = error;\n const { status } = response;\n const responseMessage = await getResponseErrorMessage(response);\n\n if (status === HTTP_STATUS_CODES.TOO_MANY_REQUESTS) {\n const retryAfterHeader = response.headers.get('Retry-After');\n const retryAfterMs = parseRetryAfter(retryAfterHeader);\n throw new RateLimitedError(\n `${errorPrefix}: ${responseMessage}`,\n retryAfterMs ?? undefined,\n );\n }\n\n throw new ErrorClass(`${errorPrefix}: ${responseMessage}`);\n}\n\nexport const NONCE_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/nonce`;\n\nexport const PAIR_IDENTIFIERS = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/identifiers/pair`;\n\nexport const OIDC_TOKEN_URL = (env: Env): string =>\n `${getEnvUrls(env).oidcApiUrl}/oauth2/token`;\n\nexport const SRP_LOGIN_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/srp/login`;\n\nexport const SIWE_LOGIN_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/siwe/login`;\n\nexport const PAIR_PROFILES_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/profile/pair`;\n\nexport const PROFILE_LINEAGE_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/profile/lineage`;\n\nexport const CUSTOMER_SERVICE_TOKEN_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/customer-service/token`;\n\nconst getAuthenticationUrl = (authType: AuthType, env: Env): string => {\n switch (authType) {\n case AuthType.SRP:\n return SRP_LOGIN_URL(env);\n case AuthType.SiWE:\n return SIWE_LOGIN_URL(env);\n /* istanbul ignore next */\n default:\n throw new ValidationError(\n `Invalid AuthType: ${authType as number} - unable to create Auth URL`,\n );\n }\n};\n\ntype NonceResponse = {\n nonce: string;\n identifier: string;\n expiresIn: number;\n};\n\ntype RawProfileAlias = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n alias_profile_id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n canonical_profile_id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_ids: { id: string; type: string }[];\n};\n\nconst parseProfileAliases = (raw: RawProfileAlias[]): ProfileAlias[] => {\n return raw.map((alias) => ({\n aliasProfileId: alias.alias_profile_id,\n canonicalProfileId: alias.canonical_profile_id,\n identifierIds: alias.identifier_ids ?? [],\n }));\n};\n\ntype PairRequest = {\n signature: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n encrypted_storage_key: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_type: 'SIWE' | 'SRP';\n};\n\n/**\n * Pair multiple identifiers under a single profile\n *\n * @param nonce - session nonce\n * @param logins - pairing request payload\n * @param accessToken - JWT access token used to access protected resources\n * @param env - server environment\n * @returns void.\n */\nexport async function pairIdentifiers(\n nonce: string,\n logins: PairRequest[],\n accessToken: string,\n env: Env,\n): Promise<void> {\n const pairUrl = new URL(PAIR_IDENTIFIERS(env));\n\n try {\n const response = await fetch(pairUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n body: JSON.stringify({\n nonce,\n logins,\n }),\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to pair identifiers',\n PairError,\n );\n }\n return undefined;\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to pair identifiers',\n PairError,\n );\n }\n}\n\nexport type PairProfilesResponse = {\n profile: UserProfile;\n profileAliases: ProfileAlias[];\n};\n\n/**\n * Pair multiple profiles using their OIDC access tokens.\n * Idempotent — calling with already-paired tokens is a no-op.\n *\n * @param accessTokens - Two or more OIDC access tokens to pair\n * @param authAccessToken - A valid access token for the Authorization header\n * @param env - server environment\n * @returns The pair response containing the canonical profile and aliases\n */\nexport async function pairProfiles(\n accessTokens: string[],\n authAccessToken: string,\n env: Env,\n): Promise<PairProfilesResponse> {\n const pairUrl = new URL(PAIR_PROFILES_URL(env));\n\n try {\n const response = await fetch(pairUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${authAccessToken}`,\n },\n body: JSON.stringify({\n jwts: accessTokens,\n }),\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to pair profiles',\n PairError,\n );\n }\n\n const pairResponse: unknown = await response.json();\n validatePairResponse(pairResponse);\n\n return {\n profile: {\n identifierId: pairResponse.profile.identifier_id,\n metaMetricsId: pairResponse.profile.metametrics_id ?? '',\n profileId: pairResponse.profile.profile_id,\n canonicalProfileId: pairResponse.profile.profile_id,\n },\n profileAliases: parseProfileAliases(pairResponse.profile_aliases ?? []),\n };\n } catch (error) {\n return await throwServiceError(error, 'Failed to pair profiles', PairError);\n }\n}\n\n/**\n * Service to Get Nonce for JWT Bearer Flow\n *\n * @param id - identifier ID\n * @param env - server environment\n * @returns the nonce.\n */\nexport async function getNonce(id: string, env: Env): Promise<NonceResponse> {\n const nonceUrl = new URL(NONCE_URL(env));\n nonceUrl.searchParams.set('identifier', id);\n\n try {\n const nonceResponse = await fetch(nonceUrl.toString());\n if (!nonceResponse.ok) {\n return await throwServiceError(\n nonceResponse,\n 'Failed to get nonce',\n NonceRetrievalError,\n );\n }\n\n const nonceJson = await nonceResponse.json();\n return {\n nonce: nonceJson.nonce,\n identifier: nonceJson.identifier,\n expiresIn: nonceJson.expires_in,\n };\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to get nonce',\n NonceRetrievalError,\n );\n }\n}\n\n/**\n * Service to Authorize And perform OIDC Flow to get the Access Token\n *\n * @param jwtToken - The original token received from Authentication. This is traded for the Access Token. (the authentication token is single-use)\n * @param env - server environment\n * @param platform - SDK platform\n * @returns Access Token from Authorization server\n */\nexport async function authorizeOIDC(\n jwtToken: string,\n env: Env,\n platform: Platform,\n): Promise<AccessToken> {\n const grantType = 'urn:ietf:params:oauth:grant-type:jwt-bearer';\n const headers = {\n 'Content-Type': 'application/x-www-form-urlencoded',\n };\n\n const urlEncodedBody = new URLSearchParams();\n urlEncodedBody.append('grant_type', grantType);\n urlEncodedBody.append('client_id', getOidcClientId(env, platform));\n urlEncodedBody.append('assertion', jwtToken);\n\n try {\n const response = await fetch(OIDC_TOKEN_URL(env), {\n method: 'POST',\n headers,\n body: urlEncodedBody.toString(),\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to get access token',\n SignInError,\n );\n }\n\n const accessTokenResponse = await response.json();\n return {\n accessToken: accessTokenResponse.access_token,\n expiresIn: accessTokenResponse.expires_in,\n obtainedAt: Date.now(),\n };\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to get access token',\n SignInError,\n );\n }\n}\n\ntype Authentication = {\n token: string;\n expiresIn: number;\n profile: UserProfile;\n profileAliases: ProfileAlias[];\n};\n/**\n * Service to Authenticate/Login a user via SIWE or SRP derived key.\n *\n * @param rawMessage - raw message for validation when authenticating\n * @param signature - signed raw message\n * @param authType - authentication type/flow used\n * @param env - server environment\n * @param metametrics - optional metametrics\n * @returns Authentication Token\n */\nexport async function authenticate(\n rawMessage: string,\n signature: string,\n authType: AuthType,\n env: Env,\n metametrics?: MetaMetricsAuth,\n): Promise<Authentication> {\n const authenticationUrl = getAuthenticationUrl(authType, env);\n\n try {\n const response = await fetch(authenticationUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...(authType === AuthType.SRP\n ? { 'X-MetaMask-Profile-Pairing': 'enabled' }\n : {}),\n },\n body: JSON.stringify({\n signature,\n raw_message: rawMessage,\n ...(metametrics\n ? {\n metametrics: {\n metametrics_id: await metametrics.getMetaMetricsId(),\n agent: metametrics.agent,\n app_version: await metametrics.getAppVersion?.(),\n },\n }\n : {}),\n }),\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n `Failed to login with ${authType}`,\n SignInError,\n );\n }\n\n const loginResponse = await response.json();\n\n return {\n token: loginResponse.token,\n expiresIn: loginResponse.expires_in,\n profile: {\n identifierId: loginResponse.profile.identifier_id,\n metaMetricsId: loginResponse.profile.metametrics_id,\n profileId: loginResponse.profile.profile_id,\n canonicalProfileId: loginResponse.profile.profile_id,\n },\n profileAliases: parseProfileAliases(loginResponse.profile_aliases ?? []),\n };\n } catch (error) {\n return await throwServiceError(\n error,\n `Failed to login with ${authType}`,\n SignInError,\n );\n }\n}\n\n/**\n * Service to get the Profile Lineage\n *\n * @param env - server environment\n * @param accessToken - JWT access token used to access protected resources\n * @returns Profile Lineage information.\n */\nexport async function getUserProfileLineage(\n env: Env,\n accessToken: string,\n): Promise<UserProfileLineage> {\n const profileLineageUrl = new URL(PROFILE_LINEAGE_URL(env));\n\n try {\n const response = await fetch(profileLineageUrl, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to get profile lineage',\n SignInError,\n );\n }\n\n const profileJson: UserProfileLineage = await response.json();\n return profileJson;\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to get profile lineage',\n SignInError,\n );\n }\n}\n\n/**\n * Service to get a Customer Service specific access token.\n *\n * Exchanges a valid OIDC access token for a short-lived token scoped to the\n * customer-service audience, which Customer Service tooling consumes to\n * identify and authenticate the user.\n *\n * @param env - server environment\n * @param accessToken - JWT access token used to access protected resources\n * @returns The customer-service access token.\n */\nexport async function getCustomerServiceToken(\n env: Env,\n accessToken: string,\n): Promise<string> {\n const customerServiceTokenUrl = new URL(CUSTOMER_SERVICE_TOKEN_URL(env));\n\n try {\n const response = await fetch(customerServiceTokenUrl, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to get customer service token',\n SignInError,\n );\n }\n\n const tokenResponse = await response.json();\n if (typeof tokenResponse?.access_token !== 'string') {\n throw new SignInError(\n 'Failed to get customer service token: missing access_token',\n );\n }\n return tokenResponse.access_token;\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to get customer service token',\n SignInError,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/services.ts"],"names":[],"mappings":";;;AACA,iDAAkE;AAElE,mDAAoD;AACpD,6CAOsB;AACtB,mFAA0E;AAU1E,0CAAsC;AAEtC;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,gBAA+B;IACtD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/B,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,uBAAuB,CAAC,QAAkB;IACvD,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IAC5B,MAAM,cAAc,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;IAExC,IA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.js';\nimport { getEnvUrls, getOidcClientId } from '../../shared/env.js';\nimport type { MetaMetricsAuth } from '../../shared/types/services.js';\nimport { HTTP_STATUS_CODES } from '../constants.js';\nimport {\n NonceRetrievalError,\n PairConflictError,\n PairError,\n SignInError,\n ValidationError,\n RateLimitedError,\n} from '../errors.js';\nimport { validatePairResponse } from '../utils/validate-pair-response.js';\nimport type {\n AccessToken,\n ErrorMessage,\n LoginIdentifierType,\n PairSocialIdentifierParams,\n ProfileAlias,\n UserProfile,\n UserProfileLineage,\n} from './types.js';\nimport { AuthType } from './types.js';\n\n/**\n * Parse Retry-After header into milliseconds if possible.\n * Supports seconds or HTTP-date formats.\n *\n * @param retryAfterHeader - The Retry-After header value (seconds or HTTP-date)\n * @returns The retry delay in milliseconds, or null if parsing fails\n */\nfunction parseRetryAfter(retryAfterHeader: string | null): number | null {\n if (!retryAfterHeader) {\n return null;\n }\n const seconds = Number(retryAfterHeader);\n if (!Number.isNaN(seconds)) {\n return seconds * 1000;\n }\n const date = Date.parse(retryAfterHeader);\n if (!Number.isNaN(date)) {\n const diff = date - Date.now();\n return diff > 0 ? diff : null;\n }\n return null;\n}\n\n/**\n * Extracts error details from a Response object.\n *\n * @param response - The HTTP response object\n * @returns Formatted error message with HTTP status and response body\n */\nasync function getResponseErrorMessage(response: Response): Promise<string> {\n const { status } = response;\n const clonedResponse = response.clone();\n\n let message = 'Unknown error';\n let error = 'unknown';\n\n try {\n const responseBody = (await response.json()) as\n | ErrorMessage\n // eslint-disable-next-line @typescript-eslint/naming-convention\n | { error_description: string; error: string };\n\n message =\n 'message' in responseBody\n ? responseBody.message\n : responseBody.error_description;\n error = responseBody.error ?? 'unknown';\n } catch {\n try {\n const textContent = await clonedResponse.text();\n message = textContent\n ? textContent.slice(0, 150)\n : 'Non-JSON error response';\n error = 'non_json_response';\n } catch {\n message = 'Unable to parse error response';\n error = 'unparseable_response';\n }\n }\n\n return `HTTP ${status} - ${message} (error: ${error})`;\n}\n\n/**\n * Type guard to check if an object is a Response-like object.\n *\n * @param obj - The object to check\n * @returns True if the object is a Response-like object, false otherwise\n */\nconst isErrorResponse = (obj: unknown): obj is Response =>\n typeof obj === 'object' &&\n obj !== null &&\n 'status' in obj &&\n 'headers' in obj;\n\n/**\n * Throws a domain-specific error for service failures.\n * Handles both HTTP error responses and regular errors (network failures, etc.).\n * For HTTP 429, throws RateLimitedError with Retry-After header parsing.\n *\n * @param error - The error (Response object or caught error)\n * @param errorPrefix - Context prefix for the error message\n * @param ErrorClass - The domain-specific error class to throw\n * @throws RateLimitedError for 429, otherwise ErrorClass\n */\nasync function throwServiceError(\n error: unknown,\n errorPrefix: string,\n ErrorClass: new (message: string) => Error,\n): Promise<never> {\n // Re-throw RateLimitedError or matching ErrorClass as-is (don't double-wrap)\n if (error instanceof RateLimitedError || error instanceof ErrorClass) {\n throw error;\n }\n\n // Not a Response-like object - handle as regular error\n if (!isErrorResponse(error)) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new ErrorClass(`${errorPrefix}: ${errorMessage}`);\n }\n\n // Handle HTTP error response\n const response = error;\n const { status } = response;\n const responseMessage = await getResponseErrorMessage(response);\n\n if (status === HTTP_STATUS_CODES.TOO_MANY_REQUESTS) {\n const retryAfterHeader = response.headers.get('Retry-After');\n const retryAfterMs = parseRetryAfter(retryAfterHeader);\n throw new RateLimitedError(\n `${errorPrefix}: ${responseMessage}`,\n retryAfterMs ?? undefined,\n );\n }\n\n throw new ErrorClass(`${errorPrefix}: ${responseMessage}`);\n}\n\nexport const NONCE_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/nonce`;\n\nexport const PAIR_IDENTIFIERS = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/identifiers/pair`;\n\nexport const OIDC_TOKEN_URL = (env: Env): string =>\n `${getEnvUrls(env).oidcApiUrl}/oauth2/token`;\n\nexport const SRP_LOGIN_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/srp/login`;\n\nexport const SIWE_LOGIN_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/siwe/login`;\n\nexport const PAIR_PROFILES_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/profile/pair`;\n\nexport const PAIR_SOCIAL_IDENTIFIER_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/profile/pair/identifier`;\n\nexport const PROFILE_LINEAGE_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/profile/lineage`;\n\nexport const CUSTOMER_SERVICE_TOKEN_URL = (env: Env): string =>\n `${getEnvUrls(env).authApiUrl}/api/v2/customer-service/token`;\n\nconst getAuthenticationUrl = (authType: AuthType, env: Env): string => {\n switch (authType) {\n case AuthType.SRP:\n return SRP_LOGIN_URL(env);\n case AuthType.SiWE:\n return SIWE_LOGIN_URL(env);\n /* istanbul ignore next */\n default:\n throw new ValidationError(\n `Invalid AuthType: ${authType as number} - unable to create Auth URL`,\n );\n }\n};\n\ntype NonceResponse = {\n nonce: string;\n identifier: string;\n expiresIn: number;\n};\n\ntype RawProfileAlias = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n alias_profile_id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n canonical_profile_id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_ids: { id: string; type: string }[];\n};\n\nconst parseProfileAliases = (raw: RawProfileAlias[]): ProfileAlias[] => {\n return raw.map((alias) => ({\n aliasProfileId: alias.alias_profile_id,\n canonicalProfileId: alias.canonical_profile_id,\n identifierIds: alias.identifier_ids ?? [],\n }));\n};\n\ntype PairRequest = {\n signature: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n encrypted_storage_key: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_type: 'SIWE' | 'SRP';\n};\n\n/**\n * Pair multiple identifiers under a single profile\n *\n * @param nonce - session nonce\n * @param logins - pairing request payload\n * @param accessToken - JWT access token used to access protected resources\n * @param env - server environment\n * @returns void.\n */\nexport async function pairIdentifiers(\n nonce: string,\n logins: PairRequest[],\n accessToken: string,\n env: Env,\n): Promise<void> {\n const pairUrl = new URL(PAIR_IDENTIFIERS(env));\n\n try {\n const response = await fetch(pairUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n body: JSON.stringify({\n nonce,\n logins,\n }),\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to pair identifiers',\n PairError,\n );\n }\n return undefined;\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to pair identifiers',\n PairError,\n );\n }\n}\n\nexport type PairProfilesResponse = {\n profile: UserProfile;\n profileAliases: ProfileAlias[];\n};\n\n/**\n * Pair multiple profiles using their OIDC access tokens.\n * Idempotent — calling with already-paired tokens is a no-op.\n *\n * @param accessTokens - Two or more OIDC access tokens to pair\n * @param authAccessToken - A valid access token for the Authorization header\n * @param env - server environment\n * @returns The pair response containing the canonical profile and aliases\n */\nexport async function pairProfiles(\n accessTokens: string[],\n authAccessToken: string,\n env: Env,\n): Promise<PairProfilesResponse> {\n const pairUrl = new URL(PAIR_PROFILES_URL(env));\n\n try {\n const response = await fetch(pairUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${authAccessToken}`,\n },\n body: JSON.stringify({\n jwts: accessTokens,\n }),\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to pair profiles',\n PairError,\n );\n }\n\n const pairResponse: unknown = await response.json();\n validatePairResponse(pairResponse);\n\n return {\n profile: {\n identifierId: pairResponse.profile.identifier_id,\n metaMetricsId: pairResponse.profile.metametrics_id ?? '',\n profileId: pairResponse.profile.profile_id,\n canonicalProfileId: pairResponse.profile.profile_id,\n },\n profileAliases: parseProfileAliases(pairResponse.profile_aliases ?? []),\n };\n } catch (error) {\n return await throwServiceError(error, 'Failed to pair profiles', PairError);\n }\n}\n\n/**\n * Attach a Google/Apple/Telegram social identifier to the profile that\n * owns `authAccessToken` (`POST /api/v2/profile/pair/identifier`).\n *\n * `email` is omitted from the body when undefined. 409 Conflict throws\n * {@link PairConflictError} so callers can treat it as terminal. The\n * response body (new token + profile) is not consumed: a 2xx status is the\n * only success signal.\n *\n * @param params - Social identifier type, social JWT, and optional email\n * @param authAccessToken - Bearer token of the canonical (primary SRP) profile\n * @param env - server environment\n */\nexport async function pairSocialIdentifier(\n params: PairSocialIdentifierParams,\n authAccessToken: string,\n env: Env,\n): Promise<void> {\n const pairUrl = new URL(PAIR_SOCIAL_IDENTIFIER_URL(env));\n const errorPrefix = 'Failed to pair social identifier';\n\n try {\n const response = await fetch(pairUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${authAccessToken}`,\n },\n body: JSON.stringify({\n identifier_type: params.identifierType,\n social_jwt: params.socialJwt,\n ...(params.email === undefined ? {} : { email: params.email }),\n }),\n });\n\n if (!response.ok) {\n if (response.status === HTTP_STATUS_CODES.CONFLICT) {\n await throwServiceError(response, errorPrefix, PairConflictError);\n }\n await throwServiceError(response, errorPrefix, PairError);\n }\n } catch (error) {\n await throwServiceError(error, errorPrefix, PairError);\n }\n}\n\n/**\n * Service to Get Nonce for JWT Bearer Flow\n *\n * @param id - identifier ID\n * @param env - server environment\n * @returns the nonce.\n */\nexport async function getNonce(id: string, env: Env): Promise<NonceResponse> {\n const nonceUrl = new URL(NONCE_URL(env));\n nonceUrl.searchParams.set('identifier', id);\n\n try {\n const nonceResponse = await fetch(nonceUrl.toString());\n if (!nonceResponse.ok) {\n return await throwServiceError(\n nonceResponse,\n 'Failed to get nonce',\n NonceRetrievalError,\n );\n }\n\n const nonceJson = await nonceResponse.json();\n return {\n nonce: nonceJson.nonce,\n identifier: nonceJson.identifier,\n expiresIn: nonceJson.expires_in,\n };\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to get nonce',\n NonceRetrievalError,\n );\n }\n}\n\n/**\n * Service to Authorize And perform OIDC Flow to get the Access Token\n *\n * @param jwtToken - The original token received from Authentication. This is traded for the Access Token. (the authentication token is single-use)\n * @param env - server environment\n * @param platform - SDK platform\n * @returns Access Token from Authorization server\n */\nexport async function authorizeOIDC(\n jwtToken: string,\n env: Env,\n platform: Platform,\n): Promise<AccessToken> {\n const grantType = 'urn:ietf:params:oauth:grant-type:jwt-bearer';\n const headers = {\n 'Content-Type': 'application/x-www-form-urlencoded',\n };\n\n const urlEncodedBody = new URLSearchParams();\n urlEncodedBody.append('grant_type', grantType);\n urlEncodedBody.append('client_id', getOidcClientId(env, platform));\n urlEncodedBody.append('assertion', jwtToken);\n\n try {\n const response = await fetch(OIDC_TOKEN_URL(env), {\n method: 'POST',\n headers,\n body: urlEncodedBody.toString(),\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to get access token',\n SignInError,\n );\n }\n\n const accessTokenResponse = await response.json();\n return {\n accessToken: accessTokenResponse.access_token,\n expiresIn: accessTokenResponse.expires_in,\n obtainedAt: Date.now(),\n };\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to get access token',\n SignInError,\n );\n }\n}\n\ntype Authentication = {\n token: string;\n expiresIn: number;\n profile: UserProfile;\n profileAliases: ProfileAlias[];\n};\n/**\n * Service to Authenticate/Login a user via SIWE or SRP derived key.\n *\n * @param rawMessage - raw message for validation when authenticating\n * @param signature - signed raw message\n * @param authType - authentication type/flow used\n * @param env - server environment\n * @param metametrics - optional metametrics\n * @param identifierType - login identifier type included in metametrics\n * (defaults to `SRP` when metametrics is present)\n * @returns Authentication Token\n */\nexport async function authenticate(\n rawMessage: string,\n signature: string,\n authType: AuthType,\n env: Env,\n metametrics?: MetaMetricsAuth,\n identifierType: LoginIdentifierType = 'SRP',\n): Promise<Authentication> {\n const authenticationUrl = getAuthenticationUrl(authType, env);\n\n try {\n const response = await fetch(authenticationUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...(authType === AuthType.SRP\n ? { 'X-MetaMask-Profile-Pairing': 'enabled' }\n : {}),\n },\n body: JSON.stringify({\n signature,\n raw_message: rawMessage,\n ...(metametrics\n ? {\n metametrics: {\n metametrics_id: await metametrics.getMetaMetricsId(),\n agent: metametrics.agent,\n app_version: await metametrics.getAppVersion?.(),\n identifier_type: identifierType,\n },\n }\n : {}),\n }),\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n `Failed to login with ${authType}`,\n SignInError,\n );\n }\n\n const loginResponse = await response.json();\n\n return {\n token: loginResponse.token,\n expiresIn: loginResponse.expires_in,\n profile: {\n identifierId: loginResponse.profile.identifier_id,\n metaMetricsId: loginResponse.profile.metametrics_id,\n profileId: loginResponse.profile.profile_id,\n canonicalProfileId: loginResponse.profile.profile_id,\n },\n profileAliases: parseProfileAliases(loginResponse.profile_aliases ?? []),\n };\n } catch (error) {\n return await throwServiceError(\n error,\n `Failed to login with ${authType}`,\n SignInError,\n );\n }\n}\n\n/**\n * Service to get the Profile Lineage\n *\n * @param env - server environment\n * @param accessToken - JWT access token used to access protected resources\n * @returns Profile Lineage information.\n */\nexport async function getUserProfileLineage(\n env: Env,\n accessToken: string,\n): Promise<UserProfileLineage> {\n const profileLineageUrl = new URL(PROFILE_LINEAGE_URL(env));\n\n try {\n const response = await fetch(profileLineageUrl, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to get profile lineage',\n SignInError,\n );\n }\n\n const profileJson: UserProfileLineage = await response.json();\n return profileJson;\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to get profile lineage',\n SignInError,\n );\n }\n}\n\n/**\n * Service to get a Customer Service specific access token.\n *\n * Exchanges a valid OIDC access token for a short-lived token scoped to the\n * customer-service audience, which Customer Service tooling consumes to\n * identify and authenticate the user.\n *\n * @param env - server environment\n * @param accessToken - JWT access token used to access protected resources\n * @returns The customer-service access token.\n */\nexport async function getCustomerServiceToken(\n env: Env,\n accessToken: string,\n): Promise<string> {\n const customerServiceTokenUrl = new URL(CUSTOMER_SERVICE_TOKEN_URL(env));\n\n try {\n const response = await fetch(customerServiceTokenUrl, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n return await throwServiceError(\n response,\n 'Failed to get customer service token',\n SignInError,\n );\n }\n\n const tokenResponse = await response.json();\n if (typeof tokenResponse?.access_token !== 'string') {\n throw new SignInError(\n 'Failed to get customer service token: missing access_token',\n );\n }\n return tokenResponse.access_token;\n } catch (error) {\n return await throwServiceError(\n error,\n 'Failed to get customer service token',\n SignInError,\n );\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { Env, Platform } from "../../shared/env.cjs";
2
2
  import type { MetaMetricsAuth } from "../../shared/types/services.cjs";
3
- import type { AccessToken, ProfileAlias, UserProfile, UserProfileLineage } from "./types.cjs";
3
+ import type { AccessToken, LoginIdentifierType, PairSocialIdentifierParams, ProfileAlias, UserProfile, UserProfileLineage } from "./types.cjs";
4
4
  import { AuthType } from "./types.cjs";
5
5
  export declare const NONCE_URL: (env: Env) => string;
6
6
  export declare const PAIR_IDENTIFIERS: (env: Env) => string;
@@ -8,6 +8,7 @@ export declare const OIDC_TOKEN_URL: (env: Env) => string;
8
8
  export declare const SRP_LOGIN_URL: (env: Env) => string;
9
9
  export declare const SIWE_LOGIN_URL: (env: Env) => string;
10
10
  export declare const PAIR_PROFILES_URL: (env: Env) => string;
11
+ export declare const PAIR_SOCIAL_IDENTIFIER_URL: (env: Env) => string;
11
12
  export declare const PROFILE_LINEAGE_URL: (env: Env) => string;
12
13
  export declare const CUSTOMER_SERVICE_TOKEN_URL: (env: Env) => string;
13
14
  type NonceResponse = {
@@ -45,6 +46,20 @@ export type PairProfilesResponse = {
45
46
  * @returns The pair response containing the canonical profile and aliases
46
47
  */
47
48
  export declare function pairProfiles(accessTokens: string[], authAccessToken: string, env: Env): Promise<PairProfilesResponse>;
49
+ /**
50
+ * Attach a Google/Apple/Telegram social identifier to the profile that
51
+ * owns `authAccessToken` (`POST /api/v2/profile/pair/identifier`).
52
+ *
53
+ * `email` is omitted from the body when undefined. 409 Conflict throws
54
+ * {@link PairConflictError} so callers can treat it as terminal. The
55
+ * response body (new token + profile) is not consumed: a 2xx status is the
56
+ * only success signal.
57
+ *
58
+ * @param params - Social identifier type, social JWT, and optional email
59
+ * @param authAccessToken - Bearer token of the canonical (primary SRP) profile
60
+ * @param env - server environment
61
+ */
62
+ export declare function pairSocialIdentifier(params: PairSocialIdentifierParams, authAccessToken: string, env: Env): Promise<void>;
48
63
  /**
49
64
  * Service to Get Nonce for JWT Bearer Flow
50
65
  *
@@ -76,9 +91,11 @@ type Authentication = {
76
91
  * @param authType - authentication type/flow used
77
92
  * @param env - server environment
78
93
  * @param metametrics - optional metametrics
94
+ * @param identifierType - login identifier type included in metametrics
95
+ * (defaults to `SRP` when metametrics is present)
79
96
  * @returns Authentication Token
80
97
  */
81
- export declare function authenticate(rawMessage: string, signature: string, authType: AuthType, env: Env, metametrics?: MetaMetricsAuth): Promise<Authentication>;
98
+ export declare function authenticate(rawMessage: string, signature: string, authType: AuthType, env: Env, metametrics?: MetaMetricsAuth, identifierType?: LoginIdentifierType): Promise<Authentication>;
82
99
  /**
83
100
  * Service to get the Profile Lineage
84
101
  *
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,6BAAyB;AAEtD,OAAO,KAAK,EAAE,eAAe,EAAE,wCAAoC;AAUnE,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EACZ,WAAW,EACX,kBAAkB,EACnB,oBAAgB;AACjB,OAAO,EAAE,QAAQ,EAAE,oBAAgB;AAwHnC,eAAO,MAAM,SAAS,QAAS,GAAG,KAAG,MACS,CAAC;AA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CAAC,aAAa,CAAC,CA2B3E;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,WAAW,CAAC,CAuCtB;AAED,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,EAAE,YAAY,EAAE,CAAC;CAChC,CAAC;AACF;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,WAAW,CAAC,EAAE,eAAe,GAC5B,OAAO,CAAC,cAAc,CAAC,CAuDzB;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CA4B7B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAiCjB"}
1
+ {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,6BAA4B;AAEzD,OAAO,KAAK,EAAE,eAAe,EAAE,wCAAuC;AAWtE,OAAO,KAAK,EACV,WAAW,EAEX,mBAAmB,EACnB,0BAA0B,EAC1B,YAAY,EACZ,WAAW,EACX,kBAAkB,EACnB,oBAAmB;AACpB,OAAO,EAAE,QAAQ,EAAE,oBAAmB;AAwHtC,eAAO,MAAM,SAAS,QAAS,GAAG,KAAG,MACS,CAAC;AAE/C,eAAO,MAAM,gBAAgB,QAAS,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EAClC,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,GAAG,GACP,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CA2B3E;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,WAAW,CAAC,CAuCtB;AAED,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC;IACrB,cAAc,EAAE,YAAY,EAAE,CAAC;CAChC,CAAC;AACF;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,WAAW,CAAC,EAAE,eAAe,EAC7B,cAAc,GAAE,mBAA2B,GAC1C,OAAO,CAAC,cAAc,CAAC,CAwDzB;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CA4B7B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAiCjB"}
@@ -1,6 +1,6 @@
1
1
  import type { Env, Platform } from "../../shared/env.mjs";
2
2
  import type { MetaMetricsAuth } from "../../shared/types/services.mjs";
3
- import type { AccessToken, ProfileAlias, UserProfile, UserProfileLineage } from "./types.mjs";
3
+ import type { AccessToken, LoginIdentifierType, PairSocialIdentifierParams, ProfileAlias, UserProfile, UserProfileLineage } from "./types.mjs";
4
4
  import { AuthType } from "./types.mjs";
5
5
  export declare const NONCE_URL: (env: Env) => string;
6
6
  export declare const PAIR_IDENTIFIERS: (env: Env) => string;
@@ -8,6 +8,7 @@ export declare const OIDC_TOKEN_URL: (env: Env) => string;
8
8
  export declare const SRP_LOGIN_URL: (env: Env) => string;
9
9
  export declare const SIWE_LOGIN_URL: (env: Env) => string;
10
10
  export declare const PAIR_PROFILES_URL: (env: Env) => string;
11
+ export declare const PAIR_SOCIAL_IDENTIFIER_URL: (env: Env) => string;
11
12
  export declare const PROFILE_LINEAGE_URL: (env: Env) => string;
12
13
  export declare const CUSTOMER_SERVICE_TOKEN_URL: (env: Env) => string;
13
14
  type NonceResponse = {
@@ -45,6 +46,20 @@ export type PairProfilesResponse = {
45
46
  * @returns The pair response containing the canonical profile and aliases
46
47
  */
47
48
  export declare function pairProfiles(accessTokens: string[], authAccessToken: string, env: Env): Promise<PairProfilesResponse>;
49
+ /**
50
+ * Attach a Google/Apple/Telegram social identifier to the profile that
51
+ * owns `authAccessToken` (`POST /api/v2/profile/pair/identifier`).
52
+ *
53
+ * `email` is omitted from the body when undefined. 409 Conflict throws
54
+ * {@link PairConflictError} so callers can treat it as terminal. The
55
+ * response body (new token + profile) is not consumed: a 2xx status is the
56
+ * only success signal.
57
+ *
58
+ * @param params - Social identifier type, social JWT, and optional email
59
+ * @param authAccessToken - Bearer token of the canonical (primary SRP) profile
60
+ * @param env - server environment
61
+ */
62
+ export declare function pairSocialIdentifier(params: PairSocialIdentifierParams, authAccessToken: string, env: Env): Promise<void>;
48
63
  /**
49
64
  * Service to Get Nonce for JWT Bearer Flow
50
65
  *
@@ -76,9 +91,11 @@ type Authentication = {
76
91
  * @param authType - authentication type/flow used
77
92
  * @param env - server environment
78
93
  * @param metametrics - optional metametrics
94
+ * @param identifierType - login identifier type included in metametrics
95
+ * (defaults to `SRP` when metametrics is present)
79
96
  * @returns Authentication Token
80
97
  */
81
- export declare function authenticate(rawMessage: string, signature: string, authType: AuthType, env: Env, metametrics?: MetaMetricsAuth): Promise<Authentication>;
98
+ export declare function authenticate(rawMessage: string, signature: string, authType: AuthType, env: Env, metametrics?: MetaMetricsAuth, identifierType?: LoginIdentifierType): Promise<Authentication>;
82
99
  /**
83
100
  * Service to get the Profile Lineage
84
101
  *
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,6BAAyB;AAEtD,OAAO,KAAK,EAAE,eAAe,EAAE,wCAAoC;AAUnE,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EACZ,WAAW,EACX,kBAAkB,EACnB,oBAAgB;AACjB,OAAO,EAAE,QAAQ,EAAE,oBAAgB;AAwHnC,eAAO,MAAM,SAAS,QAAS,GAAG,KAAG,MACS,CAAC;AAE/C,eAAO,MAAM,gBAAgB,QAAS,GAAG,KAAG,MACa,CAAC;AAE1D,eAAO,MAAM,cAAc,QAAS,GAAG,KAAG,MACI,CAAC;AAE/C,eAAO,MAAM,aAAa,QAAS,GAAG,KAAG,MACS,CAAC;AAEnD,eAAO,MAAM,cAAc,QAAS,GAAG,KAAG,MACS,CAAC;AAEpD,eAAO,MAAM,iBAAiB,QAAS,GAAG,KAAG,MACQ,CAAC;AAEtD,eAAO,MAAM,mBAAmB,QAAS,GAAG,KAAG,MACS,CAAC;AAEzD,eAAO,MAAM,0BAA0B,QAAS,GAAG,KAAG,MACS,CAAC;AAgBhE,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAmBF,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,MAAM,CAAC;IAElB,WAAW,EAAE,MAAM,CAAC;IAEpB,qBAAqB,EAAE,MAAM,CAAC;IAE9B,eAAe,EAAE,MA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AAG,EACR,WAAW,CAAC,EAAE,eAAe,EAC7B,cAAc,GAAE,mBAA2B,GAC1C,OAAO,CAAC,cAAc,CAAC,CAwDzB;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CA4B7B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAiCjB"}
@@ -1,6 +1,6 @@
1
1
  import { getEnvUrls, getOidcClientId } from "../../shared/env.mjs";
2
2
  import { HTTP_STATUS_CODES } from "../constants.mjs";
3
- import { NonceRetrievalError, PairError, SignInError, ValidationError, RateLimitedError } from "../errors.mjs";
3
+ import { NonceRetrievalError, PairConflictError, PairError, SignInError, ValidationError, RateLimitedError } from "../errors.mjs";
4
4
  import { validatePairResponse } from "../utils/validate-pair-response.mjs";
5
5
  import { AuthType } from "./types.mjs";
6
6
  /**
@@ -106,6 +106,7 @@ export const OIDC_TOKEN_URL = (env) => `${getEnvUrls(env).oidcApiUrl}/oauth2/tok
106
106
  export const SRP_LOGIN_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/srp/login`;
107
107
  export const SIWE_LOGIN_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/siwe/login`;
108
108
  export const PAIR_PROFILES_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/profile/pair`;
109
+ export const PAIR_SOCIAL_IDENTIFIER_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/profile/pair/identifier`;
109
110
  export const PROFILE_LINEAGE_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/profile/lineage`;
110
111
  export const CUSTOMER_SERVICE_TOKEN_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/customer-service/token`;
111
112
  const getAuthenticationUrl = (authType, env) => {
@@ -199,6 +200,46 @@ export async function pairProfiles(accessTokens, authAccessToken, env) {
199
200
  return await throwServiceError(error, 'Failed to pair profiles', PairError);
200
201
  }
201
202
  }
203
+ /**
204
+ * Attach a Google/Apple/Telegram social identifier to the profile that
205
+ * owns `authAccessToken` (`POST /api/v2/profile/pair/identifier`).
206
+ *
207
+ * `email` is omitted from the body when undefined. 409 Conflict throws
208
+ * {@link PairConflictError} so callers can treat it as terminal. The
209
+ * response body (new token + profile) is not consumed: a 2xx status is the
210
+ * only success signal.
211
+ *
212
+ * @param params - Social identifier type, social JWT, and optional email
213
+ * @param authAccessToken - Bearer token of the canonical (primary SRP) profile
214
+ * @param env - server environment
215
+ */
216
+ export async function pairSocialIdentifier(params, authAccessToken, env) {
217
+ const pairUrl = new URL(PAIR_SOCIAL_IDENTIFIER_URL(env));
218
+ const errorPrefix = 'Failed to pair social identifier';
219
+ try {
220
+ const response = await fetch(pairUrl, {
221
+ method: 'POST',
222
+ headers: {
223
+ 'Content-Type': 'application/json',
224
+ Authorization: `Bearer ${authAccessToken}`,
225
+ },
226
+ body: JSON.stringify({
227
+ identifier_type: params.identifierType,
228
+ social_jwt: params.socialJwt,
229
+ ...(params.email === undefined ? {} : { email: params.email }),
230
+ }),
231
+ });
232
+ if (!response.ok) {
233
+ if (response.status === HTTP_STATUS_CODES.CONFLICT) {
234
+ await throwServiceError(response, errorPrefix, PairConflictError);
235
+ }
236
+ await throwServiceError(response, errorPrefix, PairError);
237
+ }
238
+ }
239
+ catch (error) {
240
+ await throwServiceError(error, errorPrefix, PairError);
241
+ }
242
+ }
202
243
  /**
203
244
  * Service to Get Nonce for JWT Bearer Flow
204
245
  *
@@ -270,9 +311,11 @@ export async function authorizeOIDC(jwtToken, env, platform) {
270
311
  * @param authType - authentication type/flow used
271
312
  * @param env - server environment
272
313
  * @param metametrics - optional metametrics
314
+ * @param identifierType - login identifier type included in metametrics
315
+ * (defaults to `SRP` when metametrics is present)
273
316
  * @returns Authentication Token
274
317
  */
275
- export async function authenticate(rawMessage, signature, authType, env, metametrics) {
318
+ export async function authenticate(rawMessage, signature, authType, env, metametrics, identifierType = 'SRP') {
276
319
  const authenticationUrl = getAuthenticationUrl(authType, env);
277
320
  try {
278
321
  const response = await fetch(authenticationUrl, {
@@ -292,6 +335,7 @@ export async function authenticate(rawMessage, signature, authType, env, metamet
292
335
  metametrics_id: await metametrics.getMetaMetricsId(),
293
336
  agent: metametrics.agent,
294
337
  app_version: await metametrics.getAppVersion?.(),
338
+ identifier_type: identifierType,
295
339
  },
296
340
  }
297
341
  : {}),