Skip to content

Commit e2fbaab

Browse files
committed
Route based on regex
Signed-off-by: DaevMithran <daevmithran1999@gmail.com>
1 parent f022376 commit e2fbaab

4 files changed

Lines changed: 22 additions & 31 deletions

File tree

packages/cheqd/src/wrappers/CheqdTokenStatusListRegistry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import {
99
parseDid,
1010
utils,
1111
} from '@credo-ts/core'
12-
import { parseCheqdDid } from '../anoncreds/utils/identifiers'
12+
import { cheqdSdkAnonCredsRegistryIdentifierRegex, parseCheqdDid } from '../anoncreds/utils/identifiers'
1313
import { CheqdCreateResourceOptions, CheqdDidRegistrar, CheqdDidResolver } from '../dids'
1414

1515
export class CheqdTokenStatusListRegistry implements TokenStatusListRegistry {
16-
public readonly supportedMethods = ['cheqd']
17-
public readonly allowsCaching = true
16+
methodName = 'cheqd'
17+
supportedIdentifier: RegExp = cheqdSdkAnonCredsRegistryIdentifierRegex
1818

1919
/**
2020
* Publish a verified token status list JWT to the registry

packages/core/src/modules/sd-jwt-vc/credential-status/token-status-list/TokenStatusListRegistry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export interface TokenStatusListJwtPayload {
2222
}
2323

2424
export interface TokenStatusListRegistry {
25-
readonly supportedMethods: string[]
26-
readonly allowsCaching: boolean
25+
methodName: string
26+
supportedIdentifier: RegExp
27+
2728
/**
2829
* Publish a verified token status list JWT to the registry
2930
*/

packages/core/src/modules/sd-jwt-vc/credential-status/token-status-list/TokenStatusListService.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { StatusList, getListFromStatusListJWT } from '@sd-jwt/jwt-status-list'
2-
import { isURL } from 'class-validator'
32
import { injectable } from 'tsyringe'
43
import { AgentContext } from '../../../../agent'
54
import { JwsService, Jwt, JwtPayload } from '../../../../crypto'
65
import { CredoError } from '../../../../error'
7-
import { dateToSeconds, isDid } from '../../../../utils'
6+
import { dateToSeconds } from '../../../../utils'
87
import { DidsApi, getPublicJwkFromVerificationMethod, parseDid } from '../../../dids'
98
import { SdJwtVcModuleConfig } from '../../SdJwtVcModuleConfig'
109
import { SdJwtVcIssuer } from '../../SdJwtVcOptions'
@@ -158,10 +157,6 @@ export class TokenStatusListService {
158157

159158
async getStatusList(agentContext: AgentContext, uri: string): Promise<string> {
160159
const registry = this.findRegistry({ uri })
161-
if (!registry) {
162-
throw new TokenStatusListError(`No token status list registry registered for uri ${uri}`)
163-
}
164-
165160
return await registry.resolve(agentContext, uri)
166161
}
167162

@@ -184,30 +179,24 @@ export class TokenStatusListService {
184179
}
185180

186181
const registry = this.findRegistry({ uri: options.uri, issuer })
187-
if (!registry) {
188-
throw new TokenStatusListError(`No token status list registry registered for issuer ${issuer}`)
189-
}
190182
return await registry.publish(agentContext, issuer, jwt, options)
191183
}
192184

193-
private findRegistry({ uri, issuer }: { uri?: string; issuer?: SdJwtVcIssuer }): TokenStatusListRegistry | null {
194-
let method: string
195-
196-
if (uri) {
197-
if (isDid(uri)) {
198-
method = parseDid(uri).method
199-
} else if (isURL(uri)) {
200-
method = 'http'
201-
} else {
202-
throw new TokenStatusListError('Status List Uri is not supported')
203-
}
204-
} else if (issuer && issuer.method === 'did') {
205-
method = parseDid(issuer.didUrl).method
206-
} else {
185+
private findRegistry({ uri, issuer }: { uri?: string; issuer?: SdJwtVcIssuer }): TokenStatusListRegistry {
186+
if (!uri && issuer && issuer.method === 'did') {
187+
uri = parseDid(issuer.didUrl).method
188+
}
189+
190+
if (!uri) {
207191
throw new TokenStatusListError('Status List Uri is not provided')
208192
}
209193

210-
return this.sdJwtVcModuleConfig.registries.find((r) => r.supportedMethods.includes(method)) ?? null
194+
const registry = this.sdJwtVcModuleConfig.registries.find((registry) => registry.supportedIdentifier.test(uri))
195+
if (!registry) {
196+
throw new TokenStatusListError(`No token status list registry registered for issuer ${issuer}`)
197+
}
198+
199+
return registry
211200
}
212201

213202
private async verifyStatusList(agentContext: AgentContext, issuer: SdJwtVcIssuer, jwt: string) {

packages/core/src/modules/sd-jwt-vc/credential-status/token-status-list/http/HttpTokenStatusListRegistry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { SdJwtVcIssuerX5c } from '../../../SdJwtVcOptions'
55
import { PublishTokenStatusListOptions, TokenStatusListRegistry } from '../TokenStatusListRegistry'
66

77
export class HttpTokenStatusListRegistry implements TokenStatusListRegistry {
8-
public readonly supportedMethods = ['http']
9-
public readonly allowsCaching = true
8+
public readonly methodName = 'http'
9+
supportedIdentifier: RegExp =
10+
/^https?:\/\/(?: www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_,\+.~#?&\/=]*)$/
1011

1112
/**
1213
* Publish a verified token status list JWT to the registry

0 commit comments

Comments
 (0)