github.com/amazechain/amc@v0.1.3/cmd/evmsdk/blst.go (about) 1 // Copyright 2023 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The AmazeChain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package evmsdk 18 19 import ( 20 "encoding/hex" 21 22 "github.com/amazechain/amc/common/crypto/bls" 23 ) 24 25 func BlsSign(privKey, msg string) (interface{}, error) { 26 msgBytes, err := hex.DecodeString(msg) 27 if err != nil { 28 return nil, err 29 } 30 privKeyBytes, err := hex.DecodeString(privKey) 31 if err != nil { 32 return nil, err 33 } 34 arr := [32]byte{} 35 copy(arr[:], privKeyBytes[:]) 36 sk, err := bls.SecretKeyFromRandom32Byte(arr) 37 if err != nil { 38 return nil, err 39 } 40 resBytes := sk.Sign(msgBytes).Marshal() 41 return hex.EncodeToString(resBytes), nil 42 } 43 44 func BlsPublicKey(privKey string) (interface{}, error) { 45 privKeyBytes, err := hex.DecodeString(privKey) 46 if err != nil { 47 return nil, err 48 } 49 arr := [32]byte{} 50 copy(arr[:], privKeyBytes[:]) 51 sk, err := bls.SecretKeyFromRandom32Byte(arr) 52 if err != nil { 53 return nil, err 54 } 55 resBytes := sk.PublicKey().Marshal() 56 return hex.EncodeToString(resBytes), nil 57 }