{ "version": 3, "sources": ["../../src/webauthn-json/index.ts", "../../src/webauthn-json/base64url.ts", "../../src/webauthn-json/convert.ts", "../../src/webauthn-json/basic/schema.ts", "../../src/webauthn-json/basic/api.ts", "../../src/webauthn-json/basic/supported.ts", "../../src/webauthn-json/browser-global.ts"], "sourcesContent": ["export { create, get } from \"./basic/api\";\r\nexport { supported } from \"./basic/supported\";\r\nexport { schema } from \"./basic/schema\";\r\n\r\nexport type {\r\n PublicKeyCredentialDescriptorJSON,\r\n PublicKeyCredentialWithAssertionJSON,\r\n PublicKeyCredentialWithAttestationJSON,\r\n CredentialCreationOptionsJSON,\r\n CredentialRequestOptionsJSON,\r\n} from \"./basic/json\";\r\n", "export type Base64urlString = string;\r\n\r\nexport function base64urlToBuffer(\r\n baseurl64String: Base64urlString,\r\n): ArrayBuffer {\r\n // Base64url to Base64\r\n const padding = \"==\".slice(0, (4 - (baseurl64String.length % 4)) % 4);\r\n const base64String =\r\n baseurl64String.replace(/-/g, \"+\").replace(/_/g, \"/\") + padding;\r\n\r\n // Base64 to binary string\r\n const str = atob(base64String);\r\n\r\n // Binary string to buffer\r\n const buffer = new ArrayBuffer(str.length);\r\n const byteView = new Uint8Array(buffer);\r\n for (let i = 0; i < str.length; i++) {\r\n byteView[i] = str.charCodeAt(i);\r\n }\r\n return buffer;\r\n}\r\n\r\nexport function bufferToBase64url(buffer: ArrayBuffer): Base64urlString {\r\n // Buffer to binary string\r\n const byteView = new Uint8Array(buffer);\r\n let str = \"\";\r\n for (const charCode of byteView) {\r\n str += String.fromCharCode(charCode);\r\n }\r\n\r\n // Binary string to base64\r\n const base64String = btoa(str);\r\n\r\n // Base64 to base64url\r\n // We assume that the base64url string is well-formed.\r\n const base64urlString = base64String.replace(/\\+/g, \"-\").replace(\r\n /\\//g,\r\n \"_\",\r\n ).replace(/=/g, \"\");\r\n return base64urlString;\r\n}\r\n", "// We export these values in order so that they can be used to deduplicate\r\n// schema definitions in minified JS code.\r\n\r\nimport { Schema, SchemaProperty } from \"./schema-format\";\r\n\r\n// TODO: Parcel isn't deduplicating these values.\r\nexport const copyValue = \"copy\";\r\nexport const convertValue = \"convert\";\r\n\r\nexport function convert(\r\n conversionFn: (v: From) => To,\r\n schema: Schema,\r\n input: any,\r\n): any {\r\n if (schema === copyValue) {\r\n return input;\r\n }\r\n if (schema === convertValue) {\r\n return conversionFn(input);\r\n }\r\n if (schema instanceof Array) {\r\n return input.map((v: any) => convert(conversionFn, schema[0], v));\r\n }\r\n if (schema instanceof Object) {\r\n const output: any = {};\r\n for (const [key, schemaField] of Object.entries(schema)) {\r\n if (schemaField.derive) {\r\n const v = schemaField.derive(input);\r\n if (v !== undefined) {\r\n input[key] = v;\r\n }\r\n }\r\n\r\n if (!(key in input)) {\r\n if (schemaField.required) {\r\n throw new Error(`Missing key: ${key}`);\r\n }\r\n continue;\r\n }\r\n // Fields can be null (rather than missing or `undefined`), e.g. the\r\n // `userHandle` field of the `AuthenticatorAssertionResponse`:\r\n // https://www.w3.org/TR/webauthn/#iface-authenticatorassertionresponse\r\n if (input[key] == null) {\r\n output[key] = null;\r\n continue;\r\n }\r\n output[key] = convert(\r\n conversionFn,\r\n schemaField.schema,\r\n input[key],\r\n );\r\n }\r\n return output;\r\n }\r\n}\r\n\r\nexport function derived(\r\n schema: Schema,\r\n derive: (v: any) => any,\r\n): SchemaProperty {\r\n return {\r\n required: true,\r\n schema,\r\n derive,\r\n };\r\n}\r\n\r\nexport function required(schema: Schema): SchemaProperty {\r\n return {\r\n required: true,\r\n schema,\r\n };\r\n}\r\n\r\nexport function optional(schema: Schema): SchemaProperty {\r\n return {\r\n required: false,\r\n schema,\r\n };\r\n}\r\n", "import { Schema } from \"../schema-format\";\r\nimport {\r\n convertValue as convert,\r\n copyValue as copy,\r\n derived,\r\n optional,\r\n required,\r\n} from \"../convert\";\r\n\r\n// Shared by `create()` and `get()`.\r\n\r\nconst publicKeyCredentialDescriptorSchema: Schema = {\r\n type: required(copy),\r\n id: required(convert),\r\n transports: optional(copy),\r\n};\r\n\r\nconst simplifiedExtensionsSchema: Schema = {\r\n appid: optional(copy),\r\n appidExclude: optional(copy),\r\n credProps: optional(copy),\r\n};\r\n\r\nconst simplifiedClientExtensionResultsSchema = {\r\n appid: optional(copy),\r\n appidExclude: optional(copy),\r\n credProps: optional(copy),\r\n};\r\n\r\n// `navigator.create()` request\r\n\r\nexport const credentialCreationOptions: Schema = {\r\n publicKey: required({\r\n rp: required(copy),\r\n user: required({\r\n id: required(convert),\r\n name: required(copy),\r\n displayName: required(copy),\r\n }),\r\n\r\n challenge: required(convert),\r\n pubKeyCredParams: required(copy),\r\n\r\n timeout: optional(copy),\r\n excludeCredentials: optional([publicKeyCredentialDescriptorSchema]),\r\n authenticatorSelection: optional(copy),\r\n attestation: optional(copy),\r\n extensions: optional(simplifiedExtensionsSchema),\r\n }),\r\n signal: optional(copy),\r\n};\r\n\r\n// `navigator.create()` response\r\n\r\nexport const publicKeyCredentialWithAttestation: Schema = {\r\n type: required(copy),\r\n id: required(copy),\r\n rawId: required(convert),\r\n authenticatorAttachment: optional(copy),\r\n response: required({\r\n clientDataJSON: required(convert),\r\n attestationObject: required(convert),\r\n transports: derived(\r\n copy,\r\n (response: any) => response.getTransports?.() || [],\r\n ),\r\n }),\r\n clientExtensionResults: derived(\r\n simplifiedClientExtensionResultsSchema,\r\n (pkc: PublicKeyCredential) => pkc.getClientExtensionResults(),\r\n ),\r\n};\r\n\r\n// `navigator.get()` request\r\n\r\nexport const credentialRequestOptions: Schema = {\r\n mediation: optional(copy),\r\n publicKey: required({\r\n challenge: required(convert),\r\n timeout: optional(copy),\r\n rpId: optional(copy),\r\n allowCredentials: optional([publicKeyCredentialDescriptorSchema]),\r\n userVerification: optional(copy),\r\n extensions: optional(simplifiedExtensionsSchema),\r\n }),\r\n signal: optional(copy),\r\n};\r\n\r\n// `navigator.get()` response\r\n\r\nexport const publicKeyCredentialWithAssertion: Schema = {\r\n type: required(copy),\r\n id: required(copy),\r\n rawId: required(convert),\r\n authenticatorAttachment: optional(copy),\r\n response: required({\r\n clientDataJSON: required(convert),\r\n authenticatorData: required(convert),\r\n signature: required(convert),\r\n userHandle: required(convert),\r\n }),\r\n clientExtensionResults: derived(\r\n simplifiedClientExtensionResultsSchema,\r\n (pkc: PublicKeyCredential) => pkc.getClientExtensionResults(),\r\n ),\r\n};\r\n\r\nexport const schema: { [s: string]: Schema } = {\r\n credentialCreationOptions,\r\n publicKeyCredentialWithAttestation,\r\n credentialRequestOptions,\r\n publicKeyCredentialWithAssertion,\r\n};\r\n", "import { base64urlToBuffer, bufferToBase64url } from \"../base64url\";\r\nimport { convert } from \"../convert\";\r\nimport {\r\n CredentialCreationOptionsJSON,\r\n CredentialRequestOptionsJSON,\r\n PublicKeyCredentialWithAssertionJSON,\r\n PublicKeyCredentialWithAttestationJSON,\r\n} from \"./json\";\r\nimport {\r\n credentialCreationOptions,\r\n credentialRequestOptions,\r\n publicKeyCredentialWithAssertion,\r\n publicKeyCredentialWithAttestation,\r\n} from \"./schema\";\r\n\r\nexport function createRequestFromJSON(\r\n requestJSON: CredentialCreationOptionsJSON,\r\n): CredentialCreationOptions {\r\n return convert(base64urlToBuffer, credentialCreationOptions, requestJSON);\r\n}\r\n\r\nexport function createResponseToJSON(\r\n credential: PublicKeyCredential,\r\n): PublicKeyCredentialWithAttestationJSON {\r\n return convert(\r\n bufferToBase64url,\r\n publicKeyCredentialWithAttestation,\r\n credential,\r\n );\r\n}\r\n\r\nexport async function create(\r\n requestJSON: CredentialCreationOptionsJSON,\r\n): Promise {\r\n const credential = (await navigator.credentials.create(\r\n createRequestFromJSON(requestJSON),\r\n )) as PublicKeyCredential;\r\n return createResponseToJSON(credential);\r\n}\r\n\r\nexport function getRequestFromJSON(\r\n requestJSON: CredentialRequestOptionsJSON,\r\n): CredentialRequestOptions {\r\n return convert(base64urlToBuffer, credentialRequestOptions, requestJSON);\r\n}\r\n\r\nexport function getResponseToJSON(\r\n credential: PublicKeyCredential,\r\n): PublicKeyCredentialWithAssertionJSON {\r\n return convert(\r\n bufferToBase64url,\r\n publicKeyCredentialWithAssertion,\r\n credential,\r\n );\r\n}\r\n\r\nexport async function get(\r\n requestJSON: CredentialRequestOptionsJSON,\r\n): Promise {\r\n const credential = (await navigator.credentials.get(\r\n getRequestFromJSON(requestJSON),\r\n )) as PublicKeyCredential;\r\n return getResponseToJSON(credential);\r\n}\r\n\r\ndeclare global {\r\n interface Window {\r\n PublicKeyCredential: PublicKeyCredential | undefined;\r\n }\r\n}\r\n", "// This function does a simple check to test for the credential management API\r\n// functions we need, and an indication of public key credential authentication\r\n// support.\r\n// https://developers.google.com/web/updates/2018/03/webauthn-credential-management\r\n\r\nexport function supported(): boolean {\r\n // rome-ignore format: Work around https://github.com/rome/tools/issues/3734\r\n return !!(\r\n // rome-ignore lint(style/useOptionalChain): Optional chaining creates more complicated ES2019 code\r\n navigator.credentials &&\r\n navigator.credentials.create &&\r\n navigator.credentials.get &&\r\n window.PublicKeyCredential\r\n );\r\n}\r\n", "import * as webauthnJSON from \"./index\";\r\n(globalThis as any).webauthnJSON = webauthnJSON;\r\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,WAAS,kBACd,iBACa;AAEb,UAAM,UAAU,KAAK,MAAM,IAAI,IAAK,gBAAgB,SAAS,KAAM,CAAC;AACpE,UAAM,eACJ,gBAAgB,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG,IAAI;AAG1D,UAAM,MAAM,KAAK,YAAY;AAG7B,UAAM,SAAS,IAAI,YAAY,IAAI,MAAM;AACzC,UAAM,WAAW,IAAI,WAAW,MAAM;AACtC,aAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,eAAS,KAAK,IAAI,WAAW,CAAC;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AAEO,WAAS,kBAAkB,QAAsC;AAEtE,UAAM,WAAW,IAAI,WAAW,MAAM;AAC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