@ethereumjs/util
Advanced tools
Comparing version 8.0.0-beta.3 to 8.0.0-rc.1
/// <reference types="node" /> | ||
import { BigIntLike, BufferLike } from './types'; | ||
import type { BigIntLike, BufferLike } from './types'; | ||
export interface AccountData { | ||
nonce?: BigIntLike; | ||
balance?: BigIntLike; | ||
stateRoot?: BufferLike; | ||
storageRoot?: BufferLike; | ||
codeHash?: BufferLike; | ||
@@ -12,3 +12,3 @@ } | ||
balance: bigint; | ||
stateRoot: Buffer; | ||
storageRoot: Buffer; | ||
codeHash: Buffer; | ||
@@ -22,3 +22,3 @@ static fromAccountData(accountData: AccountData): Account; | ||
*/ | ||
constructor(nonce?: bigint, balance?: bigint, stateRoot?: Buffer, codeHash?: Buffer); | ||
constructor(nonce?: bigint, balance?: bigint, storageRoot?: Buffer, codeHash?: Buffer); | ||
private _validate; | ||
@@ -121,2 +121,6 @@ /** | ||
export declare const isZeroAddress: (hexAddress: string) => boolean; | ||
/** | ||
* Converts a slim account RLP to a normal account RLP | ||
*/ | ||
export declare function convertSlimAccount(body: any): Buffer; | ||
//# sourceMappingURL=account.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isZeroAddress = exports.zeroAddress = exports.importPublic = exports.privateToAddress = exports.privateToPublic = exports.publicToAddress = exports.pubToAddress = exports.isValidPublic = exports.isValidPrivate = exports.generateAddress2 = exports.generateAddress = exports.isValidChecksumAddress = exports.toChecksumAddress = exports.isValidAddress = exports.Account = void 0; | ||
exports.convertSlimAccount = exports.isZeroAddress = exports.zeroAddress = exports.importPublic = exports.privateToAddress = exports.privateToPublic = exports.publicToAddress = exports.pubToAddress = exports.isValidPublic = exports.isValidPrivate = exports.generateAddress2 = exports.generateAddress = exports.isValidChecksumAddress = exports.toChecksumAddress = exports.isValidAddress = exports.Account = void 0; | ||
const rlp_1 = require("@ethereumjs/rlp"); | ||
@@ -19,6 +19,6 @@ const keccak_1 = require("ethereum-cryptography/keccak"); | ||
*/ | ||
constructor(nonce = _0n, balance = _0n, stateRoot = constants_1.KECCAK256_RLP, codeHash = constants_1.KECCAK256_NULL) { | ||
constructor(nonce = _0n, balance = _0n, storageRoot = constants_1.KECCAK256_RLP, codeHash = constants_1.KECCAK256_NULL) { | ||
this.nonce = nonce; | ||
this.balance = balance; | ||
this.stateRoot = stateRoot; | ||
this.storageRoot = storageRoot; | ||
this.codeHash = codeHash; | ||
@@ -28,4 +28,4 @@ this._validate(); | ||
static fromAccountData(accountData) { | ||
const { nonce, balance, stateRoot, codeHash } = accountData; | ||
return new Account((0, types_1.isTruthy)(nonce) ? (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(nonce)) : undefined, (0, types_1.isTruthy)(balance) ? (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(balance)) : undefined, (0, types_1.isTruthy)(stateRoot) ? (0, bytes_1.toBuffer)(stateRoot) : undefined, (0, types_1.isTruthy)(codeHash) ? (0, bytes_1.toBuffer)(codeHash) : undefined); | ||
const { nonce, balance, storageRoot, codeHash } = accountData; | ||
return new Account((0, types_1.isTruthy)(nonce) ? (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(nonce)) : undefined, (0, types_1.isTruthy)(balance) ? (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(balance)) : undefined, (0, types_1.isTruthy)(storageRoot) ? (0, bytes_1.toBuffer)(storageRoot) : undefined, (0, types_1.isTruthy)(codeHash) ? (0, bytes_1.toBuffer)(codeHash) : undefined); | ||
} | ||
@@ -40,4 +40,4 @@ static fromRlpSerializedAccount(serialized) { | ||
static fromValuesArray(values) { | ||
const [nonce, balance, stateRoot, codeHash] = values; | ||
return new Account((0, bytes_1.bufferToBigInt)(nonce), (0, bytes_1.bufferToBigInt)(balance), stateRoot, codeHash); | ||
const [nonce, balance, storageRoot, codeHash] = values; | ||
return new Account((0, bytes_1.bufferToBigInt)(nonce), (0, bytes_1.bufferToBigInt)(balance), storageRoot, codeHash); | ||
} | ||
@@ -51,4 +51,4 @@ _validate() { | ||
} | ||
if (this.stateRoot.length !== 32) { | ||
throw new Error('stateRoot must have a length of 32'); | ||
if (this.storageRoot.length !== 32) { | ||
throw new Error('storageRoot must have a length of 32'); | ||
} | ||
@@ -66,3 +66,3 @@ if (this.codeHash.length !== 32) { | ||
(0, bytes_1.bigIntToUnpaddedBuffer)(this.balance), | ||
this.stateRoot, | ||
this.storageRoot, | ||
this.codeHash, | ||
@@ -295,2 +295,18 @@ ]; | ||
exports.isZeroAddress = isZeroAddress; | ||
/** | ||
* Converts a slim account RLP to a normal account RLP | ||
*/ | ||
function convertSlimAccount(body) { | ||
const cpy = [body[0], body[1], body[2], body[3]]; | ||
if ((0, bytes_1.arrToBufArr)(body[2]).length === 0) { | ||
// StorageRoot | ||
cpy[2] = constants_1.KECCAK256_RLP; | ||
} | ||
if ((0, bytes_1.arrToBufArr)(body[3]).length === 0) { | ||
// CodeHash | ||
cpy[3] = constants_1.KECCAK256_NULL; | ||
} | ||
return (0, bytes_1.arrToBufArr)(rlp_1.RLP.encode(cpy)); | ||
} | ||
exports.convertSlimAccount = convertSlimAccount; | ||
//# sourceMappingURL=account.js.map |
/// <reference types="node" /> | ||
import { NestedBufferArray, NestedUint8Array, PrefixedHexString, TransformableToArray, TransformableToBuffer } from './types'; | ||
import type { NestedBufferArray, NestedUint8Array, PrefixedHexString, TransformableToArray, TransformableToBuffer } from './types'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Converts a `Number` into a hex `String` |
@@ -16,3 +16,3 @@ /// <reference types="node" /> | ||
* ECDSA public key recovery from signature. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Recovered public key | ||
@@ -23,3 +23,3 @@ */ | ||
* Convert signature parameters into the format of `eth_sign` RPC method. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Signature | ||
@@ -30,3 +30,3 @@ */ | ||
* Convert signature parameters into the format of Compact Signature Representation (EIP-2098). | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Signature | ||
@@ -46,3 +46,3 @@ */ | ||
* Validate a ECDSA signature. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one | ||
@@ -49,0 +49,0 @@ */ |
@@ -38,3 +38,3 @@ "use strict"; | ||
* ECDSA public key recovery from signature. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Recovered public key | ||
@@ -54,3 +54,3 @@ */ | ||
* Convert signature parameters into the format of `eth_sign` RPC method. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Signature | ||
@@ -69,3 +69,3 @@ */ | ||
* Convert signature parameters into the format of Compact Signature Representation (EIP-2098). | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Signature | ||
@@ -127,3 +127,3 @@ */ | ||
* Validate a ECDSA signature. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one | ||
@@ -130,0 +130,0 @@ */ |
/// <reference types="node" /> | ||
import { Address } from './address'; | ||
import { ToBufferInputTypes } from './bytes'; | ||
import type { Address } from './address'; | ||
import type { ToBufferInputTypes } from './bytes'; | ||
export declare type BigIntLike = bigint | PrefixedHexString | number | Buffer; | ||
@@ -5,0 +5,0 @@ export declare type BufferLike = Buffer | Uint8Array | number[] | number | bigint | TransformableToBuffer | PrefixedHexString; |
{ | ||
"name": "@ethereumjs/util", | ||
"version": "8.0.0-beta.3", | ||
"version": "8.0.0-rc.1", | ||
"description": "A collection of utility functions for Ethereum", | ||
@@ -91,19 +91,7 @@ "keywords": [ | ||
"@types/bn.js": "^5.1.0", | ||
"@types/node": "^16.11.7", | ||
"@types/secp256k1": "^4.0.1", | ||
"@types/tape": "^4.13.2", | ||
"eslint": "^6.8.0", | ||
"karma": "^6.3.2", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-firefox-launcher": "^2.1.0", | ||
"karma-tap": "^4.2.0", | ||
"karma-typescript": "^5.5.3", | ||
"nyc": "^15.1.0", | ||
"tape": "^4.10.1", | ||
"ts-node": "^10.2.1", | ||
"typescript": "^4.4.2" | ||
"@types/secp256k1": "^4.0.1" | ||
}, | ||
"engines": { | ||
"node": ">=10.0.0" | ||
"node": ">=14" | ||
} | ||
} |
@@ -11,8 +11,12 @@ # @ethereumjs/util | ||
# INSTALL | ||
## Installation | ||
`npm install @ethereumjs/util` | ||
To obtain the latest version, simply require the project using `npm`: | ||
# USAGE | ||
```shell | ||
npm install @ethereumjs/util | ||
``` | ||
## Usage | ||
```js | ||
@@ -27,5 +31,5 @@ import assert from 'assert' | ||
# API | ||
## API | ||
## Documentation | ||
### Documentation | ||
@@ -79,16 +83,14 @@ Read the [API docs](docs/). | ||
```js | ||
```typescript | ||
import { stripHexPrefix } from '@ethereumjs/util' | ||
``` | ||
# EthereumJS | ||
## EthereumJS | ||
See our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices. | ||
See our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices. If you want to join for work or carry out improvements on the libraries, please review our [contribution guidelines](https://ethereumjs.readthedocs.io/en/latest/contributing.html) first. | ||
If you want to join for work or do improvements on the libraries have a look at our [contribution guidelines](https://ethereumjs.readthedocs.io/en/latest/contributing.html). | ||
## License | ||
# LICENSE | ||
[MPL-2.0](<https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)>) | ||
MPL-2.0 | ||
[util-npm-badge]: https://img.shields.io/npm/v/@ethereumjs/util.svg | ||
@@ -95,0 +97,0 @@ [util-npm-link]: https://www.npmjs.org/package/@ethereumjs/util |
@@ -18,4 +18,6 @@ import { RLP } from '@ethereumjs/rlp' | ||
import { stripHexPrefix } from './internal' | ||
import { BigIntLike, BufferLike, isTruthy } from './types' | ||
import { isTruthy } from './types' | ||
import type { BigIntLike, BufferLike } from './types' | ||
const _0n = BigInt(0) | ||
@@ -26,3 +28,3 @@ | ||
balance?: BigIntLike | ||
stateRoot?: BufferLike | ||
storageRoot?: BufferLike | ||
codeHash?: BufferLike | ||
@@ -34,7 +36,7 @@ } | ||
balance: bigint | ||
stateRoot: Buffer | ||
storageRoot: Buffer | ||
codeHash: Buffer | ||
static fromAccountData(accountData: AccountData) { | ||
const { nonce, balance, stateRoot, codeHash } = accountData | ||
const { nonce, balance, storageRoot, codeHash } = accountData | ||
@@ -44,3 +46,3 @@ return new Account( | ||
isTruthy(balance) ? bufferToBigInt(toBuffer(balance)) : undefined, | ||
isTruthy(stateRoot) ? toBuffer(stateRoot) : undefined, | ||
isTruthy(storageRoot) ? toBuffer(storageRoot) : undefined, | ||
isTruthy(codeHash) ? toBuffer(codeHash) : undefined | ||
@@ -61,5 +63,5 @@ ) | ||
public static fromValuesArray(values: Buffer[]) { | ||
const [nonce, balance, stateRoot, codeHash] = values | ||
const [nonce, balance, storageRoot, codeHash] = values | ||
return new Account(bufferToBigInt(nonce), bufferToBigInt(balance), stateRoot, codeHash) | ||
return new Account(bufferToBigInt(nonce), bufferToBigInt(balance), storageRoot, codeHash) | ||
} | ||
@@ -71,6 +73,6 @@ | ||
*/ | ||
constructor(nonce = _0n, balance = _0n, stateRoot = KECCAK256_RLP, codeHash = KECCAK256_NULL) { | ||
constructor(nonce = _0n, balance = _0n, storageRoot = KECCAK256_RLP, codeHash = KECCAK256_NULL) { | ||
this.nonce = nonce | ||
this.balance = balance | ||
this.stateRoot = stateRoot | ||
this.storageRoot = storageRoot | ||
this.codeHash = codeHash | ||
@@ -88,4 +90,4 @@ | ||
} | ||
if (this.stateRoot.length !== 32) { | ||
throw new Error('stateRoot must have a length of 32') | ||
if (this.storageRoot.length !== 32) { | ||
throw new Error('storageRoot must have a length of 32') | ||
} | ||
@@ -104,3 +106,3 @@ if (this.codeHash.length !== 32) { | ||
bigIntToUnpaddedBuffer(this.balance), | ||
this.stateRoot, | ||
this.storageRoot, | ||
this.codeHash, | ||
@@ -351,1 +353,17 @@ ] | ||
} | ||
/** | ||
* Converts a slim account RLP to a normal account RLP | ||
*/ | ||
export function convertSlimAccount(body: any) { | ||
const cpy = [body[0], body[1], body[2], body[3]] | ||
if (arrToBufArr(body[2]).length === 0) { | ||
// StorageRoot | ||
cpy[2] = KECCAK256_RLP | ||
} | ||
if (arrToBufArr(body[3]).length === 0) { | ||
// CodeHash | ||
cpy[3] = KECCAK256_NULL | ||
} | ||
return arrToBufArr(RLP.encode(cpy)) | ||
} |
import { assertIsArray, assertIsBuffer, assertIsHexString } from './helpers' | ||
import { isHexPrefixed, isHexString, padToEven, stripHexPrefix } from './internal' | ||
import { | ||
import type { | ||
NestedBufferArray, | ||
@@ -5,0 +6,0 @@ NestedUint8Array, |
@@ -49,3 +49,3 @@ import { keccak256 } from 'ethereum-cryptography/keccak' | ||
* ECDSA public key recovery from signature. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Recovered public key | ||
@@ -72,3 +72,3 @@ */ | ||
* Convert signature parameters into the format of `eth_sign` RPC method. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Signature | ||
@@ -88,3 +88,3 @@ */ | ||
* Convert signature parameters into the format of Compact Signature Representation (EIP-2098). | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @returns Signature | ||
@@ -149,3 +149,3 @@ */ | ||
* Validate a ECDSA signature. | ||
* NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions | ||
* NOTE: Accepts `v === 0 | v === 1` for EIP1559 transactions | ||
* @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one | ||
@@ -152,0 +152,0 @@ */ |
@@ -1,5 +0,7 @@ | ||
import { Address } from './address' | ||
import { bufferToBigInt, bufferToHex, toBuffer, ToBufferInputTypes } from './bytes' | ||
import { bufferToBigInt, bufferToHex, toBuffer } from './bytes' | ||
import { isHexString } from './internal' | ||
import type { Address } from './address' | ||
import type { ToBufferInputTypes } from './bytes' | ||
/* | ||
@@ -6,0 +8,0 @@ * A type that represents an input that can be converted to a BigInt. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179133
2
3372
103