2 lines
45 KiB
JavaScript
2 lines
45 KiB
JavaScript
var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function r(e,t){return e(t={exports:{}},t.exports),t.exports}var n=r((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var r={};t.ethers=r;var n=window;null==n._ethers?console.log("WARNING: @ethersproject/hardware-wallet requires ethers loaded first"):t.ethers=r=n._ethers})),o=(t(n),n.ethers);var i="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},s=[],a=[],u="undefined"!=typeof Uint8Array?Uint8Array:Array,h=!1;function f(){h=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t<r;++t)s[t]=e[t],a[e.charCodeAt(t)]=t;a["-".charCodeAt(0)]=62,a["_".charCodeAt(0)]=63}function c(e,t,r){for(var n,o,i=[],a=t;a<r;a+=3)n=(e[a]<<16)+(e[a+1]<<8)+e[a+2],i.push(s[(o=n)>>18&63]+s[o>>12&63]+s[o>>6&63]+s[63&o]);return i.join("")}function l(e){var t;h||f();for(var r=e.length,n=r%3,o="",i=[],a=0,u=r-n;a<u;a+=16383)i.push(c(e,a,a+16383>u?u:a+16383));return 1===n?(t=e[r-1],o+=s[t>>2],o+=s[t<<4&63],o+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],o+=s[t>>10],o+=s[t>>4&63],o+=s[t<<2&63],o+="="),i.push(o),i.join("")}function p(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 d(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 g={}.toString,v=Array.isArray||function(e){return"[object Array]"==g.call(e)};w.TYPED_ARRAY_SUPPORT=void 0===i.TYPED_ARRAY_SUPPORT||i.TYPED_ARRAY_SUPPORT;y();function y(){return w.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function E(e,t){if(y()<t)throw new RangeError("Invalid typed array length");return w.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=w.prototype:(null===e&&(e=new w(t)),e.length=t),e}function w(e,t,r){if(!(w.TYPED_ARRAY_SUPPORT||this instanceof w))return new w(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 T(this,e)}return m(this,e,t,r)}function m(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);w.TYPED_ARRAY_SUPPORT?(e=t).__proto__=w.prototype:e=A(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!w.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|b(t,r),o=(e=E(e,n)).write(t,r);o!==n&&(e=e.slice(0,o));return e}(e,t,r):function(e,t){if(I(t)){var r=0|R(t.length);return 0===(e=E(e,r)).length?e:(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?E(e,0):A(e,t);if("Buffer"===t.type&&v(t.data))return A(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){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 T(e,t){if(_(t),e=E(e,t<0?0:0|R(t)),!w.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function A(e,t){var r=t.length<0?0:0|R(t.length);e=E(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function R(e){if(e>=y())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+y().toString(16)+" bytes");return 0|e}function I(e){return!(null==e||!e._isBuffer)}function b(e,t){if(I(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 J(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return ee(e).length;default:if(n)return J(e).length;t=(""+t).toLowerCase(),n=!0}}function S(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 G(this,t,r);case"utf8":case"utf-8":return F(this,t,r);case"ascii":return Y(this,t,r);case"latin1":case"binary":return j(this,t,r);case"base64":return B(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return q(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function P(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function C(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=w.from(t,n)),I(t))return 0===t.length?-1:O(e,t,r,n,o);if("number"==typeof t)return t&=255,w.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):O(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function O(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 N(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 U(e,t,r,n){return te(J(t,e.length-r),e,r,n)}function L(e,t,r,n){return te(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function D(e,t,r,n){return L(e,t,r,n)}function M(e,t,r,n){return te(ee(t),e,r,n)}function x(e,t,r,n){return te(function(e,t){for(var r,n,o,i=[],s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function B(e,t,r){return 0===t&&r===e.length?l(e):l(e.slice(t,r))}function F(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<=k)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=k));return r}(n)}w.poolSize=8192,w._augment=function(e){return e.__proto__=w.prototype,e},w.from=function(e,t,r){return m(null,e,t,r)},w.TYPED_ARRAY_SUPPORT&&(w.prototype.__proto__=Uint8Array.prototype,w.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&w[Symbol.species]),w.alloc=function(e,t,r){return function(e,t,r,n){return _(t),t<=0?E(e,t):void 0!==r?"string"==typeof n?E(e,t).fill(r,n):E(e,t).fill(r):E(e,t)}(null,e,t,r)},w.allocUnsafe=function(e){return T(null,e)},w.allocUnsafeSlow=function(e){return T(null,e)},w.isBuffer=function(e){return null!=e&&(!!e._isBuffer||re(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&re(e.slice(0,0))}(e))},w.compare=function(e,t){if(!I(e)||!I(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},w.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}},w.concat=function(e,t){if(!v(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return w.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=w.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var i=e[r];if(!I(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o),o+=i.length}return n},w.byteLength=b,w.prototype._isBuffer=!0,w.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)P(this,t,t+1);return this},w.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)P(this,t,t+3),P(this,t+1,t+2);return this},w.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)P(this,t,t+7),P(this,t+1,t+6),P(this,t+2,t+5),P(this,t+3,t+4);return this},w.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?F(this,0,e):S.apply(this,arguments)},w.prototype.equals=function(e){if(!I(e))throw new TypeError("Argument must be a Buffer");return this===e||0===w.compare(this,e)},w.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+">"},w.prototype.compare=function(e,t,r,n,o){if(!I(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},w.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},w.prototype.indexOf=function(e,t,r){return C(this,e,t,r,!0)},w.prototype.lastIndexOf=function(e,t,r){return C(this,e,t,r,!1)},w.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 N(this,e,t,r);case"utf8":case"utf-8":return U(this,e,t,r);case"ascii":return L(this,e,t,r);case"latin1":case"binary":return D(this,e,t,r);case"base64":return M(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},w.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var k=4096;function Y(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 j(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 G(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+=Z(e[i]);return o}function q(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 H(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 K(e,t,r,n,o,i){if(!I(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 W(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 z(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 V(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 X(e,t,r,n,o){return o||V(e,0,r,4),d(e,t,r,n,23,4),r+4}function Q(e,t,r,n,o){return o||V(e,0,r,8),d(e,t,r,n,52,8),r+8}w.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),w.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=w.prototype;else{var o=t-e;r=new w(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+e]}return r},w.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||H(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n},w.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||H(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},w.prototype.readUInt8=function(e,t){return t||H(e,1,this.length),this[e]},w.prototype.readUInt16LE=function(e,t){return t||H(e,2,this.length),this[e]|this[e+1]<<8},w.prototype.readUInt16BE=function(e,t){return t||H(e,2,this.length),this[e]<<8|this[e+1]},w.prototype.readUInt32LE=function(e,t){return t||H(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},w.prototype.readUInt32BE=function(e,t){return t||H(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},w.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||H(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},w.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||H(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},w.prototype.readInt8=function(e,t){return t||H(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},w.prototype.readInt16LE=function(e,t){t||H(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},w.prototype.readInt16BE=function(e,t){t||H(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},w.prototype.readInt32LE=function(e,t){return t||H(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},w.prototype.readInt32BE=function(e,t){return t||H(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},w.prototype.readFloatLE=function(e,t){return t||H(e,4,this.length),p(this,e,!0,23,4)},w.prototype.readFloatBE=function(e,t){return t||H(e,4,this.length),p(this,e,!1,23,4)},w.prototype.readDoubleLE=function(e,t){return t||H(e,8,this.length),p(this,e,!0,52,8)},w.prototype.readDoubleBE=function(e,t){return t||H(e,8,this.length),p(this,e,!1,52,8)},w.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||K(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},w.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||K(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},w.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,1,255,0),w.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},w.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):W(this,e,t,!0),t+2},w.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):W(this,e,t,!1),t+2},w.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):z(this,e,t,!0),t+4},w.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):z(this,e,t,!1),t+4},w.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);K(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},w.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var o=Math.pow(2,8*r-1);K(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},w.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,1,127,-128),w.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},w.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):W(this,e,t,!0),t+2},w.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):W(this,e,t,!1),t+2},w.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,2147483647,-2147483648),w.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):z(this,e,t,!0),t+4},w.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||K(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),w.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):z(this,e,t,!1),t+4},w.prototype.writeFloatLE=function(e,t,r){return X(this,e,t,!0,r)},w.prototype.writeFloatBE=function(e,t,r){return X(this,e,t,!1,r)},w.prototype.writeDoubleLE=function(e,t,r){return Q(this,e,t,!0,r)},w.prototype.writeDoubleBE=function(e,t,r){return Q(this,e,t,!1,r)},w.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||!w.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},w.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&&!w.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=I(e)?e:J(new w(e,n).toString()),a=s.length;for(i=0;i<r-t;++i)this[i+t]=s[i%a]}return this};var $=/[^+\/0-9A-Za-z-_]/g;function Z(e){return e<16?"0"+e.toString(16):e.toString(16)}function J(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 ee(e){return function(e){var t,r,n,o,i,s;h||f();var c=e.length;if(c%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===e[c-2]?2:"="===e[c-1]?1:0,s=new u(3*c/4-i),n=i>0?c-4:c;var l=0;for(t=0,r=0;t<n;t+=4,r+=3)o=a[e.charCodeAt(t)]<<18|a[e.charCodeAt(t+1)]<<12|a[e.charCodeAt(t+2)]<<6|a[e.charCodeAt(t+3)],s[l++]=o>>16&255,s[l++]=o>>8&255,s[l++]=255&o;return 2===i?(o=a[e.charCodeAt(t)]<<2|a[e.charCodeAt(t+1)]>>4,s[l++]=255&o):1===i&&(o=a[e.charCodeAt(t)]<<10|a[e.charCodeAt(t+1)]<<4|a[e.charCodeAt(t+2)]>>2,s[l++]=o>>8&255,s[l++]=255&o),s}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace($,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function te(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 re(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function ne(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 oe(e,t){return Promise.resolve().then(()=>(function e(r,n,o){return r>=n.length?o:t(n[r],r).then((function(t){return o.push(t),e(r+1,n,o)}))})(0,e,[]))}const ie={},se={},ae=(e,t)=>{se[e]=t},ue=e=>{const 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,ie[e]=t,t};ue("AccountNameRequired"),ue("AccountNotSupported"),ue("AmountRequired"),ue("BluetoothRequired"),ue("BtcUnmatchedApp"),ue("CantOpenDevice"),ue("CashAddrNotSupported"),ue("CurrencyNotSupported"),ue("DeviceAppVerifyNotSupported"),ue("DeviceGenuineSocketEarlyClose"),ue("DeviceNotGenuine"),ue("DeviceOnDashboardExpected"),ue("DeviceOnDashboardUnexpected"),ue("DeviceInOSUExpected"),ue("DeviceHalted"),ue("DeviceNameInvalid"),ue("DeviceSocketFail"),ue("DeviceSocketNoBulkStatus"),ue("DisconnectedDevice"),ue("DisconnectedDeviceDuringOperation"),ue("EnpointConfig");const he=ue("EthAppPleaseEnableContractData");ue("FeeEstimationFailed"),ue("HardResetFail"),ue("InvalidXRPTag"),ue("InvalidAddress"),ue("InvalidAddressBecauseDestinationIsAlsoSource"),ue("LatestMCUInstalledError"),ue("UnknownMCU"),ue("LedgerAPIError"),ue("LedgerAPIErrorWithMessage"),ue("LedgerAPINotAvailable"),ue("ManagerAppAlreadyInstalled"),ue("ManagerAppRelyOnBTC"),ue("ManagerAppDepInstallRequired"),ue("ManagerAppDepUninstallRequired"),ue("ManagerDeviceLocked"),ue("ManagerFirmwareNotEnoughSpace"),ue("ManagerNotEnoughSpace"),ue("ManagerUninstallBTCDep"),ue("NetworkDown"),ue("NoAddressesFound"),ue("NotEnoughBalance"),ue("NotEnoughBalanceToDelegate"),ue("NotEnoughBalanceInParentAccount"),ue("NotEnoughSpendableBalance"),ue("NotEnoughBalanceBecauseDestinationNotCreated"),ue("NoAccessToCamera"),ue("NotEnoughGas"),ue("NotSupportedLegacyAddress"),ue("GasLessThanEstimate"),ue("PasswordsDontMatch"),ue("PasswordIncorrect"),ue("RecommendSubAccountsToEmpty"),ue("RecommendUndelegation"),ue("TimeoutTagged"),ue("UnexpectedBootloader"),ue("MCUNotGenuineToDashboard"),ue("RecipientRequired"),ue("UnavailableTezosOriginatedAccountReceive"),ue("UnavailableTezosOriginatedAccountSend"),ue("UpdateYourApp"),ue("UserRefusedDeviceNameChange"),ue("UserRefusedAddress"),ue("UserRefusedFirmwareUpdate"),ue("UserRefusedAllowManager"),ue("UserRefusedOnDevice"),ue("TransportOpenUserCancelled"),ue("TransportInterfaceNotAvailable"),ue("TransportWebUSBGestureRequired"),ue("DeviceShouldStayInApp"),ue("WebsocketConnectionError"),ue("WebsocketConnectionFailed"),ue("WrongDeviceForAccount"),ue("WrongAppForCurrency"),ue("ETHAddressNonEIP"),ue("CantScanQRCode"),ue("FeeNotLoaded"),ue("FeeRequired"),ue("FeeTooHigh"),ue("SyncError"),ue("PairingFailed"),ue("GenuineCheckFailed"),ue("LedgerAPI4xx"),ue("LedgerAPI5xx"),ue("FirmwareOrAppUpdateRequired"),ue("NoDBPathGiven"),ue("DBWrongPassword"),ue("DBNotReset");function fe(e,t){this.name="TransportError",this.message=e,this.stack=(new Error).stack,this.id=t}fe.prototype=new Error,ae("TransportError",e=>new fe(e.message,e.id));const ce={PIN_REMAINING_ATTEMPTS:25536,INCORRECT_LENGTH:26368,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 le(e){this.name="TransportStatusError";const t=Object.keys(ce).find(t=>ce[t]===e)||"UNKNOWN_ERROR",r=function(e){switch(e){case 26368:return"Incorrect length";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}le.prototype=new Error,ae("TransportStatusError",e=>new le(e.statusCode));const pe=e=>e&&27264===e.statusCode?new he("Please enable Contract data on the Ethereum app Settings"):e;class de{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=ne(e),o=w.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=ne(e),o=0,i=w.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=w.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 oe(s,(e,t)=>this.transport.send(224,4,0===t?0:128,0,e).then(e=>{r=e})).then(()=>{return{v:r.slice(0,1).toString("hex"),r:r.slice(1,33).toString("hex"),s:r.slice(33,65).toString("hex")}},e=>{throw pe(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=ne(e),o=0,i=w.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=w.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 oe(s,(e,t)=>this.transport.send(224,8,0===t?0:128,0,e).then(e=>{r=e})).then(()=>{return{v:r[0],r:r.slice(1,33).toString("hex"),s:r.slice(33,65).toString("hex")}})}}var ge=ge||{},ve=ge;ge.EXTENSION_ID="kmendfapggjehodndflmmgagdbamhnfd",ge.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"},ge.ErrorCodes={OK:0,OTHER_ERROR:1,BAD_REQUEST:2,CONFIGURATION_UNSUPPORTED:3,DEVICE_INELIGIBLE:4,TIMEOUT:5},ge.Request,ge.Response,ge.Error,ge.SignRequest,ge.SignResponse,ge.RegisterRequest,ge.RegisterResponse,ge.disconnect=function(){ge.port_&&ge.port_.port_&&(ge.port_.port_.disconnect(),ge.port_=null)},ge.getMessagePort=function(e){if("undefined"!=typeof chrome&&chrome.runtime){var t={type:ge.MessageTypes.U2F_SIGN_REQUEST,signRequests:[]};chrome.runtime.sendMessage(ge.EXTENSION_ID,t,(function(){chrome.runtime.lastError?ge.getIframePort_(e):ge.getChromeRuntimePort_(e)}))}else ge.getIframePort_(e)},ge.getChromeRuntimePort_=function(e){var t=chrome.runtime.connect(ge.EXTENSION_ID,{includeTlsChannelId:!0});setTimeout((function(){e(null,new ge.WrappedChromeRuntimePort_(t))}),0)},ge.WrappedChromeRuntimePort_=function(e){this.port_=e},ge.WrappedChromeRuntimePort_.prototype.postMessage=function(e){this.port_.postMessage(e)},ge.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")},ge.getIframePort_=function(e){var t="chrome-extension://"+ge.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)},ge.EXTENSION_TIMEOUT_SEC=30,ge.port_=null,ge.waitingForPort_=[],ge.reqCounter_=0,ge.callbackMap_={},ge.getPortSingleton_=function(e){ge.port_?e(null,ge.port_):(0==ge.waitingForPort_.length&&ge.getMessagePort((function(e,t){for(e||(ge.port_=t,ge.port_.addEventListener("message",ge.responseHandler_));ge.waitingForPort_.length;)ge.waitingForPort_.shift()(e,t)})),ge.waitingForPort_.push(e))},ge.responseHandler_=function(e){var t=e.data,r=t.requestId;if(r&&ge.callbackMap_[r]){var n=ge.callbackMap_[r];delete ge.callbackMap_[r],n(null,t.responseData)}else console.error("Unknown or missing requestId in response.")},ge.isSupported=function(e){ge.getPortSingleton_((function(t,r){e(!t)}))},ge.sign=function(e,t,r){ge.getPortSingleton_((function(n,o){if(n)return t(n);var i=++ge.reqCounter_;ge.callbackMap_[i]=t;var s={type:ge.MessageTypes.U2F_SIGN_REQUEST,signRequests:e,timeoutSeconds:void 0!==r?r:ge.EXTENSION_TIMEOUT_SEC,requestId:i};o.postMessage(s)}))},ge.register=function(e,t,r,n){ge.getPortSingleton_((function(o,i){if(o)return r(o);var s=++ge.reqCounter_;ge.callbackMap_[s]=r;var a={type:ge.MessageTypes.U2F_REGISTER_REQUEST,signRequests:t,registerRequests:e,timeoutSeconds:void 0!==n?n:ge.EXTENSION_TIMEOUT_SEC,requestId:s};i.postMessage(a)}))};var ye=Ae,Ee="undefined"!=typeof navigator&&!!navigator.userAgent,we=Ee&&navigator.userAgent.match(/Safari\//)&&!navigator.userAgent.match(/Chrome\//),me=Ee&&navigator.userAgent.match(/Edge\/1[2345]/),_e=null;function Te(e){return _e||(_e=new e((function(e,t){function r(){e({u2f:null,native:!0})}return Ee?we?r():(void 0!==window.u2f&&"function"==typeof window.u2f.sign&&e({u2f:window.u2f,native:!0}),me?r():"http:"===location.protocol?r():"undefined"==typeof MessageChannel?r():void ve.isSupported((function(t){t?e({u2f:ve,native:!1}):r()}))):r()}))),_e}function Ae(e){return{isSupported:be.bind(e),ensureSupport:Pe.bind(e),register:Ce.bind(e),sign:Oe.bind(e),ErrorCodes:Ae.ErrorCodes,ErrorNames:Ae.ErrorNames}}function Re(e,t){var r=null!=t?t.errorCode:1,n=Ae.ErrorNames[""+r],o=new Error(e);return o.metaData={type:n,code:r},o}function Ie(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){Te(e).then((function(e){n&&!e.native&&e.u2f.disconnect(),r.reject(Re(t,{errorCode:-1}))}))},r}function be(){return Te(this).then((function(e){return!!e.u2f}))}function Se(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 Pe(){return Te(this).then(Se)}function Ce(e,t,r){var n=this;return Array.isArray(e)||(e=[e]),"number"==typeof t&&void 0===r&&(r=t,t=null),t||(t=[]),Ie(n,Te(n).then((function(o){Se(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(Re("Registration failed",e)):(delete e.errorCode,n(e))}),r)}else s.register(e,t,(function(e,t){e?o(e):t.errorCode?o(Re("Registration failed",t)):n(t)}),r)}))}))).promise}function Oe(e,t){var r=this;return Array.isArray(e)||(e=[e]),Ie(r,Te(r).then((function(n){Se(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(Re("Sign failed",e)):(delete e.errorCode,r(e))}),t)}else i.sign(e,(function(e,t){e?n(e):t.errorCode?n(Re("Sign failed",t)):r(t)}),t)}))}))).promise}function Ne(t){Ae[t]=function(){if(!e.Promise)throw new Error("The platform doesn't natively support promises");var r=[].slice.call(arguments);return Ae(e.Promise)[t].apply(null,r)}}Ae.ErrorCodes={CANCELLED:-1,OK:0,OTHER_ERROR:1,BAD_REQUEST:2,CONFIGURATION_UNSUPPORTED:3,DEVICE_INELIGIBLE:4,TIMEOUT:5},Ae.ErrorNames={"-1":"CANCELLED",0:"OK",1:"OTHER_ERROR",2:"BAD_REQUEST",3:"CONFIGURATION_UNSUPPORTED",4:"DEVICE_INELIGIBLE",5:"TIMEOUT"},Ne("isSupported"),Ne("ensureSupport"),Ne("register"),Ne("sign");var Ue,Le=ye,De=Le.isSupported,Me=Le.sign,xe="object"==typeof Reflect?Reflect:null,Be=xe&&"function"==typeof xe.apply?xe.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};Ue=xe&&"function"==typeof xe.ownKeys?xe.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var Fe=Number.isNaN||function(e){return e!=e};function ke(){ke.init.call(this)}var Ye=ke;ke.EventEmitter=ke,ke.prototype._events=void 0,ke.prototype._eventsCount=0,ke.prototype._maxListeners=void 0;var je=10;function Ge(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function qe(e){return void 0===e._maxListeners?ke.defaultMaxListeners:e._maxListeners}function He(e,t,r,n){var o,i,s,a;if(Ge(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=qe(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 Ke(){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 We(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Ke.bind(n);return o.listener=r,n.wrapFn=o,o}function ze(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):Xe(o,o.length)}function Ve(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 Xe(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}Object.defineProperty(ke,"defaultMaxListeners",{enumerable:!0,get:function(){return je},set:function(e){if("number"!=typeof e||e<0||Fe(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");je=e}}),ke.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},ke.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||Fe(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},ke.prototype.getMaxListeners=function(){return qe(this)},ke.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)Be(a,this,t);else{var u=a.length,h=Xe(a,u);for(r=0;r<u;++r)Be(h[r],this,t)}return!0},ke.prototype.addListener=function(e,t){return He(this,e,t,!1)},ke.prototype.on=ke.prototype.addListener,ke.prototype.prependListener=function(e,t){return He(this,e,t,!0)},ke.prototype.once=function(e,t){return Ge(t),this.on(e,We(this,e,t)),this},ke.prototype.prependOnceListener=function(e,t){return Ge(t),this.prependListener(e,We(this,e,t)),this},ke.prototype.removeListener=function(e,t){var r,n,o,i,s;if(Ge(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},ke.prototype.off=ke.prototype.removeListener,ke.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},ke.prototype.listeners=function(e){return ze(this,e,!0)},ke.prototype.rawListeners=function(e){return ze(this,e,!1)},ke.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Ve.call(e,t)},ke.prototype.listenerCount=Ve,ke.prototype.eventNames=function(){return this._eventsCount>0?Ue(this._events):[]};class Qe{constructor(){this.exchangeTimeout=3e4,this._events=new Ye,this.send=async(e,t,r,n,o=w.alloc(0),i=[ce.OK])=>{if(o.length>=256)throw new fe("data.length exceed 256 bytes limit. Got: "+o.length,"DataLengthTooBig");const s=await this.exchange(w.concat([w.from([e,t,r,n]),w.from([o.length]),o])),a=s.readUInt16BE(s.length-2);if(!i.some(e=>e===a))throw new le(a);return s},this.exchangeBusyPromise=void 0,this.exchangeAtomicImpl=async e=>{if(this.exchangeBusyPromise)throw new fe("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 fe(this.ErrorMessage_NoDeviceFound,"NoDeviceFound"))}}),s=t?setTimeout(()=>{i.unsubscribe(),n(new fe(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 fe("Ledger Device is busy (lock "+i+")","TransportLocked"));try{return this._appAPIlock=e,this.setScrambleKey(n),await t.apply(r,o)}finally{this._appAPIlock=null}}}}Qe.isSupported=void 0,Qe.list=void 0,Qe.listen=void 0,Qe.open=void 0,Qe.ErrorMessage_ListenTimeout="No Ledger device found (timeout)",Qe.ErrorMessage_NoDeviceFound="No Ledger device found";let $e=0;const Ze=[],Je=(e,t,r)=>{const n={type:e,id:String(++$e),date:new Date};t&&(n.message=t),r&&(n.data=r),function(e){for(let t=0;t<Ze.length;t++)try{Ze[t](e)}catch(e){console.error(e)}}(n)};i.__ledgerLogsListen=e=>(Ze.push(e),()=>{const t=Ze.indexOf(e);-1!==t&&(Ze[t]=Ze[Ze.length-1],Ze.pop())});const et=e=>e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),tt=e=>e.replace(/-/g,"+").replace(/_/g,"/")+"==".substring(0,3*e.length%4);function rt(e,t,r,n){const o=function(e,t){const r=w.alloc(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n%t.length];return r}(e,r),i=w.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),s={version:"U2F_V2",keyHandle:et(o.toString("base64")),challenge:et(i.toString("base64")),appId:location.origin};return Je("apdu","=> "+e.toString("hex")),Me(s,t/1e3).then(e=>{const{signatureData:t}=e;if("string"==typeof t){const e=w.from(tt(t),"base64");let r;return r=n?e.slice(5):e,Je("apdu","<= "+r.toString("hex")),r}throw e})}let nt=[];class ot extends Qe{static async open(e,t=5e3){return new ot}constructor(){super(),this.scrambleKey=void 0,this.unwrap=!0,nt.push(this)}async exchange(e){try{return await rt(e,this.exchangeTimeout,this.scrambleKey,this.unwrap)}catch(e){throw"object"==typeof e.metaData?(5===e.metaData.code&&(nt.forEach(e=>e.emit("disconnect")),nt=[]),function(e,t,r){const n=new fe(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=w.from(e,"ascii")}setUnwrap(e){this.unwrap=e}close(){return Promise.resolve()}}ot.isSupported=De,ot.list=()=>De().then(e=>e?[null]:[]),ot.listen=e=>{let t=!1;return De().then(r=>{t||(r?(e.next({type:"add",descriptor:null}),e.complete()):e.error(new fe("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}}};var it,st=(it=Object.freeze({default:ot}))&&it.default||it,at=r((function(t,r){var n=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0});var o=n(st);r.transports={u2f:o.default,default:o.default}})),ut=(t(at),at.transports),ht=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 ft=new o.utils.Logger("hardware-wallets/5.0.0-beta.2"),ct="m/44'/60'/0'/0/0";function lt(e){return new Promise(t=>{setTimeout(t,e)})}class pt extends o.Signer{constructor(e,t,r){super(),null==r&&(r=ct),null==t&&(t="default"),o.utils.defineReadOnly(this,"path",r),o.utils.defineReadOnly(this,"type",t),o.utils.defineReadOnly(this,"provider",e||null);const n=ut[t];n||ft.throwArgumentError("unknown or unsupport type","type",t),o.utils.defineReadOnly(this,"_eth",n.create().then(e=>{const t=new de(e);return t.getAppConfiguration().then(e=>t,e=>Promise.reject(e))},e=>Promise.reject(e)))}_retry(e,t){return new Promise((r,n)=>ht(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 lt(100)}return n(new Error("timeout"))})))}getAddress(){return ht(this,void 0,void 0,(function*(){const e=yield this._retry(e=>e.getAddress(this.path));return o.utils.getAddress(e.address)}))}signMessage(e){return ht(this,void 0,void 0,(function*(){"string"==typeof e&&(e=o.utils.toUtf8Bytes(e));const t=o.utils.hexlify(e).substring(2),r=yield this._retry(e=>e.signPersonalMessage(this.path,t));return r.r="0x"+r.r,r.s="0x"+r.s,o.utils.joinSignature(r)}))}signTransaction(e){return ht(this,void 0,void 0,(function*(){const t=e=yield o.utils.resolveProperties(e),r=o.utils.serializeTransaction(t).substring(2),n=yield this._retry(e=>e.signTransaction(this.path,r));return o.utils.serializeTransaction(t,{v:n.v,r:"0x"+n.r,s:"0x"+n.s})}))}connect(e){return new pt(e,this.type,this.path)}}export{pt as LedgerSigner};
|