openwallet-foundation-labs / sd-jwt-js

A JavaScript implementation of the Selective Disclosure JWT (SD-JWT) spec.
https://sdjwt.js.org/
Apache License 2.0
36 stars 11 forks source link

Feat: add zod for object validation #227

Open cre8 opened 3 months ago

cre8 commented 3 months ago

Using zod could help to validate objects before dealing with them. This should be implemented for all packages where required

lukasjhan commented 3 months ago

Can you tell me what examples there are?

cre8 commented 3 months ago

It would help to validate variables. So instead of

if(jwk.exp && typeof jwk.exp === number) {

}

you could go with

const schema = z.number();
schema.parse(jwk.exp)

While I think ZOD is nice, I do not see so many values that we need to type check for validation (Timo brought the topic up in one of the issues)