Skip to content

Commit 28e177e

Browse files
authored
Merge pull request #13 from iden3/feature/new-schema-approach
fix сreateSchemaHash
2 parents 457d58e + 07128e2 commit 28e177e

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

json-ld/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (p Parser) ParseClaim(credential *verifiable.Iden3Credential, schemaBytes [
7878
return nil, err
7979
}
8080

81-
claim, err := core.NewClaim(utils.CreateSchemaHash(credentialType),
81+
claim, err := core.NewClaim(utils.CreateSchemaHash(schemaBytes, credentialType),
8282
core.WithIndexDataBytes(slots.IndexA, slots.IndexB),
8383
core.WithValueDataBytes(slots.ValueA, slots.ValueB),
8484
core.WithExpirationDate(credential.Expiration),

json/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s Parser) ParseClaim(credential *verifiable.Iden3Credential, schemaBytes [
4848
return nil, err
4949
}
5050

51-
claim, err := core.NewClaim(utils.CreateSchemaHash(credentialType),
51+
claim, err := core.NewClaim(utils.CreateSchemaHash(schemaBytes, credentialType),
5252
core.WithIndexDataBytes(slots.IndexA, slots.IndexB),
5353
core.WithValueDataBytes(slots.ValueA, slots.ValueB),
5454
core.WithExpirationDate(credential.Expiration),

processor/json-ld/processor_ipfs_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func TestParserParseClaimWithoutSubjectIDPFSLoader(t *testing.T) {
317317
assert.Errorf(t, err, "ID is not set")
318318
schemaClaimBytes, err := coreClaim.GetSchemaHash().MarshalText()
319319
assert.Nil(t, err)
320-
assert.Equal(t, "7c0844a075a9ddc7fcbdfb4f88acd9bc", string(schemaClaimBytes))
320+
assert.Equal(t, "825a563818f8450461ea87bd23bf56af", string(schemaClaimBytes))
321321

322322
revNonce := coreClaim.GetRevocationNonce()
323323
assert.Equal(t, vc.RevNonce, revNonce)
@@ -340,15 +340,15 @@ func TestParserParseClaimWithoutSubjectIDPFSLoader(t *testing.T) {
340340
assert.True(t, ok)
341341
yBigInt, ok := new(big.Int).SetString("7732074634595480184356588475330446395691728690271550550016720788712795268212", 10)
342342
assert.True(t, ok)
343-
assert.Equal(t, "c89cf5b95157f091f2d8bf49bc1a57cd7988da83bbcd982a74c5e8c70e566403", hIndex.Hex())
343+
assert.Equal(t, "c522586cce36201d072f2bb8a75e6c729960ef54d3c75903c17ab705ba43b11a", hIndex.Hex())
344344
assert.Equal(t, "449c53013992e70856c3cb7c7a10ac0b3aa455de305f4af5a93b9ade4592f319", hValue.Hex())
345345
assert.Equal(t, xBigInt, entry.Index()[2].BigInt())
346346
assert.Equal(t, yBigInt, entry.Index()[3].BigInt())
347347

348348
}
349349
func TestParserParseClaimWithSubjectIDPFSLoader(t *testing.T) {
350350

351-
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":"6a3978073c5828f2760381ba02b24bdfddf0456a244fe5d485e1135ee472042e","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"]}}]}`
351+
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"]}}]}`
352352

353353
var vc verifiable.Iden3Credential
354354

@@ -373,7 +373,7 @@ func TestParserParseClaimWithSubjectIDPFSLoader(t *testing.T) {
373373

374374
schemaClaimBytes, err := coreClaim.GetSchemaHash().MarshalText()
375375
assert.Nil(t, err)
376-
assert.Equal(t, "68041e1ca18544ece92e2ad6f17538e4", string(schemaClaimBytes))
376+
assert.Equal(t, "782bb5dd29b875efb42f6c54ab585fdb", string(schemaClaimBytes))
377377

378378
revNonce := coreClaim.GetRevocationNonce()
379379
assert.Equal(t, vc.RevNonce, revNonce)
@@ -394,7 +394,7 @@ func TestParserParseClaimWithSubjectIDPFSLoader(t *testing.T) {
394394
assert.True(t, ok)
395395
yBigInt, ok := new(big.Int).SetString("1", 10)
396396
assert.True(t, ok)
397-
assert.Equal(t, "6a3978073c5828f2760381ba02b24bdfddf0456a244fe5d485e1135ee472042e", hIndex.Hex())
397+
assert.Equal(t, "519c009c790b3bcb3ea3e9f33fc8071bacf7a1c6510e944dbb648419025e500c", hIndex.Hex())
398398
assert.Equal(t, "4da320609775b1caa029c7058f27069eccfb70560c582e8df7319ce54124b00c", hValue.Hex())
399399
assert.Equal(t, xBigInt, entry.Index()[2].BigInt())
400400
assert.Equal(t, yBigInt, entry.Index()[3].BigInt())

processor/json-ld/processor_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func TestParserParseClaimWithoutSubjectID(t *testing.T) {
306306
assert.Errorf(t, err, "ID is not set")
307307
schemaClaimBytes, err := coreClaim.GetSchemaHash().MarshalText()
308308
assert.Nil(t, err)
309-
assert.Equal(t, "7c0844a075a9ddc7fcbdfb4f88acd9bc", string(schemaClaimBytes))
309+
assert.Equal(t, "ca938857241db9451ea329256b9c06e5", string(schemaClaimBytes))
310310

311311
revNonce := coreClaim.GetRevocationNonce()
312312
assert.Equal(t, vc.RevNonce, revNonce)
@@ -329,7 +329,7 @@ func TestParserParseClaimWithoutSubjectID(t *testing.T) {
329329
assert.True(t, ok)
330330
yBigInt, ok := new(big.Int).SetString("7732074634595480184356588475330446395691728690271550550016720788712795268212", 10)
331331
assert.True(t, ok)
332-
assert.Equal(t, "c89cf5b95157f091f2d8bf49bc1a57cd7988da83bbcd982a74c5e8c70e566403", hIndex.Hex())
332+
assert.Equal(t, "f11cb68c61628ed00bad0f797a6756bd16faa983019af7f20daeb2600c437d28", hIndex.Hex())
333333
assert.Equal(t, "449c53013992e70856c3cb7c7a10ac0b3aa455de305f4af5a93b9ade4592f319", hValue.Hex())
334334
assert.Equal(t, xBigInt, entry.Index()[2].BigInt())
335335
assert.Equal(t, yBigInt, entry.Index()[3].BigInt())
@@ -363,7 +363,7 @@ func TestParserParseClaimWithSubjectID(t *testing.T) {
363363

364364
schemaClaimBytes, err := coreClaim.GetSchemaHash().MarshalText()
365365
assert.Nil(t, err)
366-
assert.Equal(t, "68041e1ca18544ece92e2ad6f17538e4", string(schemaClaimBytes))
366+
assert.Equal(t, "ce38102464833febf36e714922a83050", string(schemaClaimBytes))
367367

368368
revNonce := coreClaim.GetRevocationNonce()
369369
assert.Equal(t, vc.RevNonce, revNonce)
@@ -384,7 +384,7 @@ func TestParserParseClaimWithSubjectID(t *testing.T) {
384384
assert.True(t, ok)
385385
yBigInt, ok := new(big.Int).SetString("1", 10)
386386
assert.True(t, ok)
387-
assert.Equal(t, "6a3978073c5828f2760381ba02b24bdfddf0456a244fe5d485e1135ee472042e", hIndex.Hex())
387+
assert.Equal(t, "28876d2aeb56324aaf9c506b7313f19d309b223cbc047eb4528f2a6fdb8d1d1c", hIndex.Hex())
388388
assert.Equal(t, "4da320609775b1caa029c7058f27069eccfb70560c582e8df7319ce54124b00c", hValue.Hex())
389389
assert.Equal(t, xBigInt, entry.Index()[2].BigInt())
390390
assert.Equal(t, yBigInt, entry.Index()[3].BigInt())

utils/claims.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package utils
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/ethereum/go-ethereum/crypto"
67
core "github.com/iden3/go-iden3-core"
78
"github.com/iden3/go-schema-processor/processor"
89
"github.com/iden3/go-schema-processor/verifiable"
@@ -146,10 +147,10 @@ func IndexOf(field string, fields []string) int {
146147
return -1
147148
}
148149

149-
// CreateSchemaHash calculates schema hash
150-
func CreateSchemaHash(credentialType string) core.SchemaHash {
150+
// CreateSchemaHash computes schema hash from content and credential type
151+
func CreateSchemaHash(schemaBytes []byte, credentialType string) core.SchemaHash {
151152
var sHash core.SchemaHash
152-
h := Keccak256([]byte(credentialType))
153+
h := crypto.Keccak256(schemaBytes, []byte(credentialType))
153154
copy(sHash[:], h[len(h)-16:])
154155
return sHash
155156
}

0 commit comments

Comments
 (0)