MCPcopy
hub / github.com/mongodb/node-mongodb-native / getHmacSha256

Function getHmacSha256

src/cmap/auth/aws4.ts:44–63  ·  view source on GitHub ↗
(key: string | Uint8Array, str: string)

Source from the content-addressed store, hash-verified

42 * @returns Uint8Array containing the HMAC-SHA256 digest.
43 */
44const getHmacSha256 = async (key: string | Uint8Array, str: string): Promise<Uint8Array> => {
45 let keyData: Uint8Array;
46 if (typeof key === 'string') {
47 keyData = stringToBuffer(key);
48 } else {
49 keyData = key;
50 }
51
52 const importedKey = await crypto.subtle.importKey(
53 'raw',
54 keyData,
55 { name: 'HMAC', hash: { name: 'SHA-256' } },
56 false,
57 ['sign']
58 );
59 const strData = stringToBuffer(str);
60 const signature = await crypto.subtle.sign('HMAC', importedKey, strData);
61 const digest = new Uint8Array(signature);
62 return digest;
63};
64
65/**
66 * Converts header values according to AWS requirements,

Callers 1

aws4SignFunction · 0.85

Calls 1

stringToBufferFunction · 0.85

Tested by

no test coverage detected