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

fix: DIDDoc Service Endpoint with origins key support #3552

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/common/model/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func (s *Endpoint) URI() (string, error) {
return string(o[0]), nil
case []interface{}:
return fmt.Sprintf("%s", o[0]), nil
case map[string]interface{}:
switch uri := o["origins"].(type) {
case []interface{}:
return fmt.Sprintf("%s", uri[0]), nil
default:
return "", fmt.Errorf("unrecognized DIDCore origins object %s", o)
}
default:
return "", fmt.Errorf("unrecognized DIDCore endpoint object %s", o)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/common/model/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func TestEndpoint_MarshalUnmarshalJSON(t *testing.T) {
expectedValue: []byte(`["some random endpoint","some other endpoint"]`),
err: nil,
},
{
name: "marshal random DIDCore Endpoint (neither DIDcomm V1 nor V2) as map[string]interface{}",
endpoint: Endpoint{
rawObj: map[string]interface{}{"origins": []interface{}{"some random endpoint"}},
},
expectedValue: []byte(`{"origins":["some random endpoint"]}`),
err: nil,
},
}

for _, tc := range testCases {
Expand Down