Skip to content

Conversation

@cre8
Copy link
Contributor

@cre8 cre8 commented Nov 13, 2025

Fixes #331

  • throws an error when status list validation fails. If a custom error message should be thrown, the verify funcation has to be overriden
    Signed-off-by: Mirko Mollik [email protected]

cre8 added 2 commits November 13, 2025 08:46
Signed-off-by: Mirko Mollik <[email protected]>
@cre8
Copy link
Contributor Author

cre8 commented Nov 13, 2025

@charsleysa please have a look if this approach is fine for you

@charsleysa
Copy link
Contributor

cre8 added 2 commits November 13, 2025 10:04
Signed-off-by: Mirko Mollik <[email protected]>
@cre8
Copy link
Contributor Author

cre8 commented Nov 13, 2025

Oh you are right (no work without coffee in the morning), I removed also the redundant exp check.

Instead of the first fix, I appended all error messages during the verify function so it is clear when the sl jwt fails, it is clear from the error message.

Thank you for reviewing!!!

@charsleysa
Copy link
Contributor

That would work. Though one downside is that it would suppress custom errors (you wouldn't be able to use instanceof checks).

Maybe it's better for the status list not to use the jwt verify at all and instead have it's own independent implementation.

@cre8
Copy link
Contributor Author

cre8 commented Nov 13, 2025

That would work. Though one downside is that it would suppress custom errors (you wouldn't be able to use instanceof checks).

Maybe it's better for the status list not to use the jwt verify at all and instead have it's own independent implementation.

this would end up in code duplication that I want to avoid. We may define a new Exception type like SLException?

cre8 added 2 commits November 13, 2025 10:19
Signed-off-by: Mirko Mollik <[email protected]>
@charsleysa
Copy link
Contributor

this would end up in code duplication that I want to avoid. We may define a new Exception type like SLException?

That would still result in the suppression of custom errors from the user supplied verifier function. Though it does help in identifying exactly status list specific errors.

My thinking is the best way to avoid duplication would be to have check helper functions which return boolean results which can then be used from the status list verify function and it is the responsibility of the status list verify function to throw the errors.

@cre8
Copy link
Contributor Author

cre8 commented Nov 13, 2025

this would end up in code duplication that I want to avoid. We may define a new Exception type like SLException?

That would still result in the suppression of custom errors from the user supplied verifier function. Though it does help in identifying exactly status list specific errors.

My thinking is the best way to avoid duplication would be to have check helper functions which return boolean results which can then be used from the status list verify function and it is the responsibility of the status list verify function to throw the errors.

With:

        await slJWT
          .verify(
            this.userConfig.statusVerifier ??
              (this.userConfig.verifier as Verifier),
            options,
          )
          .catch((err) => {
            throw new SLException(
              `Status List JWT verification failed: ${err.message}`, err.details
            );
          });
          ```
I would not say it is supressed, but appended. I agree that the type of the error gets overwritten, but the error message gets passed as defined in your custom statusVerifier or verifier

Eg. with your verifier:

```ts
verifier(data: string, sig: string) {
  throw Error("it's always false");
}

Will result in an error message like Status List JWT verification failed: it's always false

cre8 added 2 commits November 13, 2025 10:58
Signed-off-by: Mirko Mollik <[email protected]>
Signed-off-by: Mirko Mollik <[email protected]>
@charsleysa
Copy link
Contributor

charsleysa commented Nov 13, 2025

That's correct, though if you throw a custom error class any other custom features would be lost too.

For example, if you had an ErrorWithKeyDetails class where the keyDetails are not included in the message, those details would be lost.

I'm not entirely opposed to the proposed solution, however I think it's important to document that only the message will ever be propagated and instance checks won't work.

Copy link
Member

@lukasjhan lukasjhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, Thanks.
Could you fix the lint error plz?

@cre8
Copy link
Contributor Author

cre8 commented Nov 13, 2025

That's correct, though if you throw a custom error class any other custom features would be lost too.

For example, if you had an ErrorWithKeyDetails class where the keyDetails are not included in the message, those details would be lost.

I'm not entirely opposed to the proposed solution, however I think it's important to document that only the message will ever be propagated and instance checks won't work.

the sdjwtexception and slexception allow to pass a message and also an object. This object is passed so no information except the type of exception is lost

Signed-off-by: Mirko Mollik <[email protected]>
Copy link
Member

@lukasjhan lukasjhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@charsleysa
Copy link
Contributor

the sdjwtexception and slexception allow to pass a message and also an object. This object is passed so no information except the type of exception is lost

Ah, so the expectation is for users to throw SDJWTException or SLException instead of their own error class so that information can be correctly propagated?

@cre8
Copy link
Contributor Author

cre8 commented Nov 13, 2025

the sdjwtexception and slexception allow to pass a message and also an object. This object is passed so no information except the type of exception is lost

Ah, so the expectation is for users to throw SDJWTException or SLException instead of their own error class so that information can be correctly propagated?

yes, we should add this to the documentation. Since the own function that can be inserted are quite small, it should not be a problem to have the tradeoff to not be able to "throw up" your own exception class, as long as all relevant informations are passed. But I am open for an update once someone struggles there

Copy link
Contributor

@charsleysa charsleysa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@cre8 cre8 merged commit 06d7cc4 into openwallet-foundation:main Nov 14, 2025
9 checks passed
(this.userConfig.verifier as Verifier),
options,
)
.catch((err: SLException) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think casting this as an SLException is unsafe, since the method could throw other errors as well (since a custom statusVerifier can be passed).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should rather be implemented as if (err instance SLException) {} else {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a suggestion with a fix here

@TimoGlastra can you please verify it if this was your intention? I agree that we should give the flexibility of throwing own exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Different errors for status checks

4 participants