Skip to content

Commit

Permalink
refactor: removed deprecated methods and utilities
Browse files Browse the repository at this point in the history
BREAKING CHANGE: deprecated method `JWK.importKey` was removed
BREAKING CHANGE: deprecated method `JWKS.KeyStore.fromJWKS` was removed
BREAKING CHANGE: the use of unregistered curve name P-256K for secp256k1
was removed
  • Loading branch information
panva committed Sep 8, 2020
1 parent 70bd4ae commit 6c35c51
Show file tree
Hide file tree
Showing 18 changed files with 7 additions and 398 deletions.
6 changes: 0 additions & 6 deletions P-256K/index.js

This file was deleted.

4 changes: 1 addition & 3 deletions lib/help/asn1/oids.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { name: secp256k1 } = require('../../jwk/key/secp256k1_crv')

const oids = {
'1 2 840 10045 3 1 7': 'P-256',
'1 3 132 0 10': secp256k1,
'1 3 132 0 10': 'secp256k1',
'1 3 132 0 34': 'P-384',
'1 3 132 0 35': 'P-521',
'1 2 840 10045 2 1': 'ecPublicKey',
Expand Down
3 changes: 1 addition & 2 deletions lib/jwa/ecdh/dir.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { improvedDH } = require('../../help/runtime_support')
const { KEYLENGTHS } = require('../../registry')
const { generateSync } = require('../../jwk/generate')
const { name: secp256k1 } = require('../../jwk/key/secp256k1_crv')

const derive = require('./derive')

Expand All @@ -24,7 +23,7 @@ const unwrapKey = (key, payload, header) => {
module.exports = (JWA, JWK) => {
JWA.keyManagementEncrypt.set('ECDH-ES', wrapKey)
JWA.keyManagementDecrypt.set('ECDH-ES', unwrapKey)
JWK.EC.deriveKey['ECDH-ES'] = key => (key.use === 'enc' || key.use === undefined) && key.crv !== secp256k1
JWK.EC.deriveKey['ECDH-ES'] = key => (key.use === 'enc' || key.use === undefined) && key.crv !== 'secp256k1'

if (improvedDH) {
JWK.OKP.deriveKey['ECDH-ES'] = key => (key.use === 'enc' || key.use === undefined) && key.keyObject.asymmetricKeyType.startsWith('x')
Expand Down
3 changes: 1 addition & 2 deletions lib/jwa/ecdh/kw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { improvedDH } = require('../../help/runtime_support')
const { KEYOBJECT } = require('../../help/consts')
const { generateSync } = require('../../jwk/generate')
const { name: secp256k1 } = require('../../jwk/key/secp256k1_crv')
const { ECDH_DERIVE_LENGTHS } = require('../../registry')

const derive = require('./derive')
Expand Down Expand Up @@ -36,7 +35,7 @@ module.exports = (JWA, JWK) => {
if (kwWrap && kwUnwrap) {
JWA.keyManagementEncrypt.set(jwaAlg, wrapKey.bind(undefined, kwWrap, derive.bind(undefined, jwaAlg, keylen)))
JWA.keyManagementDecrypt.set(jwaAlg, unwrapKey.bind(undefined, kwUnwrap, derive.bind(undefined, jwaAlg, keylen)))
JWK.EC.deriveKey[jwaAlg] = key => (key.use === 'enc' || key.use === undefined) && key.crv !== secp256k1
JWK.EC.deriveKey[jwaAlg] = key => (key.use === 'enc' || key.use === undefined) && key.crv !== 'secp256k1'

if (improvedDH) {
JWK.OKP.deriveKey[jwaAlg] = key => (key.use === 'enc' || key.use === undefined) && key.keyObject.asymmetricKeyType.startsWith('x')
Expand Down
3 changes: 1 addition & 2 deletions lib/jwa/ecdsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { KEYOBJECT } = require('../help/consts')
const resolveNodeAlg = require('../help/node_alg')
const { asInput } = require('../help/key_object')
const { dsaEncodingSupported } = require('../help/runtime_support')
const { name: secp256k1 } = require('../jwk/key/secp256k1_crv')

let sign, verify

Expand Down Expand Up @@ -40,7 +39,7 @@ const crvToAlg = (crv) => {
switch (crv) {
case 'P-256':
return 'ES256'
case secp256k1:
case 'secp256k1':
return 'ES256K'
case 'P-384':
return 'ES384'
Expand Down
6 changes: 0 additions & 6 deletions lib/jwk/import.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { deprecate } = require('util')

const { createPublicKey, createPrivateKey, createSecretKey, KeyObject } = require('../help/key_object')
const base64url = require('../help/base64url')
const isObject = require('../help/is_object')
Expand Down Expand Up @@ -134,7 +132,3 @@ const asKey = (key, parameters, { calculateMissingRSAPrimes = false } = {}) => {
}

module.exports = asKey
Object.defineProperty(asKey, 'deprecated', {
value: deprecate((key, parameters) => { return asKey(key, parameters, { calculateMissingRSAPrimes: true }) }, 'JWK.importKey() is deprecated, use JWK.asKey() instead'),
enumerable: false
})
6 changes: 0 additions & 6 deletions lib/jwk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@ module.exports = {
EmbeddedJWK,
EmbeddedX5C
}

/* deprecated */
Object.defineProperty(module.exports, 'importKey', {
value: importKey.deprecated,
enumerable: false
})
9 changes: 0 additions & 9 deletions lib/jwk/key/ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { keyObjectSupported } = require('../../help/runtime_support')
const { createPublicKey, createPrivateKey } = require('../../help/key_object')

const errors = require('../../errors')
const { name: secp256k1 } = require('./secp256k1_crv')

const Key = require('./base')

Expand Down Expand Up @@ -62,10 +61,6 @@ class ECKey extends Key {
throw new errors.JOSENotSupported(`unsupported EC key curve: ${crv}`)
}

if (crv === secp256k1 && crv !== 'secp256k1') {
crv = 'secp256k1'
}

let privateKey, publicKey

if (keyObjectSupported) {
Expand All @@ -91,10 +86,6 @@ class ECKey extends Key {
throw new errors.JOSENotSupported(`unsupported EC key curve: ${crv}`)
}

if (crv === secp256k1 && crv !== 'secp256k1') {
crv = 'secp256k1'
}

let privateKey, publicKey

if (keyObjectSupported) {
Expand Down
13 changes: 0 additions & 13 deletions lib/jwk/key/secp256k1_crv.js

This file was deleted.

7 changes: 1 addition & 6 deletions lib/jwks/keystore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { deprecate, inspect } = require('util')
const { inspect } = require('util')

const isObject = require('../help/is_object')
const { generate, generateSync } = require('../jwk/generate')
Expand Down Expand Up @@ -177,9 +177,4 @@ function asKeyStore (jwks, { ignoreErrors = false, calculateMissingRSAPrimes = f
return new KeyStore(...keys)
}

Object.defineProperty(KeyStore, 'fromJWKS', {
value: deprecate(jwks => asKeyStore(jwks, { calculateMissingRSAPrimes: true }), 'JWKS.KeyStore.fromJWKS() is deprecated, use JWKS.asKeyStore() instead'),
enumerable: false
})

module.exports = { KeyStore, asKeyStore }
4 changes: 1 addition & 3 deletions lib/registry/ec_curves.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const { getCurves } = require('crypto')

const { name: secp256k1 } = require('../jwk/key/secp256k1_crv')

const curves = new Set()

if (getCurves().includes('prime256v1')) {
curves.add('P-256')
}

if (getCurves().includes('secp256k1')) {
curves.add(secp256k1)
curves.add('secp256k1')
}

if (getCurves().includes('secp384r1')) {
Expand Down
13 changes: 0 additions & 13 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ module.exports.JWK = {
d: 'xTAmXNRL8ksBlr-F3yXDrUdRDn1gyIvY_PC2e_iUK7c'
},

'P-256K': {
kty: 'EC',
crv: 'P-256K',
x: 'VRaLqtMjg_JRaDzkbfit7zonkOGDZ42qbZyljhqsg3U',
y: '5qgTxoRAf0hJxcphVg1NE9r0Xv-HHZyVIJxEbo6SAsQ',
d: 'xTAmXNRL8ksBlr-F3yXDrUdRDn1gyIvY_PC2e_iUK7c'
},

'P-384': {
kty: 'EC',
crv: 'P-384',
Expand Down Expand Up @@ -124,11 +116,6 @@ module.exports.PEM = {
private: readFileSync(join(__dirname, 'secp256k1.key')),
public: readFileSync(join(__dirname, 'secp256k1.pem'))
},
'P-256K': {
testEnc: false,
private: readFileSync(join(__dirname, 'secp256k1.key')),
public: readFileSync(join(__dirname, 'secp256k1.pem'))
},
'P-384': {
private: readFileSync(join(__dirname, 'P-384.key')),
public: readFileSync(join(__dirname, 'P-384.pem'))
Expand Down
29 changes: 0 additions & 29 deletions test/help/P-256K.key_utils.test.js

This file was deleted.

Loading

0 comments on commit 6c35c51

Please sign in to comment.