From ed82936610b86deb9f0d2e6c3d982a6efd3c7107 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 5 Sep 2019 15:28:20 +0200 Subject: [PATCH] add nodejs support to common-hash --- www/common/common-hash.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/www/common/common-hash.js b/www/common/common-hash.js index 756877857..25bd981a8 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -1,10 +1,5 @@ -define([ - '/common/common-util.js', - '/bower_components/chainpad-crypto/crypto.js', - '/bower_components/tweetnacl/nacl-fast.min.js' -], function (Util, Crypto) { - var Nacl = window.nacl; - +(function () { +var factory = function (Util, Crypto, Nacl) { var Hash = window.CryptPad_Hash = {}; var uint8ArrayToHex = Util.uint8ArrayToHex; @@ -537,4 +532,19 @@ Version 1 }; return Hash; -}); +}; + + if (typeof(module) !== 'undefined' && module.exports) { + module.exports = factory(require("./common-util"), require("chainpad-crypto"), require("tweetnacl")); + } else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) { + define([ + '/common/common-util.js', + '/bower_components/chainpad-crypto/crypto.js', + '/bower_components/tweetnacl/nacl-fast.min.js' + ], function (Util, Crypto) { + factory(Util, Crypto, window.nacl); + }); + } else { + // unsupported initialization + } +}());