Skip to content

Commit 7741913

Browse files
committed
fix(schemas): Custom Auth Data types
1 parent 91499fa commit 7741913

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CustomAuthData, CustomAuthDataSchema } from '@lit-protocol/schemas';
12
import { hexToBigInt, keccak256, toBytes } from 'viem';
23

34
export const utils = {
@@ -56,12 +57,14 @@ export const utils = {
5657
uniqueDappName: string;
5758
uniqueAuthMethodType: bigint;
5859
userId: string;
59-
}) => {
60+
}): CustomAuthData => {
6061
const uniqueUserId = `${uniqueDappName}-${userId}`;
6162

62-
return {
63+
const customAuthData = CustomAuthDataSchema.parse({
6364
authMethodType: uniqueAuthMethodType,
6465
authMethodId: keccak256(toBytes(uniqueUserId)),
65-
};
66+
});
67+
68+
return customAuthData;
6669
},
6770
};

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import {
1111
} from '../schemas';
1212
import { ScopeSchemaRaw } from './ScopeSchema';
1313

14+
export const CustomAuthDataSchema = z.object({
15+
authMethodId: HexPrefixedSchema,
16+
// This will be a very big number, unlike our native auth
17+
authMethodType: z.bigint(),
18+
});
19+
20+
export type CustomAuthData = z.infer<typeof CustomAuthDataSchema>;
21+
1422
export const AuthDataSchema = z.object({
1523
authMethodId: HexPrefixedSchema,
1624
authMethodType: z.coerce.number().pipe(z.nativeEnum(AUTH_METHOD_TYPE)),

0 commit comments

Comments
 (0)