What does jsSHA look like?  Does it export something?  I think CommonJS uses exports vs export. 

FWIW, I did something similar in a kanso app [1].


- Jim

[1] https://github.com/jimklo/TheCollector/tree/master/dataservices/thecollector-resources

Sent from my iPad

On Oct 4, 2012, at 12:51 PM, "Wordit" <wordituk@gmail.com> wrote:

I'm using CommonJS, following Ryan's suggestion yesterday, so that
maps and update functions can access an SHA hashing function. I'm new
to this and since jsSHA needs to create an object I can't figure out
how to make it work.

jsSHA usage:

shaObj = new jsSHA(mytext, "ASCII");
hashedText = shaObj.getHash("SHA-256", "HEX");

I included the minified jsSHA code in views under lib:
"views": {
 "lib": {
       // this module is accessible from view functions
       "sha256": "export.hash = (function() ...


The map function I'm testing, which fails to deliver:

function (doc) {
var val = require('views/lib/sha256').hash;
var shaObj = new val.jsSHA("foobar", "ASCII");
var newhash = shaObj.getHash("SHA-256", "HEX");
emit(doc._id, newhash);
}

It emits nothing so I guess my syntax to access the jsSHA function is wrong?

Thanks for any help,

Marcus