datapay
Version:
post data over bitcoin sv
1 lines • 1.41 MB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.datapay=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){(function(Buffer){const mingo=require("mingo");const _Buffer=require("buffer/");const bitcoin=require("bsv");const explorer=require("bitcore-explorers");const defaults={rpc:"api.mattercloud.net",fee:400,feeb:1.4};var build=function(options,callback){let script=null;let rpcaddr=options.pay&&options.pay.rpc?options.pay.rpc:defaults.rpc;if(options.tx){let tx=new bitcoin.Transaction(options.tx);if(tx.inputs.length>0&&tx.inputs[0].script){if(options.pay||options.data){callback(new Error("the transaction is already signed and cannot be modified"));return}}}else{if(options.data){script=_script(options)}}if(options.pay&&options.pay.key){let key=options.pay.key;const privateKey=new bitcoin.PrivateKey(key);const address=privateKey.toAddress();const insight=new explorer.Insight(rpcaddr);insight.getUnspentUtxos(address,function(err,res){if(err){callback(err);return}if(options.pay.filter&&options.pay.filter.q&&options.pay.filter.q.find){let f=new mingo.Query(options.pay.filter.q.find);res=res.filter(function(item){return f.test(item)})}let tx=new bitcoin.Transaction(options.tx).from(res);if(script){tx.addOutput(new bitcoin.Transaction.Output({script:script,satoshis:0}))}if(options.pay.to&&Array.isArray(options.pay.to)){options.pay.to.forEach(function(receiver){tx.to(receiver.address,receiver.value)})}tx.fee(defaults.fee).change(address);let opt_pay=options.pay||{};let myfee=opt_pay.fee||Math.ceil(tx._estimateSize()*(opt_pay.feeb||defaults.feeb));tx.fee(myfee);for(var i=0;i<tx.outputs.length;i++){if(tx.outputs[i]._satoshis>0&&tx.outputs[i]._satoshis<546){tx.outputs.splice(i,1);i--}}let transaction=tx.sign(privateKey);callback(null,transaction)})}else{let fee=options.pay&&options.pay.fee?options.pay.fee:defaults.fee;let tx=new bitcoin.Transaction(options.tx).fee(fee);if(script){tx.addOutput(new bitcoin.Transaction.Output({script:script,satoshis:0}))}callback(null,tx)}};var send=function(options,callback){if(!callback){callback=function(){}}build(options,function(err,tx){if(err){callback(err);return}let rpcaddr=options.pay&&options.pay.rpc?options.pay.rpc:defaults.rpc;const insight=new explorer.Insight(rpcaddr);insight.broadcast(tx.toString(),callback)})};var _script=function(options){var s=null;if(options.data){if(Array.isArray(options.data)){s=new bitcoin.Script;if(!options.hasOwnProperty("safe")){options.safe=true}if(options.safe){s.add(bitcoin.Opcode.OP_FALSE)}s.add(bitcoin.Opcode.OP_RETURN);options.data.forEach(function(item){if(item.constructor.name==="ArrayBuffer"){let buffer=_Buffer.Buffer.from(item);s.add(buffer)}else if(item.constructor.name==="Buffer"){s.add(item)}else if(typeof item==="string"){if(/^0x/i.test(item)){s.add(Buffer.from(item.slice(2),"hex"))}else{s.add(Buffer.from(item))}}else if(typeof item==="object"&&item.hasOwnProperty("op")){s.add({opcodenum:item.op})}})}else if(typeof options.data==="string"){s=bitcoin.Script.fromHex(options.data)}}return s};var connect=function(endpoint){var rpc=endpoint?endpoint:defaults.rpc;return new explorer.Insight(rpc)};module.exports={build:build,send:send,bsv:bitcoin,connect:connect}}).call(this,require("buffer").Buffer)},{"bitcore-explorers":3,bsv:89,buffer:218,"buffer/":82,mingo:84}],2:[function(require,module,exports){"use strict";exports.byteLength=byteLength;exports.toByteArray=toByteArray;exports.fromByteArray=fromByteArray;var lookup=[];var revLookup=[];var Arr=typeof Uint8Array!=="undefined"?Uint8Array:Array;var code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var i=0,len=code.length;i<len;++i){lookup[i]=code[i];revLookup[code.charCodeAt(i)]=i}revLookup["-".charCodeAt(0)]=62;revLookup["_".charCodeAt(0)]=63;function getLens(b64){var len=b64.length;if(len%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}var validLen=b64.indexOf("=");if(validLen===-1)validLen=len;var placeHoldersLen=validLen===len?0:4-validLen%4;return[validLen,placeHoldersLen]}function byteLength(b64){var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function _byteLength(b64,validLen,placeHoldersLen){return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function toByteArray(b64){var tmp;var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];var arr=new Arr(_byteLength(b64,validLen,placeHoldersLen));var curByte=0;var len=placeHoldersLen>0?validLen-4:validLen;for(var i=0;i<len;i+=4){tmp=revLookup[b64.charCodeAt(i)]<<18|revLookup[b64.charCodeAt(i+1)]<<12|revLookup[b64.charCodeAt(i+2)]<<6|revLookup[b64.charCodeAt(i+3)];arr[curByte++]=tmp>>16&255;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}if(placeHoldersLen===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[curByte++]=tmp&255}if(placeHoldersLen===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}return arr}function tripletToBase64(num){return lookup[num>>18&63]+lookup[num>>12&63]+lookup[num>>6&63]+lookup[num&63]}function encodeChunk(uint8,start,end){var tmp;var output=[];for(var i=start;i<end;i+=3){tmp=(uint8[i]<<16&16711680)+(uint8[i+1]<<8&65280)+(uint8[i+2]&255);output.push(tripletToBase64(tmp))}return output.join("")}function fromByteArray(uint8){var tmp;var len=uint8.length;var extraBytes=len%3;var parts=[];var maxChunkLength=16383;for(var i=0,len2=len-extraBytes;i<len2;i+=maxChunkLength){parts.push(encodeChunk(uint8,i,i+maxChunkLength>len2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];parts.push(lookup[tmp>>2]+lookup[tmp<<4&63]+"==")}else if(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];parts.push(lookup[tmp>>10]+lookup[tmp>>4&63]+lookup[tmp<<2&63]+"=")}return parts.join("")}},{}],3:[function(require,module,exports){module.exports=require("./lib")},{"./lib":4}],4:[function(require,module,exports){module.exports={models:require("./models"),Insight:require("./insight")}},{"./insight":5,"./models":7}],5:[function(require,module,exports){"use strict";var request=require("request");var bitcore=require("bitcore-lib");var _=bitcore.deps._;var $=bitcore.util.preconditions;var Address=bitcore.Address;var JSUtil=bitcore.util.js;var Networks=bitcore.Networks;var Transaction=bitcore.Transaction;var UnspentOutput=Transaction.UnspentOutput;var AddressInfo=require("./models/addressinfo");function Insight(url,network){if(!url&&!network){return new Insight(Networks.defaultNetwork)}if(Networks.get(url)){network=Networks.get(url);if(network===Networks.livenet){url="https://insight.bitpay.com"}else{url="https://test-insight.bitpay.com"}}JSUtil.defineImmutable(this,{url:url,network:Networks.get(network)||Networks.defaultNetwork});this.request=request;return this}Insight.prototype.getUnspentUtxos=function(addresses,callback){$.checkArgument(_.isFunction(callback));if(!_.isArray(addresses)){addresses=[addresses]}addresses=_.map(addresses,function(address){return new Address(address)});this.requestPost("/api/addrs/utxo",{addrs:_.map(addresses,function(address){return address.toString()}).join(",")},function(err,res,unspent){if(err||res.statusCode!==200){return callback(err||res)}try{unspent=_.map(unspent,UnspentOutput)}catch(ex){if(ex instanceof bitcore.errors.InvalidArgument){return callback(ex)}}return callback(null,unspent)})};Insight.prototype.broadcast=function(transaction,callback){$.checkArgument(JSUtil.isHexa(transaction)||transaction instanceof Transaction);$.checkArgument(_.isFunction(callback));if(transaction instanceof Transaction){transaction=transaction.serialize()}this.requestPost("/api/tx/send",{rawtx:transaction},function(err,res,body){if(err||res.statusCode!==200){return callback(err||body)}return callback(null,body?body.txid:null)})};Insight.prototype.address=function(address,callback){$.checkArgument(_.isFunction(callback));address=new Address(address);this.requestGet("/api/addr/"+address.toString(),function(err,res,body){if(err||res.statusCode!==200){return callback(err||body)}var info;try{info=AddressInfo.fromInsight(body)}catch(e){if(e instanceof SyntaxError){return callback(e)}throw e}return callback(null,info)})};Insight.prototype.requestPost=function(path,data,callback){$.checkArgument(_.isString(path));$.checkArgument(_.isFunction(callback));this.request({method:"POST",url:this.url+path,json:data},callback)};Insight.prototype.requestGet=function(path,callback){$.checkArgument(_.isString(path));$.checkArgument(_.isFunction(callback));this.request({method:"GET",url:this.url+path},callback)};module.exports=Insight},{"./models/addressinfo":6,"bitcore-lib":8,request:81}],6:[function(require,module,exports){"use strict";var bitcore=require("bitcore-lib");var _=bitcore.deps._;var $=bitcore.util.preconditions;var Address=bitcore.Address;var JSUtil=bitcore.util.js;function AddressInfo(param){if(!(this instanceof AddressInfo)){return new AddressInfo(param)}if(param instanceof AddressInfo){return param}$.checkArgument(param.address instanceof Address);$.checkArgument(_.isNumber(param.balance));$.checkArgument(_.isNumber(param.totalSent));$.checkArgument(_.isNumber(param.totalReceived));$.checkArgument(_.isNumber(param.unconfirmedBalance));$.checkArgument(_.isArray(param.transactionIds));$.checkArgument(_.all(_.map(param.transactionIds,JSUtil.isHexa)));JSUtil.defineImmutable(this,param)}AddressInfo.fromInsight=function(param){if(_.isString(param)){param=JSON.parse(param)}return new AddressInfo({address:new Address(param.addrStr),balance:param.balanceSat,totalReceived:param.totalReceivedSat,totalSent:param.totalSentSat,unconfirmedBalance:param.unconfirmedBalanceSat,transactionIds:param.transactions})};module.exports=AddressInfo},{"bitcore-lib":8}],7:[function(require,module,exports){module.exports={AddressInfo:require("./addressinfo")}},{"./addressinfo":6}],8:[function(require,module,exports){(function(global,Buffer){"use strict";var bitcore=module.exports;bitcore.version="v"+require("./package.json").version;bitcore.versionGuard=function(version){if(version!==undefined){var message="More than one instance of bitcore-lib found. "+"Please make sure to require bitcore-lib and check that submodules do"+" not also include their own bitcore-lib dependency.";throw new Error(message)}};bitcore.versionGuard(global._bitcore);global._bitcore=bitcore.version;bitcore.crypto={};bitcore.crypto.BN=require("./lib/crypto/bn");bitcore.crypto.ECDSA=require("./lib/crypto/ecdsa");bitcore.crypto.Hash=require("./lib/crypto/hash");bitcore.crypto.Random=require("./lib/crypto/random");bitcore.crypto.Point=require("./lib/crypto/point");bitcore.crypto.Signature=require("./lib/crypto/signature");bitcore.encoding={};bitcore.encoding.Base58=require("./lib/encoding/base58");bitcore.encoding.Base58Check=require("./lib/encoding/base58check");bitcore.encoding.BufferReader=require("./lib/encoding/bufferreader");bitcore.encoding.BufferWriter=require("./lib/encoding/bufferwriter");bitcore.encoding.Varint=require("./lib/encoding/varint");bitcore.util={};bitcore.util.buffer=require("./lib/util/buffer");bitcore.util.js=require("./lib/util/js");bitcore.util.preconditions=require("./lib/util/preconditions");bitcore.errors=require("./lib/errors");bitcore.Address=require("./lib/address");bitcore.Block=require("./lib/block");bitcore.MerkleBlock=require("./lib/block/merkleblock");bitcore.BlockHeader=require("./lib/block/blockheader");bitcore.HDPrivateKey=require("./lib/hdprivatekey.js");bitcore.HDPublicKey=require("./lib/hdpublickey.js");bitcore.Networks=require("./lib/networks");bitcore.Opcode=require("./lib/opcode");bitcore.PrivateKey=require("./lib/privatekey");bitcore.PublicKey=require("./lib/publickey");bitcore.Script=require("./lib/script");bitcore.Transaction=require("./lib/transaction");bitcore.URI=require("./lib/uri");bitcore.Unit=require("./lib/unit");bitcore.deps={};bitcore.deps.bnjs=require("bn.js");bitcore.deps.bs58=require("bs58");bitcore.deps.Buffer=Buffer;bitcore.deps.elliptic=require("elliptic");bitcore.deps._=require("lodash");bitcore._HDKeyCache=require("./lib/hdkeycache");bitcore.Transaction.sighash=require("./lib/transaction/sighash")}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},require("buffer").Buffer)},{"./lib/address":9,"./lib/block":12,"./lib/block/blockheader":11,"./lib/block/merkleblock":13,"./lib/crypto/bn":14,"./lib/crypto/ecdsa":15,"./lib/crypto/hash":16,"./lib/crypto/point":17,"./lib/crypto/random":18,"./lib/crypto/signature":19,"./lib/encoding/base58":20,"./lib/encoding/base58check":21,"./lib/encoding/bufferreader":22,"./lib/encoding/bufferwriter":23,"./lib/encoding/varint":24,"./lib/errors":25,"./lib/hdkeycache":27,"./lib/hdprivatekey.js":28,"./lib/hdpublickey.js":29,"./lib/networks":30,"./lib/opcode":31,"./lib/privatekey":32,"./lib/publickey":33,"./lib/script":34,"./lib/transaction":37,"./lib/transaction/sighash":45,"./lib/unit":49,"./lib/uri":50,"./lib/util/buffer":51,"./lib/util/js":52,"./lib/util/preconditions":53,"./package.json":80,"bn.js":54,bs58:55,buffer:218,elliptic:57,lodash:79}],9:[function(require,module,exports){(function(Buffer){"use strict";var _=require("lodash");var $=require("./util/preconditions");var errors=require("./errors");var Base58Check=require("./encoding/base58check");var Networks=require("./networks");var Hash=require("./crypto/hash");var JSUtil=require("./util/js");var PublicKey=require("./publickey");function Address(data,network,type){if(!(this instanceof Address)){return new Address(data,network,type)}if(_.isArray(data)&&_.isNumber(network)){return Address.createMultisig(data,network,type)}if(data instanceof Address){return data}$.checkArgument(data,"First argument is required, please include address data.","guide/address.html");if(network&&!Networks.get(network)){throw new TypeError('Second argument must be "livenet" or "testnet".')}if(type&&(type!==Address.PayToPublicKeyHash&&type!==Address.PayToScriptHash)){throw new TypeError('Third argument must be "pubkeyhash" or "scripthash".')}var info=this._classifyArguments(data,network,type);info.network=info.network||Networks.get(network)||Networks.defaultNetwork;info.type=info.type||type||Address.PayToPublicKeyHash;JSUtil.defineImmutable(this,{hashBuffer:info.hashBuffer,network:info.network,type:info.type});return this}Address.prototype._classifyArguments=function(data,network,type){if((data instanceof Buffer||data instanceof Uint8Array)&&data.length===20){return Address._transformHash(data)}else if((data instanceof Buffer||data instanceof Uint8Array)&&data.length===21){return Address._transformBuffer(data,network,type)}else if(data instanceof PublicKey){return Address._transformPublicKey(data)}else if(data instanceof Script){return Address._transformScript(data,network)}else if(typeof data==="string"){return Address._transformString(data,network,type)}else if(_.isObject(data)){return Address._transformObject(data)}else{throw new TypeError("First argument is an unrecognized data format.")}};Address.PayToPublicKeyHash="pubkeyhash";Address.PayToScriptHash="scripthash";Address._transformHash=function(hash){var info={};if(!(hash instanceof Buffer)&&!(hash instanceof Uint8Array)){throw new TypeError("Address supplied is not a buffer.")}if(hash.length!==20){throw new TypeError("Address hashbuffers must be exactly 20 bytes.")}info.hashBuffer=hash;return info};Address._transformObject=function(data){$.checkArgument(data.hash||data.hashBuffer,"Must provide a `hash` or `hashBuffer` property");$.checkArgument(data.type,"Must provide a `type` property");return{hashBuffer:data.hash?new Buffer(data.hash,"hex"):data.hashBuffer,network:Networks.get(data.network)||Networks.defaultNetwork,type:data.type}};Address._classifyFromVersion=function(buffer){var version={};var pubkeyhashNetwork=Networks.get(buffer[0],"pubkeyhash");var scripthashNetwork=Networks.get(buffer[0],"scripthash");if(pubkeyhashNetwork){version.network=pubkeyhashNetwork;version.type=Address.PayToPublicKeyHash}else if(scripthashNetwork){version.network=scripthashNetwork;version.type=Address.PayToScriptHash}return version};Address._transformBuffer=function(buffer,network,type){var info={};if(!(buffer instanceof Buffer)&&!(buffer instanceof Uint8Array)){throw new TypeError("Address supplied is not a buffer.")}if(buffer.length!==1+20){throw new TypeError("Address buffers must be exactly 21 bytes.")}network=Networks.get(network);var bufferVersion=Address._classifyFromVersion(buffer);if(!bufferVersion.network||network&&network!==bufferVersion.network){throw new TypeError("Address has mismatched network type.")}if(!bufferVersion.type||type&&type!==bufferVersion.type){throw new TypeError("Address has mismatched type.")}info.hashBuffer=buffer.slice(1);info.network=bufferVersion.network;info.type=bufferVersion.type;return info};Address._transformPublicKey=function(pubkey){var info={};if(!(pubkey instanceof PublicKey)){throw new TypeError("Address must be an instance of PublicKey.")}info.hashBuffer=Hash.sha256ripemd160(pubkey.toBuffer());info.type=Address.PayToPublicKeyHash;return info};Address._transformScript=function(script,network){$.checkArgument(script instanceof Script,"script must be a Script instance");var info=script.getAddressInfo(network);if(!info){throw new errors.Script.CantDeriveAddress(script)}return info};Address.createMultisig=function(publicKeys,threshold,network){network=network||publicKeys[0].network||Networks.defaultNetwork;return Address.payingTo(Script.buildMultisigOut(publicKeys,threshold),network)};Address._transformString=function(data,network,type){if(typeof data!=="string"){throw new TypeError("data parameter supplied is not a string.")}data=data.trim();var addressBuffer=Base58Check.decode(data);var info=Address._transformBuffer(addressBuffer,network,type);return info};Address.fromPublicKey=function(data,network){var info=Address._transformPublicKey(data);network=network||Networks.defaultNetwork;return new Address(info.hashBuffer,network,info.type)};Address.fromPublicKeyHash=function(hash,network){var info=Address._transformHash(hash);return new Address(info.hashBuffer,network,Address.PayToPublicKeyHash)};Address.fromScriptHash=function(hash,network){$.checkArgument(hash,"hash parameter is required");var info=Address._transformHash(hash);return new Address(info.hashBuffer,network,Address.PayToScriptHash)};Address.payingTo=function(script,network){$.checkArgument(script,"script is required");$.checkArgument(script instanceof Script,"script must be instance of Script");return Address.fromScriptHash(Hash.sha256ripemd160(script.toBuffer()),network)};Address.fromScript=function(script,network){$.checkArgument(script instanceof Script,"script must be a Script instance");var info=Address._transformScript(script,network);return new Address(info.hashBuffer,network,info.type)};Address.fromBuffer=function(buffer,network,type){var info=Address._transformBuffer(buffer,network,type);return new Address(info.hashBuffer,info.network,info.type)};Address.fromString=function(str,network,type){var info=Address._transformString(str,network,type);return new Address(info.hashBuffer,info.network,info.type)};Address.fromObject=function fromObject(obj){$.checkState(JSUtil.isHexa(obj.hash),'Unexpected hash property, "'+obj.hash+'", expected to be hex.');var hashBuffer=new Buffer(obj.hash,"hex");return new Address(hashBuffer,obj.network,obj.type)};Address.getValidationError=function(data,network,type){var error;try{new Address(data,network,type)}catch(e){error=e}return error};Address.isValid=function(data,network,type){return!Address.getValidationError(data,network,type)};Address.prototype.isPayToPublicKeyHash=function(){return this.type===Address.PayToPublicKeyHash};Address.prototype.isPayToScriptHash=function(){return this.type===Address.PayToScriptHash};Address.prototype.toBuffer=function(){var version=new Buffer([this.network[this.type]]);var buf=Buffer.concat([version,this.hashBuffer]);return buf};Address.prototype.toObject=Address.prototype.toJSON=function toObject(){return{hash:this.hashBuffer.toString("hex"),type:this.type,network:this.network.toString()}};Address.prototype.toString=function(){return Base58Check.encode(this.toBuffer())};Address.prototype.inspect=function(){return"<Address: "+this.toString()+", type: "+this.type+", network: "+this.network+">"};module.exports=Address;var Script=require("./script")}).call(this,require("buffer").Buffer)},{"./crypto/hash":16,"./encoding/base58check":21,"./errors":25,"./networks":30,"./publickey":33,"./script":34,"./util/js":52,"./util/preconditions":53,buffer:218,lodash:79}],10:[function(require,module,exports){(function(Buffer){"use strict";var _=require("lodash");var BlockHeader=require("./blockheader");var BN=require("../crypto/bn");var BufferUtil=require("../util/buffer");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var Transaction=require("../transaction");var $=require("../util/preconditions");function Block(arg){if(!(this instanceof Block)){return new Block(arg)}_.extend(this,Block._from(arg));return this}Block.MAX_BLOCK_SIZE=1e6;Block._from=function _from(arg){var info={};if(BufferUtil.isBuffer(arg)){info=Block._fromBufferReader(BufferReader(arg))}else if(_.isObject(arg)){info=Block._fromObject(arg)}else{throw new TypeError("Unrecognized argument for Block")}return info};Block._fromObject=function _fromObject(data){var transactions=[];data.transactions.forEach(function(tx){if(tx instanceof Transaction){transactions.push(tx)}else{transactions.push(Transaction().fromObject(tx))}});var info={header:BlockHeader.fromObject(data.header),transactions:transactions};return info};Block.fromObject=function fromObject(obj){var info=Block._fromObject(obj);return new Block(info)};Block._fromBufferReader=function _fromBufferReader(br){var info={};$.checkState(!br.finished(),"No block data received");info.header=BlockHeader.fromBufferReader(br);var transactions=br.readVarintNum();info.transactions=[];for(var i=0;i<transactions;i++){info.transactions.push(Transaction().fromBufferReader(br))}return info};Block.fromBufferReader=function fromBufferReader(br){$.checkArgument(br,"br is required");var info=Block._fromBufferReader(br);return new Block(info)};Block.fromBuffer=function fromBuffer(buf){return Block.fromBufferReader(new BufferReader(buf))};Block.fromString=function fromString(str){var buf=new Buffer(str,"hex");return Block.fromBuffer(buf)};Block.fromRawBlock=function fromRawBlock(data){if(!BufferUtil.isBuffer(data)){data=new Buffer(data,"binary")}var br=BufferReader(data);br.pos=Block.Values.START_OF_BLOCK;var info=Block._fromBufferReader(br);return new Block(info)};Block.prototype.toObject=Block.prototype.toJSON=function toObject(){var transactions=[];this.transactions.forEach(function(tx){transactions.push(tx.toObject())});return{header:this.header.toObject(),transactions:transactions}};Block.prototype.toBuffer=function toBuffer(){return this.toBufferWriter().concat()};Block.prototype.toString=function toString(){return this.toBuffer().toString("hex")};Block.prototype.toBufferWriter=function toBufferWriter(bw){if(!bw){bw=new BufferWriter}bw.write(this.header.toBuffer());bw.writeVarintNum(this.transactions.length);for(var i=0;i<this.transactions.length;i++){this.transactions[i].toBufferWriter(bw)}return bw};Block.prototype.getTransactionHashes=function getTransactionHashes(){var hashes=[];if(this.transactions.length===0){return[Block.Values.NULL_HASH]}for(var t=0;t<this.transactions.length;t++){hashes.push(this.transactions[t]._getHash())}return hashes};Block.prototype.getMerkleTree=function getMerkleTree(){var tree=this.getTransactionHashes();var j=0;for(var size=this.transactions.length;size>1;size=Math.floor((size+1)/2)){for(var i=0;i<size;i+=2){var i2=Math.min(i+1,size-1);var buf=Buffer.concat([tree[j+i],tree[j+i2]]);tree.push(Hash.sha256sha256(buf))}j+=size}return tree};Block.prototype.getMerkleRoot=function getMerkleRoot(){var tree=this.getMerkleTree();return tree[tree.length-1]};Block.prototype.validMerkleRoot=function validMerkleRoot(){var h=new BN(this.header.merkleRoot.toString("hex"),"hex");var c=new BN(this.getMerkleRoot().toString("hex"),"hex");if(h.cmp(c)!==0){return false}return true};Block.prototype._getHash=function(){return this.header._getHash()};var idProperty={configurable:false,enumerable:true,get:function(){if(!this._id){this._id=this.header.id}return this._id},set:_.noop};Object.defineProperty(Block.prototype,"id",idProperty);Object.defineProperty(Block.prototype,"hash",idProperty);Block.prototype.inspect=function inspect(){return"<Block "+this.id+">"};Block.Values={START_OF_BLOCK:8,NULL_HASH:new Buffer("0000000000000000000000000000000000000000000000000000000000000000","hex")};module.exports=Block}).call(this,require("buffer").Buffer)},{"../crypto/bn":14,"../crypto/hash":16,"../encoding/bufferreader":22,"../encoding/bufferwriter":23,"../transaction":37,"../util/buffer":51,"../util/preconditions":53,"./blockheader":11,buffer:218,lodash:79}],11:[function(require,module,exports){(function(Buffer){"use strict";var _=require("lodash");var BN=require("../crypto/bn");var BufferUtil=require("../util/buffer");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var JSUtil=require("../util/js");var $=require("../util/preconditions");var GENESIS_BITS=486604799;var BlockHeader=function BlockHeader(arg){if(!(this instanceof BlockHeader)){return new BlockHeader(arg)}var info=BlockHeader._from(arg);this.version=info.version;this.prevHash=info.prevHash;this.merkleRoot=info.merkleRoot;this.time=info.time;this.timestamp=info.time;this.bits=info.bits;this.nonce=info.nonce;if(info.hash){$.checkState(this.hash===info.hash,"Argument object hash property does not match block hash.")}return this};BlockHeader._from=function _from(arg){var info={};if(BufferUtil.isBuffer(arg)){info=BlockHeader._fromBufferReader(BufferReader(arg))}else if(_.isObject(arg)){info=BlockHeader._fromObject(arg)}else{throw new TypeError("Unrecognized argument for BlockHeader")}return info};BlockHeader._fromObject=function _fromObject(data){$.checkArgument(data,"data is required");var prevHash=data.prevHash;var merkleRoot=data.merkleRoot;if(_.isString(data.prevHash)){prevHash=BufferUtil.reverse(new Buffer(data.prevHash,"hex"))}if(_.isString(data.merkleRoot)){merkleRoot=BufferUtil.reverse(new Buffer(data.merkleRoot,"hex"))}var info={hash:data.hash,version:data.version,prevHash:prevHash,merkleRoot:merkleRoot,time:data.time,timestamp:data.time,bits:data.bits,nonce:data.nonce};return info};BlockHeader.fromObject=function fromObject(obj){var info=BlockHeader._fromObject(obj);return new BlockHeader(info)};BlockHeader.fromRawBlock=function fromRawBlock(data){if(!BufferUtil.isBuffer(data)){data=new Buffer(data,"binary")}var br=BufferReader(data);br.pos=BlockHeader.Constants.START_OF_HEADER;var info=BlockHeader._fromBufferReader(br);return new BlockHeader(info)};BlockHeader.fromBuffer=function fromBuffer(buf){var info=BlockHeader._fromBufferReader(BufferReader(buf));return new BlockHeader(info)};BlockHeader.fromString=function fromString(str){var buf=new Buffer(str,"hex");return BlockHeader.fromBuffer(buf)};BlockHeader._fromBufferReader=function _fromBufferReader(br){var info={};info.version=br.readUInt32LE();info.prevHash=br.read(32);info.merkleRoot=br.read(32);info.time=br.readUInt32LE();info.bits=br.readUInt32LE();info.nonce=br.readUInt32LE();return info};BlockHeader.fromBufferReader=function fromBufferReader(br){var info=BlockHeader._fromBufferReader(br);return new BlockHeader(info)};BlockHeader.prototype.toObject=BlockHeader.prototype.toJSON=function toObject(){return{hash:this.hash,version:this.version,prevHash:BufferUtil.reverse(this.prevHash).toString("hex"),merkleRoot:BufferUtil.reverse(this.merkleRoot).toString("hex"),time:this.time,bits:this.bits,nonce:this.nonce}};BlockHeader.prototype.toBuffer=function toBuffer(){return this.toBufferWriter().concat()};BlockHeader.prototype.toString=function toString(){return this.toBuffer().toString("hex")};BlockHeader.prototype.toBufferWriter=function toBufferWriter(bw){if(!bw){bw=new BufferWriter}bw.writeUInt32LE(this.version);bw.write(this.prevHash);bw.write(this.merkleRoot);bw.writeUInt32LE(this.time);bw.writeUInt32LE(this.bits);bw.writeUInt32LE(this.nonce);return bw};BlockHeader.prototype.getTargetDifficulty=function getTargetDifficulty(bits){bits=bits||this.bits;var target=new BN(bits&16777215);var mov=8*((bits>>>24)-3);while(mov-- >0){target=target.mul(new BN(2))}return target};BlockHeader.prototype.getDifficulty=function getDifficulty(){var difficulty1TargetBN=this.getTargetDifficulty(GENESIS_BITS).mul(new BN(Math.pow(10,8)));var currentTargetBN=this.getTargetDifficulty();var difficultyString=difficulty1TargetBN.div(currentTargetBN).toString(10);var decimalPos=difficultyString.length-8;difficultyString=difficultyString.slice(0,decimalPos)+"."+difficultyString.slice(decimalPos);return parseFloat(difficultyString)};BlockHeader.prototype._getHash=function hash(){var buf=this.toBuffer();return Hash.sha256sha256(buf)};var idProperty={configurable:false,enumerable:true,get:function(){if(!this._id){this._id=BufferReader(this._getHash()).readReverse().toString("hex")}return this._id},set:_.noop};Object.defineProperty(BlockHeader.prototype,"id",idProperty);Object.defineProperty(BlockHeader.prototype,"hash",idProperty);BlockHeader.prototype.validTimestamp=function validTimestamp(){var currentTime=Math.round((new Date).getTime()/1e3);if(this.time>currentTime+BlockHeader.Constants.MAX_TIME_OFFSET){return false}return true};BlockHeader.prototype.validProofOfWork=function validProofOfWork(){var pow=new BN(this.id,"hex");var target=this.getTargetDifficulty();if(pow.cmp(target)>0){return false}return true};BlockHeader.prototype.inspect=function inspect(){return"<BlockHeader "+this.id+">"};BlockHeader.Constants={START_OF_HEADER:8,MAX_TIME_OFFSET:2*60*60,LARGEST_HASH:new BN("10000000000000000000000000000000000000000000000000000000000000000","hex")};module.exports=BlockHeader}).call(this,require("buffer").Buffer)},{"../crypto/bn":14,"../crypto/hash":16,"../encoding/bufferreader":22,"../encoding/bufferwriter":23,"../util/buffer":51,"../util/js":52,"../util/preconditions":53,buffer:218,lodash:79}],12:[function(require,module,exports){module.exports=require("./block");module.exports.BlockHeader=require("./blockheader");module.exports.MerkleBlock=require("./merkleblock")},{"./block":10,"./blockheader":11,"./merkleblock":13}],13:[function(require,module,exports){(function(Buffer){"use strict";var _=require("lodash");var BlockHeader=require("./blockheader");var BufferUtil=require("../util/buffer");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var JSUtil=require("../util/js");var Transaction=require("../transaction");var $=require("../util/preconditions");function MerkleBlock(arg){if(!(this instanceof MerkleBlock)){return new MerkleBlock(arg)}var info={};if(BufferUtil.isBuffer(arg)){info=MerkleBlock._fromBufferReader(BufferReader(arg))}else if(_.isObject(arg)){var header;if(arg.header instanceof BlockHeader){header=arg.header}else{header=BlockHeader.fromObject(arg.header)}info={header:header,numTransactions:arg.numTransactions,hashes:arg.hashes,flags:arg.flags}}else{throw new TypeError("Unrecognized argument for MerkleBlock")}_.extend(this,info);this._flagBitsUsed=0;this._hashesUsed=0;return this}MerkleBlock.fromBuffer=function fromBuffer(buf){return MerkleBlock.fromBufferReader(BufferReader(buf))};MerkleBlock.fromBufferReader=function fromBufferReader(br){return new MerkleBlock(MerkleBlock._fromBufferReader(br))};MerkleBlock.prototype.toBuffer=function toBuffer(){return this.toBufferWriter().concat()};MerkleBlock.prototype.toBufferWriter=function toBufferWriter(bw){if(!bw){bw=new BufferWriter}bw.write(this.header.toBuffer());bw.writeUInt32LE(this.numTransactions);bw.writeVarintNum(this.hashes.length);for(var i=0;i<this.hashes.length;i++){bw.write(new Buffer(this.hashes[i],"hex"))}bw.writeVarintNum(this.flags.length);for(i=0;i<this.flags.length;i++){bw.writeUInt8(this.flags[i])}return bw};MerkleBlock.prototype.toObject=MerkleBlock.prototype.toJSON=function toObject(){return{header:this.header.toObject(),numTransactions:this.numTransactions,hashes:this.hashes,flags:this.flags}};MerkleBlock.prototype.validMerkleTree=function validMerkleTree(){$.checkState(_.isArray(this.flags),"MerkleBlock flags is not an array");$.checkState(_.isArray(this.hashes),"MerkleBlock hashes is not an array");if(this.hashes.length>this.numTransactions){return false}if(this.flags.length*8<this.hashes.length){return false}var height=this._calcTreeHeight();var opts={hashesUsed:0,flagBitsUsed:0};var root=this._traverseMerkleTree(height,0,opts);if(opts.hashesUsed!==this.hashes.length){return false}return BufferUtil.equals(root,this.header.merkleRoot)};MerkleBlock.prototype._traverseMerkleTree=function traverseMerkleTree(depth,pos,opts){opts=opts||{};opts.txs=opts.txs||[];opts.flagBitsUsed=opts.flagBitsUsed||0;opts.hashesUsed=opts.hashesUsed||0;if(opts.flagBitsUsed>this.flags.length*8){return null}var isParentOfMatch=this.flags[opts.flagBitsUsed>>3]>>>(opts.flagBitsUsed++&7)&1;if(depth===0||!isParentOfMatch){if(opts.hashesUsed>=this.hashes.length){return null}var hash=this.hashes[opts.hashesUsed++];if(depth===0&&isParentOfMatch){opts.txs.push(hash)}return new Buffer(hash,"hex")}else{var left=this._traverseMerkleTree(depth-1,pos*2,opts);var right=left;if(pos*2+1<this._calcTreeWidth(depth-1)){right=this._traverseMerkleTree(depth-1,pos*2+1,opts)}return Hash.sha256sha256(new Buffer.concat([left,right]))}};MerkleBlock.prototype._calcTreeWidth=function calcTreeWidth(height){return this.numTransactions+(1<<height)-1>>height};MerkleBlock.prototype._calcTreeHeight=function calcTreeHeight(){var height=0;while(this._calcTreeWidth(height)>1){height++}return height};MerkleBlock.prototype.hasTransaction=function hasTransaction(tx){$.checkArgument(!_.isUndefined(tx),"tx cannot be undefined");$.checkArgument(tx instanceof Transaction||typeof tx==="string",'Invalid tx given, tx must be a "string" or "Transaction"');var hash=tx;if(tx instanceof Transaction){hash=BufferUtil.reverse(new Buffer(tx.id,"hex")).toString("hex")}var txs=[];var height=this._calcTreeHeight();this._traverseMerkleTree(height,0,{txs:txs});return txs.indexOf(hash)!==-1};MerkleBlock._fromBufferReader=function _fromBufferReader(br){$.checkState(!br.finished(),"No merkleblock data received");var info={};info.header=BlockHeader.fromBufferReader(br);info.numTransactions=br.readUInt32LE();var numHashes=br.readVarintNum();info.hashes=[];for(var i=0;i<numHashes;i++){info.hashes.push(br.read(32).toString("hex"))}var numFlags=br.readVarintNum();info.flags=[];for(i=0;i<numFlags;i++){info.flags.push(br.readUInt8())}return info};MerkleBlock.fromObject=function fromObject(obj){return new MerkleBlock(obj)};module.exports=MerkleBlock}).call(this,require("buffer").Buffer)},{"../crypto/hash":16,"../encoding/bufferreader":22,"../encoding/bufferwriter":23,"../transaction":37,"../util/buffer":51,"../util/js":52,"../util/preconditions":53,"./blockheader":11,buffer:218,lodash:79}],14:[function(require,module,exports){(function(Buffer){"use strict";var BN=require("bn.js");var $=require("../util/preconditions");var _=require("lodash");var reversebuf=function(buf){var buf2=new Buffer(buf.length);for(var i=0;i<buf.length;i++){buf2[i]=buf[buf.length-1-i]}return buf2};BN.Zero=new BN(0);BN.One=new BN(1);BN.Minus1=new BN(-1);BN.fromNumber=function(n){$.checkArgument(_.isNumber(n));return new BN(n)};BN.fromString=function(str,base){$.checkArgument(_.isString(str));return new BN(str,base)};BN.fromBuffer=function(buf,opts){if(typeof opts!=="undefined"&&opts.endian==="little"){buf=reversebuf(buf)}var hex=buf.toString("hex");var bn=new BN(hex,16);return bn};BN.fromSM=function(buf,opts){var ret;if(buf.length===0){return BN.fromBuffer(new Buffer([0]))}var endian="big";if(opts){endian=opts.endian}if(endian==="little"){buf=reversebuf(buf)}if(buf[0]&128){buf[0]=buf[0]&127;ret=BN.fromBuffer(buf);ret.neg().copy(ret)}else{ret=BN.fromBuffer(buf)}return ret};BN.prototype.toNumber=function(){return parseInt(this.toString(10),10)};BN.prototype.toBuffer=function(opts){var buf,hex;if(opts&&opts.size){hex=this.toString(16,2);var natlen=hex.length/2;buf=new Buffer(hex,"hex");if(natlen===opts.size){buf=buf}else if(natlen>opts.size){buf=BN.trim(buf,natlen)}else if(natlen<opts.size){buf=BN.pad(buf,natlen,opts.size)}}else{hex=this.toString(16,2);buf=new Buffer(hex,"hex")}if(typeof opts!=="undefined"&&opts.endian==="little"){buf=reversebuf(buf)}return buf};BN.prototype.toSMBigEndian=function(){var buf;if(this.cmp(BN.Zero)===-1){buf=this.neg().toBuffer();if(buf[0]&128){buf=Buffer.concat([new Buffer([128]),buf])}else{buf[0]=buf[0]|128}}else{buf=this.toBuffer();if(buf[0]&128){buf=Buffer.concat([new Buffer([0]),buf])}}if(buf.length===1&buf[0]===0){buf=new Buffer([])}return buf};BN.prototype.toSM=function(opts){var endian=opts?opts.endian:"big";var buf=this.toSMBigEndian();if(endian==="little"){buf=reversebuf(buf)}return buf};BN.fromScriptNumBuffer=function(buf,fRequireMinimal,size){var nMaxNumSize=size||4;$.checkArgument(buf.length<=nMaxNumSize,new Error("script number overflow"));if(fRequireMinimal&&buf.length>0){if((buf[buf.length-1]&127)===0){if(buf.length<=1||(buf[buf.length-2]&128)===0){throw new Error("non-minimally encoded script number")}}}return BN.fromSM(buf,{endian:"little"})};BN.prototype.toScriptNumBuffer=function(){return this.toSM({endian:"little"})};BN.prototype.gt=function(b){return this.cmp(b)>0};BN.prototype.gte=function(b){return this.cmp(b)>=0};BN.prototype.lt=function(b){return this.cmp(b)<0};BN.trim=function(buf,natlen){return buf.slice(natlen-buf.length,buf.length)};BN.pad=function(buf,natlen,size){var rbuf=new Buffer(size);for(var i=0;i<buf.length;i++){rbuf[rbuf.length-1-i]=buf[buf.length-1-i]}for(i=0;i<size-natlen;i++){rbuf[i]=0}return rbuf};module.exports=BN}).call(this,require("buffer").Buffer)},{"../util/preconditions":53,"bn.js":54,buffer:218,lodash:79}],15:[function(require,module,exports){(function(Buffer){"use strict";var BN=require("./bn");var Point=require("./point");var Signature=require("./signature");var PublicKey=require("../publickey");var Random=require("./random");var Hash=require("./hash");var BufferUtil=require("../util/buffer");var _=require("lodash");var $=require("../util/preconditions");var ECDSA=function ECDSA(obj){if(!(this instanceof ECDSA)){return new ECDSA(obj)}if(obj){this.set(obj)}};ECDSA.prototype.set=function(obj){this.hashbuf=obj.hashbuf||this.hashbuf;this.endian=obj.endian||this.endian;this.privkey=obj.privkey||this.privkey;this.pubkey=obj.pubkey||(this.privkey?this.privkey.publicKey:this.pubkey);this.sig=obj.sig||this.sig;this.k=obj.k||this.k;this.verified=obj.verified||this.verified;return this};ECDSA.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()};ECDSA.prototype.calci=function(){for(var i=0;i<4;i++){this.sig.i=i;var Qprime;try{Qprime=this.toPublicKey()}catch(e){console.error(e);continue}if(Qprime.point.eq(this.pubkey.point)){this.sig.compressed=this.pubkey.compressed;return this}}this.sig.i=undefined;throw new Error("Unable to find valid recovery factor")};ECDSA.fromString=function(str){var obj=JSON.parse(str);return new ECDSA(obj)};ECDSA.prototype.randomK=function(){var N=Point.getN();var k;do{k=BN.fromBuffer(Random.getRandomBuffer(32))}while(!(k.lt(N)&&k.gt(BN.Zero)));this.k=k;return this};ECDSA.prototype.deterministicK=function(badrs){if(_.isUndefined(badrs)){badrs=0}var v=new Buffer(32);v.fill(1);var k=new Buffer(32);k.fill(0);var x=this.privkey.bn.toBuffer({size:32});var hashbuf=this.endian==="little"?BufferUtil.reverse(this.hashbuf):this.hashbuf;k=Hash.sha256hmac(Buffer.concat([v,new Buffer([0]),x,hashbuf]),k);v=Hash.sha256hmac(v,k);k=Hash.sha256hmac(Buffer.concat([v,new Buffer([1]),x,hashbuf]),k);v=Hash.sha256hmac(v,k);v=Hash.sha256hmac(v,k);var T=BN.fromBuffer(v);var N=Point.getN();for(var i=0;i<badrs||!(T.lt(N)&&T.gt(BN.Zero));i++){k=Hash.sha256hmac(Buffer.concat([v,new Buffer([0])]),k);v=Hash.sha256hmac(v,k);v=Hash.sha256hmac(v,k);T=BN.fromBuffer(v)}this.k=T;return this};ECDSA.prototype.toPublicKey=function(){var i=this.sig.i;$.checkArgument(i===0||i===1||i===2||i===3,new Error("i must be equal to 0, 1, 2, or 3"));var e=BN.fromBuffer(this.hashbuf);var r=this.sig.r;var s=this.sig.s;var isYOdd=i&1;var isSecondKey=i>>1;var n=Point.getN();var G=Point.getG();var x=isSecondKey?r.add(n):r;var R=Point.fromX(isYOdd,x);var nR=R.mul(n);if(!nR.isInfinity()){throw new Error("nR is not a valid curve point")}var eNeg=e.neg().mod(n);var rInv=r.invm(n);var Q=R.mul(s).add(G.mul(eNeg)).mul(rInv);var pubkey=PublicKey.fromPoint(Q,this.sig.compressed);return pubkey};ECDSA.prototype.sigError=function(){if(!BufferUtil.isBuffer(this.hashbuf)||this.hashbuf.length!==32){return"hashbuf must be a 32 byte buffer"}var r=this.sig.r;var s=this.sig.s;if(!(r.gt(BN.Zero)&&r.lt(Point.getN()))||!(s.gt(BN.Zero)&&s.lt(Point.getN()))){return"r and s not in range"}var e=BN.fromBuffer(this.hashbuf,this.endian?{endian:this.endian}:undefined);var n=Point.getN();var sinv=s.invm(n);var u1=sinv.mul(e).mod(n);var u2=sinv.mul(r).mod(n);var p=Point.getG().mulAdd(u1,this.pubkey.point,u2);if(p.isInfinity()){return"p is infinity"}if(p.getX().mod(n).cmp(r)!==0){return"Invalid signature"}else{return false}};ECDSA.toLowS=function(s){if(s.gt(BN.fromBuffer(new Buffer("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))){s=Point.getN().sub(s)}return s};ECDSA.prototype._findSignature=function(d,e){var N=Point.getN();var G=Point.getG();var badrs=0;var k,Q,r,s;do{if(!this.k||badrs>0){this.deterministicK(badrs)}badrs++;k=this.k;Q=G.mul(k);r=Q.x.mod(N);s=k.invm(N).mul(e.add(d.mul(r))).mod(N)}while(r.cmp(BN.Zero)<=0||s.cmp(BN.Zero)<=0);s=ECDSA.toLowS(s);return{s:s,r:r}};ECDSA.prototype.sign=function(){var hashbuf=this.hashbuf;var privkey=this.privkey;var d=privkey.bn;$.checkState(hashbuf&&privkey&&d,new Error("invalid parameters"));$.checkState(BufferUtil.isBuffer(hashbuf)&&hashbuf.length===32,new Error("hashbuf must be a 32 byte buffer"));var e=BN.fromBuffer(hashbuf,this.endian?{endian:this.endian}:undefined);var obj=this._findSignature(d,e);obj.compressed=this.pubkey.compressed;this.sig=new Signature(obj);return this};ECDSA.prototype.signRandomK=function(){this.randomK();return this.sign()};ECDSA.prototype.toString=function(){var obj={};if(this.hashbuf){obj.hashbuf=this.hashbuf.toString("hex")}if(this.privkey){obj.privkey=this.privkey.toString()}if(this.pubkey){obj.pubkey=this.pubkey.toString()}if(this.sig){obj.sig=this.sig.toString()}if(this.k){obj.k=this.k.toString()}return JSON.stringify(obj)};ECDSA.prototype.verify=function(){if(!this.sigError()){this.verified=true}else{this.verified=false}return this};ECDSA.sign=function(hashbuf,privkey,endian){return ECDSA().set({hashbuf:hashbuf,endian:endian,privkey:privkey}).sign().sig};ECDSA.verify=function(hashbuf,sig,pubkey,endian){return ECDSA().set({hashbuf:hashbuf,endian:endian,sig:sig,pubkey:pubkey}).verify().verified};module.exports=ECDSA}).call(this,require("buffer").Buffer)},{"../publickey":33,"../util/buffer":51,"../util/preconditions":53,"./bn":14,"./hash":16,"./point":17,"./random":18,"./signature":19,buffer:218,lodash:79}],16:[function(require,module,exports){(function(Buffer){"use strict";var crypto=require("crypto");var BufferUtil=require("../util/buffer");var $=require("../util/preconditions");var Hash=module.exports;Hash.sha1=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha1").update(buf).digest()};Hash.sha1.blocksize=512;Hash.sha256=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha256").update(buf).digest()};Hash.sha256.blocksize=512;Hash.sha256sha256=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return Hash.sha256(Hash.sha256(buf))};Hash.ripemd160=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("ripemd160").update(buf).digest()};Hash.sha256ripemd160=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return Hash.ripemd160(Hash.sha256(buf))};Hash.sha512=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha512").update(buf).digest()};Hash.sha512.blocksize=1024;Hash.hmac=function(hashf,data,key){$.checkArgument(BufferUtil.isBuffer(data));$.checkArgument(BufferUtil.isBuffer(key));$.checkArgument(hashf.blocksize);var blocksize=hashf.blocksize/8;if(key.length>blocksize){key=hashf(key)}else if(key<blocksize){var fill=new Buffer(blocksize);fill.fill(0);key.copy(fill);key=fill}var o_key=new Buffer(blocksize);o_key.fill(92);var i_key=new Buffer(blocksize);i_key.fill(54);var o_key_pad=new Buffer(blocksize);var i_key_pad=new Buffer(blocksize);for(var i=0;i<blocksize;i++){o_key_pad[i]=o_key[i]^key[i];i_key_pad[i]=i_key[i]^key[i]}return hashf(Buffer.concat([o_key_pad,hashf(Buffer.concat([i_key_pad,data]))]))};Hash.sha256hmac=function(data,key){return Hash.hmac(Hash.sha256,data,key)};Hash.sha512hmac=function(data,key){return Hash.hmac(Hash.sha512,data,key)}}).call(this,require("buffer").Buffer)},{"../util/buffer":51,"../util/preconditions":53,buffer:218,crypto:227}],17:[function(require,module,exports){(function(Buffer){"use strict";var BN=require("./bn");var BufferUtil=require("../util/buffer");var ec=require("elliptic").curves.secp256k1;var ecPoint=ec.curve.point.bind(ec.curve);var ecPointFromX=ec.curve.pointFromX.bind(ec.curve);var Point=function Point(x,y,isRed){var point=ecPoint(x,y,isRed);point.validate();return point};Point.prototype=Object.getPrototypeOf(ec.curve.point());Point.fromX=function fromX(odd,x){var point=ecPointFromX(odd,x);point.validate();return point};Point.getG=function getG(){return ec.curve.g};Point.getN=function getN(){return new BN(ec.curve.n.toArray())};Point.prototype._getX=Point.prototype.getX;Point.prototype.getX=function getX(){return new BN(this._getX().toArray())};Point.prototype._getY=Point.prototype.getY;Point.prototype.getY=function getY(){return new BN(this._getY().toArray())};Point.prototype.validate=function validate(){if(this.isInfinity()){throw new Error("Point cannot be equal to Infinity")}if(this.getX().cmp(BN.Zero)===0||this.getY().cmp(BN.Zero)===0){throw new Error("Invalid x,y value for curve, cannot equal 0.")}var p2=ecPointFromX(this.getY().isOdd(),this.getX());if(p2.y.cmp(this.y)!==0){throw new Error("Invalid y value for curve.")}var xValidRange=this.getX().gt(BN.Minus1)&&this.getX().lt(Point.getN());var yValidRange=this.getY().gt(BN.Minus1)&&this.getY().lt(Point.getN());if(!xValidRange||!yValidRange){throw new Error("Point does not lie on the curve")}if(!this.mul(Point.getN()).isInfinity()){throw new Error("Point times N must be infinity")}return this};Point.pointToCompressed=function pointToCompressed(point){var xbuf=point.getX().toBuffer({size:32});var ybuf=point.getY().toBuffer({size:32});var prefix;var odd=ybuf[ybuf.length-1]%2;if(odd){prefix=new Buffer([3])}else{prefix=new Buffer([2])}return BufferUtil.concat([prefix,xbuf])};module.exports=Point}).call(this,require("buffer").Buffer)},{"../util/buffer":51,"./bn":14,buffer:218,elliptic:57}],18:[function(require,module,exports){(function(process,Buffer){"use strict";function Random(){}Random.getRandomBuffer=function(size){if(process.browser)return Random.getRandomBufferBrowser(size);else return Random.getRandomBufferNode(size)};Random.getRandomBufferNode=function(size){var crypto=require("crypto");return crypto.randomBytes(size)};Random.getRandomBufferBrowser=function(size){if(!window.crypto&&!window.msCrypto)throw new Error("window.crypto not available");if(window.crypto&&window.crypto.getRandomValues)var crypto=window.crypto;else if(window.msCrypto&&window.msCrypto.getRandomValues)var crypto=window.msCrypto;else throw new Error("window.crypto.getRandomValues not available");var bbuf=new Uint8Array(size);crypto.getRandomValues(bbuf);var buf=new Buffer(bbuf);return buf};Random.getPseudoRandomBuffer=function(size){var b32=4294967296;var b=new Buffer(size);var r;for(var i=0;i<=size;i++){var j=Math.floor(i/4);var k=i-j*4;if(k===0){r=Math.random()*b32;b[i]=r&255}else{b[i]=(r=r>>>8)&255}}return b};module.exports=Random}).call(this,require("_process"),require("buffer").Buffer)},{_process:289,buffer:218,crypto:227}],19:[function(require,module,exports){(function(Buffer){"use strict";var BN=require("./bn");var _=require("lodash");var $=require("../util/preconditions");var BufferUtil=require("../util/buffer");var JSUtil=require("../util/js");var Signature=function Signature(r,s){if(!(this instanceof Signature)){return new Signature(r,s)}if(r instanceof BN){this.set({r:r,s:s})}else if(r){var obj=r;this.set(obj)}};Signature.prototype.set=function(obj){this.r=obj.r||this.r||undefined;this.s=obj.s||this.s||undefined;this.i=typeof obj.i!=="undefined"?obj.i:this.i;this.compressed=typeof obj.compressed!=="undefined"?obj.compressed:this.compressed;this.nhashtype=o