Skip to content

Commit

Permalink
Remove sha hash optionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
gannan08 committed Nov 7, 2024
1 parent c0dc9d9 commit 1321a42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 2 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {name} from './name.js';
import {requiredAlgorithm} from './requiredAlgorithm.js';
import {sha} from './sha.js';

const REQUIRED_HASH_ALGORITHM = 'SHA-256';

export function createSignCryptosuite() {
return {
name,
Expand Down Expand Up @@ -41,15 +39,14 @@ function _createVerifyDataFn(modifyProofOptionsAndDocument) {
// determine digest algorithm from key algorithm
modifyProofOptionsAndDocument({proof, document});

const algorithm = REQUIRED_HASH_ALGORITHM;
// await both jcs proof hash and jcs document hash
const [proofHash, docHash] = await Promise.all([
// canonize and hash proof
_canonizeProof(proof, {cryptosuite}).then(
jcsProofOptions => sha({algorithm, string: jcsProofOptions})),
jcsProofOptions => sha({string: jcsProofOptions})),
// canonize and hash document
cryptosuite.canonize(document).then(
jcsDocument => sha({algorithm, string: jcsDocument}))
jcsDocument => sha({string: jcsDocument}))
]);

// concatenate hash of jcs proof options and hash of c14n document
Expand Down
7 changes: 4 additions & 3 deletions lib/sha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
*/
import crypto from 'node:crypto';

const REQUIRED_HASH_ALGORITHM = 'SHA-256';

/**
* Hashes a string of data using SHA-256 or SHA-384.
*
* @param {object} options - The options to use.
* @param {string} options.algorithm - The algorithm to use.
* @param {string} options.string - The string to hash.
*
* @returns {Uint8Array} The hash digest.
*/
export async function sha({algorithm, string}) {
algorithm = algorithm === 'SHA-256' ? 'sha256' : 'sha384';
export async function sha({string}) {
const algorithm = REQUIRED_HASH_ALGORITHM;
return new Uint8Array(crypto.createHash(algorithm).update(string).digest());
}

0 comments on commit 1321a42

Please sign in to comment.