This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* configs * more * add cose vc * cose tests * update docs * add all * remove tags * lints
- Loading branch information
1 parent
ea15c86
commit 8f8ea12
Showing
14 changed files
with
607 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,159 @@ | ||
# VC JOSE COSE in GO | ||
[![godoc vc-jose-cose-go](https://img.shields.io/badge/godoc-vc--jose--cose--go-blue)](https://pkg.go.dev/github.com/TBD54566975/vc-jose-cose-go) | ||
[![go version 1.23.2](https://img.shields.io/badge/go_version-1.23.2-brightgreen)](https://golang.org/) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/TBD54566975/vc-jose-cose-go)](https://goreportcard.com/report/github.com/TBD54566975/vc-jose-cose-go) | ||
[![license Apache 2](https://img.shields.io/badge/license-Apache%202-black)](https://github.com/TBD54566975/vc-jose-cose-go/blob/main/LICENSE) | ||
[![issues](https://img.shields.io/github/issues/TBD54566975/vc-jose-cose-go)](https://github.com/TBD54566975/vc-jose-cose-go/issues) | ||
![ci status](https://github.com/TBD54566975/vc-jose-cose-go/actions/workflows/ci.yml/badge.svg?branch=main&event=push) | ||
[![codecov](https://codecov.io/github/TBD54566975/vc-jose-cose-go/graph/badge.svg?token=PIS07W0RQJ)](https://codecov.io/github/TBD54566975/vc-jose-cose-go) | ||
|
||
# VC JOSE COSE in go | ||
|
||
A lightweight go implementation of the [W3C Verifiable Credentials v2 Data Model](https://www.w3.org/TR/vc-data-model-2.0) | ||
with support for [Securing Verifiable Credentials using JOSE and COSE](https://www.w3.org/TR/vc-jose-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) | ||
|
||
```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 | ||
} | ||
``` | ||
|
||
### SD-JWT (Selective Disclosure JWT) | ||
|
||
```go | ||
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) | ||
|
||
```go | ||
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](./CODEOWNERS) | Outlines the project lead(s) | | ||
| [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) | Expected behavior for project contributors, promoting a welcoming environment | | ||
| [CONTRIBUTING.md](./CONTRIBUTING.md) | Developer guide to build, test, run, access CI, chat, discuss, file issues | | ||
| [CONTRIBUTING.md](./CONTRIBUTING.md) | Developer guide to build, test, run, access CI, chat, discuss, file issues | | ||
| [GOVERNANCE.md](./GOVERNANCE.md) | Project governance | | ||
| [LICENSE](./LICENSE) | Apache License, Version 2.0 | | ||
| [LICENSE](./LICENSE) | Apache License, Version 2.0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
codecov: | ||
require_ci_to_pass: yes | ||
|
||
coverage: | ||
precision: 2 | ||
round: nearest | ||
range: "80...100" | ||
|
||
comment: | ||
layout: "reach, diff, flags, files" | ||
behavior: default | ||
require_changes: true | ||
require_head: no | ||
require_base: no |
Oops, something went wrong.