Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsontokens

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsontokens - npm Package Compare versions

Comparing version 0.7.3 to 0.7.4

lib/test/cryptoClientTests.js

61

lib/cryptoClients/secp256k1.js

@@ -14,2 +14,8 @@ 'use strict';

var _keyEncoder = require('key-encoder');
var _keyEncoder2 = _interopRequireDefault(_keyEncoder);
var _validator = require('validator');
var _ecdsaSigFormatter = require('./ecdsaSigFormatter');

@@ -19,2 +25,4 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -46,16 +54,27 @@

}, {
key: 'privateKeyToPublicKey',
value: function privateKeyToPublicKey(rawPrivateKey) {
if (typeof rawPrivateKey !== 'string') {
throw 'private key must be a string';
key: 'encodePublicKey',
value: function encodePublicKey(publicKey, originalFormat, destinationFormat) {
return SECP256K1Client.keyEncoder.encodePublic(publicKey, originalFormat, destinationFormat);
}
}, {
key: 'derivePublicKey',
value: function derivePublicKey(privateKey, compressed) {
if (typeof privateKey !== 'string') {
throw Error('private key must be a string');
}
if (rawPrivateKey.length === 66) {
rawPrivateKey = rawPrivateKey.slice(0, 64);
} else if (rawPrivateKey.length === 64) {
if (!(0, _validator.isHexadecimal)(privateKey)) {
throw Error('private key must be a hex string');
}
if (privateKey.length == 66) {
privateKey = privateKey.slice(0, 64);
} else if (privateKey.length <= 64) {
// do nothing
} else {
throw 'private key must be a 64 or 66 character hex string';
throw Error('private key must be 66 characters or less');
}
var keypair = SECP256K1Client.ec.keyFromPrivate(rawPrivateKey);
return keypair.getPublic(true, 'hex');
if (compressed === undefined) {
compressed = true;
}
var keypair = SECP256K1Client.ec.keyFromPrivate(privateKey);
return keypair.getPublic(compressed, 'hex');
}

@@ -65,2 +84,4 @@ }, {

value: function signHash(signingInputHash, rawPrivateKey) {
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'jose';
// make sure the required parameters are provided

@@ -75,5 +96,11 @@ if (!(signingInputHash && rawPrivateKey)) {

var derSignature = new Buffer(signatureObject.toDER());
var joseSignature = (0, _ecdsaSigFormatter.derToJose)(derSignature, 'ES256');
// return the JOSE-formatted signature
return joseSignature;
if (format === 'der') {
return derSignature.toString('hex');
} else if (format === 'jose') {
// return the JOSE-formatted signature
return (0, _ecdsaSigFormatter.derToJose)(derSignature, 'ES256');
} else {
throw Error('Invalid signature format');
}
}

@@ -104,2 +131,8 @@ }, {

SECP256K1Client.algorithmName = 'ES256K';
SECP256K1Client.ec = new _elliptic.ec('secp256k1');
SECP256K1Client.ec = new _elliptic.ec('secp256k1');
SECP256K1Client.keyEncoder = new _keyEncoder2.default({
curveParameters: [1, 3, 132, 0, 10],
privatePEMOptions: { label: 'EC PRIVATE KEY' },
publicPEMOptions: { label: 'PUBLIC KEY' },
curve: SECP256K1Client.ec
});
{
"name": "jsontokens",
"version": "0.7.3",
"version": "0.7.4",
"description": "node.js library for encoding, decoding, and verifying JSON Web Tokens (JWTs)",

@@ -8,3 +8,3 @@ "main": "lib/index.js",

"compile": "babel --presets es2015 src -d lib",
"test": "npm run compile; node lib/test/unitTests.js",
"test": "npm run compile; node lib/test/index.js",
"prepublish": "npm run compile",

@@ -54,4 +54,6 @@ "browserify-test": "npm run compile; node lib/test/browserifyTests.js",

"crypto": "0.0.3",
"elliptic": "^6.3.2"
"elliptic": "^6.3.2",
"key-encoder": "^1.1.6",
"validator": "^7.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc