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

@liskhq/lisk-cryptography

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liskhq/lisk-cryptography - npm Package Compare versions

Comparing version 4.0.0-beta.1 to 4.0.0-beta.2

3

dist-node/bls_lib/lib.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.blsPopVerify = exports.blsPopProve = exports.blsFastAggregateVerify = exports.blsAggregateVerify = exports.blsVerify = exports.blsSign = exports.blsAggregate = exports.blsSkToPk = exports.blsKeyGen = exports.blsKeyValidate = void 0;
const crypto_1 = require("crypto");
const blst_1 = require("@chainsafe/blst");

@@ -32,3 +33,3 @@ const bindings_1 = require("@chainsafe/blst/dist/bindings");

const blsSign = (sk, message) => {
if (sk.equals(Buffer.alloc(32))) {
if ((0, crypto_1.timingSafeEqual)(sk, Buffer.alloc(32))) {
return Buffer.concat([Buffer.from([192]), Buffer.alloc(95)]);

@@ -35,0 +36,0 @@ }

/// <reference types="node" />
export interface EncryptedMessageWithNonce {
readonly encryptedMessage: string;
readonly nonce: string;
}
export declare const encryptMessageWithPrivateKey: (message: string, senderPrivateKey: Buffer, recipientPublicKey: Buffer) => EncryptedMessageWithNonce;
export declare const decryptMessageWithPrivateKey: (cipherHex: string, nonce: string, recipientPrivateKey: Buffer, senderPublicKey: Buffer) => string;
export declare const ARGON2_MEMORY = 2097023;
export declare enum Cipher {

@@ -9,0 +4,0 @@ AES256GCM = "aes-256-gcm"

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringifyEncryptedMessage = exports.parseEncryptedMessage = exports.decryptMessageWithPassword = exports.encryptMessageWithPassword = exports.decryptAES256GCMWithPassword = exports.encryptAES256GCMWithPassword = exports.KDF = exports.Cipher = exports.decryptMessageWithPrivateKey = exports.encryptMessageWithPrivateKey = void 0;
exports.stringifyEncryptedMessage = exports.parseEncryptedMessage = exports.decryptMessageWithPassword = exports.encryptMessageWithPassword = exports.decryptAES256GCMWithPassword = exports.encryptAES256GCMWithPassword = exports.KDF = exports.Cipher = exports.ARGON2_MEMORY = void 0;
const hash_wasm_1 = require("hash-wasm");
const querystring = require("querystring");
const crypto = require("crypto");
const ed2curve = require("ed2curve");
const nacl_1 = require("./nacl");
const utils_1 = require("./utils");

@@ -17,43 +15,3 @@ const PBKDF2_ITERATIONS = 1e6;

const ARGON2_PARALLELISM = 4;
const ARGON2_MEMORY = 2024;
const encryptMessageWithPrivateKey = (message, senderPrivateKey, recipientPublicKey) => {
const convertedPrivateKey = Buffer.from(ed2curve.convertSecretKey(senderPrivateKey));
const messageInBytes = Buffer.from(message, 'utf8');
const nonceSize = 24;
const nonce = (0, nacl_1.getRandomBytes)(nonceSize);
const publicKeyUint8Array = ed2curve.convertPublicKey(recipientPublicKey);
if (publicKeyUint8Array === null) {
throw new Error('given public key is not a valid Ed25519 public key');
}
const convertedPublicKey = Buffer.from(publicKeyUint8Array);
const cipherBytes = (0, nacl_1.box)(messageInBytes, nonce, convertedPublicKey, convertedPrivateKey);
const nonceHex = nonce.toString('hex');
const encryptedMessage = cipherBytes.toString('hex');
return {
nonce: nonceHex,
encryptedMessage,
};
};
exports.encryptMessageWithPrivateKey = encryptMessageWithPrivateKey;
const decryptMessageWithPrivateKey = (cipherHex, nonce, recipientPrivateKey, senderPublicKey) => {
const convertedPrivateKey = Buffer.from(ed2curve.convertSecretKey(recipientPrivateKey));
const cipherBytes = (0, utils_1.hexToBuffer)(cipherHex);
const nonceBytes = (0, utils_1.hexToBuffer)(nonce);
const publicKeyUint8Array = ed2curve.convertPublicKey(senderPublicKey);
if (publicKeyUint8Array === null) {
throw new Error('given public key is not a valid Ed25519 public key');
}
const convertedPublicKey = Buffer.from(publicKeyUint8Array);
try {
const decoded = (0, nacl_1.openBox)(cipherBytes, nonceBytes, convertedPublicKey, convertedPrivateKey);
return Buffer.from(decoded).toString();
}
catch (error) {
if (error.message.match(/bad nonce size|"n" must be crypto_box_NONCEBYTES bytes long/)) {
throw new Error('Expected nonce to be 24 bytes.');
}
throw new Error('Something went wrong during decryption. Is this the full encrypted message?');
}
};
exports.decryptMessageWithPrivateKey = decryptMessageWithPrivateKey;
exports.ARGON2_MEMORY = 2097023;
const getKeyFromPassword = (password, salt, iterations) => crypto.pbkdf2Sync(password, salt, iterations, PBKDF2_KEYLEN, PBKDF2_HASH_FUNCTION);

@@ -87,3 +45,3 @@ const getKeyFromPasswordWithArgon2 = async (options) => Buffer.from(await (0, hash_wasm_1.argon2id)({

const parallelism = (_e = (_d = options === null || options === void 0 ? void 0 : options.kdfparams) === null || _d === void 0 ? void 0 : _d.parallelism) !== null && _e !== void 0 ? _e : ARGON2_PARALLELISM;
const memorySize = (_g = (_f = options === null || options === void 0 ? void 0 : options.kdfparams) === null || _f === void 0 ? void 0 : _f.parallelism) !== null && _g !== void 0 ? _g : ARGON2_MEMORY;
const memorySize = (_g = (_f = options === null || options === void 0 ? void 0 : options.kdfparams) === null || _f === void 0 ? void 0 : _f.memorySize) !== null && _g !== void 0 ? _g : exports.ARGON2_MEMORY;
const key = kdf === KDF.ARGON2

@@ -198,3 +156,3 @@ ? await getKeyFromPasswordWithArgon2({

iterations: (_b = parseOption(iterations)) !== null && _b !== void 0 ? _b : ARGON2_ITERATIONS,
memorySize: (_c = parseOption(memorySize)) !== null && _c !== void 0 ? _c : ARGON2_MEMORY,
memorySize: (_c = parseOption(memorySize)) !== null && _c !== void 0 ? _c : exports.ARGON2_MEMORY,
salt,

@@ -201,0 +159,0 @@ },

{
"name": "@liskhq/lisk-cryptography",
"version": "4.0.0-beta.1",
"version": "4.0.0-beta.2",
"description": "General cryptographic functions for use with Lisk-related software",

@@ -20,3 +20,3 @@ "author": "Lisk Foundation <admin@lisk.com>, lightcurve GmbH <admin@lightcurve.io>",

"engines": {
"node": ">=16.14.1 <=16",
"node": ">=18.12.0 <=18",
"npm": ">=8.1.0"

@@ -39,5 +39,4 @@ },

"dependencies": {
"@liskhq/lisk-passphrase": "^4.0.0-beta.1",
"@liskhq/lisk-passphrase": "^4.0.0-beta.2",
"buffer-reverse": "1.0.1",
"ed2curve": "0.3.0",
"hash-wasm": "4.9.0",

@@ -60,7 +59,6 @@ "tweetnacl": "1.0.3",

"devDependencies": {
"@types/ed2curve": "0.2.2",
"@types/jest": "29.2.3",
"@types/jest-when": "3.5.2",
"@types/js-yaml": "4.0.1",
"@types/node": "16.18.3",
"@types/node": "18.15.3",
"@typescript-eslint/eslint-plugin": "5.44.0",

@@ -67,0 +65,0 @@ "@typescript-eslint/parser": "5.44.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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