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..32867b8bce 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,928 +1,15 @@ +[ethereumjs-util](README.md) -# ethereumjs-util +# ethereumjs-util ## Index -### Interfaces - -* [ECDSASignature](interfaces/ecdsasignature.md) - -### 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) - -### 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) - ---- - -## Variables - - - -### `` KECCAK256_NULL - -**● KECCAK256_NULL**: *`Buffer`* = Buffer.from(KECCAK256_NULL_S, 'hex') - -*Defined in [constants.ts:28](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L28)* - -Keccak-256 hash of null - -___ - - -### `` KECCAK256_NULL_S - -**● KECCAK256_NULL_S**: *`string`* = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" - -*Defined in [constants.ts:22](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L22)* - -Keccak-256 hash of null - -___ - - -### `` KECCAK256_RLP - -**● KECCAK256_RLP**: *`Buffer`* = Buffer.from(KECCAK256_RLP_S, 'hex') - -*Defined in [constants.ts:50](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L50)* - -Keccak-256 hash of the RLP of null - -___ - - -### `` KECCAK256_RLP_ARRAY - -**● KECCAK256_RLP_ARRAY**: *`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)* - -Keccak-256 of an RLP of an empty array - -___ - - -### `` KECCAK256_RLP_ARRAY_S - -**● KECCAK256_RLP_ARRAY_S**: *`string`* = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" - -*Defined in [constants.ts:33](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L33)* - -Keccak-256 of an RLP of an empty array - -___ - - -### `` KECCAK256_RLP_S - -**● KECCAK256_RLP_S**: *`string`* = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" - -*Defined in [constants.ts:44](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L44)* - -Keccak-256 hash of the RLP of null - -___ - - -### `` MAX_INTEGER - -**● MAX_INTEGER**: *`BN`* = new BN( - 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', - 16, -) - -*Defined in [constants.ts:6](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L6)* - -The max integer that this VM can handle - -___ - - -### `` TWO_POW256 - -**● TWO_POW256**: *`BN`* = new BN( - '10000000000000000000000000000000000000000000000000000000000000000', - 16, -) - -*Defined in [constants.ts:14](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/constants.ts#L14)* - -2^256 - -___ - - -### `` publicToAddress - -**● publicToAddress**: *[pubToAddress]()* = pubToAddress - -*Defined in [account.ts:163](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L163)* - -___ - - -### `` setLength - -**● setLength**: *[setLengthLeft]()* = setLengthLeft - -*Defined in [bytes.ts:37](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L37)* - -___ - - -### `` stripZeros - -**● stripZeros**: *[unpad]()* = unpad - -*Defined in [bytes.ts:64](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/bytes.ts#L64)* - -___ - -## Functions - - - -### `` 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` - -___ - - -### `` 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) - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` | -| `Optional` chainId | `undefined` \| `number` | - -**Returns:** `Buffer` -Recovered public key - -___ - - -### `` ecsign - -▸ **ecsign**(msgHash: *`Buffer`*, privateKey: *`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` | -| privateKey | `Buffer` | -| `Optional` chainId | `undefined` \| `number` | - -**Returns:** [ECDSASignature](interfaces/ecdsasignature.md) - -___ - - -### `` 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](https://github.com/ethereum/go-ethereum/issues/2053) - -**Parameters:** - -| Name | Type | -| ------ | ------ | -| sig | `string` | - -**Returns:** [ECDSASignature](interfaces/ecdsasignature.md) - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` | -| `Optional` eip1191ChainId | `undefined` \| `number` | - -**Returns:** `boolean` - -___ - - -### `` 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` - -___ - - -### `` 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 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 | - -**Returns:** `boolean` - -___ - - -### `` 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 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` | - | - -**Returns:** `boolean` - -___ - - -### `` 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` - -___ - - -### `` 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 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 | - -**Returns:** `Buffer` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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 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 | - -**Returns:** `Buffer` - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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 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 | - -**Returns:** `any` -(Buffer\|Array) - -___ - - -### `` 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) - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ - - -### `` 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` | -| `Optional` eip1191ChainId | `undefined` \| `number` | - -**Returns:** `string` - -___ - - -### `` 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` | -| `Optional` chainId | `undefined` \| `number` | - -**Returns:** `string` -Signature - -___ - - -### `` 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` - -___ - - -### `` 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) - -___ - - -### `` 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` - -___ - - -### `` 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` - -___ +### 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 58% rename from docs/interfaces/ecdsasignature.md rename to docs/interfaces/_signature_.ecdsasignature.md index f2e32785ec..428fbc167a 100644 --- a/docs/interfaces/ecdsasignature.md +++ b/docs/interfaces/_signature_.ecdsasignature.md @@ -1,48 +1,39 @@ -[ethereumjs-util](../README.md) > [ECDSASignature](../interfaces/ecdsasignature.md) +[ethereumjs-util](../README.md) › ["signature"](../modules/_signature_.md) › [ECDSASignature](_signature_.ecdsasignature.md) # Interface: ECDSASignature ## Hierarchy -**ECDSASignature** +* **ECDSASignature** ## Index ### 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`* +• **r**: *Buffer* *Defined in [signature.ts:8](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/signature.ts#L8)* ___ - ### s -**● s**: *`Buffer`* +• **s**: *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/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 b280c8a089..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": "typedoc --out docs --mode file --readme none --theme markdown --mdEngine github --gitRevision master --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,8 +113,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": "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, +}