From d070d6c4a470a37b2afea81a5205db4468d4dbc1 Mon Sep 17 00:00:00 2001 From: Rolson Quadras Date: Wed, 29 Mar 2023 13:58:44 -0400 Subject: [PATCH] fix: DIDDoc Service Endpoint with origins key support Signed-off-by: Rolson Quadras --- pkg/common/model/endpoint.go | 7 +++++++ pkg/common/model/endpoint_test.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/common/model/endpoint.go b/pkg/common/model/endpoint.go index af0bc028b..4b1323e50 100644 --- a/pkg/common/model/endpoint.go +++ b/pkg/common/model/endpoint.go @@ -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) } diff --git a/pkg/common/model/endpoint_test.go b/pkg/common/model/endpoint_test.go index 6eb93876f..4fe796adf 100644 --- a/pkg/common/model/endpoint_test.go +++ b/pkg/common/model/endpoint_test.go @@ -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 {