Comparing version 3.5.1 to 3.5.2
@@ -5,2 +5,10 @@ # Changelog | ||
## [3.5.2](https://github.com/panva/jose/compare/v3.5.1...v3.5.2) (2021-01-18) | ||
### Performance | ||
* use 'base64url' encoding when available in Node.js runtime ([808f06c](https://github.com/panva/jose/commit/808f06cd08b10cf53343afb35802cc6e5b95ea20)) | ||
* use KeyObject.prototype asymmetricKeyDetails when available ([ad88ee2](https://github.com/panva/jose/commit/ad88ee2cd5bcaee3c3e5ec79735c8172ae2725be)) | ||
## [3.5.1](https://github.com/panva/jose/compare/v3.5.0...v3.5.1) (2021-01-10) | ||
@@ -7,0 +15,0 @@ |
@@ -5,4 +5,4 @@ "use strict"; | ||
const buffer_utils_js_1 = require("../lib/buffer_utils.js"); | ||
exports.encode = (input) => Buffer.from(input).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); | ||
exports.decode = (input) => { | ||
let encodeImpl; | ||
function normalize(input) { | ||
let encoded = input; | ||
@@ -12,3 +12,11 @@ if (encoded instanceof Uint8Array) { | ||
} | ||
return new Uint8Array(Buffer.from(encoded, 'base64')); | ||
}; | ||
return encoded; | ||
} | ||
if (Buffer.isEncoding('base64url')) { | ||
encodeImpl = (input) => Buffer.from(input).toString('base64url'); | ||
} | ||
else { | ||
encodeImpl = (input) => Buffer.from(input).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); | ||
} | ||
exports.encode = encodeImpl; | ||
exports.decode = (input) => Buffer.from(normalize(input), 'base64'); |
@@ -34,6 +34,7 @@ "use strict"; | ||
const getModulusLength = (key) => { | ||
var _a, _b; | ||
if (exports.weakMap.has(key)) { | ||
return exports.weakMap.get(key); | ||
} | ||
const modulusLength = (getLengthOfSeqIndex(key.export({ format: 'der', type: 'pkcs1' }), key.type === 'private' ? 1 : 0) - | ||
const modulusLength = (_b = (_a = key.asymmetricKeyDetails) === null || _a === void 0 ? void 0 : _a.modulusLength) !== null && _b !== void 0 ? _b : (getLengthOfSeqIndex(key.export({ format: 'der', type: 'pkcs1' }), key.type === 'private' ? 1 : 0) - | ||
1) << | ||
@@ -40,0 +41,0 @@ 3; |
@@ -11,3 +11,18 @@ "use strict"; | ||
exports.weakMap = new WeakMap(); | ||
const getNamedCurve = (key) => { | ||
const namedCurveToJOSE = (namedCurve) => { | ||
switch (namedCurve) { | ||
case 'prime256v1': | ||
return 'P-256'; | ||
case 'secp384r1': | ||
return 'P-384'; | ||
case 'secp521r1': | ||
return 'P-521'; | ||
case 'secp256k1': | ||
return namedCurve; | ||
default: | ||
throw new errors_js_1.JOSENotSupported('unsupported curve for this operation'); | ||
} | ||
}; | ||
const getNamedCurve = (key, raw) => { | ||
var _a; | ||
if (key.type === 'secret') { | ||
@@ -27,27 +42,27 @@ throw new TypeError('only "private" or "public" key objects can be used for this operation'); | ||
} | ||
if (key.type === 'private') { | ||
const curve = getNamedCurve(crypto_1.createPublicKey(key)); | ||
exports.weakMap.set(key, curve); | ||
return curve; | ||
let namedCurve = (_a = key.asymmetricKeyDetails) === null || _a === void 0 ? void 0 : _a.namedCurve; | ||
if (!namedCurve && key.type === 'private') { | ||
namedCurve = getNamedCurve(crypto_1.createPublicKey(key), true); | ||
} | ||
const buf = key.export({ format: 'der', type: 'spki' }); | ||
const i = buf[1] < 128 ? 14 : 15; | ||
const len = buf[i]; | ||
const curveOid = buf.slice(i + 1, i + 1 + len); | ||
let curve; | ||
if (curveOid.equals(p256)) { | ||
curve = 'P-256'; | ||
else if (!namedCurve) { | ||
const buf = key.export({ format: 'der', type: 'spki' }); | ||
const i = buf[1] < 128 ? 14 : 15; | ||
const len = buf[i]; | ||
const curveOid = buf.slice(i + 1, i + 1 + len); | ||
if (curveOid.equals(p256)) { | ||
namedCurve = 'prime256v1'; | ||
} | ||
else if (curveOid.equals(p384)) { | ||
namedCurve = 'secp384r1'; | ||
} | ||
else if (curveOid.equals(p521)) { | ||
namedCurve = 'secp521r1'; | ||
} | ||
else if (curveOid.equals(secp256k1)) { | ||
namedCurve = 'secp256k1'; | ||
} | ||
} | ||
else if (curveOid.equals(p384)) { | ||
curve = 'P-384'; | ||
} | ||
else if (curveOid.equals(p521)) { | ||
curve = 'P-521'; | ||
} | ||
else if (curveOid.equals(secp256k1)) { | ||
curve = 'secp256k1'; | ||
} | ||
else { | ||
throw new errors_js_1.JOSENotSupported('unsupported curve for this operation'); | ||
} | ||
if (raw) | ||
return namedCurve; | ||
const curve = namedCurveToJOSE(namedCurve); | ||
exports.weakMap.set(key, curve); | ||
@@ -54,0 +69,0 @@ return curve; |
import { decoder } from '../lib/buffer_utils.js'; | ||
export const encode = (input) => Buffer.from(input).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); | ||
export const decode = (input) => { | ||
let encodeImpl; | ||
function normalize(input) { | ||
let encoded = input; | ||
@@ -8,3 +8,11 @@ if (encoded instanceof Uint8Array) { | ||
} | ||
return new Uint8Array(Buffer.from(encoded, 'base64')); | ||
}; | ||
return encoded; | ||
} | ||
if (Buffer.isEncoding('base64url')) { | ||
encodeImpl = (input) => Buffer.from(input).toString('base64url'); | ||
} | ||
else { | ||
encodeImpl = (input) => Buffer.from(input).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); | ||
} | ||
export const encode = encodeImpl; | ||
export const decode = (input) => Buffer.from(normalize(input), 'base64'); |
@@ -31,6 +31,7 @@ export const weakMap = new WeakMap(); | ||
const getModulusLength = (key) => { | ||
var _a, _b; | ||
if (weakMap.has(key)) { | ||
return weakMap.get(key); | ||
} | ||
const modulusLength = (getLengthOfSeqIndex(key.export({ format: 'der', type: 'pkcs1' }), key.type === 'private' ? 1 : 0) - | ||
const modulusLength = (_b = (_a = key.asymmetricKeyDetails) === null || _a === void 0 ? void 0 : _a.modulusLength) !== null && _b !== void 0 ? _b : (getLengthOfSeqIndex(key.export({ format: 'der', type: 'pkcs1' }), key.type === 'private' ? 1 : 0) - | ||
1) << | ||
@@ -37,0 +38,0 @@ 3; |
@@ -8,3 +8,18 @@ import { createPublicKey } from 'crypto'; | ||
export const weakMap = new WeakMap(); | ||
const getNamedCurve = (key) => { | ||
const namedCurveToJOSE = (namedCurve) => { | ||
switch (namedCurve) { | ||
case 'prime256v1': | ||
return 'P-256'; | ||
case 'secp384r1': | ||
return 'P-384'; | ||
case 'secp521r1': | ||
return 'P-521'; | ||
case 'secp256k1': | ||
return namedCurve; | ||
default: | ||
throw new JOSENotSupported('unsupported curve for this operation'); | ||
} | ||
}; | ||
const getNamedCurve = (key, raw) => { | ||
var _a; | ||
if (key.type === 'secret') { | ||
@@ -24,27 +39,27 @@ throw new TypeError('only "private" or "public" key objects can be used for this operation'); | ||
} | ||
if (key.type === 'private') { | ||
const curve = getNamedCurve(createPublicKey(key)); | ||
weakMap.set(key, curve); | ||
return curve; | ||
let namedCurve = (_a = key.asymmetricKeyDetails) === null || _a === void 0 ? void 0 : _a.namedCurve; | ||
if (!namedCurve && key.type === 'private') { | ||
namedCurve = getNamedCurve(createPublicKey(key), true); | ||
} | ||
const buf = key.export({ format: 'der', type: 'spki' }); | ||
const i = buf[1] < 128 ? 14 : 15; | ||
const len = buf[i]; | ||
const curveOid = buf.slice(i + 1, i + 1 + len); | ||
let curve; | ||
if (curveOid.equals(p256)) { | ||
curve = 'P-256'; | ||
else if (!namedCurve) { | ||
const buf = key.export({ format: 'der', type: 'spki' }); | ||
const i = buf[1] < 128 ? 14 : 15; | ||
const len = buf[i]; | ||
const curveOid = buf.slice(i + 1, i + 1 + len); | ||
if (curveOid.equals(p256)) { | ||
namedCurve = 'prime256v1'; | ||
} | ||
else if (curveOid.equals(p384)) { | ||
namedCurve = 'secp384r1'; | ||
} | ||
else if (curveOid.equals(p521)) { | ||
namedCurve = 'secp521r1'; | ||
} | ||
else if (curveOid.equals(secp256k1)) { | ||
namedCurve = 'secp256k1'; | ||
} | ||
} | ||
else if (curveOid.equals(p384)) { | ||
curve = 'P-384'; | ||
} | ||
else if (curveOid.equals(p521)) { | ||
curve = 'P-521'; | ||
} | ||
else if (curveOid.equals(secp256k1)) { | ||
curve = 'secp256k1'; | ||
} | ||
else { | ||
throw new JOSENotSupported('unsupported curve for this operation'); | ||
} | ||
if (raw) | ||
return namedCurve; | ||
const curve = namedCurveToJOSE(namedCurve); | ||
weakMap.set(key, curve); | ||
@@ -51,0 +66,0 @@ return curve; |
@@ -5,4 +5,4 @@ "use strict"; | ||
const buffer_utils_js_1 = require("../lib/buffer_utils.js"); | ||
exports.encode = (input) => Buffer.from(input).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); | ||
exports.decode = (input) => { | ||
let encodeImpl; | ||
function normalize(input) { | ||
let encoded = input; | ||
@@ -12,3 +12,11 @@ if (encoded instanceof Uint8Array) { | ||
} | ||
return new Uint8Array(Buffer.from(encoded, 'base64')); | ||
}; | ||
return encoded; | ||
} | ||
if (Buffer.isEncoding('base64url')) { | ||
encodeImpl = (input) => Buffer.from(input).toString('base64url'); | ||
} | ||
else { | ||
encodeImpl = (input) => Buffer.from(input).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); | ||
} | ||
exports.encode = encodeImpl; | ||
exports.decode = (input) => Buffer.from(normalize(input), 'base64'); |
import { decoder } from '../lib/buffer_utils.js'; | ||
export const encode = (input) => Buffer.from(input).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); | ||
export const decode = (input) => { | ||
let encodeImpl; | ||
function normalize(input) { | ||
let encoded = input; | ||
@@ -8,3 +8,11 @@ if (encoded instanceof Uint8Array) { | ||
} | ||
return new Uint8Array(Buffer.from(encoded, 'base64')); | ||
}; | ||
return encoded; | ||
} | ||
if (Buffer.isEncoding('base64url')) { | ||
encodeImpl = (input) => Buffer.from(input).toString('base64url'); | ||
} | ||
else { | ||
encodeImpl = (input) => Buffer.from(input).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_'); | ||
} | ||
export const encode = encodeImpl; | ||
export const decode = (input) => Buffer.from(normalize(input), 'base64'); |
{ | ||
"name": "jose", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"description": "Universal 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK with no dependencies", | ||
@@ -416,3 +416,4 @@ "keywords": [ | ||
"type": "perf", | ||
"hidden": true | ||
"section": "Performance", | ||
"hidden": false | ||
}, | ||
@@ -419,0 +420,0 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
679444
15978