github.com/hyperledger/aries-framework-go@v0.3.2/test/bbs/src/support_signer.go (about)

     1  // +build js,wasm
     2  
     3  /*
     4  Copyright SecureKey Technologies Inc. All Rights Reserved.
     5  
     6  SPDX-License-Identifier: Apache-2.0
     7  */
     8  
     9  package main
    10  
    11  import (
    12  	"strings"
    13  
    14  	bbs "github.com/hyperledger/aries-framework-go/pkg/crypto/primitive/bbs12381g2pub"
    15  )
    16  
    17  type bbsSigner struct {
    18  	privKeyBytes []byte
    19  }
    20  
    21  func newBBSSigner(privKey *bbs.PrivateKey) (*bbsSigner, error) {
    22  	privKeyBytes, err := privKey.Marshal()
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  
    27  	return &bbsSigner{privKeyBytes: privKeyBytes}, nil
    28  }
    29  
    30  func (s *bbsSigner) Sign(data []byte) ([]byte, error) {
    31  	msgs := s.textToLines(string(data))
    32  
    33  	return bbs.New().Sign(msgs, s.privKeyBytes)
    34  }
    35  
    36  func (s *bbsSigner) Alg() string {
    37  	return "Bls12381G2Key2020"
    38  }
    39  
    40  func (s *bbsSigner) textToLines(txt string) [][]byte {
    41  	lines := strings.Split(txt, "\n")
    42  	linesBytes := make([][]byte, 0, len(lines))
    43  
    44  	for i := range lines {
    45  		if strings.TrimSpace(lines[i]) != "" {
    46  			linesBytes = append(linesBytes, []byte(lines[i]))
    47  		}
    48  	}
    49  
    50  	return linesBytes
    51  }