All files / src/crypto-extras/crypto-hmac-sha hmac-sha256.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 1342x   43x 42x   42x   43x 43x   43x    
import { ensureUint8Array } from 'micro-stacks/common';
 
import { hmac } from '@noble/hashes/hmac';
import { sha256 } from '@noble/hashes/sha256';
 
export function hmacSha256(key: Uint8Array, ...messages: Uint8Array[]): Uint8Array {
  const hash = hmac.create(sha256, ensureUint8Array(key));
  for (const message of messages) {
    hash.update(ensureUint8Array(message));
  }
  return Uint8Array.from(hash.digest());
}