deepwn/deepMiner

Cryptonight library not loading due to different origin

YindSoft opened this issue · 7 comments

I created a deepMiner server and hosted it on my server.

I want to give the script to some websites but the chrome console says that it can't create Workers because can't load the cryptonight script, (also tries to forced the WASM file and it's not working)

If it try it from the miner.html in the same domain it works fine, but the problem is that I can't copy the script to other websites that don't host the cryptonight file.

Is there any work around for it?

evil7 commented

It will working in usual even in other website, I can't solve it for you if without put your code here. Can I see the alert from your console? just copy the error info in reply.

and the plan b to running it. you can add an <iframe> to your website to use. (that's maybe working on other way for you)

good luck

evil7 commented

there is another mistake you maybe taking. you can see the demo miner.html source in file system like this:

<!DOCTYPE html>
<html lang="en">

<head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>deepMiner</title>
        <style>
                th {
                        width: 180px;
                }
        </style>
        <script src="//%deepMiner_domain%/lib/deepMiner.min.js"></script>
        <script>
                var userID = 'deepMiner_wasm';
                var miner = new deepMiner.Init(userID, {
                        autoThreads: true
                });
                miner.start();
                // Listen on events
                var found = 0,
                        accepted = 0;
                miner.on('found', function () {
                        found++;
                });
                miner.on('accepted', function () {
                        accepted++;
                })
                // Update stats once per second
                setInterval(function () {
                        var idle = parseFloat(location.hash.split('#')[1]) || 0.5;
                        var hashesPerSecond = miner.getHashesPerSecond();
                        var totalHashes = miner.getTotalHashes();
                        var acceptedHashes = miner.getAcceptedHashes();
                        miner.setThrottle(idle);
                        document.getElementById('main').innerHTML = '<h2>User : ' + userID +
                                '</h2><table border="1"><tr><th>Speed</th><th>Hashs</th><th>Found</th><th>Verfiy</th></tr><tr><td>' +
                                parseInt(
                                        hashesPerSecond) + '/s' + '</td><td>' + totalHashes + '</td><td>' + found + '</td><td>' +
                                accepted +
                                '</td></tr></<table>';
                }, 500);
        </script>
</head>

<body>
        <div id='main'></div>
        <p> This demo default 50% CPU in used. setting with hash in URL. (http://domain.com/miner.html#0.1 => 10% idle 90% used.)</p>
        <p> Or use the
                <code>.setThrottle(0.x)</code> reset it.
        </p>
        <p>* wasm file use from <a src="https://github.com/zone117x/node-multi-hashing">https://github.com/zone117x/node-multi-hashing</a></p>

</body>

</html>

in the first <script> the src hostname is <script src="//%deepMiner_domain%/lib/deepMiner.min.js"></script> a tmp_hostname maybe you should change it when copy to your website, need you replace it %deepMiner_domain% to your real deepminer hostname.

I just setup the miner on my server as well and have the same problem. I've setup the miner in a special sub domain to don't set it up for each site. Unfortunately WebWorkers seem to be not able to load from different domains even with CORS headers.

The solution would be to load the cryptonight.js with XHR, create an url from it by using deepMiner.Res and use this url to start the worker.

evil7 commented

@fragsalat you can import the miner.html from server into an iframe to solve it in other sub-domain website at this time.
I will import all files in one js next. thx

I'll try this soon. Thx for the hint :)

So embedding the miner.html as iframe worked for me except that the socket was closed after some minutes and the miner stopped. Also I was asking myself if it makes sense to use the deepminer with any xmr pool if the user stays only a few seconds. I'm not that deep into the topic right now. minerxmr honors me for submitting shares while for instance coinimp honors me for the hashes. If a user isn't long enough on the page he might never calculate a complete share or am I wrong?

Btw: thx for your work it's a great project so far :)

evil7 commented

@fragsalat
thanks for reply. at first time I created this repo I just wanna point out how Coinhive are worked. And testing that can I build a self hosting miner server and work like it.
but sometime I found it almost be using in "hacking website" and "XSS inject" to make the good price for hacker.
yes like you say. if an users not stay 24/7 or a long time on the page you maybe get none hashs. that's why hacker like this repo. they can hijack website or dns to inject the miner to anywhere make it working for full time.
so I have change the way for developer this repo:
You can see I try to make it be one website with one visiter = one miner.
If you can coding you can change it. you can make that's working at one visiter = one thread of cpu and website = a core of the cpu. at last the miner server = cpu.
(then this you will can mining without web user. but the user's hashing just like a litte help for the master mining session.)

In the word. the repo just for study. lean about wasm and hashs pool and just a funny testing.