Skip to content

Commit

Permalink
fix(eddsa-poseidon): throw an error if unsupported algorithm is chosen"
Browse files Browse the repository at this point in the history
BREAKING CHANGE: n

re #51
  • Loading branch information
hannahredler committed Oct 3, 2024
1 parent ef70a95 commit ce1beec
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/eddsa-poseidon/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,20 @@ export function checkMessage(message: BigNumberish): bigint {
*/
export function hashInput(message: Buffer | Uint8Array, algorithm?: SupportedHashingAlgorithms) {
let engine: HashFunction
if (!algorithm || algorithm === SupportedHashingAlgorithms.BLAKE1) engine = new Blake512()
else engine = new Blake2b()

switch (algorithm) {
case SupportedHashingAlgorithms.BLAKE1: {
engine = new Blake512()
break
}
case SupportedHashingAlgorithms.BLAKE2b: {
engine = new Blake2b()
break
}
default: {
throw new Error("Unsupported algorithm. Cannot hash input.")
}
}
engine.update(Buffer.from(message))

return engine.digest()
}

0 comments on commit ce1beec

Please sign in to comment.