Skip to content

Commit

Permalink
Update ssi-sdk version (#614)
Browse files Browse the repository at this point in the history
* Update ssi-sdk version

* spec

* prep for update of sdk

* Deps n swag

---------

Co-authored-by: Gabe <[email protected]>
  • Loading branch information
andresuribe87 and decentralgabe authored Jul 31, 2023
1 parent 9fb4ef5 commit de454c7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
30 changes: 29 additions & 1 deletion doc/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2128,20 +2128,36 @@ definitions:
resolution.DocumentMetadata:
properties:
canonicalId:
description: See `canonicalId` in https://www.w3.org/TR/did-core/#did-document-metadata
type: string
created:
description: See `created` in https://www.w3.org/TR/did-core/#did-document-metadata
type: string
deactivated:
description: See `deactivated` in https://www.w3.org/TR/did-core/#did-document-metadata
type: boolean
equivalentId:
type: string
description: See `equivalentId` in https://www.w3.org/TR/did-core/#did-document-metadata
items:
type: string
type: array
method:
allOf:
- $ref: '#/definitions/resolution.Method'
description: |-
Optional information that is specific to the DID Method of the DID Document resolved. Populated only
for sidetree based did methods (e.g. ION), as described in https://identity.foundation/sidetree/spec/#did-resolver-output
nextUpdate:
description: See `nextUpdate` in https://www.w3.org/TR/did-core/#did-document-metadata
type: string
nextVersionId:
description: See `nextVersionId` in https://www.w3.org/TR/did-core/#did-document-metadata
type: string
updated:
description: See `updated` in https://www.w3.org/TR/did-core/#did-document-metadata
type: string
versionId:
description: See `versionId` in https://www.w3.org/TR/did-core/#did-document-metadata
type: string
type: object
resolution.Error:
Expand All @@ -2162,6 +2178,18 @@ definitions:
error:
$ref: '#/definitions/resolution.Error'
type: object
resolution.Method:
properties:
published:
description: The `method` property in https://identity.foundation/sidetree/spec/#did-resolver-output
type: boolean
recoveryCommitment:
description: The `recoveryCommitment` property in https://identity.foundation/sidetree/spec/#did-resolver-output
type: string
updateCommitment:
description: The `updateCommitment` property in https://identity.foundation/sidetree/spec/#did-resolver-output
type: string
type: object
schema.JSONSchema:
additionalProperties: {}
type: object
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/BurntSushi/toml v1.3.2
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230711190054-bce640c9bf25
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230731175253-d5c302a1d9b9
github.com/alicebob/miniredis/v2 v2.30.4
github.com/ardanlabs/conf v1.5.0
github.com/benbjohnson/clock v1.3.5
Expand Down Expand Up @@ -143,7 +143,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/cachecontrol v0.2.0 // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230711190054-bce640c9bf25 h1:wW+49kQxN/BYcMkbDjQA9mkrUC9cYUV6HOFLP+JIx+E=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230711190054-bce640c9bf25/go.mod h1:lup1EqGAT730/c7dRF9Q8OvgsjWJewq4K2dFAyBV1vk=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230731175253-d5c302a1d9b9 h1:Ig2o+eOTFTaa9agWiz+Vz/7N4zoTJ2Na9PiRaYaAbXY=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20230731175253-d5c302a1d9b9/go.mod h1:mVKRjfdpgmCxPwnfQluXGkgzsFyrPsjrCvHXCJ41avQ=
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
Expand Down Expand Up @@ -437,8 +437,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0 h1:uIkTLo0AGRc8l7h5l9r+GcYi9qfVPt6lD4/bhmzfiKo=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down
9 changes: 4 additions & 5 deletions integration/didweb_resolver_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ func TestResolveDIDWebIntegration(t *testing.T) {
}

// A .well-known file exists at https://tbd.website/.well-known/did.json
didWebOutput, err := put(endpoint+version+"dids/web", `{ "keyType":"Ed25519", "options": {"didWebId":"did:web:tbd.website"}}`)
didWebOutput, err := put(endpoint+version+"dids/web", `{ "keyType":"Ed25519", "options": {"didWebId":"did:web:i-made-up-this.website"}}`)
assert.NoError(t, err)

did, err := getJSONElement(didWebOutput, "$.did.id")
assert.NoError(t, err)
resolvedOutput, err := ResolveDID(did)
assert.NoError(t, err)

didError, err := getJSONElement(resolvedOutput, "$.didResolutionMetadata.Error")
assert.NoError(t, err)
assert.Equal(t, "<nil>", didError)
_, err = getJSONElement(resolvedOutput, "$.didResolutionMetadata.Error")
assert.ErrorContains(t, err, "key error: Error not found in object")

didDocumentID, err := getJSONElement(resolvedOutput, "$.didDocument.id")
assert.NoError(t, err)
assert.Equal(t, "did:web:tbd.website", didDocumentID)
assert.Equal(t, "did:web:i-made-up-this.website", didDocumentID)

}
8 changes: 3 additions & 5 deletions pkg/server/router/did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,12 @@ func TestDIDRouter(t *testing.T) {
createOpts := did.CreateWebDIDOptions{DIDWebID: "did:web:example.com"}
_, err = didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.WebMethod, KeyType: "bad", Options: createOpts})
assert.Error(tt, err)
assert.Contains(tt, err.Error(), "could not generate key for did:web")
assert.Contains(tt, err.Error(), "key type <bad> not supported")

gock.Off()
gock.New("https://example.com").
Get("/.well-known/did.json").
Reply(200).
BodyString("")
Reply(404)
// good key type
createDIDResponse, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.WebMethod, KeyType: crypto.Ed25519, Options: createOpts})
assert.NoError(tt, err)
Expand All @@ -225,8 +224,7 @@ func TestDIDRouter(t *testing.T) {
gock.Off()
gock.New("https://tbd.website").
Get("/.well-known/did.json").
Reply(200).
BodyString("")
Reply(404)
// create a second DID
createOpts = did.CreateWebDIDOptions{DIDWebID: "did:web:tbd.website"}
createDIDResponse2, err := didService.CreateDIDByMethod(context.Background(), did.CreateDIDRequest{Method: didsdk.WebMethod, KeyType: crypto.Ed25519, Options: createOpts})
Expand Down
8 changes: 3 additions & 5 deletions pkg/server/server_did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestDIDAPI(t *testing.T) {
gock.New("https://example.com").
Get("/.well-known/did.json").
Reply(200).
BodyString(`{"didDocument": {"id": "did:web:example.com"}}`)
BodyString(`Something here that's not a DID'`)
defer gock.Off()

c = newRequestContextWithParams(w, req, params)
Expand Down Expand Up @@ -279,8 +279,7 @@ func TestDIDAPI(t *testing.T) {

gock.New("https://example.com").
Get("/.well-known/did.json").
Reply(200).
BodyString(`{"didDocument": {"id": "did:web:example.com"}}`)
Reply(404)
defer gock.Off()

c := newRequestContextWithParams(w, req, params)
Expand All @@ -299,8 +298,7 @@ func TestDIDAPI(t *testing.T) {
req2 := httptest.NewRequest(http.MethodPut, "https://ssi-service.com/v1/dids/web", requestReader2)
gock.New("https://example.com").
Get("/.well-known/did.json").
Reply(200).
BodyString(`{"didDocument": {"id": "did:web:example.com"}}`)
Reply(404)
defer gock.Off()

// Make sure it can't make another did:web of the same DIDWebID
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/did/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s *Service) ResolveDID(request ResolveDIDRequest) (*ResolveDIDResponse, er
return &ResolveDIDResponse{
ResolutionMetadata: &resolved.Metadata,
DIDDocument: &resolved.Document,
DIDDocumentMetadata: &resolved.DocumentMetadata,
DIDDocumentMetadata: resolved.DocumentMetadata,
}, nil
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/service/did/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (h *webHandler) GetMethod() did.Method {
func (h *webHandler) CreateDID(ctx context.Context, request CreateDIDRequest) (*CreateDIDResponse, error) {
logrus.Debugf("creating DID: %+v", request)

if !crypto.IsSupportedKeyType(request.KeyType) {
return nil, errors.Errorf("key type <%s> not supported", request.KeyType)
}
// process options
if request.Options == nil {
return nil, errors.New("options cannot be empty")
Expand All @@ -64,8 +67,8 @@ func (h *webHandler) CreateDID(ctx context.Context, request CreateDIDRequest) (*
didWeb := web.DIDWeb(opts.DIDWebID)

err := didWeb.Validate(ctx)
if err != nil {
return nil, errors.Wrap(err, "could not validate if did:web exists externally")
if err == nil {
return nil, fmt.Errorf("%s exists externally", didWeb.String())
}

exists, err := h.storage.DIDExists(ctx, opts.DIDWebID)
Expand Down

0 comments on commit de454c7

Please sign in to comment.