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

ec-key

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ec-key - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

ec-key.d.ts

21

package.json
{
"name": "ec-key",
"description": "Wrapper around an Elliptic Curve private or public keys",
"version": "0.0.4",
"version": "0.0.5",
"main": "src/ec-key.js",
"types": "ec-key.d.ts",
"author": "Pier Fumagalli <pier@usrz.com>",

@@ -18,3 +19,3 @@ "homepage": "https://github.com/usrz/ec-key",

"scripts": {
"test": "gulp test"
"test": "mocha"
},

@@ -39,12 +40,16 @@ "keywords": [

"devDependencies": {
"chai": "^4.2.0",
"gulp": "^4.0.2",
"gulp-mocha": "^6.0.0"
"chai": "<5",
"mocha": "^10.6.0"
},
"dependencies": {
"asn1.js": "^5.2.0"
"asn1.js": "^5.4.1"
},
"engines": {
"node": ">=6.0.0"
}
"node": ">=10.0.0"
},
"files": [
"src/ec-key.js",
"ec-key.d.ts",
"*.md"
]
}

@@ -5,4 +5,7 @@ 'use strict';

const asn = require('asn1.js');
const util = require('util');
function isString(value) {
return typeof value === 'string'
}
/* ========================================================================== *

@@ -172,15 +175,15 @@ * From RFC-4492 (Appendix A) Equivalent Curves (Informative) *

function parsePem(pem) {
if (! util.isString(pem)) throw new TypeError("PEM must be a string");
if (! isString(pem)) throw new TypeError("PEM must be a string");
var match = null;
if (match = pem.match(pemRfc5915RE)) {
var buffer = new Buffer(match[1].replace(/[\s-]/mg, ''), 'base64');
var buffer = Buffer.from(match[1].replace(/[\s-]/mg, ''), 'base64');
return parseRfc5915(buffer);
} else if (match = pem.match(pemPkcs8RE)) {
var buffer = new Buffer(match[1].replace(/[\s-]/mg, ''), 'base64');
var buffer = Buffer.from(match[1].replace(/[\s-]/mg, ''), 'base64');
return parsePkcs8(buffer);
} else if (match = pem.match(pemSpkiRE)) {
var buffer = new Buffer(match[1].replace(/[\s-]/mg, ''), 'base64');
var buffer = Buffer.from(match[1].replace(/[\s-]/mg, ''), 'base64');
return parseSpki(buffer);

@@ -206,3 +209,3 @@

// BUFFER KEYS: either in "pkcs8" or "spki" format (base64) or "pem" (ascii)
if (util.isBuffer(key)) {
if (Buffer.isBuffer(key)) {

@@ -237,3 +240,3 @@ if (format == 'pem') {

// STRING KEYS: base64 all the time, but also allowed in PEM
else if (util.isString(key)) {
else if (isString(key)) {

@@ -248,3 +251,3 @@ if (format == 'pem') {

} else if ((format == "pkcs8") || (format == "rfc5208")) {
var k = parsePkcs8(new Buffer(key, 'base64'));
var k = parsePkcs8(Buffer.from(key, 'base64'));
curve = k.c;

@@ -257,3 +260,3 @@ x = k.x;

} else if ((format == "spki") || (format == "rfc5280")) {
var k = parseSpki(new Buffer(key, 'base64'));
var k = parseSpki(Buffer.from(key, 'base64'));
curve = k.c;

@@ -271,8 +274,8 @@ x = k.x;

// private key and "(publicKey|x,y)" always required (both for priv and pub)
else if (util.isObject(key)) {
else if (key && (typeof key === 'object')) {
// Curves
if (util.isString(key.curve)) {
if (isString(key.curve)) {
curve = key.curve;
} else if (util.isString(key.crv)) {
} else if (isString(key.crv)) {
curve = curves[key.crv] || key.crv;

@@ -282,14 +285,14 @@ }

// Private key or "d"
if (util.isBuffer(key.privateKey)) {
if (Buffer.isBuffer(key.privateKey)) {
d = key.privateKey;
} else if (util.isString(key.privateKey)) {
d = new Buffer(key.privateKey, 'base64');
} else if (util.isBuffer(key.d)) {
} else if (isString(key.privateKey)) {
d = Buffer.from(key.privateKey, 'base64');
} else if (Buffer.isBuffer(key.d)) {
d = key.d;
} else if (util.isString(key.d)) {
d = new Buffer(key.d, 'base64');
} else if (isString(key.d)) {
d = Buffer.from(key.d, 'base64');
}
// Public key, or x and y
if (util.isBuffer(key.publicKey)) {
if (Buffer.isBuffer(key.publicKey)) {
var k = parsePublicKeyBuffer(curve, key.publicKey);

@@ -299,4 +302,4 @@ x = k.x;

} else if (util.isString(key.publicKey)) {
var k = parsePublicKeyBuffer(curve, new Buffer(key.publicKey, 'base64'));
} else if (isString(key.publicKey)) {
var k = parsePublicKeyBuffer(curve, Buffer.from(key.publicKey, 'base64'));
x = k.x;

@@ -307,12 +310,12 @@ y = k.y;

// Need to get x and y
if (util.isBuffer(key.x)) {
if (Buffer.isBuffer(key.x)) {
x = key.x;
} else if (util.isString(key.x)) {
x = new Buffer(key.x, 'base64');
} else if (isString(key.x)) {
x = Buffer.from(key.x, 'base64');
}
if (util.isBuffer(key.y)) {
if (Buffer.isBuffer(key.y)) {
y = key.y;
} else if (util.isString(key.y)) {
y = new Buffer(key.y, 'base64');
} else if (isString(key.y)) {
y = Buffer.from(key.y, 'base64');
}

@@ -351,3 +354,3 @@ }

get: function() {
return new Buffer(x)
return Buffer.from(x)
}

@@ -359,3 +362,3 @@ },

get: function() {
return new Buffer(y)
return Buffer.from(y)
}

@@ -374,3 +377,3 @@ },

get: function() {
return Buffer.concat([new Buffer([0x04]), x, y]);
return Buffer.concat([Buffer.from([0x04]), x, y]);
}

@@ -385,3 +388,3 @@ }

get: function() {
return new Buffer(d)
return Buffer.from(d)
}

@@ -473,3 +476,3 @@ });

// Simple PEM conversion, wrapping the string in the buffer
if (format == 'pem') return new Buffer(this.toString('pem'), 'ascii');
if (format == 'pem') return Buffer.from(this.toString('pem'), 'ascii');

@@ -589,3 +592,3 @@ if (this.isPrivateECKey) {

var remaining = bytes - d.length;
d = Buffer.concat([new Buffer(remaining).fill(0), d]);
d = Buffer.concat([Buffer.alloc(remaining).fill(0), d]);
}

@@ -604,2 +607,1 @@ jwk.d = urlsafe(d);

exports = module.exports = ECKey;
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