Replace z.any() with z.custom<T>() for WebAuthn types

Use proper TypeScript types from @simplewebauthn/types instead of
z.any() for WebAuthn-related schemas:
- PublicKeyCredentialCreationOptionsJSON
- PublicKeyCredentialRequestOptionsJSON
- RegistrationResponseJSON
- AuthenticationResponseJSON

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
RevIQ
2026-01-09 12:17:29 +08:00
parent b6bce41092
commit a4dff188eb
4 changed files with 17 additions and 6 deletions

View File

@@ -84,6 +84,7 @@
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"@orpc/contract": "^1.13.2", "@orpc/contract": "^1.13.2",
"@simplewebauthn/types": "^12.0.0",
"libphonenumber-js": "^1.12.33", "libphonenumber-js": "^1.12.33",
"zod": "^4.3.5", "zod": "^4.3.5",
}, },
@@ -351,6 +352,8 @@
"@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.55.1", "", { "os": "win32", "cpu": "x64" }, "sha512-SPEpaL6DX4rmcXtnhdrQYgzQ5W2uW3SCJch88lB2zImhJRhIIK44fkUrgIV/Q8yUNfw5oyZ5vkeQsZLhCb06lw=="], "@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.55.1", "", { "os": "win32", "cpu": "x64" }, "sha512-SPEpaL6DX4rmcXtnhdrQYgzQ5W2uW3SCJch88lB2zImhJRhIIK44fkUrgIV/Q8yUNfw5oyZ5vkeQsZLhCb06lw=="],
"@simplewebauthn/types": ["@simplewebauthn/types@12.0.0", "", {}, "sha512-q6y8MkoV8V8jB4zzp18Uyj2I7oFp2/ONL8c3j8uT06AOWu3cIChc1au71QYHrP2b+xDapkGTiv+9lX7xkTlAsA=="],
"@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="], "@standard-schema/spec": ["@standard-schema/spec@1.1.0", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],
"@stricli/core": ["@stricli/core@1.2.5", "", {}, "sha512-+afyztQW7fwWkqmU2WQZbdc3LjnZThWYdtE0l+hykZ1Rvy7YGxZSvsVCS/wZ/2BNv117pQ9TU1GZZRIcPnB4tw=="], "@stricli/core": ["@stricli/core@1.2.5", "", {}, "sha512-+afyztQW7fwWkqmU2WQZbdc3LjnZThWYdtE0l+hykZ1Rvy7YGxZSvsVCS/wZ/2BNv117pQ9TU1GZZRIcPnB4tw=="],

View File

@@ -17,6 +17,7 @@
}, },
"dependencies": { "dependencies": {
"@orpc/contract": "^1.13.2", "@orpc/contract": "^1.13.2",
"@simplewebauthn/types": "^12.0.0",
"libphonenumber-js": "^1.12.33", "libphonenumber-js": "^1.12.33",
"zod": "^4.3.5" "zod": "^4.3.5"
}, },

View File

@@ -1,3 +1,9 @@
import type {
AuthenticationResponseJSON,
PublicKeyCredentialCreationOptionsJSON,
PublicKeyCredentialRequestOptionsJSON,
RegistrationResponseJSON,
} from "@simplewebauthn/types";
import { oc } from "@orpc/contract"; import { oc } from "@orpc/contract";
import * as z from "zod"; import * as z from "zod";
import { import {
@@ -72,28 +78,28 @@ export const contract = oc.router({
.output( .output(
z.object({ z.object({
challengeId: z.number(), challengeId: z.number(),
options: z.any(), // PublicKeyCredentialCreationOptionsJSON options: z.custom<PublicKeyCredentialCreationOptionsJSON>(),
}), }),
), ),
verifyRegistration: oc verifyRegistration: oc
.input( .input(
z.object({ z.object({
challengeId: z.number(), challengeId: z.number(),
response: z.any(), // RegistrationResponseJSON response: z.custom<RegistrationResponseJSON>(),
}), }),
) )
.output(z.void()), .output(z.void()),
createAuthenticationOptions: oc.output( createAuthenticationOptions: oc.output(
z.object({ z.object({
challengeId: z.number(), challengeId: z.number(),
options: z.any(), // PublicKeyCredentialRequestOptionsJSON options: z.custom<PublicKeyCredentialRequestOptionsJSON>(),
}), }),
), ),
verifyAuthentication: oc verifyAuthentication: oc
.input( .input(
z.object({ z.object({
challengeId: z.number(), challengeId: z.number(),
response: z.any(), // AuthenticationResponseJSON response: z.custom<AuthenticationResponseJSON>(),
}), }),
) )
.output(z.void()), .output(z.void()),
@@ -113,7 +119,7 @@ export const contract = oc.router({
createPasskey: oc.input(z.object({ name: z.string() })).output( createPasskey: oc.input(z.object({ name: z.string() })).output(
z.object({ z.object({
challengeId: z.number(), challengeId: z.number(),
options: z.any(), // PublicKeyCredentialCreationOptionsJSON options: z.custom<PublicKeyCredentialCreationOptionsJSON>(),
}), }),
), ),
renamePasskey: oc renamePasskey: oc

View File

@@ -1,3 +1,4 @@
import type { RegistrationResponseJSON } from "@simplewebauthn/types";
import * as z from "zod"; import * as z from "zod";
import { emailSchema } from "./common.js"; import { emailSchema } from "./common.js";
@@ -8,7 +9,7 @@ import { emailSchema } from "./common.js";
*/ */
export const passkeyInfoSchema = z.object({ export const passkeyInfoSchema = z.object({
challengeId: z.number(), challengeId: z.number(),
response: z.any(), // RegistrationResponseJSON from @simplewebauthn/browser response: z.custom<RegistrationResponseJSON>(),
}); });
/** /**