Skip to content

Commit

Permalink
idemix aries (hyperledger-labs#488)
Browse files Browse the repository at this point in the history
Signed-off-by: Angelo De Caro <angelo.decaro@gmail.com>
Signed-off-by: Alessandro Sorniotti <aso@zurich.ibm.com>
  • Loading branch information
ale-linux authored Aug 20, 2023
1 parent 40af3ef commit 996dcf2
Show file tree
Hide file tree
Showing 15 changed files with 358 additions and 267 deletions.
14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/hyperledger-labs/fabric-smart-client

go 1.20
go 1.19

require (
github.com/IBM/idemix v0.0.2-0.20230510082947-a0c3ee5ebe35
github.com/IBM/mathlib v0.0.3-0.20230428120512-8afa4e643d4c
github.com/IBM/idemix v0.0.2-0.20230818094413-71dd11112cb5
github.com/IBM/idemix/bccsp/types v0.0.0-20230818094413-71dd11112cb5
github.com/IBM/mathlib v0.0.3-0.20230605104224-932ab92f2ce0
github.com/ReneKroon/ttlcache/v2 v2.11.0
github.com/dgraph-io/badger/v3 v3.2103.2
github.com/docker/docker v20.10.24+incompatible
Expand Down Expand Up @@ -41,7 +42,7 @@ require (
github.com/prometheus/client_golang v1.14.0
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.10.1
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
github.com/sykesm/zap-logfmt v0.0.4
github.com/tedsuo/ifrit v0.0.0-20220120221754-dd274de71113
github.com/test-go/testify v1.1.4
Expand All @@ -58,6 +59,9 @@ require (
)

require (
github.com/IBM/idemix/bccsp/schemes/aries v0.0.0-20230818094413-71dd11112cb5 // indirect
github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20230818094413-71dd11112cb5 // indirect
github.com/ale-linux/aries-framework-go/component/kmscrypto v0.0.0-20230817163708-4b3de6d91874 // indirect
github.com/bits-and-blooms/bitset v1.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
Expand Down Expand Up @@ -149,7 +153,7 @@ require (
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huin/goupnp v1.1.0 // indirect
github.com/hyperledger/fabric-amcl v0.0.0-20210603140002-2670f91851c8 // indirect
github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect
github.com/hyperledger/fabric-config v0.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
Expand Down
25 changes: 17 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/zstd v1.4.0/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/IBM/idemix v0.0.2-0.20230510082947-a0c3ee5ebe35 h1:2ucH1TS+pe18L6R2jww9UX5I8GrVWkwjcDbIChDUyfc=
github.com/IBM/idemix v0.0.2-0.20230510082947-a0c3ee5ebe35/go.mod h1:LKHePSqL9g67JezDTU8Y/HCRyzBP3zYbY7q9Hllx6y0=
github.com/IBM/mathlib v0.0.3-0.20230428120512-8afa4e643d4c h1:eLCIQV1wI6WBt1T+s2vUWFg7tBB0Xu/+YZSZ877+kyM=
github.com/IBM/mathlib v0.0.3-0.20230428120512-8afa4e643d4c/go.mod h1:p0HGSuwoOwAlts8u8rMJrInDo9BEwWUfzTIzdA+QuDo=
github.com/IBM/idemix v0.0.2-0.20230818094413-71dd11112cb5 h1:7bmMm60LbG8K/IAnIIgdV/CkPCjJIMU1RrShilhrMaU=
github.com/IBM/idemix v0.0.2-0.20230818094413-71dd11112cb5/go.mod h1:4NA9b+mxttV4D3W/GsvcLJhtrUFKhm0fJjx8dXhj8fw=
github.com/IBM/idemix/bccsp/schemes/aries v0.0.0-20230818094413-71dd11112cb5 h1:7zKch7HqzDYSYmkyj+g48ju5IPxEF9h0R7AOSX+Wzo0=
github.com/IBM/idemix/bccsp/schemes/aries v0.0.0-20230818094413-71dd11112cb5/go.mod h1:V1hC/kU/g+eZ2GOlSj4WBTB7FuGbWI0w4U2z7a4i/ew=
github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20230818094413-71dd11112cb5 h1:13AVLlfi/At8/bXKpDif3ml5HIKlKaQDvdnXRFK2cTw=
github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20230818094413-71dd11112cb5/go.mod h1:n86zzYREwJdjUybye3rerxmAFfgVJtPvNOrRX30CbrU=
github.com/IBM/idemix/bccsp/types v0.0.0-20230818094413-71dd11112cb5 h1:zBmnisWCyBr7JeH5E22kkm0W/eAse63Bxgefdu5xz7Q=
github.com/IBM/idemix/bccsp/types v0.0.0-20230818094413-71dd11112cb5/go.mod h1:6ura+11RaC9RwTQ2SEq5KZ+2w6+c7BuArQOP1Ktrlq0=
github.com/IBM/mathlib v0.0.3-0.20230605104224-932ab92f2ce0 h1:V3ElfC3Xs8bxJyc7VPcBQ9th6vyBBX8u/5bIUOXljk4=
github.com/IBM/mathlib v0.0.3-0.20230605104224-932ab92f2ce0/go.mod h1:k0NBSWMYVgaZ2keDuI8DSwdIEhUNhp8XnlVmm6Xwyuk=
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
Expand Down Expand Up @@ -113,6 +119,8 @@ github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/ale-linux/aries-framework-go/component/kmscrypto v0.0.0-20230817163708-4b3de6d91874 h1:O08ZCyb1f7UeyOmTeItAw7eSZOlyM0fBnrPgaYgKEiA=
github.com/ale-linux/aries-framework-go/component/kmscrypto v0.0.0-20230817163708-4b3de6d91874/go.mod h1:4sHtFlGI84SVjaSW7u1pCfC0bjijd9ZeqbKptU/Qljs=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -155,6 +163,7 @@ github.com/bits-and-blooms/bitset v1.2.1/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edY
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ=
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/cayleygraph/cayley v0.7.7 h1:z+7xkAbg6bKiXJOtOkEG3zCm2K084sr/aGwFV7xcQNs=
Expand Down Expand Up @@ -690,8 +699,8 @@ github.com/hyperledger/fabric v1.4.0-rc1.0.20201118191903-ec81f3e74fa1/go.mod h1
github.com/hyperledger/fabric v1.4.0-rc1.0.20230401164317-bd8e24856939 h1:+XwAnpbvmxEeRD1yT+gd77643Y1QQUv0B2HUr4CRNWE=
github.com/hyperledger/fabric v1.4.0-rc1.0.20230401164317-bd8e24856939/go.mod h1:H7BI2gsTl4fW9ARtYG7UOGjwecXHSReVaIz4p2xqUB8=
github.com/hyperledger/fabric-amcl v0.0.0-20200128223036-d1aa2665426a/go.mod h1:X+DIyUsaTmalOpmpQfIvFZjKHQedrURQ5t4YqquX7lE=
github.com/hyperledger/fabric-amcl v0.0.0-20210603140002-2670f91851c8 h1:BCR8ZlOZ+deUbWxyY6fpoY8LbB7PR5wGGwCTvWQOU2g=
github.com/hyperledger/fabric-amcl v0.0.0-20210603140002-2670f91851c8/go.mod h1:X+DIyUsaTmalOpmpQfIvFZjKHQedrURQ5t4YqquX7lE=
github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 h1:B1Nt8hKb//KvgGRprk0h1t4lCnwhE9/ryb1WqfZbV+M=
github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2/go.mod h1:X+DIyUsaTmalOpmpQfIvFZjKHQedrURQ5t4YqquX7lE=
github.com/hyperledger/fabric-chaincode-go v0.0.0-20190823162523-04390e015b85/go.mod h1:HZK6PKLWrvdD/t0oSLiyaRaUM6fZ7qjJuOlb0zrn0mo=
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200128192331-2d899240a7ed/go.mod h1:N7H3sA7Tx4k/YzFq7U0EPdqJtqvM4Kild0JoCc7C0Dc=
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200424173110-d7076418f212/go.mod h1:N7H3sA7Tx4k/YzFq7U0EPdqJtqvM4Kild0JoCc7C0Dc=
Expand Down Expand Up @@ -1284,8 +1293,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
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.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/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/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/sykesm/zap-logfmt v0.0.2/go.mod h1:TerDJT124HaO8UTpZ2wJCipJRAKQ9XONM1mzUabIh6M=
Expand Down
2 changes: 1 addition & 1 deletion platform/fabric/core/generic/msp/idemix/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package idemix
import (
"encoding/json"

csp "github.com/IBM/idemix/bccsp/schemes"
csp "github.com/IBM/idemix/bccsp/types"
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/proto"
m "github.com/hyperledger/fabric-protos-go/msp"
"github.com/pkg/errors"
Expand Down
14 changes: 9 additions & 5 deletions platform/fabric/core/generic/msp/idemix/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ type IdentityCache struct {
once sync.Once
backed IdentityCacheBackendFunc
cache chan identityCacheEntry
opts *driver.IdentityOptions
}

func NewIdentityCache(backed IdentityCacheBackendFunc, size int) *IdentityCache {
func NewIdentityCache(backed IdentityCacheBackendFunc, size int, opts *driver.IdentityOptions) *IdentityCache {
ci := &IdentityCache{
backed: backed,
cache: make(chan identityCacheEntry, size),
opts: opts,
}

return ci
Expand All @@ -44,9 +46,11 @@ func (c *IdentityCache) Identity(opts *driver.IdentityOptions) (view.Identity, [
}

c.once.Do(func() {
// Spin up as many background goroutines as we need to prepare identities in the background.
for i := 0; i < runtime.NumCPU(); i++ {
go c.provisionIdentities()
if cap(c.cache) > 0 {
// Spin up as many background goroutines as we need to prepare identities in the background.
for i := 0; i < runtime.NumCPU(); i++ {
go c.provisionIdentities()
}
}
})

Expand Down Expand Up @@ -114,7 +118,7 @@ func (c *IdentityCache) fetchIdentityFromBackend(opts *driver.IdentityOptions) (

func (c *IdentityCache) provisionIdentities() {
for {
id, audit, err := c.backed(nil)
id, audit, err := c.backed(c.opts)
if err != nil {
continue
}
Expand Down
13 changes: 4 additions & 9 deletions platform/fabric/core/generic/msp/idemix/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ package idemix
import (
"testing"

"github.com/stretchr/testify/assert"

api2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
"github.com/stretchr/testify/assert"
)

func TestIdentityCache(t *testing.T) {
c := NewIdentityCache(
func(opts *api2.IdentityOptions) (view.Identity, []byte, error) {
return []byte("hello world"), []byte("audit"), nil
},
100,
)
c := NewIdentityCache(func(opts *api2.IdentityOptions) (view.Identity, []byte, error) {
return []byte("hello world"), []byte("audit"), nil
}, 100, nil)
id, audit, err := c.Identity(&api2.IdentityOptions{
EIDExtension: true,
AuditInfo: nil,
Expand Down
5 changes: 2 additions & 3 deletions platform/fabric/core/generic/msp/idemix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"os"
"path/filepath"

"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/msp"

im "github.com/IBM/idemix/idemixmsp"
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/proto"
m "github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/msp"
"github.com/pkg/errors"
)

Expand Down
76 changes: 76 additions & 0 deletions platform/fabric/core/generic/msp/idemix/crypto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package idemix

import (
idemix "github.com/IBM/idemix/bccsp"
"github.com/IBM/idemix/bccsp/keystore"
idemix2 "github.com/IBM/idemix/bccsp/schemes/dlog/crypto"
"github.com/IBM/idemix/bccsp/schemes/dlog/crypto/translator/amcl"
bccsp "github.com/IBM/idemix/bccsp/types"
math "github.com/IBM/mathlib"
"github.com/pkg/errors"
)

// NewBCCSP returns an instance of the idemix BCCSP for the given curve
func NewBCCSP(curveID math.CurveID) (bccsp.BCCSP, error) {
curve, tr, err := GetCurveAndTranslator(curveID)
if err != nil {
return nil, err
}
cryptoProvider, err := idemix.New(&keystore.Dummy{}, curve, tr, true)
if err != nil {
return nil, errors.Wrap(err, "failed getting crypto provider")
}
return cryptoProvider, nil
}

// NewKSVBCCSP returns an instance of the idemix BCCSP for the given curve and kvsStore
func NewKSVBCCSP(kvsStore keystore.KVS, curveID math.CurveID, aries bool) (bccsp.BCCSP, error) {
curve, tr, err := GetCurveAndTranslator(curveID)
if err != nil {
return nil, err
}

keyStore := &keystore.KVSStore{
KVS: kvsStore,
Curve: curve,
Translator: tr,
}

var cryptoProvider bccsp.BCCSP
if aries {
cryptoProvider, err = idemix.NewAries(keyStore, curve, tr, true)
} else {
cryptoProvider, err = idemix.New(keyStore, curve, tr, true)
}
if err != nil {
return nil, errors.Wrap(err, "failed getting crypto provider")
}

return cryptoProvider, nil
}

func GetCurveAndTranslator(curveID math.CurveID) (*math.Curve, idemix2.Translator, error) {
curve := math.Curves[curveID]
var tr idemix2.Translator
switch curveID {
case math.BN254:
tr = &amcl.Gurvy{C: curve}
case math.BLS12_377_GURVY:
tr = &amcl.Gurvy{C: curve}
case math.FP256BN_AMCL:
tr = &amcl.Fp256bn{C: curve}
case math.FP256BN_AMCL_MIRACL:
tr = &amcl.Fp256bnMiracl{C: curve}
case math.BLS12_381_BBS:
tr = &amcl.Gurvy{C: curve}
default:
return nil, nil, errors.Errorf("unsupported curve ID: %d", curveID)
}
return curve, tr, nil
}
Loading

0 comments on commit 996dcf2

Please sign in to comment.