Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/access-control-conditions/src/lib/humanizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,16 @@ export const humanizeEvmBasicAccessControlConditions = async ({
}

// Fallback for unhandled conditions - provide debugging information
logger.warn('Unhandled access control condition', {
standardContractType: acc.standardContractType,
method: acc.method,
contractAddress: acc.contractAddress,
chain: acc.chain,
conditionType: acc.conditionType,
});
logger.warn(
{
standardContractType: acc.standardContractType,
method: acc.method,
contractAddress: acc.contractAddress,
chain: acc.chain,
conditionType: acc.conditionType,
},
'Unhandled access control condition'
);

return `Unhandled condition: ${
acc.standardContractType || 'unknown'
Expand Down
60 changes: 36 additions & 24 deletions packages/auth-services/src/queue-manager/src/genericWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,43 @@ export function createGenericWorker() {
const worker = new Worker(
mainQueueName,
async (job) => {
logger.info(`Picked up job ${job.id} with name ${job.name}`, {
jobId: job.id,
jobName: job.name,
});
logger.info(
{
jobId: job.id,
jobName: job.name,
},
`Picked up job ${job.id} with name ${job.name}`
);
const handler = jobRegistry[job.name as JobName];

if (handler) {
try {
const result = await handler(job.data);
logger.info(`Job ${job.id} (${job.name}) completed successfully.`, {
jobId: job.id,
jobName: job.name,
});
logger.info(
{
jobId: job.id,
jobName: job.name,
},
`Job ${job.id} (${job.name}) completed successfully.`
);
return result; // Result is stored by BullMQ
} catch (error: any) {
logger.error(
`Handler for job ${job.id} (${job.name}) failed: ${error.message}`,
{
jobId: job.id,
jobName: job.name,
errorMessage: error.message,
stack: error.stack,
errorObject:
typeof error === 'object' && error !== null ? error : undefined,
}
},
`Handler for job ${job.id} (${job.name}) failed: ${error.message}`
);
throw error;
}
} else {
const errorMessage = `No handler found for job name: ${job.name}. Job ID: ${job.id}`;
logger.error(errorMessage, { jobId: job.id, jobName: job.name });
logger.error({ jobId: job.id, jobName: job.name }, errorMessage);
throw new Error(errorMessage); // Mark job as failed if no handler
}
},
Expand All @@ -55,10 +61,13 @@ export function createGenericWorker() {

worker.on('completed', (job, result) => {
if (job) {
logger.info(`Job ${job.id} (${job.name}) final state: completed.`, {
jobId: job.id,
jobName: job.name,
});
logger.info(
{
jobId: job.id,
jobName: job.name,
},
`Job ${job.id} (${job.name}) final state: completed.`
);
} else {
logger.warn(
'A job completed, but job details are unavailable in the event.'
Expand All @@ -69,29 +78,32 @@ export function createGenericWorker() {
worker.on('failed', (job, err) => {
if (job) {
logger.error(
`Job ${job.id} (${job.name}) final state: failed. Error: ${err.message}`,
{
jobId: job.id,
jobName: job.name,
errorMessage: err.message,
errorStack: err.stack,
}
},
`Job ${job.id} (${job.name}) final state: failed. Error: ${err.message}`
);
} else {
logger.error(
`A job failed, but job details are unavailable in the event. Error: ${err.message}`,
{ errorMessage: err.message, errorStack: err.stack }
{ errorMessage: err.message, errorStack: err.stack },
`A job failed, but job details are unavailable in the event. Error: ${err.message}`
);
}
});

worker.on('error', (err) => {
// This is for errors in the worker itself, not necessarily job failures
logger.error('Generic BullMQ worker instance encountered an error:', {
errorMessage: err.message,
errorStack: err.stack,
errorObject: typeof err === 'object' && err !== null ? err : undefined,
});
logger.error(
{
errorMessage: err.message,
errorStack: err.stack,
errorObject: typeof err === 'object' && err !== null ? err : undefined,
},
'Generic BullMQ worker instance encountered an error:'
);
});

return worker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ const prepareCustomAuthRequestBody = async (
export const getCustomAuthContext = async (
params: z.infer<typeof GetCustomAuthContextSchema>
) => {
_logger.info('getCustomAuthContext: params', {
params,
});
_logger.info(
{
params,
},
'getCustomAuthContext: params'
);

// const _params = GetCustomAuthContextSchema.parse(params);
const _params = params;
Expand Down Expand Up @@ -186,9 +189,12 @@ export const getCustomAuthContext = async (
}),
});

_logger.info('getCustomAuthContext: delegationAuthSig', {
delegationAuthSig,
});
_logger.info(
{
delegationAuthSig,
},
'getCustomAuthContext: delegationAuthSig'
);

return {
chain: 'ethereum',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ const preparePkpAuthRequestBody = async (
export const getPkpAuthContext = async (
params: z.infer<typeof GetPkpAuthContextSchema>
) => {
_logger.info('getPkpAuthContext: params', {
params,
});
_logger.info(
{
params,
},
'getPkpAuthContext: params'
);

const _params = GetPkpAuthContextSchema.parse(params);
const _nodeInfo = NodeInfoSchema.parse(params.deps.connection.nodeUrls);
Expand Down Expand Up @@ -155,9 +158,12 @@ export const getPkpAuthContext = async (
}),
});

_logger.info('getPkpAuthContext: delegationAuthSig', {
delegationAuthSig,
});
_logger.info(
{
delegationAuthSig,
},
'getPkpAuthContext: delegationAuthSig'
);

return {
chain: 'ethereum',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,65 @@ export async function tryGetCachedAuthData(params: {
address: params.address,
})) as LitAuthData | null; // Allow null if nothing is found

_logger.info('tryGetCachedAuthData: Attempting to read from cache', {
address: params.address,
foundInCache: !!authData,
});
_logger.info(
{
address: params.address,
foundInCache: !!authData,
},
'tryGetCachedAuthData: Attempting to read from cache'
);

if (authData && authData.sessionKey && authData.sessionKey.expiresAt) {
try {
const expirationDate = new Date(authData.sessionKey.expiresAt);
if (expirationDate.getTime() > Date.now()) {
_logger.info(
'tryGetCachedAuthData: Found valid (unexpired) cached auth data',
{
address: params.address,
expiresAt: authData.sessionKey.expiresAt,
}
},
'tryGetCachedAuthData: Found valid (unexpired) cached auth data'
);
return authData; // Return valid, unexpired authData
} else {
_logger.info('tryGetCachedAuthData: Cached auth data has expired', {
address: params.address,
expiredAt: authData.sessionKey.expiresAt,
});
_logger.info(
{
address: params.address,
expiredAt: authData.sessionKey.expiresAt,
},
'tryGetCachedAuthData: Cached auth data has expired'
);
authData = null; // Treat as not found if expired
}
} catch (e: any) {
_logger.warn(
'tryGetCachedAuthData: Error parsing expirationDate from cached auth data. Will regenerate.',
{
address: params.address,
expiresAtValue: authData!.sessionKey!.expiresAt,
error: e.message || e,
}
},
'tryGetCachedAuthData: Error parsing expirationDate from cached auth data. Will regenerate.'
);
authData = null; // Treat as not found if parsing fails
}
} else if (authData) {
_logger.warn(
'tryGetCachedAuthData: Cached auth data found, but sessionKey or expiresAt is missing. Will regenerate.',
{
address: params.address,
authDataPreview: JSON.stringify(authData).substring(0, 200),
}
},
'tryGetCachedAuthData: Cached auth data found, but sessionKey or expiresAt is missing. Will regenerate.'
);
authData = null; // Treat as not found if incomplete
}

// If authData is null at this point (either not found, expired, or invalid), generate new.
if (!authData) {
_logger.info(
'tryGetCachedAuthData: No valid cached auth data found or cache expired/invalid. Generating new auth data.',
{
address: params.address,
}
},
'tryGetCachedAuthData: No valid cached auth data found or cache expired/invalid. Generating new auth data.'
);

const _expiration = ExpirationSchema.parse(params.expiration);
Expand All @@ -108,9 +114,12 @@ export async function tryGetCachedAuthData(params: {
address: params.address,
authData,
});
_logger.info('tryGetCachedAuthData: Generated and saved new auth data.', {
address: params.address,
});
_logger.info(
{
address: params.address,
},
'tryGetCachedAuthData: Generated and saved new auth data.'
);
}

// Final check to ensure authData is not null, which should be guaranteed by the logic above.
Expand All @@ -124,10 +133,13 @@ export async function tryGetCachedAuthData(params: {

const finalAuthData: LitAuthData = authData;

_logger.info('tryGetCachedAuthData: Success, returning auth data.', {
address: params.address,
// authData, // Avoid logging full authData which may contain sensitive info like keyPair and also resolves linter issue.
});
_logger.info(
{
address: params.address,
// authData, // Avoid logging full authData which may contain sensitive info like keyPair and also resolves linter issue.
},
'tryGetCachedAuthData: Success, returning auth data.'
);

return finalAuthData;
}
Loading
Loading