Browse Source

Add loop browser client test

master
arnaucube 3 years ago
parent
commit
4a63330a15
3 changed files with 105 additions and 1 deletions
  1. +1
    -1
      client/loop-test/loop-test.js
  2. +17
    -0
      client/loop.html
  3. +87
    -0
      client/loop.js

+ 1
- 1
client/loop-test/loop-test.js

@ -54,7 +54,7 @@ async function verify() {
errCount++; errCount++;
printPoint("signerR", signerR); printPoint("signerR", signerR);
printPoint("signerQ", signerQ); printPoint("signerQ", signerQ);
console.log("m:", m);
console.log("m:", m.toString());
console.log("mBlinded:", mBlinded.toString()); console.log("mBlinded:", mBlinded.toString());
console.log(`userSecretData:\n a: ${userSecretData.a.toString()}\n b: ${userSecretData.b.toString()}`); console.log(`userSecretData:\n a: ${userSecretData.a.toString()}\n b: ${userSecretData.b.toString()}`);
printPoint("userSecretData.f", userSecretData.f); printPoint("userSecretData.f", userSecretData.f);

+ 17
- 0
client/loop.html

@ -0,0 +1,17 @@
<html>
<head>
<meta charset="utf-8">
<title>blindsig-client-server-example</title>
</head>
<body>
<h3>loop-test browser version</h3>
<p>Open the console to see the logs (you may want to disable the 'Warnings' to avoid flooding the logs with innecessary messages)</p>
<button onClick="start();">start()</button>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="blindsecp256k1-browser.js"></script>
<script src="loop.js"></script>
</body>
</html>

+ 87
- 0
client/loop.js

@ -0,0 +1,87 @@
// This version uses https://github.com/arnaucube/blindsecp256k1-js
// const blindsecp256k1 = require('blindsecp256k1');
// const axios = require('axios');
let signerR, signerQ, m, mBlinded, userSecretData, blindedSig, sig, errCount, verified;
const apiUrl = "http://127.0.0.1:3000";
function printPoint(name, p) {
console.log(`${name}:\n x: ${p.affineX.toString()}\n y: ${p.affineY.toString()}`);
}
async function newRequest() {
try {
const res = await axios.get(apiUrl+'/request');
signerR = blindsecp256k1.Point.fromAffine(blindsecp256k1.ecparams,
blindsecp256k1.newBigFromString(res.data.signerR.x),
blindsecp256k1.newBigFromString(res.data.signerR.y));
signerQ = blindsecp256k1.Point.fromAffine(blindsecp256k1.ecparams,
blindsecp256k1.newBigFromString(res.data.signerQ.x),
blindsecp256k1.newBigFromString(res.data.signerQ.y));
let blindRes = blindsecp256k1.blind(m, signerR);
mBlinded = blindRes.mBlinded;
userSecretData = blindRes.userSecretData;
} catch (error) {
console.error(error);
}
}
async function askBlindSign() {
try {
let data = {
m: mBlinded.toString(),
r: {
x: signerR.affineX.toString(),
y: signerR.affineY.toString()
}
};
let res = await axios.post(apiUrl+'/blindsign', data);
blindedSig = blindsecp256k1.newBigFromString(res.data.sBlind);
sig = blindsecp256k1.unblind(
blindedSig,
userSecretData);
} catch (error) {
console.error(error);
}
}
async function verify() {
verified = blindsecp256k1.verify(m, sig, signerQ);
if (!verified) {
errCount++;
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);
alert("ERROR")
}
}
async function iteration() {
await newRequest()
await askBlindSign()
await verify()
}
async function start() {
errCount = 0;
for (let i=0; i<10000; i++) {
m = blindsecp256k1.newKeyPair().sk;
await iteration()
if (i%100 ==0) {
console.log("number of iterations", i);
}
}
console.log("errCount", errCount);
}

Loading…
Cancel
Save