You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB

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