forked from hyperledger-labs/fabric-smart-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Angelo De Caro <angelo.decaro@gmail.com> Signed-off-by: Alessandro Sorniotti <aso@zurich.ibm.com>
- Loading branch information
Showing
15 changed files
with
358 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.