Package Exports
- web-identity-schemas
- web-identity-schemas/package.json
- web-identity-schemas/valibot
- web-identity-schemas/zod
Readme
Web Identity Schemas
TypeScript types and validation schemas for Web Identity and JOSE standards, including:
- Decentralized Identifiers (DID)
- Verifiable Credentials (VC) v1.1 and v2.0, with StatusList2021, Bitstring Status List
- Verifiable Presentations (VP)
- JSON Web Tokens (JWT)
- JSON Web Keys (JWK)
- JSON Web Signatures (JWS)
- See the full list
This library provides both Valibot and Zod (v4) validation implementations with comprehensive type safety.
Installation
npm install web-identity-schemas
Quick Start
Valibot
import * as v from "valibot"
import {
DidSchema,
JwkSchema,
VerifiableCredentialSchema
} from "web-identity-schemas/valibot"
// Validate a DID
const validDid = v.parse(DidSchema, "did:example:123456789abcdefghi")
// Validate a Verifiable Credential
const validVc = v.parse(VerifiableCredentialSchema, {
"@context": "https://www.w3.org/2018/credentials/v1",
type: "VerifiableCredential",
issuer: "did:example:issuer",
issuanceDate: "2023-01-01T00:00:00Z",
credentialSubject: {
id: "did:example:subject",
degree: "Bachelor of Science"
}
})
// Validate cryptographic keys
const validKey = v.parse(JsonWebKeySchema, {
kty: "EC",
crv: "P-256",
x: "MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
y: "4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM"
})
Zod v4
import * as z from "zod"
import {
DidSchema,
JwkSchema,
VerifiableCredentialSchema
} from "web-identity-schemas/zod"
// Validate a DID
const validDid = DidSchema.parse("did:example:123456789abcdefghi")
// Validate a Verifiable Credential
const validVc = VerifiableCredentialSchema.parse({
"@context": "https://www.w3.org/2018/credentials/v1",
type: "VerifiableCredential",
issuer: "did:example:issuer",
issuanceDate: "2023-01-01T00:00:00Z",
credentialSubject: {
id: "did:example:subject",
degree: "Bachelor of Science"
}
})
// Validate cryptographic keys
const validKey = JsonWebKeySchema.parse({
kty: "EC",
crv: "P-256",
x: "MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
y: "4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM"
})
Type Safety
All types are also available as Typescript types at the root of the package, and in each schema export
import type { Did, DidDocument, JwtString } from "web-identity-schemas"
// or from "web-identity-schemas/valibot"
// or from "web-identity-schemas/zod"
const jwt: JwtString = "..."
const did: Did = "did:method:something"
const didWeb: Did<"web"> = "did:web:example.com"
const didDocument: DidDocument = {
// ...
}
Available Schemas
This library exports comprehensive schemas for Web Identity and JOSE standards. All schemas are available in both Valibot and Zod implementations, with corresponding TypeScript types.
Core Web Identity Schemas
Decentralized Identifiers (DIDs)
DidSchema
- Validates DID strings (e.g.,did:example:123
)DidUrlSchema
- Validates DID URLs with paths/queries/fragmentsDidDocumentSchema
- Validates DID DocumentsVerificationMethodSchema
- Validates verification methods in DID DocumentsServiceSchema
- Validates service endpoints in DID Documents
Verifiable Credentials (VCs)
VerifiableCredentialSchema
- Universal VC validator (v1.1 and v2.0)VerifiableCredentialV1Schema
- Specific v1.1 VC validatorVerifiableCredentialV2Schema
- Specific v2.0 VC validatorVerifiablePresentationSchema
- Validates verifiable presentations
JSON Web Tokens (JWTs)
JwtObjectSchema
- Validates JWT objects (header + payload)JwtStringSchema
- Validates JWT strings in compact formatJwtHeaderSignedSchema
- Validates JWT headers for signed tokensJwtPayloadSchema
- Validates JWT payloads
JSON Web Keys (JWKs)
JsonWebKeySchema
- Universal JWK validator (all key types)JsonWebKeySetSchema
- Validates JWK Sets
Cryptographic Schemas
Specific JWK Types
RsaJwkSchema
- RSA keys (kty: "RSA")EcJwkSchema
- Elliptic Curve keys (kty: "EC")OctJwkSchema
- Symmetric keys (kty: "oct")OkpJwkSchema
- Octet Key Pair keys (kty: "OKP")
Cryptographic Curves
EllipticCurveSchema
- Elliptic curve names (P-256, P-384, etc.)OctetKeyPairCurveSchema
- OKP curve names (Ed25519, X25519)
JOSE Specifications
JSON Web Signatures (JWS)
JwsObjectSchema
- JWS in object formatJwsStringSchema
- JWS in compact string formatJwsJsonSerializationSchema
- JWS JSON General SerializationJwsFlattenedJsonSerializationSchema
- JWS JSON Flattened Serialization
JSON Web Encryption (JWE)
JweObjectSchema
- JWE in object formatJweStringSchema
- JWE in compact string formatJweJsonSerializationSchema
- JWE JSON General SerializationJweFlattenedJsonSerializationSchema
- JWE JSON Flattened Serialization
JOSE Algorithms
JoseAlgorithmSchema
- All JOSE algorithmsJoseSignatureAlgorithmSchema
- Signature algorithms (RS256, ES256, etc.)JweContentEncryptionAlgorithmSchema
- Content encryption algorithmsJweKeyManagementAlgorithmSchema
- Key management algorithms
Status and Proof Schemas
Credential Status
StatusList2021CredentialSchema
- StatusList2021 credentialsBitstringStatusListCredentialSchema
- Bitstring status credentials
Proof Systems
Utility Schemas
Common Formats
UriSchema
- URI format validationBase64UrlSchema
- Base64url encoded stringsBase64Schema
- Base64 encoded stringsDateTimeStampSchema
- ISO 8601 datetime strings
Contributing
Contributions are welcome.
This library maintains strict type safety and comprehensive test coverage. Both Valibot and Zod implementations must pass identical test suites to ensure consistency.
See CLAUDE.md
for detailed development guidelines and schema patterns.
License (MIT)
Copyright (c) 2025 Catena Labs, Inc. See LICENSE
for details.