Comparing version 1.0.6 to 1.0.7
@@ -5,2 +5,11 @@ # Change Log | ||
## [1.0.7](https://github.com/panva/paseto/compare/v1.0.6...v1.0.7) (2020-07-09) | ||
### Performance Improvements | ||
* omit serializing KeyObjects when Node.js >= 14.5.0 is used ([3d5c148](https://github.com/panva/paseto/commit/3d5c1487df714a0bf62a4fc5f89d280a8c649f09)) | ||
## [1.0.6](https://github.com/panva/paseto/compare/v1.0.5...v1.0.6) (2020-04-21) | ||
@@ -7,0 +16,0 @@ |
const { parentPort, Worker, isMainThread } = require('worker_threads') | ||
const crypto = require('crypto') | ||
const [major, minor] = process.version.substr(1).split('.').map((x) => parseInt(x, 10)) | ||
const supportsKeyObjectInPostMessage = major > 14 || (major === 14 && minor >= 5) | ||
if (isMainThread) { | ||
@@ -37,22 +40,24 @@ const tasks = new Map() | ||
let key | ||
if (!supportsKeyObjectInPostMessage) { | ||
let key | ||
let keyObject = args[2] | ||
let keyObject = args[2] | ||
if (keyObject instanceof crypto.KeyObject) { | ||
key = { | ||
key: keyObject.export.apply(keyObject, exportArgs[keyObject.type]), | ||
...exportArgs[keyObject.type][0] | ||
if (keyObject instanceof crypto.KeyObject) { | ||
key = { | ||
key: keyObject.export.apply(keyObject, exportArgs[keyObject.type]), | ||
...exportArgs[keyObject.type][0] | ||
} | ||
} else if (Buffer.isBuffer(keyObject)) { | ||
key = keyObject | ||
} else { | ||
key = keyObject | ||
keyObject = key.key | ||
key.key = keyObject.export.apply(keyObject, exportArgs[keyObject.type]) | ||
Object.assign(key, exportArgs[keyObject.type][0]) | ||
} | ||
} else if (Buffer.isBuffer(keyObject)) { | ||
key = keyObject | ||
} else { | ||
key = keyObject | ||
keyObject = key.key | ||
key.key = keyObject.export.apply(keyObject, exportArgs[keyObject.type]) | ||
Object.assign(key, exportArgs[keyObject.type][0]) | ||
args[2] = key | ||
} | ||
args[2] = key | ||
worker.ref() | ||
@@ -70,3 +75,3 @@ worker.postMessage({ id, method, args }) | ||
} | ||
/* c8 ignore next 58 */ | ||
/* c8 ignore next 114 */ | ||
} else { | ||
@@ -141,8 +146,12 @@ const sodium = require('libsodium-wrappers') | ||
}, | ||
verify (alg, payload, { key: ab, ...key }, signature) { | ||
key.key = Buffer.from(ab) | ||
verify (alg, payload, key, signature) { | ||
if (!supportsKeyObjectInPostMessage) { | ||
key.key = Buffer.from(key.key) | ||
} | ||
return crypto.verify(alg, payload, key, signature) | ||
}, | ||
sign (alg, payload, { key: ab, ...key }) { | ||
key.key = Buffer.from(ab) | ||
sign (alg, payload, key) { | ||
if (!supportsKeyObjectInPostMessage) { | ||
key.key = Buffer.from(key.key) | ||
} | ||
return crypto.sign(alg, payload, key) | ||
@@ -149,0 +158,0 @@ }, |
{ | ||
"name": "paseto", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "PASETO for Node.js with minimal dependencies", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
56398
1312