Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

Commit ac82604

Browse files
committed
Split the browser-ponyfill into regular and extended like the main build.
I originally wanted to use just the extended version, since that will provide a full ponyfill. But the extended build is smaller (≈30% unminifed, ≈10% minified).
1 parent 52758ef commit ac82604

File tree

6 files changed

+94
-19
lines changed

6 files changed

+94
-19
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ In addition, we handle the following info (that is not technically part of exten
9696

9797
- [`transports`](https://w3c.github.io/webauthn/#dom-authenticatorattestationresponse-transports-slot) (on a public key credential)
9898

99-
If you need to convert additional input or output extensions, use `createExtended()` and `getExtended()` from `@github/webauthn-json/extended`.
99+
If you need to convert additional input or output extensions, use either of the following:
100+
101+
- `createExtended()` and `getExtended()` from `@github/webauthn-json/extended`.
102+
- `parseExtendedCreationOptionsFromJSON()` and `parseExtendedRequestOptionsFromJSON()` from `@github/webauthn-json/browser-ponyfill/extended`.
100103

101104
## Contributions
102105

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"main": "../../dist/esm/webauthn-json.browser-ponyfill.extended.js",
3+
"types": "../../dist/types/browser-ponyfill.extended.d.ts"
4+
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"require": "./dist/cjs/webauthn-json.browser-ponyfill.cjs",
2525
"import": "./dist/esm/webauthn-json.browser-ponyfill.js",
2626
"types": "./dist/types/browser-ponyfill.d.ts"
27+
},
28+
"./browser-ponyfill/extended": {
29+
"require": "./dist/cjs/webauthn-json.browser-ponyfill.extended.cjs",
30+
"import": "./dist/esm/webauthn-json.browser-ponyfill.extended.js",
31+
"types": "./dist/types/browser-ponyfill.extended.d.ts"
2732
}
2833
},
2934
"devDependencies": {

script/build-js.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ build({
6666
outfile: "dist/esm/webauthn-json.browser-ponyfill.js",
6767
});
6868

69+
build({
70+
entryPoints: ["src/webauthn-json/browser-ponyfill.extended.ts"],
71+
format: "esm",
72+
target: "es2019",
73+
bundle: true,
74+
sourcemap: true,
75+
outfile: "dist/esm/webauthn-json.browser-ponyfill.extended.js",
76+
});
77+
6978
const { version } = JSON.parse(
7079
readFileSync(new URL("../package.json", import.meta.url)),
7180
);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
createExtendedRequestFromJSON as parseExtendedCreationOptionsFromJSON,
3+
createExtendedResponseToJSON,
4+
CredentialCreationOptionsExtendedJSON,
5+
CredentialRequestOptionsExtendedJSON,
6+
getExtendedRequestFromJSON as parseExtendedRequestOptionsFromJSON,
7+
getExtendedResponseToJSON,
8+
PublicKeyCredentialWithAssertionExtendedResultsJSON as AuthenticationResponseExtendedJSON,
9+
PublicKeyCredentialWithAttestationExtendedResultsJSON as RegistrationResponseExtendedJSON,
10+
supported,
11+
} from "./extended";
12+
13+
export {
14+
parseExtendedCreationOptionsFromJSON,
15+
parseExtendedRequestOptionsFromJSON,
16+
supported,
17+
};
18+
export type {
19+
CredentialCreationOptionsExtendedJSON,
20+
CredentialRequestOptionsExtendedJSON,
21+
AuthenticationResponseExtendedJSON,
22+
RegistrationResponseExtendedJSON,
23+
};
24+
25+
export interface RegistrationPublicKeyCredential extends PublicKeyCredential {
26+
toJSON(): RegistrationResponseExtendedJSON;
27+
}
28+
29+
export async function createExtended(
30+
options: CredentialCreationOptions,
31+
): Promise<RegistrationPublicKeyCredential> {
32+
const response = (await navigator.credentials.create(
33+
options,
34+
)) as RegistrationPublicKeyCredential;
35+
response.toJSON = () => createExtendedResponseToJSON(response);
36+
return response;
37+
}
38+
39+
export interface AuthenticationPublicKeyCredential extends PublicKeyCredential {
40+
toJSON(): AuthenticationResponseExtendedJSON;
41+
}
42+
43+
export async function getExtended(
44+
options: CredentialRequestOptions,
45+
): Promise<AuthenticationPublicKeyCredential> {
46+
const response = (await navigator.credentials.get(
47+
options,
48+
)) as AuthenticationPublicKeyCredential;
49+
response.toJSON = () => getExtendedResponseToJSON(response);
50+
return response;
51+
}
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
import {
2-
createExtendedRequestFromJSON as parseCreationOptionsFromJSON,
3-
createExtendedResponseToJSON,
4-
CredentialCreationOptionsExtendedJSON,
5-
CredentialRequestOptionsExtendedJSON,
6-
getExtendedRequestFromJSON as parseRequestOptionsFromJSON,
7-
getExtendedResponseToJSON,
8-
PublicKeyCredentialWithAssertionExtendedResultsJSON as AuthenticationResponseExtendedJSON,
9-
PublicKeyCredentialWithAttestationExtendedResultsJSON as RegistrationResponseExtendedJSON,
10-
supported,
11-
} from "./extended";
2+
createRequestFromJSON as parseCreationOptionsFromJSON,
3+
createResponseToJSON,
4+
getRequestFromJSON as parseRequestOptionsFromJSON,
5+
getResponseToJSON,
6+
} from "./basic/api";
7+
import { supported } from "./basic/supported";
8+
9+
import {
10+
CredentialCreationOptionsJSON,
11+
CredentialRequestOptionsJSON,
12+
PublicKeyCredentialWithAssertionJSON as AuthenticationResponseJSON,
13+
PublicKeyCredentialWithAttestationJSON as RegistrationResponseJSON,
14+
} from "./basic/json";
1215

1316
export { parseCreationOptionsFromJSON, parseRequestOptionsFromJSON, supported };
1417
export type {
15-
CredentialCreationOptionsExtendedJSON,
16-
CredentialRequestOptionsExtendedJSON,
17-
AuthenticationResponseExtendedJSON,
18-
RegistrationResponseExtendedJSON,
18+
CredentialCreationOptionsJSON,
19+
CredentialRequestOptionsJSON,
20+
AuthenticationResponseJSON,
21+
RegistrationResponseJSON,
1922
};
2023

2124
export interface RegistrationPublicKeyCredential extends PublicKeyCredential {
22-
toJSON(): RegistrationResponseExtendedJSON;
25+
toJSON(): RegistrationResponseJSON;
2326
}
2427

2528
export async function create(
@@ -28,12 +31,12 @@ export async function create(
2831
const response = (await navigator.credentials.create(
2932
options,
3033
)) as RegistrationPublicKeyCredential;
31-
response.toJSON = () => createExtendedResponseToJSON(response);
34+
response.toJSON = () => createResponseToJSON(response);
3235
return response;
3336
}
3437

3538
export interface AuthenticationPublicKeyCredential extends PublicKeyCredential {
36-
toJSON(): AuthenticationResponseExtendedJSON;
39+
toJSON(): AuthenticationResponseJSON;
3740
}
3841

3942
export async function get(
@@ -42,6 +45,6 @@ export async function get(
4245
const response = (await navigator.credentials.get(
4346
options,
4447
)) as AuthenticationPublicKeyCredential;
45-
response.toJSON = () => getExtendedResponseToJSON(response);
48+
response.toJSON = () => getResponseToJSON(response);
4649
return response;
4750
}

0 commit comments

Comments
 (0)