@metamask-previews/profile-sync-controller 32.1.1-preview-c6cdff1dd → 32.1.1-preview-9d2a9bdf5
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 -2
- package/dist/controllers/authentication/AuthenticationController.d.ts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.js +5 -6
- package/dist/controllers/authentication/AuthenticationController.js.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.ts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.js +5 -6
- package/dist/controllers/user-storage/UserStorageController.js.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts +1 -56
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js +1 -119
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +1 -1
- package/dist/sdk/authentication.d.ts +6 -15
- package/dist/sdk/authentication.d.ts.map +1 -1
- package/dist/sdk/authentication.js +0 -24
- package/dist/sdk/authentication.js.map +1 -1
- package/dist/sdk/constants.d.ts +0 -2
- package/dist/sdk/constants.d.ts.map +1 -1
- package/dist/sdk/constants.js +0 -2
- package/dist/sdk/constants.js.map +1 -1
- package/dist/sdk/errors.d.ts +0 -91
- package/dist/sdk/errors.d.ts.map +1 -1
- package/dist/sdk/errors.js +0 -161
- package/dist/sdk/errors.js.map +1 -1
- package/dist/sdk/index.d.ts +0 -3
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +0 -1
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/mocks/auth.d.ts +0 -63
- package/dist/sdk/mocks/auth.d.ts.map +1 -1
- package/dist/sdk/mocks/auth.js +0 -90
- package/dist/sdk/mocks/auth.js.map +1 -1
- package/dist/sdk/utils/validate-login-response.d.ts.map +1 -1
- package/dist/sdk/utils/validate-login-response.js +7 -5
- package/dist/sdk/utils/validate-login-response.js.map +1 -1
- package/dist/shared/utils/entropy-source.d.ts +12 -3
- package/dist/shared/utils/entropy-source.d.ts.map +1 -1
- package/dist/shared/utils/entropy-source.js +17 -4
- package/dist/shared/utils/entropy-source.js.map +1 -1
- package/package.json +1 -3
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.d.ts +0 -691
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.js +0 -265
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/services.d.ts +0 -104
- package/dist/sdk/authentication-jwt-bearer/mfa/services.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/services.js +0 -363
- package/dist/sdk/authentication-jwt-bearer/mfa/services.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/types.d.ts +0 -125
- package/dist/sdk/authentication-jwt-bearer/mfa/types.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/mfa/types.js +0 -3
- package/dist/sdk/authentication-jwt-bearer/mfa/types.js.map +0 -1
- package/dist/sdk/utils/as-record.d.ts +0 -10
- package/dist/sdk/utils/as-record.d.ts.map +0 -1
- package/dist/sdk/utils/as-record.js +0 -14
- package/dist/sdk/utils/as-record.js.map +0 -1
- package/dist/sdk/utils/jwt.d.ts +0 -13
- package/dist/sdk/utils/jwt.d.ts.map +0 -1
- package/dist/sdk/utils/jwt.js +0 -21
- package/dist/sdk/utils/jwt.js.map +0 -1
- package/dist/sdk/utils/to-error-message.d.ts +0 -8
- package/dist/sdk/utils/to-error-message.d.ts.map +0 -1
- package/dist/sdk/utils/to-error-message.js +0 -10
- package/dist/sdk/utils/to-error-message.js.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ValidationError, RateLimitedError } from '../errors.js';
|
|
2
2
|
import { getMetaMaskProviderEIP6963 } from '../utils/eip-6963-metamask-provider.js';
|
|
3
3
|
import { MESSAGE_SIGNING_SNAP, assertMessageStartsWithMetamask, connectSnap, isSnapConnected, } from '../utils/messaging-signing-snap-requests.js';
|
|
4
4
|
import { validateLoginResponse } from '../utils/validate-login-response.js';
|
|
5
|
-
import { getMfaCredentials, mfaEnroll, mfaEnrollComplete, mfaVerify, mfaVerifyComplete, } from './mfa/services.js';
|
|
6
5
|
import { authenticate, authorizeOIDC, getCustomerServiceToken, getNonce, getPartnerIdentityToken, getUserProfileLineage, pairProfiles, pairSocialIdentifier, } from './services.js';
|
|
7
6
|
import { computeIdentifierId } from './utils/identifier.js';
|
|
8
7
|
import * as timeUtils from './utils/time.js';
|
|
@@ -96,123 +95,6 @@ export class SRPJwtBearerAuth {
|
|
|
96
95
|
const accessToken = await this.getAccessToken(entropySourceId);
|
|
97
96
|
return await getPartnerIdentityToken(this.#config.env, accessToken, claims, audience);
|
|
98
97
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Begins enrollment of an MFA credential for the primary profile.
|
|
101
|
-
*
|
|
102
|
-
* @param type - Credential type to enroll.
|
|
103
|
-
* @param options - Enrollment options.
|
|
104
|
-
* @param options.email - Email address, required for email OTP.
|
|
105
|
-
* @param options.entropySourceId - Entropy source whose profile owns the
|
|
106
|
-
* credential.
|
|
107
|
-
* @returns Enrollment challenge for the client ceremony.
|
|
108
|
-
*/
|
|
109
|
-
async beginMfaEnrollment(type, options) {
|
|
110
|
-
const { email, entropySourceId } = options ?? {};
|
|
111
|
-
const accessToken = await this.getAccessToken(entropySourceId);
|
|
112
|
-
const result = await mfaEnroll(this.#config.env, accessToken, {
|
|
113
|
-
credential_type: type,
|
|
114
|
-
...(email ? { identifier: email } : {}),
|
|
115
|
-
});
|
|
116
|
-
if (type === 'passkey') {
|
|
117
|
-
if (!result.publicKey) {
|
|
118
|
-
throw new MfaError('invalid_response', 'Passkey enrollment response is missing creation data');
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
type,
|
|
122
|
-
flowId: result.flowId,
|
|
123
|
-
expiresAt: result.expiresAt,
|
|
124
|
-
publicKey: result.publicKey,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
type,
|
|
129
|
-
flowId: result.flowId,
|
|
130
|
-
expiresAt: result.expiresAt,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Completes enrollment of an MFA credential.
|
|
135
|
-
*
|
|
136
|
-
* @param flowId - Identifier returned by the begin call.
|
|
137
|
-
* @param proof - Platform attestation or email code.
|
|
138
|
-
* @param entropySourceId - Entropy source whose profile owns the credential.
|
|
139
|
-
*/
|
|
140
|
-
async completeMfaEnrollment(flowId, proof, entropySourceId) {
|
|
141
|
-
const accessToken = await this.getAccessToken(entropySourceId);
|
|
142
|
-
await mfaEnrollComplete(this.#config.env, accessToken, {
|
|
143
|
-
credential_type: proof.type,
|
|
144
|
-
flow_id: flowId,
|
|
145
|
-
...(proof.type === 'passkey'
|
|
146
|
-
? { passkey_attestation: proof.attestation }
|
|
147
|
-
: { otp_code: proof.code }),
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Begins step-up verification with an enrolled credential.
|
|
152
|
-
*
|
|
153
|
-
* @param type - Credential type to verify.
|
|
154
|
-
* @param entropySourceId - Entropy source whose profile owns the credential.
|
|
155
|
-
* @returns Verification challenge for the client ceremony.
|
|
156
|
-
*/
|
|
157
|
-
async beginMfaVerification(type, entropySourceId) {
|
|
158
|
-
const accessToken = await this.getAccessToken(entropySourceId);
|
|
159
|
-
const result = await mfaVerify(this.#config.env, accessToken, {
|
|
160
|
-
credential_type: type,
|
|
161
|
-
});
|
|
162
|
-
if (type === 'passkey') {
|
|
163
|
-
if (!result.publicKey) {
|
|
164
|
-
throw new MfaError('invalid_response', 'Passkey verification response is missing request data');
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
type,
|
|
168
|
-
flowId: result.flowId,
|
|
169
|
-
expiresAt: result.expiresAt,
|
|
170
|
-
publicKey: result.publicKey,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
type,
|
|
175
|
-
flowId: result.flowId,
|
|
176
|
-
expiresAt: result.expiresAt,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Completes step-up verification with an enrolled credential.
|
|
181
|
-
*
|
|
182
|
-
* @param flowId - Identifier returned by the begin call.
|
|
183
|
-
* @param proof - Platform assertion or email code.
|
|
184
|
-
* @param entropySourceId - Entropy source whose profile owns the credential.
|
|
185
|
-
* @returns AAL2 assertion issued after verification.
|
|
186
|
-
*/
|
|
187
|
-
async completeMfaVerification(flowId, proof, entropySourceId) {
|
|
188
|
-
const accessToken = await this.getAccessToken(entropySourceId);
|
|
189
|
-
return await mfaVerifyComplete(this.#config.env, accessToken, {
|
|
190
|
-
credential_type: proof.type,
|
|
191
|
-
flow_id: flowId,
|
|
192
|
-
...(proof.type === 'passkey'
|
|
193
|
-
? { passkey_assertion: proof.assertion }
|
|
194
|
-
: { otp_code: proof.code }),
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Gets credentials enrolled on the primary profile.
|
|
199
|
-
*
|
|
200
|
-
* @param entropySourceId - Entropy source whose profile owns the credentials.
|
|
201
|
-
* @returns Supported enrolled credentials.
|
|
202
|
-
*/
|
|
203
|
-
async getMfaCredentials(entropySourceId) {
|
|
204
|
-
const accessToken = await this.getAccessToken(entropySourceId);
|
|
205
|
-
return await getMfaCredentials(this.#config.env, accessToken);
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Exchanges an MFA assertion for an elevated access token.
|
|
209
|
-
*
|
|
210
|
-
* @param assertionJwt - AAL2 authentication assertion.
|
|
211
|
-
* @returns Elevated access token.
|
|
212
|
-
*/
|
|
213
|
-
async exchangeMfaAssertion(assertionJwt) {
|
|
214
|
-
return await authorizeOIDC(assertionJwt, this.#config.env, this.#config.platform);
|
|
215
|
-
}
|
|
216
98
|
async pairSocialIdentifier(params, authAccessToken) {
|
|
217
99
|
await pairSocialIdentifier(params, authAccessToken, this.#config.env);
|
|
218
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-srp.js","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-srp.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACpF,OAAO,EACL,oBAAoB,EACpB,+BAA+B,EAC/B,WAAW,EACX,eAAe,GAChB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAU3B,OAAO,EACL,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,QAAQ,EACR,uBAAuB,EACvB,qBAAqB,EACrB,YAAY,EACZ,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAkBvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAuB7C,0EAA0E;AAC1E,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,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,cAA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2E;QAC3E,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,yBAAyB,CACvB,KAAa,EACb,SAAiB,EACjB,GAAiB;QAIjB,IAAI,GAAG,EAAE,CAAC;YACR,OAAO,YAAY,KAAK,IAAI,SAAS,IAAI,GAAG,EAAW,CAAC;QAC1D,CAAC;QACD,OAAO,YAAY,KAAK,IAAI,SAAS,EAAW,CAAC;IACnD,CAAC;CACF","sourcesContent":["import type { Eip1193Provider } from 'ethers';\n\nimport type { MetaMetricsAuth } from '../../shared/types/services.js';\nimport { MfaError, 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 getMfaCredentials,\n mfaEnroll,\n mfaEnrollComplete,\n mfaVerify,\n mfaVerifyComplete,\n} from './mfa/services.js';\nimport type { MfaStepUpAssertion } from './mfa/services.js';\nimport type {\n EnrolledCredential,\n EnrollmentChallenge,\n EnrollmentProof,\n MfaCredentialType,\n StepUpChallenge,\n StepUpProof,\n} from './mfa/types.js';\nimport {\n authenticate,\n authorizeOIDC,\n getCustomerServiceToken,\n getNonce,\n getPartnerIdentityToken,\n getUserProfileLineage,\n pairProfiles,\n pairSocialIdentifier,\n} from './services.js';\nimport type { PairProfilesResponse } from './services.js';\nimport type {\n AuthConfig,\n AccessToken,\n AuthSigningOptions,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginIdentifierType,\n LoginResponse,\n OidcTokenAudience,\n OidcTokenClaims,\n PairSocialIdentifierParams,\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 getPartnerIdentityToken(\n claims: OidcTokenClaims,\n audience: OidcTokenAudience,\n entropySourceId?: string,\n ): Promise<string> {\n const accessToken = await this.getAccessToken(entropySourceId);\n return await getPartnerIdentityToken(\n this.#config.env,\n accessToken,\n claims,\n audience,\n );\n }\n\n /**\n * Begins enrollment of an MFA credential for the primary profile.\n *\n * @param type - Credential type to enroll.\n * @param options - Enrollment options.\n * @param options.email - Email address, required for email OTP.\n * @param options.entropySourceId - Entropy source whose profile owns the\n * credential.\n * @returns Enrollment challenge for the client ceremony.\n */\n async beginMfaEnrollment(\n type: MfaCredentialType,\n options?: { email?: string; entropySourceId?: string },\n ): Promise<EnrollmentChallenge> {\n const { email, entropySourceId } = options ?? {};\n const accessToken = await this.getAccessToken(entropySourceId);\n const result = await mfaEnroll(this.#config.env, accessToken, {\n credential_type: type,\n ...(email ? { identifier: email } : {}),\n });\n\n if (type === 'passkey') {\n if (!result.publicKey) {\n throw new MfaError(\n 'invalid_response',\n 'Passkey enrollment response is missing creation data',\n );\n }\n return {\n type,\n flowId: result.flowId,\n expiresAt: result.expiresAt,\n publicKey: result.publicKey,\n };\n }\n return {\n type,\n flowId: result.flowId,\n expiresAt: result.expiresAt,\n };\n }\n\n /**\n * Completes enrollment of an MFA credential.\n *\n * @param flowId - Identifier returned by the begin call.\n * @param proof - Platform attestation or email code.\n * @param entropySourceId - Entropy source whose profile owns the credential.\n */\n async completeMfaEnrollment(\n flowId: string,\n proof: EnrollmentProof,\n entropySourceId?: string,\n ): Promise<void> {\n const accessToken = await this.getAccessToken(entropySourceId);\n await mfaEnrollComplete(this.#config.env, accessToken, {\n credential_type: proof.type,\n flow_id: flowId,\n ...(proof.type === 'passkey'\n ? { passkey_attestation: proof.attestation }\n : { otp_code: proof.code }),\n });\n }\n\n /**\n * Begins step-up verification with an enrolled credential.\n *\n * @param type - Credential type to verify.\n * @param entropySourceId - Entropy source whose profile owns the credential.\n * @returns Verification challenge for the client ceremony.\n */\n async beginMfaVerification(\n type: MfaCredentialType,\n entropySourceId?: string,\n ): Promise<StepUpChallenge> {\n const accessToken = await this.getAccessToken(entropySourceId);\n const result = await mfaVerify(this.#config.env, accessToken, {\n credential_type: type,\n });\n\n if (type === 'passkey') {\n if (!result.publicKey) {\n throw new MfaError(\n 'invalid_response',\n 'Passkey verification response is missing request data',\n );\n }\n return {\n type,\n flowId: result.flowId,\n expiresAt: result.expiresAt,\n publicKey: result.publicKey,\n };\n }\n return {\n type,\n flowId: result.flowId,\n expiresAt: result.expiresAt,\n };\n }\n\n /**\n * Completes step-up verification with an enrolled credential.\n *\n * @param flowId - Identifier returned by the begin call.\n * @param proof - Platform assertion or email code.\n * @param entropySourceId - Entropy source whose profile owns the credential.\n * @returns AAL2 assertion issued after verification.\n */\n async completeMfaVerification(\n flowId: string,\n proof: StepUpProof,\n entropySourceId?: string,\n ): Promise<MfaStepUpAssertion> {\n const accessToken = await this.getAccessToken(entropySourceId);\n return await mfaVerifyComplete(this.#config.env, accessToken, {\n credential_type: proof.type,\n flow_id: flowId,\n ...(proof.type === 'passkey'\n ? { passkey_assertion: proof.assertion }\n : { otp_code: proof.code }),\n });\n }\n\n /**\n * Gets credentials enrolled on the primary profile.\n *\n * @param entropySourceId - Entropy source whose profile owns the credentials.\n * @returns Supported enrolled credentials.\n */\n async getMfaCredentials(\n entropySourceId?: string,\n ): Promise<EnrolledCredential[]> {\n const accessToken = await this.getAccessToken(entropySourceId);\n return await getMfaCredentials(this.#config.env, accessToken);\n }\n\n /**\n * Exchanges an MFA assertion for an elevated access token.\n *\n * @param assertionJwt - AAL2 authentication assertion.\n * @returns Elevated access token.\n */\n async exchangeMfaAssertion(assertionJwt: string): Promise<AccessToken> {\n return await authorizeOIDC(\n assertionJwt,\n this.#config.env,\n this.#config.platform,\n );\n }\n\n async pairSocialIdentifier(\n params: PairSocialIdentifierParams,\n authAccessToken: string,\n ): Promise<void> {\n await pairSocialIdentifier(params, authAccessToken, this.#config.env);\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
|
+
{"version":3,"file":"flow-srp.js","sourceRoot":"","sources":["../../../src/sdk/authentication-jwt-bearer/flow-srp.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACpF,OAAO,EACL,oBAAoB,EACpB,+BAA+B,EAC/B,WAAW,EACX,eAAe,GAChB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EACL,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,QAAQ,EACR,uBAAuB,EACvB,qBAAqB,EACrB,YAAY,EACZ,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAiBvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAuB7C,0EAA0E;AAC1E,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,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,EAAE;QACjE,MAAM,QAAQ,GAAG,cAAc,IAAI,CAAC,MAAM,yBAAyB,EAAE,CAAC,CAAC;QACvE,OAAO,MAAM,oBAAoB,CAAC,YAAY,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC5E,C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CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC1C,MAAM,CAAC,CAAC;gBACV,CAAC;gBAED,uCAAuC;gBACvC,IAAI,OAAO,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACrC,MAAM,CAAC,CAAC;gBACV,CAAC;gBAED,2CAA2C;gBAC3C,MAAM,MAAM,GAAG,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC,kBAAkB,CAAC;gBACzD,MAAM,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAE9B,0BAA0B;YAC5B,CAAC;QACH,CAAC;QAED,2EAA2E;QAC3E,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,yBAAyB,CACvB,KAAa,EACb,SAAiB,EACjB,GAAiB;QAIjB,IAAI,GAAG,EAAE,CAAC;YACR,OAAO,YAAY,KAAK,IAAI,SAAS,IAAI,GAAG,EAAW,CAAC;QAC1D,CAAC;QACD,OAAO,YAAY,KAAK,IAAI,SAAS,EAAW,CAAC;IACnD,CAAC;CACF","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 getPartnerIdentityToken,\n getUserProfileLineage,\n pairProfiles,\n pairSocialIdentifier,\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 OidcTokenAudience,\n OidcTokenClaims,\n PairSocialIdentifierParams,\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 getPartnerIdentityToken(\n claims: OidcTokenClaims,\n audience: OidcTokenAudience,\n entropySourceId?: string,\n ): Promise<string> {\n const accessToken = await this.getAccessToken(entropySourceId);\n return await getPartnerIdentityToken(\n this.#config.env,\n accessToken,\n claims,\n audience,\n );\n }\n\n async pairSocialIdentifier(\n params: PairSocialIdentifierParams,\n authAccessToken: string,\n ): Promise<void> {\n await pairSocialIdentifier(params, authAccessToken, this.#config.env);\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,13 +1,13 @@
|
|
|
1
|
-
import type { PublicInterface } from '@metamask/utils';
|
|
2
1
|
import type { Eip1193Provider } from 'ethers';
|
|
3
2
|
import { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';
|
|
4
3
|
import { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';
|
|
5
|
-
import type { MfaStepUpAssertion } from './authentication-jwt-bearer/mfa/services.js';
|
|
6
|
-
import type { EnrolledCredential, EnrollmentChallenge, EnrollmentProof, MfaCredentialType, StepUpChallenge, StepUpProof } from './authentication-jwt-bearer/mfa/types.js';
|
|
7
4
|
import type { PairProfilesResponse } from './authentication-jwt-bearer/services.js';
|
|
8
|
-
import type {
|
|
9
|
-
type
|
|
10
|
-
|
|
5
|
+
import type { UserProfile, Pair, PairSocialIdentifierParams, OidcTokenAudience, OidcTokenClaims, UserProfileLineage } from './authentication-jwt-bearer/types.js';
|
|
6
|
+
type Compute<T> = T extends infer U ? {
|
|
7
|
+
[K in keyof U]: U[K];
|
|
8
|
+
} : never;
|
|
9
|
+
type SIWEInterface = Compute<SIWEJwtBearerAuth>;
|
|
10
|
+
export type SRPInterface = Compute<SRPJwtBearerAuth>;
|
|
11
11
|
type SiweParams = ConstructorParameters<typeof SIWEJwtBearerAuth>;
|
|
12
12
|
type SRPParams = ConstructorParameters<typeof SRPJwtBearerAuth>;
|
|
13
13
|
type JwtBearerAuthParams = SiweParams | SRPParams;
|
|
@@ -23,15 +23,6 @@ export declare class JwtBearerAuth implements SIWEInterface, SRPInterface {
|
|
|
23
23
|
getUserProfileLineage(entropySourceId?: string): Promise<UserProfileLineage>;
|
|
24
24
|
getCustomerServiceToken(entropySourceId?: string): Promise<string>;
|
|
25
25
|
getPartnerIdentityToken(claims: OidcTokenClaims, audience: OidcTokenAudience, entropySourceId?: string): Promise<string>;
|
|
26
|
-
beginMfaEnrollment(type: MfaCredentialType, options?: {
|
|
27
|
-
email?: string;
|
|
28
|
-
entropySourceId?: string;
|
|
29
|
-
}): Promise<EnrollmentChallenge>;
|
|
30
|
-
completeMfaEnrollment(flowId: string, proof: EnrollmentProof, entropySourceId?: string): Promise<void>;
|
|
31
|
-
beginMfaVerification(type: MfaCredentialType, entropySourceId?: string): Promise<StepUpChallenge>;
|
|
32
|
-
completeMfaVerification(flowId: string, proof: StepUpProof, entropySourceId?: string): Promise<MfaStepUpAssertion>;
|
|
33
|
-
getMfaCredentials(entropySourceId?: string): Promise<EnrolledCredential[]>;
|
|
34
|
-
exchangeMfaAssertion(assertionJwt: string): Promise<AccessToken>;
|
|
35
26
|
pairSrpProfiles(accessTokens: string[], authAccessToken: string): Promise<PairProfilesResponse>;
|
|
36
27
|
pairSocialIdentifier(params: PairSocialIdentifierParams, authAccessToken: string): Promise<void>;
|
|
37
28
|
signMessage(message: string, entropySourceId?: string): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/sdk/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../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getPartnerIdentityToken(claims, audience, entropySourceId);
|
|
52
52
|
}
|
|
53
|
-
async beginMfaEnrollment(type, options) {
|
|
54
|
-
this.#assertSRP(this.#type, this.#sdk);
|
|
55
|
-
return await this.#sdk.beginMfaEnrollment(type, options);
|
|
56
|
-
}
|
|
57
|
-
async completeMfaEnrollment(flowId, proof, entropySourceId) {
|
|
58
|
-
this.#assertSRP(this.#type, this.#sdk);
|
|
59
|
-
await this.#sdk.completeMfaEnrollment(flowId, proof, entropySourceId);
|
|
60
|
-
}
|
|
61
|
-
async beginMfaVerification(type, entropySourceId) {
|
|
62
|
-
this.#assertSRP(this.#type, this.#sdk);
|
|
63
|
-
return await this.#sdk.beginMfaVerification(type, entropySourceId);
|
|
64
|
-
}
|
|
65
|
-
async completeMfaVerification(flowId, proof, entropySourceId) {
|
|
66
|
-
this.#assertSRP(this.#type, this.#sdk);
|
|
67
|
-
return await this.#sdk.completeMfaVerification(flowId, proof, entropySourceId);
|
|
68
|
-
}
|
|
69
|
-
async getMfaCredentials(entropySourceId) {
|
|
70
|
-
this.#assertSRP(this.#type, this.#sdk);
|
|
71
|
-
return await this.#sdk.getMfaCredentials(entropySourceId);
|
|
72
|
-
}
|
|
73
|
-
async exchangeMfaAssertion(assertionJwt) {
|
|
74
|
-
this.#assertSRP(this.#type, this.#sdk);
|
|
75
|
-
return await this.#sdk.exchangeMfaAssertion(assertionJwt);
|
|
76
|
-
}
|
|
77
53
|
async pairSrpProfiles(accessTokens, authAccessToken) {
|
|
78
54
|
this.#assertSRP(this.#type, this.#sdk);
|
|
79
55
|
return await this.#sdk.pairSrpProfiles(accessTokens, authAccessToken);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/sdk/authentication.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAU3E,OAA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C,EAAE,CAAC;gBACX,0BAA0B;gBAC1B,MAAM,YAAY,GAChB,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC3D,MAAM,IAAI,SAAS,CACjB,mCAAmC,YAAY,EAAE,CAClD,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CACH,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAChD,MAAM,eAAe,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,CAAC,MAKP;QACC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,WAAW,CACT,IAAc,EACd,IAA0C;QAE1C,IAAI,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC3B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,wBAAwB,CAChC,kDAAkD,CACnD,CAAC;IACJ,CAAC;IAED,UAAU,CACR,IAAc,EACd,IAA0C;QAE1C,IAAI,IAAI,KAAK,QAAQ,CAAC,GAAG,EAAE,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,wBAAwB,CAChC,iDAAiD,CAClD,CAAC;IACJ,CAAC;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,cAAc,sCAAsC,CAAC","sourcesContent":["import type { PublicInterface } from '@metamask/utils';\nimport type { Eip1193Provider } from 'ethers';\n\nimport type { Env } from '../shared/env.js';\nimport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';\nimport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';\nimport type { MfaStepUpAssertion } from './authentication-jwt-bearer/mfa/services.js';\nimport type {\n EnrolledCredential,\n EnrollmentChallenge,\n EnrollmentProof,\n MfaCredentialType,\n StepUpChallenge,\n StepUpProof,\n} from './authentication-jwt-bearer/mfa/types.js';\nimport {\n getNonce,\n pairIdentifiers,\n} from './authentication-jwt-bearer/services.js';\nimport type { PairProfilesResponse } from './authentication-jwt-bearer/services.js';\nimport type {\n AccessToken,\n UserProfile,\n Pair,\n PairSocialIdentifierParams,\n OidcTokenAudience,\n OidcTokenClaims,\n UserProfileLineage,\n} from './authentication-jwt-bearer/types.js';\nimport { AuthType } from './authentication-jwt-bearer/types.js';\nimport { PairError, UnsupportedAuthTypeError } from './errors.js';\n\n// Computing the Classes, so we only get back the public methods for the interface.\n\ntype SIWEInterface = PublicInterface<SIWEJwtBearerAuth>;\nexport type SRPInterface = PublicInterface<SRPJwtBearerAuth>;\n\ntype SiweParams = ConstructorParameters<typeof SIWEJwtBearerAuth>;\ntype SRPParams = ConstructorParameters<typeof SRPJwtBearerAuth>;\ntype JwtBearerAuthParams = SiweParams | SRPParams;\n\nexport class JwtBearerAuth implements SIWEInterface, SRPInterface {\n readonly #type: AuthType;\n\n readonly #env: Env;\n\n readonly #sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth;\n\n constructor(...args: JwtBearerAuthParams) {\n this.#type = args[0].type;\n this.#env = args[0].env;\n\n if (args[0].type === AuthType.SRP) {\n this.#sdk = new SRPJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n if (args[0].type === AuthType.SiWE) {\n this.#sdk = new SIWEJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n throw new UnsupportedAuthTypeError('unsupported auth type');\n }\n\n setCustomProvider(provider: Eip1193Provider) {\n this.#assertSRP(this.#type, this.#sdk);\n this.#sdk.setCustomProvider(provider);\n }\n\n async getAccessToken(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getAccessToken(entropySourceId);\n }\n\n async connectSnap(): Promise<string> {\n this.#assertSRP(this.#type, this.#sdk);\n return this.#sdk.connectSnap();\n }\n\n async isSnapConnected(): Promise<boolean> {\n this.#assertSRP(this.#type, this.#sdk);\n return this.#sdk.isSnapConnected();\n }\n\n async getUserProfile(entropySourceId?: string): Promise<UserProfile> {\n return await this.#sdk.getUserProfile(entropySourceId);\n }\n\n async getIdentifier(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getIdentifier(entropySourceId);\n }\n\n async getUserProfileLineage(\n entropySourceId?: string,\n ): Promise<UserProfileLineage> {\n return await this.#sdk.getUserProfileLineage(entropySourceId);\n }\n\n async getCustomerServiceToken(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getCustomerServiceToken(entropySourceId);\n }\n\n async getPartnerIdentityToken(\n claims: OidcTokenClaims,\n audience: OidcTokenAudience,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#sdk.getPartnerIdentityToken(\n claims,\n audience,\n entropySourceId,\n );\n }\n\n async beginMfaEnrollment(\n type: MfaCredentialType,\n options?: { email?: string; entropySourceId?: string },\n ): Promise<EnrollmentChallenge> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.beginMfaEnrollment(type, options);\n }\n\n async completeMfaEnrollment(\n flowId: string,\n proof: EnrollmentProof,\n entropySourceId?: string,\n ): Promise<void> {\n this.#assertSRP(this.#type, this.#sdk);\n await this.#sdk.completeMfaEnrollment(flowId, proof, entropySourceId);\n }\n\n async beginMfaVerification(\n type: MfaCredentialType,\n entropySourceId?: string,\n ): Promise<StepUpChallenge> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.beginMfaVerification(type, entropySourceId);\n }\n\n async completeMfaVerification(\n flowId: string,\n proof: StepUpProof,\n entropySourceId?: string,\n ): Promise<MfaStepUpAssertion> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.completeMfaVerification(\n flowId,\n proof,\n entropySourceId,\n );\n }\n\n async getMfaCredentials(\n entropySourceId?: string,\n ): Promise<EnrolledCredential[]> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.getMfaCredentials(entropySourceId);\n }\n\n async exchangeMfaAssertion(assertionJwt: string): Promise<AccessToken> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.exchangeMfaAssertion(assertionJwt);\n }\n\n async pairSrpProfiles(\n accessTokens: string[],\n authAccessToken: string,\n ): Promise<PairProfilesResponse> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.pairSrpProfiles(accessTokens, authAccessToken);\n }\n\n async pairSocialIdentifier(\n params: PairSocialIdentifierParams,\n authAccessToken: string,\n ): Promise<void> {\n this.#assertSRP(this.#type, this.#sdk);\n await this.#sdk.pairSocialIdentifier(params, authAccessToken);\n }\n\n async signMessage(\n message: string,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#sdk.signMessage(message, entropySourceId);\n }\n\n async pairIdentifiers(pairing: Pair[]): Promise<void> {\n const profile = await this.getUserProfile();\n const n = await getNonce(profile.profileId, this.#env);\n\n const logins = await Promise.all(\n pairing.map(async (p) => {\n try {\n const raw = `metamask:${n.nonce}:${p.identifier}`;\n const sig = await p.signMessage(raw);\n return {\n signature: sig,\n raw_message: raw,\n encrypted_storage_key: p.encryptedStorageKey,\n identifier_type: p.identifierType,\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new PairError(\n `failed to sign pairing message: ${errorMessage}`,\n );\n }\n }),\n );\n\n const accessToken = await this.getAccessToken();\n await pairIdentifiers(n.nonce, logins, accessToken, this.#env);\n }\n\n prepare(signer: {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n }): void {\n this.#assertSIWE(this.#type, this.#sdk);\n this.#sdk.prepare(signer);\n }\n\n #assertSIWE(\n type: AuthType,\n _sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts _sdk is SIWEJwtBearerAuth {\n if (type === AuthType.SiWE) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SIWE auth type',\n );\n }\n\n #assertSRP(\n type: AuthType,\n _sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts _sdk is SRPJwtBearerAuth {\n if (type === AuthType.SRP) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SRP auth type',\n );\n }\n}\n\nexport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';\nexport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';\nexport * from './authentication-jwt-bearer/types.js';\n"]}
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/sdk/authentication.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EACL,QAAQ,EACR,eAAe,GAChB,MAAM,yCAAyC,CAAC;AAUjD,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAYlE,MAAM,OAAO,aAAa;IACf,KAAK,CAAW;IAEhB,IAAI,CAAM;IAEV,IAAI,CAAuC;IAEpD,YAAY,GAAG,IAAyB;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAExB,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,GAAG,EAAE,CAAC;YAClC,IAAI,CAAC,IAAI,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IA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MAAM,IAAI,wBAAwB,CAChC,kDAAkD,CACnD,CAAC;IACJ,CAAC;IAED,UAAU,CACR,IAAc,EACd,IAA0C;QAE1C,IAAI,IAAI,KAAK,QAAQ,CAAC,GAAG,EAAE,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,wBAAwB,CAChC,iDAAiD,CAClD,CAAC;IACJ,CAAC;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,cAAc,sCAAsC,CAAC","sourcesContent":["import type { Eip1193Provider } from 'ethers';\n\nimport type { Env } from '../shared/env.js';\nimport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';\nimport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';\nimport {\n getNonce,\n pairIdentifiers,\n} from './authentication-jwt-bearer/services.js';\nimport type { PairProfilesResponse } from './authentication-jwt-bearer/services.js';\nimport type {\n UserProfile,\n Pair,\n PairSocialIdentifierParams,\n OidcTokenAudience,\n OidcTokenClaims,\n UserProfileLineage,\n} from './authentication-jwt-bearer/types.js';\nimport { AuthType } from './authentication-jwt-bearer/types.js';\nimport { PairError, UnsupportedAuthTypeError } from './errors.js';\n\n// Computing the Classes, so we only get back the public methods for the interface.\n\ntype Compute<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\ntype SIWEInterface = Compute<SIWEJwtBearerAuth>;\nexport type SRPInterface = Compute<SRPJwtBearerAuth>;\n\ntype SiweParams = ConstructorParameters<typeof SIWEJwtBearerAuth>;\ntype SRPParams = ConstructorParameters<typeof SRPJwtBearerAuth>;\ntype JwtBearerAuthParams = SiweParams | SRPParams;\n\nexport class JwtBearerAuth implements SIWEInterface, SRPInterface {\n readonly #type: AuthType;\n\n readonly #env: Env;\n\n readonly #sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth;\n\n constructor(...args: JwtBearerAuthParams) {\n this.#type = args[0].type;\n this.#env = args[0].env;\n\n if (args[0].type === AuthType.SRP) {\n this.#sdk = new SRPJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n if (args[0].type === AuthType.SiWE) {\n this.#sdk = new SIWEJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n throw new UnsupportedAuthTypeError('unsupported auth type');\n }\n\n setCustomProvider(provider: Eip1193Provider) {\n this.#assertSRP(this.#type, this.#sdk);\n this.#sdk.setCustomProvider(provider);\n }\n\n async getAccessToken(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getAccessToken(entropySourceId);\n }\n\n async connectSnap(): Promise<string> {\n this.#assertSRP(this.#type, this.#sdk);\n return this.#sdk.connectSnap();\n }\n\n async isSnapConnected(): Promise<boolean> {\n this.#assertSRP(this.#type, this.#sdk);\n return this.#sdk.isSnapConnected();\n }\n\n async getUserProfile(entropySourceId?: string): Promise<UserProfile> {\n return await this.#sdk.getUserProfile(entropySourceId);\n }\n\n async getIdentifier(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getIdentifier(entropySourceId);\n }\n\n async getUserProfileLineage(\n entropySourceId?: string,\n ): Promise<UserProfileLineage> {\n return await this.#sdk.getUserProfileLineage(entropySourceId);\n }\n\n async getCustomerServiceToken(entropySourceId?: string): Promise<string> {\n return await this.#sdk.getCustomerServiceToken(entropySourceId);\n }\n\n async getPartnerIdentityToken(\n claims: OidcTokenClaims,\n audience: OidcTokenAudience,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#sdk.getPartnerIdentityToken(\n claims,\n audience,\n entropySourceId,\n );\n }\n\n async pairSrpProfiles(\n accessTokens: string[],\n authAccessToken: string,\n ): Promise<PairProfilesResponse> {\n this.#assertSRP(this.#type, this.#sdk);\n return await this.#sdk.pairSrpProfiles(accessTokens, authAccessToken);\n }\n\n async pairSocialIdentifier(\n params: PairSocialIdentifierParams,\n authAccessToken: string,\n ): Promise<void> {\n this.#assertSRP(this.#type, this.#sdk);\n await this.#sdk.pairSocialIdentifier(params, authAccessToken);\n }\n\n async signMessage(\n message: string,\n entropySourceId?: string,\n ): Promise<string> {\n return await this.#sdk.signMessage(message, entropySourceId);\n }\n\n async pairIdentifiers(pairing: Pair[]): Promise<void> {\n const profile = await this.getUserProfile();\n const n = await getNonce(profile.profileId, this.#env);\n\n const logins = await Promise.all(\n pairing.map(async (p) => {\n try {\n const raw = `metamask:${n.nonce}:${p.identifier}`;\n const sig = await p.signMessage(raw);\n return {\n signature: sig,\n raw_message: raw,\n encrypted_storage_key: p.encryptedStorageKey,\n identifier_type: p.identifierType,\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new PairError(\n `failed to sign pairing message: ${errorMessage}`,\n );\n }\n }),\n );\n\n const accessToken = await this.getAccessToken();\n await pairIdentifiers(n.nonce, logins, accessToken, this.#env);\n }\n\n prepare(signer: {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n }): void {\n this.#assertSIWE(this.#type, this.#sdk);\n this.#sdk.prepare(signer);\n }\n\n #assertSIWE(\n type: AuthType,\n _sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts _sdk is SIWEJwtBearerAuth {\n if (type === AuthType.SiWE) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SIWE auth type',\n );\n }\n\n #assertSRP(\n type: AuthType,\n _sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts _sdk is SRPJwtBearerAuth {\n if (type === AuthType.SRP) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SRP auth type',\n );\n }\n}\n\nexport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe.js';\nexport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp.js';\nexport * from './authentication-jwt-bearer/types.js';\n"]}
|
package/dist/sdk/constants.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;IAC5B,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;IAC5B,QAAQ;IACR,oBAAoB;IACpB,iBAAiB;CAClB,CAAC"}
|
package/dist/sdk/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,GAAG;IACb,oBAAoB,EAAE,GAAG;IACzB,iBAAiB,EAAE,GAAG;CACvB,CAAC","sourcesContent":["export const HTTP_STATUS_CODES = {\n CONFLICT: 409,\n UNPROCESSABLE_ENTITY: 422,\n TOO_MANY_REQUESTS: 429,\n};\n"]}
|
package/dist/sdk/errors.d.ts
CHANGED
|
@@ -1,93 +1,3 @@
|
|
|
1
|
-
import type { MfaErrorCode } from './authentication-jwt-bearer/mfa/types.js';
|
|
2
|
-
type ExtensibleMfaErrorCode = MfaErrorCode | (string & {});
|
|
3
|
-
/**
|
|
4
|
-
* Base error for MFA operations.
|
|
5
|
-
*
|
|
6
|
-
* The machine-readable code is an enumerable own property so it survives
|
|
7
|
-
* JSON-RPC error serialization.
|
|
8
|
-
*/
|
|
9
|
-
export declare class MfaError extends Error {
|
|
10
|
-
readonly mfaCode: ExtensibleMfaErrorCode;
|
|
11
|
-
readonly status?: number;
|
|
12
|
-
readonly retryAfterMs?: number;
|
|
13
|
-
constructor(mfaCode: ExtensibleMfaErrorCode, message: string, options?: {
|
|
14
|
-
status?: number;
|
|
15
|
-
retryAfterMs?: number;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
export declare class CredentialAlreadyEnrolledError extends MfaError {
|
|
19
|
-
constructor(code: 'credential_already_enrolled' | 'email_already_enrolled', message: string, status?: number);
|
|
20
|
-
}
|
|
21
|
-
export declare class CredentialNotEnrolledError extends MfaError {
|
|
22
|
-
constructor(message: string, status?: number);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* The begin/complete flow is stale or unknown; the client must restart it.
|
|
26
|
-
*/
|
|
27
|
-
export declare class MfaFlowExpiredError extends MfaError {
|
|
28
|
-
constructor(code: 'flow_expired' | 'invalid_flow', message: string, status?: number);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* The profile has no identity-provider record yet. Not a stale flow: the
|
|
32
|
-
* user must enroll a first credential before verifying.
|
|
33
|
-
*/
|
|
34
|
-
export declare class MfaIdentityMissingError extends MfaError {
|
|
35
|
-
constructor(message: string, status?: number);
|
|
36
|
-
}
|
|
37
|
-
export declare class MfaVerificationFailedError extends MfaError {
|
|
38
|
-
constructor(code: 'invalid_code' | 'invalid_attestation' | 'invalid_assertion', message: string, status?: number);
|
|
39
|
-
}
|
|
40
|
-
export declare class TooManyAttemptsError extends MfaError {
|
|
41
|
-
constructor(message: string, status?: number);
|
|
42
|
-
}
|
|
43
|
-
export declare class MaxPasskeysReachedError extends MfaError {
|
|
44
|
-
constructor(message: string, status?: number);
|
|
45
|
-
}
|
|
46
|
-
export declare class MaxIdentifiersReachedError extends MfaError {
|
|
47
|
-
constructor(message: string, status?: number);
|
|
48
|
-
}
|
|
49
|
-
export declare class OtpResendCooldownError extends MfaError {
|
|
50
|
-
constructor(message: string, retryAfterMs?: number, status?: number);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* A 429 without an MFA-specific code: generic throttling, not an OTP resend
|
|
54
|
-
* cooldown.
|
|
55
|
-
*/
|
|
56
|
-
export declare class MfaRateLimitedError extends MfaError {
|
|
57
|
-
constructor(message: string, retryAfterMs?: number, status?: number);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* The identity provider or the network is unreachable. Safe to retry.
|
|
61
|
-
* `status` is only set when the service answered.
|
|
62
|
-
*/
|
|
63
|
-
export declare class MfaUnavailableError extends MfaError {
|
|
64
|
-
constructor(message: string, status?: number);
|
|
65
|
-
}
|
|
66
|
-
export declare class ElevatedTokenInvalidError extends MfaError {
|
|
67
|
-
constructor(message: string);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Gets an MFA code from direct, serialized, or message-only errors.
|
|
71
|
-
*
|
|
72
|
-
* @param error - Value to inspect.
|
|
73
|
-
* @returns The stable code, if present.
|
|
74
|
-
*/
|
|
75
|
-
export declare function getMfaErrorCode(error: unknown): ExtensibleMfaErrorCode | undefined;
|
|
76
|
-
/**
|
|
77
|
-
* Checks whether a value carries an MFA error code.
|
|
78
|
-
*
|
|
79
|
-
* @param error - Value to inspect.
|
|
80
|
-
* @param codes - Optional codes to match.
|
|
81
|
-
* @returns Whether the value is an MFA error with a requested code.
|
|
82
|
-
*/
|
|
83
|
-
export declare function isMfaError(error: unknown, ...codes: ExtensibleMfaErrorCode[]): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Gets a retry delay from direct or serialized MFA errors.
|
|
86
|
-
*
|
|
87
|
-
* @param error - Value to inspect.
|
|
88
|
-
* @returns Retry delay in milliseconds, if present.
|
|
89
|
-
*/
|
|
90
|
-
export declare function getMfaRetryAfterMs(error: unknown): number | undefined;
|
|
91
1
|
export declare class NonceRetrievalError extends Error {
|
|
92
2
|
constructor(message: string);
|
|
93
3
|
}
|
|
@@ -139,5 +49,4 @@ export declare class RateLimitedError extends Error {
|
|
|
139
49
|
*/
|
|
140
50
|
static isRateLimitError(e: unknown): e is RateLimitedError;
|
|
141
51
|
}
|
|
142
|
-
export {};
|
|
143
52
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/sdk/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sdk/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sdk/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,QAAQ,CAAC,MAAM,SAA8B;IAE7C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,MAAM,SAA0C;IAEzD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,MAAM,SAAuC;IAEtD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B,YAAY,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAIjD;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,gBAAgB,CAQzD;CACF"}
|