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

@harmony-js/crypto

Package Overview
Dependencies
Maintainers
3
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.35 to 0.1.41-alpha.1

tsconfig.tsbuildinfo

8

dist/address.d.ts

@@ -8,6 +8,6 @@ export declare class HarmonyAddress {

basic: string;
readonly basicHex: string;
readonly checksum: string;
readonly bech32: string;
readonly bech32TestNet: string;
get basicHex(): string;
get checksum(): string;
get bech32(): string;
get bech32TestNet(): string;
constructor(raw: string);

@@ -14,0 +14,0 @@ private getBasic;

@@ -891,6 +891,7 @@ /**

function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -976,4 +977,3 @@ });

}
// TODO: should use isString() to implement this
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -1008,3 +1008,3 @@ }

address: address.toLowerCase().replace('0x', ''),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -1034,10 +1034,10 @@ cipherparams: {

case 0:
ciphertext = Buffer.from(keystore.Crypto.ciphertext, 'hex');
iv = Buffer.from(keystore.Crypto.cipherparams.iv, 'hex');
kdfparams = keystore.Crypto.kdfparams;
return [4 /*yield*/, getDerivedKey(Buffer.from(password), keystore.Crypto.kdf, kdfparams)];
ciphertext = Buffer.from(keystore.crypto.ciphertext, 'hex');
iv = Buffer.from(keystore.crypto.cipherparams.iv, 'hex');
kdfparams = keystore.crypto.kdfparams;
return [4 /*yield*/, getDerivedKey(Buffer.from(password), keystore.crypto.kdf, kdfparams)];
case 1:
derivedKey = _a.sent();
mac = keccak256(concat([derivedKey.slice(16, 32), ciphertext])).replace('0x', '');
if (mac.toUpperCase() !== keystore.Crypto.mac.toUpperCase()) {
if (mac.toUpperCase() !== keystore.crypto.mac.toUpperCase()) {
return [2 /*return*/, Promise.reject(new Error('Failed to decrypt.'))];

@@ -1057,3 +1057,3 @@ }

case 0:
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -1086,3 +1086,3 @@ }

id: uuid.v4({ random: uuidRandom || hexToIntArray(randomBytes(16)) }),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -1089,0 +1089,0 @@ cipherparams: {

@@ -888,6 +888,7 @@ /**

function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -973,4 +974,3 @@ });

}
// TODO: should use isString() to implement this
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -1005,3 +1005,3 @@ }

address: address.toLowerCase().replace('0x', ''),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -1031,10 +1031,10 @@ cipherparams: {

case 0:
ciphertext = Buffer.from(keystore.Crypto.ciphertext, 'hex');
iv = Buffer.from(keystore.Crypto.cipherparams.iv, 'hex');
kdfparams = keystore.Crypto.kdfparams;
return [4 /*yield*/, getDerivedKey(Buffer.from(password), keystore.Crypto.kdf, kdfparams)];
ciphertext = Buffer.from(keystore.crypto.ciphertext, 'hex');
iv = Buffer.from(keystore.crypto.cipherparams.iv, 'hex');
kdfparams = keystore.crypto.kdfparams;
return [4 /*yield*/, getDerivedKey(Buffer.from(password), keystore.crypto.kdf, kdfparams)];
case 1:
derivedKey = _a.sent();
mac = keccak256(concat([derivedKey.slice(16, 32), ciphertext])).replace('0x', '');
if (mac.toUpperCase() !== keystore.Crypto.mac.toUpperCase()) {
if (mac.toUpperCase() !== keystore.crypto.mac.toUpperCase()) {
return [2 /*return*/, Promise.reject(new Error('Failed to decrypt.'))];

@@ -1054,3 +1054,3 @@ }

case 0:
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -1083,3 +1083,3 @@ }

id: uuid.v4({ random: uuidRandom || hexToIntArray(randomBytes(16)) }),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -1086,0 +1086,0 @@ cipherparams: {

@@ -888,6 +888,7 @@ /**

function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -973,4 +974,3 @@ });

}
// TODO: should use isString() to implement this
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -1005,3 +1005,3 @@ }

address: address.toLowerCase().replace('0x', ''),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -1031,10 +1031,10 @@ cipherparams: {

case 0:
ciphertext = Buffer.from(keystore.Crypto.ciphertext, 'hex');
iv = Buffer.from(keystore.Crypto.cipherparams.iv, 'hex');
kdfparams = keystore.Crypto.kdfparams;
return [4 /*yield*/, getDerivedKey(Buffer.from(password), keystore.Crypto.kdf, kdfparams)];
ciphertext = Buffer.from(keystore.crypto.ciphertext, 'hex');
iv = Buffer.from(keystore.crypto.cipherparams.iv, 'hex');
kdfparams = keystore.crypto.kdfparams;
return [4 /*yield*/, getDerivedKey(Buffer.from(password), keystore.crypto.kdf, kdfparams)];
case 1:
derivedKey = _a.sent();
mac = keccak256(concat([derivedKey.slice(16, 32), ciphertext])).replace('0x', '');
if (mac.toUpperCase() !== keystore.Crypto.mac.toUpperCase()) {
if (mac.toUpperCase() !== keystore.crypto.mac.toUpperCase()) {
return [2 /*return*/, Promise.reject(new Error('Failed to decrypt.'))];

@@ -1054,3 +1054,3 @@ }

case 0:
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -1083,3 +1083,3 @@ }

id: uuid.v4({ random: uuidRandom || hexToIntArray(randomBytes(16)) }),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -1086,0 +1086,0 @@ cipherparams: {

@@ -62,4 +62,3 @@ "use strict";

}
// TODO: should use isString() to implement this
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -94,3 +93,3 @@ }

address: address.toLowerCase().replace('0x', ''),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -120,10 +119,10 @@ cipherparams: {

case 0:
ciphertext = Buffer.from(keystore.Crypto.ciphertext, 'hex');
iv = Buffer.from(keystore.Crypto.cipherparams.iv, 'hex');
kdfparams = keystore.Crypto.kdfparams;
return [4 /*yield*/, getDerivedKey(Buffer.from(password), keystore.Crypto.kdf, kdfparams)];
ciphertext = Buffer.from(keystore.crypto.ciphertext, 'hex');
iv = Buffer.from(keystore.crypto.cipherparams.iv, 'hex');
kdfparams = keystore.crypto.kdfparams;
return [4 /*yield*/, getDerivedKey(Buffer.from(password), keystore.crypto.kdf, kdfparams)];
case 1:
derivedKey = _a.sent();
mac = keccak256_1.keccak256(bytes_1.concat([derivedKey.slice(16, 32), ciphertext])).replace('0x', '');
if (mac.toUpperCase() !== keystore.Crypto.mac.toUpperCase()) {
if (mac.toUpperCase() !== keystore.crypto.mac.toUpperCase()) {
return [2 /*return*/, Promise.reject(new Error('Failed to decrypt.'))];

@@ -143,3 +142,3 @@ }

case 0:
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -172,3 +171,3 @@ }

id: uuid_1.default.v4({ random: uuidRandom || bytes_1.hexToIntArray(random_1.randomBytes(16)) }),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -175,0 +174,0 @@ cipherparams: {

@@ -22,3 +22,3 @@ export declare type KDF = 'pbkdf2' | 'scrypt';

address?: string;
Crypto: {
crypto: {
cipher: string;

@@ -25,0 +25,0 @@ cipherparams: {

{
"name": "@harmony-js/crypto",
"version": "0.1.35",
"version": "0.1.41-alpha.1+3c7e080",
"description": "crypto libraries for harmony",

@@ -21,3 +21,3 @@ "main": "dist/index.js",

"dependencies": {
"@harmony-js/utils": "0.1.35",
"@harmony-js/utils": "^0.1.41-alpha.1+3c7e080",
"aes-js": "^3.1.2",

@@ -34,3 +34,3 @@ "bip39": "^2.5.0",

},
"gitHead": "cc00c23e9a5da76ad044490827995f1e5c66781e"
"gitHead": "3c7e080a7dad4f2636f307347132a992a2f76cca"
}

@@ -61,5 +61,3 @@ import aes from 'aes-js';

}
// TODO: should use isString() to implement this
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -100,3 +98,3 @@ }

address: address.toLowerCase().replace('0x', ''),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -121,11 +119,11 @@ cipherparams: {

export const decrypt = async (keystore: Keystore, password: string): Promise<string> => {
const ciphertext = Buffer.from(keystore.Crypto.ciphertext, 'hex');
const iv = Buffer.from(keystore.Crypto.cipherparams.iv, 'hex');
const { kdfparams } = keystore.Crypto;
const ciphertext = Buffer.from(keystore.crypto.ciphertext, 'hex');
const iv = Buffer.from(keystore.crypto.cipherparams.iv, 'hex');
const { kdfparams } = keystore.crypto;
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', '');
if (mac.toUpperCase() !== keystore.Crypto.mac.toUpperCase()) {
if (mac.toUpperCase() !== keystore.crypto.mac.toUpperCase()) {
return Promise.reject(new Error('Failed to decrypt.'));

@@ -147,3 +145,3 @@ }

): Promise<string> => {
if (!password) {
if (typeof password !== 'string') {
throw new Error('password is not found');

@@ -179,3 +177,3 @@ }

id: uuid.v4({ random: uuidRandom || hexToIntArray(randomBytes(16)) }),
Crypto: {
crypto: {
ciphertext: ciphertext.toString('hex'),

@@ -182,0 +180,0 @@ cipherparams: {

@@ -27,3 +27,3 @@ export type KDF = 'pbkdf2' | 'scrypt';

address?: string;
Crypto: {
crypto: {
cipher: string;

@@ -30,0 +30,0 @@ cipherparams: {

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

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