blindsecp256k1-js/test/index.test.ts
test/index.test.tsRaw
1import * as assert from 'assert'
2import * as BigInteger from 'bigi'
3// import { Point } from 'ecurve'
4import { keccak256 } from "@ethersproject/keccak256"
5
6import { newBigFromString, ecparams, newKeyPair, newRequestParameters, blind, blindSign, unblind, verify } from "../src/index"
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.strictEqual('0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658', hHex)
14 const h = BigInteger.fromHex(hHex.slice(2))
15 assert.strictEqual('70622639689279718371527342103894932928233838121221666359043189029713682937432', h.toString())
16 })
17})
18
19describe("test blind", function () {
20 it("should 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.strictEqual('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(verified)
38 })
39})