-
Notifications
You must be signed in to change notification settings - Fork 239
feat(cheqd): Add Token StatusList Service #2325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: DaevMithran <daevmithran1999@gmail.com>
|
import { TokenStatusList } from './types/tokenStatusList' | ||
import { CheqdApi } from '../CheqdApi' | ||
import { parseCheqdDid } from '../anoncreds/utils/identifiers' | ||
import base64url from 'base64url' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have base64url support in the TypedArrayEncoder
in the core package
const jwt = resource.resource?.data.toString() | ||
const payload = JSON.parse(Buffer.from(jwt!.split('.')[1], 'base64').toString()) as StatusListPayload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WE have tools like the Jwt.fromSerializedJwt
to parse JWTs.
Also should we not verify it first?
const payload: StatusListPayload = { | ||
iss: did, | ||
iat: Math.floor(Date.now() / 1000), | ||
status_list: { | ||
encoding: 'bitstring', | ||
bits: encodeBitmap(bitmap), | ||
}, | ||
} | ||
|
||
const jwt = await signer.signJWT(payload) | ||
|
||
const resource = { | ||
collectionId: did.split(':')[3], | ||
id: utils.uuid(), | ||
name: name, | ||
resourceType: 'StatusList', | ||
data: jwt, | ||
version: tag || utils.uuid(), | ||
} satisfies CheqdCreateResourceOptions | ||
|
||
await api.createResource(did, resource) | ||
|
||
return { | ||
jwt, | ||
metadata: { | ||
statusListId: resource.id, | ||
issuedAt: payload.iat, | ||
size: size, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have quite some utils also to create JWTs. See the Jwt service, also we should probably make a generic status list service that creates the status list (like we have an SD-JWT VC service) which works with a signer.method
(see sd-jwt-vc service) which can be a cheqd did or a x509 cert for example.
Making a cheqd focused status list service will just result in duplication. So I don't think we can merge the PR like this, and it would first need to be refactored to a generic status list service.
Then i see two options for the cheqd integration:
- you call two methods
- we have a
agent.modules.tokenStatusList.createStatusList
- we have a
agent.modules.cheqd.uploadStatusList
- we have a
- we create one wrapper method
agent.modules.cheqd.createStatustList
- which call theagent.modules.tokenStatusList.createStatusList
and then uploads it as a cheqd resource, but still using the generic implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimoGlastra Is this the right way to create JWTs?
const jwsService = agentContext.dependencyManager.resolve(JwsService)
const jwt = await jwsService.createJwsCompact(agentContext, {
payload: jwtPayload,
keyId: issuer.publicJwk.keyId,
protectedHeaderOptions: {
alg: issuer.alg,
typ: "statuslist+jwt"
}
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimoGlastra to publish status lists in different registries. How about following the pattern similar to registrar
agent.modules.tokenStatusList.registerRegistry([new CheqdStatusListRegistry(), new HttpStatusListRegistry]); etc.
and the functions within TokenStatusListService call registry.publish(), registry.retreive() etc
@@ -0,0 +1,159 @@ | |||
import { AgentContext, CredoError, getKeyFromVerificationMethod, Buffer, utils } from '@credo-ts/core' | |||
import { StatusListPayload, StatusListToken } from './types' | |||
import { createEmptyBitmap, decodeBitmap, encodeBitmap, isBitSet, setBit } from './utils/bitmap' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SD-JWT VC library already has utils to create status lists.
const statusListValues = new Array(body.size).fill(0)
const statusList = new StatusList(statusListValues, 1)
Or updating an existing one:
import { getListFromStatusListJWT } from '@sd-jwt/jwt-status-list'
const statusList = getListFromStatusListJWT(currentStatusListJwt)
const parsedStatusListJwt = Jwt.fromSerializedJwt(currentStatusListJwt)
// Set the revoked indices to 1
for (const revokedIndex of body.revokedIndices) {
statusList.setStatus(revokedIndex, 1)
}
Closing and implementing new approach suggested in #2326 |
No description provided.