![codecov](https://codecov.io/github/TBD54566975/vc-jose-cose-go/graph/badge.svg?token=PIS07W0RQJ)
VC JOSE COSE in go
A lightweight go implementation of the W3C Verifiable Credentials v2 Data Model
with support for Securing Verifiable Credentials using JOSE and COSE.
Usage
This library provides Go implementations for signing and verifying Verifiable Credentials (VCs) and Verifiable Presentations (VPs) using JOSE, SD-JWT, and COSE formats.
Installation
go get github.com/TBD54566975/vc-jose-cose-go
JOSE (JSON Object Signing and Encryption)
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
}
SD-JWT (Selective Disclosure JWT)
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
}
}
COSE (CBOR Object Signing and Encryption)
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
}
Project Resources
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 |