I am trying to validate a document using public key crypto (tweetnacl). I know that you can add commonjs modules to validate functions but haven't been able to.
{
"_id": "_design/validate_update",
"language": "javascript",
"validate_doc_update":
"function(newDoc, oldDoc, userCtx){
verify=require('lib/validation').sign.detached.verify;
if(verify(newDoc.message, new.Doc.signature, oldDoc.publicKey)){
return true;
}
}",
"lib": {
"validation": "exports.nacl=(function(nacl){..... })"
}
}
When I do this I get the error:
Module require('lib/validation') raised error (new TypeError("func.apply is not a function", "/usr/local/share/couchdb/server/main.js", 1181))
I suppose I have to somehow change the tweetnacl code to be interpreted as a commonjs module?