|
@ -2,6 +2,7 @@ package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
|
|
|
"math/big" |
|
|
"syscall/js" |
|
|
"syscall/js" |
|
|
|
|
|
|
|
|
"github.com/arnaucube/go-snark" |
|
|
"github.com/arnaucube/go-snark" |
|
@ -11,15 +12,14 @@ import ( |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
c := make(chan struct{}, 0) |
|
|
c := make(chan struct{}, 0) |
|
|
|
|
|
|
|
|
println("WASM Go Initialized") |
|
|
println("WASM Go Initialized") |
|
|
// register functions
|
|
|
|
|
|
registerCallbacks() |
|
|
registerCallbacks() |
|
|
<-c |
|
|
<-c |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func registerCallbacks() { |
|
|
func registerCallbacks() { |
|
|
js.Global().Set("generateProofs", js.FuncOf(generateProofs)) |
|
|
js.Global().Set("generateProofs", js.FuncOf(generateProofs)) |
|
|
|
|
|
js.Global().Set("verifyProofs", js.FuncOf(verifyProofs)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func generateProofs(this js.Value, i []js.Value) interface{} { |
|
|
func generateProofs(this js.Value, i []js.Value) interface{} { |
|
@ -89,3 +89,56 @@ func generateProofs(this js.Value, i []js.Value) interface{} { |
|
|
println("proofJson", string(proofJson)) |
|
|
println("proofJson", string(proofJson)) |
|
|
return js.ValueOf(string(proofJson)) |
|
|
return js.ValueOf(string(proofJson)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func verifyProofs(this js.Value, i []js.Value) interface{} { |
|
|
|
|
|
var circuitStr utils.CircuitString |
|
|
|
|
|
err := json.Unmarshal([]byte(i[0].String()), &circuitStr) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println(i[0].String()) |
|
|
|
|
|
println("error parsing circuit from stringified json") |
|
|
|
|
|
} |
|
|
|
|
|
circuit, err := utils.CircuitFromString(circuitStr) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println("error " + err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var setupStr utils.SetupString |
|
|
|
|
|
println(i[1].String()) |
|
|
|
|
|
err = json.Unmarshal([]byte(i[1].String()), &setupStr) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println("error parsing setup from stringified json") |
|
|
|
|
|
} |
|
|
|
|
|
setup, err := utils.SetupFromString(setupStr) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println("error " + err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var proofStr utils.ProofString |
|
|
|
|
|
err = json.Unmarshal([]byte(i[2].String()), &proofStr) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println(i[0].String()) |
|
|
|
|
|
println("error parsing proof from stringified json") |
|
|
|
|
|
} |
|
|
|
|
|
proof, err := utils.ProofFromString(proofStr) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println("error " + err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var publicInputs []*big.Int |
|
|
|
|
|
err = json.Unmarshal([]byte(i[3].String()), &publicInputs) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println(i[0].String()) |
|
|
|
|
|
println("error parsing publicInputs from stringified json") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
verified := snark.VerifyProof(circuit, setup, proof, publicInputs, false) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println("error verifiyng proof", err) |
|
|
|
|
|
} |
|
|
|
|
|
verifiedJson, err := json.Marshal(verified) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
println("error marshal verified to json", err) |
|
|
|
|
|
} |
|
|
|
|
|
println("verifiedJson", string(verifiedJson)) |
|
|
|
|
|
return js.ValueOf(string(verifiedJson)) |
|
|
|
|
|
} |