nid-webauthn-emulator 0.1.4 → 0.2.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/README.md CHANGED
@@ -143,6 +143,13 @@ async function startWebAuthnEmulator(page: Page, origin: string, debug = false)
143
143
  return response;
144
144
  },
145
145
  );
146
+
147
+ await page.exposeFunction(
148
+ BrowserInjection.WebAuthnEmulatorSignalUnknownCredential,
149
+ async (options: { rpId: string; credentialId: string }) => {
150
+ emulator.signalUnknownCredential(options);
151
+ },
152
+ );
146
153
  }
147
154
 
148
155
  test.describe("Passkeys Tests", { tag: ["@daily"] }, () => {
@@ -162,6 +169,7 @@ test.describe("Passkeys Tests", { tag: ["@daily"] }, () => {
162
169
 
163
170
  - `window.webAuthnEmulatorGet`: `WebAuthnEmulator.getJSON` の Exposed Function
164
171
  - `window.webAuthnEmulatorCreate`: `WebAuthnEmulator.createJSON` の Exposed Function
172
+ - `window.webAuthnEmulatorSignalUnknownCredential`: `WebAuthnEmulator.signalUnknownCredential` の Exposed Function
165
173
 
166
174
  これらは Page グローバルに定義されるため、Page インスタンスにつき 1 回だけ定義する必要があります。
167
175
 
@@ -175,6 +183,7 @@ await page.evaluate(BrowserInjection.HookWebAuthnApis);
175
183
 
176
184
  - `navigator.credentials.get` の定義を上書きし、`window.webAuthnEmulatorGet` を呼び出す
177
185
  - `navigator.credentials.create` の定義を上書きし、`window.webAuthnEmulatorCreate` を呼び出す
186
+ - `PublicKeyCredential.signalUnknownCredential` の定義を追加し、`window.webAuthnEmulatorSignalUnknownCredential` を呼び出す
178
187
 
179
188
  これにより先ほどの `exposeFunction` で定義した `WebAuthnEmulator` のメソッドが、`navigator.credentials.get` および `navigator.credentials.create` 呼び出し時に実行されるようになります。これらの処理中にはテストコンテキストと Playwright のコンテキスト間の通信のためにデータのシリアライズおよびデシリアライズが行われるため、そのための処理も含まれています。
180
189
 
@@ -5,11 +5,15 @@ const browser_injection_1 = require("../../src/test-utils/browser-injection");
5
5
  (0, globals_1.describe)("Browser Injection Test", () => {
6
6
  (0, globals_1.test)("Browser Injection Test", async () => {
7
7
  const window = { navigator: { credentials: { create: undefined, get: undefined } } };
8
- const PublicKeyCredential = { isConditionalMediationAvailable: async () => false };
8
+ const PublicKeyCredential = {
9
+ isConditionalMediationAvailable: async () => false,
10
+ signalUnknownCredential: undefined,
11
+ };
9
12
  // biome-ignore lint/security/noGlobalEval: This is a test code.
10
13
  eval(browser_injection_1.HookWebAuthnApis);
11
14
  (0, globals_1.expect)(await PublicKeyCredential.isConditionalMediationAvailable()).toBeTruthy();
12
15
  (0, globals_1.expect)(window.navigator.credentials.create).toBeDefined();
13
16
  (0, globals_1.expect)(window.navigator.credentials.get).toBeDefined();
17
+ (0, globals_1.expect)(PublicKeyCredential.signalUnknownCredential).toBeDefined();
14
18
  });
15
19
  });
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -29,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
39
  const globals_1 = require("@jest/globals");
30
40
  const src_1 = __importStar(require("../../src"));
31
41
  const encode_utils_1 = __importDefault(require("../../src/libs/encode-utils"));
42
+ const credentials_memory_repository_1 = require("../../src/repository/credentials-memory-repository");
32
43
  const webauthn_test_server_1 = require("./webauthn-test-server");
33
44
  (0, globals_1.describe)("WebAuthnEmulator Registration Passkeys Test", () => {
34
45
  const user = { username: "test", id: "test" };
@@ -220,3 +231,30 @@ const webauthn_test_server_1 = require("./webauthn-test-server");
220
231
  });
221
232
  });
222
233
  });
234
+ (0, globals_1.describe)("WebAuthnEmulator signalUnknownCredential Test", () => {
235
+ (0, globals_1.test)("Signal Unknown Credential _ OK", async () => {
236
+ const user = { username: "test-signal", id: "test-signal" };
237
+ // Create a new emulator with a clean repository
238
+ const repository = new credentials_memory_repository_1.PasskeysCredentialsMemoryRepository();
239
+ const authenticator = new src_1.AuthenticatorEmulator({
240
+ credentialsRepository: repository,
241
+ });
242
+ const emulator = new src_1.default(authenticator);
243
+ const testServer = new webauthn_test_server_1.WebAuthnTestServer();
244
+ // Create a credential
245
+ const options = await testServer.getRegistrationOptions(user);
246
+ const credential = emulator.createJSON(webauthn_test_server_1.TEST_RP_ORIGIN, options);
247
+ await testServer.getRegistrationVerification(user, credential);
248
+ // Verify the credential exists
249
+ const credentialsBefore = repository.loadCredentials();
250
+ (0, globals_1.expect)(credentialsBefore.length).toBe(1);
251
+ // Signal unknown credential
252
+ emulator.signalUnknownCredential({
253
+ rpId: webauthn_test_server_1.TEST_RP_ORIGIN.replace("https://", ""),
254
+ credentialId: credential.id,
255
+ });
256
+ // Verify the credential was deleted
257
+ const credentialsAfter = repository.loadCredentials();
258
+ (0, globals_1.expect)(credentialsAfter.length).toBe(0);
259
+ });
260
+ });
@@ -1,6 +1,6 @@
1
1
  import type { PasskeysCredentialsRepository } from "../repository/credentials-repository";
2
2
  import { type AuthenticatorData, type PublicKeyCredentialSource } from "../webauthn/webauthn-model";
3
- import { type AuthenticatorGetAssertionRequest, type AuthenticatorGetAssertionResponse, type AuthenticatorGetInfoResponse, type AuthenticatorMakeCredentialRequest, type AuthenticatorMakeCredentialResponse, type AuthenticatorOptions, type CTAPAuthenticatorRequest, type CTAPAuthenticatorResponse } from "./ctap-model";
3
+ import { type AuthenticatorCredentialManagementRequest, type AuthenticatorCredentialManagementResponse, type AuthenticatorGetAssertionRequest, type AuthenticatorGetAssertionResponse, type AuthenticatorGetInfoResponse, type AuthenticatorMakeCredentialRequest, type AuthenticatorMakeCredentialResponse, type AuthenticatorOptions, type CTAPAuthenticatorRequest, type CTAPAuthenticatorResponse } from "./ctap-model";
4
4
  type InteractionResponse = {
5
5
  options: {
6
6
  uv: boolean;
@@ -52,6 +52,11 @@ export declare class AuthenticatorEmulator {
52
52
  constructor(params?: Partial<AuthenticatorParameters>);
53
53
  /** @see https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#authenticator-api */
54
54
  command(request: CTAPAuthenticatorRequest): CTAPAuthenticatorResponse;
55
+ /**
56
+ * @see https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorCredentialManagement
57
+ */
58
+ authenticatorCredentialManagement(request: AuthenticatorCredentialManagementRequest): AuthenticatorCredentialManagementResponse;
59
+ private authenticatorDeleteCredential;
55
60
  /** @see https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#authenticatorGetInfo */
56
61
  authenticatorGetInfo(): AuthenticatorGetInfoResponse;
57
62
  /**
@@ -48,7 +48,9 @@ class AuthenticatorEmulator {
48
48
  verifications: params.verifications ?? AuthenticatorEmulator.DEFAULT_VERIFICATIONS,
49
49
  userMakeCredentialInteraction: params.userMakeCredentialInteraction ?? AuthenticatorEmulator.DEFAULT_MAKE_CREDENTIAL_INTERACTION,
50
50
  userGetAssertionInteraction: params.userGetAssertionInteraction ?? AuthenticatorEmulator.DEFAULT_GET_ASSERTION_INTERACTION,
51
- credentialsRepository: params.stateless ? undefined : AuthenticatorEmulator.DEFAULT_CREDENTIALS_REPOSITORY,
51
+ credentialsRepository: params.stateless
52
+ ? undefined
53
+ : (params.credentialsRepository ?? AuthenticatorEmulator.DEFAULT_CREDENTIALS_REPOSITORY),
52
54
  stateless: params.stateless ?? AuthenticatorEmulator.DEFAULT_STATELESS,
53
55
  };
54
56
  }
@@ -68,8 +70,47 @@ class AuthenticatorEmulator {
68
70
  if (unpackedRequest.command === ctap_model_1.CTAP_COMMAND.authenticatorGetInfo) {
69
71
  return (0, ctap_model_1.packGetInfoResponse)(this.authenticatorGetInfo());
70
72
  }
73
+ if (unpackedRequest.command === ctap_model_1.CTAP_COMMAND.authenticatorCredentialManagement) {
74
+ const credentialManagementRequest = (0, ctap_model_1.unpackCredentialManagementRequest)(request);
75
+ const credentialManagementResponse = this.authenticatorCredentialManagement(credentialManagementRequest);
76
+ return (0, ctap_model_1.packCredentialManagementResponse)(credentialManagementResponse);
77
+ }
71
78
  throw new ctap_model_1.AuthenticationEmulatorError(ctap_model_1.CTAP_STATUS_CODE.CTAP1_ERR_INVALID_COMMAND);
72
79
  }
80
+ /**
81
+ * @see https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#authenticatorCredentialManagement
82
+ */
83
+ authenticatorCredentialManagement(request) {
84
+ const repository = this.params.credentialsRepository;
85
+ if (!repository) {
86
+ throw new ctap_model_1.AuthenticationEmulatorError(ctap_model_1.CTAP_STATUS_CODE.CTAP2_ERR_NOT_ALLOWED);
87
+ }
88
+ switch (request.subCommand) {
89
+ case ctap_model_1.CREDENTIAL_MANAGEMENT_SUBCOMMAND.deleteCredential:
90
+ return this.authenticatorDeleteCredential(request);
91
+ default:
92
+ throw new ctap_model_1.AuthenticationEmulatorError(ctap_model_1.CTAP_STATUS_CODE.CTAP1_ERR_INVALID_COMMAND);
93
+ }
94
+ }
95
+ authenticatorDeleteCredential(request) {
96
+ const repository = this.params.credentialsRepository;
97
+ if (!repository) {
98
+ throw new ctap_model_1.AuthenticationEmulatorError(ctap_model_1.CTAP_STATUS_CODE.CTAP2_ERR_NOT_ALLOWED);
99
+ }
100
+ if (!request.subCommandParams?.credentialId) {
101
+ throw new ctap_model_1.AuthenticationEmulatorError(ctap_model_1.CTAP_STATUS_CODE.CTAP1_ERR_INVALID_PARAMETER);
102
+ }
103
+ const credentialId = request.subCommandParams.credentialId;
104
+ const credentials = repository.loadCredentials();
105
+ const credential = credentials.find((cred) => encode_utils_1.default.encodeBase64Url(cred.publicKeyCredentialSource.id) === encode_utils_1.default.encodeBase64Url(credentialId));
106
+ if (!credential) {
107
+ throw new ctap_model_1.AuthenticationEmulatorError(ctap_model_1.CTAP_STATUS_CODE.CTAP2_ERR_NO_CREDENTIALS);
108
+ }
109
+ repository.deleteCredential(credential);
110
+ return {
111
+ existingResidentCredentialsCount: repository.loadCredentials().length,
112
+ };
113
+ }
73
114
  /** @see https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#authenticatorGetInfo */
74
115
  authenticatorGetInfo() {
75
116
  return {
@@ -76,7 +76,40 @@ export declare enum CTAP_COMMAND {
76
76
  authenticatorGetInfo = 4,
77
77
  authenticatorClientPIN = 6,
78
78
  authenticatorReset = 7,
79
- authenticatorGetNextAssertion = 8
79
+ authenticatorGetNextAssertion = 8,
80
+ authenticatorCredentialManagement = 10
81
+ }
82
+ export declare enum CREDENTIAL_MANAGEMENT_SUBCOMMAND {
83
+ getCredsMetadata = 1,
84
+ enumerateRPsBegin = 2,
85
+ enumerateRPsGetNextRP = 3,
86
+ enumerateCredentialsBegin = 4,
87
+ enumerateCredentialsGetNextCredential = 5,
88
+ deleteCredential = 6,
89
+ updateUserInformation = 7
90
+ }
91
+ export interface AuthenticatorCredentialManagementRequest {
92
+ subCommand: CREDENTIAL_MANAGEMENT_SUBCOMMAND;
93
+ subCommandParams?: {
94
+ credentialId?: Uint8Array;
95
+ rpId?: string;
96
+ user?: PublicKeyCredentialUserEntity;
97
+ };
98
+ pinUvAuthProtocol?: number;
99
+ pinUvAuthParam?: Uint8Array;
100
+ }
101
+ export interface AuthenticatorCredentialManagementResponse {
102
+ existingResidentCredentialsCount?: number;
103
+ maxPossibleRemainingResidentCredentialsCount?: number;
104
+ rp?: PublicKeyCredentialRpEntity;
105
+ rpIDHash?: Uint8Array;
106
+ totalRPs?: number;
107
+ user?: PublicKeyCredentialUserEntity;
108
+ credentialID?: Uint8Array;
109
+ publicKey?: Uint8Array;
110
+ totalCredentials?: number;
111
+ credProtect?: number;
112
+ largeBlobKey?: Uint8Array;
80
113
  }
81
114
  /** @see https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#responses */
82
115
  export interface CTAPAuthenticatorResponse {
@@ -99,9 +132,13 @@ export declare function unpackRequest(request: CTAPAuthenticatorRequest): {
99
132
  };
100
133
  export declare function packMakeCredentialRequest(request: AuthenticatorMakeCredentialRequest): CTAPAuthenticatorRequest;
101
134
  export declare function packGetAssertionRequest(request: AuthenticatorGetAssertionRequest): CTAPAuthenticatorRequest;
135
+ export declare function packCredentialManagementRequest(request: AuthenticatorCredentialManagementRequest): CTAPAuthenticatorRequest;
136
+ export declare function unpackCredentialManagementRequest(request: CTAPAuthenticatorRequest): AuthenticatorCredentialManagementRequest;
102
137
  export declare function unpackMakeCredentialResponse(response: CTAPAuthenticatorResponse): AuthenticatorMakeCredentialResponse;
103
138
  export declare function packMakeCredentialResponse(response: AuthenticatorMakeCredentialResponse): CTAPAuthenticatorResponse;
104
139
  export declare function unpackGetAssertionResponse(response: CTAPAuthenticatorResponse): AuthenticatorGetAssertionResponse;
105
140
  export declare function packGetAssertionResponse(response: AuthenticatorGetAssertionResponse): CTAPAuthenticatorResponse;
106
141
  export declare function unpackGetInfoResponse(response: CTAPAuthenticatorResponse): AuthenticatorGetInfoResponse;
107
142
  export declare function packGetInfoResponse(response: AuthenticatorGetInfoResponse): CTAPAuthenticatorResponse;
143
+ export declare function packCredentialManagementResponse(response: AuthenticatorCredentialManagementResponse): CTAPAuthenticatorResponse;
144
+ export declare function unpackCredentialManagementResponse(response: CTAPAuthenticatorResponse): AuthenticatorCredentialManagementResponse;
@@ -3,16 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AuthenticationEmulatorError = exports.CTAP_COMMAND = exports.CTAP_STATUS_CODE = void 0;
6
+ exports.AuthenticationEmulatorError = exports.CREDENTIAL_MANAGEMENT_SUBCOMMAND = exports.CTAP_COMMAND = exports.CTAP_STATUS_CODE = void 0;
7
7
  exports.unpackRequest = unpackRequest;
8
8
  exports.packMakeCredentialRequest = packMakeCredentialRequest;
9
9
  exports.packGetAssertionRequest = packGetAssertionRequest;
10
+ exports.packCredentialManagementRequest = packCredentialManagementRequest;
11
+ exports.unpackCredentialManagementRequest = unpackCredentialManagementRequest;
10
12
  exports.unpackMakeCredentialResponse = unpackMakeCredentialResponse;
11
13
  exports.packMakeCredentialResponse = packMakeCredentialResponse;
12
14
  exports.unpackGetAssertionResponse = unpackGetAssertionResponse;
13
15
  exports.packGetAssertionResponse = packGetAssertionResponse;
14
16
  exports.unpackGetInfoResponse = unpackGetInfoResponse;
15
17
  exports.packGetInfoResponse = packGetInfoResponse;
18
+ exports.packCredentialManagementResponse = packCredentialManagementResponse;
19
+ exports.unpackCredentialManagementResponse = unpackCredentialManagementResponse;
16
20
  const encode_utils_1 = __importDefault(require("../libs/encode-utils"));
17
21
  /** @see https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#error-responses */
18
22
  var CTAP_STATUS_CODE;
@@ -36,7 +40,18 @@ var CTAP_COMMAND;
36
40
  CTAP_COMMAND[CTAP_COMMAND["authenticatorClientPIN"] = 6] = "authenticatorClientPIN";
37
41
  CTAP_COMMAND[CTAP_COMMAND["authenticatorReset"] = 7] = "authenticatorReset";
38
42
  CTAP_COMMAND[CTAP_COMMAND["authenticatorGetNextAssertion"] = 8] = "authenticatorGetNextAssertion";
43
+ CTAP_COMMAND[CTAP_COMMAND["authenticatorCredentialManagement"] = 10] = "authenticatorCredentialManagement";
39
44
  })(CTAP_COMMAND || (exports.CTAP_COMMAND = CTAP_COMMAND = {}));
45
+ var CREDENTIAL_MANAGEMENT_SUBCOMMAND;
46
+ (function (CREDENTIAL_MANAGEMENT_SUBCOMMAND) {
47
+ CREDENTIAL_MANAGEMENT_SUBCOMMAND[CREDENTIAL_MANAGEMENT_SUBCOMMAND["getCredsMetadata"] = 1] = "getCredsMetadata";
48
+ CREDENTIAL_MANAGEMENT_SUBCOMMAND[CREDENTIAL_MANAGEMENT_SUBCOMMAND["enumerateRPsBegin"] = 2] = "enumerateRPsBegin";
49
+ CREDENTIAL_MANAGEMENT_SUBCOMMAND[CREDENTIAL_MANAGEMENT_SUBCOMMAND["enumerateRPsGetNextRP"] = 3] = "enumerateRPsGetNextRP";
50
+ CREDENTIAL_MANAGEMENT_SUBCOMMAND[CREDENTIAL_MANAGEMENT_SUBCOMMAND["enumerateCredentialsBegin"] = 4] = "enumerateCredentialsBegin";
51
+ CREDENTIAL_MANAGEMENT_SUBCOMMAND[CREDENTIAL_MANAGEMENT_SUBCOMMAND["enumerateCredentialsGetNextCredential"] = 5] = "enumerateCredentialsGetNextCredential";
52
+ CREDENTIAL_MANAGEMENT_SUBCOMMAND[CREDENTIAL_MANAGEMENT_SUBCOMMAND["deleteCredential"] = 6] = "deleteCredential";
53
+ CREDENTIAL_MANAGEMENT_SUBCOMMAND[CREDENTIAL_MANAGEMENT_SUBCOMMAND["updateUserInformation"] = 7] = "updateUserInformation";
54
+ })(CREDENTIAL_MANAGEMENT_SUBCOMMAND || (exports.CREDENTIAL_MANAGEMENT_SUBCOMMAND = CREDENTIAL_MANAGEMENT_SUBCOMMAND = {}));
40
55
  // Not standard functions and interfaces
41
56
  class AuthenticationEmulatorError extends Error {
42
57
  status;
@@ -84,6 +99,24 @@ function unpackRequest(request) {
84
99
  pinProtocol: data[0x07],
85
100
  },
86
101
  };
102
+ case CTAP_COMMAND.authenticatorCredentialManagement:
103
+ return {
104
+ command: request.command,
105
+ request: {
106
+ subCommand: data[0x01],
107
+ subCommandParams: data[0x02]
108
+ ? {
109
+ credentialId: data[0x02][0x01]
110
+ ? encode_utils_1.default.bufferSourceToUint8Array(data[0x02][0x01])
111
+ : undefined,
112
+ rpId: data[0x02][0x02],
113
+ user: data[0x02][0x03],
114
+ }
115
+ : undefined,
116
+ pinUvAuthProtocol: data[0x03],
117
+ pinUvAuthParam: data[0x04] ? encode_utils_1.default.bufferSourceToUint8Array(data[0x04]) : undefined,
118
+ },
119
+ };
87
120
  default:
88
121
  return {
89
122
  command: request.command,
@@ -121,6 +154,46 @@ function packGetAssertionRequest(request) {
121
154
  }),
122
155
  };
123
156
  }
157
+ function packCredentialManagementRequest(request) {
158
+ return {
159
+ command: CTAP_COMMAND.authenticatorCredentialManagement,
160
+ data: encode_utils_1.default.encodeCbor({
161
+ [0x01]: request.subCommand,
162
+ [0x02]: request.subCommandParams
163
+ ? {
164
+ [0x01]: request.subCommandParams.credentialId,
165
+ [0x02]: request.subCommandParams.rpId,
166
+ [0x03]: request.subCommandParams.user,
167
+ }
168
+ : undefined,
169
+ [0x03]: request.pinUvAuthProtocol,
170
+ [0x04]: request.pinUvAuthParam,
171
+ }),
172
+ };
173
+ }
174
+ function unpackCredentialManagementRequest(request) {
175
+ try {
176
+ const data = encode_utils_1.default.decodeCbor(request.data);
177
+ const subCommandParams = data[0x02];
178
+ return {
179
+ subCommand: data[0x01],
180
+ subCommandParams: subCommandParams
181
+ ? {
182
+ credentialId: subCommandParams[0x01]
183
+ ? encode_utils_1.default.bufferSourceToUint8Array(subCommandParams[0x01])
184
+ : undefined,
185
+ rpId: subCommandParams[0x02],
186
+ user: subCommandParams[0x03],
187
+ }
188
+ : undefined,
189
+ pinUvAuthProtocol: data[0x03],
190
+ pinUvAuthParam: data[0x04] ? encode_utils_1.default.bufferSourceToUint8Array(data[0x04]) : undefined,
191
+ };
192
+ }
193
+ catch (error) {
194
+ throw new AuthenticationEmulatorError(CTAP_STATUS_CODE.CTAP2_ERR_INVALID_CBOR, { cause: error });
195
+ }
196
+ }
124
197
  function unpackMakeCredentialResponse(response) {
125
198
  try {
126
199
  const data = encode_utils_1.default.decodeCbor(response.data);
@@ -200,3 +273,42 @@ function packGetInfoResponse(response) {
200
273
  }),
201
274
  };
202
275
  }
276
+ function packCredentialManagementResponse(response) {
277
+ return {
278
+ status: CTAP_STATUS_CODE.CTAP2_OK,
279
+ data: encode_utils_1.default.encodeCbor({
280
+ [0x01]: response.existingResidentCredentialsCount,
281
+ [0x02]: response.maxPossibleRemainingResidentCredentialsCount,
282
+ [0x03]: response.rp,
283
+ [0x04]: response.rpIDHash,
284
+ [0x05]: response.totalRPs,
285
+ [0x06]: response.user,
286
+ [0x07]: response.credentialID,
287
+ [0x08]: response.publicKey,
288
+ [0x09]: response.totalCredentials,
289
+ [0x0a]: response.credProtect,
290
+ [0x0b]: response.largeBlobKey,
291
+ }),
292
+ };
293
+ }
294
+ function unpackCredentialManagementResponse(response) {
295
+ try {
296
+ const data = encode_utils_1.default.decodeCbor(response.data);
297
+ return {
298
+ existingResidentCredentialsCount: data[0x01],
299
+ maxPossibleRemainingResidentCredentialsCount: data[0x02],
300
+ rp: data[0x03],
301
+ rpIDHash: data[0x04] ? encode_utils_1.default.bufferSourceToUint8Array(data[0x04]) : undefined,
302
+ totalRPs: data[0x05],
303
+ user: data[0x06],
304
+ credentialID: data[0x07] ? encode_utils_1.default.bufferSourceToUint8Array(data[0x07]) : undefined,
305
+ publicKey: data[0x08] ? encode_utils_1.default.bufferSourceToUint8Array(data[0x08]) : undefined,
306
+ totalCredentials: data[0x09],
307
+ credProtect: data[0x0a],
308
+ largeBlobKey: data[0x0b] ? encode_utils_1.default.bufferSourceToUint8Array(data[0x0b]) : undefined,
309
+ };
310
+ }
311
+ catch (error) {
312
+ throw new AuthenticationEmulatorError(CTAP_STATUS_CODE.CTAP2_ERR_INVALID_CBOR, { cause: error });
313
+ }
314
+ }
@@ -12,5 +12,6 @@ export * from "./repository/credentials-memory-repository";
12
12
  export declare const BrowserInjection: {
13
13
  WebAuthnEmulatorGet: string;
14
14
  WebAuthnEmulatorCreate: string;
15
+ WebAuthnEmulatorSignalUnknownCredential: string;
15
16
  HookWebAuthnApis: string;
16
17
  };
package/dist/src/index.js CHANGED
@@ -30,5 +30,6 @@ __exportStar(require("./repository/credentials-memory-repository"), exports);
30
30
  exports.BrowserInjection = {
31
31
  WebAuthnEmulatorGet: browser_injection_1.WebAuthnEmulatorGet,
32
32
  WebAuthnEmulatorCreate: browser_injection_1.WebAuthnEmulatorCreate,
33
+ WebAuthnEmulatorSignalUnknownCredential: browser_injection_1.WebAuthnEmulatorSignalUnknownCredential,
33
34
  HookWebAuthnApis: browser_injection_1.HookWebAuthnApis,
34
35
  };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.PasskeysCredentialsFileRepository = void 0;
27
37
  const fs = __importStar(require("node:fs"));
@@ -1,3 +1,4 @@
1
1
  export declare const WebAuthnEmulatorGet = "webAuthnEmulatorGet";
2
2
  export declare const WebAuthnEmulatorCreate = "webAuthnEmulatorCreate";
3
+ export declare const WebAuthnEmulatorSignalUnknownCredential = "webAuthnEmulatorSignalUnknownCredential";
3
4
  export declare const HookWebAuthnApis: string;
@@ -15,18 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.HookWebAuthnApis = exports.WebAuthnEmulatorCreate = exports.WebAuthnEmulatorGet = void 0;
36
+ exports.HookWebAuthnApis = exports.WebAuthnEmulatorSignalUnknownCredential = exports.WebAuthnEmulatorCreate = exports.WebAuthnEmulatorGet = void 0;
27
37
  const Model = __importStar(require("../webauthn/webauthn-model-json"));
28
38
  exports.WebAuthnEmulatorGet = "webAuthnEmulatorGet";
29
39
  exports.WebAuthnEmulatorCreate = "webAuthnEmulatorCreate";
40
+ exports.WebAuthnEmulatorSignalUnknownCredential = "webAuthnEmulatorSignalUnknownCredential";
30
41
  const webAuthnModelExports = Object.values(Model)
31
42
  .map((m) => m.toString())
32
43
  .join("\n ");
@@ -47,6 +58,12 @@ exports.HookWebAuthnApis = `
47
58
  const responseJSON = await window.${exports.WebAuthnEmulatorGet}(optionsJSON);
48
59
  return parseAuthenticationResponseFromJSON(responseJSON);
49
60
  }
61
+
50
62
  PublicKeyCredential.isConditionalMediationAvailable = async () => true;
63
+
64
+ PublicKeyCredential.signalUnknownCredential = async (options) => {
65
+ if (!options || !options.rpId || !options.credentialId) return;
66
+ await window.${exports.WebAuthnEmulatorSignalUnknownCredential}(options);
67
+ }
51
68
  })();
52
69
  `;
@@ -1,5 +1,5 @@
1
1
  import { AuthenticatorEmulator } from "../authenticator/authenticator-emulator";
2
- import { type AuthenticationResponseJSON, type CreatePublicKeyCredential, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RegistrationResponseJSON, type RequestPublicKeyCredential } from "./webauthn-model-json";
2
+ import { type AuthenticationResponseJSON, type CreatePublicKeyCredential, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RegistrationResponseJSON, type RequestPublicKeyCredential, type UnknownCredentialOptionsJSON } from "./webauthn-model-json";
3
3
  export type AuthenticatorInfo = {
4
4
  version: string;
5
5
  aaguid: string;
@@ -23,6 +23,7 @@ export declare class WebAuthnEmulator {
23
23
  getJSON(origin: string, optionsJSON: PublicKeyCredentialRequestOptionsJSON): AuthenticationResponseJSON;
24
24
  createJSON(origin: string, optionsJSON: PublicKeyCredentialCreationOptionsJSON): RegistrationResponseJSON;
25
25
  getAuthenticatorInfo(): AuthenticatorInfo;
26
+ signalUnknownCredential(options: UnknownCredentialOptionsJSON): void;
26
27
  /** @see https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer/get */
27
28
  get(origin: string, options: CredentialRequestOptions): RequestPublicKeyCredential;
28
29
  /** @see https://developer.mozilla.org/ja/docs/Web/API/CredentialsContainer/create */
@@ -48,6 +48,17 @@ class WebAuthnEmulator {
48
48
  },
49
49
  };
50
50
  }
51
+ signalUnknownCredential(options) {
52
+ const credentialId = (0, webauthn_model_json_1.decodeBase64Url)(options.credentialId);
53
+ const request = (0, ctap_model_1.packCredentialManagementRequest)({
54
+ subCommand: ctap_model_1.CREDENTIAL_MANAGEMENT_SUBCOMMAND.deleteCredential,
55
+ subCommandParams: {
56
+ credentialId: encode_utils_1.default.bufferSourceToUint8Array(credentialId),
57
+ rpId: options.rpId,
58
+ },
59
+ });
60
+ this.authenticator.command(request);
61
+ }
51
62
  /** @see https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer/get */
52
63
  get(origin, options) {
53
64
  if (!options.publicKey)
@@ -91,6 +91,10 @@ export declare function toAuthenticationResponseJSON(credential: PublicKeyCreden
91
91
  export declare function toCreationOptionsJSON(options: PublicKeyCredentialCreationOptions): PublicKeyCredentialCreationOptionsJSON;
92
92
  export declare function toRequestOptionsJSON(options: PublicKeyCredentialRequestOptions): PublicKeyCredentialRequestOptionsJSON;
93
93
  export declare function parseRegistrationResponseFromJSON(options: RegistrationResponseJSON): CreatePublicKeyCredential;
94
+ export interface UnknownCredentialOptionsJSON {
95
+ rpId: string;
96
+ credentialId: Base64urlString;
97
+ }
94
98
  export declare function parseAuthenticationResponseFromJSON(options: AuthenticationResponseJSON): RequestPublicKeyCredential;
95
99
  export declare function toPublicKeyCredentialDescriptorJSON(credential: PublicKeyCredentialDescriptor): PublicKeyCredentialDescriptorJSON;
96
100
  export declare function parsePublicKeyCredentialDescriptorFromJSON(credential: PublicKeyCredentialDescriptorJSON): PublicKeyCredentialDescriptor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nid-webauthn-emulator",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "keywords": [
5
5
  "test",
6
6
  "e2e",
@@ -15,19 +15,19 @@
15
15
  "main": "dist/src/index.js",
16
16
  "types": "dist/src/index.d.ts",
17
17
  "devDependencies": {
18
- "@biomejs/biome": "^1.9.3",
18
+ "@biomejs/biome": "^1.9.4",
19
19
  "@jest/globals": "^29.7.0",
20
- "@simplewebauthn/server": "^11.0.0",
21
- "@tsconfig/recommended": "^1.0.7",
22
- "@types/node": "^22.7.5",
20
+ "@simplewebauthn/server": "^13.1.1",
21
+ "@tsconfig/recommended": "^1.0.8",
22
+ "@types/node": "^22.13.4",
23
23
  "jest": "^29.7.0",
24
24
  "ts-jest": "^29.2.5",
25
25
  "ts-node": "^10.9.2",
26
- "typescript": "^5.6.3"
26
+ "typescript": "^5.7.3"
27
27
  },
28
28
  "dependencies": {
29
- "cbor": "^9.0.2",
30
- "tldts": "^6.1.51"
29
+ "cbor": "^10.0.3",
30
+ "tldts": "^6.1.77"
31
31
  },
32
32
  "scripts": {
33
33
  "check": "biome check .",