package mutations import ( "crypto/sha256" "encoding/hex" "fmt" "math/big" "github.com/pkg/errors" "git.lehouerou.net/laurent/sorare/starkware" ) type MangopayWalletTransfer struct { Amount int `graphql:"amount"` Currency string `graphql:"currency"` MangopayWalletId string `graphql:"mangopayWalletId"` Nonce int `graphql:"nonce"` OperationHash string `graphql:"operationHash"` } func (t MangopayWalletTransfer) hash() (string, error) { message := fmt.Sprintf( "%s:%s:%s:%d:%d", t.MangopayWalletId, t.OperationHash, t.Currency, t.Amount, t.Nonce, ) return hashMessage(message) } func hashMessage( message string) (string, error) { if message == "" { return "", errors.New("message cannot be empty") } h := sha256.Sum256([]byte(message)) hexH := hex.EncodeToString(h[:]) if len(hexH) < 64 { return "", errors.New("invalid hash length") } hexH1Bn, ok := big.NewInt(0).SetString(hexH[:32], 16) if !ok { return "", errors.New("invalid hexH1") } hexH2Bn, ok := big.NewInt(0).SetString(hexH[32:], 16) if !ok { return "", errors.New("invalid hexH2") } return starkware.PedersenHash(hexH1Bn.String(), hexH2Bn.String()), nil }