@metamask-previews/passkey-controller 2.1.0-preview-eade524 → 2.1.0-preview-355b70c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -21
- package/README.md +20 -85
- package/dist/PasskeyController-method-action-types.cjs.map +1 -1
- package/dist/PasskeyController-method-action-types.d.cts +7 -85
- package/dist/PasskeyController-method-action-types.d.cts.map +1 -1
- package/dist/PasskeyController-method-action-types.d.mts +7 -85
- package/dist/PasskeyController-method-action-types.d.mts.map +1 -1
- package/dist/PasskeyController-method-action-types.mjs.map +1 -1
- package/dist/PasskeyController.cjs +164 -326
- package/dist/PasskeyController.cjs.map +1 -1
- package/dist/PasskeyController.d.cts +50 -88
- package/dist/PasskeyController.d.cts.map +1 -1
- package/dist/PasskeyController.d.mts +50 -88
- package/dist/PasskeyController.d.mts.map +1 -1
- package/dist/PasskeyController.mjs +164 -326
- package/dist/PasskeyController.mjs.map +1 -1
- package/dist/constants.cjs +0 -3
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -4
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -4
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +0 -3
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +0 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +0 -38
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +0 -38
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -4
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
|
|
1
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
4
|
import { controllerName } from "./constants.mjs";
|
|
3
|
-
import
|
|
5
|
+
import { PasskeyControllerMethodActions } from "./PasskeyController-method-action-types.mjs";
|
|
6
|
+
import type { PasskeyRecord } from "./types.mjs";
|
|
4
7
|
import type { PasskeyAuthenticationOptions, PasskeyAuthenticationResponse, PasskeyRegistrationOptions, PasskeyRegistrationResponse } from "./webauthn/types.mjs";
|
|
5
|
-
export type
|
|
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>;
|
|
6
26
|
/**
|
|
7
27
|
* Returns the default (empty) state for {@link PasskeyController}.
|
|
8
28
|
*
|
|
@@ -28,18 +48,29 @@ export declare class PasskeyController extends BaseController<typeof controllerN
|
|
|
28
48
|
/**
|
|
29
49
|
* Creates a passkey controller with WebAuthn relying-party settings.
|
|
30
50
|
*
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
});
|
|
43
74
|
/**
|
|
44
75
|
* Whether a passkey is enrolled and vault key material is stored.
|
|
45
76
|
*
|
|
@@ -77,54 +108,23 @@ export declare class PasskeyController extends BaseController<typeof controllerN
|
|
|
77
108
|
* Verifies registration and post-registration authentication, then stores the
|
|
78
109
|
* vault key encrypted under the new passkey.
|
|
79
110
|
*
|
|
80
|
-
* Fetches the current vault encryption key from KeyringController before wrapping.
|
|
81
|
-
* When onboarding is complete, requires `password` for step-up verification first.
|
|
82
|
-
*
|
|
83
111
|
* @param params - Enrollment completion inputs.
|
|
84
112
|
* @param params.registrationResponse - Result of `navigator.credentials.create()`.
|
|
85
113
|
* @param params.authenticationResponse - Result of `navigator.credentials.get()` after {@link generatePostRegistrationAuthenticationOptions}.
|
|
86
|
-
* @param params.
|
|
87
|
-
* @returns Resolves when enrollment completes.
|
|
114
|
+
* @param params.vaultKey - Vault encryption key to encrypt and persist.
|
|
88
115
|
*/
|
|
89
116
|
protectVaultKeyWithPasskey(params: {
|
|
90
117
|
registrationResponse: PasskeyRegistrationResponse;
|
|
91
118
|
authenticationResponse: PasskeyAuthenticationResponse;
|
|
92
|
-
|
|
119
|
+
vaultKey: string;
|
|
93
120
|
}): Promise<void>;
|
|
94
121
|
/**
|
|
95
122
|
* Verifies an authentication assertion and returns the decrypted vault key.
|
|
96
123
|
*
|
|
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
|
-
*
|
|
101
124
|
* @param authenticationResponse - Result of `navigator.credentials.get()`.
|
|
102
125
|
* @returns The plaintext vault encryption key.
|
|
103
126
|
*/
|
|
104
127
|
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,15 +143,10 @@ 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
|
-
*
|
|
150
146
|
* @param params - Re-wrap inputs.
|
|
151
147
|
* @param params.authenticationResponse - Used to derive the wrapping key.
|
|
152
148
|
* @param params.oldVaultKey - Expected current vault key.
|
|
153
149
|
* @param params.newVaultKey - New vault key to encrypt under the passkey.
|
|
154
|
-
* @returns Resolves when the passkey record is updated.
|
|
155
150
|
*/
|
|
156
151
|
renewVaultKeyProtection(params: {
|
|
157
152
|
authenticationResponse: PasskeyAuthenticationResponse;
|
|
@@ -159,45 +154,12 @@ export declare class PasskeyController extends BaseController<typeof controllerN
|
|
|
159
154
|
newVaultKey: string;
|
|
160
155
|
}): Promise<void>;
|
|
161
156
|
/**
|
|
162
|
-
*
|
|
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.
|
|
157
|
+
* Clears enrolled passkey state and in-flight ceremonies. Call only after the same
|
|
158
|
+
* auth gate as renewal (verified passkey assertion or password).
|
|
193
159
|
*/
|
|
194
|
-
|
|
160
|
+
removePasskey(): void;
|
|
195
161
|
/**
|
|
196
162
|
* 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}.
|
|
201
163
|
*/
|
|
202
164
|
clearState(): void;
|
|
203
165
|
/**
|
|
@@ -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":"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,2BAA2B,EAC5B,6BAAyB;AAI1B,MAAM,MAAM,sBAAsB,GAAG;IACnC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,wBAAwB,CACpE,OAAO,cAAc,EACrB,sBAAsB,CACvB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,wBAAwB,GAChC,+BAA+B,GAC/B,8BAA8B,CAAC;AAEnC,MAAM,MAAM,kCAAkC,GAAG,2BAA2B,CAC1E,OAAO,cAAc,EACrB,sBAAsB,CACvB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,kCAAkC,CAAC;AAEzE,MAAM,MAAM,0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