( method: CryptoMethod, key: Uint8Array, text: Uint8Array | string )
| 273 | } |
| 274 | |
| 275 | async function HMAC( |
| 276 | method: CryptoMethod, |
| 277 | key: Uint8Array, |
| 278 | text: Uint8Array | string |
| 279 | ): Promise<Uint8Array> { |
| 280 | const keyBuffer = ByteUtils.toLocalBufferType(key); |
| 281 | const cryptoKey = await crypto.subtle.importKey( |
| 282 | 'raw', |
| 283 | keyBuffer, |
| 284 | { name: 'HMAC', hash: { name: method === 'sha256' ? 'SHA-256' : 'SHA-1' } }, |
| 285 | false, |
| 286 | ['sign', 'verify'] |
| 287 | ); |
| 288 | const textData: Uint8Array = typeof text === 'string' ? new TextEncoder().encode(text) : text; |
| 289 | const textBuffer = ByteUtils.toLocalBufferType(textData); |
| 290 | const signature = await crypto.subtle.sign('HMAC', cryptoKey, textBuffer); |
| 291 | return new Uint8Array(signature); |
| 292 | } |
| 293 | |
| 294 | interface HICache { |
| 295 | [key: string]: Uint8Array; |
no outgoing calls
no test coverage detected