diff --git a/backend/routes/templates.go b/backend/routes/templates.go index 0cf004a4..48c1f4a1 100644 --- a/backend/routes/templates.go +++ b/backend/routes/templates.go @@ -5,11 +5,13 @@ import ( "fmt" "io" "io/ioutil" - "math/rand" "net/http" "os" "os/exec" + "github.com/NethermindEth/juno/core/crypto" + "github.com/NethermindEth/juno/core/felt" + "art-peace-backend/backend" ) @@ -21,10 +23,14 @@ func InitTemplateRoutes() { // TODO: Add specific location for template images -func hashTemplateImage(imageData []byte) string { - // TODO: Use poseidon hash to hash image data and return hash - // Make sure the hash matches the hash generated by the contract - return "hash" + string(rand.Intn(1000000)) +func hashTemplateImage(pixelData []byte) string { + var data[]*felt.Felt + for _, pixel := range pixelData { + f := new(felt.Felt).SetUint64(uint64(pixel)) + data = append(data, f) + } + hash := crypto.PoseidonArray(data...) + return hash.String() } func imageToPixelData(imageData []byte) []byte {