Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let ecpair = this.slp.BITBOX.ECPair.fromWIF(wif);
// we set the previous output for the input
// again, this is for bitcore-lib input sig generation
txn.inputs[input_index].output = new Bitcore.Transaction.Output({
satoshis: input_satoshis,
script: redeemScript
});
// produce a signature that is specific to this input
// NOTE: currently only uses ecdsa
let privateKey = new Bitcore.PrivateKey(wif);
var sig = Bitcore.Transaction.Sighash.sign(txn, privateKey, sigHashType, input_index, redeemScript, Bitcore.crypto.BN.fromNumber(input_satoshis));
// add have to add the sighash type manually.. :(
// NOTE: signature is in DER format and is specific to ecdsa & sigHash 0x41
let sigBuf = Buffer.concat([ sig.toDER(), Buffer.alloc(1, sigHashType) ]);
// we can return a object conforming to InputSigData interface
return {
index: input_index,
pubKeyBuf: ecpair.getPublicKeyBuffer(),
signatureBuf: sigBuf
}
}
'use strict';
var bitcore = require('bitcore-lib-cash');
var BufferUtil = bitcore.util.buffer;
var Hash = bitcore.crypto.Hash;
var $ = bitcore.util.preconditions;
/**
* A factory to build Bitcoin protocol messages.
* @param {Object=} options
* @param {Network=} options.network
* @param {Function=} options.Block - A block constructor
* @param {Function=} options.BlockHeader - A block header constructor
* @param {Function=} options.MerkleBlock - A merkle block constructor
* @param {Function=} options.Transaction - A transaction constructor
* @constructor
*/
function Messages(options) {
this.builder = Messages.builder(options);
// map message constructors by name
getNonce: function getNonce() {
return bitcore.crypto.Random.getRandomBuffer(8);
},
writeIP: function writeIP(ip, bw) {
import * as eth from "ethereumjs-wallet";
import * as ethUtil from "ethereumjs-util";
import { compose, take, head, reduce } from "ramda";
import { generateMnemonic } from "bip39";
import { config, curNames } from "../AppConfig";
const Web3 = require("web3");
const abi = require("human-standard-token-abi");
const EthereumTx = require("ethereumjs-tx");
const createBuf = str => new Buffer(str);
const mkBCHpk = compose(
bch.crypto.BN.fromBuffer,
bch.crypto.Hash.sha256,
createBuf
);
export const toSatoshi = btc => btc * 100000000;
export const toBTC = satoshi => satoshi / 100000000;
export const toFiat = (value, course) => (value * course).toFixed(2);
export const toETH = gWei => gWei / 10000000000;
export const toGwei = v => v * 1000000000;
export const toETHFromWei = wei => wei / 1000000000000000000;
app.import_mnemonic = (mnemonic) => {
if (! bip39.validateMnemonic(mnemonic)) {
window.alert('Invalid mnemonic');
return false;
}
const seed = bip39.mnemonicToSeed(mnemonic);
const hash = bch.crypto.Hash.sha256(seed);
const bn = bch.crypto.BN.fromBuffer(hash);
const key = new bch.PrivateKey(bn);
const wif = key.toWIF();
return wif;
};
import * as ethUtil from "ethereumjs-util";
import { compose, take, head, reduce } from "ramda";
import { generateMnemonic } from "bip39";
import { config, curNames } from "../AppConfig";
const Web3 = require("web3");
const abi = require("human-standard-token-abi");
const EthereumTx = require("ethereumjs-tx");
const createBuf = str => new Buffer(str);
const mkBCHpk = compose(
bch.crypto.BN.fromBuffer,
bch.crypto.Hash.sha256,
createBuf
);
export const toSatoshi = btc => btc * 100000000;
export const toBTC = satoshi => satoshi / 100000000;
export const toFiat = (value, course) => (value * course).toFixed(2);
export const toETH = gWei => gWei / 10000000000;
export const toGwei = v => v * 1000000000;
export const toETHFromWei = wei => wei / 1000000000000000000;
export const calculateTotalBalance = walletBalanceList => {
'use strict';
var bitcore = require('bitcore-lib-cash');
var $ = bitcore.util.preconditions;
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 {Network=} options.network
* @constructor
*/
function Message(options) {
this.command = options.command;
this.network = options.network;
}
/**
* @returns {Buffer} - Serialized message
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var BufferWriter = bitcore.encoding.BufferWriter;
var BufferReader = bitcore.encoding.BufferReader;
var BN = bitcore.crypto.BN;
var utils = require('../utils');
var packageInfo = require('../../../package.json');
/**
* The version message is used on connection creation to advertise
* the type of node. The remote node will respond with its version, and no
* communication is possible until both peers have exchanged their versions.
*
* @see https://en.bitcoin.it/wiki/Protocol_documentation#version
* @param {Object=} arg - properties for the version message
* @param {Buffer=} arg.nonce - a random 8 byte buffer
* @param {String=} arg.subversion - version of the client
* @param {BN=} arg.services
* @param {Date=} arg.timestamp
* @param {Number=} arg.startHeight
app.import_mnemonic = (mnemonic) => {
if (! bip39.validateMnemonic(mnemonic)) {
window.alert('Invalid mnemonic');
return false;
}
const seed = bip39.mnemonicToSeed(mnemonic);
const hash = bch.crypto.Hash.sha256(seed);
const bn = bch.crypto.BN.fromBuffer(hash);
const key = new bch.PrivateKey(bn);
const wif = key.toWIF();
return wif;
};
'use strict';
var dns = require('dns');
var EventEmitter = require('events').EventEmitter;
var bitcore = require('bitcore-lib-cash');
var sha256 = bitcore.crypto.Hash.sha256;
var Peer = require('./peer');
var Networks = bitcore.Networks;
var util = require('util');
var net = require('net');
function now() {
return Math.floor(new Date().getTime() / 1000);
}
/**
* A pool is a collection of Peers. A pool will discover peers from DNS seeds, and
* collect information about new peers in the network. When a peer disconnects the pool
* will connect to others that are available to maintain a max number of
* ongoing peer connections. Peer events are relayed to the pool.
*
* @example