# @trust/keyto

> A utility for translating cryptographic keys between representations

Latest version **1.0.1** (published 2020-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @trust/keyto
pnpm add @trust/keyto
yarn add @trust/keyto
bun add @trust/keyto
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-02-26 |
| First published | 2017-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/trust__keyto) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 100 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | christiansmith, codenamedmitri, cstefanache, eternaldeiwos, ibudea, keelerh, thelunararmy |
| Keywords | PEM, JWK, Webcrypto, JOSE |

## Links

- npm: https://www.npmjs.com/package/@trust/keyto
- Repository: https://github.com/EternalDeiwos/keyto
- Homepage: https://github.com/EternalDeiwos/keyto#readme
- Issues: https://github.com/EternalDeiwos/keyto/issues
- npm.io page: https://npm.io/package/@trust/keyto

## Dependencies (3)

- [asn1.js](https://npm.io/package/asn1.js.md) ^5.2.0
- [elliptic](https://npm.io/package/elliptic.md) ^6.5.2
- [base64url](https://npm.io/package/base64url.md) ^3.0.1

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-02-26
- 2.0.0-alpha1 (next) — 2020-03-05
- 1.0.0 — 2019-11-24
- 0.3.7 — 2019-03-25
- 0.3.5 — 2019-02-13
- 0.3.4 — 2018-05-19
- 0.3.3 — 2018-05-19
- 0.3.2 — 2018-01-20
- 0.3.1 — 2017-06-22
- 0.3.0 — 2017-06-15
- 0.2.0 — 2017-06-14
- 0.1.2 — 2017-06-12
- 0.1.0 — 2017-06-11

## README

# Keyto _(@trust/keyto)_

[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![Build Status](https://travis-ci.org/EternalDeiwos/keyto.svg?branch=master)](https://travis-ci.org/EternalDeiwos/keyto)
[![codecov](https://codecov.io/gh/EternalDeiwos/keyto/branch/master/graph/badge.svg)](https://codecov.io/gh/EternalDeiwos/keyto)

> A utility for translating cryptographic keys between representations.

Keyto is pronounced 'key-to'.

Full project documentation is available [here](https://eternaldeiwos.github.io/keyto).

## Table of Contents

- [Status](#status)
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Maintainers](#maintainers)
- [Contribute](#contribute)
- [License](#license)

## Status

### RSA

- [x] PKCS1
- [x] PKCS8
- [x] JWK

### ECDSA - secp256k1 (Blockchain Curve)

- [x] PKCS1 (Private Only)
- [x] PKCS8
- [x] JWK
- [x] BLK (Private Key Hex String)

### ECDSA - secp256r1 (P-256)

- [x] PKCS1 (Private Only)
- [x] PKCS8
- [x] JWK

### ECDSA - secp384r1 (P-384)

- [x] PKCS1 (Private Only)
- [x] PKCS8
- [x] JWK

### ECDSA - secp521r1 (P-521)

- [x] PKCS1 (Private Only)
- [x] PKCS8
- [x] JWK

### EDDSA - ed25519

- [x] PKCS8
- [x] JWK

### EDDSA - ed448

- [ ] PKCS8
- [ ] JWK

## Install

```bash
$ npm install @trust/keyto --save
```

## Usage

Translate Private PEM to Public JWK:

```js
const keyto = require('@trust/keyto')

let pemPrivate = getPrivatePemStringSomehow()
let jwk = getPublicJwkSomehow()

// String data can either be passed in directly:
let key = keyto.from(pemPrivate, 'pem').toJwk('public')

// Or can be passed in as an object instead:
let key = keyto.from({ key: pemPrivate }, 'pem').toJwk('public')
assertEqual(jwk, key)
```

Translate Private Hex (Blockchain) Key to PKCS8 Public PEM:

```js
const keyto = require('@trust/keyto')

let blk = getPrivateBlockchainHexStringSomehow()
let pemPublic = getPublicPemSomehow()

let key = keyto.from(blk, 'blk').toString('pem', 'public_pkcs8')
assertEqual(pemPublic, key)
```

## API

### keyto.from(key, format) -> {Key}

**args**:

* key := (String|JWK)
* format := String

**format**:

Format can be any of these: 'pem', 'jwk' or 'blk'.

* format = pem: will parse a PEM encoded string (as per OpenSSL output).
* format = jwk: will parse a JWK object or JSON String
* format = blk: will parse a hex encoded key string as used on various blockchains (limited to secp256k1 keys).

### {Key}.toJwk(selector = 'public') -> {JWK}

**args**:

* selector := String

**selector**:

Selector can be any of these: 'public', 'private'.

* selector := public: will produce a public JWK.
* selector := private: will produce a private JWK.

### {Key}.toString(format = 'pem', selector = 'public') -> {String}

**args**:

* format := String
* selector := String

**format**:

Format can be any of these: 'pem', 'jwk' or 'blk'.

* format = pem: will produce a PEM encoded string (as per OpenSSL output).
* format = jwk: will produce a stringified JWK.
* format = blk: will produce a hex encoded key string as used on various blockchains (limited to secp256k1 keys).

**selector**:

Selector can be any of these: 'public', 'private', 'public_pkcs1', 'public_pkcs8', 'private_pkcs1' or 'private_pkcs8'.

* selector = public: will produce a public key.
* selector = private: will produce a private key.
* selector = public_pkcs1: will produce a public key according to the PKCS1 ASN Schema. Only relevant to DER related encodings.
* selector = public_pkcs8: will produce a public key according to the PKCS8 ASN Schema. Only relevant to DER related encodings.
* selector = private_pkcs1: will produce a private key according to the PKCS1 ASN Schema. Only relevant to DER related encodings.
* selector = private_pkcs8: will produce a private key according to the PKCS8 ASN Schema. Only relevant to DER related encodings.


## Maintainers

[@EternalDeiwos](https://github.com/EternalDeiwos)
[@thelunararmy](https://github.com/thelunararmy)

## Contribute

PRs accepted.

Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

## License

MIT © 2017-2020 Greg Linklater

---
_Source: https://npm.io/package/@trust/keyto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
