Skip to content

Commit

Permalink
website: remove dependency on crypto in @uppy/transloadit example (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Dec 13, 2021
1 parent cfdba97 commit 0c794a6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions website/src/examples/transloadit/app.es6
Expand Up @@ -5,13 +5,15 @@ const Transloadit = require('@uppy/transloadit')
const Instagram = require('@uppy/instagram')
const Facebook = require('@uppy/facebook')
const Zoom = require('@uppy/zoom')
const { createHmac } = require('crypto')
const COMPANION = require('../env')

function sha1 (key, text) {
return createHmac('sha1', key)
.update(text)
.digest('hex')
const enc = new TextEncoder('utf-8')
async function sha1 (secret, body) {
const algorithm = { name: 'HMAC', hash: 'SHA-1' }

const key = await crypto.subtle.importKey('raw', enc.encode(secret), algorithm, false, ['sign', 'verify'])
const signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(body))
return Array.from(new Uint8Array(signature), x => x.toString(16).padStart(2, '0')).join('')
}

function initUppy (opts = {}) {
Expand Down Expand Up @@ -44,7 +46,7 @@ function initUppy (opts = {}) {
.replace(/\.\d+Z$/, '+00:00')
}

function getAssemblyOptions () {
async function getAssemblyOptions () {
const hasSecret = opts.secret != null
let params = {
auth: {
Expand Down Expand Up @@ -104,7 +106,7 @@ function initUppy (opts = {}) {
let signature
if (opts.secret) {
params = JSON.stringify(params)
signature = sha1(opts.secret, params)
signature = await sha1(opts.secret, params)
}

return { params, signature }
Expand Down

0 comments on commit 0c794a6

Please sign in to comment.