@lelantos-org/sdk / crypto / Poseidon
Class: Poseidon โ
Defined in: @lelantos-org/sdk/dist/crypto/poseidon.d.ts:5
Properties โ
backend โ
readonly backend: PoseidonBackend;Defined in: @lelantos-org/sdk/dist/crypto/poseidon.d.ts:11
Which implementation arity-5 hashes use. "js" means the wasm module did not load and every hash is ~2.5x slower โ worth asserting in benchmarks and worth checking first when a sync is unexpectedly slow.
hash โ
readonly hash: (xs) => bigint;Defined in: @lelantos-org/sdk/dist/crypto/poseidon.d.ts:34
Inputs must already be canonical field elements, i.e. in [0, r).
poseidon-lite reduces mod r internally, so x and x + r hash identically. Every domain-separated construction in the SDK routes through here โ nullifiers, note commitments, rho, the key ladder, merkle nodes โ so without this check two distinct decoded records or two distinct merkle leaves can be made to collide by construction. Both decoders that feed it (notes/codec.ts, keys/address.ts) read raw 32-byte slices and can produce unreduced values.
The wasm backend rejects unreduced input rather than reducing it, so the two agree โ but the check stays here to keep the error identical whichever backend is live.
One comparison per input against a full permutation: not measurable.
A bound property rather than a prototype method, so the class stays structurally { backend, hash } and the arity table can be captured per instance โ the backend is a property of the instance, not of the call, so it must not be branched on per hash.
Parameters โ
| Parameter | Type |
|---|---|
xs | bigint[] |
Returns โ
bigint
Methods โ
build() โ
static build(): Promise<Poseidon>;Defined in: @lelantos-org/sdk/dist/crypto/poseidon.d.ts:46
Initialises the wasm backend. Already async before it did anything, so no caller changes.
A failure here is not fatal: the JS tables cover every arity, so an environment that cannot load wasm degrades to the slower backend rather than to a broken wallet. It is logged rather than swallowed โ silently losing 2.5x is the kind of regression nobody notices until a cold sync takes a minute.
Returns โ
Promise<Poseidon>