Adding missing instructions to load missing Apache2 modules for Fidelius to work!
[iotcloud.git] / version1 / src / js / iotjs / src / main.js
1 /* jshint devel:true */
2 "use strict";
3 console.log('Welcome to iotjs-www', '\n\n');
4 // set up the base line..
5 // Using browserify to set up browser exports
6 var crypto = require('crypto-js');
7 var _ = require('underscore');
8 var ByteBuffer = require('bytebuffer');
9 var hash = require('object-hash');
10 var forge = require('node-forge');
11 (function() {
12     var root = this;
13     // iot namespace main constructor
14     var iot = function(obj) {
15         if (obj instanceof iot) return obj;
16         if (!(this instanceof iot)) return new iot(obj);
17         this.iot = obj;
18     };
19     // export iot to the global exports
20     if (typeof exports !== 'undefined') {
21         if (typeof module !== 'undefined' && module.exports) {
22             exports = module.exports = iot;
23         }
24         exports.iot = iot;
25     } else {
26         root.iot = iot;
27     }
28
29
30     iot.baselinetest = function() {
31         // baseline test
32         console.log('its alive!!!');
33         console.log();
34
35
36         //local hash test
37         console.log(hash('hello man'));
38         console.log(typeof hash('hello man'));
39         console.log();
40
41
42         //Pair test
43         var p = new Pair(1, 2);
44         console.log(p.toString());
45         console.log();
46
47
48         //iotstring test
49         var i = new IoTString('hello');
50         console.log(i.length());
51         console.log();
52
53
54         //local crypto test
55         var data = [{id: 1}, {id: 2}];
56         // Encrypt 
57         var ciphertext = crypto.AES.encrypt(JSON.stringify(data), 'secret key 123');
58         // Decrypt 
59         var bytes = crypto.AES.decrypt(ciphertext.toString(), 'secret key 123');
60         var decryptedData = JSON.parse(bytes.toString(crypto.enc.Utf8));
61         // console.log(decryptedData);
62
63         var e = crypto.HmacMD5("Message", "Secret Passphrase");
64         console.log(typeof e.toString());
65     }
66 }())