github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/requester/publicapi/utils.go (about) 1 package publicapi 2 3 import ( 4 "encoding/json" 5 "errors" 6 "fmt" 7 8 "github.com/filecoin-project/bacalhau/pkg/system" 9 ) 10 11 func verifyRequestSignature(msg json.RawMessage, clientSignature string, clientPubKey string) error { 12 err := system.Verify(msg, clientSignature, clientPubKey) 13 if err != nil { 14 return fmt.Errorf("client's signature is invalid: %w", err) 15 } 16 17 return nil 18 } 19 20 func verifySignedJobRequest(reqClientID string, clientSig string, clientPubKey string) error { 21 if reqClientID == "" { 22 return errors.New("job create payload must contain a client ID") 23 } 24 if clientSig == "" { 25 return errors.New("client's signature is required") 26 } 27 if clientPubKey == "" { 28 return errors.New("client's public key is required") 29 } 30 31 // Check that the client's public key matches the client ID: 32 ok, err := system.PublicKeyMatchesID(clientPubKey, reqClientID) 33 if err != nil { 34 return fmt.Errorf("error verifying client ID: %w", err) 35 } 36 if !ok { 37 return errors.New("client's public key does not match client ID") 38 } 39 return nil 40 }