@metamask-previews/profile-sync-controller 32.1.1-preview-d43f7b9f4 → 32.1.1-preview-2731bd7
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 +1 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.d.ts +691 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.d.ts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.js +269 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/schemas.js.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/types.d.ts +125 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/types.d.ts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/types.js +3 -0
- package/dist/sdk/authentication-jwt-bearer/mfa/types.js.map +1 -0
- package/dist/sdk/constants.d.ts +2 -0
- package/dist/sdk/constants.d.ts.map +1 -1
- package/dist/sdk/constants.js +2 -0
- package/dist/sdk/constants.js.map +1 -1
- package/dist/sdk/errors.d.ts +91 -0
- package/dist/sdk/errors.d.ts.map +1 -1
- package/dist/sdk/errors.js +165 -0
- package/dist/sdk/errors.js.map +1 -1
- package/dist/sdk/utils/jwt.d.ts +13 -0
- package/dist/sdk/utils/jwt.d.ts.map +1 -0
- package/dist/sdk/utils/jwt.js +21 -0
- package/dist/sdk/utils/jwt.js.map +1 -0
- package/dist/sdk/utils/validate-login-response.d.ts.map +1 -1
- package/dist/sdk/utils/validate-login-response.js +5 -7
- package/dist/sdk/utils/validate-login-response.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { array, assert, boolean, enums, integer, literal, min, nullable, object, optional, pattern, refine, size, string, StructError, type, union, } from '@metamask/superstruct';
|
|
2
|
+
import { ElevatedTokenInvalidError, MfaError } from '../../errors.js';
|
|
3
|
+
export const MFA_CREDENTIAL_TYPES = ['passkey', 'email_otp'];
|
|
4
|
+
export const MfaCredentialTypeStruct = enums(MFA_CREDENTIAL_TYPES);
|
|
5
|
+
const CredentialDescriptorStruct = type({
|
|
6
|
+
type: literal('public-key'),
|
|
7
|
+
id: string(),
|
|
8
|
+
transports: optional(array(string())),
|
|
9
|
+
});
|
|
10
|
+
const ExtensionsStruct = type({});
|
|
11
|
+
export const PublicKeyCredentialCreationOptionsJSONStruct = type({
|
|
12
|
+
rp: type({
|
|
13
|
+
id: string(),
|
|
14
|
+
name: string(),
|
|
15
|
+
}),
|
|
16
|
+
user: type({
|
|
17
|
+
id: string(),
|
|
18
|
+
name: string(),
|
|
19
|
+
displayName: string(),
|
|
20
|
+
}),
|
|
21
|
+
challenge: string(),
|
|
22
|
+
pubKeyCredParams: array(type({
|
|
23
|
+
type: literal('public-key'),
|
|
24
|
+
alg: integer(),
|
|
25
|
+
})),
|
|
26
|
+
excludeCredentials: optional(array(CredentialDescriptorStruct)),
|
|
27
|
+
authenticatorSelection: optional(type({
|
|
28
|
+
authenticatorAttachment: optional(string()),
|
|
29
|
+
residentKey: optional(string()),
|
|
30
|
+
requireResidentKey: optional(boolean()),
|
|
31
|
+
userVerification: optional(string()),
|
|
32
|
+
})),
|
|
33
|
+
attestation: optional(string()),
|
|
34
|
+
timeout: optional(integer()),
|
|
35
|
+
extensions: optional(ExtensionsStruct),
|
|
36
|
+
});
|
|
37
|
+
export const PublicKeyCredentialRequestOptionsJSONStruct = type({
|
|
38
|
+
challenge: string(),
|
|
39
|
+
rpId: optional(string()),
|
|
40
|
+
allowCredentials: optional(array(CredentialDescriptorStruct)),
|
|
41
|
+
userVerification: optional(string()),
|
|
42
|
+
timeout: optional(integer()),
|
|
43
|
+
extensions: optional(ExtensionsStruct),
|
|
44
|
+
});
|
|
45
|
+
export const PasskeyCreateDataStruct = type({
|
|
46
|
+
publicKey: PublicKeyCredentialCreationOptionsJSONStruct,
|
|
47
|
+
});
|
|
48
|
+
export const PasskeyRequestDataStruct = type({
|
|
49
|
+
publicKey: PublicKeyCredentialRequestOptionsJSONStruct,
|
|
50
|
+
});
|
|
51
|
+
export const RegistrationResponseJSONStruct = type({
|
|
52
|
+
id: string(),
|
|
53
|
+
rawId: string(),
|
|
54
|
+
type: literal('public-key'),
|
|
55
|
+
response: type({
|
|
56
|
+
attestationObject: string(),
|
|
57
|
+
clientDataJSON: string(),
|
|
58
|
+
transports: optional(array(string())),
|
|
59
|
+
publicKeyAlgorithm: optional(integer()),
|
|
60
|
+
publicKey: optional(string()),
|
|
61
|
+
authenticatorData: optional(string()),
|
|
62
|
+
}),
|
|
63
|
+
authenticatorAttachment: optional(nullable(string())),
|
|
64
|
+
clientExtensionResults: optional(ExtensionsStruct),
|
|
65
|
+
});
|
|
66
|
+
export const AuthenticationResponseJSONStruct = type({
|
|
67
|
+
id: string(),
|
|
68
|
+
rawId: string(),
|
|
69
|
+
type: literal('public-key'),
|
|
70
|
+
response: type({
|
|
71
|
+
authenticatorData: string(),
|
|
72
|
+
clientDataJSON: string(),
|
|
73
|
+
signature: string(),
|
|
74
|
+
userHandle: optional(nullable(string())),
|
|
75
|
+
}),
|
|
76
|
+
authenticatorAttachment: optional(nullable(string())),
|
|
77
|
+
clientExtensionResults: optional(ExtensionsStruct),
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Only the assertion JWT is consumed from the verification response; the
|
|
81
|
+
* profile fields on the wire duplicate what the login flow already resolved.
|
|
82
|
+
*/
|
|
83
|
+
export const MfaVerifyCompleteResponseStruct = type({
|
|
84
|
+
token: string(),
|
|
85
|
+
expires_in: integer(),
|
|
86
|
+
});
|
|
87
|
+
export const MfaEnrollResponseStruct = type({
|
|
88
|
+
flow_id: string(),
|
|
89
|
+
expires_at: string(),
|
|
90
|
+
passkey_create_data: optional(string()),
|
|
91
|
+
});
|
|
92
|
+
export const MfaEnrollCompleteResponseStruct = type({
|
|
93
|
+
status: literal('enrolled'),
|
|
94
|
+
});
|
|
95
|
+
export const MfaVerifyResponseStruct = type({
|
|
96
|
+
flow_id: string(),
|
|
97
|
+
expires_at: string(),
|
|
98
|
+
passkey_request_data: optional(string()),
|
|
99
|
+
});
|
|
100
|
+
export const MfaPasskeyDetailStruct = type({
|
|
101
|
+
display_name: optional(string()),
|
|
102
|
+
added_at: optional(string()),
|
|
103
|
+
});
|
|
104
|
+
export const MfaEmailDetailStruct = type({
|
|
105
|
+
address: optional(string()),
|
|
106
|
+
verified: optional(boolean()),
|
|
107
|
+
});
|
|
108
|
+
export const MfaCredentialStruct = type({
|
|
109
|
+
// Intentionally accepts strings so future server credential types and
|
|
110
|
+
// statuses can be ignored without making the complete response invalid.
|
|
111
|
+
credential_type: string(),
|
|
112
|
+
status: string(),
|
|
113
|
+
enrolled_at: optional(string()),
|
|
114
|
+
passkey: optional(MfaPasskeyDetailStruct),
|
|
115
|
+
email: optional(MfaEmailDetailStruct),
|
|
116
|
+
});
|
|
117
|
+
export const MfaCredentialsResponseStruct = type({
|
|
118
|
+
credentials: array(MfaCredentialStruct),
|
|
119
|
+
});
|
|
120
|
+
export const MfaErrorResponseStruct = type({
|
|
121
|
+
code: optional(string()),
|
|
122
|
+
message: string(),
|
|
123
|
+
});
|
|
124
|
+
export const TokenReasonStruct = object({
|
|
125
|
+
operation: pattern(string(), /^[A-Za-z0-9_.:-]{1,64}$/u),
|
|
126
|
+
});
|
|
127
|
+
export const BeginEnrollmentRequestStruct = refine(object({
|
|
128
|
+
type: MfaCredentialTypeStruct,
|
|
129
|
+
email: optional(size(string(), 3, 254)),
|
|
130
|
+
reason: TokenReasonStruct,
|
|
131
|
+
}), 'BeginEnrollmentRequest', (value) => {
|
|
132
|
+
if (value.type === 'email_otp' && value.email === undefined) {
|
|
133
|
+
return 'email is required for email_otp enrollment';
|
|
134
|
+
}
|
|
135
|
+
if (value.type === 'passkey' && value.email !== undefined) {
|
|
136
|
+
return 'email is not accepted for passkey enrollment';
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
});
|
|
140
|
+
const EmailOtpCodeStruct = pattern(string(), /^\d{6}$/u);
|
|
141
|
+
const EnrollmentProofStruct = union([
|
|
142
|
+
object({
|
|
143
|
+
type: literal('passkey'),
|
|
144
|
+
attestation: RegistrationResponseJSONStruct,
|
|
145
|
+
}),
|
|
146
|
+
object({
|
|
147
|
+
type: literal('email_otp'),
|
|
148
|
+
code: EmailOtpCodeStruct,
|
|
149
|
+
}),
|
|
150
|
+
]);
|
|
151
|
+
export const CompleteEnrollmentRequestStruct = object({
|
|
152
|
+
flowId: string(),
|
|
153
|
+
proof: EnrollmentProofStruct,
|
|
154
|
+
reason: TokenReasonStruct,
|
|
155
|
+
});
|
|
156
|
+
export const BeginStepUpRequestStruct = object({
|
|
157
|
+
type: MfaCredentialTypeStruct,
|
|
158
|
+
reason: TokenReasonStruct,
|
|
159
|
+
});
|
|
160
|
+
const StepUpProofStruct = union([
|
|
161
|
+
object({
|
|
162
|
+
type: literal('passkey'),
|
|
163
|
+
assertion: AuthenticationResponseJSONStruct,
|
|
164
|
+
}),
|
|
165
|
+
object({
|
|
166
|
+
type: literal('email_otp'),
|
|
167
|
+
code: EmailOtpCodeStruct,
|
|
168
|
+
}),
|
|
169
|
+
]);
|
|
170
|
+
export const CompleteStepUpRequestStruct = object({
|
|
171
|
+
flowId: string(),
|
|
172
|
+
proof: StepUpProofStruct,
|
|
173
|
+
reason: TokenReasonStruct,
|
|
174
|
+
});
|
|
175
|
+
export const GetElevatedTokenRequestStruct = object({
|
|
176
|
+
maxSessionAgeMs: optional(min(integer(), 0)),
|
|
177
|
+
});
|
|
178
|
+
export const ElevatedTokenClaimsStruct = type({
|
|
179
|
+
sub: string(),
|
|
180
|
+
aal: literal(2),
|
|
181
|
+
exp: integer(),
|
|
182
|
+
amr: union([MfaCredentialTypeStruct, array(MfaCredentialTypeStruct)]),
|
|
183
|
+
});
|
|
184
|
+
function formatStructError(error) {
|
|
185
|
+
return error
|
|
186
|
+
.failures()
|
|
187
|
+
.map(({ path, message }) => `[${path.join('.')}] ${message}`)
|
|
188
|
+
.join(', ');
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Validates data received from the authentication service.
|
|
192
|
+
*
|
|
193
|
+
* @param value - Untrusted response data.
|
|
194
|
+
* @param struct - Expected response structure.
|
|
195
|
+
* @throws MfaError if the response does not match the structure.
|
|
196
|
+
*/
|
|
197
|
+
export function assertValidMfaResponse(value, struct) {
|
|
198
|
+
try {
|
|
199
|
+
assert(value, struct);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (error instanceof StructError) {
|
|
203
|
+
throw new MfaError('invalid_response', formatStructError(error));
|
|
204
|
+
}
|
|
205
|
+
/* istanbul ignore next */
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Validates data received from an untyped controller boundary.
|
|
211
|
+
*
|
|
212
|
+
* @param value - Untrusted request data.
|
|
213
|
+
* @param struct - Expected request structure.
|
|
214
|
+
* @throws MfaError if the request does not match the structure.
|
|
215
|
+
*/
|
|
216
|
+
export function assertValidMfaRequest(value, struct) {
|
|
217
|
+
try {
|
|
218
|
+
assert(value, struct);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (error instanceof StructError) {
|
|
222
|
+
throw new MfaError('invalid_request', formatStructError(error));
|
|
223
|
+
}
|
|
224
|
+
/* istanbul ignore next */
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function asRecord(value) {
|
|
229
|
+
return typeof value === 'object' && value !== null
|
|
230
|
+
? value
|
|
231
|
+
: undefined;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Validates and normalizes claims from an elevated access token.
|
|
235
|
+
*
|
|
236
|
+
* Hydra places hook-supplied claims under `ext` unless they are promoted to
|
|
237
|
+
* the top level, so `aal` and `amr` are read from either location.
|
|
238
|
+
*
|
|
239
|
+
* @param payload - Decoded JWT payload.
|
|
240
|
+
* @returns Validated claims with `amr` represented as an array.
|
|
241
|
+
* @throws ElevatedTokenInvalidError if claims are missing or invalid.
|
|
242
|
+
*/
|
|
243
|
+
export function parseElevatedTokenClaims(payload) {
|
|
244
|
+
const record = asRecord(payload);
|
|
245
|
+
const ext = asRecord(record?.ext);
|
|
246
|
+
const value = {
|
|
247
|
+
sub: record?.sub,
|
|
248
|
+
exp: record?.exp,
|
|
249
|
+
aal: record?.aal ?? ext?.aal,
|
|
250
|
+
amr: record?.amr ?? ext?.amr,
|
|
251
|
+
};
|
|
252
|
+
try {
|
|
253
|
+
assert(value, ElevatedTokenClaimsStruct);
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
if (error instanceof StructError) {
|
|
257
|
+
throw new ElevatedTokenInvalidError(formatStructError(error));
|
|
258
|
+
}
|
|
259
|
+
/* istanbul ignore next */
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
sub: value.sub,
|
|
264
|
+
aal: value.aal,
|
|
265
|
+
exp: value.exp,
|
|
266
|
+
amr: Array.isArray(value.amr) ? value.amr : [value.amr],
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../../src/sdk/authentication-jwt-bearer/mfa/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,GAAG,EACH,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,OAAO,EACP,MAAM,EACN,IAAI,EACJ,MAAM,EACN,WAAW,EACX,IAAI,EACJ,KAAK,GACN,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,WAAW,CAAU,CAAC;AAEtE,MA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K,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC;KACxD,CAAC;AACJ,CAAC","sourcesContent":["import {\n array,\n assert,\n boolean,\n enums,\n integer,\n literal,\n min,\n nullable,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n StructError,\n type,\n union,\n} from '@metamask/superstruct';\nimport type { Struct } from '@metamask/superstruct';\n\nimport { ElevatedTokenInvalidError, MfaError } from '../../errors.js';\n\nexport const MFA_CREDENTIAL_TYPES = ['passkey', 'email_otp'] as const;\n\nexport const MfaCredentialTypeStruct = enums(MFA_CREDENTIAL_TYPES);\n\nconst CredentialDescriptorStruct = type({\n type: literal('public-key'),\n id: string(),\n transports: optional(array(string())),\n});\n\nconst ExtensionsStruct = type({});\n\nexport const PublicKeyCredentialCreationOptionsJSONStruct = type({\n rp: type({\n id: string(),\n name: string(),\n }),\n user: type({\n id: string(),\n name: string(),\n displayName: string(),\n }),\n challenge: string(),\n pubKeyCredParams: array(\n type({\n type: literal('public-key'),\n alg: integer(),\n }),\n ),\n excludeCredentials: optional(array(CredentialDescriptorStruct)),\n authenticatorSelection: optional(\n type({\n authenticatorAttachment: optional(string()),\n residentKey: optional(string()),\n requireResidentKey: optional(boolean()),\n userVerification: optional(string()),\n }),\n ),\n attestation: optional(string()),\n timeout: optional(integer()),\n extensions: optional(ExtensionsStruct),\n});\n\nexport const PublicKeyCredentialRequestOptionsJSONStruct = type({\n challenge: string(),\n rpId: optional(string()),\n allowCredentials: optional(array(CredentialDescriptorStruct)),\n userVerification: optional(string()),\n timeout: optional(integer()),\n extensions: optional(ExtensionsStruct),\n});\n\nexport const PasskeyCreateDataStruct = type({\n publicKey: PublicKeyCredentialCreationOptionsJSONStruct,\n});\n\nexport const PasskeyRequestDataStruct = type({\n publicKey: PublicKeyCredentialRequestOptionsJSONStruct,\n});\n\nexport const RegistrationResponseJSONStruct = type({\n id: string(),\n rawId: string(),\n type: literal('public-key'),\n response: type({\n attestationObject: string(),\n clientDataJSON: string(),\n transports: optional(array(string())),\n publicKeyAlgorithm: optional(integer()),\n publicKey: optional(string()),\n authenticatorData: optional(string()),\n }),\n authenticatorAttachment: optional(nullable(string())),\n clientExtensionResults: optional(ExtensionsStruct),\n});\n\nexport const AuthenticationResponseJSONStruct = type({\n id: string(),\n rawId: string(),\n type: literal('public-key'),\n response: type({\n authenticatorData: string(),\n clientDataJSON: string(),\n signature: string(),\n userHandle: optional(nullable(string())),\n }),\n authenticatorAttachment: optional(nullable(string())),\n clientExtensionResults: optional(ExtensionsStruct),\n});\n\n/**\n * Only the assertion JWT is consumed from the verification response; the\n * profile fields on the wire duplicate what the login flow already resolved.\n */\nexport const MfaVerifyCompleteResponseStruct = type({\n token: string(),\n\n expires_in: integer(),\n});\n\nexport const MfaEnrollResponseStruct = type({\n flow_id: string(),\n\n expires_at: string(),\n\n passkey_create_data: optional(string()),\n});\n\nexport const MfaEnrollCompleteResponseStruct = type({\n status: literal('enrolled'),\n});\n\nexport const MfaVerifyResponseStruct = type({\n flow_id: string(),\n\n expires_at: string(),\n\n passkey_request_data: optional(string()),\n});\n\nexport const MfaPasskeyDetailStruct = type({\n display_name: optional(string()),\n\n added_at: optional(string()),\n});\n\nexport const MfaEmailDetailStruct = type({\n address: optional(string()),\n verified: optional(boolean()),\n});\n\nexport const MfaCredentialStruct = type({\n // Intentionally accepts strings so future server credential types and\n // statuses can be ignored without making the complete response invalid.\n\n credential_type: string(),\n status: string(),\n\n enrolled_at: optional(string()),\n passkey: optional(MfaPasskeyDetailStruct),\n email: optional(MfaEmailDetailStruct),\n});\n\nexport const MfaCredentialsResponseStruct = type({\n credentials: array(MfaCredentialStruct),\n});\n\nexport const MfaErrorResponseStruct = type({\n code: optional(string()),\n message: string(),\n});\n\nexport const TokenReasonStruct = object({\n operation: pattern(string(), /^[A-Za-z0-9_.:-]{1,64}$/u),\n});\n\nexport const BeginEnrollmentRequestStruct = refine(\n object({\n type: MfaCredentialTypeStruct,\n email: optional(size(string(), 3, 254)),\n reason: TokenReasonStruct,\n }),\n 'BeginEnrollmentRequest',\n (value) => {\n if (value.type === 'email_otp' && value.email === undefined) {\n return 'email is required for email_otp enrollment';\n }\n if (value.type === 'passkey' && value.email !== undefined) {\n return 'email is not accepted for passkey enrollment';\n }\n return true;\n },\n);\n\nconst EmailOtpCodeStruct = pattern(string(), /^\\d{6}$/u);\n\nconst EnrollmentProofStruct = union([\n object({\n type: literal('passkey'),\n attestation: RegistrationResponseJSONStruct,\n }),\n object({\n type: literal('email_otp'),\n code: EmailOtpCodeStruct,\n }),\n]);\n\nexport const CompleteEnrollmentRequestStruct = object({\n flowId: string(),\n proof: EnrollmentProofStruct,\n reason: TokenReasonStruct,\n});\n\nexport const BeginStepUpRequestStruct = object({\n type: MfaCredentialTypeStruct,\n reason: TokenReasonStruct,\n});\n\nconst StepUpProofStruct = union([\n object({\n type: literal('passkey'),\n assertion: AuthenticationResponseJSONStruct,\n }),\n object({\n type: literal('email_otp'),\n code: EmailOtpCodeStruct,\n }),\n]);\n\nexport const CompleteStepUpRequestStruct = object({\n flowId: string(),\n proof: StepUpProofStruct,\n reason: TokenReasonStruct,\n});\n\nexport const GetElevatedTokenRequestStruct = object({\n maxSessionAgeMs: optional(min(integer(), 0)),\n});\n\nexport const ElevatedTokenClaimsStruct = type({\n sub: string(),\n aal: literal(2),\n exp: integer(),\n amr: union([MfaCredentialTypeStruct, array(MfaCredentialTypeStruct)]),\n});\n\nfunction formatStructError(error: StructError): string {\n return error\n .failures()\n .map(({ path, message }) => `[${path.join('.')}] ${message}`)\n .join(', ');\n}\n\n/**\n * Validates data received from the authentication service.\n *\n * @param value - Untrusted response data.\n * @param struct - Expected response structure.\n * @throws MfaError if the response does not match the structure.\n */\nexport function assertValidMfaResponse<Value>(\n value: unknown,\n struct: Struct<Value>,\n): asserts value is Value {\n try {\n assert(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw new MfaError('invalid_response', formatStructError(error));\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Validates data received from an untyped controller boundary.\n *\n * @param value - Untrusted request data.\n * @param struct - Expected request structure.\n * @throws MfaError if the request does not match the structure.\n */\nexport function assertValidMfaRequest<Value>(\n value: unknown,\n struct: Struct<Value>,\n): asserts value is Value {\n try {\n assert(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw new MfaError('invalid_request', formatStructError(error));\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\n/**\n * Validates and normalizes claims from an elevated access token.\n *\n * Hydra places hook-supplied claims under `ext` unless they are promoted to\n * the top level, so `aal` and `amr` are read from either location.\n *\n * @param payload - Decoded JWT payload.\n * @returns Validated claims with `amr` represented as an array.\n * @throws ElevatedTokenInvalidError if claims are missing or invalid.\n */\nexport function parseElevatedTokenClaims(payload: unknown): {\n sub: string;\n aal: 2;\n exp: number;\n amr: ('passkey' | 'email_otp')[];\n} {\n const record = asRecord(payload);\n const ext = asRecord(record?.ext);\n const value: unknown = {\n sub: record?.sub,\n exp: record?.exp,\n aal: record?.aal ?? ext?.aal,\n amr: record?.amr ?? ext?.amr,\n };\n\n try {\n assert(value, ElevatedTokenClaimsStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw new ElevatedTokenInvalidError(formatStructError(error));\n }\n /* istanbul ignore next */\n throw error;\n }\n\n return {\n sub: value.sub,\n aal: value.aal,\n exp: value.exp,\n amr: Array.isArray(value.amr) ? value.amr : [value.amr],\n };\n}\n"]}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
import type { AuthenticationResponseJSONStruct, MfaCredentialStruct, MfaCredentialsResponseStruct, MfaEmailDetailStruct, MfaEnrollCompleteResponseStruct, MfaEnrollResponseStruct, MfaPasskeyDetailStruct, MfaVerifyCompleteResponseStruct, MfaVerifyResponseStruct, PublicKeyCredentialCreationOptionsJSONStruct, PublicKeyCredentialRequestOptionsJSONStruct, RegistrationResponseJSONStruct } from './schemas.js';
|
|
3
|
+
import { MFA_CREDENTIAL_TYPES } from './schemas.js';
|
|
4
|
+
export { MFA_CREDENTIAL_TYPES };
|
|
5
|
+
export type MfaCredentialType = (typeof MFA_CREDENTIAL_TYPES)[number];
|
|
6
|
+
export type MfaCredentialStatus = 'active' | 'pending';
|
|
7
|
+
export type PublicKeyCredentialCreationOptionsJSON = Infer<typeof PublicKeyCredentialCreationOptionsJSONStruct>;
|
|
8
|
+
export type PublicKeyCredentialRequestOptionsJSON = Infer<typeof PublicKeyCredentialRequestOptionsJSONStruct>;
|
|
9
|
+
export type RegistrationResponseJSON = Infer<typeof RegistrationResponseJSONStruct>;
|
|
10
|
+
export type AuthenticationResponseJSON = Infer<typeof AuthenticationResponseJSONStruct>;
|
|
11
|
+
export type MfaEnrollResponse = Infer<typeof MfaEnrollResponseStruct>;
|
|
12
|
+
export type MfaEnrollCompleteResponse = Infer<typeof MfaEnrollCompleteResponseStruct>;
|
|
13
|
+
export type MfaVerifyResponse = Infer<typeof MfaVerifyResponseStruct>;
|
|
14
|
+
export type MfaVerifyCompleteResponse = Infer<typeof MfaVerifyCompleteResponseStruct>;
|
|
15
|
+
export type MfaCredentialsResponse = Infer<typeof MfaCredentialsResponseStruct>;
|
|
16
|
+
export type MfaCredential = Infer<typeof MfaCredentialStruct>;
|
|
17
|
+
export type MfaPasskeyDetail = Infer<typeof MfaPasskeyDetailStruct>;
|
|
18
|
+
export type MfaEmailDetail = Infer<typeof MfaEmailDetailStruct>;
|
|
19
|
+
export type MfaEnrollRequest = {
|
|
20
|
+
credential_type: MfaCredentialType;
|
|
21
|
+
identifier?: string;
|
|
22
|
+
};
|
|
23
|
+
export type MfaEnrollCompleteRequest = {
|
|
24
|
+
credential_type: MfaCredentialType;
|
|
25
|
+
flow_id: string;
|
|
26
|
+
otp_code?: string;
|
|
27
|
+
passkey_attestation?: string;
|
|
28
|
+
};
|
|
29
|
+
export type MfaVerifyRequest = {
|
|
30
|
+
credential_type: MfaCredentialType;
|
|
31
|
+
};
|
|
32
|
+
export type MfaVerifyCompleteRequest = {
|
|
33
|
+
credential_type: MfaCredentialType;
|
|
34
|
+
flow_id: string;
|
|
35
|
+
passkey_assertion?: string;
|
|
36
|
+
otp_code?: string;
|
|
37
|
+
};
|
|
38
|
+
export type EnrolledCredential = {
|
|
39
|
+
type: 'passkey';
|
|
40
|
+
status: MfaCredentialStatus;
|
|
41
|
+
enrolledAt?: number;
|
|
42
|
+
displayName?: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: 'email_otp';
|
|
45
|
+
status: MfaCredentialStatus;
|
|
46
|
+
enrolledAt?: number;
|
|
47
|
+
email: string;
|
|
48
|
+
verified: boolean;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Caller-supplied context attached to MFA trace spans. `operation` names the
|
|
52
|
+
* client flow that needs the credential (for example `money.signTransaction`).
|
|
53
|
+
*/
|
|
54
|
+
export type TokenReason = {
|
|
55
|
+
operation: string;
|
|
56
|
+
};
|
|
57
|
+
export type EnrollmentChallenge = {
|
|
58
|
+
type: 'passkey';
|
|
59
|
+
flowId: string;
|
|
60
|
+
expiresAt: number;
|
|
61
|
+
publicKey: PublicKeyCredentialCreationOptionsJSON;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'email_otp';
|
|
64
|
+
flowId: string;
|
|
65
|
+
expiresAt: number;
|
|
66
|
+
};
|
|
67
|
+
export type EnrollmentProof = {
|
|
68
|
+
type: 'passkey';
|
|
69
|
+
attestation: RegistrationResponseJSON;
|
|
70
|
+
} | {
|
|
71
|
+
type: 'email_otp';
|
|
72
|
+
code: string;
|
|
73
|
+
};
|
|
74
|
+
export type StepUpChallenge = {
|
|
75
|
+
type: 'passkey';
|
|
76
|
+
flowId: string;
|
|
77
|
+
expiresAt: number;
|
|
78
|
+
publicKey: PublicKeyCredentialRequestOptionsJSON;
|
|
79
|
+
} | {
|
|
80
|
+
type: 'email_otp';
|
|
81
|
+
flowId: string;
|
|
82
|
+
expiresAt: number;
|
|
83
|
+
};
|
|
84
|
+
export type StepUpProof = {
|
|
85
|
+
type: 'passkey';
|
|
86
|
+
assertion: AuthenticationResponseJSON;
|
|
87
|
+
} | {
|
|
88
|
+
type: 'email_otp';
|
|
89
|
+
code: string;
|
|
90
|
+
};
|
|
91
|
+
export type ElevatedProfileToken = {
|
|
92
|
+
accessToken: string;
|
|
93
|
+
expiresIn: number;
|
|
94
|
+
obtainedAt: number;
|
|
95
|
+
claims: {
|
|
96
|
+
sub: string;
|
|
97
|
+
aal: 2;
|
|
98
|
+
amr: MfaCredentialType[];
|
|
99
|
+
exp: number;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
export type BeginEnrollmentRequest = {
|
|
103
|
+
type: MfaCredentialType;
|
|
104
|
+
email?: string;
|
|
105
|
+
reason: TokenReason;
|
|
106
|
+
};
|
|
107
|
+
export type CompleteEnrollmentRequest = {
|
|
108
|
+
flowId: string;
|
|
109
|
+
proof: EnrollmentProof;
|
|
110
|
+
reason: TokenReason;
|
|
111
|
+
};
|
|
112
|
+
export type BeginStepUpRequest = {
|
|
113
|
+
type: MfaCredentialType;
|
|
114
|
+
reason: TokenReason;
|
|
115
|
+
};
|
|
116
|
+
export type CompleteStepUpRequest = {
|
|
117
|
+
flowId: string;
|
|
118
|
+
proof: StepUpProof;
|
|
119
|
+
reason: TokenReason;
|
|
120
|
+
};
|
|
121
|
+
export type GetElevatedTokenRequest = {
|
|
122
|
+
maxSessionAgeMs?: number;
|
|
123
|
+
};
|
|
124
|
+
export type MfaErrorCode = 'max_passkeys_reached' | 'max_identifiers_reached' | 'email_already_enrolled' | 'credential_already_enrolled' | 'credential_not_enrolled' | 'mfa_identity_missing' | 'otp_resend_cooldown' | 'rate_limited' | 'kratos_unavailable' | 'flow_expired' | 'invalid_flow' | 'invalid_attestation' | 'invalid_code' | 'invalid_assertion' | 'too_many_attempts' | 'elevated_token_invalid' | 'authentication_required' | 'server_error' | 'invalid_response' | 'invalid_request';
|
|
125
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/sdk/authentication-jwt-bearer/mfa/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EACV,gCAAgC,EAChC,mBAAmB,EACnB,4BAA4B,EAC5B,oBAAoB,EACpB,+BAA+B,EAC/B,uBAAuB,EACvB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACvB,4CAA4C,EAC5C,2CAA2C,EAC3C,8BAA8B,EAC/B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEvD,MAAM,MAAM,sCAAsC,GAAG,KAAK,CACxD,OAAO,4CAA4C,CACpD,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAAG,KAAK,CACvD,OAAO,2CAA2C,CACnD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,KAAK,CAC1C,OAAO,8BAA8B,CACtC,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,KAAK,CAC5C,OAAO,gCAAgC,CACxC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEtE,MAAM,MAAM,yBAAyB,GAAG,KAAK,CAC3C,OAAO,+BAA+B,CACvC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE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zB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,eAAe,CAAC;IACvB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,YAAY,GACpB,sBAAsB,GACtB,yBAAyB,GACzB,wBAAwB,GACxB,6BAA6B,GAC7B,yBAAyB,GACzB,sBAAsB,GACtB,qBAAqB,GACrB,cAAc,GACd,oBAAoB,GACpB,cAAc,GACd,cAAc,GACd,qBAAqB,GACrB,cAAc,GACd,mBAAmB,GACnB,mBAAmB,GACnB,wBAAwB,GACxB,yBAAyB,GACzB,cAAc,GACd,kBAAkB,GAClB,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/sdk/authentication-jwt-bearer/mfa/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\n\nimport type {\n AuthenticationResponseJSONStruct,\n MfaCredentialStruct,\n MfaCredentialsResponseStruct,\n MfaEmailDetailStruct,\n MfaEnrollCompleteResponseStruct,\n MfaEnrollResponseStruct,\n MfaPasskeyDetailStruct,\n MfaVerifyCompleteResponseStruct,\n MfaVerifyResponseStruct,\n PublicKeyCredentialCreationOptionsJSONStruct,\n PublicKeyCredentialRequestOptionsJSONStruct,\n RegistrationResponseJSONStruct,\n} from './schemas.js';\nimport { MFA_CREDENTIAL_TYPES } from './schemas.js';\n\nexport { MFA_CREDENTIAL_TYPES };\n\nexport type MfaCredentialType = (typeof MFA_CREDENTIAL_TYPES)[number];\n\nexport type MfaCredentialStatus = 'active' | 'pending';\n\nexport type PublicKeyCredentialCreationOptionsJSON = Infer<\n typeof PublicKeyCredentialCreationOptionsJSONStruct\n>;\n\nexport type PublicKeyCredentialRequestOptionsJSON = Infer<\n typeof PublicKeyCredentialRequestOptionsJSONStruct\n>;\n\nexport type RegistrationResponseJSON = Infer<\n typeof RegistrationResponseJSONStruct\n>;\n\nexport type AuthenticationResponseJSON = Infer<\n typeof AuthenticationResponseJSONStruct\n>;\n\nexport type MfaEnrollResponse = Infer<typeof MfaEnrollResponseStruct>;\n\nexport type MfaEnrollCompleteResponse = Infer<\n typeof MfaEnrollCompleteResponseStruct\n>;\n\nexport type MfaVerifyResponse = Infer<typeof MfaVerifyResponseStruct>;\n\nexport type MfaVerifyCompleteResponse = Infer<\n typeof MfaVerifyCompleteResponseStruct\n>;\n\nexport type MfaCredentialsResponse = Infer<typeof MfaCredentialsResponseStruct>;\n\nexport type MfaCredential = Infer<typeof MfaCredentialStruct>;\n\nexport type MfaPasskeyDetail = Infer<typeof MfaPasskeyDetailStruct>;\n\nexport type MfaEmailDetail = Infer<typeof MfaEmailDetailStruct>;\n\nexport type MfaEnrollRequest = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n credential_type: MfaCredentialType;\n identifier?: string;\n};\n\nexport type MfaEnrollCompleteRequest = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n credential_type: MfaCredentialType;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n flow_id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n otp_code?: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n passkey_attestation?: string;\n};\n\nexport type MfaVerifyRequest = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n credential_type: MfaCredentialType;\n};\n\nexport type MfaVerifyCompleteRequest = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n credential_type: MfaCredentialType;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n flow_id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n passkey_assertion?: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n otp_code?: string;\n};\n\nexport type EnrolledCredential =\n | {\n type: 'passkey';\n status: MfaCredentialStatus;\n enrolledAt?: number;\n displayName?: string;\n }\n | {\n type: 'email_otp';\n status: MfaCredentialStatus;\n enrolledAt?: number;\n email: string;\n verified: boolean;\n };\n\n/**\n * Caller-supplied context attached to MFA trace spans. `operation` names the\n * client flow that needs the credential (for example `money.signTransaction`).\n */\nexport type TokenReason = {\n operation: string;\n};\n\nexport type EnrollmentChallenge =\n | {\n type: 'passkey';\n flowId: string;\n expiresAt: number;\n publicKey: PublicKeyCredentialCreationOptionsJSON;\n }\n | {\n type: 'email_otp';\n flowId: string;\n expiresAt: number;\n };\n\nexport type EnrollmentProof =\n | {\n type: 'passkey';\n attestation: RegistrationResponseJSON;\n }\n | {\n type: 'email_otp';\n code: string;\n };\n\nexport type StepUpChallenge =\n | {\n type: 'passkey';\n flowId: string;\n expiresAt: number;\n publicKey: PublicKeyCredentialRequestOptionsJSON;\n }\n | {\n type: 'email_otp';\n flowId: string;\n expiresAt: number;\n };\n\nexport type StepUpProof =\n | {\n type: 'passkey';\n assertion: AuthenticationResponseJSON;\n }\n | {\n type: 'email_otp';\n code: string;\n };\n\nexport type ElevatedProfileToken = {\n accessToken: string;\n expiresIn: number;\n obtainedAt: number;\n claims: {\n sub: string;\n aal: 2;\n amr: MfaCredentialType[];\n exp: number;\n };\n};\n\nexport type BeginEnrollmentRequest = {\n type: MfaCredentialType;\n email?: string;\n reason: TokenReason;\n};\n\nexport type CompleteEnrollmentRequest = {\n flowId: string;\n proof: EnrollmentProof;\n reason: TokenReason;\n};\n\nexport type BeginStepUpRequest = {\n type: MfaCredentialType;\n reason: TokenReason;\n};\n\nexport type CompleteStepUpRequest = {\n flowId: string;\n proof: StepUpProof;\n reason: TokenReason;\n};\n\nexport type GetElevatedTokenRequest = {\n maxSessionAgeMs?: number;\n};\n\nexport type MfaErrorCode =\n | 'max_passkeys_reached'\n | 'max_identifiers_reached'\n | 'email_already_enrolled'\n | 'credential_already_enrolled'\n | 'credential_not_enrolled'\n | 'mfa_identity_missing'\n | 'otp_resend_cooldown'\n | 'rate_limited'\n | 'kratos_unavailable'\n | 'flow_expired'\n | 'invalid_flow'\n | 'invalid_attestation'\n | 'invalid_code'\n | 'invalid_assertion'\n | 'too_many_attempts'\n | 'elevated_token_invalid'\n | 'authentication_required'\n | 'server_error'\n | 'invalid_response'\n | 'invalid_request';\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,QAAQ;IACR,oBAAoB;IACpB,iBAAiB;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;IAC5B,YAAY;IACZ,QAAQ;IACR,oBAAoB;IACpB,iBAAiB;IACjB,WAAW;CACZ,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,QAAQ,EAAE,GAAG;IACb,oBAAoB,EAAE,GAAG;IACzB,iBAAiB,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/sdk/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,YAAY,EAAE,GAAG;IACjB,QAAQ,EAAE,GAAG;IACb,oBAAoB,EAAE,GAAG;IACzB,iBAAiB,EAAE,GAAG;IACtB,WAAW,EAAE,GAAG;CACjB,CAAC","sourcesContent":["export const HTTP_STATUS_CODES = {\n UNAUTHORIZED: 401,\n CONFLICT: 409,\n UNPROCESSABLE_ENTITY: 422,\n TOO_MANY_REQUESTS: 429,\n BAD_GATEWAY: 502,\n};\n"]}
|
package/dist/sdk/errors.d.ts
CHANGED
|
@@ -1,3 +1,93 @@
|
|
|
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;
|
|
1
91
|
export declare class NonceRetrievalError extends Error {
|
|
2
92
|
constructor(message: string);
|
|
3
93
|
}
|
|
@@ -49,4 +139,5 @@ export declare class RateLimitedError extends Error {
|
|
|
49
139
|
*/
|
|
50
140
|
static isRateLimitError(e: unknown): e is RateLimitedError;
|
|
51
141
|
}
|
|
142
|
+
export {};
|
|
52
143
|
//# 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":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAG7E,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