Comparing version 0.0.2 to 0.0.4
#!/usr/bin/env node | ||
const fs = require('fs') | ||
const homedir = require('os').homedir() | ||
const exec = require('child_process').exec | ||
const handler = require('serve-handler') | ||
const http = require('http') | ||
function getPrivKey() { | ||
try { | ||
const fetchHeadDir = './.git/' | ||
var fetchHeadFile = fetchHeadDir + 'FETCH_HEAD' | ||
var fetchHead = fs.readFileSync(fetchHeadFile).toString() | ||
var repo = fetchHead | ||
.split(' ') | ||
.pop() | ||
.replace(':', '/') | ||
.replace('\n', '') | ||
const gitmarkRepoBase = homedir + '/.gitmark/repo' | ||
const gitmarkFile = gitmarkRepoBase + '/' + repo + '/gitmark.json' | ||
return require(gitmarkFile).privkey58 | ||
} catch (e) { | ||
const fetchHeadDir = './.git/' | ||
var fetchHeadFile = fetchHeadDir + 'FETCH_HEAD' | ||
var fetchHead = fs.readFileSync(fetchHeadFile).toString() | ||
var repo = fetchHead | ||
.split(' ') | ||
.pop() | ||
.replace(':', '/') | ||
.replace('\n', '') | ||
const gitmarkRepoBase = homedir + '/.gitmark/repo' | ||
const gitmarkFile = gitmarkRepoBase + '/' + repo + '/gitmark.json' | ||
console.log('no priv key found in', gitmarkFile) | ||
return undefined | ||
} | ||
} | ||
var port = 5000 | ||
@@ -27,5 +70,7 @@ var root = '.' | ||
for (var property in object) { | ||
if (object.hasOwnProperty(property) && | ||
property.toString().startsWith(prefix)) { | ||
return object[property]; | ||
if ( | ||
object.hasOwnProperty(property) && | ||
property.toString().startsWith(prefix) | ||
) { | ||
return { k: property, v: object[property] } | ||
} | ||
@@ -35,3 +80,2 @@ } | ||
function withdrawToAddress(address) { | ||
@@ -41,2 +85,3 @@ const amount = 1000 | ||
const pubkey = 'bLSMWcELqH9Y9ajmNuSrwbTCUVzJ94YpTb' | ||
const serverCmd = 'ssh ubuntu@157.90.144.229' | ||
@@ -64,3 +109,3 @@ // validate address | ||
// get txo: | ||
var txo = findValueByPrefix(ledger, "txo:") | ||
var txo = findValueByPrefix(ledger, 'txo:') | ||
if (!txo) { | ||
@@ -73,17 +118,38 @@ console.error('no txo found') | ||
// get amounts | ||
var newamount = txo - (amount + fee) | ||
var newamount = txo.v - (amount + fee) | ||
// get key | ||
var key = getPrivKey() | ||
console.log(key) | ||
// translate key into base58address | ||
// build tx | ||
// TODO: round division | ||
var createrawtransaction = `txc.sh '[{"txid": "${txo}", "vout": 0}]' '{"${pubkey}": ${(newamount / 1000000)}, "${address}": 0.000001}' key` | ||
var createrawtransaction = `${serverCmd} bin/txc.sh ${txo.k.split(':')[1] | ||
} ${txo.k.split(':')[2]} ${address} ${amount / 1000000} ${key} ${pubkey} ${newamount / 1000000}` | ||
console.log(createrawtransaction) | ||
console.log('sign and send that!') | ||
// trap response | ||
// if successful update ledger | ||
// add bitmark address | ||
// subtract txo | ||
// write ledger | ||
exec(createrawtransaction, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`exec error: ${error}`) | ||
return | ||
} | ||
console.log(`stdout: ${stdout}`) | ||
console.error(`stderr: ${stderr}`) | ||
stdout = stdout.replace('\n', '') | ||
var newtxo = `txo:${stdout}:1` | ||
console.log('newtxo', newtxo) | ||
if (stdout && stdout.length === 64) { | ||
// if successful update ledger | ||
// subtract txo | ||
delete ledger[txo.k] | ||
ledger[address] = amount | ||
ledger[newtxo] = newamount | ||
// write ledger | ||
console.log('ledger', JSON.stringify(ledger, null, 2)) | ||
fs.writeFileSync(ledgerFile, JSON.stringify(ledger, null, 2)) | ||
} | ||
}) | ||
} | ||
@@ -90,0 +156,0 @@ |
{ | ||
"name": "aa_faucet", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"description": "faucet", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"server": "pm2 start --name aa_faucet_server ./node_modules/skill-serve/bin/serve.js", | ||
"server": "pm2 start --name aa_faucet_server ./bin/serve.js", | ||
"updater": "pm2 start --name aa_faucet_updater ./node_modules/skill-updater/bin/deploy.sh --restart-delay=300000" | ||
@@ -24,2 +24,4 @@ }, | ||
"dependencies": { | ||
"fs": "^0.0.1-security", | ||
"os": "^0.1.2", | ||
"skill-serve": "^0.0.6", | ||
@@ -29,2 +31,2 @@ "skill-updater": "^0.0.4", | ||
} | ||
} | ||
} |
{ | ||
"txo:1f2a7447be9437d0712bf4e9650c156963291f3c5ea62f126e4c540e5ae24b3e": 1000000 | ||
} | ||
"bGRcox1bkqpm5A2MGqoUQAVjqxzL4VZnRc": 1000, | ||
"baBeRuDfxKd3JNACUNSgkXpxomrVmuZyGz": 1000, | ||
"bRStpv9ZdPjLi8xSJ1F9GnzRqXTtg9qhGX": 1000, | ||
"txo:9aaa0a067ae20afa2901c6f99c54228209a87b810b514a581923a7ae227fb9dc:1": 996970 | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33502
790
5
4
6
+ Addedfs@^0.0.1-security
+ Addedos@^0.1.2
+ Addedfs@0.0.1-security(transitive)
+ Addedos@0.1.2(transitive)