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.

48 lines
1.1 KiB

  1. import * as assert from 'assert'
  2. import {
  3. bigNumberFromString,
  4. ecParams,
  5. newKeyPair,
  6. newRequestParameters,
  7. blind,
  8. blindSign,
  9. unblind,
  10. verify,
  11. hashBigNumber,
  12. Point,
  13. BigNumber
  14. } from "../src/index"
  15. describe("keccak256", function () {
  16. it("keccak256", async () => {
  17. const msg = Buffer.from("test", 'utf8')
  18. const m = new BigNumber(msg)
  19. const hHex = hashBigNumber(m)
  20. assert.strictEqual(hHex, '9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658')
  21. const h = new BigNumber(Buffer.from(hHex, "hex"))
  22. assert.strictEqual(h.toString(), '70622639689279718371527342103894932928233838121221666359043189029713682937432')
  23. })
  24. })
  25. describe("test blind", function () {
  26. it("should blind", async () => {
  27. const { sk, pk } = newKeyPair()
  28. const { k, signerR } = newRequestParameters()
  29. const msg = new BigNumber(
  30. Buffer.from("test", 'utf8')
  31. )
  32. assert.strictEqual('1952805748', msg.toString())
  33. const { mBlinded, userSecretData } = blind(msg, signerR)
  34. const sBlind = blindSign(sk, mBlinded, k)
  35. const sig = unblind(sBlind, userSecretData)
  36. const verified = verify(msg, sig, pk)
  37. assert(verified)
  38. })
  39. })