Socket
Socket
Sign inDemoInstall

coin-hive

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coin-hive - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

bin/help

9

config/defaults.js
module.exports = {
SITE_KEY: '3kK4xAVlA6XXVRmuR6RRGYIxEsTku2rn',
PORT: 3002,
HOST: 'localhost',
INTERVAL: 1000
}
port: 3002,
host: 'localhost',
interval: 1000,
threads: -1
}
{
"name": "coin-hive",
"version": "1.1.1",
"version": "1.2.0",
"description": "",

@@ -12,2 +12,3 @@ "main": "src/index.js",

"express": "^4.15.4",
"minimist": "^1.2.0",
"puppeteer": "^0.10.2"

@@ -25,3 +26,7 @@ },

"url": "git+https://github.com/cazala/coin-hive.git"
},
"engines": {
"node": ">=8.0",
"npm": ">=5.0"
}
}

@@ -5,2 +5,18 @@ # Coin-Hive [![Build Status](https://travis-ci.org/cazala/coin-hive.svg?branch=master)](https://travis-ci.org/cazala/coin-hive)

## Disclaimer
This project has nothing to do with `coin-hive.com`
## What is this?
This package just does the following:
1. Launch a local server that serves a page where CoinHive's Javascript miner is embedded.
2. Launch puppeteer (a headless chrome) pointing to that page.
3. Expose an API that allows you to interact with that miner from node.js (starting, stopping, etc).
The purpose of this package is to allow you to run CoinHive's JavaScript miner from node.js (otherwise it only works on the browser).
## Install

@@ -15,7 +31,15 @@

```js
var CoinHive = require('coin-hive');
const CoinHive = require('coin-hive');
(async () => {
// Options are not mandatory, defaults values:
const options = {
interval: 1000, // interval for "update"
port: 3002, // puppeteer port
host: 'localhost', // puppeteer host,
threads: -1 // number of threads to start with, defaults to navigator.hardwareConcurrency see https://coin-hive.com/documentation/miner#constructor-options
}
// Create miner
var miner = await CoinHive('ZM4gjqQ0jh0jbZ3tZDByOXAjyotDbo00'); // Coin-Hive's Site Key
const miner = await CoinHive('ZM4gjqQ0jh0jbZ3tZDByOXAjyotDbo00', options); // Coin-Hive's Site Key

@@ -42,3 +66,13 @@ // Start miner

```
coin-hive <site-key>
Usage: coin-hive <site-key>
<site-key>: You CoinHive Site Key
Options:
--interval Interval between updates (logs)
--port Port for the miner server
--host Host for the miner server
--threads Number of threads for the miner
--proxy Proxy socket 5/4, for example: socks5://127.0.0.1:9050
```

@@ -54,4 +88,8 @@

- `miner.kill()`: Stop mining, disconnect from the pool, shutdown the server and close the headless browser. Returns a promise that will resolve once the miner is dead.
- `miner.on(event, callback)`: Specify a callback for an event. The event types are:
- `update`: Informs `hashesPerSecond`, `totalHashes` and `acceptedHashes`.
- `open`: The connection to our mining pool was opened. Usually happens shortly after miner.start() was called.

@@ -71,3 +109,3 @@

- `miner.rpc(methodName, argsArray)`: This method allows to interact with the Coin-Hive miner instance. It returns a Promise that resolves the the value of the remote method that was called. The miner intance API can be [found here](https://coin-hive.com/documentation/miner#miner-is-running). Here's an example:
- `miner.rpc(methodName, argsArray)`: This method allows you to interact with the Coin-Hive miner instance. It returns a Promise that resolves the the value of the remote method that was called. The miner intance API can be [found here](https://coin-hive.com/documentation/miner#miner-is-running). Here's an example:

@@ -88,18 +126,18 @@ ```js

- `SITE_KEY`: Coin-Hive's Site Key
- `COINHIVE_SITE_KEY`: Coin-Hive's Site Key
- `INTERVAL`: The interval on which the miner reports an update
- `COINHIVE_INTERVAL`: The interval on which the miner reports an update
- `PORT`: The port that will be used to launch the server, and where puppeteer will point to
- `COINHIVE_THREADS`: Number of threads
- `HOST`: The host that will be used to launch the server, and where puppeteer will point to
- `COINHIVE_PORT`: The port that will be used to launch the server, and where puppeteer will point to
- `PUPPETEER_URL`: In case you don't want to point puppeteer to the local server, you can use this to make it point somewhere else where the miner is served (ie: `PUPPETEER_URL=http://coin-hive.herokuapp.com`)
- `COINHIVE_HOST`: The host that will be used to launch the server, and where puppeteer will point to
- `COINHIVE_PUPPETEER_URL`: In case you don't want to point puppeteer to the local server, you can use this to make it point somewhere else where the miner is served (ie: `PUPPETEER_URL=http://coin-hive.herokuapp.com`)
- `COINHIVE_PROXY`: Proxy socket 5/4 (ie: `COINHIVE_PROXY=socks5://127.0.0.1:9050`)
## Requisites
+ Node v8+
## Disclaimer
I have nothing to do with `coin-hive.com`

@@ -5,27 +5,23 @@ const server = require('./server');

module.exports = async function getRunner(
siteKey = defaults.SITE_KEY,
interval = defaults.INTERVAL,
port = defaults.PORT,
host = defaults.HOST
) {
module.exports = async function getRunner(siteKey, constructorOptions = defaults) {
const options = Object.assign({}, defaults, constructorOptions)
const miner = await new Promise((resolve, reject) => {
var minerServer = server().listen(
process.env.SERVER_PORT || process.env.PORT || port,
process.env.SERVER_HOST || process.env.HOST || host,
async (err) => {
if (err) {
return reject(err);
}
return resolve(
puppeteer({
siteKey,
interval,
port,
host,
server: minerServer
})
);
const minerServer = server().listen(options.port, options.host, async (err) => {
if (err) {
return reject(err);
}
);
return resolve(
puppeteer({
siteKey,
interval: options.interval,
port: options.port,
host: options.host,
threads: options.threads,
server: minerServer,
proxy: options.proxy
})
);
});
});

@@ -32,0 +28,0 @@ await miner.init();

@@ -6,6 +6,10 @@ var miner = null;

// Init miner
function init(siteKey, interval = 1000) {
function init({siteKey, interval = 1000, threads = null}) {
// Create miner
miner = new CoinHive.Anonymous(siteKey);
if (threads > 0) {
miner.setNumThreads(threads)
}
// Listen on events

@@ -36,3 +40,4 @@ miner.on('found', function () {

totalHashes: miner.getTotalHashes(),
acceptedHashes: miner.getAcceptedHashes()
acceptedHashes: miner.getAcceptedHashes(),
threads: miner.getNumThreads()
}

@@ -57,2 +62,2 @@ console.log('update:', update)

}
}
}
const EventEmitter = require('events');
const puppeteer = require('puppeteer');
const defaults = require('../config/defaults');
class Puppeteer extends EventEmitter {
constructor(siteKey, interval, port, host, server) {
constructor({siteKey, interval, host, port, server, threads, proxy}) {
super();
this.inited = false;
this.dead = false;
this.siteKey = siteKey;
this.interval = interval;
this.host = host;

@@ -18,2 +15,4 @@ this.port = port;

this.page = null;
this.proxy = proxy;
this.options = {siteKey, interval, threads};
}

@@ -25,3 +24,3 @@

}
this.browser = await puppeteer.launch({ args: ['--no-sandbox'] });
this.browser = await puppeteer.launch({ args: this.proxy ? ['--no-sandbox','--proxy-server='+this.proxy] : ['--no-sandbox'] });
return this.browser;

@@ -49,3 +48,3 @@ }

const page = await this.getPage();
const url = process.env.PUPPETEER_URL || `http://${this.host}:${this.port}`;
const url = process.env.COINHIVE_PUPPETEER_URL || `http://${this.host}:${this.port}`;
await page.goto(url);

@@ -55,3 +54,3 @@ await page.exposeFunction('found', () => this.emit('found'));

await page.exposeFunction('update', (data, interval) => this.emit('update', data, interval));
await page.evaluate((siteKey, interval) => window.init(siteKey, interval), this.siteKey, this.interval);
await page.evaluate(({siteKey, interval, threads}) => window.init({siteKey, interval, threads}), this.options);

@@ -84,3 +83,2 @@ this.inited = true;

this.server.close();
console.log('server closed')
}

@@ -98,10 +96,3 @@ } catch (e) { console.log('Error closing server', e) }

module.exports = function getPuppeteer(options = {}) {
const siteKey = process.env.SITE_KEY || options.siteKey || defaults.SITE_KEY;
const interval = process.env.INTERVAL || options.interval || defaults.INTERVAL;
const port = process.env.PUPPETEER_PORT || process.env.PORT || options.port || defaults.PORT;
const host = process.env.PUPPETEER_HOST || process.env.HOST || options.host || defaults.HOST;
const server = options.server || null;
return new Puppeteer(siteKey, interval, port, host, server);
}
return new Puppeteer(options);
}
const expect = require('expect');
const defaults = require('../config/defaults.js')
const CoinHive = require('../src');

@@ -7,3 +8,3 @@

it('should mine', async () => {
var miner = await CoinHive();
var miner = await CoinHive(defaults.SITE_KEY);
await miner.start();

@@ -21,3 +22,3 @@ return new Promise(resolve => {

it('should do RPC', async () => {
var miner = await CoinHive();
var miner = await CoinHive(defaults.SITE_KEY);
let isRunning = await miner.rpc('isRunning');

@@ -35,2 +36,2 @@ expect(isRunning).toBe(false);

});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc