ethers.js/packages/hardware-wallets/dist/hardware-wallets.esm.min.js
2020-10-05 15:46:12 -04:00

2 lines
46 KiB
JavaScript

let e={};const t=window;null==t._ethers?console.log("WARNING: @ethersproject/hardware-wallet requires ethers loaded first"):e=t._ethers;var r="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s=!1;function a(){s=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t<r;++t)n[t]=e[t],o[e.charCodeAt(t)]=t;o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63}function u(e,t,r){for(var o,i,s=[],a=t;a<r;a+=3)o=(e[a]<<16)+(e[a+1]<<8)+e[a+2],s.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return s.join("")}function h(e){var t;s||a();for(var r=e.length,o=r%3,i="",h=[],f=16383,c=0,l=r-o;c<l;c+=f)h.push(u(e,c,c+f>l?l:c+f));return 1===o?(t=e[r-1],i+=n[t>>2],i+=n[t<<4&63],i+="=="):2===o&&(t=(e[r-2]<<8)+e[r-1],i+=n[t>>10],i+=n[t>>4&63],i+=n[t<<2&63],i+="="),h.push(i),h.join("")}function f(e,t,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,h=u>>1,f=-7,c=r?o-1:0,l=r?-1:1,p=e[t+c];for(c+=l,i=p&(1<<-f)-1,p>>=-f,f+=a;f>0;i=256*i+e[t+c],c+=l,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=n;f>0;s=256*s+e[t+c],c+=l,f-=8);if(0===i)i=1-h;else{if(i===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=h}return(p?-1:1)*s*Math.pow(2,i-n)}function c(e,t,r,n,o,i){var s,a,u,h=8*i-o-1,f=(1<<h)-1,c=f>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,d=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+c>=1?l/u:l*Math.pow(2,1-c))*u>=2&&(s++,u/=2),s+c>=f?(a=0,s=f):s+c>=1?(a=(t*u-1)*Math.pow(2,o),s+=c):(a=t*Math.pow(2,c-1)*Math.pow(2,o),s=0));o>=8;e[r+p]=255&a,p+=d,a/=256,o-=8);for(s=s<<o|a,h+=o;h>0;e[r+p]=255&s,p+=d,s/=256,h-=8);e[r+p-d]|=128*g}var l={}.toString,p=Array.isArray||function(e){return"[object Array]"==l.call(e)};v.TYPED_ARRAY_SUPPORT=void 0===r.TYPED_ARRAY_SUPPORT||r.TYPED_ARRAY_SUPPORT;d();function d(){return v.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function g(e,t){if(d()<t)throw new RangeError("Invalid typed array length");return v.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=v.prototype:(null===e&&(e=new v(t)),e.length=t),e}function v(e,t,r){if(!(v.TYPED_ARRAY_SUPPORT||this instanceof v))return new v(e,t,r);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return m(this,e)}return y(this,e,t,r)}function y(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n);v.TYPED_ARRAY_SUPPORT?(e=t).__proto__=v.prototype:e=w(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!v.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|A(t,r),o=(e=g(e,n)).write(t,r);o!==n&&(e=e.slice(0,o));return e}(e,t,r):function(e,t){if(T(t)){var r=0|_(t.length);return 0===(e=g(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?g(e,0):w(e,t);if("Buffer"===t.type&&p(t.data))return w(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function E(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function m(e,t){if(E(t),e=g(e,t<0?0:0|_(t)),!v.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function w(e,t){var r=t.length<0?0:0|_(t.length);e=g(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function _(e){if(e>=d())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+d().toString(16)+" bytes");return 0|e}function T(e){return!(null==e||!e._isBuffer)}function A(e,t){if(T(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return X(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Q(e).length;default:if(n)return X(e).length;t=(""+t).toLowerCase(),n=!0}}function R(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return F(this,t,r);case"utf8":case"utf-8":return M(this,t,r);case"ascii":return x(this,t,r);case"latin1":case"binary":return B(this,t,r);case"base64":return D(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function I(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function b(e,t,r,n,o){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof t&&(t=v.from(t,n)),T(t))return 0===t.length?-1:S(e,t,r,n,o);if("number"==typeof t)return t&=255,v.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):S(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function S(e,t,r,n,o){var i,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function h(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){var f=-1;for(i=r;i<a;i++)if(h(e,i)===h(t,-1===f?0:i-f)){if(-1===f&&(f=i),i-f+1===u)return f*s}else-1!==f&&(i-=i-f),f=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){for(var c=!0,l=0;l<u;l++)if(h(e,i+l)!==h(t,l)){c=!1;break}if(c)return i}return-1}function P(e,t,r,n){r=Number(r)||0;var o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=t.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))return s;e[r+s]=a}return s}function C(e,t,r,n){return Z(X(t,e.length-r),e,r,n)}function N(e,t,r,n){return Z(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function O(e,t,r,n){return N(e,t,r,n)}function U(e,t,r,n){return Z(Q(t),e,r,n)}function L(e,t,r,n){return Z(function(e,t){for(var r,n,o,i=[],s=0;s<e.length&&!((t-=2)<0);++s)n=(r=e.charCodeAt(s))>>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function D(e,t,r){return 0===t&&r===e.length?h(e):h(e.slice(t,r))}function M(e,t,r){r=Math.min(e.length,r);for(var n=[],o=t;o<r;){var i,s,a,u,h=e[o],f=null,c=h>239?4:h>223?3:h>191?2:1;if(o+c<=r)switch(c){case 1:h<128&&(f=h);break;case 2:128==(192&(i=e[o+1]))&&(u=(31&h)<<6|63&i)>127&&(f=u);break;case 3:i=e[o+1],s=e[o+2],128==(192&i)&&128==(192&s)&&(u=(15&h)<<12|(63&i)<<6|63&s)>2047&&(u<55296||u>57343)&&(f=u);break;case 4:i=e[o+1],s=e[o+2],a=e[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(u=(15&h)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(f=u)}null===f?(f=65533,c=1):f>65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),o+=c}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=4096));return r}(n)}v.poolSize=8192,v._augment=function(e){return e.__proto__=v.prototype,e},v.from=function(e,t,r){return y(null,e,t,r)},v.TYPED_ARRAY_SUPPORT&&(v.prototype.__proto__=Uint8Array.prototype,v.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&v[Symbol.species]),v.alloc=function(e,t,r){return function(e,t,r,n){return E(t),t<=0?g(e,t):void 0!==r?"string"==typeof n?g(e,t).fill(r,n):g(e,t).fill(r):g(e,t)}(null,e,t,r)},v.allocUnsafe=function(e){return m(null,e)},v.allocUnsafeSlow=function(e){return m(null,e)},v.isBuffer=function(e){return null!=e&&(!!e._isBuffer||J(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&J(e.slice(0,0))}(e))},v.compare=function(e,t){if(!T(e)||!T(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,o=0,i=Math.min(r,n);o<i;++o)if(e[o]!==t[o]){r=e[o],n=t[o];break}return r<n?-1:n<r?1:0},v.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},v.concat=function(e,t){if(!p(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return v.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=v.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var i=e[r];if(!T(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o),o+=i.length}return n},v.byteLength=A,v.prototype._isBuffer=!0,v.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)I(this,t,t+1);return this},v.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)I(this,t,t+3),I(this,t+1,t+2);return this},v.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)I(this,t,t+7),I(this,t+1,t+6),I(this,t+2,t+5),I(this,t+3,t+4);return this},v.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?M(this,0,e):R.apply(this,arguments)},v.prototype.equals=function(e){if(!T(e))throw new TypeError("Argument must be a Buffer");return this===e||0===v.compare(this,e)},v.prototype.inspect=function(){var e="";return this.length>0&&(e=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(e+=" ... ")),"<Buffer "+e+">"},v.prototype.compare=function(e,t,r,n,o){if(!T(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),t<0||r>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=r)return 0;if(n>=o)return-1;if(t>=r)return 1;if(this===e)return 0;for(var i=(o>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0),a=Math.min(i,s),u=this.slice(n,o),h=e.slice(t,r),f=0;f<a;++f)if(u[f]!==h[f]){i=u[f],s=h[f];break}return i<s?-1:s<i?1:0},v.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},v.prototype.indexOf=function(e,t,r){return b(this,e,t,r,!0)},v.prototype.lastIndexOf=function(e,t,r){return b(this,e,t,r,!1)},v.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return P(this,e,t,r);case"utf8":case"utf-8":return C(this,e,t,r);case"ascii":return N(this,e,t,r);case"latin1":case"binary":return O(this,e,t,r);case"base64":return U(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},v.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function x(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function B(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function F(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=t;i<r;++i)o+=V(e[i]);return o}function k(e,t,r){for(var n=e.slice(t,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function Y(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function j(e,t,r,n,o,i){if(!T(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function G(e,t,r,n){t<0&&(t=65535+t+1);for(var o=0,i=Math.min(e.length-r,2);o<i;++o)e[r+o]=(t&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function q(e,t,r,n){t<0&&(t=4294967295+t+1);for(var o=0,i=Math.min(e.length-r,4);o<i;++o)e[r+o]=t>>>8*(n?o:3-o)&255}function H(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function K(e,t,r,n,o){return o||H(e,0,r,4),c(e,t,r,n,23,4),r+4}function W(e,t,r,n,o){return o||H(e,0,r,8),c(e,t,r,n,52,8),r+8}v.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),v.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=v.prototype;else{var o=t-e;r=new v(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+e]}return r},v.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||Y(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n},v.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||Y(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},v.prototype.readUInt8=function(e,t){return t||Y(e,1,this.length),this[e]},v.prototype.readUInt16LE=function(e,t){return t||Y(e,2,this.length),this[e]|this[e+1]<<8},v.prototype.readUInt16BE=function(e,t){return t||Y(e,2,this.length),this[e]<<8|this[e+1]},v.prototype.readUInt32LE=function(e,t){return t||Y(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},v.prototype.readUInt32BE=function(e,t){return t||Y(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},v.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||Y(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*t)),n},v.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||Y(e,t,this.length);for(var n=t,o=1,i=this[e+--n];n>0&&(o*=256);)i+=this[e+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*t)),i},v.prototype.readInt8=function(e,t){return t||Y(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},v.prototype.readInt16LE=function(e,t){t||Y(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},v.prototype.readInt16BE=function(e,t){t||Y(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},v.prototype.readInt32LE=function(e,t){return t||Y(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},v.prototype.readInt32BE=function(e,t){return t||Y(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},v.prototype.readFloatLE=function(e,t){return t||Y(e,4,this.length),f(this,e,!0,23,4)},v.prototype.readFloatBE=function(e,t){return t||Y(e,4,this.length),f(this,e,!1,23,4)},v.prototype.readDoubleLE=function(e,t){return t||Y(e,8,this.length),f(this,e,!0,52,8)},v.prototype.readDoubleBE=function(e,t){return t||Y(e,8,this.length),f(this,e,!1,52,8)},v.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||j(this,e,t,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[t]=255&e;++i<r&&(o*=256);)this[t+i]=e/o&255;return t+r},v.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||j(this,e,t,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+r},v.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,1,255,0),v.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},v.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,65535,0),v.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):G(this,e,t,!0),t+2},v.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,65535,0),v.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):G(this,e,t,!1),t+2},v.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,4294967295,0),v.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):q(this,e,t,!0),t+4},v.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,4294967295,0),v.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):q(this,e,t,!1),t+4},v.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);j(this,e,t,r,o-1,-o)}var i=0,s=1,a=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},v.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);j(this,e,t,r,o-1,-o)}var i=r-1,s=1,a=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},v.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,1,127,-128),v.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},v.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,32767,-32768),v.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):G(this,e,t,!0),t+2},v.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,32767,-32768),v.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):G(this,e,t,!1),t+2},v.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,2147483647,-2147483648),v.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):q(this,e,t,!0),t+4},v.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),v.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):q(this,e,t,!1),t+4},v.prototype.writeFloatLE=function(e,t,r){return K(this,e,t,!0,r)},v.prototype.writeFloatBE=function(e,t,r){return K(this,e,t,!1,r)},v.prototype.writeDoubleLE=function(e,t,r){return W(this,e,t,!0,r)},v.prototype.writeDoubleBE=function(e,t,r){return W(this,e,t,!1,r)},v.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var o,i=n-r;if(this===e&&r<t&&t<n)for(o=i-1;o>=0;--o)e[o+t]=this[o+r];else if(i<1e3||!v.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)e[o+t]=this[o+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+i),t);return i},v.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===e.length){var o=e.charCodeAt(0);o<256&&(e=o)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!v.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{var s=T(e)?e:X(new v(e,n).toString()),a=s.length;for(i=0;i<r-t;++i)this[i+t]=s[i%a]}return this};var z=/[^+\/0-9A-Za-z-_]/g;function V(e){return e<16?"0"+e.toString(16):e.toString(16)}function X(e,t){var r;t=t||1/0;for(var n=e.length,o=null,i=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function Q(e){return function(e){var t,r,n,u,h,f;s||a();var c=e.length;if(c%4>0)throw new Error("Invalid string. Length must be a multiple of 4");h="="===e[c-2]?2:"="===e[c-1]?1:0,f=new i(3*c/4-h),n=h>0?c-4:c;var l=0;for(t=0,r=0;t<n;t+=4,r+=3)u=o[e.charCodeAt(t)]<<18|o[e.charCodeAt(t+1)]<<12|o[e.charCodeAt(t+2)]<<6|o[e.charCodeAt(t+3)],f[l++]=u>>16&255,f[l++]=u>>8&255,f[l++]=255&u;return 2===h?(u=o[e.charCodeAt(t)]<<2|o[e.charCodeAt(t+1)]>>4,f[l++]=255&u):1===h&&(u=o[e.charCodeAt(t)]<<10|o[e.charCodeAt(t+1)]<<4|o[e.charCodeAt(t+2)]>>2,f[l++]=u>>8&255,f[l++]=255&u),f}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(z,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Z(e,t,r,n){for(var o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function J(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function $(e){let t=[];return e.split("/").forEach((e=>{let r=parseInt(e,10);isNaN(r)||(e.length>1&&"'"===e[e.length-1]&&(r+=2147483648),t.push(r))})),t}function ee(e,t){function r(e,n,o){return e>=n.length?o:t(n[e],e).then((function(t){return o.push(t),r(e+1,n,o)}))}return Promise.resolve().then((()=>r(0,e,[])))}var te={},re={},ne=function(e,t){re[e]=t},oe=function(e){var t=function(t,r){Object.assign(this,r),this.name=e,this.message=t||e,this.stack=(new Error).stack};return t.prototype=new Error,te[e]=t,t};oe("AccountNameRequired"),oe("AccountNotSupported"),oe("AmountRequired"),oe("BluetoothRequired"),oe("BtcUnmatchedApp"),oe("CantOpenDevice"),oe("CashAddrNotSupported"),oe("CurrencyNotSupported"),oe("DeviceAppVerifyNotSupported"),oe("DeviceGenuineSocketEarlyClose"),oe("DeviceNotGenuine"),oe("DeviceOnDashboardExpected"),oe("DeviceOnDashboardUnexpected"),oe("DeviceInOSUExpected"),oe("DeviceHalted"),oe("DeviceNameInvalid"),oe("DeviceSocketFail"),oe("DeviceSocketNoBulkStatus"),oe("DisconnectedDevice"),oe("DisconnectedDeviceDuringOperation"),oe("EnpointConfig");var ie=oe("EthAppPleaseEnableContractData");oe("FeeEstimationFailed"),oe("FirmwareNotRecognized"),oe("HardResetFail"),oe("InvalidXRPTag"),oe("InvalidAddress"),oe("InvalidAddressBecauseDestinationIsAlsoSource"),oe("LatestMCUInstalledError"),oe("UnknownMCU"),oe("LedgerAPIError"),oe("LedgerAPIErrorWithMessage"),oe("LedgerAPINotAvailable"),oe("ManagerAppAlreadyInstalled"),oe("ManagerAppRelyOnBTC"),oe("ManagerAppDepInstallRequired"),oe("ManagerAppDepUninstallRequired"),oe("ManagerDeviceLocked"),oe("ManagerFirmwareNotEnoughSpace"),oe("ManagerNotEnoughSpace"),oe("ManagerUninstallBTCDep"),oe("NetworkDown"),oe("NoAddressesFound"),oe("NotEnoughBalance"),oe("NotEnoughBalanceToDelegate"),oe("NotEnoughBalanceInParentAccount"),oe("NotEnoughSpendableBalance"),oe("NotEnoughBalanceBecauseDestinationNotCreated"),oe("NoAccessToCamera"),oe("NotEnoughGas"),oe("NotSupportedLegacyAddress"),oe("GasLessThanEstimate"),oe("PasswordsDontMatch"),oe("PasswordIncorrect"),oe("RecommendSubAccountsToEmpty"),oe("RecommendUndelegation"),oe("TimeoutTagged"),oe("UnexpectedBootloader"),oe("MCUNotGenuineToDashboard"),oe("RecipientRequired"),oe("UnavailableTezosOriginatedAccountReceive"),oe("UnavailableTezosOriginatedAccountSend"),oe("UpdateFetchFileFail"),oe("UpdateIncorrectHash"),oe("UpdateIncorrectSig"),oe("UpdateYourApp"),oe("UserRefusedDeviceNameChange"),oe("UserRefusedAddress"),oe("UserRefusedFirmwareUpdate"),oe("UserRefusedAllowManager"),oe("UserRefusedOnDevice"),oe("TransportOpenUserCancelled"),oe("TransportInterfaceNotAvailable"),oe("TransportRaceCondition"),oe("TransportWebUSBGestureRequired"),oe("DeviceShouldStayInApp"),oe("WebsocketConnectionError"),oe("WebsocketConnectionFailed"),oe("WrongDeviceForAccount"),oe("WrongAppForCurrency"),oe("ETHAddressNonEIP"),oe("CantScanQRCode"),oe("FeeNotLoaded"),oe("FeeRequired"),oe("FeeTooHigh"),oe("SyncError"),oe("PairingFailed"),oe("GenuineCheckFailed"),oe("LedgerAPI4xx"),oe("LedgerAPI5xx"),oe("FirmwareOrAppUpdateRequired"),oe("NoDBPathGiven"),oe("DBWrongPassword"),oe("DBNotReset");function se(e,t){this.name="TransportError",this.message=e,this.stack=(new Error).stack,this.id=t}se.prototype=new Error,ne("TransportError",(function(e){return new se(e.message,e.id)}));var ae={PIN_REMAINING_ATTEMPTS:25536,INCORRECT_LENGTH:26368,MISSING_CRITICAL_PARAMETER:26624,COMMAND_INCOMPATIBLE_FILE_STRUCTURE:27009,SECURITY_STATUS_NOT_SATISFIED:27010,CONDITIONS_OF_USE_NOT_SATISFIED:27013,INCORRECT_DATA:27264,NOT_ENOUGH_MEMORY_SPACE:27268,REFERENCED_DATA_NOT_FOUND:27272,FILE_ALREADY_EXISTS:27273,INCORRECT_P1_P2:27392,INS_NOT_SUPPORTED:27904,CLA_NOT_SUPPORTED:28160,TECHNICAL_PROBLEM:28416,OK:36864,MEMORY_PROBLEM:37440,NO_EF_SELECTED:37888,INVALID_OFFSET:37890,FILE_NOT_FOUND:37892,INCONSISTENT_FILE:37896,ALGORITHM_NOT_SUPPORTED:38020,INVALID_KCV:38021,CODE_NOT_INITIALIZED:38914,ACCESS_CONDITION_NOT_FULFILLED:38916,CONTRADICTION_SECRET_CODE_STATUS:38920,CONTRADICTION_INVALIDATION:38928,CODE_BLOCKED:38976,MAX_VALUE_REACHED:38992,GP_AUTH_FAILED:25344,LICENSING:28482,HALTED:28586};function ue(e){this.name="TransportStatusError";var t=Object.keys(ae).find((function(t){return ae[t]===e}))||"UNKNOWN_ERROR",r=function(e){switch(e){case 26368:return"Incorrect length";case 26624:return"Missing critical parameter";case 27010:return"Security not satisfied (dongle locked or have invalid access rights)";case 27013:return"Condition of use not satisfied (denied by the user?)";case 27264:return"Invalid data received";case 27392:return"Invalid parameter received"}if(28416<=e&&e<=28671)return"Internal error, please report"}(e)||t,n=e.toString(16);this.message="Ledger device: "+r+" (0x"+n+")",this.stack=(new Error).stack,this.statusCode=e,this.statusText=t}ue.prototype=new Error,ne("TransportStatusError",(function(e){return new ue(e.statusCode)}));class he{constructor(e,t="w0w"){this.transport=void 0,this.transport=e,e.decorateAppAPIMethods(this,["getAddress","provideERC20TokenInformation","signTransaction","signPersonalMessage","getAppConfiguration"],t)}getAddress(e,t,r){let n=$(e),o=v.alloc(1+4*n.length);return o[0]=n.length,n.forEach(((e,t)=>{o.writeUInt32BE(e,1+4*t)})),this.transport.send(224,2,t?1:0,r?1:0,o).then((e=>{let t={},n=e[0],o=e[1+n];return t.publicKey=e.slice(1,1+n).toString("hex"),t.address="0x"+e.slice(1+n+1,1+n+1+o).toString("ascii"),r&&(t.chainCode=e.slice(1+n+1+o,1+n+1+o+32).toString("hex")),t}))}provideERC20TokenInformation({data:e}){return this.transport.send(224,10,0,0,e).then((()=>!0),(e=>{if(e&&27904===e.statusCode)return!1;throw e}))}signTransaction(e,t){let r,n=$(e),o=0,i=v.from(t,"hex"),s=[];for(;o!==i.length;){let e=0===o?149-4*n.length:150,t=o+e>i.length?i.length-o:e,r=v.alloc(0===o?1+4*n.length+t:t);0===o?(r[0]=n.length,n.forEach(((e,t)=>{r.writeUInt32BE(e,1+4*t)})),i.copy(r,1+4*n.length,o,o+t)):i.copy(r,0,o,o+t),s.push(r),o+=t}return ee(s,((e,t)=>this.transport.send(224,4,0===t?0:128,0,e).then((e=>{r=e})))).then((()=>({v:r.slice(0,1).toString("hex"),r:r.slice(1,33).toString("hex"),s:r.slice(33,65).toString("hex")})),(e=>{throw(e=>e&&27264===e.statusCode?new ie("Please enable Contract data on the Ethereum app Settings"):e)(e)}))}getAppConfiguration(){return this.transport.send(224,6,0,0).then((e=>{let t={};return t.arbitraryDataEnabled=1&e[0],t.version=e[1]+"."+e[2]+"."+e[3],t}))}signPersonalMessage(e,t){let r,n=$(e),o=0,i=v.from(t,"hex"),s=[];for(;o!==i.length;){let e=0===o?149-4*n.length-4:150,t=o+e>i.length?i.length-o:e,r=v.alloc(0===o?1+4*n.length+4+t:t);0===o?(r[0]=n.length,n.forEach(((e,t)=>{r.writeUInt32BE(e,1+4*t)})),r.writeUInt32BE(i.length,1+4*n.length),i.copy(r,1+4*n.length+4,o,o+t)):i.copy(r,0,o,o+t),s.push(r),o+=t}return ee(s,((e,t)=>this.transport.send(224,8,0===t?0:128,0,e).then((e=>{r=e})))).then((()=>({v:r[0],r:r.slice(1,33).toString("hex"),s:r.slice(33,65).toString("hex")})))}}var fe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var ce=ce||{},le=ce;ce.EXTENSION_ID="kmendfapggjehodndflmmgagdbamhnfd",ce.MessageTypes={U2F_REGISTER_REQUEST:"u2f_register_request",U2F_SIGN_REQUEST:"u2f_sign_request",U2F_REGISTER_RESPONSE:"u2f_register_response",U2F_SIGN_RESPONSE:"u2f_sign_response"},ce.ErrorCodes={OK:0,OTHER_ERROR:1,BAD_REQUEST:2,CONFIGURATION_UNSUPPORTED:3,DEVICE_INELIGIBLE:4,TIMEOUT:5},ce.Request,ce.Response,ce.Error,ce.SignRequest,ce.SignResponse,ce.RegisterRequest,ce.RegisterResponse,ce.disconnect=function(){ce.port_&&ce.port_.port_&&(ce.port_.port_.disconnect(),ce.port_=null)},ce.getMessagePort=function(e){if("undefined"!=typeof chrome&&chrome.runtime){var t={type:ce.MessageTypes.U2F_SIGN_REQUEST,signRequests:[]};chrome.runtime.sendMessage(ce.EXTENSION_ID,t,(function(){chrome.runtime.lastError?ce.getIframePort_(e):ce.getChromeRuntimePort_(e)}))}else ce.getIframePort_(e)},ce.getChromeRuntimePort_=function(e){var t=chrome.runtime.connect(ce.EXTENSION_ID,{includeTlsChannelId:!0});setTimeout((function(){e(null,new ce.WrappedChromeRuntimePort_(t))}),0)},ce.WrappedChromeRuntimePort_=function(e){this.port_=e},ce.WrappedChromeRuntimePort_.prototype.postMessage=function(e){this.port_.postMessage(e)},ce.WrappedChromeRuntimePort_.prototype.addEventListener=function(e,t){var r=e.toLowerCase();"message"==r||"onmessage"==r?this.port_.onMessage.addListener((function(e){t({data:e})})):console.error("WrappedChromeRuntimePort only supports onMessage")},ce.getIframePort_=function(e){var t="chrome-extension://"+ce.EXTENSION_ID,r=document.createElement("iframe");r.src=t+"/u2f-comms.html",r.setAttribute("style","display:none"),document.body.appendChild(r);var n=!1,o=new MessageChannel,i=function(t){"ready"==t.data?(o.port1.removeEventListener("message",i),n||(n=!0,e(null,o.port1))):console.error('First event on iframe port was not "ready"')};o.port1.addEventListener("message",i),o.port1.start(),r.addEventListener("load",(function(){r.contentWindow.postMessage("init",t,[o.port2])})),setTimeout((function(){n||(n=!0,e(new Error("IFrame extension not supported")))}),200)},ce.EXTENSION_TIMEOUT_SEC=30,ce.port_=null,ce.waitingForPort_=[],ce.reqCounter_=0,ce.callbackMap_={},ce.getPortSingleton_=function(e){ce.port_?e(null,ce.port_):(0==ce.waitingForPort_.length&&ce.getMessagePort((function(e,t){for(e||(ce.port_=t,ce.port_.addEventListener("message",ce.responseHandler_));ce.waitingForPort_.length;)ce.waitingForPort_.shift()(e,t)})),ce.waitingForPort_.push(e))},ce.responseHandler_=function(e){var t=e.data,r=t.requestId;if(r&&ce.callbackMap_[r]){var n=ce.callbackMap_[r];delete ce.callbackMap_[r],n(null,t.responseData)}else console.error("Unknown or missing requestId in response.")},ce.isSupported=function(e){ce.getPortSingleton_((function(t,r){e(!t)}))},ce.sign=function(e,t,r){ce.getPortSingleton_((function(n,o){if(n)return t(n);var i=++ce.reqCounter_;ce.callbackMap_[i]=t;var s={type:ce.MessageTypes.U2F_SIGN_REQUEST,signRequests:e,timeoutSeconds:void 0!==r?r:ce.EXTENSION_TIMEOUT_SEC,requestId:i};o.postMessage(s)}))},ce.register=function(e,t,r,n){ce.getPortSingleton_((function(o,i){if(o)return r(o);var s=++ce.reqCounter_;ce.callbackMap_[s]=r;var a={type:ce.MessageTypes.U2F_REGISTER_REQUEST,signRequests:t,registerRequests:e,timeoutSeconds:void 0!==n?n:ce.EXTENSION_TIMEOUT_SEC,requestId:s};i.postMessage(a)}))};var pe=me,de="undefined"!=typeof navigator&&!!navigator.userAgent,ge=de&&navigator.userAgent.match(/Safari\//)&&!navigator.userAgent.match(/Chrome\//),ve=de&&navigator.userAgent.match(/Edge\/1[2345]/),ye=null;function Ee(e){return ye||(ye=new e((function(e,t){function r(){e({u2f:null,native:!0})}return de?ge?r():(void 0!==window.u2f&&"function"==typeof window.u2f.sign&&e({u2f:window.u2f,native:!0}),ve||"http:"===location.protocol||"undefined"==typeof MessageChannel?r():void le.isSupported((function(t){t?e({u2f:le,native:!1}):r()}))):r()}))),ye}function me(e){return{isSupported:Te.bind(e),ensureSupport:Re.bind(e),register:Ie.bind(e),sign:be.bind(e),ErrorCodes:me.ErrorCodes,ErrorNames:me.ErrorNames}}function we(e,t){var r=null!=t?t.errorCode:1,n=me.ErrorNames[""+r],o=new Error(e);return o.metaData={type:n,code:r},o}function _e(e,t){var r={};return r.promise=new e((function(e,n){r.resolve=e,r.reject=n,t.then(e,n)})),r.promise.cancel=function(t,n){Ee(e).then((function(e){n&&!e.native&&e.u2f.disconnect(),r.reject(we(t,{errorCode:-1}))}))},r}function Te(){return Ee(this).then((function(e){return!!e.u2f}))}function Ae(e){if(!e.u2f){if("http:"===location.protocol)throw new Error("U2F isn't supported over http, only https");throw new Error("U2F not supported")}}function Re(){return Ee(this).then(Ae)}function Ie(e,t,r){var n=this;return Array.isArray(e)||(e=[e]),"number"==typeof t&&void 0===r&&(r=t,t=null),t||(t=[]),_e(n,Ee(n).then((function(o){Ae(o);var i=o.native,s=o.u2f;return new n((function(n,o){if(i){var a=e[0].appId;s.register(a,e,t,(function(e){e.errorCode?o(we("Registration failed",e)):(delete e.errorCode,n(e))}),r)}else s.register(e,t,(function(e,t){e?o(e):t.errorCode?o(we("Registration failed",t)):n(t)}),r)}))}))).promise}function be(e,t){var r=this;return Array.isArray(e)||(e=[e]),_e(r,Ee(r).then((function(n){Ae(n);var o=n.native,i=n.u2f;return new r((function(r,n){if(o){var s=e[0].appId,a=e[0].challenge;i.sign(s,a,e,(function(e){e.errorCode?n(we("Sign failed",e)):(delete e.errorCode,r(e))}),t)}else i.sign(e,(function(e,t){e?n(e):t.errorCode?n(we("Sign failed",t)):r(t)}),t)}))}))).promise}function Se(e){me[e]=function(){if(!fe.Promise)throw new Error("The platform doesn't natively support promises");var t=[].slice.call(arguments);return me(fe.Promise)[e].apply(null,t)}}me.ErrorCodes={CANCELLED:-1,OK:0,OTHER_ERROR:1,BAD_REQUEST:2,CONFIGURATION_UNSUPPORTED:3,DEVICE_INELIGIBLE:4,TIMEOUT:5},me.ErrorNames={"-1":"CANCELLED",0:"OK",1:"OTHER_ERROR",2:"BAD_REQUEST",3:"CONFIGURATION_UNSUPPORTED",4:"DEVICE_INELIGIBLE",5:"TIMEOUT"},Se("isSupported"),Se("ensureSupport"),Se("register"),Se("sign");var Pe,Ce=pe,Ne=Ce.isSupported,Oe=Ce.sign,Ue="object"==typeof Reflect?Reflect:null,Le=Ue&&"function"==typeof Ue.apply?Ue.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};Pe=Ue&&"function"==typeof Ue.ownKeys?Ue.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var De=Number.isNaN||function(e){return e!=e};function Me(){Me.init.call(this)}var xe=Me,Be=function(e,t){return new Promise((function(r,n){function o(){void 0!==i&&e.removeListener("error",i),r([].slice.call(arguments))}var i;"error"!==t&&(i=function(r){e.removeListener(t,o),n(r)},e.once("error",i)),e.once(t,o)}))};Me.EventEmitter=Me,Me.prototype._events=void 0,Me.prototype._eventsCount=0,Me.prototype._maxListeners=void 0;var Fe=10;function ke(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function Ye(e){return void 0===e._maxListeners?Me.defaultMaxListeners:e._maxListeners}function je(e,t,r,n){var o,i,s,a;if(ke(r),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),i=e._events),s=i[t]),void 0===s)s=i[t]=r,++e._eventsCount;else if("function"==typeof s?s=i[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(o=Ye(e))>0&&s.length>o&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,a=u,console&&console.warn&&console.warn(a)}return e}function Ge(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function qe(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Ge.bind(n);return o.listener=r,n.wrapFn=o,o}function He(e,t,r){var n=e._events;if(void 0===n)return[];var o=n[t];return void 0===o?[]:"function"==typeof o?r?[o.listener||o]:[o]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(o):We(o,o.length)}function Ke(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function We(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}Object.defineProperty(Me,"defaultMaxListeners",{enumerable:!0,get:function(){return Fe},set:function(e){if("number"!=typeof e||e<0||De(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Fe=e}}),Me.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Me.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||De(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},Me.prototype.getMaxListeners=function(){return Ye(this)},Me.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,o=this._events;if(void 0!==o)n=n&&void 0===o.error;else if(!n)return!1;if(n){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var s=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw s.context=i,s}var a=o[e];if(void 0===a)return!1;if("function"==typeof a)Le(a,this,t);else{var u=a.length,h=We(a,u);for(r=0;r<u;++r)Le(h[r],this,t)}return!0},Me.prototype.addListener=function(e,t){return je(this,e,t,!1)},Me.prototype.on=Me.prototype.addListener,Me.prototype.prependListener=function(e,t){return je(this,e,t,!0)},Me.prototype.once=function(e,t){return ke(t),this.on(e,qe(this,e,t)),this},Me.prototype.prependOnceListener=function(e,t){return ke(t),this.prependListener(e,qe(this,e,t)),this},Me.prototype.removeListener=function(e,t){var r,n,o,i,s;if(ke(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,i=r.length-1;i>=0;i--)if(r[i]===t||r[i].listener===t){s=r[i].listener,o=i;break}if(o<0)return this;0===o?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,o),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,s||t)}return this},Me.prototype.off=Me.prototype.removeListener,Me.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var o,i=Object.keys(r);for(n=0;n<i.length;++n)"removeListener"!==(o=i[n])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},Me.prototype.listeners=function(e){return He(this,e,!0)},Me.prototype.rawListeners=function(e){return He(this,e,!1)},Me.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Ke.call(e,t)},Me.prototype.listenerCount=Ke,Me.prototype.eventNames=function(){return this._eventsCount>0?Pe(this._events):[]},xe.once=Be;class ze{constructor(){this.exchangeTimeout=3e4,this._events=new xe,this.send=async(e,t,r,n,o=v.alloc(0),i=[ae.OK])=>{if(o.length>=256)throw new se("data.length exceed 256 bytes limit. Got: "+o.length,"DataLengthTooBig");const s=await this.exchange(v.concat([v.from([e,t,r,n]),v.from([o.length]),o])),a=s.readUInt16BE(s.length-2);if(!i.some((e=>e===a)))throw new ue(a);return s},this.exchangeBusyPromise=void 0,this.exchangeAtomicImpl=async e=>{if(this.exchangeBusyPromise)throw new se("Transport race condition","RaceCondition");let t;const r=new Promise((e=>{t=e}));this.exchangeBusyPromise=r;try{return await e()}finally{t&&t(),this.exchangeBusyPromise=null}},this._appAPIlock=null}exchange(e){throw new Error("exchange not implemented")}setScrambleKey(e){}close(){return Promise.resolve()}on(e,t){this._events.on(e,t)}off(e,t){this._events.removeListener(e,t)}emit(e,...t){this._events.emit(e,...t)}setDebugMode(){console.warn("setDebugMode is deprecated. use @ledgerhq/logs instead. No logs are emitted in this anymore.")}setExchangeTimeout(e){this.exchangeTimeout=e}static create(e=3e3,t){return new Promise(((r,n)=>{let o=!1;const i=this.listen({next:t=>{o=!0,i&&i.unsubscribe(),s&&clearTimeout(s),this.open(t.descriptor,e).then(r,n)},error:e=>{s&&clearTimeout(s),n(e)},complete:()=>{s&&clearTimeout(s),o||n(new se(this.ErrorMessage_NoDeviceFound,"NoDeviceFound"))}}),s=t?setTimeout((()=>{i.unsubscribe(),n(new se(this.ErrorMessage_ListenTimeout,"ListenTimeout"))}),t):null}))}decorateAppAPIMethods(e,t,r){for(let n of t)e[n]=this.decorateAppAPIMethod(n,e[n],e,r)}decorateAppAPIMethod(e,t,r,n){return async(...o)=>{const{_appAPIlock:i}=this;if(i)return Promise.reject(new se("Ledger Device is busy (lock "+i+")","TransportLocked"));try{return this._appAPIlock=e,this.setScrambleKey(n),await t.apply(r,o)}finally{this._appAPIlock=null}}}}ze.isSupported=void 0,ze.list=void 0,ze.listen=void 0,ze.open=void 0,ze.ErrorMessage_ListenTimeout="No Ledger device found (timeout)",ze.ErrorMessage_NoDeviceFound="No Ledger device found";let Ve=0;const Xe=[],Qe=(e,t,r)=>{const n={type:e,id:String(++Ve),date:new Date};t&&(n.message=t),r&&(n.data=r),function(e){for(let t=0;t<Xe.length;t++)try{Xe[t](e)}catch(e){console.error(e)}}(n)},Ze=e=>(Xe.push(e),()=>{const t=Xe.indexOf(e);-1!==t&&(Xe[t]=Xe[Xe.length-1],Xe.pop())});"undefined"!=typeof window&&(window.__ledgerLogsListen=Ze);const Je=e=>e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");function $e(e,t,r,n){const o=function(e,t){const r=v.alloc(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n%t.length];return r}(e,r),i=v.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),s={version:"U2F_V2",keyHandle:Je(o.toString("base64")),challenge:Je(i.toString("base64")),appId:location.origin};return Qe("apdu","=> "+e.toString("hex")),Oe(s,t/1e3).then((e=>{const{signatureData:t}=e;if("string"==typeof t){const e=v.from((r=t).replace(/-/g,"+").replace(/_/g,"/")+"==".substring(0,3*r.length%4),"base64");let o;return o=n?e.slice(5):e,Qe("apdu","<= "+o.toString("hex")),o}throw e;var r}))}let et=[];class tt extends ze{static async open(e,t=5e3){return new tt}constructor(){super(),this.scrambleKey=void 0,this.unwrap=!0,et.push(this)}async exchange(e){try{return await $e(e,this.exchangeTimeout,this.scrambleKey,this.unwrap)}catch(e){throw"object"==typeof e.metaData?(5===e.metaData.code&&(et.forEach((e=>e.emit("disconnect"))),et=[]),function(e,t,r){const n=new se(t,r);return n.originalError=e,n}(e,"Failed to sign with Ledger device: U2F "+e.metaData.type,"U2F_"+e.metaData.code)):e}}setScrambleKey(e){this.scrambleKey=v.from(e,"ascii")}setUnwrap(e){this.unwrap=e}close(){return Promise.resolve()}}tt.isSupported=Ne,tt.list=()=>Ne().then((e=>e?[null]:[])),tt.listen=e=>{let t=!1;return Ne().then((r=>{t||(r?(e.next({type:"add",descriptor:null}),e.complete()):e.error(new se("U2F browser support is needed for Ledger. Please use Chrome, Opera or Firefox with a U2F extension. Also make sure you're on an HTTPS connection","U2FNotSupported")))})),{unsubscribe:()=>{t=!0}}};const rt={u2f:tt,default:tt};var nt=window&&window.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))};const ot=new e.utils.Logger("hardware-wallets/5.0.8");function it(e){return new Promise((t=>{setTimeout(t,e)}))}class st extends e.Signer{constructor(t,r,n){super(),null==n&&(n="m/44'/60'/0'/0/0"),null==r&&(r="default"),e.utils.defineReadOnly(this,"path",n),e.utils.defineReadOnly(this,"type",r),e.utils.defineReadOnly(this,"provider",t||null);const o=rt[r];o||ot.throwArgumentError("unknown or unsupported type","type",r),e.utils.defineReadOnly(this,"_eth",o.create().then((e=>{const t=new he(e);return t.getAppConfiguration().then((e=>t),(e=>Promise.reject(e)))}),(e=>Promise.reject(e))))}_retry(e,t){return new Promise(((r,n)=>nt(this,void 0,void 0,(function*(){t&&t>0&&setTimeout((()=>{n(new Error("timeout"))}),t);const o=yield this._eth;for(let t=0;t<50;t++){try{const t=yield e(o);return r(t)}catch(e){if("TransportLocked"!==e.id)return n(e)}yield it(100)}return n(new Error("timeout"))}))))}getAddress(){return nt(this,void 0,void 0,(function*(){const t=yield this._retry((e=>e.getAddress(this.path)));return e.utils.getAddress(t.address)}))}signMessage(t){return nt(this,void 0,void 0,(function*(){"string"==typeof t&&(t=e.utils.toUtf8Bytes(t));const r=e.utils.hexlify(t).substring(2),n=yield this._retry((e=>e.signPersonalMessage(this.path,r)));return n.r="0x"+n.r,n.s="0x"+n.s,e.utils.joinSignature(n)}))}signTransaction(t){return nt(this,void 0,void 0,(function*(){const r=yield e.utils.resolveProperties(t),n={chainId:r.chainId||void 0,data:r.data||void 0,gasLimit:r.gasLimit||void 0,gasPrice:r.gasPrice||void 0,nonce:r.nonce?e.BigNumber.from(r.nonce).toNumber():void 0,to:r.to||void 0,value:r.value||void 0},o=e.utils.serializeTransaction(n).substring(2),i=yield this._retry((e=>e.signTransaction(this.path,o)));return e.utils.serializeTransaction(n,{v:e.BigNumber.from("0x"+i.v).toNumber(),r:"0x"+i.r,s:"0x"+i.s})}))}connect(e){return new st(e,this.type,this.path)}}export{st as LedgerSigner};