Skip to content

Commit

Permalink
✨ add pixel data hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkac committed Apr 12, 2024
1 parent 9110859 commit fd1e7da
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions backend/routes/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down

0 comments on commit fd1e7da

Please sign in to comment.