2023-04-08 22:17:52 +03:00
|
|
|
import chai from 'chai'
|
|
|
|
|
|
|
|
import { solidity } from 'ethereum-waffle'
|
|
|
|
import { BigNumber } from 'ethers'
|
2023-05-03 01:19:28 +03:00
|
|
|
import { Primitives } from '@tornado/sdk-crypto'
|
2023-04-08 22:17:52 +03: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 22:36:32 +03:00
|
|
|
expect(deposit.hexCommitment).to.exist
|
|
|
|
expect(deposit.hexNullifierHash).to.exist
|
2023-04-08 22:17:52 +03: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-24 01:01:45 +03: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 22:17:52 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|