(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.ledger=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;o0){throw new Error("Invalid string. Length must be a multiple of 4")}return b64[len-2]==="="?2:b64[len-1]==="="?1:0}function byteLength(b64){return b64.length*3/4-placeHoldersCount(b64)}function toByteArray(b64){var i,l,tmp,placeHolders,arr;var len=b64.length;placeHolders=placeHoldersCount(b64);arr=new Arr(len*3/4-placeHolders);l=placeHolders>0?len-4:len;var L=0;for(i=0;i>16&255;arr[L++]=tmp>>8&255;arr[L++]=tmp&255}if(placeHolders===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[L++]=tmp&255}else if(placeHolders===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[L++]=tmp>>8&255;arr[L++]=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;ilen2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];output+=lookup[tmp>>2];output+=lookup[tmp<<4&63];output+="=="}else if(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];output+=lookup[tmp>>10];output+=lookup[tmp>>4&63];output+=lookup[tmp<<2&63];output+="="}parts.push(output);return parts.join("")}},{}],2:[function(require,module,exports){(function(global){"use strict";var base64=require("base64-js");var ieee754=require("ieee754");var isArray=require("isarray");exports.Buffer=Buffer;exports.SlowBuffer=SlowBuffer;exports.INSPECT_MAX_BYTES=50;Buffer.TYPED_ARRAY_SUPPORT=global.TYPED_ARRAY_SUPPORT!==undefined?global.TYPED_ARRAY_SUPPORT:typedArraySupport();exports.kMaxLength=kMaxLength();function typedArraySupport(){try{var arr=new Uint8Array(1);arr.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}};return arr.foo()===42&&typeof arr.subarray==="function"&&arr.subarray(1,1).byteLength===0}catch(e){return false}}function kMaxLength(){return Buffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function createBuffer(that,length){if(kMaxLength()=kMaxLength()){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+kMaxLength().toString(16)+" bytes")}return length|0}function SlowBuffer(length){if(+length!=length){length=0}return Buffer.alloc(+length)}Buffer.isBuffer=function isBuffer(b){return!!(b!=null&&b._isBuffer)};Buffer.compare=function compare(a,b){if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b)){throw new TypeError("Arguments must be Buffers")}if(a===b)return 0;var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i>>1;case"base64":return base64ToBytes(string).length;default:if(loweredCase)return utf8ToBytes(string).length;encoding=(""+encoding).toLowerCase();loweredCase=true}}}Buffer.byteLength=byteLength;function slowToString(encoding,start,end){var loweredCase=false;if(start===undefined||start<0){start=0}if(start>this.length){return""}if(end===undefined||end>this.length){end=this.length}if(end<=0){return""}end>>>=0;start>>>=0;if(end<=start){return""}if(!encoding)encoding="utf8";while(true){switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"latin1":case"binary":return latin1Slice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase();loweredCase=true}}}Buffer.prototype._isBuffer=true;function swap(b,n,m){var i=b[n];b[n]=b[m];b[m]=i}Buffer.prototype.swap16=function swap16(){var len=this.length;if(len%2!==0){throw new RangeError("Buffer size must be a multiple of 16-bits")}for(var i=0;i0){str=this.toString("hex",0,max).match(/.{2}/g).join(" ");if(this.length>max)str+=" ... "}return""};Buffer.prototype.compare=function compare(target,start,end,thisStart,thisEnd){if(!Buffer.isBuffer(target)){throw new TypeError("Argument must be a Buffer")}if(start===undefined){start=0}if(end===undefined){end=target?target.length:0}if(thisStart===undefined){thisStart=0}if(thisEnd===undefined){thisEnd=this.length}if(start<0||end>target.length||thisStart<0||thisEnd>this.length){throw new RangeError("out of range index")}if(thisStart>=thisEnd&&start>=end){return 0}if(thisStart>=thisEnd){return-1}if(start>=end){return 1}start>>>=0;end>>>=0;thisStart>>>=0;thisEnd>>>=0;if(this===target)return 0;var x=thisEnd-thisStart;var y=end-start;var len=Math.min(x,y);var thisCopy=this.slice(thisStart,thisEnd);var targetCopy=target.slice(start,end);for(var i=0;i2147483647){byteOffset=2147483647}else if(byteOffset<-2147483648){byteOffset=-2147483648}byteOffset=+byteOffset;if(isNaN(byteOffset)){byteOffset=dir?0:buffer.length-1}if(byteOffset<0)byteOffset=buffer.length+byteOffset;if(byteOffset>=buffer.length){if(dir)return-1;else byteOffset=buffer.length-1}else if(byteOffset<0){if(dir)byteOffset=0;else return-1}if(typeof val==="string"){val=Buffer.from(val,encoding)}if(Buffer.isBuffer(val)){if(val.length===0){return-1}return arrayIndexOf(buffer,val,byteOffset,encoding,dir)}else if(typeof val==="number"){val=val&255;if(Buffer.TYPED_ARRAY_SUPPORT&&typeof Uint8Array.prototype.indexOf==="function"){if(dir){return Uint8Array.prototype.indexOf.call(buffer,val,byteOffset)}else{return Uint8Array.prototype.lastIndexOf.call(buffer,val,byteOffset)}}return arrayIndexOf(buffer,[val],byteOffset,encoding,dir)}throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(arr,val,byteOffset,encoding,dir){var indexSize=1;var arrLength=arr.length;var valLength=val.length;if(encoding!==undefined){encoding=String(encoding).toLowerCase();if(encoding==="ucs2"||encoding==="ucs-2"||encoding==="utf16le"||encoding==="utf-16le"){if(arr.length<2||val.length<2){return-1}indexSize=2;arrLength/=2;valLength/=2;byteOffset/=2}}function read(buf,i){if(indexSize===1){return buf[i]}else{return buf.readUInt16BE(i*indexSize)}}var i;if(dir){var foundIndex=-1;for(i=byteOffset;iarrLength)byteOffset=arrLength-valLength;for(i=byteOffset;i>=0;i--){var found=true;for(var j=0;jremaining){length=remaining}}var strLen=string.length;if(strLen%2!==0)throw new TypeError("Invalid hex string");if(length>strLen/2){length=strLen/2}for(var i=0;iremaining)length=remaining;if(string.length>0&&(length<0||offset<0)||offset>this.length){throw new RangeError("Attempt to write outside buffer bounds")}if(!encoding)encoding="utf8";var loweredCase=false;for(;;){switch(encoding){case"hex":return hexWrite(this,string,offset,length);case"utf8":case"utf-8":return utf8Write(this,string,offset,length);case"ascii":return asciiWrite(this,string,offset,length);case"latin1":case"binary":return latin1Write(this,string,offset,length);case"base64":return base64Write(this,string,offset,length);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,string,offset,length);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(""+encoding).toLowerCase();loweredCase=true}}};Buffer.prototype.toJSON=function toJSON(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function base64Slice(buf,start,end){if(start===0&&end===buf.length){return base64.fromByteArray(buf)}else{return base64.fromByteArray(buf.slice(start,end))}}function utf8Slice(buf,start,end){end=Math.min(buf.length,end);var res=[];var i=start;while(i239?4:firstByte>223?3:firstByte>191?2:1;if(i+bytesPerSequence<=end){var secondByte,thirdByte,fourthByte,tempCodePoint;switch(bytesPerSequence){case 1:if(firstByte<128){codePoint=firstByte}break;case 2:secondByte=buf[i+1];if((secondByte&192)===128){tempCodePoint=(firstByte&31)<<6|secondByte&63;if(tempCodePoint>127){codePoint=tempCodePoint}}break;case 3:secondByte=buf[i+1];thirdByte=buf[i+2];if((secondByte&192)===128&&(thirdByte&192)===128){tempCodePoint=(firstByte&15)<<12|(secondByte&63)<<6|thirdByte&63;if(tempCodePoint>2047&&(tempCodePoint<55296||tempCodePoint>57343)){codePoint=tempCodePoint}}break;case 4:secondByte=buf[i+1];thirdByte=buf[i+2];fourthByte=buf[i+3];if((secondByte&192)===128&&(thirdByte&192)===128&&(fourthByte&192)===128){tempCodePoint=(firstByte&15)<<18|(secondByte&63)<<12|(thirdByte&63)<<6|fourthByte&63;if(tempCodePoint>65535&&tempCodePoint<1114112){codePoint=tempCodePoint}}}}if(codePoint===null){codePoint=65533;bytesPerSequence=1}else if(codePoint>65535){codePoint-=65536;res.push(codePoint>>>10&1023|55296);codePoint=56320|codePoint&1023}res.push(codePoint);i+=bytesPerSequence}return decodeCodePointsArray(res)}var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(codePoints){var len=codePoints.length;if(len<=MAX_ARGUMENTS_LENGTH){return String.fromCharCode.apply(String,codePoints)}var res="";var i=0;while(ilen)end=len;var out="";for(var i=start;ilen){start=len}if(end<0){end+=len;if(end<0)end=0}else if(end>len){end=len}if(endlength)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function readUIntLE(offset,byteLength,noAssert){offset=offset|0;byteLength=byteLength|0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i0&&(mul*=256)){val+=this[offset+--byteLength]*mul}return val};Buffer.prototype.readUInt8=function readUInt8(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function readUInt16LE(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function readUInt16BE(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function readUInt32LE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function readUInt32BE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function readIntLE(offset,byteLength,noAssert){offset=offset|0;byteLength=byteLength|0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function readIntBE(offset,byteLength,noAssert){offset=offset|0;byteLength=byteLength|0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256)){val+=this[offset+--i]*mul}mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function readInt8(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function readInt16LE(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function readInt16BE(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function readInt32LE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function readInt32BE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function readFloatLE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function readFloatBE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function readDoubleLE(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function readDoubleBE(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError('"buffer" argument must be a Buffer instance');if(value>max||valuebuf.length)throw new RangeError("Index out of range")}Buffer.prototype.writeUIntLE=function writeUIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset|0;byteLength=byteLength|0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var mul=1;var i=0;this[offset]=value&255;while(++i=0&&(mul*=256)){this[offset+i]=value/mul&255}return offset+byteLength};Buffer.prototype.writeUInt8=function writeUInt8(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,1,255,0);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);this[offset]=value&255;return offset+1};function objectWriteUInt16(buf,value,offset,littleEndian){if(value<0)value=65535+value+1;for(var i=0,j=Math.min(buf.length-offset,2);i>>(littleEndian?i:1-i)*8}}Buffer.prototype.writeUInt16LE=function writeUInt16LE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value&255;this[offset+1]=value>>>8}else{objectWriteUInt16(this,value,offset,true)}return offset+2};Buffer.prototype.writeUInt16BE=function writeUInt16BE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value&255}else{objectWriteUInt16(this,value,offset,false)}return offset+2};function objectWriteUInt32(buf,value,offset,littleEndian){if(value<0)value=4294967295+value+1;for(var i=0,j=Math.min(buf.length-offset,4);i>>(littleEndian?i:3-i)*8&255}}Buffer.prototype.writeUInt32LE=function writeUInt32LE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value&255}else{objectWriteUInt32(this,value,offset,true)}return offset+4};Buffer.prototype.writeUInt32BE=function writeUInt32BE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255}else{objectWriteUInt32(this,value,offset,false)}return offset+4};Buffer.prototype.writeIntLE=function writeIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset|0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=0;var mul=1;var sub=0;this[offset]=value&255;while(++i>0)-sub&255}return offset+byteLength};Buffer.prototype.writeIntBE=function writeIntBE(value,offset,byteLength,noAssert){value=+value;offset=offset|0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=byteLength-1;var mul=1;var sub=0;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){if(value<0&&sub===0&&this[offset+i+1]!==0){sub=1}this[offset+i]=(value/mul>>0)-sub&255}return offset+byteLength};Buffer.prototype.writeInt8=function writeInt8(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);if(value<0)value=255+value+1;this[offset]=value&255;return offset+1};Buffer.prototype.writeInt16LE=function writeInt16LE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value&255;this[offset+1]=value>>>8}else{objectWriteUInt16(this,value,offset,true)}return offset+2};Buffer.prototype.writeInt16BE=function writeInt16BE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value&255}else{objectWriteUInt16(this,value,offset,false)}return offset+2};Buffer.prototype.writeInt32LE=function writeInt32LE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value&255;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24}else{objectWriteUInt32(this,value,offset,true)}return offset+4};Buffer.prototype.writeInt32BE=function writeInt32BE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255}else{objectWriteUInt32(this,value,offset,false)}return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(offset+ext>buf.length)throw new RangeError("Index out of range");if(offset<0)throw new RangeError("Index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){if(!noAssert){checkIEEE754(buf,value,offset,4,3.4028234663852886e38,-3.4028234663852886e38)}ieee754.write(buf,value,offset,littleEndian,23,4);return offset+4}Buffer.prototype.writeFloatLE=function writeFloatLE(value,offset,noAssert){return writeFloat(this,value,offset,true,noAssert)};Buffer.prototype.writeFloatBE=function writeFloatBE(value,offset,noAssert){return writeFloat(this,value,offset,false,noAssert)};function writeDouble(buf,value,offset,littleEndian,noAssert){if(!noAssert){checkIEEE754(buf,value,offset,8,1.7976931348623157e308,-1.7976931348623157e308)}ieee754.write(buf,value,offset,littleEndian,52,8);return offset+8}Buffer.prototype.writeDoubleLE=function writeDoubleLE(value,offset,noAssert){return writeDouble(this,value,offset,true,noAssert)};Buffer.prototype.writeDoubleBE=function writeDoubleBE(value,offset,noAssert){return writeDouble(this,value,offset,false,noAssert)};Buffer.prototype.copy=function copy(target,targetStart,start,end){if(!start)start=0;if(!end&&end!==0)end=this.length;if(targetStart>=target.length)targetStart=target.length;if(!targetStart)targetStart=0;if(end>0&&end=this.length)throw new RangeError("sourceStart out of bounds");if(end<0)throw new RangeError("sourceEnd out of bounds");if(end>this.length)end=this.length;if(target.length-targetStart=0;--i){target[i+targetStart]=this[i+start]}}else if(len<1e3||!Buffer.TYPED_ARRAY_SUPPORT){ for(i=0;i>>0;end=end===undefined?this.length:end>>>0;if(!val)val=0;var i;if(typeof val==="number"){for(i=start;i55295&&codePoint<57344){if(!leadSurrogate){if(codePoint>56319){if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}leadSurrogate=codePoint;continue}if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}codePoint=(leadSurrogate-55296<<10|codePoint-56320)+65536}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189)}leadSurrogate=null;if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<1114112){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i>8;lo=c%256;byteArray.push(lo);byteArray.push(hi)}return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length){for(var i=0;i=dst.length||i>=src.length)break;dst[i+offset]=src[i]}return i}function isnan(val){return val!==val}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"base64-js":1,ieee754:3,isarray:4}],3:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m;var eLen=nBytes*8-mLen-1;var eMax=(1<>1;var nBits=-7;var i=isLE?nBytes-1:0;var d=isLE?-1:1;var s=buffer[offset+i];i+=d;e=s&(1<<-nBits)-1;s>>=-nBits;nBits+=eLen;for(;nBits>0;e=e*256+buffer[offset+i],i+=d,nBits-=8){}m=e&(1<<-nBits)-1;e>>=-nBits;nBits+=mLen;for(;nBits>0;m=m*256+buffer[offset+i],i+=d,nBits-=8){}if(e===0){e=1-eBias}else if(e===eMax){return m?NaN:(s?-1:1)*Infinity}else{m=m+Math.pow(2,mLen);e=e-eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)};exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c;var eLen=nBytes*8-mLen-1;var eMax=(1<>1;var rt=mLen===23?Math.pow(2,-24)-Math.pow(2,-77):0;var i=isLE?0:nBytes-1;var d=isLE?1:-1;var s=value<0||value===0&&1/value<0?1:0;value=Math.abs(value);if(isNaN(value)||value===Infinity){m=isNaN(value)?1:0;e=eMax}else{e=Math.floor(Math.log(value)/Math.LN2);if(value*(c=Math.pow(2,-e))<1){e--;c*=2}if(e+eBias>=1){value+=rt/c}else{value+=rt*Math.pow(2,1-eBias)}if(value*c>=2){e++;c/=2}if(e+eBias>=eMax){m=0;e=eMax}else if(e+eBias>=1){m=(value*c-1)*Math.pow(2,mLen);e=e+eBias}else{m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen);e=0}}for(;mLen>=8;buffer[offset+i]=m&255,i+=d,m/=256,mLen-=8){}e=e<0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8){}buffer[offset+i-d]|=s*128}},{}],4:[function(require,module,exports){var toString={}.toString;module.exports=Array.isArray||function(arr){return toString.call(arr)=="[object Array]"}},{}],5:[function(require,module,exports){var process=module.exports={};var cachedSetTimeout;var cachedClearTimeout;function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}(function(){try{if(typeof setTimeout==="function"){cachedSetTimeout=setTimeout}else{cachedSetTimeout=defaultSetTimout}}catch(e){cachedSetTimeout=defaultSetTimout}try{if(typeof clearTimeout==="function"){cachedClearTimeout=clearTimeout}else{cachedClearTimeout=defaultClearTimeout}}catch(e){cachedClearTimeout=defaultClearTimeout}})();function runTimeout(fun){if(cachedSetTimeout===setTimeout){return setTimeout(fun,0)}if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout){cachedSetTimeout=setTimeout;return setTimeout(fun,0)}try{return cachedSetTimeout(fun,0)}catch(e){try{return cachedSetTimeout.call(null,fun,0)}catch(e){return cachedSetTimeout.call(this,fun,0)}}}function runClearTimeout(marker){if(cachedClearTimeout===clearTimeout){return clearTimeout(marker)}if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout){cachedClearTimeout=clearTimeout;return clearTimeout(marker)}try{return cachedClearTimeout(marker)}catch(e){try{return cachedClearTimeout.call(null,marker)}catch(e){return cachedClearTimeout.call(this,marker)}}}var queue=[];var draining=false;var currentQueue;var queueIndex=-1;function cleanUpNextTick(){if(!draining||!currentQueue){return}draining=false;if(currentQueue.length){queue=currentQueue.concat(queue)}else{queueIndex=-1}if(queue.length){drainQueue()}}function drainQueue(){if(draining){return}var timeout=runTimeout(cleanUpNextTick);draining=true;var len=queue.length;while(len){currentQueue=queue;queue=[];while(++queueIndex1){for(var i=1;i=length){throw new TypeError}}while(1)}for(;index=qStartingLine&&lineNumber<=qEndingLine}function captureLine(){if(!hasStacks){return}try{throw new Error}catch(e){var lines=e.stack.split("\n");var firstLine=lines[0].indexOf("@")>0?lines[1]:lines[2];var fileNameAndLineNumber=getFileNameAndLineNumber(firstLine);if(!fileNameAndLineNumber){return}qFileName=fileNameAndLineNumber[0];return fileNameAndLineNumber[1]}}function deprecate(callback,name,alternative){return function(){if(typeof console!=="undefined"&&typeof console.warn==="function"){console.warn(name+" is deprecated, use "+alternative+" instead.",new Error("").stack)}return callback.apply(callback,arguments)}}function Q(value){if(value instanceof Promise){return value}if(isPromiseAlike(value)){return coerce(value)}else{return fulfill(value)}}Q.resolve=Q;Q.nextTick=nextTick;Q.longStackSupport=false;if(typeof process==="object"&&process&&process.env&&process.env.Q_DEBUG){Q.longStackSupport=true}Q.defer=defer;function defer(){var messages=[],progressListeners=[],resolvedPromise;var deferred=object_create(defer.prototype);var promise=object_create(Promise.prototype);promise.promiseDispatch=function(resolve,op,operands){var args=array_slice(arguments);if(messages){messages.push(args);if(op==="when"&&operands[1]){progressListeners.push(operands[1])}}else{Q.nextTick(function(){resolvedPromise.promiseDispatch.apply(resolvedPromise,args)})}};promise.valueOf=function(){if(messages){return promise}var nearerValue=nearer(resolvedPromise);if(isPromise(nearerValue)){resolvedPromise=nearerValue}return nearerValue};promise.inspect=function(){if(!resolvedPromise){return{state:"pending"}}return resolvedPromise.inspect()};if(Q.longStackSupport&&hasStacks){try{throw new Error}catch(e){promise.stack=e.stack.substring(e.stack.indexOf("\n")+1)}}function become(newPromise){resolvedPromise=newPromise;promise.source=newPromise;array_reduce(messages,function(undefined,message){Q.nextTick(function(){newPromise.promiseDispatch.apply(newPromise,message)})},void 0);messages=void 0;progressListeners=void 0}deferred.promise=promise;deferred.resolve=function(value){if(resolvedPromise){return}become(Q(value))};deferred.fulfill=function(value){if(resolvedPromise){return}become(fulfill(value))};deferred.reject=function(reason){if(resolvedPromise){return}become(reject(reason))};deferred.notify=function(progress){if(resolvedPromise){return}array_reduce(progressListeners,function(undefined,progressListener){Q.nextTick(function(){progressListener(progress)})},void 0)};return deferred}defer.prototype.makeNodeResolver=function(){var self=this;return function(error,value){if(error){self.reject(error)}else if(arguments.length>2){self.resolve(array_slice(arguments,1))}else{self.resolve(value)}}};Q.Promise=promise;Q.promise=promise;function promise(resolver){if(typeof resolver!=="function"){throw new TypeError("resolver must be a function.")}var deferred=defer();try{resolver(deferred.resolve,deferred.reject,deferred.notify)}catch(reason){deferred.reject(reason)}return deferred.promise}promise.race=race;promise.all=all;promise.reject=reject;promise.resolve=Q;Q.passByCopy=function(object){return object};Promise.prototype.passByCopy=function(){return this};Q.join=function(x,y){return Q(x).join(y)};Promise.prototype.join=function(that){return Q([this,that]).spread(function(x,y){if(x===y){return x}else{throw new Error("Can't join: not the same: "+x+" "+y)}})};Q.race=race;function race(answerPs){return promise(function(resolve,reject){for(var i=0,len=answerPs.length;i-1};u2f.getChromeRuntimePort_=function(callback){var port=chrome.runtime.connect(u2f.EXTENSION_ID,{includeTlsChannelId:true});setTimeout(function(){callback(new u2f.WrappedChromeRuntimePort_(port))},0)};u2f.getAuthenticatorPort_=function(callback){setTimeout(function(){callback(new u2f.WrappedAuthenticatorPort_)},0)};u2f.getIosPort_=function(callback){setTimeout(function(){callback(new u2f.WrappedIosPort_)},0)};u2f.WrappedChromeRuntimePort_=function(port){this.port_=port};u2f.formatSignRequest_=function(appId,challenge,registeredKeys,timeoutSeconds,reqId){if(js_api_version===undefined||js_api_version<1.1){var signRequests=[];for(var i=0;iLedgerBtc.MAX_SCRIPT_BLOCK?LedgerBtc.MAX_SCRIPT_BLOCK:script.length-offset;if(offset+blockSize!=script.length){scriptBlocks.push(script.slice(offset,offset+blockSize))}else{scriptBlocks.push(Buffer.concat([script.slice(offset,offset+blockSize),sequence]))}offset+=blockSize}return utils.eachSeries(scriptBlocks,function(scriptBlock){return currentObject.getTrustedInputRaw_async(false,undefined,scriptBlock)})};var processInputs=function(){return utils.eachSeries(transaction["inputs"],function(input){data=Buffer.concat([input["prevout"],currentObject.createVarint(input["script"].length)]);return currentObject.getTrustedInputRaw_async(false,undefined,data).then(function(result){return processScriptBlocks(input["script"],input["sequence"])})}).then(function(){data=currentObject.createVarint(transaction["outputs"].length);return currentObject.getTrustedInputRaw_async(false,undefined,data)})};var processOutputs=function(){return utils.eachSeries(transaction["outputs"],function(output){data=output["amount"];data=Buffer.concat([data,currentObject.createVarint(output["script"].length),output["script"]]);return currentObject.getTrustedInputRaw_async(false,undefined,data).then(function(result){})}).then(function(){data=transaction["locktime"];return currentObject.getTrustedInputRaw_async(false,undefined,data)})};var data=Buffer.concat([transaction["version"],currentObject.createVarint(transaction["inputs"].length)]);return currentObject.getTrustedInputRaw_async(true,indexLookup,data).then(processInputs).then(processOutputs)};LedgerBtc.prototype.getVarint=function(data,offset){if(data[offset]<253){return[data[offset],1]}if(data[offset]==253){return[(data[offset+2]<<8)+data[offset+1],3]}if(data[offset]==254){return[(data[offset+4]<<24)+(data[offset+3]<<16)+(data[offset+2]<<8)+data[offset+1],5]}};LedgerBtc.prototype.startUntrustedHashTransactionInputRaw_async=function(newTransaction,firstRound,transactionData){var buffer=Buffer.alloc(5);buffer[0]=224;buffer[1]=68;buffer[2]=firstRound?0:128;buffer[3]=newTransaction?0:128;buffer[4]=transactionData.length;buffer=Buffer.concat([buffer,transactionData],5+transactionData.length);return this.comm.exchange(buffer.toString("hex"),[36864])};LedgerBtc.prototype.startUntrustedHashTransactionInput_async=function(newTransaction,transaction,inputs){var currentObject=this;var data=Buffer.concat([transaction["version"],currentObject.createVarint(transaction["inputs"].length)]);return currentObject.startUntrustedHashTransactionInputRaw_async(newTransaction,true,data).then(function(result){var i=0;return utils.eachSeries(transaction["inputs"],function(input){var inputKey;var prefix;if(inputs[i]["trustedInput"]){prefix=Buffer.alloc(2);prefix[0]=1;prefix[1]=inputs[i]["value"].length}else{prefix=Buffer.alloc(1);prefix[0]=0}data=Buffer.concat([prefix,inputs[i]["value"],currentObject.createVarint(input["script"].length)]);return currentObject.startUntrustedHashTransactionInputRaw_async(newTransaction,false,data).then(function(result){var scriptBlocks=[];var offset=0;if(input["script"].length==0){scriptBlocks.push(input["sequence"])}else{while(offset!=input["script"].length){var blockSize=input["script"].length-offset>LedgerBtc.MAX_SCRIPT_BLOCK?LedgerBtc.MAX_SCRIPT_BLOCK:input["script"].length-offset;if(offset+blockSize!=input["script"].length){scriptBlocks.push(input["script"].slice(offset,offset+blockSize))}else{scriptBlocks.push(Buffer.concat([input["script"].slice(offset,offset+blockSize),input["sequence"]]))}offset+=blockSize}}return utils.eachSeries(scriptBlocks,function(scriptBlock){return currentObject.startUntrustedHashTransactionInputRaw_async(newTransaction,false,scriptBlock)}).then(function(){i++})})})})};LedgerBtc.prototype.provideOutputFullChangePath_async=function(path){var splitPath=utils.splitPath(path);var buffer=Buffer.alloc(5+1+splitPath.length*4);buffer[0]=224;buffer[1]=74;buffer[2]=255;buffer[3]=0;buffer[4]=1+splitPath.length*4;buffer[5]=splitPath.length;splitPath.forEach(function(element,index){buffer.writeUInt32BE(element,6+4*index)});var self=this;return this.comm.exchange(buffer.toString("hex"),[36864])};LedgerBtc.prototype.hashOutputFull_async=function(outputScript){var offset=0;var self=this;return utils.asyncWhile(function(){return offset=outputScript.length?outputScript.length-offset:LedgerBtc.MAX_SCRIPT_BLOCK;var p1=offset+blockSize==outputScript.length?128:0;var prefix=Buffer.alloc(5);prefix[0]=224;prefix[1]=74;prefix[2]=p1;prefix[3]=0;prefix[4]=blockSize;var data=Buffer.concat([prefix,outputScript.slice(offset,offset+blockSize)]);return self.comm.exchange(data.toString("hex"),[36864]).then(function(data){offset+=blockSize})})};LedgerBtc.prototype.signTransaction_async=function(path,lockTime,sigHashType){if(typeof lockTime=="undefined"){lockTime=LedgerBtc.DEFAULT_LOCKTIME}if(typeof sigHashType=="undefined"){sigHashType=LedgerBtc.SIGHASH_ALL}var splitPath=utils.splitPath(path);var buffer=Buffer.alloc(5+1+splitPath.length*4+1+4+1);var offset=0;buffer[offset++]=224;buffer[offset++]=72;buffer[offset++]=0;buffer[offset++]=0;buffer[offset++]=1+splitPath.length*4+1+4+1;buffer[offset++]=splitPath.length;splitPath.forEach(function(element){buffer.writeUInt32BE(element,offset);offset+=4});buffer[offset++]=0;buffer.writeUInt32LE(lockTime,offset);offset+=4;buffer[offset++]=sigHashType;var self=this;return self.comm.exchange(buffer.toString("hex"),[36864]).then(function(signature){var result=Buffer.from(signature,"hex");result[0]=48;return result.slice(0,result.length-2)})};LedgerBtc.prototype.signMessageNew_async=function(path,messageHex){var splitPath=utils.splitPath(path);var offset=0;var message=new Buffer(messageHex,"hex");var apdus=[];var response=[];var self=this;while(offset!=message.length){var maxChunkSize=offset==0?LedgerBtc.MAX_SCRIPT_BLOCK-1-splitPath.length*4-4:LedgerBtc.MAX_SCRIPT_BLOCK;var chunkSize=offset+maxChunkSize>message.length?message.length-offset:maxChunkSize;var buffer=new Buffer(offset==0?5+1+splitPath.length*4+2+chunkSize:5+chunkSize);buffer[0]=224;buffer[1]=78;buffer[2]=0;buffer[3]=offset==0?1:128;buffer[4]=offset==0?1+splitPath.length*4+2+chunkSize:chunkSize;if(offset==0){buffer[5]=splitPath.length;splitPath.forEach(function(element,index){buffer.writeUInt32BE(element,6+4*index)});buffer.writeUInt16BE(message.length,6+4*splitPath.length);message.copy(buffer,6+4*splitPath.length+2,offset,offset+chunkSize)}else{message.copy(buffer,5,offset,offset+chunkSize)}apdus.push(buffer.toString("hex"));offset+=chunkSize}return utils.foreach(apdus,function(apdu){return self.comm.exchange(apdu,[36864]).then(function(apduResponse){response=apduResponse})}).then(function(){buffer=Buffer.alloc(6);buffer[0]=224;buffer[1]=78;buffer[2]=128;buffer[3]=0;buffer[4]=1;buffer[5]=0;return self.comm.exchange(buffer.toString("hex"),[36864]).then(function(apduResponse){var response=Buffer.from(apduResponse,"hex");var result={};result["v"]=response[0]-48;var r=response.slice(4,4+response[3]);if(r[0]==0){r=r.slice(1)}result["r"]=r.toString("hex");var offset=4+response[3]+2;var s=response.slice(offset,offset+response[offset-1]);if(s[0]==0){s=s.slice(1)}result["s"]=s.toString("hex");return result})})};LedgerBtc.prototype.createPaymentTransactionNew_async=function(inputs,associatedKeysets,changePath,outputScript,lockTime,sigHashType){var nullScript=Buffer.alloc(0);var defaultVersion=Buffer.alloc(4);defaultVersion.writeUInt32LE(1,0);var trustedInputs=[];var regularOutputs=[];var signatures=[];var publicKeys=[];var firstRun=true;var resuming=false;var self=this;var targetTransaction={};outputScript=Buffer.from(outputScript,"hex");if(typeof lockTime=="undefined"){lockTime=LedgerBtc.DEFAULT_LOCKTIME}if(typeof sigHashType=="undefined"){sigHashType=LedgerBtc.SIGHASH_ALL}var deferred=Q.defer();utils.foreach(inputs,function(input,i){return utils.doIf(!resuming,function(){return self.getTrustedInput_async(input[1],input[0]).then(function(trustedInput){var inputItem={};inputItem["trustedInput"]=true;inputItem["value"]=Buffer.from(trustedInput,"hex");trustedInputs.push(inputItem)})}).then(function(){regularOutputs.push(input[0].outputs[input[1]])})}).then(function(){targetTransaction["version"]=defaultVersion;targetTransaction["inputs"]=[];for(var i=0;i=4&&typeof inputs[i][3]!="undefined"){sequence=inputs[i][3]}else{sequence=LedgerBtc.DEFAULT_SEQUENCE}tmp.writeUInt32LE(sequence,0);tmpInput["script"]=nullScript;tmpInput["sequence"]=tmp;targetTransaction["inputs"].push(tmpInput)}}).then(function(){return utils.doIf(!resuming,function(){return utils.foreach(inputs,function(input,i){return self.getWalletPublicKey_async(associatedKeysets[i]).then(function(p){return p})}).then(function(result){for(var index=0;index=3&&typeof inputs[i][2]!="undefined"){usedScript=Buffer.from(inputs[i][2],"hex")}else{usedScript=regularOutputs[i]["script"]}targetTransaction["inputs"][i]["script"]=usedScript;return self.startUntrustedHashTransactionInput_async(firstRun,targetTransaction,trustedInputs).then(function(){return utils.doIf(!resuming&&typeof changePath!="undefined",function(){return self.provideOutputFullChangePath_async(changePath)}).then(function(){return self.hashOutputFull_async(outputScript)}).then(function(resultHash){return self.signTransaction_async(associatedKeysets[i],lockTime,sigHashType).then(function(signature){signatures.push(signature);targetTransaction["inputs"][i]["script"]=nullScript;if(firstRun){firstRun=false}})})})})}).then(function(){for(var i=0;i=4&&typeof inputs[i][3]!="undefined"){sequence=inputs[i][3]}else{sequence=LedgerBtc.DEFAULT_SEQUENCE}tmp.writeUInt32LE(sequence,0);tmpInput["script"]=nullScript;tmpInput["sequence"]=tmp;targetTransaction["inputs"].push(tmpInput)}}).then(function(){return utils.foreach(inputs,function(input,i){var usedScript;if(inputs[i].length>=3&&typeof inputs[i][2]!="undefined"){usedScript=Buffer.from(inputs[i][2],"hex")}else{usedScript=regularOutputs[i]["script"]}targetTransaction["inputs"][i]["script"]=usedScript;return self.startUntrustedHashTransactionInput_async(firstRun,targetTransaction,trustedInputs).then(function(){return self.hashOutputFull_async(outputScript)}).then(function(resultHash){return self.signTransaction_async(associatedKeysets[i],lockTime,sigHashType).then(function(signature){signatures.push(signature.slice(0,signature.length-1).toString("hex"));targetTransaction["inputs"][i]["script"]=nullScript;if(firstRun){firstRun=false}})})})}).then(function(){return signatures}).fail(function(failure){throw failure}).then(function(result){deferred.resolve(result)}).fail(function(error){deferred.reject(error)});return deferred.promise};LedgerBtc.prototype.compressPublicKey=function(publicKey){var prefix=(publicKey[64]&1)!=0?3:2;var prefixBuffer=Buffer.alloc(1);prefixBuffer[0]=prefix;return Buffer.concat([prefixBuffer,publicKey.slice(1,1+32)])},LedgerBtc.prototype.createVarint=function(value){if(value<253){var buffer=Buffer.alloc(1);buffer[0]=value;return buffer}if(value<=65535){var buffer=Buffer.alloc(3);buffer[0]=253;buffer[1]=value&255;buffer[2]=value>>8&255;return buffer}var buffer=Buffer.alloc(4);buffer[0]=254;buffer[1]=value&255;buffer[2]=value>>8&255;buffer[3]=value>>16&255;buffer[4]=value>>24&255;return buffer};LedgerBtc.prototype.splitTransaction=function(transaction){var result={};var inputs=[];var outputs=[];var offset=0;var transaction=Buffer.from(transaction,"hex");var version=transaction.slice(offset,offset+4);offset+=4;var varint=this.getVarint(transaction,offset);var numberInputs=varint[0];offset+=varint[1];for(var i=0;irawTx.length?rawTx.length-offset:maxChunkSize;var buffer=new Buffer(offset==0?5+1+splitPath.length*4+chunkSize:5+chunkSize);buffer[0]=224;buffer[1]=4;buffer[2]=offset==0?0:128;buffer[3]=0;buffer[4]=offset==0?1+splitPath.length*4+chunkSize:chunkSize;if(offset==0){buffer[5]=splitPath.length;splitPath.forEach(function(element,index){buffer.writeUInt32BE(element,6+4*index)});rawTx.copy(buffer,6+4*splitPath.length,offset,offset+chunkSize)}else{rawTx.copy(buffer,5,offset,offset+chunkSize)}apdus.push(buffer.toString("hex"));offset+=chunkSize}return utils.foreach(apdus,function(apdu){return self.comm.exchange(apdu,[36864]).then(function(apduResponse){response=apduResponse})}).then(function(){response=new Buffer(response,"hex");var result={};result["v"]=response.slice(0,1).toString("hex");result["r"]=response.slice(1,1+32).toString("hex");result["s"]=response.slice(1+32,1+32+32).toString("hex");return result})};LedgerEth.prototype.getAppConfiguration_async=function(){var buffer=new Buffer(5);buffer[0]=224;buffer[1]=6;buffer[2]=0;buffer[3]=0;buffer[4]=0;return this.comm.exchange(buffer.toString("hex"),[36864]).then(function(response){var result={};var response=new Buffer(response,"hex");result["arbitraryDataEnabled"]=response[0]&1;result["version"]=""+response[1]+"."+response[2]+"."+response[3];return result})};LedgerEth.prototype.signPersonalMessage_async=function(path,messageHex){var splitPath=utils.splitPath(path);var offset=0;var message=new Buffer(messageHex,"hex");var apdus=[];var response=[];var self=this;while(offset!=message.length){var maxChunkSize=offset==0?150-1-splitPath.length*4-4:150;var chunkSize=offset+maxChunkSize>message.length?message.length-offset:maxChunkSize;var buffer=new Buffer(offset==0?5+1+splitPath.length*4+4+chunkSize:5+chunkSize);buffer[0]=224;buffer[1]=8;buffer[2]=offset==0?0:128;buffer[3]=0;buffer[4]=offset==0?1+splitPath.length*4+4+chunkSize:chunkSize;if(offset==0){buffer[5]=splitPath.length;splitPath.forEach(function(element,index){buffer.writeUInt32BE(element,6+4*index)});buffer.writeUInt32BE(message.length,6+4*splitPath.length);message.copy(buffer,6+4*splitPath.length+4,offset,offset+chunkSize)}else{message.copy(buffer,5,offset,offset+chunkSize)}apdus.push(buffer.toString("hex"));offset+=chunkSize}return utils.foreach(apdus,function(apdu){return self.comm.exchange(apdu,[36864]).then(function(apduResponse){response=apduResponse})}).then(function(){response=new Buffer(response,"hex");var result={};result["v"]=response[0];result["r"]=response.slice(1,1+32).toString("hex");result["s"]=response.slice(1+32,1+32+32).toString("hex");return result})};module.exports=LedgerEth}).call(this,require("buffer").Buffer)},{"./utils":12,buffer:2,q:6}],12:[function(require,module,exports){"use strict";var Q=require("q");var LedgerUtils={};LedgerUtils.eachSeries=function(arr,fun){return arr.reduce(function(p,e){return p.then(function(){return fun(e)})},Q.resolve())};LedgerUtils.splitPath=function(path){var result=[];var components=path.split("/");components.forEach(function(element,index){var number=parseInt(element,10);if(isNaN(number)){return}if(element.length>1&&element[element.length-1]=="'"){number+=2147483648}result.push(number)});return result};LedgerUtils.foreach=function(arr,callback){var deferred=Q.defer();var iterate=function(index,array,result){if(index>=array.length){deferred.resolve(result);return}callback(array[index],index).then(function(res){result.push(res);iterate(index+1,array,result)}).fail(function(ex){deferred.reject(ex)}).done()};iterate(0,arr,[]);return deferred.promise};LedgerUtils.doIf=function(condition,callback){var deferred=Q.defer();if(condition){deferred.resolve(callback())}else{deferred.resolve()}return deferred.promise};LedgerUtils.asyncWhile=function(condition,callback){var deferred=Q.defer();var iterate=function(result){if(!condition()){deferred.resolve(result);return}callback().then(function(res){result.push(res);iterate(result)}).fail(function(ex){deferred.reject(ex)}).done()};iterate([]);return deferred.promise};module.exports=LedgerUtils},{q:6}]},{},[8])(8)});