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

Commit

Permalink
set default key id as jwk thumbprint (#488)
Browse files Browse the repository at this point in the history
* set default key id as jwk thumbprint

* update go version
  • Loading branch information
decentralgabe authored Nov 21, 2023
1 parent 22beff9 commit c496504
Show file tree
Hide file tree
Showing 25 changed files with 97 additions and 67 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.21.3
go-version: 1.21.4

- 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.21.3
go-version: 1.21.4

- 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.21.3
go-version: 1.21.4
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ When you're ready you may:

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

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

```
$> go version
go version go1.21.3 darwin/amd64
go version go1.21.4 darwin/amd64
```

If you do not have go, we recommend installing it by:
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.21.3](https://img.shields.io/badge/go_version-1.21.3-brightgreen)](https://golang.org/)
[![go version 1.21.4](https://img.shields.io/badge/go_version-1.21.4-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
10 changes: 5 additions & 5 deletions credential/exchange/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestBuildPresentationRequest(t *testing.T) {
_, privKey, err := crypto.GenerateEd25519Key()
assert.NoError(t, err)

signer, err := jwx.NewJWXSigner("test-id", "test-kid", privKey)
signer, err := jwx.NewJWXSigner("test-id", nil, privKey)
assert.NoError(t, err)

testDef := getDummyPresentationDefinition()
Expand All @@ -34,14 +34,14 @@ func TestBuildPresentationRequest(t *testing.T) {

kid, ok := headers.Get("kid")
assert.True(t, ok)
assert.Equal(t, "test-kid", kid)
assert.NotEmpty(t, kid)
})

t.Run("Happy Path", func(t *testing.T) {
_, privKey, err := crypto.GenerateEd25519Key()
assert.NoError(t, err)

signer, err := jwx.NewJWXSigner("test-id", "test-kid", privKey)
signer, err := jwx.NewJWXSigner("test-id", nil, privKey)
assert.NoError(t, err)

testDef := getDummyPresentationDefinition()
Expand All @@ -61,14 +61,14 @@ func TestBuildPresentationRequest(t *testing.T) {

kid, ok := headers.Get("kid")
assert.True(t, ok)
assert.Equal(t, "test-kid", kid)
assert.NotEmpty(t, kid)
})

t.Run("Unsupported Request Method", func(t *testing.T) {
_, privKey, err := crypto.GenerateEd25519Key()
assert.NoError(t, err)

signer, err := jwx.NewJWXSigner("test-id", "test-kid", privKey)
signer, err := jwx.NewJWXSigner("test-id", nil, privKey)
assert.NoError(t, err)

testDef := getDummyPresentationDefinition()
Expand Down
2 changes: 1 addition & 1 deletion credential/exchange/submission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ func getJWKSignerVerifier(t *testing.T) (*jwx.Signer, *jwx.Verifier) {
expanded, err := didKey.Expand()
require.NoError(t, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
require.NoError(t, err)

verifier, err := signer.ToVerifier(didKey.String())
Expand Down
6 changes: 3 additions & 3 deletions credential/integrity/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestVerifiableCredentialJWT(t *testing.T) {
_, privKey, err := crypto.GenerateEd25519Key()
assert.NoError(tt, err)

signer, err := jwx.NewJWXSigner("test-id", "test-kid", privKey)
signer, err := jwx.NewJWXSigner("test-id", nil, privKey)
assert.NoError(tt, err)

signed, err := SignVerifiableCredentialJWT(*signer, testCredential)
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestVerifiablePresentationJWT(t *testing.T) {
},
}

issuerSigner, err := jwx.NewJWXSigner(issuerDID.String(), issuerKID, issuerPrivKey)
issuerSigner, err := jwx.NewJWXSigner(issuerDID.String(), &issuerKID, issuerPrivKey)
assert.NoError(tt, err)
signedVC, err := SignVerifiableCredentialJWT(*issuerSigner, testCredential)
assert.NoError(t, err)
Expand All @@ -232,7 +232,7 @@ func TestVerifiablePresentationJWT(t *testing.T) {
}

// sign the presentation from the subject to the issuer
subjectSigner, err := jwx.NewJWXSigner(subjectDID.String(), subjectKID, subjectPrivKey)
subjectSigner, err := jwx.NewJWXSigner(subjectDID.String(), &subjectKID, subjectPrivKey)
assert.NoError(tt, err)
signed, err := SignVerifiablePresentationJWT(*subjectSigner, &JWTVVPParameters{Audience: []string{issuerDID.String()}}, testPresentation)
assert.NoError(tt, err)
Expand Down
4 changes: 2 additions & 2 deletions credential/integrity/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func VerifyJWTCredential(ctx context.Context, cred string, r resolution.Resolver
}

// construct a verifier
credVerifier, err := jwx.NewJWXVerifier(issuerDID.ID, issuerKID, issuerKey)
credVerifier, err := jwx.NewJWXVerifier(issuerDID.ID, &issuerKID, issuerKey)
if err != nil {
return false, errors.Wrapf(err, "error constructing verifier for credential<%s>", token.JwtID())
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func VerifyJWTPresentation(ctx context.Context, pres string, r resolution.Resolv
}

// construct a verifier
presVerifier, err := jwx.NewJWXVerifier(issuerDID.ID, issuerKID, issuerKey)
presVerifier, err := jwx.NewJWXVerifier(issuerDID.ID, &issuerKID, issuerKey)
if err != nil {
return false, errors.Wrapf(err, "error constructing verifier for presentation<%s>", token.JwtID())
}
Expand Down
30 changes: 15 additions & 15 deletions credential/integrity/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestVerifyCredentialSignature(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtCred := getTestJWTCredential(tt, *signer)
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestVerifyJWTCredential(t *testing.T) {

_, privKey, err := crypto.GenerateEd25519Key()
assert.NoError(tt, err)
signer, err := jwx.NewJWXSigner("test-id", "test-kid", privKey)
signer, err := jwx.NewJWXSigner("test-id", nil, privKey)
assert.NoError(tt, err)

jwtCred := getTestJWTCredential(tt, *signer)
Expand All @@ -163,7 +163,7 @@ func TestVerifyJWTCredential(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtCred := getTestJWTCredential(tt, *signer)
Expand All @@ -178,13 +178,13 @@ func TestVerifyJWTCredential(t *testing.T) {

privKey, didKey, err := key.GenerateDIDKey(crypto.Ed25519)
assert.NoError(tt, err)
signer, err := jwx.NewJWXSigner(didKey.String(), "missing", privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), nil, privKey)
assert.NoError(tt, err)

jwtCred := getTestJWTCredential(tt, *signer)
_, err = VerifyJWTCredential(context.Background(), jwtCred, resolver)
assert.Error(tt, err)
assert.Contains(tt, err.Error(), "has no verification methods with kid: missing")
assert.Contains(tt, err.Error(), "has no verification methods with kid: ")
})

t.Run("valid credential, bad signature", func(tt *testing.T) {
Expand All @@ -196,7 +196,7 @@ func TestVerifyJWTCredential(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtCred := getTestJWTCredential(tt, *signer)
Expand All @@ -218,7 +218,7 @@ func TestVerifyJWTCredential(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtCred := getTestJWTCredential(tt, *signer)
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestVerifyJWTPresentation(t *testing.T) {

_, privKey, err := crypto.GenerateEd25519Key()
assert.NoError(tt, err)
signer, err := jwx.NewJWXSigner("test-id", "test-kid", privKey)
signer, err := jwx.NewJWXSigner("test-id", nil, privKey)
assert.NoError(tt, err)

jwtPres := getTestJWTPresentation(tt, *signer)
Expand All @@ -312,7 +312,7 @@ func TestVerifyJWTPresentation(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtCred := getTestJWTPresentation(tt, *signer)
Expand All @@ -327,13 +327,13 @@ func TestVerifyJWTPresentation(t *testing.T) {

privKey, didKey, err := key.GenerateDIDKey(crypto.Ed25519)
assert.NoError(tt, err)
signer, err := jwx.NewJWXSigner(didKey.String(), "missing", privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), nil, privKey)
assert.NoError(tt, err)

jwtPres := getTestJWTPresentation(tt, *signer)
_, err = VerifyJWTPresentation(context.Background(), jwtPres, resolver)
assert.Error(tt, err)
assert.Contains(tt, err.Error(), "has no verification methods with kid: missing")
assert.Contains(tt, err.Error(), "has no verification methods with kid: ")
})

t.Run("valid presentation, bad signature", func(tt *testing.T) {
Expand All @@ -345,7 +345,7 @@ func TestVerifyJWTPresentation(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtPres := getTestJWTPresentation(tt, *signer)
Expand All @@ -368,7 +368,7 @@ func TestVerifyJWTPresentation(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtPres := geTestJWTPresentationNoCred(tt, *signer)
Expand All @@ -393,7 +393,7 @@ func TestVerifyJWTPresentation(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtPres := getTestJWTPresentationBadCred(tt, *signer)
Expand All @@ -413,7 +413,7 @@ func TestVerifyJWTPresentation(t *testing.T) {
expanded, err := didKey.Expand()
assert.NoError(tt, err)
kid := expanded.VerificationMethod[0].ID
signer, err := jwx.NewJWXSigner(didKey.String(), kid, privKey)
signer, err := jwx.NewJWXSigner(didKey.String(), &kid, privKey)
assert.NoError(tt, err)

jwtPres := getTestJWTPresentation(tt, *signer)
Expand Down
2 changes: 1 addition & 1 deletion credential/manifest/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func getValidTestCredManifestCredApplicationJWTCred(t *testing.T) (CredentialMan
// turn into a jwt
_, privKey, err := crypto.GenerateEd25519Key()
require.NoError(t, err)
signer, err := jwx.NewJWXSigner("test-id", "test-kid", privKey)
signer, err := jwx.NewJWXSigner("test-id", nil, privKey)
require.NoError(t, err)
jwt, err := integrity.SignVerifiableCredentialJWT(*signer, vc)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit c496504

Please sign in to comment.