diff --git a/.gitignore b/.gitignore index c936e67..eb8f0b3 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ isolate-*-v8.log processed.txt .env +package-lock.json diff --git a/README.md b/README.md index b3cbb60..80f17d4 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ You can remotely control your wallet via chat interface from devices listed in ` * `pay ` to request withdrawal from the headless wallet to your `payout_address`, or `pay ` to withdraw another asset. * `mci`: to get the last stable MCI on the headless wallet; * `space`: to get the file sizes of data folder; +* `ip`: to get the IP address of the wallet; +* `ip-proxy`: to get the IP address of the wallet through socks proxy; ![Chat with headless wallet](chat-with-headless.png) diff --git a/package.json b/package.json index 5d45ca2..b7e844b 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,11 @@ "secp256k1": "secp256k1/js" }, "dependencies": { - "ocore": "git+https://github.com/byteball/ocore.git", "bitcore-lib": "^0.13.14", "bitcore-mnemonic": "~1.0.0", - "json-rpc2": "^1.0.2" + "json-rpc2": "^1.0.2", + "ocore": "git+https://github.com/byteball/ocore.git", + "request": "^2.88.0", + "socks": "1.1.10" } } diff --git a/start.js b/start.js index 93f04ed..16e7682 100644 --- a/start.js +++ b/start.js @@ -22,6 +22,8 @@ var storage = require('ocore/storage.js'); var Mnemonic = require('bitcore-mnemonic'); var Bitcore = require('bitcore-lib'); var readline = require('readline'); +var request = require('request'); +var socks = process.browser ? null : require('socks'+''); var KEYS_FILENAME = appDataDir + '/' + (conf.KEYS_FILENAME || 'keys.json'); var wallet_id; @@ -659,6 +661,18 @@ function handleText(from_address, text, onUnknown){ }); break; + case 'ip': + getMyIPAddress(false, function(data) { + device.sendMessageToDevice(from_address, 'text', data); + }); + break; + + case 'ip-proxy': + getMyIPAddress(true, function(data) { + device.sendMessageToDevice(from_address, 'text', data); + }); + break; + default: if (onUnknown){ onUnknown(from_address, text); @@ -700,6 +714,36 @@ function getFileSizes(rootDir, cb) { }); } +function getMyIPAddress(testProxy, cb){ + var options = {'url': 'https://api.ipify.org/?format=json', 'json': true, 'agent': null, 'timeout': 3000}; + if (testProxy === true){ + if (socks && conf.socksHost && conf.socksPort){ + options.agent = new socks.Agent({ + proxy: { + ipaddress: conf.socksHost, + port: conf.socksPort, + type: 5, + authentication: { + username: "dummy", + password: "dummy" + } + } + }, true); + } + else { + return cb('Error, socks configuration missing.'); + } + } + request(options, function(err, res, body){ + if (!err && res.statusCode == 200){ + return cb(body.ip); + } else { + return cb('Error requesting IP address.'); + } + }); +} + + function analyzePayParams(amountText, assetText, cb){ // expected: // amountText = amount; only digits