Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bbs-plus
Browse files Browse the repository at this point in the history
* origin/main:
  Bump github.com/multiformats/go-multibase from 0.1.1 to 0.2.0 (#313)
  Bump github.com/go-playground/validator/v10 from 10.11.2 to 10.12.0 (#311)
  Bump github.com/goccy/go-json from 0.10.0 to 0.10.2 (#310)
  Bump golang.org/x/term from 0.5.0 to 0.6.0 (#299)
  Update JWX lib to use v2 (#308)
  Added style and best practices (#298)
  Add models for Credential Issuer Metadata (#304)
  Upgrade go version to 1.20.2 (#305)
  add missing param (#297)
  interface to any (#296)

# Conflicts:
#	cryptosuite/cryptosuite.go
#	cryptosuite/jsonwebkey2020.go
#	cryptosuite/jwssignaturesuite.go
#	cryptosuite/jwssignaturesuite_test.go
#	go.mod
#	go.sum
#	util/helpers.go
#	wasm/static/main.wasm
  • Loading branch information
decentralgabe committed Mar 21, 2023
2 parents 247339f + c9cdf21 commit b172d0a
Show file tree
Hide file tree
Showing 74 changed files with 1,275 additions and 627 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.1
go-version: 1.20.2

- name: Install Mage
run: go install github.com/magefile/mage
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.1
go-version: 1.20.2

- name: Install Mage
run: go install github.com/magefile/mage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.20.1
go-version: 1.20.2
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
9 changes: 7 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This guide is for you.

| Requirement | Tested Version | Installation Instructions |
|-------------|----------------|--------------------------------------------------------|
| Go | 1.20.1 | [go.dev](https://go.dev/doc/tutorial/compile-install) |
| Go | 1.20.2 | [go.dev](https://go.dev/doc/tutorial/compile-install) |
| Mage | 1.13.0-6 | [magefile.org](https://magefile.org/) |

### Go
Expand All @@ -25,7 +25,7 @@ You may verify your `go` installation via the terminal:

```
$> go version
go version go1.20.1 darwin/amd64
go version go1.20.2 darwin/amd64
```

If you do not have go, we recommend installing it by:
Expand Down Expand Up @@ -99,6 +99,11 @@ using [GitHub Actions](https://github.com/TBD54566975/ssi-sdk/actions).
We review contributions to the codebase via GitHub's Pull Request mechanism. We have the following guidelines to ease
your experience and help our leads respond quickly to your valuable work:

### Code
* All new code and PRs should follow [Uber's Go Style guide](https://github.com/uber-go/guide/blob/master/style.md).
* All new tests should follow unit test [best practices from Microsoft](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-best-practices#best-practices).

### Process
* Start by proposing a change either in Issues (most appropriate for small change requests or bug fixes) or in
Discussions (most appropriate for design and architecture considerations, proposing a new feature, or where you'd like
insight and feedback)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![godoc ssi-sdk](https://img.shields.io/badge/godoc-ssi--sdk-blue)](https://pkg.go.dev/github.com/TBD54566975/ssi-sdk)
[![go version 1.20.1](https://img.shields.io/badge/go_version-1.20.1-brightgreen)](https://golang.org/)
[![go version 1.20.2](https://img.shields.io/badge/go_version-1.20.2-brightgreen)](https://golang.org/)
[![Go Report Card A+](https://goreportcard.com/badge/github.com/TBD54566975/ssi-sdk)](https://goreportcard.com/report/github.com/TBD54566975/ssi-sdk)
[![license Apache 2](https://img.shields.io/badge/license-Apache%202-black)](https://github.com/TBD54566975/ssi-sdk/blob/main/LICENSE)
[![issues](https://img.shields.io/github/issues/TBD54566975/ssi-sdk)](https://github.com/TBD54566975/ssi-sdk/issues)
Expand Down
24 changes: 12 additions & 12 deletions credential/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (

// VerifiableCredentialBuilder uses the builder pattern to construct a verifiable credential
type VerifiableCredentialBuilder struct {
// contexts and types are kept to avoid having cast to/from interface{} values
// contexts and types are kept to avoid having cast to/from any values
contexts []string
types []string
*VerifiableCredential
Expand Down Expand Up @@ -65,7 +65,7 @@ func (vcb *VerifiableCredentialBuilder) IsEmpty() bool {
return reflect.DeepEqual(vcb, &VerifiableCredentialBuilder{})
}

func (vcb *VerifiableCredentialBuilder) AddContext(context interface{}) error {
func (vcb *VerifiableCredentialBuilder) AddContext(context any) error {
if vcb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand All @@ -88,7 +88,7 @@ func (vcb *VerifiableCredentialBuilder) SetID(id string) error {
return nil
}

func (vcb *VerifiableCredentialBuilder) AddType(t interface{}) error {
func (vcb *VerifiableCredentialBuilder) AddType(t any) error {
if vcb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand All @@ -102,7 +102,7 @@ func (vcb *VerifiableCredentialBuilder) AddType(t interface{}) error {
return nil
}

func (vcb *VerifiableCredentialBuilder) SetIssuer(issuer interface{}) error {
func (vcb *VerifiableCredentialBuilder) SetIssuer(issuer any) error {
if vcb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand Down Expand Up @@ -160,14 +160,14 @@ func (vcb *VerifiableCredentialBuilder) SetExpirationDate(dateTime string) error
return nil
}

func (vcb *VerifiableCredentialBuilder) SetCredentialStatus(status interface{}) error {
func (vcb *VerifiableCredentialBuilder) SetCredentialStatus(status any) error {
if vcb.IsEmpty() {
return errors.New(BuilderEmptyError)
}

statusMap, err := util.ToJSONMap(status)
if err != nil {
return errors.Wrap(err, "status value not of required type map[string]interface{}")
return errors.Wrap(err, "status value not of required type map[string]any")
}

// check required properties
Expand Down Expand Up @@ -233,7 +233,7 @@ func (vcb *VerifiableCredentialBuilder) SetTermsOfUse(terms []TermsOfUse) error
return nil
}

func (vcb *VerifiableCredentialBuilder) SetEvidence(evidence []interface{}) error {
func (vcb *VerifiableCredentialBuilder) SetEvidence(evidence []any) error {
if vcb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand All @@ -247,7 +247,7 @@ func (vcb *VerifiableCredentialBuilder) SetEvidence(evidence []interface{}) erro

// VerifiablePresentationBuilder uses the builder pattern to construct a verifiable presentation
type VerifiablePresentationBuilder struct {
// contexts and types are kept to avoid having cast to/from interface{} values
// contexts and types are kept to avoid having cast to/from any values
contexts []string
types []string
*VerifiablePresentation
Expand Down Expand Up @@ -289,7 +289,7 @@ func (vpb *VerifiablePresentationBuilder) IsEmpty() bool {
return reflect.DeepEqual(vpb, &VerifiablePresentationBuilder{})
}

func (vpb *VerifiablePresentationBuilder) AddContext(context interface{}) error {
func (vpb *VerifiablePresentationBuilder) AddContext(context any) error {
if vpb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand Down Expand Up @@ -321,7 +321,7 @@ func (vpb *VerifiablePresentationBuilder) SetHolder(holder string) error {
return nil
}

func (vpb *VerifiablePresentationBuilder) AddType(t interface{}) error {
func (vpb *VerifiablePresentationBuilder) AddType(t any) error {
if vpb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand All @@ -335,7 +335,7 @@ func (vpb *VerifiablePresentationBuilder) AddType(t interface{}) error {
return nil
}

func (vpb *VerifiablePresentationBuilder) SetPresentationSubmission(ps interface{}) error {
func (vpb *VerifiablePresentationBuilder) SetPresentationSubmission(ps any) error {
if vpb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand All @@ -346,7 +346,7 @@ func (vpb *VerifiablePresentationBuilder) SetPresentationSubmission(ps interface

// AddVerifiableCredentials appends the given credentials to the verifiable presentation.
// It does not check for duplicates.
func (vpb *VerifiablePresentationBuilder) AddVerifiableCredentials(creds ...interface{}) error {
func (vpb *VerifiablePresentationBuilder) AddVerifiableCredentials(creds ...any) error {
if vpb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand Down
20 changes: 10 additions & 10 deletions credential/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ func TestCredential(t *testing.T) {
knownType := []string{"VerifiableCredential", "AlumniCredential"}
knownIssuer := "https://example.edu/issuers/565049"
knownIssuanceDate := "2010-01-01T19:23:24Z"
knownSubject := map[string]interface{}{
knownSubject := map[string]any{
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
"alumniOf": map[string]interface{}{
"alumniOf": map[string]any{
"id": "did:example:c276e12ec21ebfeb1f712ebc6f1",
"name": []interface{}{
map[string]interface{}{"value": "Example University",
"name": []any{
map[string]any{"value": "Example University",
"lang": "en",
}, map[string]interface{}{
}, map[string]any{
"value": "Exemple d'Université",
"lang": "fr",
},
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestCredentialBuilder(t *testing.T) {
assert.NoError(t, err)

// reset issuer as an object without an id property
badIssuerObject := map[string]interface{}{
badIssuerObject := map[string]any{
"issuer": "abcd",
"bad": "efghi",
}
Expand All @@ -128,7 +128,7 @@ func TestCredentialBuilder(t *testing.T) {
assert.Contains(t, err.Error(), "issuer object did not contain `id` property")

// issuer object with an id property
goodIssuerObject := map[string]interface{}{
goodIssuerObject := map[string]any{
"id": "issuer",
}
err = builder.SetIssuer(goodIssuerObject)
Expand Down Expand Up @@ -227,12 +227,12 @@ func TestCredentialBuilder(t *testing.T) {
assert.NoError(t, err)

// empty evidence
err = builder.SetEvidence([]interface{}{})
err = builder.SetEvidence([]any{})
assert.Error(t, err)
assert.Contains(t, err.Error(), "evidence cannot be empty")

// valid evidence
evidence := []interface{}{"evidence"}
evidence := []any{"evidence"}
err = builder.SetEvidence(evidence)
assert.NoError(t, err)

Expand Down Expand Up @@ -303,7 +303,7 @@ func TestVerifiablePresentationBuilder(t *testing.T) {
assert.NoError(t, err)

// add two credentials
creds := []interface{}{
creds := []any{
VerifiableCredential{
ID: "cred-1",
Type: "type",
Expand Down
2 changes: 1 addition & 1 deletion credential/exchange/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (pdb *PresentationDefinitionBuilder) SetSubmissionRequirements(requirements
return nil
}

func (pdb *PresentationDefinitionBuilder) SetFrame(frame interface{}) error {
func (pdb *PresentationDefinitionBuilder) SetFrame(frame any) error {
if pdb.IsEmpty() {
return errors.New(BuilderEmptyError)
}
Expand Down
4 changes: 2 additions & 2 deletions credential/exchange/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestInputDescriptorBuilderProperties(t *testing.T) {
}
}`)

var props interface{}
var props any
err := json.Unmarshal(b, &props)
assert.NoError(t, err)

Expand Down Expand Up @@ -169,7 +169,7 @@ func TestInputDescriptorBuilderRequired(t *testing.T) {
}
}`)

var props interface{}
var props any
err := json.Unmarshal(b, &props)
assert.NoError(t, err)

Expand Down
36 changes: 18 additions & 18 deletions credential/exchange/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type PresentationDefinition struct {
SubmissionRequirements []SubmissionRequirement `json:"submission_requirements,omitempty" validate:"omitempty,dive"`

// https://identity.foundation/presentation-exchange/#json-ld-framing-feature
Frame interface{} `json:"frame,omitempty"`
Frame any `json:"frame,omitempty"`
}

func (pd *PresentationDefinition) IsEmpty() bool {
Expand Down Expand Up @@ -287,23 +287,23 @@ type RelationalConstraint struct {
}

type Filter struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Properties interface{} `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
AdditionalProperties bool `json:"additionalProperties,omitempty"`
Pattern string `json:"pattern,omitempty"`
Minimum interface{} `json:"minimum,omitempty"`
Maximum interface{} `json:"maximum,omitempty"`
MinLength int `json:"minLength,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"`
ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"`
Const interface{} `json:"const,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Not interface{} `json:"not,omitempty"`
AllOf interface{} `json:"allOf,omitempty"`
OneOf interface{} `json:"oneOf,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Properties any `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
AdditionalProperties bool `json:"additionalProperties,omitempty"`
Pattern string `json:"pattern,omitempty"`
Minimum any `json:"minimum,omitempty"`
Maximum any `json:"maximum,omitempty"`
MinLength int `json:"minLength,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
ExclusiveMinimum any `json:"exclusiveMinimum,omitempty"`
ExclusiveMaximum any `json:"exclusiveMaximum,omitempty"`
Const any `json:"const,omitempty"`
Enum []any `json:"enum,omitempty"`
Not any `json:"not,omitempty"`
AllOf any `json:"allOf,omitempty"`
OneOf any `json:"oneOf,omitempty"`
}

// CredentialStatus https://identity.foundation/presentation-exchange/#credential-status-constraint-feature
Expand Down
8 changes: 4 additions & 4 deletions credential/exchange/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/TBD54566975/ssi-sdk/crypto"
"github.com/goccy/go-json"
"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwt"
"github.com/lestrrat-go/jwx/v2/jwt"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -40,13 +40,13 @@ func BuildPresentationRequest(signer crypto.JWTSigner, pt PresentationRequestTyp

// BuildJWTPresentationRequest builds a JWT representation of a presentation request
func BuildJWTPresentationRequest(signer crypto.JWTSigner, def PresentationDefinition, target string) ([]byte, error) {
jwtValues := map[string]interface{}{
jwtValues := map[string]any{
jwt.JwtIDKey: uuid.NewString(),
jwt.IssuerKey: signer.KeyID(),
jwt.AudienceKey: target,
PresentationDefinitionKey: def,
}
return signer.SignJWT(jwtValues)
return signer.SignWithDefaults(jwtValues)
}

// VerifyPresentationRequest finds the correct verifier and parser for a given presentation request type,
Expand All @@ -67,7 +67,7 @@ func VerifyPresentationRequest(verifier crypto.JWTVerifier, pt PresentationReque
// VerifyJWTPresentationRequest verifies the signature on a JWT-based presentation request for a given verifier
// and then returns the parsed Presentation Definition object as a result.
func VerifyJWTPresentationRequest(verifier crypto.JWTVerifier, request []byte) (*PresentationDefinition, error) {
parsed, err := verifier.VerifyAndParseJWT(string(request))
parsed, err := verifier.VerifyAndParse(string(request))
if err != nil {
return nil, errors.Wrap(err, "could not verify and parse jwt presentation request")
}
Expand Down
6 changes: 3 additions & 3 deletions credential/exchange/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestBuildPresentationRequest(t *testing.T) {
verifier, err := signer.ToVerifier()
assert.NoError(t, err)

parsed, err := verifier.VerifyAndParseJWT(string(requestJWTBytes))
parsed, err := verifier.VerifyAndParse(string(requestJWTBytes))
assert.NoError(t, err)

presDef, ok := parsed.Get(PresentationDefinitionKey)
Expand All @@ -47,7 +47,7 @@ func TestBuildPresentationRequest(t *testing.T) {
verifier, err := signer.ToVerifier()
assert.NoError(t, err)

parsed, err := verifier.VerifyAndParseJWT(string(requestJWTBytes))
parsed, err := verifier.VerifyAndParse(string(requestJWTBytes))
assert.NoError(t, err)

presDef, ok := parsed.Get(PresentationDefinitionKey)
Expand Down Expand Up @@ -87,7 +87,7 @@ func getDummyPresentationDefinition() PresentationDefinition {
}

// turn two objects into json and compare value equality
func jsonEq(t *testing.T, a interface{}, b interface{}) {
func jsonEq(t *testing.T, a any, b any) {
aBytes, err := json.Marshal(a)
assert.NoError(t, err)
bBytes, err := json.Marshal(b)
Expand Down
4 changes: 3 additions & 1 deletion credential/exchange/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ func TestMain(m *testing.M) {
if err != nil {
os.Exit(1)
}
if _, err = schema.NewCachingLoader(localSchemas); err != nil {
loader, err := schema.NewCachingLoader(localSchemas)
if err != nil {
os.Exit(1)
}
loader.EnableHTTPCache()
os.Exit(m.Run())
}

Expand Down
Loading

0 comments on commit b172d0a

Please sign in to comment.