2023-04-08 15:17:52 -04:00
|
|
|
import chai from 'chai'
|
|
|
|
|
|
|
|
import { solidity } from 'ethereum-waffle'
|
|
|
|
import { BigNumber } from 'ethers'
|
2023-05-02 18:19:28 -04:00
|
|
|
import { Primitives } from '@tornado/sdk-crypto'
|
2023-04-08 15:17:52 -04:00
|
|
|
|
|
|
|
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
|
2023-04-11 15:36:32 -04:00
|
|
|
expect(deposit.hexCommitment).to.exist
|
|
|
|
expect(deposit.hexNullifierHash).to.exist
|
2023-04-08 15:17:52 -04:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
})
|
2023-04-23 18:01:45 -04:00
|
|
|
|
|
|
|
it('parseNote', () => {
|
|
|
|
const deposit = Primitives.createDeposit()
|
|
|
|
const note = Primitives.createNote(deposit.preimage)
|
|
|
|
const parsed = Primitives.parseNote(note)
|
|
|
|
expect(parsed.hexCommitment).to.equal(deposit.hexCommitment)
|
|
|
|
})
|
2023-04-08 15:17:52 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|