code.vegaprotocol.io/vega@v0.79.0/commands/is_vega_pubkey.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package commands 17 18 import ( 19 "encoding/hex" 20 "errors" 21 ) 22 23 const ( 24 vegaPublicKeyLen = 64 25 vegaIDLen = 64 26 ) 27 28 var ( 29 ErrShouldBeAValidVegaPublicKey = errors.New("should be a valid vega public key") 30 ErrShouldBeAValidVegaID = errors.New("should be a valid Vega ID") 31 ) 32 33 // IsVegaPublicKey check if a string is a valid Vega public key. 34 // A public key is a string of 64 characters containing only hexadecimal characters. 35 // Despite being similar to the function IsVegaID, the Vega ID and public 36 // key are different concept that generated, and used differently. 37 func IsVegaPublicKey(key string) bool { 38 _, err := hex.DecodeString(key) 39 return len(key) == vegaPublicKeyLen && err == nil 40 } 41 42 // IsVegaID check if a string is a valid Vega public key. 43 // An ID is a string of 64 characters containing only hexadecimal characters. 44 // Despite being similar to the function IsVegaPublicKey, the Vega ID and public 45 // key are different concept that generated, and used differently. 46 func IsVegaID(id string) bool { 47 _, err := hex.DecodeString(id) 48 return len(id) == vegaIDLen && err == nil 49 }