github.com/0chain/gosdk@v1.17.11/core/zcncrypto/factory_wasm.go (about)

     1  //go:build js && wasm
     2  // +build js,wasm
     3  
     4  package zcncrypto
     5  
     6  import (
     7  	"encoding/json"
     8  	"fmt"
     9  
    10  	"github.com/0chain/errors"
    11  )
    12  
    13  // NewSignatureScheme creates an instance for using signature functions
    14  func NewSignatureScheme(sigScheme string) SignatureScheme {
    15  	switch sigScheme {
    16  	case "ed25519":
    17  		return NewED255190chainScheme()
    18  	case "bls0chain":
    19  		return NewWasmScheme()
    20  	default:
    21  		panic(fmt.Sprintf("unknown signature scheme: %v", sigScheme))
    22  	}
    23  }
    24  
    25  // UnmarshalSignatureSchemes unmarshal SignatureScheme from json string
    26  func UnmarshalSignatureSchemes(sigScheme string, obj interface{}) ([]SignatureScheme, error) {
    27  	switch sigScheme {
    28  
    29  	case "bls0chain":
    30  
    31  		if obj == nil {
    32  			return nil, nil
    33  		}
    34  
    35  		buf, err := json.Marshal(obj)
    36  		if err != nil {
    37  			return nil, err
    38  		}
    39  
    40  		var list []*WasmScheme
    41  
    42  		if err := json.Unmarshal(buf, &list); err != nil {
    43  			return nil, err
    44  		}
    45  
    46  		ss := make([]SignatureScheme, len(list))
    47  
    48  		for i, v := range list {
    49  			// bls.ID from json
    50  			v.SetID(v.Ids)
    51  			ss[i] = v
    52  		}
    53  
    54  		return ss, nil
    55  
    56  	default:
    57  		panic(fmt.Sprintf("unknown signature scheme: %v", sigScheme))
    58  	}
    59  }
    60  
    61  //GenerateThresholdKeyShares given a signature scheme will generate threshold sig keys
    62  func GenerateThresholdKeyShares(t, n int, originalKey SignatureScheme) ([]SignatureScheme, error) {
    63  
    64  	return nil, errors.New("wasm_not_supported", "GenerateThresholdKeyShares")
    65  }