33 AuthData ,
44 HexPrefixedSchema ,
55 NodeUrlsSchema ,
6+ // SessionKeyUriSchema,
67} from '@lit-protocol/schemas' ;
8+ // import { AuthSig, LitResourceAbilityRequest, SessionKeyPair } from '@lit-protocol/types';
79import { ethers } from 'ethers' ;
810import { z } from 'zod' ;
911import { AuthConfigV2 } from '../../authenticators/types' ;
@@ -19,6 +21,40 @@ export const PkpAuthDepsSchema = z.object({
1921 nodeUrls : NodeUrlsSchema ,
2022} ) ;
2123
24+ /**
25+ * Validates that the provided delegation auth sig hasn't expired and contains required resources
26+ */
27+ // function validateDelegationAuthSig(
28+ // delegationAuthSig: AuthSig,
29+ // requiredResources: LitResourceAbilityRequest[],
30+ // sessionKeyUri: string
31+ // ): void {
32+ // try {
33+ // // Parse the signed message to extract expiration and validate session key match
34+ // const siweMessage = delegationAuthSig.signedMessage;
35+
36+ // // Check expiration
37+ // const expirationMatch = siweMessage.match(/^Expiration Time: (.*)$/m);
38+ // if (expirationMatch && expirationMatch[1]) {
39+ // const expiration = new Date(expirationMatch[1].trim());
40+ // if (expiration.getTime() <= Date.now()) {
41+ // throw new Error(`Delegation signature has expired at ${expiration.toISOString()}`);
42+ // }
43+ // }
44+
45+ // // Validate session key URI matches
46+ // if (!siweMessage.includes(sessionKeyUri)) {
47+ // throw new Error('Session key URI in delegation signature does not match provided session key pair');
48+ // }
49+
50+ // // TODO: Add resource validation - check if delegationAuthSig has required resources
51+ // // This would involve parsing the RECAP URN and checking against requiredResources
52+
53+ // } catch (error) {
54+ // throw new Error(`Invalid delegation signature: ${error instanceof Error ? error.message : 'Unknown error'}`);
55+ // }
56+ // }
57+
2258export async function getPkpAuthContextAdapter (
2359 upstreamParams : AuthManagerParams ,
2460 params : {
@@ -28,10 +64,53 @@ export async function getPkpAuthContextAdapter(
2864 litClient : {
2965 getContext : ( ) => Promise < any > ;
3066 } ;
67+ // Optional pre-generated auth materials
68+ // sessionKeyPair?: SessionKeyPair;
69+ // delegationAuthSig?: AuthSig;
3170 }
3271) {
3372 const _resources = processResources ( params . authConfig . resources ) ;
3473
74+ // // Validate optional parameters
75+ // if ((params.sessionKeyPair && !params.delegationAuthSig) ||
76+ // (!params.sessionKeyPair && params.delegationAuthSig)) {
77+ // throw new Error('Both sessionKeyPair and delegationAuthSig must be provided together, or neither should be provided');
78+ // }
79+
80+ // // If pre-generated auth materials are provided, validate and use them
81+ // if (params.sessionKeyPair && params.delegationAuthSig) {
82+ // // Generate sessionKeyUri from the public key
83+ // const sessionKeyUri = SessionKeyUriSchema.parse(params.sessionKeyPair.publicKey);
84+
85+ // // Validate the delegation signature
86+ // validateDelegationAuthSig(
87+ // params.delegationAuthSig,
88+ // _resources,
89+ // sessionKeyUri
90+ // );
91+
92+ // // Return auth context using provided materials
93+ // return {
94+ // chain: 'ethereum',
95+ // pkpPublicKey: params.pkpPublicKey,
96+ // authData: params.authData,
97+ // authConfig: {
98+ // domain: params.authConfig.domain!,
99+ // resources: _resources,
100+ // capabilityAuthSigs: params.authConfig.capabilityAuthSigs!,
101+ // expiration: params.authConfig.expiration!,
102+ // statement: params.authConfig.statement!,
103+ // },
104+ // sessionKeyPair: {
105+ // ...params.sessionKeyPair,
106+ // sessionKeyUri, // Add the generated sessionKeyUri to match expected interface
107+ // },
108+ // // Provide the pre-generated delegation signature
109+ // authNeededCallback: async () => params.delegationAuthSig!,
110+ // };
111+ // }
112+
113+ // Original logic for generating auth materials
35114 // TODO: 👇 The plan is to identify if the certain operations could be wrapped inside a single function
36115 // where different network modules can provide their own implementations.
37116
0 commit comments