Package to replace
create-hmac
Suggested replacement(s)
In Node.js
import { createHmac } from 'node:crypto'
In Browser
const toHex = buf => Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2, '0')).join('')
async function generateHMAC(secret, data) {
const enc = new TextEncoder()
const key = await crypto.subtle.importKey("raw",
enc.encode(secret),
{ name: "HMAC", hash: "SHA-256" },
false, ["sign"])
const signature = await crypto.subtle.sign("HMAC", key, enc.encode(data))
return toHex(signature)
}
Also, if already installed, can use @noble/hashes
import { hmac } from '@noble/hashes/hmac;
import { sha256 } from '@noble/hashes/sha256'
import { bytesToHex } from '@noble/hashes/utils'
const hash = bytesToHex(hmac(sha256, 'secret-key', 'message-to-sign'))
console.log(hash)
Manifest type
preferred (lighter or more modern alternative package)
Rationale
Native, simpler or more performant alternatives
Availability
No response
Code example (optional)
Package to replace
create-hmacSuggested replacement(s)
In Node.js
In Browser
Also, if already installed, can use
@noble/hashesManifest type
preferred (lighter or more modern alternative package)
Rationale
Native, simpler or more performant alternatives
Availability
No response
Code example (optional)