# yoroi-extension-ledger-connect-handler

> Interface for communication with Cardano Ledger app

Latest version **2.0.4** (published 2019-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install yoroi-extension-ledger-connect-handler
pnpm add yoroi-extension-ledger-connect-handler
yarn add yoroi-extension-ledger-connect-handler
bun add yoroi-extension-ledger-connect-handler
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2019-10-26 |
| First published | 2019-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 32.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | EMURGO.io |
| Maintainers | emurgo-shin |
| Keywords | cardano, ledger, yoroi, webauthn, webusb, u2f |

## Links

- npm: https://www.npmjs.com/package/yoroi-extension-ledger-connect-handler
- Repository: https://github.com/Emurgo/yoroi-extension-ledger-connect-handler
- Homepage: https://github.com/Emurgo/yoroi-extension-ledger-connect-handler#readme
- Issues: https://github.com/Emurgo/yoroi-extension-ledger-connect-handler/issues
- npm.io page: https://npm.io/package/yoroi-extension-ledger-connect-handler

## Dependencies (1)

- [@cardano-foundation/ledgerjs-hw-app-cardano](https://npm.io/package/@cardano-foundation/ledgerjs-hw-app-cardano.md) 1.0.7

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 2.0.4 (latest) — 2019-10-26
- 2.0.3 — 2019-10-26

## README

# yoroi-extension-ledger-connect-handler
This library enables Yoroi extension to communicate with Ledger device, in process this library needs one web page that directly communicates with Ledger device.
This library is responsible for opening, sendind resquest, passing back response to Yoroi and closing the target web page.

# Message Passing
![ledger-content-script](https://user-images.githubusercontent.com/19986226/66384568-f77fff00-e9f9-11e9-9d1d-dfe4b8afc5fc.png)

**Flow:**
1. `Yoroi` requests `yoroi-extension-ledger-connect-handler`(Using function call).
2. `yoroi-extension-ledger-connect-handler` opens target Website.
3. `yoroi-extension-ledger-connect-handler` sends request message to `content-script`(Using extension port).
4. `content-script` passes request to the target Website app(Using `postMessage()`).
5. Target Website app processes the request and send response to `content-script`(Using `postMessage()`).
6. `content-script` passes response to `yoroi-extension-ledger-connect-handler`(Using extension port).
7. Finally, `yoroi-extension-ledger-connect-handler` passes response to `Yoroi`(Using function return).

# Supported Functions
- [getExtendedPublicKey](https://github.com/Emurgo/yoroi-extension-ledger-connect-handler/blob/a130d213ce4bfbb4f51e90d44345d2c32aab825b/src/ledgerConnect.js#L56) = (hdPath: BIP32Path): Promise\<ExtendedPublicKeyResp\>

  params:
  - hdPath: [BIP32Path](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L38)<br>
  HARDENED = 0x80000000;<br>
  PURPOSE = 44;<br>
  COIN_TYPE = 1815; // Cardano<br><br>
  BIP32Path = [<br>
    HARDENED + PURPOSE,<br>
    HARDENED + COIN_TYPE,<br>
    HARDENED + account,<br>
    chain,<br>
    address<br>
  ]

  returns:
  - [Promise\<ExtendedPublicKeyResp\>](https://github.com/Emurgo/yoroi-extension-ledger-connect-handler/blob/a130d213ce4bfbb4f51e90d44345d2c32aab825b/src/types.js#L39)<br>
  type ExtendedPublicKeyResp = {
    ePublicKey: [GetExtendedPublicKeyResponse](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L71),
    deviceVersion: [GetVersionResponse](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L60),
  }

- [signTransaction](https://github.com/Emurgo/yoroi-extension-ledger-connect-handler/blob/a130d213ce4bfbb4f51e90d44345d2c32aab825b/src/ledgerConnect.js#L96) = (inputs: Array\<InputTypeUTxO>, outputs: Array<OutputTypeAddress | OutputTypeChange\>): Promise\<SignTransactionResponse\>

  params:
  - inputs: Array<[InputTypeUTxO](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L40)>
  - outputs: Array<[OutputTypeAddress](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L46) | [OutputTypeChange](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L51)>

  returns:
  - [Promise\<SignTransactionResponse\>](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L84)

- [showAddress](https://github.com/Emurgo/yoroi-extension-ledger-connect-handler/blob/3c14ffe02e0ba11740b8103d5e20b7cabbbe88db/src/ledgerConnect.js#L95) = (hdPath: BIP32Path, address: string): Promise\<void\>

  params:
  - hdPath: [BIP32Path](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L38)
  - address: string

  returns:
  - Promise\<void\>

- [deriveAddress](https://github.com/Emurgo/yoroi-extension-ledger-connect-handler/blob/a130d213ce4bfbb4f51e90d44345d2c32aab825b/src/ledgerConnect.js#L115) = (hdPath: BIP32Path): Promise\<DeriveAddressResponse\>

  params:
  - hdPath: [BIP32Path](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L38)

  returns:
  - [Promise\<DeriveAddressResponse\>](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L67)

- [getVersion](https://github.com/Emurgo/yoroi-extension-ledger-connect-handler/blob/3c14ffe02e0ba11740b8103d5e20b7cabbbe88db/src/ledgerConnect.js#L132) = (): Promise\<GetVersionResponse\>

  params:
  - `void`

  returns:
  - [Promise\<GetVersionResponse\>](https://github.com/cardano-foundation/ledgerjs-hw-app-cardano/blob/ac3ee1345506ab343a7159ebbcec8e616f8ac5d9/src/Ada.js#L60)

# Example
**Import**
```
import LedgerConnect from 'yoroi-extension-ledger-connect-handler';
```
**Create new instance**
```

const ledgerConnect = new LedgerConnect(config);
```
`config` is type of: [Config](https://github.com/Emurgo/yoroi-extension-ledger-connect-handler/blob/c88151a718c660ef63bbbcd563de452a29861348/src/types.js#L43)

**Calling function**
```
const deviceVersionResp = await ledgerConnect.getVersion();
```

# Supported Ledger Transport
- [@ledgerhq/hw-transport-webauthn](https://www.npmjs.com/package/@ledgerhq/hw-transport-webauthn) [Default]
- [@ledgerhq/hw-transport-u2f](https://www.npmjs.com/package/@ledgerhq/hw-transport-u2f)
  - Has issues on `Windows 10 Version: >= 1903`. [Refer](https://github.com/Emurgo/yoroi-frontend/pull/696).
- [@ledgerhq/hw-transport-webusb](https://www.npmjs.com/package/@ledgerhq/hw-transport-webusb) [Incomplete]
  - Firefox does not supports [WebUSB](https://caniuse.com/#feat=webusb).
  - Needs `udev rules`(on Linux) or `drivers`(on Windows) to be pre-installed. [Refer](https://github.com/Emurgo/yoroi-frontend/pull/696) WebUSB section.

# <a name="building-up">Building up</a>
- `nvm i`
- `yarn`
- `yarn run build`

# Publishing
Make sure you have followed [Building up](#building-up) steps before publishing.
- `npm publish`

---
_Source: https://npm.io/package/yoroi-extension-ledger-connect-handler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
