Skip to content

Commit

Permalink
chore: fixed statuslist result content type
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Jan 31, 2025
1 parent fc5bef6 commit ca3797f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions packages/vc-status-list-issuer-rest-api/src/api-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ import { checkAuth, sendErrorResponse } from '@sphereon/ssi-express-support'
import {
checkStatusIndexFromStatusListCredential,
CreateNewStatusListFuncArgs,
StatusListResult,
updateStatusIndexFromStatusListCredential,
} from '@sphereon/ssi-sdk.vc-status-list'
import { getDriver } from '@sphereon/ssi-sdk.vc-status-list-issuer-drivers'
import Debug from 'debug'
import { Request, Response, Router } from 'express'
import { ICredentialStatusListEndpointOpts, IRequiredContext, IW3CredentialStatusEndpointOpts, UpdateCredentialStatusRequest } from './types'
import { StatusListType } from '@sphereon/ssi-types'
import { StatusListCredential, StatusListType } from '@sphereon/ssi-types'

const debug = Debug('sphereon:ssi-sdk:status-list')

function sendStatuslistResponse(details: StatusListResult, statuslistPayload: StatusListCredential, response: Response) {
switch (details.proofFormat) {
case 'jwt':
case 'cbor':
const asciiData = Buffer.from(statuslistPayload as string, 'ascii')
return response.status(200).setHeader('Content-Type', details.statuslistContentType).send(asciiData)
default:
return response.status(200).setHeader('Content-Type', details.statuslistContentType).send(statuslistPayload)
}
}

export function createNewStatusListEndpoint(router: Router, context: IRequiredContext, opts: ICredentialStatusListEndpointOpts) {
if (opts?.enabled === false) {
console.log(`Create new status list endpoint is disabled`)
Expand All @@ -25,8 +37,9 @@ export function createNewStatusListEndpoint(router: Router, context: IRequiredCo
if (!statusListArgs) {
return sendErrorResponse(response, 400, 'No statusList details supplied')
}
const statusListDetails = await context.agent.slCreateStatusList(statusListArgs)
return response.send({ statusListDetails })
const details = await context.agent.slCreateStatusList(statusListArgs)
const statuslistPayload = details.statusListCredential
return sendStatuslistResponse(details, statuslistPayload, response)
} catch (e) {
return sendErrorResponse(response, 500, e.message as string, e)
}
Expand Down Expand Up @@ -59,9 +72,8 @@ export function getStatusListCredentialEndpoint(router: Router, context: IRequir
const correlationId = request.query.correlationId?.toString() ?? request.params.index?.toString() ?? request.originalUrl
const driver = await getDriver({ id: buildStatusListId(request), correlationId, dbName: opts.dbName })
const details = await driver.getStatusList()
response.statusCode = 200
response.set('Content-Type', details.statuslistContentType)
return response.send(details.statusListCredential)
const statuslistPayload = details.statusListCredential
return sendStatuslistResponse(details, statuslistPayload, response)
} catch (e) {
return sendErrorResponse(response, 500, e.message as string, e)
}
Expand Down Expand Up @@ -121,7 +133,7 @@ export function getStatusListCredentialIndexStatusEndpoint(router: Router, conte
}
}
response.statusCode = 200
return response.send({ ...entry, status })
return response.send({ ...entry, status }) // FIXME content type?
} catch (e) {
return sendErrorResponse(response, 500, e.message as string, e)
}
Expand Down Expand Up @@ -193,9 +205,8 @@ export function updateW3CStatusEndpoint(router: Router, context: IRequiredContex
details = await driver.updateStatusList({ statusListCredential: details.statusListCredential })
}

response.statusCode = 200
response.set('Content-Type', details.statuslistContentType)
return response.send(details.statusListCredential)
const statuslistPayload = details.statusListCredential
return sendStatuslistResponse(details, statuslistPayload, response)
} catch (e) {
return sendErrorResponse(response, 500, e.message as string, e)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vc-status-list/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface UpdateStatusListFromStatusListCredentialArgs {

export interface StatusListResult {
encodedList: string
statusListCredential: StatusListCredential // | CompactJWT
statusListCredential: StatusListCredential
length: number
type: StatusListType
proofFormat: ProofFormat
Expand Down

0 comments on commit ca3797f

Please sign in to comment.