Skip to content

Commit e62eee8

Browse files
committed
fix(build): 33 type errors from different places in the codebase. Majority of them came from createContractManager which supplies incompatible client shapes (or mixing public/wallet inference) made Client generics collide. Explicit PublicClient annotation triggered heavy generic expansion and account mismatches. Letting TS infer the type from createPublicClient resolves this.
- removed capacity credits as we have remove this concept for Naga - Using `LitResourceAbilityRequestSchema` inferred type instead of legacy `CapacityDelegationRequest` (Types to be removed) - Login server Node's CJS resolving dir name - types on JobStatus - declare the `auth-services` package as types node - replaced @ts-expect-error in error.ts to @ts-ignore - fixed the type from Ajv - Introduced StrictAuthData instead of inline type - bindAccount helper in the createChainManagerFactory to fix signature mismatch - updated targets from ES2020 to ES2022
1 parent 52ed77c commit e62eee8

File tree

26 files changed

+452
-227
lines changed

26 files changed

+452
-227
lines changed

packages/access-control-conditions/src/lib/canonicalFormatter.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { type OperatorAcc } from '@lit-protocol/access-control-conditions-schemas';
1+
import {
2+
EvmContractAcc,
3+
type OperatorAcc,
4+
} from '@lit-protocol/access-control-conditions-schemas';
25
import { InvalidAccessControlConditions } from '@lit-protocol/constants';
36
import {
47
AccessControlConditions,
@@ -13,11 +16,6 @@ import {
1316
UnifiedAccessControlConditions,
1417
} from '@lit-protocol/types';
1518

16-
interface ABIParams {
17-
name: string;
18-
type: string;
19-
}
20-
2119
/** ---------- Local Functions ---------- */
2220
/**
2321
*
@@ -41,11 +39,15 @@ const getOperatorParam = (cond: ConditionItem): OperatorAcc => {
4139
* @param { Array<ABIParams> } params
4240
* @returns { Array<ABIParams> }
4341
*/
44-
const canonicalAbiParamss = (params: ABIParams[]): ABIParams[] => {
45-
return params.map((param) => ({
46-
name: param.name,
47-
type: param.type,
48-
}));
42+
const canonicalAbiParamss = (
43+
params: EvmContractAcc['functionAbi']['inputs']
44+
): EvmContractAcc['functionAbi']['outputs'] => {
45+
return params.map(
46+
(param: EvmContractAcc['functionAbi']['inputs'][number]) => ({
47+
name: param.name,
48+
type: param.type,
49+
})
50+
);
4951
};
5052

5153
/**

packages/auth-helpers/src/lib/siwe/create-siwe-message.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { SiweMessage } from 'siwe';
44
import { getGlobal, InvalidArgumentException } from '@lit-protocol/constants';
55
import {
66
BaseSiweMessage,
7-
CapacityDelegationFields,
87
WithCapacityDelegation,
98
WithRecap,
109
} from '@lit-protocol/types';
@@ -120,34 +119,6 @@ export const createSiweMessage = async <T extends BaseSiweMessage>(
120119

121120
let siweMessage = new SiweMessage(siweParams);
122121

123-
// -- create a message with capacity credits
124-
if (
125-
'dAppOwnerWallet' in params || // required param
126-
'uses' in params || // optional
127-
'delegateeAddresses' in params // optional
128-
// 'capacityTokenId' in params // optional
129-
) {
130-
const ccParams = params as CapacityDelegationFields;
131-
132-
const capabilities = createCapacityCreditsResourceData(ccParams);
133-
134-
params.resources = [
135-
{
136-
// TODO: new resource to be used
137-
// resource: new LitRLIResource(ccParams.capacityTokenId ?? '*'),
138-
// ability: LIT_ABILITY.RateLimitIncreaseAuth,
139-
140-
// @ts-expect-error - TODO: new resource to be used
141-
resource: null,
142-
143-
// @ts-expect-error - TODO: new ability to be used
144-
ability: null,
145-
// @ts-expect-error Complaining because of index signature in destination
146-
data: capabilities,
147-
},
148-
];
149-
}
150-
151122
// -- add recap resources if needed
152123
if (params.resources) {
153124
siweMessage = await addRecapToSiweMessage({

packages/auth-helpers/src/lib/siwe/siwe-helper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import {
66
} from '@lit-protocol/constants';
77
import {
88
CapacityDelegationFields,
9-
CapacityDelegationRequest,
109
ILitResource,
1110
ISessionCapabilityObject,
1211
LitResourceAbilityRequest,
1312
} from '@lit-protocol/types';
1413

1514
import { RecapSessionCapabilityObject } from '../recap/recap-session-capability-object';
15+
import { LitResourceAbilityRequestSchema } from '@lit-protocol/schemas';
16+
import { z } from 'zod';
1617

1718
/**
1819
* Sanitizes a SIWE message by unescaping double-escaped newlines and replacing escaped double quotes with single quotes.
@@ -35,7 +36,7 @@ export function sanitizeSiweMessage(message: string): string {
3536
*/
3637
export const createCapacityCreditsResourceData = (
3738
params: CapacityDelegationFields
38-
): CapacityDelegationRequest => {
39+
): z.infer<(typeof LitResourceAbilityRequestSchema)['shape']['data']> => {
3940
return {
4041
...(params.delegateeAddresses
4142
? {

packages/auth-services/src/login-server/src/app.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import express, { Express } from 'express';
22
import cors from 'cors';
33
import { OAuth2Client } from 'google-auth-library';
4-
import { fileURLToPath } from 'node:url';
54
import path from 'node:path';
6-
const __filename = fileURLToPath(import.meta.url);
7-
const __dirname = path.dirname(__filename);
5+
// Prefer Node's CJS globals when available; fallback to process.cwd()
6+
const resolvedDirname = typeof __dirname !== 'undefined' ? __dirname : process.cwd();
7+
8+
type DiscordTokenResponse = {
9+
access_token?: string;
10+
token_type?: string;
11+
scope?: string;
12+
expires_in?: number;
13+
refresh_token?: string;
14+
error?: string;
15+
};
816

917
export type LoginAppConfig = {
1018
origin: string;
@@ -32,12 +40,12 @@ export const createLoginApp = (config: LoginAppConfig): Express => {
3240
const app = express();
3341
app.use(cors({ origin: true, credentials: true }));
3442

35-
const staticDir = path.join(__dirname, 'public');
43+
const staticDir = path.join(resolvedDirname, 'public');
3644
app.use(express.static(staticDir, { index: 'index.html', maxAge: '1h' }));
3745

3846
// error page /error goes to /error.html
3947
app.get('/error', (req, res) => {
40-
res.sendFile(path.join(__dirname, 'public', 'error.html'));
48+
res.sendFile(path.join(resolvedDirname, 'public', 'error.html'));
4149
});
4250

4351
app.get('/auth/google', (req, res) => {
@@ -179,7 +187,7 @@ export const createLoginApp = (config: LoginAppConfig): Express => {
179187
body: params,
180188
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
181189
});
182-
const json = await response.json();
190+
const json = (await response.json()) as DiscordTokenResponse;
183191
if (!json.access_token) {
184192
const url = new URL(appRedirect);
185193
url.searchParams.set('error', 'invalid_access_token');

packages/auth-services/src/queue-manager/src/bullmqSetup.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,27 @@ export const addJob = async (
7979
return job;
8080
};
8181

82-
export const getJobStatus = async (jobId: string) => {
82+
export type JobStatusPayload =
83+
| { error: string }
84+
| {
85+
jobId: string | number;
86+
name: string;
87+
state: string;
88+
progress: unknown;
89+
timestamp: number;
90+
processedOn: number | null | undefined;
91+
finishedOn: number | null | undefined;
92+
returnValue: unknown;
93+
failedReason: string | null | undefined;
94+
};
95+
96+
export const getJobStatus = async (
97+
jobId: string
98+
): Promise<JobStatusPayload> => {
8399
const job = await getMainAppQueue().getJob(jobId);
84100

85-
if (!job) {
86-
return new Response(BigIntStringify({ error: 'Job not found.' }), {
87-
headers: { 'content-type': 'application/json' },
88-
status: 404,
89-
});
101+
if (!job || !job.id) {
102+
return { error: 'Job not found.' };
90103
}
91104

92105
const state = await job.getState();

packages/auth-services/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"module": "ES2022",
55
"target": "ES2022",
66
"moduleResolution": "bundler",
7+
"types": ["node"],
78
"forceConsistentCasingInFileNames": true,
89
"strict": false,
910
"noImplicitOverride": true,

packages/constants/src/lib/errors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// @ts-expect-error No types available for this package
1+
// The directive is “unused” because the import line isn’t erroring in this build context. @ts-expect-error only works when the next line definitely produces a TS error.
2+
// @ts-ignore No types available for this package
23
import { Options, VError } from '@openagenda/verror';
34

45
import { ConstantValues } from './constants/constants';

packages/crypto/src/lib/misc.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Ajv, { JSONSchemaType } from 'ajv';
1+
import Ajv, { SchemaObject, ValidateFunction } from 'ajv';
22

33
import {
44
InvalidArgumentException,
@@ -313,12 +313,16 @@ export const checkType = ({
313313
*/
314314
export const checkSchema = (
315315
value: any,
316-
schema: JSONSchemaType<any>,
316+
schema: SchemaObject | boolean,
317317
paramName: string,
318318
functionName: string,
319319
throwOnError: boolean = true
320320
): boolean => {
321-
let validate = schema.$id ? ajv.getSchema(schema.$id) : undefined;
321+
let validate: ValidateFunction | undefined =
322+
typeof schema === 'object' && schema && (schema as SchemaObject).$id
323+
? ajv.getSchema((schema as SchemaObject).$id as string)
324+
: undefined;
325+
322326
if (!validate) {
323327
validate = ajv.compile(schema);
324328
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
HexPrefixedSchema,
2222
JsonSignCustomSessionKeyRequestForPkpReturnSchema,
2323
JsonSignSessionKeyRequestForPkpReturnSchema,
24+
StrictAuthData,
2425
} from '@lit-protocol/schemas';
2526
import {
2627
DecryptRequest,
@@ -827,13 +828,7 @@ export const _createNagaLitClient = async (
827828
};
828829
},
829830
viewPKPsByAuthData: async (params: {
830-
authData:
831-
| {
832-
authMethodType: number | bigint;
833-
authMethodId: string;
834-
accessToken?: string;
835-
}
836-
| AuthData;
831+
authData: StrictAuthData | AuthData;
837832
pagination?: { limit?: number; offset?: number };
838833
}) => {
839834
// Use read-only account for viewing PKPs

packages/networks/src/networks/vNaga/shared/factories/BaseChainManagerFactory.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '../interfaces/NetworkContext';
1010
import type { PKPStorageProvider } from '../../../../storage/types';
1111
import { DEV_PRIVATE_KEY } from '@lit-protocol/constants';
12+
import { AuthData, StrictAuthData } from '@lit-protocol/schemas';
1213

1314
export type CreateChainManagerReturn = {
1415
api: {
@@ -26,11 +27,7 @@ export type CreateChainManagerReturn = {
2627
) => InstanceType<typeof api.PKPPermissionsManager>;
2728
paymentManager: () => InstanceType<typeof api.PaymentManager>;
2829
getPKPsByAuthData: (
29-
authData: {
30-
authMethodType: number | bigint;
31-
authMethodId: string;
32-
accessToken?: string;
33-
},
30+
authData: StrictAuthData | AuthData,
3431
pagination?: { limit?: number; offset?: number },
3532
storageProvider?: PKPStorageProvider
3633
) => ReturnType<typeof api.PKPPermissionsManager.getPKPsByAuthData>;
@@ -78,6 +75,15 @@ export const createChainManagerFactory = <T, M>(
7875
fn(req, _networkConfig, accountOrWalletClient);
7976
};
8077

78+
const bindAccount = <ReqArgType, RetType>(
79+
fn: (
80+
req: ReqArgType,
81+
accountOrWalletClient: ExpectedAccountOrWalletClient
82+
) => RetType
83+
) => {
84+
return (req: ReqArgType): RetType => fn(req, accountOrWalletClient);
85+
};
86+
8187
return {
8288
api: {
8389
mintWithEoa: bindContext(api.mintWithEoa),
@@ -135,8 +141,8 @@ export const createChainManagerFactory = <T, M>(
135141
);
136142
},
137143
pricing: {
138-
getPriceFeedInfo: bindContext(api.pricing.getPriceFeedInfo),
139-
getNodePrices: bindContext(api.pricing.getNodePrices),
144+
getPriceFeedInfo: bindAccount(api.pricing.getPriceFeedInfo),
145+
getNodePrices: bindAccount(api.pricing.getNodePrices),
140146
},
141147
connection: {
142148
getConnectionInfo: (args?: {

0 commit comments

Comments
 (0)