github.com/klaytn/klaytn@v1.12.1/crypto/bls/types/bls_types.go (about) 1 // Copyright 2023 The klaytn Authors 2 // This file is part of the klaytn library. 3 // 4 // The klaytn 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 klaytn 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 klaytn library. If not, see <http://www.gnu.org/licenses/>. 16 17 package types 18 19 import ( 20 "errors" 21 "fmt" 22 ) 23 24 var ( 25 // For immediate clarity, using literal numbers instead of blst named constants 26 SecretKeyLength = 32 27 PublicKeyLength = 48 28 SignatureLength = 96 29 // draft-irtf-cfrg-pairing-friendly-curves-11#4.2.1 BLS12_381 30 CurveOrderHex = "0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001" 31 // draft-irtf-cfrg-bls-signature-05#4.2.3 32 DomainSeparationTagSig = []byte("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") 33 DomainSeparationTagPop = []byte("BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") 34 ) 35 36 var ( 37 ErrSecretKeyGen = errors.New("BLS secret keygen failed") 38 ErrSecretKeyUnmarshal = errors.New("BLS secret key unmarshal failed") 39 ErrPublicKeyUnmarshal = errors.New("BLS public key unmarshal failed") 40 ErrPublicKeyAggregate = errors.New("BLS public key aggregation failed") 41 ErrSignatureUnmarshal = errors.New("BLS signature unmarshal failed") 42 ErrSignatureAggregate = errors.New("BLS signature aggregation failed") 43 ErrEmptyArray = errors.New("BLS aggregation failed due to empty array") 44 ) 45 46 func ErrSecretKeyLength(have int) error { 47 return fmt.Errorf("BLS secret key length mismatch: want: %d have: %d", SecretKeyLength, have) 48 } 49 50 func ErrPublicKeyLength(have int) error { 51 return fmt.Errorf("BLS public key length mismatch: want: %d have: %d", PublicKeyLength, have) 52 } 53 54 func ErrSignatureLength(have int) error { 55 return fmt.Errorf("BLS signature length mismatch: want: %d have: %d", SignatureLength, have) 56 } 57 58 type SecretKey interface { 59 PublicKey() PublicKey 60 Marshal() []byte 61 } 62 63 type PublicKey interface { 64 Marshal() []byte 65 Copy() PublicKey 66 } 67 68 type Signature interface { 69 Marshal() []byte 70 Copy() Signature 71 }