@metamask-previews/passkey-controller 2.1.0-preview-789f7f935 → 2.1.0-preview-eade524

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +85 -20
  3. package/dist/PasskeyController-method-action-types.cjs.map +1 -1
  4. package/dist/PasskeyController-method-action-types.d.cts +85 -7
  5. package/dist/PasskeyController-method-action-types.d.cts.map +1 -1
  6. package/dist/PasskeyController-method-action-types.d.mts +85 -7
  7. package/dist/PasskeyController-method-action-types.d.mts.map +1 -1
  8. package/dist/PasskeyController-method-action-types.mjs.map +1 -1
  9. package/dist/PasskeyController.cjs +326 -164
  10. package/dist/PasskeyController.cjs.map +1 -1
  11. package/dist/PasskeyController.d.cts +88 -50
  12. package/dist/PasskeyController.d.cts.map +1 -1
  13. package/dist/PasskeyController.d.mts +88 -50
  14. package/dist/PasskeyController.d.mts.map +1 -1
  15. package/dist/PasskeyController.mjs +326 -164
  16. package/dist/PasskeyController.mjs.map +1 -1
  17. package/dist/constants.cjs +3 -0
  18. package/dist/constants.cjs.map +1 -1
  19. package/dist/constants.d.cts +4 -1
  20. package/dist/constants.d.cts.map +1 -1
  21. package/dist/constants.d.mts +4 -1
  22. package/dist/constants.d.mts.map +1 -1
  23. package/dist/constants.mjs +3 -0
  24. package/dist/constants.mjs.map +1 -1
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +2 -3
  27. package/dist/index.d.cts.map +1 -1
  28. package/dist/index.d.mts +2 -3
  29. package/dist/index.d.mts.map +1 -1
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/types.cjs +1 -0
  32. package/dist/types.cjs.map +1 -1
  33. package/dist/types.d.cts +38 -0
  34. package/dist/types.d.cts.map +1 -1
  35. package/dist/types.d.mts +38 -0
  36. package/dist/types.d.mts.map +1 -1
  37. package/dist/types.mjs +1 -1
  38. package/dist/types.mjs.map +1 -1
  39. package/package.json +4 -2
@@ -1,28 +1,8 @@
1
- import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
2
1
  import { BaseController } from "@metamask/base-controller";
3
- import type { Messenger } from "@metamask/messenger";
4
2
  import { controllerName } from "./constants.mjs";
5
- import { PasskeyControllerMethodActions } from "./PasskeyController-method-action-types.mjs";
6
- import type { PasskeyRecord } from "./types.mjs";
3
+ import type { PasskeyControllerMessenger, PasskeyControllerOptions, PasskeyControllerState } from "./types.mjs";
7
4
  import type { PasskeyAuthenticationOptions, PasskeyAuthenticationResponse, PasskeyRegistrationOptions, PasskeyRegistrationResponse } from "./webauthn/types.mjs";
8
- export type PasskeyControllerState = {
9
- passkeyRecord: PasskeyRecord | null;
10
- };
11
- export type PasskeyControllerGetStateAction = ControllerGetStateAction<typeof controllerName, PasskeyControllerState>;
12
- /**
13
- * Actions exposed by {@link PasskeyController} on its messenger.
14
- *
15
- * Only `:getState` is exposed. Derived enrollment status is available via
16
- * {@link passkeyControllerSelectors.selectIsPasskeyEnrolled}, and lifecycle
17
- * methods ({@link PasskeyController.generateRegistrationOptions},
18
- * {@link PasskeyController.protectVaultKeyWithPasskey}, etc.) accept or
19
- * return non-`Json` runtime values (WebAuthn `PublicKeyCredential` objects
20
- * and the vault key string), so they require a direct controller reference.
21
- */
22
- export type PasskeyControllerActions = PasskeyControllerGetStateAction | PasskeyControllerMethodActions;
23
- export type PasskeyControllerStateChangedEvent = ControllerStateChangedEvent<typeof controllerName, PasskeyControllerState>;
24
- export type PasskeyControllerEvents = PasskeyControllerStateChangedEvent;
25
- export type PasskeyControllerMessenger = Messenger<typeof controllerName, PasskeyControllerActions, PasskeyControllerEvents>;
5
+ export type { PasskeyControllerActions, PasskeyControllerAllowedActions, PasskeyControllerEvents, PasskeyControllerGetStateAction, PasskeyControllerMessenger, PasskeyControllerOptions, PasskeyControllerState, PasskeyControllerStateChangedEvent, } from "./types.mjs";
26
6
  /**
27
7
  * Returns the default (empty) state for {@link PasskeyController}.
28
8
  *
@@ -48,29 +28,18 @@ export declare class PasskeyController extends BaseController<typeof controllerN
48
28
  /**
49
29
  * Creates a passkey controller with WebAuthn relying-party settings.
50
30
  *
51
- * @param args - Constructor options.
52
- * @param args.messenger - Controller messenger.
53
- * @param args.state - Partial initial state; merged with {@link getDefaultPasskeyControllerState}.
54
- * @param args.expectedRPID - Relying party ID(s) for verification (SHA-256 hash match in
55
- * authenticator data). Pass a string or array of strings; an empty array skips RP ID
56
- * allowlist checks in {@link verifyRegistrationResponse} / {@link verifyAuthenticationResponse}.
57
- * @param args.rpId - When set, included as `rp.id` on registration options and `rpId` on
58
- * authentication options. When omitted, those fields are left unset (client default RP ID).
59
- * @param args.rpName - Relying party name shown in the platform passkey UI.
60
- * @param args.expectedOrigin - Allowed value(s) for the WebAuthn client origin.
61
- * @param args.userName - Optional passkey user name; defaults to `rpName`.
62
- * @param args.userDisplayName - Optional display name; defaults to `rpName`.
63
- */
64
- constructor({ messenger, state, rpId, expectedRPID, rpName, expectedOrigin, userName, userDisplayName, }: {
65
- messenger: PasskeyControllerMessenger;
66
- state?: Partial<PasskeyControllerState>;
67
- rpId?: string;
68
- expectedRPID: string | string[];
69
- rpName: string;
70
- expectedOrigin: string | string[];
71
- userName?: string;
72
- userDisplayName?: string;
73
- });
31
+ * @param options - Constructor options.
32
+ * @param options.messenger - The messenger to use for communication.
33
+ * @param options.state - The initial state of the controller.
34
+ * @param options.rpId - The relying party ID to use for the passkey.
35
+ * @param options.expectedRPID - The expected relying party ID to use for the passkey.
36
+ * @param options.rpName - The relying party name to use for the passkey.
37
+ * @param options.expectedOrigin - The expected origin to use for the passkey.
38
+ * @param options.userName - The user name to use for the passkey.
39
+ * @param options.userDisplayName - The user display name to use for the passkey.
40
+ * @param options.getIsOnboardingCompleted - The callback to use to check if onboarding is complete.
41
+ */
42
+ constructor({ messenger, state, rpId, expectedRPID, rpName, expectedOrigin, userName, userDisplayName, getIsOnboardingCompleted, }: PasskeyControllerOptions);
74
43
  /**
75
44
  * Whether a passkey is enrolled and vault key material is stored.
76
45
  *
@@ -108,23 +77,54 @@ export declare class PasskeyController extends BaseController<typeof controllerN
108
77
  * Verifies registration and post-registration authentication, then stores the
109
78
  * vault key encrypted under the new passkey.
110
79
  *
80
+ * Fetches the current vault encryption key from KeyringController before wrapping.
81
+ * When onboarding is complete, requires `password` for step-up verification first.
82
+ *
111
83
  * @param params - Enrollment completion inputs.
112
84
  * @param params.registrationResponse - Result of `navigator.credentials.create()`.
113
85
  * @param params.authenticationResponse - Result of `navigator.credentials.get()` after {@link generatePostRegistrationAuthenticationOptions}.
114
- * @param params.vaultKey - Vault encryption key to encrypt and persist.
86
+ * @param params.password - Wallet password when onboarding is complete (step-up).
87
+ * @returns Resolves when enrollment completes.
115
88
  */
116
89
  protectVaultKeyWithPasskey(params: {
117
90
  registrationResponse: PasskeyRegistrationResponse;
118
91
  authenticationResponse: PasskeyAuthenticationResponse;
119
- vaultKey: string;
92
+ password?: string;
120
93
  }): Promise<void>;
121
94
  /**
122
95
  * Verifies an authentication assertion and returns the decrypted vault key.
123
96
  *
97
+ * Prefer orchestrated methods ({@link unlockWithPasskey},
98
+ * {@link exportSeedPhraseWithPasskey}, {@link exportAccountsWithPasskey}) for product
99
+ * flows instead of calling KeyringController with the returned key manually.
100
+ *
124
101
  * @param authenticationResponse - Result of `navigator.credentials.get()`.
125
102
  * @returns The plaintext vault encryption key.
126
103
  */
127
104
  retrieveVaultKeyWithPasskey(authenticationResponse: PasskeyAuthenticationResponse): Promise<string>;
105
+ /**
106
+ * Unlocks the keyring using a passkey authentication assertion.
107
+ *
108
+ * @param authenticationResponse - Result of `navigator.credentials.get()`.
109
+ * @returns Resolves when the keyring is unlocked.
110
+ */
111
+ unlockWithPasskey(authenticationResponse: PasskeyAuthenticationResponse): Promise<void>;
112
+ /**
113
+ * Exports the seed phrase after passkey step-up authentication.
114
+ *
115
+ * @param authenticationResponse - Result of `navigator.credentials.get()`.
116
+ * @param keyringId - Optional keyring id; defaults to the primary HD keyring.
117
+ * @returns Raw seed phrase bytes from KeyringController.
118
+ */
119
+ exportSeedPhraseWithPasskey(authenticationResponse: PasskeyAuthenticationResponse, keyringId?: string): Promise<Uint8Array>;
120
+ /**
121
+ * Exports private keys for the given addresses after passkey step-up authentication.
122
+ *
123
+ * @param authenticationResponse - Result of `navigator.credentials.get()`.
124
+ * @param addresses - Account addresses to export.
125
+ * @returns Private keys in the same order as `addresses`.
126
+ */
127
+ exportAccountsWithPasskey(authenticationResponse: PasskeyAuthenticationResponse, addresses: string[]): Promise<string[]>;
128
128
  /**
129
129
  * Checks whether the given authentication assertion is valid for the enrolled passkey.
130
130
  *
@@ -143,10 +143,15 @@ export declare class PasskeyController extends BaseController<typeof controllerN
143
143
  * pass the same `authenticationResponse` you just verified (e.g. from
144
144
  * {@link retrieveVaultKeyWithPasskey} / {@link verifyPasskeyAuthentication}).
145
145
  *
146
+ * For password change with passkey step-up, prefer
147
+ * {@link changePasswordWithPasskeyVerification}, which orchestrates keyring export,
148
+ * `changePassword`, and re-wrap in one call.
149
+ *
146
150
  * @param params - Re-wrap inputs.
147
151
  * @param params.authenticationResponse - Used to derive the wrapping key.
148
152
  * @param params.oldVaultKey - Expected current vault key.
149
153
  * @param params.newVaultKey - New vault key to encrypt under the passkey.
154
+ * @returns Resolves when the passkey record is updated.
150
155
  */
151
156
  renewVaultKeyProtection(params: {
152
157
  authenticationResponse: PasskeyAuthenticationResponse;
@@ -154,12 +159,45 @@ export declare class PasskeyController extends BaseController<typeof controllerN
154
159
  newVaultKey: string;
155
160
  }): Promise<void>;
156
161
  /**
157
- * Clears enrolled passkey state and in-flight ceremonies. Call only after the same
158
- * auth gate as renewal (verified passkey assertion or password).
162
+ * Changes the wallet password after passkey step-up authentication.
163
+ *
164
+ * When `renewVaultKeyProtection` is `true` (default), re-wraps the vault key under the
165
+ * passkey after rotation. When `false`, removes the passkey instead.
166
+ *
167
+ * @param params - Change-password inputs.
168
+ * @param params.newPassword - New wallet password.
169
+ * @param params.authenticationResponse - Result of `navigator.credentials.get()`.
170
+ * @param params.options - Optional flow controls.
171
+ * @param params.options.renewVaultKeyProtection - Re-wrap vault key after password change.
172
+ * @returns Resolves when the password change completes.
173
+ */
174
+ changePasswordWithPasskeyVerification(params: {
175
+ newPassword: string;
176
+ authenticationResponse: PasskeyAuthenticationResponse;
177
+ options?: {
178
+ renewVaultKeyProtection?: boolean;
179
+ };
180
+ }): Promise<void>;
181
+ /**
182
+ * Removes the enrolled passkey after verifying a passkey authentication assertion.
183
+ *
184
+ * @param authenticationResponse - Result of `navigator.credentials.get()`.
185
+ * @returns Resolves when the passkey is removed.
186
+ */
187
+ removePasskeyWithPasskeyVerification(authenticationResponse: PasskeyAuthenticationResponse): Promise<void>;
188
+ /**
189
+ * Removes the enrolled passkey after verifying the wallet password.
190
+ *
191
+ * @param password - Wallet password for step-up verification.
192
+ * @returns Resolves when the passkey is removed.
159
193
  */
160
- removePasskey(): void;
194
+ removePasskeyWithPasswordVerification(password: string): Promise<void>;
161
195
  /**
162
196
  * Resets state and clears in-flight registration/authentication ceremonies.
197
+ *
198
+ * For user-facing passkey removal with step-up, use
199
+ * {@link removePasskeyWithPasskeyVerification} or
200
+ * {@link removePasskeyWithPasswordVerification}.
163
201
  */
164
202
  clearState(): void;
165
203
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"PasskeyController.d.mts","sourceRoot":"","sources":["../src/PasskeyController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAIrD,OAAO,EACL,cAAc,EAGf,wBAAoB;AAIrB,OAAO,EAAE,8BAA8B,EAAE,oDAAgD;AACzF,OAAO,KAAK,EAIV,aAAa,EAEd,oBAAgB;AASjB,OAAO,KAAK,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,0BAA0B,EAC1B,2B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