Socket
Socket
Sign inDemoInstall

ganache-cli

Package Overview
Dependencies
844
Maintainers
7
Versions
88
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.12.0 to 6.12.1-tezos.0

lib.js

60

args.js

@@ -0,11 +1,27 @@

module.exports = exports = function(yargs, version, isDocker) {
const getFlavor = () => {
return yargs
.strict(false)
.showHelpOnFail(false)
.help(false)
.option("flavor", {default: "ethereum"})
.parse(process.argv).flavor;
}
return yargs
.strict()
.option("flavor", {
describe: "Ethereum or Tezos flavored ganache",
choices: ["ethereum", "tezos"],
default: "ethereum"
})
.option('p', {
group: 'Network:',
alias: 'port',
type: 'number',
default: 8545,
describe: 'Port number to listen on'
})
group: 'Network:',
alias: 'port',
type: 'number',
describe: 'Port number to listen on',
default: () => {
return getFlavor() === "tezos" ? 8732 : 8545
}
})
.option('h', {

@@ -24,2 +40,9 @@ group: 'Network:',

})
.option('gbh', {
group: 'Network:',
alias: 'genesisBlockHash',
type: 'string',
demandOption: false,
describe: 'The chain_id is computed from the hash of the Genesis block.'
})
.option('a', {

@@ -34,4 +57,4 @@ group: 'Accounts:',

group: 'Accounts:',
alias: 'defaultBalanceEther',
describe: 'Amount of ether to assign each test account',
alias: ['defaultBalanceEther', 'defaultBalance', 'defaultBalanceTez'],
describe: 'Amount of value to assign each test account',
type: 'number',

@@ -75,3 +98,3 @@ default: 100.0

type: 'string',
describe: "Allows users to specify which hardfork should be used. Supported hardforks are `byzantium`, `constantinople`, `petersburg`, `istanbul` and `muirGlacier` (default).",
describe: "Allows users to specify which hardfork should be used. Supported Ethereum hardforks are `byzantium`, `constantinople`, `petersburg`, `istanbul` and `muirGlacier` (default). And for Tezos `carthage`, `edo`, and `delphi` (default)",
default: "muirGlacier"

@@ -86,8 +109,2 @@ })

})
.option('forkCacheSize', {
group: 'Chain:',
type: 'number',
describe: "The maximum size, in bytes, of the in-memory cache for queries on a chain fork. Defaults to `1_073_741_824` bytes (1 gigabyte). You can set this to `0` to disable caching (not recommended), or to `-1` for unlimited (will be limited by your node process).",
default: 1073741824
})
.option('db', {

@@ -153,9 +170,2 @@ group: 'Chain:',

})
.option('chainId', {
group: 'Chain:',
type: 'number',
describe: "The Chain ID ganache-cli will use for `eth_chainId` RPC and the `CHAINID` opcode.",
defaultDescription: "For legacy reasons, the default is currently `1337` for `eth_chainId` RPC and `1` for the `CHAINID` opcode. This will be fixed in the next major version of ganache-cli and ganache-core!",
demandOption: false
})
.option('g', {

@@ -226,2 +236,8 @@ group: 'Chain:',

})
.option('deasync', {
group: 'Other::',
describe: 'Synchronize ganache server startup. Useful in certain scenarios (see ganache-cli issue #733).',
type: 'boolean',
default: false
})
.showHelpOnFail(false, 'Specify -? or --help for available options')

@@ -228,0 +244,0 @@ .help('help')

@@ -6,5 +6,2 @@ #!/usr/bin/env node

var yargs = require("yargs");
var pkg = require("./package.json");
var {toChecksumAddress, BN} = require("ethereumjs-util");
var ganache;

@@ -16,10 +13,99 @@ try {

}
var to = ganache.to;
var initArgs = require("./args")
let server;
let started = false;
process.on("uncaughtException", function(e) {
if (started) {
console.log(e);
} else {
console.log(e.stack);
}
process.exit(1);
})
// See http://stackoverflow.com/questions/10021373/what-is-the-windows-equivalent-of-process-onsigint-in-node-js
if (process.platform === "win32") {
require("readline").createInterface({
input: process.stdin,
output: process.stdout
})
.on("SIGINT", function () {
process.emit("SIGINT");
});
}
const closeHandler = function () {
// graceful shutdown
server && server.close(function(err) {
if (err) {
// https://nodejs.org/api/process.html#process_process_exit_code
// writes to process.stdout in Node.js are sometimes asynchronous and may occur over
// multiple ticks of the Node.js event loop. Calling process.exit(), however, forces
// the process to exit before those additional writes to stdout can be performed.
if(process.stdout._handle) process.stdout._handle.setBlocking(true);
console.log(err.stack || err);
process.exit();
} else {
process.exit(0);
}
});
}
process.on("SIGINT", closeHandler);
process.on("SIGTERM", closeHandler);
process.on("SIGHUP", closeHandler);
var yargs = require("yargs");
var pkg = require("./package.json");
var {toChecksumAddress, BN} = require("ethereumjs-util");
var detailedVersion = "Ganache CLI v" + pkg.version + " (ganache-core: " + ganache.version + ")";
const { promisify } = require("util");
var initArgs = require("./args")
var isDocker = "DOCKER" in process.env && process.env.DOCKER.toLowerCase() === "true";
var argv = initArgs(yargs, detailedVersion, isDocker).argv;
if (argv.flavor === "tezos") {
console.log(detailedVersion);
// if the deterministic flag is set, use "tim" as the seed.
if (argv.d) {
argv.seed = "tim";
}
server = ganache.server({
defaultBalance: argv.defaultBalance,
flavor: argv.flavor,
seed: argv.seed,
accounts: argv.accounts,
genesisBlockHash: argv.genesisBlockHash,
protocol: argv.hardfork,
logger: console,
});
promisify(server.listen.bind(server))(argv.port, argv.host).then((flextesa) => {
started = true;
console.log("");
console.log("Listening on " + argv.host + ":" + argv.port);
flextesa.on("close", (code) =>{
process.exit(code)
})
}).catch(e => {
throw e;
});
return;
} else if (argv.flavor !== "ethereum") {
throw new Error("Valid flavors are \"ethereum\" or \"tezos\".");
}
var to = ganache.to;
var deasync;
try {
deasync = argv.deasync ? require("deasync") : false;
} catch(e) {
deasync = false;
}
function parseAccounts(accounts) {

@@ -90,3 +176,2 @@ function splitAccount(account) {

fork: argv.f,
forkCacheSize: argv.forkCacheSize,
hardfork: argv.k,

@@ -103,54 +188,10 @@ network_id: argv.i,

time: argv.t,
keepAliveTimeout: argv.keepAliveTimeout,
_chainId: argv.chainId,
// gross!
_chainIdRpc: argv.chainId
keepAliveTimeout: argv.keepAliveTimeout
}
var server = ganache.server(options);
var fork_address;
server = ganache.server(options);
console.log(detailedVersion);
let started = false;
process.on("uncaughtException", function(e) {
if (started) {
console.log(e);
} else {
console.log(e.stack);
}
process.exit(1);
})
// See http://stackoverflow.com/questions/10021373/what-is-the-windows-equivalent-of-process-onsigint-in-node-js
if (process.platform === "win32") {
require("readline").createInterface({
input: process.stdin,
output: process.stdout
})
.on("SIGINT", function () {
process.emit("SIGINT");
});
}
const closeHandler = function () {
// graceful shutdown
server.close(function(err) {
if (err) {
// https://nodejs.org/api/process.html#process_process_exit_code
// writes to process.stdout in Node.js are sometimes asynchronous and may occur over
// multiple ticks of the Node.js event loop. Calling process.exit(), however, forces
// the process to exit before those additional writes to stdout can be performed.
if(process.stdout._handle) process.stdout._handle.setBlocking(true);
console.log(err.stack || err);
process.exit();
} else {
process.exit(0);
}
});
}
process.on("SIGINT", closeHandler);
process.on("SIGTERM", closeHandler);
process.on("SIGHUP", closeHandler);
function startGanache(err, result) {

@@ -232,13 +273,6 @@ if (err) {

console.log("==================");
console.log("Location: " + state.blockchain.options.fork);
console.log("Block: " + to.number(state.blockchain.forkBlockNumber));
console.log("Network ID: " + state.net_version);
console.log("Time: " + (state.blockchain.startTime || new Date()).toString());
let maxCacheSize;
if (options.forkCacheSize === -1) {
maxCacheSize = "∞";
} else {
maxCacheSize = options.forkCacheSize + " bytes";
}
console.log("Max Cache Size: " + maxCacheSize);
console.log("Location: " + fork_address);
console.log("Block: " + to.number(state.blockchain.forkBlockNumber));
console.log("Network ID: " + state.net_version);
console.log("Time: " + (state.blockchain.startTime || new Date()).toString());
}

@@ -250,2 +284,8 @@

server.listen(options.port, options.hostname, startGanache);
if (deasync) {
const listen = deasync(server.listen);
const result = listen(options.port, options.hostname);
startGanache(null, result);
} else {
server.listen(options.port, options.hostname, startGanache);
}

@@ -35,8 +35,2 @@ 'use strict';

var octetLen = initial & 0xf;
// Indefinite length or overflow
if (octetLen === 0 || octetLen > 4) {
return false;
}
var val = 0;

@@ -46,10 +40,3 @@ for (var i = 0, off = p.place; i < octetLen; i++, off++) {

val |= buf[off];
val >>>= 0;
}
// Leading zeroes
if (val <= 0x7f) {
return false;
}
p.place = off;

@@ -78,5 +65,2 @@ return val;

var len = getLength(data, p);
if (len === false) {
return false;
}
if ((len + p.place) !== data.length) {

@@ -89,5 +73,2 @@ return false;

var rlen = getLength(data, p);
if (rlen === false) {
return false;
}
var r = data.slice(p.place, rlen + p.place);

@@ -99,5 +80,2 @@ p.place += rlen;

var slen = getLength(data, p);
if (slen === false) {
return false;
}
if (data.length !== slen + p.place) {

@@ -107,17 +85,7 @@ return false;

var s = data.slice(p.place, slen + p.place);
if (r[0] === 0) {
if (r[1] & 0x80) {
r = r.slice(1);
} else {
// Leading zeroes
return false;
}
if (r[0] === 0 && (r[1] & 0x80)) {
r = r.slice(1);
}
if (s[0] === 0) {
if (s[1] & 0x80) {
s = s.slice(1);
} else {
// Leading zeroes
return false;
}
if (s[0] === 0 && (s[1] & 0x80)) {
s = s.slice(1);
}

@@ -124,0 +92,0 @@

{
"name": "elliptic",
"version": "6.5.3",
"version": "6.5.2",
"description": "EC cryptography",

@@ -59,5 +59,5 @@ "main": "lib/elliptic.js",

,"_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz"
,"_integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw=="
,"_from": "elliptic@6.5.3"
,"_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.2.tgz"
,"_integrity": "sha512-f4x70okzZbIQl/NSRLkI/+tteV/9WqL98zx+SQ69KbXxmVrmjwsNUPn/gYJJ0sHvEak24cZgHIPegRePAtA/xw=="
,"_from": "elliptic@6.5.2"
}

@@ -9,60 +9,2 @@ # Changelog

## [6.2.1] - 2020-07-17
This release replaces the native `secp256k1` and `keccak` dependencies with
[ethereum-cryptopgraphy](https://github.com/ethereum/js-ethereum-cryptography)
which doesn't need native compilation.
[6.2.1]: https://github.com/ethereumjs/ethereumjs-util/compare/v6.2.0...v6.2.1
## [6.2.0] - 2019-11-06
This release comes with a new file structure, related functionality is now broken
down into separate files (like `account.js`) allowing for more oversight and
modular integration. All functionality is additionally exposed through an
aggregating `index.js` file, so this version remains backwards-compatible.
Overview on the new structure:
- `account`: Private/public key and address-related functionality
(creation, validation, conversion)
- `byte`: Byte-related helper and conversion functions
- `constants`: Exposed constants (e.g. `KECCAK256_NULL_S` for the string
representation of the Keccak-256 hash of null)
- `hash`: Hash functions
- `object`: Helper function for creating a binary object (`DEPRECATED`)
- `signature`: Signing, signature validation, conversion, recovery
See associated PRs [#182](https://github.com/ethereumjs/ethereumjs-util/pull/182)
and [#179](https://github.com/ethereumjs/ethereumjs-util/pull/179).
**Features**
- `account`: Added `EIP-1191` address checksum algorithm support for
`toChecksumAddress()`,
PR [#204](https://github.com/ethereumjs/ethereumjs-util/pull/204)
**Bug Fixes**
- `bytes`: `toBuffer()` conversion function now throws if strings aren't
`0x`-prefixed hex values making the behavior of `toBuffer()` more predictable
respectively less error-prone (you might generally want to check cases in your
code where you eventually allowed non-`0x`-prefixed input before),
PR [#197](https://github.com/ethereumjs/ethereumjs-util/pull/197)
**Dependencies / Environment**
- Dropped Node `6`, added Node `11` and `12` to officially supported Node versions,
PR [#207](https://github.com/ethereumjs/ethereumjs-util/pull/207)
- Dropped `safe-buffer` dependency,
PR [#182](https://github.com/ethereumjs/ethereumjs-util/pull/182)
- Updated `rlp` dependency from `v2.0.0` to `v2.2.3` (`TypeScript` improvements
for RLP hash functionality),
PR [#187](https://github.com/ethereumjs/ethereumjs-util/pull/187)
- Made `@types/bn.js` a `dependency` instead of a `devDependency`,
PR [#205](https://github.com/ethereumjs/ethereumjs-util/pull/205)
- Updated `keccak256` dependency from `v1.4.0` to `v2.0.0`, PR [#168](https://github.com/ethereumjs/ethereumjs-util/pull/168)
[6.2.0]: https://github.com/ethereumjs/ethereumjs-util/compare/v6.1.0...v6.2.0
## [6.1.0] - 2019-02-12

@@ -69,0 +11,0 @@

@@ -1,5 +0,42 @@

declare const secp256k1: any;
import BN = require('bn.js');
import rlp = require('rlp');
declare const secp256k1: any;
export interface ECDSASignature {
v: number;
r: Buffer;
s: Buffer;
}
/**
* The max integer that this VM can handle
*/
export declare const MAX_INTEGER: BN;
/**
* 2^256
*/
export declare const TWO_POW256: BN;
/**
* Keccak-256 hash of null
*/
export declare const KECCAK256_NULL_S: string;
/**
* Keccak-256 hash of null
*/
export declare const KECCAK256_NULL: Buffer;
/**
* Keccak-256 of an RLP of an empty array
*/
export declare const KECCAK256_RLP_ARRAY_S: string;
/**
* Keccak-256 of an RLP of an empty array
*/
export declare const KECCAK256_RLP_ARRAY: Buffer;
/**
* Keccak-256 hash of the RLP of null
*/
export declare const KECCAK256_RLP_S: string;
/**
* Keccak-256 hash of the RLP of null
*/
export declare const KECCAK256_RLP: Buffer;
/**
* [`BN`](https://github.com/indutny/bn.js)

@@ -17,24 +54,205 @@ */

/**
* Constants
* Returns a buffer filled with 0s.
* @param bytes the number of bytes the buffer should be
*/
export * from './constants';
export declare const zeros: (bytes: number) => Buffer;
/**
* Public-key cryptography (secp256k1) and addresses
* Returns a zero address.
*/
export * from './account';
export declare const zeroAddress: () => string;
/**
* Hash functions
* Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.
* Or it truncates the beginning if it exceeds.
* @param msg the value to pad (Buffer|Array)
* @param length the number of bytes the output should be
* @param right whether to start padding form the left or right
* @return (Buffer|Array)
*/
export * from './hash';
export declare const setLengthLeft: (msg: any, length: number, right?: boolean) => any;
export declare const setLength: (msg: any, length: number, right?: boolean) => any;
/**
* ECDSA signature
* Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.
* Or it truncates the beginning if it exceeds.
* @param msg the value to pad (Buffer|Array)
* @param length the number of bytes the output should be
* @return (Buffer|Array)
*/
export * from './signature';
export declare const setLengthRight: (msg: any, length: number) => any;
/**
* Utilities for manipulating Buffers, byte arrays, etc.
* Trims leading zeros from a `Buffer` or an `Array`.
* @param a (Buffer|Array|String)
* @return (Buffer|Array|String)
*/
export * from './bytes';
export declare const unpad: (a: any) => any;
export declare const stripZeros: (a: any) => any;
/**
* Function for definining properties on an object
* Attempts to turn a value into a `Buffer`. As input it supports `Buffer`, `String`, `Number`, null/undefined, `BN` and other objects with a `toArray()` method.
* @param v the value
*/
export * from './object';
export declare const toBuffer: (v: any) => Buffer;
/**
* Converts a `Buffer` to a `Number`.
* @param buf `Buffer` object to convert
* @throws If the input number exceeds 53 bits.
*/
export declare const bufferToInt: (buf: Buffer) => number;
/**
* Converts a `Buffer` into a hex `String`.
* @param buf `Buffer` object to convert
*/
export declare const bufferToHex: (buf: Buffer) => string;
/**
* Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
* @param num Signed integer value
*/
export declare const fromSigned: (num: Buffer) => BN;
/**
* Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
* @param num
*/
export declare const toUnsigned: (num: BN) => Buffer;
/**
* Creates Keccak hash of the input
* @param a The input data (Buffer|Array|String|Number)
* @param bits The Keccak width
*/
export declare const keccak: (a: any, bits?: number) => Buffer;
/**
* Creates Keccak-256 hash of the input, alias for keccak(a, 256).
* @param a The input data (Buffer|Array|String|Number)
*/
export declare const keccak256: (a: any) => Buffer;
/**
* Creates SHA256 hash of the input.
* @param a The input data (Buffer|Array|String|Number)
*/
export declare const sha256: (a: any) => Buffer;
/**
* Creates RIPEMD160 hash of the input.
* @param a The input data (Buffer|Array|String|Number)
* @param padded Whether it should be padded to 256 bits or not
*/
export declare const ripemd160: (a: any, padded: boolean) => Buffer;
/**
* Creates SHA-3 hash of the RLP encoded version of the input.
* @param a The input data
*/
export declare const rlphash: (a: rlp.Input) => Buffer;
/**
* Checks if the private key satisfies the rules of the curve secp256k1.
*/
export declare const isValidPrivate: (privateKey: Buffer) => boolean;
/**
* Checks if the public key satisfies the rules of the curve secp256k1
* and the requirements of Ethereum.
* @param publicKey The two points of an uncompressed key, unless sanitize is enabled
* @param sanitize Accept public keys in other formats
*/
export declare const isValidPublic: (publicKey: Buffer, sanitize?: boolean) => boolean;
/**
* Returns the ethereum address of a given public key.
* Accepts "Ethereum public keys" and SEC1 encoded keys.
* @param pubKey The two points of an uncompressed key, unless sanitize is enabled
* @param sanitize Accept public keys in other formats
*/
export declare const pubToAddress: (pubKey: Buffer, sanitize?: boolean) => Buffer;
export declare const publicToAddress: (pubKey: Buffer, sanitize?: boolean) => Buffer;
/**
* Returns the ethereum public key of a given private key.
* @param privateKey A private key must be 256 bits wide
*/
export declare const privateToPublic: (privateKey: Buffer) => Buffer;
/**
* Converts a public key to the Ethereum format.
*/
export declare const importPublic: (publicKey: Buffer) => Buffer;
/**
* Returns the ECDSA signature of a message hash.
*/
export declare const ecsign: (msgHash: Buffer, privateKey: Buffer, chainId?: number | undefined) => ECDSASignature;
/**
* Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call.
* The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign`
* call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key
* used to produce the signature.
*/
export declare const hashPersonalMessage: (message: any) => Buffer;
/**
* ECDSA public key recovery from signature.
* @returns Recovered public key
*/
export declare const ecrecover: (msgHash: Buffer, v: number, r: Buffer, s: Buffer, chainId?: number | undefined) => Buffer;
/**
* Convert signature parameters into the format of `eth_sign` RPC method.
* @returns Signature
*/
export declare const toRpcSig: (v: number, r: Buffer, s: Buffer, chainId?: number | undefined) => string;
/**
* Convert signature format of the `eth_sign` RPC method to signature parameters
* NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053
*/
export declare const fromRpcSig: (sig: string) => ECDSASignature;
/**
* Returns the ethereum address of a given private key.
* @param privateKey A private key must be 256 bits wide
*/
export declare const privateToAddress: (privateKey: Buffer) => Buffer;
/**
* Checks if the address is a valid. Accepts checksummed addresses too.
*/
export declare const isValidAddress: (address: string) => boolean;
/**
* Checks if a given address is a zero address.
*/
export declare const isZeroAddress: (address: string) => boolean;
/**
* Returns a checksummed address.
*/
export declare const toChecksumAddress: (address: string) => string;
/**
* Checks if the address is a valid checksummed address.
*/
export declare const isValidChecksumAddress: (address: string) => boolean;
/**
* Generates an address of a newly created contract.
* @param from The address which is creating this new address
* @param nonce The nonce of the from account
*/
export declare const generateAddress: (from: Buffer, nonce: Buffer) => Buffer;
/**
* Generates an address for a contract created using CREATE2.
* @param from The address which is creating this new address
* @param salt A salt
* @param initCode The init code of the contract being created
*/
export declare const generateAddress2: (from: string | Buffer, salt: string | Buffer, initCode: string | Buffer) => Buffer;
/**
* Returns true if the supplied address belongs to a precompiled account (Byzantium).
*/
export declare const isPrecompiled: (address: string | Buffer) => boolean;
/**
* Adds "0x" to a given `String` if it does not already start with "0x".
*/
export declare const addHexPrefix: (str: string) => string;
/**
* Validate a ECDSA signature.
* @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one
*/
export declare const isValidSignature: (v: number, r: Buffer, s: Buffer, homesteadOrLater?: boolean, chainId?: number | undefined) => boolean;
/**
* Converts a `Buffer` or `Array` to JSON.
* @param ba (Buffer|Array)
* @return (Array|String|null)
*/
export declare const baToJSON: (ba: any) => string | any[] | undefined;
/**
* Defines properties on a `Object`. It make the assumption that underlying data is binary.
* @param self the `Object` to define properties on
* @param fields an array fields to define. Fields can contain:
* * `name` - the name of the properties
* * `length` - the number of bytes the field can have
* * `allowLess` - if the field can be less than the length
* * `allowEmpty`
* @param data data to be validated against the definitions
*/
export declare const defineProperties: (self: any, fields: any, data: any) => void;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1 = exports.rlp = exports.BN = void 0;
var secp256k1 = require('./secp256k1v3-adapter');
exports.secp256k1 = secp256k1;
var ethjsUtil = require('ethjs-util');
var BN = require("bn.js");

@@ -21,27 +7,593 @@ exports.BN = BN;

exports.rlp = rlp;
var createKeccakHash = require('keccak');
var secp256k1 = require('secp256k1');
exports.secp256k1 = secp256k1;
var assert = require('assert');
var createHash = require('create-hash');
var Buffer = require('safe-buffer').Buffer;
var ethjsUtil = require('ethjs-util');
Object.assign(exports, ethjsUtil);
/**
* Constants
* The max integer that this VM can handle
*/
__exportStar(require("./constants"), exports);
exports.MAX_INTEGER = new BN('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16);
/**
* Public-key cryptography (secp256k1) and addresses
* 2^256
*/
__exportStar(require("./account"), exports);
exports.TWO_POW256 = new BN('10000000000000000000000000000000000000000000000000000000000000000', 16);
/**
* Hash functions
* Keccak-256 hash of null
*/
__exportStar(require("./hash"), exports);
exports.KECCAK256_NULL_S = 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470';
/**
* ECDSA signature
* Keccak-256 hash of null
*/
__exportStar(require("./signature"), exports);
exports.KECCAK256_NULL = Buffer.from(exports.KECCAK256_NULL_S, 'hex');
/**
* Utilities for manipulating Buffers, byte arrays, etc.
* Keccak-256 of an RLP of an empty array
*/
__exportStar(require("./bytes"), exports);
exports.KECCAK256_RLP_ARRAY_S = '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347';
/**
* Function for definining properties on an object
* Keccak-256 of an RLP of an empty array
*/
__exportStar(require("./object"), exports);
exports.KECCAK256_RLP_ARRAY = Buffer.from(exports.KECCAK256_RLP_ARRAY_S, 'hex');
/**
* Keccak-256 hash of the RLP of null
*/
exports.KECCAK256_RLP_S = '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421';
/**
* Keccak-256 hash of the RLP of null
*/
exports.KECCAK256_RLP = Buffer.from(exports.KECCAK256_RLP_S, 'hex');
/**
* Returns a buffer filled with 0s.
* @param bytes the number of bytes the buffer should be
*/
exports.zeros = function (bytes) {
return Buffer.allocUnsafe(bytes).fill(0);
};
/**
* Returns a zero address.
*/
exports.zeroAddress = function () {
var addressLength = 20;
var addr = exports.zeros(addressLength);
return exports.bufferToHex(addr);
};
/**
* Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.
* Or it truncates the beginning if it exceeds.
* @param msg the value to pad (Buffer|Array)
* @param length the number of bytes the output should be
* @param right whether to start padding form the left or right
* @return (Buffer|Array)
*/
exports.setLengthLeft = function (msg, length, right) {
if (right === void 0) { right = false; }
var buf = exports.zeros(length);
msg = exports.toBuffer(msg);
if (right) {
if (msg.length < length) {
msg.copy(buf);
return buf;
}
return msg.slice(0, length);
}
else {
if (msg.length < length) {
msg.copy(buf, length - msg.length);
return buf;
}
return msg.slice(-length);
}
};
exports.setLength = exports.setLengthLeft;
/**
* Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.
* Or it truncates the beginning if it exceeds.
* @param msg the value to pad (Buffer|Array)
* @param length the number of bytes the output should be
* @return (Buffer|Array)
*/
exports.setLengthRight = function (msg, length) {
return exports.setLength(msg, length, true);
};
/**
* Trims leading zeros from a `Buffer` or an `Array`.
* @param a (Buffer|Array|String)
* @return (Buffer|Array|String)
*/
exports.unpad = function (a) {
a = ethjsUtil.stripHexPrefix(a);
var first = a[0];
while (a.length > 0 && first.toString() === '0') {
a = a.slice(1);
first = a[0];
}
return a;
};
exports.stripZeros = exports.unpad;
/**
* Attempts to turn a value into a `Buffer`. As input it supports `Buffer`, `String`, `Number`, null/undefined, `BN` and other objects with a `toArray()` method.
* @param v the value
*/
exports.toBuffer = function (v) {
if (!Buffer.isBuffer(v)) {
if (Array.isArray(v)) {
v = Buffer.from(v);
}
else if (typeof v === 'string') {
if (exports.isHexString(v)) {
v = Buffer.from(exports.padToEven(exports.stripHexPrefix(v)), 'hex');
}
else {
v = Buffer.from(v);
}
}
else if (typeof v === 'number') {
v = exports.intToBuffer(v);
}
else if (v === null || v === undefined) {
v = Buffer.allocUnsafe(0);
}
else if (BN.isBN(v)) {
v = v.toArrayLike(Buffer);
}
else if (v.toArray) {
// converts a BN to a Buffer
v = Buffer.from(v.toArray());
}
else {
throw new Error('invalid type');
}
}
return v;
};
/**
* Converts a `Buffer` to a `Number`.
* @param buf `Buffer` object to convert
* @throws If the input number exceeds 53 bits.
*/
exports.bufferToInt = function (buf) {
return new BN(exports.toBuffer(buf)).toNumber();
};
/**
* Converts a `Buffer` into a hex `String`.
* @param buf `Buffer` object to convert
*/
exports.bufferToHex = function (buf) {
buf = exports.toBuffer(buf);
return '0x' + buf.toString('hex');
};
/**
* Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
* @param num Signed integer value
*/
exports.fromSigned = function (num) {
return new BN(num).fromTwos(256);
};
/**
* Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
* @param num
*/
exports.toUnsigned = function (num) {
return Buffer.from(num.toTwos(256).toArray());
};
/**
* Creates Keccak hash of the input
* @param a The input data (Buffer|Array|String|Number)
* @param bits The Keccak width
*/
exports.keccak = function (a, bits) {
if (bits === void 0) { bits = 256; }
a = exports.toBuffer(a);
if (!bits)
bits = 256;
return createKeccakHash("keccak" + bits)
.update(a)
.digest();
};
/**
* Creates Keccak-256 hash of the input, alias for keccak(a, 256).
* @param a The input data (Buffer|Array|String|Number)
*/
exports.keccak256 = function (a) {
return exports.keccak(a);
};
/**
* Creates SHA256 hash of the input.
* @param a The input data (Buffer|Array|String|Number)
*/
exports.sha256 = function (a) {
a = exports.toBuffer(a);
return createHash('sha256')
.update(a)
.digest();
};
/**
* Creates RIPEMD160 hash of the input.
* @param a The input data (Buffer|Array|String|Number)
* @param padded Whether it should be padded to 256 bits or not
*/
exports.ripemd160 = function (a, padded) {
a = exports.toBuffer(a);
var hash = createHash('rmd160')
.update(a)
.digest();
if (padded === true) {
return exports.setLength(hash, 32);
}
else {
return hash;
}
};
/**
* Creates SHA-3 hash of the RLP encoded version of the input.
* @param a The input data
*/
exports.rlphash = function (a) {
return exports.keccak(rlp.encode(a));
};
/**
* Checks if the private key satisfies the rules of the curve secp256k1.
*/
exports.isValidPrivate = function (privateKey) {
return secp256k1.privateKeyVerify(privateKey);
};
/**
* Checks if the public key satisfies the rules of the curve secp256k1
* and the requirements of Ethereum.
* @param publicKey The two points of an uncompressed key, unless sanitize is enabled
* @param sanitize Accept public keys in other formats
*/
exports.isValidPublic = function (publicKey, sanitize) {
if (sanitize === void 0) { sanitize = false; }
if (publicKey.length === 64) {
// Convert to SEC1 for secp256k1
return secp256k1.publicKeyVerify(Buffer.concat([Buffer.from([4]), publicKey]));
}
if (!sanitize) {
return false;
}
return secp256k1.publicKeyVerify(publicKey);
};
/**
* Returns the ethereum address of a given public key.
* Accepts "Ethereum public keys" and SEC1 encoded keys.
* @param pubKey The two points of an uncompressed key, unless sanitize is enabled
* @param sanitize Accept public keys in other formats
*/
exports.pubToAddress = function (pubKey, sanitize) {
if (sanitize === void 0) { sanitize = false; }
pubKey = exports.toBuffer(pubKey);
if (sanitize && pubKey.length !== 64) {
pubKey = secp256k1.publicKeyConvert(pubKey, false).slice(1);
}
assert(pubKey.length === 64);
// Only take the lower 160bits of the hash
return exports.keccak(pubKey).slice(-20);
};
exports.publicToAddress = exports.pubToAddress;
/**
* Returns the ethereum public key of a given private key.
* @param privateKey A private key must be 256 bits wide
*/
exports.privateToPublic = function (privateKey) {
privateKey = exports.toBuffer(privateKey);
// skip the type flag and use the X, Y points
return secp256k1.publicKeyCreate(privateKey, false).slice(1);
};
/**
* Converts a public key to the Ethereum format.
*/
exports.importPublic = function (publicKey) {
publicKey = exports.toBuffer(publicKey);
if (publicKey.length !== 64) {
publicKey = secp256k1.publicKeyConvert(publicKey, false).slice(1);
}
return publicKey;
};
/**
* Returns the ECDSA signature of a message hash.
*/
exports.ecsign = function (msgHash, privateKey, chainId) {
var sig = secp256k1.sign(msgHash, privateKey);
var recovery = sig.recovery;
var ret = {
r: sig.signature.slice(0, 32),
s: sig.signature.slice(32, 64),
v: chainId ? recovery + (chainId * 2 + 35) : recovery + 27,
};
return ret;
};
/**
* Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call.
* The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign`
* call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key
* used to produce the signature.
*/
exports.hashPersonalMessage = function (message) {
var prefix = exports.toBuffer("\u0019Ethereum Signed Message:\n" + message.length.toString());
return exports.keccak(Buffer.concat([prefix, message]));
};
/**
* ECDSA public key recovery from signature.
* @returns Recovered public key
*/
exports.ecrecover = function (msgHash, v, r, s, chainId) {
var signature = Buffer.concat([exports.setLength(r, 32), exports.setLength(s, 32)], 64);
var recovery = calculateSigRecovery(v, chainId);
if (!isValidSigRecovery(recovery)) {
throw new Error('Invalid signature v value');
}
var senderPubKey = secp256k1.recover(msgHash, signature, recovery);
return secp256k1.publicKeyConvert(senderPubKey, false).slice(1);
};
/**
* Convert signature parameters into the format of `eth_sign` RPC method.
* @returns Signature
*/
exports.toRpcSig = function (v, r, s, chainId) {
var recovery = calculateSigRecovery(v, chainId);
if (!isValidSigRecovery(recovery)) {
throw new Error('Invalid signature v value');
}
// geth (and the RPC eth_sign method) uses the 65 byte format used by Bitcoin
return exports.bufferToHex(Buffer.concat([exports.setLengthLeft(r, 32), exports.setLengthLeft(s, 32), exports.toBuffer(v)]));
};
/**
* Convert signature format of the `eth_sign` RPC method to signature parameters
* NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053
*/
exports.fromRpcSig = function (sig) {
var buf = exports.toBuffer(sig);
// NOTE: with potential introduction of chainId this might need to be updated
if (buf.length !== 65) {
throw new Error('Invalid signature length');
}
var v = buf[64];
// support both versions of `eth_sign` responses
if (v < 27) {
v += 27;
}
return {
v: v,
r: buf.slice(0, 32),
s: buf.slice(32, 64),
};
};
/**
* Returns the ethereum address of a given private key.
* @param privateKey A private key must be 256 bits wide
*/
exports.privateToAddress = function (privateKey) {
return exports.publicToAddress(exports.privateToPublic(privateKey));
};
/**
* Checks if the address is a valid. Accepts checksummed addresses too.
*/
exports.isValidAddress = function (address) {
return /^0x[0-9a-fA-F]{40}$/.test(address);
};
/**
* Checks if a given address is a zero address.
*/
exports.isZeroAddress = function (address) {
var zeroAddr = exports.zeroAddress();
return zeroAddr === exports.addHexPrefix(address);
};
/**
* Returns a checksummed address.
*/
exports.toChecksumAddress = function (address) {
address = ethjsUtil.stripHexPrefix(address).toLowerCase();
var hash = exports.keccak(address).toString('hex');
var ret = '0x';
for (var i = 0; i < address.length; i++) {
if (parseInt(hash[i], 16) >= 8) {
ret += address[i].toUpperCase();
}
else {
ret += address[i];
}
}
return ret;
};
/**
* Checks if the address is a valid checksummed address.
*/
exports.isValidChecksumAddress = function (address) {
return exports.isValidAddress(address) && exports.toChecksumAddress(address) === address;
};
/**
* Generates an address of a newly created contract.
* @param from The address which is creating this new address
* @param nonce The nonce of the from account
*/
exports.generateAddress = function (from, nonce) {
from = exports.toBuffer(from);
var nonceBN = new BN(nonce);
if (nonceBN.isZero()) {
// in RLP we want to encode null in the case of zero nonce
// read the RLP documentation for an answer if you dare
return exports.rlphash([from, null]).slice(-20);
}
// Only take the lower 160bits of the hash
return exports.rlphash([from, Buffer.from(nonceBN.toArray())]).slice(-20);
};
/**
* Generates an address for a contract created using CREATE2.
* @param from The address which is creating this new address
* @param salt A salt
* @param initCode The init code of the contract being created
*/
exports.generateAddress2 = function (from, salt, initCode) {
var fromBuf = exports.toBuffer(from);
var saltBuf = exports.toBuffer(salt);
var initCodeBuf = exports.toBuffer(initCode);
assert(fromBuf.length === 20);
assert(saltBuf.length === 32);
var address = exports.keccak256(Buffer.concat([Buffer.from('ff', 'hex'), fromBuf, saltBuf, exports.keccak256(initCodeBuf)]));
return address.slice(-20);
};
/**
* Returns true if the supplied address belongs to a precompiled account (Byzantium).
*/
exports.isPrecompiled = function (address) {
var a = exports.unpad(address);
return a.length === 1 && a[0] >= 1 && a[0] <= 8;
};
/**
* Adds "0x" to a given `String` if it does not already start with "0x".
*/
exports.addHexPrefix = function (str) {
if (typeof str !== 'string') {
return str;
}
return ethjsUtil.isHexPrefixed(str) ? str : '0x' + str;
};
/**
* Validate a ECDSA signature.
* @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one
*/
exports.isValidSignature = function (v, r, s, homesteadOrLater, chainId) {
if (homesteadOrLater === void 0) { homesteadOrLater = true; }
var SECP256K1_N_DIV_2 = new BN('7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0', 16);
var SECP256K1_N = new BN('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 16);
if (r.length !== 32 || s.length !== 32) {
return false;
}
if (!isValidSigRecovery(calculateSigRecovery(v, chainId))) {
return false;
}
var rBN = new BN(r);
var sBN = new BN(s);
if (rBN.isZero() || rBN.gt(SECP256K1_N) || sBN.isZero() || sBN.gt(SECP256K1_N)) {
return false;
}
if (homesteadOrLater && sBN.cmp(SECP256K1_N_DIV_2) === 1) {
return false;
}
return true;
};
/**
* Converts a `Buffer` or `Array` to JSON.
* @param ba (Buffer|Array)
* @return (Array|String|null)
*/
exports.baToJSON = function (ba) {
if (Buffer.isBuffer(ba)) {
return "0x" + ba.toString('hex');
}
else if (ba instanceof Array) {
var array = [];
for (var i = 0; i < ba.length; i++) {
array.push(exports.baToJSON(ba[i]));
}
return array;
}
};
/**
* Defines properties on a `Object`. It make the assumption that underlying data is binary.
* @param self the `Object` to define properties on
* @param fields an array fields to define. Fields can contain:
* * `name` - the name of the properties
* * `length` - the number of bytes the field can have
* * `allowLess` - if the field can be less than the length
* * `allowEmpty`
* @param data data to be validated against the definitions
*/
exports.defineProperties = function (self, fields, data) {
self.raw = [];
self._fields = [];
// attach the `toJSON`
self.toJSON = function (label) {
if (label === void 0) { label = false; }
if (label) {
var obj_1 = {};
self._fields.forEach(function (field) {
obj_1[field] = "0x" + self[field].toString('hex');
});
return obj_1;
}
return exports.baToJSON(self.raw);
};
self.serialize = function serialize() {
return rlp.encode(self.raw);
};
fields.forEach(function (field, i) {
self._fields.push(field.name);
function getter() {
return self.raw[i];
}
function setter(v) {
v = exports.toBuffer(v);
if (v.toString('hex') === '00' && !field.allowZero) {
v = Buffer.allocUnsafe(0);
}
if (field.allowLess && field.length) {
v = exports.stripZeros(v);
assert(field.length >= v.length, "The field " + field.name + " must not have more " + field.length + " bytes");
}
else if (!(field.allowZero && v.length === 0) && field.length) {
assert(field.length === v.length, "The field " + field.name + " must have byte length of " + field.length);
}
self.raw[i] = v;
}
Object.defineProperty(self, field.name, {
enumerable: true,
configurable: true,
get: getter,
set: setter,
});
if (field.default) {
self[field.name] = field.default;
}
// attach alias
if (field.alias) {
Object.defineProperty(self, field.alias, {
enumerable: false,
configurable: true,
set: setter,
get: getter,
});
}
});
// if the constuctor is passed data
if (data) {
if (typeof data === 'string') {
data = Buffer.from(ethjsUtil.stripHexPrefix(data), 'hex');
}
if (Buffer.isBuffer(data)) {
data = rlp.decode(data);
}
if (Array.isArray(data)) {
if (data.length > self._fields.length) {
throw new Error('wrong number of fields in data');
}
// make sure all the items are buffers
data.forEach(function (d, i) {
self[self._fields[i]] = exports.toBuffer(d);
});
}
else if (typeof data === 'object') {
var keys_1 = Object.keys(data);
fields.forEach(function (field) {
if (keys_1.indexOf(field.name) !== -1)
self[field.name] = data[field.name];
if (keys_1.indexOf(field.alias) !== -1)
self[field.alias] = data[field.alias];
});
}
else {
throw new Error('invalid data');
}
}
};
function calculateSigRecovery(v, chainId) {
return chainId ? v - (2 * chainId + 35) : v - 27;
}
function isValidSigRecovery(recovery) {
return recovery === 0 || recovery === 1;
}
//# sourceMappingURL=index.js.map
{
"name": "ethereumjs-util",
"version": "6.2.1",
"version": "6.1.0",
"description": "a collection of utility functions for Ethereum",

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

"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
"docs:build": "typedoc --out docs --mode file --readme none --theme markdown --mdEngine github --gitRevision master --excludeNotExported src",
"docs:build": "typedoc --out docs --mode file --readme none --theme markdown --mdEngine github --excludeNotExported src",
"format": "ethereumjs-config-format",

@@ -28,7 +28,2 @@ "format:fix": "ethereumjs-config-format-fix",

},
"husky": {
"hooks": {
"pre-push": "npm run lint"
}
},
"repository": {

@@ -93,9 +88,9 @@ "type": "git",

"dependencies": {
"@types/bn.js": "^4.11.3",
"bn.js": "^4.11.0",
"create-hash": "^1.1.2",
"ethereum-cryptography": "^0.1.3",
"elliptic": "^6.5.2",
"ethjs-util": "0.1.6",
"rlp": "^2.2.3"
"keccak": "^1.0.2",
"rlp": "^2.0.0",
"safe-buffer": "^5.1.1",
"secp256k1": "^3.0.1"
},

@@ -106,2 +101,3 @@ "devDependencies": {

"@ethereumjs/config-tslint": "^1.1.0",
"@types/bn.js": "^4.11.3",
"@types/node": "^11.9.0",

@@ -114,5 +110,4 @@ "babel-cli": "^6.26.0",

"coveralls": "^3.0.0",
"husky": "^2.1.0",
"istanbul": "^0.4.1",
"karma": "^4.0.0",
"karma": "^2.0.0",
"karma-browserify": "^5.0.0",

@@ -124,3 +119,3 @@ "karma-chrome-launcher": "^2.0.0",

"karma-mocha": "^1.3.0",
"mocha": "^6.0.0",
"mocha": "^4.0.0",
"prettier": "^1.15.3",

@@ -134,5 +129,5 @@ "tslint": "^5.12.0",

,"_resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.2.1.tgz"
,"_integrity": "sha512-W2Ktez4L01Vexijrm5EB6w7dg4n/TgpoYU4avuT5T3Vmnw/eCRtiBrJfQYS/DCSvDIOLn2k57GcHdeBcgVxAqw=="
,"_from": "ethereumjs-util@6.2.1"
,"_resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz"
,"_integrity": "sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q=="
,"_from": "ethereumjs-util@6.1.0"
}

@@ -8,2 +8,4 @@ # SYNOPSIS

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
A collection of utility functions for ethereum. It can be used in node.js or can be in the browser with browserify.

@@ -25,10 +27,4 @@

# EthereumJS
See our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices.
If you want to join for work or do improvements on the libraries have a look at our [contribution guidelines](https://ethereumjs.readthedocs.io/en/latest/contributing.html).
# LICENSE
MPL-2.0

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

module.exports = require('./lib/api')(require('node-gyp-build')(__dirname))
'use strict'
module.exports = require('./lib/api')(require('bindings')('keccak'))

@@ -0,5 +1,10 @@

'use strict'
try {
module.exports = require('./bindings')
} catch (err) {
if (process.env.DEBUG) {
console.error('Keccak bindings are not compiled. Pure JS implementation will be used.')
}
module.exports = require('./js')
}

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

'use strict'
module.exports = require('./lib/api')(require('./lib/keccak'))

@@ -1,10 +0,11 @@

const createKeccak = require('./keccak')
const createShake = require('./shake')
'use strict'
var createKeccak = require('./keccak')
var createShake = require('./shake')
module.exports = function (KeccakState) {
const Keccak = createKeccak(KeccakState)
const Shake = createShake(KeccakState)
var Keccak = createKeccak(KeccakState)
var Shake = createShake(KeccakState)
return function (algorithm, options) {
const hash = typeof algorithm === 'string' ? algorithm.toLowerCase() : algorithm
var hash = typeof algorithm === 'string' ? algorithm.toLowerCase() : algorithm
switch (hash) {

@@ -11,0 +12,0 @@ case 'keccak224': return new Keccak(1152, 448, null, 224, options)

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

const { Transform } = require('stream')
'use strict'
var Buffer = require('safe-buffer').Buffer
var Transform = require('stream').Transform
var inherits = require('inherits')
module.exports = (KeccakState) => class Keccak extends Transform {
constructor (rate, capacity, delimitedSuffix, hashBitLength, options) {
super(options)
module.exports = function (KeccakState) {
function Keccak (rate, capacity, delimitedSuffix, hashBitLength, options) {
Transform.call(this, options)

@@ -18,4 +21,6 @@ this._rate = rate

_transform (chunk, encoding, callback) {
let error = null
inherits(Keccak, Transform)
Keccak.prototype._transform = function (chunk, encoding, callback) {
var error = null
try {

@@ -30,4 +35,4 @@ this.update(chunk, encoding)

_flush (callback) {
let error = null
Keccak.prototype._flush = function (callback) {
var error = null
try {

@@ -42,3 +47,3 @@ this.push(this.digest())

update (data, encoding) {
Keccak.prototype.update = function (data, encoding) {
if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')

@@ -53,3 +58,3 @@ if (this._finalized) throw new Error('Digest already called')

digest (encoding) {
Keccak.prototype.digest = function (encoding) {
if (this._finalized) throw new Error('Digest already called')

@@ -59,3 +64,3 @@ this._finalized = true

if (this._delimitedSuffix) this._state.absorbLastFewBits(this._delimitedSuffix)
let digest = this._state.squeeze(this._hashBitLength / 8)
var digest = this._state.squeeze(this._hashBitLength / 8)
if (encoding !== undefined) digest = digest.toString(encoding)

@@ -69,3 +74,3 @@

// remove result from memory
_resetState () {
Keccak.prototype._resetState = function () {
this._state.initialize(this._rate, this._capacity)

@@ -76,4 +81,4 @@ return this

// because sometimes we need hash right now and little later
_clone () {
const clone = new Keccak(this._rate, this._capacity, this._delimitedSuffix, this._hashBitLength, this._options)
Keccak.prototype._clone = function () {
var clone = new Keccak(this._rate, this._capacity, this._delimitedSuffix, this._hashBitLength, this._options)
this._state.copy(clone._state)

@@ -84,2 +89,4 @@ clone._finalized = this._finalized

}
return Keccak
}

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

const { Transform } = require('stream')
'use strict'
var Buffer = require('safe-buffer').Buffer
var Transform = require('stream').Transform
var inherits = require('inherits')
module.exports = (KeccakState) => class Shake extends Transform {
constructor (rate, capacity, delimitedSuffix, options) {
super(options)
module.exports = function (KeccakState) {
function Shake (rate, capacity, delimitedSuffix, options) {
Transform.call(this, options)

@@ -17,4 +20,6 @@ this._rate = rate

_transform (chunk, encoding, callback) {
let error = null
inherits(Shake, Transform)
Shake.prototype._transform = function (chunk, encoding, callback) {
var error = null
try {

@@ -29,9 +34,9 @@ this.update(chunk, encoding)

_flush () {}
Shake.prototype._flush = function () {}
_read (size) {
Shake.prototype._read = function (size) {
this.push(this.squeeze(size))
}
update (data, encoding) {
Shake.prototype.update = function (data, encoding) {
if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')

@@ -46,3 +51,3 @@ if (this._finalized) throw new Error('Squeeze already called')

squeeze (dataByteLength, encoding) {
Shake.prototype.squeeze = function (dataByteLength, encoding) {
if (!this._finalized) {

@@ -53,3 +58,3 @@ this._finalized = true

let data = this._state.squeeze(dataByteLength)
var data = this._state.squeeze(dataByteLength)
if (encoding !== undefined) data = data.toString(encoding)

@@ -60,3 +65,3 @@

_resetState () {
Shake.prototype._resetState = function () {
this._state.initialize(this._rate, this._capacity)

@@ -66,4 +71,4 @@ return this

_clone () {
const clone = new Shake(this._rate, this._capacity, this._delimitedSuffix, this._options)
Shake.prototype._clone = function () {
var clone = new Shake(this._rate, this._capacity, this._delimitedSuffix, this._options)
this._state.copy(clone._state)

@@ -74,2 +79,4 @@ clone._finalized = this._finalized

}
return Shake
}

@@ -1,3 +0,4 @@

const P1600_RHO_OFFSETS = [0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14]
const P1600_ROUND_CONSTANTS = [
'use strict'
var P1600_RHO_OFFSETS = [0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14]
var P1600_ROUND_CONSTANTS = [
0x00000001, 0x00000000,

@@ -30,3 +31,3 @@ 0x00008082, 0x00000000,

function p1600 (state) {
for (let round = 0; round < 24; ++round) {
for (var round = 0; round < 24; ++round) {
theta(state)

@@ -42,7 +43,7 @@ rho(state)

function theta (s) {
const clo = [0, 0, 0, 0, 0]
const chi = [0, 0, 0, 0, 0]
var clo = [0, 0, 0, 0, 0]
var chi = [0, 0, 0, 0, 0]
for (let x = 0; x < 5; ++x) {
for (let y = 0; y < 5; ++y) {
for (var x = 0; x < 5; ++x) {
for (var y = 0; y < 5; ++y) {
clo[x] ^= s[ilo(x, y)]

@@ -53,9 +54,9 @@ chi[x] ^= s[ihi(x, y)]

for (let x = 0; x < 5; ++x) {
const next = (x + 1) % 5
const prev = (x + 4) % 5
const dlo = rol64lo(clo[next], chi[next], 1) ^ clo[prev]
const dhi = rol64hi(clo[next], chi[next], 1) ^ chi[prev]
for (x = 0; x < 5; ++x) {
var next = (x + 1) % 5
var prev = (x + 4) % 5
var dlo = rol64lo(clo[next], chi[next], 1) ^ clo[prev]
var dhi = rol64hi(clo[next], chi[next], 1) ^ chi[prev]
for (let y = 0; y < 5; ++y) {
for (y = 0; y < 5; ++y) {
s[ilo(x, y)] ^= dlo

@@ -68,6 +69,6 @@ s[ihi(x, y)] ^= dhi

function rho (s) {
for (let x = 0; x < 5; ++x) {
for (let y = 0; y < 5; ++y) {
const lo = rol64lo(s[ilo(x, y)], s[ihi(x, y)], P1600_RHO_OFFSETS[index(x, y)])
const hi = rol64hi(s[ilo(x, y)], s[ihi(x, y)], P1600_RHO_OFFSETS[index(x, y)])
for (var x = 0; x < 5; ++x) {
for (var y = 0; y < 5; ++y) {
var lo = rol64lo(s[ilo(x, y)], s[ihi(x, y)], P1600_RHO_OFFSETS[index(x, y)])
var hi = rol64hi(s[ilo(x, y)], s[ihi(x, y)], P1600_RHO_OFFSETS[index(x, y)])
s[ilo(x, y)] = lo

@@ -80,8 +81,8 @@ s[ihi(x, y)] = hi

function pi (s) {
const ts = s.slice()
var ts = s.slice()
for (let x = 0; x < 5; ++x) {
for (let y = 0; y < 5; ++y) {
const nx = (0 * x + 1 * y) % 5
const ny = (2 * x + 3 * y) % 5
for (var x = 0; x < 5; ++x) {
for (var y = 0; y < 5; ++y) {
var nx = (0 * x + 1 * y) % 5
var ny = (2 * x + 3 * y) % 5
s[ilo(nx, ny)] = ts[ilo(x, y)]

@@ -94,7 +95,7 @@ s[ihi(nx, ny)] = ts[ihi(x, y)]

function chi (s) {
const clo = [0, 0, 0, 0, 0]
const chi = [0, 0, 0, 0, 0]
var clo = [0, 0, 0, 0, 0]
var chi = [0, 0, 0, 0, 0]
for (let y = 0; y < 5; ++y) {
for (let x = 0; x < 5; ++x) {
for (var y = 0; y < 5; ++y) {
for (var x = 0; x < 5; ++x) {
clo[x] = s[ilo(x, y)] ^ (~s[ilo((x + 1) % 5, y)] & s[ilo((x + 2) % 5, y)])

@@ -104,3 +105,3 @@ chi[x] = s[ihi(x, y)] ^ (~s[ihi((x + 1) % 5, y)] & s[ihi((x + 2) % 5, y)])

for (let x = 0; x < 5; ++x) {
for (x = 0; x < 5; ++x) {
s[ilo(x, y)] = clo[x]

@@ -124,3 +125,3 @@ s[ihi(x, y)] = chi[x]

if (shift >= 32) {
const t = lo
var t = lo
lo = hi

@@ -136,3 +137,3 @@ hi = t

if (shift >= 32) {
const t = lo
var t = lo
lo = hi

@@ -139,0 +140,0 @@ hi = t

@@ -1,129 +0,130 @@

const P1600_ROUND_CONSTANTS = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648]
'use strict'
var P1600_ROUND_CONSTANTS = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648]
exports.p1600 = function (s) {
for (let round = 0; round < 24; ++round) {
for (var round = 0; round < 24; ++round) {
// theta
const lo0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]
const hi0 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]
const lo1 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]
const hi1 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43]
const lo2 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44]
const hi2 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45]
const lo3 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46]
const hi3 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47]
const lo4 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48]
const hi4 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49]
var lo0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]
var hi0 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]
var lo1 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]
var hi1 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43]
var lo2 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44]
var hi2 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45]
var lo3 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46]
var hi3 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47]
var lo4 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48]
var hi4 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49]
let lo = lo4 ^ (lo1 << 1 | hi1 >>> 31)
let hi = hi4 ^ (hi1 << 1 | lo1 >>> 31)
const t1slo0 = s[0] ^ lo
const t1shi0 = s[1] ^ hi
const t1slo5 = s[10] ^ lo
const t1shi5 = s[11] ^ hi
const t1slo10 = s[20] ^ lo
const t1shi10 = s[21] ^ hi
const t1slo15 = s[30] ^ lo
const t1shi15 = s[31] ^ hi
const t1slo20 = s[40] ^ lo
const t1shi20 = s[41] ^ hi
var lo = lo4 ^ (lo1 << 1 | hi1 >>> 31)
var hi = hi4 ^ (hi1 << 1 | lo1 >>> 31)
var t1slo0 = s[0] ^ lo
var t1shi0 = s[1] ^ hi
var t1slo5 = s[10] ^ lo
var t1shi5 = s[11] ^ hi
var t1slo10 = s[20] ^ lo
var t1shi10 = s[21] ^ hi
var t1slo15 = s[30] ^ lo
var t1shi15 = s[31] ^ hi
var t1slo20 = s[40] ^ lo
var t1shi20 = s[41] ^ hi
lo = lo0 ^ (lo2 << 1 | hi2 >>> 31)
hi = hi0 ^ (hi2 << 1 | lo2 >>> 31)
const t1slo1 = s[2] ^ lo
const t1shi1 = s[3] ^ hi
const t1slo6 = s[12] ^ lo
const t1shi6 = s[13] ^ hi
const t1slo11 = s[22] ^ lo
const t1shi11 = s[23] ^ hi
const t1slo16 = s[32] ^ lo
const t1shi16 = s[33] ^ hi
const t1slo21 = s[42] ^ lo
const t1shi21 = s[43] ^ hi
var t1slo1 = s[2] ^ lo
var t1shi1 = s[3] ^ hi
var t1slo6 = s[12] ^ lo
var t1shi6 = s[13] ^ hi
var t1slo11 = s[22] ^ lo
var t1shi11 = s[23] ^ hi
var t1slo16 = s[32] ^ lo
var t1shi16 = s[33] ^ hi
var t1slo21 = s[42] ^ lo
var t1shi21 = s[43] ^ hi
lo = lo1 ^ (lo3 << 1 | hi3 >>> 31)
hi = hi1 ^ (hi3 << 1 | lo3 >>> 31)
const t1slo2 = s[4] ^ lo
const t1shi2 = s[5] ^ hi
const t1slo7 = s[14] ^ lo
const t1shi7 = s[15] ^ hi
const t1slo12 = s[24] ^ lo
const t1shi12 = s[25] ^ hi
const t1slo17 = s[34] ^ lo
const t1shi17 = s[35] ^ hi
const t1slo22 = s[44] ^ lo
const t1shi22 = s[45] ^ hi
var t1slo2 = s[4] ^ lo
var t1shi2 = s[5] ^ hi
var t1slo7 = s[14] ^ lo
var t1shi7 = s[15] ^ hi
var t1slo12 = s[24] ^ lo
var t1shi12 = s[25] ^ hi
var t1slo17 = s[34] ^ lo
var t1shi17 = s[35] ^ hi
var t1slo22 = s[44] ^ lo
var t1shi22 = s[45] ^ hi
lo = lo2 ^ (lo4 << 1 | hi4 >>> 31)
hi = hi2 ^ (hi4 << 1 | lo4 >>> 31)
const t1slo3 = s[6] ^ lo
const t1shi3 = s[7] ^ hi
const t1slo8 = s[16] ^ lo
const t1shi8 = s[17] ^ hi
const t1slo13 = s[26] ^ lo
const t1shi13 = s[27] ^ hi
const t1slo18 = s[36] ^ lo
const t1shi18 = s[37] ^ hi
const t1slo23 = s[46] ^ lo
const t1shi23 = s[47] ^ hi
var t1slo3 = s[6] ^ lo
var t1shi3 = s[7] ^ hi
var t1slo8 = s[16] ^ lo
var t1shi8 = s[17] ^ hi
var t1slo13 = s[26] ^ lo
var t1shi13 = s[27] ^ hi
var t1slo18 = s[36] ^ lo
var t1shi18 = s[37] ^ hi
var t1slo23 = s[46] ^ lo
var t1shi23 = s[47] ^ hi
lo = lo3 ^ (lo0 << 1 | hi0 >>> 31)
hi = hi3 ^ (hi0 << 1 | lo0 >>> 31)
const t1slo4 = s[8] ^ lo
const t1shi4 = s[9] ^ hi
const t1slo9 = s[18] ^ lo
const t1shi9 = s[19] ^ hi
const t1slo14 = s[28] ^ lo
const t1shi14 = s[29] ^ hi
const t1slo19 = s[38] ^ lo
const t1shi19 = s[39] ^ hi
const t1slo24 = s[48] ^ lo
const t1shi24 = s[49] ^ hi
var t1slo4 = s[8] ^ lo
var t1shi4 = s[9] ^ hi
var t1slo9 = s[18] ^ lo
var t1shi9 = s[19] ^ hi
var t1slo14 = s[28] ^ lo
var t1shi14 = s[29] ^ hi
var t1slo19 = s[38] ^ lo
var t1shi19 = s[39] ^ hi
var t1slo24 = s[48] ^ lo
var t1shi24 = s[49] ^ hi
// rho & pi
const t2slo0 = t1slo0
const t2shi0 = t1shi0
const t2slo16 = (t1shi5 << 4 | t1slo5 >>> 28)
const t2shi16 = (t1slo5 << 4 | t1shi5 >>> 28)
const t2slo7 = (t1slo10 << 3 | t1shi10 >>> 29)
const t2shi7 = (t1shi10 << 3 | t1slo10 >>> 29)
const t2slo23 = (t1shi15 << 9 | t1slo15 >>> 23)
const t2shi23 = (t1slo15 << 9 | t1shi15 >>> 23)
const t2slo14 = (t1slo20 << 18 | t1shi20 >>> 14)
const t2shi14 = (t1shi20 << 18 | t1slo20 >>> 14)
const t2slo10 = (t1slo1 << 1 | t1shi1 >>> 31)
const t2shi10 = (t1shi1 << 1 | t1slo1 >>> 31)
const t2slo1 = (t1shi6 << 12 | t1slo6 >>> 20)
const t2shi1 = (t1slo6 << 12 | t1shi6 >>> 20)
const t2slo17 = (t1slo11 << 10 | t1shi11 >>> 22)
const t2shi17 = (t1shi11 << 10 | t1slo11 >>> 22)
const t2slo8 = (t1shi16 << 13 | t1slo16 >>> 19)
const t2shi8 = (t1slo16 << 13 | t1shi16 >>> 19)
const t2slo24 = (t1slo21 << 2 | t1shi21 >>> 30)
const t2shi24 = (t1shi21 << 2 | t1slo21 >>> 30)
const t2slo20 = (t1shi2 << 30 | t1slo2 >>> 2)
const t2shi20 = (t1slo2 << 30 | t1shi2 >>> 2)
const t2slo11 = (t1slo7 << 6 | t1shi7 >>> 26)
const t2shi11 = (t1shi7 << 6 | t1slo7 >>> 26)
const t2slo2 = (t1shi12 << 11 | t1slo12 >>> 21)
const t2shi2 = (t1slo12 << 11 | t1shi12 >>> 21)
const t2slo18 = (t1slo17 << 15 | t1shi17 >>> 17)
const t2shi18 = (t1shi17 << 15 | t1slo17 >>> 17)
const t2slo9 = (t1shi22 << 29 | t1slo22 >>> 3)
const t2shi9 = (t1slo22 << 29 | t1shi22 >>> 3)
const t2slo5 = (t1slo3 << 28 | t1shi3 >>> 4)
const t2shi5 = (t1shi3 << 28 | t1slo3 >>> 4)
const t2slo21 = (t1shi8 << 23 | t1slo8 >>> 9)
const t2shi21 = (t1slo8 << 23 | t1shi8 >>> 9)
const t2slo12 = (t1slo13 << 25 | t1shi13 >>> 7)
const t2shi12 = (t1shi13 << 25 | t1slo13 >>> 7)
const t2slo3 = (t1slo18 << 21 | t1shi18 >>> 11)
const t2shi3 = (t1shi18 << 21 | t1slo18 >>> 11)
const t2slo19 = (t1shi23 << 24 | t1slo23 >>> 8)
const t2shi19 = (t1slo23 << 24 | t1shi23 >>> 8)
const t2slo15 = (t1slo4 << 27 | t1shi4 >>> 5)
const t2shi15 = (t1shi4 << 27 | t1slo4 >>> 5)
const t2slo6 = (t1slo9 << 20 | t1shi9 >>> 12)
const t2shi6 = (t1shi9 << 20 | t1slo9 >>> 12)
const t2slo22 = (t1shi14 << 7 | t1slo14 >>> 25)
const t2shi22 = (t1slo14 << 7 | t1shi14 >>> 25)
const t2slo13 = (t1slo19 << 8 | t1shi19 >>> 24)
const t2shi13 = (t1shi19 << 8 | t1slo19 >>> 24)
const t2slo4 = (t1slo24 << 14 | t1shi24 >>> 18)
const t2shi4 = (t1shi24 << 14 | t1slo24 >>> 18)
var t2slo0 = t1slo0
var t2shi0 = t1shi0
var t2slo16 = (t1shi5 << 4 | t1slo5 >>> 28)
var t2shi16 = (t1slo5 << 4 | t1shi5 >>> 28)
var t2slo7 = (t1slo10 << 3 | t1shi10 >>> 29)
var t2shi7 = (t1shi10 << 3 | t1slo10 >>> 29)
var t2slo23 = (t1shi15 << 9 | t1slo15 >>> 23)
var t2shi23 = (t1slo15 << 9 | t1shi15 >>> 23)
var t2slo14 = (t1slo20 << 18 | t1shi20 >>> 14)
var t2shi14 = (t1shi20 << 18 | t1slo20 >>> 14)
var t2slo10 = (t1slo1 << 1 | t1shi1 >>> 31)
var t2shi10 = (t1shi1 << 1 | t1slo1 >>> 31)
var t2slo1 = (t1shi6 << 12 | t1slo6 >>> 20)
var t2shi1 = (t1slo6 << 12 | t1shi6 >>> 20)
var t2slo17 = (t1slo11 << 10 | t1shi11 >>> 22)
var t2shi17 = (t1shi11 << 10 | t1slo11 >>> 22)
var t2slo8 = (t1shi16 << 13 | t1slo16 >>> 19)
var t2shi8 = (t1slo16 << 13 | t1shi16 >>> 19)
var t2slo24 = (t1slo21 << 2 | t1shi21 >>> 30)
var t2shi24 = (t1shi21 << 2 | t1slo21 >>> 30)
var t2slo20 = (t1shi2 << 30 | t1slo2 >>> 2)
var t2shi20 = (t1slo2 << 30 | t1shi2 >>> 2)
var t2slo11 = (t1slo7 << 6 | t1shi7 >>> 26)
var t2shi11 = (t1shi7 << 6 | t1slo7 >>> 26)
var t2slo2 = (t1shi12 << 11 | t1slo12 >>> 21)
var t2shi2 = (t1slo12 << 11 | t1shi12 >>> 21)
var t2slo18 = (t1slo17 << 15 | t1shi17 >>> 17)
var t2shi18 = (t1shi17 << 15 | t1slo17 >>> 17)
var t2slo9 = (t1shi22 << 29 | t1slo22 >>> 3)
var t2shi9 = (t1slo22 << 29 | t1shi22 >>> 3)
var t2slo5 = (t1slo3 << 28 | t1shi3 >>> 4)
var t2shi5 = (t1shi3 << 28 | t1slo3 >>> 4)
var t2slo21 = (t1shi8 << 23 | t1slo8 >>> 9)
var t2shi21 = (t1slo8 << 23 | t1shi8 >>> 9)
var t2slo12 = (t1slo13 << 25 | t1shi13 >>> 7)
var t2shi12 = (t1shi13 << 25 | t1slo13 >>> 7)
var t2slo3 = (t1slo18 << 21 | t1shi18 >>> 11)
var t2shi3 = (t1shi18 << 21 | t1slo18 >>> 11)
var t2slo19 = (t1shi23 << 24 | t1slo23 >>> 8)
var t2shi19 = (t1slo23 << 24 | t1shi23 >>> 8)
var t2slo15 = (t1slo4 << 27 | t1shi4 >>> 5)
var t2shi15 = (t1shi4 << 27 | t1slo4 >>> 5)
var t2slo6 = (t1slo9 << 20 | t1shi9 >>> 12)
var t2shi6 = (t1shi9 << 20 | t1slo9 >>> 12)
var t2slo22 = (t1shi14 << 7 | t1slo14 >>> 25)
var t2shi22 = (t1slo14 << 7 | t1shi14 >>> 25)
var t2slo13 = (t1slo19 << 8 | t1shi19 >>> 24)
var t2shi13 = (t1shi19 << 8 | t1slo19 >>> 24)
var t2slo4 = (t1slo24 << 14 | t1shi24 >>> 18)
var t2shi4 = (t1shi24 << 14 | t1slo24 >>> 18)

@@ -130,0 +131,0 @@ // chi

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

const keccakState = require('./keccak-state-unroll')
'use strict'
var Buffer = require('safe-buffer').Buffer
var keccakState = require('./keccak-state-unroll')

@@ -19,3 +21,3 @@ function Keccak () {

Keccak.prototype.initialize = function (rate, capacity) {
for (let i = 0; i < 50; ++i) this.state[i] = 0
for (var i = 0; i < 50; ++i) this.state[i] = 0
this.blockSize = rate / 8

@@ -27,3 +29,3 @@ this.count = 0

Keccak.prototype.absorb = function (data) {
for (let i = 0; i < data.length; ++i) {
for (var i = 0; i < data.length; ++i) {
this.state[~~(this.count / 4)] ^= data[i] << (8 * (this.count % 4))

@@ -50,4 +52,4 @@ this.count += 1

const output = Buffer.alloc(length)
for (let i = 0; i < length; ++i) {
var output = Buffer.alloc(length)
for (var i = 0; i < length; ++i) {
output[i] = (this.state[~~(this.count / 4)] >>> (8 * (this.count % 4))) & 0xff

@@ -65,3 +67,3 @@ this.count += 1

Keccak.prototype.copy = function (dest) {
for (let i = 0; i < 50; ++i) dest.state[i] = this.state[i]
for (var i = 0; i < 50; ++i) dest.state[i] = this.state[i]
dest.blockSize = this.blockSize

@@ -68,0 +70,0 @@ dest.count = this.count

{
"name": "keccak",
"version": "3.0.1",
"version": "1.4.0",
"description": "Keccak sponge function family",

@@ -14,6 +14,2 @@ "keywords": [

},
"repository": {
"type": "git",
"url": "https://github.com/cryptocoinjs/keccak.git"
},
"license": "MIT",

@@ -23,21 +19,49 @@ "contributors": [

],
"files": [
"lib",
"src",
"binding.gyp",
"bindings.js",
"index.js",
"js.js"
],
"main": "./index.js",
"browser": {
"./index.js": "./js.js"
"repository": {
"type": "git",
"url": "https://github.com/cryptocoinjs/keccak.git"
},
"scripts": {
"install": "node-gyp-build || exit 0"
"coverage": "nyc tape test/index.js",
"coverage-lcov": "npm run coverage && nyc report -r lcov",
"install": "npm run rebuild || echo \"Keccak bindings compilation fail. Pure JS implementation will be used.\"",
"libkeccak": "./util/libkeccak.sh",
"lint": "standard",
"rebuild": "node-gyp rebuild",
"test": "npm run lint && npm run unit",
"unit": "tape test/index.js"
},
"dependencies": {
"node-addon-api": "^2.0.0",
"node-gyp-build": "^4.2.0"
"bindings": "^1.2.1",
"inherits": "^2.0.3",
"nan": "^2.2.1",
"safe-buffer": "^5.1.0"
},
"devDependencies": {
"browserify": "^14.1.0",
"nyc": "^11.0.2",
"proxyquire": "^1.7.10",
"standard": "^10.0.2",
"tape": "^4.5.1"
},
"engines": {
"node": ">=10.0.0"
"node": ">=4.0.0"
},
"gypfile": true
"gypfile": true,
"browser": {
"./index.js": "./js.js"
}
,"_resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.1.tgz"
,"_integrity": "sha512-epq90L9jlFWCW7+pQa6JOnKn2Xgl2mtI664seYR6MHskvI9agt7AnDqmAlp9TqU4/caMYbA08Hi5DMZAl5zdkA=="
,"_from": "keccak@3.0.1"
,"_resolved": "https://registry.npmjs.org/keccak/-/keccak-1.4.0.tgz"
,"_integrity": "sha512-eZVaCpblK5formjPjeTBik7TAg+pqnDrMHIffSvi9Lh7PQgM1+hSzakUeZFCk9DVVG0dacZJuaz2ntwlzZUIBw=="
,"_from": "keccak@1.4.0"
}
# keccak
Version | Mac/Linux | Windows
------- | --------- | -------
[![NPM Package](https://img.shields.io/npm/v/keccak.svg?style=flat-square)](https://www.npmjs.org/package/keccak) | [![Build Status](https://img.shields.io/travis/cryptocoinjs/keccak.svg?branch=master&style=flat-square)](https://travis-ci.org/cryptocoinjs/keccak) | [![AppVeyor](https://img.shields.io/appveyor/ci/fanatid/keccak.svg?branch=master&style=flat-square)](https://ci.appveyor.com/project/fanatid/keccak)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
This module provides native bindings to [Keccak sponge function family][1] from [Keccak Code Package][2]. In browser pure JavaScript implementation will be used.

@@ -4,0 +10,0 @@

@@ -9,12 +9,2 @@ # Changelog

## [v2.2.6] - 2020-07-17
- Fixed a few edge-cases in decoding long strings that previously could cause
OOM (Out of Memory) crash,
PR [#91](https://github.com/ethereumjs/rlp/pull/91)
- Updated GitHub `actions/checkout` to v2,
PR [#92](https://github.com/ethereumjs/rlp/pull/92)
[v2.2.6]: https://github.com/ethereumjs/rlp/compare/2.2.5...v2.2.6
## [v2.2.5] - 2020-05-25

@@ -21,0 +11,0 @@

@@ -130,15 +130,7 @@ "use strict";

else if (firstByte <= 0xbf) {
// string is greater than 55 bytes long. A single byte with the value (0xb7 plus the length of the length),
// followed by the length, followed by the string
llength = firstByte - 0xb6;
if (input.length - 1 < llength) {
throw new Error('invalid RLP: not enough bytes for string length');
}
length = safeParseInt(input.slice(1, llength).toString('hex'), 16);
if (length <= 55) {
throw new Error('invalid RLP: expected string length to be greater than 55');
}
data = input.slice(llength, length + llength);
if (data.length < length) {
throw new Error('invalid RLP: not enough bytes for string');
throw new Error('invalid RLP');
}

@@ -145,0 +137,0 @@ return {

{
"name": "rlp",
"version": "2.2.6",
"version": "2.2.5",
"description": "Recursive Length Prefix Encoding Module",

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

,"_resolved": "https://registry.npmjs.org/rlp/-/rlp-2.2.6.tgz"
,"_integrity": "sha512-HAfAmL6SDYNWPUOJNrM500x4Thn4PZsEy5pijPh40U9WfNk0z15hUYzO9xVIMAdIHdFtD8CBDHd75Td1g36Mjg=="
,"_from": "rlp@2.2.6"
,"_resolved": "https://registry.npmjs.org/rlp/-/rlp-2.2.5.tgz"
,"_integrity": "sha512-y1QxTQOp0OZnjn19FxBmped4p+BSKPHwGndaqrESseyd2xXZtcgR3yuTIosh8CaMaOii9SKIYerBXnV/CpJ3qw=="
,"_from": "rlp@2.2.5"
}

@@ -1,116 +0,186 @@

## API Reference (v4.x)
# API Reference (v3.x)
- Functions work with [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array). While [Buffer](https://nodejs.org/api/buffer.html) is awesome, current version for browsers ([feross/buffer](https://github.com/feross/buffer/)) is out of date (compare to Node.js Buffer) and in future difference probably will be only bigger. But because Buffer extends Uint8Array, you can pass and receive Buffers easily. Also, work with native Uint8Array reduce final build size, if you do not use Buffer in your browser application.
- [`.privateKeyVerify(Buffer privateKey)`](#privatekeyverifybuffer-privatekey---boolean)
- [`.privateKeyExport(Buffer privateKey [, Boolean compressed = true])`](#privatekeyexportbuffer-privatekey--boolean-compressed--true---buffer)
- [`.privateKeyImport(Buffer privateKey)`](#privatekeyimportbuffer-privatekey---buffer)
- [`.privateKeyNegate(Buffer privateKey)`](#privatekeynegatebuffer-privatekey---buffer)
- [`.privateKeyModInverse(Buffer privateKey)`](#privatekeymodinversebuffer-privatekey---buffer)
- [`.privateKeyTweakAdd(Buffer privateKey, Buffer tweak)`](#privatekeytweakaddbuffer-privatekey-buffer-tweak---buffer)
- [`.privateKeyTweakMul(Buffer privateKey, Buffer tweak)`](#privatekeytweakmulbuffer-privatekey-buffer-tweak---buffer)
- [`.publicKeyCreate(Buffer privateKey [, Boolean compressed = true])`](#publickeycreatebuffer-privatekey--boolean-compressed--true---buffer)
- [`.publicKeyConvert(Buffer publicKey [, Boolean compressed = true])`](#publickeyconvertbuffer-publickey--boolean-compressed--true---buffer)
- [`.publicKeyVerify(Buffer publicKey)`](#publickeyverifybuffer-publickey---boolean)
- [`.publicKeyTweakAdd(Buffer publicKey, Buffer tweak [, Boolean compressed = true])`](#publickeytweakaddbuffer-publickey-buffer-tweak--boolean-compressed--true---buffer)
- [`.publicKeyTweakMul(Buffer publicKey, Buffer tweak [, Boolean compressed = true])`](#publickeytweakmulbuffer-publickey-buffer-tweak--boolean-compressed--true---buffer)
- [`.publicKeyCombine(Array<Buffer> publicKeys [, Boolean compressed = true])`](#publickeycombinearraybuffer-publickeys--boolean-compressed--true---buffer)
- [`.signatureNormalize(Buffer signature)`](#signaturenormalizebuffer-signature---buffer)
- [`.signatureExport(Buffer signature)`](#signatureexportbuffer-signature---buffer)
- [`.signatureImport(Buffer signature)`](#signatureimportbuffer-signature---buffer)
- [`.signatureImportLax(Buffer signature)`](#signatureimportlaxbuffer-signature---buffer)
- [`.sign(Buffer message, Buffer privateKey [, Object options])`](#signbuffer-message-buffer-privatekey--object-options---signature-buffer-recovery-number)
- [Option: `Function noncefn`](#option-function-noncefn)
- [Option: `Buffer data`](#option-buffer-data)
- [`.verify(Buffer message, Buffer signature, Buffer publicKey)`](#verifybuffer-message-buffer-signature-buffer-publickey---boolean)
- [`.recover(Buffer message, Buffer signature, Number recovery [, Boolean compressed = true])`](#recoverbuffer-message-buffer-signature-number-recovery--boolean-compressed--true---buffer)
- [`.ecdh(Buffer publicKey, Buffer privateKey)`](#ecdhbuffer-publickey-buffer-privatekey---buffer)
- [`.ecdhUnsafe(Buffer publicKey, Buffer privateKey [, Boolean compressed = true])`](#ecdhunsafebuffer-publickey-buffer-privatekey--boolean-compressed--true---buffer)
- Custom type for data output. It's possible pass Buffer or Object which inherits Uint8Array to function for data output. Of course length should match, or you can pass function which accept number of bytes and return instance with specified length.
<hr>
- In place operations (follow [bitcoin-core/secp256k1](https://github.com/bitcoin-core/secp256k1) API):
##### .privateKeyVerify(Buffer privateKey) -> Boolean
- `privateKeyNegate`
- `privateKeyTweakAdd`
- `privateKeyTweakMul`
- `signatureNormalize`
Verify an ECDSA *privateKey*.
If you need new instance this can be easily done with creating it before pass to functions. For example:
<hr>
```js
const newPrivateKey = secp256k1.privateKeyNegate(Buffer.from(privateKey))
```
##### .privateKeyExport(Buffer privateKey [, Boolean compressed = true]) -> Buffer
Export a *privateKey* in DER format.
<hr>
- [`.contextRandomize(seed: Uint8Array): void`](#contextrandomizeseed-uint8array-void)
- [`.privateKeyVerify(privateKey: Uint8Array): boolean`](#privatekeyverifyprivatekey-uint8array-boolean)
- [`.privateKeyNegate(privateKey: Uint8Array): Uint8Array`](#privatekeynegateprivatekey-uint8array-uint8array)
- [`.privateKeyTweakAdd(privateKey: Uint8Array, tweak: Uint8Array): Uint8Array`](#privatekeytweakaddprivatekey-uint8array-tweak-uint8array-uint8array)
- [`.privateKeyTweakMul(privateKey: Uint8Array, tweak: Uint8Array): Uint8Array`](#privatekeytweakmulprivatekey-uint8array-tweak-uint8array-uint8array)
- [`.publicKeyVerify(publicKey: Uint8Array): boolean`](#publickeyverifypublickey-uint8array-boolean)
- [`.publicKeyCreate(privateKey: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#publickeycreateprivatekey-uint8array-compressed-boolean--true-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.publicKeyConvert(publicKey: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#publickeyconvertpublickey-uint8array-compressed-boolean--true-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.publicKeyNegate(publicKey: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#publickeynegatepublickey-uint8array-compressed-boolean--true-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.publicKeyCombine(publicKeys: Uint8Array[], compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#publickeycombinepublickeys-uint8array-compressed-boolean--true-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.publicKeyTweakAdd(publicKey: Uint8Array, tweak: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#publickeytweakaddpublickey-uint8array-tweak-uint8array-compressed-boolean--true-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.publicKeyTweakMul(publicKey: Uint8Array, tweak: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#publickeytweakmulpublickey-uint8array-tweak-uint8array-compressed-boolean--true-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.signatureNormalize(signature: Uint8Array): Uint8Array`](#signaturenormalizesignature-uint8array-uint8array)
- [`.signatureExport(signature, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#signatureexportsignature-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.signatureImport(signature, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#signatureimportsignature-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.ecdsaSign(message: Uint8Array, privateKey: Uint8Array, { data, noncefn }: { data?: Uint8Array, noncefn?: ((message: Uint8Array, privateKey: Uint8Array, algo: null, data: Uint8Array, counter: number) => Uint8Array) } = {}, output: Uint8Array | ((len: number) => Uint8Array)): { signature: Uint8Array, recid: number }`](#ecdsasignmessage-uint8array-privatekey-uint8array--data-noncefn---data-uint8array-noncefn-message-uint8array-privatekey-uint8array-algo-null-data-uint8array-counter-number--uint8array----output-uint8array--len-number--uint8array--signature-uint8array-recid-number-)
- [`.ecdsaVerify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean`](#ecdsaverifysignature-uint8array-message-uint8array-publickey-uint8array-boolean)
- [`.ecdsaRecover(signature: Uint8Array, recid: number, message: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#ecdsarecoversignature-uint8array-recid-number-message-uint8array-compressed-boolean--true-output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
- [`.ecdh(publicKey: Uint8Array, privateKey: Uint8Array, { data, xbuf, ybuf, hashfn }: { data?: Uint8Array, xbuf?: Uint8Array, ybuf?: Uint8Array, hashfn?: ((x: Uint8Array, y: Uint8Array, data: Uint8Array) => Uint8Array) } = {}, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array`](#ecdhpublickey-uint8array-privatekey-uint8array--data-xbuf-ybuf-hashfn---data-uint8array-xbuf-uint8array-ybuf-uint8array-hashfn-x-uint8array-y-uint8array-data-uint8array--uint8array----output-uint8array--len-number--uint8array--len--new-uint8arraylen-uint8array)
##### .privateKeyImport(Buffer privateKey) -> Buffer
##### .contextRandomize(seed: Uint8Array): void
Import a *privateKey* in DER format.
Updates the context randomization to protect against side-channel leakage, `seed` should be Uint8Array with length 32.
<hr>
##### .privateKeyVerify(privateKey: Uint8Array): boolean
##### .privateKeyNegate(Buffer privateKey) -> Buffer
Verify a private key.
Negate a *privateKey* by subtracting it from the order of the curve's base point.
##### .privateKeyNegate(privateKey: Uint8Array): Uint8Array
<hr>
Negate a private key in place and return result.
##### .privateKeyModInverse(Buffer privateKey) -> Buffer
##### .privateKeyTweakAdd(privateKey: Uint8Array, tweak: Uint8Array): Uint8Array
Compute the inverse of a *privateKey* (modulo the order of the curve's base point).
Tweak a private key in place by adding tweak to it.
<hr>
##### .privateKeyTweakMul(privateKey: Uint8Array, tweak: Uint8Array): Uint8Array
##### .privateKeyTweakAdd(Buffer privateKey, Buffer tweak) -> Buffer
Tweak a private key in place by multiplying it by a tweak.
Tweak a *privateKey* by adding *tweak* to it.
##### .publicKeyVerify(publicKey: Uint8Array): boolean
<hr>
Verify a public key.
##### .privateKeyTweakMul(Buffer privateKey, Buffer tweak) -> Buffer
##### .publicKeyCreate(privateKey: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
Tweak a *privateKey* by multiplying it by a *tweak*.
Compute the public key for a secret key.
<hr>
##### .publicKeyConvert(publicKey: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
##### .publicKeyCreate(Buffer privateKey [, Boolean compressed = true]) -> Buffer
Reserialize public key to another format.
Compute the public key for a *privateKey*.
##### .publicKeyNegate(publicKey: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
<hr>
Negates a public key in place.
##### .publicKeyConvert(Buffer publicKey [, Boolean compressed = true]) -> Buffer
##### .publicKeyCombine(publicKeys: Uint8Array[], compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
Convert a *publicKey* to *compressed* or *uncompressed* form.
Add a number of public keys together.
<hr>
##### .publicKeyTweakAdd(publicKey: Uint8Array, tweak: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
##### .publicKeyVerify(Buffer publicKey) -> Boolean
Tweak a public key by adding tweak times the generator to it.
Verify an ECDSA *publicKey*.
##### .publicKeyTweakMul(publicKey: Uint8Array, tweak: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
<hr>
Tweak a public key by multiplying it by a tweak value.
##### .publicKeyTweakAdd(Buffer publicKey, Buffer tweak [, Boolean compressed = true]) -> Buffer
##### .signatureNormalize(signature: Uint8Array): Uint8Array
Tweak a *publicKey* by adding *tweak* times the generator to it.
Convert a signature to a normalized lower-S form in place.
<hr>
##### .signatureExport(signature, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
##### .publicKeyTweakMul(Buffer publicKey, Buffer tweak [, Boolean compressed = true]) -> Buffer
Export an ECDSA signature to DER format.
Tweak a *publicKey* by multiplying it by a *tweak* value.
##### .signatureImport(signature, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
<hr>
Parse a DER ECDSA signature.
##### .publicKeyCombine(Array<Buffer> publicKeys [, Boolean compressed = true]) -> Buffer
##### .ecdsaSign(message: Uint8Array, privateKey: Uint8Array, { data, noncefn }: { data?: Uint8Array, noncefn?: ((message: Uint8Array, privateKey: Uint8Array, algo: null, data: Uint8Array, counter: number) => Uint8Array) } = {}, output: Uint8Array | ((len: number) => Uint8Array)): { signature: Uint8Array, recid: number }
Add a given *publicKeys* together.
Create an ECDSA signature.
<hr>
##### .ecdsaVerify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean
##### .signatureNormalize(Buffer signature) -> Buffer
Convert a *signature* to a normalized lower-S form.
<hr>
##### .signatureExport(Buffer signature) -> Buffer
Serialize an ECDSA *signature* in DER format.
<hr>
##### .signatureImport(Buffer signature) -> Buffer
Parse a DER ECDSA *signature* (follow by [BIP66](https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki)).
<hr>
##### .signatureImportLax(Buffer signature) -> Buffer
Same as [signatureImport](#signatureimportbuffer-signature---buffer) but not follow by [BIP66](https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki).
<hr>
##### .sign(Buffer message, Buffer privateKey [, Object options]) -> {signature: Buffer, recovery: number}
Create an ECDSA signature. Always return low-S signature.
Inputs: 32-byte message m, 32-byte scalar key d, 32-byte scalar nonce k.
* Compute point R = k * G. Reject nonce if R's x coordinate is zero.
* Compute 32-byte scalar r, the serialization of R's x coordinate.
* Compose 32-byte scalar s = k^-1 \* (r \* d + m). Reject nonce if s is zero.
* The signature is (r, s).
###### Option: `Function noncefn`
Nonce generator. By default it is [rfc6979](https://tools.ietf.org/html/rfc6979).
Function signature:
##### noncefn(Buffer message, Buffer privateKey, ?Buffer algo, ?Buffer data, Number attempt) -> Buffer
###### Option: `Buffer data`
Additional data for [noncefn](#option-function-noncefn) (RFC 6979 3.6) (32 bytes). By default is `null`.
<hr>
##### .verify(Buffer message, Buffer signature, Buffer publicKey) -> Boolean
Verify an ECDSA signature.
##### .ecdsaRecover(signature: Uint8Array, recid: number, message: Uint8Array, compressed: boolean = true, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
Note: **return false for high signatures!**
Inputs: 32-byte message m, public key point Q, signature: (32-byte r, scalar s).
* Signature is invalid if r is zero.
* Signature is invalid if s is zero.
* Compute point R = (s^-1 \* m \* G + s^-1 \* r \* Q). Reject if R is infinity.
* Signature is valid if R's x coordinate equals to r.
<hr>
##### .recover(Buffer message, Buffer signature, Number recovery [, Boolean compressed = true]) -> Buffer
Recover an ECDSA public key from a signature.
##### .ecdh(publicKey: Uint8Array, privateKey: Uint8Array, { data, xbuf, ybuf, hashfn }: { data?: Uint8Array, xbuf?: Uint8Array, ybuf?: Uint8Array, hashfn?: ((x: Uint8Array, y: Uint8Array, data: Uint8Array) => Uint8Array) } = {}, output: Uint8Array | ((len: number) => Uint8Array) = (len) => new Uint8Array(len)): Uint8Array
<hr>
Compute an EC Diffie-Hellman secret in constant time.
##### .ecdh(Buffer publicKey, Buffer privateKey) -> Buffer
Compute an EC Diffie-Hellman secret and applied sha256 to compressed public key.
<hr>
##### .ecdhUnsafe(Buffer publicKey, Buffer privateKey [, Boolean compressed = true]) -> Buffer
Compute an EC Diffie-Hellman secret and return public key as result.

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

const addon = require('node-gyp-build')(__dirname)
module.exports = require('./lib')(new addon.Secp256k1())
'use strict'
module.exports = require('bindings')('secp256k1')

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

'use strict'
module.exports = require('./lib')(require('./lib/elliptic'))

@@ -0,5 +1,10 @@

'use strict'
try {
module.exports = require('./bindings')
} catch (err) {
if (process.env.DEBUG) {
console.error('Secp256k1 bindings are not compiled. Pure JS implementation will be used.')
}
module.exports = require('./elliptic')
}

@@ -1,336 +0,245 @@

const errors = {
IMPOSSIBLE_CASE: 'Impossible case. Please create issue.',
TWEAK_ADD:
'The tweak was out of range or the resulted private key is invalid',
TWEAK_MUL: 'The tweak was out of range or equal to zero',
CONTEXT_RANDOMIZE_UNKNOW: 'Unknow error on context randomization',
SECKEY_INVALID: 'Private Key is invalid',
PUBKEY_PARSE: 'Public Key could not be parsed',
PUBKEY_SERIALIZE: 'Public Key serialization error',
PUBKEY_COMBINE: 'The sum of the public keys is not valid',
SIG_PARSE: 'Signature could not be parsed',
SIGN: 'The nonce generation function failed, or the private key was invalid',
RECOVER: 'Public key could not be recover',
ECDH: 'Scalar was invalid (zero or overflow)'
}
'use strict'
var assert = require('./assert')
var der = require('./der')
var messages = require('./messages.json')
function assert (cond, msg) {
if (!cond) throw new Error(msg)
function initCompressedValue (value, defaultValue) {
if (value === undefined) return defaultValue
assert.isBoolean(value, messages.COMPRESSED_TYPE_INVALID)
return value
}
function isUint8Array (name, value, length) {
assert(value instanceof Uint8Array, `Expected ${name} to be an Uint8Array`)
module.exports = function (secp256k1) {
return {
privateKeyVerify: function (privateKey) {
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
return privateKey.length === 32 && secp256k1.privateKeyVerify(privateKey)
},
if (length !== undefined) {
if (Array.isArray(length)) {
const numbers = length.join(', ')
const msg = `Expected ${name} to be an Uint8Array with length [${numbers}]`
assert(length.includes(value.length), msg)
} else {
const msg = `Expected ${name} to be an Uint8Array with length ${length}`
assert(value.length === length, msg)
}
}
}
privateKeyExport: function (privateKey, compressed) {
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
function isCompressed (value) {
assert(toTypeString(value) === 'Boolean', 'Expected compressed to be a Boolean')
}
compressed = initCompressedValue(compressed, true)
var publicKey = secp256k1.privateKeyExport(privateKey, compressed)
function getAssertedOutput (output = (len) => new Uint8Array(len), length) {
if (typeof output === 'function') output = output(length)
isUint8Array('output', output, length)
return output
}
return der.privateKeyExport(privateKey, publicKey, compressed)
},
function toTypeString (value) {
return Object.prototype.toString.call(value).slice(8, -1)
}
privateKeyImport: function (privateKey) {
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
module.exports = (secp256k1) => {
return {
contextRandomize (seed) {
assert(
seed === null || seed instanceof Uint8Array,
'Expected seed to be an Uint8Array or null'
)
if (seed !== null) isUint8Array('seed', seed, 32)
privateKey = der.privateKeyImport(privateKey)
if (privateKey && privateKey.length === 32 && secp256k1.privateKeyVerify(privateKey)) return privateKey
switch (secp256k1.contextRandomize(seed)) {
case 1:
throw new Error(errors.CONTEXT_RANDOMIZE_UNKNOW)
}
throw new Error(messages.EC_PRIVATE_KEY_IMPORT_DER_FAIL)
},
privateKeyVerify (seckey) {
isUint8Array('private key', seckey, 32)
privateKeyNegate: function (privateKey) {
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
return secp256k1.privateKeyVerify(seckey) === 0
return secp256k1.privateKeyNegate(privateKey)
},
privateKeyNegate (seckey) {
isUint8Array('private key', seckey, 32)
privateKeyModInverse: function (privateKey) {
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
switch (secp256k1.privateKeyNegate(seckey)) {
case 0:
return seckey
case 1:
throw new Error(errors.IMPOSSIBLE_CASE)
}
return secp256k1.privateKeyModInverse(privateKey)
},
privateKeyTweakAdd (seckey, tweak) {
isUint8Array('private key', seckey, 32)
isUint8Array('tweak', tweak, 32)
privateKeyTweakAdd: function (privateKey, tweak) {
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
switch (secp256k1.privateKeyTweakAdd(seckey, tweak)) {
case 0:
return seckey
case 1:
throw new Error(errors.TWEAK_ADD)
}
assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID)
assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)
return secp256k1.privateKeyTweakAdd(privateKey, tweak)
},
privateKeyTweakMul (seckey, tweak) {
isUint8Array('private key', seckey, 32)
isUint8Array('tweak', tweak, 32)
privateKeyTweakMul: function (privateKey, tweak) {
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
switch (secp256k1.privateKeyTweakMul(seckey, tweak)) {
case 0:
return seckey
case 1:
throw new Error(errors.TWEAK_MUL)
}
assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID)
assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)
return secp256k1.privateKeyTweakMul(privateKey, tweak)
},
publicKeyVerify (pubkey) {
isUint8Array('public key', pubkey, [33, 65])
publicKeyCreate: function (privateKey, compressed) {
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
return secp256k1.publicKeyVerify(pubkey) === 0
compressed = initCompressedValue(compressed, true)
return secp256k1.publicKeyCreate(privateKey, compressed)
},
publicKeyCreate (seckey, compressed = true, output) {
isUint8Array('private key', seckey, 32)
isCompressed(compressed)
output = getAssertedOutput(output, compressed ? 33 : 65)
publicKeyConvert: function (publicKey, compressed) {
assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
switch (secp256k1.publicKeyCreate(output, seckey)) {
case 0:
return output
case 1:
throw new Error(errors.SECKEY_INVALID)
case 2:
throw new Error(errors.PUBKEY_SERIALIZE)
}
compressed = initCompressedValue(compressed, true)
return secp256k1.publicKeyConvert(publicKey, compressed)
},
publicKeyConvert (pubkey, compressed = true, output) {
isUint8Array('public key', pubkey, [33, 65])
isCompressed(compressed)
output = getAssertedOutput(output, compressed ? 33 : 65)
publicKeyVerify: function (publicKey) {
assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
return secp256k1.publicKeyVerify(publicKey)
},
switch (secp256k1.publicKeyConvert(output, pubkey)) {
case 0:
return output
case 1:
throw new Error(errors.PUBKEY_PARSE)
case 2:
throw new Error(errors.PUBKEY_SERIALIZE)
}
publicKeyTweakAdd: function (publicKey, tweak, compressed) {
assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID)
assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)
compressed = initCompressedValue(compressed, true)
return secp256k1.publicKeyTweakAdd(publicKey, tweak, compressed)
},
publicKeyNegate (pubkey, compressed = true, output) {
isUint8Array('public key', pubkey, [33, 65])
isCompressed(compressed)
output = getAssertedOutput(output, compressed ? 33 : 65)
publicKeyTweakMul: function (publicKey, tweak, compressed) {
assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
switch (secp256k1.publicKeyNegate(output, pubkey)) {
case 0:
return output
case 1:
throw new Error(errors.PUBKEY_PARSE)
case 2:
throw new Error(errors.IMPOSSIBLE_CASE)
case 3:
throw new Error(errors.PUBKEY_SERIALIZE)
}
assert.isBuffer(tweak, messages.TWEAK_TYPE_INVALID)
assert.isBufferLength(tweak, 32, messages.TWEAK_LENGTH_INVALID)
compressed = initCompressedValue(compressed, true)
return secp256k1.publicKeyTweakMul(publicKey, tweak, compressed)
},
publicKeyCombine (pubkeys, compressed = true, output) {
assert(Array.isArray(pubkeys), 'Expected public keys to be an Array')
assert(pubkeys.length > 0, 'Expected public keys array will have more than zero items')
for (const pubkey of pubkeys) {
isUint8Array('public key', pubkey, [33, 65])
publicKeyCombine: function (publicKeys, compressed) {
assert.isArray(publicKeys, messages.EC_PUBLIC_KEYS_TYPE_INVALID)
assert.isLengthGTZero(publicKeys, messages.EC_PUBLIC_KEYS_LENGTH_INVALID)
for (var i = 0; i < publicKeys.length; ++i) {
assert.isBuffer(publicKeys[i], messages.EC_PUBLIC_KEY_TYPE_INVALID)
assert.isBufferLength2(publicKeys[i], 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
}
isCompressed(compressed)
output = getAssertedOutput(output, compressed ? 33 : 65)
switch (secp256k1.publicKeyCombine(output, pubkeys)) {
case 0:
return output
case 1:
throw new Error(errors.PUBKEY_PARSE)
case 2:
throw new Error(errors.PUBKEY_COMBINE)
case 3:
throw new Error(errors.PUBKEY_SERIALIZE)
}
compressed = initCompressedValue(compressed, true)
return secp256k1.publicKeyCombine(publicKeys, compressed)
},
publicKeyTweakAdd (pubkey, tweak, compressed = true, output) {
isUint8Array('public key', pubkey, [33, 65])
isUint8Array('tweak', tweak, 32)
isCompressed(compressed)
output = getAssertedOutput(output, compressed ? 33 : 65)
signatureNormalize: function (signature) {
assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID)
assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
switch (secp256k1.publicKeyTweakAdd(output, pubkey, tweak)) {
case 0:
return output
case 1:
throw new Error(errors.PUBKEY_PARSE)
case 2:
throw new Error(errors.TWEAK_ADD)
}
return secp256k1.signatureNormalize(signature)
},
publicKeyTweakMul (pubkey, tweak, compressed = true, output) {
isUint8Array('public key', pubkey, [33, 65])
isUint8Array('tweak', tweak, 32)
isCompressed(compressed)
output = getAssertedOutput(output, compressed ? 33 : 65)
signatureExport: function (signature) {
assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID)
assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
switch (secp256k1.publicKeyTweakMul(output, pubkey, tweak)) {
case 0:
return output
case 1:
throw new Error(errors.PUBKEY_PARSE)
case 2:
throw new Error(errors.TWEAK_MUL)
}
var sigObj = secp256k1.signatureExport(signature)
return der.signatureExport(sigObj)
},
signatureNormalize (sig) {
isUint8Array('signature', sig, 64)
signatureImport: function (sig) {
assert.isBuffer(sig, messages.ECDSA_SIGNATURE_TYPE_INVALID)
assert.isLengthGTZero(sig, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
switch (secp256k1.signatureNormalize(sig)) {
case 0:
return sig
case 1:
throw new Error(errors.SIG_PARSE)
}
var sigObj = der.signatureImport(sig)
if (sigObj) return secp256k1.signatureImport(sigObj)
throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL)
},
signatureExport (sig, output) {
isUint8Array('signature', sig, 64)
output = getAssertedOutput(output, 72)
signatureImportLax: function (sig) {
assert.isBuffer(sig, messages.ECDSA_SIGNATURE_TYPE_INVALID)
assert.isLengthGTZero(sig, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
const obj = { output, outputlen: 72 }
switch (secp256k1.signatureExport(obj, sig)) {
case 0:
return output.slice(0, obj.outputlen)
case 1:
throw new Error(errors.SIG_PARSE)
case 2:
throw new Error(errors.IMPOSSIBLE_CASE)
}
var sigObj = der.signatureImportLax(sig)
if (sigObj) return secp256k1.signatureImport(sigObj)
throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL)
},
signatureImport (sig, output) {
isUint8Array('signature', sig)
output = getAssertedOutput(output, 64)
sign: function (message, privateKey, options) {
assert.isBuffer(message, messages.MSG32_TYPE_INVALID)
assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID)
switch (secp256k1.signatureImport(output, sig)) {
case 0:
return output
case 1:
throw new Error(errors.SIG_PARSE)
case 2:
throw new Error(errors.IMPOSSIBLE_CASE)
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
var data = null
var noncefn = null
if (options !== undefined) {
assert.isObject(options, messages.OPTIONS_TYPE_INVALID)
if (options.data !== undefined) {
assert.isBuffer(options.data, messages.OPTIONS_DATA_TYPE_INVALID)
assert.isBufferLength(options.data, 32, messages.OPTIONS_DATA_LENGTH_INVALID)
data = options.data
}
if (options.noncefn !== undefined) {
assert.isFunction(options.noncefn, messages.OPTIONS_NONCEFN_TYPE_INVALID)
noncefn = options.noncefn
}
}
return secp256k1.sign(message, privateKey, noncefn, data)
},
ecdsaSign (msg32, seckey, options = {}, output) {
isUint8Array('message', msg32, 32)
isUint8Array('private key', seckey, 32)
assert(toTypeString(options) === 'Object', 'Expected options to be an Object')
if (options.data !== undefined) isUint8Array('options.data', options.data)
if (options.noncefn !== undefined) assert(toTypeString(options.noncefn) === 'Function', 'Expected options.noncefn to be a Function')
output = getAssertedOutput(output, 64)
verify: function (message, signature, publicKey) {
assert.isBuffer(message, messages.MSG32_TYPE_INVALID)
assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID)
const obj = { signature: output, recid: null }
switch (secp256k1.ecdsaSign(obj, msg32, seckey, options.data, options.noncefn)) {
case 0:
return obj
case 1:
throw new Error(errors.SIGN)
case 2:
throw new Error(errors.IMPOSSIBLE_CASE)
}
assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID)
assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
return secp256k1.verify(message, signature, publicKey)
},
ecdsaVerify (sig, msg32, pubkey) {
isUint8Array('signature', sig, 64)
isUint8Array('message', msg32, 32)
isUint8Array('public key', pubkey, [33, 65])
recover: function (message, signature, recovery, compressed) {
assert.isBuffer(message, messages.MSG32_TYPE_INVALID)
assert.isBufferLength(message, 32, messages.MSG32_LENGTH_INVALID)
switch (secp256k1.ecdsaVerify(sig, msg32, pubkey)) {
case 0:
return true
case 3:
return false
case 1:
throw new Error(errors.SIG_PARSE)
case 2:
throw new Error(errors.PUBKEY_PARSE)
}
assert.isBuffer(signature, messages.ECDSA_SIGNATURE_TYPE_INVALID)
assert.isBufferLength(signature, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID)
assert.isNumber(recovery, messages.RECOVERY_ID_TYPE_INVALID)
assert.isNumberInInterval(recovery, -1, 4, messages.RECOVERY_ID_VALUE_INVALID)
compressed = initCompressedValue(compressed, true)
return secp256k1.recover(message, signature, recovery, compressed)
},
ecdsaRecover (sig, recid, msg32, compressed = true, output) {
isUint8Array('signature', sig, 64)
assert(
toTypeString(recid) === 'Number' &&
recid >= 0 &&
recid <= 3,
'Expected recovery id to be a Number within interval [0, 3]'
)
isUint8Array('message', msg32, 32)
isCompressed(compressed)
output = getAssertedOutput(output, compressed ? 33 : 65)
ecdh: function (publicKey, privateKey) {
assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
switch (secp256k1.ecdsaRecover(output, sig, recid, msg32)) {
case 0:
return output
case 1:
throw new Error(errors.SIG_PARSE)
case 2:
throw new Error(errors.RECOVER)
case 3:
throw new Error(errors.IMPOSSIBLE_CASE)
}
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
return secp256k1.ecdh(publicKey, privateKey)
},
ecdh (pubkey, seckey, options = {}, output) {
isUint8Array('public key', pubkey, [33, 65])
isUint8Array('private key', seckey, 32)
assert(toTypeString(options) === 'Object', 'Expected options to be an Object')
if (options.data !== undefined) isUint8Array('options.data', options.data)
if (options.hashfn !== undefined) {
assert(toTypeString(options.hashfn) === 'Function', 'Expected options.hashfn to be a Function')
if (options.xbuf !== undefined) isUint8Array('options.xbuf', options.xbuf, 32)
if (options.ybuf !== undefined) isUint8Array('options.ybuf', options.ybuf, 32)
isUint8Array('output', output)
} else {
output = getAssertedOutput(output, 32)
}
ecdhUnsafe: function (publicKey, privateKey, compressed) {
assert.isBuffer(publicKey, messages.EC_PUBLIC_KEY_TYPE_INVALID)
assert.isBufferLength2(publicKey, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID)
switch (secp256k1.ecdh(output, pubkey, seckey, options.data, options.hashfn, options.xbuf, options.ybuf)) {
case 0:
return output
case 1:
throw new Error(errors.PUBKEY_PARSE)
case 2:
throw new Error(errors.ECDH)
}
assert.isBuffer(privateKey, messages.EC_PRIVATE_KEY_TYPE_INVALID)
assert.isBufferLength(privateKey, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID)
compressed = initCompressedValue(compressed, true)
return secp256k1.ecdhUnsafe(publicKey, privateKey, compressed)
}
}
}
{
"name": "secp256k1",
"version": "4.0.2",
"version": "3.8.0",
"description": "This module provides native bindings to ecdsa secp256k1 functions",

@@ -14,6 +14,2 @@ "keywords": [

},
"repository": {
"type": "git",
"url": "https://github.com/cryptocoinjs/secp256k1-node.git"
},
"license": "MIT",

@@ -28,22 +24,65 @@ "author": "Martin Becze <mjbecze@gmail.com>",

],
"files": [
"lib",
"src",
"API.md",
"binding.gyp",
"bindings.js",
"elliptic.js",
"index.js",
"js.js",
"utils/has_lib.sh"
],
"main": "./index.js",
"browser": {
"./index.js": "./elliptic.js"
"repository": {
"type": "git",
"url": "https://github.com/cryptocoinjs/secp256k1-node.git"
},
"scripts": {
"install": "node-gyp-build || exit 0"
"coverage": "RANDOM_TESTS_REPEAT=1 nyc tape test/index.js",
"coverage-lcov": "npm run coverage && nyc report -r lcov",
"install": "npm run rebuild || echo \"Secp256k1 bindings compilation fail. Pure JS implementation will be used.\"",
"lint": "standard",
"rebuild": "node-gyp rebuild",
"test": "npm run lint && npm run unit",
"test:browser": "karma start karma.conf.js",
"unit": "tape test/index.js"
},
"dependencies": {
"bindings": "^1.5.0",
"bip66": "^1.1.5",
"bn.js": "^4.11.8",
"create-hash": "^1.2.0",
"drbg.js": "^1.0.1",
"elliptic": "^6.5.2",
"node-addon-api": "^2.0.0",
"node-gyp-build": "^4.2.0"
"nan": "^2.14.0",
"safe-buffer": "^5.1.2"
},
"devDependencies": {
"bignum": "https://github.com/fanatid/node-bignum#e688fd40dff43b03480bcdb5e4c099ee9ac27102",
"browserify": "^16.2.3",
"karma": "^1.3.0",
"karma-browserify": "^5.0.4",
"karma-chrome-launcher": "^2.2.0",
"karma-detect-browsers": "^2.3.3",
"karma-env-preprocessor": "^0.1.1",
"karma-firefox-launcher": "^1.0.0",
"karma-tap": "^3.1.1",
"node-gyp": "^4.0.0",
"nyc": "^14.1.0",
"standard": "^12.0.1",
"tape": "^4.10.1",
"xorshift.js": "^1.0.3"
},
"engines": {
"node": ">=10.0.0"
"node": ">=4.0.0"
},
"gypfile": true
"gypfile": true,
"browser": {
"./index.js": "./elliptic.js"
}
,"_resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.2.tgz"
,"_integrity": "sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg=="
,"_from": "secp256k1@4.0.2"
,"_resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.8.0.tgz"
,"_integrity": "sha512-k5ke5avRZbtl9Tqx/SA7CbY3NF6Ro+Sj9cZxezFzuBlLDmyqPiL8hJJ+EmzD8Ig4LUDByHJ3/iPOVoRixs/hmw=="
,"_from": "secp256k1@3.8.0"
}
# secp256k1-node
This module provides native bindings to [bitcoin-core/secp256k1](https://github.com/bitcoin-core/secp256k1). In browser [elliptic](https://github.com/indutny/elliptic) will be used as fallback.
Version | Mac/Linux | Windows
------- | --------- | -------
[![NPM Package](https://img.shields.io/npm/v/secp256k1.svg?style=flat-square)](https://www.npmjs.org/package/secp256k1) | [![Build Status](https://img.shields.io/travis/cryptocoinjs/secp256k1-node.svg?branch=master&style=flat-square)](https://travis-ci.org/cryptocoinjs/secp256k1-node) | [![AppVeyor](https://img.shields.io/appveyor/ci/fanatid/secp256k1-node.svg?branch=master&style=flat-square)](https://ci.appveyor.com/project/fanatid/secp256k1-node)
Works on node version 10.0.0 or greater, because use [N-API](https://nodejs.org/api/n-api.html).
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
This module provides native bindings to [bitcoin-core/secp256k1](https://github.com/bitcoin-core/secp256k1). In browser [elliptic](https://github.com/indutny/elliptic) will be used.
This library is experimental, so use at your own risk. Works on node version 4.0.0 or greater.
## Installation

@@ -47,8 +53,5 @@

* [API Reference (v4.x)](API.md) (current version)
* [API Reference (v3.x)](https://github.com/cryptocoinjs/secp256k1-node/blob/v3.x/API.md)
* [API Reference (v3.x)](https://github.com/cryptocoinjs/secp256k1-node/blob/master/API.md)
* [API Reference (v2.x)](https://github.com/cryptocoinjs/secp256k1-node/blob/v2.x/API.md)
##### Private Key generation, Public Key creation, signature creation, signature verification
```js

@@ -61,4 +64,2 @@ const { randomBytes } = require('crypto')

// generate message to sign
// message should have 32-byte length, if you have some other length you can hash message
// for example `msg = sha256(rawMessage)`
const msg = randomBytes(32)

@@ -76,6 +77,6 @@

// sign the message
const sigObj = secp256k1.ecdsaSign(msg, privKey)
const sigObj = secp256k1.sign(msg, privKey)
// verify the signature
console.log(secp256k1.ecdsaVerify(sigObj.signature, msg, pubKey))
console.log(secp256k1.verify(msg, sigObj.signature, pubKey))
// => true

@@ -86,36 +87,8 @@ ```

##### Get X point of ECDH
## Second pure js implementation
```js
const { randomBytes } = require('crypto')
// const secp256k1 = require('./elliptic')
const secp256k1 = require('./')
Project has yet one secp256k1 implementation based on [elliptic](http://github.com/indutny/elliptic) and [bn.js](http://github.com/indutny/bn.js). The main purpose of this smaller size, high performance and easy code audit. This implementation is super experimental, use it at your own risk.
// generate privKey
function getPrivateKey () {
while (true) {
const privKey = randomBytes(32)
if (secp256k1.privateKeyVerify(privKey)) return privKey
}
}
// generate private and public keys
const privKey = getPrivateKey()
const pubKey = secp256k1.publicKeyCreate(getPrivateKey())
// compressed public key from X and Y
function hashfn (x, y) {
const pubKey = new Uint8Array(33)
pubKey[0] = (y[31] & 1) === 0 ? 0x02 : 0x03
pubKey.set(x, 1)
return pubKey
}
// get X point of ecdh
const ecdhPointX = secp256k1.ecdh(pubKey, privKey, { hashfn }, Buffer.alloc(33))
console.log(ecdhPointX.toString('hex'))
```
## LICENSE
This library is free and open-source software released under the MIT license.
{
"name": "ganache-cli",
"version": "6.12.0",
"version": "6.12.1-tezos.0",
"bin": {

@@ -16,3 +16,4 @@ "ganache-cli": "cli.js"

"dependencies": {
"ethereumjs-util": "6.2.1",
"ethereumjs-util": "6.1.0",
"ganache-core": "2.13.2-tezos.2",
"source-map-support": "0.5.12",

@@ -27,4 +28,3 @@ "yargs": "13.2.4"

"devDependencies": {
"@semantic-release/git": "^9.0.0",
"ganache-core": "2.13.0",
"js-scrypt": "0.2.0",
"node-loader": "^0.6.0",

@@ -34,8 +34,13 @@ "notp": "2.0.3",

"prepend-file": "^1.3.1",
"semantic-release": "^17.1.1",
"scrypt": "6.0.3",
"semantic-release": "^17.0.7",
"sha3": "1.2.2",
"shebang-loader": "0.0.1",
"thirty-two": "1.0.2",
"webpack": "4.43.0",
"webpack-cli": "3.3.12"
"webpack-cli": "3.1.0"
},
"optionalDependencies": {
"deasync": "0.1.20"
},
"repository": {

@@ -53,26 +58,5 @@ "type": "git",

"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/github",
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": [
"package.json",
"package-lock.json",
"npm-shrinkwrap.json"
],
"message": "${nextRelease.version}\n\n${nextRelease.notes}"
}
],
"@semantic-release/release-notes-generator"
]
}
}

@@ -15,6 +15,8 @@ <p align="center">

## Welcome to Ganache CLI
Ganache CLI, part of the Truffle suite of Ethereum development tools, is the command line version of [Ganache](https://github.com/trufflesuite/ganache), your personal blockchain for Ethereum development.
Ganache CLI, part of the Truffle suite of blockchain development tools, is the command line version of [Ganache](https://github.com/trufflesuite/ganache), your personal blockchain for Ethereum development.
Ganache CLI uses ethereumjs to simulate full client behavior and make developing Ethereum applications faster, easier, and safer. It also includes all popular RPC functions and features (like events) and can be run deterministically to make development a breeze.
For Tezos networks, Ganache CLI uses Flextesa to make developing Tezos applications faster, easier, and safer.
### Looking for TestRPC?

@@ -26,3 +28,3 @@

`ganache-cli` is written in JavaScript and distributed as a Node.js package via `npm`. Make sure you have Node.js (>= v8) installed.
`ganache-cli` is written in JavaScript and distributed as a Node.js package via `npm`. Make sure you have Node.js (>= v10.7.0) installed.

@@ -41,4 +43,2 @@ Using npm:

`ganache-cli` utilizes [`ganache-core`](https://github.com/trufflesuite/ganache-core) internally, which is distributed with optional native dependencies for increased performance. If these native dependencies fail to install on your system `ganache-cli` will automatically fallback to `ganache-core`’s pre-bundled JavaScript build.
Having problems? Be sure to check out the [FAQ](https://github.com/trufflesuite/ganache-cli/wiki/FAQ) and if you're still having issues and you're sure its a problem with `ganache-cli` please open an issue.

@@ -56,11 +56,18 @@

### Ethereum and Tezos
* `-a` or `--accounts`: Specify the number of accounts to generate at startup.
* `-e` or `--defaultBalanceEther`: Amount of ether to assign each test account. Default is 100.
* `-e` or `--defaultBalance` (alias: `--defaultBalanceEther`): Amount of Ether/Tez to assign each test account. Default is 100.
* `-d` or `--deterministic`: Generate deterministic addresses based on a pre-defined mnemonic.
* `-s` or `--seed`: Use arbitrary data to generate accounts to be used.
* `-p` or `--port`: Port number to listen on. Defaults to port `8545` (ethereum) or `8732` (tezos).
* `-h` or `--host` or `--hostname`: Hostname to listen on. Defaults to 127.0.0.1 (defaults to 0.0.0.0 for Docker instances of ganache-cli).
* `-?` or `--help`: Display help information
* `--version`: Display the version of ganache-cli
### Ethereum only
* `-b` or `--blockTime`: Specify blockTime in seconds for automatic mining. If you don't specify this flag, ganache will instantly mine a new block for every transaction. Using the --blockTime flag is discouraged unless you have tests which require a specific mining interval.
* `-d` or `--deterministic`: Generate deterministic addresses based on a pre-defined mnemonic.
* `-n` or `--secure`: Lock available accounts by default (good for third party transaction signing)
* `-m` or `--mnemonic`: Use a bip39 mnemonic phrase for generating a PRNG seed, which is in turn used for hierarchical deterministic (HD) account generation.
* `-p` or `--port`: Port number to listen on. Defaults to 8545.
* `-h` or `--host` or `--hostname`: Hostname to listen on. Defaults to 127.0.0.1 (defaults to 0.0.0.0 for Docker instances of ganache-cli).
* `-s` or `--seed`: Use arbitrary data to generate the HD wallet mnemonic to be used.
* `-g` or `--gasPrice`: The price of gas in wei (defaults to 20000000000)

@@ -71,5 +78,3 @@ * `-l` or `--gasLimit`: The block gas limit (defaults to 0x6691b7)

* `-f` or `--fork`: Fork from another currently running Ethereum client at a given block. Input should be the HTTP location and port of the other client, e.g. `http://localhost:8545`. You can optionally specify the block to fork from using an `@` sign: `http://localhost:8545@1599200`.
* `forkCacheSize`: `number` - The maximum size, in bytes, of the in-memory cache for queries on a chain fork. Defaults to `1_073_741_824` bytes (1 gigabyte). You can set this to `0` to disable caching (not recommended), or to `-1` for unlimited (will be limited by your node process).
* `-i` or `--networkId`: Specify the network id ganache-cli will use to identify itself (defaults to the current time or the network id of the forked blockchain if configured)
* `--chainId`: Specify the Chain ID ganache-cli will use for `eth_chainId` RPC and the `CHAINID` opcode. For legacy reasons, the default is currently `1337` for `eth_chainId` RPC and `1` for the `CHAINID` opcode. Setting this flag will align the chainId values. This will be fixed in the next major version of ganache-cli and ganache-core!
* `--db`: Specify a path to a directory to save the chain database. If a database already exists, ganache-cli will initialize that chain instead of creating a new one.

@@ -80,4 +85,2 @@ * `--debug`: Output VM opcodes for debugging

* `-v` or `--verbose`: Log all requests and responses to stdout
* `-?` or `--help`: Display help information
* `--version`: Display the version of ganache-cli
* `--account_keys_path` or `--acctKeys`: Specifies a file to save accounts and private keys to, for testing.

@@ -88,4 +91,5 @@ * `--noVMErrorsOnRPCResponse`: Do not transmit transaction failures as RPC errors. Enable this flag for error reporting behaviour which is compatible with other clients such as geth and Parity.

* `-t` or `--time`: Date (ISO 8601) that the first block should start. Use this feature, along with the evm_increaseTime method to test time-dependent code.
* `--deasync`: `boolean` Synchronizes ganache server startup. Useful in certain scenarios - see ganache-cli issue [#733](https://github.com/trufflesuite/ganache-cli/issues/733).
Special Options:
Special Ethereum Options:

@@ -118,2 +122,12 @@ * `--account`: Specify `--account=...` (no 's') any number of times passing arbitrary private keys and their associated balances to generate initial addresses:

As a general HTTP and WebSocket server:
```javascript
const ganache = require("ganache-cli");
const server = ganache.server();
server.listen(port, function(err, blockchain) {...});
```
### Ethereum:
As a [Web3](https://github.com/ethereum/web3.js/) provider:

@@ -142,10 +156,2 @@

As a general HTTP and WebSocket server:
```javascript
const ganache = require("ganache-cli");
const server = ganache.server();
server.listen(port, function(err, blockchain) {...});
```
## Options

@@ -155,14 +161,21 @@

* `"accounts"`: `Array` of `Object`'s. Each object should have a `balance` key with a hexadecimal value. The key `secretKey` can also be specified, which represents the account's private key. If no `secretKey`, the address is auto-generated with the given balance. If specified, the key is used to determine the account's address.
### Ethereum and Tezos
* `"flavor"`: The blockchain technology to simulate. Valid values are `"ethereum"` or `"tezos"`. Default is `"ethereum"`.
* `"logger"`: `Object` - Object, like `console`, that implements a `log()` function.
* `"total_accounts"`: `number` - Number of accounts to generate at startup.
* `"port"`: `number` Port number to listen on when running as a server. Defaults to port `8545` (ethereum) or `8732` (tezos).
* `"seed"`: `string` Use arbitrary data to generate accounts to be used.
### Ethereum
* `"accounts"`: `Array` of `Object`'s of the following shape: `{ secretKey: privateKey, balance: HexString }`.
* If `secretKey` is specified, the key is used to determine the account's address. Otherwise, the address is auto-generated.
* The `balance` is a hexadecimal value of the amount of Ether (in Wei) you want the account to be pre-loaded with.
* `"blockTime"`: `number` - Specify blockTime in seconds for automatic mining. If you don't specify this flag, ganache will instantly mine a new block for every transaction. Using the `blockTime` option is discouraged unless you have tests which require a specific mining interval.
* `"debug"`: `boolean` - Output VM opcodes for debugging
* `"blockTime"`: `number` - Specify blockTime in seconds for automatic mining. If you don't specify this flag, ganache will instantly mine a new block for every transaction. Using the `blockTime` option is discouraged unless you have tests which require a specific mining interval.
* `"logger"`: `Object` - Object, like `console`, that implements a `log()` function.
* `"default_balance_ether"`: `number` - The default account balance, specified in Ether.
* `"mnemonic"`: Use a specific HD wallet mnemonic to generate initial addresses.
* `"port"`: `number` Port number to listen on when running as a server.
* `"seed"`: Use arbitrary data to generate the HD wallet mnemonic to be used.
* `"default_balance_ether"`: `number` - The default account balance, specified in ether.
* `"total_accounts"`: `number` - Number of accounts to generate at startup.
* `"fork"`: `string` or `object` - Fork from another currently running Ethereum client at a given block. When a `string`, input should be the HTTP location and port of the other client, e.g. `http://localhost:8545`. You can optionally specify the block to fork from using an `@` sign: `http://localhost:8545@1599200`. Can also be a `Web3 Provider` object, optionally used in conjunction with the `fork_block_number` option below.
* `"fork_block_number"`: `string` or `number` - Block number the provider should fork from, when the `fork` option is specified. If the `fork` option is specified as a string including the `@` sign and a block number, the block number in the `fork` parameter takes precedence.
`forkCacheSize`: `number` - The maximum size, in bytes, of the in-memory cache for queries on a chain fork. Defaults to `1_073_741_824` bytes (1 gigabyte). You can set this to `0` to disable caching (not recommended), or to `-1` for unlimited (will be limited by your node/browser process).
* `"network_id"`: Specify the network id ganache-core will use to identify itself (defaults to the current time or the network id of the forked blockchain if configured)

@@ -185,4 +198,9 @@ * `"time"`: `Date` - Date that the first block should start. Use this feature, along with the `evm_increaseTime` method to test time-dependent code.

## Implemented Methods
### Tezos
* `"defaultBalance"`: `number` - The default account balance, specified in Tez.
* `--gbh` or `--genesisBlockHash` - Specifies the hash of the genesis block from which the chain_id is computed. Default is random.
## Ethereum, Implemented Methods
The RPC methods currently implemented are:

@@ -246,3 +264,3 @@

## Custom Methods
## Ethereum, Custom Methods

@@ -290,29 +308,5 @@ Special non-standard methods that aren’t included within the original RPC specification:

```
* `evm_unlockUnknownAccount` : Unlocks any unknown account. Accounts known to the `personal` namespace and accounts
returned by `eth_accounts` cannot be unlocked using this method; use `personal_lockAccount` instead.
```bash
# Ex: account: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
curl -H "Content-Type: application/json" -X POST --data \
'{"id":1337,"jsonrpc":"2.0","method":"evm_unlockUnknownAccount","params":["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}' \
http://localhost:8545
```
```json
{ "id": 1337, "jsonrpc": "2.0", "result": true }
```
* `evm_lockUnknownAccount` : Locks any unknown account. Accounts known to the `personal` namespace and accounts
returned by `eth_accounts` cannot be locked using this method; use `personal_unlockAccount` instead.
```bash
# Ex: account: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
curl -H "Content-Type: application/json" -X POST --data \
'{"id":1337,"jsonrpc":"2.0","method":"evm_lockUnknownAccount","params":["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}' \
http://localhost:8545
```
## Ethereum, Unsupported Methods
```json
{ "id": 1337, "jsonrpc": "2.0", "result": true }
```
## Unsupported Methods
* `eth_compileSolidity`: If you'd like Solidity compilation in Javascript, please see the [solc-js project](https://github.com/ethereum/solc-js).

@@ -374,22 +368,3 @@

### PR Message format:
`<type>(<scope>): <subject>`
Where `type` must be one of the following:
* **feat**: A new feature
* **fix**: A bug fix
* **docs**: Documentation only changes
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing
semi-colons, etc)
* **refactor**: A code change that neither fixes a bug nor adds a feature
* **perf**: A code change that improves performance
* **test**: Adding missing or correcting existing tests
* **chore**: Changes to the build process or auxiliary tools and libraries such as documentation
generation
see: https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines
# License
[MIT](https://tldrlegal.com/license/mit-license)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc