github.com/trustbloc/kms-go@v1.1.2/crypto/tinkcrypto/primitive/bbs/bbs_key_template.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package bbs
     8  
     9  import (
    10  	"github.com/golang/protobuf/proto"
    11  	commonpb "github.com/google/tink/go/proto/common_go_proto"
    12  	tinkpb "github.com/google/tink/go/proto/tink_go_proto"
    13  
    14  	bbspb "github.com/trustbloc/kms-go/crypto/tinkcrypto/primitive/proto/bbs_go_proto"
    15  )
    16  
    17  // BLS12381G2KeyTemplate creates a Tink key template for BBS+ on BLS12-381 curve with G2 group.
    18  func BLS12381G2KeyTemplate() *tinkpb.KeyTemplate {
    19  	return createKeyTemplate(bbspb.BBSCurveType_BLS12_381, bbspb.GroupField_G2, commonpb.HashType_SHA256)
    20  }
    21  
    22  // createKeyTemplate for BBS+ keys.
    23  func createKeyTemplate(curve bbspb.BBSCurveType, group bbspb.GroupField, hash commonpb.HashType) *tinkpb.KeyTemplate {
    24  	format := &bbspb.BBSKeyFormat{
    25  		Params: &bbspb.BBSParams{
    26  			HashType: hash,
    27  			Curve:    curve,
    28  			Group:    group,
    29  		},
    30  	}
    31  
    32  	serializedFormat, err := proto.Marshal(format)
    33  	if err != nil {
    34  		panic("failed to marshal BBSKeyFormat proto")
    35  	}
    36  
    37  	return &tinkpb.KeyTemplate{
    38  		TypeUrl:          bbsSignerKeyTypeURL,
    39  		Value:            serializedFormat,
    40  		OutputPrefixType: tinkpb.OutputPrefixType_RAW,
    41  	}
    42  }