@harmony-js/crypto
Advanced tools
Comparing version 0.1.27 to 0.1.28
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
607133
72
0
7358
1
+ Added@harmony-js/utils@0.1.28(transitive)
+ Added@types/node@22.9.4(transitive)
+ Addedcipher-base@1.0.5(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removedscrypt.js@^0.3.0
- Removed@harmony-js/utils@0.1.27(transitive)
- Removed@types/node@22.10.1(transitive)
- Removedcipher-base@1.0.6(transitive)
- Removedscrypt@6.0.3(transitive)
- Removedscrypt.js@0.3.0(transitive)
- Removedscryptsy@1.2.1(transitive)
- Removedundici-types@6.20.0(transitive)
Updated@harmony-js/utils@0.1.28