Skip to content

Commit 26d8eab

Browse files
committed
feat(#4528): add place holder for feature/node-4528-naga-sdk-add-a-make-a-request-function-to-take
1 parent c754e60 commit 26d8eab

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

packages/auth/src/lib/AuthManager/auth-manager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getChildLogger } from '@lit-protocol/logger';
22
import { AuthData, HexPrefixedSchema } from '@lit-protocol/schemas';
3+
// import { AuthSig, SessionKeyPair } from '@lit-protocol/types';
34
import { z } from 'zod';
45
import { AuthConfigV2 } from '../authenticators/types';
56
import type { LitAuthStorageProvider } from '../storage/types';
@@ -73,6 +74,9 @@ export const createAuthManager = (authManagerParams: AuthManagerParams) => {
7374
pkpPublicKey: z.infer<typeof HexPrefixedSchema>;
7475
authConfig: AuthConfigV2;
7576
litClient: BaseAuthContext<any>['litClient'];
77+
// Optional pre-generated auth materials for server-side usage
78+
// sessionKeyPair?: SessionKeyPair;
79+
// delegationAuthSig?: AuthSig;
7680
}) => {
7781
return getPkpAuthContextAdapter(authManagerParams, params);
7882
},

packages/auth/src/lib/AuthManager/authAdapters/getPkpAuthContextAdapter.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
AuthData,
44
HexPrefixedSchema,
55
NodeUrlsSchema,
6+
// SessionKeyUriSchema,
67
} from '@lit-protocol/schemas';
8+
// import { AuthSig, LitResourceAbilityRequest, SessionKeyPair } from '@lit-protocol/types';
79
import { ethers } from 'ethers';
810
import { z } from 'zod';
911
import { 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+
2258
export 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

Comments
 (0)