@metamask/passkey-controller 2.0.1 → 3.0.0
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 +52 -1
- package/README.md +83 -20
- package/dist/PasskeyController-method-action-types.cjs +7 -0
- package/dist/PasskeyController-method-action-types.cjs.map +1 -0
- package/dist/PasskeyController-method-action-types.d.cts +204 -0
- package/dist/PasskeyController-method-action-types.d.cts.map +1 -0
- package/dist/PasskeyController-method-action-types.d.mts +204 -0
- package/dist/PasskeyController-method-action-types.d.mts.map +1 -0
- package/dist/PasskeyController-method-action-types.mjs +6 -0
- package/dist/PasskeyController-method-action-types.mjs.map +1 -0
- package/dist/PasskeyController.cjs +341 -163
- package/dist/PasskeyController.cjs.map +1 -1
- package/dist/PasskeyController.d.cts +88 -49
- package/dist/PasskeyController.d.cts.map +1 -1
- package/dist/PasskeyController.d.mts +88 -49
- package/dist/PasskeyController.d.mts.map +1 -1
- package/dist/PasskeyController.mjs +341 -163
- package/dist/PasskeyController.mjs.map +1 -1
- package/dist/constants.cjs +4 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +5 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +5 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +38 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +38 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +11 -4
|
@@ -1,27 +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 type {
|
|
3
|
+
import type { PasskeyControllerMessenger, PasskeyControllerOptions, PasskeyControllerState } from "./types.mjs";
|
|
6
4
|
import type { PasskeyAuthenticationOptions, PasskeyAuthenticationResponse, PasskeyRegistrationOptions, PasskeyRegistrationResponse } from "./webauthn/types.mjs";
|
|
7
|
-
export type PasskeyControllerState
|
|
8
|
-
passkeyRecord: PasskeyRecord | null;
|
|
9
|
-
};
|
|
10
|
-
export type PasskeyControllerGetStateAction = ControllerGetStateAction<typeof controllerName, PasskeyControllerState>;
|
|
11
|
-
/**
|
|
12
|
-
* Actions exposed by {@link PasskeyController} on its messenger.
|
|
13
|
-
*
|
|
14
|
-
* Only `:getState` is exposed. Derived enrollment status is available via
|
|
15
|
-
* {@link passkeyControllerSelectors.selectIsPasskeyEnrolled}, and lifecycle
|
|
16
|
-
* methods ({@link PasskeyController.generateRegistrationOptions},
|
|
17
|
-
* {@link PasskeyController.protectVaultKeyWithPasskey}, etc.) accept or
|
|
18
|
-
* return non-`Json` runtime values (WebAuthn `PublicKeyCredential` objects
|
|
19
|
-
* and the vault key string), so they require a direct controller reference.
|
|
20
|
-
*/
|
|
21
|
-
export type PasskeyControllerActions = PasskeyControllerGetStateAction;
|
|
22
|
-
export type PasskeyControllerStateChangedEvent = ControllerStateChangedEvent<typeof controllerName, PasskeyControllerState>;
|
|
23
|
-
export type PasskeyControllerEvents = PasskeyControllerStateChangedEvent;
|
|
24
|
-
export type PasskeyControllerMessenger = Messenger<typeof controllerName, PasskeyControllerActions, PasskeyControllerEvents>;
|
|
5
|
+
export type { PasskeyControllerActions, PasskeyControllerAllowedActions, PasskeyControllerEvents, PasskeyControllerGetStateAction, PasskeyControllerMessenger, PasskeyControllerOptions, PasskeyControllerState, PasskeyControllerStateChangedEvent, } from "./types.mjs";
|
|
25
6
|
/**
|
|
26
7
|
* Returns the default (empty) state for {@link PasskeyController}.
|
|
27
8
|
*
|
|
@@ -47,29 +28,18 @@ export declare class PasskeyController extends BaseController<typeof controllerN
|
|
|
47
28
|
/**
|
|
48
29
|
* Creates a passkey controller with WebAuthn relying-party settings.
|
|
49
30
|
*
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @param
|
|
57
|
-
*
|
|
58
|
-
* @param
|
|
59
|
-
* @param
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*/
|
|
63
|
-
constructor({ messenger, state, rpId, expectedRPID, rpName, expectedOrigin, userName, userDisplayName, }: {
|
|
64
|
-
messenger: PasskeyControllerMessenger;
|
|
65
|
-
state?: Partial<PasskeyControllerState>;
|
|
66
|
-
rpId?: string;
|
|
67
|
-
expectedRPID: string | string[];
|
|
68
|
-
rpName: string;
|
|
69
|
-
expectedOrigin: string | string[];
|
|
70
|
-
userName?: string;
|
|
71
|
-
userDisplayName?: string;
|
|
72
|
-
});
|
|
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);
|
|
73
43
|
/**
|
|
74
44
|
* Whether a passkey is enrolled and vault key material is stored.
|
|
75
45
|
*
|
|
@@ -107,23 +77,54 @@ export declare class PasskeyController extends BaseController<typeof controllerN
|
|
|
107
77
|
* Verifies registration and post-registration authentication, then stores the
|
|
108
78
|
* vault key encrypted under the new passkey.
|
|
109
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
|
+
*
|
|
110
83
|
* @param params - Enrollment completion inputs.
|
|
111
84
|
* @param params.registrationResponse - Result of `navigator.credentials.create()`.
|
|
112
85
|
* @param params.authenticationResponse - Result of `navigator.credentials.get()` after {@link generatePostRegistrationAuthenticationOptions}.
|
|
113
|
-
* @param params.
|
|
86
|
+
* @param params.password - Wallet password when onboarding is complete (step-up).
|
|
87
|
+
* @returns Resolves when enrollment completes.
|
|
114
88
|
*/
|
|
115
89
|
protectVaultKeyWithPasskey(params: {
|
|
116
90
|
registrationResponse: PasskeyRegistrationResponse;
|
|
117
91
|
authenticationResponse: PasskeyAuthenticationResponse;
|
|
118
|
-
|
|
92
|
+
password?: string;
|
|
119
93
|
}): Promise<void>;
|
|
120
94
|
/**
|
|
121
95
|
* Verifies an authentication assertion and returns the decrypted vault key.
|
|
122
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
|
+
*
|
|
123
101
|
* @param authenticationResponse - Result of `navigator.credentials.get()`.
|
|
124
102
|
* @returns The plaintext vault encryption key.
|
|
125
103
|
*/
|
|
126
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[]>;
|
|
127
128
|
/**
|
|
128
129
|
* Checks whether the given authentication assertion is valid for the enrolled passkey.
|
|
129
130
|
*
|
|
@@ -142,10 +143,15 @@ export declare class PasskeyController extends BaseController<typeof controllerN
|
|
|
142
143
|
* pass the same `authenticationResponse` you just verified (e.g. from
|
|
143
144
|
* {@link retrieveVaultKeyWithPasskey} / {@link verifyPasskeyAuthentication}).
|
|
144
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
|
+
*
|
|
145
150
|
* @param params - Re-wrap inputs.
|
|
146
151
|
* @param params.authenticationResponse - Used to derive the wrapping key.
|
|
147
152
|
* @param params.oldVaultKey - Expected current vault key.
|
|
148
153
|
* @param params.newVaultKey - New vault key to encrypt under the passkey.
|
|
154
|
+
* @returns Resolves when the passkey record is updated.
|
|
149
155
|
*/
|
|
150
156
|
renewVaultKeyProtection(params: {
|
|
151
157
|
authenticationResponse: PasskeyAuthenticationResponse;
|
|
@@ -153,12 +159,45 @@ export declare class PasskeyController extends BaseController<typeof controllerN
|
|
|
153
159
|
newVaultKey: string;
|
|
154
160
|
}): Promise<void>;
|
|
155
161
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
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.
|
|
158
193
|
*/
|
|
159
|
-
|
|
194
|
+
removePasskeyWithPasswordVerification(password: string): Promise<void>;
|
|
160
195
|
/**
|
|
161
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}.
|
|
162
201
|
*/
|
|
163
202
|
clearState(): void;
|
|
164
203
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasskeyController.d.mts","sourceRoot":"","sources":["../src/PasskeyController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PasskeyController.d.mts","sourceRoot":"","sources":["../src/PasskeyController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,EACL,cAAc,EAGf,wBAAoB;AAIrB,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACxB,sBAAsB,EAKvB,oBAAgB;AASjB,OAAO,KAAK,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,0BAA0B,EAC1B,2BAA2B,EAC5B,6BAAyB;AAI1B,YAAY,EACV,wBAAwB,EACxB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,0BAA0B,EAC1B,wBAAwB,EACxB,sBAAsB,EACtB,kCAAkC,GACnC,oBAAgB;AAEjB;;;;GAIG;AACH,wBAAgB,gCAAgC,IAAI,sBAAsB,CAEzE;AAaD;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B;qCACJ,sBAAsB,KAAG,OAAO;CAElE,CAAC;AAqBF;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,cAAc,CACnD,OAAO,cAAc,EACrB,sBAAsB,EACtB,0BAA0B,CAC3B;;IAmBC;;;;;;;;;;;;;OAaG;gBACS,EACV,SAAS,EACT,KAAU,EACV,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