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.

50 lines
1.8 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, importPointFromHex, 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. })
  31. describe('import point from hex', function () {
  32. it('', async () => {
  33. // pointHex and expected values was generated from
  34. // go-blindsecp256k1 (Point.Bytes())
  35. const pointHex = '73a68e845e626a2d7f683dd2ceb57956f755d623c0b729af30a72c7bf4dee7a6932d08955c98cf21edf35f5df218b56c41014db06f513cecc85dc3d8671f9521'
  36. const p = importPointFromHex(pointHex)
  37. assert.strictEqual('75493613315673782629634797792529672610524641864826422940379513836118869976691', p.x.toString())
  38. assert.strictEqual('15189800969738851359449622716277258420468338317311652509571160848111971610003', p.y.toString())
  39. })
  40. })