blindsecp256k1-js/test/index.test.js
test/index.test.jsRaw
1const assert = require('assert');
2const BigInteger = require('bigi');
3var {Point} = require('ecurve')
4const {keccak256} = require("@ethersproject/keccak256");
5
6const {newBigFromString, ecparams, newKeyPair, newRequestParameters, blind, blindSign, unblind, verify} = require("../src/index.js");
7
8describe("keccak256", function () {
9 it("keccak256", async () => {
10 const m = BigInteger.fromBuffer(Buffer.from("test", 'utf8'));
11 const mHex = m.toString(16);
12 const hHex = keccak256('0x' + mHex);
13 assert.equal('0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658', hHex);
14 const h = BigInteger.fromHex(hHex.slice(2));
15 assert.equal('70622639689279718371527342103894932928233838121221666359043189029713682937432', h.toString());
16 });
17});
18
19describe("test blind", function () {
20 it("blind", async () => {
21 const {sk, pk} = newKeyPair();
22
23 const {k, signerR} = newRequestParameters();
24
25 const msg = BigInteger.fromBuffer(
26 Buffer.from("test", 'utf8')
27 );
28 assert.equal('1952805748', msg.toString());
29
30 const {mBlinded, userSecretData} = blind(msg, signerR);
31
32 const sBlind = blindSign(sk, mBlinded, k);
33
34 const sig = unblind(sBlind, userSecretData);
35
36 const verified = verify(msg, sig, pk);
37 assert.equal(true, verified);
38 });
39});