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

Commit 8f8ea12

Browse files
add COSE; update README (#7)
* configs * more * add cose vc * cose tests * update docs * add all * remove tags * lints
1 parent ea15c86 commit 8f8ea12

File tree

14 files changed

+607
-40
lines changed

14 files changed

+607
-40
lines changed

.golangci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# See https://golangci-lint.run/usage/configuration/ for reference.
22
run:
33
concurrency: 16
4-
build-tags:
5-
- jwx_es256k
64

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

330+

CONTRIBUTING.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ This guide is for you.
1313

1414
## Development Prerequisites
1515

16-
___***UPDATE TABLE OF PROJECT DEPS AND INSTALLATION NOTES***___
17-
18-
1916
| Requirement | Tested Version | Installation Instructions |
2017
| ----------- | -------------- | ----------------------------------------------------- |
2118
| Go | 1.23.2 | [go.dev](https://go.dev/doc/tutorial/compile-install) |

README.md

Lines changed: 148 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,159 @@
1-
# VC JOSE COSE in GO
1+
[![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)
2+
[![go version 1.23.2](https://img.shields.io/badge/go_version-1.23.2-brightgreen)](https://golang.org/)
3+
[![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)
4+
[![license Apache 2](https://img.shields.io/badge/license-Apache%202-black)](https://github.com/TBD54566975/vc-jose-cose-go/blob/main/LICENSE)
5+
[![issues](https://img.shields.io/github/issues/TBD54566975/vc-jose-cose-go)](https://github.com/TBD54566975/vc-jose-cose-go/issues)
6+
![ci status](https://github.com/TBD54566975/vc-jose-cose-go/actions/workflows/ci.yml/badge.svg?branch=main&event=push)
7+
[![codecov](https://codecov.io/github/TBD54566975/vc-jose-cose-go/graph/badge.svg?token=PIS07W0RQJ)](https://codecov.io/github/TBD54566975/vc-jose-cose-go)
8+
9+
# VC JOSE COSE in go
210

311
A lightweight go implementation of the [W3C Verifiable Credentials v2 Data Model](https://www.w3.org/TR/vc-data-model-2.0)
412
with support for [Securing Verifiable Credentials using JOSE and COSE](https://www.w3.org/TR/vc-jose-cose/).
513

14+
## Usage
15+
16+
This library provides Go implementations for signing and verifying Verifiable Credentials (VCs) and Verifiable Presentations (VPs) using JOSE, SD-JWT, and COSE formats.
17+
18+
## Installation
19+
20+
```
21+
go get github.com/TBD54566975/vc-jose-cose-go
22+
```
23+
24+
### JOSE (JSON Object Signing and Encryption)
25+
26+
```go
27+
import (
28+
"github.com/TBD54566975/vc-jose-cose-go/jose"
29+
"github.com/TBD54566975/vc-jose-cose-go/credential"
30+
"github.com/TBD54566975/vc-jose-cose-go/util"
31+
"github.com/lestrrat-go/jwx/v2/jwk"
32+
"github.com/lestrrat-go/jwx/v2/jwa"
33+
)
34+
35+
func main() {
36+
// Create a VC
37+
vc := credential.VerifiableCredential{
38+
Context: []string{"https://www.w3.org/2018/credentials/v1"},
39+
ID: "https://example.edu/credentials/1872",
40+
Type: []string{"VerifiableCredential"},
41+
Issuer: credential.NewIssuerHolderFromString("did:example:issuer"),
42+
ValidFrom: "2010-01-01T19:23:24Z",
43+
CredentialSubject: map[string]any{
44+
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
45+
},
46+
}
47+
48+
// Create the issuer's key
49+
key, _ := util.GenerateJWK(jwa.Ed25519)
50+
51+
// Sign the VC
52+
jwt, err := jose.SignVerifiableCredential(vc, key)
53+
if err != nil {
54+
// Handle error
55+
}
56+
57+
vc, err := jose.VerifyVerifiableCredential(jwt, key)
58+
if err != nil {
59+
// Handle error
60+
}
61+
// Use the verified VC
62+
}
63+
```
64+
65+
### SD-JWT (Selective Disclosure JWT)
66+
67+
```go
68+
import (
69+
"github.com/TBD54566975/vc-jose-cose-go/sdjwt"
70+
"github.com/TBD54566975/vc-jose-cose-go/credential"
71+
"github.com/TBD54566975/vc-jose-cose-go/util"
72+
"github.com/lestrrat-go/jwx/v2/jwk"
73+
"github.com/lestrrat-go/jwx/v2/jwa"
74+
)
75+
76+
func main() {
77+
vc := credential.VerifiableCredential{
78+
Context: []string{"https://www.w3.org/2018/credentials/v1"},
79+
ID: "https://example.edu/credentials/1872",
80+
Type: []string{"VerifiableCredential"},
81+
Issuer: credential.NewIssuerHolderFromString("did:example:issuer"),
82+
ValidFrom: "2010-01-01T19:23:24Z",
83+
CredentialSubject: map[string]any{
84+
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
85+
},
86+
}
87+
88+
// Define disclosure paths
89+
disclosurePaths := []sdjwt.DisclosurePath{
90+
"issuer",
91+
"credentialSubject.id",
92+
}
93+
94+
// Create the issuer's key
95+
key, _ := util.GenerateJWK(jwa.Ed25519)
96+
97+
// Create SD-JWT
98+
sdJWT, err := sdjwt.SignVerifiableCredential(vc, disclosurePaths, issuerKey)
99+
if err != nil {
100+
// Handle error
101+
}
102+
103+
verifiedVC, err := sdjwt.VerifyVerifiableCredential(*sdJWT, issuerKey)
104+
if err != nil {
105+
// Handle error
106+
}
107+
}
108+
```
109+
110+
### COSE (CBOR Object Signing and Encryption)
111+
112+
```go
113+
import (
114+
"github.com/TBD54566975/vc-jose-cose-go/cose"
115+
"github.com/TBD54566975/vc-jose-cose-go/credential"
116+
"github.com/TBD54566975/vc-jose-cose-go/util"
117+
"github.com/lestrrat-go/jwx/v2/jwk"
118+
"github.com/lestrrat-go/jwx/v2/jwa"
119+
)
120+
121+
func main() {
122+
// Create a VC
123+
vc := credential.VerifiableCredential{
124+
Context: []string{"https://www.w3.org/2018/credentials/v1"},
125+
ID: "https://example.edu/credentials/1872",
126+
Type: []string{"VerifiableCredential"},
127+
Issuer: credential.NewIssuerHolderFromString("did:example:issuer"),
128+
ValidFrom: "2010-01-01T19:23:24Z",
129+
CredentialSubject: map[string]any{
130+
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
131+
},
132+
}
133+
134+
// Create the issuer's key
135+
key, _ := util.GenerateJWK(jwa.Ed25519)
136+
137+
// Sign the VC
138+
cs1, err := cose.SignVerifiableCredential(vc, key)
139+
if err != nil {
140+
// Handle error
141+
}
142+
143+
vc, err := cose.VerifyVerifiableCredential(cs1, key)
144+
if err != nil {
145+
// Handle error
146+
}
147+
// Use the verified VC
148+
}
149+
```
150+
6151
## Project Resources
7152

8153
| Resource | Description |
9154
| ------------------------------------------ | ------------------------------------------------------------------------------ |
10155
| [CODEOWNERS](./CODEOWNERS) | Outlines the project lead(s) |
11156
| [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) | Expected behavior for project contributors, promoting a welcoming environment |
12-
| [CONTRIBUTING.md](./CONTRIBUTING.md) | Developer guide to build, test, run, access CI, chat, discuss, file issues |
157+
| [CONTRIBUTING.md](./CONTRIBUTING.md) | Developer guide to build, test, run, access CI, chat, discuss, file issues |
13158
| [GOVERNANCE.md](./GOVERNANCE.md) | Project governance |
14-
| [LICENSE](./LICENSE) | Apache License, Version 2.0 |
159+
| [LICENSE](./LICENSE) | Apache License, Version 2.0 |

codecov.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
codecov:
2+
require_ci_to_pass: yes
3+
4+
coverage:
5+
precision: 2
6+
round: nearest
7+
range: "80...100"
8+
9+
comment:
10+
layout: "reach, diff, flags, files"
11+
behavior: default
12+
require_changes: true
13+
require_head: no
14+
require_base: no

0 commit comments

Comments
 (0)