Skip to main content

curvy_core/
note.rs

1//! Note commitments - a faithful port of `note.ts`'s Poseidon derivations.
2//!
3//! Note the deliberate input ordering: `ownerHash` and `nullifier` hash the *same
4//! three values* in a *different order*.
5
6use crate::field::Fr;
7use crate::poseidon::poseidon;
8
9/// `ownerHash = Poseidon([pub.x, pub.y, sharedSecret])`.
10pub fn owner_hash(public_key: (Fr, Fr), shared_secret: Fr) -> Fr {
11    poseidon(&[public_key.0, public_key.1, shared_secret])
12}
13
14/// `id = Poseidon([ownerHash, amount, token])`.
15pub fn note_id(owner_hash: Fr, amount: Fr, token: Fr) -> Fr {
16    poseidon(&[owner_hash, amount, token])
17}
18
19/// `nullifier = Poseidon([sharedSecret, pub.x, pub.y])`.
20pub fn nullifier(shared_secret: Fr, public_key: (Fr, Fr)) -> Fr {
21    poseidon(&[shared_secret, public_key.0, public_key.1])
22}