{"version":3,"file":"ledger-transport-middleware.cjs","sourceRoot":"","sources":["../src/ledger-transport-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,uDAAyD;AAUzD;;GAEG;AACH,MAAa,yBAAyB;IAAtC;QACW,gBAAW,GAAG,OAAO,CAAC;QAEtB,eAAU,GAAG,UAAU,CAAC;QAExB,sBAAiB,GAAG,OAAO,CAAC;QAErC,uDAAuB;IAuCzB,CAAC;IArCC;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACtC,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,SAAoB;QAC/B,uBAAA,IAAI,wCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,YAAY;QACV,IAAI,CAAC,uBAAA,IAAI,4CAAW,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,uBAAA,IAAI,4CAAW,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,IAAI,sCAAsB,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IACzD,CAAC;CACF;AA9CD,8DA8CC","sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\n\nimport { MetaMaskLedgerHwAppEth } from './ledger-hw-app';\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TransportMiddleware {\n  setTransport(transport: Transport): void;\n  getTransport(): Transport;\n  getEthApp(): MetaMaskLedgerHwAppEth;\n  dispose(): Promise<void>;\n}\n\n/**\n * LedgerTransportMiddleware is a middleware to communicate with the Ledger device via transport or LedgerHwAppEth\n */\nexport class LedgerTransportMiddleware implements TransportMiddleware {\n  readonly mainAppName = 'BOLOS';\n\n  readonly ethAppName = 'Ethereum';\n\n  readonly transportEncoding = 'ascii';\n\n  #transport?: Transport;\n\n  /**\n   * Method to close the transport connection.\n   */\n  async dispose(): Promise<void> {\n    const transport = this.getTransport();\n    await transport.close();\n  }\n\n  /**\n   * Method to set the transport object.\n   *\n   * @param transport - The transport object for communicating with a Ledger hardware wallet.\n   */\n  setTransport(transport: Transport): void {\n    this.#transport = transport;\n  }\n\n  /**\n   * Method to retrieve the transport object.\n   *\n   * @returns An generic interface for communicating with a Ledger hardware wallet.\n   */\n  getTransport(): Transport {\n    if (!this.#transport) {\n      throw new Error('Instance `transport` is not initialized.');\n    }\n    return this.#transport;\n  }\n\n  /**\n   * Method to get a new instance of the eth app object.\n   *\n   * @returns An generic interface for communicating with a Ledger hardware wallet to perform operation.\n   */\n  getEthApp(): MetaMaskLedgerHwAppEth {\n    return new MetaMaskLedgerHwAppEth(this.getTransport());\n  }\n}\n"]}