Sign In

@toruslabs/eccrypto

Package Overview
Dependencies
Maintainers
5
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toruslabs/eccrypto - npm Package Compare versions

Comparing version
6.1.0
to
6.2.0
+17
-22
dist/lib.cjs/index.js

@@ -126,4 +126,3 @@ 'use strict';

// This function has sync API so we throw an error immediately.
assert(privateKey.length === 32, "Bad private key");
assert(isValidPrivateKey(privateKey), "Bad private key");
assertPrivateKey(privateKey);
// XXX(Kagami): `elliptic.utils.encode` returns array for every

@@ -137,5 +136,3 @@ // encoding except `hex`.

const getPublicCompressed = function (privateKey) {
// jshint ignore:line
assert(privateKey.length === 32, "Bad private key");
assert(isValidPrivateKey(privateKey), "Bad private key");
assertPrivateKey(privateKey);
// See https://github.com/wanderer/secp256k1-node/issues/46

@@ -151,4 +148,3 @@ const compressed = true;

const sign = async function (privateKey, msg) {
assert(privateKey.length === 32, "Bad private key");
assert(isValidPrivateKey(privateKey), "Bad private key");
assertPrivateKey(privateKey);
assert(msg.length > 0, "Message should not be empty");

@@ -160,10 +156,18 @@ assert(msg.length <= 32, "Message is too long");

};
const verify = async function (publicKey, msg, sig) {
assert(publicKey.length === 65 || publicKey.length === 33, "Bad public key");
const assertPublicKey = function (publicKey) {
assert(publicKey.length === 65 || publicKey.length === 33, "Bad public key: expected 65 or 33 bytes, got " + publicKey.length);
if (publicKey.length === 65) {
assert(publicKey[0] === 4, "Bad public key");
assert(publicKey[0] === 4, "Bad public key: expected first byte 4, got " + publicKey[0]);
}
if (publicKey.length === 33) {
assert(publicKey[0] === 2 || publicKey[0] === 3, "Bad public key");
assert(publicKey[0] === 2 || publicKey[0] === 3, "Bad public key: expected first byte 2 or 3, got " + publicKey[0]);
}
};
const assertPrivateKey = function (privateKey) {
assert(Buffer.isBuffer(privateKey), "Bad private key: expected Buffer");
assert(privateKey.length === 32, "Bad private key: expected 32 bytes, got " + privateKey.length);
assert(isValidPrivateKey(privateKey), "Bad private key: out of range");
};
const verify = async function (publicKey, msg, sig) {
assertPublicKey(publicKey);
assert(msg.length > 0, "Message should not be empty");

@@ -177,13 +181,4 @@ assert(msg.length <= 32, "Message is too long");

const derive = async function (privateKeyA, publicKeyB, padding) {
assert(Buffer.isBuffer(privateKeyA), "Bad private key");
assert(Buffer.isBuffer(publicKeyB), "Bad public key");
assert(privateKeyA.length === 32, "Bad private key");
assert(isValidPrivateKey(privateKeyA), "Bad private key");
assert(publicKeyB.length === 65 || publicKeyB.length === 33, "Bad public key");
if (publicKeyB.length === 65) {
assert(publicKeyB[0] === 4, "Bad public key");
}
if (publicKeyB.length === 33) {
assert(publicKeyB[0] === 2 || publicKeyB[0] === 3, "Bad public key");
}
assertPrivateKey(privateKeyA);
assertPublicKey(publicKeyB);
const keyA = ec.keyFromPrivate(privateKeyA);

@@ -190,0 +185,0 @@ const keyB = ec.keyFromPublic(publicKeyB);

@@ -127,4 +127,3 @@ import { ec as ec$1 } from 'elliptic';

// This function has sync API so we throw an error immediately.
assert(privateKey.length === 32, "Bad private key");
assert(isValidPrivateKey(privateKey), "Bad private key");
assertPrivateKey(privateKey);
// XXX(Kagami): `elliptic.utils.encode` returns array for every

@@ -139,5 +138,3 @@ // encoding except `hex`.

const getPublicCompressed = function (privateKey) {
// jshint ignore:line
assert(privateKey.length === 32, "Bad private key");
assert(isValidPrivateKey(privateKey), "Bad private key");
assertPrivateKey(privateKey);
// See https://github.com/wanderer/secp256k1-node/issues/46

@@ -154,4 +151,3 @@ const compressed = true;

const sign = async function (privateKey, msg) {
assert(privateKey.length === 32, "Bad private key");
assert(isValidPrivateKey(privateKey), "Bad private key");
assertPrivateKey(privateKey);
assert(msg.length > 0, "Message should not be empty");

@@ -163,10 +159,18 @@ assert(msg.length <= 32, "Message is too long");

};
const verify = async function (publicKey, msg, sig) {
assert(publicKey.length === 65 || publicKey.length === 33, "Bad public key");
const assertPublicKey = function (publicKey) {
assert(publicKey.length === 65 || publicKey.length === 33, "Bad public key: expected 65 or 33 bytes, got " + publicKey.length);
if (publicKey.length === 65) {
assert(publicKey[0] === 4, "Bad public key");
assert(publicKey[0] === 4, "Bad public key: expected first byte 4, got " + publicKey[0]);
}
if (publicKey.length === 33) {
assert(publicKey[0] === 2 || publicKey[0] === 3, "Bad public key");
assert(publicKey[0] === 2 || publicKey[0] === 3, "Bad public key: expected first byte 2 or 3, got " + publicKey[0]);
}
};
const assertPrivateKey = function (privateKey) {
assert(Buffer.isBuffer(privateKey), "Bad private key: expected Buffer");
assert(privateKey.length === 32, "Bad private key: expected 32 bytes, got " + privateKey.length);
assert(isValidPrivateKey(privateKey), "Bad private key: out of range");
};
const verify = async function (publicKey, msg, sig) {
assertPublicKey(publicKey);
assert(msg.length > 0, "Message should not be empty");

@@ -180,13 +184,4 @@ assert(msg.length <= 32, "Message is too long");

const derive = async function (privateKeyA, publicKeyB, padding) {
assert(Buffer.isBuffer(privateKeyA), "Bad private key");
assert(Buffer.isBuffer(publicKeyB), "Bad public key");
assert(privateKeyA.length === 32, "Bad private key");
assert(isValidPrivateKey(privateKeyA), "Bad private key");
assert(publicKeyB.length === 65 || publicKeyB.length === 33, "Bad public key");
if (publicKeyB.length === 65) {
assert(publicKeyB[0] === 4, "Bad public key");
}
if (publicKeyB.length === 33) {
assert(publicKeyB[0] === 2 || publicKeyB[0] === 3, "Bad public key");
}
assertPrivateKey(privateKeyA);
assertPublicKey(publicKeyB);
const keyA = ec.keyFromPrivate(privateKeyA);

@@ -193,0 +188,0 @@ const keyB = ec.keyFromPublic(publicKeyB);

{
"name": "@toruslabs/eccrypto",
"version": "6.1.0",
"version": "6.2.0",
"description": "JavaScript Elliptic curve cryptography library, includes fix to browser.js so that encrypt/decrypt works",

@@ -5,0 +5,0 @@ "main": "./dist/lib.cjs/index.js",

Sorry, the diff of this file is too big to display