Skip to content

Commit

Permalink
fix aliases for sha3 vs sha2
Browse files Browse the repository at this point in the history
  • Loading branch information
querolita committed Dec 18, 2024
1 parent 06afc51 commit 40482ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/examples/zkapps/hashing/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ const initialState =
let currentState;
console.log('Initial State', initialState);

console.log(`Updating commitment from ${initialState} using SHA256 ...`);
console.log(`Updating commitment from ${initialState} using SHA3-256 ...`);
txn = await Mina.transaction(feePayer, async () => {
await contract.SHA256(hashData);
await contract.SHA3_256(hashData);
});
await txn.prove();
await txn.sign([feePayer.key]).send();
currentState = Mina.getAccount(contractAccount).zkapp?.appState?.[0].toString();
console.log(`Current state successfully updated to ${currentState}`);

console.log(`Updating commitment from ${initialState} using SHA384 ...`);
console.log(`Updating commitment from ${initialState} using SHA3-384 ...`);
txn = await Mina.transaction(feePayer, async () => {
await contract.SHA384(hashData);
await contract.SHA3_384(hashData);
});
await txn.prove();
await txn.sign([feePayer.key]).send();
currentState = Mina.getAccount(contractAccount).zkapp?.appState?.[0].toString();
console.log(`Current state successfully updated to ${currentState}`);

console.log(`Updating commitment from ${initialState} using SHA512 ...`);
console.log(`Updating commitment from ${initialState} using SHA3-512 ...`);
txn = await Mina.transaction(feePayer, async () => {
await contract.SHA512(hashData);
await contract.SHA3_512(hashData);
});
await txn.prove();
await txn.sign([feePayer.key]).send();
Expand Down
13 changes: 13 additions & 0 deletions src/lib/provable/crypto/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ const Hash = {
hash: Gadgets.SHA256.hash,
},

/**
* The SHA2 hash function with an output length of 224 | 256 | 384 | 512 bits.
*/
SHA2: {
/**
* Hashes the given bytes using SHA2.
*
* This is an alias for `Gadgets.SHA2.hash(length,bytes)`.\
* See {@link Gadgets.SHA2.hash} for details and usage examples.
*/
hash: Gadgets.SHA2.hash,
},

/**
* The SHA3 hash function with an output length of 256 bits.
*/
Expand Down
1 change: 1 addition & 0 deletions src/lib/provable/gadgets/gadgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ const Gadgets = {
*
* Produces an output of {@link Bytes} that conforms to the chosen bit length.
*
* @param length - 224 | 256 | 384 | 512 representing the length of the hash.
* @param data - {@link Bytes} representing the message to hash.
*
* ```ts
Expand Down

0 comments on commit 40482ee

Please sign in to comment.