Skip to content

Commit aa8c47f

Browse files
committed
fix(customAuthData): integrate CustomAuthDataSchema into utils and MintWithCustomAuthSchema for improved type consistency
1 parent 824f9cc commit aa8c47f

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

packages/lit-client/src/lib/LitClient/schemas/MintWithCustomAuthSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthData } from '@lit-protocol/schemas';
1+
import { AuthData, CustomAuthDataSchema } from '@lit-protocol/schemas';
22
import { Optional } from '@lit-protocol/types';
33
import { z } from 'zod';
44

@@ -9,7 +9,7 @@ const BaseMintWithCustomAuthSchema = z.object({
99
// Account information - this will be passed from the calling context
1010
account: z.any(), // Account type varies by network
1111
// Authentication data for the user
12-
authData: z.custom<Optional<AuthData, 'accessToken'>>(),
12+
authData: CustomAuthDataSchema,
1313
scope: z.enum(['no-permissions', 'sign-anything', 'personal-sign']),
1414
// Optional overrides
1515
addPkpEthAddressAsPermittedAddress: z.boolean().default(false),

packages/lit-client/src/lib/LitClient/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CustomAuthData } from '@lit-protocol/schemas';
1+
import { CustomAuthData, CustomAuthDataSchema } from '@lit-protocol/schemas';
22
import { hexToBigInt, keccak256, toBytes } from 'viem';
33

44
export const utils = {
@@ -60,9 +60,11 @@ export const utils = {
6060
}): CustomAuthData => {
6161
const uniqueUserId = `${uniqueDappName}-${userId}`;
6262

63-
return {
63+
const customAuthData = CustomAuthDataSchema.parse({
6464
authMethodType: uniqueAuthMethodType,
6565
authMethodId: keccak256(toBytes(uniqueUserId)),
66-
};
66+
});
67+
68+
return customAuthData;
6769
},
6870
};

packages/schemas/src/lib/auth/auth-schemas.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AUTH_METHOD_TYPE_VALUES } from '@lit-protocol/constants';
1+
import { AUTH_METHOD_TYPE } from '@lit-protocol/constants';
22
import { z } from 'zod';
33
import {
44
AuthMethodSchema,
@@ -9,6 +9,7 @@ import {
99

1010
export const CustomAuthDataSchema = z.object({
1111
authMethodId: HexPrefixedSchema,
12+
// This will be a very big number, unlike our native auth
1213
authMethodType: z.bigint(),
1314
});
1415

@@ -28,11 +29,7 @@ export type StrictAuthData = z.infer<typeof StrictAuthDataSchema>;
2829

2930
export const AuthDataSchema = z.object({
3031
authMethodId: HexPrefixedSchema,
31-
authMethodType: z.union([
32-
AuthMethodSchema.shape.authMethodType,
33-
z.number(),
34-
z.bigint(),
35-
]),
32+
authMethodType: z.coerce.number().pipe(z.nativeEnum(AUTH_METHOD_TYPE)),
3633
accessToken: AuthMethodSchema.shape.accessToken,
3734
publicKey: HexPrefixedSchema.optional(),
3835

0 commit comments

Comments
 (0)