Using crypto operations of blockstack.js in web workers

#1

I have noticed that blockstack.js executes encryption in the foreground which is causing the UI to hang if you are passing it larger files. Is there any chance to use e.g. userSession.encryptContent from within a web worker?

I found a related issue on GitHub that is closed but does not seem to be resolved: https://github.com/blockstack/blockstack.js/issues/264

#2

Seems to be resolved with 19.1, as you can now specify your own store and it’s not using localStorage anymore. (see discussion: https://github.com/blockstack/blockstack.js/issues/265 )

#3

Thanks for the hint. A minimal setup of a worker can look something like this:

importScripts('blockstack.min.js')

const sessionStore = {
  data: {},
  getSessionData() { return this.data },
  setSessionData(data) { this.data = data },
  deleteSessionData() { this.data = {} },
}

const userSession = new blockstack.UserSession({
  appConfig: new blockstack.AppConfig({ /* ... */ }),
  sessionStore,
})

// ... and then given that you have a buffer and a key available in your worker:
userSession.decryptContent(aBuffer, { privateKey })
2 Likes