A lightweight go implementation of the W3C Verifiable Credentials v2 Data Model with support for Securing Verifiable Credentials using JOSE and COSE.
This library provides Go implementations for signing and verifying Verifiable Credentials (VCs) and Verifiable Presentations (VPs) using JOSE, SD-JWT, and COSE formats.
go get github.com/TBD54566975/vc-jose-cose-go
import (
"github.com/TBD54566975/vc-jose-cose-go/jose"
"github.com/TBD54566975/vc-jose-cose-go/credential"
"github.com/TBD54566975/vc-jose-cose-go/util"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/lestrrat-go/jwx/v2/jwa"
)
func main() {
// Create a VC
vc := credential.VerifiableCredential{
Context: []string{"https://www.w3.org/2018/credentials/v1"},
ID: "https://example.edu/credentials/1872",
Type: []string{"VerifiableCredential"},
Issuer: credential.NewIssuerHolderFromString("did:example:issuer"),
ValidFrom: "2010-01-01T19:23:24Z",
CredentialSubject: map[string]any{
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
},
}
// Create the issuer's key
key, _ := util.GenerateJWK(jwa.Ed25519)
// Sign the VC
jwt, err := jose.SignVerifiableCredential(vc, key)
if err != nil {
// Handle error
}
vc, err := jose.VerifyVerifiableCredential(jwt, key)
if err != nil {
// Handle error
}
// Use the verified VC
}
import (
"github.com/TBD54566975/vc-jose-cose-go/sdjwt"
"github.com/TBD54566975/vc-jose-cose-go/credential"
"github.com/TBD54566975/vc-jose-cose-go/util"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/lestrrat-go/jwx/v2/jwa"
)
func main() {
vc := credential.VerifiableCredential{
Context: []string{"https://www.w3.org/2018/credentials/v1"},
ID: "https://example.edu/credentials/1872",
Type: []string{"VerifiableCredential"},
Issuer: credential.NewIssuerHolderFromString("did:example:issuer"),
ValidFrom: "2010-01-01T19:23:24Z",
CredentialSubject: map[string]any{
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
},
}
// Define disclosure paths
disclosurePaths := []sdjwt.DisclosurePath{
"issuer",
"credentialSubject.id",
}
// Create the issuer's key
key, _ := util.GenerateJWK(jwa.Ed25519)
// Create SD-JWT
sdJWT, err := sdjwt.SignVerifiableCredential(vc, disclosurePaths, issuerKey)
if err != nil {
// Handle error
}
verifiedVC, err := sdjwt.VerifyVerifiableCredential(*sdJWT, issuerKey)
if err != nil {
// Handle error
}
}
import (
"github.com/TBD54566975/vc-jose-cose-go/cose"
"github.com/TBD54566975/vc-jose-cose-go/credential"
"github.com/TBD54566975/vc-jose-cose-go/util"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/lestrrat-go/jwx/v2/jwa"
)
func main() {
// Create a VC
vc := credential.VerifiableCredential{
Context: []string{"https://www.w3.org/2018/credentials/v1"},
ID: "https://example.edu/credentials/1872",
Type: []string{"VerifiableCredential"},
Issuer: credential.NewIssuerHolderFromString("did:example:issuer"),
ValidFrom: "2010-01-01T19:23:24Z",
CredentialSubject: map[string]any{
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
},
}
// Create the issuer's key
key, _ := util.GenerateJWK(jwa.Ed25519)
// Sign the VC
cs1, err := cose.SignVerifiableCredential(vc, key)
if err != nil {
// Handle error
}
vc, err := cose.VerifyVerifiableCredential(cs1, key)
if err != nil {
// Handle error
}
// Use the verified VC
}
Resource | Description |
---|---|
CODEOWNERS | Outlines the project lead(s) |
CODE_OF_CONDUCT.md | Expected behavior for project contributors, promoting a welcoming environment |
CONTRIBUTING.md | Developer guide to build, test, run, access CI, chat, discuss, file issues |
GOVERNANCE.md | Project governance |
LICENSE | Apache License, Version 2.0 |