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

ec-key

Package Overview
Dependencies
Maintainers
1
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.1 to 0.0.2

test/support/secp256k1.priv-openssl.pem

2

package.json
{
"name": "ec-key",
"description": "Wrapper around an Elliptic Curve private or public keys",
"version": "0.0.1",
"version": "0.0.2",
"main": "src/ec-key.js",

@@ -6,0 +6,0 @@

@@ -31,7 +31,8 @@ Elliptic Curve Keys

| OpenSSL Curve Name | RFC-7518 (6.2.1.1) | ASN.1 OID |
| ------------------ | ------------------ | ------------------- |
| `prime256v1` | `P-256` | 1.2.840.10045.3.1.7 |
| `secp384r1` | `P-384` | 1.3.132.0.34 |
| `secp521r1` | `P-521` | 1.3.132.0.35 |
| OpenSSL Curve Name | RFC-7518 (6.2.1.1) | ASN.1 OID |
| ------------------ | ----------------------- | ------------------- |
| `prime256v1` | `P-256` | 1.2.840.10045.3.1.7 |
| `secp384k1` | `P-256K` _non standard_ | 1.3.132.0.10 |
| `secp384r1` | `P-384` | 1.3.132.0.34 |
| `secp521r1` | `P-521` | 1.3.132.0.35 |

@@ -45,2 +46,10 @@ Both the OpenSSL names and RFC-7518 (JWA/JWK) names can be used as parameters

> *PLEASE NOTE:* The `P-256K` curve name (`crv` parameter) used when serializing
> a key using the `secp384k1` curve is not standard, and *NOT* interoperable
> with other systems.
>
> See the [IANA](https://www.iana.org/assignments/jose/jose.xhtml#web-key-elliptic-curve)
> registry for all known (and interoperable) curve names.
>
> The `P-256K` name used might change at _ANY_ time.

@@ -47,0 +56,0 @@

@@ -18,2 +18,3 @@ 'use strict';

* | secp256r1 | prime256v1 | NIST P-256 | prime256v1 | 1.2.840.10045.3.1.7 | *
* | secp256k1 | | | secp256k1 | 1.3.132.0.10 | *
* | secp384r1 | | NIST P-384 | secp384r1 | 1.3.132.0.34 | *

@@ -27,5 +28,6 @@ * | secp521r1 | | NIST P-521 | secp521r1 | 1.3.132.0.35 | *

prime256v1 : Math.ceil(256 / 8),
secp256k1 : Math.ceil(256 / 8),
secp384r1 : Math.ceil(384 / 8),
secp521r1 : Math.ceil(521 / 8),
}
secp521r1 : Math.ceil(521 / 8)
};

@@ -35,12 +37,14 @@ /* JWK curve names */

prime256v1 : 'P-256',
secp256k1 : 'P-256K', /* NOT A STANDARD NAME: See the README.md file */
secp384r1 : 'P-384',
secp521r1 : 'P-521',
}
secp521r1 : 'P-521'
};
/* OpenSSL curve names */
const curves = {
'P-256' : 'prime256v1',
'P-384' : 'secp384r1',
'P-521' : 'secp521r1',
}
'P-256' : 'prime256v1',
'P-256K' : 'secp256k1', /* NOT A STANDARD NAME: See the README.md file */
'P-384' : 'secp384r1',
'P-521' : 'secp521r1'
};

@@ -51,3 +55,3 @@ /* ========================================================================== *

const ASN1ECRfc5915KeyDecoder = asn.define('Rfc5915Key', function() {
const ASN1ECRfc5915Key = asn.define('Rfc5915Key', function() {
this.seq().obj(

@@ -58,5 +62,5 @@ this.key('version').int(),

'1 2 840 10045 3 1 7' : 'prime256v1',
'1 3 132 0 10' : 'prime256v1',
'1 3 132 0 10' : 'secp256k1',
'1 3 132 0 34' : 'secp384r1',
'1 3 132 0 35' : 'secp521r1',
'1 3 132 0 35' : 'secp521r1'
}),

@@ -67,18 +71,5 @@ this.key('publicKey').optional().explicit(1).bitstr()

const ASN1ECRfc5915KeyEncoder = asn.define('Rfc5915Key', function() {
this.seq().obj(
this.key('version').int(),
this.key('privateKey').octstr(),
this.key('parameters').optional().explicit(0).objid({
'1 2 840 10045 3 1 7' : 'prime256v1',
'1 3 132 0 34' : 'secp384r1',
'1 3 132 0 35' : 'secp521r1',
}),
this.key('publicKey').optional().explicit(1).bitstr()
);
});
/* ========================================================================== */
const ASN1ECPkcs8KeyDecoder = asn.define('Pkcs8Key', function() {
const ASN1ECPkcs8Key = asn.define('Pkcs8Key', function() {
this.seq().obj(

@@ -92,5 +83,5 @@ this.key('version').int(),

'1 2 840 10045 3 1 7' : 'prime256v1',
'1 3 132 0 10' : 'prime256v1',
'1 3 132 0 10' : 'secp256k1',
'1 3 132 0 34' : 'secp384r1',
'1 3 132 0 35' : 'secp521r1',
'1 3 132 0 35' : 'secp521r1'
})

@@ -102,22 +93,5 @@ ),

const ASN1ECPkcs8KeyEncoder = asn.define('Pkcs8Key', function() {
this.seq().obj(
this.key('version').int(),
this.key('algorithmIdentifier').seq().obj(
this.key('privateKeyType').objid({
'1 2 840 10045 2 1': 'EC'
}),
this.key('parameters').objid({
'1 2 840 10045 3 1 7' : 'prime256v1',
'1 3 132 0 34' : 'secp384r1',
'1 3 132 0 35' : 'secp521r1',
})
),
this.key('privateKey').octstr()
);
});
/* ========================================================================== */
const ASN1ECSpkiKeyDecoder = asn.define('SpkiKey', function() {
const ASN1ECSpkiKey = asn.define('SpkiKey', function() {
this.seq().obj(

@@ -130,5 +104,5 @@ this.key('algorithmIdentifier').seq().obj(

'1 2 840 10045 3 1 7' : 'prime256v1',
'1 3 132 0 10' : 'prime256v1',
'1 3 132 0 10' : 'secp256k1',
'1 3 132 0 34' : 'secp384r1',
'1 3 132 0 35' : 'secp521r1',
'1 3 132 0 35' : 'secp521r1'
})

@@ -140,18 +114,2 @@ ),

const ASN1ECSpkiKeyEncoder = asn.define('SpkiKey', function() {
this.seq().obj(
this.key('algorithmIdentifier').seq().obj(
this.key('publicKeyType').objid({
'1 2 840 10045 2 1': 'EC'
}),
this.key('parameters').objid({
'1 2 840 10045 3 1 7' : 'prime256v1',
'1 3 132 0 34' : 'secp384r1',
'1 3 132 0 35' : 'secp521r1',
})
),
this.key('publicKey').bitstr()
);
});
/* ========================================================================== *

@@ -178,4 +136,4 @@ * ASN.1 PARSING *

function parsePkcs8(buffer) {
var key = ASN1ECPkcs8KeyDecoder.decode(buffer, 'der');
var privateKeyWrapper = ASN1ECRfc5915KeyDecoder.decode(key.privateKey, 'der');
var key = ASN1ECPkcs8Key.decode(buffer, 'der');
var privateKeyWrapper = ASN1ECRfc5915Key.decode(key.privateKey, 'der');
var curve = key.algorithmIdentifier.parameters;

@@ -196,3 +154,3 @@ var bytes = lengths[curve];

function parseRfc5915(buffer) {
var key = ASN1ECRfc5915KeyDecoder.decode(buffer, 'der');
var key = ASN1ECRfc5915Key.decode(buffer, 'der');
var bytes = lengths[key.parameters];

@@ -212,3 +170,3 @@

function parseSpki(buffer) {
var key = ASN1ECSpkiKeyDecoder.decode(buffer, 'der');
var key = ASN1ECSpkiKey.decode(buffer, 'der');
return parsePublicKeyBuffer(key.algorithmIdentifier.parameters, key.publicKey.data);

@@ -525,3 +483,3 @@ }

// Encode in PKCS8
return ASN1ECPkcs8KeyEncoder.encode({
return ASN1ECPkcs8Key.encode({
version: 0,

@@ -533,3 +491,3 @@ algorithmIdentifier: {

// Private key is RFC5915 minus curve
privateKey: ASN1ECRfc5915KeyEncoder.encode({
privateKey: ASN1ECRfc5915Key.encode({
version: 1,

@@ -544,3 +502,3 @@ privateKey: d,

// Simply encode in ASN.1
return ASN1ECRfc5915KeyEncoder.encode({
return ASN1ECRfc5915Key.encode({
version: 1,

@@ -559,3 +517,3 @@ privateKey: d,

if ((format == "spki") || (format == "rfc5280")) {
return ASN1ECSpkiKeyEncoder.encode({
return ASN1ECSpkiKey.encode({
algorithmIdentifier: {

@@ -562,0 +520,0 @@ publicKeyType: 'EC',

@@ -10,3 +10,3 @@ 'use strict';

var re = /-+BEGIN .* KEY-+([\s\S]+)-+END .* KEY-+/m;
var names = [ 'prime256v1', 'secp384r1', 'secp521r1' ];
var names = [ 'prime256v1', 'secp384r1', 'secp521r1', 'secp256k1' ];
var curves = {};

@@ -23,4 +23,4 @@

privJwk: JSON.parse(fs.readFileSync('./test/support/' + name + '.priv.json', 'utf8')),
pubJwk: JSON.parse(fs.readFileSync('./test/support/' + name + '.pub.json', 'utf8')),
}
pubJwk: JSON.parse(fs.readFileSync('./test/support/' + name + '.pub.json', 'utf8'))
};
})(names[i]);

@@ -57,4 +57,5 @@ });

// Buffers: pkcs8, openssl and spki (public)
var pkcs8b64 = curve.pkcs8.match(re)[1].replace(/[\s-]/g, '')
expect(key.toBuffer('pkcs8').toString('base64'))
.to.equal(curve.pkcs8.match(re)[1].replace(/[\s-]/g, ''));
.to.equal(pkcs8b64);
expect(key.toBuffer('rfc5915').toString('base64'))

@@ -61,0 +62,0 @@ .to.equal(curve.priv.match(re)[1].replace(/[\s-]/g, ''));

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