arnaucube
arnaucube/blindsig-client-server-examplePublic Self-hosted repository
Loop-test send signature to server to be verified
arnaucube root@arnaucube.com
Thu, 11 Feb 2021 23:22:03 +0100
commit

7b32ec29fa08d6f685286327879f333825a2fba2

parent

4a63330a15a4fc8effd653ab253bf5bd8eae4da7

M client/loop-test/README.md → client/loop-test/README.md

@@ -4,5 +4,6 @@ - Install npm dependancies `npm install`

- Run the nodejs loop script: `node loop-test.js` - This will print on the screen the number of iterations each 100 iterations - And if there is an error verifying a signature, will print all the involved parameters + - signature verification is done on the JS side, but also sent to the server to verify it from the Go side
M client/loop-test/loop-test.js → client/loop-test/loop-test.js

@@ -52,6 +52,8 @@ async function verify() {

verified = blindsecp256k1.verify(m, sig, signerQ); if (!verified) { errCount++; + console.log("==verification failed on client==", res.data.verification); + printPoint("signerR", signerR); printPoint("signerQ", signerQ); console.log("m:", m.toString());

@@ -62,6 +64,55 @@ console.log("blinded sig:", blindedSig.toString());

console.log("sig.s:", sig.s.toString()); printPoint("sig.f", sig.f); console.log("verify", verified); + } + + // send to verify by the go server + let data = { + m: m.toString(), + sig: { + S: sig.s.toString(), + F: { + x: sig.f.affineX.toString(), + y: sig.f.affineY.toString() + } + }, + q: { + x: signerQ.affineX.toString(), + y: signerQ.affineY.toString() + } + }; + try { + let res = await axios.post(apiUrl+'/verify', data); + if (!res.data.verification) { + errCount++; + console.log("==verification failed on server==", res.data.verification); + + printPoint("signerR", signerR); + printPoint("signerQ", signerQ); + console.log("m:", m.toString()); + console.log("mBlinded:", mBlinded.toString()); + console.log(`userSecretData:\n a: ${userSecretData.a.toString()}\n b: ${userSecretData.b.toString()}`); + printPoint("userSecretData.f", userSecretData.f); + console.log("blinded sig:", blindedSig.toString()); + console.log("sig.s:", sig.s.toString()); + printPoint("sig.f", sig.f); + console.log("verify", verified); + } + } catch (error) { + console.error(error.response.data); + errCount++; + console.log("==verification failed on server==", error.response.data.verification); + + printPoint("signerR", signerR); + printPoint("signerQ", signerQ); + console.log("m:", m.toString()); + console.log("mBlinded:", mBlinded.toString()); + console.log(`userSecretData:\n a: ${userSecretData.a.toString()}\n b: ${userSecretData.b.toString()}`); + printPoint("userSecretData.f", userSecretData.f); + console.log("blinded sig:", blindedSig.toString()); + console.log("sig.s:", sig.s.toString()); + printPoint("sig.f", sig.f); + console.log("js verify", verified); } }
M client/loop-test/package-lock.json → client/loop-test/package-lock.json

@@ -45,9 +45,9 @@ "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-7.0.2.tgz",

"integrity": "sha512-TosM7Yg1Ux0ZCNwwS/tW95r3q9xIZstgsUGKWaez0Cgq8Oy3qia9RGvyG/fbxlQAvigjza1d057QNQLGvYXCeg==" }, "blindsecp256k1": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/blindsecp256k1/-/blindsecp256k1-0.0.5.tgz", - "integrity": "sha512-P+ahL3AlZY2RvtEUH7W3yidTNfDsu7yUsb2OOorEzsSE0cBovQKyBi+d883CVwbgjcW4mFFmHYgBZ0q+QOz9zQ==", + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/blindsecp256k1/-/blindsecp256k1-0.0.6.tgz", + "integrity": "sha512-M+QV0G6h5FIR0eqiRkW3DySMoDoobHkr8Zrcx1kLxuvbpZaBI5NL60LI3c600TaHz4TuEJB2C2BdDWsA6JYl4w==", "requires": { "@ethersproject/keccak256": "5.0.7", "bigi": "^1.4.2",
M client/loop-test/package.json → client/loop-test/package.json

@@ -10,6 +10,6 @@ "author": "arnaucube",

"license": "ISC", "dependencies": { "axios": "^0.21.1", - "blindsecp256k1": "0.0.5" + "blindsecp256k1": "0.0.6" } }
M client/loop.js → client/loop.js

@@ -64,6 +64,20 @@ printPoint("sig.f", sig.f);

console.log("verify", verified); alert("ERROR") } + // send to verify by the go server + let data = { + m: mBlinded.toString(), + sig: { + s: sig.s.toString(), + f: { + x: sig.f.affineX.toString(), + y: sig.f.affineY.toString() + } + } + }; + let res = await axios.post(apiUrl+'/blindsign', data); + console.log("res", res.data); + console.log("ver by server", res.data.verification); } async function iteration() {
M main.go → main.go

@@ -1,6 +1,7 @@

package main import ( + "fmt" "math/big" "net/http"

@@ -48,6 +49,36 @@ delete(secretRs, key)

c.JSON(http.StatusOK, gin.H{"sBlind": sBlind.String()}) } +type msgPostVerify struct { + M string `json:"m"` + Sig *blindsecp256k1.Signature `json:"sig"` + Q *blindsecp256k1.PublicKey `json:"q"` +} + +func postVerify(c *gin.Context) { + var msg msgPostVerify + c.BindJSON(&msg) + + m, ok := new(big.Int).SetString(msg.M, 10) + if !ok { + c.String(http.StatusBadRequest, "can not parse m") + return + } + fmt.Println(msg.Sig.S, msg.Sig.F) + v := blindsecp256k1.Verify(m, msg.Sig, sk.Public()) + fmt.Println("v", v) + if !v { + fmt.Println("m", m) + fmt.Println("sig.s", msg.Sig.S) + fmt.Println("sig.f", msg.Sig.F) + fmt.Println("pubk", sk.Public()) + fmt.Println("q", msg.Q) + c.JSON(http.StatusNotAcceptable, gin.H{"verification": false}) + return + } + c.JSON(http.StatusOK, gin.H{"verification": v}) +} + func main() { secretRs = make(map[string]*big.Int) sk = blindsecp256k1.NewPrivateKey()

@@ -56,6 +87,7 @@ r := gin.Default()

r.GET("/request", getNewRequest) r.POST("/blindsign", postBlindSign) + r.POST("/verify", postVerify) r.Static("/web", "./client") r.Run("127.0.0.1:3000")
A package-lock.json

@@ -0,0 +1,3 @@

+{ + "lockfileVersion": 1 +}