new Key(key, options)
A high level class for accepting and processing keys
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
key |
Object | |||||||||||||||||||||||||
options |
Object |
Properties
|
Throws:
-
-
If key is omitted
-
-
-
If required options are omitted
-
Methods
(static) from(key, format) → {Key}
Import a key
Parameters:
Name | Type | Description |
---|---|---|
key |
JWK | String | |
format |
SerializableFormat |
Throws:
-
-
If key is omitted.
-
-
-
If format is omitted.
-
Returns:
- Type
- Key
Examples
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)
const keyto = require('@trust/keyto')
let blk = getPrivateBlockchainHexStringSomehow()
let pemPublic = getPublicPemSomehow()
let key = keyto.from(blk, 'blk').toString('pem', 'public_pkcs8')
assertEqual(pemPublic, key)
toJwk(selector) → {JWK}
Convert a key to JWK.
Parameters:
Name | Type | Description |
---|---|---|
selector |
KeySelector |
Returns:
- Type
- JWK
toString(formatopt, selectoropt) → {String}
Serialize a key to the specified format
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
format |
SerializableFormat |
<optional> |
pem | |
selector |
KeySelector | PEMKeySelector |
<optional> |
public_pkcs8 |
Returns:
- Type
- String