Socket
Socket
Sign inDemoInstall

ethereum-cryptography

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethereum-cryptography - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

hash-utils.d.ts

4

aes.d.ts
/// <reference types="node" />
export declare function encrypt(msg: Buffer, key: Buffer, iv: Buffer, mode: string, pkcs7PaddingEnabled?: boolean): Buffer;
export declare function decrypt(cypherText: Buffer, key: Buffer, iv: Buffer, mode: string, pkcs7PaddingEnabled?: boolean): Buffer;
export declare function encrypt(msg: Buffer, key: Buffer, iv: Buffer, mode?: string, pkcs7PaddingEnabled?: boolean): Buffer;
export declare function decrypt(cypherText: Buffer, key: Buffer, iv: Buffer, mode?: string, pkcs7PaddingEnabled?: boolean): Buffer;
//# sourceMappingURL=aes.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_1 = require("crypto");
var browserifyAes = require("browserify-aes");
var SUPPORTED_MODES = ["aes-128-ctr", "aes-128-cbc", "aes-256-cbc"];
function ensureAesMode(mode) {

@@ -9,6 +10,13 @@ if (!mode.startsWith("aes-")) {

}
function warnIfUnsuportedMode(mode) {
if (!SUPPORTED_MODES.includes(mode)) {
// tslint:disable-next-line no-console
console.warn("Using an unsupported AES mode. Consider using aes-128-ctr.");
}
}
function encrypt(msg, key, iv, mode, pkcs7PaddingEnabled) {
if (mode === void 0) { mode = "aes-128-ctr"; }
if (pkcs7PaddingEnabled === void 0) { pkcs7PaddingEnabled = true; }
ensureAesMode(mode);
var cipher = crypto_1.createCipheriv(mode, key, iv);
var cipher = browserifyAes.createCipheriv(mode, key, iv);
cipher.setAutoPadding(pkcs7PaddingEnabled);

@@ -21,5 +29,6 @@ var encrypted = cipher.update(msg);

function decrypt(cypherText, key, iv, mode, pkcs7PaddingEnabled) {
if (mode === void 0) { mode = "aes-128-ctr"; }
if (pkcs7PaddingEnabled === void 0) { pkcs7PaddingEnabled = true; }
ensureAesMode(mode);
var decipher = crypto_1.createDecipheriv(mode, key, iv);
var decipher = browserifyAes.createDecipheriv(mode, key, iv);
decipher.setAutoPadding(pkcs7PaddingEnabled);

@@ -26,0 +35,0 @@ var encrypted = decipher.update(cypherText);

@@ -1,6 +0,6 @@

import * as keccakPure from "./pure/keccak";
export declare const keccak224: typeof keccakPure.keccak224;
export declare const keccak256: typeof keccakPure.keccak256;
export declare const keccak384: typeof keccakPure.keccak384;
export declare const keccak512: typeof keccakPure.keccak512;
/// <reference types="node" />
export declare const keccak224: (msg: Buffer) => Buffer;
export declare const keccak256: (msg: Buffer) => Buffer;
export declare const keccak384: (msg: Buffer) => Buffer;
export declare const keccak512: (msg: Buffer) => Buffer;
//# sourceMappingURL=keccak.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var keccakModule;
try {
// tslint:disable-next-line no-implicit-dependencies
keccakModule = require("ethereum-cryptography-native/keccak");
}
catch (_a) {
keccakModule = require("./pure/keccak");
}
exports.keccak224 = keccakModule.keccak224;
exports.keccak256 = keccakModule.keccak256;
exports.keccak384 = keccakModule.keccak384;
exports.keccak512 = keccakModule.keccak512;
var hash_utils_1 = require("./hash-utils");
var createKeccakHash = require("keccak");
exports.keccak224 = hash_utils_1.createHashFunction(function () {
return createKeccakHash("keccak224");
});
exports.keccak256 = hash_utils_1.createHashFunction(function () {
return createKeccakHash("keccak256");
});
exports.keccak384 = hash_utils_1.createHashFunction(function () {
return createKeccakHash("keccak384");
});
exports.keccak512 = hash_utils_1.createHashFunction(function () {
return createKeccakHash("keccak512");
});
//# sourceMappingURL=keccak.js.map
{
"name": "ethereum-cryptography",
"version": "0.0.7",
"version": "0.1.0",
"description": "All the cryptographic primitives used in Ethereum",

@@ -52,12 +52,6 @@ "contributors": [

"browser": {
"./keccak.js": "./pure/keccak.js",
"./scrypt.js": "./pure/scrypt.js",
"./pbkdf2.js": "./pure/pbkdf2.js",
"./ripemd160.js": "./pure/ripemd160.js",
"./secp256k1.js": "./pure/secp256k1.js",
"./sha256.js": "./pure/sha256.js",
"./aes.js": "./pure/aes.js",
"./hdkey.js": "./pure/hdkey.js",
"./blake2b.js": "./pure/blake2b.js",
"./random.js": "./pure/random.js",
"./bip39/index.js": "./pure/bip39/index.js"

@@ -68,7 +62,7 @@ },

"prepare": "npm run build",
"build": "npm-run-all build:tsc elliptic-secp256k1:build elliptic-secp256k1:copy scryptsy-without-crypto:build scryptsy-without-crypto:copy hdkey-without-crypto:build hdkey-without-crypto:copy bip39-without-wordlists:build bip39-without-wordlists:copy",
"build": "npm-run-all build:tsc hdkey-without-crypto:build hdkey-without-crypto:copy bip39-without-wordlists:build bip39-without-wordlists:copy",
"build:tsc": "tsc --project tsconfig.prod.json",
"test": "npm-run-all elliptic-secp256k1:build scryptsy-without-crypto:build hdkey-without-crypto:build bip39-without-wordlists:build test:node",
"test": "npm-run-all hdkey-without-crypto:build bip39-without-wordlists:build test:node",
"test:node": "mocha",
"clean": "rimraf vendor test-builds pure shims scryptsy-without-crypto-build hdkey-without-crypto-build bip39-without-wordlists-build '*.js' '*.js.map' '*.d.ts' '*.d.ts.map' 'src/**/*.js'",
"clean": "rimraf vendor test-builds pure shims hdkey-without-crypto-build bip39-without-wordlists-build bip39 '*.js' '*.js.map' '*.d.ts' '*.d.ts.map' 'src/**/*.js'",
"lint": "tslint --project tsconfig.json",

@@ -83,6 +77,2 @@ "lint:fix": "tslint --fix --project tsconfig.json",

"browser-tests:test-rollup": "karma start --single-run --browsers ChromeHeadless test/karma.rollup.conf.js",
"elliptic-secp256k1:build": "rollup -c elliptic-secp256k1-config/rollup.config.js",
"elliptic-secp256k1:copy": "mkdir -p vendor && cp src/vendor/elliptic-secp256k1.js ./vendor",
"scryptsy-without-crypto:build": "bash -x scripts/build-scryptsy-without-crypto.sh",
"scryptsy-without-crypto:copy": "mkdir -p vendor pure/vendor && cp src/vendor/scryptsy-without-crypto.js ./vendor && cp src/pure/vendor/scryptsy-without-crypto.js ./pure/vendor",
"hdkey-without-crypto:build": "bash -x scripts/build-hdkey-without-crypto.sh",

@@ -127,6 +117,4 @@ "hdkey-without-crypto:copy": "mkdir -p vendor pure/vendor && cp src/vendor/hdkey-without-crypto.js ./vendor && cp src/pure/vendor/hdkey-without-crypto.js ./pure/vendor",

"@types/pbkdf2": "^3.0.0",
"@types/secp256k1": "^3.5.0",
"bip66": "^1.1.5",
"@types/secp256k1": "^4.0.1",
"blakejs": "^1.1.0",
"bn.js": "^4.11.8",
"browserify-aes": "^1.2.0",

@@ -136,10 +124,11 @@ "bs58check": "^2.1.2",

"create-hmac": "^1.1.7",
"elliptic": "^6.4.1",
"hash.js": "^1.1.7",
"js-sha3": "^0.8.0",
"keccak": "^3.0.0",
"pbkdf2": "^3.0.17",
"randombytes": "^2.1.0",
"safe-buffer": "^5.1.2",
"scrypt-js": "^3.0.0",
"secp256k1": "^4.0.1",
"setimmediate": "^1.0.5"
}
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_1 = __importDefault(require("crypto"));
var pbkdf2Js = __importStar(require("pbkdf2"));
function pbkdf2(password, salt, iterations, keylen, digest) {
return new Promise(function (resolve, reject) {
crypto_1.default.pbkdf2(password, salt, iterations, keylen, digest, function (err, result) {
pbkdf2Js.pbkdf2(password, salt, iterations, keylen, digest, function (err, result) {
if (err) {

@@ -20,5 +24,5 @@ reject(err);

function pbkdf2Sync(password, salt, iterations, keylen, digest) {
return crypto_1.default.pbkdf2Sync(password, salt, iterations, keylen, digest);
return pbkdf2Js.pbkdf2Sync(password, salt, iterations, keylen, digest);
}
exports.pbkdf2Sync = pbkdf2Sync;
//# sourceMappingURL=pbkdf2.js.map
/// <reference types="node" />
export declare function ripemd160(msg: Buffer): Buffer;
export declare const ripemd160: (msg: Buffer) => Buffer;
//# sourceMappingURL=ripemd160.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Ripemd160 = require("hash.js/lib/hash/ripemd").ripemd160;
function ripemd160(msg) {
var hash = new Ripemd160();
hash.update(msg);
return Buffer.from(hash.digest());
}
exports.ripemd160 = ripemd160;
var hash_utils_1 = require("../hash-utils");
exports.ripemd160 = hash_utils_1.createHashFunction(function () { return new Ripemd160(); });
//# sourceMappingURL=ripemd160.js.map
/// <reference types="node" />
export declare function sha256(msg: Buffer): Buffer;
export declare const sha256: (msg: Buffer) => Buffer;
//# sourceMappingURL=sha256.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Sha256Hash = require("hash.js/lib/hash/sha/256");
function sha256(msg) {
var hash = new Sha256Hash();
hash.update(msg);
return Buffer.from(hash.digest());
}
exports.sha256 = sha256;
var hash_utils_1 = require("../hash-utils");
exports.sha256 = hash_utils_1.createHashFunction(function () { return new Sha256Hash(); });
//# sourceMappingURL=sha256.js.map

@@ -0,4 +1,13 @@

/// <reference types="node" />
export declare const createHmac: any;
export declare const createHash: any;
export declare const randomBytes: any;
declare class Hash {
private readonly hashFunction;
private buffers;
constructor(hashFunction: (msg: Buffer) => Buffer);
update(buffer: Buffer): this;
digest(param: any): Buffer;
}
export declare const createHash: (name: string) => Hash;
export {};
//# sourceMappingURL=hdkey-crypto.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ripemd160_1 = require("../ripemd160");
var sha256_1 = require("../sha256");
exports.createHmac = require("create-hmac");
exports.createHash = require("create-hash");
exports.randomBytes = require("randombytes");
var Hash = /** @class */ (function () {
function Hash(hashFunction) {
this.hashFunction = hashFunction;
this.buffers = [];
}
Hash.prototype.update = function (buffer) {
if (!Buffer.isBuffer(buffer)) {
throw new Error("hdkey-crypto shim is outdated");
}
this.buffers.push(buffer);
return this;
};
Hash.prototype.digest = function (param) {
if (param) {
throw new Error("hdkey-crypto shim is outdated");
}
return this.hashFunction(Buffer.concat(this.buffers));
};
return Hash;
}());
// We don't use create-hash here, as it doesn't work well with Rollup
exports.createHash = function (name) {
if (name === "ripemd160") {
return new Hash(ripemd160_1.ripemd160);
}
if (name === "sha256") {
return new Hash(sha256_1.sha256);
}
throw new Error("hdkey-crypto shim is outdated");
};
//# sourceMappingURL=hdkey-crypto.js.map

@@ -11,3 +11,3 @@ 'use strict';

var secp256k1Shim = require("../secp256k1");
var secp256k1Shim = require("../shims/hdkey-secp256k1v3");

@@ -144,3 +144,3 @@ var Buffer = safeBuffer.Buffer;

// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
return this.derive(index + 1)
return this.deriveChild(index + 1)
}

@@ -156,3 +156,3 @@ // Public parent key -> public child key

// In case parse256(IL) >= n or Ki is the point at infinity, one should proceed with the next value for i
return this.derive(index + 1, isHardened)
return this.deriveChild(index + 1)
}

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

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_1 = __importDefault(require("crypto"));
var randombytes = require("randombytes");
function getRandomBytes(bytes) {
return new Promise(function (resolve, reject) {
crypto_1.default.randomBytes(bytes, function (err, resp) {
randombytes(bytes, function (err, resp) {
if (err) {

@@ -20,5 +17,5 @@ reject(err);

function getRandomBytesSync(bytes) {
return crypto_1.default.randomBytes(bytes);
return randombytes(bytes);
}
exports.getRandomBytesSync = getRandomBytesSync;
//# sourceMappingURL=random.js.map

@@ -16,6 +16,4 @@ # ethereum-cryptography

In Node, it takes advantage of the built-in implementations when possible. To
improve performance of some primitives, you can install a
[second package](https://www.npmjs.com/package/ethereum-cryptography-native)
with native implementations that will be detected and used by this one.
In Node, it takes advantage of the built-in and N-API based implementations
whenever possible.

@@ -271,12 +269,11 @@ The cryptographic primitives included are:

This submodule works with different [block cipher modes of operation](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation).
To choose one of them, you should pass the `mode` parameter a string with the
same format as OpenSSL and Node use. You can take a look at them by running
`openssl list -cipher-algorithms`.
This submodule works with different [block cipher modes of operation](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation). If you are using this module in a new
application, we recommend using the default.
In Node, any mode that its OpenSSL version supports can be used.
While this module may work with any mode supported by OpenSSL, we only test it
with `aes-128-ctr`, `aes-128-cbc`, and `aes-256-cbc`. If you use another module
a warning will be printed in the console.
In the browser, we test it to work with the modes that are normally used in
Ethereum libraries and applications. Those are `aes-128-ctr`, `aes-126-cbc`, and
`aes-256-cbc`, but other modes may work.
We only recommend using `aes-128-cbc` and `aes-256-cbc` to decrypt already
encrypted data.

@@ -297,10 +294,34 @@ ### Padding plaintext messages

requires padding, `encrypt` will throw if your plaintext message isn't a
multiple of `16.
multiple of `16`.
This option is only present to enable the decryption of already encrypted data.
To encrypt new data, we recommend using the default.
### IV reusing
The `iv` parameter of the `encrypt` function must be unique, or the security
of the encryption algorithm can be compromissed.
You can generate a new `iv` using the `random` module.
Note that to decrypt a value, you have to provide the same `iv` used to encrypt
it.
### How to handle errors with this module
Sensitive information can be leaked via error messages when using this module.
To avoid this, you should make sure that the errors you return don't
contain the exact reason for the error. Instead, errors must report general
encryption/decryption failures.
Note that implementing this can mean catching all errors that can be thrown
when calling on of this module's functions, and just throwing a new generic
exception.
### Function types
```ts
function encrypt(msg: Buffer, key: Buffer, iv: Buffer, mode: string, pkcs7PaddingEnabled = true): Buffer;
function encrypt(msg: Buffer, key: Buffer, iv: Buffer, mode = "aes-128-ctr", pkcs7PaddingEnabled = true): Buffer;
function decrypt(cypherText: Buffer, key: Buffer, iv: Buffer, mode: string, pkcs7PaddingEnabled = true): Buffer
function decrypt(cypherText: Buffer, key: Buffer, iv: Buffer, mode = "aes-128-ctr", pkcs7PaddingEnabled = true): Buffer
```

@@ -317,4 +338,3 @@

Buffer.from("2b7e151628aed2a6abf7158809cf4f3c", "hex"),
Buffer.from("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", "hex"),
"aes-128-cbc"
Buffer.from("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", "hex")
).toString("hex")

@@ -329,15 +349,29 @@ );

It has the exact same API than the version `3.x` of the native module
[`secp256k1` from cryptocoinjs](https://github.com/cryptocoinjs/secp256k1-node),
but it's backed by [`elliptic`](https://www.npmjs.com/package/elliptic).
It has the exact same API than the version `4.x` of the [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node)
module from cryptocoinjs, with two added function to create private keys.
### Creating private keys
Secp256k1 private keys need to be cryptographycally secure random numbers with
certain caracteristics. If this is not the case, the security of Secp256k1 is
compromissed.
We strongly recommend to use this module to create new private keys.
### Function types
Go to [`secp256k1`'s documentation](https://github.com/cryptocoinjs/secp256k1-node)
to learn how to use it.
Functions to create private keys:
```ts
function createPrivateKey(): Promise<Uint8Array>;
function function createPrivateKeySync(): Uint8Array;
```
For the rest of the functions, pleasse read [`secp256k1`'s documentation](https://github.com/cryptocoinjs/secp256k1-node).
### Example usage
```js
const { sign } = require("ethereum-cryptography/secp256k1");
const { sign, createPrivateKeySync } = require("ethereum-cryptography/secp256k1");

@@ -349,8 +383,5 @@ const msgHash = Buffer.from(

const privateKey = Buffer.from(
"3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1",
"hex"
);
const privateKey = createPrivateKeySync();
console.log(sign(msgHash, privateKey).signature.toString("hex"));
console.log(Buffer.from(sign(msgHash, privateKey)).signature.toString("hex"));
```

@@ -487,17 +518,2 @@

## Opt-in native implementations (Node.js only)
If you are using this package in Node, you can install
[`ethereum-cryptography-native`](https://www.npmjs.com/package/ethereum-cryptography-native)
to opt-in to use native implementations of some of the cryptographic primitives
provided by this package.
No extra work is needed for this to work. This package will detect that
`ethereum-cryptography-native` is installed, and use it.
While installing `ethereum-cryptography-native` will generally improve the
performance of your application, we recommend leaving the decision of installing
it to your users. It has multiple native dependencies that need to be compiled,
and this can be problematic in some environments.
## Missing cryptographic primitives

@@ -504,0 +520,0 @@

/// <reference types="node" />
export declare function ripemd160(msg: Buffer): Buffer;
export declare const ripemd160: (msg: Buffer) => Buffer;
//# sourceMappingURL=ripemd160.d.ts.map

@@ -7,8 +7,6 @@ "use strict";

var crypto_1 = __importDefault(require("crypto"));
function ripemd160(msg) {
var hash = crypto_1.default.createHash("ripemd160");
hash.update(msg);
return Buffer.from(hash.digest());
}
exports.ripemd160 = ripemd160;
var hash_utils_1 = require("./hash-utils");
exports.ripemd160 = hash_utils_1.createHashFunction(function () {
return crypto_1.default.createHash("ripemd160");
});
//# sourceMappingURL=ripemd160.js.map

@@ -1,4 +0,5 @@

import * as scryptPure from "./pure/scrypt";
export declare const scrypt: typeof scryptPure.scrypt;
export declare const scryptSync: typeof scryptPure.scryptSync;
/// <reference types="node" />
import "scrypt-js/thirdparty/setImmediate";
export declare function scrypt(password: Buffer, salt: Buffer, n: number, p: number, r: number, dklen: number): Promise<Buffer>;
export declare function scryptSync(password: Buffer, salt: Buffer, n: number, p: number, r: number, dklen: number): Buffer;
//# sourceMappingURL=scrypt.d.ts.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var scryptModule;
try {
// tslint:disable-next-line no-implicit-dependencies
scryptModule = require("ethereum-cryptography-native/scrypt");
require("scrypt-js/thirdparty/setImmediate");
var scryptJs = require("scrypt-js");
function scrypt(password, salt, n, p, r, dklen) {
return __awaiter(this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_b = (_a = Buffer).from;
return [4 /*yield*/, scryptJs.scrypt(password, salt, n, r, p, dklen)];
case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
}
});
});
}
catch (_a) {
// This module is slightly more complicated, as we don't want to use the
// 100% pure version of scrypt if the native one isn't installed.
// We require this local version of scryptsy-without-crypto because it uses
// the built-in implementation of pbkdf2
var scryptsy_1 = require("./vendor/scryptsy-without-crypto");
scryptModule = {
scrypt: function (password, salt, n, p, r, dklen) {
return scryptsy_1.async(password, salt, n, r, p, dklen);
},
scryptSync: function (password, salt, n, p, r, dklen) {
return scryptsy_1(password, salt, n, r, p, dklen);
}
};
exports.scrypt = scrypt;
function scryptSync(password, salt, n, p, r, dklen) {
return Buffer.from(scryptJs.syncScrypt(password, salt, n, r, p, dklen));
}
exports.scrypt = scryptModule.scrypt;
exports.scryptSync = scryptModule.scryptSync;
exports.scryptSync = scryptSync;
//# sourceMappingURL=scrypt.js.map

@@ -1,23 +0,4 @@

export declare const privateKeyVerify: typeof import("secp256k1").privateKeyVerify;
export declare const privateKeyExport: typeof import("secp256k1").privateKeyExport;
export declare const privateKeyImport: typeof import("secp256k1").privateKeyImport;
export declare const privateKeyNegate: typeof import("secp256k1").privateKeyNegate;
export declare const privateKeyModInverse: typeof import("secp256k1").privateKeyModInverse;
export declare const privateKeyTweakAdd: typeof import("secp256k1").privateKeyTweakAdd;
export declare const privateKeyTweakMul: typeof import("secp256k1").privateKeyTweakMul;
export declare const publicKeyCreate: typeof import("secp256k1").publicKeyCreate;
export declare const publicKeyConvert: typeof import("secp256k1").publicKeyConvert;
export declare const publicKeyVerify: typeof import("secp256k1").publicKeyVerify;
export declare const publicKeyTweakAdd: typeof import("secp256k1").publicKeyTweakAdd;
export declare const publicKeyTweakMul: typeof import("secp256k1").publicKeyTweakMul;
export declare const publicKeyCombine: typeof import("secp256k1").publicKeyCombine;
export declare const signatureNormalize: typeof import("secp256k1").signatureNormalize;
export declare const signatureExport: typeof import("secp256k1").signatureExport;
export declare const signatureImport: typeof import("secp256k1").signatureImport;
export declare const signatureImportLax: typeof import("secp256k1").signatureImportLax;
export declare const sign: typeof import("secp256k1").sign;
export declare const verify: typeof import("secp256k1").verify;
export declare const recover: typeof import("secp256k1").recover;
export declare const ecdh: typeof import("secp256k1").ecdh;
export declare const ecdhUnsafe: typeof import("secp256k1").ecdhUnsafe;
export declare function createPrivateKey(): Promise<Uint8Array>;
export declare function createPrivateKeySync(): Uint8Array;
export * from "secp256k1";
//# sourceMappingURL=secp256k1.d.ts.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var secp256k1Module;
try {
// tslint:disable-next-line no-implicit-dependencies
secp256k1Module = require("ethereum-cryptography-native/secp256k1");
var secp256k1_1 = require("secp256k1");
var random_1 = require("./random");
var SECP256K1_PRIVATE_KEY_SIZE = 32;
function createPrivateKey() {
return __awaiter(this, void 0, void 0, function () {
var pk;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!true) return [3 /*break*/, 2];
return [4 /*yield*/, random_1.getRandomBytes(SECP256K1_PRIVATE_KEY_SIZE)];
case 1:
pk = _a.sent();
if (secp256k1_1.privateKeyVerify(pk)) {
return [2 /*return*/, pk];
}
return [3 /*break*/, 0];
case 2: return [2 /*return*/];
}
});
});
}
catch (_a) {
secp256k1Module = require("./pure/secp256k1");
exports.createPrivateKey = createPrivateKey;
function createPrivateKeySync() {
while (true) {
var pk = random_1.getRandomBytesSync(SECP256K1_PRIVATE_KEY_SIZE);
if (secp256k1_1.privateKeyVerify(pk)) {
return pk;
}
}
}
exports.privateKeyVerify = secp256k1Module.privateKeyVerify;
exports.privateKeyExport = secp256k1Module.privateKeyExport;
exports.privateKeyImport = secp256k1Module.privateKeyImport;
exports.privateKeyNegate = secp256k1Module.privateKeyNegate;
exports.privateKeyModInverse = secp256k1Module.privateKeyModInverse;
exports.privateKeyTweakAdd = secp256k1Module.privateKeyTweakAdd;
exports.privateKeyTweakMul = secp256k1Module.privateKeyTweakMul;
exports.publicKeyCreate = secp256k1Module.publicKeyCreate;
exports.publicKeyConvert = secp256k1Module.publicKeyConvert;
exports.publicKeyVerify = secp256k1Module.publicKeyVerify;
exports.publicKeyTweakAdd = secp256k1Module.publicKeyTweakAdd;
exports.publicKeyTweakMul = secp256k1Module.publicKeyTweakMul;
exports.publicKeyCombine = secp256k1Module.publicKeyCombine;
exports.signatureNormalize = secp256k1Module.signatureNormalize;
exports.signatureExport = secp256k1Module.signatureExport;
exports.signatureImport = secp256k1Module.signatureImport;
exports.signatureImportLax = secp256k1Module.signatureImportLax;
exports.sign = secp256k1Module.sign;
exports.verify = secp256k1Module.verify;
exports.recover = secp256k1Module.recover;
exports.ecdh = secp256k1Module.ecdh;
exports.ecdhUnsafe = secp256k1Module.ecdhUnsafe;
exports.createPrivateKeySync = createPrivateKeySync;
__export(require("secp256k1"));
//# sourceMappingURL=secp256k1.js.map
/// <reference types="node" />
export declare function sha256(msg: Buffer): Buffer;
export declare const sha256: (msg: Buffer) => Buffer;
//# sourceMappingURL=sha256.d.ts.map

@@ -7,8 +7,4 @@ "use strict";

var crypto_1 = __importDefault(require("crypto"));
function sha256(msg) {
var hash = crypto_1.default.createHash("sha256");
hash.update(msg);
return Buffer.from(hash.digest());
}
exports.sha256 = sha256;
var hash_utils_1 = require("./hash-utils");
exports.sha256 = hash_utils_1.createHashFunction(function () { return crypto_1.default.createHash("sha256"); });
//# sourceMappingURL=sha256.js.map

@@ -1,2 +0,2 @@

export { createHmac, createHash, randomBytes } from "crypto";
export { createHash, createHmac, randomBytes } from "crypto";
//# sourceMappingURL=hdkey-crypto.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_1 = require("crypto");
exports.createHash = crypto_1.createHash;
exports.createHmac = crypto_1.createHmac;
exports.createHash = crypto_1.createHash;
exports.randomBytes = crypto_1.randomBytes;
//# sourceMappingURL=hdkey-crypto.js.map

@@ -1,3 +0,5 @@

import { createCipheriv, createDecipheriv } from "crypto";
const browserifyAes = require("browserify-aes");
const SUPPORTED_MODES = ["aes-128-ctr", "aes-128-cbc", "aes-256-cbc"];
function ensureAesMode(mode: string) {

@@ -9,2 +11,9 @@ if (!mode.startsWith("aes-")) {

function warnIfUnsuportedMode(mode: string) {
if (!SUPPORTED_MODES.includes(mode)) {
// tslint:disable-next-line no-console
console.warn("Using an unsupported AES mode. Consider using aes-128-ctr.");
}
}
export function encrypt(

@@ -14,3 +23,3 @@ msg: Buffer,

iv: Buffer,
mode: string,
mode = "aes-128-ctr",
pkcs7PaddingEnabled = true

@@ -20,3 +29,3 @@ ): Buffer {

const cipher = createCipheriv(mode, key, iv);
const cipher = browserifyAes.createCipheriv(mode, key, iv);
cipher.setAutoPadding(pkcs7PaddingEnabled);

@@ -34,3 +43,3 @@

iv: Buffer,
mode: string,
mode = "aes-128-ctr",
pkcs7PaddingEnabled = true

@@ -40,3 +49,3 @@ ): Buffer {

const decipher = createDecipheriv(mode, key, iv);
const decipher = browserifyAes.createDecipheriv(mode, key, iv);
decipher.setAutoPadding(pkcs7PaddingEnabled);

@@ -43,0 +52,0 @@

@@ -1,15 +0,19 @@

import * as keccakPure from "./pure/keccak";
import { createHashFunction } from "./hash-utils";
let keccakModule: typeof keccakPure;
const createKeccakHash = require("keccak");
try {
// tslint:disable-next-line no-implicit-dependencies
keccakModule = require("ethereum-cryptography-native/keccak");
} catch {
keccakModule = require("./pure/keccak");
}
export const keccak224 = createHashFunction(() =>
createKeccakHash("keccak224")
);
export const keccak224 = keccakModule.keccak224;
export const keccak256 = keccakModule.keccak256;
export const keccak384 = keccakModule.keccak384;
export const keccak512 = keccakModule.keccak512;
export const keccak256 = createHashFunction(() =>
createKeccakHash("keccak256")
);
export const keccak384 = createHashFunction(() =>
createKeccakHash("keccak384")
);
export const keccak512 = createHashFunction(() =>
createKeccakHash("keccak512")
);

@@ -1,2 +0,2 @@

import crypto from "crypto";
import * as pbkdf2Js from "pbkdf2";

@@ -11,10 +11,17 @@ export function pbkdf2(

return new Promise((resolve, reject) => {
crypto.pbkdf2(password, salt, iterations, keylen, digest, (err, result) => {
if (err) {
reject(err);
return;
pbkdf2Js.pbkdf2(
password,
salt,
iterations,
keylen,
digest,
(err, result) => {
if (err) {
reject(err);
return;
}
resolve(result);
}
resolve(result);
});
);
});

@@ -30,3 +37,3 @@ }

): Buffer {
return crypto.pbkdf2Sync(password, salt, iterations, keylen, digest);
return pbkdf2Js.pbkdf2Sync(password, salt, iterations, keylen, digest);
}
const { ripemd160: Ripemd160 } = require("hash.js/lib/hash/ripemd");
export function ripemd160(msg: Buffer): Buffer {
const hash = new Ripemd160();
hash.update(msg);
import { createHashFunction } from "../hash-utils";
return Buffer.from(hash.digest());
}
export const ripemd160 = createHashFunction(() => new Ripemd160());
const Sha256Hash = require("hash.js/lib/hash/sha/256");
export function sha256(msg: Buffer): Buffer {
const hash = new Sha256Hash();
hash.update(msg);
import { createHashFunction } from "../hash-utils";
return Buffer.from(hash.digest());
}
export const sha256 = createHashFunction(() => new Sha256Hash());

@@ -0,3 +1,42 @@

import { ripemd160 } from "../ripemd160";
import { sha256 } from "../sha256";
export const createHmac = require("create-hmac");
export const createHash = require("create-hash");
export const randomBytes = require("randombytes");
class Hash {
private buffers: Buffer[] = [];
constructor(private readonly hashFunction: (msg: Buffer) => Buffer) {}
public update(buffer: Buffer): this {
if (!Buffer.isBuffer(buffer)) {
throw new Error("hdkey-crypto shim is outdated");
}
this.buffers.push(buffer);
return this;
}
public digest(param: any): Buffer {
if (param) {
throw new Error("hdkey-crypto shim is outdated");
}
return this.hashFunction(Buffer.concat(this.buffers));
}
}
// We don't use create-hash here, as it doesn't work well with Rollup
export const createHash = (name: string) => {
if (name === "ripemd160") {
return new Hash(ripemd160);
}
if (name === "sha256") {
return new Hash(sha256);
}
throw new Error("hdkey-crypto shim is outdated");
};

@@ -11,3 +11,3 @@ 'use strict';

var secp256k1Shim = require("../secp256k1");
var secp256k1Shim = require("../shims/hdkey-secp256k1v3");

@@ -144,3 +144,3 @@ var Buffer = safeBuffer.Buffer;

// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
return this.derive(index + 1)
return this.deriveChild(index + 1)
}

@@ -156,3 +156,3 @@ // Public parent key -> public child key

// In case parse256(IL) >= n or Ki is the point at infinity, one should proceed with the next value for i
return this.derive(index + 1, isHardened)
return this.deriveChild(index + 1)
}

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

@@ -1,6 +0,6 @@

import crypto from "crypto";
const randombytes = require("randombytes");
export function getRandomBytes(bytes: number): Promise<Buffer> {
return new Promise((resolve, reject) => {
crypto.randomBytes(bytes, function(err: any, resp: Buffer) {
randombytes(bytes, function(err: any, resp: Buffer) {
if (err) {

@@ -17,3 +17,3 @@ reject(err);

export function getRandomBytesSync(bytes: number): Buffer {
return crypto.randomBytes(bytes);
return randombytes(bytes);
}
import crypto from "crypto";
export function ripemd160(msg: Buffer): Buffer {
const hash = crypto.createHash("ripemd160");
hash.update(msg);
return Buffer.from(hash.digest());
}
import { createHashFunction } from "./hash-utils";
export const ripemd160 = createHashFunction(() =>
crypto.createHash("ripemd160")
);

@@ -1,41 +0,24 @@

import * as scryptPure from "./pure/scrypt";
import "scrypt-js/thirdparty/setImmediate";
const scryptJs = require("scrypt-js");
let scryptModule: typeof scryptPure;
export async function scrypt(
password: Buffer,
salt: Buffer,
n: number,
p: number,
r: number,
dklen: number
): Promise<Buffer> {
return Buffer.from(await scryptJs.scrypt(password, salt, n, r, p, dklen));
}
try {
// tslint:disable-next-line no-implicit-dependencies
scryptModule = require("ethereum-cryptography-native/scrypt");
} catch {
// This module is slightly more complicated, as we don't want to use the
// 100% pure version of scrypt if the native one isn't installed.
// We require this local version of scryptsy-without-crypto because it uses
// the built-in implementation of pbkdf2
const scryptsy = require("./vendor/scryptsy-without-crypto");
scryptModule = {
scrypt(
password: Buffer,
salt: Buffer,
n: number,
p: number,
r: number,
dklen: number
): Promise<Buffer> {
return scryptsy.async(password, salt, n, r, p, dklen);
},
scryptSync(
password: Buffer,
salt: Buffer,
n: number,
p: number,
r: number,
dklen: number
): Buffer {
return scryptsy(password, salt, n, r, p, dklen);
}
};
export function scryptSync(
password: Buffer,
salt: Buffer,
n: number,
p: number,
r: number,
dklen: number
): Buffer {
return Buffer.from(scryptJs.syncScrypt(password, salt, n, r, p, dklen));
}
export const scrypt = scryptModule.scrypt;
export const scryptSync = scryptModule.scryptSync;

@@ -1,33 +0,24 @@

import * as secp256k1Pure from "./pure/secp256k1";
import { privateKeyVerify } from "secp256k1";
import { getRandomBytes, getRandomBytesSync } from "./random";
let secp256k1Module: typeof secp256k1Pure;
const SECP256K1_PRIVATE_KEY_SIZE = 32;
try {
// tslint:disable-next-line no-implicit-dependencies
secp256k1Module = require("ethereum-cryptography-native/secp256k1");
} catch {
secp256k1Module = require("./pure/secp256k1");
export async function createPrivateKey(): Promise<Uint8Array> {
while (true) {
const pk = await getRandomBytes(SECP256K1_PRIVATE_KEY_SIZE);
if (privateKeyVerify(pk)) {
return pk;
}
}
}
export const privateKeyVerify = secp256k1Module.privateKeyVerify;
export const privateKeyExport = secp256k1Module.privateKeyExport;
export const privateKeyImport = secp256k1Module.privateKeyImport;
export const privateKeyNegate = secp256k1Module.privateKeyNegate;
export const privateKeyModInverse = secp256k1Module.privateKeyModInverse;
export const privateKeyTweakAdd = secp256k1Module.privateKeyTweakAdd;
export const privateKeyTweakMul = secp256k1Module.privateKeyTweakMul;
export const publicKeyCreate = secp256k1Module.publicKeyCreate;
export const publicKeyConvert = secp256k1Module.publicKeyConvert;
export const publicKeyVerify = secp256k1Module.publicKeyVerify;
export const publicKeyTweakAdd = secp256k1Module.publicKeyTweakAdd;
export const publicKeyTweakMul = secp256k1Module.publicKeyTweakMul;
export const publicKeyCombine = secp256k1Module.publicKeyCombine;
export const signatureNormalize = secp256k1Module.signatureNormalize;
export const signatureExport = secp256k1Module.signatureExport;
export const signatureImport = secp256k1Module.signatureImport;
export const signatureImportLax = secp256k1Module.signatureImportLax;
export const sign = secp256k1Module.sign;
export const verify = secp256k1Module.verify;
export const recover = secp256k1Module.recover;
export const ecdh = secp256k1Module.ecdh;
export const ecdhUnsafe = secp256k1Module.ecdhUnsafe;
export function createPrivateKeySync(): Uint8Array {
while (true) {
const pk = getRandomBytesSync(SECP256K1_PRIVATE_KEY_SIZE);
if (privateKeyVerify(pk)) {
return pk;
}
}
}
export * from "secp256k1";
import crypto from "crypto";
export function sha256(msg: Buffer): Buffer {
const hash = crypto.createHash("sha256");
hash.update(msg);
return Buffer.from(hash.digest());
}
import { createHashFunction } from "./hash-utils";
export const sha256 = createHashFunction(() => crypto.createHash("sha256"));

@@ -1,1 +0,1 @@

export { createHmac, createHash, randomBytes } from "crypto";
export { createHash, createHmac, randomBytes } from "crypto";

@@ -11,3 +11,3 @@ 'use strict';

var secp256k1Shim = require("../secp256k1");
var secp256k1Shim = require("../shims/hdkey-secp256k1v3");

@@ -144,3 +144,3 @@ var Buffer = safeBuffer.Buffer;

// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
return this.derive(index + 1)
return this.deriveChild(index + 1)
}

@@ -156,3 +156,3 @@ // Public parent key -> public child key

// In case parse256(IL) >= n or Ki is the point at infinity, one should proceed with the next value for i
return this.derive(index + 1, isHardened)
return this.deriveChild(index + 1)
}

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

@@ -11,3 +11,3 @@ 'use strict';

var secp256k1Shim = require("../secp256k1");
var secp256k1Shim = require("../shims/hdkey-secp256k1v3");

@@ -144,3 +144,3 @@ var Buffer = safeBuffer.Buffer;

// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
return this.derive(index + 1)
return this.deriveChild(index + 1)
}

@@ -156,3 +156,3 @@ // Public parent key -> public child key

// In case parse256(IL) >= n or Ki is the point at infinity, one should proceed with the next value for i
return this.derive(index + 1, isHardened)
return this.deriveChild(index + 1)
}

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

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

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

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

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