Skip to content

Commit

Permalink
Add hash2
Browse files Browse the repository at this point in the history
  • Loading branch information
r0qs committed Oct 25, 2022
1 parent 5b70733 commit 2d63c49
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/poseidon.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Poseidon {

constructor(hashFunction) {
this.#hashFn = hashFunction
this.F = hashFunction.F
}

static async initialize() {
Expand All @@ -17,7 +18,15 @@ class Poseidon {
* @param {Array<BigNumber>} items Array of items to be hashed
*/
hash(items) {
return this.#hashFn.F.toString(this.#hashFn(items.map((x) => BigNumber.from(x).toBigInt())))
return this.F.toString(this.#hashFn(items.map((x) => BigNumber.from(x).toBigInt())))
}

/**
* Hash two elements using Poseidon elliptic curve hash function
* @param {BigNumber, BigNumber} elements to be hashed
*/
hash2(a, b) {
return this.hash([a, b])
}
}

Expand Down

0 comments on commit 2d63c49

Please sign in to comment.