Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions infrastructure/eid-wallet/src/lib/utils/capitalize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Returns a new string with the first letter of each word in uppercase and the remaining letters in lowercase.
*
* @param str - The input string to capitalize.
* @returns The capitalized string.
*/
export function capitalize(str: string) {
return str
.toLowerCase()
Expand Down
15 changes: 15 additions & 0 deletions infrastructure/evault-provisioner/src/utils/hmac.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { createHmac } from "crypto";

/**
* Generates an HMAC SHA-256 signature for a JSON-serializable object using the provided secret key.
*
* @param body - The object to be signed.
* @param secret - The secret key used for HMAC generation.
* @returns The hexadecimal string representation of the HMAC signature.
*/
export function createHmacSignature(body: Record<string, any>, secret: string) {
return createHmac("sha256", secret)
.update(JSON.stringify(body))
.digest("hex");
}

/**
* Verifies that a provided HMAC signature matches the expected signature for a given object and secret key.
*
* @param body - The object whose signature is to be verified.
* @param signature - The HMAC signature to compare against.
* @param secret - The secret key used to generate the expected signature.
* @returns `true` if the signature is valid; otherwise, `false`.
*/
export function verifyHmacSignature(
body: Record<string, any>,
signature: string,
Expand Down
Loading