@@ -8,11 +8,84 @@ enable the direct use of JWK formatted keys with other node modules like
88
99## Usage
1010
11- _ will come_
11+ The module offers the classes ` JWK ` and ` JWKSet ` to work with JWK encoded keys
12+ or key sets.
1213
13- ## Documentation
14+ You can instantiate either of the objects from a stringified JSON or an object.
15+ ```
16+ const njwk = require('node-jwk');
17+
18+ const myKey = njwk.JWK.fromJSON(myJSONString);
19+ const myKeySet = njwk.JWKSet.fromObject(myKeySet);
20+ ```
21+
22+ ### Keysets (JWKSet)
23+
24+ Keysets can contain a number of different keys which are unique by their _ kid_ .
25+
26+ #### JWKSet.findKeyById(kid)
27+
28+ The JWKSet class offers the ` findKeyById ` method that will let you grab a key
29+ by its id and returns it wrapped in a JWK object.
30+
31+ #### JWKSet.findKeysByUse(use)
32+
33+ There might be cases where you want to use a key designated for encoding/decoding or
34+ signing/verification. With ` findKeysByUse ` you can retrieve an array of all
35+ contained keys that match the use given.
36+
37+ But remember that the use property is specified as OPTIONAL, so is the content of
38+ it. Be prepared that keys you get from 3rd party could miss it.
39+
40+ #### JWKSet.keys
41+
42+ Returns all keys as an array of JWK objects.
43+
44+ #### JWKSet.fromObject(object) JWKSet.fromJSON(string)
45+
46+ Factory to instantiate JWKSet objects. This method will throw on invalid
47+ keysets (the keyset structure or invalid JSON). According to the specification
48+ (RFC) invalid keys contained in a valid set are ignored.
49+
50+
51+ ### Keys (JWK)
52+
53+ All standard JWK properties are exposed by the JWK object. Be aware that per
54+ specification all properties but ` kty ` and ` kid ` are optional. Here's a list:
55+ ```
56+ kid
57+ kty
58+ use
59+ key_ops
60+ alg
61+ ```
62+
63+ #### JWK.key
64+
65+ Through the key property you can access the key algorithm specific functionality.
66+
67+ ##### JWK.key.hasPrivateKey
68+
69+ Returns true if the key contains a private key part.
70+
71+ ##### JWK.key.toPublicKeyPEM() => String
72+
73+ Generates a PEM that contains the public key of the JWK. This can be used
74+ directly as key in OpenSSL or other node modules and works for EC as well as
75+ RSA keys.
76+
77+ ##### JWK.key.toPrivateKeyPEM() => String
78+
79+ Generates a PEM that contains the private key of the JWK. This can be used
80+ directly as key in OpenSSL or other node modules and works for EC as well as
81+ RSA keys.
82+
83+ #### JWK.fromObject(object) JWK.fromJSON(string)
84+
85+ Factory to instantiate JWK objects. This method will throw on invalid
86+ keys (the keyset structure or invalid JSON).
87+ Normally you should use keysets to manage your keys instead of single keys.
1488
15- _ will come_
1689
1790## Examples
1891
0 commit comments