Skip to content

Commit 47bf448

Browse files
authored
Merge pull request #15 from iden3/feature/bump-go-iden3-core
core-lib bumb
2 parents 8e9697f + cf75009 commit 47bf448

File tree

5 files changed

+50
-171
lines changed

5 files changed

+50
-171
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.17
44

55
require (
66
github.com/ethereum/go-ethereum v1.10.15
7-
github.com/iden3/go-iden3-core v0.0.13
7+
github.com/iden3/go-iden3-core v0.0.16
88
github.com/iden3/go-iden3-crypto v0.0.13
99
github.com/iden3/go-merkletree-sql v1.0.0-pre8
1010
github.com/iden3/go-schema-registry-wrapper v0.0.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ github.com/huin/goupnp v1.0.2 h1:RfGLP+h3mvisuWEyybxNq5Eft3NWhHLPeUN72kpKZoI=
214214
github.com/huin/goupnp v1.0.2/go.mod h1:0dxJBVBHqTMjIUMkESDTNgOOx/Mw5wYIfyFmdzSamkM=
215215
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
216216
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
217-
github.com/iden3/go-iden3-core v0.0.13 h1:Bu9JDxxy+P43QAES9SMuBczvtlmRGbXVs0iyYcaMb+0=
218-
github.com/iden3/go-iden3-core v0.0.13/go.mod h1:wJtcMK/bSazyW/JrQaRrbpUMgSMg79Pke3xgtfPxDnQ=
217+
github.com/iden3/go-iden3-core v0.0.16 h1:BHNcRA+3Jbz0ur9VhQePP9u9o6cGvLBLB3Qs9OGoQlM=
218+
github.com/iden3/go-iden3-core v0.0.16/go.mod h1:wJtcMK/bSazyW/JrQaRrbpUMgSMg79Pke3xgtfPxDnQ=
219219
github.com/iden3/go-iden3-crypto v0.0.11/go.mod h1:yUBWcXgAUDZxa1PvRl0zIT4Q4/rQO5PacE52Z06i8kw=
220220
github.com/iden3/go-iden3-crypto v0.0.13 h1:ixWRiaqDULNyIDdOWz2QQJG5t4PpNHkQk2P6GV94cok=
221221
github.com/iden3/go-iden3-crypto v0.0.13/go.mod h1:swXIv0HFbJKobbQBtsB50G7IHr6PbTowutSew/iBEoo=

processor/json-ld/processor_ipfs_test.go

Lines changed: 12 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jsonld
33
import (
44
"context"
55
commonJSON "encoding/json"
6+
schemaUtils "github.com/iden3/go-schema-processor/utils"
67
"math/big"
78
"os"
89
"testing"
@@ -12,10 +13,8 @@ import (
1213
jsonld "github.com/iden3/go-schema-processor/json-ld"
1314
"github.com/iden3/go-schema-processor/loaders"
1415
"github.com/iden3/go-schema-processor/processor"
15-
schemaUtils "github.com/iden3/go-schema-processor/utils"
1616
"github.com/iden3/go-schema-processor/verifiable"
1717
"github.com/stretchr/testify/assert"
18-
"github.com/stretchr/testify/require"
1918
)
2019

2120
func getIPFSLoader(t string) processor.SchemaLoader {
@@ -25,7 +24,7 @@ func getIPFSLoader(t string) processor.SchemaLoader {
2524
case "kyc":
2625
cid = "QmaniifmAkPfmTkpNzVQPcdn4Bu5LuNx1qn1dpNFmU6en6"
2726
case "kyc-v2":
28-
cid = "QmZm9WhzuyqXnhBmvd9aNYP6qQAHnpghFbVzH5kiAikmhW"
27+
cid = "QmP8NrKqoBKjmKwMsC8pwBCBxXR2PhwSepwXx31gnJxAbP"
2928
case "auth":
3029
cid = "QmWf7fD5txHaMH1zhrWUKSVvACgTLLqcdWbFPqQkKHa9yJ"
3130
default:
@@ -142,7 +141,7 @@ func TestValidatorPFSLoader(t *testing.T) {
142141

143142
}
144143

145-
func TestValidatorWithInvalidFieldPFSLoader(t *testing.T) {
144+
func TestValidatorWithInvalidFieldIPFSLoader(t *testing.T) {
146145

147146
loader := getIPFSLoader("kyc")
148147
validator := jsonld.Validator{ClaimType: "KYCAgeCredential"}
@@ -174,7 +173,7 @@ func TestValidatorWithInvalidFieldPFSLoader(t *testing.T) {
174173

175174
}
176175

177-
func TestValidatorWithPositionedDataPFSLoader(t *testing.T) {
176+
func TestValidatorWithPositionedDataIPFSLoader(t *testing.T) {
178177

179178
loader := getIPFSLoader("kyc")
180179
validator := jsonld.Validator{ClaimType: "KYCAgeCredential"}
@@ -203,7 +202,7 @@ func TestValidatorWithPositionedDataPFSLoader(t *testing.T) {
203202

204203
}
205204

206-
func TestParserWithSlotsTypesPFSLoader(t *testing.T) {
205+
func TestParserWithSlotsTypesIPFSLoader(t *testing.T) {
207206

208207
loader := getIPFSLoader("kyc-v2")
209208
validator := json.Validator{}
@@ -243,7 +242,7 @@ func TestParserWithSlotsTypesPFSLoader(t *testing.T) {
243242

244243
}
245244

246-
func TestGetFieldIndexWithSlotsTypesPFSLoader(t *testing.T) {
245+
func TestGetFieldIndexWithSlotsTypesIPFSLoader(t *testing.T) {
247246

248247
loader := getIPFSLoader("kyc-v2")
249248
validator := json.Validator{}
@@ -272,7 +271,7 @@ func TestGetFieldIndexWithSlotsTypesPFSLoader(t *testing.T) {
272271

273272
}
274273

275-
func TestParserForBigIntegersPFSLoader(t *testing.T) {
274+
func TestParserForBigIntegersIPFSLoader(t *testing.T) {
276275

277276
loader := getIPFSLoader("auth")
278277
validator := json.Validator{}
@@ -313,66 +312,9 @@ func TestParserForBigIntegersPFSLoader(t *testing.T) {
313312
assert.Empty(t, parsedData.ValueB)
314313
}
315314

316-
func TestParserParseClaimWithoutSubjectIDPFSLoader(t *testing.T) {
317-
318-
jsonLDDocument := `{"id":"c0f6ac87-603e-44cd-8d83-0caeb458d50d","@context":["https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/iden3credential.json-ld","https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/auth.json-ld"],"@type":["Iden3Credential"],"expiration":"2361-03-21T21:14:48+02:00","updatable":false,"version":0,"rev_nonce":2034832188220019200,"credentialSubject":{"type":"AuthBJJCredential","x":"12747559771369266961976321746772881814229091957322087014312756428846389160887","y":"7732074634595480184356588475330446395691728690271550550016720788712795268212"},"credentialStatus":{"id":"http://localhost:8001/api/v1/identities/118VhAf6ng6J44FhNrGeYzSbJgGVmcpeXYFR2YTrZ6/claims/revocation/status/2034832188220019081","type":"SparseMerkleTreeProof"},"credentialSchema":{"@id":"auth","type":"JsonSchemaValidator2018"},"proof":[{"@type":"BJJSignature2021","issuer":"118VhAf6ng6J44FhNrGeYzSbJgGVmcpeXYFR2YTrZ6","h_index":"c89cf5b95157f091f2d8bf49bc1a57cd7988da83bbcd982a74c5e8c70e566403","h_value":"0262b2cd6b9ae44cd9a39045c9bb03ad4e1f056cb81d855f1fc4ef0cdf827912","created":1642518655,"issuer_mtp":{"@type":"Iden3SparseMerkleProof","issuer":"118VhAf6ng6J44FhNrGeYzSbJgGVmcpeXYFR2YTrZ6","h_index":"201a02eb979be695702ea37d930309d2965d803541be5f7b3900459b2fad8726","h_value":"0654da1d53ca201cb42b767a6f12265ff7a08720b88a82182e0f20702479d12d","state":{"claims_tree_root":"a5087cfa6f2c7c565d831327091533f09999133df1df51104d2ce6f8e4d90529","value":"dca344e95da517a301729d94b213298b9de96dfddaf7aad9423d918ea3208820"},"mtp":{"existence":true,"siblings":[]}},"verification_method":"2764e2d8241b18c217010ebf90bebb30240d32c33f3007f33e42d58680813123","proof_value":"c354eb1006534c59766ed8398d49a9a614312e430c5373ea493395db6369d49485e9a0d63f3bfe9fd157294ffbf706b6b7df7a8662a58fae0056a046af1caa04","proof_purpose":"Authentication"},{"@type":"Iden3SparseMerkleProof","issuer":"118VhAf6ng6J44FhNrGeYzSbJgGVmcpeXYFR2YTrZ6","h_index":"c89cf5b95157f091f2d8bf49bc1a57cd7988da83bbcd982a74c5e8c70e566403","h_value":"0262b2cd6b9ae44cd9a39045c9bb03ad4e1f056cb81d855f1fc4ef0cdf827912","state":{"tx_id":"0xf2e23524ab76cb4f371b921a214ff411d5d391962899a2afe20f356e3bdc0c71","block_timestamp":1642522496,"block_number":11837707,"claims_tree_root":"bebcaee8444e93b6e32855f54e9f617d5fd654570badce7d6bc649304169681d","revocation_tree_root":"0000000000000000000000000000000000000000000000000000000000000000","value":"2806aa9a045b2a5503b12f2979b2d19933e803fd3dd73d8ad40dc138bc9a582e"},"mtp":{"existence":true,"siblings":["0","0","0","18555164879275043542501047154170418730098376961920428892719505858997411121317"]}}]}`
319-
320-
var vc verifiable.Iden3Credential
321-
322-
err := commonJSON.Unmarshal([]byte(jsonLDDocument), &vc)
323-
assert.Nil(t, err)
324-
325-
credType := vc.CredentialSubject["type"].(string)
326-
parser := jsonld.Parser{ClaimType: credType,
327-
ParsingStrategy: processor.OneFieldPerSlotStrategy}
328-
loader := getIPFSLoader(vc.CredentialSchema.ID)
329-
schemaBytes, ext, err := loader.Load(context.Background())
330-
assert.Nil(t, err)
331-
assert.Equal(t, ext, "json-ld")
332-
assert.NotEmpty(t, schemaBytes)
333-
334-
coreClaim, err := parser.ParseClaim(&vc, schemaBytes)
335-
assert.Nil(t, err)
336-
_, err = coreClaim.GetID()
337-
assert.Errorf(t, err, "ID is not set")
338-
schemaClaimBytes, err := coreClaim.GetSchemaHash().MarshalText()
339-
assert.Nil(t, err)
340-
assert.Equal(t, "825a563818f8450461ea87bd23bf56af",
341-
string(schemaClaimBytes))
342-
343-
revNonce := coreClaim.GetRevocationNonce()
344-
assert.Equal(t, vc.RevNonce, revNonce)
345-
346-
expTime, _ := coreClaim.GetExpirationDate()
347-
assert.Equal(t, vc.Expiration.Unix(), expTime.Unix())
348-
349-
updatable := coreClaim.GetFlagUpdatable()
350-
assert.Equal(t, vc.Updatable, updatable)
351-
352-
indexSlots, _ := coreClaim.RawSlots()
353-
hIndex, hValue, err := schemaUtils.IndexValueHash(*coreClaim)
354-
require.NoError(t, err)
355-
356-
xBigInt, ok := new(big.Int).SetString("12747559771369266961976321746772881814229091957322087014312756428846389160887",
357-
10)
358-
assert.True(t, ok)
359-
yBigInt, ok := new(big.Int).SetString("7732074634595480184356588475330446395691728690271550550016720788712795268212",
360-
10)
361-
assert.True(t, ok)
362-
assert.Equal(t,
363-
"c522586cce36201d072f2bb8a75e6c729960ef54d3c75903c17ab705ba43b11a",
364-
hIndex.Hex())
365-
assert.Equal(t,
366-
"449c53013992e70856c3cb7c7a10ac0b3aa455de305f4af5a93b9ade4592f319",
367-
hValue.Hex())
368-
assert.Equal(t, xBigInt, indexSlots[2].ToInt())
369-
assert.Equal(t, yBigInt, indexSlots[3].ToInt())
370-
371-
}
372315
func TestParserParseClaimWithSubjectIDPFSLoader(t *testing.T) {
373316

374-
jsonLDDocument := `{"id":"2caf3139-7f69-4f9c-a2cb-5a35cff78aab","@context":["https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/iden3credential.json-ld","https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v2.json-ld"],"@type":["Iden3Credential"],"expiration":"2361-03-21T21:14:48+02:00","updatable":false,"version":0,"rev_nonce":3473370693766599700,"credentialSubject":{"countryCode":980,"documentType":1,"id":"114RrowVvS5fz1XDmTG1EXBuYsruvdYzGByqFBvpHc","type":"KYCCountryOfResidenceCredential"},"credentialStatus":{"id":"http://localhost:8001/api/v1/identities/115mN2C7gh65EpfKt6skXeKGcJ53PACCSGfapzYkAW/claims/revocation/status/3473370693766599916","type":"SparseMerkleTreeProof"},"credentialSchema":{"@id":"kyc-v2","type":"JsonSchemaValidator2018"},"proof":[{"@type":"BJJSignature2021","issuer":"115mN2C7gh65EpfKt6skXeKGcJ53PACCSGfapzYkAW","h_index":"519c009c790b3bcb3ea3e9f33fc8071bacf7a1c6510e944dbb648419025e500c","h_value":"1d4895af94c1d4abfe658876f75baf527711d20b130cba4589e879afdaed7520","created":1642497726,"issuer_mtp":{"@type":"Iden3SparseMerkleProof","issuer":"115mN2C7gh65EpfKt6skXeKGcJ53PACCSGfapzYkAW","h_index":"eaa341a91db8b914d61326d9642c35ac2ca4f6dbb1a87609f84b669685141f11","h_value":"46993eb76d20c1880406798b1b9237092515c2d9949620510ec7196e43fd3205","state":{"claims_tree_root":"5ce2c11a4474fe4c6041e5105b0b381c0efb203ef0ce4d88c4ed32d3d8877001","value":"9a47b0353868f5c0ec3eae7a20bab97cbfd789b334424ab41c9bd40c1f762823"},"mtp":{"existence":true,"siblings":[]}},"verification_method":"ddba158931e361d48f195417413a2ec931441847200fe276bcb1648a4e184c1e","proof_value":"40dd0fb06386d78021d999c4b49d659dd90333a64d87d27870297d31188f95948e86ea2d37f605295074f16a837b6a9bc6189d90aaed1be10bcaca06292a4005","proof_purpose":"Authentication"},{"@type":"Iden3SparseMerkleProof","issuer":"115mN2C7gh65EpfKt6skXeKGcJ53PACCSGfapzYkAW","h_index":"6a3978073c5828f2760381ba02b24bdfddf0456a244fe5d485e1135ee472042e","h_value":"1d4895af94c1d4abfe658876f75baf527711d20b130cba4589e879afdaed7520","state":{"tx_id":"0x8537e0645996e34a8115da9a60b307094580e840a030668127393826d61cd0d1","block_timestamp":1642497740,"block_number":11836551,"claims_tree_root":"0511047e551c7e0d2ae1884636fbdf86c1a5a0156938b6ea857a4e34e06a7a0c","revocation_tree_root":"0000000000000000000000000000000000000000000000000000000000000000","value":"c5803aeb2c6d0a357855e070c24fddd5c4ccfef4692cfbf5e1c9068581d53712"},"mtp":{"existence":true,"siblings":["5691303581499283741098849603802493433441417335538778353796518252917364457995","0","0","0","0","0","0","651137301185586690938826662242457730822130240763746109003863565068434268764"]}}]}`
375-
317+
jsonLDDocument := `{"id":"e65a0bfb-d1a0-4f8d-bbd4-7705a17f6b5d","@context":["https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/iden3credential.json-ld","ipfs://QmP8NrKqoBKjmKwMsC8pwBCBxXR2PhwSepwXx31gnJxAbP"],"@type":["Iden3Credential"],"expiration":"2361-03-21T21:14:48+02:00","updatable":false,"version":0,"rev_nonce":1427136406,"credentialSubject":{"countryCode":980,"documentType":1,"id":"116iPg7dwEP5VqNr1DHQKo4JRbypL2ccJryV3626yV","type":"KYCCountryOfResidenceCredential"},"credentialStatus":{"id":"http://localhost:8001/api/v1/identities/118HT4DprVZDh1hwxNbgXvj3WYfs7aJMejdKBCr3fz/claims/revocation/status/1427136406","type":"SparseMerkleTreeProof"},"credentialSchema":{"@id":"ipfs://QmP8NrKqoBKjmKwMsC8pwBCBxXR2PhwSepwXx31gnJxAbP","type":"KYCCountryOfResidenceCredential"},"proof":{"@type":"BJJSignature2021","issuer":"118HT4DprVZDh1hwxNbgXvj3WYfs7aJMejdKBCr3fz","h_index":"6e43eefcb286da6410752683af39ac01fe4c2b71bb6bc33153f817c1ff72b323","h_value":"095192dcc00fc43d0df69c59905b150376c317a92f0f29e5cb958cd2856b8908","created":1650903921,"issuer_mtp":{"@type":"Iden3SparseMerkleProof","issuer":"118HT4DprVZDh1hwxNbgXvj3WYfs7aJMejdKBCr3fz","h_index":"90feb35f5b65f0b51d24d88a933dd6bde9809dc0d5bfe1f48219864036e61105","h_value":"46993eb76d20c1880406798b1b9237092515c2d9949620510ec7196e43fd3205","state":{"claims_tree_root":"4a215db950a071439fee5c2d4862d6fab89c2f7b1e06735e1c23e96b0584142e","value":"c4000e554cc3a6a725e0298b816e1952c3b1681bbed44e0a84fc6957b908900f","status":"created"},"mtp":{"existence":true,"siblings":[]}},"verification_method":"d2050abbe1e4d788621e5e54ef0e40081d3e1a1e5753b08e159608f60eb48715","proof_value":"6b3b95fa5365df397cb2d0d638fc2d9ec2e7bb687937a50d3c9aa8820343c01c80821f66eea8c706cf836040e7b58dc85513b3aad99abbc7067cbe1ee6a36701","proof_purpose":"Authentication"}}`
376318
var vc verifiable.Iden3Credential
377319

378320
err := commonJSON.Unmarshal([]byte(jsonLDDocument), &vc)
@@ -383,7 +325,7 @@ func TestParserParseClaimWithSubjectIDPFSLoader(t *testing.T) {
383325
parser := jsonld.Parser{ClaimType: credType,
384326
ParsingStrategy: processor.OneFieldPerSlotStrategy}
385327

386-
loader := getIPFSLoader(vc.CredentialSchema.ID)
328+
loader := getIPFSLoader("kyc-v2")
387329
schemaBytes, ext, err := loader.Load(context.Background())
388330
assert.Nil(t, err)
389331
assert.Equal(t, ext, "json-ld")
@@ -397,7 +339,7 @@ func TestParserParseClaimWithSubjectIDPFSLoader(t *testing.T) {
397339

398340
schemaClaimBytes, err := coreClaim.GetSchemaHash().MarshalText()
399341
assert.Nil(t, err)
400-
assert.Equal(t, "782bb5dd29b875efb42f6c54ab585fdb",
342+
assert.Equal(t, "ce38102464833febf36e714922a83050",
401343
string(schemaClaimBytes))
402344

403345
revNonce := coreClaim.GetRevocationNonce()
@@ -409,20 +351,6 @@ func TestParserParseClaimWithSubjectIDPFSLoader(t *testing.T) {
409351
updatable := coreClaim.GetFlagUpdatable()
410352
assert.Equal(t, vc.Updatable, updatable)
411353

412-
hIndex, hValue, err := schemaUtils.IndexValueHash(*coreClaim)
413-
require.NoError(t, err)
414-
indexSlots, _ := coreClaim.RawSlots()
415-
xBigInt, ok := new(big.Int).SetString("980", 10)
416-
assert.True(t, ok)
417-
yBigInt, ok := new(big.Int).SetString("1", 10)
418-
assert.True(t, ok)
419-
assert.Equal(t,
420-
"519c009c790b3bcb3ea3e9f33fc8071bacf7a1c6510e944dbb648419025e500c",
421-
hIndex.Hex())
422-
assert.Equal(t,
423-
"4da320609775b1caa029c7058f27069eccfb70560c582e8df7319ce54124b00c",
424-
hValue.Hex())
425-
assert.Equal(t, xBigInt, indexSlots[2].ToInt())
426-
assert.Equal(t, yBigInt, indexSlots[3].ToInt())
427-
354+
err = schemaUtils.VerifyClaimHash(&vc, coreClaim)
355+
assert.Nil(t, err)
428356
}

0 commit comments

Comments
 (0)