github.com/0chain/gosdk@v1.17.11/core/zcncrypto/bls0chain_wasm.go (about) 1 //go:build js && wasm 2 // +build js,wasm 3 4 package zcncrypto 5 6 import ( 7 "encoding/hex" 8 9 "github.com/0chain/errors" 10 ) 11 12 var ( 13 Sign func(hash string) (string, error) 14 ) 15 16 // WasmScheme - a signature scheme for BLS0Chain Signature 17 type WasmScheme struct { 18 PublicKey string `json:"public_key"` 19 PrivateKey string `json:"private_key"` 20 Mnemonic string `json:"mnemonic"` 21 22 id ID 23 Ids string `json:"threshold_scheme_id"` 24 } 25 26 // NewWasmScheme - create a BLS0ChainScheme object 27 func NewWasmScheme() *WasmScheme { 28 return &WasmScheme{} 29 } 30 31 func (b0 *WasmScheme) GenerateKeysWithEth(mnemonic, password string) (*Wallet, error) { 32 return nil, errors.New("wasm_not_support", "please generate keys by bls_wasm in js") 33 } 34 35 // GenerateKeys - implement interface 36 func (b0 *WasmScheme) GenerateKeys() (*Wallet, error) { 37 return nil, errors.New("wasm_not_support", "please generate keys by bls_wasm in js") 38 } 39 40 func (b0 *WasmScheme) RecoverKeys(mnemonic string) (*Wallet, error) { 41 return nil, errors.New("wasm_not_support", "please recover keys by bls_wasm in js") 42 } 43 44 func (b0 *WasmScheme) GetMnemonic() string { 45 return "" 46 } 47 48 // SetPrivateKey - implement interface 49 func (b0 *WasmScheme) SetPrivateKey(privateKey string) error { 50 return errors.New("wasm_not_support", "please set keys by bls_wasm in js") 51 } 52 53 // SetPublicKey - implement interface 54 func (b0 *WasmScheme) SetPublicKey(publicKey string) error { 55 return errors.New("wasm_not_support", "please set keys by bls_wasm in js") 56 } 57 58 // GetPublicKey - implement interface 59 func (b0 *WasmScheme) GetPublicKey() string { 60 return "please get key in js" 61 } 62 63 func (b0 *WasmScheme) GetPrivateKey() string { 64 return "please get key in js" 65 } 66 67 // Sign - implement interface 68 func (b0 *WasmScheme) Sign(hash string) (string, error) { 69 rawHash, err := hex.DecodeString(hash) 70 if err != nil { 71 return "", err 72 } 73 74 if Sign != nil { 75 return Sign(string(rawHash)) 76 } 77 78 return "", errors.New("wasm_not_initialized", "please init wasm sdk first") 79 } 80 81 // Verify - implement interface 82 func (b0 *WasmScheme) Verify(signature, msg string) (bool, error) { 83 return false, errors.New("wasm_not_support", "please verify signature by bls_wasm in js") 84 } 85 86 func (b0 *WasmScheme) Add(signature, msg string) (string, error) { 87 88 return "", errors.New("wasm_not_support", "aggregate signature is not supported on wasm sdk") 89 } 90 91 // SetID sets ID in HexString format 92 func (b0 *WasmScheme) SetID(id string) error { 93 return errors.New("wasm_not_support", "setid is not supported on wasm sdk") 94 } 95 96 // GetID gets ID in hex string format 97 func (b0 *WasmScheme) GetID() string { 98 return "" 99 } 100 101 // GetPrivateKeyAsByteArray - converts private key into byte array 102 func (b0 *WasmScheme) GetPrivateKeyAsByteArray() ([]byte, error) { 103 return nil, errors.New("wasm_not_support", "please get keys by bls_wasm in js") 104 105 } 106 107 func (b0 *WasmScheme) SplitKeys(numSplits int) (*Wallet, error) { 108 return nil, errors.New("wasm_not_support", "splitkeys is not supported on wasm sdk") 109 }