Issues (615)

test/webworkifier.test.js (2 issues)

Labels
Severity
1
/* global navigator, onLoadWorkerLoadAsmCrypto */
2
var blocktrailSDK = require('../');
3
var webworkifier = require('../lib/webworkifier');
4
var assert = require('assert');
5
var randomBytes = require('randombytes');
6
7
var isNodeJS = !process.browser;
8
var useWebWorker = require('../lib/use-webworker')();
9
10
describe('webworkifier', function() {
11
    var androidVersionV4 = ((typeof navigator !== "undefined" && navigator.userAgent) || "").match(/Android 4\./);
12
13
    if (isNodeJS) {
14
        it('is not used on NodeJS', function(cb) {
15
            assert(!useWebWorker);
16
17
            cb();
18
        });
19
    } else if (androidVersionV4) {
20
        it('is not used on Android v4.x', function(cb) {
21
            assert(!useWebWorker);
22
23
            cb();
24
        });
25
    } else {
26
        it('can use webworker', function(cb) {
27
            assert(useWebWorker);
28
29
            cb();
30
        });
31
32
        it('can encrypt on webworker', function() {
33
            var self = {};
34
35
            assert(typeof onLoadWorkerLoadAsmCrypto === "function");
36
37
            var pt = new Buffer("plaintextdata");
0 ignored issues
show
The variable Buffer seems to be never declared. If this is a global, consider adding a /** global: Buffer */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
38
            var pw = new Buffer("passphrase");
39
            var saltBuf = randomBytes(blocktrailSDK.Encryption.defaultSaltLen);
40
            var iv = randomBytes(blocktrailSDK.Encryption.ivLenBits / 8);
41
            var iterations = blocktrailSDK.KeyDerivation.defaultIterations;
42
43
            return webworkifier.workify(self, function() {
44
                return require('../lib/webworker');
45
            }, onLoadWorkerLoadAsmCrypto, {
46
                method: 'Encryption.encryptWithSaltAndIV',
47
                pt: pt,
48
                pw: pw,
49
                saltBuf: saltBuf,
50
                iv: iv,
51
                iterations: iterations
52
            })
53
                .then(function(data) {
54
                    var cipherText = Buffer.from(data.cipherText.buffer);
0 ignored issues
show
The variable Buffer seems to be never declared. If this is a global, consider adding a /** global: Buffer */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
55
                    assert(blocktrailSDK.Encryption.decrypt(cipherText, pw).equals(pt));
56
                });
57
        });
58
    }
59
});
60