From 4833f300c527b96cc5d6d16c605df8cf04d06c1d Mon Sep 17 00:00:00 2001 From: Claudius Date: Mon, 13 May 2019 12:55:03 +0200 Subject: polyfilling scrypt for node 8.5+ Signed-off-by: Claudius --- lib/models/user.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lib/models') diff --git a/lib/models/user.js b/lib/models/user.js index 8da12b83..76e20a32 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -1,11 +1,20 @@ 'use strict' // external modules -var Sequelize = require('sequelize') -var scrypt = require('scrypt-kdf') +const Sequelize = require('sequelize') +const crypto = require('crypto') +if (!crypto.scrypt) { + // polyfill for node.js 8.0, see https://github.com/chrisveness/scrypt-kdf#openssl-implementation + const scryptAsync = require('scrypt-async') + crypto.scrypt = function (password, salt, keylen, options, callback) { + const opt = Object.assign({}, options, { dkLen: keylen }) + scryptAsync(password, salt, opt, (derivedKey) => callback(null, Buffer.from(derivedKey))) + } +} +const scrypt = require('scrypt-kdf') // core -var logger = require('../logger') -var { generateAvatarURL } = require('../letter-avatars') +const logger = require('../logger') +const { generateAvatarURL } = require('../letter-avatars') module.exports = function (sequelize, DataTypes) { var User = sequelize.define('User', { -- cgit v1.2.3