@metamask-previews/mfa-recovery-controller 0.0.0-preview-3d6bb9b8e → 0.0.0-preview-eb5c879

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 CHANGED
@@ -12,14 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
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))
13
13
  - Requires recent, request-bound AAL2 approvals for writes and reads.
14
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))
15
- - Adds `getIdentifiers`, which returns the enrolled identifiers at the highest escrow version as `epoch` along with Auth's identifiers, for building `updateIdentifiers` calls ([#11149](https://github.com/MetaMask/core/pull/11149))
16
- - Passes the operation's AuthController token to `RecoveryEscrowProvider.generateChallenge`, and requires `RecoveryEscrowProvider.getIdentifiers` ([#11149](https://github.com/MetaMask/core/pull/11149))
17
15
  - Exports `MfaRecoveryController`, `getDefaultMfaRecoveryControllerState`, and the controller's action, event, messenger, state, and options types.
18
16
  - Exports `AuthApiRecoveryAuthProvider`, `AuthApiRecoveryAuthProviderOptions` and `AuthApiRecoveryAuthProviderMessenger` for requesting approvals through `AuthenticationController:requestMfaApproval`, using the profile id from `AuthenticationController:refreshCanonicalProfileId` ([#10883](https://github.com/MetaMask/core/pull/10883))
19
17
  - Exports `CubistEscrowProvider` and `CubistEscrowProviderOptions` for storing recovery secrets with CubeSigner.
20
18
  - Exports `MfaRecoveryError`, `IncompleteMutationError`, and `MutationRejectedError`.
21
19
  - Exports `MIN_IDENTIFIERS`, `IDENTIFIER_AUTH_MODES`, and `getIdentifierAuthMode` for identifier authentication.
22
- - Exports types for the recovery providers (`RecoveryAuthProvider`, `RecoveryIdentifierAuthProvider`, `RecoveryEscrowProvider`) and the pending operation encryptor (`PendingOperationEncryptor`), along with the related identifier, mutation, and recovery phase types, including `GetIdentifiersResponse` and `RecoveryIdentifiers` ([#11149](https://github.com/MetaMask/core/pull/11149))
20
+ - Exports types for the recovery providers (`RecoveryAuthProvider`, `RecoveryIdentifierAuthProvider`, `RecoveryEscrowProvider`) and the pending operation encryptor (`PendingOperationEncryptor`), along with the related identifier, mutation, and recovery phase types.
23
21
  - Add support for Node.js 26 ([#10981](https://github.com/MetaMask/core/pull/10981))
24
22
 
25
23
  ### Changed
package/README.md CHANGED
@@ -22,10 +22,6 @@ included): the controller rejects any other identifier before writing, and the
22
22
  mutation can then be aborted. Set `CubistEscrowProviderOptions.authAudience` to the escrow's
23
23
  `AUTH_CONTROLLER_AUDIENCE`.
24
24
 
25
- Before `updateIdentifiers`, call `getIdentifiers()` (AAL1) for the enrolled
26
- identifiers, their `epoch` (pass as `expectedEpoch`), and Auth's identifiers;
27
- build the new set from Auth's entries.
28
-
29
25
  ## Installation
30
26
 
31
27
  `yarn add @metamask/mfa-recovery-controller`
@@ -60,17 +60,6 @@ export type MfaRecoveryControllerGetRecoverySecretAction = {
60
60
  type: `MfaRecoveryController:getRecoverySecret`;
61
61
  handler: MfaRecoveryController['getRecoverySecret'];
62
62
  };
63
- /**
64
- * Reads the enrolled identifiers from available escrows at the highest
65
- * consistent version, with Auth's current identifiers. Needs no recent MFA,
66
- * so a new device can build an {@link updateIdentifiers} call from it.
67
- *
68
- * @returns Enrolled identifiers, `epoch`, and Auth's identifiers.
69
- */
70
- export type MfaRecoveryControllerGetIdentifiersAction = {
71
- type: `MfaRecoveryController:getIdentifiers`;
72
- handler: MfaRecoveryController['getIdentifiers'];
73
- };
74
63
  /**
75
64
  * Completes a persisted pending mutation, if any.
76
65
  */
@@ -95,5 +84,5 @@ export type MfaRecoveryControllerGetPhaseAction = {
95
84
  /**
96
85
  * Union of all MfaRecoveryController action types.
97
86
  */
98
- export type MfaRecoveryControllerMethodActions = MfaRecoveryControllerRegisterAction | MfaRecoveryControllerUpdateRecoverySecretAction | MfaRecoveryControllerUpdateIdentifiersAction | MfaRecoveryControllerAuthenticateIdentifierAction | MfaRecoveryControllerGetRecoverySecretAction | MfaRecoveryControllerGetIdentifiersAction | MfaRecoveryControllerResumeAction | MfaRecoveryControllerAbortAction | MfaRecoveryControllerGetPhaseAction;
87
+ export type MfaRecoveryControllerMethodActions = MfaRecoveryControllerRegisterAction | MfaRecoveryControllerUpdateRecoverySecretAction | MfaRecoveryControllerUpdateIdentifiersAction | MfaRecoveryControllerAuthenticateIdentifierAction | MfaRecoveryControllerGetRecoverySecretAction | MfaRecoveryControllerResumeAction | MfaRecoveryControllerAbortAction | MfaRecoveryControllerGetPhaseAction;
99
88
  //# sourceMappingURL=MfaRecoveryController-method-action-types.d.ts.map
@@ -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;;;;;GAKG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,qBAAqB,CAAC,wBAAwB,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,qBAAqB,CAAC,QAAQ,CAAC,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,qBAAqB,CAAC,UAAU,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
+ {"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,UA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{"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"]}
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 * 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 | 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 { Identifier, IdentifierSession, PendingOperationEncryptor, RecoveryAuthProvider, RecoveryEscrowProvider, RecoveryIdentifierAuthProvider, RecoveryIdentifiers, RecoveryPhase, RecoveredSecret } from './types.js';
5
+ import type { Identifier, IdentifierSession, PendingOperationEncryptor, RecoveryAuthProvider, RecoveryEscrowProvider, RecoveryIdentifierAuthProvider, RecoveryPhase, RecoveredSecret } from './types.js';
6
6
  declare const CONTROLLER_NAME = "MfaRecoveryController";
7
7
  export type MfaRecoveryControllerState = {
8
8
  /**
@@ -102,14 +102,6 @@ export declare class MfaRecoveryController extends BaseController<typeof CONTROL
102
102
  * @returns Recovered secret bytes and the selected epoch.
103
103
  */
104
104
  getRecoverySecret(session: IdentifierSession): Promise<RecoveredSecret>;
105
- /**
106
- * Reads the enrolled identifiers from available escrows at the highest
107
- * consistent version, with Auth's current identifiers. Needs no recent MFA,
108
- * so a new device can build an {@link updateIdentifiers} call from it.
109
- *
110
- * @returns Enrolled identifiers, `epoch`, and Auth's identifiers.
111
- */
112
- getIdentifiers(): Promise<RecoveryIdentifiers>;
113
105
  /**
114
106
  * Completes a persisted pending mutation, if any.
115
107
  */
@@ -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;AAgCrD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,gDAAgD,CAAC;AAOzG,OAAO,KAAK,EAEV,UAAU,EACV,iBAAiB,EAKjB,yBAAyB,EAIzB,oBAAoB,EACpB,sBAAsB,EACtB,8BAA8B,EAC9B,mBAAmB,EACnB,aAAa,EACb,eAAe,EAGhB,MAAM,YAAY,CAAC;AAEpB,QAAA,MAAM,eAAe,0BAA0B,CAAC;AAchD,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,CAAC;AAWF;;GAEG;AACH,wBAAgB,oCAAoC,IAAI,0BAA0B,CAEjF;AAED,MAAM,MAAM,mCAAmC,GAAG,wBAAwB,CACxE,OAAO,eAAe,EACtB,0BAA0B,CAC3B,CAAC;AAEF,MAAM,MAAM,4BAA4B,GACpC,mCAAmC,GACnC,kCAAkC,CAAC;AAEvC,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B,MAAM,MAAM,sCAAsC,GAChD,2BAA2B,CACzB,OAAO,eAAe,EACtB,0BAA0B,CAC3B,CAAC;AAEJ,MAAM,MAAM,2BAA2B,GACrC,sCAAsC,CAAC;AAEzC,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,8BAA8B,GAAG,SAAS,CACpD,OAAO,eAAe,EACtB,4BAA4B,GAAG,cAAc,EAC7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M,GACZ,OAAO,CAAC,IAAI,CAAC,CASf;IAED;;;;;OAKG;IACG,sBAAsB,CAC1B,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,iBAAiB,CAAC,CAqB5B;IAED;;;;;;;;OAQG;IACG,iBAAiB,CACrB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,eAAe,CAAC,CA+D1B;IAED;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAI5B;IAED;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAQ3B;IAED;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,CAIvC;CAkXF"}
@@ -14,7 +14,6 @@ const MESSENGER_EXPOSED_METHODS = [
14
14
  'updateIdentifiers',
15
15
  'authenticateIdentifier',
16
16
  'getRecoverySecret',
17
- 'getIdentifiers',
18
17
  'resume',
19
18
  'abort',
20
19
  'getPhase',
@@ -184,7 +183,6 @@ export class MfaRecoveryController extends BaseController {
184
183
  const authorizedEscrows = await authorizeEscrowsWithToken({
185
184
  escrows: available,
186
185
  credential: session,
187
- authControllerToken: approval,
188
186
  });
189
187
  const results = await Promise.allSettled(authorizedEscrows.map(async ({ escrow, authorization }) => {
190
188
  const response = await escrow.getSecret(approval, authorization, requestId, pkE);
@@ -205,38 +203,6 @@ export class MfaRecoveryController extends BaseController {
205
203
  };
206
204
  });
207
205
  }
208
- /**
209
- * Reads the enrolled identifiers from available escrows at the highest
210
- * consistent version, with Auth's current identifiers. Needs no recent MFA,
211
- * so a new device can build an {@link updateIdentifiers} call from it.
212
- *
213
- * @returns Enrolled identifiers, `epoch`, and Auth's identifiers.
214
- */
215
- async getIdentifiers() {
216
- return await this.#withLock(async () => {
217
- const available = await this.#getAvailableEscrows();
218
- if (available.length === 0) {
219
- throw new MfaRecoveryError('No escrow is available', 'no_available_escrow');
220
- }
221
- const { approval, identifiers: authIdentifiers } = await this.#authProvider.authorizeRecoveryRequest({
222
- requestHash: await hash({ operation: 'getIdentifiers' }),
223
- audiences: available.map((escrow) => escrow.authAudience),
224
- });
225
- const responses = (await Promise.allSettled(available.map(async (escrow) => await escrow.getIdentifiers(approval))))
226
- .filter(isFulfilledResult)
227
- .map((result) => result.value);
228
- if (responses.length === 0) {
229
- throw new MfaRecoveryError('No escrow returned identifiers', 'read_failed');
230
- }
231
- const epoch = Math.max(...responses.map(({ version }) => version));
232
- const highest = responses.filter(({ version }) => version === epoch);
233
- const hashes = await Promise.all(highest.map(async ({ identifiers }) => await hash(identifiers)));
234
- if (new Set(hashes).size !== 1) {
235
- throw new MfaRecoveryError('Replica corruption', 'replica_corruption');
236
- }
237
- return { identifiers: highest[0].identifiers, epoch, authIdentifiers };
238
- });
239
- }
240
206
  /**
241
207
  * Completes a persisted pending mutation, if any.
242
208
  */
@@ -347,7 +313,6 @@ export class MfaRecoveryController extends BaseController {
347
313
  escrows: remainingEscrows,
348
314
  identifier: identifier,
349
315
  requestHash: mutation.requestHash,
350
- authControllerToken: writing.authControllerToken,
351
316
  });
352
317
  if (authorizedEscrows !== null &&
353
318
  authorizedEscrows.length !== remainingEscrows.length) {
@@ -415,18 +380,14 @@ export class MfaRecoveryController extends BaseController {
415
380
  }
416
381
  return { receipts, hasInvalidReceipt };
417
382
  }
418
- async #authorizeEscrows({ escrows, identifier, requestHash, authControllerToken, }) {
383
+ async #authorizeEscrows({ escrows, identifier, requestHash, }) {
419
384
  getIdentifierAuthMode(identifier.type);
420
385
  const credential = await requestKeyBoundIdentifierToken({
421
386
  identifier,
422
387
  requestHash,
423
388
  identifierAuthProvider: this.#identifierAuthProvider,
424
389
  });
425
- return await authorizeEscrowsWithToken({
426
- escrows,
427
- credential,
428
- authControllerToken,
429
- });
390
+ return await authorizeEscrowsWithToken({ escrows, credential });
430
391
  }
431
392
  async #payloadForEscrow(pending, escrow) {
432
393
  const { payload } = pending;
@@ -1 +1 @@
1
- {"version":3,"file":"MfaRecoveryController.js","sourceRoot":"","sources":["../src/MfaRecovery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AE,CAAC,CACzC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,SAAS,CACb,EAA8B;QAE9B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,CACnB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;QACF,OAAO,MAAM,GAAG,CAAC;IACnB,CAAC;CACF;AAED;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,OAAgD,EAChD,gBAAmC;IAEnC,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,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 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
+ {"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;AAqB1E,MAA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AC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,SAAS,CACb,EAA8B;QAE9B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,CACnB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;QACF,OAAO,MAAM,GAAG,CAAC;IACnB,CAAC;CACF;AAED;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,OAAgD,EAChD,gBAAmC;IAEnC,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,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 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 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 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 '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 });\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 * 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 });\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 }: {\n escrows: RecoveryEscrowProvider[];\n identifier: Identifier;\n requestHash: string;\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({ escrows, credential });\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,5 +1,5 @@
1
1
  import type { CubeSignerClient, Version } from '@cubist-labs/cubesigner-sdk';
2
- import type { AuthControllerToken, GetIdentifiersResponse, GetRecoverySecretResponse, Identifier, IdentifierAuthorization, Mutation, MutationPayload, MutationReceipt, PoPChallenge, RecoveryEscrowProvider } from '../types.js';
2
+ import type { AuthControllerToken, GetRecoverySecretResponse, Identifier, IdentifierAuthorization, Mutation, MutationPayload, MutationReceipt, PoPChallenge, RecoveryEscrowProvider } from '../types.js';
3
3
  /**
4
4
  * CubeSigner C2F client for the Cubist recovery escrow.
5
5
  *
@@ -48,15 +48,9 @@ export declare class CubistEscrowProvider implements RecoveryEscrowProvider {
48
48
  */
49
49
  isAvailable(): Promise<boolean>;
50
50
  /**
51
- * @param authControllerToken - Approval for the profile the challenge is for.
52
51
  * @returns A proof-of-possession challenge for this escrow.
53
52
  */
54
- generateChallenge(authControllerToken: AuthControllerToken): Promise<PoPChallenge>;
55
- /**
56
- * @param authControllerToken - Approval for the profile to read.
57
- * @returns The enrolled identifiers and record version.
58
- */
59
- getIdentifiers(authControllerToken: AuthControllerToken): Promise<GetIdentifiersResponse>;
53
+ generateChallenge(): Promise<PoPChallenge>;
60
54
  /**
61
55
  * @param authControllerToken - Request-bound approval for this read.
62
56
  * @param authorization - Identifier proof for this read.
@@ -1 +1 @@
1
- {"version":3,"file":"cubist-escrow-provider.d.ts","sourceRoot":"","sources":["../../src/escrow-providers/cubist-escrow-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAEhB,OAAO,EACR,MAAM,6BAA6B,CAAC;AAwBrC,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,EACzB,UAAU,EACV,uBAAuB,EACvB,QAAQ,EACR,eAAe,EACf,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAMrB;;;;;;;GAOG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAAC;IACzB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,aAAa,EAAE,UAAU,CAAC;IAC1B;;OAEG;IACH,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CAAC;AAEF,qBAAa,oBAAqB,YAAW,sBAAsB;;IACjE,QAAQ,CAAC,EAAE,YAAa;IAExB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IAUnC;;OAEG;IACH,YAAY,OAAO,EAAE,2BAA2B,EAO/C;IAED;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAOpC;IAED;;;OAGG;IACG,iBAAiB,CACrB,mBAAmB,EAAE,mBAAmB,GACvC,OAAO,CAAC,YAAY,CAAC,CAMvB;IAED;;;OAGG;IACG,cAAc,CAClB,mBAAmB,EAAE,mBAAmB,GACvC,OAAO,CAAC,sBAAsB,CAAC,CAMjC;IAED;;;;;;OAMG;IACG,SAAS,CACb,mBAAmB,EAAE,mBAAmB,EACxC,aAAa,EAAE,uBAAuB,EACtC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,yBAAyB,CAAC,CAWpC;IAED;;;;;;;;OAQG;IACG,aAAa,CACjB,QAAQ,EAAE,QAAQ,EAClB,mBAAmB,EAAE,mBAAmB,EACxC,uBAAuB,EAAE,uBAAuB,GAAG,IAAI,EACvD,OAAO,EAAE,eAAe,EACxB,mBAAmB,EAAE,UAAU,EAAE,GAChC,OAAO,CAAC,eAAe,CAAC,CAa1B;IAED;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,OAAO,CAAC,CAsBlB;CA0CF"}
1
+ {"version":3,"file":"cubist-escrow-provider.d.ts","sourceRoot":"","sources":["../../src/escrow-providers/cubist-escrow-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAEhB,OAAO,EACR,MAAM,6BAA6B,CAAC;AAgBrC,OAAO,KAAK,EACV,mBAAmB,EACnB,yBAAyB,EACzB,UAAU,EACV,uBAAuB,EACvB,QAAQ,EACR,eAAe,EACf,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAMrB;;;;;;;GAOG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAAC;IACzB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,aAAa,EAAE,UAAU,CAAC;IAC1B;;OAEG;IACH,gBAAgB,EAAE,UAAU,CAAC;CAC9B,CAAC;AAEF,qBAAa,oBAAqB,YAAW,sBAAsB;;IACjE,QAAQ,CAAC,EAAE,YAAa;IAExB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IAUnC;;OAEG;IACH,YAAY,OAAO,EAAE,2BAA2B,EAO/C;IAED;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAOpC;IAED;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,YAAY,CAAC,CAE/C;IAED;;;;;;OAMG;IACG,SAAS,CACb,mBAAmB,EAAE,mBAAmB,EACxC,aAAa,EAAE,uBAAuB,EACtC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,yBAAyB,CAAC,CAWpC;IAED;;;;;;;;OAQG;IACG,aAAa,CACjB,QAAQ,EAAE,QAAQ,EAClB,mBAAmB,EAAE,mBAAmB,EACxC,uBAAuB,EAAE,uBAAuB,GAAG,IAAI,EACvD,OAAO,EAAE,eAAe,EACxB,mBAAmB,EAAE,UAAU,EAAE,GAChC,OAAO,CAAC,eAAe,CAAC,CAa1B;IAED;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,OAAO,CAAC,CAsBlB;CA0CF"}
@@ -1,4 +1,4 @@
1
- import { array, integer, is, literal, min, string, type, } from '@metamask/superstruct';
1
+ import { integer, is, literal, min, string, type } from '@metamask/superstruct';
2
2
  import { bytesToHex, bytesToString, hexToBytes, isStrictHexString, } from '@metamask/utils';
3
3
  import { hashMutationReceipt, receiptKeyId, verifySignature, } from '../crypto.js';
4
4
  import { MfaRecoveryError, MutationRejectedError } from '../errors.js';
@@ -38,18 +38,10 @@ export class CubistEscrowProvider {
38
38
  }
39
39
  }
40
40
  /**
41
- * @param authControllerToken - Approval for the profile the challenge is for.
42
41
  * @returns A proof-of-possession challenge for this escrow.
43
42
  */
44
- async generateChallenge(authControllerToken) {
45
- return await this.#invoke('generateChallenge', { authControllerToken }, parseChallenge);
46
- }
47
- /**
48
- * @param authControllerToken - Approval for the profile to read.
49
- * @returns The enrolled identifiers and record version.
50
- */
51
- async getIdentifiers(authControllerToken) {
52
- return await this.#invoke('getIdentifiers', { authControllerToken }, parseIdentifiers);
43
+ async generateChallenge() {
44
+ return await this.#invoke('generateChallenge', {}, parseChallenge);
53
45
  }
54
46
  /**
55
47
  * @param authControllerToken - Request-bound approval for this read.
@@ -142,10 +134,6 @@ const ChallengeStruct = type({
142
134
  escrowId: literal(ESCROW_ID),
143
135
  expiresAt: integer(),
144
136
  });
145
- const IdentifiersStruct = type({
146
- identifiers: array(type({ type: string(), namespace: string(), value: string() })),
147
- version: min(integer(), 0),
148
- });
149
137
  const GetSecretResponseStruct = type({
150
138
  recoverySecret: type({ ciphertext: string() }),
151
139
  version: min(integer(), 0),
@@ -167,12 +155,6 @@ function parseChallenge(value) {
167
155
  expiresAt: value.expiresAt,
168
156
  };
169
157
  }
170
- function parseIdentifiers(value) {
171
- if (!is(value, IdentifiersStruct)) {
172
- throw new MfaRecoveryError('Invalid identifiers response', 'escrow_response_invalid');
173
- }
174
- return { identifiers: value.identifiers, version: value.version };
175
- }
176
158
  /**
177
159
  * Encodes a request for the escrow wire: every byte field becomes a 0x-prefixed
178
160
  * hex string. Typed arrays have no `toJSON`, so the replacer sees them directly.
@@ -1 +1 @@
1
- {"version":3,"file":"cubist-escrow-provider.js","sourceRoot":"","sources":["../../src/escrow-providers/cubist-escrow-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,EACL,OAAO,EACP,EAAE,EACF,OAAO,EACP,GAAG,EACH,MAAM,EACN,IAAI,GACL,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB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Ac,EAAE;YACd,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC;SACxD;QACD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,gBAAgB,CACxB,0BAA0B,EAC1B,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type {\n CubeSignerClient,\n InvokePolicyResponse,\n Version,\n} from '@cubist-labs/cubesigner-sdk';\nimport {\n array,\n integer,\n is,\n literal,\n min,\n string,\n type,\n} from '@metamask/superstruct';\nimport {\n bytesToHex,\n bytesToString,\n hexToBytes,\n isStrictHexString,\n} from '@metamask/utils';\n\nimport {\n hashMutationReceipt,\n receiptKeyId,\n verifySignature,\n} from '../crypto.js';\nimport { MfaRecoveryError, MutationRejectedError } from '../errors.js';\nimport { isMutationReceipt } from '../escrow-utils.js';\nimport type {\n AuthControllerToken,\n GetIdentifiersResponse,\n GetRecoverySecretResponse,\n Identifier,\n IdentifierAuthorization,\n Mutation,\n MutationPayload,\n MutationReceipt,\n PoPChallenge,\n RecoveryEscrowProvider,\n} from '../types.js';\n\nconst ESCROW_ID = 'cubist';\nconst DEFAULT_FUNCTION_ID = 'cubist_secret_escrow';\nconst DEFAULT_VERSION: Version = 'latest';\n\n/**\n * CubeSigner C2F client for the Cubist recovery escrow.\n *\n * Commands are sent with `policyInvoke` as `{ cmd, ...fields }` on\n * `cubist_secret_escrow`.\n * Escrow JSON is read from C2F stdout. Receipt signatures are checked locally\n * with the pinned receipt public key.\n */\nexport type CubistEscrowProviderOptions = {\n /**\n * Authenticated CubeSigner client used to invoke the escrow C2F.\n */\n client: CubeSignerClient;\n /**\n * Must match the escrow's AUTH_CONTROLLER_AUDIENCE configuration.\n */\n authAudience: string;\n /**\n * C2F name or named-policy id. Defaults to `cubist_secret_escrow`.\n */\n functionId?: string;\n /**\n * C2F version to invoke. Defaults to `latest`.\n */\n version?: Version;\n /**\n * Raw 32-byte X25519 public key of the escrow wrap key.\n */\n wrapPublicKey: Uint8Array;\n /**\n * Raw 32-byte Ed25519 public key of the escrow receipt key.\n */\n receiptPublicKey: Uint8Array;\n};\n\nexport class CubistEscrowProvider implements RecoveryEscrowProvider {\n readonly id = ESCROW_ID;\n\n readonly authAudience: string;\n\n readonly wrapPublicKey: Uint8Array;\n\n readonly #receiptPublicKey: Uint8Array;\n\n readonly #client: CubeSignerClient;\n\n readonly #functionId: string;\n\n readonly #version: Version;\n\n /**\n * @param options - CubeSigner client, pinned keys, and optional C2F id/version.\n */\n constructor(options: CubistEscrowProviderOptions) {\n this.authAudience = options.authAudience;\n this.wrapPublicKey = options.wrapPublicKey;\n this.#receiptPublicKey = options.receiptPublicKey;\n this.#client = options.client;\n this.#functionId = options.functionId ?? DEFAULT_FUNCTION_ID;\n this.#version = options.version ?? DEFAULT_VERSION;\n }\n\n /**\n * @returns Whether a ping of the escrow C2F is allowed and reports ok.\n */\n async isAvailable(): Promise<boolean> {\n try {\n await this.#invoke('ping', {}, parsePing);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * @param authControllerToken - Approval for the profile the challenge is for.\n * @returns A proof-of-possession challenge for this escrow.\n */\n async generateChallenge(\n authControllerToken: AuthControllerToken,\n ): Promise<PoPChallenge> {\n return await this.#invoke(\n 'generateChallenge',\n { authControllerToken },\n parseChallenge,\n );\n }\n\n /**\n * @param authControllerToken - Approval for the profile to read.\n * @returns The enrolled identifiers and record version.\n */\n async getIdentifiers(\n authControllerToken: AuthControllerToken,\n ): Promise<GetIdentifiersResponse> {\n return await this.#invoke(\n 'getIdentifiers',\n { authControllerToken },\n parseIdentifiers,\n );\n }\n\n /**\n * @param authControllerToken - Request-bound approval for this read.\n * @param authorization - Identifier proof for this read.\n * @param requestId - Client request id bound into the read hash.\n * @param pkE - Ephemeral wrap public key for the response.\n * @returns The wrapped recovery secret and its version.\n */\n async getSecret(\n authControllerToken: AuthControllerToken,\n authorization: IdentifierAuthorization,\n requestId: string,\n pkE: Uint8Array,\n ): Promise<GetRecoverySecretResponse> {\n return await this.#invoke(\n 'getSecret',\n {\n identifierAuthorization: authorization,\n requestId,\n pkE,\n authControllerToken,\n },\n parseGetSecretResponse,\n );\n }\n\n /**\n * @param mutation - Mutation to apply.\n * @param authControllerToken - Request-bound AuthController token.\n * @param identifierAuthorization - Identifier proof. `null` for register.\n * @param payload - Per-escrow mutation payload.\n * @param approvedIdentifiers - The approval's identifiers, which payload\n * identifiers must be drawn from.\n * @returns The escrow's mutation receipt.\n */\n async applyMutation(\n mutation: Mutation,\n authControllerToken: AuthControllerToken,\n identifierAuthorization: IdentifierAuthorization | null,\n payload: MutationPayload,\n approvedIdentifiers: Identifier[],\n ): Promise<MutationReceipt> {\n return await this.#invoke(\n 'applyMutation',\n {\n mutation,\n authControllerToken,\n identifierAuthorization,\n payload,\n approvedIdentifiers,\n },\n parseReceipt,\n true, // a policy Deny did not apply the mutation\n );\n }\n\n /**\n * Verifies a receipt with the pinned receipt public key.\n *\n * @param receipt - Receipt returned by the escrow.\n * @param mutation - Mutation the receipt must acknowledge.\n * @param expectedEscrowId - Escrow identity expected by the caller.\n * @returns Whether the receipt is valid for this escrow.\n */\n async verifyReceipt(\n receipt: MutationReceipt,\n mutation: Mutation,\n expectedEscrowId: string,\n ): Promise<boolean> {\n if (\n receipt.mutationId !== mutation.id ||\n receipt.requestHash !== mutation.requestHash ||\n receipt.escrowId !== expectedEscrowId ||\n expectedEscrowId !== this.id ||\n receipt.version !== mutation.newVersion ||\n receipt.receiptKeyId !== (await receiptKeyId(this.#receiptPublicKey))\n ) {\n return false;\n }\n return await verifySignature(\n this.#receiptPublicKey,\n receipt.signature,\n await hashMutationReceipt({\n escrowId: receipt.escrowId,\n mutationId: receipt.mutationId,\n receiptKeyId: receipt.receiptKeyId,\n requestHash: receipt.requestHash,\n version: receipt.version,\n }),\n );\n }\n\n async #invoke<Result>(\n cmd: string,\n body: Record<string, unknown>,\n parse: (value: unknown) => Result,\n denyIsRejection = false,\n ): Promise<Result> {\n let invocation: InvokePolicyResponse;\n try {\n invocation = await this.#client.apiClient.policyInvoke(\n this.#functionId,\n this.#version,\n { request: toWire({ cmd, ...body }) },\n );\n } catch (error) {\n throw new MfaRecoveryError(\n error instanceof Error ? error.message : 'Escrow request failed',\n 'escrow_request_failed',\n );\n }\n const policy = invocation.response;\n if (policy.response !== 'Allow') {\n if (denyIsRejection && policy.response === 'Deny') {\n throw new MutationRejectedError(policy.reason);\n }\n throw new MfaRecoveryError(\n policy.response === 'Deny' ? policy.reason : policy.error,\n 'escrow_request_failed',\n );\n }\n let json: unknown;\n try {\n json = JSON.parse(bytesToString(hexToBytes(invocation.stdout)));\n } catch {\n throw new MfaRecoveryError(\n 'Escrow response was not JSON',\n 'escrow_response_invalid',\n );\n }\n return parse(json);\n }\n}\n\n// `type()` is non-strict, so unknown fields are ignored. The explicit field\n// mapping below still strips them from the returned value.\nconst PingStruct = type({ ok: literal(true) });\n\nconst ChallengeStruct = type({\n id: string(),\n escrowId: literal(ESCROW_ID),\n expiresAt: integer(),\n});\n\nconst IdentifiersStruct = type({\n identifiers: array(\n type({ type: string(), namespace: string(), value: string() }),\n ),\n version: min(integer(), 0),\n});\n\nconst GetSecretResponseStruct = type({\n recoverySecret: type({ ciphertext: string() }),\n version: min(integer(), 0),\n lastMutationId: string(),\n wrapKeyId: string(),\n});\n\nfunction parsePing(value: unknown): void {\n if (!is(value, PingStruct)) {\n throw new MfaRecoveryError(\n 'Invalid ping response',\n 'escrow_response_invalid',\n );\n }\n}\n\nfunction parseChallenge(value: unknown): PoPChallenge {\n if (!is(value, ChallengeStruct)) {\n throw new MfaRecoveryError(\n 'Invalid PoP challenge',\n 'escrow_response_invalid',\n );\n }\n return {\n id: value.id,\n escrowId: value.escrowId,\n expiresAt: value.expiresAt,\n };\n}\n\nfunction parseIdentifiers(value: unknown): GetIdentifiersResponse {\n if (!is(value, IdentifiersStruct)) {\n throw new MfaRecoveryError(\n 'Invalid identifiers response',\n 'escrow_response_invalid',\n );\n }\n return { identifiers: value.identifiers, version: value.version };\n}\n\n/**\n * Encodes a request for the escrow wire: every byte field becomes a 0x-prefixed\n * hex string. Typed arrays have no `toJSON`, so the replacer sees them directly.\n *\n * @param value - Request body.\n * @returns JSON-compatible request body.\n */\nfunction toWire(value: Record<string, unknown>): Record<string, unknown> {\n return JSON.parse(\n JSON.stringify(value, (_key, node: unknown) =>\n node instanceof Uint8Array ? bytesToHex(node) : node,\n ),\n ) as Record<string, unknown>;\n}\n\nfunction parseGetSecretResponse(value: unknown): GetRecoverySecretResponse {\n if (\n !is(value, GetSecretResponseStruct) ||\n !isStrictHexString(value.recoverySecret.ciphertext)\n ) {\n throw new MfaRecoveryError(\n 'Invalid recovery secret response',\n 'escrow_response_invalid',\n );\n }\n return {\n recoverySecret: {\n ciphertext: hexToBytes(value.recoverySecret.ciphertext),\n },\n version: value.version,\n lastMutationId: value.lastMutationId,\n wrapKeyId: value.wrapKeyId,\n };\n}\n\nfunction parseReceipt(value: unknown): MutationReceipt {\n if (!isMutationReceipt(value)) {\n throw new MfaRecoveryError(\n 'Invalid mutation receipt',\n 'escrow_response_invalid',\n );\n }\n return value;\n}\n"]}
1
+ {"version":3,"file":"cubist-escrow-provider.js","sourceRoot":"","sources":["../../src/escrow-providers/cubist-escrow-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EAC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IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAa,EAAE,EAAE,CAC5C,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CACrD,CACyB,CAAC;AAC/B,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAc;IAC5C,IACE,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,CAAC;QACnC,CAAC,iBAAiB,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,EACnD,CAAC;QACD,MAAM,IAAI,gBAAgB,CACxB,kCAAkC,EAClC,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IACD,OAAO;QACL,cAAc,EAAE;YACd,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC;SACxD;QACD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,gBAAgB,CACxB,0BAA0B,EAC1B,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type {\n CubeSignerClient,\n InvokePolicyResponse,\n Version,\n} from '@cubist-labs/cubesigner-sdk';\nimport { integer, is, literal, min, string, type } from '@metamask/superstruct';\nimport {\n bytesToHex,\n bytesToString,\n hexToBytes,\n isStrictHexString,\n} from '@metamask/utils';\n\nimport {\n hashMutationReceipt,\n receiptKeyId,\n verifySignature,\n} from '../crypto.js';\nimport { MfaRecoveryError, MutationRejectedError } from '../errors.js';\nimport { isMutationReceipt } from '../escrow-utils.js';\nimport type {\n AuthControllerToken,\n GetRecoverySecretResponse,\n Identifier,\n IdentifierAuthorization,\n Mutation,\n MutationPayload,\n MutationReceipt,\n PoPChallenge,\n RecoveryEscrowProvider,\n} from '../types.js';\n\nconst ESCROW_ID = 'cubist';\nconst DEFAULT_FUNCTION_ID = 'cubist_secret_escrow';\nconst DEFAULT_VERSION: Version = 'latest';\n\n/**\n * CubeSigner C2F client for the Cubist recovery escrow.\n *\n * Commands are sent with `policyInvoke` as `{ cmd, ...fields }` on\n * `cubist_secret_escrow`.\n * Escrow JSON is read from C2F stdout. Receipt signatures are checked locally\n * with the pinned receipt public key.\n */\nexport type CubistEscrowProviderOptions = {\n /**\n * Authenticated CubeSigner client used to invoke the escrow C2F.\n */\n client: CubeSignerClient;\n /**\n * Must match the escrow's AUTH_CONTROLLER_AUDIENCE configuration.\n */\n authAudience: string;\n /**\n * C2F name or named-policy id. Defaults to `cubist_secret_escrow`.\n */\n functionId?: string;\n /**\n * C2F version to invoke. Defaults to `latest`.\n */\n version?: Version;\n /**\n * Raw 32-byte X25519 public key of the escrow wrap key.\n */\n wrapPublicKey: Uint8Array;\n /**\n * Raw 32-byte Ed25519 public key of the escrow receipt key.\n */\n receiptPublicKey: Uint8Array;\n};\n\nexport class CubistEscrowProvider implements RecoveryEscrowProvider {\n readonly id = ESCROW_ID;\n\n readonly authAudience: string;\n\n readonly wrapPublicKey: Uint8Array;\n\n readonly #receiptPublicKey: Uint8Array;\n\n readonly #client: CubeSignerClient;\n\n readonly #functionId: string;\n\n readonly #version: Version;\n\n /**\n * @param options - CubeSigner client, pinned keys, and optional C2F id/version.\n */\n constructor(options: CubistEscrowProviderOptions) {\n this.authAudience = options.authAudience;\n this.wrapPublicKey = options.wrapPublicKey;\n this.#receiptPublicKey = options.receiptPublicKey;\n this.#client = options.client;\n this.#functionId = options.functionId ?? DEFAULT_FUNCTION_ID;\n this.#version = options.version ?? DEFAULT_VERSION;\n }\n\n /**\n * @returns Whether a ping of the escrow C2F is allowed and reports ok.\n */\n async isAvailable(): Promise<boolean> {\n try {\n await this.#invoke('ping', {}, parsePing);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * @returns A proof-of-possession challenge for this escrow.\n */\n async generateChallenge(): Promise<PoPChallenge> {\n return await this.#invoke('generateChallenge', {}, parseChallenge);\n }\n\n /**\n * @param authControllerToken - Request-bound approval for this read.\n * @param authorization - Identifier proof for this read.\n * @param requestId - Client request id bound into the read hash.\n * @param pkE - Ephemeral wrap public key for the response.\n * @returns The wrapped recovery secret and its version.\n */\n async getSecret(\n authControllerToken: AuthControllerToken,\n authorization: IdentifierAuthorization,\n requestId: string,\n pkE: Uint8Array,\n ): Promise<GetRecoverySecretResponse> {\n return await this.#invoke(\n 'getSecret',\n {\n identifierAuthorization: authorization,\n requestId,\n pkE,\n authControllerToken,\n },\n parseGetSecretResponse,\n );\n }\n\n /**\n * @param mutation - Mutation to apply.\n * @param authControllerToken - Request-bound AuthController token.\n * @param identifierAuthorization - Identifier proof. `null` for register.\n * @param payload - Per-escrow mutation payload.\n * @param approvedIdentifiers - The approval's identifiers, which payload\n * identifiers must be drawn from.\n * @returns The escrow's mutation receipt.\n */\n async applyMutation(\n mutation: Mutation,\n authControllerToken: AuthControllerToken,\n identifierAuthorization: IdentifierAuthorization | null,\n payload: MutationPayload,\n approvedIdentifiers: Identifier[],\n ): Promise<MutationReceipt> {\n return await this.#invoke(\n 'applyMutation',\n {\n mutation,\n authControllerToken,\n identifierAuthorization,\n payload,\n approvedIdentifiers,\n },\n parseReceipt,\n true, // a policy Deny did not apply the mutation\n );\n }\n\n /**\n * Verifies a receipt with the pinned receipt public key.\n *\n * @param receipt - Receipt returned by the escrow.\n * @param mutation - Mutation the receipt must acknowledge.\n * @param expectedEscrowId - Escrow identity expected by the caller.\n * @returns Whether the receipt is valid for this escrow.\n */\n async verifyReceipt(\n receipt: MutationReceipt,\n mutation: Mutation,\n expectedEscrowId: string,\n ): Promise<boolean> {\n if (\n receipt.mutationId !== mutation.id ||\n receipt.requestHash !== mutation.requestHash ||\n receipt.escrowId !== expectedEscrowId ||\n expectedEscrowId !== this.id ||\n receipt.version !== mutation.newVersion ||\n receipt.receiptKeyId !== (await receiptKeyId(this.#receiptPublicKey))\n ) {\n return false;\n }\n return await verifySignature(\n this.#receiptPublicKey,\n receipt.signature,\n await hashMutationReceipt({\n escrowId: receipt.escrowId,\n mutationId: receipt.mutationId,\n receiptKeyId: receipt.receiptKeyId,\n requestHash: receipt.requestHash,\n version: receipt.version,\n }),\n );\n }\n\n async #invoke<Result>(\n cmd: string,\n body: Record<string, unknown>,\n parse: (value: unknown) => Result,\n denyIsRejection = false,\n ): Promise<Result> {\n let invocation: InvokePolicyResponse;\n try {\n invocation = await this.#client.apiClient.policyInvoke(\n this.#functionId,\n this.#version,\n { request: toWire({ cmd, ...body }) },\n );\n } catch (error) {\n throw new MfaRecoveryError(\n error instanceof Error ? error.message : 'Escrow request failed',\n 'escrow_request_failed',\n );\n }\n const policy = invocation.response;\n if (policy.response !== 'Allow') {\n if (denyIsRejection && policy.response === 'Deny') {\n throw new MutationRejectedError(policy.reason);\n }\n throw new MfaRecoveryError(\n policy.response === 'Deny' ? policy.reason : policy.error,\n 'escrow_request_failed',\n );\n }\n let json: unknown;\n try {\n json = JSON.parse(bytesToString(hexToBytes(invocation.stdout)));\n } catch {\n throw new MfaRecoveryError(\n 'Escrow response was not JSON',\n 'escrow_response_invalid',\n );\n }\n return parse(json);\n }\n}\n\n// `type()` is non-strict, so unknown fields are ignored. The explicit field\n// mapping below still strips them from the returned value.\nconst PingStruct = type({ ok: literal(true) });\n\nconst ChallengeStruct = type({\n id: string(),\n escrowId: literal(ESCROW_ID),\n expiresAt: integer(),\n});\n\nconst GetSecretResponseStruct = type({\n recoverySecret: type({ ciphertext: string() }),\n version: min(integer(), 0),\n lastMutationId: string(),\n wrapKeyId: string(),\n});\n\nfunction parsePing(value: unknown): void {\n if (!is(value, PingStruct)) {\n throw new MfaRecoveryError(\n 'Invalid ping response',\n 'escrow_response_invalid',\n );\n }\n}\n\nfunction parseChallenge(value: unknown): PoPChallenge {\n if (!is(value, ChallengeStruct)) {\n throw new MfaRecoveryError(\n 'Invalid PoP challenge',\n 'escrow_response_invalid',\n );\n }\n return {\n id: value.id,\n escrowId: value.escrowId,\n expiresAt: value.expiresAt,\n };\n}\n\n/**\n * Encodes a request for the escrow wire: every byte field becomes a 0x-prefixed\n * hex string. Typed arrays have no `toJSON`, so the replacer sees them directly.\n *\n * @param value - Request body.\n * @returns JSON-compatible request body.\n */\nfunction toWire(value: Record<string, unknown>): Record<string, unknown> {\n return JSON.parse(\n JSON.stringify(value, (_key, node: unknown) =>\n node instanceof Uint8Array ? bytesToHex(node) : node,\n ),\n ) as Record<string, unknown>;\n}\n\nfunction parseGetSecretResponse(value: unknown): GetRecoverySecretResponse {\n if (\n !is(value, GetSecretResponseStruct) ||\n !isStrictHexString(value.recoverySecret.ciphertext)\n ) {\n throw new MfaRecoveryError(\n 'Invalid recovery secret response',\n 'escrow_response_invalid',\n );\n }\n return {\n recoverySecret: {\n ciphertext: hexToBytes(value.recoverySecret.ciphertext),\n },\n version: value.version,\n lastMutationId: value.lastMutationId,\n wrapKeyId: value.wrapKeyId,\n };\n}\n\nfunction parseReceipt(value: unknown): MutationReceipt {\n if (!isMutationReceipt(value)) {\n throw new MfaRecoveryError(\n 'Invalid mutation receipt',\n 'escrow_response_invalid',\n );\n }\n return value;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { AuthControllerToken, Identifier, IdentifierAuthMode, IdentifierAuthorization, KeyBoundCredential, RecoveryEscrowProvider, RecoveryIdentifierAuthProvider } from './types.js';
1
+ import type { Identifier, IdentifierAuthMode, IdentifierAuthorization, KeyBoundCredential, RecoveryEscrowProvider, RecoveryIdentifierAuthProvider } from './types.js';
2
2
  /**
3
3
  * Minimum identifier count for register and updateIdentifiers.
4
4
  */
@@ -43,14 +43,11 @@ export declare function requestKeyBoundIdentifierToken({ identifier, requestHash
43
43
  * @param params - Escrow authorization parameters.
44
44
  * @param params.escrows - Escrows to authorize.
45
45
  * @param params.credential - Key-bound identifier credential.
46
- * @param params.authControllerToken - Approval each escrow keys its challenge
47
- * to.
48
46
  * @returns Successful escrow authorizations.
49
47
  */
50
- export declare function authorizeEscrowsWithToken({ escrows, credential, authControllerToken, }: {
48
+ export declare function authorizeEscrowsWithToken({ escrows, credential, }: {
51
49
  escrows: RecoveryEscrowProvider[];
52
50
  credential: KeyBoundCredential;
53
- authControllerToken: AuthControllerToken;
54
51
  }): Promise<AuthorizedEscrow[]>;
55
52
  /**
56
53
  * Returns the auth mode for an identifier type.
@@ -1 +1 @@
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,EAA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B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAStE"}
@@ -51,13 +51,11 @@ export async function requestKeyBoundIdentifierToken({ identifier, requestHash,
51
51
  * @param params - Escrow authorization parameters.
52
52
  * @param params.escrows - Escrows to authorize.
53
53
  * @param params.credential - Key-bound identifier credential.
54
- * @param params.authControllerToken - Approval each escrow keys its challenge
55
- * to.
56
54
  * @returns Successful escrow authorizations.
57
55
  */
58
- export async function authorizeEscrowsWithToken({ escrows, credential, authControllerToken, }) {
56
+ export async function authorizeEscrowsWithToken({ escrows, credential, }) {
59
57
  const { token, proofPrivateKey } = credential;
60
- const challengeResults = await Promise.allSettled(escrows.map((escrow) => escrow.generateChallenge(authControllerToken)));
58
+ const challengeResults = await Promise.allSettled(escrows.map((escrow) => escrow.generateChallenge()));
61
59
  const challenges = challengeResults.flatMap((result, index) => isFulfilledResult(result)
62
60
  ? [{ escrow: escrows[index], challenge: result.value }]
63
61
  : []);
@@ -1 +1 @@
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;A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AE,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"]}
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;AAUtD;;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;;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AAM,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 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 * @returns Successful escrow authorizations.\n */\nexport async function authorizeEscrowsWithToken({\n escrows,\n credential,\n}: {\n escrows: RecoveryEscrowProvider[];\n credential: KeyBoundCredential;\n}): Promise<AuthorizedEscrow[]> {\n const { token, proofPrivateKey } = credential;\n const challengeResults = await Promise.allSettled(\n escrows.map((escrow) => escrow.generateChallenge()),\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
@@ -1,11 +1,11 @@
1
1
  export { MfaRecoveryController, getDefaultMfaRecoveryControllerState, } from './MfaRecoveryController.js';
2
2
  export type { MfaRecoveryControllerActions, MfaRecoveryControllerEvents, MfaRecoveryControllerGetStateAction, MfaRecoveryControllerMessenger, MfaRecoveryControllerOptions, MfaRecoveryControllerState, MfaRecoveryControllerStateChangedEvent, } from './MfaRecoveryController.js';
3
- export type { MfaRecoveryControllerAbortAction, MfaRecoveryControllerAuthenticateIdentifierAction, MfaRecoveryControllerGetIdentifiersAction, MfaRecoveryControllerGetPhaseAction, MfaRecoveryControllerGetRecoverySecretAction, MfaRecoveryControllerRegisterAction, MfaRecoveryControllerResumeAction, MfaRecoveryControllerUpdateIdentifiersAction, MfaRecoveryControllerUpdateRecoverySecretAction, } from './MfaRecoveryController-method-action-types.js';
3
+ export type { MfaRecoveryControllerAbortAction, MfaRecoveryControllerAuthenticateIdentifierAction, MfaRecoveryControllerGetPhaseAction, MfaRecoveryControllerGetRecoverySecretAction, MfaRecoveryControllerRegisterAction, MfaRecoveryControllerResumeAction, MfaRecoveryControllerUpdateIdentifiersAction, MfaRecoveryControllerUpdateRecoverySecretAction, } from './MfaRecoveryController-method-action-types.js';
4
4
  export { CubistEscrowProvider } from './escrow-providers/cubist-escrow-provider.js';
5
5
  export type { CubistEscrowProviderOptions } from './escrow-providers/cubist-escrow-provider.js';
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
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';
10
+ export type { AuthControllerToken, EncryptedPendingOperation, Identifier, IdentifierAuthorization, IdentifierSession, Mutation, MutationPayload, MutationReceipt, PendingMutationPayload, PendingOperation, PendingOperationEncryptor, PendingRecoverySecretHex, PendingRegisterPayload, PendingUpdateIdentifiersPayload, PendingUpdateRecoverySecretPayload, RecoveryApproval, RecoveryAuthProvider, RecoveryEscrowProvider, RecoveryIdentifierAuthProvider, RecoveryPhase, RecoveredSecret, WrappedSecret, WrappedSecretOutput, } from './types.js';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -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,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"}
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,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,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,aAAa,EACb,eAAe,EACf,aAAa,EACb,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
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,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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,MAAM,4BAA4B,CAAC;AAoBpC,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 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 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 RecoveryPhase,\n RecoveredSecret,\n WrappedSecret,\n WrappedSecretOutput,\n} from './types.js';\n"]}
package/dist/types.d.ts CHANGED
@@ -198,22 +198,6 @@ export type RecoveredSecret = {
198
198
  recoverySecret: Uint8Array;
199
199
  epoch: number;
200
200
  };
201
- /**
202
- * One escrow's enrolled identifiers and record version.
203
- */
204
- export type GetIdentifiersResponse = {
205
- identifiers: Identifier[];
206
- version: number;
207
- };
208
- /**
209
- * Enrolled identifiers and `epoch`, plus Auth's current identifiers to build
210
- * an `updateIdentifiers` set from.
211
- */
212
- export type RecoveryIdentifiers = {
213
- identifiers: Identifier[];
214
- epoch: number;
215
- authIdentifiers: Identifier[];
216
- };
217
201
  /**
218
202
  * Authenticates the MetaMask profile and issues request-bound attestations.
219
203
  */
@@ -259,8 +243,7 @@ export type RecoveryEscrowProvider = {
259
243
  */
260
244
  readonly wrapPublicKey: Uint8Array;
261
245
  isAvailable: () => Promise<boolean>;
262
- generateChallenge: (authControllerToken: AuthControllerToken) => Promise<PoPChallenge>;
263
- getIdentifiers: (authControllerToken: AuthControllerToken) => Promise<GetIdentifiersResponse>;
246
+ generateChallenge: () => Promise<PoPChallenge>;
264
247
  getSecret: (authControllerToken: AuthControllerToken, authorization: IdentifierAuthorization, requestId: string, pkE: Uint8Array) => Promise<GetRecoverySecretResponse>;
265
248
  applyMutation: (mutation: Mutation, authControllerToken: AuthControllerToken, identifierAuthorization: IdentifierAuthorization | null, payload: MutationPayload, approvedIdentifiers: Identifier[]) => Promise<MutationReceipt>;
266
249
  /**
@@ -1 +1 @@
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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9B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IACnC,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,iBAAiB,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/C,SAAS,EAAE,CACT,mBAAmB,EAAE,mBAAmB,EACxC,aAAa,EAAE,uBAAuB,EACtC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,UAAU,KACZ,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACxC,aAAa,EAAE,CACb,QAAQ,EAAE,QAAQ,EAClB,mBAAmB,EAAE,mBAAmB,EACxC,uBAAuB,EAAE,uBAAuB,GAAG,IAAI,EACvD,OAAO,EAAE,eAAe,EACxB,mBAAmB,EAAE,UAAU,EAAE,KAC9B,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9B;;;;;;;OAOG;IACH,aAAa,EAAE,CACb,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,MAAM,KACrB,OAAO,CAAC,OAAO,CAAC,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,EAAE,CAAC,SAAS,EAAE,gBAAgB,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC7E,OAAO,EAAE,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\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"]}
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 * 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: () => Promise<PoPChallenge>;\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-3d6bb9b8e",
3
+ "version": "0.0.0-preview-eb5c879",
4
4
  "description": "Manages MFA recovery flows across MetaMask clients",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -38,7 +38,7 @@
38
38
  "build:docs": "typedoc",
39
39
  "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
40
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/mfa-recovery-controller",
41
- "changelog:validate": "../../scripts/validate-changelog.sh @metamask/mfa-recovery-controller",
41
+ "changelog:validate": "../../scripts/validate-changelog.sh",
42
42
  "cubesigner:invoke-escrow": "tsx scripts/invoke-escrow.ts",
43
43
  "cubesigner:register": "tsx scripts/register-with-controller.ts",
44
44
  "lint:tsconfigs": "node --import ../../scripts/resolver/register.ts ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@cubist-labs/cubesigner-sdk-fs-storage": "^0.4.284",
66
- "@metamask/auto-changelog": "^6.2.1",
66
+ "@metamask/auto-changelog": "^7.1.0",
67
67
  "@typescript/native": "npm:typescript@^7.0.2",
68
68
  "rimraf": "^6.1.3",
69
69
  "tsx": "^4.20.5",