diff scripts/minifier/otr/dsa-webworker.js @ 12:1596660ddf72

Add minifier script for otr.js and its dependencies
author souliane <souliane@mailoo.org>
date Wed, 03 Sep 2014 19:38:05 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/minifier/otr/dsa-webworker.js	Wed Sep 03 19:38:05 2014 +0200
@@ -0,0 +1,52 @@
+;(function (root) {
+  "use strict";
+
+  root.OTR = {}
+  root.DSA = {}
+  root.crypto = {
+    randomBytes: function () {
+      throw new Error("Haven't seeded yet.")
+    }
+  }
+
+  // default imports
+  var imports = [
+      'vendor/salsa20.js'
+    , 'vendor/bigint.js'
+    , 'vendor/crypto.js'
+    , 'vendor/eventemitter.js'
+    , 'lib/const.js'
+    , 'lib/helpers.js'
+    , 'lib/dsa.js'
+  ]
+
+  function sendMsg(type, val) {
+    postMessage({ type: type, val: val })
+  }
+
+  onmessage = function (e) {
+    var data = e.data;
+
+    if (data.imports) imports = data.imports
+    importScripts.apply(root, imports);
+
+    // use salsa20 since there's no prng in webworkers
+    var state = new root.Salsa20(data.seed.slice(0, 32), data.seed.slice(32))
+    root.crypto.randomBytes = function (n) {
+      return state.getBytes(n)
+    }
+
+    if (data.debug) sendMsg('debug', 'DSA key creation started')
+    var dsa
+    try {
+      dsa = new root.DSA()
+    } catch (e) {
+      if (data.debug) sendMsg('debug', e.toString())
+      return
+    }
+    if (data.debug) sendMsg('debug', 'DSA key creation finished')
+
+    sendMsg('data', dsa.packPrivate())
+  }
+
+}(this))
\ No newline at end of file