Example #1
0
    describe('> when compressed is true', function () {
      var key = new ECKey(null, true)
      assert(key.compressed)

      var key2 = new ECKey(secureRandom(32), true)
      assert(key2.compressed)
    })
Example #2
0
      it('should create a new ECKey ', function () {
        var bytes = secureRandom(32, {type: 'Array'})
        assert(Array.isArray(bytes))

        var key = new ECKey(bytes)
        assert.equal(key.privateKey.toString('hex'), new Buffer(bytes).toString('hex'))
        assert.equal(key.compressed, true)
      })
Example #3
0
      it('should create a new ECKey', function () {
        var bytes = secureRandom(32, {type: 'Buffer'})
        var buf = new Buffer(bytes)
        var key = ECKey(buf)
        assert.equal(key.privateKey.toString('hex'), buf.toString('hex'))

        key = ECKey(buf, true)
        assert(key.compressed)

        key = ECKey(buf, false)
        assert(!key.compressed)
      })
Example #4
0
 it('should verify the signature', function() {
   var randArr = secureRandom(32, {array: true})
   var privKey = BigInteger.fromByteArrayUnsigned(randArr)
   //var privKey = ecdsa.getBigRandom(ecparams.getN())
   var pubPoint = ecparams.getG().multiply(privKey)
   var pubKey = pubPoint.getEncoded(true) //true => compressed
   var msg = "hello world!"
   var shaMsg = sha256(msg)
   var signature = ECDSA.sign(shaMsg, privKey)
   var isValid = ECDSA.verify(shaMsg, signature, pubKey)
   T (isValid)
 })
Example #5
0
      it('should verify the signature', function () {
        var randArr = secureRandom(32, {array: true})
        var privKeyBigInt = BigInteger.fromByteArrayUnsigned(randArr)

        var pubPoint = curve.G.multiply(privKeyBigInt)
        // var pubKey = pubPoint.getEncoded(true) // true => compressed
        var msg = 'hello world!'
        var shaMsg = crypto.createHash('sha256').update(new Buffer(msg, 'utf8')).digest()
        var signature = ecdsa.sign(shaMsg, privKeyBigInt)
        var isValid = ecdsa.verify(shaMsg, signature, pubPoint)
        assert.ok(isValid)
      })
Example #6
0
 it('should verify the signature', function() {
   var randArr = secureRandom(32, {array: true});
   var privKey = BigInteger.fromByteArrayUnsigned(randArr);
   var ecdsa = new ECDSA(ecparams);
   //var privKey = ecdsa.getBigRandom(ecparams.getN())
   var pubPoint = ecparams.getG().multiply(privKey)
   var pubKey = pubPoint.getEncoded(false) //true => compressed, test fails then, must investigate
   var msg = "hello world!"
   var shaMsg = sha256(msg)
   var signature = ecdsa.sign(shaMsg, privKey)
   var isValid = ecdsa.verify(shaMsg, signature, pubKey)
   T (isValid)
 })
    getRandom(bits) {
        let _rand = 0;
        const _bytes = bits;

        while (_rand.toString(2).length < bits) {
            _rand = parseInt(
                secureRandom(bits, {type: 'Array'})
                .map(x => x.toString(16))
                .map(x => x.length === 2 ? x : `0${x}`)
                .join(''),
            16);
        }

        return _rand;
    }
Example #8
0
  this.newMasterKey = function(seed, network) {
    if (!seed) seed = rng(32, { array: true });
    masterkey = new HDNode(seed, network)

    // HD first-level child derivation method should be private
    // See https://bitcointalk.org/index.php?topic=405179.msg4415254#msg4415254
    accountZero = masterkey.derivePrivate(0)
    externalAccount = accountZero.derive(0)
    internalAccount = accountZero.derive(1)

    me.addresses = []
    me.changeAddresses = []

    me.outputs = {}
  }
Example #9
0
  this.newMasterKey = function(seed) {
    seed = seed || new Buffer(rng(32))
    masterkey = HDNode.fromSeedBuffer(seed, network)

    // HD first-level child derivation method should be hardened
    // See https://bitcointalk.org/index.php?topic=405179.msg4415254#msg4415254
    accountZero = masterkey.deriveHardened(0)
    externalAccount = accountZero.derive(0)
    internalAccount = accountZero.derive(1)

    me.addresses = []
    me.changeAddresses = []

    me.outputs = {}
  }
Example #10
0
  hashReport: function (branchId, votePeriod, decisions) {
    var saltBytes = secureRandom(32);
    var salt = bytesToHex(saltBytes);

    var pendingReports = this.flux.store('report').getState().pendingReports;
    pendingReports.push({
      branchId,
      votePeriod,
      decisions,
      salt,
      reported: false
    });
    this.flux.actions.report.storeReports(pendingReports);

    // Hash the report and submit it to the network.
    var ethereumClient = this.flux.store('config').getEthereumClient();
    var hash = Augur.hashReport(decisions, salt);
    console.log('Submitting hash for period', votePeriod, 'reports:', hash);
    var log = x => console.log('Augur.submitReportHash callback:', x);
    Augur.submitReportHash(branchId, hash, votePeriod, log, log, log);

    this.dispatch(constants.report.UPDATE_PENDING_REPORTS, {pendingReports});
  },
Example #11
0
 nextBytes: function(arr) {
   var byteArr = secureRandom(arr.length)
   for (var i = 0; i < byteArr.length; ++i)
     arr[i] = byteArr[i]
 }
Example #12
0
function uid(n) {
	n = (typeof n === 'undefined') ? 32 : n;
	var br = secureRandom(Math.floor(n % 2 === 0 ? (n / 2) : ((n / 2) + 1) ), {type: 'Buffer'});
	var r = br.toString('hex');
	return r.substring(0, n);
}
Example #13
0
var secureRandom = require("secure-random");
var key = secureRandom(128, {type:"Buffer"}).toString("base64");
console.log(key);
Example #14
0
#! ./node_modules/babel-cli/bin/babel-node.js

/* eslint-disable no-console*/
import secureRandom from 'secure-random';

console.log(secureRandom(128, { type: 'Buffer' }).toString('base64'));
Example #15
0
function randomBuf(s) {
  return new Buffer(secureRandom(s))
}
Example #16
0
 it('should create a new ECKey ', function () {
   var buf = secureRandom(32, {type: 'Buffer'})
   var key = new ECKey(buf)
   assert.equal(key.privateKey.toString('hex'), buf.toString('hex'))
   assert.equal(key.compressed, true)
 })
Example #17
0
exports.generateSecret = function () {
  var arr = secureRandom(16);
  return arrayToString(arr);
};
Example #18
0
import secureRandom from "secure-random"

const { npm_config__graphene_local_secret_secret } = process.env

if( ! npm_config__graphene_local_secret_secret ) {
    const buf = secureRandom(256, {type: 'Buffer'})
    const local_secret = buf.toString('base64')
    console.error("# WARN you need to run this command to lock-in your secret.")
    console.error("# Add the following to ./.npmrc")
    console.error("@graphene/local-secret:secret = '%s'", local_secret)
    console.error()
    process.env.npm_config__graphene_local_secret_secret = local_secret
}

export default process.env.npm_config__graphene_local_secret_secret
Example #19
0
var secureRandom = require('secure-random');

module.exports = {
    'secret': secureRandom(256, {type: 'Buffer'}),
    'database': 'mongodb://*****:*****@ds023425.mlab.com:23425/gitripped'
}