javascript - Add tweetNaCL-js crypto library to CouchDB validate_doc function -
i trying validate document using public key crypto (tweetnacl). know you can add commonjs modules validate functions 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 error:
module require('lib/validation') raised error (new typeerror("func.apply not function", "/usr/local/share/couchdb/server/main.js", 1181)) i suppose have somehow change tweetnacl code interpreted commonjs module?
seems initialisation of nacl lib commonjs module failing because anonymous function - try give nacl exports context:
"lib": { "validation": "(function(nacl){..... })(exports)" }
Comments
Post a Comment