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>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=0,c=r-o;fc?c:f+16383));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<>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<>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<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()=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 S(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:b(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):b(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function b(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;ia&&(r=a-u),i=r;i>=0;i--){for(var c=!0,l=0;lo&&(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>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;o239?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(;n0&&(e=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(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;fo)&&(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 O(this,e,t,r);case"latin1":case"binary":return N(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;on)&&(r=n);for(var o="",i=t;ir)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||te.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>>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>>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),t0&&(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=(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=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>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=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=0;--o)e[o+t]=this[o+r];else if(i<1e3||!v.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i55295&&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>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=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){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,[]))}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=we,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 we(e){return{isSupported:Te.bind(e),ensureSupport:Re.bind(e),register:Ie.bind(e),sign:Se.bind(e),ErrorCodes:we.ErrorCodes,ErrorNames:we.ErrorNames}}function me(e,t){var r=null!=t?t.errorCode:1,n=we.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(me(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(me("Registration failed",e)):(delete e.errorCode,n(e))}),r)}else s.register(e,t,(function(e,t){e?o(e):t.errorCode?o(me("Registration failed",t)):n(t)}),r)}))}))).promise}function Se(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(me("Sign failed",e)):(delete e.errorCode,r(e))}),t)}else i.sign(e,(function(e,t){e?n(e):t.errorCode?n(me("Sign failed",t)):r(t)}),t)}))}))).promise}function be(e){we[e]=function(){if(!fe.Promise)throw new Error("The platform doesn't natively support promises");var t=[].slice.call(arguments);return we(fe.Promise)[e].apply(null,t)}}we.ErrorCodes={CANCELLED:-1,OK:0,OTHER_ERROR:1,BAD_REQUEST:2,CONFIGURATION_UNSUPPORTED:3,DEVICE_INELIGIBLE:4,TIMEOUT:5},we.ErrorNames={"-1":"CANCELLED",0:"OK",1:"OTHER_ERROR",2:"BAD_REQUEST",3:"CONFIGURATION_UNSUPPORTED",4:"DEVICE_INELIGIBLE",5:"TIMEOUT"},be("isSupported"),be("ensureSupport"),be("register"),be("sign");var Pe,Ce=pe,Oe=Ce.isSupported,Ne=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;Me.EventEmitter=Me,Me.prototype._events=void 0,Me.prototype._eventsCount=0,Me.prototype._maxListeners=void 0;var Be=10;function Fe(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function ke(e){return void 0===e._maxListeners?Me.defaultMaxListeners:e._maxListeners}function Ye(e,t,r,n){var o,i,s,a;if(Fe(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=ke(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 je(){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 Ge(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=je.bind(n);return o.listener=r,n.wrapFn=o,o}function qe(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;r0&&(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=Ke(a,u);for(r=0;r=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=0;n--)this.removeListener(e,t[n]);return this},Me.prototype.listeners=function(e){return qe(this,e,!0)},Me.prototype.rawListeners=function(e){return qe(this,e,!1)},Me.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):He.call(e,t)},Me.prototype.listenerCount=He,Me.prototype.eventNames=function(){return this._eventsCount>0?Pe(this._events):[]};class We{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}}}}We.isSupported=void 0,We.list=void 0,We.listen=void 0,We.open=void 0,We.ErrorMessage_ListenTimeout="No Ledger device found (timeout)",We.ErrorMessage_NoDeviceFound="No Ledger device found";let ze=0;const Ve=[],Xe=(e,t,r)=>{const n={type:e,id:String(++ze),date:new Date};t&&(n.message=t),r&&(n.data=r),function(e){for(let t=0;t(Ve.push(e),()=>{const t=Ve.indexOf(e);-1!==t&&(Ve[t]=Ve[Ve.length-1],Ve.pop())});"undefined"!=typeof window&&(window.__ledgerLogsListen=Qe);const Ze=e=>e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");function Je(e,t,r,n){const o=function(e,t){const r=v.alloc(e.length);for(let n=0;n "+e.toString("hex")),Ne(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,Xe("apdu","<= "+o.toString("hex")),o}throw e;var r})}let $e=[];class et extends We{static async open(e,t=5e3){return new et}constructor(){super(),this.scrambleKey=void 0,this.unwrap=!0,$e.push(this)}async exchange(e){try{return await Je(e,this.exchangeTimeout,this.scrambleKey,this.unwrap)}catch(e){throw"object"==typeof e.metaData?(5===e.metaData.code&&($e.forEach(e=>e.emit("disconnect")),$e=[]),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()}}et.isSupported=Oe,et.list=()=>Oe().then(e=>e?[null]:[]),et.listen=e=>{let t=!1;return Oe().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 tt={u2f:et,default:et};var rt=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 nt=new e.utils.Logger("hardware-wallets/5.0.0-beta.8");function ot(e){return new Promise(t=>{setTimeout(t,e)})}class it 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=tt[r];o||nt.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)=>rt(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 ot(100)}return n(new Error("timeout"))})))}getAddress(){return rt(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 rt(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 rt(this,void 0,void 0,(function*(){const r=t=yield e.utils.resolveProperties(t),n=e.utils.serializeTransaction(r).substring(2),o=yield this._retry(e=>e.signTransaction(this.path,n));return e.utils.serializeTransaction(r,{v:o.v,r:"0x"+o.r,s:"0x"+o.s})}))}connect(e){return new it(e,this.type,this.path)}}export{it as LedgerSigner};