github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/vm/risc0vm/risc0.go (about) 1 package risc0vm 2 3 import ( 4 "context" 5 "encoding/json" 6 "net/url" 7 8 "github.com/gorilla/websocket" 9 10 "github.com/machinefi/w3bstream/pkg/depends/kit/logr" 11 ) 12 13 func CreateProof(ctx context.Context, req *CreateProofReq, host string, path string) (*CreateProofRsp, error) { 14 params := make(map[string]interface{}) 15 16 ctx, l := logr.Start(ctx, "vm.risc0.CreateProof") 17 defer l.End() 18 19 params["private_input"] = req.PrivateInput 20 params["public_input"] = req.PublicInput 21 params["receipt_type"] = req.ReceiptType 22 params["image_id"] = req.ImageID 23 jsonParams, err := json.Marshal(params) 24 if err != nil { 25 l.Error(err) 26 return nil, err 27 } 28 29 url := url.URL{Scheme: "ws", Host: host, Path: path} 30 client, _, err := websocket.DefaultDialer.Dial(url.String(), nil) 31 defer client.Close() 32 33 if err != nil { 34 l.Error(err) 35 return nil, err 36 } 37 err = client.WriteMessage(websocket.TextMessage, jsonParams) 38 if err != nil { 39 l.Error(err) 40 return nil, err 41 } 42 43 _, message, err := client.ReadMessage() 44 if err != nil { 45 l.Error(err) 46 return nil, err 47 } 48 println(string(message)) 49 50 return &CreateProofRsp{ 51 Receipt: string(message), 52 }, nil 53 }