<commit_before>// import errors from 'feathers-errors';
import makeDebug from 'debug';
import crypto from 'crypto';

const debug = makeDebug('feathers-authentication-signed');

export default function init () {
  debug('Initializing feathers-authentication-signed plugin');
  return 'feathers-authentication-signed';
}

init.generateSecret = function generateSecret (password, salt) {
  crypto.pbkdf2(password, salt, 100000, 512, 'sha512', (err, key) => {
    if (err) throw err;
    console.log(key.toString('hex'));
  });
};
<commit_msg>Add client utilities.<commit_after>const defaults = {
  pbkdf2: undefined, // Must be passed in
  createHmac: undefined // Must be passed in
};

export default function plugin (options) {
  options = Object.assign({}, defaults, options);

  if (!options.pbkdf2) {
    throw new Error('You must provide a `pbkdf2` function to the feathers-authentication-signed plugin options');
  }
  if (!options.createHmac) {
    throw new Error('You must provide a `createHmac` function to the feathers-authentication-signed plugin options');
  }

  function signed () {

  }

  let utils = {
    generateSecret (password, salt) {
      return new Promise((resolve, reject) => {
        options.pbkdf2(password, salt, 250, 512, 'sha512', function (err, key) {
          if (err) return reject(err);
          resolve(key.toString('hex'));
        });
      });
    },
    sign (data, secret) {
      return new Promise((resolve, reject) => {
        let dataString = JSON.stringify(data);
        let hmac = options.createHmac('sha512', secret);
        let signature = hmac.update(dataString).digest('hex');
        data.signature = signature;
        resolve(data);
      });
    }
  };

  Object.assign(signed, utils);
  return signed;
}

{'fraction_non_alphanumeric': 0.1347678369195923, 'fraction_numerical': 0.01642129105322763, 'mean_word_length': 3.4396984924623117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4583672', 'n_tokens_mistral': 540, 'n_tokens_neox': 513, 'n_words': 145}