1- import { type AgentContext , Buffer , CredoError , Jwt , utils } from '@credo-ts/core'
21import {
2+ type AgentContext ,
3+ CredoError ,
4+ Jwt ,
35 PublishTokenStatusListOptions ,
6+ SdJwtVcIssuerDid ,
47 TokenStatusListRegistry ,
5- } from 'packages/core/src/modules/sd-jwt-vc/credential-status/token-status-list/TokenStatusListRegistry'
8+ TokenStatusListResponse ,
9+ TypedArrayEncoder ,
10+ utils ,
11+ } from '@credo-ts/core'
612import { parseCheqdDid } from '../anoncreds/utils/identifiers'
713import { CheqdCreateResourceOptions , CheqdDidRegistrar , CheqdDidResolver } from '../dids'
814
9- export interface CheqdPublishTokenStatusListOptions extends PublishTokenStatusListOptions {
10- name : string
11- }
12-
1315export class CheqdTokenStatusListRegistry implements TokenStatusListRegistry {
1416 public readonly supportedMethods = [ 'cheqd' ]
1517 public readonly allowsCaching = true
@@ -19,11 +21,11 @@ export class CheqdTokenStatusListRegistry implements TokenStatusListRegistry {
1921 */
2022 async publish (
2123 agentContext : AgentContext ,
22- statusListId : string ,
24+ issuer : SdJwtVcIssuerDid ,
2325 jwt : string ,
24- options : CheqdPublishTokenStatusListOptions
26+ options : PublishTokenStatusListOptions
2527 ) : Promise < string > {
26- const parsedDid = parseCheqdDid ( statusListId )
28+ const parsedDid = parseCheqdDid ( issuer . didUrl )
2729 if ( ! parsedDid ) {
2830 throw new Error ( 'Invalid did:cheqd' )
2931 }
@@ -48,11 +50,8 @@ export class CheqdTokenStatusListRegistry implements TokenStatusListRegistry {
4850 const { didDocument } = await didResolver . resolve ( agentContext , did , parsedDid )
4951 if ( ! didDocument ) throw new CredoError ( `Unable to resolve DID Document for ${ did } ` )
5052
51- const kid = parsedJwt . header . kid
52- if ( ! kid ) throw new CredoError ( `JWT is missing 'kid' header` )
53-
54- const method = didDocument . verificationMethod ?. find ( ( vm ) => vm . id === kid )
55- if ( ! method ) throw new CredoError ( `No verification method found for kid ${ kid } ` )
53+ const method = didDocument . verificationMethod ?. find ( ( vm ) => vm . id === issuer . didUrl )
54+ if ( ! method ) throw new CredoError ( `No verification method found for issuer ${ issuer . didUrl } ` )
5655
5756 // Upload to Cheqd
5857 const cheqdDidRegistrar = agentContext . dependencyManager . resolve ( CheqdDidRegistrar )
@@ -62,7 +61,7 @@ export class CheqdTokenStatusListRegistry implements TokenStatusListRegistry {
6261 id : utils . uuid ( ) ,
6362 name : options . name ,
6463 resourceType : 'TokenStatusList' ,
65- data : Buffer . from ( jwt ) ,
64+ data : TypedArrayEncoder . toBase64 ( TypedArrayEncoder . fromString ( jwt ) ) ,
6665 version : options . version ?? utils . uuid ( ) ,
6766 }
6867
@@ -71,20 +70,25 @@ export class CheqdTokenStatusListRegistry implements TokenStatusListRegistry {
7170 throw new CredoError ( response . resourceState . reason ?? 'Unknown error' )
7271 }
7372
73+ // return statusListUri
7474 return `${ did } ?resourceName=${ options . name } &resourceType=TokenStatusList`
7575 }
7676
7777 /**
7878 * Retrieve a token status list JWT from the registry
7979 */
80- async retrieve ( agentContext : AgentContext , statusListId : string ) : Promise < string > {
80+ async retrieve ( agentContext : AgentContext , statusListUri : SdJwtVcIssuerDid ) : Promise < TokenStatusListResponse > {
8181 const cheqdDidResolver = agentContext . dependencyManager . resolve ( CheqdDidResolver )
8282
83- const response = await cheqdDidResolver . resolveResource ( agentContext , statusListId )
84- if ( response . error ) {
83+ const response = await cheqdDidResolver . resolveResource ( agentContext , statusListUri . didUrl )
84+ if ( response . error || ! response . resourceMetadata ) {
8585 throw new CredoError ( response . message )
8686 }
8787
88- return response . resource
88+ return {
89+ jwt : TypedArrayEncoder . fromBase64 ( response . resource ) . toString ( ) ,
90+ name : response . resourceMetadata ?. name ,
91+ version : response . resourceMetadata ?. version ,
92+ }
8993 }
9094}
0 commit comments