JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21
  • Score
    100M100P100Q62983F
  • License MIT

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/fragments
  • DidDocumentSchema - Validates DID Documents
  • VerificationMethodSchema - Validates verification methods in DID Documents
  • ServiceSchema - Validates service endpoints in DID Documents

Verifiable Credentials (VCs)

  • VerifiableCredentialSchema - Universal VC validator (v1.1 and v2.0)
  • VerifiableCredentialV1Schema - Specific v1.1 VC validator
  • VerifiableCredentialV2Schema - Specific v2.0 VC validator
  • VerifiablePresentationSchema - Validates verifiable presentations

JSON Web Tokens (JWTs)

  • JwtObjectSchema - Validates JWT objects (header + payload)
  • JwtStringSchema - Validates JWT strings in compact format
  • JwtHeaderSignedSchema - Validates JWT headers for signed tokens
  • JwtPayloadSchema - Validates JWT payloads

JSON Web Keys (JWKs)

Cryptographic Schemas

Specific JWK Types

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 format
  • JwsStringSchema - JWS in compact string format
  • JwsJsonSerializationSchema - JWS JSON General Serialization
  • JwsFlattenedJsonSerializationSchema - JWS JSON Flattened Serialization

JSON Web Encryption (JWE)

  • JweObjectSchema - JWE in object format
  • JweStringSchema - JWE in compact string format
  • JweJsonSerializationSchema - JWE JSON General Serialization
  • JweFlattenedJsonSerializationSchema - JWE JSON Flattened Serialization

JOSE Algorithms

  • JoseAlgorithmSchema - All JOSE algorithms
  • JoseSignatureAlgorithmSchema - Signature algorithms (RS256, ES256, etc.)
  • JweContentEncryptionAlgorithmSchema - Content encryption algorithms
  • JweKeyManagementAlgorithmSchema - Key management algorithms

Status and Proof Schemas

Credential Status

  • StatusList2021CredentialSchema - StatusList2021 credentials
  • BitstringStatusListCredentialSchema - Bitstring status credentials

Proof Systems

Utility Schemas

Common Formats

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.