@metamask-previews/profile-sync-controller 32.1.1-preview-2731bd7 → 32.1.1-preview-f67925e6c
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/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 -165
- package/dist/sdk/errors.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/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 -269
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.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/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/CHANGELOG.md
CHANGED
|
@@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
-
- Add validated MFA domain types and structured `MfaError` classes with a serialization-safe `mfaCode` ([#10264](https://github.com/MetaMask/core/pull/10264))
|
|
13
12
|
- Add `rampsOrders` to `USER_STORAGE_FEATURE_NAMES` ([#10227](https://github.com/MetaMask/core/pull/10227))
|
|
14
13
|
|
|
15
14
|
## [32.1.1]
|
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"}
|
package/dist/sdk/errors.js
CHANGED
|
@@ -1,169 +1,4 @@
|
|
|
1
1
|
import { HTTP_STATUS_CODES } from './constants.js';
|
|
2
|
-
function asRecord(value) {
|
|
3
|
-
return typeof value === 'object' && value !== null
|
|
4
|
-
? value
|
|
5
|
-
: undefined;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Base error for MFA operations.
|
|
9
|
-
*
|
|
10
|
-
* The machine-readable code is an enumerable own property so it survives
|
|
11
|
-
* JSON-RPC error serialization.
|
|
12
|
-
*/
|
|
13
|
-
export class MfaError extends Error {
|
|
14
|
-
mfaCode;
|
|
15
|
-
status;
|
|
16
|
-
retryAfterMs;
|
|
17
|
-
constructor(mfaCode, message, options) {
|
|
18
|
-
super(`MFA[${mfaCode}]: ${message}`);
|
|
19
|
-
this.name = 'MfaError';
|
|
20
|
-
this.mfaCode = mfaCode;
|
|
21
|
-
this.status = options?.status;
|
|
22
|
-
this.retryAfterMs = options?.retryAfterMs;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export class CredentialAlreadyEnrolledError extends MfaError {
|
|
26
|
-
constructor(code, message, status = HTTP_STATUS_CODES.CONFLICT) {
|
|
27
|
-
super(code, message, { status });
|
|
28
|
-
this.name = 'CredentialAlreadyEnrolledError';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export class CredentialNotEnrolledError extends MfaError {
|
|
32
|
-
constructor(message, status = HTTP_STATUS_CODES.CONFLICT) {
|
|
33
|
-
super('credential_not_enrolled', message, { status });
|
|
34
|
-
this.name = 'CredentialNotEnrolledError';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* The begin/complete flow is stale or unknown; the client must restart it.
|
|
39
|
-
*/
|
|
40
|
-
export class MfaFlowExpiredError extends MfaError {
|
|
41
|
-
constructor(code, message, status) {
|
|
42
|
-
super(code, message, { status });
|
|
43
|
-
this.name = 'MfaFlowExpiredError';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The profile has no identity-provider record yet. Not a stale flow: the
|
|
48
|
-
* user must enroll a first credential before verifying.
|
|
49
|
-
*/
|
|
50
|
-
export class MfaIdentityMissingError extends MfaError {
|
|
51
|
-
constructor(message, status = HTTP_STATUS_CODES.CONFLICT) {
|
|
52
|
-
super('mfa_identity_missing', message, { status });
|
|
53
|
-
this.name = 'MfaIdentityMissingError';
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export class MfaVerificationFailedError extends MfaError {
|
|
57
|
-
constructor(code, message, status) {
|
|
58
|
-
super(code, message, { status });
|
|
59
|
-
this.name = 'MfaVerificationFailedError';
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export class TooManyAttemptsError extends MfaError {
|
|
63
|
-
constructor(message, status) {
|
|
64
|
-
super('too_many_attempts', message, { status });
|
|
65
|
-
this.name = 'TooManyAttemptsError';
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export class MaxPasskeysReachedError extends MfaError {
|
|
69
|
-
constructor(message, status = HTTP_STATUS_CODES.UNPROCESSABLE_ENTITY) {
|
|
70
|
-
super('max_passkeys_reached', message, { status });
|
|
71
|
-
this.name = 'MaxPasskeysReachedError';
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export class MaxIdentifiersReachedError extends MfaError {
|
|
75
|
-
constructor(message, status = HTTP_STATUS_CODES.CONFLICT) {
|
|
76
|
-
super('max_identifiers_reached', message, { status });
|
|
77
|
-
this.name = 'MaxIdentifiersReachedError';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export class OtpResendCooldownError extends MfaError {
|
|
81
|
-
constructor(message, retryAfterMs, status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS) {
|
|
82
|
-
super('otp_resend_cooldown', message, { status, retryAfterMs });
|
|
83
|
-
this.name = 'OtpResendCooldownError';
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* A 429 without an MFA-specific code: generic throttling, not an OTP resend
|
|
88
|
-
* cooldown.
|
|
89
|
-
*/
|
|
90
|
-
export class MfaRateLimitedError extends MfaError {
|
|
91
|
-
constructor(message, retryAfterMs, status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS) {
|
|
92
|
-
super('rate_limited', message, { status, retryAfterMs });
|
|
93
|
-
this.name = 'MfaRateLimitedError';
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* The identity provider or the network is unreachable. Safe to retry.
|
|
98
|
-
* `status` is only set when the service answered.
|
|
99
|
-
*/
|
|
100
|
-
export class MfaUnavailableError extends MfaError {
|
|
101
|
-
constructor(message, status) {
|
|
102
|
-
super('kratos_unavailable', message, { status });
|
|
103
|
-
this.name = 'MfaUnavailableError';
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
export class ElevatedTokenInvalidError extends MfaError {
|
|
107
|
-
constructor(message) {
|
|
108
|
-
super('elevated_token_invalid', message);
|
|
109
|
-
this.name = 'ElevatedTokenInvalidError';
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Gets an MFA code from direct, serialized, or message-only errors.
|
|
114
|
-
*
|
|
115
|
-
* @param error - Value to inspect.
|
|
116
|
-
* @returns The stable code, if present.
|
|
117
|
-
*/
|
|
118
|
-
export function getMfaErrorCode(error) {
|
|
119
|
-
const direct = asRecord(error);
|
|
120
|
-
if (typeof direct?.mfaCode === 'string') {
|
|
121
|
-
return direct.mfaCode;
|
|
122
|
-
}
|
|
123
|
-
const data = asRecord(direct?.data);
|
|
124
|
-
const cause = asRecord(data?.cause);
|
|
125
|
-
if (typeof cause?.mfaCode === 'string') {
|
|
126
|
-
return cause.mfaCode;
|
|
127
|
-
}
|
|
128
|
-
const messages = [direct?.message, cause?.message];
|
|
129
|
-
for (const message of messages) {
|
|
130
|
-
if (typeof message === 'string') {
|
|
131
|
-
const match = /^MFA\[([^\]]+)\]:/u.exec(message);
|
|
132
|
-
if (match?.[1]) {
|
|
133
|
-
return match[1];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Checks whether a value carries an MFA error code.
|
|
141
|
-
*
|
|
142
|
-
* @param error - Value to inspect.
|
|
143
|
-
* @param codes - Optional codes to match.
|
|
144
|
-
* @returns Whether the value is an MFA error with a requested code.
|
|
145
|
-
*/
|
|
146
|
-
export function isMfaError(error, ...codes) {
|
|
147
|
-
const code = getMfaErrorCode(error);
|
|
148
|
-
return code !== undefined && (codes.length === 0 || codes.includes(code));
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Gets a retry delay from direct or serialized MFA errors.
|
|
152
|
-
*
|
|
153
|
-
* @param error - Value to inspect.
|
|
154
|
-
* @returns Retry delay in milliseconds, if present.
|
|
155
|
-
*/
|
|
156
|
-
export function getMfaRetryAfterMs(error) {
|
|
157
|
-
const direct = asRecord(error);
|
|
158
|
-
if (typeof direct?.retryAfterMs === 'number') {
|
|
159
|
-
return direct.retryAfterMs;
|
|
160
|
-
}
|
|
161
|
-
const data = asRecord(direct?.data);
|
|
162
|
-
const cause = asRecord(data?.cause);
|
|
163
|
-
return typeof cause?.retryAfterMs === 'number'
|
|
164
|
-
? cause.retryAfterMs
|
|
165
|
-
: undefined;
|
|
166
|
-
}
|
|
167
2
|
export class NonceRetrievalError extends Error {
|
|
168
3
|
constructor(message) {
|
|
169
4
|
super(message);
|
package/dist/sdk/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/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B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,MAAM,GAAG,iBAAiB,CAAC,iBAAiB,CAAC;IAE7C,YAAY,CAAU;IAE/B,YAAY,OAAe,EAAE,YAAqB;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAU;QAChC,OAAO,CACL,CAAC,YAAY,gBAAgB;YAC7B,CAAC,OAAO,CAAC,KAAK,QAAQ;gBACpB,CAAC,KAAK,IAAI;gBACV,QAAQ,IAAI,CAAC;gBACb,CAAC,CAAC,MAAM,KAAK,iBAAiB,CAAC,iBAAiB,CAAC,CACpD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { MfaErrorCode } from './authentication-jwt-bearer/mfa/types.js';\nimport { HTTP_STATUS_CODES } from './constants.js';\n\ntype ExtensibleMfaErrorCode = MfaErrorCode | (string & {});\n\ntype ErrorRecord = Record<string, unknown>;\n\nfunction asRecord(value: unknown): ErrorRecord | undefined {\n return typeof value === 'object' && value !== null\n ? (value as ErrorRecord)\n : undefined;\n}\n\n/**\n * Base error for MFA operations.\n *\n * The machine-readable code is an enumerable own property so it survives\n * JSON-RPC error serialization.\n */\nexport class MfaError extends Error {\n readonly mfaCode: ExtensibleMfaErrorCode;\n\n readonly status?: number;\n\n readonly retryAfterMs?: number;\n\n constructor(\n mfaCode: ExtensibleMfaErrorCode,\n message: string,\n options?: { status?: number; retryAfterMs?: number },\n ) {\n super(`MFA[${mfaCode}]: ${message}`);\n this.name = 'MfaError';\n this.mfaCode = mfaCode;\n this.status = options?.status;\n this.retryAfterMs = options?.retryAfterMs;\n }\n}\n\nexport class CredentialAlreadyEnrolledError extends MfaError {\n constructor(\n code: 'credential_already_enrolled' | 'email_already_enrolled',\n message: string,\n status = HTTP_STATUS_CODES.CONFLICT,\n ) {\n super(code, message, { status });\n this.name = 'CredentialAlreadyEnrolledError';\n }\n}\n\nexport class CredentialNotEnrolledError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('credential_not_enrolled', message, { status });\n this.name = 'CredentialNotEnrolledError';\n }\n}\n\n/**\n * The begin/complete flow is stale or unknown; the client must restart it.\n */\nexport class MfaFlowExpiredError extends MfaError {\n constructor(\n code: 'flow_expired' | 'invalid_flow',\n message: string,\n status?: number,\n ) {\n super(code, message, { status });\n this.name = 'MfaFlowExpiredError';\n }\n}\n\n/**\n * The profile has no identity-provider record yet. Not a stale flow: the\n * user must enroll a first credential before verifying.\n */\nexport class MfaIdentityMissingError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('mfa_identity_missing', message, { status });\n this.name = 'MfaIdentityMissingError';\n }\n}\n\nexport class MfaVerificationFailedError extends MfaError {\n constructor(\n code: 'invalid_code' | 'invalid_attestation' | 'invalid_assertion',\n message: string,\n status?: number,\n ) {\n super(code, message, { status });\n this.name = 'MfaVerificationFailedError';\n }\n}\n\nexport class TooManyAttemptsError extends MfaError {\n constructor(message: string, status?: number) {\n super('too_many_attempts', message, { status });\n this.name = 'TooManyAttemptsError';\n }\n}\n\nexport class MaxPasskeysReachedError extends MfaError {\n constructor(\n message: string,\n status = HTTP_STATUS_CODES.UNPROCESSABLE_ENTITY,\n ) {\n super('max_passkeys_reached', message, { status });\n this.name = 'MaxPasskeysReachedError';\n }\n}\n\nexport class MaxIdentifiersReachedError extends MfaError {\n constructor(message: string, status = HTTP_STATUS_CODES.CONFLICT) {\n super('max_identifiers_reached', message, { status });\n this.name = 'MaxIdentifiersReachedError';\n }\n}\n\nexport class OtpResendCooldownError extends MfaError {\n constructor(\n message: string,\n retryAfterMs?: number,\n status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS,\n ) {\n super('otp_resend_cooldown', message, { status, retryAfterMs });\n this.name = 'OtpResendCooldownError';\n }\n}\n\n/**\n * A 429 without an MFA-specific code: generic throttling, not an OTP resend\n * cooldown.\n */\nexport class MfaRateLimitedError extends MfaError {\n constructor(\n message: string,\n retryAfterMs?: number,\n status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS,\n ) {\n super('rate_limited', message, { status, retryAfterMs });\n this.name = 'MfaRateLimitedError';\n }\n}\n\n/**\n * The identity provider or the network is unreachable. Safe to retry.\n * `status` is only set when the service answered.\n */\nexport class MfaUnavailableError extends MfaError {\n constructor(message: string, status?: number) {\n super('kratos_unavailable', message, { status });\n this.name = 'MfaUnavailableError';\n }\n}\n\nexport class ElevatedTokenInvalidError extends MfaError {\n constructor(message: string) {\n super('elevated_token_invalid', message);\n this.name = 'ElevatedTokenInvalidError';\n }\n}\n\n/**\n * Gets an MFA code from direct, serialized, or message-only errors.\n *\n * @param error - Value to inspect.\n * @returns The stable code, if present.\n */\nexport function getMfaErrorCode(\n error: unknown,\n): ExtensibleMfaErrorCode | undefined {\n const direct = asRecord(error);\n if (typeof direct?.mfaCode === 'string') {\n return direct.mfaCode;\n }\n\n const data = asRecord(direct?.data);\n const cause = asRecord(data?.cause);\n if (typeof cause?.mfaCode === 'string') {\n return cause.mfaCode;\n }\n\n const messages = [direct?.message, cause?.message];\n for (const message of messages) {\n if (typeof message === 'string') {\n const match = /^MFA\\[([^\\]]+)\\]:/u.exec(message);\n if (match?.[1]) {\n return match[1];\n }\n }\n }\n return undefined;\n}\n\n/**\n * Checks whether a value carries an MFA error code.\n *\n * @param error - Value to inspect.\n * @param codes - Optional codes to match.\n * @returns Whether the value is an MFA error with a requested code.\n */\nexport function isMfaError(\n error: unknown,\n ...codes: ExtensibleMfaErrorCode[]\n): boolean {\n const code = getMfaErrorCode(error);\n return code !== undefined && (codes.length === 0 || codes.includes(code));\n}\n\n/**\n * Gets a retry delay from direct or serialized MFA errors.\n *\n * @param error - Value to inspect.\n * @returns Retry delay in milliseconds, if present.\n */\nexport function getMfaRetryAfterMs(error: unknown): number | undefined {\n const direct = asRecord(error);\n if (typeof direct?.retryAfterMs === 'number') {\n return direct.retryAfterMs;\n }\n const data = asRecord(direct?.data);\n const cause = asRecord(data?.cause);\n return typeof cause?.retryAfterMs === 'number'\n ? cause.retryAfterMs\n : undefined;\n}\n\nexport class NonceRetrievalError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NonceRetrievalError';\n }\n}\n\nexport class SignInError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SignInError';\n }\n}\n\nexport class PairError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PairError';\n }\n}\n\n/**\n * Thrown when `POST /api/v2/profile/pair/identifier` returns 409 Conflict:\n * the social identifier already belongs to another canonical profile.\n * Retrying the same request cannot succeed.\n */\nexport class PairConflictError extends PairError {\n readonly status = HTTP_STATUS_CODES.CONFLICT;\n\n constructor(message: string) {\n super(message);\n this.name = 'PairConflictError';\n }\n}\n\n/**\n * Thrown when `POST /api/v2/oidc/token` returns 422: this profile has no\n * verified email on record. Consumers should send the user through email\n * OTP (or Google pair) and retry.\n */\nexport class EmailRequiredError extends Error {\n readonly status = HTTP_STATUS_CODES.UNPROCESSABLE_ENTITY;\n\n constructor(message: string) {\n super(message);\n this.name = 'EmailRequiredError';\n }\n}\n\nexport class UserStorageError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UserStorageError';\n }\n}\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n\nexport class UnsupportedAuthTypeError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UnsupportedAuthTypeError';\n }\n}\n\nexport class NotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NotFoundError';\n }\n}\n\nexport class RateLimitedError extends Error {\n readonly status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS;\n\n readonly retryAfterMs?: number;\n\n constructor(message: string, retryAfterMs?: number) {\n super(message);\n this.name = 'RateLimitedError';\n this.retryAfterMs = retryAfterMs;\n }\n\n /**\n * Check if an unknown error is a rate limit error (429 status).\n *\n * @param e - The error to check\n * @returns True if the error is a rate limit error\n */\n static isRateLimitError(e: unknown): e is RateLimitedError {\n return (\n e instanceof RateLimitedError ||\n (typeof e === 'object' &&\n e !== null &&\n 'status' in e &&\n e.status === HTTP_STATUS_CODES.TOO_MANY_REQUESTS)\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sdk/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OA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IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAU;QAChC,OAAO,CACL,CAAC,YAAY,gBAAgB;YAC7B,CAAC,OAAO,CAAC,KAAK,QAAQ;gBACpB,CAAC,KAAK,IAAI;gBACV,QAAQ,IAAI,CAAC;gBACb,CAAC,CAAC,MAAM,KAAK,iBAAiB,CAAC,iBAAiB,CAAC,CACpD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { HTTP_STATUS_CODES } from './constants.js';\n\nexport class NonceRetrievalError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NonceRetrievalError';\n }\n}\n\nexport class SignInError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SignInError';\n }\n}\n\nexport class PairError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PairError';\n }\n}\n\n/**\n * Thrown when `POST /api/v2/profile/pair/identifier` returns 409 Conflict:\n * the social identifier already belongs to another canonical profile.\n * Retrying the same request cannot succeed.\n */\nexport class PairConflictError extends PairError {\n readonly status = HTTP_STATUS_CODES.CONFLICT;\n\n constructor(message: string) {\n super(message);\n this.name = 'PairConflictError';\n }\n}\n\n/**\n * Thrown when `POST /api/v2/oidc/token` returns 422: this profile has no\n * verified email on record. Consumers should send the user through email\n * OTP (or Google pair) and retry.\n */\nexport class EmailRequiredError extends Error {\n readonly status = HTTP_STATUS_CODES.UNPROCESSABLE_ENTITY;\n\n constructor(message: string) {\n super(message);\n this.name = 'EmailRequiredError';\n }\n}\n\nexport class UserStorageError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UserStorageError';\n }\n}\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n\nexport class UnsupportedAuthTypeError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UnsupportedAuthTypeError';\n }\n}\n\nexport class NotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NotFoundError';\n }\n}\n\nexport class RateLimitedError extends Error {\n readonly status = HTTP_STATUS_CODES.TOO_MANY_REQUESTS;\n\n readonly retryAfterMs?: number;\n\n constructor(message: string, retryAfterMs?: number) {\n super(message);\n this.name = 'RateLimitedError';\n this.retryAfterMs = retryAfterMs;\n }\n\n /**\n * Check if an unknown error is a rate limit error (429 status).\n *\n * @param e - The error to check\n * @returns True if the error is a rate limit error\n */\n static isRateLimitError(e: unknown): e is RateLimitedError {\n return (\n e instanceof RateLimitedError ||\n (typeof e === 'object' &&\n e !== null &&\n 'status' in e &&\n e.status === HTTP_STATUS_CODES.TOO_MANY_REQUESTS)\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-login-response.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"validate-login-response.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAgB5E"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { decodeJwtPayload } from './jwt.js';
|
|
2
1
|
/**
|
|
3
2
|
* Validates that the input is a well-formed, non-expired LoginResponse.
|
|
4
3
|
*
|
|
@@ -31,10 +30,13 @@ export function validateLoginResponse(input) {
|
|
|
31
30
|
*/
|
|
32
31
|
function isJwtExpired(token) {
|
|
33
32
|
try {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const parts = token.split('.');
|
|
34
|
+
if (parts.length !== 3) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const base64 = parts[1].replace(/-/gu, '+').replace(/_/gu, '/');
|
|
38
|
+
const { exp } = JSON.parse(atob(base64));
|
|
39
|
+
return !Number.isInteger(exp) || exp * 1000 <= Date.now();
|
|
38
40
|
}
|
|
39
41
|
catch {
|
|
40
42
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-login-response.js","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-login-response.js","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,MAAM,YAAY,GAAG,KAAsB,CAAC;IAE5C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;QACjD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { LoginResponse } from '../authentication.js';\n\n/**\n * Validates that the input is a well-formed, non-expired LoginResponse.\n *\n * Checks structural shape (token + profile objects exist) and verifies\n * the JWT access token's `exp` claim is still in the future. This acts\n * as a hard guard against stale cached tokens regardless of client-side\n * TTL tracking (obtainedAt / expiresIn), which can be corrupted.\n *\n * @param input - unknown/untyped input\n * @returns boolean if input is a valid, non-expired LoginResponse\n */\nexport function validateLoginResponse(input: unknown): input is LoginResponse {\n const assumedInput = input as LoginResponse;\n\n if (!assumedInput) {\n return false;\n }\n\n if (!assumedInput?.token || !assumedInput?.profile) {\n return false;\n }\n\n if (isJwtExpired(assumedInput.token.accessToken)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Checks whether a JWT has expired by decoding its `exp` claim.\n *\n * @param token - A JWT string.\n * @returns true if the token is expired or cannot be decoded; false if still valid.\n */\nfunction isJwtExpired(token: string): boolean {\n try {\n const parts = token.split('.');\n if (parts.length !== 3) {\n return true;\n }\n const base64 = parts[1].replace(/-/gu, '+').replace(/_/gu, '/');\n const { exp } = JSON.parse(atob(base64));\n return !Number.isInteger(exp) || exp * 1000 <= Date.now();\n } catch {\n return true;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/profile-sync-controller",
|
|
3
|
-
"version": "32.1.1-preview-
|
|
3
|
+
"version": "32.1.1-preview-f67925e6c",
|
|
4
4
|
"description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -79,7 +79,6 @@
|
|
|
79
79
|
"@metamask/keyring-controller": "^28.0.0",
|
|
80
80
|
"@metamask/messenger": "^3.0.0",
|
|
81
81
|
"@metamask/seedless-onboarding-controller": "^11.0.0",
|
|
82
|
-
"@metamask/superstruct": "^3.4.1",
|
|
83
82
|
"@metamask/utils": "^12.0.0",
|
|
84
83
|
"@noble/ciphers": "^1.3.0",
|
|
85
84
|
"@noble/curves": "^1.9.2",
|
|
@@ -96,7 +95,6 @@
|
|
|
96
95
|
"@metamask/keyring-api": "^24.0.0",
|
|
97
96
|
"@metamask/keyring-internal-api": "^12.0.0",
|
|
98
97
|
"@metamask/providers": "^22.1.0",
|
|
99
|
-
"@metamask/rpc-errors": "^7.0.2",
|
|
100
98
|
"@types/jest": "^30.0.0",
|
|
101
99
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
102
100
|
"deepmerge": "^4.2.2",
|