Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/aws-s3-multipart: Read from globalThis in functions #4584

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@uppy/aws-s3-multipart/src/createSignedURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ function createCanonicalRequest ({
].join('\n')
}

const { subtle } = globalThis.crypto
const ec = new TextEncoder()
const algorithm = { name: 'HMAC', hash: 'SHA-256' }

async function digest (data) {
const { subtle } = globalThis.crypto
return subtle.digest(algorithm.hash, ec.encode(data))
}

async function generateHmacKey (secret) {
const { subtle } = globalThis.crypto
return subtle.importKey('raw', typeof secret === 'string' ? ec.encode(secret) : secret, algorithm, false, ['sign'])
}

Expand All @@ -71,6 +72,7 @@ function arrayBufferToHexString (arrayBuffer) {
}

async function hash (key, data) {
const { subtle } = globalThis.crypto
return subtle.sign(algorithm, await generateHmacKey(key), ec.encode(data))
}

Expand Down