@metamask-previews/mfa-recovery-controller 0.0.0-preview-13e241f7f → 0.0.0-preview-693aef2bf
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 -5
- package/README.md +0 -39
- package/dist/MfaRecoveryController-method-action-types.d.ts +2 -8
- package/dist/MfaRecoveryController-method-action-types.d.ts.map +1 -1
- package/dist/MfaRecoveryController-method-action-types.js.map +1 -1
- package/dist/MfaRecoveryController.d.ts +4 -10
- package/dist/MfaRecoveryController.d.ts.map +1 -1
- package/dist/MfaRecoveryController.js +7 -24
- package/dist/MfaRecoveryController.js.map +1 -1
- package/dist/identifier-auth.d.ts +8 -35
- package/dist/identifier-auth.d.ts.map +1 -1
- package/dist/identifier-auth.js +9 -90
- package/dist/identifier-auth.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +10 -44
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,11 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
-
- `authenticateIdentifier` returns `{ session, seedlessAuthData? }` from one identifier login: a key-bound recovery `session` for `getRecoverySecret`, plus seedless auth-server data when the login returned it (social logins; passkey / SIWE omit it) ([#11224](https://github.com/MetaMask/core/pull/11224))
|
|
13
|
-
- `RecoveryIdentifierAuthProvider` has a single method, `getKeyBoundIdentifierLogin`, which returns the key-bound `token` and optional `seedlessAuthData` (`KeyBoundIdentifierLogin`). It replaces `getKeyBoundIdentifierToken`; reads and mutation writes both call it.
|
|
14
|
-
- Callers decide whether they need `seedlessAuthData`, including checking `revokeToken` for the seedless password unlock path. Mutation writes ignore `seedlessAuthData` and never send it to escrows.
|
|
15
|
-
- Validates that the key-bound token matches the requested identifier, proof key, and request hash. Empty request `identifier.value` (provider-discovered subject) is allowed only on `authenticateIdentifier`, not on mutation writes.
|
|
16
|
-
- `seedlessAuthData` is `SeedlessAuthData` from `@metamask/seedless-onboarding-controller` (the `authenticate` parameters, without `skipLock`). Shape checks use that package's `parseSeedlessAuthData`, and the issuer-namespace map is its `AUTH_CONNECTION_BY_NAMESPACE`. `authConnection` is still checked against the social identifier's issuer namespace (provider check only; subject / `userId` are not compared).
|
|
17
12
|
- Initial release of `MfaRecoveryController`, which manages MFA recovery flows and persists in-flight operations in its state ([#10022](https://github.com/MetaMask/core/pull/10022))
|
|
18
13
|
- Requires recent, request-bound AAL2 approvals for writes and reads.
|
|
19
14
|
- Sends the approval's identifiers to escrows as `approvedIdentifiers` with `register` and `updateIdentifiers` mutations, and rejects payload identifiers that are not exactly among them before writing ([#10883](https://github.com/MetaMask/core/pull/10883))
|
package/README.md
CHANGED
|
@@ -26,45 +26,6 @@ Before `updateIdentifiers`, call `getIdentifiers()` (AAL1) for the enrolled
|
|
|
26
26
|
identifiers, their `epoch` (pass as `expectedEpoch`), and Auth's identifiers;
|
|
27
27
|
build the new set from Auth's entries.
|
|
28
28
|
|
|
29
|
-
## Seedless password unlock
|
|
30
|
-
|
|
31
|
-
`RecoveryIdentifierAuthProvider` has one method, `getKeyBoundIdentifierLogin`.
|
|
32
|
-
It performs one identifier login and returns the key-bound recovery `token`
|
|
33
|
-
plus, for social logins, the seedless auth-server token set
|
|
34
|
-
(`seedlessAuthData`). Every controller path calls it and uses only what it
|
|
35
|
-
needs: `authenticateIdentifier` returns both, and mutation writes
|
|
36
|
-
(`updateRecoverySecret` / `updateIdentifiers`) use only the token and never
|
|
37
|
-
send `seedlessAuthData` to escrows.
|
|
38
|
-
|
|
39
|
-
`seedlessAuthData` on the result is **optional**: passkey / SIWE logins omit
|
|
40
|
-
it. The caller decides whether it needs it. For seedless social password
|
|
41
|
-
unlock, check that it is present (including `revokeToken`):
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
const { session, seedlessAuthData } =
|
|
45
|
-
await mfaRecoveryController.authenticateIdentifier(identifier);
|
|
46
|
-
if (!seedlessAuthData?.revokeToken) {
|
|
47
|
-
throw new Error('Social login did not return seedless auth data');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
await seedlessOnboardingController.authenticate(seedlessAuthData);
|
|
51
|
-
// Prompt for the password, evaluate TOPRF, and decrypt the vault.
|
|
52
|
-
// Keep `session` only if a later getRecoverySecret is needed; drop seedlessAuthData.
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
`seedlessAuthData` is the `SeedlessAuthData` type from
|
|
56
|
-
`@metamask/seedless-onboarding-controller`, the parameters of
|
|
57
|
-
`SeedlessOnboardingController.authenticate` without `skipLock`. When present,
|
|
58
|
-
it is checked with `parseSeedlessAuthData` from that package (required fields
|
|
59
|
-
present, unknown fields stripped) and its `authConnection` is checked against
|
|
60
|
-
the social identifier's issuer namespace using `AUTH_CONNECTION_BY_NAMESPACE`
|
|
61
|
-
(provider match only). Pass only `session` to `getRecoverySecret(session)`
|
|
62
|
-
later — do not keep auth-server tokens on the session object.
|
|
63
|
-
|
|
64
|
-
The seedless auth data comes only from the AAL1 social login and is never sent
|
|
65
|
-
to recovery escrows. `getRecoverySecret` separately requests its AAL2
|
|
66
|
-
approval when a recovery-secret read is needed.
|
|
67
|
-
|
|
68
29
|
## Installation
|
|
69
30
|
|
|
70
31
|
`yarn add @metamask/mfa-recovery-controller`
|
|
@@ -38,16 +38,10 @@ export type MfaRecoveryControllerUpdateIdentifiersAction = {
|
|
|
38
38
|
handler: MfaRecoveryController['updateIdentifiers'];
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
|
-
* Authenticates an identifier
|
|
42
|
-
* `session` for {@link getRecoverySecret} and, for seedless social logins,
|
|
43
|
-
* `seedlessAuthData` for `SeedlessOnboardingController.authenticate`.
|
|
44
|
-
* Callers decide whether they need `seedlessAuthData` (and its
|
|
45
|
-
* `revokeToken`), drop it after seedless authenticate, and keep only
|
|
46
|
-
* `session` for recovery reads.
|
|
41
|
+
* Authenticates an identifier for a subsequent recovery-secret read.
|
|
47
42
|
*
|
|
48
43
|
* @param identifier - Identifier to authenticate.
|
|
49
|
-
* @returns
|
|
50
|
-
* login returned it.
|
|
44
|
+
* @returns Ephemeral session data required by {@link getRecoverySecret}.
|
|
51
45
|
*/
|
|
52
46
|
export type MfaRecoveryControllerAuthenticateIdentifierAction = {
|
|
53
47
|
type: `MfaRecoveryController:authenticateIdentifier`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MfaRecoveryController-method-action-types.d.ts","sourceRoot":"","sources":["../src/MfaRecoveryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,qBAAqB,CAAC,UAAU,CAAC,CAAC;CAC5C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,qBAAqB,CAAC,sBAAsB,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;CACrD,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"MfaRecoveryController-method-action-types.d.ts","sourceRoot":"","sources":["../src/MfaRecoveryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,MAAM,mCAAmC,GAAG;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AAU,CAAC,CAAC;CAC5C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAC1C,mCAAmC,GACnC,+CAA+C,GAC/C,4CAA4C,GAC5C,iDAAiD,GACjD,4CAA4C,GAC5C,yCAAyC,GACzC,iCAAiC,GACjC,gCAAgC,GAChC,mCAAmC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MfaRecoveryController-method-action-types.js","sourceRoot":"","sources":["../src/MfaRecoveryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MfaRecoveryController } from './MfaRecoveryController.js';\n\n/**\n * Creates version 1 of a recovery record.\n *\n * @param recoverySecret - Secret replicated in full to every escrow.\n * @param identifiers - Ownership-approved identifier set. Must contain at\n * least two identifiers.\n */\nexport type MfaRecoveryControllerRegisterAction = {\n type: `MfaRecoveryController:register`;\n handler: MfaRecoveryController['register'];\n};\n\n/**\n * Replaces the recovery secret.\n *\n * @param identifier - Currently registered identifier used to authorize.\n * @param recoverySecret - New secret.\n * @param epoch - Current recovery version, used as `expectedVersion`.\n */\nexport type MfaRecoveryControllerUpdateRecoverySecretAction = {\n type: `MfaRecoveryController:updateRecoverySecret`;\n handler: MfaRecoveryController['updateRecoverySecret'];\n};\n\n/**\n * Replaces the complete identifier set.\n *\n * @param identifier - Currently registered identifier used to authorize.\n * @param identifiers - New identifier set. Must contain at least two\n * identifiers.\n * @param epoch - Current recovery version, used as `expectedVersion`.\n */\nexport type MfaRecoveryControllerUpdateIdentifiersAction = {\n type: `MfaRecoveryController:updateIdentifiers`;\n handler: MfaRecoveryController['updateIdentifiers'];\n};\n\n/**\n * Authenticates an identifier
|
|
1
|
+
{"version":3,"file":"MfaRecoveryController-method-action-types.js","sourceRoot":"","sources":["../src/MfaRecoveryController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MfaRecoveryController } from './MfaRecoveryController.js';\n\n/**\n * Creates version 1 of a recovery record.\n *\n * @param recoverySecret - Secret replicated in full to every escrow.\n * @param identifiers - Ownership-approved identifier set. Must contain at\n * least two identifiers.\n */\nexport type MfaRecoveryControllerRegisterAction = {\n type: `MfaRecoveryController:register`;\n handler: MfaRecoveryController['register'];\n};\n\n/**\n * Replaces the recovery secret.\n *\n * @param identifier - Currently registered identifier used to authorize.\n * @param recoverySecret - New secret.\n * @param epoch - Current recovery version, used as `expectedVersion`.\n */\nexport type MfaRecoveryControllerUpdateRecoverySecretAction = {\n type: `MfaRecoveryController:updateRecoverySecret`;\n handler: MfaRecoveryController['updateRecoverySecret'];\n};\n\n/**\n * Replaces the complete identifier set.\n *\n * @param identifier - Currently registered identifier used to authorize.\n * @param identifiers - New identifier set. Must contain at least two\n * identifiers.\n * @param epoch - Current recovery version, used as `expectedVersion`.\n */\nexport type MfaRecoveryControllerUpdateIdentifiersAction = {\n type: `MfaRecoveryController:updateIdentifiers`;\n handler: MfaRecoveryController['updateIdentifiers'];\n};\n\n/**\n * Authenticates an identifier for a subsequent recovery-secret read.\n *\n * @param identifier - Identifier to authenticate.\n * @returns Ephemeral session data required by {@link getRecoverySecret}.\n */\nexport type MfaRecoveryControllerAuthenticateIdentifierAction = {\n type: `MfaRecoveryController:authenticateIdentifier`;\n handler: MfaRecoveryController['authenticateIdentifier'];\n};\n\n/**\n * Reads the recovery secret from available escrows and returns the highest\n * consistent version. `epoch` is the current recovery version and is required\n * by later mutations. Does not wait for a pending mutation to be repaired.\n *\n * @param session - Identifier authentication session used to authorize the\n * read.\n * @returns Recovered secret bytes and the selected epoch.\n */\nexport type MfaRecoveryControllerGetRecoverySecretAction = {\n type: `MfaRecoveryController:getRecoverySecret`;\n handler: MfaRecoveryController['getRecoverySecret'];\n};\n\n/**\n * Reads the enrolled identifiers from available escrows at the highest\n * consistent version, with Auth's current identifiers. Needs no recent MFA,\n * so a new device can build an {@link updateIdentifiers} call from it.\n *\n * @returns Enrolled identifiers, `epoch`, and Auth's identifiers.\n */\nexport type MfaRecoveryControllerGetIdentifiersAction = {\n type: `MfaRecoveryController:getIdentifiers`;\n handler: MfaRecoveryController['getIdentifiers'];\n};\n\n/**\n * Completes a persisted pending mutation, if any.\n */\nexport type MfaRecoveryControllerResumeAction = {\n type: `MfaRecoveryController:resume`;\n handler: MfaRecoveryController['resume'];\n};\n\n/**\n * Drops `authorizing` pending. `writing` must be finished with {@link resume}.\n */\nexport type MfaRecoveryControllerAbortAction = {\n type: `MfaRecoveryController:abort`;\n handler: MfaRecoveryController['abort'];\n};\n\n/**\n * @returns Current recovery phase.\n */\nexport type MfaRecoveryControllerGetPhaseAction = {\n type: `MfaRecoveryController:getPhase`;\n handler: MfaRecoveryController['getPhase'];\n};\n\n/**\n * Union of all MfaRecoveryController action types.\n */\nexport type MfaRecoveryControllerMethodActions =\n | MfaRecoveryControllerRegisterAction\n | MfaRecoveryControllerUpdateRecoverySecretAction\n | MfaRecoveryControllerUpdateIdentifiersAction\n | MfaRecoveryControllerAuthenticateIdentifierAction\n | MfaRecoveryControllerGetRecoverySecretAction\n | MfaRecoveryControllerGetIdentifiersAction\n | MfaRecoveryControllerResumeAction\n | MfaRecoveryControllerAbortAction\n | MfaRecoveryControllerGetPhaseAction;\n"]}
|
|
@@ -2,7 +2,7 @@ import type { ControllerGetStateAction, ControllerStateChangedEvent } from '@met
|
|
|
2
2
|
import { BaseController } from '@metamask/base-controller';
|
|
3
3
|
import type { Messenger } from '@metamask/messenger';
|
|
4
4
|
import type { MfaRecoveryControllerMethodActions } from './MfaRecoveryController-method-action-types.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { Identifier, IdentifierSession, PendingOperationEncryptor, RecoveryAuthProvider, RecoveryEscrowProvider, RecoveryIdentifierAuthProvider, RecoveryIdentifiers, RecoveryPhase, RecoveredSecret } from './types.js';
|
|
6
6
|
declare const CONTROLLER_NAME = "MfaRecoveryController";
|
|
7
7
|
export type MfaRecoveryControllerState = {
|
|
8
8
|
/**
|
|
@@ -86,18 +86,12 @@ export declare class MfaRecoveryController extends BaseController<typeof CONTROL
|
|
|
86
86
|
*/
|
|
87
87
|
updateIdentifiers(identifier: Identifier, identifiers: Identifier[], epoch: number): Promise<void>;
|
|
88
88
|
/**
|
|
89
|
-
* Authenticates an identifier
|
|
90
|
-
* `session` for {@link getRecoverySecret} and, for seedless social logins,
|
|
91
|
-
* `seedlessAuthData` for `SeedlessOnboardingController.authenticate`.
|
|
92
|
-
* Callers decide whether they need `seedlessAuthData` (and its
|
|
93
|
-
* `revokeToken`), drop it after seedless authenticate, and keep only
|
|
94
|
-
* `session` for recovery reads.
|
|
89
|
+
* Authenticates an identifier for a subsequent recovery-secret read.
|
|
95
90
|
*
|
|
96
91
|
* @param identifier - Identifier to authenticate.
|
|
97
|
-
* @returns
|
|
98
|
-
* login returned it.
|
|
92
|
+
* @returns Ephemeral session data required by {@link getRecoverySecret}.
|
|
99
93
|
*/
|
|
100
|
-
authenticateIdentifier(identifier: Identifier): Promise<
|
|
94
|
+
authenticateIdentifier(identifier: Identifier): Promise<IdentifierSession>;
|
|
101
95
|
/**
|
|
102
96
|
* Reads the recovery secret from available escrows and returns the highest
|
|
103
97
|
* consistent version. `epoch` is the current recovery version and is required
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MfaRecoveryController.d.ts","sourceRoot":"","sources":["../src/MfaRecoveryController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"MfaRecoveryController.d.ts","sourceRoot":"","sources":["../src/MfaRecoveryController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,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CAAC,CAQ3B;IAED;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,CAIvC;CAyXF"}
|
|
@@ -4,7 +4,7 @@ import { decodeAuthControllerToken } from './auth-controller-token.js';
|
|
|
4
4
|
import { decryptFromPublic, encryptToPublic, generateWrapKey, hash, randomId, unixNow, wrapKeyId, } from './crypto.js';
|
|
5
5
|
import { IncompleteMutationError, MfaRecoveryError, MutationRejectedError, } from './errors.js';
|
|
6
6
|
import { isFulfilledResult, isMutationReceipt, selectHighestConsistentVersion, verifyMutationReceipt, } from './escrow-utils.js';
|
|
7
|
-
import { authorizeEscrowsWithToken, countDistinctIdentifiers, getIdentifierAuthMode, MIN_IDENTIFIERS,
|
|
7
|
+
import { authorizeEscrowsWithToken, countDistinctIdentifiers, getIdentifierAuthMode, MIN_IDENTIFIERS, requestKeyBoundIdentifierToken, } from './identifier-auth.js';
|
|
8
8
|
import { assertValidPendingOperation, pendingPayloadHasIdentifiers, pendingPayloadHasRecoverySecret, } from './pending-operation-validation.js';
|
|
9
9
|
import { assertAbortAllowed, getRecoveryPhase } from './state-machine.js';
|
|
10
10
|
const CONTROLLER_NAME = 'MfaRecoveryController';
|
|
@@ -124,16 +124,10 @@ export class MfaRecoveryController extends BaseController {
|
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
|
-
* Authenticates an identifier
|
|
128
|
-
* `session` for {@link getRecoverySecret} and, for seedless social logins,
|
|
129
|
-
* `seedlessAuthData` for `SeedlessOnboardingController.authenticate`.
|
|
130
|
-
* Callers decide whether they need `seedlessAuthData` (and its
|
|
131
|
-
* `revokeToken`), drop it after seedless authenticate, and keep only
|
|
132
|
-
* `session` for recovery reads.
|
|
127
|
+
* Authenticates an identifier for a subsequent recovery-secret read.
|
|
133
128
|
*
|
|
134
129
|
* @param identifier - Identifier to authenticate.
|
|
135
|
-
* @returns
|
|
136
|
-
* login returned it.
|
|
130
|
+
* @returns Ephemeral session data required by {@link getRecoverySecret}.
|
|
137
131
|
*/
|
|
138
132
|
async authenticateIdentifier(identifier) {
|
|
139
133
|
this.#assertKnownIdentifierTypes([identifier]);
|
|
@@ -145,23 +139,17 @@ export class MfaRecoveryController extends BaseController {
|
|
|
145
139
|
requestId,
|
|
146
140
|
pkE,
|
|
147
141
|
});
|
|
148
|
-
const
|
|
142
|
+
const credential = await requestKeyBoundIdentifierToken({
|
|
149
143
|
identifier,
|
|
150
144
|
requestHash,
|
|
151
145
|
identifierAuthProvider: this.#identifierAuthProvider,
|
|
152
146
|
});
|
|
153
|
-
|
|
147
|
+
return {
|
|
154
148
|
...credential,
|
|
155
149
|
requestId,
|
|
156
150
|
ephemeralPrivateKey: ephemeral.privateKey,
|
|
157
151
|
pkE,
|
|
158
152
|
};
|
|
159
|
-
return seedlessAuthData === undefined
|
|
160
|
-
? { session }
|
|
161
|
-
: {
|
|
162
|
-
session,
|
|
163
|
-
seedlessAuthData: validateSeedlessAuthData(seedlessAuthData, identifier),
|
|
164
|
-
};
|
|
165
153
|
}
|
|
166
154
|
/**
|
|
167
155
|
* Reads the recovery secret from available escrows and returns the highest
|
|
@@ -429,19 +417,14 @@ export class MfaRecoveryController extends BaseController {
|
|
|
429
417
|
}
|
|
430
418
|
async #authorizeEscrows({ escrows, identifier, requestHash, authControllerToken, }) {
|
|
431
419
|
getIdentifierAuthMode(identifier.type);
|
|
432
|
-
const
|
|
420
|
+
const credential = await requestKeyBoundIdentifierToken({
|
|
433
421
|
identifier,
|
|
434
422
|
requestHash,
|
|
435
423
|
identifierAuthProvider: this.#identifierAuthProvider,
|
|
436
424
|
});
|
|
437
|
-
// Writes authorize a registered identifier, so the subject must match
|
|
438
|
-
// exactly; only reads may discover it from an empty value.
|
|
439
|
-
if (token.identifier.value !== identifier.value) {
|
|
440
|
-
throw new MfaRecoveryError('Identifier token is not bound to this request', 'invalid_identifier_token');
|
|
441
|
-
}
|
|
442
425
|
return await authorizeEscrowsWithToken({
|
|
443
426
|
escrows,
|
|
444
|
-
credential
|
|
427
|
+
credential,
|
|
445
428
|
authControllerToken,
|
|
446
429
|
});
|
|
447
430
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MfaRecoveryController.js","sourceRoot":"","sources":["../src/MfaRecoveryController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAwB1E,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEhD,MAAM,yBAAyB,GAAG;IAChC,UAAU;IACV,sBAAsB;IACtB,mBAAmB;IACnB,wBAAwB;IACxB,mBAAmB;IACnB,gBAAgB;IAChB,QAAQ;IACR,OAAO;IACP,UAAU;CACF,CAAC;AASX,MAAM,6BAA6B,GAAG;IACpC,gBAAgB,EAAE;QAChB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAA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AC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,SAAS,GAAiC,IAAI,CAAC;IACnD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IACE,MAAM,CAAC,MAAM,KAAK,UAAU;YAC5B,CAAC,CAAC,MAAM,CAAC,MAAM,YAAY,qBAAqB,CAAC,EACjD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,SAAS,KAAK,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { bytesToHex, hexToBytes } from '@metamask/utils';\n\nimport { decodeAuthControllerToken } from './auth-controller-token.js';\nimport {\n decryptFromPublic,\n encryptToPublic,\n generateWrapKey,\n hash,\n randomId,\n unixNow,\n wrapKeyId,\n} from './crypto.js';\nimport {\n IncompleteMutationError,\n MfaRecoveryError,\n MutationRejectedError,\n} from './errors.js';\nimport {\n isFulfilledResult,\n isMutationReceipt,\n selectHighestConsistentVersion,\n verifyMutationReceipt,\n} from './escrow-utils.js';\nimport {\n authorizeEscrowsWithToken,\n countDistinctIdentifiers,\n getIdentifierAuthMode,\n MIN_IDENTIFIERS,\n requestIdentifierLogin,\n validateSeedlessAuthData,\n} from './identifier-auth.js';\nimport type { AuthorizedEscrow } from './identifier-auth.js';\nimport type { MfaRecoveryControllerMethodActions } from './MfaRecoveryController-method-action-types.js';\nimport {\n assertValidPendingOperation,\n pendingPayloadHasIdentifiers,\n pendingPayloadHasRecoverySecret,\n} from './pending-operation-validation.js';\nimport { assertAbortAllowed, getRecoveryPhase } from './state-machine.js';\nimport type {\n AuthControllerToken,\n AuthenticateIdentifierResult,\n Identifier,\n IdentifierSession,\n Mutation,\n MutationPayload,\n MutationReceipt,\n PendingOperation,\n PendingOperationEncryptor,\n PendingRegisterPayload,\n PendingUpdateIdentifiersPayload,\n PendingUpdateRecoverySecretPayload,\n RecoveryAuthProvider,\n RecoveryEscrowProvider,\n RecoveryIdentifierAuthProvider,\n RecoveryIdentifiers,\n RecoveryPhase,\n RecoveredSecret,\n WrappedSecret,\n WritingPendingOperation,\n} from './types.js';\n\nconst CONTROLLER_NAME = 'MfaRecoveryController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'register',\n 'updateRecoverySecret',\n 'updateIdentifiers',\n 'authenticateIdentifier',\n 'getRecoverySecret',\n 'getIdentifiers',\n 'resume',\n 'abort',\n 'getPhase',\n] as const;\n\nexport type MfaRecoveryControllerState = {\n /**\n * Encrypted pending mutation, or `null` when idle.\n */\n pendingOperation: string | null;\n};\n\nconst mfaRecoveryControllerMetadata = {\n pendingOperation: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n} satisfies StateMetadata<MfaRecoveryControllerState>;\n\n/**\n * @returns The default {@link MfaRecoveryController} state.\n */\nexport function getDefaultMfaRecoveryControllerState(): MfaRecoveryControllerState {\n return { pendingOperation: null };\n}\n\nexport type MfaRecoveryControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n MfaRecoveryControllerState\n>;\n\nexport type MfaRecoveryControllerActions =\n | MfaRecoveryControllerGetStateAction\n | MfaRecoveryControllerMethodActions;\n\ntype AllowedActions = never;\n\nexport type MfaRecoveryControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof CONTROLLER_NAME,\n MfaRecoveryControllerState\n >;\n\nexport type MfaRecoveryControllerEvents =\n MfaRecoveryControllerStateChangedEvent;\n\ntype AllowedEvents = never;\n\nexport type MfaRecoveryControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n MfaRecoveryControllerActions | AllowedActions,\n MfaRecoveryControllerEvents | AllowedEvents\n>;\n\nexport type MfaRecoveryControllerOptions = {\n /**\n * The messenger suited for this controller.\n */\n messenger: MfaRecoveryControllerMessenger;\n\n /**\n * The desired state with which to initialize this controller. Missing\n * properties will be filled in with defaults.\n */\n state?: Partial<MfaRecoveryControllerState>;\n\n /**\n * Authenticates the MetaMask profile and issues request-bound attestations.\n */\n authProvider: RecoveryAuthProvider;\n\n /**\n * Obtains key-bound identifier tokens from an IdP.\n */\n identifierAuthProvider: RecoveryIdentifierAuthProvider;\n\n /**\n * Ordered, non-empty set of recovery escrow replicas. This is build-time\n * configuration; public methods cannot override it.\n */\n escrows: RecoveryEscrowProvider[];\n\n /**\n * Encrypts pending mutation state using wallet secure storage.\n */\n pendingOperationEncryptor: PendingOperationEncryptor;\n\n /**\n * Clock used for AuthController token expiry checks. Unix seconds.\n * Defaults to {@link unixNow}.\n */\n now?: () => number;\n};\n\ntype MutateParams = {\n epoch: number;\n} & (\n | {\n operation: 'register';\n payload: PendingRegisterPayload;\n identifier: null;\n }\n | {\n operation: 'updateRecoverySecret';\n payload: PendingUpdateRecoverySecretPayload;\n identifier: Identifier;\n }\n | {\n operation: 'updateIdentifiers';\n payload: PendingUpdateIdentifiersPayload;\n identifier: Identifier;\n }\n);\n\n/**\n * Coordinates MFA recovery secret replication across independent escrows.\n */\nexport class MfaRecoveryController extends BaseController<\n typeof CONTROLLER_NAME,\n MfaRecoveryControllerState,\n MfaRecoveryControllerMessenger\n> {\n readonly #authProvider: RecoveryAuthProvider;\n\n readonly #identifierAuthProvider: RecoveryIdentifierAuthProvider;\n\n readonly #escrows: RecoveryEscrowProvider[];\n\n readonly #encryptor: PendingOperationEncryptor;\n\n readonly #now: () => number;\n\n #lock: Promise<void> = Promise.resolve();\n\n constructor({\n messenger,\n state,\n authProvider,\n identifierAuthProvider,\n escrows,\n pendingOperationEncryptor,\n now = unixNow,\n }: MfaRecoveryControllerOptions) {\n if (escrows.length === 0) {\n throw new MfaRecoveryError(\n 'At least one escrow is required',\n 'empty_escrow_set',\n );\n }\n const escrowIds = escrows.map((escrow) => escrow.id);\n if (new Set(escrowIds).size !== escrowIds.length) {\n throw new MfaRecoveryError('Duplicate escrow id', 'duplicate_escrow_id');\n }\n\n super({\n messenger,\n metadata: mfaRecoveryControllerMetadata,\n name: CONTROLLER_NAME,\n state: {\n ...getDefaultMfaRecoveryControllerState(),\n ...state,\n },\n });\n\n this.#authProvider = authProvider;\n this.#identifierAuthProvider = identifierAuthProvider;\n this.#escrows = [...escrows];\n this.#encryptor = pendingOperationEncryptor;\n this.#now = now;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Creates version 1 of a recovery record.\n *\n * @param recoverySecret - Secret replicated in full to every escrow.\n * @param identifiers - Ownership-approved identifier set. Must contain at\n * least two identifiers.\n */\n async register(\n recoverySecret: Uint8Array,\n identifiers: Identifier[],\n ): Promise<void> {\n this.#assertKnownIdentifierTypes(identifiers);\n this.#assertMinIdentifiers(identifiers);\n await this.#mutate({\n operation: 'register',\n payload: {\n identifiers,\n recoverySecret: bytesToHex(recoverySecret),\n },\n identifier: null,\n epoch: 0,\n });\n }\n\n /**\n * Replaces the recovery secret.\n *\n * @param identifier - Currently registered identifier used to authorize.\n * @param recoverySecret - New secret.\n * @param epoch - Current recovery version, used as `expectedVersion`.\n */\n async updateRecoverySecret(\n identifier: Identifier,\n recoverySecret: Uint8Array,\n epoch: number,\n ): Promise<void> {\n this.#assertKnownIdentifierTypes([identifier]);\n await this.#mutate({\n operation: 'updateRecoverySecret',\n payload: {\n recoverySecret: bytesToHex(recoverySecret),\n },\n identifier,\n epoch,\n });\n }\n\n /**\n * Replaces the complete identifier set.\n *\n * @param identifier - Currently registered identifier used to authorize.\n * @param identifiers - New identifier set. Must contain at least two\n * identifiers.\n * @param epoch - Current recovery version, used as `expectedVersion`.\n */\n async updateIdentifiers(\n identifier: Identifier,\n identifiers: Identifier[],\n epoch: number,\n ): Promise<void> {\n this.#assertKnownIdentifierTypes([identifier, ...identifiers]);\n this.#assertMinIdentifiers(identifiers);\n await this.#mutate({\n operation: 'updateIdentifiers',\n payload: { identifiers },\n identifier,\n epoch,\n });\n }\n\n /**\n * Authenticates an identifier with a single login. Returns an ephemeral\n * `session` for {@link getRecoverySecret} and, for seedless social logins,\n * `seedlessAuthData` for `SeedlessOnboardingController.authenticate`.\n * Callers decide whether they need `seedlessAuthData` (and its\n * `revokeToken`), drop it after seedless authenticate, and keep only\n * `session` for recovery reads.\n *\n * @param identifier - Identifier to authenticate.\n * @returns Session for recovery reads, plus seedless auth data when the\n * login returned it.\n */\n async authenticateIdentifier(\n identifier: Identifier,\n ): Promise<AuthenticateIdentifierResult> {\n this.#assertKnownIdentifierTypes([identifier]);\n const requestId = randomId();\n const ephemeral = await generateWrapKey();\n const pkE = ephemeral.publicKey;\n const requestHash = await hash({\n operation: 'getRecoverySecret',\n requestId,\n pkE,\n });\n const { seedlessAuthData, ...credential } = await requestIdentifierLogin({\n identifier,\n requestHash,\n identifierAuthProvider: this.#identifierAuthProvider,\n });\n const session: IdentifierSession = {\n ...credential,\n requestId,\n ephemeralPrivateKey: ephemeral.privateKey,\n pkE,\n };\n return seedlessAuthData === undefined\n ? { session }\n : {\n session,\n seedlessAuthData: validateSeedlessAuthData(\n seedlessAuthData,\n identifier,\n ),\n };\n }\n\n /**\n * Reads the recovery secret from available escrows and returns the highest\n * consistent version. `epoch` is the current recovery version and is required\n * by later mutations. Does not wait for a pending mutation to be repaired.\n *\n * @param session - Identifier authentication session used to authorize the\n * read.\n * @returns Recovered secret bytes and the selected epoch.\n */\n async getRecoverySecret(\n session: IdentifierSession,\n ): Promise<RecoveredSecret> {\n return await this.#withLock(async () => {\n const { token, requestId, pkE } = session;\n this.#assertKnownIdentifierTypes([token.identifier]);\n const requestHash = await hash({\n operation: 'getRecoverySecret',\n requestId,\n pkE,\n });\n if (token.requestHash !== requestHash) {\n throw new MfaRecoveryError(\n 'Invalid identifier session',\n 'invalid_identifier_session',\n );\n }\n const available = await this.#getAvailableEscrows();\n if (available.length === 0) {\n throw new MfaRecoveryError(\n 'No escrow is available',\n 'no_available_escrow',\n );\n }\n const { approval } = await this.#authProvider.authorizeRecoveryRequest({\n requestHash,\n audiences: available.map((escrow) => escrow.authAudience),\n requireTwoFactor: true,\n });\n const authorizedEscrows = await authorizeEscrowsWithToken({\n escrows: available,\n credential: session,\n authControllerToken: approval,\n });\n const results = await Promise.allSettled(\n authorizedEscrows.map(async ({ escrow, authorization }) => {\n const response = await escrow.getSecret(\n approval,\n authorization,\n requestId,\n pkE,\n );\n if (response.wrapKeyId !== (await wrapKeyId(escrow.wrapPublicKey))) {\n throw new MfaRecoveryError(\n 'Unexpected wrap key',\n 'wrap_key_mismatch',\n );\n }\n return {\n escrowId: escrow.id,\n recoverySecret: await decryptFromPublic(\n session.ephemeralPrivateKey,\n escrow.wrapPublicKey,\n response.recoverySecret.ciphertext,\n ),\n version: response.version,\n lastMutationId: response.lastMutationId,\n };\n }),\n );\n const selected = selectHighestConsistentVersion(results);\n return {\n recoverySecret: selected.recoverySecret,\n epoch: selected.version,\n };\n });\n }\n\n /**\n * Reads the enrolled identifiers from available escrows at the highest\n * consistent version, with Auth's current identifiers. Needs no recent MFA,\n * so a new device can build an {@link updateIdentifiers} call from it.\n *\n * @returns Enrolled identifiers, `epoch`, and Auth's identifiers.\n */\n async getIdentifiers(): Promise<RecoveryIdentifiers> {\n return await this.#withLock(async () => {\n const available = await this.#getAvailableEscrows();\n if (available.length === 0) {\n throw new MfaRecoveryError(\n 'No escrow is available',\n 'no_available_escrow',\n );\n }\n const { approval, identifiers: authIdentifiers } =\n await this.#authProvider.authorizeRecoveryRequest({\n requestHash: await hash({ operation: 'getIdentifiers' }),\n audiences: available.map((escrow) => escrow.authAudience),\n });\n const responses = (\n await Promise.allSettled(\n available.map(\n async (escrow) => await escrow.getIdentifiers(approval),\n ),\n )\n )\n .filter(isFulfilledResult)\n .map((result) => result.value);\n if (responses.length === 0) {\n throw new MfaRecoveryError(\n 'No escrow returned identifiers',\n 'read_failed',\n );\n }\n const epoch = Math.max(...responses.map(({ version }) => version));\n const highest = responses.filter(({ version }) => version === epoch);\n const hashes = await Promise.all(\n highest.map(async ({ identifiers }) => await hash(identifiers)),\n );\n if (new Set(hashes).size !== 1) {\n throw new MfaRecoveryError('Replica corruption', 'replica_corruption');\n }\n return { identifiers: highest[0].identifiers, epoch, authIdentifiers };\n });\n }\n\n /**\n * Completes a persisted pending mutation, if any.\n */\n async resume(): Promise<void> {\n await this.#withLock(async () => {\n await this.#repairPendingMutation();\n });\n }\n\n /**\n * Drops `authorizing` pending. `writing` must be finished with {@link resume}.\n */\n async abort(): Promise<void> {\n await this.#withLock(async () => {\n const pending = await this.#loadPending();\n assertAbortAllowed(pending);\n if (pending) {\n await this.#clearPending();\n }\n });\n }\n\n /**\n * @returns Current recovery phase.\n */\n async getPhase(): Promise<RecoveryPhase> {\n return await this.#withLock(async () =>\n getRecoveryPhase(await this.#loadPending()),\n );\n }\n\n async #mutate(params: MutateParams): Promise<void> {\n const { operation, payload, identifier, epoch } = params;\n await this.#withLock(async () => {\n if (await this.#loadPending()) {\n throw new MfaRecoveryError(\n 'A pending mutation must be resumed or aborted first',\n 'pending_mutation',\n );\n }\n\n await this.#assertEscrowsAvailable(this.#escrows);\n\n const profileId = await this.#authProvider.getAuthenticatedProfileId();\n const audiences = this.#escrows.map((escrow) => escrow.id);\n const currentVersion = this.#resolveCurrentRecoveryVersion(epoch);\n const payloadHash = await hash(payload);\n\n const mutationFields = {\n id: randomId(),\n profileId,\n operation,\n expectedVersion: currentVersion,\n newVersion: currentVersion + 1,\n payloadHash,\n audiences,\n };\n const mutation: Mutation = {\n ...mutationFields,\n requestHash: await hash(mutationFields),\n };\n\n const pending: PendingOperation = {\n phase: 'authorizing',\n mutation,\n payload,\n identifier,\n };\n await this.#persistPending(pending);\n\n await this.#replicateMutation({\n ...pending,\n phase: 'writing',\n ...(await this.#authorizeMutation(mutation)),\n receipts: [],\n });\n });\n }\n\n async #authorizeMutation(\n mutation: Mutation,\n ): Promise<\n Pick<WritingPendingOperation, 'authControllerToken' | 'approvedIdentifiers'>\n > {\n const { approval, identifiers } =\n await this.#authProvider.authorizeRecoveryRequest({\n requestHash: mutation.requestHash,\n audiences: this.#escrows.map((escrow) => escrow.authAudience),\n requireTwoFactor: true,\n });\n return { authControllerToken: approval, approvedIdentifiers: identifiers };\n }\n\n async #repairPendingMutation(): Promise<void> {\n const pending = await this.#loadPending();\n if (!pending) {\n return;\n }\n\n if (pending.phase === 'authorizing') {\n await this.#assertEscrowsAvailable(this.#escrows);\n await this.#replicateMutation({\n ...pending,\n phase: 'writing',\n ...(await this.#authorizeMutation(pending.mutation)),\n receipts: [],\n });\n return;\n }\n\n // writing phase\n await this.#replicateMutation(pending);\n }\n\n async #replicateMutation(pending: WritingPendingOperation): Promise<void> {\n const { mutation, identifier } = pending;\n const remainingEscrows = await this.#getRemainingEscrows(pending);\n if (remainingEscrows.length === 0) {\n await this.#clearPending();\n return;\n }\n\n await this.#assertEscrowsAvailable(remainingEscrows);\n\n const claims = decodeAuthControllerToken(pending.authControllerToken);\n const writing =\n claims && claims.exp > this.#now()\n ? pending\n : { ...pending, ...(await this.#authorizeMutation(mutation)) };\n await this.#assertPending(writing);\n const authorizedEscrows =\n mutation.operation === 'register'\n ? null\n : await this.#authorizeEscrows({\n escrows: remainingEscrows,\n identifier: identifier as Identifier,\n requestHash: mutation.requestHash,\n authControllerToken: writing.authControllerToken,\n });\n if (\n authorizedEscrows !== null &&\n authorizedEscrows.length !== remainingEscrows.length\n ) {\n throw new MfaRecoveryError(\n 'Unable to authorize every escrow',\n 'identifier_auth_failed',\n );\n }\n const payloads = await Promise.all(\n remainingEscrows.map(async (escrow) =>\n this.#payloadForEscrow(writing, escrow),\n ),\n );\n\n await this.#persistPending(writing);\n const results = await Promise.allSettled(\n remainingEscrows.map((escrow, index) =>\n escrow.applyMutation(\n mutation,\n writing.authControllerToken,\n authorizedEscrows?.[index]?.authorization ?? null,\n payloads[index],\n writing.approvedIdentifiers,\n ),\n ),\n );\n\n const { receipts, hasInvalidReceipt } = await this.#collectMutationReceipts(\n results,\n remainingEscrows,\n mutation,\n writing.receipts,\n );\n const rejection = unanimousMutationRejection(results, writing.receipts);\n if (rejection) {\n await this.#clearPending();\n throw rejection;\n }\n await this.#persistPending({ ...writing, receipts });\n\n if (hasInvalidReceipt) {\n throw new MfaRecoveryError('Invalid mutation receipt', 'invalid_receipt');\n }\n\n if (\n new Set(receipts.map((receipt) => receipt.escrowId)).size !==\n this.#escrows.length\n ) {\n throw new IncompleteMutationError(mutation.id);\n }\n await this.#clearPending();\n }\n\n async #assertEscrowsAvailable(\n escrows: RecoveryEscrowProvider[],\n ): Promise<void> {\n const availableEscrows = await this.#getAvailableEscrows(escrows);\n // Do we want to wait for all escrows to be available?\n if (availableEscrows.length !== escrows.length) {\n throw new MfaRecoveryError(\n 'All configured escrows are required for mutation',\n 'escrow_unavailable',\n );\n }\n }\n\n async #getRemainingEscrows(\n pending: WritingPendingOperation,\n ): Promise<RecoveryEscrowProvider[]> {\n const { mutation } = pending;\n const remainingEscrows: RecoveryEscrowProvider[] = [];\n for (const escrow of this.#escrows) {\n const receipt = pending.receipts.find(\n (item) => item.escrowId === escrow.id,\n );\n if (receipt === undefined) {\n remainingEscrows.push(escrow);\n continue;\n }\n if (!(await verifyMutationReceipt(receipt, mutation, escrow))) {\n throw new MfaRecoveryError(\n 'Invalid mutation receipt',\n 'invalid_receipt',\n );\n }\n }\n if (\n remainingEscrows.length + pending.receipts.length !==\n this.#escrows.length\n ) {\n throw new MfaRecoveryError(\n 'Receipt escrow is not configured',\n 'unknown_receipt_escrow',\n );\n }\n return remainingEscrows;\n }\n\n async #collectMutationReceipts(\n results: PromiseSettledResult<MutationReceipt>[],\n escrows: RecoveryEscrowProvider[],\n mutation: Mutation,\n existingReceipts: MutationReceipt[],\n ): Promise<{ receipts: MutationReceipt[]; hasInvalidReceipt: boolean }> {\n const receipts = [...existingReceipts];\n let hasInvalidReceipt = false;\n for (const [index, result] of results.entries()) {\n if (!isFulfilledResult(result)) {\n continue;\n }\n const escrow = escrows[index];\n if (\n !isMutationReceipt(result.value) ||\n !(await verifyMutationReceipt(result.value, mutation, escrow))\n ) {\n hasInvalidReceipt = true;\n continue;\n }\n receipts.push(result.value);\n }\n return { receipts, hasInvalidReceipt };\n }\n\n async #authorizeEscrows({\n escrows,\n identifier,\n requestHash,\n authControllerToken,\n }: {\n escrows: RecoveryEscrowProvider[];\n identifier: Identifier;\n requestHash: string;\n authControllerToken: AuthControllerToken;\n }): Promise<AuthorizedEscrow[]> {\n getIdentifierAuthMode(identifier.type);\n const { token, proofPrivateKey } = await requestIdentifierLogin({\n identifier,\n requestHash,\n identifierAuthProvider: this.#identifierAuthProvider,\n });\n // Writes authorize a registered identifier, so the subject must match\n // exactly; only reads may discover it from an empty value.\n if (token.identifier.value !== identifier.value) {\n throw new MfaRecoveryError(\n 'Identifier token is not bound to this request',\n 'invalid_identifier_token',\n );\n }\n return await authorizeEscrowsWithToken({\n escrows,\n credential: { token, proofPrivateKey },\n authControllerToken,\n });\n }\n\n async #payloadForEscrow(\n pending: WritingPendingOperation,\n escrow: RecoveryEscrowProvider,\n ): Promise<MutationPayload> {\n const { payload } = pending;\n if (!pendingPayloadHasRecoverySecret(payload)) {\n return {\n identifiers: payload.identifiers,\n };\n }\n const recoverySecret = await this.#wrapRecoverySecret(\n hexToBytes(payload.recoverySecret),\n escrow.wrapPublicKey,\n );\n if (pendingPayloadHasIdentifiers(payload)) {\n return {\n identifiers: payload.identifiers,\n recoverySecret,\n };\n }\n return { recoverySecret };\n }\n\n #resolveCurrentRecoveryVersion(epoch: number): number {\n if (!Number.isInteger(epoch) || epoch < 0) {\n throw new MfaRecoveryError('Invalid epoch', 'invalid_epoch');\n }\n return epoch;\n }\n\n async #getAvailableEscrows(\n escrows: RecoveryEscrowProvider[] = this.#escrows,\n ): Promise<RecoveryEscrowProvider[]> {\n const flags = await Promise.allSettled(\n escrows.map(async (escrow) => ({\n escrow,\n available: await escrow.isAvailable(),\n })),\n );\n return flags.flatMap((result) =>\n isFulfilledResult(result) && result.value.available\n ? [result.value.escrow]\n : [],\n );\n }\n\n #assertKnownIdentifierTypes(identifiers: Identifier[]): void {\n for (const identifier of identifiers) {\n getIdentifierAuthMode(identifier.type);\n }\n }\n\n #assertMinIdentifiers(identifiers: Identifier[]): void {\n if (countDistinctIdentifiers(identifiers) < MIN_IDENTIFIERS) {\n throw new MfaRecoveryError(\n `Requires at least ${MIN_IDENTIFIERS} identifiers`,\n 'too_few_identifiers',\n );\n }\n }\n\n async #wrapRecoverySecret(\n plaintext: Uint8Array,\n wrapPublicKey: Uint8Array,\n ): Promise<WrappedSecret> {\n const ephemeral = await generateWrapKey();\n return {\n pkE: ephemeral.publicKey,\n ciphertext: await encryptToPublic(\n ephemeral.privateKey,\n wrapPublicKey,\n plaintext,\n ),\n };\n }\n\n async #loadPending(): Promise<PendingOperation | null> {\n const { pendingOperation } = this.state;\n if (pendingOperation === null) {\n return null;\n }\n const pending = (await this.#encryptor.decrypt(\n pendingOperation,\n )) as unknown;\n await this.#assertPending(pending);\n return pending as PendingOperation;\n }\n\n async #persistPending(operation: PendingOperation): Promise<void> {\n await this.#assertPending(operation);\n const encrypted = await this.#encryptor.encrypt(operation);\n this.update((state) => {\n state.pendingOperation = encrypted;\n });\n }\n\n async #assertPending(pending: unknown): Promise<void> {\n await assertValidPendingOperation(\n pending,\n this.#escrows.map((escrow) => escrow.id),\n );\n }\n\n async #clearPending(): Promise<void> {\n this.update((state) => {\n state.pendingOperation = null;\n });\n }\n\n async #withLock<ReturnValue>(\n fn: () => Promise<ReturnValue>,\n ): Promise<ReturnValue> {\n const run = this.#lock.then(fn, fn);\n this.#lock = run.then(\n () => undefined,\n () => undefined,\n );\n return await run;\n }\n}\n\n/**\n * Every remaining escrow refused the mutation, and none has a receipt.\n *\n * @param results - Settled apply results for the remaining escrows.\n * @param existingReceipts - Receipts already stored for this mutation.\n * @returns The first refusal, or `null` when the write may have been applied.\n */\nfunction unanimousMutationRejection(\n results: PromiseSettledResult<MutationReceipt>[],\n existingReceipts: MutationReceipt[],\n): MutationRejectedError | null {\n if (existingReceipts.length > 0 || results.length === 0) {\n return null;\n }\n let rejection: MutationRejectedError | null = null;\n for (const result of results) {\n if (\n result.status !== 'rejected' ||\n !(result.reason instanceof MutationRejectedError)\n ) {\n return null;\n }\n rejection ??= result.reason;\n }\n return rejection;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MfaRecoveryController.js","sourceRoot":"","sources":["../src/MfaRecoveryController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAuB1E,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEhD,MAAM,yBAAyB,GAAG;IAChC,UAAU;IACV,sBAAsB;IACtB,mBAAmB;IACnB,wBAAwB;IAC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AC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,SAAS,KAAK,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { bytesToHex, hexToBytes } from '@metamask/utils';\n\nimport { decodeAuthControllerToken } from './auth-controller-token.js';\nimport {\n decryptFromPublic,\n encryptToPublic,\n generateWrapKey,\n hash,\n randomId,\n unixNow,\n wrapKeyId,\n} from './crypto.js';\nimport {\n IncompleteMutationError,\n MfaRecoveryError,\n MutationRejectedError,\n} from './errors.js';\nimport {\n isFulfilledResult,\n isMutationReceipt,\n selectHighestConsistentVersion,\n verifyMutationReceipt,\n} from './escrow-utils.js';\nimport {\n authorizeEscrowsWithToken,\n countDistinctIdentifiers,\n getIdentifierAuthMode,\n MIN_IDENTIFIERS,\n requestKeyBoundIdentifierToken,\n} from './identifier-auth.js';\nimport type { AuthorizedEscrow } from './identifier-auth.js';\nimport type { MfaRecoveryControllerMethodActions } from './MfaRecoveryController-method-action-types.js';\nimport {\n assertValidPendingOperation,\n pendingPayloadHasIdentifiers,\n pendingPayloadHasRecoverySecret,\n} from './pending-operation-validation.js';\nimport { assertAbortAllowed, getRecoveryPhase } from './state-machine.js';\nimport type {\n AuthControllerToken,\n Identifier,\n IdentifierSession,\n Mutation,\n MutationPayload,\n MutationReceipt,\n PendingOperation,\n PendingOperationEncryptor,\n PendingRegisterPayload,\n PendingUpdateIdentifiersPayload,\n PendingUpdateRecoverySecretPayload,\n RecoveryAuthProvider,\n RecoveryEscrowProvider,\n RecoveryIdentifierAuthProvider,\n RecoveryIdentifiers,\n RecoveryPhase,\n RecoveredSecret,\n WrappedSecret,\n WritingPendingOperation,\n} from './types.js';\n\nconst CONTROLLER_NAME = 'MfaRecoveryController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'register',\n 'updateRecoverySecret',\n 'updateIdentifiers',\n 'authenticateIdentifier',\n 'getRecoverySecret',\n 'getIdentifiers',\n 'resume',\n 'abort',\n 'getPhase',\n] as const;\n\nexport type MfaRecoveryControllerState = {\n /**\n * Encrypted pending mutation, or `null` when idle.\n */\n pendingOperation: string | null;\n};\n\nconst mfaRecoveryControllerMetadata = {\n pendingOperation: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n} satisfies StateMetadata<MfaRecoveryControllerState>;\n\n/**\n * @returns The default {@link MfaRecoveryController} state.\n */\nexport function getDefaultMfaRecoveryControllerState(): MfaRecoveryControllerState {\n return { pendingOperation: null };\n}\n\nexport type MfaRecoveryControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n MfaRecoveryControllerState\n>;\n\nexport type MfaRecoveryControllerActions =\n | MfaRecoveryControllerGetStateAction\n | MfaRecoveryControllerMethodActions;\n\ntype AllowedActions = never;\n\nexport type MfaRecoveryControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof CONTROLLER_NAME,\n MfaRecoveryControllerState\n >;\n\nexport type MfaRecoveryControllerEvents =\n MfaRecoveryControllerStateChangedEvent;\n\ntype AllowedEvents = never;\n\nexport type MfaRecoveryControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n MfaRecoveryControllerActions | AllowedActions,\n MfaRecoveryControllerEvents | AllowedEvents\n>;\n\nexport type MfaRecoveryControllerOptions = {\n /**\n * The messenger suited for this controller.\n */\n messenger: MfaRecoveryControllerMessenger;\n\n /**\n * The desired state with which to initialize this controller. Missing\n * properties will be filled in with defaults.\n */\n state?: Partial<MfaRecoveryControllerState>;\n\n /**\n * Authenticates the MetaMask profile and issues request-bound attestations.\n */\n authProvider: RecoveryAuthProvider;\n\n /**\n * Obtains key-bound identifier tokens from an IdP.\n */\n identifierAuthProvider: RecoveryIdentifierAuthProvider;\n\n /**\n * Ordered, non-empty set of recovery escrow replicas. This is build-time\n * configuration; public methods cannot override it.\n */\n escrows: RecoveryEscrowProvider[];\n\n /**\n * Encrypts pending mutation state using wallet secure storage.\n */\n pendingOperationEncryptor: PendingOperationEncryptor;\n\n /**\n * Clock used for AuthController token expiry checks. Unix seconds.\n * Defaults to {@link unixNow}.\n */\n now?: () => number;\n};\n\ntype MutateParams = {\n epoch: number;\n} & (\n | {\n operation: 'register';\n payload: PendingRegisterPayload;\n identifier: null;\n }\n | {\n operation: 'updateRecoverySecret';\n payload: PendingUpdateRecoverySecretPayload;\n identifier: Identifier;\n }\n | {\n operation: 'updateIdentifiers';\n payload: PendingUpdateIdentifiersPayload;\n identifier: Identifier;\n }\n);\n\n/**\n * Coordinates MFA recovery secret replication across independent escrows.\n */\nexport class MfaRecoveryController extends BaseController<\n typeof CONTROLLER_NAME,\n MfaRecoveryControllerState,\n MfaRecoveryControllerMessenger\n> {\n readonly #authProvider: RecoveryAuthProvider;\n\n readonly #identifierAuthProvider: RecoveryIdentifierAuthProvider;\n\n readonly #escrows: RecoveryEscrowProvider[];\n\n readonly #encryptor: PendingOperationEncryptor;\n\n readonly #now: () => number;\n\n #lock: Promise<void> = Promise.resolve();\n\n constructor({\n messenger,\n state,\n authProvider,\n identifierAuthProvider,\n escrows,\n pendingOperationEncryptor,\n now = unixNow,\n }: MfaRecoveryControllerOptions) {\n if (escrows.length === 0) {\n throw new MfaRecoveryError(\n 'At least one escrow is required',\n 'empty_escrow_set',\n );\n }\n const escrowIds = escrows.map((escrow) => escrow.id);\n if (new Set(escrowIds).size !== escrowIds.length) {\n throw new MfaRecoveryError('Duplicate escrow id', 'duplicate_escrow_id');\n }\n\n super({\n messenger,\n metadata: mfaRecoveryControllerMetadata,\n name: CONTROLLER_NAME,\n state: {\n ...getDefaultMfaRecoveryControllerState(),\n ...state,\n },\n });\n\n this.#authProvider = authProvider;\n this.#identifierAuthProvider = identifierAuthProvider;\n this.#escrows = [...escrows];\n this.#encryptor = pendingOperationEncryptor;\n this.#now = now;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Creates version 1 of a recovery record.\n *\n * @param recoverySecret - Secret replicated in full to every escrow.\n * @param identifiers - Ownership-approved identifier set. Must contain at\n * least two identifiers.\n */\n async register(\n recoverySecret: Uint8Array,\n identifiers: Identifier[],\n ): Promise<void> {\n this.#assertKnownIdentifierTypes(identifiers);\n this.#assertMinIdentifiers(identifiers);\n await this.#mutate({\n operation: 'register',\n payload: {\n identifiers,\n recoverySecret: bytesToHex(recoverySecret),\n },\n identifier: null,\n epoch: 0,\n });\n }\n\n /**\n * Replaces the recovery secret.\n *\n * @param identifier - Currently registered identifier used to authorize.\n * @param recoverySecret - New secret.\n * @param epoch - Current recovery version, used as `expectedVersion`.\n */\n async updateRecoverySecret(\n identifier: Identifier,\n recoverySecret: Uint8Array,\n epoch: number,\n ): Promise<void> {\n this.#assertKnownIdentifierTypes([identifier]);\n await this.#mutate({\n operation: 'updateRecoverySecret',\n payload: {\n recoverySecret: bytesToHex(recoverySecret),\n },\n identifier,\n epoch,\n });\n }\n\n /**\n * Replaces the complete identifier set.\n *\n * @param identifier - Currently registered identifier used to authorize.\n * @param identifiers - New identifier set. Must contain at least two\n * identifiers.\n * @param epoch - Current recovery version, used as `expectedVersion`.\n */\n async updateIdentifiers(\n identifier: Identifier,\n identifiers: Identifier[],\n epoch: number,\n ): Promise<void> {\n this.#assertKnownIdentifierTypes([identifier, ...identifiers]);\n this.#assertMinIdentifiers(identifiers);\n await this.#mutate({\n operation: 'updateIdentifiers',\n payload: { identifiers },\n identifier,\n epoch,\n });\n }\n\n /**\n * Authenticates an identifier for a subsequent recovery-secret read.\n *\n * @param identifier - Identifier to authenticate.\n * @returns Ephemeral session data required by {@link getRecoverySecret}.\n */\n async authenticateIdentifier(\n identifier: Identifier,\n ): Promise<IdentifierSession> {\n this.#assertKnownIdentifierTypes([identifier]);\n const requestId = randomId();\n const ephemeral = await generateWrapKey();\n const pkE = ephemeral.publicKey;\n const requestHash = await hash({\n operation: 'getRecoverySecret',\n requestId,\n pkE,\n });\n const credential = await requestKeyBoundIdentifierToken({\n identifier,\n requestHash,\n identifierAuthProvider: this.#identifierAuthProvider,\n });\n return {\n ...credential,\n requestId,\n ephemeralPrivateKey: ephemeral.privateKey,\n pkE,\n };\n }\n\n /**\n * Reads the recovery secret from available escrows and returns the highest\n * consistent version. `epoch` is the current recovery version and is required\n * by later mutations. Does not wait for a pending mutation to be repaired.\n *\n * @param session - Identifier authentication session used to authorize the\n * read.\n * @returns Recovered secret bytes and the selected epoch.\n */\n async getRecoverySecret(\n session: IdentifierSession,\n ): Promise<RecoveredSecret> {\n return await this.#withLock(async () => {\n const { token, requestId, pkE } = session;\n this.#assertKnownIdentifierTypes([token.identifier]);\n const requestHash = await hash({\n operation: 'getRecoverySecret',\n requestId,\n pkE,\n });\n if (token.requestHash !== requestHash) {\n throw new MfaRecoveryError(\n 'Invalid identifier session',\n 'invalid_identifier_session',\n );\n }\n const available = await this.#getAvailableEscrows();\n if (available.length === 0) {\n throw new MfaRecoveryError(\n 'No escrow is available',\n 'no_available_escrow',\n );\n }\n const { approval } = await this.#authProvider.authorizeRecoveryRequest({\n requestHash,\n audiences: available.map((escrow) => escrow.authAudience),\n requireTwoFactor: true,\n });\n const authorizedEscrows = await authorizeEscrowsWithToken({\n escrows: available,\n credential: session,\n authControllerToken: approval,\n });\n const results = await Promise.allSettled(\n authorizedEscrows.map(async ({ escrow, authorization }) => {\n const response = await escrow.getSecret(\n approval,\n authorization,\n requestId,\n pkE,\n );\n if (response.wrapKeyId !== (await wrapKeyId(escrow.wrapPublicKey))) {\n throw new MfaRecoveryError(\n 'Unexpected wrap key',\n 'wrap_key_mismatch',\n );\n }\n return {\n escrowId: escrow.id,\n recoverySecret: await decryptFromPublic(\n session.ephemeralPrivateKey,\n escrow.wrapPublicKey,\n response.recoverySecret.ciphertext,\n ),\n version: response.version,\n lastMutationId: response.lastMutationId,\n };\n }),\n );\n const selected = selectHighestConsistentVersion(results);\n return {\n recoverySecret: selected.recoverySecret,\n epoch: selected.version,\n };\n });\n }\n\n /**\n * Reads the enrolled identifiers from available escrows at the highest\n * consistent version, with Auth's current identifiers. Needs no recent MFA,\n * so a new device can build an {@link updateIdentifiers} call from it.\n *\n * @returns Enrolled identifiers, `epoch`, and Auth's identifiers.\n */\n async getIdentifiers(): Promise<RecoveryIdentifiers> {\n return await this.#withLock(async () => {\n const available = await this.#getAvailableEscrows();\n if (available.length === 0) {\n throw new MfaRecoveryError(\n 'No escrow is available',\n 'no_available_escrow',\n );\n }\n const { approval, identifiers: authIdentifiers } =\n await this.#authProvider.authorizeRecoveryRequest({\n requestHash: await hash({ operation: 'getIdentifiers' }),\n audiences: available.map((escrow) => escrow.authAudience),\n });\n const responses = (\n await Promise.allSettled(\n available.map(\n async (escrow) => await escrow.getIdentifiers(approval),\n ),\n )\n )\n .filter(isFulfilledResult)\n .map((result) => result.value);\n if (responses.length === 0) {\n throw new MfaRecoveryError(\n 'No escrow returned identifiers',\n 'read_failed',\n );\n }\n const epoch = Math.max(...responses.map(({ version }) => version));\n const highest = responses.filter(({ version }) => version === epoch);\n const hashes = await Promise.all(\n highest.map(async ({ identifiers }) => await hash(identifiers)),\n );\n if (new Set(hashes).size !== 1) {\n throw new MfaRecoveryError('Replica corruption', 'replica_corruption');\n }\n return { identifiers: highest[0].identifiers, epoch, authIdentifiers };\n });\n }\n\n /**\n * Completes a persisted pending mutation, if any.\n */\n async resume(): Promise<void> {\n await this.#withLock(async () => {\n await this.#repairPendingMutation();\n });\n }\n\n /**\n * Drops `authorizing` pending. `writing` must be finished with {@link resume}.\n */\n async abort(): Promise<void> {\n await this.#withLock(async () => {\n const pending = await this.#loadPending();\n assertAbortAllowed(pending);\n if (pending) {\n await this.#clearPending();\n }\n });\n }\n\n /**\n * @returns Current recovery phase.\n */\n async getPhase(): Promise<RecoveryPhase> {\n return await this.#withLock(async () =>\n getRecoveryPhase(await this.#loadPending()),\n );\n }\n\n async #mutate(params: MutateParams): Promise<void> {\n const { operation, payload, identifier, epoch } = params;\n await this.#withLock(async () => {\n if (await this.#loadPending()) {\n throw new MfaRecoveryError(\n 'A pending mutation must be resumed or aborted first',\n 'pending_mutation',\n );\n }\n\n await this.#assertEscrowsAvailable(this.#escrows);\n\n const profileId = await this.#authProvider.getAuthenticatedProfileId();\n const audiences = this.#escrows.map((escrow) => escrow.id);\n const currentVersion = this.#resolveCurrentRecoveryVersion(epoch);\n const payloadHash = await hash(payload);\n\n const mutationFields = {\n id: randomId(),\n profileId,\n operation,\n expectedVersion: currentVersion,\n newVersion: currentVersion + 1,\n payloadHash,\n audiences,\n };\n const mutation: Mutation = {\n ...mutationFields,\n requestHash: await hash(mutationFields),\n };\n\n const pending: PendingOperation = {\n phase: 'authorizing',\n mutation,\n payload,\n identifier,\n };\n await this.#persistPending(pending);\n\n await this.#replicateMutation({\n ...pending,\n phase: 'writing',\n ...(await this.#authorizeMutation(mutation)),\n receipts: [],\n });\n });\n }\n\n async #authorizeMutation(\n mutation: Mutation,\n ): Promise<\n Pick<WritingPendingOperation, 'authControllerToken' | 'approvedIdentifiers'>\n > {\n const { approval, identifiers } =\n await this.#authProvider.authorizeRecoveryRequest({\n requestHash: mutation.requestHash,\n audiences: this.#escrows.map((escrow) => escrow.authAudience),\n requireTwoFactor: true,\n });\n return { authControllerToken: approval, approvedIdentifiers: identifiers };\n }\n\n async #repairPendingMutation(): Promise<void> {\n const pending = await this.#loadPending();\n if (!pending) {\n return;\n }\n\n if (pending.phase === 'authorizing') {\n await this.#assertEscrowsAvailable(this.#escrows);\n await this.#replicateMutation({\n ...pending,\n phase: 'writing',\n ...(await this.#authorizeMutation(pending.mutation)),\n receipts: [],\n });\n return;\n }\n\n // writing phase\n await this.#replicateMutation(pending);\n }\n\n async #replicateMutation(pending: WritingPendingOperation): Promise<void> {\n const { mutation, identifier } = pending;\n const remainingEscrows = await this.#getRemainingEscrows(pending);\n if (remainingEscrows.length === 0) {\n await this.#clearPending();\n return;\n }\n\n await this.#assertEscrowsAvailable(remainingEscrows);\n\n const claims = decodeAuthControllerToken(pending.authControllerToken);\n const writing =\n claims && claims.exp > this.#now()\n ? pending\n : { ...pending, ...(await this.#authorizeMutation(mutation)) };\n await this.#assertPending(writing);\n const authorizedEscrows =\n mutation.operation === 'register'\n ? null\n : await this.#authorizeEscrows({\n escrows: remainingEscrows,\n identifier: identifier as Identifier,\n requestHash: mutation.requestHash,\n authControllerToken: writing.authControllerToken,\n });\n if (\n authorizedEscrows !== null &&\n authorizedEscrows.length !== remainingEscrows.length\n ) {\n throw new MfaRecoveryError(\n 'Unable to authorize every escrow',\n 'identifier_auth_failed',\n );\n }\n const payloads = await Promise.all(\n remainingEscrows.map(async (escrow) =>\n this.#payloadForEscrow(writing, escrow),\n ),\n );\n\n await this.#persistPending(writing);\n const results = await Promise.allSettled(\n remainingEscrows.map((escrow, index) =>\n escrow.applyMutation(\n mutation,\n writing.authControllerToken,\n authorizedEscrows?.[index]?.authorization ?? null,\n payloads[index],\n writing.approvedIdentifiers,\n ),\n ),\n );\n\n const { receipts, hasInvalidReceipt } = await this.#collectMutationReceipts(\n results,\n remainingEscrows,\n mutation,\n writing.receipts,\n );\n const rejection = unanimousMutationRejection(results, writing.receipts);\n if (rejection) {\n await this.#clearPending();\n throw rejection;\n }\n await this.#persistPending({ ...writing, receipts });\n\n if (hasInvalidReceipt) {\n throw new MfaRecoveryError('Invalid mutation receipt', 'invalid_receipt');\n }\n\n if (\n new Set(receipts.map((receipt) => receipt.escrowId)).size !==\n this.#escrows.length\n ) {\n throw new IncompleteMutationError(mutation.id);\n }\n await this.#clearPending();\n }\n\n async #assertEscrowsAvailable(\n escrows: RecoveryEscrowProvider[],\n ): Promise<void> {\n const availableEscrows = await this.#getAvailableEscrows(escrows);\n // Do we want to wait for all escrows to be available?\n if (availableEscrows.length !== escrows.length) {\n throw new MfaRecoveryError(\n 'All configured escrows are required for mutation',\n 'escrow_unavailable',\n );\n }\n }\n\n async #getRemainingEscrows(\n pending: WritingPendingOperation,\n ): Promise<RecoveryEscrowProvider[]> {\n const { mutation } = pending;\n const remainingEscrows: RecoveryEscrowProvider[] = [];\n for (const escrow of this.#escrows) {\n const receipt = pending.receipts.find(\n (item) => item.escrowId === escrow.id,\n );\n if (receipt === undefined) {\n remainingEscrows.push(escrow);\n continue;\n }\n if (!(await verifyMutationReceipt(receipt, mutation, escrow))) {\n throw new MfaRecoveryError(\n 'Invalid mutation receipt',\n 'invalid_receipt',\n );\n }\n }\n if (\n remainingEscrows.length + pending.receipts.length !==\n this.#escrows.length\n ) {\n throw new MfaRecoveryError(\n 'Receipt escrow is not configured',\n 'unknown_receipt_escrow',\n );\n }\n return remainingEscrows;\n }\n\n async #collectMutationReceipts(\n results: PromiseSettledResult<MutationReceipt>[],\n escrows: RecoveryEscrowProvider[],\n mutation: Mutation,\n existingReceipts: MutationReceipt[],\n ): Promise<{ receipts: MutationReceipt[]; hasInvalidReceipt: boolean }> {\n const receipts = [...existingReceipts];\n let hasInvalidReceipt = false;\n for (const [index, result] of results.entries()) {\n if (!isFulfilledResult(result)) {\n continue;\n }\n const escrow = escrows[index];\n if (\n !isMutationReceipt(result.value) ||\n !(await verifyMutationReceipt(result.value, mutation, escrow))\n ) {\n hasInvalidReceipt = true;\n continue;\n }\n receipts.push(result.value);\n }\n return { receipts, hasInvalidReceipt };\n }\n\n async #authorizeEscrows({\n escrows,\n identifier,\n requestHash,\n authControllerToken,\n }: {\n escrows: RecoveryEscrowProvider[];\n identifier: Identifier;\n requestHash: string;\n authControllerToken: AuthControllerToken;\n }): Promise<AuthorizedEscrow[]> {\n getIdentifierAuthMode(identifier.type);\n const credential = await requestKeyBoundIdentifierToken({\n identifier,\n requestHash,\n identifierAuthProvider: this.#identifierAuthProvider,\n });\n return await authorizeEscrowsWithToken({\n escrows,\n credential,\n authControllerToken,\n });\n }\n\n async #payloadForEscrow(\n pending: WritingPendingOperation,\n escrow: RecoveryEscrowProvider,\n ): Promise<MutationPayload> {\n const { payload } = pending;\n if (!pendingPayloadHasRecoverySecret(payload)) {\n return {\n identifiers: payload.identifiers,\n };\n }\n const recoverySecret = await this.#wrapRecoverySecret(\n hexToBytes(payload.recoverySecret),\n escrow.wrapPublicKey,\n );\n if (pendingPayloadHasIdentifiers(payload)) {\n return {\n identifiers: payload.identifiers,\n recoverySecret,\n };\n }\n return { recoverySecret };\n }\n\n #resolveCurrentRecoveryVersion(epoch: number): number {\n if (!Number.isInteger(epoch) || epoch < 0) {\n throw new MfaRecoveryError('Invalid epoch', 'invalid_epoch');\n }\n return epoch;\n }\n\n async #getAvailableEscrows(\n escrows: RecoveryEscrowProvider[] = this.#escrows,\n ): Promise<RecoveryEscrowProvider[]> {\n const flags = await Promise.allSettled(\n escrows.map(async (escrow) => ({\n escrow,\n available: await escrow.isAvailable(),\n })),\n );\n return flags.flatMap((result) =>\n isFulfilledResult(result) && result.value.available\n ? [result.value.escrow]\n : [],\n );\n }\n\n #assertKnownIdentifierTypes(identifiers: Identifier[]): void {\n for (const identifier of identifiers) {\n getIdentifierAuthMode(identifier.type);\n }\n }\n\n #assertMinIdentifiers(identifiers: Identifier[]): void {\n if (countDistinctIdentifiers(identifiers) < MIN_IDENTIFIERS) {\n throw new MfaRecoveryError(\n `Requires at least ${MIN_IDENTIFIERS} identifiers`,\n 'too_few_identifiers',\n );\n }\n }\n\n async #wrapRecoverySecret(\n plaintext: Uint8Array,\n wrapPublicKey: Uint8Array,\n ): Promise<WrappedSecret> {\n const ephemeral = await generateWrapKey();\n return {\n pkE: ephemeral.publicKey,\n ciphertext: await encryptToPublic(\n ephemeral.privateKey,\n wrapPublicKey,\n plaintext,\n ),\n };\n }\n\n async #loadPending(): Promise<PendingOperation | null> {\n const { pendingOperation } = this.state;\n if (pendingOperation === null) {\n return null;\n }\n const pending = (await this.#encryptor.decrypt(\n pendingOperation,\n )) as unknown;\n await this.#assertPending(pending);\n return pending as PendingOperation;\n }\n\n async #persistPending(operation: PendingOperation): Promise<void> {\n await this.#assertPending(operation);\n const encrypted = await this.#encryptor.encrypt(operation);\n this.update((state) => {\n state.pendingOperation = encrypted;\n });\n }\n\n async #assertPending(pending: unknown): Promise<void> {\n await assertValidPendingOperation(\n pending,\n this.#escrows.map((escrow) => escrow.id),\n );\n }\n\n async #clearPending(): Promise<void> {\n this.update((state) => {\n state.pendingOperation = null;\n });\n }\n\n async #withLock<ReturnValue>(\n fn: () => Promise<ReturnValue>,\n ): Promise<ReturnValue> {\n const run = this.#lock.then(fn, fn);\n this.#lock = run.then(\n () => undefined,\n () => undefined,\n );\n return await run;\n }\n}\n\n/**\n * Every remaining escrow refused the mutation, and none has a receipt.\n *\n * @param results - Settled apply results for the remaining escrows.\n * @param existingReceipts - Receipts already stored for this mutation.\n * @returns The first refusal, or `null` when the write may have been applied.\n */\nfunction unanimousMutationRejection(\n results: PromiseSettledResult<MutationReceipt>[],\n existingReceipts: MutationReceipt[],\n): MutationRejectedError | null {\n if (existingReceipts.length > 0 || results.length === 0) {\n return null;\n }\n let rejection: MutationRejectedError | null = null;\n for (const result of results) {\n if (\n result.status !== 'rejected' ||\n !(result.reason instanceof MutationRejectedError)\n ) {\n return null;\n }\n rejection ??= result.reason;\n }\n return rejection;\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AuthConnection, SeedlessAuthData } from '@metamask/seedless-onboarding-controller';
|
|
2
1
|
import type { AuthControllerToken, Identifier, IdentifierAuthMode, IdentifierAuthorization, KeyBoundCredential, RecoveryEscrowProvider, RecoveryIdentifierAuthProvider } from './types.js';
|
|
3
2
|
/**
|
|
4
3
|
* Minimum identifier count for register and updateIdentifiers.
|
|
@@ -24,46 +23,20 @@ export type AuthorizedEscrow = {
|
|
|
24
23
|
authorization: IdentifierAuthorization;
|
|
25
24
|
};
|
|
26
25
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* use only the parts they need. An empty request `identifier.value` may bind
|
|
30
|
-
* to the subject the provider discovers (see metamask-mobile OIDC identifier
|
|
31
|
-
* provider).
|
|
26
|
+
* Requests a key-bound identifier token and returns the private key used to
|
|
27
|
+
* prove possession of it.
|
|
32
28
|
*
|
|
33
|
-
* @param params - Identifier
|
|
34
|
-
* @param params.identifier - Identifier to
|
|
35
|
-
* @param params.requestHash - Request hash bound to the
|
|
29
|
+
* @param params - Identifier authorization parameters.
|
|
30
|
+
* @param params.identifier - Identifier to authenticate.
|
|
31
|
+
* @param params.requestHash - Request hash bound to the authorization.
|
|
36
32
|
* @param params.identifierAuthProvider - Provider for key-bound assertions.
|
|
37
|
-
* @returns Key-bound
|
|
38
|
-
* the provider returned any.
|
|
39
|
-
* @throws If the returned token is not bound to this identifier and request.
|
|
33
|
+
* @returns Key-bound identifier token and its proof private key.
|
|
40
34
|
*/
|
|
41
|
-
export declare function
|
|
35
|
+
export declare function requestKeyBoundIdentifierToken({ identifier, requestHash, identifierAuthProvider, }: {
|
|
42
36
|
identifier: Identifier;
|
|
43
37
|
requestHash: string;
|
|
44
38
|
identifierAuthProvider: RecoveryIdentifierAuthProvider;
|
|
45
|
-
}): Promise<KeyBoundCredential
|
|
46
|
-
seedlessAuthData?: unknown;
|
|
47
|
-
}>;
|
|
48
|
-
/**
|
|
49
|
-
* Expected seedless `authConnection` for a social identifier, if known.
|
|
50
|
-
*
|
|
51
|
-
* @param identifier - Authenticated identifier.
|
|
52
|
-
* @returns Matching connection, or `undefined` when the identifier is not a
|
|
53
|
-
* known social issuer.
|
|
54
|
-
*/
|
|
55
|
-
export declare function expectedSeedlessAuthConnection(identifier: Identifier): AuthConnection | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Validates seedless auth data shape, strips unknown fields, and checks that
|
|
58
|
-
* `authConnection` matches the expected provider for the authenticated social
|
|
59
|
-
* identifier's issuer namespace. It does not verify that tokens belong to the
|
|
60
|
-
* same subject / `userId` as the identifier value.
|
|
61
|
-
*
|
|
62
|
-
* @param data - Provider-returned seedless auth data.
|
|
63
|
-
* @param identifier - Identifier that was authenticated.
|
|
64
|
-
* @returns Documented seedless auth data fields only.
|
|
65
|
-
*/
|
|
66
|
-
export declare function validateSeedlessAuthData(data: unknown, identifier: Identifier): SeedlessAuthData;
|
|
39
|
+
}): Promise<KeyBoundCredential>;
|
|
67
40
|
/**
|
|
68
41
|
* Presents a key-bound credential to each escrow that provides a challenge.
|
|
69
42
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifier-auth.d.ts","sourceRoot":"","sources":["../src/identifier-auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"identifier-auth.d.ts","sourceRoot":"","sources":["../src/identifier-auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,CAM1E;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAIpE,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,sBAAsB,CAAC;IAC/B,aAAa,EAAE,uBAAuB,CAAC;CACxC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,8BAA8B,CAAC,EACnD,UAAU,EACV,WAAW,EACX,sBAAsB,GACvB,EAAE;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB,EAAE,8BAA8B,CAAC;CACxD,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAQ9B;AAED;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAAC,EAC9C,OAAO,EACP,UAAU,EACV,mBAAmB,GACpB,EAAE;IACD,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAClC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA8B9B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAStE"}
|
package/dist/identifier-auth.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AUTH_CONNECTION_BY_NAMESPACE, parseSeedlessAuthData, } from '@metamask/seedless-onboarding-controller';
|
|
2
|
-
import { areUint8ArraysEqual } from '@metamask/utils';
|
|
3
1
|
import { generateSigningKey, hash, sign } from './crypto.js';
|
|
4
2
|
import { MfaRecoveryError } from './errors.js';
|
|
5
3
|
import { isFulfilledResult } from './escrow-utils.js';
|
|
@@ -29,102 +27,23 @@ export const IDENTIFIER_AUTH_MODES = {
|
|
|
29
27
|
siwe: 'key-bound',
|
|
30
28
|
};
|
|
31
29
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* use only the parts they need. An empty request `identifier.value` may bind
|
|
35
|
-
* to the subject the provider discovers (see metamask-mobile OIDC identifier
|
|
36
|
-
* provider).
|
|
30
|
+
* Requests a key-bound identifier token and returns the private key used to
|
|
31
|
+
* prove possession of it.
|
|
37
32
|
*
|
|
38
|
-
* @param params - Identifier
|
|
39
|
-
* @param params.identifier - Identifier to
|
|
40
|
-
* @param params.requestHash - Request hash bound to the
|
|
33
|
+
* @param params - Identifier authorization parameters.
|
|
34
|
+
* @param params.identifier - Identifier to authenticate.
|
|
35
|
+
* @param params.requestHash - Request hash bound to the authorization.
|
|
41
36
|
* @param params.identifierAuthProvider - Provider for key-bound assertions.
|
|
42
|
-
* @returns Key-bound
|
|
43
|
-
* the provider returned any.
|
|
44
|
-
* @throws If the returned token is not bound to this identifier and request.
|
|
37
|
+
* @returns Key-bound identifier token and its proof private key.
|
|
45
38
|
*/
|
|
46
|
-
export async function
|
|
39
|
+
export async function requestKeyBoundIdentifierToken({ identifier, requestHash, identifierAuthProvider, }) {
|
|
47
40
|
const proofKey = await generateSigningKey();
|
|
48
|
-
const
|
|
41
|
+
const token = await identifierAuthProvider.getKeyBoundIdentifierToken({
|
|
49
42
|
identifier,
|
|
50
43
|
proofPublicKey: proofKey.publicKey,
|
|
51
44
|
requestHash,
|
|
52
45
|
});
|
|
53
|
-
|
|
54
|
-
if (!login ||
|
|
55
|
-
!isTokenBoundToRequest(token, identifier, proofKey.publicKey, requestHash)) {
|
|
56
|
-
throwInvalidIdentifierToken();
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
token,
|
|
60
|
-
proofPrivateKey: proofKey.privateKey,
|
|
61
|
-
seedlessAuthData: login.seedlessAuthData,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* @param token - Token returned by the identifier provider.
|
|
66
|
-
* @param identifier - Identifier the provider was asked to authenticate.
|
|
67
|
-
* @param proofPublicKey - Proof public key sent to the provider.
|
|
68
|
-
* @param requestHash - Request hash sent to the provider.
|
|
69
|
-
* @returns Whether the token is bound to the identifier, proof key, and
|
|
70
|
-
* request. An empty request `value` binds to any non-empty token `value`.
|
|
71
|
-
*/
|
|
72
|
-
function isTokenBoundToRequest(token, identifier, proofPublicKey, requestHash) {
|
|
73
|
-
if (typeof token !== 'object' || token === null) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
const candidate = token;
|
|
77
|
-
const tokenIdentifier = candidate.identifier;
|
|
78
|
-
if (candidate.requestHash !== requestHash ||
|
|
79
|
-
!(candidate.proofPublicKey instanceof Uint8Array) ||
|
|
80
|
-
!areUint8ArraysEqual(candidate.proofPublicKey, proofPublicKey) ||
|
|
81
|
-
tokenIdentifier === undefined ||
|
|
82
|
-
tokenIdentifier.type !== identifier.type ||
|
|
83
|
-
tokenIdentifier.namespace !== identifier.namespace) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
if (identifier.value === '') {
|
|
87
|
-
return tokenIdentifier.value.length > 0;
|
|
88
|
-
}
|
|
89
|
-
return tokenIdentifier.value === identifier.value;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Expected seedless `authConnection` for a social identifier, if known.
|
|
93
|
-
*
|
|
94
|
-
* @param identifier - Authenticated identifier.
|
|
95
|
-
* @returns Matching connection, or `undefined` when the identifier is not a
|
|
96
|
-
* known social issuer.
|
|
97
|
-
*/
|
|
98
|
-
export function expectedSeedlessAuthConnection(identifier) {
|
|
99
|
-
if (identifier.type !== 'social') {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
return AUTH_CONNECTION_BY_NAMESPACE[identifier.namespace];
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Validates seedless auth data shape, strips unknown fields, and checks that
|
|
106
|
-
* `authConnection` matches the expected provider for the authenticated social
|
|
107
|
-
* identifier's issuer namespace. It does not verify that tokens belong to the
|
|
108
|
-
* same subject / `userId` as the identifier value.
|
|
109
|
-
*
|
|
110
|
-
* @param data - Provider-returned seedless auth data.
|
|
111
|
-
* @param identifier - Identifier that was authenticated.
|
|
112
|
-
* @returns Documented seedless auth data fields only.
|
|
113
|
-
*/
|
|
114
|
-
export function validateSeedlessAuthData(data, identifier) {
|
|
115
|
-
const seedlessAuthData = parseSeedlessAuthData(data);
|
|
116
|
-
if (seedlessAuthData === undefined) {
|
|
117
|
-
throw new MfaRecoveryError('Incomplete seedless auth data', 'invalid_seedless_auth_data');
|
|
118
|
-
}
|
|
119
|
-
const expectedConnection = expectedSeedlessAuthConnection(identifier);
|
|
120
|
-
if (expectedConnection === undefined ||
|
|
121
|
-
seedlessAuthData.authConnection !== expectedConnection) {
|
|
122
|
-
throw new MfaRecoveryError('Seedless auth data does not match the authenticated identifier', 'invalid_seedless_auth_data');
|
|
123
|
-
}
|
|
124
|
-
return seedlessAuthData;
|
|
125
|
-
}
|
|
126
|
-
function throwInvalidIdentifierToken() {
|
|
127
|
-
throw new MfaRecoveryError('Identifier token is not bound to this request', 'invalid_identifier_token');
|
|
46
|
+
return { token, proofPrivateKey: proofKey.privateKey };
|
|
128
47
|
}
|
|
129
48
|
/**
|
|
130
49
|
* Presents a key-bound credential to each escrow that provides a challenge.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifier-auth.js","sourceRoot":"","sources":["../src/identifier-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,0CAA0C,CAAC;AAKlD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAatD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAyB;IAChE,OAAO,IAAI,GAAG,CACZ,WAAW,CAAC,GAAG,CACb,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,SAAS,KAAK,KAAK,EAAE,CAClE,CACF,CAAC,IAAI,CAAC;AACT,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAuC;IACvE,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,WAAW;IACpB,IAAI,EAAE,WAAW;CAClB,CAAC;AAOF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,UAAU,EACV,WAAW,EACX,sBAAsB,GAKvB;IACC,MAAM,QAAQ,GAAG,MAAM,kB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","sourcesContent":["import {\n AUTH_CONNECTION_BY_NAMESPACE,\n parseSeedlessAuthData,\n} from '@metamask/seedless-onboarding-controller';\nimport type {\n AuthConnection,\n SeedlessAuthData,\n} from '@metamask/seedless-onboarding-controller';\nimport { areUint8ArraysEqual } from '@metamask/utils';\n\nimport { generateSigningKey, hash, sign } from './crypto.js';\nimport { MfaRecoveryError } from './errors.js';\nimport { isFulfilledResult } from './escrow-utils.js';\nimport type {\n AuthControllerToken,\n Identifier,\n IdentifierAuthMode,\n IdentifierAuthorization,\n KeyBoundCredential,\n KeyBoundIdentifierLogin,\n KeyBoundIdentifierToken,\n RecoveryEscrowProvider,\n RecoveryIdentifierAuthProvider,\n} from './types.js';\n\n/**\n * Minimum identifier count for register and updateIdentifiers.\n */\nexport const MIN_IDENTIFIERS = 2;\n\n/**\n * Distinct identifier identities (`type` + `namespace` + `value`).\n *\n * @param identifiers - Identifier list.\n * @returns Distinct identity count.\n */\nexport function countDistinctIdentifiers(identifiers: Identifier[]): number {\n return new Set(\n identifiers.map(\n ({ type, namespace, value }) => `${type}\\0${namespace}\\0${value}`,\n ),\n ).size;\n}\n\n/**\n * Trusted identifier-type registry. Escrows and the controller derive the\n * authentication mode from this table, never from a client-selected flag.\n *\n * TODO: MFA-605 / MFA-606 / MFA-568 — add `emailOtp` / `smsOtp` as\n * `escrow-challenge` once escrow OTP commands exist.\n */\nexport const IDENTIFIER_AUTH_MODES: Record<string, IdentifierAuthMode> = {\n social: 'key-bound',\n passkey: 'key-bound',\n siwe: 'key-bound',\n};\n\nexport type AuthorizedEscrow = {\n escrow: RecoveryEscrowProvider;\n authorization: IdentifierAuthorization;\n};\n\n/**\n * Logs in an identifier with a fresh proof key and checks the returned token\n * is bound to the request. Returns everything the provider issued; callers\n * use only the parts they need. An empty request `identifier.value` may bind\n * to the subject the provider discovers (see metamask-mobile OIDC identifier\n * provider).\n *\n * @param params - Identifier login parameters.\n * @param params.identifier - Identifier to log in.\n * @param params.requestHash - Request hash bound to the token.\n * @param params.identifierAuthProvider - Provider for key-bound assertions.\n * @returns Key-bound credential and the unvalidated seedless auth data, if\n * the provider returned any.\n * @throws If the returned token is not bound to this identifier and request.\n */\nexport async function requestIdentifierLogin({\n identifier,\n requestHash,\n identifierAuthProvider,\n}: {\n identifier: Identifier;\n requestHash: string;\n identifierAuthProvider: RecoveryIdentifierAuthProvider;\n}): Promise<KeyBoundCredential & { seedlessAuthData?: unknown }> {\n const proofKey = await generateSigningKey();\n const login: Partial<KeyBoundIdentifierLogin> | null | undefined =\n await identifierAuthProvider.getKeyBoundIdentifierLogin({\n identifier,\n proofPublicKey: proofKey.publicKey,\n requestHash,\n });\n const token: unknown = login?.token;\n if (\n !login ||\n !isTokenBoundToRequest(token, identifier, proofKey.publicKey, requestHash)\n ) {\n throwInvalidIdentifierToken();\n }\n return {\n token,\n proofPrivateKey: proofKey.privateKey,\n seedlessAuthData: login.seedlessAuthData,\n };\n}\n\n/**\n * @param token - Token returned by the identifier provider.\n * @param identifier - Identifier the provider was asked to authenticate.\n * @param proofPublicKey - Proof public key sent to the provider.\n * @param requestHash - Request hash sent to the provider.\n * @returns Whether the token is bound to the identifier, proof key, and\n * request. An empty request `value` binds to any non-empty token `value`.\n */\nfunction isTokenBoundToRequest(\n token: unknown,\n identifier: Identifier,\n proofPublicKey: Uint8Array,\n requestHash: string,\n): token is KeyBoundIdentifierToken {\n if (typeof token !== 'object' || token === null) {\n return false;\n }\n const candidate = token as Partial<KeyBoundIdentifierToken>;\n const tokenIdentifier = candidate.identifier;\n if (\n candidate.requestHash !== requestHash ||\n !(candidate.proofPublicKey instanceof Uint8Array) ||\n !areUint8ArraysEqual(candidate.proofPublicKey, proofPublicKey) ||\n tokenIdentifier === undefined ||\n tokenIdentifier.type !== identifier.type ||\n tokenIdentifier.namespace !== identifier.namespace\n ) {\n return false;\n }\n if (identifier.value === '') {\n return tokenIdentifier.value.length > 0;\n }\n return tokenIdentifier.value === identifier.value;\n}\n\n/**\n * Expected seedless `authConnection` for a social identifier, if known.\n *\n * @param identifier - Authenticated identifier.\n * @returns Matching connection, or `undefined` when the identifier is not a\n * known social issuer.\n */\nexport function expectedSeedlessAuthConnection(\n identifier: Identifier,\n): AuthConnection | undefined {\n if (identifier.type !== 'social') {\n return undefined;\n }\n return AUTH_CONNECTION_BY_NAMESPACE[identifier.namespace];\n}\n\n/**\n * Validates seedless auth data shape, strips unknown fields, and checks that\n * `authConnection` matches the expected provider for the authenticated social\n * identifier's issuer namespace. It does not verify that tokens belong to the\n * same subject / `userId` as the identifier value.\n *\n * @param data - Provider-returned seedless auth data.\n * @param identifier - Identifier that was authenticated.\n * @returns Documented seedless auth data fields only.\n */\nexport function validateSeedlessAuthData(\n data: unknown,\n identifier: Identifier,\n): SeedlessAuthData {\n const seedlessAuthData = parseSeedlessAuthData(data);\n if (seedlessAuthData === undefined) {\n throw new MfaRecoveryError(\n 'Incomplete seedless auth data',\n 'invalid_seedless_auth_data',\n );\n }\n const expectedConnection = expectedSeedlessAuthConnection(identifier);\n if (\n expectedConnection === undefined ||\n seedlessAuthData.authConnection !== expectedConnection\n ) {\n throw new MfaRecoveryError(\n 'Seedless auth data does not match the authenticated identifier',\n 'invalid_seedless_auth_data',\n );\n }\n return seedlessAuthData;\n}\n\nfunction throwInvalidIdentifierToken(): never {\n throw new MfaRecoveryError(\n 'Identifier token is not bound to this request',\n 'invalid_identifier_token',\n );\n}\n\n/**\n * Presents a key-bound credential to each escrow that provides a challenge.\n *\n * @param params - Escrow authorization parameters.\n * @param params.escrows - Escrows to authorize.\n * @param params.credential - Key-bound identifier credential.\n * @param params.authControllerToken - Approval each escrow keys its challenge\n * to.\n * @returns Successful escrow authorizations.\n */\nexport async function authorizeEscrowsWithToken({\n escrows,\n credential,\n authControllerToken,\n}: {\n escrows: RecoveryEscrowProvider[];\n credential: KeyBoundCredential;\n authControllerToken: AuthControllerToken;\n}): Promise<AuthorizedEscrow[]> {\n const { token, proofPrivateKey } = credential;\n const challengeResults = await Promise.allSettled(\n escrows.map((escrow) => escrow.generateChallenge(authControllerToken)),\n );\n const challenges = challengeResults.flatMap((result, index) =>\n isFulfilledResult(result)\n ? [{ escrow: escrows[index], challenge: result.value }]\n : [],\n );\n const authorizationResults = await Promise.allSettled(\n challenges.map(async ({ escrow, challenge }) => {\n const message = await hash([token, challenge.id, token.requestHash]);\n return {\n escrow,\n authorization: {\n kind: 'key-bound' as const,\n token,\n proof: {\n challengeId: challenge.id,\n requestHash: token.requestHash,\n signature: await sign(proofPrivateKey, message),\n },\n },\n };\n }),\n );\n return authorizationResults\n .filter(isFulfilledResult)\n .map((result) => result.value);\n}\n\n/**\n * Returns the auth mode for an identifier type.\n *\n * @param type - Identifier type.\n * @returns Auth mode.\n * @throws If the type is not in the trusted registry.\n */\nexport function getIdentifierAuthMode(type: string): IdentifierAuthMode {\n const mode = IDENTIFIER_AUTH_MODES[type];\n if (mode === undefined) {\n throw new MfaRecoveryError(\n `Unknown identifier type: ${type}`,\n 'unknown_identifier_type',\n );\n }\n return mode;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"identifier-auth.js","sourceRoot":"","sources":["../src/identifier-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAWtD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAyB;IAChE,OAAO,IAAI,GAAG,CACZ,WAAW,CAAC,GAAG,CACb,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,SAAS,KAAK,KAAK,EAAE,CAClE,CACF,CAAC,IAAI,CAAC;AACT,CAAC;AAED;;;;;;GAMG;AACH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,EAAE;QAC7C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;QACrE,OAAO;YACL,MAAM;YACN,aAAa,EAAE;gBACb,IAAI,EAAE,WAAoB;gBAC1B,KAAK;gBACL,KAAK,EAAE;oBACL,WAAW,EAAE,SAAS,CAAC,EAAE;oBACzB,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,SAAS,EAAE,MAAM,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC;iBAChD;aACF;SACF,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;IACF,OAAO,oBAAoB;SACxB,MAAM,CAAC,iBAAiB,CAAC;SACzB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,gBAAgB,CACxB,4BAA4B,IAAI,EAAE,EAClC,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { generateSigningKey, hash, sign } from './crypto.js';\nimport { MfaRecoveryError } from './errors.js';\nimport { isFulfilledResult } from './escrow-utils.js';\nimport type {\n AuthControllerToken,\n Identifier,\n IdentifierAuthMode,\n IdentifierAuthorization,\n KeyBoundCredential,\n RecoveryEscrowProvider,\n RecoveryIdentifierAuthProvider,\n} from './types.js';\n\n/**\n * Minimum identifier count for register and updateIdentifiers.\n */\nexport const MIN_IDENTIFIERS = 2;\n\n/**\n * Distinct identifier identities (`type` + `namespace` + `value`).\n *\n * @param identifiers - Identifier list.\n * @returns Distinct identity count.\n */\nexport function countDistinctIdentifiers(identifiers: Identifier[]): number {\n return new Set(\n identifiers.map(\n ({ type, namespace, value }) => `${type}\\0${namespace}\\0${value}`,\n ),\n ).size;\n}\n\n/**\n * Trusted identifier-type registry. Escrows and the controller derive the\n * authentication mode from this table, never from a client-selected flag.\n *\n * TODO: MFA-605 / MFA-606 / MFA-568 — add `emailOtp` / `smsOtp` as\n * `escrow-challenge` once escrow OTP commands exist.\n */\nexport const IDENTIFIER_AUTH_MODES: Record<string, IdentifierAuthMode> = {\n social: 'key-bound',\n passkey: 'key-bound',\n siwe: 'key-bound',\n};\n\nexport type AuthorizedEscrow = {\n escrow: RecoveryEscrowProvider;\n authorization: IdentifierAuthorization;\n};\n\n/**\n * Requests a key-bound identifier token and returns the private key used to\n * prove possession of it.\n *\n * @param params - Identifier authorization parameters.\n * @param params.identifier - Identifier to authenticate.\n * @param params.requestHash - Request hash bound to the authorization.\n * @param params.identifierAuthProvider - Provider for key-bound assertions.\n * @returns Key-bound identifier token and its proof private key.\n */\nexport async function requestKeyBoundIdentifierToken({\n identifier,\n requestHash,\n identifierAuthProvider,\n}: {\n identifier: Identifier;\n requestHash: string;\n identifierAuthProvider: RecoveryIdentifierAuthProvider;\n}): Promise<KeyBoundCredential> {\n const proofKey = await generateSigningKey();\n const token = await identifierAuthProvider.getKeyBoundIdentifierToken({\n identifier,\n proofPublicKey: proofKey.publicKey,\n requestHash,\n });\n return { token, proofPrivateKey: proofKey.privateKey };\n}\n\n/**\n * Presents a key-bound credential to each escrow that provides a challenge.\n *\n * @param params - Escrow authorization parameters.\n * @param params.escrows - Escrows to authorize.\n * @param params.credential - Key-bound identifier credential.\n * @param params.authControllerToken - Approval each escrow keys its challenge\n * to.\n * @returns Successful escrow authorizations.\n */\nexport async function authorizeEscrowsWithToken({\n escrows,\n credential,\n authControllerToken,\n}: {\n escrows: RecoveryEscrowProvider[];\n credential: KeyBoundCredential;\n authControllerToken: AuthControllerToken;\n}): Promise<AuthorizedEscrow[]> {\n const { token, proofPrivateKey } = credential;\n const challengeResults = await Promise.allSettled(\n escrows.map((escrow) => escrow.generateChallenge(authControllerToken)),\n );\n const challenges = challengeResults.flatMap((result, index) =>\n isFulfilledResult(result)\n ? [{ escrow: escrows[index], challenge: result.value }]\n : [],\n );\n const authorizationResults = await Promise.allSettled(\n challenges.map(async ({ escrow, challenge }) => {\n const message = await hash([token, challenge.id, token.requestHash]);\n return {\n escrow,\n authorization: {\n kind: 'key-bound' as const,\n token,\n proof: {\n challengeId: challenge.id,\n requestHash: token.requestHash,\n signature: await sign(proofPrivateKey, message),\n },\n },\n };\n }),\n );\n return authorizationResults\n .filter(isFulfilledResult)\n .map((result) => result.value);\n}\n\n/**\n * Returns the auth mode for an identifier type.\n *\n * @param type - Identifier type.\n * @returns Auth mode.\n * @throws If the type is not in the trusted registry.\n */\nexport function getIdentifierAuthMode(type: string): IdentifierAuthMode {\n const mode = IDENTIFIER_AUTH_MODES[type];\n if (mode === undefined) {\n throw new MfaRecoveryError(\n `Unknown identifier type: ${type}`,\n 'unknown_identifier_type',\n );\n }\n return mode;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export type { CubistEscrowProviderOptions } from './escrow-providers/cubist-escr
|
|
|
6
6
|
export { AuthApiRecoveryAuthProvider } from './auth-api-recovery-provider.js';
|
|
7
7
|
export type { AuthApiRecoveryAuthProviderMessenger, AuthApiRecoveryAuthProviderOptions, } from './auth-api-recovery-provider.js';
|
|
8
8
|
export { IncompleteMutationError, MfaRecoveryError, MutationRejectedError, } from './errors.js';
|
|
9
|
-
export { IDENTIFIER_AUTH_MODES, MIN_IDENTIFIERS,
|
|
10
|
-
export type { AuthControllerToken,
|
|
9
|
+
export { IDENTIFIER_AUTH_MODES, MIN_IDENTIFIERS, getIdentifierAuthMode, } from './identifier-auth.js';
|
|
10
|
+
export type { AuthControllerToken, EncryptedPendingOperation, GetIdentifiersResponse, Identifier, IdentifierAuthorization, IdentifierSession, Mutation, MutationPayload, MutationReceipt, PendingMutationPayload, PendingOperation, PendingOperationEncryptor, PendingRecoverySecretHex, PendingRegisterPayload, PendingUpdateIdentifiersPayload, PendingUpdateRecoverySecretPayload, RecoveryApproval, RecoveryAuthProvider, RecoveryEscrowProvider, RecoveryIdentifierAuthProvider, RecoveryIdentifiers, RecoveryPhase, RecoveredSecret, WrappedSecret, WrappedSecretOutput, } from './types.js';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,4BAA4B,EAC5B,2BAA2B,EAC3B,mCAAmC,EACnC,8BAA8B,EAC9B,4BAA4B,EAC5B,0BAA0B,EAC1B,sCAAsC,GACvC,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,gCAAgC,EAChC,iDAAiD,EACjD,yCAAyC,EACzC,mCAAmC,EACnC,4CAA4C,EAC5C,mCAAmC,EACnC,iCAAiC,EACjC,4CAA4C,EAC5C,+CAA+C,GAChD,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AACpF,YAAY,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAChG,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EACV,oCAAoC,EACpC,kCAAkC,GACnC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,4BAA4B,EAC5B,2BAA2B,EAC3B,mCAAmC,EACnC,8BAA8B,EAC9B,4BAA4B,EAC5B,0BAA0B,EAC1B,sCAAsC,GACvC,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,gCAAgC,EAChC,iDAAiD,EACjD,yCAAyC,EACzC,mCAAmC,EACnC,4CAA4C,EAC5C,mCAAmC,EACnC,iCAAiC,EACjC,4CAA4C,EAC5C,+CAA+C,GAChD,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AACpF,YAAY,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAChG,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EACV,oCAAoC,EACpC,kCAAkC,GACnC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,UAAU,EACV,uBAAuB,EACvB,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,+BAA+B,EAC/B,kCAAkC,EAClC,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,8BAA8B,EAC9B,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,aAAa,EACb,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,5 @@ export { MfaRecoveryController, getDefaultMfaRecoveryControllerState, } from './
|
|
|
2
2
|
export { CubistEscrowProvider } from './escrow-providers/cubist-escrow-provider.js';
|
|
3
3
|
export { AuthApiRecoveryAuthProvider } from './auth-api-recovery-provider.js';
|
|
4
4
|
export { IncompleteMutationError, MfaRecoveryError, MutationRejectedError, } from './errors.js';
|
|
5
|
-
export { IDENTIFIER_AUTH_MODES, MIN_IDENTIFIERS,
|
|
5
|
+
export { IDENTIFIER_AUTH_MODES, MIN_IDENTIFIERS, getIdentifierAuthMode, } from './identifier-auth.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,MAAM,4BAA4B,CAAC;AAqBpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAK9E,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,MAAM,4BAA4B,CAAC;AAqBpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAEpF,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAK9E,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,qBAAqB,GACtB,MAAM,sBAAsB,CAAC","sourcesContent":["export {\n MfaRecoveryController,\n getDefaultMfaRecoveryControllerState,\n} from './MfaRecoveryController.js';\nexport type {\n MfaRecoveryControllerActions,\n MfaRecoveryControllerEvents,\n MfaRecoveryControllerGetStateAction,\n MfaRecoveryControllerMessenger,\n MfaRecoveryControllerOptions,\n MfaRecoveryControllerState,\n MfaRecoveryControllerStateChangedEvent,\n} from './MfaRecoveryController.js';\nexport type {\n MfaRecoveryControllerAbortAction,\n MfaRecoveryControllerAuthenticateIdentifierAction,\n MfaRecoveryControllerGetIdentifiersAction,\n MfaRecoveryControllerGetPhaseAction,\n MfaRecoveryControllerGetRecoverySecretAction,\n MfaRecoveryControllerRegisterAction,\n MfaRecoveryControllerResumeAction,\n MfaRecoveryControllerUpdateIdentifiersAction,\n MfaRecoveryControllerUpdateRecoverySecretAction,\n} from './MfaRecoveryController-method-action-types.js';\nexport { CubistEscrowProvider } from './escrow-providers/cubist-escrow-provider.js';\nexport type { CubistEscrowProviderOptions } from './escrow-providers/cubist-escrow-provider.js';\nexport { AuthApiRecoveryAuthProvider } from './auth-api-recovery-provider.js';\nexport type {\n AuthApiRecoveryAuthProviderMessenger,\n AuthApiRecoveryAuthProviderOptions,\n} from './auth-api-recovery-provider.js';\nexport {\n IncompleteMutationError,\n MfaRecoveryError,\n MutationRejectedError,\n} from './errors.js';\nexport {\n IDENTIFIER_AUTH_MODES,\n MIN_IDENTIFIERS,\n getIdentifierAuthMode,\n} from './identifier-auth.js';\nexport type {\n AuthControllerToken,\n EncryptedPendingOperation,\n GetIdentifiersResponse,\n Identifier,\n IdentifierAuthorization,\n IdentifierSession,\n Mutation,\n MutationPayload,\n MutationReceipt,\n PendingMutationPayload,\n PendingOperation,\n PendingOperationEncryptor,\n PendingRecoverySecretHex,\n PendingRegisterPayload,\n PendingUpdateIdentifiersPayload,\n PendingUpdateRecoverySecretPayload,\n RecoveryApproval,\n RecoveryAuthProvider,\n RecoveryEscrowProvider,\n RecoveryIdentifierAuthProvider,\n RecoveryIdentifiers,\n RecoveryPhase,\n RecoveredSecret,\n WrappedSecret,\n WrappedSecretOutput,\n} from './types.js';\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MFA recovery protocol types from the recovery ADR.
|
|
3
3
|
*/
|
|
4
|
-
import type { SeedlessAuthData } from '@metamask/seedless-onboarding-controller';
|
|
5
|
-
export type { SeedlessAuthData };
|
|
6
4
|
export type Identifier = {
|
|
7
5
|
type: string;
|
|
8
6
|
namespace: string;
|
|
@@ -83,36 +81,13 @@ export type KeyBoundCredential = {
|
|
|
83
81
|
*/
|
|
84
82
|
proofPrivateKey: Uint8Array;
|
|
85
83
|
};
|
|
86
|
-
/**
|
|
87
|
-
* Parameters for requesting a key-bound identifier token from an IdP.
|
|
88
|
-
*/
|
|
89
|
-
export type KeyBoundIdentifierTokenRequest = {
|
|
90
|
-
identifier: Identifier;
|
|
91
|
-
/**
|
|
92
|
-
* Raw 32-byte Ed25519 public key to bind into the token.
|
|
93
|
-
*/
|
|
94
|
-
proofPublicKey: Uint8Array;
|
|
95
|
-
requestHash: string;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Result of one identifier login. `token` is the key-bound recovery material
|
|
99
|
-
* presented to escrows (its `providerAssertion` carries the provider ID token
|
|
100
|
-
* or assertion). `seedlessAuthData` is present when the IdP issued seedless
|
|
101
|
-
* auth-server tokens in the same exchange (social logins); passkey / SIWE
|
|
102
|
-
* omit it.
|
|
103
|
-
*/
|
|
104
|
-
export type KeyBoundIdentifierLogin = {
|
|
105
|
-
token: KeyBoundIdentifierToken;
|
|
106
|
-
seedlessAuthData?: SeedlessAuthData;
|
|
107
|
-
};
|
|
108
84
|
/**
|
|
109
85
|
* Result of first-factor identifier authentication, consumed by
|
|
110
86
|
* `getRecoverySecret`.
|
|
111
87
|
*
|
|
112
88
|
* `proofPrivateKey` signs escrow challenges. `ephemeralPrivateKey` is the
|
|
113
89
|
* private half of `pkE` and decrypts the recovery secret. Keep both in
|
|
114
|
-
* memory only.
|
|
115
|
-
* returned beside the session from {@link AuthenticateIdentifierResult}.
|
|
90
|
+
* memory only.
|
|
116
91
|
*/
|
|
117
92
|
export type IdentifierSession = KeyBoundCredential & {
|
|
118
93
|
requestId: string;
|
|
@@ -125,16 +100,6 @@ export type IdentifierSession = KeyBoundCredential & {
|
|
|
125
100
|
*/
|
|
126
101
|
pkE: Uint8Array;
|
|
127
102
|
};
|
|
128
|
-
/**
|
|
129
|
-
* Result of `authenticateIdentifier`. `seedlessAuthData` is present when the
|
|
130
|
-
* login also completed a seedless auth-server exchange. Callers that need it
|
|
131
|
-
* use it for `SeedlessOnboardingController.authenticate` and then drop it;
|
|
132
|
-
* keep only `session` for a later `getRecoverySecret`.
|
|
133
|
-
*/
|
|
134
|
-
export type AuthenticateIdentifierResult = {
|
|
135
|
-
session: IdentifierSession;
|
|
136
|
-
seedlessAuthData?: SeedlessAuthData;
|
|
137
|
-
};
|
|
138
103
|
/**
|
|
139
104
|
* Recovery secret wrapped to one escrow wrap key for transit.
|
|
140
105
|
*/
|
|
@@ -268,14 +233,14 @@ export type RecoveryAuthProvider = {
|
|
|
268
233
|
* Obtains a key-bound identifier assertion from an IdP (OIDC, Passkey, SIWE).
|
|
269
234
|
*/
|
|
270
235
|
export type RecoveryIdentifierAuthProvider = {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
236
|
+
getKeyBoundIdentifierToken: (params: {
|
|
237
|
+
identifier: Identifier;
|
|
238
|
+
/**
|
|
239
|
+
* Raw 32-byte Ed25519 public key to bind into the token.
|
|
240
|
+
*/
|
|
241
|
+
proofPublicKey: Uint8Array;
|
|
242
|
+
requestHash: string;
|
|
243
|
+
}) => Promise<KeyBoundIdentifierToken>;
|
|
279
244
|
};
|
|
280
245
|
/**
|
|
281
246
|
* One recovery escrow replica. Implementations may talk to different backends.
|
|
@@ -315,4 +280,5 @@ export type PendingOperationEncryptor = {
|
|
|
315
280
|
encrypt: (operation: PendingOperation) => Promise<EncryptedPendingOperation>;
|
|
316
281
|
decrypt: (ciphertext: EncryptedPendingOperation) => Promise<PendingOperation>;
|
|
317
282
|
};
|
|
283
|
+
export {};
|
|
318
284
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAE7C,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,UAAU,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,UAAU,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,uBAAuB,CAAC;IAC/B,KAAK,EAAE,iBAAiB,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB,UAAU,GACV,sBAAsB,GACtB,mBAAmB,CAAC;AAExB,MAAM,MAAM,QAAQ,GA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,CAAC,UAAU,EAAE,yBAAyB,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC/E,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG","sourcesContent":["/**\n * MFA recovery protocol types from the recovery ADR.\n */\n\nimport type { SeedlessAuthData } from '@metamask/seedless-onboarding-controller';\n\nexport type { SeedlessAuthData };\n\nexport type Identifier = {\n type: string;\n namespace: string;\n value: string;\n verifier?: unknown;\n};\n\nexport type PoPChallenge = {\n id: string;\n escrowId: string;\n /**\n * Unix time in seconds.\n */\n expiresAt: number;\n};\n\nexport type IdentifierAuthMode = 'key-bound';\n\nexport type KeyBoundIdentifierToken = {\n identifier: Identifier;\n /**\n * Raw 32-byte Ed25519 public key of the ephemeral proof key.\n */\n proofPublicKey: Uint8Array;\n requestHash: string;\n providerAssertion: unknown;\n};\n\nexport type ProofOfPossession = {\n challengeId: string;\n requestHash: string;\n signature: string;\n};\n\n/**\n * Identifier proof presented to an escrow. Only key-bound proofs are wired;\n * escrow-challenge grants land with MFA-605 / MFA-606 / MFA-568.\n */\nexport type IdentifierAuthorization = {\n kind: 'key-bound';\n token: KeyBoundIdentifierToken;\n proof: ProofOfPossession;\n};\n\nexport type MutationOperation =\n | 'register'\n | 'updateRecoverySecret'\n | 'updateIdentifiers';\n\nexport type Mutation = {\n id: string;\n profileId: string;\n operation: MutationOperation;\n expectedVersion: number;\n newVersion: number;\n payloadHash: string;\n audiences: string[];\n requestHash: string;\n};\n\n/**\n * Auth API approval (compact JWT). Its `ext` claims bind it to one mutation:\n * `aal`, `request_hash`, and `identifiers_hash`.\n */\nexport type AuthControllerToken = string;\n\nexport type RecoveryApproval = {\n approval: AuthControllerToken;\n identifiers: Identifier[];\n};\n\nexport type MutationReceipt = {\n mutationId: string;\n requestHash: string;\n escrowId: string;\n version: number;\n /**\n * SHA-256 of the raw 32-byte Ed25519 receipt public key, as `0x` hex.\n */\n receiptKeyId: string;\n signature: string;\n};\n\n/**\n * Key-bound identifier credential: the IdP token and the private key that\n * proves possession of it. Ephemeral; keep only in memory.\n */\nexport type KeyBoundCredential = {\n token: KeyBoundIdentifierToken;\n /**\n * Raw 32-byte Ed25519 private key of the ephemeral proof key.\n */\n proofPrivateKey: Uint8Array;\n};\n\n/**\n * Parameters for requesting a key-bound identifier token from an IdP.\n */\nexport type KeyBoundIdentifierTokenRequest = {\n identifier: Identifier;\n /**\n * Raw 32-byte Ed25519 public key to bind into the token.\n */\n proofPublicKey: Uint8Array;\n requestHash: string;\n};\n\n/**\n * Result of one identifier login. `token` is the key-bound recovery material\n * presented to escrows (its `providerAssertion` carries the provider ID token\n * or assertion). `seedlessAuthData` is present when the IdP issued seedless\n * auth-server tokens in the same exchange (social logins); passkey / SIWE\n * omit it.\n */\nexport type KeyBoundIdentifierLogin = {\n token: KeyBoundIdentifierToken;\n seedlessAuthData?: SeedlessAuthData;\n};\n\n/**\n * Result of first-factor identifier authentication, consumed by\n * `getRecoverySecret`.\n *\n * `proofPrivateKey` signs escrow challenges. `ephemeralPrivateKey` is the\n * private half of `pkE` and decrypts the recovery secret. Keep both in\n * memory only. Does not carry seedless auth-server tokens — those are\n * returned beside the session from {@link AuthenticateIdentifierResult}.\n */\nexport type IdentifierSession = KeyBoundCredential & {\n requestId: string;\n /**\n * Raw 32-byte X25519 private key matching `pkE`.\n */\n ephemeralPrivateKey: Uint8Array;\n /**\n * Raw 32-byte X25519 public key, the client's one-time read key.\n */\n pkE: Uint8Array;\n};\n\n/**\n * Result of `authenticateIdentifier`. `seedlessAuthData` is present when the\n * login also completed a seedless auth-server exchange. Callers that need it\n * use it for `SeedlessOnboardingController.authenticate` and then drop it;\n * keep only `session` for a later `getRecoverySecret`.\n */\nexport type AuthenticateIdentifierResult = {\n session: IdentifierSession;\n seedlessAuthData?: SeedlessAuthData;\n};\n\n/**\n * Recovery secret wrapped to one escrow wrap key for transit.\n */\nexport type WrappedSecret = {\n /**\n * Raw 32-byte X25519 public key of the sender's ephemeral key.\n */\n pkE: Uint8Array;\n /**\n * Raw bytes of `iv || AES-256-GCM(ciphertext+tag)`.\n */\n ciphertext: Uint8Array;\n};\n\nexport type WrappedSecretOutput = {\n /**\n * Raw bytes of `iv || AES-256-GCM(ciphertext+tag)`.\n */\n ciphertext: Uint8Array;\n};\n\nexport type RegisterPayload = {\n recoverySecret: WrappedSecret;\n identifiers: Identifier[];\n};\n\nexport type UpdateRecoverySecretPayload = Pick<\n RegisterPayload,\n 'recoverySecret'\n>;\n\nexport type UpdateIdentifiersPayload = Pick<RegisterPayload, 'identifiers'>;\n\n/**\n * Escrow `applyMutation` body. Recovery secrets are wrapped to that escrow's\n * wrap key; do not confuse with {@link PendingMutationPayload}.\n */\nexport type MutationPayload =\n | RegisterPayload\n | UpdateRecoverySecretPayload\n | UpdateIdentifiersPayload;\n\n/**\n * 0x-hex of a plaintext recovery secret. Encrypted pending state stores this\n * logical value; each escrow receives a {@link WrappedSecret} only at apply.\n */\nexport type PendingRecoverySecretHex = string;\n\n/**\n * Logical register payload stored in encrypted pending state.\n */\nexport type PendingRegisterPayload = {\n identifiers: Identifier[];\n recoverySecret: PendingRecoverySecretHex;\n};\n\n/**\n * Logical secret-update payload stored in encrypted pending state.\n */\nexport type PendingUpdateRecoverySecretPayload = Pick<\n PendingRegisterPayload,\n 'recoverySecret'\n>;\n\n/**\n * Logical identifier-update payload stored in encrypted pending state.\n */\nexport type PendingUpdateIdentifiersPayload = Pick<\n PendingRegisterPayload,\n 'identifiers'\n>;\n\n/**\n * Logical mutation payload persisted in encrypted pending state. Distinct from\n * {@link MutationPayload}, which is the per-escrow apply body.\n */\nexport type PendingMutationPayload =\n | PendingRegisterPayload\n | PendingUpdateRecoverySecretPayload\n | PendingUpdateIdentifiersPayload;\n\ntype PendingOperationBase = {\n mutation: Mutation;\n identifier: Identifier | null;\n payload: PendingMutationPayload;\n};\n\nexport type AuthorizingPendingOperation = PendingOperationBase & {\n phase: 'authorizing';\n};\n\nexport type WritingPendingOperation = PendingOperationBase & {\n phase: 'writing';\n authControllerToken: AuthControllerToken;\n /**\n * The approval's identifiers, in Auth API order, bound by its\n * `identifiers_hash`.\n */\n approvedIdentifiers: Identifier[];\n receipts: MutationReceipt[];\n};\n\nexport type PendingOperation =\n | AuthorizingPendingOperation\n | WritingPendingOperation;\n\nexport type RecoveryPhase = 'idle' | PendingOperation['phase'];\n\n/**\n * Encoded ciphertext of {@link PendingOperation}. Wallet secure storage\n * encrypts this blob (including any hex recovery secret). A raw recovery\n * secret is never persisted in BaseController state.\n *\n * The recovery spec's pseudocode represents this as `Uint8Array`, but the\n * controller stores the encoded ciphertext as a string so BaseController state\n * persistence and serialization preserve it without binary coercion.\n */\nexport type EncryptedPendingOperation = string;\n\nexport type GetRecoverySecretResponse = {\n recoverySecret: WrappedSecretOutput;\n version: number;\n lastMutationId: string;\n wrapKeyId: string;\n};\n\n/**\n * Recovery secret plus the version to use as `epoch` on later mutations.\n */\nexport type RecoveredSecret = {\n recoverySecret: Uint8Array;\n epoch: number;\n};\n\n/**\n * One escrow's enrolled identifiers and record version.\n */\nexport type GetIdentifiersResponse = {\n identifiers: Identifier[];\n version: number;\n};\n\n/**\n * Enrolled identifiers and `epoch`, plus Auth's current identifiers to build\n * an `updateIdentifiers` set from.\n */\nexport type RecoveryIdentifiers = {\n identifiers: Identifier[];\n epoch: number;\n authIdentifiers: Identifier[];\n};\n\n/**\n * Authenticates the MetaMask profile and issues request-bound attestations.\n */\nexport type RecoveryAuthProvider = {\n getAuthenticatedProfileId: () => Promise<string>;\n /**\n * Returns the Auth API's approval and current recovery identifiers.\n * `requireTwoFactor` requests recent AAL2 authentication.\n */\n authorizeRecoveryRequest: (params: {\n requestHash: string;\n audiences: string[];\n requireTwoFactor?: boolean;\n }) => Promise<RecoveryApproval>;\n};\n\n/**\n * Obtains a key-bound identifier assertion from an IdP (OIDC, Passkey, SIWE).\n */\nexport type RecoveryIdentifierAuthProvider = {\n /**\n * One identifier login. Returns the key-bound token, bound to the requested\n * `proofPublicKey` and `requestHash`, and any seedless auth-server tokens\n * from the same exchange. Omit `seedlessAuthData` when the IdP does not\n * issue it (e.g. passkey). Every controller path calls this method and uses\n * only the parts it needs.\n */\n getKeyBoundIdentifierLogin: (\n params: KeyBoundIdentifierTokenRequest,\n ) => Promise<KeyBoundIdentifierLogin>;\n};\n\n/**\n * One recovery escrow replica. Implementations may talk to different backends.\n */\nexport type RecoveryEscrowProvider = {\n readonly id: string;\n /**\n * Audience the AuthController token must carry for this escrow to accept it.\n * Independent of `id`.\n */\n readonly authAudience: string;\n /**\n * Raw 32-byte X25519 wrap public key. Mutation payloads are encrypted to this\n * key; `getSecret` responses are encrypted to the request's ephemeral key\n * using the corresponding wrap private key.\n */\n readonly wrapPublicKey: Uint8Array;\n isAvailable: () => Promise<boolean>;\n generateChallenge: (\n authControllerToken: AuthControllerToken,\n ) => Promise<PoPChallenge>;\n getIdentifiers: (\n authControllerToken: AuthControllerToken,\n ) => Promise<GetIdentifiersResponse>;\n getSecret: (\n authControllerToken: AuthControllerToken,\n authorization: IdentifierAuthorization,\n requestId: string,\n pkE: Uint8Array,\n ) => Promise<GetRecoverySecretResponse>;\n applyMutation: (\n mutation: Mutation,\n authControllerToken: AuthControllerToken,\n identifierAuthorization: IdentifierAuthorization | null,\n payload: MutationPayload,\n approvedIdentifiers: Identifier[],\n ) => Promise<MutationReceipt>;\n /**\n * Verifies a receipt cryptographically using the build-pinned receipt key\n * and confirms it targets the expected escrow.\n *\n * @param receipt - Receipt returned by an escrow.\n * @param mutation - Mutation acknowledged by the receipt.\n * @param expectedEscrowId - Escrow identity expected by the caller.\n */\n verifyReceipt: (\n receipt: MutationReceipt,\n mutation: Mutation,\n expectedEscrowId: string,\n ) => Promise<boolean>;\n};\n\n/**\n * Encrypts pending mutation state using wallet secure storage.\n */\nexport type PendingOperationEncryptor = {\n encrypt: (operation: PendingOperation) => Promise<EncryptedPendingOperation>;\n decrypt: (ciphertext: EncryptedPendingOperation) => Promise<PendingOperation>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG","sourcesContent":["/**\n * MFA recovery protocol types from the recovery ADR.\n */\n\nexport type Identifier = {\n type: string;\n namespace: string;\n value: string;\n verifier?: unknown;\n};\n\nexport type PoPChallenge = {\n id: string;\n escrowId: string;\n /**\n * Unix time in seconds.\n */\n expiresAt: number;\n};\n\nexport type IdentifierAuthMode = 'key-bound';\n\nexport type KeyBoundIdentifierToken = {\n identifier: Identifier;\n /**\n * Raw 32-byte Ed25519 public key of the ephemeral proof key.\n */\n proofPublicKey: Uint8Array;\n requestHash: string;\n providerAssertion: unknown;\n};\n\nexport type ProofOfPossession = {\n challengeId: string;\n requestHash: string;\n signature: string;\n};\n\n/**\n * Identifier proof presented to an escrow. Only key-bound proofs are wired;\n * escrow-challenge grants land with MFA-605 / MFA-606 / MFA-568.\n */\nexport type IdentifierAuthorization = {\n kind: 'key-bound';\n token: KeyBoundIdentifierToken;\n proof: ProofOfPossession;\n};\n\nexport type MutationOperation =\n | 'register'\n | 'updateRecoverySecret'\n | 'updateIdentifiers';\n\nexport type Mutation = {\n id: string;\n profileId: string;\n operation: MutationOperation;\n expectedVersion: number;\n newVersion: number;\n payloadHash: string;\n audiences: string[];\n requestHash: string;\n};\n\n/**\n * Auth API approval (compact JWT). Its `ext` claims bind it to one mutation:\n * `aal`, `request_hash`, and `identifiers_hash`.\n */\nexport type AuthControllerToken = string;\n\nexport type RecoveryApproval = {\n approval: AuthControllerToken;\n identifiers: Identifier[];\n};\n\nexport type MutationReceipt = {\n mutationId: string;\n requestHash: string;\n escrowId: string;\n version: number;\n /**\n * SHA-256 of the raw 32-byte Ed25519 receipt public key, as `0x` hex.\n */\n receiptKeyId: string;\n signature: string;\n};\n\n/**\n * Key-bound identifier credential: the IdP token and the private key that\n * proves possession of it. Ephemeral; keep only in memory.\n */\nexport type KeyBoundCredential = {\n token: KeyBoundIdentifierToken;\n /**\n * Raw 32-byte Ed25519 private key of the ephemeral proof key.\n */\n proofPrivateKey: Uint8Array;\n};\n\n/**\n * Result of first-factor identifier authentication, consumed by\n * `getRecoverySecret`.\n *\n * `proofPrivateKey` signs escrow challenges. `ephemeralPrivateKey` is the\n * private half of `pkE` and decrypts the recovery secret. Keep both in\n * memory only.\n */\nexport type IdentifierSession = KeyBoundCredential & {\n requestId: string;\n /**\n * Raw 32-byte X25519 private key matching `pkE`.\n */\n ephemeralPrivateKey: Uint8Array;\n /**\n * Raw 32-byte X25519 public key, the client's one-time read key.\n */\n pkE: Uint8Array;\n};\n\n/**\n * Recovery secret wrapped to one escrow wrap key for transit.\n */\nexport type WrappedSecret = {\n /**\n * Raw 32-byte X25519 public key of the sender's ephemeral key.\n */\n pkE: Uint8Array;\n /**\n * Raw bytes of `iv || AES-256-GCM(ciphertext+tag)`.\n */\n ciphertext: Uint8Array;\n};\n\nexport type WrappedSecretOutput = {\n /**\n * Raw bytes of `iv || AES-256-GCM(ciphertext+tag)`.\n */\n ciphertext: Uint8Array;\n};\n\nexport type RegisterPayload = {\n recoverySecret: WrappedSecret;\n identifiers: Identifier[];\n};\n\nexport type UpdateRecoverySecretPayload = Pick<\n RegisterPayload,\n 'recoverySecret'\n>;\n\nexport type UpdateIdentifiersPayload = Pick<RegisterPayload, 'identifiers'>;\n\n/**\n * Escrow `applyMutation` body. Recovery secrets are wrapped to that escrow's\n * wrap key; do not confuse with {@link PendingMutationPayload}.\n */\nexport type MutationPayload =\n | RegisterPayload\n | UpdateRecoverySecretPayload\n | UpdateIdentifiersPayload;\n\n/**\n * 0x-hex of a plaintext recovery secret. Encrypted pending state stores this\n * logical value; each escrow receives a {@link WrappedSecret} only at apply.\n */\nexport type PendingRecoverySecretHex = string;\n\n/**\n * Logical register payload stored in encrypted pending state.\n */\nexport type PendingRegisterPayload = {\n identifiers: Identifier[];\n recoverySecret: PendingRecoverySecretHex;\n};\n\n/**\n * Logical secret-update payload stored in encrypted pending state.\n */\nexport type PendingUpdateRecoverySecretPayload = Pick<\n PendingRegisterPayload,\n 'recoverySecret'\n>;\n\n/**\n * Logical identifier-update payload stored in encrypted pending state.\n */\nexport type PendingUpdateIdentifiersPayload = Pick<\n PendingRegisterPayload,\n 'identifiers'\n>;\n\n/**\n * Logical mutation payload persisted in encrypted pending state. Distinct from\n * {@link MutationPayload}, which is the per-escrow apply body.\n */\nexport type PendingMutationPayload =\n | PendingRegisterPayload\n | PendingUpdateRecoverySecretPayload\n | PendingUpdateIdentifiersPayload;\n\ntype PendingOperationBase = {\n mutation: Mutation;\n identifier: Identifier | null;\n payload: PendingMutationPayload;\n};\n\nexport type AuthorizingPendingOperation = PendingOperationBase & {\n phase: 'authorizing';\n};\n\nexport type WritingPendingOperation = PendingOperationBase & {\n phase: 'writing';\n authControllerToken: AuthControllerToken;\n /**\n * The approval's identifiers, in Auth API order, bound by its\n * `identifiers_hash`.\n */\n approvedIdentifiers: Identifier[];\n receipts: MutationReceipt[];\n};\n\nexport type PendingOperation =\n | AuthorizingPendingOperation\n | WritingPendingOperation;\n\nexport type RecoveryPhase = 'idle' | PendingOperation['phase'];\n\n/**\n * Encoded ciphertext of {@link PendingOperation}. Wallet secure storage\n * encrypts this blob (including any hex recovery secret). A raw recovery\n * secret is never persisted in BaseController state.\n *\n * The recovery spec's pseudocode represents this as `Uint8Array`, but the\n * controller stores the encoded ciphertext as a string so BaseController state\n * persistence and serialization preserve it without binary coercion.\n */\nexport type EncryptedPendingOperation = string;\n\nexport type GetRecoverySecretResponse = {\n recoverySecret: WrappedSecretOutput;\n version: number;\n lastMutationId: string;\n wrapKeyId: string;\n};\n\n/**\n * Recovery secret plus the version to use as `epoch` on later mutations.\n */\nexport type RecoveredSecret = {\n recoverySecret: Uint8Array;\n epoch: number;\n};\n\n/**\n * One escrow's enrolled identifiers and record version.\n */\nexport type GetIdentifiersResponse = {\n identifiers: Identifier[];\n version: number;\n};\n\n/**\n * Enrolled identifiers and `epoch`, plus Auth's current identifiers to build\n * an `updateIdentifiers` set from.\n */\nexport type RecoveryIdentifiers = {\n identifiers: Identifier[];\n epoch: number;\n authIdentifiers: Identifier[];\n};\n\n/**\n * Authenticates the MetaMask profile and issues request-bound attestations.\n */\nexport type RecoveryAuthProvider = {\n getAuthenticatedProfileId: () => Promise<string>;\n /**\n * Returns the Auth API's approval and current recovery identifiers.\n * `requireTwoFactor` requests recent AAL2 authentication.\n */\n authorizeRecoveryRequest: (params: {\n requestHash: string;\n audiences: string[];\n requireTwoFactor?: boolean;\n }) => Promise<RecoveryApproval>;\n};\n\n/**\n * Obtains a key-bound identifier assertion from an IdP (OIDC, Passkey, SIWE).\n */\nexport type RecoveryIdentifierAuthProvider = {\n getKeyBoundIdentifierToken: (params: {\n identifier: Identifier;\n /**\n * Raw 32-byte Ed25519 public key to bind into the token.\n */\n proofPublicKey: Uint8Array;\n requestHash: string;\n }) => Promise<KeyBoundIdentifierToken>;\n};\n\n/**\n * One recovery escrow replica. Implementations may talk to different backends.\n */\nexport type RecoveryEscrowProvider = {\n readonly id: string;\n /**\n * Audience the AuthController token must carry for this escrow to accept it.\n * Independent of `id`.\n */\n readonly authAudience: string;\n /**\n * Raw 32-byte X25519 wrap public key. Mutation payloads are encrypted to this\n * key; `getSecret` responses are encrypted to the request's ephemeral key\n * using the corresponding wrap private key.\n */\n readonly wrapPublicKey: Uint8Array;\n isAvailable: () => Promise<boolean>;\n generateChallenge: (\n authControllerToken: AuthControllerToken,\n ) => Promise<PoPChallenge>;\n getIdentifiers: (\n authControllerToken: AuthControllerToken,\n ) => Promise<GetIdentifiersResponse>;\n getSecret: (\n authControllerToken: AuthControllerToken,\n authorization: IdentifierAuthorization,\n requestId: string,\n pkE: Uint8Array,\n ) => Promise<GetRecoverySecretResponse>;\n applyMutation: (\n mutation: Mutation,\n authControllerToken: AuthControllerToken,\n identifierAuthorization: IdentifierAuthorization | null,\n payload: MutationPayload,\n approvedIdentifiers: Identifier[],\n ) => Promise<MutationReceipt>;\n /**\n * Verifies a receipt cryptographically using the build-pinned receipt key\n * and confirms it targets the expected escrow.\n *\n * @param receipt - Receipt returned by an escrow.\n * @param mutation - Mutation acknowledged by the receipt.\n * @param expectedEscrowId - Escrow identity expected by the caller.\n */\n verifyReceipt: (\n receipt: MutationReceipt,\n mutation: Mutation,\n expectedEscrowId: string,\n ) => Promise<boolean>;\n};\n\n/**\n * Encrypts pending mutation state using wallet secure storage.\n */\nexport type PendingOperationEncryptor = {\n encrypt: (operation: PendingOperation) => Promise<EncryptedPendingOperation>;\n decrypt: (ciphertext: EncryptedPendingOperation) => Promise<PendingOperation>;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/mfa-recovery-controller",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-693aef2bf",
|
|
4
4
|
"description": "Manages MFA recovery flows across MetaMask clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -59,7 +59,6 @@
|
|
|
59
59
|
"@metamask/cryptography": "^1.1.2",
|
|
60
60
|
"@metamask/messenger": "^3.0.0",
|
|
61
61
|
"@metamask/profile-sync-controller": "^36.1.0",
|
|
62
|
-
"@metamask/seedless-onboarding-controller": "^12.0.0",
|
|
63
62
|
"@metamask/superstruct": "^3.4.1",
|
|
64
63
|
"@metamask/utils": "^12.0.1",
|
|
65
64
|
"json-stable-stringify": "^1.3.0"
|