Skip to content

Commit 7020320

Browse files
committed
chore: debu logging fixes
1 parent 2afc90d commit 7020320

42 files changed

Lines changed: 198 additions & 244 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

biome.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
"lineWidth": 150,
1313
"attributePosition": "auto",
1414
"bracketSpacing": true,
15-
"ignore": ["**/dist", "**/coverage", "**/*/node_modules", "packages/siop-oid4vp/lib/schemas", "**/*tsconfig*", "**/schemaValidation.*js"]
15+
"ignore": ["**/dist/*", "**/coverage/*", "**/*/node_modules", "packages/siop-oid4vp/lib/schemas", "**/*tsconfig*", "**/schemaValidation.*js"]
1616
},
1717
"organizeImports": { "enabled": true },
1818
"linter": {
1919
"enabled": true,
2020
"rules": { "recommended": false },
21-
"ignore": ["**/node_modules", "**/dist", "**/coverage", "**/jest.js", "**/*tsconfig*", "**/schemaValidation.*js"]
21+
"ignore": ["**/node_modules", "**/dist/*", "**/coverage/*", "**/jest.js", "**/*tsconfig*", "**/schemaValidation.*js"]
2222
},
2323
"javascript": {
2424
"formatter": {

packages/client/lib/AccessTokenClientV1_0_11.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ import {
2424
toUniformCredentialOfferRequest,
2525
UniformCredentialOfferPayload,
2626
} from '@sphereon/oid4vci-common'
27-
import { ObjectUtils } from '@sphereon/ssi-types'
28-
import pkg from 'debug'
29-
const { debug: Debug } = pkg
27+
import { Loggers, ObjectUtils } from '@sphereon/ssi-types'
3028

3129
import { MetadataClientV1_0_13 } from './MetadataClientV1_0_13'
3230
import { createJwtBearerClientAssertion } from './functions'
3331
import { shouldRetryTokenRequestWithDPoPNonce } from './functions/dpopUtil'
3432

35-
const debug = Debug('sphereon:oid4vci:token')
33+
const logger = Loggers.DEFAULT.get('sphereon:oid4vci:token')
3634

3735
export class AccessTokenClientV1_0_11 {
3836
public async acquireAccessToken(opts: AccessTokenRequestOpts): Promise<OpenIDResponse<AccessTokenResponse, DPoPResponseParams>> {
@@ -185,39 +183,39 @@ export class AccessTokenClientV1_0_11 {
185183
if (requestPayload.grants?.[PRE_AUTH_GRANT_LITERAL]) {
186184
isPinRequired = requestPayload.grants[PRE_AUTH_GRANT_LITERAL]?.user_pin_required ?? false
187185
}
188-
debug(`Pin required for issuer ${issuer}: ${isPinRequired}`)
186+
logger.debug(`Pin required for issuer ${issuer}: ${isPinRequired}`)
189187
return isPinRequired
190188
}
191189

192190
private assertNumericPin(isPinRequired?: boolean, pin?: string): void {
193191
if (isPinRequired) {
194192
if (!pin || !/^\d{1,8}$/.test(pin)) {
195-
debug(`Pin is not 1 to 8 digits long`)
193+
logger.debug(`Pin is not 1 to 8 digits long`)
196194
throw new Error('A valid pin consisting of maximal 8 numeric characters must be present.')
197195
}
198196
} else if (pin) {
199-
debug(`Pin set, whilst not required`)
197+
logger.debug(`Pin set, whilst not required`)
200198
throw new Error('Cannot set a pin, when the pin is not required.')
201199
}
202200
}
203201

204202
private assertNonEmptyPreAuthorizedCode(accessTokenRequest: AccessTokenRequest): void {
205203
if (!accessTokenRequest[PRE_AUTH_CODE_LITERAL]) {
206-
debug(`No pre-authorized code present, whilst it is required`)
204+
logger.debug(`No pre-authorized code present, whilst it is required`)
207205
throw new Error('Pre-authorization must be proven by presenting the pre-authorized code. Code must be present.')
208206
}
209207
}
210208

211209
private assertNonEmptyCodeVerifier(accessTokenRequest: AccessTokenRequest): void {
212210
if (!accessTokenRequest.code_verifier) {
213-
debug('No code_verifier present, whilst it is required')
211+
logger.debug('No code_verifier present, whilst it is required')
214212
throw new Error('Authorization flow requires the code_verifier to be present')
215213
}
216214
}
217215

218216
private assertNonEmptyCode(accessTokenRequest: AccessTokenRequest): void {
219217
if (!accessTokenRequest.code) {
220-
debug('No code present, whilst it is required')
218+
logger.debug('No code present, whilst it is required')
221219
throw new Error('Authorization flow requires the code to be present')
222220
}
223221
}
@@ -273,7 +271,7 @@ export class AccessTokenClientV1_0_11 {
273271
if (!url || !ObjectUtils.isString(url)) {
274272
throw new Error('No authorization server token URL present. Cannot acquire access token')
275273
}
276-
debug(`Token endpoint determined to be ${url}`)
274+
logger.debug(`Token endpoint determined to be ${url}`)
277275
return url
278276
}
279277

@@ -290,7 +288,7 @@ export class AccessTokenClientV1_0_11 {
290288
}
291289

292290
private throwNotSupportedFlow(): void {
293-
debug(`Only pre-authorized or authorization code flows supported.`)
291+
logger.debug(`Only pre-authorized or authorization code flows supported.`)
294292
throw new Error('Only pre-authorized-code or authorization code flows are supported')
295293
}
296294
}

packages/client/lib/AuthorizationCodeClient.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ import {
2828
RequestObjectOpts,
2929
ResponseType,
3030
} from '@sphereon/oid4vci-common'
31-
import pkg from 'debug'
32-
const { debug: Debug } = pkg
31+
import { Loggers } from '@sphereon/ssi-types'
3332

3433
import { MetadataClient } from './MetadataClient'
3534
import { ProofOfPossessionBuilder } from './ProofOfPossessionBuilder'
3635

37-
const debug = Debug('sphereon:oid4vci')
36+
const logger = Loggers.DEFAULT.get('sphereon:oid4vci')
3837

3938
export async function createSignedAuthRequestWhenNeeded(requestObject: Record<string, any>, opts: RequestObjectOpts & { aud?: string }) {
4039
if (opts.requestObjectMode === CreateRequestObjectMode.REQUEST_URI) {
@@ -217,7 +216,7 @@ export const createAuthorizationRequestUrl = async ({
217216
if (!parEndpoint && parMode === PARMode.REQUIRE) {
218217
throw Error(`PAR mode is set to required by Authorization Server does not support PAR!`)
219218
} else if (parEndpoint && parMode !== PARMode.NEVER) {
220-
debug(`USING PAR with endpoint ${parEndpoint}`)
219+
logger.debug(`USING PAR with endpoint ${parEndpoint}`)
221220

222221
const parResponse = await formPost<PushedAuthorizationResponse>(
223222
parEndpoint,
@@ -232,23 +231,23 @@ export const createAuthorizationRequestUrl = async ({
232231
throw Error(`PAR error: ${parResponse.origResponse.statusText}`)
233232
}
234233

235-
debug('Falling back to regular request URI, since PAR failed', JSON.stringify(parResponse.errorBody))
234+
logger.debug('Falling back to regular request URI, since PAR failed', JSON.stringify(parResponse.errorBody))
236235
} else {
237-
debug(`PAR response: ${JSON.stringify(parResponse.successBody, null, 2)}`)
236+
logger.debug(`PAR response: ${JSON.stringify(parResponse.successBody, null, 2)}`)
238237
queryObj = { /*response_type: ResponseType.AUTH_CODE,*/ client_id, request_uri: parResponse.successBody.request_uri }
239238
}
240239
}
241240
await createSignedAuthRequestWhenNeeded(queryObj, { ...requestObjectOpts, aud: endpointMetadata.authorization_server })
242241

243-
debug(`Object that will become query params: ` + JSON.stringify(queryObj, null, 2))
242+
logger.debug(`Object that will become query params: ` + JSON.stringify(queryObj, null, 2))
244243
const url = convertJsonToURI(queryObj, {
245244
baseUrl: endpointMetadata.authorization_endpoint,
246245
uriTypeProperties: ['client_id', 'request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state', 'state'],
247246
// arrayTypeProperties: ['authorization_details'],
248247
mode: JsonURIMode.X_FORM_WWW_URLENCODED,
249248
// We do not add the version here, as this always needs to be form encoded
250249
})
251-
debug(`Authorization Request URL: ${url}`)
250+
logger.debug(`Authorization Request URL: ${url}`)
252251
return url
253252
}
254253

packages/client/lib/AuthorizationCodeClientV1_0_11.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ import {
1616
PushedAuthorizationResponse,
1717
ResponseType,
1818
} from '@sphereon/oid4vci-common'
19-
import pkg from 'debug'
20-
const { debug: Debug } = pkg
19+
import { Loggers } from '@sphereon/ssi-types'
2120

2221
import { createSignedAuthRequestWhenNeeded } from './AuthorizationCodeClient'
2322

24-
const debug = Debug('sphereon:oid4vci')
23+
const logger = Loggers.DEFAULT.get('sphereon:oid4vci')
2524

2625
export const createAuthorizationRequestUrlV1_0_11 = async ({
2726
pkce,
@@ -97,7 +96,7 @@ export const createAuthorizationRequestUrlV1_0_11 = async ({
9796
if (!parEndpoint && parMode === PARMode.REQUIRE) {
9897
throw Error(`PAR mode is set to required by Authorization Server does not support PAR!`)
9998
} else if (parEndpoint && parMode !== PARMode.NEVER) {
100-
debug(`USING PAR with endpoint ${parEndpoint}`)
99+
logger.debug(`USING PAR with endpoint ${parEndpoint}`)
101100
const parResponse = await formPost<PushedAuthorizationResponse>(
102101
parEndpoint,
103102
convertJsonToURI(queryObj, {
@@ -113,21 +112,21 @@ export const createAuthorizationRequestUrlV1_0_11 = async ({
113112
throw Error(`PAR error: ${parResponse.origResponse.statusText}`)
114113
}
115114
} else {
116-
debug(`PAR response: ${JSON.stringify(parResponse.successBody, null, 2)}`)
115+
logger.debug(`PAR response: ${JSON.stringify(parResponse.successBody, null, 2)}`)
117116
queryObj = { request_uri: parResponse.successBody.request_uri }
118117
}
119118
}
120119
await createSignedAuthRequestWhenNeeded(queryObj, { ...requestObjectOpts, aud: endpointMetadata.authorization_server })
121120

122-
debug(`Object that will become query params: ` + JSON.stringify(queryObj, null, 2))
121+
logger.debug(`Object that will become query params: ` + JSON.stringify(queryObj, null, 2))
123122
const url = convertJsonToURI(queryObj, {
124123
baseUrl: endpointMetadata.authorization_endpoint,
125124
uriTypeProperties: ['client_id', 'request_uri', 'redirect_uri', 'scope', 'authorization_details', 'issuer_state'],
126125
// arrayTypeProperties: ['authorization_details'],
127126
mode: JsonURIMode.X_FORM_WWW_URLENCODED,
128127
// We do not add the version here, as this always needs to be form encoded
129128
})
130-
debug(`Authorization Request URL: ${url}`)
129+
logger.debug(`Authorization Request URL: ${url}`)
131130
return url
132131
}
133132

packages/client/lib/CredentialOfferClient.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ import {
1212
PRE_AUTH_GRANT_LITERAL,
1313
toUniformCredentialOfferRequest,
1414
} from '@sphereon/oid4vci-common'
15-
import pkg from 'debug'
16-
const { debug: Debug } = pkg
1715

1816
import { constructBaseResponse, handleCredentialOfferUri } from './functions'
1917
import { LOG } from './types'
2018

21-
const debug = Debug('sphereon:oid4vci:offer')
22-
2319
export class CredentialOfferClient {
2420
public static async fromURI(uri: string, opts?: { resolve?: boolean }): Promise<CredentialOfferRequestWithBaseUrl> {
25-
debug(`Credential Offer URI: ${uri}`)
21+
LOG.debug(`Credential Offer URI: ${uri}`)
2622
if (!uri.includes('?') || !uri.includes('://')) {
27-
debug(`Invalid Credential Offer URI: ${uri}`)
23+
LOG.debug(`Invalid Credential Offer URI: ${uri}`)
2824
throw Error(`Invalid Credential Offer Request`)
2925
}
3026
const scheme = uri.split('://')[0]
@@ -77,7 +73,7 @@ export class CredentialOfferClient {
7773
version?: OpenId4VCIVersion
7874
},
7975
): string {
80-
debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`)
76+
LOG.debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`)
8177
const version = opts?.version ?? requestWithBaseUrl.version
8278
let baseUrl = requestWithBaseUrl.baseUrl.includes(requestWithBaseUrl.scheme)
8379
? requestWithBaseUrl.baseUrl

packages/client/lib/CredentialOfferClientV1_0_11.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ import {
1414
PRE_AUTH_GRANT_LITERAL,
1515
toUniformCredentialOfferRequest,
1616
} from '@sphereon/oid4vci-common'
17-
import pkg from 'debug'
18-
const { debug: Debug } = pkg
17+
import { Loggers } from '@sphereon/ssi-types'
1918

20-
const debug = Debug('sphereon:oid4vci:offer')
19+
const logger = Loggers.DEFAULT.get('sphereon:oid4vci:offer')
2120

2221
export class CredentialOfferClientV1_0_11 {
2322
public static async fromURI(uri: string, opts?: { resolve?: boolean }): Promise<CredentialOfferRequestWithBaseUrlV1_0_11> {
24-
debug(`Credential Offer URI: ${uri}`)
23+
logger.debug(`Credential Offer URI: ${uri}`)
2524
if (!uri.includes('?') || !uri.includes('://')) {
26-
debug(`Invalid Credential Offer URI: ${uri}`)
25+
logger.debug(`Invalid Credential Offer URI: ${uri}`)
2726
throw Error(`Invalid Credential Offer Request`)
2827
}
2928
const scheme = uri.split('://')[0]
@@ -75,7 +74,7 @@ export class CredentialOfferClientV1_0_11 {
7574
version?: OpenId4VCIVersion
7675
},
7776
): string {
78-
debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`)
77+
logger.debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`)
7978
const version = opts?.version ?? requestWithBaseUrl.version
8079
let baseUrl = requestWithBaseUrl.baseUrl.includes(requestWithBaseUrl.scheme)
8180
? requestWithBaseUrl.baseUrl

packages/client/lib/CredentialOfferClientV1_0_13.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ import {
99
PRE_AUTH_GRANT_LITERAL,
1010
toUniformCredentialOfferRequest,
1111
} from '@sphereon/oid4vci-common'
12-
import pkg from 'debug'
13-
const { debug: Debug } = pkg
12+
import { Loggers } from '@sphereon/ssi-types'
1413

1514
import { constructBaseResponse, handleCredentialOfferUri } from './functions'
1615

17-
const debug = Debug('sphereon:oid4vci:offer')
16+
const logger = Loggers.DEFAULT.get('sphereon:oid4vci:offer')
1817

1918
export class CredentialOfferClientV1_0_13 {
2019
public static async fromURI(uri: string, opts?: { resolve?: boolean }): Promise<CredentialOfferRequestWithBaseUrl> {
21-
debug(`Credential Offer URI: ${uri}`)
20+
logger.debug(`Credential Offer URI: ${uri}`)
2221
if (!uri.includes('?') || !uri.includes('://')) {
23-
debug(`Invalid Credential Offer URI: ${uri}`)
22+
logger.debug(`Invalid Credential Offer URI: ${uri}`)
2423
throw Error(`Invalid Credential Offer Request`)
2524
}
2625
const scheme = uri.split('://')[0]
@@ -60,7 +59,7 @@ export class CredentialOfferClientV1_0_13 {
6059
version?: OpenId4VCIVersion
6160
},
6261
): string {
63-
debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`)
62+
logger.debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`)
6463
const version = opts?.version ?? requestWithBaseUrl.version
6564
let baseUrl = requestWithBaseUrl.baseUrl.includes(requestWithBaseUrl.scheme)
6665
? requestWithBaseUrl.baseUrl

packages/client/lib/CredentialRequestClient.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ import {
1818
UniformCredentialRequest,
1919
URL_NOT_VALID,
2020
} from '@sphereon/oid4vci-common'
21-
import { CredentialFormat } from '@sphereon/ssi-types'
22-
import pkg from 'debug'
23-
const { debug: Debug } = pkg
21+
import { CredentialFormat, Loggers } from '@sphereon/ssi-types'
2422

2523
import { CredentialRequestClientBuilderV1_0_11 } from './CredentialRequestClientBuilderV1_0_11'
2624
import { CredentialRequestClientBuilderV1_0_13 } from './CredentialRequestClientBuilderV1_0_13'
2725
import { ProofOfPossessionBuilder } from './ProofOfPossessionBuilder'
2826
import { shouldRetryResourceRequestWithDPoPNonce } from './functions/dpopUtil'
2927

30-
const debug = Debug('sphereon:oid4vci:credential')
28+
const logger = Loggers.DEFAULT.get('sphereon:oid4vci:credential')
3129

3230
export interface CredentialRequestOpts {
3331
deferredCredentialAwait?: boolean
@@ -171,11 +169,11 @@ export class CredentialRequestClient {
171169
const request: CredentialRequestV1_0_13 = getCredentialRequestForVersion(uniformRequest, this.version()) as CredentialRequestV1_0_13
172170
const credentialEndpoint: string = this.credentialRequestOpts.credentialEndpoint
173171
if (!isValidURL(credentialEndpoint)) {
174-
debug(`Invalid credential endpoint: ${credentialEndpoint}`)
172+
logger.debug(`Invalid credential endpoint: ${credentialEndpoint}`)
175173
throw new Error(URL_NOT_VALID)
176174
}
177-
debug(`Acquiring credential(s) from: ${credentialEndpoint}`)
178-
debug(`request\n: ${JSON.stringify(request, null, 2)}`)
175+
logger.debug(`Acquiring credential(s) from: ${credentialEndpoint}`)
176+
logger.debug(`request\n: ${JSON.stringify(request, null, 2)}`)
179177
const requestToken: string = this.credentialRequestOpts.token
180178

181179
let dPoP = createDPoPOpts ? await createDPoP(getCreateDPoPOptions(createDPoPOpts, credentialEndpoint, { accessToken: requestToken })) : undefined
@@ -215,7 +213,7 @@ export class CredentialRequestClient {
215213
throw Error('Subject signing was requested, but issuer did not provide the options in its response')
216214
}
217215
}
218-
debug(`Credential endpoint ${credentialEndpoint} response:\r\n${JSON.stringify(response, null, 2)}`)
216+
logger.debug(`Credential endpoint ${credentialEndpoint} response:\r\n${JSON.stringify(response, null, 2)}`)
219217

220218
return {
221219
...response,

packages/client/lib/CredentialRequestClientV1_0_11.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ import {
1616
UniformCredentialRequest,
1717
URL_NOT_VALID,
1818
} from '@sphereon/oid4vci-common'
19-
import { CredentialFormat } from '@sphereon/ssi-types'
20-
import pkg from 'debug'
21-
const { debug: Debug } = pkg
19+
import { CredentialFormat, Loggers } from '@sphereon/ssi-types'
2220

2321
import { buildProof } from './CredentialRequestClient'
2422
import { CredentialRequestClientBuilderV1_0_11 } from './CredentialRequestClientBuilderV1_0_11'
2523
import { ProofOfPossessionBuilder } from './ProofOfPossessionBuilder'
2624
import { shouldRetryResourceRequestWithDPoPNonce } from './functions/dpopUtil'
2725

28-
const debug = Debug('sphereon:oid4vci:credential')
26+
const logger = Loggers.DEFAULT.get('sphereon:oid4vci:credential')
2927

3028
export interface CredentialRequestOptsV1_0_11 {
3129
deferredCredentialAwait?: boolean
@@ -83,11 +81,11 @@ export class CredentialRequestClientV1_0_11 {
8381
const request = getCredentialRequestForVersion(uniformRequest, this.version())
8482
const credentialEndpoint: string = this.credentialRequestOpts.credentialEndpoint
8583
if (!isValidURL(credentialEndpoint)) {
86-
debug(`Invalid credential endpoint: ${credentialEndpoint}`)
84+
logger.debug(`Invalid credential endpoint: ${credentialEndpoint}`)
8785
throw new Error(URL_NOT_VALID)
8886
}
89-
debug(`Acquiring credential(s) from: ${credentialEndpoint}`)
90-
debug(`request\n: ${JSON.stringify(request, null, 2)}`)
87+
logger.debug(`Acquiring credential(s) from: ${credentialEndpoint}`)
88+
logger.debug(`request\n: ${JSON.stringify(request, null, 2)}`)
9189
const requestToken: string = this.credentialRequestOpts.token
9290

9391
let dPoP = createDPoPOpts ? await createDPoP(getCreateDPoPOptions(createDPoPOpts, credentialEndpoint, { accessToken: requestToken })) : undefined
@@ -122,7 +120,7 @@ export class CredentialRequestClientV1_0_11 {
122120
}
123121
response.access_token = requestToken
124122

125-
debug(`Credential endpoint ${credentialEndpoint} response:\r\n${JSON.stringify(response, null, 2)}`)
123+
logger.debug(`Credential endpoint ${credentialEndpoint} response:\r\n${JSON.stringify(response, null, 2)}`)
126124

127125
return {
128126
...response,

0 commit comments

Comments
 (0)