diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/types.go b/types.go index 96a0ff9..71998d7 100644 --- a/types.go +++ b/types.go @@ -99,6 +99,7 @@ func (f *ForField) UnmarshalJSON(data []byte) error { type Policy struct { Type string `json:"@type"` Context any `json:"@context,omitempty"` + From string `json:"from,omitempty"` FromAgent string `json:"fromAgent,omitempty"` FromRole string `json:"fromRole,omitempty"` AboutParty string `json:"aboutParty,omitempty"` diff --git a/types_test.go b/types_test.go index 07883c0..698d019 100644 --- a/types_test.go +++ b/types_test.go @@ -1,6 +1,7 @@ package tap import ( + "bytes" "encoding/json" "testing" ) @@ -137,6 +138,24 @@ func TestPolicy_JSONRoundTrip(t *testing.T) { } } +func TestPolicy_FromFieldRoundTrip(t *testing.T) { + in := Policy{Type: "RequireAuthorization", From: "did:web:vasp.example"} + data, err := json.Marshal(in) + if err != nil { + t.Fatalf("marshal: %v", err) + } + if !bytes.Contains(data, []byte(`"from":"did:web:vasp.example"`)) { + t.Fatalf("missing from in JSON: %s", string(data)) + } + var out Policy + if err := json.Unmarshal(data, &out); err != nil { + t.Fatalf("unmarshal: %v", err) + } + if out.From != in.From { + t.Errorf("From = %q, want %q", out.From, in.From) + } +} + func TestTransactionConstraints_JSONRoundTrip(t *testing.T) { tc := TransactionConstraints{ Purposes: []string{"BEXP", "SUPP"},