1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
# Keyto _(@trust/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
### SemVer Notice
This library is currently experimental. Until v1.0.0 is released, breaking changes will only incur a minor version increment.
### 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
- [ ] PKCS1
- [ ] PKCS8
- [ ] JWK
- [ ] BLK
## 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-2018 Greg Linklater
|