From fd1e7da206713810cd8bc2e4747f03270095e263 Mon Sep 17 00:00:00 2001 From: tekkac Date: Fri, 12 Apr 2024 16:49:54 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20pixel=20data=20hashing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/routes/templates.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 {