本文整理匯總了Golang中github.com/hyperledger/fabric/core/crypto.CertificateHandler.Sign方法的典型用法代碼示例。如果您正苦於以下問題:Golang CertificateHandler.Sign方法的具體用法?Golang CertificateHandler.Sign怎麽用?Golang CertificateHandler.Sign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hyperledger/fabric/core/crypto.CertificateHandler
的用法示例。
在下文中一共展示了CertificateHandler.Sign方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: transferOwnership
func transferOwnership(owner crypto.Client, ownerCert crypto.CertificateHandler, asset string, newOwnerCert crypto.CertificateHandler) error {
// Get a transaction handler to be used to submit the execute transaction
// and bind the chaincode access control logic using the binding
submittingCertHandler, err := owner.GetTCertificateHandlerNext()
if err != nil {
return err
}
txHandler, err := submittingCertHandler.GetTransactionHandler()
if err != nil {
return err
}
binding, err := txHandler.GetBinding()
if err != nil {
return err
}
chaincodeInput := &pb.ChaincodeInput{Function: "transfer", Args: []string{asset, string(newOwnerCert.GetCertificate())}}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
return err
}
// Access control. Owner signs chaincodeInputRaw || binding to confirm his identity
sigma, err := ownerCert.Sign(append(chaincodeInputRaw, binding...))
if err != nil {
return err
}
// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: chaincodeInput,
Metadata: sigma, // Proof of identity
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
var ctx = context.Background()
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
tid := chaincodeInvocationSpec.ChaincodeSpec.ChaincodeID.Name
// Now create the Transactions message and send to Peer.
transaction, err := txHandler.NewChaincodeExecute(chaincodeInvocationSpec, tid)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s ", err)
}
ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
_, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s", err)
}
ledger.CommitTxBatch("1", []*pb.Transaction{transaction}, nil, nil)
return err
}
示例2: transferOwnershipInternal
func transferOwnershipInternal(owner crypto.Client, ownerCert crypto.CertificateHandler, asset string, newOwnerCert crypto.CertificateHandler) (resp *pb.Response, err error) {
// Get a transaction handler to be used to submit the execute transaction
// and bind the chaincode access control logic using the binding
submittingCertHandler, err := owner.GetTCertificateHandlerNext()
if err != nil {
return nil, err
}
txHandler, err := submittingCertHandler.GetTransactionHandler()
if err != nil {
return nil, err
}
binding, err := txHandler.GetBinding()
if err != nil {
return nil, err
}
chaincodeInput := &pb.ChaincodeInput{
Function: "transfer",
Args: []string{asset, base64.StdEncoding.EncodeToString(newOwnerCert.GetCertificate())},
}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
return nil, err
}
// Access control. Owner signs chaincodeInputRaw || binding to confirm his identity
sigma, err := ownerCert.Sign(append(chaincodeInputRaw, binding...))
if err != nil {
return nil, err
}
// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: chaincodeName},
CtorMsg: chaincodeInput,
Metadata: sigma, // Proof of identity
ConfidentialityLevel: confidentialityLevel,
}
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
// Now create the Transactions message and send to Peer.
transaction, err := txHandler.NewChaincodeExecute(chaincodeInvocationSpec, util.GenerateUUID())
if err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s ", err)
}
return processTransaction(transaction)
}
示例3: read
func read(invoker crypto.Client, invokerCert crypto.CertificateHandler) ([]byte, error) {
// Get a transaction handler to be used to submit the query transaction
// and bind the chaincode access control logic using the binding
submittingCertHandler, err := invoker.GetTCertificateHandlerNext()
if err != nil {
return nil, err
}
txHandler, err := submittingCertHandler.GetTransactionHandler()
if err != nil {
return nil, err
}
binding, err := txHandler.GetBinding()
if err != nil {
return nil, err
}
chaincodeInput := &pb.ChaincodeInput{Args: util.ToChaincodeArgs("read")}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
return nil, err
}
// Access control:
// invokerCert signs invokerCert.GetCertificate() || chaincodeInputRaw || binding to confirm his identity
sigma, err := invokerCert.Sign(append(invokerCert.GetCertificate(), append(chaincodeInputRaw, binding...)...))
if err != nil {
return nil, err
}
rbacMetadata := RBACMetadata{invokerCert.GetCertificate(), sigma}
rbacMetadataRaw, err := asn1.Marshal(rbacMetadata)
if err != nil {
return nil, err
}
// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: chaincodeInput,
Metadata: rbacMetadataRaw,
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
var ctx = context.Background()
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
tid := chaincodeInvocationSpec.ChaincodeSpec.ChaincodeID.Name
// Now create the Transactions message and send to Peer.
transaction, err := txHandler.NewChaincodeQuery(chaincodeInvocationSpec, tid)
if err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s ", err)
}
ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
result, _, err := chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return nil, fmt.Errorf("Error deploying chaincode: %s", err)
}
ledger.CommitTxBatch("1", []*pb.Transaction{transaction}, nil, nil)
return result, err
}
示例4: addRole
func addRole(admCert crypto.CertificateHandler, idCert crypto.CertificateHandler, role string) error {
// Get a transaction handler to be used to submit the execute transaction
// and bind the chaincode access control logic using the binding
submittingCertHandler, err := administrator.GetTCertificateHandlerNext()
if err != nil {
return err
}
txHandler, err := submittingCertHandler.GetTransactionHandler()
if err != nil {
return err
}
binding, err := txHandler.GetBinding()
if err != nil {
return err
}
chaincodeInput := &pb.ChaincodeInput{Function: "addRole", Args: []string{string(idCert.GetCertificate()), role}}
chaincodeInputRaw, err := proto.Marshal(chaincodeInput)
if err != nil {
return err
}
// Access control:
// admCert signs admCert.GetCertificate() || chaincodeInputRaw || binding to confirm his identity
sigma, err := admCert.Sign(append(admCert.GetCertificate(), append(chaincodeInputRaw, binding...)...))
if err != nil {
return err
}
rbacMetadata := RBACMetadata{admCert.GetCertificate(), sigma}
rbacMetadataRaw, err := asn1.Marshal(rbacMetadata)
if err != nil {
return err
}
// Prepare spec and submit
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeID: &pb.ChaincodeID{Name: "mycc"},
CtorMsg: chaincodeInput,
Metadata: rbacMetadataRaw, // Proof of identity
ConfidentialityLevel: pb.ConfidentialityLevel_PUBLIC,
}
var ctx = context.Background()
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
tid := chaincodeInvocationSpec.ChaincodeSpec.ChaincodeID.Name
// Now create the Transactions message and send to Peer.
transaction, err := txHandler.NewChaincodeExecute(chaincodeInvocationSpec, tid)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s ", err)
}
ledger, err := ledger.GetLedger()
ledger.BeginTxBatch("1")
_, err = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return fmt.Errorf("Error deploying chaincode: %s", err)
}
ledger.CommitTxBatch("1", []*pb.Transaction{transaction}, nil, nil)
return err
}