@opertus/crypto
Commitments, nullifiers, BabyJubJub stealth ownership, and clone salts.
This package contains protocol-compatible cryptographic primitives. Most
applications should use @opertus/wallet, which composes them safely. See
keys and notes for the committed values and
the privacy model for key
capabilities.
Note hashes
import {
computeNoteCommitment,
computeNoteNullifier,
deriveNullifierKey,
noteBlind,
nullifierImage,
} from '@opertus/crypto';
const nk = deriveNullifierKey(viewPrivateKey); // bigint
const nImage = nullifierImage(nk);
const blind = noteBlind(nImage, blinding);
const commitment = computeNoteCommitment(
tokenId,
value,
ownerPubKey,
randomness,
blind,
);
const nullifier = computeNoteNullifier(nk, commitment);Prop
Type
deriveNullifierKey throws unless the view key is exactly 32 bytes. Poseidon inputs must be non-negative and strictly below BN254_PRIME; the exported hash helpers rely on the Poseidon implementation to reject invalid inputs.
Stealth ownership
import {
deriveOwnerPubKey,
randomSuborderScalar,
recipientStealth,
senderStealth,
spendPointFromScalar,
} from '@opertus/crypto';
const spendScalar = randomSuborderScalar();
const ephemeralScalar = randomSuborderScalar();
const sent = senderStealth(
spendPointFromScalar(spendScalar),
ephemeralScalar,
);
const oneTimeSecret = recipientStealth(
spendScalar,
sent.spendEphemeral,
);
if (deriveOwnerPubKey(oneTimeSecret) !== sent.ownerPubKey) {
throw new Error('Stealth key mismatch');
}Prop
Type
Scalars must be in [0, BABYJUB_SUBORDER); sender ephemerals and recipient spend scalars must also be nonzero. Invalid, identity, off-curve, or wrong-subgroup spend points are rejected. unpackSpendPoint requires exactly 32 bytes.
Other exports
Prop
Type
The package also exports BN254_PRIME, BABYJUB_SUBORDER, and the BabyPoint type.