Closed start940315 closed 1 year ago
My code runs into this function:
hmacSha256: async (key, ...messages) => { if (crypto.web) { const ckey = await crypto.web.subtle.importKey('raw', key, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']); const message = concatBytes(...messages); const buffer = await crypto.web.subtle.sign('HMAC', ckey, message); return new Uint8Array(buffer); } else if (crypto.node) { const { createHmac } = crypto.node; const hash = createHmac('sha256', key); messages.forEach((m) => hash.update(m)); return Uint8Array.from(hash.digest()); } else { throw new Error("The environment doesn't have hmac-sha256 function"); } },
and my website is under http protocol. So the crypto doesn't have subtle property. The code containing importKey reports error. How can I solve this problem?
re-define hmacSha256 with your own code, for example, using noble-hashes
hmacSha256
My code runs into this function:
and my website is under http protocol. So the crypto doesn't have subtle property. The code containing importKey reports error. How can I solve this problem?