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

@harmony-js/crypto

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harmony-js/crypto - npm Package Compare versions

Comparing version 0.1.27 to 0.1.28

yarn-error.log

11

dist/index.cjs.js

@@ -15,3 +15,3 @@ /**

var aes = _interopDefault(require('aes-js'));
var scrypt = _interopDefault(require('scrypt.js'));
var scrypt = _interopDefault(require('scrypt-shim'));
var pbkdf2 = require('pbkdf2');

@@ -920,3 +920,2 @@ var uuid = _interopDefault(require('uuid'));

var _this = undefined;
var DEFAULT_ALGORITHM = 'aes-128-ctr';

@@ -962,3 +961,3 @@ /**

*/
var encrypt = function (privateKey, password, options) { return __awaiter(_this, void 0, void 0, function () {
var encrypt = function (privateKey, password, options) { return __awaiter(void 0, void 0, void 0, function () {
var address, salt, iv, kdf, level, uuidRandom, n, kdfparams, derivedKey, cipher, ciphertext, mac;

@@ -1022,3 +1021,3 @@ return __generator(this, function (_a) {

*/
var decrypt = function (keystore, password) { return __awaiter(_this, void 0, void 0, function () {
var decrypt = function (keystore, password) { return __awaiter(void 0, void 0, void 0, function () {
var ciphertext, iv, kdfparams, derivedKey, mac, CTR, cipher, decrypted;

@@ -1045,3 +1044,3 @@ return __generator(this, function (_a) {

}); };
var encryptPhrase = function (phrase, password, options) { return __awaiter(_this, void 0, void 0, function () {
var encryptPhrase = function (phrase, password, options) { return __awaiter(void 0, void 0, void 0, function () {
var salt, iv, kdf, level, uuidRandom, n, kdfparams, derivedKey, cipher, ciphertext, mac;

@@ -1093,3 +1092,3 @@ return __generator(this, function (_a) {

}); };
var decryptPhrase = function (keystore, password) { return __awaiter(_this, void 0, void 0, function () {
var decryptPhrase = function (keystore, password) { return __awaiter(void 0, void 0, void 0, function () {
var result;

@@ -1096,0 +1095,0 @@ return __generator(this, function (_a) {

@@ -9,3 +9,3 @@ /**

import aes from 'aes-js';
import scrypt from 'scrypt.js';
import scrypt from 'scrypt-shim';
import { pbkdf2Sync } from 'pbkdf2';

@@ -917,3 +917,2 @@ import uuid from 'uuid';

var _this = undefined;
var DEFAULT_ALGORITHM = 'aes-128-ctr';

@@ -959,3 +958,3 @@ /**

*/
var encrypt = function (privateKey, password, options) { return __awaiter(_this, void 0, void 0, function () {
var encrypt = function (privateKey, password, options) { return __awaiter(void 0, void 0, void 0, function () {
var address, salt, iv, kdf, level, uuidRandom, n, kdfparams, derivedKey, cipher, ciphertext, mac;

@@ -1019,3 +1018,3 @@ return __generator(this, function (_a) {

*/
var decrypt = function (keystore, password) { return __awaiter(_this, void 0, void 0, function () {
var decrypt = function (keystore, password) { return __awaiter(void 0, void 0, void 0, function () {
var ciphertext, iv, kdfparams, derivedKey, mac, CTR, cipher, decrypted;

@@ -1042,3 +1041,3 @@ return __generator(this, function (_a) {

}); };
var encryptPhrase = function (phrase, password, options) { return __awaiter(_this, void 0, void 0, function () {
var encryptPhrase = function (phrase, password, options) { return __awaiter(void 0, void 0, void 0, function () {
var salt, iv, kdf, level, uuidRandom, n, kdfparams, derivedKey, cipher, ciphertext, mac;

@@ -1090,3 +1089,3 @@ return __generator(this, function (_a) {

}); };
var decryptPhrase = function (keystore, password) { return __awaiter(_this, void 0, void 0, function () {
var decryptPhrase = function (keystore, password) { return __awaiter(void 0, void 0, void 0, function () {
var result;

@@ -1093,0 +1092,0 @@ return __generator(this, function (_a) {

@@ -6,5 +6,5 @@ /**

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('js-sha3'), require('elliptic'), require('@harmony-js/utils'), require('aes-js'), require('scrypt.js'), require('pbkdf2'), require('uuid'), require('hdkey'), require('bip39'), require('bn.js')) :
typeof define === 'function' && define.amd ? define(['exports', 'js-sha3', 'elliptic', '@harmony-js/utils', 'aes-js', 'scrypt.js', 'pbkdf2', 'uuid', 'hdkey', 'bip39', 'bn.js'], factory) :
(factory((global.harmonyCrypto = {}),global['js-sha3'],global.elliptic,global['@harmony-js/utils'],global['aes-js'],global.scrypt.js,global.pbkdf2,global.uuid,global.hdkey,global.bip39,global.bn.js));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('js-sha3'), require('elliptic'), require('@harmony-js/utils'), require('aes-js'), require('scrypt-shim'), require('pbkdf2'), require('uuid'), require('hdkey'), require('bip39'), require('bn.js')) :
typeof define === 'function' && define.amd ? define(['exports', 'js-sha3', 'elliptic', '@harmony-js/utils', 'aes-js', 'scrypt-shim', 'pbkdf2', 'uuid', 'hdkey', 'bip39', 'bn.js'], factory) :
(factory((global.harmonyCrypto = {}),global['js-sha3'],global.elliptic,global['@harmony-js/utils'],global['aes-js'],global['scrypt-shim'],global.pbkdf2,global.uuid,global.hdkey,global.bip39,global.bn.js));
}(this, (function (exports,sha3,elliptic,utils,aes,scrypt,pbkdf2,uuid,hdkey,bip39,bn_js) { 'use strict';

@@ -917,3 +917,2 @@

var _this = undefined;
var DEFAULT_ALGORITHM = 'aes-128-ctr';

@@ -959,3 +958,3 @@ /**

*/
var encrypt = function (privateKey, password, options) { return __awaiter(_this, void 0, void 0, function () {
var encrypt = function (privateKey, password, options) { return __awaiter(void 0, void 0, void 0, function () {
var address, salt, iv, kdf, level, uuidRandom, n, kdfparams, derivedKey, cipher, ciphertext, mac;

@@ -1019,3 +1018,3 @@ return __generator(this, function (_a) {

*/
var decrypt = function (keystore, password) { return __awaiter(_this, void 0, void 0, function () {
var decrypt = function (keystore, password) { return __awaiter(void 0, void 0, void 0, function () {
var ciphertext, iv, kdfparams, derivedKey, mac, CTR, cipher, decrypted;

@@ -1042,3 +1041,3 @@ return __generator(this, function (_a) {

}); };
var encryptPhrase = function (phrase, password, options) { return __awaiter(_this, void 0, void 0, function () {
var encryptPhrase = function (phrase, password, options) { return __awaiter(void 0, void 0, void 0, function () {
var salt, iv, kdf, level, uuidRandom, n, kdfparams, derivedKey, cipher, ciphertext, mac;

@@ -1090,3 +1089,3 @@ return __generator(this, function (_a) {

}); };
var decryptPhrase = function (keystore, password) { return __awaiter(_this, void 0, void 0, function () {
var decryptPhrase = function (keystore, password) { return __awaiter(void 0, void 0, void 0, function () {
var result;

@@ -1093,0 +1092,0 @@ return __generator(this, function (_a) {

"use strict";
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var aes_js_1 = tslib_1.__importDefault(require("aes-js"));
var scrypt_js_1 = tslib_1.__importDefault(require("scrypt.js"));
// import scrypt from 'scrypt.js';
var scrypt_shim_1 = tslib_1.__importDefault(require("scrypt-shim"));
var pbkdf2_1 = require("pbkdf2");

@@ -37,3 +37,3 @@ var uuid_1 = tslib_1.__importDefault(require("uuid"));

_b = params, n = _b.n, r = _b.r, p = _b.p, dklen = _b.dklen;
return [2 /*return*/, scrypt_js_1.default(key, salt, n, r, p, dklen)];
return [2 /*return*/, scrypt_shim_1.default(key, salt, n, r, p, dklen)];
}

@@ -55,3 +55,3 @@ throw new Error('Only pbkdf2 and scrypt are supported');

*/
exports.encrypt = function (privateKey, password, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
exports.encrypt = function (privateKey, password, options) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var address, salt, iv, kdf, level, uuidRandom, n, kdfparams, derivedKey, cipher, ciphertext, mac;

@@ -115,3 +115,3 @@ return tslib_1.__generator(this, function (_a) {

*/
exports.decrypt = function (keystore, password) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
exports.decrypt = function (keystore, password) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var ciphertext, iv, kdfparams, derivedKey, mac, CTR, cipher, decrypted;

@@ -138,3 +138,3 @@ return tslib_1.__generator(this, function (_a) {

}); };
exports.encryptPhrase = function (phrase, password, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
exports.encryptPhrase = function (phrase, password, options) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var salt, iv, kdf, level, uuidRandom, n, kdfparams, derivedKey, cipher, ciphertext, mac;

@@ -186,3 +186,3 @@ return tslib_1.__generator(this, function (_a) {

}); };
exports.decryptPhrase = function (keystore, password) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
exports.decryptPhrase = function (keystore, password) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var result;

@@ -189,0 +189,0 @@ return tslib_1.__generator(this, function (_a) {

{
"name": "@harmony-js/crypto",
"version": "0.1.27",
"version": "0.1.28",
"description": "crypto libraries for harmony",

@@ -19,5 +19,5 @@ "main": "dist/index.js",

},
"license": "ISC",
"license": "MIT",
"dependencies": {
"@harmony-js/utils": "0.1.27",
"@harmony-js/utils": "0.1.28",
"aes-js": "^3.1.2",

@@ -31,6 +31,6 @@ "bip39": "^2.5.0",

"pbkdf2": "^3.0.17",
"scrypt.js": "^0.3.0",
"scrypt-shim": "github:web3-js/scrypt-shim",
"uuid": "^3.3.2"
},
"gitHead": "6e1abec93bbdb2ca5fd1acfc8d0093165688ef91"
"gitHead": "1ccc7071aee39a4597caa1019c36104420499af9"
}
import aes from 'aes-js';
import scrypt from 'scrypt.js';
// import scrypt from 'scrypt.js';
import scrypt from 'scrypt-shim';
import { pbkdf2Sync } from 'pbkdf2';

@@ -10,10 +11,3 @@ import uuid from 'uuid';

import { keccak256 } from './keccak256';
import {
KDF,
KDFParams,
EncryptOptions,
PBKDF2Params,
ScryptParams,
Keystore,
} from './types';
import { KDF, KDFParams, EncryptOptions, PBKDF2Params, ScryptParams, Keystore } from './types';

@@ -33,7 +27,3 @@ const DEFAULT_ALGORITHM = 'aes-128-ctr';

*/
async function getDerivedKey(
key: Buffer,
kdf: KDF,
params: KDFParams,
): Promise<Buffer> {
async function getDerivedKey(key: Buffer, kdf: KDF, params: KDFParams): Promise<Buffer> {
const salt = Buffer.from(params.salt, 'hex');

@@ -82,6 +72,4 @@

const iv = Buffer.from(randomBytes(16), 'hex');
const kdf =
options !== undefined ? (options.kdf ? options.kdf : 'scrypt') : 'scrypt';
const level =
options !== undefined ? (options.level ? options.level : 8192) : 8192;
const kdf = options !== undefined ? (options.kdf ? options.kdf : 'scrypt') : 'scrypt';
const level = options !== undefined ? (options.level ? options.level : 8192) : 8192;

@@ -100,6 +88,3 @@ const uuidRandom = options !== undefined ? options.uuid : undefined;

const derivedKey = await getDerivedKey(Buffer.from(password), kdf, kdfparams);
const cipher = new aes.ModeOfOperation.ctr(
derivedKey.slice(0, 16),
new aes.Counter(iv),
);
const cipher = new aes.ModeOfOperation.ctr(derivedKey.slice(0, 16), new aes.Counter(iv));

@@ -110,5 +95,3 @@ if (!cipher) {

const ciphertext = Buffer.from(
cipher.encrypt(Buffer.from(privateKey.replace('0x', ''), 'hex')),
);
const ciphertext = Buffer.from(cipher.encrypt(Buffer.from(privateKey.replace('0x', ''), 'hex')));

@@ -140,6 +123,3 @@ const mac = keccak256(concat([derivedKey.slice(16, 32), ciphertext]));

*/
export const decrypt = async (
keystore: Keystore,
password: string,
): Promise<string> => {
export const decrypt = async (keystore: Keystore, password: string): Promise<string> => {
const ciphertext = Buffer.from(keystore.Crypto.ciphertext, 'hex');

@@ -149,12 +129,5 @@ const iv = Buffer.from(keystore.Crypto.cipherparams.iv, 'hex');

const derivedKey = await getDerivedKey(
Buffer.from(password),
keystore.Crypto.kdf,
kdfparams,
);
const derivedKey = await getDerivedKey(Buffer.from(password), keystore.Crypto.kdf, kdfparams);
const mac = keccak256(concat([derivedKey.slice(16, 32), ciphertext])).replace(
'0x',
'',
);
const mac = keccak256(concat([derivedKey.slice(16, 32), ciphertext])).replace('0x', '');

@@ -169,4 +142,3 @@ if (mac.toUpperCase() !== keystore.Crypto.mac.toUpperCase()) {

const decrypted =
'0x' + Buffer.from(cipher.decrypt(ciphertext)).toString('hex');
const decrypted = '0x' + Buffer.from(cipher.decrypt(ciphertext)).toString('hex');
return decrypted;

@@ -185,6 +157,4 @@ };

const iv = Buffer.from(randomBytes(16), 'hex');
const kdf =
options !== undefined ? (options.kdf ? options.kdf : 'scrypt') : 'scrypt';
const level =
options !== undefined ? (options.level ? options.level : 8192) : 8192;
const kdf = options !== undefined ? (options.kdf ? options.kdf : 'scrypt') : 'scrypt';
const level = options !== undefined ? (options.level ? options.level : 8192) : 8192;

@@ -202,6 +172,3 @@ const uuidRandom = options !== undefined ? options.uuid : undefined;

const derivedKey = await getDerivedKey(Buffer.from(password), kdf, kdfparams);
const cipher = new aes.ModeOfOperation.ctr(
derivedKey.slice(0, 16),
new aes.Counter(iv),
);
const cipher = new aes.ModeOfOperation.ctr(derivedKey.slice(0, 16), new aes.Counter(iv));

@@ -231,8 +198,5 @@ if (!cipher) {

export const decryptPhrase = async (
keystore: Keystore,
password: string,
): Promise<string> => {
export const decryptPhrase = async (keystore: Keystore, password: string): Promise<string> => {
const result = await decrypt(keystore, password);
return Buffer.from(result.replace('0x', ''), 'hex').toString();
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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