Hash Functions
Overview
The SDK provides various cryptographic hash functions that match Aleo's native hash implementations. These include BHP (Bowe-Hopwood-Pedersen), Pedersen, and Poseidon hash functions.
BHP Hash Functions
BHP (Bowe-Hopwood-Pedersen) hash functions are available with different input sizes:
BHP256- 256-bit input hasherBHP512- 512-bit input hasherBHP768- 768-bit input hasherBHP1024- 1024-bit input hasher
BHP Methods
constructor
Create a BHP hasher with the default domain separator
new BHP256() ► BHP256
new BHP512() ► BHP512
new BHP768() ► BHP768
new BHP1024() ► BHP1024
setup
Create a BHP hasher with a custom domain separator
setup(domain_separator) ► BHP
| Param | Type | Description |
|---|---|---|
| domain_separator | string | Custom domain separator |
| return | BHP | BHP hasher instance |
hash
Returns the BHP hash of the input bits
hash(input) ► Field
| Param | Type | Description |
|---|---|---|
| input | Array | Boolean array representing the input bits |
| return | Field | The hash result |
hashToGroup
Returns a BHP hash as a group element
hashToGroup(input) ► Group
| Param | Type | Description |
|---|---|---|
| input | Array | Boolean array representing the input bits |
| return | Group | The hash result as a group element |
commit
Returns a BHP commitment with the given randomizer
commit(input, randomizer) ► Field
| Param | Type | Description |
|---|---|---|
| input | Array | Boolean array representing the input bits |
| randomizer | Scalar | The randomizer for the commitment |
| return | Field | The commitment result |
commitToGroup
Returns a BHP commitment as a group element
commitToGroup(input, randomizer) ► Group
| Param | Type | Description |
|---|---|---|
| input | Array | Boolean array representing the input bits |
| randomizer | Scalar | The randomizer for the commitment |
| return | Group | The commitment result as a group element |
Pedersen Hash Functions
Pedersen hash functions are available for small inputs:
Pedersen64- up to 64-bit inputPedersen128- up to 128-bit input
Pedersen Methods
constructor
Create a Pedersen hasher with the default domain separator
new Pedersen64() ► Pedersen64
new Pedersen128() ► Pedersen128
setup
Create a Pedersen hasher with a custom domain separator
setup(domain_separator) ► Pedersen
| Param | Type | Description |
|---|---|---|
| domain_separator | string | Custom domain separator |
| return | Pedersen | Pedersen hasher instance |
hash
Returns the Pedersen hash of the input bits
hash(input) ► Field
| Param | Type | Description |
|---|---|---|
| input | Array | Boolean array representing the input bits |
| return | Field | The hash result |
commit
Returns a Pedersen commitment with the given randomizer
commit(input, randomizer) ► Field
| Param | Type | Description |
|---|---|---|
| input | Array | Boolean array representing the input bits |
| randomizer | Scalar | The randomizer for the commitment |
| return | Field | The commitment result |
commitToGroup
Returns a Pedersen commitment as a group element
commitToGroup(input, randomizer) ► Group
| Param | Type | Description |
|---|---|---|
| input | Array | Boolean array representing the input bits |
| randomizer | Scalar | The randomizer for the commitment |
| return | Group | The commitment result as a group element |
Poseidon Hash Functions
Poseidon hash functions operate on field elements with different input rates:
Poseidon2- input rate of 2Poseidon4- input rate of 4Poseidon8- input rate of 8
Poseidon Methods
constructor
Create a Poseidon hasher with the default domain separator
new Poseidon2() ► Poseidon2
new Poseidon4() ► Poseidon4
new Poseidon8() ► Poseidon8
setup
Create a Poseidon hasher with a custom domain separator
setup(domain_separator) ► Poseidon
| Param | Type | Description |
|---|---|---|
| domain_separator | string | Custom domain separator |
| return | Poseidon | Poseidon hasher instance |
hash
Returns the Poseidon hash of the input field elements
hash(input) ► Field
| Param | Type | Description |
|---|---|---|
| input | Array | Array of Field elements |
| return | Field | The hash result |
hashMany
Returns the extended Poseidon hash with multiple outputs
hashMany(input, num_outputs) ► Array
| Param | Type | Description |
|---|---|---|
| input | Array | Array of Field elements |
| num_outputs | number | Number of output field elements |
| return | Array | Array of Field elements |
hashToScalar
Returns the Poseidon hash on the scalar field
hashToScalar(input) ► Scalar
| Param | Type | Description |
|---|---|---|
| input | Array | Array of Field elements |
| return | Scalar | The hash result as a scalar |
hashToGroup
Returns the Poseidon hash on the affine curve
hashToGroup(input) ► Group
| Param | Type | Description |
|---|---|---|
| input | Array | Array of Field elements |
| return | Group | The hash result as a group element |