hubot-openassets
Advanced tools
Comparing version 0.4.3 to 0.5.0
{ | ||
"name": "hubot-openassets", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"description": "Hubot script for managing and sending assets based on the Open Assets protocol", | ||
@@ -24,4 +24,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"bs58": "3.0.0", | ||
"bufferput": "0.1.1", | ||
"strict-mode": "^0.4.2" | ||
} | ||
} |
@@ -26,2 +26,6 @@ // Description: | ||
var Base58 = require('bs58'); | ||
var Put = require('bufferput'); | ||
var crypto = require('crypto'); | ||
module.exports = function(robot) { | ||
@@ -81,5 +85,6 @@ | ||
let content = this.getContent(); | ||
Object.keys(content).forEach(name => { | ||
if (content[name] === address) { return name; } | ||
}); | ||
let keys = Object.keys(content); | ||
for (var i = 0; i< keys.length; i++) { | ||
if (content[keys[i]] === address) { return keys[i]; } | ||
} | ||
} | ||
@@ -145,2 +150,16 @@ }; | ||
function addressFromBitcoinAddress(btcAddress) { | ||
function sha256(data) { | ||
return new Buffer(crypto.createHash('sha256').update(data).digest('binary'), 'binary'); | ||
} | ||
var btcAddr = new Buffer(Base58.decode(btcAddress)); | ||
var btcBuff = new Put() | ||
.word8(19) | ||
.put(btcAddr.slice(0, -4)) | ||
var btcCheck = sha256(sha256(btcBuff.buffer())); | ||
btcBuff.put(btcCheck.slice(0,4)) | ||
return Base58.encode(btcBuff.buffer()); | ||
} | ||
robot.hear(new RegExp(`${robotKeyword} show (.+)`, 'i'), function(hearResponse) { | ||
@@ -164,8 +183,13 @@ balanceOf(hearResponse.match[1], function(assetDetails) { | ||
} | ||
var owners = JSON.parse(body).owners; | ||
var total = owners.length > 10 ? 10 : owners.length; | ||
for (var i=0; i<total; i++) { | ||
var name = addressBook.lookupName(owners[i].address) || owners[i].address; | ||
var asset = JSON.parse(body); | ||
var owners = asset.owners; | ||
var displayTotal = owners.length > 10 ? 10 : owners.length; | ||
var totalAssets = 0; | ||
owners.forEach(function(o) { totalAssets += parseInt(o.asset_quantity); }); | ||
for (var i=0; i<displayTotal; i++) { | ||
var oaAddress = addressFromBitcoinAddress(owners[i].address); | ||
var name = addressBook.lookupName(oaAddress) || oaAddress; | ||
hearResponse.send(name + ': ' + owners[i].asset_quantity); | ||
} | ||
hearResponse.send(`${totalAssets} ${robotKeyword} total, owned by ${owners.length} addresses. details: https://www.coinprism.info/asset/${process.env.OA_ASSET_ID}/owners`); | ||
}); | ||
@@ -247,4 +271,11 @@ }); | ||
.auth(process.env.OA_SERVER_USERNAME, process.env.OA_SERVER_PASSWORD) | ||
.query(params).post()(cb); | ||
.query(params).post()(function(err, res, body) { | ||
if(err || res.statusCode !== 200) { | ||
console.log("sending assets failed"); | ||
} | ||
console.log(body); | ||
cb(err, res, body); | ||
}); | ||
} | ||
}; |
13
test.js
var Base58 = require('bs58'); | ||
var BufferPut = require('bufferput'); | ||
var Put = require('bufferput'); | ||
var crypto = require('crypto'); | ||
var buffertools = require('buffertools') | ||
var BufferPut = require('bufferput'); | ||
@@ -14,12 +11,12 @@ function sha256(data) { | ||
function addressFromBitcoinAddress(btcAddress) { | ||
var btcAddr = Base58.decode(btcAddress); | ||
var btcAddr = new Buffer(Base58.decode(btcAddress)); | ||
var btcBuff = new Put() | ||
.word8(19) | ||
.put(btcAddr.slice(0, -4)); | ||
console.log(btcBuff.buffer()); | ||
var btcCheck = sha256(btcBuff.buffer()) | ||
.put(btcAddr.slice(0, -4)) | ||
var btcCheck = sha256(sha256(btcBuff.buffer())); | ||
btcBuff.put(btcCheck.slice(0,4)) | ||
return Base58.encode(btcBuff.buffer()); | ||
} | ||
console.log(addressFromBitcoinAddress('18mkjg6pRdJg1SEkj4riwaBs19kU4URtC9')); | ||
console.log(addressFromBitcoinAddress('12ukurZsDMtSSJ1Qad59LiFqVM8YQnbTen')); |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 8 instances 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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13164
257
0
3
14
+ Addedbs58@3.0.0
+ Addedbufferput@0.1.1
+ Addedbase-x@1.1.0(transitive)
+ Addedbs58@3.0.0(transitive)
+ Addedbufferput@0.1.1(transitive)