1 Star 0 Fork 0

妥協/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
nymsigner.go 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
Angelo De Caro 提交于 2018-04-27 11:11 . [FAB-9526] Idemix BCCSP
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package handlers
import (
"github.com/hyperledger/fabric/bccsp"
"github.com/pkg/errors"
)
type NymSigner struct {
NymSignatureScheme NymSignatureScheme
}
func (s *NymSigner) Sign(k bccsp.Key, digest []byte, opts bccsp.SignerOpts) ([]byte, error) {
userSecretKey, ok := k.(*userSecretKey)
if !ok {
return nil, errors.New("invalid key, expected *userSecretKey")
}
signerOpts, ok := opts.(*bccsp.IdemixNymSignerOpts)
if !ok {
return nil, errors.New("invalid options, expected *IdemixNymSignerOpts")
}
// Issuer public key
if signerOpts.IssuerPK == nil {
return nil, errors.New("invalid options, missing issuer public key")
}
ipk, ok := signerOpts.IssuerPK.(*issuerPublicKey)
if !ok {
return nil, errors.New("invalid issuer public key, expected *issuerPublicKey")
}
// Nym
if signerOpts.Nym == nil {
return nil, errors.New("invalid options, missing nym key")
}
nymSk, ok := signerOpts.Nym.(*nymSecretKey)
if !ok {
return nil, errors.New("invalid nym key, expected *nymSecretKey")
}
sigma, err := s.NymSignatureScheme.Sign(
userSecretKey.sk,
nymSk.pk, nymSk.sk,
ipk.pk,
digest)
if err != nil {
return nil, err
}
return sigma, nil
}
type NymVerifier struct {
NymSignatureScheme NymSignatureScheme
}
func (v *NymVerifier) Verify(k bccsp.Key, signature, digest []byte, opts bccsp.SignerOpts) (bool, error) {
nymPublicKey, ok := k.(*nymPublicKey)
if !ok {
return false, errors.New("invalid key, expected *nymPublicKey")
}
signerOpts, ok := opts.(*bccsp.IdemixNymSignerOpts)
if !ok {
return false, errors.New("invalid options, expected *IdemixNymSignerOpts")
}
if signerOpts.IssuerPK == nil {
return false, errors.New("invalid options, missing issuer public key")
}
ipk, ok := signerOpts.IssuerPK.(*issuerPublicKey)
if !ok {
return false, errors.New("invalid issuer public key, expected *issuerPublicKey")
}
if len(signature) == 0 {
return false, errors.New("invalid signature, it must not be empty")
}
err := v.NymSignatureScheme.Verify(
ipk.pk,
nymPublicKey.pk,
signature,
digest)
if err != nil {
return false, err
}
return true, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liurenhao/fabric.git
git@gitee.com:liurenhao/fabric.git
liurenhao
fabric
fabric
v2.0.1

搜索帮助