@pump-fun/shared-contracts
Version:
Shared contracts for Pump.fun microservices.
102 lines (82 loc) • 2.74 kB
text/typescript
/**
* Shared authentication and JWT payload schemas
* Used across all pump.fun microservices for consistent JWT handling
*/
import { z } from "zod";
/**
* JWT payload schema for company-wide shared JWT tokens
* This ensures all required claims are present and properly typed
*
* This matches the JWT structure issued by the main pump.fun API
*/
export const JwtPayloadSchema = z
.object({
/** Alternative wallet address field used by mobile app */
address: z.string().min(1).optional(),
/** Audience (optional) */
aud: z.union([z.string(), z.array(z.string())]).optional(),
/** Era field from mobile app */
era: z.string().nullable().optional(),
/** Eras array from mobile app */
eras: z.array(z.any()).optional(),
/** Expiration timestamp (set by JWT library) */
exp: z.number().optional(),
/** Group field from mobile app */
group: z.string().nullable().optional(),
/** Issued at timestamp (set by JWT library) */
iat: z.number().optional(),
/** Issuer (optional) */
iss: z.string().optional(),
/** JWT ID (optional) */
jti: z.string().optional(),
/** Display name (optional) */
name: z.string().optional(),
/** Roles array from mobile app */
roles: z.array(z.string()).optional(),
/** User ID (required) - this is the wallet address */
sub: z.string().min(1, "User ID is required").optional(),
})
.refine((data) => data.sub || data.address, { message: "Either 'sub' or 'address' must be provided" });
/**
* Inferred TypeScript type from JWT payload schema
*/
export type JwtPayload = z.infer<typeof JwtPayloadSchema>;
/**
* User context schema after JWT validation
*/
export const AuthUserSchema = z.object({
exp: z.number().optional(),
iat: z.number().optional(),
name: z.string().optional(),
walletAddress: z.string(),
});
/**
* Inferred TypeScript type for authenticated user
*/
export type AuthUser = z.infer<typeof AuthUserSchema>;
/**
* Authentication context schema passed to oRPC procedures
* This provides a consistent interface for all microservices
*/
export const ProcedureContextSchema = z.object({
authError: z.string().optional(),
user: AuthUserSchema.optional(),
});
/**
* Inferred TypeScript type for procedure context
*/
export type ProcedureContext = z.infer<typeof ProcedureContextSchema>;
/**
* Schema for token validation request (development only)
*/
export const ValidateTokenRequestSchema = z.object({
token: z.string().min(1, "JWT token is required"),
});
/**
* Response schema for token validation
*/
export const ValidateTokenResponseSchema = z.object({
error: z.string().optional(),
user: AuthUserSchema.optional(),
valid: z.boolean(),
});