openwallet-foundation / sd-jwt-js

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

Feat: add zod for object validation #227

Open cre8 opened 6 months ago

cre8 commented 6 months ago

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

lukasjhan commented 5 months ago

Can you tell me what examples there are?

cre8 commented 5 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)