File tree 3 files changed +40
-0
lines changed
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -238,6 +238,17 @@ keystore.remove(key);
238
238
239
239
### Importing and Exporting a Single Key ###
240
240
241
+ To create a single "stand alone" key:
242
+
243
+ ``` javascript
244
+ jose .JWK .createKey (" oct" , 256 , { alg: " A256GCM" }).
245
+ then (function (result ) {
246
+ // {result} is a jose.JWK.Key
247
+ // {result.keystore} is a unique jose.JWK.KeyStore
248
+ });
249
+ ```
250
+
251
+
241
252
To import a single Key:
242
253
243
254
``` javascript
Original file line number Diff line number Diff line change @@ -656,6 +656,23 @@ JWKStore.isKey = function(obj) {
656
656
return true ;
657
657
} ;
658
658
659
+ /**
660
+ * Creates a new key with the given properties. This method is a convenience
661
+ * to calling `JWK.createKeyStore()` then `generate()` on the returned keystore.
662
+ *
663
+ * @param {String } kty The type of generated key
664
+ * @param {String|Number } [size] The size of the generated key
665
+ * @param {Object } [props] Additional properties to apply to the generated
666
+ * key.
667
+ * @returns {Promise } The promise for the generated Key
668
+ * @throws {Error } If {kty} is not supported
669
+ * @see JWKStore#generate
670
+ */
671
+ JWKStore . createKey = function ( kty , size , props ) {
672
+ var ks = JWKStore . createKeyStore ( ) ;
673
+ return ks . generate ( kty , size , props ) ;
674
+ }
675
+
659
676
/**
660
677
* Coerces the given object into a Key. If {key} is an instance of JWK.Key,
661
678
* it is returned directly. Otherwise, this method first creates a new
Original file line number Diff line number Diff line change @@ -495,6 +495,18 @@ describe("jwk/keystore", function() {
495
495
assert . equal ( JWK . store . KeyStore . isKey ( ) , false ) ;
496
496
} ) ;
497
497
} ) ;
498
+ describe ( "KeyStore.createKey" , function ( ) {
499
+ it ( "creates a new Key" , function ( ) {
500
+ var p ;
501
+ p = JWK . store . KeyStore . createKey ( "oct" , 256 ) ;
502
+ p = p . then ( function ( result ) {
503
+ assert . ok ( JWK . store . KeyStore . isKey ( result ) ) ;
504
+ assert . strictEqual ( result . kty , "oct" ) ;
505
+ assert . strictEqual ( result . length , 256 ) ;
506
+ } ) ;
507
+ return p ;
508
+ } ) ;
509
+ } ) ;
498
510
describe ( "KeyStore.asKey" , function ( ) {
499
511
var props = {
500
512
kty : "oct" ,
You can’t perform that action at this time.
0 commit comments