No title

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
genSalt
  :: forall e.
     Rounds
  -> Aff (bcrypt :: BCRYPT | e) Salt
genSalt rounds =
  makeAff (\onError onSuccess -> _genSalt rounds onError onSuccess)

foreign import _genSalt
  :: forall e.
     Rounds
  -> (Error -> Eff (bcrypt :: BCRYPT | e) Unit)
  -> (Salt -> Eff (bcrypt :: BCRYPT | e) Unit)
  -> Eff (bcrypt :: BCRYPT | e) Unit

// my FFI binding
 exports._genSalt = function (rounds) {
    return function (onError) {
      return function (onSuccess) {
        return function () {
          return __webpack_require__(135).genSalt(rounds, function (err, res) {
            if (err)
              return onError(err)()
            else
              return onSuccess(res)()
          })
        }
      }
    }
  }

// library function
    bcrypt.genSalt = function(rounds, seed_length, callback) {
        if (typeof seed_length === 'function')
            callback = seed_length,
            seed_length = undefined; // Not supported.
        if (typeof rounds === 'function')
            callback = rounds,
            rounds = GENSALT_DEFAULT_LOG2_ROUNDS;
        if (typeof callback !== 'function')
            throw Error("Illegal callback: "+typeof(callback));
        if (typeof rounds !== 'number') {
            nextTick(callback.bind(this, Error("Illegal arguments: "+(typeof rounds))));
            return;
        }
        nextTick(function() { // Pretty thin, but salting is fast enough
            try {
                callback(null, bcrypt.genSaltSync(rounds));
            } catch (err) {
                callback(err);  // this is what's on the stack
            }
        });
    };