W3C Verifiable Credentials 2.0 with JSON-LD and ECDSA-SD-2023
This package implements support for W3C Verifiable Credentials Data Model v2.0 with JSON-LD credentials and the ECDSA-SD-2023 selective disclosure cryptosuite.
Status: π§ Work in Progress
Phase 1 Foundation: β
COMPLETED
- β
W3C VC 2.0 data structures (
pkg/vc20/credential)
- β
Context management and validation (
pkg/vc20/contextstore)
- β
Core dependencies integrated
Phase 2 RDF Canonicalization: β
COMPLETED
- β
RDFC-1.0 implementation (
pkg/vc20/rdfcanon)
- β
URDNA2015 algorithm via json-gold
- β
Dataset and N-Quads handling
- β
All tests passing (11 test functions)
Phase 3 ECDSA-SD-2023 Cryptosuite: π TODO
- β³ Base proof creation (issuer)
- β³ Derived proof creation (holder)
- β³ Derived proof verification (verifier)
Phase 4 Integration: π TODO
- β³ W3C test suite integration
- β³ Service integration
- β³ Documentation
Building
This package uses a build tag to make it optional:
# Build with VC 2.0 support
go build -tags=vc20 ./...
# Run tests
go test -tags=vc20 ./pkg/vc20/...
Package Structure
pkg/vc20/
βββ credential/ # VC 2.0 data model
β βββ credential.go # JSON-LD credential structures
β βββ errors.go # Error definitions
β βββ *_test.go # Tests
βββ contextstore/ # Context management
β βββ manager.go # Context caching and validation
β βββ *_test.go # Tests
βββ rdfcanon/ # RDF Canonicalization (RDFC-1.0)
β βββ canonicalize.go # URDNA2015 implementation
β βββ *_test.go # Tests
βββ crypto/ # Cryptographic suites (TODO)
βββ ecdsa-sd/ # ECDSA-SD-2023 cryptosuite
βββ keys/ # Key management
Features Implemented
Credential Data Model (pkg/vc20/credential)
Context Management (pkg/vc20/contextstore)
RDF Canonicalization (pkg/vc20/rdfcanon)
Constants
Context URLs
VC20ContextURL - https://www.w3.org/ns/credentials/v2
VC20ContextHash - SHA-256 hash: 59955ced6697d61e03f2b2556febe5308ab16842846f5b586d7f1f7adec92734
MediaTypeVC - application/vc
MediaTypeVP - application/vp
Proof Types
ProofTypeDataIntegrity - DataIntegrityProof
CryptosuiteECDSASD2023 - ecdsa-sd-2023 (implementation pending)
CryptosuiteECDSARDFC2019 - ecdsa-rdfc-2019 (planned)
CryptosuiteECDSAJCS2019 - ecdsa-jcs-2019 (planned)
Example Usage
// +build vc20
package main
import (
"encoding/json"
"fmt"
"time"
"vc/pkg/vc20/credential"
"vc/pkg/vc20/contextstore"
)
func main() {
// Create a credential
vc := &credential.VerifiableCredential{
Context: []string{credential.VC20ContextURL},
Type: []string{credential.TypeVerifiableCredential, "UniversityDegree"},
Issuer: "did:example:university",
ValidFrom: time.Now().Format(time.RFC3339),
CredentialSubject: map[string]any{
"id": "did:example:student",
"degree": "Bachelor of Science",
"major": "Computer Science",
},
}
// Validate the credential
if err := vc.Validate(); err != nil {
panic(err)
}
// Create context manager
ctxMgr := contextstore.NewManager()
// Validate contexts (requires network access)
if err := ctxMgr.ValidateContexts(vc.Context); err != nil {
fmt.Printf("Context validation failed: %v\n", err)
}
// Check if credential is valid now
if vc.IsValidNow() {
fmt.Println("Credential is currently valid")
}
// Marshal to JSON
data, _ := json.Marshal(vc)
fmt.Println(string(data))
}
Dependencies
External Libraries
github.com/piprate/json-gold v0.7.0 - JSON-LD 1.1 processing
github.com/fxamacker/cbor/v2 v2.6.0 - CBOR encoding
github.com/multiformats/go-multibase v0.2.0 - Multibase encoding
github.com/cloudflare/circl v1.3.7 - ECDSA P-256/P-384
Standard Library
crypto/sha256 - Context hash verification
crypto/ecdsa - ECDSA operations (planned)
crypto/hmac - HMAC for blank nodes (planned)
encoding/json - JSON processing
net/http - Context fetching
Specifications
Next Steps
The next phases of implementation will focus on:
-
RDF Canonicalization (RDFC-1.0)
- Implement the canonical ordering algorithm
- Use json-gold for RDF dataset generation
- Hash computation for RDF statements
-
ECDSA-SD-2023 Cryptosuite
- Base proof creation with HMAC blank node randomization
- Derived proof creation with JSON Pointer selection
- Signature verification
- CBOR serialization for proof values
- Multikey encoding for public keys
-
Integration
- W3C test vectors (Appendix A.7, A.8)
- Service integration (issuer, verifier)
- Complete documentation
Testing
All packages include comprehensive unit tests:
# Run all vc20 tests
go test -tags=vc20 -v ./pkg/vc20/...
# Run specific package tests
go test -tags=vc20 -v ./pkg/vc20/credential/
go test -tags=vc20 -v ./pkg/vc20/contextstore/
# Run with coverage
go test -tags=vc20 -cover ./pkg/vc20/...
Contributing
This is an active development project. The implementation follows the W3C specifications closely and aims for full compliance with test vectors.
License
[Your project's license]