How to use the libsodium-wrappers-sumo.crypto_sign_SECRETKEYBYTES function in libsodium-wrappers-sumo

To help you get started, we’ve selected a few libsodium-wrappers-sumo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sjudson / paseto.js / lib / key / private.js View on Github external
const sodium = require('libsodium-wrappers-sumo');

const extcrypto = require('../../extcrypto');
const V1        = require('../protocol/V1');
const V2        = require('../protocol/V2');
const utils     = require('../utils');
const PublicKey = require('./public');


// patch
sodium.crypto_sign_KEYPAIRBYTES = sodium.crypto_sign_SECRETKEYBYTES + sodium.crypto_sign_PUBLICKEYBYTES;


/***
 * PrivateKey
 *
 * private key for asymmetric cryptography
 *
 * @constructor
 *
 * @api public
 *
 * @param {Object} protocol
 */
module.exports = PrivateKey;
function PrivateKey(protocol) {
  const self = this;
github sjudson / paseto.js / lib / key / private.js View on Github external
return sodium.ready.then(() => {

    if (self.protocol() instanceof V2) {

      if (!(rkey instanceof Buffer)) { return done(new TypeError('Raw key must be provided as a buffer')); }

      const len = Buffer.byteLength(rkey);

      if (len === sodium.crypto_sign_KEYPAIRBYTES) {
        rkey = rkey.slice(0, sodium.crypto_sign_SECRETKEYBYTES);
      } else if (len !== sodium.crypto_sign_SECRETKEYBYTES) {

        if (len !== sodium.crypto_sign_SEEDBYTES) {
          throw new Error('Secret keys must be 32 or 64 bytes long; ' + len + ' given.')
        }

        rkey = Buffer.from(sodium.crypto_sign_seed_keypair(rkey).privateKey);
      }
    }

    self._key = rkey;

    return done();
  });
}
github sjudson / paseto.js / lib / key / private.js View on Github external
return sodium.ready.then(() => {

    if (self.protocol() instanceof V2) {

      if (!(rkey instanceof Buffer)) { return done(new TypeError('Raw key must be provided as a buffer')); }

      const len = Buffer.byteLength(rkey);

      if (len === sodium.crypto_sign_KEYPAIRBYTES) {
        rkey = rkey.slice(0, sodium.crypto_sign_SECRETKEYBYTES);
      } else if (len !== sodium.crypto_sign_SECRETKEYBYTES) {

        if (len !== sodium.crypto_sign_SEEDBYTES) {
          throw new Error('Secret keys must be 32 or 64 bytes long; ' + len + ' given.')
        }

        rkey = Buffer.from(sodium.crypto_sign_seed_keypair(rkey).privateKey);
      }
    }

    self._key = rkey;

    return done();
  });
}
github auth0 / magic / magic.js View on Github external
function sign(message, sk, cb) {
  if (typeof sk === 'function') {
    cb = sk;
    sk = null;
  }
  const done = ret(cb);

  let payload, isk;
  [ payload ] = iparse(message);
  [ sk ]      = cparse(sk);

  switch (sk && Buffer.byteLength(sk)) {
    case sodium.crypto_sign_SECRETKEYBYTES:
      isk = sk;
      break;
    case sodium.crypto_sign_SEEDBYTES:
      isk = sodium.crypto_sign_seed_keypair(sk).privateKey;
      break;
    default:
      isk = sodium.crypto_sign_keypair().privateKey;
      sk  = sodium.crypto_sign_ed25519_sk_to_seed(isk);
  }

  let signature;
  try {
    signature = sodium.crypto_sign_detached(payload, isk);
  } catch(ex) {
    return done(new Error('Libsodium error: ' + ex));
  }