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).
This commit is contained in:
Родитель
52758efa61
Коммит
ac826044a1
|
@ -96,7 +96,10 @@ In addition, we handle the following info (that is not technically part of exten
|
|||
|
||||
- [`transports`](https://w3c.github.io/webauthn/#dom-authenticatorattestationresponse-transports-slot) (on a public key credential)
|
||||
|
||||
If you need to convert additional input or output extensions, use `createExtended()` and `getExtended()` from `@github/webauthn-json/extended`.
|
||||
If you need to convert additional input or output extensions, use either of the following:
|
||||
|
||||
- `createExtended()` and `getExtended()` from `@github/webauthn-json/extended`.
|
||||
- `parseExtendedCreationOptionsFromJSON()` and `parseExtendedRequestOptionsFromJSON()` from `@github/webauthn-json/browser-ponyfill/extended`.
|
||||
|
||||
## Contributions
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"main": "../../dist/esm/webauthn-json.browser-ponyfill.extended.js",
|
||||
"types": "../../dist/types/browser-ponyfill.extended.d.ts"
|
||||
}
|
|
@ -24,6 +24,11 @@
|
|||
"require": "./dist/cjs/webauthn-json.browser-ponyfill.cjs",
|
||||
"import": "./dist/esm/webauthn-json.browser-ponyfill.js",
|
||||
"types": "./dist/types/browser-ponyfill.d.ts"
|
||||
},
|
||||
"./browser-ponyfill/extended": {
|
||||
"require": "./dist/cjs/webauthn-json.browser-ponyfill.extended.cjs",
|
||||
"import": "./dist/esm/webauthn-json.browser-ponyfill.extended.js",
|
||||
"types": "./dist/types/browser-ponyfill.extended.d.ts"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -66,6 +66,15 @@ build({
|
|||
outfile: "dist/esm/webauthn-json.browser-ponyfill.js",
|
||||
});
|
||||
|
||||
build({
|
||||
entryPoints: ["src/webauthn-json/browser-ponyfill.extended.ts"],
|
||||
format: "esm",
|
||||
target: "es2019",
|
||||
bundle: true,
|
||||
sourcemap: true,
|
||||
outfile: "dist/esm/webauthn-json.browser-ponyfill.extended.js",
|
||||
});
|
||||
|
||||
const { version } = JSON.parse(
|
||||
readFileSync(new URL("../package.json", import.meta.url)),
|
||||
);
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
import {
|
||||
createExtendedRequestFromJSON as parseExtendedCreationOptionsFromJSON,
|
||||
createExtendedResponseToJSON,
|
||||
CredentialCreationOptionsExtendedJSON,
|
||||
CredentialRequestOptionsExtendedJSON,
|
||||
getExtendedRequestFromJSON as parseExtendedRequestOptionsFromJSON,
|
||||
getExtendedResponseToJSON,
|
||||
PublicKeyCredentialWithAssertionExtendedResultsJSON as AuthenticationResponseExtendedJSON,
|
||||
PublicKeyCredentialWithAttestationExtendedResultsJSON as RegistrationResponseExtendedJSON,
|
||||
supported,
|
||||
} from "./extended";
|
||||
|
||||
export {
|
||||
parseExtendedCreationOptionsFromJSON,
|
||||
parseExtendedRequestOptionsFromJSON,
|
||||
supported,
|
||||
};
|
||||
export type {
|
||||
CredentialCreationOptionsExtendedJSON,
|
||||
CredentialRequestOptionsExtendedJSON,
|
||||
AuthenticationResponseExtendedJSON,
|
||||
RegistrationResponseExtendedJSON,
|
||||
};
|
||||
|
||||
export interface RegistrationPublicKeyCredential extends PublicKeyCredential {
|
||||
toJSON(): RegistrationResponseExtendedJSON;
|
||||
}
|
||||
|
||||
export async function createExtended(
|
||||
options: CredentialCreationOptions,
|
||||
): Promise<RegistrationPublicKeyCredential> {
|
||||
const response = (await navigator.credentials.create(
|
||||
options,
|
||||
)) as RegistrationPublicKeyCredential;
|
||||
response.toJSON = () => createExtendedResponseToJSON(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
export interface AuthenticationPublicKeyCredential extends PublicKeyCredential {
|
||||
toJSON(): AuthenticationResponseExtendedJSON;
|
||||
}
|
||||
|
||||
export async function getExtended(
|
||||
options: CredentialRequestOptions,
|
||||
): Promise<AuthenticationPublicKeyCredential> {
|
||||
const response = (await navigator.credentials.get(
|
||||
options,
|
||||
)) as AuthenticationPublicKeyCredential;
|
||||
response.toJSON = () => getExtendedResponseToJSON(response);
|
||||
return response;
|
||||
}
|
|
@ -1,25 +1,28 @@
|
|||
import {
|
||||
createExtendedRequestFromJSON as parseCreationOptionsFromJSON,
|
||||
createExtendedResponseToJSON,
|
||||
CredentialCreationOptionsExtendedJSON,
|
||||
CredentialRequestOptionsExtendedJSON,
|
||||
getExtendedRequestFromJSON as parseRequestOptionsFromJSON,
|
||||
getExtendedResponseToJSON,
|
||||
PublicKeyCredentialWithAssertionExtendedResultsJSON as AuthenticationResponseExtendedJSON,
|
||||
PublicKeyCredentialWithAttestationExtendedResultsJSON as RegistrationResponseExtendedJSON,
|
||||
supported,
|
||||
} from "./extended";
|
||||
createRequestFromJSON as parseCreationOptionsFromJSON,
|
||||
createResponseToJSON,
|
||||
getRequestFromJSON as parseRequestOptionsFromJSON,
|
||||
getResponseToJSON,
|
||||
} from "./basic/api";
|
||||
import { supported } from "./basic/supported";
|
||||
|
||||
import {
|
||||
CredentialCreationOptionsJSON,
|
||||
CredentialRequestOptionsJSON,
|
||||
PublicKeyCredentialWithAssertionJSON as AuthenticationResponseJSON,
|
||||
PublicKeyCredentialWithAttestationJSON as RegistrationResponseJSON,
|
||||
} from "./basic/json";
|
||||
|
||||
export { parseCreationOptionsFromJSON, parseRequestOptionsFromJSON, supported };
|
||||
export type {
|
||||
CredentialCreationOptionsExtendedJSON,
|
||||
CredentialRequestOptionsExtendedJSON,
|
||||
AuthenticationResponseExtendedJSON,
|
||||
RegistrationResponseExtendedJSON,
|
||||
CredentialCreationOptionsJSON,
|
||||
CredentialRequestOptionsJSON,
|
||||
AuthenticationResponseJSON,
|
||||
RegistrationResponseJSON,
|
||||
};
|
||||
|
||||
export interface RegistrationPublicKeyCredential extends PublicKeyCredential {
|
||||
toJSON(): RegistrationResponseExtendedJSON;
|
||||
toJSON(): RegistrationResponseJSON;
|
||||
}
|
||||
|
||||
export async function create(
|
||||
|
@ -28,12 +31,12 @@ export async function create(
|
|||
const response = (await navigator.credentials.create(
|
||||
options,
|
||||
)) as RegistrationPublicKeyCredential;
|
||||
response.toJSON = () => createExtendedResponseToJSON(response);
|
||||
response.toJSON = () => createResponseToJSON(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
export interface AuthenticationPublicKeyCredential extends PublicKeyCredential {
|
||||
toJSON(): AuthenticationResponseExtendedJSON;
|
||||
toJSON(): AuthenticationResponseJSON;
|
||||
}
|
||||
|
||||
export async function get(
|
||||
|
@ -42,6 +45,6 @@ export async function get(
|
|||
const response = (await navigator.credentials.get(
|
||||
options,
|
||||
)) as AuthenticationPublicKeyCredential;
|
||||
response.toJSON = () => getExtendedResponseToJSON(response);
|
||||
response.toJSON = () => getResponseToJSON(response);
|
||||
return response;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче