1import{e as T,u as x,c as _}from"./DmE-NGqm.js";function L(a,e){for(var n=0;n<e.length;n++){const t=e[n];if(typeof t!="string"&&!Array.isArray(t)){for(const r in t)if(r!=="default"&&!(r in a)){const i=Object.getOwnPropertyDescriptor(t,r);i&&Object.defineProperty(a,r,i.get?i:{enumerable:!0,get:()=>t[r]})}}}return Object.freeze(Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}))}var w={},b={},m=_&&_.__awaiter||function(a,e,n,t){function r(i){return i instanceof n?i:new n(function(s){s(i)})}return new(n||(n=Promise))(function(i,s){function o(c){try{d(t.next(c))}catch(u){s(u)}}function l(c){try{d(t.throw(c))}catch(u){s(u)}}function d(c){c.done?i(c.value):r(c.value).then(o,l)}d((t=t.apply(a,e||[])).next())})};Object.defineProperty(b,"__esModule",{value:!0});b.Transport=void 0;const U=x,g=T;class k{constructor(){this._listeners=new Map,this._exchangeBusy=null,this._appAPILock=null,this.send=(e,n,t,r,i=new Uint8Array(0))=>m(this,void 0,void 0,function*(){if(i.length>=256)throw new g.TransportError(`data.length exceed 256 bytes limit. Got: ${i.length}`,"DataLengthTooBig");const s=(0,U.concat)([new Uint8Array([e,n,t,r,i.length]),i]),o=yield this.exchange(s),l=(0,U.readU16BE)(o,o.length-2);if(l!==g.StatusCodes.OK)throw new g.TransportStatusError(l);return o})}on(e,n){let t=this._listeners.get(e);t||(t=new Set,this._listeners.set(e,t)),t.add(n)}off(e,n){var t;(t=this._listeners.get(e))===null||t===void 0||t.delete(n)}emit(e,...n){const t=this._listeners.get(e);if(t)for(const r of Array.from(t))r(...n)}exchangeAtomicImpl(e){return m(this,void 0,void 0,function*(){if(this._exchangeBusy)throw new g.TransportRaceCondition("An action was already pending on the Ledger device. Please deny or reconnect.");let n;this._exchangeBusy=new Promise(t=>{n=t});try{return yield e()}finally{n(),this._exchangeBusy=null}})}setScrambleKey(e){}decorateAppAPIMethods(e,n,t){for(const r of n){const i=e[r];e[r]=(...s)=>m(this,void 0,void 0,function*(){if(this._appAPILock)throw new g.TransportError(`Ledger Device is busy (lock ${this._appAPILock})`,"TransportLocked");try{return this._appAPILock=r,this.setScrambleKey(t),yield i.apply(e,s)}finally{this._appAPILock=null}})}}}b.Transport=k;b.default=k;var v={};Object.defineProperty(v,"__esModule",{value:!0});v.getReducedResult=v.reduceResponse=v.makeBlocks=void 0;const y=x,D=T,O=5;function N(a,e,n){const t=new Uint8Array(2);new DataView(t.buffer).setUint16(0,n.length,!1);let r=(0,y.concat)([t,n]);const i=e-5,s=Math.ceil(r.length/i),o=new Uint8Array(s*i-r.length+1);r=(0,y.concat)([r,o]);const l=[];for(let d=0;d<s;d++){const c=new Uint8Array(5),u=new DataView(c.buffer);u.setUint16(0,a,!1),c[2]=O,u.setUint16(3,d,!1);const B=r.subarray(d*i,(d+1)*i);l.push((0,y.concat)([c,B]))}return l}v.makeBlocks=N;function P(a,e,n){const t=new DataView(n.buffer,n.byteOffset,n.byteLength);if(t.getUint16(0,!1)!==a)throw new D.TransportError("Invalid channel","InvalidChannel");if(n[2]!==O)throw new D.TransportError("Invalid tag","InvalidTag");const r=e?e.sequence:0;if(t.getUint16(3,!1)!==r)throw new D.TransportError("Invalid sequence","InvalidSequence");let i=e?e.dataLength:(0,y.readU16BE)(n,5);const s=e?5:7;let o=e?(0,y.concat)([e.data,n.subarray(s)]):n.subarray(s).slice();return o.length>i&&(o=o.subarray(0,i)),{data:o,dataLength:i,sequence:(e?e.sequence:0)+1}}v.reduceResponse=P;function q(a){return a&&a.data.length===a.dataLength?a.data:null}v.getReducedResult=q;var p=_&&_.__awaiter||function(a,e,n,t){function r(i){return i instanceof n?i:new n(function(s){s(i)})}return new(n||(n=Promise))(function(i,s){function o(c){try{d(t.next(c))}catch(u){s(u)}}function l(c){try{d(t.throw(c))}catch(u){s(u)}}function d(c){c.done?i(c.value):r(c.value).then(o,l)}d((t=t.apply(a,e||[])).next())})};Object.defineProperty(w,"__esModule",{value:!0});var R=w.TransportWebUSB=void 0;const M=b,I=v,f=T,A=11415,j=1,E=3,C=64;function S(a){return p(this,void 0,void 0,function*(){try{yield a.reset()}catch(e){console.warn(e)}})}class h extends M.Transport{constructor(e,n){super(),this.device=e,this.interfaceNumber=n,this.channel=Math.floor(Math.random()*65535),this.packetSize=C,this._disconnectEmitted=!1}static isSupported(){return Promise.resolve(typeof navigator<"u"&&!!navigator.usb&&typeof navigator.usb.getDevices=="function")}static list(){return navigator!=null&&navigator.usb?navigator.usb.getDevices().then(e=>e.filter(n=>n.vendorId===A)):Promise.resolve([])}static request(){var e;return p(this,void 0,void 0,function*(){if(!(navigator!=null&&navigator.usb))throw new f.TransportWebUSBGestureRequired("WebUSB not available");let n;try{n=yield navigator.usb.requestDevice({filters:[{vendorId:A}]})}catch(t){throw typeof DOMException<"u"&&t instanceof DOMException&&t.code===18?new f.TransportWebUSBGestureRequired(t.message):new f.TransportOpenUserCancelled((e=t==null?void 0:t.message)!==null&&e!==void 0?e:"User cancelled")}return h.open(n)})}static create(){return p(this,void 0,void 0,function*(){const e=yield h.list();return e.length===0?h.request():h.open(e[0])})}static open(e){var n;return p(this,void 0,void 0,function*(){const t=navigator.usb;if(!t)throw new f.TransportWebUSBGestureRequired("WebUSB not available");yield e.open(),e.configuration===null&&(yield e.selectConfiguration(j)),yield S(e);const r=e.configurations[0].interfaces.find(o=>o.alternates.some(l=>l.interfaceClass===255));if(!r)throw new f.TransportInterfaceNotAvailable("No WebUSB interface found for your Ledger device. Please upgrade firmware or contact techsupport.");try{yield e.claimInterface(r.interfaceNumber)}catch(o){throw yield e.close(),new f.TransportInterfaceNotAvailable((n=o==null?void 0:o.message)!==null&&n!==void 0?n:"claimInterface failed")}const i=new h(e,r.interfaceNumber),s=o=>{o.device===e&&(t.removeEventListener("disconnect",s),i._emitDisconnect(new f.DisconnectedDevice))};return t.addEventListener("disconnect",s),i})}_emitDisconnect(e){this._disconnectEmitted||(this._disconnectEmitted=!0,this.emit
1("disconnect",e))}exchange(e){return p(this,void 0,void 0,function*(){return this.exchangeAtomicImpl(()=>p(this,void 0,void 0,function*(){var n,t;try{const r=(0,I.makeBlocks)(this.channel,this.packetSize,e);for(const o of r)yield this.device.transferOut(E,o);let i=null,s=null;for(;!(s=(0,I.getReducedResult)(i));){const o=yield this.device.transferIn(E,this.packetSize);if(!o.data)throw new f.DisconnectedDeviceDuringOperation("transferIn returned no data");const l=new Uint8Array(o.data.buffer,o.data.byteOffset,o.data.byteLength);i=(0,I.reduceResponse)(this.channel,i,l)}return s}catch(r){throw!((t=(n=r==null?void 0:r.message)===null||n===void 0?void 0:n.includes)===null||t===void 0)&&t.call(n,"disconnected")?(this._emitDisconnect(r),new f.DisconnectedDeviceDuringOperation(r.message)):r}}))})}close(){return p(this,void 0,void 0,function*(){yield this.device.releaseInterface(this.interfaceNumber),yield S(this.device),yield this.device.close()})}}R=w.TransportWebUSB=h;var G=w.default=h;const W=L({__proto__:null,get TransportWebUSB(){return R},default:G},[w]);export{W as w};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.