@metamask-previews/profile-sync-controller 29.0.0-preview-3866c0ff1 → 29.0.0-preview-e3275932a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs +7 -0
- package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs.map +1 -0
- package/dist/controllers/authentication/{AuthenticationController-method-action-types.d.ts → AuthenticationController-method-action-types.d.cts} +2 -2
- package/dist/controllers/authentication/AuthenticationController-method-action-types.d.cts.map +1 -0
- package/dist/controllers/authentication/AuthenticationController-method-action-types.d.mts +102 -0
- package/dist/controllers/authentication/AuthenticationController-method-action-types.d.mts.map +1 -0
- package/dist/controllers/authentication/{AuthenticationController-method-action-types.js → AuthenticationController-method-action-types.mjs} +1 -1
- package/dist/controllers/authentication/AuthenticationController-method-action-types.mjs.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.cjs +489 -0
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -0
- package/dist/controllers/authentication/{AuthenticationController.d.ts → AuthenticationController.d.cts} +10 -10
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.d.mts +130 -0
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.mjs +485 -0
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -0
- package/dist/controllers/authentication/index.cjs +35 -0
- package/dist/controllers/authentication/index.cjs.map +1 -0
- package/dist/controllers/authentication/{index.d.ts → index.d.cts} +5 -5
- package/dist/controllers/authentication/index.d.cts.map +1 -0
- package/dist/controllers/authentication/index.d.mts +7 -0
- package/dist/controllers/authentication/index.d.mts.map +1 -0
- package/dist/controllers/authentication/index.mjs +6 -0
- package/dist/controllers/authentication/index.mjs.map +1 -0
- package/dist/controllers/authentication/mocks/index.cjs +18 -0
- package/dist/controllers/authentication/mocks/index.cjs.map +1 -0
- package/dist/controllers/authentication/mocks/index.d.cts +2 -0
- package/dist/controllers/authentication/mocks/index.d.cts.map +1 -0
- package/dist/controllers/authentication/mocks/index.d.mts +2 -0
- package/dist/controllers/authentication/mocks/index.d.mts.map +1 -0
- package/dist/controllers/authentication/mocks/index.mjs +2 -0
- package/dist/controllers/authentication/mocks/index.mjs.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.cjs +126 -0
- package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -0
- package/dist/controllers/authentication/mocks/{mockResponses.d.ts → mockResponses.d.cts} +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts +58 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -0
- package/dist/controllers/authentication/mocks/{mockResponses.js → mockResponses.mjs} +2 -2
- package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -0
- package/dist/controllers/index.cjs +29 -0
- package/dist/controllers/index.cjs.map +1 -0
- package/dist/controllers/index.d.cts +3 -0
- package/dist/controllers/index.d.cts.map +1 -0
- package/dist/controllers/index.d.mts +3 -0
- package/dist/controllers/index.d.mts.map +1 -0
- package/dist/controllers/index.mjs +3 -0
- package/dist/controllers/index.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs +7 -0
- package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs.map +1 -0
- package/dist/controllers/user-storage/{UserStorageController-method-action-types.d.ts → UserStorageController-method-action-types.d.cts} +2 -2
- package/dist/controllers/user-storage/UserStorageController-method-action-types.d.cts.map +1 -0
- package/dist/controllers/user-storage/UserStorageController-method-action-types.d.mts +137 -0
- package/dist/controllers/user-storage/UserStorageController-method-action-types.d.mts.map +1 -0
- package/dist/controllers/user-storage/{UserStorageController-method-action-types.js → UserStorageController-method-action-types.mjs} +1 -1
- package/dist/controllers/user-storage/UserStorageController-method-action-types.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.cjs +412 -0
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -0
- package/dist/controllers/user-storage/{UserStorageController.d.ts → UserStorageController.d.cts} +14 -14
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.d.mts +182 -0
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.mjs +408 -0
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -0
- package/dist/controllers/user-storage/constants.cjs +19 -0
- package/dist/controllers/user-storage/constants.cjs.map +1 -0
- package/dist/controllers/user-storage/constants.d.cts +15 -0
- package/dist/controllers/user-storage/constants.d.cts.map +1 -0
- package/dist/controllers/user-storage/constants.d.mts +15 -0
- package/dist/controllers/user-storage/constants.d.mts.map +1 -0
- package/dist/controllers/user-storage/{constants.js → constants.mjs} +1 -1
- package/dist/controllers/user-storage/constants.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/constants.cjs +12 -0
- package/dist/controllers/user-storage/contact-syncing/constants.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/controllers/user-storage/contact-syncing/constants.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/constants.d.mts +9 -0
- package/dist/controllers/user-storage/contact-syncing/constants.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{constants.js → constants.mjs} +1 -1
- package/dist/controllers/user-storage/contact-syncing/constants.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +346 -0
- package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{controller-integration.d.ts → controller-integration.d.cts} +3 -3
- package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts +47 -0
- package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{controller-integration.js → controller-integration.mjs} +6 -6
- package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs +50 -0
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{setup-subscriptions.d.ts → setup-subscriptions.d.cts} +2 -2
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts +8 -0
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{setup-subscriptions.js → setup-subscriptions.mjs} +4 -4
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs +23 -0
- package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{sync-utils.d.ts → sync-utils.d.cts} +2 -2
- package/dist/controllers/user-storage/contact-syncing/sync-utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts +9 -0
- package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{sync-utils.js → sync-utils.mjs} +1 -1
- package/dist/controllers/user-storage/contact-syncing/sync-utils.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/types.cjs +3 -0
- package/dist/controllers/user-storage/contact-syncing/types.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{types.d.ts → types.d.cts} +6 -6
- package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/types.d.mts +37 -0
- package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/types.mjs +2 -0
- package/dist/controllers/user-storage/contact-syncing/types.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/utils.cjs +64 -0
- package/dist/controllers/user-storage/contact-syncing/utils.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{utils.d.ts → utils.d.cts} +3 -3
- package/dist/controllers/user-storage/contact-syncing/utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/utils.d.mts +36 -0
- package/dist/controllers/user-storage/contact-syncing/utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{utils.js → utils.mjs} +2 -2
- package/dist/controllers/user-storage/contact-syncing/utils.mjs.map +1 -0
- package/dist/controllers/user-storage/index.cjs +38 -0
- package/dist/controllers/user-storage/index.cjs.map +1 -0
- package/dist/controllers/user-storage/{index.d.ts → index.d.cts} +8 -8
- package/dist/controllers/user-storage/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/index.d.mts +10 -0
- package/dist/controllers/user-storage/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/index.mjs +9 -0
- package/dist/controllers/user-storage/index.mjs.map +1 -0
- package/dist/controllers/user-storage/mocks/index.cjs +19 -0
- package/dist/controllers/user-storage/mocks/index.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/index.d.cts +3 -0
- package/dist/controllers/user-storage/mocks/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/index.d.mts +3 -0
- package/dist/controllers/user-storage/mocks/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/index.mjs +3 -0
- package/dist/controllers/user-storage/mocks/index.mjs.map +1 -0
- package/dist/controllers/user-storage/mocks/mockResponses.cjs +113 -0
- package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/{mockResponses.d.ts → mockResponses.d.cts} +3 -3
- package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/mockResponses.d.mts +66 -0
- package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/{mockResponses.js → mockResponses.mjs} +4 -4
- package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.cjs +36 -0
- package/dist/controllers/user-storage/mocks/mockStorage.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/{mockStorage.d.ts → mockStorage.d.cts} +1 -1
- package/dist/controllers/user-storage/mocks/mockStorage.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.d.mts +5 -0
- package/dist/controllers/user-storage/mocks/mockStorage.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/{mockStorage.js → mockStorage.mjs} +3 -3
- package/dist/controllers/user-storage/mocks/mockStorage.mjs.map +1 -0
- package/dist/controllers/user-storage/types.cjs +3 -0
- package/dist/controllers/user-storage/types.cjs.map +1 -0
- package/dist/controllers/user-storage/{types.d.ts → types.d.cts} +3 -3
- package/dist/controllers/user-storage/types.d.cts.map +1 -0
- package/dist/controllers/user-storage/types.d.mts +23 -0
- package/dist/controllers/user-storage/types.d.mts.map +1 -0
- package/dist/controllers/user-storage/types.mjs +2 -0
- package/dist/controllers/user-storage/types.mjs.map +1 -0
- package/dist/controllers/user-storage/utils.cjs +32 -0
- package/dist/controllers/user-storage/utils.cjs.map +1 -0
- package/dist/controllers/user-storage/{utils.d.ts → utils.d.cts} +1 -1
- package/dist/controllers/user-storage/utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/utils.d.mts +19 -0
- package/dist/controllers/user-storage/utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/{utils.js → utils.mjs} +1 -1
- package/dist/controllers/user-storage/utils.mjs.map +1 -0
- package/dist/index.cjs +30 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +114 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{flow-siwe.d.ts → flow-siwe.d.cts} +2 -2
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +25 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +110 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +290 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{flow-srp.d.ts → flow-srp.d.cts} +5 -5
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +44 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +263 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/services.cjs +400 -0
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{services.d.ts → services.d.cts} +5 -5
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +105 -0
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{services.js → services.mjs} +6 -6
- package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/types.cjs +12 -0
- package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{types.d.ts → types.d.cts} +2 -2
- package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/types.d.mts +114 -0
- package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{types.js → types.mjs} +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs +27 -0
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/{identifier.d.ts → identifier.d.cts} +2 -2
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts +13 -0
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/{identifier.js → identifier.mjs} +2 -2
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/time.cjs +17 -0
- package/dist/sdk/authentication-jwt-bearer/utils/time.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/{time.d.ts → time.d.cts} +1 -1
- package/dist/sdk/authentication-jwt-bearer/utils/time.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/time.d.mts +8 -0
- package/dist/sdk/authentication-jwt-bearer/utils/time.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/{time.js → time.mjs} +1 -1
- package/dist/sdk/authentication-jwt-bearer/utils/time.mjs.map +1 -0
- package/dist/sdk/authentication.cjs +132 -0
- package/dist/sdk/authentication.cjs.map +1 -0
- package/dist/sdk/{authentication.d.ts → authentication.d.cts} +9 -9
- package/dist/sdk/authentication.d.cts.map +1 -0
- package/dist/sdk/authentication.d.mts +38 -0
- package/dist/sdk/authentication.d.mts.map +1 -0
- package/dist/sdk/authentication.mjs +112 -0
- package/dist/sdk/authentication.mjs.map +1 -0
- package/dist/sdk/constants.cjs +7 -0
- package/dist/sdk/constants.cjs.map +1 -0
- package/dist/sdk/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/sdk/constants.d.cts.map +1 -0
- package/dist/sdk/constants.d.mts +4 -0
- package/dist/sdk/constants.d.mts.map +1 -0
- package/dist/sdk/{constants.js → constants.mjs} +1 -1
- package/dist/sdk/constants.mjs.map +1 -0
- package/dist/sdk/errors.cjs +76 -0
- package/dist/sdk/errors.cjs.map +1 -0
- package/dist/sdk/{errors.d.ts → errors.d.cts} +1 -1
- package/dist/sdk/errors.d.cts.map +1 -0
- package/dist/sdk/errors.d.mts +34 -0
- package/dist/sdk/errors.d.mts.map +1 -0
- package/dist/sdk/{errors.js → errors.mjs} +3 -4
- package/dist/sdk/errors.mjs.map +1 -0
- package/dist/sdk/index.cjs +24 -0
- package/dist/sdk/index.cjs.map +1 -0
- package/dist/sdk/index.d.cts +8 -0
- package/dist/sdk/index.d.cts.map +1 -0
- package/dist/sdk/index.d.mts +8 -0
- package/dist/sdk/index.d.mts.map +1 -0
- package/dist/sdk/index.mjs +8 -0
- package/dist/sdk/index.mjs.map +1 -0
- package/dist/sdk/mocks/auth.cjs +82 -0
- package/dist/sdk/mocks/auth.cjs.map +1 -0
- package/dist/sdk/mocks/{auth.d.ts → auth.d.cts} +2 -2
- package/dist/sdk/mocks/auth.d.cts.map +1 -0
- package/dist/sdk/mocks/auth.d.mts +69 -0
- package/dist/sdk/mocks/auth.d.mts.map +1 -0
- package/dist/sdk/mocks/{auth.js → auth.mjs} +3 -3
- package/dist/sdk/mocks/auth.mjs.map +1 -0
- package/dist/sdk/mocks/userstorage.cjs +43 -0
- package/dist/sdk/mocks/userstorage.cjs.map +1 -0
- package/dist/sdk/mocks/{userstorage.d.ts → userstorage.d.cts} +1 -1
- package/dist/sdk/mocks/userstorage.d.cts.map +1 -0
- package/dist/sdk/mocks/userstorage.d.mts +10 -0
- package/dist/sdk/mocks/userstorage.d.mts.map +1 -0
- package/dist/sdk/mocks/{userstorage.js → userstorage.mjs} +5 -5
- package/dist/sdk/mocks/userstorage.mjs.map +1 -0
- package/dist/sdk/user-storage.cjs +386 -0
- package/dist/sdk/user-storage.cjs.map +1 -0
- package/dist/sdk/{user-storage.d.ts → user-storage.d.cts} +5 -5
- package/dist/sdk/user-storage.d.cts.map +1 -0
- package/dist/sdk/user-storage.d.mts +47 -0
- package/dist/sdk/user-storage.d.mts.map +1 -0
- package/dist/sdk/user-storage.mjs +358 -0
- package/dist/sdk/user-storage.mjs.map +1 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.cjs +70 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.cjs.map +1 -0
- package/dist/sdk/utils/{eip-6963-metamask-provider.d.ts → eip-6963-metamask-provider.d.cts} +2 -2
- package/dist/sdk/utils/eip-6963-metamask-provider.d.cts.map +1 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.d.mts +25 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.d.mts.map +1 -0
- package/dist/sdk/utils/{eip-6963-metamask-provider.js → eip-6963-metamask-provider.mjs} +1 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.mjs.map +1 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs +96 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -0
- package/dist/sdk/utils/{messaging-signing-snap-requests.d.ts → messaging-signing-snap-requests.d.cts} +2 -2
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +41 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -0
- package/dist/sdk/utils/{messaging-signing-snap-requests.js → messaging-signing-snap-requests.mjs} +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -0
- package/dist/sdk/utils/validate-login-response.cjs +49 -0
- package/dist/sdk/utils/validate-login-response.cjs.map +1 -0
- package/dist/sdk/utils/{validate-login-response.d.ts → validate-login-response.d.cts} +2 -2
- package/dist/sdk/utils/validate-login-response.d.cts.map +1 -0
- package/dist/sdk/utils/validate-login-response.d.mts +14 -0
- package/dist/sdk/utils/validate-login-response.d.mts.map +1 -0
- package/dist/sdk/utils/{validate-login-response.js → validate-login-response.mjs} +1 -1
- package/dist/sdk/utils/validate-login-response.mjs.map +1 -0
- package/dist/sdk/utils/validate-pair-response.cjs +29 -0
- package/dist/sdk/utils/validate-pair-response.cjs.map +1 -0
- package/dist/sdk/utils/{validate-pair-response.d.ts → validate-pair-response.d.cts} +1 -1
- package/dist/sdk/utils/validate-pair-response.d.cts.map +1 -0
- package/dist/sdk/utils/validate-pair-response.d.mts +26 -0
- package/dist/sdk/utils/validate-pair-response.d.mts.map +1 -0
- package/dist/sdk/utils/{validate-pair-response.js → validate-pair-response.mjs} +1 -1
- package/dist/sdk/utils/validate-pair-response.mjs.map +1 -0
- package/dist/shared/encryption/cache.cjs +77 -0
- package/dist/shared/encryption/cache.cjs.map +1 -0
- package/dist/shared/encryption/{cache.d.ts → cache.d.cts} +1 -1
- package/dist/shared/encryption/cache.d.cts.map +1 -0
- package/dist/shared/encryption/cache.d.mts +32 -0
- package/dist/shared/encryption/cache.d.mts.map +1 -0
- package/dist/shared/encryption/{cache.js → cache.mjs} +4 -4
- package/dist/shared/encryption/cache.mjs.map +1 -0
- package/dist/shared/encryption/constants.cjs +17 -0
- package/dist/shared/encryption/constants.cjs.map +1 -0
- package/dist/shared/encryption/{constants.d.ts → constants.d.cts} +2 -2
- package/dist/shared/encryption/constants.d.cts.map +1 -0
- package/dist/shared/encryption/constants.d.mts +9 -0
- package/dist/shared/encryption/constants.d.mts.map +1 -0
- package/dist/shared/encryption/{constants.js → constants.mjs} +1 -1
- package/dist/shared/encryption/constants.mjs.map +1 -0
- package/dist/shared/encryption/encryption.cjs +209 -0
- package/dist/shared/encryption/encryption.cjs.map +1 -0
- package/dist/shared/encryption/{encryption.d.ts → encryption.d.cts} +3 -3
- package/dist/shared/encryption/encryption.d.cts.map +1 -0
- package/dist/shared/encryption/encryption.d.mts +30 -0
- package/dist/shared/encryption/encryption.d.mts.map +1 -0
- package/dist/shared/encryption/encryption.mjs +205 -0
- package/dist/shared/encryption/encryption.mjs.map +1 -0
- package/dist/shared/encryption/index.cjs +25 -0
- package/dist/shared/encryption/index.cjs.map +1 -0
- package/dist/shared/encryption/index.d.cts +5 -0
- package/dist/shared/encryption/index.d.cts.map +1 -0
- package/dist/shared/encryption/index.d.mts +5 -0
- package/dist/shared/encryption/index.d.mts.map +1 -0
- package/dist/shared/encryption/index.mjs +5 -0
- package/dist/shared/encryption/index.mjs.map +1 -0
- package/dist/shared/encryption/utils.cjs +21 -0
- package/dist/shared/encryption/utils.cjs.map +1 -0
- package/dist/shared/encryption/{utils.d.ts → utils.d.cts} +3 -3
- package/dist/shared/encryption/utils.d.cts.map +1 -0
- package/dist/shared/encryption/utils.d.mts +5 -0
- package/dist/shared/encryption/utils.d.mts.map +1 -0
- package/dist/shared/encryption/{utils.js → utils.mjs} +1 -1
- package/dist/shared/encryption/utils.mjs.map +1 -0
- package/dist/shared/env.cjs +85 -0
- package/dist/shared/env.cjs.map +1 -0
- package/dist/shared/{env.d.ts → env.d.cts} +1 -1
- package/dist/shared/env.d.cts.map +1 -0
- package/dist/shared/env.d.mts +34 -0
- package/dist/shared/env.d.mts.map +1 -0
- package/dist/shared/{env.js → env.mjs} +1 -1
- package/dist/shared/env.mjs.map +1 -0
- package/dist/shared/storage-schema.cjs +42 -0
- package/dist/shared/storage-schema.cjs.map +1 -0
- package/dist/shared/{storage-schema.d.ts → storage-schema.d.cts} +1 -1
- package/dist/shared/storage-schema.d.cts.map +1 -0
- package/dist/shared/storage-schema.d.mts +34 -0
- package/dist/shared/storage-schema.d.mts.map +1 -0
- package/dist/shared/{storage-schema.js → storage-schema.mjs} +2 -2
- package/dist/shared/storage-schema.mjs.map +1 -0
- package/dist/shared/types/encryption.cjs +3 -0
- package/dist/shared/types/encryption.cjs.map +1 -0
- package/dist/shared/types/{encryption.d.ts → encryption.d.cts} +1 -1
- package/dist/shared/types/encryption.d.cts.map +1 -0
- package/dist/shared/types/encryption.d.mts +2 -0
- package/dist/shared/types/encryption.d.mts.map +1 -0
- package/dist/shared/types/encryption.mjs +2 -0
- package/dist/shared/types/encryption.mjs.map +1 -0
- package/dist/shared/types/services.cjs +3 -0
- package/dist/shared/types/services.cjs.map +1 -0
- package/dist/shared/types/{services.d.ts → services.d.cts} +2 -2
- package/dist/shared/types/services.d.cts.map +1 -0
- package/dist/shared/types/services.d.mts +17 -0
- package/dist/shared/types/services.d.mts.map +1 -0
- package/dist/shared/types/services.mjs +2 -0
- package/dist/shared/types/services.mjs.map +1 -0
- package/dist/shared/utils/entropy-source.cjs +37 -0
- package/dist/shared/utils/entropy-source.cjs.map +1 -0
- package/dist/shared/utils/{entropy-source.d.ts → entropy-source.d.cts} +2 -2
- package/dist/shared/utils/entropy-source.d.cts.map +1 -0
- package/dist/shared/utils/entropy-source.d.mts +22 -0
- package/dist/shared/utils/entropy-source.d.mts.map +1 -0
- package/dist/shared/utils/{entropy-source.js → entropy-source.mjs} +2 -2
- package/dist/shared/utils/entropy-source.mjs.map +1 -0
- package/dist/shared/utils/event-queue.cjs +24 -0
- package/dist/shared/utils/event-queue.cjs.map +1 -0
- package/dist/shared/utils/{event-queue.d.ts → event-queue.d.cts} +1 -1
- package/dist/shared/utils/event-queue.d.cts.map +1 -0
- package/dist/shared/utils/event-queue.d.mts +6 -0
- package/dist/shared/utils/event-queue.d.mts.map +1 -0
- package/dist/shared/utils/{event-queue.js → event-queue.mjs} +4 -2
- package/dist/shared/utils/event-queue.mjs.map +1 -0
- package/dist/shared/utils/hd-keyring-seed.cjs +49 -0
- package/dist/shared/utils/hd-keyring-seed.cjs.map +1 -0
- package/dist/shared/utils/{hd-keyring-seed.d.ts → hd-keyring-seed.d.cts} +3 -3
- package/dist/shared/utils/hd-keyring-seed.d.cts.map +1 -0
- package/dist/shared/utils/hd-keyring-seed.d.mts +27 -0
- package/dist/shared/utils/hd-keyring-seed.d.mts.map +1 -0
- package/dist/shared/utils/{hd-keyring-seed.js → hd-keyring-seed.mjs} +1 -1
- package/dist/shared/utils/hd-keyring-seed.mjs.map +1 -0
- package/dist/shared/utils/message-signing.cjs +147 -0
- package/dist/shared/utils/message-signing.cjs.map +1 -0
- package/dist/shared/utils/{message-signing.d.ts → message-signing.d.cts} +1 -1
- package/dist/shared/utils/message-signing.d.cts.map +1 -0
- package/dist/shared/utils/message-signing.d.mts +73 -0
- package/dist/shared/utils/message-signing.d.mts.map +1 -0
- package/dist/shared/utils/{message-signing.js → message-signing.mjs} +7 -7
- package/dist/shared/utils/message-signing.mjs.map +1 -0
- package/package.json +56 -22
- package/dist/controllers/authentication/AuthenticationController-method-action-types.d.ts.map +0 -1
- package/dist/controllers/authentication/AuthenticationController-method-action-types.js.map +0 -1
- package/dist/controllers/authentication/AuthenticationController.d.ts.map +0 -1
- package/dist/controllers/authentication/AuthenticationController.js +0 -536
- package/dist/controllers/authentication/AuthenticationController.js.map +0 -1
- package/dist/controllers/authentication/index.d.ts.map +0 -1
- package/dist/controllers/authentication/index.js +0 -6
- package/dist/controllers/authentication/index.js.map +0 -1
- package/dist/controllers/authentication/mocks/index.d.ts +0 -2
- package/dist/controllers/authentication/mocks/index.d.ts.map +0 -1
- package/dist/controllers/authentication/mocks/index.js +0 -2
- package/dist/controllers/authentication/mocks/index.js.map +0 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.ts.map +0 -1
- package/dist/controllers/authentication/mocks/mockResponses.js.map +0 -1
- package/dist/controllers/index.d.ts +0 -3
- package/dist/controllers/index.d.ts.map +0 -1
- package/dist/controllers/index.js +0 -3
- package/dist/controllers/index.js.map +0 -1
- package/dist/controllers/user-storage/UserStorageController-method-action-types.d.ts.map +0 -1
- package/dist/controllers/user-storage/UserStorageController-method-action-types.js.map +0 -1
- package/dist/controllers/user-storage/UserStorageController.d.ts.map +0 -1
- package/dist/controllers/user-storage/UserStorageController.js +0 -429
- package/dist/controllers/user-storage/UserStorageController.js.map +0 -1
- package/dist/controllers/user-storage/constants.d.ts +0 -15
- package/dist/controllers/user-storage/constants.d.ts.map +0 -1
- package/dist/controllers/user-storage/constants.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/constants.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/constants.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/controller-integration.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/controller-integration.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/sync-utils.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/sync-utils.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/types.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/types.js +0 -2
- package/dist/controllers/user-storage/contact-syncing/types.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/utils.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/utils.js.map +0 -1
- package/dist/controllers/user-storage/index.d.ts.map +0 -1
- package/dist/controllers/user-storage/index.js +0 -9
- package/dist/controllers/user-storage/index.js.map +0 -1
- package/dist/controllers/user-storage/mocks/index.d.ts +0 -3
- package/dist/controllers/user-storage/mocks/index.d.ts.map +0 -1
- package/dist/controllers/user-storage/mocks/index.js +0 -3
- package/dist/controllers/user-storage/mocks/index.js.map +0 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.ts.map +0 -1
- package/dist/controllers/user-storage/mocks/mockResponses.js.map +0 -1
- package/dist/controllers/user-storage/mocks/mockStorage.d.ts.map +0 -1
- package/dist/controllers/user-storage/mocks/mockStorage.js.map +0 -1
- package/dist/controllers/user-storage/types.d.ts.map +0 -1
- package/dist/controllers/user-storage/types.js +0 -2
- package/dist/controllers/user-storage/types.js.map +0 -1
- package/dist/controllers/user-storage/utils.d.ts.map +0 -1
- package/dist/controllers/user-storage/utils.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +0 -99
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js +0 -255
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/services.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/types.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/types.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/utils/time.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/utils/time.js.map +0 -1
- package/dist/sdk/authentication.d.ts.map +0 -1
- package/dist/sdk/authentication.js +0 -100
- package/dist/sdk/authentication.js.map +0 -1
- package/dist/sdk/constants.d.ts.map +0 -1
- package/dist/sdk/constants.js.map +0 -1
- package/dist/sdk/errors.d.ts.map +0 -1
- package/dist/sdk/errors.js.map +0 -1
- package/dist/sdk/index.d.ts +0 -8
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/index.js +0 -8
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/mocks/auth.d.ts.map +0 -1
- package/dist/sdk/mocks/auth.js.map +0 -1
- package/dist/sdk/mocks/userstorage.d.ts.map +0 -1
- package/dist/sdk/mocks/userstorage.js.map +0 -1
- package/dist/sdk/user-storage.d.ts.map +0 -1
- package/dist/sdk/user-storage.js +0 -364
- package/dist/sdk/user-storage.js.map +0 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.d.ts.map +0 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.js.map +0 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.ts.map +0 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.js.map +0 -1
- package/dist/sdk/utils/validate-login-response.d.ts.map +0 -1
- package/dist/sdk/utils/validate-login-response.js.map +0 -1
- package/dist/sdk/utils/validate-pair-response.d.ts.map +0 -1
- package/dist/sdk/utils/validate-pair-response.js.map +0 -1
- package/dist/shared/encryption/cache.d.ts.map +0 -1
- package/dist/shared/encryption/cache.js.map +0 -1
- package/dist/shared/encryption/constants.d.ts.map +0 -1
- package/dist/shared/encryption/constants.js.map +0 -1
- package/dist/shared/encryption/encryption.d.ts.map +0 -1
- package/dist/shared/encryption/encryption.js +0 -202
- package/dist/shared/encryption/encryption.js.map +0 -1
- package/dist/shared/encryption/index.d.ts +0 -5
- package/dist/shared/encryption/index.d.ts.map +0 -1
- package/dist/shared/encryption/index.js +0 -5
- package/dist/shared/encryption/index.js.map +0 -1
- package/dist/shared/encryption/utils.d.ts.map +0 -1
- package/dist/shared/encryption/utils.js.map +0 -1
- package/dist/shared/env.d.ts.map +0 -1
- package/dist/shared/env.js.map +0 -1
- package/dist/shared/storage-schema.d.ts.map +0 -1
- package/dist/shared/storage-schema.js.map +0 -1
- package/dist/shared/types/encryption.d.ts.map +0 -1
- package/dist/shared/types/encryption.js +0 -2
- package/dist/shared/types/encryption.js.map +0 -1
- package/dist/shared/types/services.d.ts.map +0 -1
- package/dist/shared/types/services.js +0 -2
- package/dist/shared/types/services.js.map +0 -1
- package/dist/shared/utils/entropy-source.d.ts.map +0 -1
- package/dist/shared/utils/entropy-source.js.map +0 -1
- package/dist/shared/utils/event-queue.d.ts.map +0 -1
- package/dist/shared/utils/event-queue.js.map +0 -1
- package/dist/shared/utils/hd-keyring-seed.d.ts.map +0 -1
- package/dist/shared/utils/hd-keyring-seed.js.map +0 -1
- package/dist/shared/utils/message-signing.d.ts.map +0 -1
- package/dist/shared/utils/message-signing.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-srp.cjs","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-srp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,6CAAiE;AACjE,2FAAoF;AACpF,qGAKqD;AACrD,qFAA4E;AAC5E,gDAOuB;AAcvB,0DAA4D;AAC5D,4DAA6C;AAuB7C,0EAA0E;AAC1E,kFAAkF;AACrE,QAAA,kBAAkB,GAAG,KAAM,CAAC;AAEzC,MAAM,yBAAyB,GAAG,KAAK,IAAI,EAAE;IAC3C,MAAM,QAAQ,GAAG,MAAM,IAAA,0DAA0B,GAAE,CAAC;IACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,2BAAe,CAAC,8BAA8B,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,+BAA+B,GAAG,CACtC,cAAgC,EACZ,EAAE,CAAC,CAAC;IACxB,aAAa,EAAE,KAAK,EAAE,eAAwB,EAAmB,EAAE;QACjE,MAAM,QAAQ,GAAG,cAAc,IAAI,CAAC,MAAM,yBAAyB,EAAE,CAAC,CAAC;QACvE,OAAO,MAAM,yDAAoB,CAAC,YAAY,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC5E,CAAC;IACD,WAAW,EAAE,KAAK,EAChB,OAAe,EACf,eAAwB,EACP,EAAE;QACnB,MAAM,QAAQ,GAAG,cAAc,IAAI,CAAC,MAAM,yBAAyB,EAAE,CAAC,CAAC;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AK,CAAC,MAAM,CAAC,CAAC;YAE9B,0BAA0B;QAC5B,CAAC;IACH,CAAC;IAED,2EAA2E;IAC3E,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;AACrE,CAAC,mGAGC,KAAa,EACb,SAAiB,EACjB,GAAiB;IAIjB,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,YAAY,KAAK,IAAI,SAAS,IAAI,GAAG,EAAW,CAAC;IAC1D,CAAC;IACD,OAAO,YAAY,KAAK,IAAI,SAAS,EAAW,CAAC;AACnD,CAAC","sourcesContent":["import type { Eip1193Provider } from 'ethers';\n\nimport type { MetaMetricsAuth } from '../../shared/types/services.js';\nimport { ValidationError, RateLimitedError } from '../errors.js';\nimport { getMetaMaskProviderEIP6963 } from '../utils/eip-6963-metamask-provider.js';\nimport {\n MESSAGE_SIGNING_SNAP,\n assertMessageStartsWithMetamask,\n connectSnap,\n isSnapConnected,\n} from '../utils/messaging-signing-snap-requests.js';\nimport { validateLoginResponse } from '../utils/validate-login-response.js';\nimport {\n authenticate,\n authorizeOIDC,\n getCustomerServiceToken,\n getNonce,\n getUserProfileLineage,\n pairProfiles,\n} from './services.js';\nimport type { PairProfilesResponse } from './services.js';\nimport type {\n AuthConfig,\n AuthSigningOptions,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginIdentifierType,\n LoginResponse,\n SrpLoginTag,\n UserProfile,\n UserProfileLineage,\n} from './types.js';\nimport { computeIdentifierId } from './utils/identifier.js';\nimport * as timeUtils from './utils/time.js';\n\ntype JwtBearerAuth_SRP_Options = {\n storage: AuthStorageOptions;\n signing?: AuthSigningOptions;\n /**\n * Resolves the login tag for a given entropy source.\n * When omitted, `raw_message` stays untagged (`metamask:<nonce>:<pubkey>`).\n */\n getLoginTag?: (entropySourceId?: string) => Promise<SrpLoginTag>;\n /**\n * Resolves the metametrics `identifier_type` for a given entropy source.\n * Defaults to `'SRP'` when omitted.\n */\n getLoginIdentifierType?: (\n entropySourceId?: string,\n ) => Promise<LoginIdentifierType>;\n rateLimitRetry?: {\n cooldownDefaultMs?: number; // default cooldown when 429 has no Retry-After\n maxLoginRetries?: number; // maximum number of login retries on rate limit\n };\n};\n\n// How long a successful pairing result stays cached so identical payloads\n// (concurrent or sequential retries) reuse it instead of re-hitting the endpoint.\nexport const PAIR_DEDUPE_TTL_MS = 30_000;\n\nconst getDefaultEIP6963Provider = async () => {\n const provider = await getMetaMaskProviderEIP6963();\n if (!provider) {\n throw new ValidationError('No MetaMask wallet connected');\n }\n return provider;\n};\n\nconst getDefaultEIP6963SigningOptions = (\n customProvider?: Eip1193Provider,\n): AuthSigningOptions => ({\n getIdentifier: async (entropySourceId?: string): Promise<string> => {\n const provider = customProvider ?? (await getDefaultEIP6963Provider());\n return await MESSAGE_SIGNING_SNAP.getPublicKey(provider, entropySourceId);\n },\n signMessage: async (\n message: string,\n entropySourceId?: string,\n ): Promise<string> => {\n const provider = customProvider ?? (await getDefaultEIP6963Provider());\n assertMessageStartsWithMetamask(message);\n return await MESSAGE_SIGNING_SNAP.signMessage(\n provider,\n message,\n entropySourceId,\n );\n },\n});\n\nexport class SRPJwtBearerAuth implements IBaseAuth {\n readonly #config: AuthConfig;\n\n readonly #options: {\n storage: AuthStorageOptions;\n signing: AuthSigningOptions;\n };\n\n readonly #metametrics?: MetaMetricsAuth;\n\n // Map to store ongoing login promises by entropySourceId\n readonly #ongoingLogins = new Map<\n string | undefined,\n Promise<LoginResponse>\n >();\n\n // Map to dedupe pairing calls by an order-insensitive token-set key.\n // Holds the in-flight promise (coalescing concurrent callers) and keeps it\n // for a short TTL after success (collapsing sequential retries).\n readonly #ongoingPairings = new Map<\n string,\n { promise: Promise<PairProfilesResponse>; expiresAt: number }\n >();\n\n // Default cooldown when 429 has no Retry-After header\n readonly #cooldownDefaultMs: number;\n\n // Maximum number of login retries on rate limit errors\n readonly #maxLoginRetries: number;\n\n readonly #getLoginTag?: (entropySourceId?: string) => Promise<SrpLoginTag>;\n\n readonly #getLoginIdentifierType?: (\n entropySourceId?: string,\n ) => Promise<LoginIdentifierType>;\n\n #customProvider?: Eip1193Provider;\n\n constructor(\n config: AuthConfig & { type: AuthType.SRP },\n options: JwtBearerAuth_SRP_Options & {\n customProvider?: Eip1193Provider;\n metametrics?: MetaMetricsAuth;\n },\n ) {\n this.#config = config;\n this.#customProvider = options.customProvider;\n this.#getLoginTag = options.getLoginTag;\n this.#getLoginIdentifierType = options.getLoginIdentifierType;\n this.#options = {\n storage: options.storage,\n signing:\n options.signing ??\n getDefaultEIP6963SigningOptions(this.#customProvider),\n };\n this.#metametrics = options.metametrics;\n\n // Apply rate limit retry config if provided\n this.#cooldownDefaultMs =\n options.rateLimitRetry?.cooldownDefaultMs ?? 10000;\n this.#maxLoginRetries = options.rateLimitRetry?.maxLoginRetries ?? 1;\n }\n\n setCustomProvider(provider: Eip1193Provider) {\n this.#customProvider = provider;\n this.#options.signing = getDefaultEIP6963SigningOptions(provider);\n }\n\n // TODO: might be easier to keep entropySourceId as a class param and use multiple SRPJwtBearerAuth instances where needed\n async getAccessToken(entropySourceId?: string): Promise<string> {\n const session = await this.#getAuthSession(entropySourceId);\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login(entropySourceId);\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(entropySourceId?: string): Promise<UserProfile> {\n const session = await this.#getAuthSession(entropySourceId);\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login(entropySourceId);\n return loginResponse.profile;\n }\n\n async getIdentifier(entropySourceId?: string): Promise<string> {\n return await this.#options.signing.getIdentifier(entropySourceId);\n }\n\n async getUserProfileLineage(\n entropySourceId?: string,\n ): Promise<UserProfileLineage> {\n const accessToken = await this.getAccessToken(entropySourceId);\n return await getUserProfileLineage(this.#config.env, accessToken);\n }\n\n async getCustomerServiceToken(entropySourceId?: string): Promise<string> {\n const accessToken = await this.getAccessToken(entropySourceId);\n return await getCustomerServiceToken(this.#config.env, accessToken);\n }\n\n async pairSrpProfiles(\n accessTokens: string[],\n authAccessToken: string,\n ): Promise<PairProfilesResponse> {\n // Order-insensitive key: the same token set in any order maps to the same\n // entry. Sort a copy so the request payload itself stays primary-first.\n const key = JSON.stringify([...accessTokens].sort());\n\n const cached = this.#ongoingPairings.get(key);\n if (cached && cached.expiresAt > Date.now()) {\n return await cached.promise;\n }\n\n const promise = pairProfiles(\n accessTokens,\n authAccessToken,\n this.#config.env,\n );\n // Store the in-flight promise immediately so concurrent callers coalesce\n // regardless of how long the request takes.\n this.#ongoingPairings.set(key, {\n promise,\n expiresAt: Number.MAX_SAFE_INTEGER,\n });\n\n try {\n const result = await promise;\n // Keep the resolved result cached for a short window so sequential\n // retries with the same payload reuse it.\n this.#ongoingPairings.set(key, {\n promise,\n expiresAt: Date.now() + PAIR_DEDUPE_TTL_MS,\n });\n return result;\n } catch (error) {\n // Never cache failures: the pairing retry loop must be able to re-hit\n // the endpoint on the next attempt.\n this.#ongoingPairings.delete(key);\n throw error;\n }\n }\n\n async signMessage(\n message: string,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#options.signing.signMessage(message, entropySourceId);\n }\n\n async isSnapConnected(): Promise<boolean> {\n const provider =\n this.#customProvider ?? (await getDefaultEIP6963Provider());\n if (!provider) {\n return false;\n }\n\n const isConnected = await isSnapConnected(provider);\n return isConnected;\n }\n\n async connectSnap(): Promise<string> {\n const provider =\n this.#customProvider ?? (await getDefaultEIP6963Provider());\n\n const res = await connectSnap(provider);\n return res;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(\n entropySourceId?: string,\n ): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse(entropySourceId);\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n // get canonical profile id from server if not present in the cached session\n if (!auth.profile.canonicalProfileId) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(entropySourceId?: string): Promise<LoginResponse> {\n // Use a deferred login to avoid race conditions\n return await this.#deferredLogin(entropySourceId);\n }\n\n async #performLogin(entropySourceId?: string): Promise<LoginResponse> {\n // Nonce\n const publicKey = await this.getIdentifier(entropySourceId);\n const nonceRes = await getNonce(publicKey, this.#config.env);\n\n // Tag only when the wallet supplies getLoginTag. SDK callers keep the\n // legacy 3-part message rather than guessing `primary`.\n const tag = await this.#getLoginTag?.(entropySourceId);\n const identifierType =\n (await this.#getLoginIdentifierType?.(entropySourceId)) ?? 'SRP';\n const rawMessage = this.#createSrpLoginRawMessage(\n nonceRes.nonce,\n publicKey,\n tag,\n );\n const signature = await this.signMessage(rawMessage, entropySourceId);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n this.#metametrics,\n identifierType,\n );\n\n // Resolve original profileId from aliases.\n // This is done mainly to preserve the original profileId for storage key derivation\n // until we migrate to the canonical profileId storage system.\n const canonicalProfileId = authResponse.profile.profileId;\n const profile = { ...authResponse.profile };\n\n if (authResponse.profileAliases?.length > 0) {\n const targetIdentifierId = computeIdentifierId(\n publicKey,\n this.#config.env,\n );\n\n const matchingAliases = authResponse.profileAliases.filter((alias) =>\n alias.identifierIds.some((id) => id.id === targetIdentifierId),\n );\n\n // Prefer the leaf alias (single identifier) — it's the original profile\n // created for this SRP. Multi-identifier aliases are former canonicals\n // that absorbed other profiles; they are correct only when this SRP's\n // original profile was itself a canonical before being absorbed.\n const targetAlias =\n matchingAliases.find((alias) => alias.identifierIds.length === 1) ??\n matchingAliases[0];\n\n if (targetAlias) {\n profile.profileId = targetAlias.aliasProfileId;\n }\n }\n\n profile.canonicalProfileId = canonicalProfileId;\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result, entropySourceId);\n\n return result;\n }\n\n async #deferredLogin(entropySourceId?: string): Promise<LoginResponse> {\n // Check if there's already an ongoing login for this entropySourceId\n const existingLogin = this.#ongoingLogins.get(entropySourceId);\n if (existingLogin) {\n return existingLogin;\n }\n\n // Create a new login promise\n const loginPromise = this.#loginWithRetry(entropySourceId);\n\n // Store the promise in the map\n this.#ongoingLogins.set(entropySourceId, loginPromise);\n\n try {\n // Wait for the login to complete\n return await loginPromise;\n } finally {\n // Always clean up the ongoing login promise when done\n this.#ongoingLogins.delete(entropySourceId);\n }\n }\n\n async #loginWithRetry(entropySourceId?: string): Promise<LoginResponse> {\n // Allow max attempts: initial + maxLoginRetries on 429\n for (let attempt = 0; attempt < 1 + this.#maxLoginRetries; attempt += 1) {\n try {\n return await this.#performLogin(entropySourceId);\n } catch (e) {\n // Only retry on rate-limit (429) errors\n if (!RateLimitedError.isRateLimitError(e)) {\n throw e;\n }\n\n // If we've exhausted attempts, rethrow\n if (attempt >= this.#maxLoginRetries) {\n throw e;\n }\n\n // Wait for Retry-After or default cooldown\n const waitMs = e.retryAfterMs ?? this.#cooldownDefaultMs;\n await timeUtils.delay(waitMs);\n\n // Loop continues to retry\n }\n }\n\n // Should never reach here due to loop logic, but TypeScript needs a return\n throw new Error('Unexpected: login loop exhausted without result');\n }\n\n #createSrpLoginRawMessage(\n nonce: string,\n publicKey: string,\n tag?: SrpLoginTag,\n ):\n | `metamask:${string}:${string}`\n | `metamask:${string}:${string}:${SrpLoginTag}` {\n if (tag) {\n return `metamask:${nonce}:${publicKey}:${tag}` as const;\n }\n return `metamask:${nonce}:${publicKey}` as const;\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Eip1193Provider } from
|
|
2
|
-
import type { MetaMetricsAuth } from
|
|
3
|
-
import type { PairProfilesResponse } from
|
|
4
|
-
import type { AuthConfig, AuthSigningOptions, AuthStorageOptions, AuthType, IBaseAuth, LoginIdentifierType, SrpLoginTag, UserProfile, UserProfileLineage } from
|
|
1
|
+
import type { Eip1193Provider } from "ethers";
|
|
2
|
+
import type { MetaMetricsAuth } from "../../shared/types/services.cjs";
|
|
3
|
+
import type { PairProfilesResponse } from "./services.cjs";
|
|
4
|
+
import type { AuthConfig, AuthSigningOptions, AuthStorageOptions, AuthType, IBaseAuth, LoginIdentifierType, SrpLoginTag, UserProfile, UserProfileLineage } from "./types.cjs";
|
|
5
5
|
type JwtBearerAuth_SRP_Options = {
|
|
6
6
|
storage: AuthStorageOptions;
|
|
7
7
|
signing?: AuthSigningOptions;
|
|
@@ -41,4 +41,4 @@ export declare class SRPJwtBearerAuth implements IBaseAuth {
|
|
|
41
41
|
connectSnap(): Promise<string>;
|
|
42
42
|
}
|
|
43
43
|
export {};
|
|
44
|
-
//# sourceMappingURL=flow-srp.d.
|
|
44
|
+
//# sourceMappingURL=flow-srp.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-srp.d.cts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-srp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,wCAAuC;AAkBtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAsB;AAC1D,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,SAAS,EACT,mBAAmB,EAEnB,WAAW,EACX,WAAW,EACX,kBAAkB,EACnB,oBAAmB;AAIpB,KAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,kBAAkB,CAAC;IAC5B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,eAAe,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IACjE;;;OAGG;IACH,sBAAsB,CAAC,EAAE,CACvB,eAAe,CAAC,E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aMetricsAuth } from "../../shared/types/services.mjs";
|
|
3
|
+
import type { PairProfilesResponse } from "./services.mjs";
|
|
4
|
+
import type { AuthConfig, AuthSigningOptions, AuthStorageOptions, AuthType, IBaseAuth, LoginIdentifierType, SrpLoginTag, UserProfile, UserProfileLineage } from "./types.mjs";
|
|
5
|
+
type JwtBearerAuth_SRP_Options = {
|
|
6
|
+
storage: AuthStorageOptions;
|
|
7
|
+
signing?: AuthSigningOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the login tag for a given entropy source.
|
|
10
|
+
* When omitted, `raw_message` stays untagged (`metamask:<nonce>:<pubkey>`).
|
|
11
|
+
*/
|
|
12
|
+
getLoginTag?: (entropySourceId?: string) => Promise<SrpLoginTag>;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves the metametrics `identifier_type` for a given entropy source.
|
|
15
|
+
* Defaults to `'SRP'` when omitted.
|
|
16
|
+
*/
|
|
17
|
+
getLoginIdentifierType?: (entropySourceId?: string) => Promise<LoginIdentifierType>;
|
|
18
|
+
rateLimitRetry?: {
|
|
19
|
+
cooldownDefaultMs?: number;
|
|
20
|
+
maxLoginRetries?: number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare const PAIR_DEDUPE_TTL_MS = 30000;
|
|
24
|
+
export declare class SRPJwtBearerAuth implements IBaseAuth {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(config: AuthConfig & {
|
|
27
|
+
type: AuthType.SRP;
|
|
28
|
+
}, options: JwtBearerAuth_SRP_Options & {
|
|
29
|
+
customProvider?: Eip1193Provider;
|
|
30
|
+
metametrics?: MetaMetricsAuth;
|
|
31
|
+
});
|
|
32
|
+
setCustomProvider(provider: Eip1193Provider): void;
|
|
33
|
+
getAccessToken(entropySourceId?: string): Promise<string>;
|
|
34
|
+
getUserProfile(entropySourceId?: string): Promise<UserProfile>;
|
|
35
|
+
getIdentifier(entropySourceId?: string): Promise<string>;
|
|
36
|
+
getUserProfileLineage(entropySourceId?: string): Promise<UserProfileLineage>;
|
|
37
|
+
getCustomerServiceToken(entropySourceId?: string): Promise<string>;
|
|
38
|
+
pairSrpProfiles(accessTokens: string[], authAccessToken: string): Promise<PairProfilesResponse>;
|
|
39
|
+
signMessage(message: string, entropySourceId?: string): Promise<string>;
|
|
40
|
+
isSnapConnected(): Promise<boolean>;
|
|
41
|
+
connectSnap(): Promise<string>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=flow-srp.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-srp.d.mts","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-srp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,wCAAuC;AAkBtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAsB;AAC1D,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,SAAS,EACT,mBAAmB,EAEnB,WAAW,EACX,WAAW,EACX,kBAAkB,EACnB,oBAAmB;AAIpB,KAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,kBAAkB,CAAC;IAC5B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,eAAe,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IACjE;;;OAGG;IACH,sBAAsB,CAAC,EAAE,CACvB,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAClC,cAAc,CAAC,EAAE;QACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH,CAAC;AAIF,eAAO,MAAM,kBAAkB,QAAS,CAAC;AA+BzC,qBAAa,gBAAiB,YAAW,SAAS;;gBAuC9C,MAAM,EAAE,UAAU,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAA;KAAE,EAC3C,OAAO,EAAE,yBAAyB,GAAG;QACnC,cAAc,CAAC,EAAE,eAAe,CAAC;QACjC,WAAW,CAAC,EAAE,eAAe,CAAC;KAC/B;IAoBH,iBAAiB,CAAC,QAAQ,EAAE,eAAe;IAMrC,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUzD,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAU9D,aAAa,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxD,qBAAqB,CACzB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,kBAAkB,CAAC;IAKxB,uBAAuB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKlE,eAAe,CACnB,YAAY,EAAE,MAAM,EAAE,EACtB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,oBAAoB,CAAC;IAuC1B,WAAW,CACf,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC;IAIZ,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAWnC,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;CA+KrC"}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _SRPJwtBearerAuth_instances, _SRPJwtBearerAuth_config, _SRPJwtBearerAuth_options, _SRPJwtBearerAuth_metametrics, _SRPJwtBearerAuth_ongoingLogins, _SRPJwtBearerAuth_ongoingPairings, _SRPJwtBearerAuth_cooldownDefaultMs, _SRPJwtBearerAuth_maxLoginRetries, _SRPJwtBearerAuth_getLoginTag, _SRPJwtBearerAuth_getLoginIdentifierType, _SRPJwtBearerAuth_customProvider, _SRPJwtBearerAuth_getAuthSession, _SRPJwtBearerAuth_login, _SRPJwtBearerAuth_performLogin, _SRPJwtBearerAuth_deferredLogin, _SRPJwtBearerAuth_loginWithRetry, _SRPJwtBearerAuth_createSrpLoginRawMessage;
|
|
13
|
+
import { ValidationError, RateLimitedError } from "../errors.mjs";
|
|
14
|
+
import { getMetaMaskProviderEIP6963 } from "../utils/eip-6963-metamask-provider.mjs";
|
|
15
|
+
import { MESSAGE_SIGNING_SNAP, assertMessageStartsWithMetamask, connectSnap, isSnapConnected } from "../utils/messaging-signing-snap-requests.mjs";
|
|
16
|
+
import { validateLoginResponse } from "../utils/validate-login-response.mjs";
|
|
17
|
+
import { authenticate, authorizeOIDC, getCustomerServiceToken, getNonce, getUserProfileLineage, pairProfiles } from "./services.mjs";
|
|
18
|
+
import { computeIdentifierId } from "./utils/identifier.mjs";
|
|
19
|
+
import * as timeUtils from "./utils/time.mjs";
|
|
20
|
+
// How long a successful pairing result stays cached so identical payloads
|
|
21
|
+
// (concurrent or sequential retries) reuse it instead of re-hitting the endpoint.
|
|
22
|
+
export const PAIR_DEDUPE_TTL_MS = 30000;
|
|
23
|
+
const getDefaultEIP6963Provider = async () => {
|
|
24
|
+
const provider = await getMetaMaskProviderEIP6963();
|
|
25
|
+
if (!provider) {
|
|
26
|
+
throw new ValidationError('No MetaMask wallet connected');
|
|
27
|
+
}
|
|
28
|
+
return provider;
|
|
29
|
+
};
|
|
30
|
+
const getDefaultEIP6963SigningOptions = (customProvider) => ({
|
|
31
|
+
getIdentifier: async (entropySourceId) => {
|
|
32
|
+
const provider = customProvider ?? (await getDefaultEIP6963Provider());
|
|
33
|
+
return await MESSAGE_SIGNING_SNAP.getPublicKey(provider, entropySourceId);
|
|
34
|
+
},
|
|
35
|
+
signMessage: async (message, entropySourceId) => {
|
|
36
|
+
const provider = customProvider ?? (await getDefaultEIP6963Provider());
|
|
37
|
+
assertMessageStartsWithMetamask(message);
|
|
38
|
+
return await MESSAGE_SIGNING_SNAP.signMessage(provider, message, entropySourceId);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
export class SRPJwtBearerAuth {
|
|
42
|
+
constructor(config, options) {
|
|
43
|
+
_SRPJwtBearerAuth_instances.add(this);
|
|
44
|
+
_SRPJwtBearerAuth_config.set(this, void 0);
|
|
45
|
+
_SRPJwtBearerAuth_options.set(this, void 0);
|
|
46
|
+
_SRPJwtBearerAuth_metametrics.set(this, void 0);
|
|
47
|
+
// Map to store ongoing login promises by entropySourceId
|
|
48
|
+
_SRPJwtBearerAuth_ongoingLogins.set(this, new Map());
|
|
49
|
+
// Map to dedupe pairing calls by an order-insensitive token-set key.
|
|
50
|
+
// Holds the in-flight promise (coalescing concurrent callers) and keeps it
|
|
51
|
+
// for a short TTL after success (collapsing sequential retries).
|
|
52
|
+
_SRPJwtBearerAuth_ongoingPairings.set(this, new Map());
|
|
53
|
+
// Default cooldown when 429 has no Retry-After header
|
|
54
|
+
_SRPJwtBearerAuth_cooldownDefaultMs.set(this, void 0);
|
|
55
|
+
// Maximum number of login retries on rate limit errors
|
|
56
|
+
_SRPJwtBearerAuth_maxLoginRetries.set(this, void 0);
|
|
57
|
+
_SRPJwtBearerAuth_getLoginTag.set(this, void 0);
|
|
58
|
+
_SRPJwtBearerAuth_getLoginIdentifierType.set(this, void 0);
|
|
59
|
+
_SRPJwtBearerAuth_customProvider.set(this, void 0);
|
|
60
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_config, config, "f");
|
|
61
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_customProvider, options.customProvider, "f");
|
|
62
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_getLoginTag, options.getLoginTag, "f");
|
|
63
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_getLoginIdentifierType, options.getLoginIdentifierType, "f");
|
|
64
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_options, {
|
|
65
|
+
storage: options.storage,
|
|
66
|
+
signing: options.signing ??
|
|
67
|
+
getDefaultEIP6963SigningOptions(__classPrivateFieldGet(this, _SRPJwtBearerAuth_customProvider, "f")),
|
|
68
|
+
}, "f");
|
|
69
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_metametrics, options.metametrics, "f");
|
|
70
|
+
// Apply rate limit retry config if provided
|
|
71
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_cooldownDefaultMs, options.rateLimitRetry?.cooldownDefaultMs ?? 10000, "f");
|
|
72
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_maxLoginRetries, options.rateLimitRetry?.maxLoginRetries ?? 1, "f");
|
|
73
|
+
}
|
|
74
|
+
setCustomProvider(provider) {
|
|
75
|
+
__classPrivateFieldSet(this, _SRPJwtBearerAuth_customProvider, provider, "f");
|
|
76
|
+
__classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").signing = getDefaultEIP6963SigningOptions(provider);
|
|
77
|
+
}
|
|
78
|
+
// TODO: might be easier to keep entropySourceId as a class param and use multiple SRPJwtBearerAuth instances where needed
|
|
79
|
+
async getAccessToken(entropySourceId) {
|
|
80
|
+
const session = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_getAuthSession).call(this, entropySourceId);
|
|
81
|
+
if (session) {
|
|
82
|
+
return session.token.accessToken;
|
|
83
|
+
}
|
|
84
|
+
const loginResponse = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_login).call(this, entropySourceId);
|
|
85
|
+
return loginResponse.token.accessToken;
|
|
86
|
+
}
|
|
87
|
+
async getUserProfile(entropySourceId) {
|
|
88
|
+
const session = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_getAuthSession).call(this, entropySourceId);
|
|
89
|
+
if (session) {
|
|
90
|
+
return session.profile;
|
|
91
|
+
}
|
|
92
|
+
const loginResponse = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_login).call(this, entropySourceId);
|
|
93
|
+
return loginResponse.profile;
|
|
94
|
+
}
|
|
95
|
+
async getIdentifier(entropySourceId) {
|
|
96
|
+
return await __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").signing.getIdentifier(entropySourceId);
|
|
97
|
+
}
|
|
98
|
+
async getUserProfileLineage(entropySourceId) {
|
|
99
|
+
const accessToken = await this.getAccessToken(entropySourceId);
|
|
100
|
+
return await getUserProfileLineage(__classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env, accessToken);
|
|
101
|
+
}
|
|
102
|
+
async getCustomerServiceToken(entropySourceId) {
|
|
103
|
+
const accessToken = await this.getAccessToken(entropySourceId);
|
|
104
|
+
return await getCustomerServiceToken(__classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env, accessToken);
|
|
105
|
+
}
|
|
106
|
+
async pairSrpProfiles(accessTokens, authAccessToken) {
|
|
107
|
+
// Order-insensitive key: the same token set in any order maps to the same
|
|
108
|
+
// entry. Sort a copy so the request payload itself stays primary-first.
|
|
109
|
+
const key = JSON.stringify([...accessTokens].sort());
|
|
110
|
+
const cached = __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingPairings, "f").get(key);
|
|
111
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
112
|
+
return await cached.promise;
|
|
113
|
+
}
|
|
114
|
+
const promise = pairProfiles(accessTokens, authAccessToken, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env);
|
|
115
|
+
// Store the in-flight promise immediately so concurrent callers coalesce
|
|
116
|
+
// regardless of how long the request takes.
|
|
117
|
+
__classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingPairings, "f").set(key, {
|
|
118
|
+
promise,
|
|
119
|
+
expiresAt: Number.MAX_SAFE_INTEGER,
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
const result = await promise;
|
|
123
|
+
// Keep the resolved result cached for a short window so sequential
|
|
124
|
+
// retries with the same payload reuse it.
|
|
125
|
+
__classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingPairings, "f").set(key, {
|
|
126
|
+
promise,
|
|
127
|
+
expiresAt: Date.now() + PAIR_DEDUPE_TTL_MS,
|
|
128
|
+
});
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
// Never cache failures: the pairing retry loop must be able to re-hit
|
|
133
|
+
// the endpoint on the next attempt.
|
|
134
|
+
__classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingPairings, "f").delete(key);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async signMessage(message, entropySourceId) {
|
|
139
|
+
return await __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").signing.signMessage(message, entropySourceId);
|
|
140
|
+
}
|
|
141
|
+
async isSnapConnected() {
|
|
142
|
+
const provider = __classPrivateFieldGet(this, _SRPJwtBearerAuth_customProvider, "f") ?? (await getDefaultEIP6963Provider());
|
|
143
|
+
if (!provider) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const isConnected = await isSnapConnected(provider);
|
|
147
|
+
return isConnected;
|
|
148
|
+
}
|
|
149
|
+
async connectSnap() {
|
|
150
|
+
const provider = __classPrivateFieldGet(this, _SRPJwtBearerAuth_customProvider, "f") ?? (await getDefaultEIP6963Provider());
|
|
151
|
+
const res = await connectSnap(provider);
|
|
152
|
+
return res;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
_SRPJwtBearerAuth_config = new WeakMap(), _SRPJwtBearerAuth_options = new WeakMap(), _SRPJwtBearerAuth_metametrics = new WeakMap(), _SRPJwtBearerAuth_ongoingLogins = new WeakMap(), _SRPJwtBearerAuth_ongoingPairings = new WeakMap(), _SRPJwtBearerAuth_cooldownDefaultMs = new WeakMap(), _SRPJwtBearerAuth_maxLoginRetries = new WeakMap(), _SRPJwtBearerAuth_getLoginTag = new WeakMap(), _SRPJwtBearerAuth_getLoginIdentifierType = new WeakMap(), _SRPJwtBearerAuth_customProvider = new WeakMap(), _SRPJwtBearerAuth_instances = new WeakSet(), _SRPJwtBearerAuth_getAuthSession =
|
|
156
|
+
// convert expiresIn from seconds to milliseconds and use 90% of expiresIn
|
|
157
|
+
async function _SRPJwtBearerAuth_getAuthSession(entropySourceId) {
|
|
158
|
+
const auth = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").storage.getLoginResponse(entropySourceId);
|
|
159
|
+
if (!validateLoginResponse(auth)) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
// get canonical profile id from server if not present in the cached session
|
|
163
|
+
if (!auth.profile.canonicalProfileId) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const currentTime = Date.now();
|
|
167
|
+
const sessionAge = currentTime - auth.token.obtainedAt;
|
|
168
|
+
const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;
|
|
169
|
+
if (sessionAge < refreshThreshold) {
|
|
170
|
+
return auth;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}, _SRPJwtBearerAuth_login = async function _SRPJwtBearerAuth_login(entropySourceId) {
|
|
174
|
+
// Use a deferred login to avoid race conditions
|
|
175
|
+
return await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_deferredLogin).call(this, entropySourceId);
|
|
176
|
+
}, _SRPJwtBearerAuth_performLogin = async function _SRPJwtBearerAuth_performLogin(entropySourceId) {
|
|
177
|
+
// Nonce
|
|
178
|
+
const publicKey = await this.getIdentifier(entropySourceId);
|
|
179
|
+
const nonceRes = await getNonce(publicKey, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env);
|
|
180
|
+
// Tag only when the wallet supplies getLoginTag. SDK callers keep the
|
|
181
|
+
// legacy 3-part message rather than guessing `primary`.
|
|
182
|
+
const tag = await __classPrivateFieldGet(this, _SRPJwtBearerAuth_getLoginTag, "f")?.call(this, entropySourceId);
|
|
183
|
+
const identifierType = (await __classPrivateFieldGet(this, _SRPJwtBearerAuth_getLoginIdentifierType, "f")?.call(this, entropySourceId)) ?? 'SRP';
|
|
184
|
+
const rawMessage = __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_createSrpLoginRawMessage).call(this, nonceRes.nonce, publicKey, tag);
|
|
185
|
+
const signature = await this.signMessage(rawMessage, entropySourceId);
|
|
186
|
+
// Authenticate
|
|
187
|
+
const authResponse = await authenticate(rawMessage, signature, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").type, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env, __classPrivateFieldGet(this, _SRPJwtBearerAuth_metametrics, "f"), identifierType);
|
|
188
|
+
// Resolve original profileId from aliases.
|
|
189
|
+
// This is done mainly to preserve the original profileId for storage key derivation
|
|
190
|
+
// until we migrate to the canonical profileId storage system.
|
|
191
|
+
const canonicalProfileId = authResponse.profile.profileId;
|
|
192
|
+
const profile = { ...authResponse.profile };
|
|
193
|
+
if (authResponse.profileAliases?.length > 0) {
|
|
194
|
+
const targetIdentifierId = computeIdentifierId(publicKey, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env);
|
|
195
|
+
const matchingAliases = authResponse.profileAliases.filter((alias) => alias.identifierIds.some((id) => id.id === targetIdentifierId));
|
|
196
|
+
// Prefer the leaf alias (single identifier) — it's the original profile
|
|
197
|
+
// created for this SRP. Multi-identifier aliases are former canonicals
|
|
198
|
+
// that absorbed other profiles; they are correct only when this SRP's
|
|
199
|
+
// original profile was itself a canonical before being absorbed.
|
|
200
|
+
const targetAlias = matchingAliases.find((alias) => alias.identifierIds.length === 1) ??
|
|
201
|
+
matchingAliases[0];
|
|
202
|
+
if (targetAlias) {
|
|
203
|
+
profile.profileId = targetAlias.aliasProfileId;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
profile.canonicalProfileId = canonicalProfileId;
|
|
207
|
+
// Authorize
|
|
208
|
+
const tokenResponse = await authorizeOIDC(authResponse.token, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").env, __classPrivateFieldGet(this, _SRPJwtBearerAuth_config, "f").platform);
|
|
209
|
+
// Save
|
|
210
|
+
const result = {
|
|
211
|
+
profile,
|
|
212
|
+
token: tokenResponse,
|
|
213
|
+
};
|
|
214
|
+
await __classPrivateFieldGet(this, _SRPJwtBearerAuth_options, "f").storage.setLoginResponse(result, entropySourceId);
|
|
215
|
+
return result;
|
|
216
|
+
}, _SRPJwtBearerAuth_deferredLogin = async function _SRPJwtBearerAuth_deferredLogin(entropySourceId) {
|
|
217
|
+
// Check if there's already an ongoing login for this entropySourceId
|
|
218
|
+
const existingLogin = __classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingLogins, "f").get(entropySourceId);
|
|
219
|
+
if (existingLogin) {
|
|
220
|
+
return existingLogin;
|
|
221
|
+
}
|
|
222
|
+
// Create a new login promise
|
|
223
|
+
const loginPromise = __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_loginWithRetry).call(this, entropySourceId);
|
|
224
|
+
// Store the promise in the map
|
|
225
|
+
__classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingLogins, "f").set(entropySourceId, loginPromise);
|
|
226
|
+
try {
|
|
227
|
+
// Wait for the login to complete
|
|
228
|
+
return await loginPromise;
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
// Always clean up the ongoing login promise when done
|
|
232
|
+
__classPrivateFieldGet(this, _SRPJwtBearerAuth_ongoingLogins, "f").delete(entropySourceId);
|
|
233
|
+
}
|
|
234
|
+
}, _SRPJwtBearerAuth_loginWithRetry = async function _SRPJwtBearerAuth_loginWithRetry(entropySourceId) {
|
|
235
|
+
// Allow max attempts: initial + maxLoginRetries on 429
|
|
236
|
+
for (let attempt = 0; attempt < 1 + __classPrivateFieldGet(this, _SRPJwtBearerAuth_maxLoginRetries, "f"); attempt += 1) {
|
|
237
|
+
try {
|
|
238
|
+
return await __classPrivateFieldGet(this, _SRPJwtBearerAuth_instances, "m", _SRPJwtBearerAuth_performLogin).call(this, entropySourceId);
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
// Only retry on rate-limit (429) errors
|
|
242
|
+
if (!RateLimitedError.isRateLimitError(e)) {
|
|
243
|
+
throw e;
|
|
244
|
+
}
|
|
245
|
+
// If we've exhausted attempts, rethrow
|
|
246
|
+
if (attempt >= __classPrivateFieldGet(this, _SRPJwtBearerAuth_maxLoginRetries, "f")) {
|
|
247
|
+
throw e;
|
|
248
|
+
}
|
|
249
|
+
// Wait for Retry-After or default cooldown
|
|
250
|
+
const waitMs = e.retryAfterMs ?? __classPrivateFieldGet(this, _SRPJwtBearerAuth_cooldownDefaultMs, "f");
|
|
251
|
+
await timeUtils.delay(waitMs);
|
|
252
|
+
// Loop continues to retry
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// Should never reach here due to loop logic, but TypeScript needs a return
|
|
256
|
+
throw new Error('Unexpected: login loop exhausted without result');
|
|
257
|
+
}, _SRPJwtBearerAuth_createSrpLoginRawMessage = function _SRPJwtBearerAuth_createSrpLoginRawMessage(nonce, publicKey, tag) {
|
|
258
|
+
if (tag) {
|
|
259
|
+
return `metamask:${nonce}:${publicKey}:${tag}`;
|
|
260
|
+
}
|
|
261
|
+
return `metamask:${nonce}:${publicKey}`;
|
|
262
|
+
};
|
|
263
|
+
//# sourceMappingURL=flow-srp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-srp.mjs","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-srp.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,sBAAqB;AACjE,OAAO,EAAE,0BAA0B,EAAE,gDAA+C;AACpF,OAAO,EACL,oBAAoB,EACpB,+BAA+B,EAC/B,WAAW,EACX,eAAe,EAChB,qDAAoD;AACrD,OAAO,EAAE,qBAAqB,EAAE,6CAA4C;AAC5E,OAAO,EACL,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,QAAQ,EACR,qBAAqB,EACrB,YAAY,EACb,uBAAsB;AAcvB,OAAO,EAAE,mBAAmB,EAAE,+BAA8B;AAC5D,OAAO,KAAK,SAAS,yBAAwB;AAuB7C,0EAA0E;AAC1E,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAM,CAAC;AAEzC,MAAM,yBAAyB,GAAG,KAAK,IAAI,EAAE;IAC3C,MAAM,QAAQ,GAAG,MAAM,0BAA0B,EAAE,CAAC;IACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,eAAe,CAAC,8BAA8B,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,+BAA+B,GAAG,CACtC,cAAgC,EACZ,EAAE,CAAC,CAAC;IACxB,aAAa,EAAE,KAAK,EAAE,eAAwB,EAAmB,E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ED,uCAAuC;YACvC,IAAI,OAAO,IAAI,uBAAA,IAAI,yCAAiB,EAAE,CAAC;gBACrC,MAAM,CAAC,CAAC;YACV,CAAC;YAED,2CAA2C;YAC3C,MAAM,MAAM,GAAG,CAAC,CAAC,YAAY,IAAI,uBAAA,IAAI,2CAAmB,CAAC;YACzD,MAAM,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAE9B,0BAA0B;QAC5B,CAAC;IACH,CAAC;IAED,2EAA2E;IAC3E,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;AACrE,CAAC,mGAGC,KAAa,EACb,SAAiB,EACjB,GAAiB;IAIjB,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,YAAY,KAAK,IAAI,SAAS,IAAI,GAAG,EAAW,CAAC;IAC1D,CAAC;IACD,OAAO,YAAY,KAAK,IAAI,SAAS,EAAW,CAAC;AACnD,CAAC","sourcesContent":["import type { Eip1193Provider } from 'ethers';\n\nimport type { MetaMetricsAuth } from '../../shared/types/services.js';\nimport { ValidationError, RateLimitedError } from '../errors.js';\nimport { getMetaMaskProviderEIP6963 } from '../utils/eip-6963-metamask-provider.js';\nimport {\n MESSAGE_SIGNING_SNAP,\n assertMessageStartsWithMetamask,\n connectSnap,\n isSnapConnected,\n} from '../utils/messaging-signing-snap-requests.js';\nimport { validateLoginResponse } from '../utils/validate-login-response.js';\nimport {\n authenticate,\n authorizeOIDC,\n getCustomerServiceToken,\n getNonce,\n getUserProfileLineage,\n pairProfiles,\n} from './services.js';\nimport type { PairProfilesResponse } from './services.js';\nimport type {\n AuthConfig,\n AuthSigningOptions,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginIdentifierType,\n LoginResponse,\n SrpLoginTag,\n UserProfile,\n UserProfileLineage,\n} from './types.js';\nimport { computeIdentifierId } from './utils/identifier.js';\nimport * as timeUtils from './utils/time.js';\n\ntype JwtBearerAuth_SRP_Options = {\n storage: AuthStorageOptions;\n signing?: AuthSigningOptions;\n /**\n * Resolves the login tag for a given entropy source.\n * When omitted, `raw_message` stays untagged (`metamask:<nonce>:<pubkey>`).\n */\n getLoginTag?: (entropySourceId?: string) => Promise<SrpLoginTag>;\n /**\n * Resolves the metametrics `identifier_type` for a given entropy source.\n * Defaults to `'SRP'` when omitted.\n */\n getLoginIdentifierType?: (\n entropySourceId?: string,\n ) => Promise<LoginIdentifierType>;\n rateLimitRetry?: {\n cooldownDefaultMs?: number; // default cooldown when 429 has no Retry-After\n maxLoginRetries?: number; // maximum number of login retries on rate limit\n };\n};\n\n// How long a successful pairing result stays cached so identical payloads\n// (concurrent or sequential retries) reuse it instead of re-hitting the endpoint.\nexport const PAIR_DEDUPE_TTL_MS = 30_000;\n\nconst getDefaultEIP6963Provider = async () => {\n const provider = await getMetaMaskProviderEIP6963();\n if (!provider) {\n throw new ValidationError('No MetaMask wallet connected');\n }\n return provider;\n};\n\nconst getDefaultEIP6963SigningOptions = (\n customProvider?: Eip1193Provider,\n): AuthSigningOptions => ({\n getIdentifier: async (entropySourceId?: string): Promise<string> => {\n const provider = customProvider ?? (await getDefaultEIP6963Provider());\n return await MESSAGE_SIGNING_SNAP.getPublicKey(provider, entropySourceId);\n },\n signMessage: async (\n message: string,\n entropySourceId?: string,\n ): Promise<string> => {\n const provider = customProvider ?? (await getDefaultEIP6963Provider());\n assertMessageStartsWithMetamask(message);\n return await MESSAGE_SIGNING_SNAP.signMessage(\n provider,\n message,\n entropySourceId,\n );\n },\n});\n\nexport class SRPJwtBearerAuth implements IBaseAuth {\n readonly #config: AuthConfig;\n\n readonly #options: {\n storage: AuthStorageOptions;\n signing: AuthSigningOptions;\n };\n\n readonly #metametrics?: MetaMetricsAuth;\n\n // Map to store ongoing login promises by entropySourceId\n readonly #ongoingLogins = new Map<\n string | undefined,\n Promise<LoginResponse>\n >();\n\n // Map to dedupe pairing calls by an order-insensitive token-set key.\n // Holds the in-flight promise (coalescing concurrent callers) and keeps it\n // for a short TTL after success (collapsing sequential retries).\n readonly #ongoingPairings = new Map<\n string,\n { promise: Promise<PairProfilesResponse>; expiresAt: number }\n >();\n\n // Default cooldown when 429 has no Retry-After header\n readonly #cooldownDefaultMs: number;\n\n // Maximum number of login retries on rate limit errors\n readonly #maxLoginRetries: number;\n\n readonly #getLoginTag?: (entropySourceId?: string) => Promise<SrpLoginTag>;\n\n readonly #getLoginIdentifierType?: (\n entropySourceId?: string,\n ) => Promise<LoginIdentifierType>;\n\n #customProvider?: Eip1193Provider;\n\n constructor(\n config: AuthConfig & { type: AuthType.SRP },\n options: JwtBearerAuth_SRP_Options & {\n customProvider?: Eip1193Provider;\n metametrics?: MetaMetricsAuth;\n },\n ) {\n this.#config = config;\n this.#customProvider = options.customProvider;\n this.#getLoginTag = options.getLoginTag;\n this.#getLoginIdentifierType = options.getLoginIdentifierType;\n this.#options = {\n storage: options.storage,\n signing:\n options.signing ??\n getDefaultEIP6963SigningOptions(this.#customProvider),\n };\n this.#metametrics = options.metametrics;\n\n // Apply rate limit retry config if provided\n this.#cooldownDefaultMs =\n options.rateLimitRetry?.cooldownDefaultMs ?? 10000;\n this.#maxLoginRetries = options.rateLimitRetry?.maxLoginRetries ?? 1;\n }\n\n setCustomProvider(provider: Eip1193Provider) {\n this.#customProvider = provider;\n this.#options.signing = getDefaultEIP6963SigningOptions(provider);\n }\n\n // TODO: might be easier to keep entropySourceId as a class param and use multiple SRPJwtBearerAuth instances where needed\n async getAccessToken(entropySourceId?: string): Promise<string> {\n const session = await this.#getAuthSession(entropySourceId);\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login(entropySourceId);\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(entropySourceId?: string): Promise<UserProfile> {\n const session = await this.#getAuthSession(entropySourceId);\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login(entropySourceId);\n return loginResponse.profile;\n }\n\n async getIdentifier(entropySourceId?: string): Promise<string> {\n return await this.#options.signing.getIdentifier(entropySourceId);\n }\n\n async getUserProfileLineage(\n entropySourceId?: string,\n ): Promise<UserProfileLineage> {\n const accessToken = await this.getAccessToken(entropySourceId);\n return await getUserProfileLineage(this.#config.env, accessToken);\n }\n\n async getCustomerServiceToken(entropySourceId?: string): Promise<string> {\n const accessToken = await this.getAccessToken(entropySourceId);\n return await getCustomerServiceToken(this.#config.env, accessToken);\n }\n\n async pairSrpProfiles(\n accessTokens: string[],\n authAccessToken: string,\n ): Promise<PairProfilesResponse> {\n // Order-insensitive key: the same token set in any order maps to the same\n // entry. Sort a copy so the request payload itself stays primary-first.\n const key = JSON.stringify([...accessTokens].sort());\n\n const cached = this.#ongoingPairings.get(key);\n if (cached && cached.expiresAt > Date.now()) {\n return await cached.promise;\n }\n\n const promise = pairProfiles(\n accessTokens,\n authAccessToken,\n this.#config.env,\n );\n // Store the in-flight promise immediately so concurrent callers coalesce\n // regardless of how long the request takes.\n this.#ongoingPairings.set(key, {\n promise,\n expiresAt: Number.MAX_SAFE_INTEGER,\n });\n\n try {\n const result = await promise;\n // Keep the resolved result cached for a short window so sequential\n // retries with the same payload reuse it.\n this.#ongoingPairings.set(key, {\n promise,\n expiresAt: Date.now() + PAIR_DEDUPE_TTL_MS,\n });\n return result;\n } catch (error) {\n // Never cache failures: the pairing retry loop must be able to re-hit\n // the endpoint on the next attempt.\n this.#ongoingPairings.delete(key);\n throw error;\n }\n }\n\n async signMessage(\n message: string,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#options.signing.signMessage(message, entropySourceId);\n }\n\n async isSnapConnected(): Promise<boolean> {\n const provider =\n this.#customProvider ?? (await getDefaultEIP6963Provider());\n if (!provider) {\n return false;\n }\n\n const isConnected = await isSnapConnected(provider);\n return isConnected;\n }\n\n async connectSnap(): Promise<string> {\n const provider =\n this.#customProvider ?? (await getDefaultEIP6963Provider());\n\n const res = await connectSnap(provider);\n return res;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(\n entropySourceId?: string,\n ): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse(entropySourceId);\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n // get canonical profile id from server if not present in the cached session\n if (!auth.profile.canonicalProfileId) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(entropySourceId?: string): Promise<LoginResponse> {\n // Use a deferred login to avoid race conditions\n return await this.#deferredLogin(entropySourceId);\n }\n\n async #performLogin(entropySourceId?: string): Promise<LoginResponse> {\n // Nonce\n const publicKey = await this.getIdentifier(entropySourceId);\n const nonceRes = await getNonce(publicKey, this.#config.env);\n\n // Tag only when the wallet supplies getLoginTag. SDK callers keep the\n // legacy 3-part message rather than guessing `primary`.\n const tag = await this.#getLoginTag?.(entropySourceId);\n const identifierType =\n (await this.#getLoginIdentifierType?.(entropySourceId)) ?? 'SRP';\n const rawMessage = this.#createSrpLoginRawMessage(\n nonceRes.nonce,\n publicKey,\n tag,\n );\n const signature = await this.signMessage(rawMessage, entropySourceId);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n this.#metametrics,\n identifierType,\n );\n\n // Resolve original profileId from aliases.\n // This is done mainly to preserve the original profileId for storage key derivation\n // until we migrate to the canonical profileId storage system.\n const canonicalProfileId = authResponse.profile.profileId;\n const profile = { ...authResponse.profile };\n\n if (authResponse.profileAliases?.length > 0) {\n const targetIdentifierId = computeIdentifierId(\n publicKey,\n this.#config.env,\n );\n\n const matchingAliases = authResponse.profileAliases.filter((alias) =>\n alias.identifierIds.some((id) => id.id === targetIdentifierId),\n );\n\n // Prefer the leaf alias (single identifier) — it's the original profile\n // created for this SRP. Multi-identifier aliases are former canonicals\n // that absorbed other profiles; they are correct only when this SRP's\n // original profile was itself a canonical before being absorbed.\n const targetAlias =\n matchingAliases.find((alias) => alias.identifierIds.length === 1) ??\n matchingAliases[0];\n\n if (targetAlias) {\n profile.profileId = targetAlias.aliasProfileId;\n }\n }\n\n profile.canonicalProfileId = canonicalProfileId;\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result, entropySourceId);\n\n return result;\n }\n\n async #deferredLogin(entropySourceId?: string): Promise<LoginResponse> {\n // Check if there's already an ongoing login for this entropySourceId\n const existingLogin = this.#ongoingLogins.get(entropySourceId);\n if (existingLogin) {\n return existingLogin;\n }\n\n // Create a new login promise\n const loginPromise = this.#loginWithRetry(entropySourceId);\n\n // Store the promise in the map\n this.#ongoingLogins.set(entropySourceId, loginPromise);\n\n try {\n // Wait for the login to complete\n return await loginPromise;\n } finally {\n // Always clean up the ongoing login promise when done\n this.#ongoingLogins.delete(entropySourceId);\n }\n }\n\n async #loginWithRetry(entropySourceId?: string): Promise<LoginResponse> {\n // Allow max attempts: initial + maxLoginRetries on 429\n for (let attempt = 0; attempt < 1 + this.#maxLoginRetries; attempt += 1) {\n try {\n return await this.#performLogin(entropySourceId);\n } catch (e) {\n // Only retry on rate-limit (429) errors\n if (!RateLimitedError.isRateLimitError(e)) {\n throw e;\n }\n\n // If we've exhausted attempts, rethrow\n if (attempt >= this.#maxLoginRetries) {\n throw e;\n }\n\n // Wait for Retry-After or default cooldown\n const waitMs = e.retryAfterMs ?? this.#cooldownDefaultMs;\n await timeUtils.delay(waitMs);\n\n // Loop continues to retry\n }\n }\n\n // Should never reach here due to loop logic, but TypeScript needs a return\n throw new Error('Unexpected: login loop exhausted without result');\n }\n\n #createSrpLoginRawMessage(\n nonce: string,\n publicKey: string,\n tag?: SrpLoginTag,\n ):\n | `metamask:${string}:${string}`\n | `metamask:${string}:${string}:${SrpLoginTag}` {\n if (tag) {\n return `metamask:${nonce}:${publicKey}:${tag}` as const;\n }\n return `metamask:${nonce}:${publicKey}` as const;\n }\n}\n"]}
|