From 98c1de028dee5aea5c34159e4a597164350a04f1 Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Thu, 30 Jan 2020 16:25:54 -0800 Subject: [PATCH 1/2] update typedoc and docs --- README.md | 2 +- docs/README.md | 882 +++++++++++++++++------------- docs/interfaces/ecdsasignature.md | 19 +- package.json | 6 +- 4 files changed, 497 insertions(+), 412 deletions(-) diff --git a/README.md b/README.md index cf521790e0..2e8b24101d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # SYNOPSIS [![NPM Package](https://img.shields.io/npm/v/ethereumjs-util.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-util) -[![Actions Status](https://github.com/ethereumjs/ethereumjs-util/workflows/Build/badge.svg)](https://github.com/ethereumjs/ethereumjs-util/actions +[![Actions Status](https://github.com/ethereumjs/ethereumjs-util/workflows/Build/badge.svg)](https://github.com/ethereumjs/ethereumjs-util/actions) [![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-util.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-util) [![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode diff --git a/docs/README.md b/docs/README.md index 3023b7f2b0..1277d57698 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,6 @@ +[ethereumjs-util](README.md) -# ethereumjs-util +# ethereumjs-util ## Index @@ -9,191 +10,273 @@ ### Variables -* [KECCAK256_NULL](#keccak256_null) -* [KECCAK256_NULL_S](#keccak256_null_s) -* [KECCAK256_RLP](#keccak256_rlp) -* [KECCAK256_RLP_ARRAY](#keccak256_rlp_array) -* [KECCAK256_RLP_ARRAY_S](#keccak256_rlp_array_s) -* [KECCAK256_RLP_S](#keccak256_rlp_s) -* [MAX_INTEGER](#max_integer) -* [TWO_POW256](#two_pow256) -* [publicToAddress](#publictoaddress) -* [setLength](#setlength) -* [stripZeros](#stripzeros) +* [BN](README.md#bn) +* [Buffer](README.md#const-buffer) +* [KECCAK256_NULL](README.md#const-keccak256_null) +* [KECCAK256_NULL_S](README.md#const-keccak256_null_s) +* [KECCAK256_RLP](README.md#const-keccak256_rlp) +* [KECCAK256_RLP_ARRAY](README.md#const-keccak256_rlp_array) +* [KECCAK256_RLP_ARRAY_S](README.md#const-keccak256_rlp_array_s) +* [KECCAK256_RLP_S](README.md#const-keccak256_rlp_s) +* [MAX_INTEGER](README.md#const-max_integer) +* [TWO_POW256](README.md#const-two_pow256) +* [assert](README.md#const-assert) +* [createHash](README.md#const-createhash) +* [createKeccakHash](README.md#const-createkeccakhash) +* [ethjsUtil](README.md#const-ethjsutil) +* [publicToAddress](README.md#const-publictoaddress) +* [rlp](README.md#rlp) +* [secp256k1](README.md#const-secp256k1) +* [setLength](README.md#const-setlength) +* [stripZeros](README.md#const-stripzeros) ### Functions -* [addHexPrefix](#addhexprefix) -* [baToJSON](#batojson) -* [bufferToHex](#buffertohex) -* [bufferToInt](#buffertoint) -* [defineProperties](#defineproperties) -* [ecrecover](#ecrecover) -* [ecsign](#ecsign) -* [fromRpcSig](#fromrpcsig) -* [fromSigned](#fromsigned) -* [generateAddress](#generateaddress) -* [generateAddress2](#generateaddress2) -* [hashPersonalMessage](#hashpersonalmessage) -* [importPublic](#importpublic) -* [isPrecompiled](#isprecompiled) -* [isValidAddress](#isvalidaddress) -* [isValidChecksumAddress](#isvalidchecksumaddress) -* [isValidPrivate](#isvalidprivate) -* [isValidPublic](#isvalidpublic) -* [isValidSignature](#isvalidsignature) -* [isZeroAddress](#iszeroaddress) -* [keccak](#keccak) -* [keccak256](#keccak256) -* [privateToAddress](#privatetoaddress) -* [privateToPublic](#privatetopublic) -* [pubToAddress](#pubtoaddress) -* [ripemd160](#ripemd160) -* [rlphash](#rlphash) -* [setLengthLeft](#setlengthleft) -* [setLengthRight](#setlengthright) -* [sha256](#sha256) -* [toBuffer](#tobuffer) -* [toChecksumAddress](#tochecksumaddress) -* [toRpcSig](#torpcsig) -* [toUnsigned](#tounsigned) -* [unpad](#unpad) -* [zeroAddress](#zeroaddress) -* [zeros](#zeros) - ---- +* [addHexPrefix](README.md#const-addhexprefix) +* [baToJSON](README.md#const-batojson) +* [bufferToHex](README.md#const-buffertohex) +* [bufferToInt](README.md#const-buffertoint) +* [calculateSigRecovery](README.md#calculatesigrecovery) +* [defineProperties](README.md#const-defineproperties) +* [ecrecover](README.md#const-ecrecover) +* [ecsign](README.md#const-ecsign) +* [fromRpcSig](README.md#const-fromrpcsig) +* [fromSigned](README.md#const-fromsigned) +* [generateAddress](README.md#const-generateaddress) +* [generateAddress2](README.md#const-generateaddress2) +* [hashPersonalMessage](README.md#const-hashpersonalmessage) +* [importPublic](README.md#const-importpublic) +* [isPrecompiled](README.md#const-isprecompiled) +* [isValidAddress](README.md#const-isvalidaddress) +* [isValidChecksumAddress](README.md#const-isvalidchecksumaddress) +* [isValidPrivate](README.md#const-isvalidprivate) +* [isValidPublic](README.md#const-isvalidpublic) +* [isValidSigRecovery](README.md#isvalidsigrecovery) +* [isValidSignature](README.md#const-isvalidsignature) +* [isZeroAddress](README.md#const-iszeroaddress) +* [keccak](README.md#const-keccak) +* [keccak256](README.md#const-keccak256) +* [privateToAddress](README.md#const-privatetoaddress) +* [privateToPublic](README.md#const-privatetopublic) +* [pubToAddress](README.md#const-pubtoaddress) +* [ripemd160](README.md#const-ripemd160) +* [rlphash](README.md#const-rlphash) +* [setLengthLeft](README.md#const-setlengthleft) +* [setLengthRight](README.md#const-setlengthright) +* [sha256](README.md#const-sha256) +* [toBuffer](README.md#const-tobuffer) +* [toChecksumAddress](README.md#const-tochecksumaddress) +* [toRpcSig](README.md#const-torpcsig) +* [toUnsigned](README.md#const-tounsigned) +* [unpad](README.md#const-unpad) +* [zeroAddress](README.md#const-zeroaddress) +* [zeros](README.md#const-zeros) ## Variables - +### BN -### `` KECCAK256_NULL +• **BN**: *[BN](README.md#bn)* -**● KECCAK256_NULL**: *`Buffer`* = Buffer.from(KECCAK256_NULL_S, 'hex') +*Defined in [bytes.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L2)* -*Defined in [constants.ts:28](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L28)* +*Defined in [account.ts:4](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L4)* + +*Defined in [constants.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L1)* + +*Defined in [signature.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L2)* + +*Defined in [index.ts:3](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/index.ts#L3)* + +___ + +### `Const` Buffer + +• **Buffer**: *any* = require('buffer').Buffer + +*Defined in [constants.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L2)* + +___ + +### `Const` KECCAK256_NULL + +• **KECCAK256_NULL**: *[Buffer](README.md#const-buffer)* = Buffer.from(KECCAK256_NULL_S, 'hex') + +*Defined in [constants.ts:29](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L29)* Keccak-256 hash of null ___ - -### `` KECCAK256_NULL_S +### `Const` KECCAK256_NULL_S -**● KECCAK256_NULL_S**: *`string`* = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" +• **KECCAK256_NULL_S**: *string* = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" -*Defined in [constants.ts:22](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L22)* +*Defined in [constants.ts:23](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L23)* Keccak-256 hash of null ___ - -### `` KECCAK256_RLP +### `Const` KECCAK256_RLP -**● KECCAK256_RLP**: *`Buffer`* = Buffer.from(KECCAK256_RLP_S, 'hex') +• **KECCAK256_RLP**: *[Buffer](README.md#const-buffer)* = Buffer.from(KECCAK256_RLP_S, 'hex') -*Defined in [constants.ts:50](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L50)* +*Defined in [constants.ts:51](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L51)* Keccak-256 hash of the RLP of null ___ - -### `` KECCAK256_RLP_ARRAY +### `Const` KECCAK256_RLP_ARRAY -**● KECCAK256_RLP_ARRAY**: *`Buffer`* = Buffer.from(KECCAK256_RLP_ARRAY_S, 'hex') +• **KECCAK256_RLP_ARRAY**: *[Buffer](README.md#const-buffer)* = Buffer.from(KECCAK256_RLP_ARRAY_S, 'hex') -*Defined in [constants.ts:39](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L39)* +*Defined in [constants.ts:40](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L40)* Keccak-256 of an RLP of an empty array ___ - -### `` KECCAK256_RLP_ARRAY_S +### `Const` KECCAK256_RLP_ARRAY_S -**● KECCAK256_RLP_ARRAY_S**: *`string`* = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" +• **KECCAK256_RLP_ARRAY_S**: *string* = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" -*Defined in [constants.ts:33](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L33)* +*Defined in [constants.ts:34](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L34)* Keccak-256 of an RLP of an empty array ___ - -### `` KECCAK256_RLP_S +### `Const` KECCAK256_RLP_S -**● KECCAK256_RLP_S**: *`string`* = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" +• **KECCAK256_RLP_S**: *string* = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" -*Defined in [constants.ts:44](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L44)* +*Defined in [constants.ts:45](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L45)* Keccak-256 hash of the RLP of null ___ - -### `` MAX_INTEGER +### `Const` MAX_INTEGER -**● MAX_INTEGER**: *`BN`* = new BN( +• **MAX_INTEGER**: *[BN](README.md#bn)* = new BN( 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16, ) -*Defined in [constants.ts:6](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L6)* +*Defined in [constants.ts:7](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L7)* The max integer that this VM can handle ___ - -### `` TWO_POW256 +### `Const` TWO_POW256 -**● TWO_POW256**: *`BN`* = new BN( +• **TWO_POW256**: *[BN](README.md#bn)* = new BN( '10000000000000000000000000000000000000000000000000000000000000000', 16, ) -*Defined in [constants.ts:14](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L14)* +*Defined in [constants.ts:15](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L15)* 2^256 ___ - -### `` publicToAddress +### `Const` assert + +• **assert**: *any* = require('assert') + +*Defined in [account.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L1)* + +*Defined in [object.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L1)* + +___ + +### `Const` createHash -**● publicToAddress**: *[pubToAddress]()* = pubToAddress +• **createHash**: *any* = require('create-hash') + +*Defined in [hash.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L2)* + +___ + +### `Const` createKeccakHash + +• **createKeccakHash**: *any* = require('keccak') + +*Defined in [hash.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L1)* + +___ + +### `Const` ethjsUtil + +• **ethjsUtil**: *any* = require('ethjs-util') + +*Defined in [bytes.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L1)* + +*Defined in [hash.ts:3](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L3)* + +*Defined in [account.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L2)* + +*Defined in [object.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L2)* + +*Defined in [index.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/index.ts#L2)* + +___ + +### `Const` publicToAddress + +• **publicToAddress**: *pubToAddress* = pubToAddress *Defined in [account.ts:163](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L163)* ___ - -### `` setLength +### rlp -**● setLength**: *[setLengthLeft]()* = setLengthLeft +• **rlp**: *"/Users/ryanghods/dev/ethereumjs-util/node_modules/rlp/dist/index"* -*Defined in [bytes.ts:37](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L37)* +*Defined in [hash.ts:4](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L4)* + +*Defined in [object.ts:3](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L3)* + +*Defined in [index.ts:4](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/index.ts#L4)* ___ - -### `` stripZeros +### `Const` secp256k1 -**● stripZeros**: *[unpad]()* = unpad +• **secp256k1**: *any* = require('secp256k1') -*Defined in [bytes.ts:64](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L64)* +*Defined in [account.ts:3](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L3)* + +*Defined in [signature.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L1)* + +*Defined in [index.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/index.ts#L1)* ___ -## Functions +### `Const` setLength - +• **setLength**: *setLengthLeft* = setLengthLeft -### `` addHexPrefix +*Defined in [bytes.ts:37](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L37)* -▸ **addHexPrefix**(str: *`string`*): `string` +___ + +### `Const` stripZeros + +• **stripZeros**: *unpad* = unpad + +*Defined in [bytes.ts:64](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L64)* + +## Functions + +### `Const` addHexPrefix + +▸ **addHexPrefix**(`str`: string): *string* *Defined in [bytes.ts:135](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L135)* @@ -201,18 +284,17 @@ Adds "0x" to a given `String` if it does not already start with "0x". **Parameters:** -| Name | Type | -| ------ | ------ | -| str | `string` | +Name | Type | +------ | ------ | +`str` | string | -**Returns:** `string` +**Returns:** *string* ___ - -### `` baToJSON +### `Const` baToJSON -▸ **baToJSON**(ba: *`any`*): `any` +▸ **baToJSON**(`ba`: any): *any* *Defined in [bytes.ts:148](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L148)* @@ -220,38 +302,37 @@ Converts a `Buffer` or `Array` to JSON. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| ba | `any` | (Buffer\|Array) | +Name | Type | Description | +------ | ------ | ------ | +`ba` | any | (Buffer|Array) | -**Returns:** `any` -(Array\|String\|null) +**Returns:** *any* + +(Array|String|null) ___ - -### `` bufferToHex +### `Const` bufferToHex -▸ **bufferToHex**(buf: *`Buffer`*): `string` +▸ **bufferToHex**(`buf`: [Buffer](README.md#const-buffer)): *string* *Defined in [bytes.ts:111](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L111)* -Converts a `Buffer` into a `0x`\-prefixed hex `String`. +Converts a `Buffer` into a `0x`-prefixed hex `String`. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| buf | `Buffer` | \`Buffer\` object to convert | +Name | Type | Description | +------ | ------ | ------ | +`buf` | [Buffer](README.md#const-buffer) | `Buffer` object to convert | -**Returns:** `string` +**Returns:** *string* ___ - -### `` bufferToInt +### `Const` bufferToInt -▸ **bufferToInt**(buf: *`Buffer`*): `number` +▸ **bufferToInt**(`buf`: [Buffer](README.md#const-buffer)): *number* *Defined in [bytes.ts:103](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L103)* @@ -259,18 +340,34 @@ Converts a `Buffer` to a `Number`. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| buf | `Buffer` | \`Buffer\` object to convert | +Name | Type | Description | +------ | ------ | ------ | +`buf` | [Buffer](README.md#const-buffer) | `Buffer` object to convert | -**Returns:** `number` +**Returns:** *number* ___ - -### `` defineProperties +### calculateSigRecovery + +▸ **calculateSigRecovery**(`v`: number, `chainId?`: undefined | number): *number* -▸ **defineProperties**(self: *`any`*, fields: *`any`*, data: *`any`*): `void` +*Defined in [signature.ts:144](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L144)* + +**Parameters:** + +Name | Type | +------ | ------ | +`v` | number | +`chainId?` | undefined | number | + +**Returns:** *number* + +___ + +### `Const` defineProperties + +▸ **defineProperties**(`self`: any, `fields`: any, `data`: any): *void* *Defined in [object.ts:17](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L17)* @@ -278,20 +375,19 @@ Defines properties on a `Object`. It make the assumption that underlying data is **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| self | `any` | the \`Object\` to define properties on | -| fields | `any` | 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\` | -| data | `any` | data to be validated against the definitions | +Name | Type | Description | +------ | ------ | ------ | +`self` | any | the `Object` to define properties on | +`fields` | any | 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` | +`data` | any | data to be validated against the definitions | -**Returns:** `void` +**Returns:** *void* ___ - -### `` ecrecover +### `Const` ecrecover -▸ **ecrecover**(msgHash: *`Buffer`*, v: *`number`*, r: *`Buffer`*, s: *`Buffer`*, chainId?: *`undefined` \| `number`*): `Buffer` +▸ **ecrecover**(`msgHash`: [Buffer](README.md#const-buffer), `v`: number, `r`: [Buffer](README.md#const-buffer), `s`: [Buffer](README.md#const-buffer), `chainId?`: undefined | number): *[Buffer](README.md#const-buffer)* *Defined in [signature.ts:36](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L36)* @@ -299,23 +395,23 @@ ECDSA public key recovery from signature. **Parameters:** -| Name | Type | -| ------ | ------ | -| msgHash | `Buffer` | -| v | `number` | -| r | `Buffer` | -| s | `Buffer` | -| `Optional` chainId | `undefined` \| `number` | +Name | Type | +------ | ------ | +`msgHash` | [Buffer](README.md#const-buffer) | +`v` | number | +`r` | [Buffer](README.md#const-buffer) | +`s` | [Buffer](README.md#const-buffer) | +`chainId?` | undefined | number | + +**Returns:** *[Buffer](README.md#const-buffer)* -**Returns:** `Buffer` Recovered public key ___ - -### `` ecsign +### `Const` ecsign -▸ **ecsign**(msgHash: *`Buffer`*, privateKey: *`Buffer`*, chainId?: *`undefined` \| `number`*): [ECDSASignature](interfaces/ecdsasignature.md) +▸ **ecsign**(`msgHash`: [Buffer](README.md#const-buffer), `privateKey`: [Buffer](README.md#const-buffer), `chainId?`: undefined | number): *[ECDSASignature](interfaces/ecdsasignature.md)* *Defined in [signature.ts:15](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L15)* @@ -323,39 +419,38 @@ Returns the ECDSA signature of a message hash. **Parameters:** -| Name | Type | -| ------ | ------ | -| msgHash | `Buffer` | -| privateKey | `Buffer` | -| `Optional` chainId | `undefined` \| `number` | +Name | Type | +------ | ------ | +`msgHash` | [Buffer](README.md#const-buffer) | +`privateKey` | [Buffer](README.md#const-buffer) | +`chainId?` | undefined | number | -**Returns:** [ECDSASignature](interfaces/ecdsasignature.md) +**Returns:** *[ECDSASignature](interfaces/ecdsasignature.md)* ___ - -### `` fromRpcSig +### `Const` fromRpcSig -▸ **fromRpcSig**(sig: *`string`*): [ECDSASignature](interfaces/ecdsasignature.md) +▸ **fromRpcSig**(`sig`: string): *[ECDSASignature](interfaces/ecdsasignature.md)* *Defined in [signature.ts:70](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L70)* -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](https://github.com/ethereum/go-ethereum/issues/2053) +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 **Parameters:** -| Name | Type | -| ------ | ------ | -| sig | `string` | +Name | Type | +------ | ------ | +`sig` | string | -**Returns:** [ECDSASignature](interfaces/ecdsasignature.md) +**Returns:** *[ECDSASignature](interfaces/ecdsasignature.md)* ___ - -### `` fromSigned +### `Const` fromSigned -▸ **fromSigned**(num: *`Buffer`*): `BN` +▸ **fromSigned**(`num`: [Buffer](README.md#const-buffer)): *[BN](README.md#bn)* *Defined in [bytes.ts:120](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L120)* @@ -363,18 +458,17 @@ Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit nu **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| num | `Buffer` | Signed integer value | +Name | Type | Description | +------ | ------ | ------ | +`num` | [Buffer](README.md#const-buffer) | Signed integer value | -**Returns:** `BN` +**Returns:** *[BN](README.md#bn)* ___ - -### `` generateAddress +### `Const` generateAddress -▸ **generateAddress**(from: *`Buffer`*, nonce: *`Buffer`*): `Buffer` +▸ **generateAddress**(`from`: [Buffer](README.md#const-buffer), `nonce`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* *Defined in [account.ts:75](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L75)* @@ -382,19 +476,18 @@ Generates an address of a newly created contract. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| from | `Buffer` | The address which is creating this new address | -| nonce | `Buffer` | The nonce of the from account | +Name | Type | Description | +------ | ------ | ------ | +`from` | [Buffer](README.md#const-buffer) | The address which is creating this new address | +`nonce` | [Buffer](README.md#const-buffer) | The nonce of the from account | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` generateAddress2 +### `Const` generateAddress2 -▸ **generateAddress2**(from: *`Buffer` \| `string`*, salt: *`Buffer` \| `string`*, initCode: *`Buffer` \| `string`*): `Buffer` +▸ **generateAddress2**(`from`: [Buffer](README.md#const-buffer) | string, `salt`: [Buffer](README.md#const-buffer) | string, `initCode`: [Buffer](README.md#const-buffer) | string): *[Buffer](README.md#const-buffer)* *Defined in [account.ts:95](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L95)* @@ -402,39 +495,40 @@ Generates an address for a contract created using CREATE2. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| from | `Buffer` \| `string` | The address which is creating this new address | -| salt | `Buffer` \| `string` | A salt | -| initCode | `Buffer` \| `string` | The init code of the contract being created | +Name | Type | Description | +------ | ------ | ------ | +`from` | [Buffer](README.md#const-buffer) | string | The address which is creating this new address | +`salt` | [Buffer](README.md#const-buffer) | string | A salt | +`initCode` | [Buffer](README.md#const-buffer) | string | The init code of the contract being created | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` hashPersonalMessage +### `Const` hashPersonalMessage -▸ **hashPersonalMessage**(message: *`Buffer`*): `Buffer` +▸ **hashPersonalMessage**(`message`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* *Defined in [signature.ts:136](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L136)* -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. +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. **Parameters:** -| Name | Type | -| ------ | ------ | -| message | `Buffer` | +Name | Type | +------ | ------ | +`message` | [Buffer](README.md#const-buffer) | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` importPublic +### `Const` importPublic -▸ **importPublic**(publicKey: *`Buffer`*): `Buffer` +▸ **importPublic**(`publicKey`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* *Defined in [account.ts:186](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L186)* @@ -442,18 +536,17 @@ Converts a public key to the Ethereum format. **Parameters:** -| Name | Type | -| ------ | ------ | -| publicKey | `Buffer` | +Name | Type | +------ | ------ | +`publicKey` | [Buffer](README.md#const-buffer) | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` isPrecompiled +### `Const` isPrecompiled -▸ **isPrecompiled**(address: *`Buffer` \| `string`*): `boolean` +▸ **isPrecompiled**(`address`: [Buffer](README.md#const-buffer) | string): *boolean* *Defined in [account.ts:117](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L117)* @@ -461,18 +554,17 @@ Returns true if the supplied address belongs to a precompiled account (Byzantium **Parameters:** -| Name | Type | -| ------ | ------ | -| address | `Buffer` \| `string` | +Name | Type | +------ | ------ | +`address` | [Buffer](README.md#const-buffer) | string | -**Returns:** `boolean` +**Returns:** *boolean* ___ - -### `` isValidAddress +### `Const` isValidAddress -▸ **isValidAddress**(address: *`string`*): `boolean` +▸ **isValidAddress**(`address`: string): *boolean* *Defined in [account.ts:20](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L20)* @@ -480,18 +572,17 @@ Checks if the address is a valid. Accepts checksummed addresses too. **Parameters:** -| Name | Type | -| ------ | ------ | -| address | `string` | +Name | Type | +------ | ------ | +`address` | string | -**Returns:** `boolean` +**Returns:** *boolean* ___ - -### `` isValidChecksumAddress +### `Const` isValidChecksumAddress -▸ **isValidChecksumAddress**(address: *`string`*, eip1191ChainId?: *`undefined` \| `number`*): `boolean` +▸ **isValidChecksumAddress**(`address`: string, `eip1191ChainId?`: undefined | number): *boolean* *Defined in [account.ts:66](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L66)* @@ -501,19 +592,18 @@ See toChecksumAddress' documentation for details about the eip1191ChainId parame **Parameters:** -| Name | Type | -| ------ | ------ | -| address | `string` | -| `Optional` eip1191ChainId | `undefined` \| `number` | +Name | Type | +------ | ------ | +`address` | string | +`eip1191ChainId?` | undefined | number | -**Returns:** `boolean` +**Returns:** *boolean* ___ - -### `` isValidPrivate +### `Const` isValidPrivate -▸ **isValidPrivate**(privateKey: *`Buffer`*): `boolean` +▸ **isValidPrivate**(`privateKey`: [Buffer](README.md#const-buffer)): *boolean* *Defined in [account.ts:125](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L125)* @@ -521,38 +611,53 @@ Checks if the private key satisfies the rules of the curve secp256k1. **Parameters:** -| Name | Type | -| ------ | ------ | -| privateKey | `Buffer` | +Name | Type | +------ | ------ | +`privateKey` | [Buffer](README.md#const-buffer) | -**Returns:** `boolean` +**Returns:** *boolean* ___ - -### `` isValidPublic +### `Const` isValidPublic -▸ **isValidPublic**(publicKey: *`Buffer`*, sanitize?: *`boolean`*): `boolean` +▸ **isValidPublic**(`publicKey`: [Buffer](README.md#const-buffer), `sanitize`: boolean): *boolean* *Defined in [account.ts:135](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L135)* -Checks if the public key satisfies the rules of the curve secp256k1 and the requirements of Ethereum. +Checks if the public key satisfies the rules of the curve secp256k1 +and the requirements of Ethereum. + +**Parameters:** + +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`publicKey` | [Buffer](README.md#const-buffer) | - | The two points of an uncompressed key, unless sanitize is enabled | +`sanitize` | boolean | false | Accept public keys in other formats | + +**Returns:** *boolean* + +___ + +### isValidSigRecovery + +▸ **isValidSigRecovery**(`recovery`: number): *boolean* + +*Defined in [signature.ts:148](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L148)* **Parameters:** -| Name | Type | Default value | Description | -| ------ | ------ | ------ | ------ | -| publicKey | `Buffer` | - | The two points of an uncompressed key, unless sanitize is enabled | -| `Default value` sanitize | `boolean` | false | Accept public keys in other formats | +Name | Type | +------ | ------ | +`recovery` | number | -**Returns:** `boolean` +**Returns:** *boolean* ___ - -### `` isValidSignature +### `Const` isValidSignature -▸ **isValidSignature**(v: *`number`*, r: *`Buffer`*, s: *`Buffer`*, homesteadOrLater?: *`boolean`*, chainId?: *`undefined` \| `number`*): `boolean` +▸ **isValidSignature**(`v`: number, `r`: [Buffer](README.md#const-buffer), `s`: [Buffer](README.md#const-buffer), `homesteadOrLater`: boolean, `chainId?`: undefined | number): *boolean* *Defined in [signature.ts:95](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L95)* @@ -560,22 +665,21 @@ Validate a ECDSA signature. **Parameters:** -| Name | Type | Default value | Description | -| ------ | ------ | ------ | ------ | -| v | `number` | - | -| r | `Buffer` | - | -| s | `Buffer` | - | -| `Default value` homesteadOrLater | `boolean` | true | Indicates whether this is being used on either the homestead hardfork or a later one | -| `Optional` chainId | `undefined` \| `number` | - | +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`v` | number | - | - | +`r` | [Buffer](README.md#const-buffer) | - | - | +`s` | [Buffer](README.md#const-buffer) | - | - | +`homesteadOrLater` | boolean | true | Indicates whether this is being used on either the homestead hardfork or a later one | +`chainId?` | undefined | number | - | - | -**Returns:** `boolean` +**Returns:** *boolean* ___ - -### `` isZeroAddress +### `Const` isZeroAddress -▸ **isZeroAddress**(address: *`string`*): `boolean` +▸ **isZeroAddress**(`address`: string): *boolean* *Defined in [account.ts:27](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L27)* @@ -583,18 +687,17 @@ Checks if a given address is a zero address. **Parameters:** -| Name | Type | -| ------ | ------ | -| address | `string` | +Name | Type | +------ | ------ | +`address` | string | -**Returns:** `boolean` +**Returns:** *boolean* ___ - -### `` keccak +### `Const` keccak -▸ **keccak**(a: *`any`*, bits?: *`number`*): `Buffer` +▸ **keccak**(`a`: any, `bits`: number): *[Buffer](README.md#const-buffer)* *Defined in [hash.ts:13](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L13)* @@ -602,19 +705,18 @@ Creates Keccak hash of the input **Parameters:** -| Name | Type | Default value | Description | -| ------ | ------ | ------ | ------ | -| a | `any` | - | The input data (Buffer\|Array\|String\|Number) If the string is a 0x-prefixed hex value it's interpreted as hexadecimal, otherwise as utf8. | -| `Default value` bits | `number` | 256 | The Keccak width | +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`a` | any | - | The input data (Buffer|Array|String|Number) If the string is a 0x-prefixed hex value it's interpreted as hexadecimal, otherwise as utf8. | +`bits` | number | 256 | The Keccak width | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` keccak256 +### `Const` keccak256 -▸ **keccak256**(a: *`any`*): `Buffer` +▸ **keccak256**(`a`: any): *[Buffer](README.md#const-buffer)* *Defined in [hash.ts:31](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L31)* @@ -622,18 +724,17 @@ Creates Keccak-256 hash of the input, alias for keccak(a, 256). **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| a | `any` | The input data (Buffer\|Array\|String\|Number) | +Name | Type | Description | +------ | ------ | ------ | +`a` | any | The input data (Buffer|Array|String|Number) | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` privateToAddress +### `Const` privateToAddress -▸ **privateToAddress**(privateKey: *`Buffer`*): `Buffer` +▸ **privateToAddress**(`privateKey`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* *Defined in [account.ts:169](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L169)* @@ -641,18 +742,17 @@ Returns the ethereum address of a given private key. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| privateKey | `Buffer` | A private key must be 256 bits wide | +Name | Type | Description | +------ | ------ | ------ | +`privateKey` | [Buffer](README.md#const-buffer) | A private key must be 256 bits wide | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` privateToPublic +### `Const` privateToPublic -▸ **privateToPublic**(privateKey: *`Buffer`*): `Buffer` +▸ **privateToPublic**(`privateKey`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* *Defined in [account.ts:177](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L177)* @@ -660,38 +760,37 @@ Returns the ethereum public key of a given private key. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| privateKey | `Buffer` | A private key must be 256 bits wide | +Name | Type | Description | +------ | ------ | ------ | +`privateKey` | [Buffer](README.md#const-buffer) | A private key must be 256 bits wide | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` pubToAddress +### `Const` pubToAddress -▸ **pubToAddress**(pubKey: *`Buffer`*, sanitize?: *`boolean`*): `Buffer` +▸ **pubToAddress**(`pubKey`: [Buffer](README.md#const-buffer), `sanitize`: boolean): *[Buffer](README.md#const-buffer)* *Defined in [account.ts:154](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L154)* -Returns the ethereum address of a given public key. Accepts "Ethereum public keys" and SEC1 encoded keys. +Returns the ethereum address of a given public key. +Accepts "Ethereum public keys" and SEC1 encoded keys. **Parameters:** -| Name | Type | Default value | Description | -| ------ | ------ | ------ | ------ | -| pubKey | `Buffer` | - | The two points of an uncompressed key, unless sanitize is enabled | -| `Default value` sanitize | `boolean` | false | Accept public keys in other formats | +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`pubKey` | [Buffer](README.md#const-buffer) | - | The two points of an uncompressed key, unless sanitize is enabled | +`sanitize` | boolean | false | Accept public keys in other formats | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` ripemd160 +### `Const` ripemd160 -▸ **ripemd160**(a: *`any`*, padded: *`boolean`*): `Buffer` +▸ **ripemd160**(`a`: any, `padded`: boolean): *[Buffer](README.md#const-buffer)* *Defined in [hash.ts:51](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L51)* @@ -699,19 +798,18 @@ Creates RIPEMD160 hash of the input. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| a | `any` | The input data (Buffer\|Array\|String\|Number) | -| padded | `boolean` | Whether it should be padded to 256 bits or not | +Name | Type | Description | +------ | ------ | ------ | +`a` | any | The input data (Buffer|Array|String|Number) | +`padded` | boolean | Whether it should be padded to 256 bits or not | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` rlphash +### `Const` rlphash -▸ **rlphash**(a: *`rlp.Input`*): `Buffer` +▸ **rlphash**(`a`: rlp.Input): *[Buffer](README.md#const-buffer)* *Defined in [hash.ts:67](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L67)* @@ -719,61 +817,62 @@ Creates SHA-3 hash of the RLP encoded version of the input. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| a | `rlp.Input` | The input data | +Name | Type | Description | +------ | ------ | ------ | +`a` | rlp.Input | The input data | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` setLengthLeft +### `Const` setLengthLeft -▸ **setLengthLeft**(msg: *`any`*, length: *`number`*, right?: *`boolean`*): `any` +▸ **setLengthLeft**(`msg`: any, `length`: number, `right`: boolean): *any* *Defined in [bytes.ts:20](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L20)* -Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. Or it truncates the beginning if it exceeds. +Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. +Or it truncates the beginning if it exceeds. **Parameters:** -| Name | Type | Default value | Description | -| ------ | ------ | ------ | ------ | -| msg | `any` | - | the value to pad (Buffer\|Array) | -| length | `number` | - | the number of bytes the output should be | -| `Default value` right | `boolean` | false | whether to start padding form the left or right | +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`msg` | any | - | the value to pad (Buffer|Array) | +`length` | number | - | the number of bytes the output should be | +`right` | boolean | false | whether to start padding form the left or right | -**Returns:** `any` -(Buffer\|Array) +**Returns:** *any* + +(Buffer|Array) ___ - -### `` setLengthRight +### `Const` setLengthRight -▸ **setLengthRight**(msg: *`any`*, length: *`number`*): `any` +▸ **setLengthRight**(`msg`: any, `length`: number): *any* *Defined in [bytes.ts:46](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L46)* -Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. Or it truncates the beginning if it exceeds. +Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. +Or it truncates the beginning if it exceeds. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| msg | `any` | the value to pad (Buffer\|Array) | -| length | `number` | the number of bytes the output should be | +Name | Type | Description | +------ | ------ | ------ | +`msg` | any | the value to pad (Buffer|Array) | +`length` | number | the number of bytes the output should be | + +**Returns:** *any* -**Returns:** `any` -(Buffer\|Array) +(Buffer|Array) ___ - -### `` sha256 +### `Const` sha256 -▸ **sha256**(a: *`any`*): `Buffer` +▸ **sha256**(`a`: any): *[Buffer](README.md#const-buffer)* *Defined in [hash.ts:39](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L39)* @@ -781,18 +880,17 @@ Creates SHA256 hash of the input. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| a | `any` | The input data (Buffer\|Array\|String\|Number) | +Name | Type | Description | +------ | ------ | ------ | +`a` | any | The input data (Buffer|Array|String|Number) | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` toBuffer +### `Const` toBuffer -▸ **toBuffer**(v: *`any`*): `Buffer` +▸ **toBuffer**(`v`: any): *[Buffer](README.md#const-buffer)* *Defined in [bytes.ts:70](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L70)* @@ -800,42 +898,43 @@ Attempts to turn a value into a `Buffer`. As input it supports `Buffer`, `String **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| v | `any` | the value | +Name | Type | Description | +------ | ------ | ------ | +`v` | any | the value | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` toChecksumAddress +### `Const` toChecksumAddress -▸ **toChecksumAddress**(address: *`string`*, eip1191ChainId?: *`undefined` \| `number`*): `string` +▸ **toChecksumAddress**(`address`: string, `eip1191ChainId?`: undefined | number): *string* *Defined in [account.ts:42](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L42)* Returns a checksummed address. -If a eip1191ChainId is provided, the chainId will be included in the checksum calculation. This has the effect of checksummed addresses for one chain having invalid checksums for others. For more details, consult EIP-1191. +If a eip1191ChainId is provided, the chainId will be included in the checksum calculation. This +has the effect of checksummed addresses for one chain having invalid checksums for others. +For more details, consult EIP-1191. -WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly used variation in Ethereum was without the chainId. This may change in the future. +WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly +used variation in Ethereum was without the chainId. This may change in the future. **Parameters:** -| Name | Type | -| ------ | ------ | -| address | `string` | -| `Optional` eip1191ChainId | `undefined` \| `number` | +Name | Type | +------ | ------ | +`address` | string | +`eip1191ChainId?` | undefined | number | -**Returns:** `string` +**Returns:** *string* ___ - -### `` toRpcSig +### `Const` toRpcSig -▸ **toRpcSig**(v: *`number`*, r: *`Buffer`*, s: *`Buffer`*, chainId?: *`undefined` \| `number`*): `string` +▸ **toRpcSig**(`v`: number, `r`: [Buffer](README.md#const-buffer), `s`: [Buffer](README.md#const-buffer), `chainId?`: undefined | number): *string* *Defined in [signature.ts:56](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L56)* @@ -843,22 +942,22 @@ Convert signature parameters into the format of `eth_sign` RPC method. **Parameters:** -| Name | Type | -| ------ | ------ | -| v | `number` | -| r | `Buffer` | -| s | `Buffer` | -| `Optional` chainId | `undefined` \| `number` | +Name | Type | +------ | ------ | +`v` | number | +`r` | [Buffer](README.md#const-buffer) | +`s` | [Buffer](README.md#const-buffer) | +`chainId?` | undefined | number | + +**Returns:** *string* -**Returns:** `string` Signature ___ - -### `` toUnsigned +### `Const` toUnsigned -▸ **toUnsigned**(num: *`BN`*): `Buffer` +▸ **toUnsigned**(`num`: [BN](README.md#bn)): *[Buffer](README.md#const-buffer)* *Defined in [bytes.ts:128](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L128)* @@ -866,18 +965,17 @@ Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256 **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| num | `BN` | | +Name | Type | Description | +------ | ------ | ------ | +`num` | [BN](README.md#bn) | | -**Returns:** `Buffer` +**Returns:** *[Buffer](README.md#const-buffer)* ___ - -### `` unpad +### `Const` unpad -▸ **unpad**(a: *`any`*): `any` +▸ **unpad**(`a`: any): *any* *Defined in [bytes.ts:55](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L55)* @@ -885,32 +983,31 @@ Trims leading zeros from a `Buffer` or an `Array`. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| a | `any` | (Buffer\|Array\|String) | +Name | Type | Description | +------ | ------ | ------ | +`a` | any | (Buffer|Array|String) | + +**Returns:** *any* -**Returns:** `any` -(Buffer\|Array\|String) +(Buffer|Array|String) ___ - -### `` zeroAddress +### `Const` zeroAddress -▸ **zeroAddress**(): `string` +▸ **zeroAddress**(): *string* *Defined in [account.ts:11](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L11)* Returns a zero address. -**Returns:** `string` +**Returns:** *string* ___ - -### `` zeros +### `Const` zeros -▸ **zeros**(bytes: *`number`*): `Buffer` +▸ **zeros**(`bytes`: number): *[Buffer](README.md#const-buffer)* *Defined in [bytes.ts:8](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L8)* @@ -918,11 +1015,8 @@ Returns a buffer filled with 0s. **Parameters:** -| Name | Type | Description | -| ------ | ------ | ------ | -| bytes | `number` | the number of bytes the buffer should be | - -**Returns:** `Buffer` - -___ +Name | Type | Description | +------ | ------ | ------ | +`bytes` | number | the number of bytes the buffer should be | +**Returns:** *[Buffer](README.md#const-buffer)* diff --git a/docs/interfaces/ecdsasignature.md b/docs/interfaces/ecdsasignature.md index f2e32785ec..52775c085f 100644 --- a/docs/interfaces/ecdsasignature.md +++ b/docs/interfaces/ecdsasignature.md @@ -1,10 +1,10 @@ -[ethereumjs-util](../README.md) > [ECDSASignature](../interfaces/ecdsasignature.md) +[ethereumjs-util](../README.md) › [ECDSASignature](ecdsasignature.md) # Interface: ECDSASignature ## Hierarchy -**ECDSASignature** +* **ECDSASignature** ## Index @@ -14,35 +14,26 @@ * [s](ecdsasignature.md#s) * [v](ecdsasignature.md#v) ---- - ## Properties - - ### r -**● r**: *`Buffer`* +• **r**: *[Buffer](../README.md#const-buffer)* *Defined in [signature.ts:8](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L8)* ___ - ### s -**● s**: *`Buffer`* +• **s**: *[Buffer](../README.md#const-buffer)* *Defined in [signature.ts:9](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L9)* ___ - ### v -**● v**: *`number`* +• **v**: *number* *Defined in [signature.ts:7](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L7)* - -___ - diff --git a/package.json b/package.json index b280c8a089..a150544f28 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "build": "ethereumjs-config-build", "prepublishOnly": "npm run test && npm run build", - "docs:build": "typedoc --out docs --mode file --readme none --theme markdown --mdEngine github --gitRevision master --excludeNotExported src", + "docs:build": "npx typedoc --plugin typedoc-plugin-markdown --out docs --mode file --readme none --gitRevision master --module commonjs --excludeNotExported src", "format": "ethereumjs-config-format", "format:fix": "ethereumjs-config-format-fix", "lint": "ethereumjs-config-lint", @@ -112,8 +112,8 @@ "prettier": "^1.15.3", "ts-node": "^8.6.2", "tslint": "^5.12.0", - "typedoc": "^0.14.0", - "typedoc-plugin-markdown": "^1.1.21", + "typedoc": "^0.16.9", + "typedoc-plugin-markdown": "^2.2.16", "typescript": "^3.2.2", "typestrict": "^1.0.2" } From 59e9849ac291c7bb2318f804b8f4b02277bf5bca Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Mon, 3 Feb 2020 11:22:56 -0800 Subject: [PATCH 2/2] * use library mode in typedoc@next * create `src/externals.ts` and `test/externals.spec.ts` --- docs/README.md | 1025 +---------------- ...ature.md => _signature_.ecdsasignature.md} | 12 +- docs/modules/_account_.md | 298 +++++ docs/modules/_bytes_.md | 251 ++++ docs/modules/_constants_.md | 102 ++ docs/modules/_externals_.md | 7 + docs/modules/_hash_.md | 105 ++ docs/modules/_object_.md | 29 + docs/modules/_signature_.md | 147 +++ package.json | 5 +- src/account.ts | 6 +- src/bytes.ts | 2 +- src/constants.ts | 2 +- src/externals.ts | 31 + src/hash.ts | 2 +- src/index.ts | 26 +- src/object.ts | 4 +- src/signature.ts | 4 +- test/externals.spec.ts | 29 + typedoc.js | 12 + 20 files changed, 1044 insertions(+), 1055 deletions(-) rename docs/interfaces/{ecdsasignature.md => _signature_.ecdsasignature.md} (63%) create mode 100644 docs/modules/_account_.md create mode 100644 docs/modules/_bytes_.md create mode 100644 docs/modules/_constants_.md create mode 100644 docs/modules/_externals_.md create mode 100644 docs/modules/_hash_.md create mode 100644 docs/modules/_object_.md create mode 100644 docs/modules/_signature_.md create mode 100644 src/externals.ts create mode 100644 test/externals.spec.ts create mode 100644 typedoc.js diff --git a/docs/README.md b/docs/README.md index 1277d57698..32867b8bce 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,1019 +4,12 @@ ## Index -### Interfaces - -* [ECDSASignature](interfaces/ecdsasignature.md) - -### Variables - -* [BN](README.md#bn) -* [Buffer](README.md#const-buffer) -* [KECCAK256_NULL](README.md#const-keccak256_null) -* [KECCAK256_NULL_S](README.md#const-keccak256_null_s) -* [KECCAK256_RLP](README.md#const-keccak256_rlp) -* [KECCAK256_RLP_ARRAY](README.md#const-keccak256_rlp_array) -* [KECCAK256_RLP_ARRAY_S](README.md#const-keccak256_rlp_array_s) -* [KECCAK256_RLP_S](README.md#const-keccak256_rlp_s) -* [MAX_INTEGER](README.md#const-max_integer) -* [TWO_POW256](README.md#const-two_pow256) -* [assert](README.md#const-assert) -* [createHash](README.md#const-createhash) -* [createKeccakHash](README.md#const-createkeccakhash) -* [ethjsUtil](README.md#const-ethjsutil) -* [publicToAddress](README.md#const-publictoaddress) -* [rlp](README.md#rlp) -* [secp256k1](README.md#const-secp256k1) -* [setLength](README.md#const-setlength) -* [stripZeros](README.md#const-stripzeros) - -### Functions - -* [addHexPrefix](README.md#const-addhexprefix) -* [baToJSON](README.md#const-batojson) -* [bufferToHex](README.md#const-buffertohex) -* [bufferToInt](README.md#const-buffertoint) -* [calculateSigRecovery](README.md#calculatesigrecovery) -* [defineProperties](README.md#const-defineproperties) -* [ecrecover](README.md#const-ecrecover) -* [ecsign](README.md#const-ecsign) -* [fromRpcSig](README.md#const-fromrpcsig) -* [fromSigned](README.md#const-fromsigned) -* [generateAddress](README.md#const-generateaddress) -* [generateAddress2](README.md#const-generateaddress2) -* [hashPersonalMessage](README.md#const-hashpersonalmessage) -* [importPublic](README.md#const-importpublic) -* [isPrecompiled](README.md#const-isprecompiled) -* [isValidAddress](README.md#const-isvalidaddress) -* [isValidChecksumAddress](README.md#const-isvalidchecksumaddress) -* [isValidPrivate](README.md#const-isvalidprivate) -* [isValidPublic](README.md#const-isvalidpublic) -* [isValidSigRecovery](README.md#isvalidsigrecovery) -* [isValidSignature](README.md#const-isvalidsignature) -* [isZeroAddress](README.md#const-iszeroaddress) -* [keccak](README.md#const-keccak) -* [keccak256](README.md#const-keccak256) -* [privateToAddress](README.md#const-privatetoaddress) -* [privateToPublic](README.md#const-privatetopublic) -* [pubToAddress](README.md#const-pubtoaddress) -* [ripemd160](README.md#const-ripemd160) -* [rlphash](README.md#const-rlphash) -* [setLengthLeft](README.md#const-setlengthleft) -* [setLengthRight](README.md#const-setlengthright) -* [sha256](README.md#const-sha256) -* [toBuffer](README.md#const-tobuffer) -* [toChecksumAddress](README.md#const-tochecksumaddress) -* [toRpcSig](README.md#const-torpcsig) -* [toUnsigned](README.md#const-tounsigned) -* [unpad](README.md#const-unpad) -* [zeroAddress](README.md#const-zeroaddress) -* [zeros](README.md#const-zeros) - -## Variables - -### BN - -• **BN**: *[BN](README.md#bn)* - -*Defined in [bytes.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L2)* - -*Defined in [account.ts:4](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L4)* - -*Defined in [constants.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L1)* - -*Defined in [signature.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L2)* - -*Defined in [index.ts:3](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/index.ts#L3)* - -___ - -### `Const` Buffer - -• **Buffer**: *any* = require('buffer').Buffer - -*Defined in [constants.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L2)* - -___ - -### `Const` KECCAK256_NULL - -• **KECCAK256_NULL**: *[Buffer](README.md#const-buffer)* = Buffer.from(KECCAK256_NULL_S, 'hex') - -*Defined in [constants.ts:29](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L29)* - -Keccak-256 hash of null - -___ - -### `Const` KECCAK256_NULL_S - -• **KECCAK256_NULL_S**: *string* = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" - -*Defined in [constants.ts:23](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L23)* - -Keccak-256 hash of null - -___ - -### `Const` KECCAK256_RLP - -• **KECCAK256_RLP**: *[Buffer](README.md#const-buffer)* = Buffer.from(KECCAK256_RLP_S, 'hex') - -*Defined in [constants.ts:51](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L51)* - -Keccak-256 hash of the RLP of null - -___ - -### `Const` KECCAK256_RLP_ARRAY - -• **KECCAK256_RLP_ARRAY**: *[Buffer](README.md#const-buffer)* = Buffer.from(KECCAK256_RLP_ARRAY_S, 'hex') - -*Defined in [constants.ts:40](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L40)* - -Keccak-256 of an RLP of an empty array - -___ - -### `Const` KECCAK256_RLP_ARRAY_S - -• **KECCAK256_RLP_ARRAY_S**: *string* = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - -*Defined in [constants.ts:34](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L34)* - -Keccak-256 of an RLP of an empty array - -___ - -### `Const` KECCAK256_RLP_S - -• **KECCAK256_RLP_S**: *string* = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" - -*Defined in [constants.ts:45](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L45)* - -Keccak-256 hash of the RLP of null - -___ - -### `Const` MAX_INTEGER - -• **MAX_INTEGER**: *[BN](README.md#bn)* = new BN( - 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', - 16, -) - -*Defined in [constants.ts:7](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L7)* - -The max integer that this VM can handle - -___ - -### `Const` TWO_POW256 - -• **TWO_POW256**: *[BN](README.md#bn)* = new BN( - '10000000000000000000000000000000000000000000000000000000000000000', - 16, -) - -*Defined in [constants.ts:15](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L15)* - -2^256 - -___ - -### `Const` assert - -• **assert**: *any* = require('assert') - -*Defined in [account.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L1)* - -*Defined in [object.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L1)* - -___ - -### `Const` createHash - -• **createHash**: *any* = require('create-hash') - -*Defined in [hash.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L2)* - -___ - -### `Const` createKeccakHash - -• **createKeccakHash**: *any* = require('keccak') - -*Defined in [hash.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L1)* - -___ - -### `Const` ethjsUtil - -• **ethjsUtil**: *any* = require('ethjs-util') - -*Defined in [bytes.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L1)* - -*Defined in [hash.ts:3](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L3)* - -*Defined in [account.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L2)* - -*Defined in [object.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L2)* - -*Defined in [index.ts:2](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/index.ts#L2)* - -___ - -### `Const` publicToAddress - -• **publicToAddress**: *pubToAddress* = pubToAddress - -*Defined in [account.ts:163](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L163)* - -___ - -### rlp - -• **rlp**: *"/Users/ryanghods/dev/ethereumjs-util/node_modules/rlp/dist/index"* - -*Defined in [hash.ts:4](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L4)* - -*Defined in [object.ts:3](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L3)* - -*Defined in [index.ts:4](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/index.ts#L4)* - -___ - -### `Const` secp256k1 - -• **secp256k1**: *any* = require('secp256k1') - -*Defined in [account.ts:3](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L3)* - -*Defined in [signature.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L1)* - -*Defined in [index.ts:1](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/index.ts#L1)* - -___ - -### `Const` setLength - -• **setLength**: *setLengthLeft* = setLengthLeft - -*Defined in [bytes.ts:37](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L37)* - -___ - -### `Const` stripZeros - -• **stripZeros**: *unpad* = unpad - -*Defined in [bytes.ts:64](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L64)* - -## Functions - -### `Const` addHexPrefix - -▸ **addHexPrefix**(`str`: string): *string* - -*Defined in [bytes.ts:135](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L135)* - -Adds "0x" to a given `String` if it does not already start with "0x". - -**Parameters:** - -Name | Type | ------- | ------ | -`str` | string | - -**Returns:** *string* - -___ - -### `Const` baToJSON - -▸ **baToJSON**(`ba`: any): *any* - -*Defined in [bytes.ts:148](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L148)* - -Converts a `Buffer` or `Array` to JSON. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`ba` | any | (Buffer|Array) | - -**Returns:** *any* - -(Array|String|null) - -___ - -### `Const` bufferToHex - -▸ **bufferToHex**(`buf`: [Buffer](README.md#const-buffer)): *string* - -*Defined in [bytes.ts:111](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L111)* - -Converts a `Buffer` into a `0x`-prefixed hex `String`. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`buf` | [Buffer](README.md#const-buffer) | `Buffer` object to convert | - -**Returns:** *string* - -___ - -### `Const` bufferToInt - -▸ **bufferToInt**(`buf`: [Buffer](README.md#const-buffer)): *number* - -*Defined in [bytes.ts:103](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L103)* - -Converts a `Buffer` to a `Number`. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`buf` | [Buffer](README.md#const-buffer) | `Buffer` object to convert | - -**Returns:** *number* - -___ - -### calculateSigRecovery - -▸ **calculateSigRecovery**(`v`: number, `chainId?`: undefined | number): *number* - -*Defined in [signature.ts:144](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L144)* - -**Parameters:** - -Name | Type | ------- | ------ | -`v` | number | -`chainId?` | undefined | number | - -**Returns:** *number* - -___ - -### `Const` defineProperties - -▸ **defineProperties**(`self`: any, `fields`: any, `data`: any): *void* - -*Defined in [object.ts:17](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L17)* - -Defines properties on a `Object`. It make the assumption that underlying data is binary. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`self` | any | the `Object` to define properties on | -`fields` | any | 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` | -`data` | any | data to be validated against the definitions | - -**Returns:** *void* - -___ - -### `Const` ecrecover - -▸ **ecrecover**(`msgHash`: [Buffer](README.md#const-buffer), `v`: number, `r`: [Buffer](README.md#const-buffer), `s`: [Buffer](README.md#const-buffer), `chainId?`: undefined | number): *[Buffer](README.md#const-buffer)* - -*Defined in [signature.ts:36](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L36)* - -ECDSA public key recovery from signature. - -**Parameters:** - -Name | Type | ------- | ------ | -`msgHash` | [Buffer](README.md#const-buffer) | -`v` | number | -`r` | [Buffer](README.md#const-buffer) | -`s` | [Buffer](README.md#const-buffer) | -`chainId?` | undefined | number | - -**Returns:** *[Buffer](README.md#const-buffer)* - -Recovered public key - -___ - -### `Const` ecsign - -▸ **ecsign**(`msgHash`: [Buffer](README.md#const-buffer), `privateKey`: [Buffer](README.md#const-buffer), `chainId?`: undefined | number): *[ECDSASignature](interfaces/ecdsasignature.md)* - -*Defined in [signature.ts:15](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L15)* - -Returns the ECDSA signature of a message hash. - -**Parameters:** - -Name | Type | ------- | ------ | -`msgHash` | [Buffer](README.md#const-buffer) | -`privateKey` | [Buffer](README.md#const-buffer) | -`chainId?` | undefined | number | - -**Returns:** *[ECDSASignature](interfaces/ecdsasignature.md)* - -___ - -### `Const` fromRpcSig - -▸ **fromRpcSig**(`sig`: string): *[ECDSASignature](interfaces/ecdsasignature.md)* - -*Defined in [signature.ts:70](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L70)* - -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 - -**Parameters:** - -Name | Type | ------- | ------ | -`sig` | string | - -**Returns:** *[ECDSASignature](interfaces/ecdsasignature.md)* - -___ - -### `Const` fromSigned - -▸ **fromSigned**(`num`: [Buffer](README.md#const-buffer)): *[BN](README.md#bn)* - -*Defined in [bytes.ts:120](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L120)* - -Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`num` | [Buffer](README.md#const-buffer) | Signed integer value | - -**Returns:** *[BN](README.md#bn)* - -___ - -### `Const` generateAddress - -▸ **generateAddress**(`from`: [Buffer](README.md#const-buffer), `nonce`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* - -*Defined in [account.ts:75](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L75)* - -Generates an address of a newly created contract. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`from` | [Buffer](README.md#const-buffer) | The address which is creating this new address | -`nonce` | [Buffer](README.md#const-buffer) | The nonce of the from account | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` generateAddress2 - -▸ **generateAddress2**(`from`: [Buffer](README.md#const-buffer) | string, `salt`: [Buffer](README.md#const-buffer) | string, `initCode`: [Buffer](README.md#const-buffer) | string): *[Buffer](README.md#const-buffer)* - -*Defined in [account.ts:95](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L95)* - -Generates an address for a contract created using CREATE2. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`from` | [Buffer](README.md#const-buffer) | string | The address which is creating this new address | -`salt` | [Buffer](README.md#const-buffer) | string | A salt | -`initCode` | [Buffer](README.md#const-buffer) | string | The init code of the contract being created | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` hashPersonalMessage - -▸ **hashPersonalMessage**(`message`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* - -*Defined in [signature.ts:136](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L136)* - -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. - -**Parameters:** - -Name | Type | ------- | ------ | -`message` | [Buffer](README.md#const-buffer) | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` importPublic - -▸ **importPublic**(`publicKey`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* - -*Defined in [account.ts:186](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L186)* - -Converts a public key to the Ethereum format. - -**Parameters:** - -Name | Type | ------- | ------ | -`publicKey` | [Buffer](README.md#const-buffer) | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` isPrecompiled - -▸ **isPrecompiled**(`address`: [Buffer](README.md#const-buffer) | string): *boolean* - -*Defined in [account.ts:117](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L117)* - -Returns true if the supplied address belongs to a precompiled account (Byzantium). - -**Parameters:** - -Name | Type | ------- | ------ | -`address` | [Buffer](README.md#const-buffer) | string | - -**Returns:** *boolean* - -___ - -### `Const` isValidAddress - -▸ **isValidAddress**(`address`: string): *boolean* - -*Defined in [account.ts:20](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L20)* - -Checks if the address is a valid. Accepts checksummed addresses too. - -**Parameters:** - -Name | Type | ------- | ------ | -`address` | string | - -**Returns:** *boolean* - -___ - -### `Const` isValidChecksumAddress - -▸ **isValidChecksumAddress**(`address`: string, `eip1191ChainId?`: undefined | number): *boolean* - -*Defined in [account.ts:66](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L66)* - -Checks if the address is a valid checksummed address. - -See toChecksumAddress' documentation for details about the eip1191ChainId parameter. - -**Parameters:** - -Name | Type | ------- | ------ | -`address` | string | -`eip1191ChainId?` | undefined | number | - -**Returns:** *boolean* - -___ - -### `Const` isValidPrivate - -▸ **isValidPrivate**(`privateKey`: [Buffer](README.md#const-buffer)): *boolean* - -*Defined in [account.ts:125](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L125)* - -Checks if the private key satisfies the rules of the curve secp256k1. - -**Parameters:** - -Name | Type | ------- | ------ | -`privateKey` | [Buffer](README.md#const-buffer) | - -**Returns:** *boolean* - -___ - -### `Const` isValidPublic - -▸ **isValidPublic**(`publicKey`: [Buffer](README.md#const-buffer), `sanitize`: boolean): *boolean* - -*Defined in [account.ts:135](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L135)* - -Checks if the public key satisfies the rules of the curve secp256k1 -and the requirements of Ethereum. - -**Parameters:** - -Name | Type | Default | Description | ------- | ------ | ------ | ------ | -`publicKey` | [Buffer](README.md#const-buffer) | - | The two points of an uncompressed key, unless sanitize is enabled | -`sanitize` | boolean | false | Accept public keys in other formats | - -**Returns:** *boolean* - -___ - -### isValidSigRecovery - -▸ **isValidSigRecovery**(`recovery`: number): *boolean* - -*Defined in [signature.ts:148](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L148)* - -**Parameters:** - -Name | Type | ------- | ------ | -`recovery` | number | - -**Returns:** *boolean* - -___ - -### `Const` isValidSignature - -▸ **isValidSignature**(`v`: number, `r`: [Buffer](README.md#const-buffer), `s`: [Buffer](README.md#const-buffer), `homesteadOrLater`: boolean, `chainId?`: undefined | number): *boolean* - -*Defined in [signature.ts:95](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L95)* - -Validate a ECDSA signature. - -**Parameters:** - -Name | Type | Default | Description | ------- | ------ | ------ | ------ | -`v` | number | - | - | -`r` | [Buffer](README.md#const-buffer) | - | - | -`s` | [Buffer](README.md#const-buffer) | - | - | -`homesteadOrLater` | boolean | true | Indicates whether this is being used on either the homestead hardfork or a later one | -`chainId?` | undefined | number | - | - | - -**Returns:** *boolean* - -___ - -### `Const` isZeroAddress - -▸ **isZeroAddress**(`address`: string): *boolean* - -*Defined in [account.ts:27](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L27)* - -Checks if a given address is a zero address. - -**Parameters:** - -Name | Type | ------- | ------ | -`address` | string | - -**Returns:** *boolean* - -___ - -### `Const` keccak - -▸ **keccak**(`a`: any, `bits`: number): *[Buffer](README.md#const-buffer)* - -*Defined in [hash.ts:13](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L13)* - -Creates Keccak hash of the input - -**Parameters:** - -Name | Type | Default | Description | ------- | ------ | ------ | ------ | -`a` | any | - | The input data (Buffer|Array|String|Number) If the string is a 0x-prefixed hex value it's interpreted as hexadecimal, otherwise as utf8. | -`bits` | number | 256 | The Keccak width | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` keccak256 - -▸ **keccak256**(`a`: any): *[Buffer](README.md#const-buffer)* - -*Defined in [hash.ts:31](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L31)* - -Creates Keccak-256 hash of the input, alias for keccak(a, 256). - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`a` | any | The input data (Buffer|Array|String|Number) | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` privateToAddress - -▸ **privateToAddress**(`privateKey`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* - -*Defined in [account.ts:169](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L169)* - -Returns the ethereum address of a given private key. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`privateKey` | [Buffer](README.md#const-buffer) | A private key must be 256 bits wide | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` privateToPublic - -▸ **privateToPublic**(`privateKey`: [Buffer](README.md#const-buffer)): *[Buffer](README.md#const-buffer)* - -*Defined in [account.ts:177](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L177)* - -Returns the ethereum public key of a given private key. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`privateKey` | [Buffer](README.md#const-buffer) | A private key must be 256 bits wide | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` pubToAddress - -▸ **pubToAddress**(`pubKey`: [Buffer](README.md#const-buffer), `sanitize`: boolean): *[Buffer](README.md#const-buffer)* - -*Defined in [account.ts:154](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L154)* - -Returns the ethereum address of a given public key. -Accepts "Ethereum public keys" and SEC1 encoded keys. - -**Parameters:** - -Name | Type | Default | Description | ------- | ------ | ------ | ------ | -`pubKey` | [Buffer](README.md#const-buffer) | - | The two points of an uncompressed key, unless sanitize is enabled | -`sanitize` | boolean | false | Accept public keys in other formats | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` ripemd160 - -▸ **ripemd160**(`a`: any, `padded`: boolean): *[Buffer](README.md#const-buffer)* - -*Defined in [hash.ts:51](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L51)* - -Creates RIPEMD160 hash of the input. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`a` | any | The input data (Buffer|Array|String|Number) | -`padded` | boolean | Whether it should be padded to 256 bits or not | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` rlphash - -▸ **rlphash**(`a`: rlp.Input): *[Buffer](README.md#const-buffer)* - -*Defined in [hash.ts:67](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L67)* - -Creates SHA-3 hash of the RLP encoded version of the input. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`a` | rlp.Input | The input data | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` setLengthLeft - -▸ **setLengthLeft**(`msg`: any, `length`: number, `right`: boolean): *any* - -*Defined in [bytes.ts:20](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L20)* - -Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. -Or it truncates the beginning if it exceeds. - -**Parameters:** - -Name | Type | Default | Description | ------- | ------ | ------ | ------ | -`msg` | any | - | the value to pad (Buffer|Array) | -`length` | number | - | the number of bytes the output should be | -`right` | boolean | false | whether to start padding form the left or right | - -**Returns:** *any* - -(Buffer|Array) - -___ - -### `Const` setLengthRight - -▸ **setLengthRight**(`msg`: any, `length`: number): *any* - -*Defined in [bytes.ts:46](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L46)* - -Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. -Or it truncates the beginning if it exceeds. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`msg` | any | the value to pad (Buffer|Array) | -`length` | number | the number of bytes the output should be | - -**Returns:** *any* - -(Buffer|Array) - -___ - -### `Const` sha256 - -▸ **sha256**(`a`: any): *[Buffer](README.md#const-buffer)* - -*Defined in [hash.ts:39](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L39)* - -Creates SHA256 hash of the input. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`a` | any | The input data (Buffer|Array|String|Number) | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` toBuffer - -▸ **toBuffer**(`v`: any): *[Buffer](README.md#const-buffer)* - -*Defined in [bytes.ts:70](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L70)* - -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. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`v` | any | the value | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` toChecksumAddress - -▸ **toChecksumAddress**(`address`: string, `eip1191ChainId?`: undefined | number): *string* - -*Defined in [account.ts:42](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L42)* - -Returns a checksummed address. - -If a eip1191ChainId is provided, the chainId will be included in the checksum calculation. This -has the effect of checksummed addresses for one chain having invalid checksums for others. -For more details, consult EIP-1191. - -WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly -used variation in Ethereum was without the chainId. This may change in the future. - -**Parameters:** - -Name | Type | ------- | ------ | -`address` | string | -`eip1191ChainId?` | undefined | number | - -**Returns:** *string* - -___ - -### `Const` toRpcSig - -▸ **toRpcSig**(`v`: number, `r`: [Buffer](README.md#const-buffer), `s`: [Buffer](README.md#const-buffer), `chainId?`: undefined | number): *string* - -*Defined in [signature.ts:56](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L56)* - -Convert signature parameters into the format of `eth_sign` RPC method. - -**Parameters:** - -Name | Type | ------- | ------ | -`v` | number | -`r` | [Buffer](README.md#const-buffer) | -`s` | [Buffer](README.md#const-buffer) | -`chainId?` | undefined | number | - -**Returns:** *string* - -Signature - -___ - -### `Const` toUnsigned - -▸ **toUnsigned**(`num`: [BN](README.md#bn)): *[Buffer](README.md#const-buffer)* - -*Defined in [bytes.ts:128](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L128)* - -Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`num` | [BN](README.md#bn) | | - -**Returns:** *[Buffer](README.md#const-buffer)* - -___ - -### `Const` unpad - -▸ **unpad**(`a`: any): *any* - -*Defined in [bytes.ts:55](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L55)* - -Trims leading zeros from a `Buffer` or an `Array`. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`a` | any | (Buffer|Array|String) | - -**Returns:** *any* - -(Buffer|Array|String) - -___ - -### `Const` zeroAddress - -▸ **zeroAddress**(): *string* - -*Defined in [account.ts:11](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L11)* - -Returns a zero address. - -**Returns:** *string* - -___ - -### `Const` zeros - -▸ **zeros**(`bytes`: number): *[Buffer](README.md#const-buffer)* - -*Defined in [bytes.ts:8](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L8)* - -Returns a buffer filled with 0s. - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`bytes` | number | the number of bytes the buffer should be | - -**Returns:** *[Buffer](README.md#const-buffer)* +### Modules + +* ["account"](modules/_account_.md) +* ["bytes"](modules/_bytes_.md) +* ["constants"](modules/_constants_.md) +* ["externals"](modules/_externals_.md) +* ["hash"](modules/_hash_.md) +* ["object"](modules/_object_.md) +* ["signature"](modules/_signature_.md) diff --git a/docs/interfaces/ecdsasignature.md b/docs/interfaces/_signature_.ecdsasignature.md similarity index 63% rename from docs/interfaces/ecdsasignature.md rename to docs/interfaces/_signature_.ecdsasignature.md index 52775c085f..428fbc167a 100644 --- a/docs/interfaces/ecdsasignature.md +++ b/docs/interfaces/_signature_.ecdsasignature.md @@ -1,4 +1,4 @@ -[ethereumjs-util](../README.md) › [ECDSASignature](ecdsasignature.md) +[ethereumjs-util](../README.md) › ["signature"](../modules/_signature_.md) › [ECDSASignature](_signature_.ecdsasignature.md) # Interface: ECDSASignature @@ -10,15 +10,15 @@ ### Properties -* [r](ecdsasignature.md#r) -* [s](ecdsasignature.md#s) -* [v](ecdsasignature.md#v) +* [r](_signature_.ecdsasignature.md#r) +* [s](_signature_.ecdsasignature.md#s) +* [v](_signature_.ecdsasignature.md#v) ## Properties ### r -• **r**: *[Buffer](../README.md#const-buffer)* +• **r**: *Buffer* *Defined in [signature.ts:8](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L8)* @@ -26,7 +26,7 @@ ___ ### s -• **s**: *[Buffer](../README.md#const-buffer)* +• **s**: *Buffer* *Defined in [signature.ts:9](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L9)* diff --git a/docs/modules/_account_.md b/docs/modules/_account_.md new file mode 100644 index 0000000000..720a3c3b21 --- /dev/null +++ b/docs/modules/_account_.md @@ -0,0 +1,298 @@ +[ethereumjs-util](../README.md) › ["account"](_account_.md) + +# Module: "account" + +## Index + +### Variables + +* [publicToAddress](_account_.md#const-publictoaddress) + +### Functions + +* [generateAddress](_account_.md#const-generateaddress) +* [generateAddress2](_account_.md#const-generateaddress2) +* [importPublic](_account_.md#const-importpublic) +* [isPrecompiled](_account_.md#const-isprecompiled) +* [isValidAddress](_account_.md#const-isvalidaddress) +* [isValidChecksumAddress](_account_.md#const-isvalidchecksumaddress) +* [isValidPrivate](_account_.md#const-isvalidprivate) +* [isValidPublic](_account_.md#const-isvalidpublic) +* [isZeroAddress](_account_.md#const-iszeroaddress) +* [privateToAddress](_account_.md#const-privatetoaddress) +* [privateToPublic](_account_.md#const-privatetopublic) +* [pubToAddress](_account_.md#const-pubtoaddress) +* [toChecksumAddress](_account_.md#const-tochecksumaddress) +* [zeroAddress](_account_.md#const-zeroaddress) + +## Variables + +### `Const` publicToAddress + +• **publicToAddress**: *pubToAddress* = pubToAddress + +*Defined in [account.ts:163](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L163)* + +## Functions + +### `Const` generateAddress + +▸ **generateAddress**(`from`: Buffer, `nonce`: Buffer): *Buffer* + +*Defined in [account.ts:75](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L75)* + +Generates an address of a newly created contract. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`from` | Buffer | The address which is creating this new address | +`nonce` | Buffer | The nonce of the from account | + +**Returns:** *Buffer* + +___ + +### `Const` generateAddress2 + +▸ **generateAddress2**(`from`: Buffer | string, `salt`: Buffer | string, `initCode`: Buffer | string): *Buffer* + +*Defined in [account.ts:95](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L95)* + +Generates an address for a contract created using CREATE2. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`from` | Buffer | string | The address which is creating this new address | +`salt` | Buffer | string | A salt | +`initCode` | Buffer | string | The init code of the contract being created | + +**Returns:** *Buffer* + +___ + +### `Const` importPublic + +▸ **importPublic**(`publicKey`: Buffer): *Buffer* + +*Defined in [account.ts:186](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L186)* + +Converts a public key to the Ethereum format. + +**Parameters:** + +Name | Type | +------ | ------ | +`publicKey` | Buffer | + +**Returns:** *Buffer* + +___ + +### `Const` isPrecompiled + +▸ **isPrecompiled**(`address`: Buffer | string): *boolean* + +*Defined in [account.ts:117](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L117)* + +Returns true if the supplied address belongs to a precompiled account (Byzantium). + +**Parameters:** + +Name | Type | +------ | ------ | +`address` | Buffer | string | + +**Returns:** *boolean* + +___ + +### `Const` isValidAddress + +▸ **isValidAddress**(`address`: string): *boolean* + +*Defined in [account.ts:20](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L20)* + +Checks if the address is a valid. Accepts checksummed addresses too. + +**Parameters:** + +Name | Type | +------ | ------ | +`address` | string | + +**Returns:** *boolean* + +___ + +### `Const` isValidChecksumAddress + +▸ **isValidChecksumAddress**(`address`: string, `eip1191ChainId?`: undefined | number): *boolean* + +*Defined in [account.ts:66](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L66)* + +Checks if the address is a valid checksummed address. + +See toChecksumAddress' documentation for details about the eip1191ChainId parameter. + +**Parameters:** + +Name | Type | +------ | ------ | +`address` | string | +`eip1191ChainId?` | undefined | number | + +**Returns:** *boolean* + +___ + +### `Const` isValidPrivate + +▸ **isValidPrivate**(`privateKey`: Buffer): *boolean* + +*Defined in [account.ts:125](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L125)* + +Checks if the private key satisfies the rules of the curve secp256k1. + +**Parameters:** + +Name | Type | +------ | ------ | +`privateKey` | Buffer | + +**Returns:** *boolean* + +___ + +### `Const` isValidPublic + +▸ **isValidPublic**(`publicKey`: Buffer, `sanitize`: boolean): *boolean* + +*Defined in [account.ts:135](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L135)* + +Checks if the public key satisfies the rules of the curve secp256k1 +and the requirements of Ethereum. + +**Parameters:** + +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`publicKey` | Buffer | - | The two points of an uncompressed key, unless sanitize is enabled | +`sanitize` | boolean | false | Accept public keys in other formats | + +**Returns:** *boolean* + +___ + +### `Const` isZeroAddress + +▸ **isZeroAddress**(`address`: string): *boolean* + +*Defined in [account.ts:27](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L27)* + +Checks if a given address is a zero address. + +**Parameters:** + +Name | Type | +------ | ------ | +`address` | string | + +**Returns:** *boolean* + +___ + +### `Const` privateToAddress + +▸ **privateToAddress**(`privateKey`: Buffer): *Buffer* + +*Defined in [account.ts:169](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L169)* + +Returns the ethereum address of a given private key. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`privateKey` | Buffer | A private key must be 256 bits wide | + +**Returns:** *Buffer* + +___ + +### `Const` privateToPublic + +▸ **privateToPublic**(`privateKey`: Buffer): *Buffer* + +*Defined in [account.ts:177](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L177)* + +Returns the ethereum public key of a given private key. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`privateKey` | Buffer | A private key must be 256 bits wide | + +**Returns:** *Buffer* + +___ + +### `Const` pubToAddress + +▸ **pubToAddress**(`pubKey`: Buffer, `sanitize`: boolean): *Buffer* + +*Defined in [account.ts:154](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L154)* + +Returns the ethereum address of a given public key. +Accepts "Ethereum public keys" and SEC1 encoded keys. + +**Parameters:** + +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`pubKey` | Buffer | - | The two points of an uncompressed key, unless sanitize is enabled | +`sanitize` | boolean | false | Accept public keys in other formats | + +**Returns:** *Buffer* + +___ + +### `Const` toChecksumAddress + +▸ **toChecksumAddress**(`address`: string, `eip1191ChainId?`: undefined | number): *string* + +*Defined in [account.ts:42](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L42)* + +Returns a checksummed address. + +If a eip1191ChainId is provided, the chainId will be included in the checksum calculation. This +has the effect of checksummed addresses for one chain having invalid checksums for others. +For more details, consult EIP-1191. + +WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly +used variation in Ethereum was without the chainId. This may change in the future. + +**Parameters:** + +Name | Type | +------ | ------ | +`address` | string | +`eip1191ChainId?` | undefined | number | + +**Returns:** *string* + +___ + +### `Const` zeroAddress + +▸ **zeroAddress**(): *string* + +*Defined in [account.ts:11](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L11)* + +Returns a zero address. + +**Returns:** *string* diff --git a/docs/modules/_bytes_.md b/docs/modules/_bytes_.md new file mode 100644 index 0000000000..14cb64bce9 --- /dev/null +++ b/docs/modules/_bytes_.md @@ -0,0 +1,251 @@ +[ethereumjs-util](../README.md) › ["bytes"](_bytes_.md) + +# Module: "bytes" + +## Index + +### Variables + +* [setLength](_bytes_.md#const-setlength) +* [stripZeros](_bytes_.md#const-stripzeros) + +### Functions + +* [addHexPrefix](_bytes_.md#const-addhexprefix) +* [baToJSON](_bytes_.md#const-batojson) +* [bufferToHex](_bytes_.md#const-buffertohex) +* [bufferToInt](_bytes_.md#const-buffertoint) +* [fromSigned](_bytes_.md#const-fromsigned) +* [setLengthLeft](_bytes_.md#const-setlengthleft) +* [setLengthRight](_bytes_.md#const-setlengthright) +* [toBuffer](_bytes_.md#const-tobuffer) +* [toUnsigned](_bytes_.md#const-tounsigned) +* [unpad](_bytes_.md#const-unpad) +* [zeros](_bytes_.md#const-zeros) + +## Variables + +### `Const` setLength + +• **setLength**: *setLengthLeft* = setLengthLeft + +*Defined in [bytes.ts:37](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L37)* + +___ + +### `Const` stripZeros + +• **stripZeros**: *unpad* = unpad + +*Defined in [bytes.ts:64](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L64)* + +## Functions + +### `Const` addHexPrefix + +▸ **addHexPrefix**(`str`: string): *string* + +*Defined in [bytes.ts:135](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L135)* + +Adds "0x" to a given `String` if it does not already start with "0x". + +**Parameters:** + +Name | Type | +------ | ------ | +`str` | string | + +**Returns:** *string* + +___ + +### `Const` baToJSON + +▸ **baToJSON**(`ba`: any): *any* + +*Defined in [bytes.ts:148](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L148)* + +Converts a `Buffer` or `Array` to JSON. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`ba` | any | (Buffer|Array) | + +**Returns:** *any* + +(Array|String|null) + +___ + +### `Const` bufferToHex + +▸ **bufferToHex**(`buf`: Buffer): *string* + +*Defined in [bytes.ts:111](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L111)* + +Converts a `Buffer` into a `0x`-prefixed hex `String`. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`buf` | Buffer | `Buffer` object to convert | + +**Returns:** *string* + +___ + +### `Const` bufferToInt + +▸ **bufferToInt**(`buf`: Buffer): *number* + +*Defined in [bytes.ts:103](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L103)* + +Converts a `Buffer` to a `Number`. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`buf` | Buffer | `Buffer` object to convert | + +**Returns:** *number* + +___ + +### `Const` fromSigned + +▸ **fromSigned**(`num`: Buffer): *BN* + +*Defined in [bytes.ts:120](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L120)* + +Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`num` | Buffer | Signed integer value | + +**Returns:** *BN* + +___ + +### `Const` setLengthLeft + +▸ **setLengthLeft**(`msg`: any, `length`: number, `right`: boolean): *any* + +*Defined in [bytes.ts:20](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L20)* + +Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. +Or it truncates the beginning if it exceeds. + +**Parameters:** + +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`msg` | any | - | the value to pad (Buffer|Array) | +`length` | number | - | the number of bytes the output should be | +`right` | boolean | false | whether to start padding form the left or right | + +**Returns:** *any* + +(Buffer|Array) + +___ + +### `Const` setLengthRight + +▸ **setLengthRight**(`msg`: any, `length`: number): *any* + +*Defined in [bytes.ts:46](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L46)* + +Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes. +Or it truncates the beginning if it exceeds. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`msg` | any | the value to pad (Buffer|Array) | +`length` | number | the number of bytes the output should be | + +**Returns:** *any* + +(Buffer|Array) + +___ + +### `Const` toBuffer + +▸ **toBuffer**(`v`: any): *Buffer* + +*Defined in [bytes.ts:70](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L70)* + +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. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`v` | any | the value | + +**Returns:** *Buffer* + +___ + +### `Const` toUnsigned + +▸ **toUnsigned**(`num`: BN): *Buffer* + +*Defined in [bytes.ts:128](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L128)* + +Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`num` | BN | | + +**Returns:** *Buffer* + +___ + +### `Const` unpad + +▸ **unpad**(`a`: any): *any* + +*Defined in [bytes.ts:55](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L55)* + +Trims leading zeros from a `Buffer` or an `Array`. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`a` | any | (Buffer|Array|String) | + +**Returns:** *any* + +(Buffer|Array|String) + +___ + +### `Const` zeros + +▸ **zeros**(`bytes`: number): *Buffer* + +*Defined in [bytes.ts:8](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L8)* + +Returns a buffer filled with 0s. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`bytes` | number | the number of bytes the buffer should be | + +**Returns:** *Buffer* diff --git a/docs/modules/_constants_.md b/docs/modules/_constants_.md new file mode 100644 index 0000000000..78542f0110 --- /dev/null +++ b/docs/modules/_constants_.md @@ -0,0 +1,102 @@ +[ethereumjs-util](../README.md) › ["constants"](_constants_.md) + +# Module: "constants" + +## Index + +### Variables + +* [KECCAK256_NULL](_constants_.md#const-keccak256_null) +* [KECCAK256_NULL_S](_constants_.md#const-keccak256_null_s) +* [KECCAK256_RLP](_constants_.md#const-keccak256_rlp) +* [KECCAK256_RLP_ARRAY](_constants_.md#const-keccak256_rlp_array) +* [KECCAK256_RLP_ARRAY_S](_constants_.md#const-keccak256_rlp_array_s) +* [KECCAK256_RLP_S](_constants_.md#const-keccak256_rlp_s) +* [MAX_INTEGER](_constants_.md#const-max_integer) +* [TWO_POW256](_constants_.md#const-two_pow256) + +## Variables + +### `Const` KECCAK256_NULL + +• **KECCAK256_NULL**: *Buffer* = Buffer.from(KECCAK256_NULL_S, 'hex') + +*Defined in [constants.ts:29](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L29)* + +Keccak-256 hash of null + +___ + +### `Const` KECCAK256_NULL_S + +• **KECCAK256_NULL_S**: *string* = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" + +*Defined in [constants.ts:23](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L23)* + +Keccak-256 hash of null + +___ + +### `Const` KECCAK256_RLP + +• **KECCAK256_RLP**: *Buffer* = Buffer.from(KECCAK256_RLP_S, 'hex') + +*Defined in [constants.ts:51](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L51)* + +Keccak-256 hash of the RLP of null + +___ + +### `Const` KECCAK256_RLP_ARRAY + +• **KECCAK256_RLP_ARRAY**: *Buffer* = Buffer.from(KECCAK256_RLP_ARRAY_S, 'hex') + +*Defined in [constants.ts:40](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L40)* + +Keccak-256 of an RLP of an empty array + +___ + +### `Const` KECCAK256_RLP_ARRAY_S + +• **KECCAK256_RLP_ARRAY_S**: *string* = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" + +*Defined in [constants.ts:34](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L34)* + +Keccak-256 of an RLP of an empty array + +___ + +### `Const` KECCAK256_RLP_S + +• **KECCAK256_RLP_S**: *string* = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + +*Defined in [constants.ts:45](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L45)* + +Keccak-256 hash of the RLP of null + +___ + +### `Const` MAX_INTEGER + +• **MAX_INTEGER**: *BN* = new BN( + 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', + 16, +) + +*Defined in [constants.ts:7](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L7)* + +The max integer that this VM can handle + +___ + +### `Const` TWO_POW256 + +• **TWO_POW256**: *BN* = new BN( + '10000000000000000000000000000000000000000000000000000000000000000', + 16, +) + +*Defined in [constants.ts:15](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L15)* + +2^256 diff --git a/docs/modules/_externals_.md b/docs/modules/_externals_.md new file mode 100644 index 0000000000..e950346426 --- /dev/null +++ b/docs/modules/_externals_.md @@ -0,0 +1,7 @@ +[ethereumjs-util](../README.md) › ["externals"](_externals_.md) + +# Module: "externals" + +Re-exports commonly used modules: +* Adds [`ethjsUtil`](https://github.com/ethjs/ethjs-util) methods. +* Exports [`BN`](https://github.com/indutny/bn.js), [`rlp`](https://github.com/ethereumjs/rlp), [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/)`. diff --git a/docs/modules/_hash_.md b/docs/modules/_hash_.md new file mode 100644 index 0000000000..6e95275906 --- /dev/null +++ b/docs/modules/_hash_.md @@ -0,0 +1,105 @@ +[ethereumjs-util](../README.md) › ["hash"](_hash_.md) + +# Module: "hash" + +## Index + +### Functions + +* [keccak](_hash_.md#const-keccak) +* [keccak256](_hash_.md#const-keccak256) +* [ripemd160](_hash_.md#const-ripemd160) +* [rlphash](_hash_.md#const-rlphash) +* [sha256](_hash_.md#const-sha256) + +## Functions + +### `Const` keccak + +▸ **keccak**(`a`: any, `bits`: number): *Buffer* + +*Defined in [hash.ts:13](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L13)* + +Creates Keccak hash of the input + +**Parameters:** + +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`a` | any | - | The input data (Buffer|Array|String|Number) If the string is a 0x-prefixed hex value it's interpreted as hexadecimal, otherwise as utf8. | +`bits` | number | 256 | The Keccak width | + +**Returns:** *Buffer* + +___ + +### `Const` keccak256 + +▸ **keccak256**(`a`: any): *Buffer* + +*Defined in [hash.ts:31](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L31)* + +Creates Keccak-256 hash of the input, alias for keccak(a, 256). + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`a` | any | The input data (Buffer|Array|String|Number) | + +**Returns:** *Buffer* + +___ + +### `Const` ripemd160 + +▸ **ripemd160**(`a`: any, `padded`: boolean): *Buffer* + +*Defined in [hash.ts:51](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L51)* + +Creates RIPEMD160 hash of the input. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`a` | any | The input data (Buffer|Array|String|Number) | +`padded` | boolean | Whether it should be padded to 256 bits or not | + +**Returns:** *Buffer* + +___ + +### `Const` rlphash + +▸ **rlphash**(`a`: rlp.Input): *Buffer* + +*Defined in [hash.ts:67](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L67)* + +Creates SHA-3 hash of the RLP encoded version of the input. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`a` | rlp.Input | The input data | + +**Returns:** *Buffer* + +___ + +### `Const` sha256 + +▸ **sha256**(`a`: any): *Buffer* + +*Defined in [hash.ts:39](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/hash.ts#L39)* + +Creates SHA256 hash of the input. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`a` | any | The input data (Buffer|Array|String|Number) | + +**Returns:** *Buffer* diff --git a/docs/modules/_object_.md b/docs/modules/_object_.md new file mode 100644 index 0000000000..983e568cbe --- /dev/null +++ b/docs/modules/_object_.md @@ -0,0 +1,29 @@ +[ethereumjs-util](../README.md) › ["object"](_object_.md) + +# Module: "object" + +## Index + +### Functions + +* [defineProperties](_object_.md#const-defineproperties) + +## Functions + +### `Const` defineProperties + +▸ **defineProperties**(`self`: any, `fields`: any, `data`: any): *void* + +*Defined in [object.ts:17](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/object.ts#L17)* + +Defines properties on a `Object`. It make the assumption that underlying data is binary. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`self` | any | the `Object` to define properties on | +`fields` | any | 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` | +`data` | any | data to be validated against the definitions | + +**Returns:** *void* diff --git a/docs/modules/_signature_.md b/docs/modules/_signature_.md new file mode 100644 index 0000000000..96e7c35bee --- /dev/null +++ b/docs/modules/_signature_.md @@ -0,0 +1,147 @@ +[ethereumjs-util](../README.md) › ["signature"](_signature_.md) + +# Module: "signature" + +## Index + +### Interfaces + +* [ECDSASignature](../interfaces/_signature_.ecdsasignature.md) + +### Functions + +* [ecrecover](_signature_.md#const-ecrecover) +* [ecsign](_signature_.md#const-ecsign) +* [fromRpcSig](_signature_.md#const-fromrpcsig) +* [hashPersonalMessage](_signature_.md#const-hashpersonalmessage) +* [isValidSignature](_signature_.md#const-isvalidsignature) +* [toRpcSig](_signature_.md#const-torpcsig) + +## Functions + +### `Const` ecrecover + +▸ **ecrecover**(`msgHash`: Buffer, `v`: number, `r`: Buffer, `s`: Buffer, `chainId?`: undefined | number): *Buffer* + +*Defined in [signature.ts:36](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L36)* + +ECDSA public key recovery from signature. + +**Parameters:** + +Name | Type | +------ | ------ | +`msgHash` | Buffer | +`v` | number | +`r` | Buffer | +`s` | Buffer | +`chainId?` | undefined | number | + +**Returns:** *Buffer* + +Recovered public key + +___ + +### `Const` ecsign + +▸ **ecsign**(`msgHash`: Buffer, `privateKey`: Buffer, `chainId?`: undefined | number): *[ECDSASignature](../interfaces/_signature_.ecdsasignature.md)* + +*Defined in [signature.ts:15](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L15)* + +Returns the ECDSA signature of a message hash. + +**Parameters:** + +Name | Type | +------ | ------ | +`msgHash` | Buffer | +`privateKey` | Buffer | +`chainId?` | undefined | number | + +**Returns:** *[ECDSASignature](../interfaces/_signature_.ecdsasignature.md)* + +___ + +### `Const` fromRpcSig + +▸ **fromRpcSig**(`sig`: string): *[ECDSASignature](../interfaces/_signature_.ecdsasignature.md)* + +*Defined in [signature.ts:70](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L70)* + +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 + +**Parameters:** + +Name | Type | +------ | ------ | +`sig` | string | + +**Returns:** *[ECDSASignature](../interfaces/_signature_.ecdsasignature.md)* + +___ + +### `Const` hashPersonalMessage + +▸ **hashPersonalMessage**(`message`: Buffer): *Buffer* + +*Defined in [signature.ts:136](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L136)* + +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. + +**Parameters:** + +Name | Type | +------ | ------ | +`message` | Buffer | + +**Returns:** *Buffer* + +___ + +### `Const` isValidSignature + +▸ **isValidSignature**(`v`: number, `r`: Buffer, `s`: Buffer, `homesteadOrLater`: boolean, `chainId?`: undefined | number): *boolean* + +*Defined in [signature.ts:95](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L95)* + +Validate a ECDSA signature. + +**Parameters:** + +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`v` | number | - | - | +`r` | Buffer | - | - | +`s` | Buffer | - | - | +`homesteadOrLater` | boolean | true | Indicates whether this is being used on either the homestead hardfork or a later one | +`chainId?` | undefined | number | - | - | + +**Returns:** *boolean* + +___ + +### `Const` toRpcSig + +▸ **toRpcSig**(`v`: number, `r`: Buffer, `s`: Buffer, `chainId?`: undefined | number): *string* + +*Defined in [signature.ts:56](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L56)* + +Convert signature parameters into the format of `eth_sign` RPC method. + +**Parameters:** + +Name | Type | +------ | ------ | +`v` | number | +`r` | Buffer | +`s` | Buffer | +`chainId?` | undefined | number | + +**Returns:** *string* + +Signature diff --git a/package.json b/package.json index a150544f28..d3c8d36bfb 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "build": "ethereumjs-config-build", "prepublishOnly": "npm run test && npm run build", - "docs:build": "npx typedoc --plugin typedoc-plugin-markdown --out docs --mode file --readme none --gitRevision master --module commonjs --excludeNotExported src", + "docs:build": "npx typedoc --options typedoc.js", "format": "ethereumjs-config-format", "format:fix": "ethereumjs-config-format-fix", "lint": "ethereumjs-config-lint", @@ -100,6 +100,7 @@ "@ethereumjs/config-tslint": "^1.1.0", "@types/mocha": "^5.2.7", "@types/node": "^11.9.0", + "@types/secp256k1": "3.5.0", "contributor": "^0.1.25", "husky": "^2.1.0", "karma": "^4.0.0", @@ -112,7 +113,7 @@ "prettier": "^1.15.3", "ts-node": "^8.6.2", "tslint": "^5.12.0", - "typedoc": "^0.16.9", + "typedoc": "next", "typedoc-plugin-markdown": "^2.2.16", "typescript": "^3.2.2", "typestrict": "^1.0.2" diff --git a/src/account.ts b/src/account.ts index 79e8e0a53e..8eabac82f1 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,7 +1,7 @@ -const assert = require('assert') const ethjsUtil = require('ethjs-util') -const secp256k1 = require('secp256k1') -import BN = require('bn.js') +import * as assert from 'assert' +import * as secp256k1 from 'secp256k1' +import * as BN from 'bn.js' import { toBuffer, addHexPrefix, zeros, bufferToHex, unpad } from './bytes' import { keccak, keccak256, rlphash } from './hash' diff --git a/src/bytes.ts b/src/bytes.ts index 7d117b3e87..37e8af1e10 100644 --- a/src/bytes.ts +++ b/src/bytes.ts @@ -1,5 +1,5 @@ const ethjsUtil = require('ethjs-util') -import BN = require('bn.js') +import * as BN from 'bn.js' /** * Returns a buffer filled with 0s. diff --git a/src/constants.ts b/src/constants.ts index a0aa9b6917..160284f3d2 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,5 @@ -import BN = require('bn.js') const Buffer = require('buffer').Buffer +import * as BN from 'bn.js' /** * The max integer that this VM can handle diff --git a/src/externals.ts b/src/externals.ts new file mode 100644 index 0000000000..fba9626c2b --- /dev/null +++ b/src/externals.ts @@ -0,0 +1,31 @@ +/** + * Re-exports commonly used modules: + * * Adds [`ethjsUtil`](https://github.com/ethjs/ethjs-util) methods. + * * Exports [`BN`](https://github.com/indutny/bn.js), [`rlp`](https://github.com/ethereumjs/rlp), [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/)`. + * @packageDocumentation + */ + +const ethjsUtil = require('ethjs-util') +import * as secp256k1 from 'secp256k1' +import * as BN from 'bn.js' +import * as rlp from 'rlp' + +/** + * [`ethjsUtil`](https://github.com/ethjs/ethjs-util) + */ +Object.assign(exports, ethjsUtil) + +/** + * [`BN`](https://github.com/indutny/bn.js) + */ +export { BN } + +/** + * [`rlp`](https://github.com/ethereumjs/rlp) + */ +export { rlp } + +/** + * [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/) + */ +export { secp256k1 } diff --git a/src/hash.ts b/src/hash.ts index ea83790660..4faff40fbf 100644 --- a/src/hash.ts +++ b/src/hash.ts @@ -1,7 +1,7 @@ const createKeccakHash = require('keccak') const createHash = require('create-hash') const ethjsUtil = require('ethjs-util') -import rlp = require('rlp') +import * as rlp from 'rlp' import { toBuffer, setLength } from './bytes' /** diff --git a/src/index.ts b/src/index.ts index c44af02e88..73e913d3b2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,24 +1,3 @@ -const secp256k1 = require('secp256k1') -const ethjsUtil = require('ethjs-util') -import BN = require('bn.js') -import rlp = require('rlp') -Object.assign(exports, ethjsUtil) - -/** - * [`BN`](https://github.com/indutny/bn.js) - */ -export { BN } - -/** - * [`rlp`](https://github.com/ethereumjs/rlp) - */ -export { rlp } - -/** - * [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/) - */ -export { secp256k1 } - /** * Constants */ @@ -48,3 +27,8 @@ export * from './bytes' * Function for definining properties on an object */ export * from './object' + +/** + * External exports (ethjsUtil, BN, rlp, secp256k1) + */ +export * from './externals' diff --git a/src/object.ts b/src/object.ts index 24ca0cfba0..e6327e03af 100644 --- a/src/object.ts +++ b/src/object.ts @@ -1,6 +1,6 @@ -const assert = require('assert') const ethjsUtil = require('ethjs-util') -import rlp = require('rlp') +import * as assert from 'assert' +import * as rlp from 'rlp' import { toBuffer, baToJSON, stripZeros } from './bytes' /** diff --git a/src/signature.ts b/src/signature.ts index 0149b6baad..23e09e374d 100644 --- a/src/signature.ts +++ b/src/signature.ts @@ -1,5 +1,5 @@ -const secp256k1 = require('secp256k1') -import BN = require('bn.js') +import * as secp256k1 from 'secp256k1' +import * as BN from 'bn.js' import { toBuffer, setLength, setLengthLeft, bufferToHex } from './bytes' import { keccak } from './hash' diff --git a/test/externals.spec.ts b/test/externals.spec.ts new file mode 100644 index 0000000000..bb49ced699 --- /dev/null +++ b/test/externals.spec.ts @@ -0,0 +1,29 @@ +import assert = require('assert') + +import * as BN_export from 'bn.js' +import * as rlp_export from 'rlp' +import * as secp256k1_export from 'secp256k1' + +const ethjsUtil = require('ethjs-util') + +import * as src from '../src' + +describe('externals', function() { + it('should export `BN`', function() { + assert.equal(src.BN, BN_export) + }) + + it('should export `rlp`', function() { + assert.equal(src.rlp, rlp_export) + }) + + it('should export `scep256k1`', function() { + assert.equal(src.secp256k1, secp256k1_export) + }) + + it('should have `ethjs-util` methods', function() { + for (const property in ethjsUtil) { + assert.ok(src.hasOwnProperty(property)) + } + }) +}) diff --git a/typedoc.js b/typedoc.js new file mode 100644 index 0000000000..3bf7fa0304 --- /dev/null +++ b/typedoc.js @@ -0,0 +1,12 @@ +module.exports = { + inputFiles: ['src/*.ts'], + mode: 'library', + out: 'docs', + plugin: 'typedoc-plugin-markdown', + readme: 'none', + gitRevision: 'master', + exclude: '**/*+(index|.spec|.e2e).ts', + excludeNotExported: true, + // excludePrivate: true, + // excludeProtected: true, +}