From 04967f7f074b91a61963069426f3a178482c2a05 Mon Sep 17 00:00:00 2001 From: Stas Dm Date: Wed, 30 Oct 2024 12:39:23 +0100 Subject: [PATCH] feat: add vp test --- ld/processor_test.go | 64 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/ld/processor_test.go b/ld/processor_test.go index f6d2836..e1148c0 100644 --- a/ld/processor_test.go +++ b/ld/processor_test.go @@ -27,8 +27,9 @@ import ( "testing" "time" - . "github.com/piprate/json-gold/ld" "github.com/stretchr/testify/assert" + + . "github.com/piprate/json-gold/ld" ) // RewriteHostTransport is an http.RoundTripper that rewrites requests @@ -694,3 +695,64 @@ func (er *EarlReport) write(filename string) { _, _ = f.Write(b) _, _ = f.WriteString("\n") } + +func TestVPNormalization(t *testing.T) { + proc := NewJsonLdProcessor() + options := NewJsonLdOptions("") + options.Algorithm = AlgorithmURDNA2015 + options.ProduceGeneralizedRdf = true + + input := `{ + "@context": [ + "https://www.w3.org/ns/credentials/v2" + ], + "type": [ + "VerifiablePresentation" + ], + "verifiableCredential": [ + { + "@context": [ + "https://www.w3.org/ns/credentials/v2" + ], + "type": [ + "VerifiableCredential" + ], + "issuer": "did:key:z6MkpJySvETLnxhQG9DzEdmKJtysBDjuuTeDfUj1uNNCUqcj", + "credentialSubject": { + "id": "did:example:subject" + }, + "proof": { + "type": "DataIntegrityProof", + "created": "2024-10-17T18:17:31Z", + "verificationMethod": "did:key:z6MkpJySvETLnxhQG9DzEdmKJtysBDjuuTeDfUj1uNNCUqcj#z6MkpJySvETLnxhQG9DzEdmKJtysBDjuuTeDfUj1uNNCUqcj", + "cryptosuite": "eddsa-rdfc-2022", + "proofPurpose": "assertionMethod", + "proofValue": "z49q4jLydafVc5qGuRg5WAnG7au6uddhCCr2pNK23JJKzgwhWQUCDGym5GDqJM76ZzEWaU8y53xZffFk7XsLYo8ek" + } + } + ] +}` + + var dict map[string]interface{} + err := json.Unmarshal([]byte(input), &dict) + assert.NoError(t, err) + + options.Format = "application/n-quads" + output2, err := proc.Normalize(dict, options) + assert.NoError(t, err) + + assert.EqualValues(t, output2.(string), + `_:c14n0 "2024-10-17T18:17:31Z"^^ _:c14n2 . +_:c14n0 _:c14n2 . +_:c14n0 "eddsa-rdfc-2022"^^ _:c14n2 . +_:c14n0 _:c14n2 . +_:c14n0 "z49q4jLydafVc5qGuRg5WAnG7au6uddhCCr2pNK23JJKzgwhWQUCDGym5GDqJM76ZzEWaU8y53xZffFk7XsLYo8ek"^^ _:c14n2 . +_:c14n0 _:c14n2 . +_:c14n1 . +_:c14n1 _:c14n3 . +_:c14n4 _:c14n3 . +_:c14n4 _:c14n2 _:c14n3 . +_:c14n4 _:c14n3 . +_:c14n4 _:c14n3 . +`) +}