Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
add COSE; update README (#7)
Browse files Browse the repository at this point in the history
* configs

* more

* add cose vc

* cose tests

* update docs

* add all

* remove tags

* lints
  • Loading branch information
decentralgabe authored Oct 24, 2024
1 parent ea15c86 commit 8f8ea12
Show file tree
Hide file tree
Showing 14 changed files with 607 additions and 40 deletions.
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# See https://golangci-lint.run/usage/configuration/ for reference.
run:
concurrency: 16
build-tags:
- jwx_es256k

output:
sort-results: true
Expand Down Expand Up @@ -329,3 +327,4 @@ linters-settings:
G101:
pattern: "(/i)passwd|pass|password|pwd|secret|token|pw|apiKey|bearer"


3 changes: 0 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ This guide is for you.

## Development Prerequisites

___***UPDATE TABLE OF PROJECT DEPS AND INSTALLATION NOTES***___


| Requirement | Tested Version | Installation Instructions |
| ----------- | -------------- | ----------------------------------------------------- |
| Go | 1.23.2 | [go.dev](https://go.dev/doc/tutorial/compile-install) |
Expand Down
151 changes: 148 additions & 3 deletions README.md
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 |
14 changes: 14 additions & 0 deletions codecov.yaml
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
Loading

0 comments on commit 8f8ea12

Please sign in to comment.