{"_id":"@bangjelkoski/ledgerhq-hw-transport","_rev":"1-bbcee197f159308cba454b371f7b0212","name":"@bangjelkoski/ledgerhq-hw-transport","dist-tags":{"latest":"6.31.4-beta.0"},"versions":{"6.31.4":{"name":"@bangjelkoski/ledgerhq-hw-transport","version":"6.31.4","keywords":["Ledger","LedgerWallet","NanoS","Blue","Hardware Wallet"],"license":"Apache-2.0","_id":"@bangjelkoski/ledgerhq-hw-transport@6.31.4","maintainers":[{"name":"bangjelkoski","email":"bangjelkoskii@gmail.com"}],"homepage":"https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledgerjs/packages/hw-transport","bugs":{"url":"https://github.com/LedgerHQ/ledger-live/issues"},"dist":{"shasum":"4a3979bcd82f7f62068bbb99c2da348ae885bcc5","tarball":"https://registry.npmjs.org/@bangjelkoski/ledgerhq-hw-transport/-/ledgerhq-hw-transport-6.31.4.tgz","fileCount":16,"integrity":"sha512-A059zHJGzeFHIpp5go6cIT/xVHUEzfdK9TUgahTnUkoI3yrVLu4+VAabLKnKz3L6c2MxJB/6VcN0SRLI8rk4ZQ==","signatures":[{"sig":"MEUCIQDRzNzgvoAV9Oi/MXyxaBab2s7xecB97wdCz0bnJTMGWgIgLHDJq//SCST+Iy6VrC4DMA2dZ2pQckQSQFG7r+xMif8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":134472},"main":"lib/Transport.js","types":"lib/Transport.d.ts","module":"lib-es/Transport.js","gitHead":"dd0dea64b58e5a9125c8a422dcffd29e5ef6abec","scripts":{"doc":"documentation readme src/** --section=API --pe ts --re ts --re d.ts","lint":"eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache","test":"jest","build":"tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es","clean":"rimraf lib lib-es","watch":"tsc --watch","lint:fix":"pnpm lint --fix","prewatch":"pnpm build","watch:es":"tsc --watch -m esnext --moduleResolution bundler --outDir lib-es","unimported":"unimported"},"_npmUser":{"name":"bangjelkoski","email":"bangjelkoskii@gmail.com"},"repository":{"url":"git+https://github.com/LedgerHQ/ledger-live.git","type":"git"},"_npmVersion":"10.8.2","description":"Ledger Hardware Wallet common interface of the communication layer","directories":{},"_nodeVersion":"20.18.2","dependencies":{"events":"^3.3.0","@ledgerhq/logs":"workspace:^","@ledgerhq/errors":"workspace:^","@ledgerhq/devices":"workspace:*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","rimraf":"^4.4.1","ts-jest":"^29.1.1","ts-node":"^10.4.0","@types/jest":"^29.5.10","@types/node":"^22.10.10","documentation":"14.0.2","source-map-support":"^0.5.21"},"_npmOperationalInternal":{"tmp":"tmp/ledgerhq-hw-transport_6.31.4_1740050527758_0.33253218894680114","host":"s3://npm-registry-packages-npm-production"}},"6.31.4-beta.0":{"name":"@bangjelkoski/ledgerhq-hw-transport","version":"6.31.4-beta.0","description":"Ledger Hardware Wallet common interface of the communication layer","keywords":["Ledger","LedgerWallet","NanoS","Blue","Hardware Wallet"],"repository":{"type":"git","url":"git+https://github.com/LedgerHQ/ledger-live.git"},"bugs":{"url":"https://github.com/LedgerHQ/ledger-live/issues"},"homepage":"https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledgerjs/packages/hw-transport","publishConfig":{"access":"public"},"main":"lib/Transport.js","module":"lib-es/Transport.js","types":"lib/Transport.d.ts","license":"Apache-2.0","dependencies":{"events":"^3.3.0","@ledgerhq/devices":"8.4.4","@ledgerhq/logs":"^6.12.0","@ledgerhq/errors":"^6.19.1"},"gitHead":"dd0dea64b58e5a9125c8a422dcffd29e5ef6abec","devDependencies":{"@types/jest":"^29.5.10","@types/node":"^22.10.10","documentation":"14.0.2","jest":"^29.7.0","rimraf":"^4.4.1","source-map-support":"^0.5.21","ts-jest":"^29.1.1","ts-node":"^10.4.0"},"scripts":{"clean":"rimraf lib lib-es","build":"tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es","prewatch":"pnpm build","watch":"tsc --watch","watch:es":"tsc --watch -m esnext --moduleResolution bundler --outDir lib-es","doc":"documentation readme src/** --section=API --pe ts --re ts --re d.ts","lint":"eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache","lint:fix":"pnpm lint --fix","test":"jest","unimported":"unimported"},"_id":"@bangjelkoski/ledgerhq-hw-transport@6.31.4-beta.0","_integrity":"sha512-AIRuxu8s83mv0cBooO5v+pirZyIEUobl8L9QmXvBlTJybmMmyBgigLuoIcZDlSp4Tc7jnoOlHSpFQkASc+5sNA==","_resolved":"/private/var/folders/81/1f_q36hn2lv9zvbgjm_bfv140000gn/T/26beebf9cc4f7d302b1683df679841a0/bangjelkoski-ledgerhq-hw-transport-6.31.4-beta.0.tgz","_from":"file:bangjelkoski-ledgerhq-hw-transport-6.31.4-beta.0.tgz","_nodeVersion":"20.18.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-AIRuxu8s83mv0cBooO5v+pirZyIEUobl8L9QmXvBlTJybmMmyBgigLuoIcZDlSp4Tc7jnoOlHSpFQkASc+5sNA==","shasum":"c5a3b49f6b7cc16a9243285a4dd18d8b3a53e94f","tarball":"https://registry.npmjs.org/@bangjelkoski/ledgerhq-hw-transport/-/ledgerhq-hw-transport-6.31.4-beta.0.tgz","fileCount":17,"unpackedSize":135563,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAVHKS6GCD9ZdtqAjHCO584S2Akv1y/D4TyaCgjO44SEAiEApbvLy5i//jEo+nVu7Qo/fGj4RqxX5VtyHipvpfLBxJU="}]},"_npmUser":{"name":"bangjelkoski","email":"bangjelkoskii@gmail.com"},"directories":{},"maintainers":[{"name":"bangjelkoski","email":"bangjelkoskii@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ledgerhq-hw-transport_6.31.4-beta.0_1740051898046_0.19568304356809296"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-20T11:22:07.677Z","modified":"2025-02-20T11:44:58.522Z","6.31.4":"2025-02-20T11:22:07.944Z","6.31.4-beta.0":"2025-02-20T11:44:58.334Z"},"bugs":{"url":"https://github.com/LedgerHQ/ledger-live/issues"},"license":"Apache-2.0","homepage":"https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ledgerjs/packages/hw-transport","keywords":["Ledger","LedgerWallet","NanoS","Blue","Hardware Wallet"],"repository":{"type":"git","url":"git+https://github.com/LedgerHQ/ledger-live.git"},"description":"Ledger Hardware Wallet common interface of the communication layer","maintainers":[{"name":"bangjelkoski","email":"bangjelkoskii@gmail.com"}],"readme":"<img src=\"https://user-images.githubusercontent.com/4631227/191834116-59cf590e-25cc-4956-ae5c-812ea464f324.png\" height=\"100\" />\n\n[GitHub](https://github.com/LedgerHQ/ledger-live/),\n[Ledger Devs Discord](https://developers.ledger.com/discord-pro),\n[Developer Portal](https://developers.ledger.com/)\n\n## @ledgerhq/hw-transport\n\n`@ledgerhq/hw-transport` implements the generic interface of a Ledger Hardware Wallet transport.\n\n## API\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n#### Table of Contents\n\n*   [Subscription](#subscription)\n    *   [Properties](#properties)\n*   [Device](#device)\n*   [DescriptorEvent](#descriptorevent)\n*   [Observer](#observer)\n*   [Transport](#transport)\n    *   [Parameters](#parameters)\n    *   [exchange](#exchange)\n        *   [Parameters](#parameters-1)\n    *   [exchangeBulk](#exchangebulk)\n        *   [Parameters](#parameters-2)\n    *   [setScrambleKey](#setscramblekey)\n        *   [Parameters](#parameters-3)\n    *   [close](#close)\n    *   [on](#on)\n        *   [Parameters](#parameters-4)\n    *   [off](#off)\n        *   [Parameters](#parameters-5)\n    *   [setDebugMode](#setdebugmode)\n    *   [setExchangeTimeout](#setexchangetimeout)\n        *   [Parameters](#parameters-6)\n    *   [setExchangeUnresponsiveTimeout](#setexchangeunresponsivetimeout)\n        *   [Parameters](#parameters-7)\n    *   [send](#send)\n        *   [Parameters](#parameters-8)\n    *   [exchangeAtomicImpl](#exchangeatomicimpl)\n        *   [Parameters](#parameters-9)\n    *   [setTraceContext](#settracecontext)\n        *   [Parameters](#parameters-10)\n    *   [updateTraceContext](#updatetracecontext)\n        *   [Parameters](#parameters-11)\n    *   [getTraceContext](#gettracecontext)\n    *   [isSupported](#issupported)\n    *   [list](#list)\n        *   [Examples](#examples)\n    *   [listen](#listen)\n        *   [Parameters](#parameters-12)\n        *   [Examples](#examples-1)\n    *   [open](#open)\n        *   [Parameters](#parameters-13)\n        *   [Examples](#examples-2)\n    *   [create](#create)\n        *   [Parameters](#parameters-14)\n        *   [Examples](#examples-3)\n\n### Subscription\n\nType: {unsubscribe: function (): void}\n\n#### Properties\n\n*   `unsubscribe` **function (): void**&#x20;\n\n### Device\n\nType: any\n\n### DescriptorEvent\n\nA \"descriptor\" is a parameter that is specific to the implementation, and can be an ID, file path, or URL.\ntype: add or remove event\ndescriptor: a parameter that can be passed to open(descriptor)\ndeviceModel: device info on the model (is it a nano s, nano x, ...)\ndevice: transport specific device info\n\n### Observer\n\nObserver generic type, following the Observer pattern\n\nType: Readonly<{next: function (event: EventType): any, error: function (e: EventError): any, complete: function (): any}>\n\n### Transport\n\nThe Transport class defines a generic interface for communicating with a Ledger hardware wallet.\nThere are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb) and environment (Node, Web,...).\nIt is an abstract class that needs to be implemented.\n\n#### Parameters\n\n*   `$0` **{context: TraceContext?, logType: LogType?}**  (optional, default `{}`)\n\n    *   `$0.context` &#x20;\n    *   `$0.logType` &#x20;\n\n#### exchange\n\nSend data to the device using a low level API.\nIt's recommended to use the \"send\" method for a higher level API.\n\n##### Parameters\n\n*   `_apdu` **[Buffer](https://nodejs.org/api/buffer.html)**&#x20;\n*   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Contains optional options for the exchange function*   abortTimeoutMs: stop the exchange after a given timeout. Another timeout exists\n        to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange. (optional, default `{}`)\n\n    *   `options.abortTimeoutMs` &#x20;\n*   `apdu` **[Buffer](https://nodejs.org/api/buffer.html)** The data to send.\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** A promise that resolves with the response data from the device.\n\n#### exchangeBulk\n\nSend apdus in batch to the device using a low level API.\nThe default implementation is to call exchange for each apdu.\n\n##### Parameters\n\n*   `apdus` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>** array of apdus to send.\n*   `observer` **[Observer](#observer)<[Buffer](https://nodejs.org/api/buffer.html)>** an observer that will receive the response of each apdu.\n\nReturns **[Subscription](#subscription)** A Subscription object on which you can call \".unsubscribe()\" to stop sending apdus.\n\n#### setScrambleKey\n\nSet the \"scramble key\" for the next data exchanges with the device.\nEach app can have a different scramble key and it is set internally during instantiation.\n\n##### Parameters\n\n*   `_key` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;\n*   `key` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The scramble key to set.\n    deprecated This method is no longer needed for modern transports and should be migrated away from.\n    no @ before deprecated as it breaks documentationjs on version 14.0.2\n    <https://github.com/documentationjs/documentation/issues/1596>\n\n#### close\n\nClose the connection with the device.\n\nNote: for certain transports (hw-transport-node-hid-singleton for ex), once the promise resolved,\nthe transport instance is actually still cached, and the device is disconnected only after a defined timeout.\nBut for the consumer of the Transport, this does not matter and it can consider the transport to be closed.\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<void>** A promise that resolves when the transport is closed.\n\n#### on\n\nListen for an event on the transport instance.\nTransport implementations may have specific events. Common events include:\n\"disconnect\" : triggered when the transport is disconnected.\n\n##### Parameters\n\n*   `eventName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the event to listen for.\n*   `cb` **function (...args: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\\<any>): any**&#x20;\n\nReturns **void**&#x20;\n\n#### off\n\nStop listening to an event on an instance of transport.\n\n##### Parameters\n\n*   `eventName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;\n*   `cb` **function (...args: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\\<any>): any**&#x20;\n\nReturns **void**&#x20;\n\n#### setDebugMode\n\nEnable or not logs of the binary exchange\n\n#### setExchangeTimeout\n\nSet a timeout (in milliseconds) for the exchange call. Only some transport might implement it. (e.g. U2F)\n\n##### Parameters\n\n*   `exchangeTimeout` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;\n\nReturns **void**&#x20;\n\n#### setExchangeUnresponsiveTimeout\n\nDefine the delay before emitting \"unresponsive\" on an exchange that does not respond\n\n##### Parameters\n\n*   `unresponsiveTimeout` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;\n\nReturns **void**&#x20;\n\n#### send\n\nSend data to the device using the higher level API.\n\n##### Parameters\n\n*   `cla` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The instruction class for the command.\n*   `ins` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The instruction code for the command.\n*   `p1` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The first parameter for the instruction.\n*   `p2` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The second parameter for the instruction.\n*   `data` **[Buffer](https://nodejs.org/api/buffer.html)** The data to be sent. Defaults to an empty buffer. (optional, default `Buffer.alloc(0)`)\n*   `statusList` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** A list of acceptable status codes for the response. Defaults to \\[StatusCodes.OK]. (optional, default `[StatusCodes.OK]`)\n*   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Contains optional options for the exchange function*   abortTimeoutMs: stop the send after a given timeout. Another timeout exists\n        to detect unresponsive device (see `unresponsiveTimeout`). This timeout aborts the exchange. (optional, default `{}`)\n\n    *   `options.abortTimeoutMs` &#x20;\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** A promise that resolves with the response data from the device.\n\n#### exchangeAtomicImpl\n\nWrapper to make an exchange \"atomic\" (blocking any other exchange)\n\nIt also handles \"unresponsiveness\" by emitting \"unresponsive\" and \"responsive\" events.\n\n##### Parameters\n\n*   `f` **function (): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<Output>** The exchange job, using the transport to run\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<Output>** a Promise resolving with the output of the given job\n\n#### setTraceContext\n\nSets the context used by the logging/tracing mechanism\n\nUseful when re-using (cached) the same Transport instance,\nbut with a new tracing context.\n\n##### Parameters\n\n*   `context` **TraceContext?** A TraceContext, that can undefined to reset the context\n\n#### updateTraceContext\n\nUpdates the context used by the logging/tracing mechanism\n\nThe update only overrides the key-value that are already defined in the current context.\n\n##### Parameters\n\n*   `contextToAdd` **TraceContext** A TraceContext that will be added to the current context\n\n#### getTraceContext\n\nGets the tracing context of the transport instance\n\nReturns **(TraceContext | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**&#x20;\n\n#### isSupported\n\nCheck if the transport is supported on the current platform/browser.\n\nType: function (): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** A promise that resolves with a boolean indicating support.\n\n#### list\n\nList all available descriptors for the transport.\nFor a better granularity, checkout `listen()`.\n\nType: function (): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\\<any>>\n\n##### Examples\n\n```javascript\nTransportFoo.list().then(descriptors => ...)\n```\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\\<any>>** A promise that resolves with an array of descriptors.\n\n#### listen\n\nListen for device events for the transport. The method takes an observer of DescriptorEvent and returns a Subscription.\nA DescriptorEvent is an object containing a \"descriptor\" and a \"type\" field. The \"type\" field can be \"add\" or \"remove\", and the \"descriptor\" field can be passed to the \"open\" method.\nThe \"listen\" method will first emit all currently connected devices and then will emit events as they occur, such as when a USB device is plugged in or a Bluetooth device becomes discoverable.\n\nType: function (observer: [Observer](#observer)<[DescriptorEvent](#descriptorevent)\\<any>>): [Subscription](#subscription)\n\n##### Parameters\n\n*   `observer` **[Observer](#observer)<[DescriptorEvent](#descriptorevent)\\<any>>** An object with \"next\", \"error\", and \"complete\" functions, following the observer pattern.\n\n##### Examples\n\n```javascript\nconst sub = TransportFoo.listen({\nnext: e => {\nif (e.type===\"add\") {\nsub.unsubscribe();\nconst transport = await TransportFoo.open(e.descriptor);\n...\n}\n},\nerror: error => {},\ncomplete: () => {}\n})\n```\n\nReturns **[Subscription](#subscription)** A Subscription object on which you can call \".unsubscribe()\" to stop listening to descriptors.\n\n#### open\n\nAttempt to create a Transport instance with a specific descriptor.\n\nType: function (descriptor: any, timeoutMs: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), context: TraceContext): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Transport](#transport)>\n\n##### Parameters\n\n*   `descriptor` **any** The descriptor to open the transport with.\n*   `timeout` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** An optional timeout for the transport connection.\n*   `context` **TraceContext** Optional tracing/log context\n\n##### Examples\n\n```javascript\nTransportFoo.open(descriptor).then(transport => ...)\n```\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Transport](#transport)>** A promise that resolves with a Transport instance.\n\n#### create\n\ncreate() allows to open the first descriptor available or\nthrow if there is none or if timeout is reached.\nThis is a light helper, alternative to using listen() and open() (that you may need for any more advanced usecase)\n\n##### Parameters\n\n*   `openTimeout`   (optional, default `3000`)\n*   `listenTimeout` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**&#x20;\n\n##### Examples\n\n```javascript\nTransportFoo.create().then(transport => ...)\n```\n\nReturns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Transport](#transport)>**&#x20;\n","readmeFilename":"README.md"}