diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 70e23ef78..d7c6b6e0e 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -215,6 +215,14 @@ interface AuthenticationExtensionsClientOutputs { prf?: AuthenticationExtensionsPRFOutputs; } +interface AuthenticationExtensionsClientOutputsJSON { + appid?: boolean; + appidExclude?: boolean; + credProps?: CredentialPropertiesOutput; + largeBlob?: AuthenticationExtensionsLargeBlobOutputsJSON; + prf?: AuthenticationExtensionsPRFOutputsJSON; +} + interface AuthenticationExtensionsLargeBlobInputs { read?: boolean; support?: string; @@ -233,6 +241,12 @@ interface AuthenticationExtensionsLargeBlobOutputs { written?: boolean; } +interface AuthenticationExtensionsLargeBlobOutputsJSON { + blob?: Base64URLString; + supported?: boolean; + written?: boolean; +} + interface AuthenticationExtensionsPRFInputs { eval?: AuthenticationExtensionsPRFValues; evalByCredential?: Record; @@ -248,6 +262,11 @@ interface AuthenticationExtensionsPRFOutputs { results?: AuthenticationExtensionsPRFValues; } +interface AuthenticationExtensionsPRFOutputsJSON { + enabled?: boolean; + results?: AuthenticationExtensionsPRFValuesJSON; +} + interface AuthenticationExtensionsPRFValues { first: BufferSource; second?: BufferSource; @@ -258,6 +277,31 @@ interface AuthenticationExtensionsPRFValuesJSON { second?: Base64URLString; } +interface AuthenticationResponseJSON { + authenticatorAttachment?: string; + clientExtensionResults: AuthenticationExtensionsClientOutputsJSON; + id: string; + rawId: Base64URLString; + response: AuthenticatorAssertionResponseJSON; + type: string; +} + +interface AuthenticatorAssertionResponseJSON { + authenticatorData: Base64URLString; + clientDataJSON: Base64URLString; + signature: Base64URLString; + userHandle?: Base64URLString; +} + +interface AuthenticatorAttestationResponseJSON { + attestationObject: Base64URLString; + authenticatorData: Base64URLString; + clientDataJSON: Base64URLString; + publicKey?: Base64URLString; + publicKeyAlgorithm: COSEAlgorithmIdentifier; + transports: string[]; +} + interface AuthenticatorSelectionCriteria { authenticatorAttachment?: AuthenticatorAttachment; requireResidentKey?: boolean; @@ -2098,6 +2142,15 @@ interface RegistrationOptions { updateViaCache?: ServiceWorkerUpdateViaCache; } +interface RegistrationResponseJSON { + authenticatorAttachment?: string; + clientExtensionResults: AuthenticationExtensionsClientOutputsJSON; + id: string; + rawId: Base64URLString; + response: AuthenticatorAttestationResponseJSON; + type: string; +} + interface Report { body?: ReportBody | null; type?: string; @@ -26953,7 +27006,7 @@ interface PublicKeyCredential extends Credential { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PublicKeyCredential/toJSON) */ - toJSON(): PublicKeyCredentialJSON; + toJSON(): RegistrationResponseJSON | AuthenticationResponseJSON; } declare var PublicKeyCredential: { @@ -42398,7 +42451,6 @@ type OptionalPostfixToken = ` ${T}` | ""; type OptionalPrefixToken = `${T} ` | ""; type PerformanceEntryList = PerformanceEntry[]; type PublicKeyCredentialClientCapabilities = Record; -type PublicKeyCredentialJSON = any; type RTCRtpTransform = RTCRtpScriptTransform; type ReadableStreamController = ReadableStreamDefaultController | ReadableByteStreamController; type ReadableStreamReadResult = ReadableStreamReadValueResult | ReadableStreamReadDoneResult; diff --git a/baselines/ts5.5/dom.generated.d.ts b/baselines/ts5.5/dom.generated.d.ts index 308ad8250..ee561fd85 100644 --- a/baselines/ts5.5/dom.generated.d.ts +++ b/baselines/ts5.5/dom.generated.d.ts @@ -212,6 +212,14 @@ interface AuthenticationExtensionsClientOutputs { prf?: AuthenticationExtensionsPRFOutputs; } +interface AuthenticationExtensionsClientOutputsJSON { + appid?: boolean; + appidExclude?: boolean; + credProps?: CredentialPropertiesOutput; + largeBlob?: AuthenticationExtensionsLargeBlobOutputsJSON; + prf?: AuthenticationExtensionsPRFOutputsJSON; +} + interface AuthenticationExtensionsLargeBlobInputs { read?: boolean; support?: string; @@ -230,6 +238,12 @@ interface AuthenticationExtensionsLargeBlobOutputs { written?: boolean; } +interface AuthenticationExtensionsLargeBlobOutputsJSON { + blob?: Base64URLString; + supported?: boolean; + written?: boolean; +} + interface AuthenticationExtensionsPRFInputs { eval?: AuthenticationExtensionsPRFValues; evalByCredential?: Record; @@ -245,6 +259,11 @@ interface AuthenticationExtensionsPRFOutputs { results?: AuthenticationExtensionsPRFValues; } +interface AuthenticationExtensionsPRFOutputsJSON { + enabled?: boolean; + results?: AuthenticationExtensionsPRFValuesJSON; +} + interface AuthenticationExtensionsPRFValues { first: BufferSource; second?: BufferSource; @@ -255,6 +274,31 @@ interface AuthenticationExtensionsPRFValuesJSON { second?: Base64URLString; } +interface AuthenticationResponseJSON { + authenticatorAttachment?: string; + clientExtensionResults: AuthenticationExtensionsClientOutputsJSON; + id: string; + rawId: Base64URLString; + response: AuthenticatorAssertionResponseJSON; + type: string; +} + +interface AuthenticatorAssertionResponseJSON { + authenticatorData: Base64URLString; + clientDataJSON: Base64URLString; + signature: Base64URLString; + userHandle?: Base64URLString; +} + +interface AuthenticatorAttestationResponseJSON { + attestationObject: Base64URLString; + authenticatorData: Base64URLString; + clientDataJSON: Base64URLString; + publicKey?: Base64URLString; + publicKeyAlgorithm: COSEAlgorithmIdentifier; + transports: string[]; +} + interface AuthenticatorSelectionCriteria { authenticatorAttachment?: AuthenticatorAttachment; requireResidentKey?: boolean; @@ -2095,6 +2139,15 @@ interface RegistrationOptions { updateViaCache?: ServiceWorkerUpdateViaCache; } +interface RegistrationResponseJSON { + authenticatorAttachment?: string; + clientExtensionResults: AuthenticationExtensionsClientOutputsJSON; + id: string; + rawId: Base64URLString; + response: AuthenticatorAttestationResponseJSON; + type: string; +} + interface Report { body?: ReportBody | null; type?: string; @@ -26929,7 +26982,7 @@ interface PublicKeyCredential extends Credential { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PublicKeyCredential/toJSON) */ - toJSON(): PublicKeyCredentialJSON; + toJSON(): RegistrationResponseJSON | AuthenticationResponseJSON; } declare var PublicKeyCredential: { @@ -42372,7 +42425,6 @@ type OptionalPostfixToken = ` ${T}` | ""; type OptionalPrefixToken = `${T} ` | ""; type PerformanceEntryList = PerformanceEntry[]; type PublicKeyCredentialClientCapabilities = Record; -type PublicKeyCredentialJSON = any; type RTCRtpTransform = RTCRtpScriptTransform; type ReadableStreamController = ReadableStreamDefaultController | ReadableByteStreamController; type ReadableStreamReadResult = ReadableStreamReadValueResult | ReadableStreamReadDoneResult; diff --git a/baselines/ts5.6/dom.generated.d.ts b/baselines/ts5.6/dom.generated.d.ts index 3d8546117..08c30221b 100644 --- a/baselines/ts5.6/dom.generated.d.ts +++ b/baselines/ts5.6/dom.generated.d.ts @@ -212,6 +212,14 @@ interface AuthenticationExtensionsClientOutputs { prf?: AuthenticationExtensionsPRFOutputs; } +interface AuthenticationExtensionsClientOutputsJSON { + appid?: boolean; + appidExclude?: boolean; + credProps?: CredentialPropertiesOutput; + largeBlob?: AuthenticationExtensionsLargeBlobOutputsJSON; + prf?: AuthenticationExtensionsPRFOutputsJSON; +} + interface AuthenticationExtensionsLargeBlobInputs { read?: boolean; support?: string; @@ -230,6 +238,12 @@ interface AuthenticationExtensionsLargeBlobOutputs { written?: boolean; } +interface AuthenticationExtensionsLargeBlobOutputsJSON { + blob?: Base64URLString; + supported?: boolean; + written?: boolean; +} + interface AuthenticationExtensionsPRFInputs { eval?: AuthenticationExtensionsPRFValues; evalByCredential?: Record; @@ -245,6 +259,11 @@ interface AuthenticationExtensionsPRFOutputs { results?: AuthenticationExtensionsPRFValues; } +interface AuthenticationExtensionsPRFOutputsJSON { + enabled?: boolean; + results?: AuthenticationExtensionsPRFValuesJSON; +} + interface AuthenticationExtensionsPRFValues { first: BufferSource; second?: BufferSource; @@ -255,6 +274,31 @@ interface AuthenticationExtensionsPRFValuesJSON { second?: Base64URLString; } +interface AuthenticationResponseJSON { + authenticatorAttachment?: string; + clientExtensionResults: AuthenticationExtensionsClientOutputsJSON; + id: string; + rawId: Base64URLString; + response: AuthenticatorAssertionResponseJSON; + type: string; +} + +interface AuthenticatorAssertionResponseJSON { + authenticatorData: Base64URLString; + clientDataJSON: Base64URLString; + signature: Base64URLString; + userHandle?: Base64URLString; +} + +interface AuthenticatorAttestationResponseJSON { + attestationObject: Base64URLString; + authenticatorData: Base64URLString; + clientDataJSON: Base64URLString; + publicKey?: Base64URLString; + publicKeyAlgorithm: COSEAlgorithmIdentifier; + transports: string[]; +} + interface AuthenticatorSelectionCriteria { authenticatorAttachment?: AuthenticatorAttachment; requireResidentKey?: boolean; @@ -2095,6 +2139,15 @@ interface RegistrationOptions { updateViaCache?: ServiceWorkerUpdateViaCache; } +interface RegistrationResponseJSON { + authenticatorAttachment?: string; + clientExtensionResults: AuthenticationExtensionsClientOutputsJSON; + id: string; + rawId: Base64URLString; + response: AuthenticatorAttestationResponseJSON; + type: string; +} + interface Report { body?: ReportBody | null; type?: string; @@ -26950,7 +27003,7 @@ interface PublicKeyCredential extends Credential { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PublicKeyCredential/toJSON) */ - toJSON(): PublicKeyCredentialJSON; + toJSON(): RegistrationResponseJSON | AuthenticationResponseJSON; } declare var PublicKeyCredential: { @@ -42395,7 +42448,6 @@ type OptionalPostfixToken = ` ${T}` | ""; type OptionalPrefixToken = `${T} ` | ""; type PerformanceEntryList = PerformanceEntry[]; type PublicKeyCredentialClientCapabilities = Record; -type PublicKeyCredentialJSON = any; type RTCRtpTransform = RTCRtpScriptTransform; type ReadableStreamController = ReadableStreamDefaultController | ReadableByteStreamController; type ReadableStreamReadResult = ReadableStreamReadValueResult | ReadableStreamReadDoneResult; diff --git a/baselines/ts5.9/dom.generated.d.ts b/baselines/ts5.9/dom.generated.d.ts index 01b293947..d4a02a001 100644 --- a/baselines/ts5.9/dom.generated.d.ts +++ b/baselines/ts5.9/dom.generated.d.ts @@ -212,6 +212,14 @@ interface AuthenticationExtensionsClientOutputs { prf?: AuthenticationExtensionsPRFOutputs; } +interface AuthenticationExtensionsClientOutputsJSON { + appid?: boolean; + appidExclude?: boolean; + credProps?: CredentialPropertiesOutput; + largeBlob?: AuthenticationExtensionsLargeBlobOutputsJSON; + prf?: AuthenticationExtensionsPRFOutputsJSON; +} + interface AuthenticationExtensionsLargeBlobInputs { read?: boolean; support?: string; @@ -230,6 +238,12 @@ interface AuthenticationExtensionsLargeBlobOutputs { written?: boolean; } +interface AuthenticationExtensionsLargeBlobOutputsJSON { + blob?: Base64URLString; + supported?: boolean; + written?: boolean; +} + interface AuthenticationExtensionsPRFInputs { eval?: AuthenticationExtensionsPRFValues; evalByCredential?: Record; @@ -245,6 +259,11 @@ interface AuthenticationExtensionsPRFOutputs { results?: AuthenticationExtensionsPRFValues; } +interface AuthenticationExtensionsPRFOutputsJSON { + enabled?: boolean; + results?: AuthenticationExtensionsPRFValuesJSON; +} + interface AuthenticationExtensionsPRFValues { first: BufferSource; second?: BufferSource; @@ -255,6 +274,31 @@ interface AuthenticationExtensionsPRFValuesJSON { second?: Base64URLString; } +interface AuthenticationResponseJSON { + authenticatorAttachment?: string; + clientExtensionResults: AuthenticationExtensionsClientOutputsJSON; + id: string; + rawId: Base64URLString; + response: AuthenticatorAssertionResponseJSON; + type: string; +} + +interface AuthenticatorAssertionResponseJSON { + authenticatorData: Base64URLString; + clientDataJSON: Base64URLString; + signature: Base64URLString; + userHandle?: Base64URLString; +} + +interface AuthenticatorAttestationResponseJSON { + attestationObject: Base64URLString; + authenticatorData: Base64URLString; + clientDataJSON: Base64URLString; + publicKey?: Base64URLString; + publicKeyAlgorithm: COSEAlgorithmIdentifier; + transports: string[]; +} + interface AuthenticatorSelectionCriteria { authenticatorAttachment?: AuthenticatorAttachment; requireResidentKey?: boolean; @@ -2095,6 +2139,15 @@ interface RegistrationOptions { updateViaCache?: ServiceWorkerUpdateViaCache; } +interface RegistrationResponseJSON { + authenticatorAttachment?: string; + clientExtensionResults: AuthenticationExtensionsClientOutputsJSON; + id: string; + rawId: Base64URLString; + response: AuthenticatorAttestationResponseJSON; + type: string; +} + interface Report { body?: ReportBody | null; type?: string; @@ -26950,7 +27003,7 @@ interface PublicKeyCredential extends Credential { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PublicKeyCredential/toJSON) */ - toJSON(): PublicKeyCredentialJSON; + toJSON(): RegistrationResponseJSON | AuthenticationResponseJSON; } declare var PublicKeyCredential: { @@ -42395,7 +42448,6 @@ type OptionalPostfixToken = ` ${T}` | ""; type OptionalPrefixToken = `${T} ` | ""; type PerformanceEntryList = PerformanceEntry[]; type PublicKeyCredentialClientCapabilities = Record; -type PublicKeyCredentialJSON = any; type RTCRtpTransform = RTCRtpScriptTransform; type ReadableStreamController = ReadableStreamDefaultController | ReadableByteStreamController; type ReadableStreamReadResult = ReadableStreamReadValueResult | ReadableStreamReadDoneResult; diff --git a/inputfiles/patches/webauthn.kdl b/inputfiles/patches/webauthn.kdl index f2f166e3d..14e8374e7 100644 --- a/inputfiles/patches/webauthn.kdl +++ b/inputfiles/patches/webauthn.kdl @@ -1,3 +1,10 @@ +interface PublicKeyCredential { + method toJSON signatureIndex=0 { + type RegistrationResponseJSON + type AuthenticationResponseJSON + } +} + removals { enum AuthenticatorTransport { smart-card // WebKit only as of 2023-05 diff --git a/src/build/patches.ts b/src/build/patches.ts index 26368e585..b560b5174 100644 --- a/src/build/patches.ts +++ b/src/build/patches.ts @@ -48,13 +48,13 @@ function string(arg: unknown): string { return arg; } -function handleTyped(type: Node): DeepPartial { +function handleSingleTypeNode(type: Node): DeepPartial { const isTyped = type.name == "type"; if (!isTyped) { throw new Error("Expected a type node"); } const subType = - type.children.length > 0 ? handleTyped(type.children[0]) : undefined; + type.children.length > 0 ? handleTyped(type.children) : undefined; return { ...optionalMember("type", "string", type.values[0]), subtype: subType, @@ -62,6 +62,28 @@ function handleTyped(type: Node): DeepPartial { }; } +function handleTyped( + typeNodes: Node[], + returns?: Value, +): DeepPartial | undefined { + // Support multiple types, merged into array. If only one, keep as object. + let type: DeepPartial | undefined; + if (typeNodes.length === 1) { + type = handleSingleTypeNode(typeNodes[0]); + } else if (typeNodes.length > 1) { + const types = typeNodes.map(handleSingleTypeNode); + type = { type: types }; + } else if (returns) { + type = { + type: string(returns), + subtype: undefined, + }; + } else { + type = undefined; + } + return type; +} + function handleTypeParameters(value: Value | Node) { if (!value) { return {}; @@ -246,22 +268,14 @@ function handleEvent(child: Node): Event { * @param child The child node to handle. */ function handleProperty(child: Node): DeepPartial { - let typeNode: Node | undefined; - for (const c of child.children) { - if (c.name === "type") { - typeNode = c; - break; - } - } + const typeNodes = child.children.filter((c) => c.name === "type"); return { name: string(child.values[0]), ...optionalMember("exposed", "string", child.properties?.exposed), ...optionalMember("optional", "boolean", child.properties?.optional), ...optionalMember("overrideType", "string", child.properties?.overrideType), - ...(typeNode - ? handleTyped(typeNode) - : optionalMember("type", "string", child.properties?.type)), + ...handleTyped(typeNodes, child.properties?.type), ...optionalMember("readonly", "boolean", child.properties?.readonly), ...optionalMember("deprecated", "string", child.properties?.deprecated), }; @@ -300,16 +314,14 @@ function handleParam(node: Node) { function handleMethod(child: Node): DeepPartial { const name = string(child.values[0]); - let typeNode: Node | undefined; + // Collect all type nodes into an array + const typeNodes: Node[] = []; const params: Partial[] = []; for (const c of child.children) { switch (c.name) { case "type": - if (typeNode) { - throw new Error(`Method "${name}" has multiple type nodes (invalid)`); - } - typeNode = c; + typeNodes.push(c); break; case "param": @@ -321,16 +333,8 @@ function handleMethod(child: Node): DeepPartial { } } - const type = typeNode - ? handleTyped(typeNode) - : child.properties?.returns - ? { - type: string(child.properties?.returns), - subtype: undefined, - } - : null; - const signatureIndex = child.properties?.signatureIndex; + const type = handleTyped(typeNodes, child.properties?.returns); let signature: OverridableMethod["signature"] = []; if (type || params.length > 0) {