All files / client/functions createMacTag.ts

100% Statements 7/7
100% Branches 2/2
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 101x   1x 13x 13x 13x 13x 13x    
import { BytesCoder, HMAC } from '@stevenkellner/typescript-common-functionality';
 
export function createMacTag(parameters: unknown, key: Uint8Array): string {
    const messageAuthenticater = new HMAC(key);
    const jsonString = parameters === undefined ? '' : JSON.stringify(parameters);
    const encodedParameters = BytesCoder.fromUtf8(jsonString);
    const tagBytes = messageAuthenticater.sign(encodedParameters);
    return BytesCoder.toHex(tagBytes);
}