How to use the bitcore.crypto function in bitcore

To help you get started, we’ve selected a few bitcore 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 moneybutton / yours-core / lib / walletfile.js View on Github external
WalletFile.fromRandom = function fromRandom () {
  // 128 bit buffers produce 12-word mnemonics, which are both secure and
  // relatively easy to remember (compared to 256-bit/24-word mnemonics)
  var randbuf = bitcore.crypto.Random.getRandomBuffer(128 / 8)
  return WalletFile.fromSeed(randbuf)
}
github bitpay / bitcore / lib / signutils.js View on Github external
var _ = require('lodash');
var Bitcore = require('bitcore');
var PrivateKey = Bitcore.PrivateKey;
var PublicKey = Bitcore.PublicKey;
var Signature = Bitcore.crypto.Signature;
var ECDSA = Bitcore.crypto.ECDSA;
var Hash = Bitcore.crypto.Hash;
var BufferReader = Bitcore.encoding.BufferReader;



var SignUtils = function() {};

/* TODO: It would be nice to be compatible with bitcoind signmessage. How
 * the hash is calculated there? */
SignUtils.hash = function(text) {
  var buf = new Buffer(text);
  var ret = Hash.sha256sha256(buf);
  ret = new BufferReader(ret).readReverse();
  return ret;
};
github bitpay / bitcore-node / lib / block.js View on Github external
'use strict';

var bitcore = require('bitcore');
var BufferReader = bitcore.encoding.BufferReader;
var BufferWriter = bitcore.encoding.BufferWriter;
var Hash = bitcore.crypto.Hash;

//TODO: use bitcore.Block

function Block(obj) {
  /* jshint maxstatements: 25 */
  if (!(this instanceof Block)) {
    return new Block(obj);
  }

  this.version = obj.version || 1;
  this.prevHash = obj.prevHash;

  if (!obj.hasOwnProperty('prevHash')) {
    throw new TypeError('"prevHash" is expected');
  }
  if (!obj.timestamp) {
github bitpay / bitcore / lib / walletutils.js View on Github external
'use strict';

var _ = require('lodash');
var $ = require('preconditions').singleton();
var sjcl = require('sjcl');

var Bitcore = require('bitcore');
var Address = Bitcore.Address;
var PrivateKey = Bitcore.PrivateKey;
var PublicKey = Bitcore.PublicKey;
var crypto = Bitcore.crypto;
var encoding = Bitcore.encoding;
var Utils = require('./utils');

function WalletUtils() {};

/* TODO: It would be nice to be compatible with bitcoind signmessage. How
 * the hash is calculated there? */
WalletUtils.hashMessage = function(text) {
  $.checkArgument(text);
  var buf = new Buffer(text);
  var ret = crypto.Hash.sha256sha256(buf);
  ret = new Bitcore.encoding.BufferReader(ret).readReverse();
  return ret;
};
github bitpay / bitcore / lib / signutils.js View on Github external
var _ = require('lodash');
var Bitcore = require('bitcore');
var PrivateKey = Bitcore.PrivateKey;
var PublicKey = Bitcore.PublicKey;
var Signature = Bitcore.crypto.Signature;
var ECDSA = Bitcore.crypto.ECDSA;
var Hash = Bitcore.crypto.Hash;
var BufferReader = Bitcore.encoding.BufferReader;



var SignUtils = function() {};

/* TODO: It would be nice to be compatible with bitcoind signmessage. How
 * the hash is calculated there? */
SignUtils.hash = function(text) {
  var buf = new Buffer(text);
  var ret = Hash.sha256sha256(buf);
  ret = new BufferReader(ret).readReverse();
  return ret;
};
github bitpay / bitcore-node / test / chain.unit.js View on Github external
'use strict';

var chai = require('chai');
var should = chai.should();
var sinon = require('sinon');
var memdown = require('memdown');

var index = require('../');
var DB = index.DB;
var Chain = index.Chain;
var bitcore = require('bitcore');
var BufferUtil = bitcore.util.buffer;
var Block = bitcore.Block;
var BN = bitcore.crypto.BN;

var chainData = require('./data/testnet-blocks.json');

describe('Bitcoin Chain', function() {

  describe('@constructor', function() {

    it('can create a new instance with and without `new`', function() {
      var chain = new Chain();
      chain = Chain();
    });

  });

  describe('#start', function() {
    it('should call the callback when base chain is initialized', function(done) {
github moneybutton / yours-core / lib / workers.js View on Github external
return q(pool.exec('sign', [hashhex, privateKeyHex, endian])).then(function (sighex) {
    return bitcore.crypto.Signature.fromBuffer(new Buffer(sighex, 'hex'))
  })
}
github moneybutton / yours-core / lib / contentStore-browser.js View on Github external
ContentStore.prototype.putContent = function putContent (content) {
  var hash = bitcore.crypto.Hash.sha256(new Buffer(content, 'utf8')).toString('hex')
  this.db[hash] = content
  return hash
}
github bitpay / bitcore-p2p / lib / messages / message.js View on Github external
'use strict';

var bitcore = require('bitcore');
var BufferWriter = bitcore.encoding.BufferWriter;
var Hash = bitcore.crypto.Hash;

/**
 * Base message that can be inherited to add an additional
 * `getPayload` method to modify the message payload.
 * @param {Object=} options
 * @param {String=} options.command
 * @param {Number=} options.magicNumber
 * @constructor
 */
function Message(arg, options) {
  this.command = options.command;
  this.magicNumber = options.magicNumber;
}

/**
 * @returns {Buffer} - Serialized message
github bitpay / bitcore / lib / walletutils.js View on Github external
WalletUtils.privateKeyToAESKey = function(privKey) {
  var pk = Bitcore.PrivateKey.fromString(privKey);
  return Bitcore.crypto.Hash.sha256(pk.toBuffer()).slice(0, 16).toString('base64');
};