New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

encryption-test

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encryption-test - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

23

index.js

@@ -380,3 +380,19 @@ 'use strict'

}
function getPrivateKeyByKeystore (keystoreContent, password) {
let rawKeyResult = keystore.decrypt(keystoreContent, password)
let privateKey = ''
if (rawKeyResult.version === 2) {
privateKey = rawKeyResult.privateKey
} else {
let chainType = keystoreContent.address.substring(8, 10);
let rowPrivateKey = rawKeyResult.privateKey
chainType = chainType === 'ef' ? CRYPTO_ED25519 : CRYPTO_SM2;
privateKey = generatePrivateKeyBySeedAndCryptoType(chainType, rowPrivateKey)
}
const accountObj = generateByKey(privateKey)
if (accountObj.address !== keystoreContent.address) {
throw ('Keystore error');
}
return privateKey
}
function _bytesToHex (bytes) {

@@ -437,2 +453,5 @@ for (var hex = [], i = 0; i < bytes.length; i++) {

}
if (language === 'chinese') {
word = WORDLISTS.chinese_simplified;
}
return bip39.entropyToMnemonic(entropy, word)

@@ -597,2 +616,3 @@ }

parsePublicKey,
publicToAddress,
isPrivateKey,

@@ -603,2 +623,3 @@ isPublicKey,

decipherKeyStore,
getPrivateKeyByKeystore,
generateChild,

@@ -605,0 +626,0 @@ privKeyFromMCodeAndCrypto,

5

package.json
{
"name": "encryption-test",
"version": "1.0.7",
"version": "1.0.8",
"description": "",

@@ -24,4 +24,5 @@ "main": "index.js",

"json-bigint": "^1.0.0",
"long": "^5.2.3"
"long": "^5.2.3",
"sha3": "^2.1.4"
}
}
'use strict'
const sjcl = require('brdc-sjcl')
const CryptoJS = require('crypto-js')
const {Keccak} = require('sha3');
const crypto = {}

@@ -72,2 +73,50 @@ // const SCRYPT_PARAMS_COST_FACTOR = 16384

}
crypto.decryptByV3 = (password, keystoreJson) => {
const n = keystoreJson.crypto.kdfparams.n;
const r = keystoreJson.crypto.kdfparams.r;
const p = keystoreJson.crypto.kdfparams.p;
const dkLen = keystoreJson.crypto.kdfparams.dklen * 8;
let cypherText = {};
cypherText.ciphertext = CryptoJS.enc.Hex.parse(keystoreJson.crypto.ciphertext);
let saltBits = sjcl.codec.hex.toBits(keystoreJson.crypto.kdfparams.salt);
let passwordBits = sjcl.codec.utf8String.toBits(password);
const dk = crypto.deriveKey(passwordBits, saltBits, keystoreJson.crypto.kdf, {n: n, r: r, p: p, dkLen: dkLen});
let macBody = sjcl.bitArray.concat(dk.slice(4, 8), cypherText.ciphertext.words);
const derivedMac = keccak256(sjcl.codec.hex.fromBits(macBody));
if (derivedMac !== keystoreJson.crypto.mac) {
throw ({code: '', codeKey: 'KeystorePasswordError', errorMessage: 'The password is incorrect'});
}
const encryptKey = sjcl.codec.hex.fromBits(dk.slice(0, 4));
let aes = new sjcl.cipher.aes(sjcl.codec.hex.toBits(encryptKey));
return sjcl.mode.ctr.decrypt(aes, cypherText.ciphertext.words, sjcl.codec.hex.toBits(keystoreJson.crypto.cipherparams.iv));
}
crypto.deriveKey = (password, saltBits, kdf, deriveConfig) => {
if (kdf === 'scrypt') {
return sjcl.misc.scrypt(
password,
saltBits,
deriveConfig.n,
deriveConfig.r,
deriveConfig.p,
deriveConfig.dkLen
);
} else if (kdf === 'pbkdf2') {
// 使用pbkdf2进行密钥派生
return sjcl.misc.pbkdf2(password, sjcl.codec.hex.toBits(salt), 10000, 256, sjcl.misc.hmac);
} else {
throw new Error('Unsupported KDF algorithm');
}
};
function keccak256(data) {
const hash = new Keccak(256);
hash.update(data, 'hex');
return hash.digest('hex');
}
module.exports = crypto

@@ -24,3 +24,17 @@ 'use strict'

}
keystore.decrypt = (keystoreContent, password) => {
let version = keystoreContent.version ||
(keystoreContent.crypto || keystoreContent.Crypto)
|| '';
if (!version) {
throw new Error('Keystore error');
}
let result = ''
if (version === 2) {
result = {version: version, privateKey: crypto.decrypt(password, keystoreContent)}
} else {
result = {version: version, privateKey: crypto.decryptByV3(password, keystoreContent)}
}
return result
}
module.exports = keystore
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