import chai from 'chai' import { solidity } from 'ethereum-waffle' import { BigNumber } from 'ethers' import { Primitives } from 'lib/crypto' chai.use(solidity) const expect = chai.expect describe('crypto', () => { describe('namespace Crypto', () => { describe('namespace Primitives', () => { it('createDeposit', () => { const deposit = Primitives.createDeposit() // @ts-ignore const limit = BigNumber.from(2).pow(248).sub(1) expect(deposit.nullifier).to.exist expect(deposit.secret).to.exist expect(deposit.preimage).to.exist expect(deposit.commitment).to.exist expect(deposit.hexCommitment).to.exist expect(deposit.hexNullifierHash).to.exist // From the whitepaper, the nullifier k E B^248 expect(BigNumber.from(deposit.nullifier.toString())).to.be.lte(limit) // From the whitepaper, the randomness r E B^248 expect(BigNumber.from(deposit.secret.toString())).to.be.lte(limit) }) it('parseNote', () => { const deposit = Primitives.createDeposit() const note = Primitives.createNote(deposit.preimage) const parsed = Primitives.parseNote(note) expect(parsed.hexCommitment).to.equal(deposit.hexCommitment) }) }) }) })