Skip to content

Commit

Permalink
Generate signals event if entry is not found in the original document…
Browse files Browse the repository at this point in the history
…. It is required for queries like exists=false. (#76)
  • Loading branch information
olomix authored Apr 24, 2024
1 parent cc0573d commit 2117a75
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ go 1.21.4

require (
github.com/dgraph-io/badger/v4 v4.2.0
github.com/ethereum/go-ethereum v1.13.14
github.com/iden3/go-circuits/v2 v2.2.0
github.com/iden3/go-iden3-core/v2 v2.1.0
github.com/ethereum/go-ethereum v1.13.15
github.com/iden3/go-circuits/v2 v2.2.1
github.com/iden3/go-iden3-core/v2 v2.1.1
github.com/iden3/go-iden3-crypto v0.0.16
github.com/iden3/go-merkletree-sql/v2 v2.0.6
github.com/iden3/go-onchain-credential-adapter v0.0.0-20240223120548-5d8d1d28c6d1
github.com/iden3/go-schema-processor/v2 v2.3.3
github.com/iden3/merkletree-proof v0.1.0
github.com/iden3/go-schema-processor/v2 v2.3.4
github.com/iden3/merkletree-proof v0.1.1
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-ethereum v1.13.14 h1:EwiY3FZP94derMCIam1iW4HFVrSgIcpsu0HwTQtm6CQ=
github.com/ethereum/go-ethereum v1.13.14/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
github.com/ethereum/go-ethereum v1.13.15 h1:U7sSGYGo4SPjP6iNIifNoyIAiNjrmQkz6EwQG+/EZWo=
github.com/ethereum/go-ethereum v1.13.15/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA=
github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -160,20 +160,20 @@ github.com/iden3/contracts-abi/onchain-non-merklized-issuer-base/v0/go/abi v0.0.
github.com/iden3/contracts-abi/onchain-non-merklized-issuer-base/v0/go/abi v0.0.0-20240222110004-06aa097d1318/go.mod h1:vMgeBNntJeIDZrIDY0d6sZQU+JigUo4h+m95qeU03ew=
github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4 h1:iPvYa/AhhGo3juoUFDm/fBE2CZKy4WfQu7JY90tRf9Q=
github.com/iden3/contracts-abi/state/go/abi v0.0.0-20230405152923-4a25f6f1f0f4/go.mod h1:TxgIrXCvxms3sbOdsy8kTvffUCIpEEifNy0fSXdkU4w=
github.com/iden3/go-circuits/v2 v2.2.0 h1:qJeySVPG9vxZwJyL/CsvXdUhccWOctXQUYGnyX5p2Kc=
github.com/iden3/go-circuits/v2 v2.2.0/go.mod h1:1LET+T8i9Rkfx+RNj2BBHKAPGDODEWWwSEFjR6g3h6c=
github.com/iden3/go-iden3-core/v2 v2.1.0 h1:R1s7Tj3tIx5lDy8S7OJrSNuxXIFeRzWRmTBaQoQHJps=
github.com/iden3/go-iden3-core/v2 v2.1.0/go.mod h1:L9PxhWPvoS9qTb3inEkZBm1RpjHBt+VTwvxssdzbAdw=
github.com/iden3/go-circuits/v2 v2.2.1 h1:ww+qOmEZJjL3bolLlnZv2SuukiVolgdcSaL3vonXoxI=
github.com/iden3/go-circuits/v2 v2.2.1/go.mod h1:Q6IFYauDdWo0hES4XzHXxz7hUYpmNsVmtP36Lxkjc/0=
github.com/iden3/go-iden3-core/v2 v2.1.1 h1:WD14iWKZmnfHTl9Em/PfGssrFYXz8YNQPjPs/cn+eHc=
github.com/iden3/go-iden3-core/v2 v2.1.1/go.mod h1:L9PxhWPvoS9qTb3inEkZBm1RpjHBt+VTwvxssdzbAdw=
github.com/iden3/go-iden3-crypto v0.0.16 h1:zN867xiz6HgErXVIV/6WyteGcOukE9gybYTorBMEdsk=
github.com/iden3/go-iden3-crypto v0.0.16/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E=
github.com/iden3/go-merkletree-sql/v2 v2.0.6 h1:vsVDImnvnHf7Ggr45ptFOXJyWNA/8IwVQO1jzRLUlY8=
github.com/iden3/go-merkletree-sql/v2 v2.0.6/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk=
github.com/iden3/go-onchain-credential-adapter v0.0.0-20240223120548-5d8d1d28c6d1 h1:xpKhrLYi0s6ocUCrFwkjG0YQjndDGMW7/cgU9KjLyig=
github.com/iden3/go-onchain-credential-adapter v0.0.0-20240223120548-5d8d1d28c6d1/go.mod h1:1RVClY0JdWmzgx3ZBvy0Z2bNyPg2iz+0R9Ryl2Z3s64=
github.com/iden3/go-schema-processor/v2 v2.3.3 h1:GfChxMZHG4miA3p/5rLIrM7TGmKu/oAAXgLloYTBHSI=
github.com/iden3/go-schema-processor/v2 v2.3.3/go.mod h1:8y/R0iQpYhyhRQ3sL4F5Aja3+1T68M6uwGQdC4pQ4X0=
github.com/iden3/merkletree-proof v0.1.0 h1:AHmpkbCTLKv1MWWt6YwogB65E4y6UZthbZYPed81w4U=
github.com/iden3/merkletree-proof v0.1.0/go.mod h1:ul0HDU6/eVNX++u/PWScY7pTXiFjqM5kA6vl1wEoTUU=
github.com/iden3/go-schema-processor/v2 v2.3.4 h1:zWE9NrY7dm9Il8c0u3XcJfenptmxbvIaNDOqkq5uQ0A=
github.com/iden3/go-schema-processor/v2 v2.3.4/go.mod h1:tuz/iuqU13NdpCY1Ovsh7n6KTZnJnfhqjB0MUgxbcA4=
github.com/iden3/merkletree-proof v0.1.1 h1:NwuaW/t0HTwZpmxWSxqeh/hYRjAQt/uIvw5QeW5GE8I=
github.com/iden3/merkletree-proof v0.1.1/go.mod h1:ul0HDU6/eVNX++u/PWScY7pTXiFjqM5kA6vl1wEoTUU=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
Expand Down Expand Up @@ -255,8 +255,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
Expand Down
34 changes: 24 additions & 10 deletions inputs_sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,17 @@ func buildQueryPath(ctx context.Context, contextURL string, contextType string,
return
}

func datatypeFromContext(contextURL string, contextType string, field string,
documentLoader ld.DocumentLoader, hasher merklize.Hasher) (string, error) {

return merklize.Options{
Hasher: hasher,
DocumentLoader: documentLoader,
}.TypeFromContext(
[]byte(`{"@context":"`+contextURL+`"}`),
contextType+"."+field)
}

func querySkipRevocation(requestObj jsonObj) (bool, error) {
result, err := getByPath(requestObj, "query.skipClaimRevocationCheck")
if errors.As(err, &errPathNotFound{}) {
Expand Down Expand Up @@ -1510,16 +1521,14 @@ func mkValueProof(ctx context.Context, mz *merklize.Merklizer,
return nil, err
}

if !existenceProof.Existence {
return nil, fmt.Errorf(
"value not found in verifiable credential by path %v",
fmtPath(path))
}

var valueEntry *big.Int
valueEntry, err = mzValue.MtEntry()
if err != nil {
return nil, err
if existenceProof.Existence {
valueEntry, err = mzValue.MtEntry()
if err != nil {
return nil, err
}
} else {
valueEntry = big.NewInt(0)
}

var pathEntry *big.Int
Expand Down Expand Up @@ -1707,7 +1716,12 @@ func queriesFromObjMerklized(ctx context.Context,
val := ops[op]

var fieldDatatype string
fieldDatatype, err = mz.JSONLDType(path)
if valueProof.MTP.Existence {
fieldDatatype, err = mz.JSONLDType(path)
} else {
fieldDatatype, err = datatypeFromContext(contextURL,
contextType, field, documentLoader, mz.Hasher())
}
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 2117a75

Please sign in to comment.