34 lines
1 KiB
JavaScript
34 lines
1 KiB
JavaScript
/**
|
|
* @fileoverview Certificate verification with usage metering.
|
|
* @module services/verifyService
|
|
*/
|
|
|
|
import { veraeClient } from '../clients/veraeClient.js';
|
|
import { checkEntitlement, recordUsage } from './entitlementService.js';
|
|
import { createDebugger } from '../debug/logger.js';
|
|
|
|
const log = createDebugger('jobs');
|
|
|
|
/**
|
|
* @param {object} ctx
|
|
* @param {{ certificate: string }} body
|
|
*/
|
|
export async function verifyTimestamp(ctx, body) {
|
|
checkEntitlement(ctx.tenantId, 'verify');
|
|
const result = await veraeClient.verify(ctx.veraeToken, body);
|
|
recordUsage(ctx.tenantId, 'verify');
|
|
log.debug('verify result', { tenantId: ctx.tenantId, valid: result.valid });
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* @param {object} ctx
|
|
* @param {{ certificates: string[] }} body
|
|
*/
|
|
export async function verifyBatch(ctx, body) {
|
|
const amount = body.certificates?.length ?? 1;
|
|
checkEntitlement(ctx.tenantId, 'verify', { amount });
|
|
const result = await veraeClient.verifyBatch(ctx.veraeToken, body);
|
|
recordUsage(ctx.tenantId, 'verify', { amount });
|
|
return result;
|
|
}
|