annotate scripts/minifier/otr/sm-webworker.js @ 41:21d0d0ab7aa0

xeps: renamed published proto-xeps, and updated them according to published version
author Goffi <goffi@goffi.org>
date Fri, 20 Mar 2015 16:13:10 +0100
parents 1596660ddf72
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
1 ;(function (root) {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
2 "use strict";
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
3
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
4 root.OTR = {}
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
5 root.crypto = {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
6 randomBytes: function () {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
7 throw new Error("Haven't seeded yet.")
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
8 }
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
9 }
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
10
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
11 // default imports
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
12 var imports = [
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
13 'vendor/salsa20.js'
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
14 , 'vendor/bigint.js'
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
15 , 'vendor/crypto.js'
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
16 , 'vendor/eventemitter.js'
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
17 , 'lib/const.js'
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
18 , 'lib/helpers.js'
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
19 , 'lib/sm.js'
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
20 ]
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
21
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
22 function wrapPostMessage(method) {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
23 return function () {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
24 postMessage({
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
25 method: method
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
26 , args: Array.prototype.slice.call(arguments, 0)
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
27 })
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
28 }
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
29 }
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
30
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
31 var sm
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
32 onmessage = function (e) {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
33 var data = e.data
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
34 switch (data.type) {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
35 case 'seed':
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
36 if (data.imports) imports = data.imports
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
37 importScripts.apply(root, imports)
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
38
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
39 // use salsa20 since there's no prng in webworkers
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
40 var state = new root.Salsa20(
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
41 data.seed.slice(0, 32),
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
42 data.seed.slice(32)
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
43 )
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
44 root.crypto.randomBytes = function (n) {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
45 return state.getBytes(n)
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
46 }
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
47 break
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
48 case 'init':
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
49 sm = new root.OTR.SM(data.reqs)
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
50 ;['trust','question', 'send', 'abort'].forEach(function (m) {
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
51 sm.on(m, wrapPostMessage(m));
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
52 })
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
53 break
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
54 case 'method':
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
55 sm[data.method].apply(sm, data.args)
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
56 break
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
57 }
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
58 }
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
59
1596660ddf72 Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff changeset
60 }(this))