Skip to content

Commit

Permalink
context, test
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Oct 2, 2023
1 parent a09bf2c commit 9b8791d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
16 changes: 6 additions & 10 deletions vdr/didkey/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,11 @@ func (r Resolver) Resolve(id did.DID, metadata *resolver.ResolveMetadata) (*did.
}

document := did.Document{
Context: nil,
ID: id,
AlsoKnownAs: nil,
Authentication: nil,
AssertionMethod: nil,
KeyAgreement: nil,
CapabilityInvocation: nil,
CapabilityDelegation: nil,
Service: nil,
Context: []ssi.URI{
ssi.MustParseURI("https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json"),
did.DIDContextV1URI(),
},
ID: id,
}
keyID := id
keyID.Fragment = id.ID
Expand All @@ -105,5 +101,5 @@ func (r Resolver) Resolve(id did.DID, metadata *resolver.ResolveMetadata) (*did.
document.AddKeyAgreement(vm)
document.AddCapabilityDelegation(vm)
document.AddCapabilityInvocation(vm)
return nil, nil, nil
return &document, &resolver.DocumentMetadata{}, nil
}
71 changes: 46 additions & 25 deletions vdr/didkey/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,55 @@ package didkey

import (
"github.com/nuts-foundation/go-did/did"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func TestResolver_Resolve(t *testing.T) {
tests := []struct {
name string
id string
err error
}{
{
name: "Ed25519",
id: "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := Resolver{}
got, got1, err := r.Resolve(did.MustParseDID(tt.id), nil)
if tt.err != nil {
require.Error(t, err)
require.Nil(t, got)
require.Nil(t, got1)
return
}
require.NoError(t, err)
require.NotNil(t, got)
require.NotNil(t, got1)
})
}
t.Run("Ed25519", func(t *testing.T) {
const expected = `
{
"@context": [
"https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json",
"https://www.w3.org/ns/did/v1"
],
"assertionMethod": [
"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
],
"authentication": [
"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
],
"capabilityDelegation": [
"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
],
"capabilityInvocation": [
"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
],
"id": "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
"keyAgreement": [
"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
],
"verificationMethod": [
{
"controller": "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
"id": "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
"publicKeyJwk": {
"crv": "Ed25519",
"kty": "OKP",
"x": "AS5vzONnAdx5FIjg0LF0XMHjOkwcn8xBxjvTQ9u-CXDm"
},
"type": "JsonWebKey2020"
}
]
}
`
r := Resolver{}
doc, md, err := r.Resolve(did.MustParseDID("did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"), nil)
require.NoError(t, err)
require.NotNil(t, doc)
require.NotNil(t, md)
docJSON, _ := doc.MarshalJSON()
assert.JSONEq(t, expected, string(docJSON))
})
}

0 comments on commit 9b8791d

Please sign in to comment.