Comparing version 3.2.5 to 3.3.0
334
index.js
@@ -43,25 +43,2 @@ (function() { | ||
Stampery.prototype._convertSiblingArray = function(siblings) { | ||
if (siblings === '') { | ||
return []; | ||
} else { | ||
return siblings.map(function(v, i) { | ||
return v.toString(); | ||
}); | ||
} | ||
}; | ||
Stampery.prototype._recursiveConvert = function(proof) { | ||
return proof.map((function(_this) { | ||
return function(e) { | ||
if (e instanceof Buffer) { | ||
e = e.toString('utf8'); | ||
} else if (e instanceof Array) { | ||
e = _this._recursiveConvert(e); | ||
} | ||
return e; | ||
}; | ||
})(this)); | ||
}; | ||
function Stampery(clientSecret, beta) { | ||
@@ -71,9 +48,10 @@ var host, sock; | ||
this.beta = beta; | ||
this.receiveMissedProofs = __bind(this.receiveMissedProofs, this); | ||
this.checkRootInChain = __bind(this.checkRootInChain, this); | ||
this.checkSiblings = __bind(this.checkSiblings, this); | ||
this.prove = __bind(this.prove, this); | ||
this._getETHtx = __bind(this._getETHtx, this); | ||
this._getBTCtx = __bind(this._getBTCtx, this); | ||
this._merkleMixer = __bind(this._merkleMixer, this); | ||
this.receiveMissedProofs = __bind(this.receiveMissedProofs, this); | ||
this._handleQueueConsumingForHash = __bind(this._handleQueueConsumingForHash, this); | ||
this._sumSiblings = __bind(this._sumSiblings, this); | ||
this._auth = __bind(this._auth, this); | ||
@@ -94,2 +72,25 @@ this._connectRabbit = __bind(this._connectRabbit, this); | ||
Stampery.prototype._convertSiblingArray = function(siblings) { | ||
if (siblings === '') { | ||
return []; | ||
} else { | ||
return siblings.map(function(v, i) { | ||
return v.toString(); | ||
}); | ||
} | ||
}; | ||
Stampery.prototype._recursiveConvert = function(proof) { | ||
return proof.map((function(_this) { | ||
return function(e) { | ||
if (e instanceof Buffer) { | ||
e = e.toString('utf8'); | ||
} else if (e instanceof Array) { | ||
e = _this._recursiveConvert(e); | ||
} | ||
return e; | ||
}; | ||
})(this)); | ||
}; | ||
Stampery.prototype._connectRabbit = function() { | ||
@@ -155,13 +156,2 @@ var err, ___iced_passed_deferral, __iced_deferrals, __iced_k; | ||
Stampery.prototype.hash = function(data, cb) { | ||
var sha3; | ||
if (data instanceof stream) { | ||
return this._hashFile(data, cb); | ||
} else { | ||
sha3 = new SHA3.SHA3Hash(); | ||
sha3.update(data); | ||
return cb(sha3.digest('hex').toUpperCase()); | ||
} | ||
}; | ||
Stampery.prototype._sha3Hash = function(stringToHash, cb) { | ||
@@ -203,3 +193,3 @@ var hash; | ||
})(), | ||
lineno: 88 | ||
lineno: 80 | ||
})); | ||
@@ -219,71 +209,2 @@ __iced_deferrals._fulfill(); | ||
Stampery.prototype.calculateProof = function(hash, siblings, cb) { | ||
var idx, lastComputedleaf, sibling; | ||
lastComputedleaf = hash; | ||
for (idx in siblings) { | ||
sibling = siblings[idx]; | ||
console.log("[SIBLINGS] Calculating sibling " + idx, lastComputedleaf, sibling); | ||
this._sumSiblings(lastComputedleaf, sibling, function(sum) { | ||
console.log("[SIBLINGS] Calculated " + sum); | ||
return lastComputedleaf = sum; | ||
}); | ||
} | ||
return cb(lastComputedleaf); | ||
}; | ||
Stampery.prototype._sumSiblings = function(leaf1, leaf2, cb) { | ||
var hash, ___iced_passed_deferral, __iced_deferrals, __iced_k; | ||
__iced_k = __iced_k_noop; | ||
___iced_passed_deferral = iced.findDeferral(arguments); | ||
if (parseInt(leaf1, 16) > parseInt(leaf2, 16)) { | ||
console.log("[SIBLINGS] Leaf1 is bigger than Leaf2"); | ||
(function(_this) { | ||
return (function(__iced_k) { | ||
__iced_deferrals = new iced.Deferrals(__iced_k, { | ||
parent: ___iced_passed_deferral, | ||
filename: "./index.iced", | ||
funcname: "Stampery._sumSiblings" | ||
}); | ||
_this._sha3Hash("" + leaf1 + leaf2, __iced_deferrals.defer({ | ||
assign_fn: (function() { | ||
return function() { | ||
return hash = arguments[0]; | ||
}; | ||
})(), | ||
lineno: 107 | ||
})); | ||
__iced_deferrals._fulfill(); | ||
}); | ||
})(this)((function(_this) { | ||
return function() { | ||
return __iced_k(cb(hash)); | ||
}; | ||
})(this)); | ||
} else { | ||
console.log("[SIBLINGS] Leaf2 is bigger than Leaf1"); | ||
(function(_this) { | ||
return (function(__iced_k) { | ||
__iced_deferrals = new iced.Deferrals(__iced_k, { | ||
parent: ___iced_passed_deferral, | ||
filename: "./index.iced", | ||
funcname: "Stampery._sumSiblings" | ||
}); | ||
_this._sha3Hash("" + leaf2 + leaf1, __iced_deferrals.defer({ | ||
assign_fn: (function() { | ||
return function() { | ||
return hash = arguments[0]; | ||
}; | ||
})(), | ||
lineno: 111 | ||
})); | ||
__iced_deferrals._fulfill(); | ||
}); | ||
})(this)((function(_this) { | ||
return function() { | ||
return __iced_k(cb(hash)); | ||
}; | ||
})(this)); | ||
} | ||
}; | ||
Stampery.prototype._handleQueueConsumingForHash = function(queue) { | ||
@@ -308,3 +229,3 @@ var err, ___iced_passed_deferral, __iced_deferrals, __iced_k; | ||
})(_this), | ||
lineno: 116 | ||
lineno: 87 | ||
})); | ||
@@ -339,71 +260,2 @@ __iced_deferrals._fulfill(); | ||
Stampery.prototype.stamp = function(hash) { | ||
var err, res, ___iced_passed_deferral, __iced_deferrals, __iced_k; | ||
__iced_k = __iced_k_noop; | ||
___iced_passed_deferral = iced.findDeferral(arguments); | ||
console.log("Stamping " + hash); | ||
(function(_this) { | ||
return (function(__iced_k) { | ||
if (!_this.authed) { | ||
(function(__iced_k) { | ||
__iced_deferrals = new iced.Deferrals(__iced_k, { | ||
parent: ___iced_passed_deferral, | ||
filename: "./index.iced", | ||
funcname: "Stampery.stamp" | ||
}); | ||
_this._auth(__iced_deferrals.defer({ | ||
assign_fn: (function(__slot_1) { | ||
return function() { | ||
return __slot_1.authed = arguments[0]; | ||
}; | ||
})(_this), | ||
lineno: 143 | ||
})); | ||
__iced_deferrals._fulfill(); | ||
})(__iced_k); | ||
} else { | ||
return __iced_k(); | ||
} | ||
}); | ||
})(this)((function(_this) { | ||
return function() { | ||
hash = hash.toUpperCase(); | ||
console.log("Let's stamp " + hash); | ||
if (!_this.rabbit) { | ||
return setTimeout(_this.stamp.bind(_this, hash), 500); | ||
} | ||
(function(__iced_k) { | ||
__iced_deferrals = new iced.Deferrals(__iced_k, { | ||
parent: ___iced_passed_deferral, | ||
filename: "./index.iced", | ||
funcname: "Stampery.stamp" | ||
}); | ||
_this.rpc.invoke('stamp', [hash], __iced_deferrals.defer({ | ||
assign_fn: (function() { | ||
return function() { | ||
err = arguments[0]; | ||
return res = arguments[1]; | ||
}; | ||
})(), | ||
lineno: 147 | ||
})); | ||
__iced_deferrals._fulfill(); | ||
})(function() { | ||
if (!_this.authed) { | ||
return _this.emit('error', 'Not authenticated'); | ||
} | ||
console.log("[API] Received response: ", res); | ||
if (err) { | ||
console.log("[RPC] Error: " + err); | ||
return _this.emit('error', err); | ||
} | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
Stampery.prototype.receiveMissedProofs = function() { | ||
return this._handleQueueConsumingForHash(this.clientId); | ||
}; | ||
Stampery.prototype._merkleMixer = function(a, b, cb) { | ||
@@ -418,2 +270,28 @@ var data, _ref; | ||
Stampery.prototype._getBTCtx = function(txid, cb) { | ||
return request("https://api.blockcypher.com/v1/btc/main/txs/" + txid, (function(_this) { | ||
return function(err, res, body) { | ||
var tx; | ||
if (err || !body || !JSON.parse(body).outputs) { | ||
_this.emit('error', 'BTC explorer error'); | ||
} | ||
tx = JSON.parse(body).outputs.find(function(e) { | ||
return e.data_hex != null; | ||
}); | ||
return cb(tx.data_hex); | ||
}; | ||
})(this)); | ||
}; | ||
Stampery.prototype._getETHtx = function(txid, cb) { | ||
return request("https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=" + txid, (function(_this) { | ||
return function(err, res, body) { | ||
if (err || !body || !JSON.parse(body).result) { | ||
_this.emit('error', 'ETH explorer error'); | ||
} | ||
return cb(JSON.parse(body).result.input); | ||
}; | ||
})(this)); | ||
}; | ||
Stampery.prototype.prove = function(hash, proof, cb) { | ||
@@ -436,3 +314,3 @@ var rootIsInChain, siblingsAreOK, ___iced_passed_deferral, __iced_deferrals, __iced_k; | ||
})(), | ||
lineno: 164 | ||
lineno: 132 | ||
})); | ||
@@ -455,3 +333,3 @@ __iced_deferrals._fulfill(); | ||
})(), | ||
lineno: 165 | ||
lineno: 133 | ||
})); | ||
@@ -483,3 +361,3 @@ __iced_deferrals._fulfill(); | ||
})(), | ||
lineno: 169 | ||
lineno: 137 | ||
})); | ||
@@ -496,3 +374,3 @@ __iced_deferrals._fulfill(); | ||
})(), | ||
lineno: 170 | ||
lineno: 138 | ||
})); | ||
@@ -524,3 +402,3 @@ return cb(valid); | ||
})(), | ||
lineno: 177 | ||
lineno: 145 | ||
})); | ||
@@ -570,3 +448,3 @@ __iced_deferrals._fulfill(); | ||
})(), | ||
lineno: 187 | ||
lineno: 155 | ||
})); | ||
@@ -582,22 +460,80 @@ __iced_deferrals._fulfill(); | ||
Stampery.prototype._getBTCtx = function(txid, cb) { | ||
return request("https://api.blockcypher.com/v1/btc/main/txs/" + txid, function(err, res, body) { | ||
var tx; | ||
if (err || !body || !JSON.parse(body).outputs) { | ||
throw new Error('BTC explorer error'); | ||
} | ||
tx = JSON.parse(body).outputs.find(function(e) { | ||
return e.data_hex != null; | ||
Stampery.prototype.receiveMissedProofs = function() { | ||
return this._handleQueueConsumingForHash(this.clientId); | ||
}; | ||
Stampery.prototype.stamp = function(hash) { | ||
var err, res, ___iced_passed_deferral, __iced_deferrals, __iced_k; | ||
__iced_k = __iced_k_noop; | ||
___iced_passed_deferral = iced.findDeferral(arguments); | ||
console.log("Stamping " + hash); | ||
(function(_this) { | ||
return (function(__iced_k) { | ||
if (!_this.authed) { | ||
(function(__iced_k) { | ||
__iced_deferrals = new iced.Deferrals(__iced_k, { | ||
parent: ___iced_passed_deferral, | ||
filename: "./index.iced", | ||
funcname: "Stampery.stamp" | ||
}); | ||
_this._auth(__iced_deferrals.defer({ | ||
assign_fn: (function(__slot_1) { | ||
return function() { | ||
return __slot_1.authed = arguments[0]; | ||
}; | ||
})(_this), | ||
lineno: 165 | ||
})); | ||
__iced_deferrals._fulfill(); | ||
})(__iced_k); | ||
} else { | ||
return __iced_k(); | ||
} | ||
}); | ||
return cb(tx.data_hex); | ||
}); | ||
})(this)((function(_this) { | ||
return function() { | ||
hash = hash.toUpperCase(); | ||
console.log("Let's stamp " + hash); | ||
if (!_this.rabbit) { | ||
return setTimeout(_this.stamp.bind(_this, hash), 500); | ||
} | ||
(function(__iced_k) { | ||
__iced_deferrals = new iced.Deferrals(__iced_k, { | ||
parent: ___iced_passed_deferral, | ||
filename: "./index.iced", | ||
funcname: "Stampery.stamp" | ||
}); | ||
_this.rpc.invoke('stamp', [hash], __iced_deferrals.defer({ | ||
assign_fn: (function() { | ||
return function() { | ||
err = arguments[0]; | ||
return res = arguments[1]; | ||
}; | ||
})(), | ||
lineno: 169 | ||
})); | ||
__iced_deferrals._fulfill(); | ||
})(function() { | ||
if (!_this.authed) { | ||
return _this.emit('error', 'Not authenticated'); | ||
} | ||
console.log("[API] Received response: ", res); | ||
if (err) { | ||
console.log("[RPC] Error: " + err); | ||
return _this.emit('error', err); | ||
} | ||
}); | ||
}; | ||
})(this)); | ||
}; | ||
Stampery.prototype._getETHtx = function(txid, cb) { | ||
return request("https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=" + txid, function(err, res, body) { | ||
if (err || !body || !JSON.parse(body).result) { | ||
throw new Error('ETH explorer error'); | ||
} | ||
return cb(JSON.parse(body).result.input); | ||
}); | ||
Stampery.prototype.hash = function(data, cb) { | ||
var sha3; | ||
if (data instanceof stream) { | ||
return this._hashFile(data, cb); | ||
} else { | ||
sha3 = new SHA3.SHA3Hash(); | ||
sha3.update(data); | ||
return cb(sha3.digest('hex').toUpperCase()); | ||
} | ||
}; | ||
@@ -604,0 +540,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! stampery-node 2016-08-01 */ | ||
(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=function(a,b){return function(){return a.apply(b,arguments)}};j=require("iced-runtime"),o=p=function(){},h=require("crypto"),m=require("stream"),d=require("sha3"),c=require("rocksolidsocket"),b=require("msgpackrpc"),f=require("amqplib/callback_api"),k=require("msgpack"),i=require("domain"),n=require("util"),l=require("request"),a=require("events").EventEmitter,g=i.create(),g.on("error",function(a){return function(a){return console.log("[QUEUE] Error with queue: "+a)}}(this)),e=function(){function a(a,d){var e,f;this.clientSecret=a,this.beta=d,this.checkRootInChain=q(this.checkRootInChain,this),this.checkSiblings=q(this.checkSiblings,this),this.prove=q(this.prove,this),this._merkleMixer=q(this._merkleMixer,this),this.receiveMissedProofs=q(this.receiveMissedProofs,this),this._handleQueueConsumingForHash=q(this._handleQueueConsumingForHash,this),this._sumSiblings=q(this._sumSiblings,this),this._auth=q(this._auth,this),this._connectRabbit=q(this._connectRabbit,this),this._recursiveConvert=q(this._recursiveConvert,this),this._convertSiblingArray=q(this._convertSiblingArray,this),this.clientId=h.createHash("md5").update(this.clientSecret).digest("hex").substring(0,15),e=this.beta?"api-beta.stampery.com:4000":"api.stampery.com:4000",f=new c(e),this.rpc=new b("stampery.3",f),this._connectRabbit()}return a.prototype.ethSiblings={},a.prototype.authed=!1,a.prototype._convertSiblingArray=function(a){return""===a?[]:a.map(function(a,b){return a.toString()})},a.prototype._recursiveConvert=function(a){return a.map(function(a){return function(b){return b instanceof Buffer?b=b.toString("utf8"):b instanceof Array&&(b=a._recursiveConvert(b)),b}}(this))},a.prototype._connectRabbit=function(){var a,b,c,d;d=p,b=j.findDeferral(arguments),function(d){return function(e){d.beta?!function(e){c=new j.Deferrals(e,{parent:b,filename:"./index.iced",funcname:"Stampery._connectRabbit"}),f.connect("amqp://consumer:9FBln3UxOgwgLZtYvResNXE7@young-squirrel.rmq.cloudamqp.com/beta",c.defer({assign_fn:function(b){return function(){return a=arguments[0],b.rabbit=arguments[1]}}(d),lineno:54})),c._fulfill()}(e):!function(e){c=new j.Deferrals(e,{parent:b,filename:"./index.iced",funcname:"Stampery._connectRabbit"}),f.connect("amqp://consumer:9FBln3UxOgwgLZtYvResNXE7@young-squirrel.rmq.cloudamqp.com/ukgmnhoi",c.defer({assign_fn:function(b){return function(){return a=arguments[0],b.rabbit=arguments[1]}}(d),lineno:56})),c._fulfill()}(e)}}(this)(function(b){return function(){return a?console.log("[QUEUE] Error connecting "+a):(console.log("[QUEUE] Connected to Rabbit!"),b.emit("ready"),g.add(b.rabbit),b.rabbit.on("error",function(a){return b.emit("error",a),b._connectRabbit}))}}(this))},a.prototype.hash=function(a,b){var c;return a instanceof m?this._hashFile(a,b):(c=new d.SHA3Hash,c.update(a),b(c.digest("hex").toUpperCase()))},a.prototype._sha3Hash=function(a,b){var c;return c=new d.SHA3Hash,c.update(a),b(c.digest("hex"))},a.prototype._hashFile=function(a,b){var c;return c=new d.SHA3Hash,a.on("end",function(){return b(c.digest("hex"))}),a.on("data",function(a){return c.update(a)})},a.prototype._auth=function(a){var b,c,d,e,f;f=p,d=j.findDeferral(arguments),function(a){return function(f){e=new j.Deferrals(f,{parent:d,filename:"./index.iced",funcname:"Stampery._auth"}),a.rpc.invoke("auth",[a.clientId,a.clientSecret],e.defer({assign_fn:function(){return function(){return b=arguments[0],c=arguments[1]}}(),lineno:88})),e._fulfill()}}(this)(function(d){return function(){return console.log("[RPC] Auth: ",b,c),b?d.emit("error",b):a(!0)}}(this))},a.prototype.calculateProof=function(a,b,c){var d,e,f;e=a;for(d in b)f=b[d],console.log("[SIBLINGS] Calculating sibling "+d,e,f),this._sumSiblings(e,f,function(a){return console.log("[SIBLINGS] Calculated "+a),e=a});return c(e)},a.prototype._sumSiblings=function(a,b,c){var d,e,f,g;g=p,e=j.findDeferral(arguments),parseInt(a,16)>parseInt(b,16)?(console.log("[SIBLINGS] Leaf1 is bigger than Leaf2"),function(c){return function(g){f=new j.Deferrals(g,{parent:e,filename:"./index.iced",funcname:"Stampery._sumSiblings"}),c._sha3Hash(""+a+b,f.defer({assign_fn:function(){return function(){return d=arguments[0]}}(),lineno:107})),f._fulfill()}}(this)(function(a){return function(){return g(c(d))}}(this))):(console.log("[SIBLINGS] Leaf2 is bigger than Leaf1"),function(c){return function(g){f=new j.Deferrals(g,{parent:e,filename:"./index.iced",funcname:"Stampery._sumSiblings"}),c._sha3Hash(""+b+a,f.defer({assign_fn:function(){return function(){return d=arguments[0]}}(),lineno:111})),f._fulfill()}}(this)(function(a){return function(){return g(c(d))}}(this)))},a.prototype._handleQueueConsumingForHash=function(a){var b,c,d,e;return e=p,c=j.findDeferral(arguments),this.rabbit?void!function(a){return function(e){d=new j.Deferrals(e,{parent:c,filename:"./index.iced",funcname:"Stampery._handleQueueConsumingForHash"}),a.rabbit.createChannel(d.defer({assign_fn:function(a){return function(){return b=arguments[0],a.channel=arguments[1]}}(a),lineno:116})),d._fulfill()}}(this)(function(c){return function(){return console.log("[QUEUE] Bound to "+a+"-clnt",b),e(c.channel.consume(""+a+"-clnt",function(a){var b,d,e;return console.log("[QUEUE] Received data!"),e=k.unpack(a.content),b=a.fields.routingKey,1===e[3][0]||e[3][0]===-1?(console.log("[QUEUE] Received BTC proof for "+b),e[1]=(c.ethSiblings[b]||[]).concat(e[1]||[])):2!==e[3][0]&&e[3][0]!==-2||(console.log("[QUEUE] Received ETH proof for "+b),c.ethSiblings[b]=c._convertSiblingArray(e[1])),c.channel.ack(a),d=c._recursiveConvert(e),c.emit("proof",b,d)}))}}(this)):e(this.emit("error","Error binding to "+hash+"-clnt"))},a.prototype.stamp=function(a){var b,c,d,e,f;f=p,d=j.findDeferral(arguments),console.log("Stamping "+a),function(a){return function(b){return a.authed?b():void!function(b){e=new j.Deferrals(b,{parent:d,filename:"./index.iced",funcname:"Stampery.stamp"}),a._auth(e.defer({assign_fn:function(a){return function(){return a.authed=arguments[0]}}(a),lineno:143})),e._fulfill()}(b)}}(this)(function(f){return function(){return a=a.toUpperCase(),console.log("Let's stamp "+a),f.rabbit?void function(g){e=new j.Deferrals(g,{parent:d,filename:"./index.iced",funcname:"Stampery.stamp"}),f.rpc.invoke("stamp",[a],e.defer({assign_fn:function(){return function(){return b=arguments[0],c=arguments[1]}}(),lineno:147})),e._fulfill()}(function(){return f.authed?(console.log("[API] Received response: ",c),b?(console.log("[RPC] Error: "+b),f.emit("error",b)):void 0):f.emit("error","Not authenticated")}):setTimeout(f.stamp.bind(f,a),500)}}(this))},a.prototype.receiveMissedProofs=function(){return this._handleQueueConsumingForHash(this.clientId)},a.prototype._merkleMixer=function(a,b,c){var d,e;return b>a&&(e=[b,a],a=e[0],b=e[1]),d=a+b,this._sha3Hash(d,c)},a.prototype.prove=function(a,b,c){var d,e,f,g,h;h=p,f=j.findDeferral(arguments),function(c){return function(d){g=new j.Deferrals(d,{parent:f,filename:"./index.iced",funcname:"Stampery.prove"}),c.checkSiblings(a,b[1],b[2],g.defer({assign_fn:function(){return function(){return e=arguments[0]}}(),lineno:164})),g._fulfill()}}(this)(function(a){return function(){!function(c){g=new j.Deferrals(c,{parent:f,filename:"./index.iced",funcname:"Stampery.prove"}),a.checkRootInChain(b[2],b[3][0],b[3][1],g.defer({assign_fn:function(){return function(){return d=arguments[0]}}(),lineno:165})),g._fulfill()}(function(){return c(e&&d)})}}(this))},a.prototype.checkDataIntegrity=function(a,b,c){var d,e,f,g,h;h=p,f=j.findDeferral(arguments),function(b){return function(c){g=new j.Deferrals(c,{parent:f,filename:"./index.iced",funcname:"Stampery.checkDataIntegrity"}),b.hash(a,g.defer({assign_fn:function(){return function(){return d=arguments[0]}}(),lineno:169})),g._fulfill()}}(this)(function(a){return function(){return a.prove(d,b,g.defer({assign_fn:function(){return function(){return e=arguments[0]}}(),lineno:170})),c(e)}}(this))},a.prototype.checkSiblings=function(a,b,c,d){var e,f,g,h,i;return i=p,g=j.findDeferral(arguments),b.length>0?(e=b[0],f=b.slice(1),function(b){return function(c){h=new j.Deferrals(c,{parent:g,filename:"./index.iced",funcname:"Stampery.checkSiblings"}),b._merkleMixer(a,e,h.defer({assign_fn:function(){return function(){return a=arguments[0]}}(),lineno:177})),h._fulfill()}}(this)(function(b){return function(){!function(e){h=new j.Deferrals(e,{parent:g,filename:"./index.iced",funcname:"Stampery.checkSiblings"}),b.checkSiblings(a,f,c,function(a){return d(a)}),h._fulfill()}(i)}}(this)),void 0):i(d(a===c))},a.prototype.checkRootInChain=function(a,b,c,d){var e,f,g,h,i;i=p,g=j.findDeferral(arguments),f=this._getBTCtx,2===b&&(f=this._getETHtx),function(a){return function(a){h=new j.Deferrals(a,{parent:g,filename:"./index.iced",funcname:"Stampery.checkRootInChain"}),f(c,h.defer({assign_fn:function(){return function(){return e=arguments[0]}}(),lineno:187})),h._fulfill()}}(this)(function(b){return function(){return d(e.indexOf(a.toLowerCase())>=0)}}(this))},a.prototype._getBTCtx=function(a,b){return l("https://api.blockcypher.com/v1/btc/main/txs/"+a,function(a,c,d){var e;if(a||!d||!JSON.parse(d).outputs)throw new Error("BTC explorer error");return e=JSON.parse(d).outputs.find(function(a){return null!=a.data_hex}),b(e.data_hex)})},a.prototype._getETHtx=function(a,b){return l("https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash="+a,function(a,c,d){if(a||!d||!JSON.parse(d).result)throw new Error("ETH explorer error");return b(JSON.parse(d).result.input)})},a}(),n.inherits(e,a),module.exports=e}).call(this); | ||
/*! stampery-node 2016-08-02 */ | ||
(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q=function(a,b){return function(){return a.apply(b,arguments)}};j=require("iced-runtime"),o=p=function(){},h=require("crypto"),m=require("stream"),d=require("sha3"),c=require("rocksolidsocket"),b=require("msgpackrpc"),f=require("amqplib/callback_api"),k=require("msgpack"),i=require("domain"),n=require("util"),l=require("request"),a=require("events").EventEmitter,g=i.create(),g.on("error",function(a){return function(a){return console.log("[QUEUE] Error with queue: "+a)}}(this)),e=function(){function a(a,d){var e,f;this.clientSecret=a,this.beta=d,this.receiveMissedProofs=q(this.receiveMissedProofs,this),this.checkRootInChain=q(this.checkRootInChain,this),this.checkSiblings=q(this.checkSiblings,this),this.prove=q(this.prove,this),this._getETHtx=q(this._getETHtx,this),this._getBTCtx=q(this._getBTCtx,this),this._merkleMixer=q(this._merkleMixer,this),this._handleQueueConsumingForHash=q(this._handleQueueConsumingForHash,this),this._auth=q(this._auth,this),this._connectRabbit=q(this._connectRabbit,this),this._recursiveConvert=q(this._recursiveConvert,this),this._convertSiblingArray=q(this._convertSiblingArray,this),this.clientId=h.createHash("md5").update(this.clientSecret).digest("hex").substring(0,15),e=this.beta?"api-beta.stampery.com:4000":"api.stampery.com:4000",f=new c(e),this.rpc=new b("stampery.3",f),this._connectRabbit()}return a.prototype.ethSiblings={},a.prototype.authed=!1,a.prototype._convertSiblingArray=function(a){return""===a?[]:a.map(function(a,b){return a.toString()})},a.prototype._recursiveConvert=function(a){return a.map(function(a){return function(b){return b instanceof Buffer?b=b.toString("utf8"):b instanceof Array&&(b=a._recursiveConvert(b)),b}}(this))},a.prototype._connectRabbit=function(){var a,b,c,d;d=p,b=j.findDeferral(arguments),function(d){return function(e){d.beta?!function(e){c=new j.Deferrals(e,{parent:b,filename:"./index.iced",funcname:"Stampery._connectRabbit"}),f.connect("amqp://consumer:9FBln3UxOgwgLZtYvResNXE7@young-squirrel.rmq.cloudamqp.com/beta",c.defer({assign_fn:function(b){return function(){return a=arguments[0],b.rabbit=arguments[1]}}(d),lineno:54})),c._fulfill()}(e):!function(e){c=new j.Deferrals(e,{parent:b,filename:"./index.iced",funcname:"Stampery._connectRabbit"}),f.connect("amqp://consumer:9FBln3UxOgwgLZtYvResNXE7@young-squirrel.rmq.cloudamqp.com/ukgmnhoi",c.defer({assign_fn:function(b){return function(){return a=arguments[0],b.rabbit=arguments[1]}}(d),lineno:56})),c._fulfill()}(e)}}(this)(function(b){return function(){return a?console.log("[QUEUE] Error connecting "+a):(console.log("[QUEUE] Connected to Rabbit!"),b.emit("ready"),g.add(b.rabbit),b.rabbit.on("error",function(a){return b.emit("error",a),b._connectRabbit}))}}(this))},a.prototype._sha3Hash=function(a,b){var c;return c=new d.SHA3Hash,c.update(a),b(c.digest("hex"))},a.prototype._hashFile=function(a,b){var c;return c=new d.SHA3Hash,a.on("end",function(){return b(c.digest("hex"))}),a.on("data",function(a){return c.update(a)})},a.prototype._auth=function(a){var b,c,d,e,f;f=p,d=j.findDeferral(arguments),function(a){return function(f){e=new j.Deferrals(f,{parent:d,filename:"./index.iced",funcname:"Stampery._auth"}),a.rpc.invoke("auth",[a.clientId,a.clientSecret],e.defer({assign_fn:function(){return function(){return b=arguments[0],c=arguments[1]}}(),lineno:80})),e._fulfill()}}(this)(function(d){return function(){return console.log("[RPC] Auth: ",b,c),b?d.emit("error",b):a(!0)}}(this))},a.prototype._handleQueueConsumingForHash=function(a){var b,c,d,e;return e=p,c=j.findDeferral(arguments),this.rabbit?void!function(a){return function(e){d=new j.Deferrals(e,{parent:c,filename:"./index.iced",funcname:"Stampery._handleQueueConsumingForHash"}),a.rabbit.createChannel(d.defer({assign_fn:function(a){return function(){return b=arguments[0],a.channel=arguments[1]}}(a),lineno:87})),d._fulfill()}}(this)(function(c){return function(){return console.log("[QUEUE] Bound to "+a+"-clnt",b),e(c.channel.consume(""+a+"-clnt",function(a){var b,d,e;return console.log("[QUEUE] Received data!"),e=k.unpack(a.content),b=a.fields.routingKey,1===e[3][0]||e[3][0]===-1?(console.log("[QUEUE] Received BTC proof for "+b),e[1]=(c.ethSiblings[b]||[]).concat(e[1]||[])):2!==e[3][0]&&e[3][0]!==-2||(console.log("[QUEUE] Received ETH proof for "+b),c.ethSiblings[b]=c._convertSiblingArray(e[1])),c.channel.ack(a),d=c._recursiveConvert(e),c.emit("proof",b,d)}))}}(this)):e(this.emit("error","Error binding to "+hash+"-clnt"))},a.prototype._merkleMixer=function(a,b,c){var d,e;return b>a&&(e=[b,a],a=e[0],b=e[1]),d=a+b,this._sha3Hash(d,c)},a.prototype._getBTCtx=function(a,b){return l("https://api.blockcypher.com/v1/btc/main/txs/"+a,function(a){return function(c,d,e){var f;return!c&&e&&JSON.parse(e).outputs||a.emit("error","BTC explorer error"),f=JSON.parse(e).outputs.find(function(a){return null!=a.data_hex}),b(f.data_hex)}}(this))},a.prototype._getETHtx=function(a,b){return l("https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash="+a,function(a){return function(c,d,e){return!c&&e&&JSON.parse(e).result||a.emit("error","ETH explorer error"),b(JSON.parse(e).result.input)}}(this))},a.prototype.prove=function(a,b,c){var d,e,f,g,h;h=p,f=j.findDeferral(arguments),function(c){return function(d){g=new j.Deferrals(d,{parent:f,filename:"./index.iced",funcname:"Stampery.prove"}),c.checkSiblings(a,b[1],b[2],g.defer({assign_fn:function(){return function(){return e=arguments[0]}}(),lineno:132})),g._fulfill()}}(this)(function(a){return function(){!function(c){g=new j.Deferrals(c,{parent:f,filename:"./index.iced",funcname:"Stampery.prove"}),a.checkRootInChain(b[2],b[3][0],b[3][1],g.defer({assign_fn:function(){return function(){return d=arguments[0]}}(),lineno:133})),g._fulfill()}(function(){return c(e&&d)})}}(this))},a.prototype.checkDataIntegrity=function(a,b,c){var d,e,f,g,h;h=p,f=j.findDeferral(arguments),function(b){return function(c){g=new j.Deferrals(c,{parent:f,filename:"./index.iced",funcname:"Stampery.checkDataIntegrity"}),b.hash(a,g.defer({assign_fn:function(){return function(){return d=arguments[0]}}(),lineno:137})),g._fulfill()}}(this)(function(a){return function(){return a.prove(d,b,g.defer({assign_fn:function(){return function(){return e=arguments[0]}}(),lineno:138})),c(e)}}(this))},a.prototype.checkSiblings=function(a,b,c,d){var e,f,g,h,i;return i=p,g=j.findDeferral(arguments),b.length>0?(e=b[0],f=b.slice(1),function(b){return function(c){h=new j.Deferrals(c,{parent:g,filename:"./index.iced",funcname:"Stampery.checkSiblings"}),b._merkleMixer(a,e,h.defer({assign_fn:function(){return function(){return a=arguments[0]}}(),lineno:145})),h._fulfill()}}(this)(function(b){return function(){!function(e){h=new j.Deferrals(e,{parent:g,filename:"./index.iced",funcname:"Stampery.checkSiblings"}),b.checkSiblings(a,f,c,function(a){return d(a)}),h._fulfill()}(i)}}(this)),void 0):i(d(a===c))},a.prototype.checkRootInChain=function(a,b,c,d){var e,f,g,h,i;i=p,g=j.findDeferral(arguments),f=this._getBTCtx,2===b&&(f=this._getETHtx),function(a){return function(a){h=new j.Deferrals(a,{parent:g,filename:"./index.iced",funcname:"Stampery.checkRootInChain"}),f(c,h.defer({assign_fn:function(){return function(){return e=arguments[0]}}(),lineno:155})),h._fulfill()}}(this)(function(b){return function(){return d(e.indexOf(a.toLowerCase())>=0)}}(this))},a.prototype.receiveMissedProofs=function(){return this._handleQueueConsumingForHash(this.clientId)},a.prototype.stamp=function(a){var b,c,d,e,f;f=p,d=j.findDeferral(arguments),console.log("Stamping "+a),function(a){return function(b){return a.authed?b():void!function(b){e=new j.Deferrals(b,{parent:d,filename:"./index.iced",funcname:"Stampery.stamp"}),a._auth(e.defer({assign_fn:function(a){return function(){return a.authed=arguments[0]}}(a),lineno:165})),e._fulfill()}(b)}}(this)(function(f){return function(){return a=a.toUpperCase(),console.log("Let's stamp "+a),f.rabbit?void function(g){e=new j.Deferrals(g,{parent:d,filename:"./index.iced",funcname:"Stampery.stamp"}),f.rpc.invoke("stamp",[a],e.defer({assign_fn:function(){return function(){return b=arguments[0],c=arguments[1]}}(),lineno:169})),e._fulfill()}(function(){return f.authed?(console.log("[API] Received response: ",c),b?(console.log("[RPC] Error: "+b),f.emit("error",b)):void 0):f.emit("error","Not authenticated")}):setTimeout(f.stamp.bind(f,a),500)}}(this))},a.prototype.hash=function(a,b){var c;return a instanceof m?this._hashFile(a,b):(c=new d.SHA3Hash,c.update(a),b(c.digest("hex").toUpperCase()))},a}(),n.inherits(e,a),module.exports=e}).call(this); |
{ | ||
"name": "stampery", | ||
"version": "3.2.5", | ||
"version": "3.3.0", | ||
"description": "Stampery API for NodeJS. Notarize all your data using the blockchain", | ||
@@ -42,3 +42,6 @@ "main": "index.js", | ||
"iced-coffee-script": "^108.0.11" | ||
}, | ||
"engines": { | ||
"node": "5.x" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
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
11
41151
513