I'm developing an addon and have to create a hmac sha512 hash but jpm says that the crypto module can't be found (https://nodejs.org/api/crypto.html#crypto_crypto_createhmac_algorithm_key) - can't I use standard node modules in firefox addon development?
Sorry I'm very new to this.
If not, is there another way to create the hash?
One can only use npm-hoisted third-party SDK modules and currently there are not many modules of this type e.g menuitem.
If you want to create hash then you can use crypto.js library.But you cannot use it directly in index.js.For that you have to create pageworker and do message passing whenever you want to create hash.
To create pageworker in index.js your code will something look like this :
var HashWorker = require('sdk/page-worker').Page({
contentURL: "./hash.html",
contentScriptFile : ["./crypto.js","./myfile.js"]
});
In myfile.js you will use crypto.js functions to create hash.Note that all the files hash.html,crypto.js and myfile.js must be in data directory of your addon.
hash.html will look something look like this :
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
Once all this setup,you can communicate from index.js to myfile.js or vice versa through message passing.
To create hash of something you can send message to myfile.js that will look something like this : index.js
//send message to myfile.js to create hash of some value
HashWorker.port.emit('createHash',{data : "whose hash to create"});
//message received from myfile.js containing hash of specified value
HashWorker.port.on('hash_result',function(message){
console.log(message.hash);
});
In myfile.js message passing will look something like this : myfile.js
//message received from index.js to create hash of specified value
self.port.on('createHash',function(message){
var value = message.data
var hash = ...//cryptojs function to create hash of above value.
//send hash created to index.js
self.port.emit('hash_result',{hash : hash});
});