@@ -9,15 +9,11 @@ import {
99 NodeSetSchema ,
1010 SessionKeyUriSchema ,
1111} from '../schemas' ;
12- import { ScopeStringSchema , SCOPE_MAPPING } from './ScopeSchema' ;
12+ import { ScopeStringSchema } from './ScopeSchema' ;
1313
1414export const AuthDataSchema = z . object ( {
1515 authMethodId : HexPrefixedSchema ,
16- authMethodType : z . union ( [
17- AuthMethodSchema . shape . authMethodType ,
18- z . number ( ) ,
19- z . bigint ( ) ,
20- ] ) ,
16+ authMethodType : z . coerce . number ( ) . pipe ( z . nativeEnum ( AUTH_METHOD_TYPE ) ) ,
2117 accessToken : AuthMethodSchema . shape . accessToken ,
2218 publicKey : HexPrefixedSchema . optional ( ) ,
2319
@@ -26,7 +22,8 @@ export const AuthDataSchema = z.object({
2622 metadata : z . any ( ) . optional ( ) ,
2723} ) ;
2824
29- export type AuthData = z . infer < typeof AuthDataSchema > ;
25+ export type AuthData = z . output < typeof AuthDataSchema > ;
26+ export type AuthDataInput = z . input < typeof AuthDataSchema > ;
3027
3128/**
3229 * Return Object Schema
@@ -77,48 +74,25 @@ export const JsonSignCustomSessionKeyRequestForPkpReturnSchema = z
7774export const MintPKPRequestSchema = z
7875 . object ( {
7976 authMethodId : HexPrefixedSchema ,
80- // Accept string, number, or enum for backwards compatibility
81- authMethodType : z
82- . union ( [
83- AuthMethodSchema . shape . authMethodType , // z.nativeEnum(AUTH_METHOD_TYPE)
84- z . string ( ) . transform ( ( val ) => parseInt ( val , 10 ) ) ,
85- z . number ( ) ,
86- ] )
87- . transform ( ( val ) => {
88- // Ensure it's a valid AUTH_METHOD_TYPE enum value
89- const numVal = typeof val === 'string' ? parseInt ( val , 10 ) : val ;
90- if ( ! Object . values ( AUTH_METHOD_TYPE ) . includes ( numVal as any ) ) {
91- throw new Error ( `Invalid authMethodType: ${ val } ` ) ;
92- }
93- return numVal as AUTH_METHOD_TYPE_VALUES ;
94- } ) ,
95- pubkey : HexPrefixedSchema . optional ( ) ,
77+ authMethodType : z . coerce . number ( ) . pipe ( z . nativeEnum ( AUTH_METHOD_TYPE ) ) ,
78+ pubkey : HexPrefixedSchema . default ( '0x' ) ,
9679 scopes : z . array ( ScopeStringSchema ) . optional ( ) . default ( [ ] ) ,
9780 } )
98- . transform ( async ( data ) => {
99- let derivedPubkey : z . infer < typeof HexPrefixedSchema > ;
100-
101- // Validate pubkey for WebAuthn
102- if ( data . authMethodType === AUTH_METHOD_TYPE . WebAuthn ) {
103- if ( ! data . pubkey || data . pubkey === '0x' ) {
104- throw new Error (
105- `pubkey is required for WebAuthn and cannot be 0x. Received pubkey: "${ data . pubkey } " and authMethodType: ${ data . authMethodType } `
106- ) ;
81+ . refine (
82+ ( data ) => {
83+ // Validate pubkey is present for WebAuthn
84+ // the default has been set to 0x, so we need to check when
85+ // webauthn is used the pubkey should NOT be 0x
86+ if ( data . authMethodType === AUTH_METHOD_TYPE . WebAuthn ) {
87+ return data . pubkey && data . pubkey !== '0x' ;
10788 }
108- derivedPubkey = data . pubkey ;
109- } else {
110- derivedPubkey = '0x' as z . infer < typeof HexPrefixedSchema > ;
89+ return true ;
90+ } ,
91+ {
92+ message : 'pubkey is required for WebAuthn and cannot be 0x' ,
93+ path : [ 'pubkey' ] ,
11194 }
112-
113- // Transform scope strings to bigints for contract calls
114- const scopeBigInts = data . scopes . map ( scope => SCOPE_MAPPING [ scope ] ) ;
115-
116- return {
117- ...data ,
118- pubkey : derivedPubkey ,
119- scopes : scopeBigInts ,
120- } ;
121- } ) ;
95+ ) ;
12296
12397export type MintPKPRequest = z . input < typeof MintPKPRequestSchema > ;
12498export type MintPKPRequestTransformed = z . output < typeof MintPKPRequestSchema > ;
0 commit comments