Skip to content

Commit

Permalink
do not use async syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Skinner committed Oct 16, 2024
1 parent c81a572 commit 7177ddf
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/delivery-xml-http-request/delivery.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const payload = require('@bugsnag/core/lib/json-payload')

async function getIntegrity (windowOrWorkerGlobalScope, requestBody) {
function getIntegrity (windowOrWorkerGlobalScope, requestBody) {
if (windowOrWorkerGlobalScope.isSecureContext && windowOrWorkerGlobalScope.crypto && windowOrWorkerGlobalScope.crypto.subtle && windowOrWorkerGlobalScope.crypto.subtle.digest && typeof TextEncoder === 'function') {
const msgUint8 = new TextEncoder().encode(requestBody)
const hashBuffer = await windowOrWorkerGlobalScope.crypto.subtle.digest('SHA-1', msgUint8)
const hashArray = Array.from(new Uint8Array(hashBuffer))
const hashHex = hashArray
.map((b) => b.toString(16).padStart(2, '0'))
.join('')

return 'sha1 ' + hashHex
return windowOrWorkerGlobalScope.crypto.subtle.digest('SHA-1', msgUint8).then((hashBuffer) => {
const hashArray = Array.from(new Uint8Array(hashBuffer))
const hashHex = hashArray
.map((b) => b.toString(16).padStart(2, '0'))
.join('')

return 'sha1 ' + hashHex
})
}
return Promise.resolve()
}

module.exports = (client, win = window) => ({
Expand Down

0 comments on commit 7177ddf

Please sign in to comment.