ethereumjs-account
Advanced tools
Comparing version 2.0.5 to 3.0.0
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
(modification: no type change headlines) and this project adheres to | ||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
(modification: no type change headlines) and this project adheres to | ||
[Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
## [3.0.0] - 2019-01-14 | ||
First **TypeScript** based release of the library together with a switch to an `ES6` | ||
class structure of the `Account` class. `TypeScript` handles `ES6` transpilation | ||
[a bit differently](https://github.com/Microsoft/TypeScript/issues/2719) (at the | ||
end: cleaner) than `babel` so `require` syntax of the library slightly changes to: | ||
```javascript | ||
let Account = require('ethereumjs-account').default | ||
``` | ||
The library now also comes with a **type declaration file** distributed along with the package published. | ||
- Migration of code base and toolchain to `TypeScript`, PR [#27](https://github.com/ethereumjs/ethereumjs-account/pull/27) | ||
- Updated `ethereumjs-util` dependency to `v6.0.0` | ||
[3.0.0]: https://github.com/ethereumjs/ethereumjs-account/compare/v2.0.5...v3.0.0 | ||
## [2.0.5] - 2018-05-08 | ||
- Fixes a bug for contract code stored with level DB, PR [#5](https://github.com/ethereumjs/ethereumjs-account/pull/5) | ||
- Added ``safe-buffer`` dependency for backwards compatibility, PR [#14](https://github.com/ethereumjs/ethereumjs-account/pull/14) | ||
- Code examples in README for ``getCode``/``setCode`` and ``getStorage``/``setStorage``, PR [#19](https://github.com/ethereumjs/ethereumjs-account/pull/19) | ||
- Added `safe-buffer` dependency for backwards compatibility, PR [#14](https://github.com/ethereumjs/ethereumjs-account/pull/14) | ||
- Code examples in README for `getCode`/`setCode` and `getStorage`/`setStorage`, PR [#19](https://github.com/ethereumjs/ethereumjs-account/pull/19) | ||
- Added test coverage | ||
@@ -18,2 +38,3 @@ - Updated dependencies | ||
## [2.0.2] - 2016-03-01 | ||
- Update dependencies to install on windows | ||
@@ -24,9 +45,11 @@ | ||
## [2.0.1] - 2016-01-17 | ||
- Use ``SHA_*_S`` for faster comparison | ||
- Use `SHA_*_S` for faster comparison | ||
[2.0.1]: https://github.com/ethereumjs/ethereumjs-account/compare/v2.0.0...v2.0.1 | ||
## [2.0.0] - 2016-01-06 | ||
- Improved documentation | ||
- Simplified ``getCode()`` | ||
- Simplified `getCode()` | ||
- Added tests | ||
@@ -40,3 +63,1 @@ | ||
- 1.0.3 - 2015-09-24 | ||
{ | ||
"name": "ethereumjs-account", | ||
"version": "2.0.5", | ||
"version": "3.0.0", | ||
"description": "Encoding, decoding and validation of Ethereum's Account schema", | ||
"main": "index.js", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"repository": { | ||
@@ -11,6 +15,14 @@ "type": "git", | ||
"scripts": { | ||
"build": "tsc -p ./tsconfig.prod.json", | ||
"prepublishOnly": "npm run test && npm run build", | ||
"coverage": "nyc npm run test && nyc report --reporter=text-lcov > .nyc_output/lcov.info", | ||
"coveralls": "npm run coverage && coveralls <.nyc_output/lcov.info", | ||
"lint": "standard", | ||
"test": "tape ./test/index.js" | ||
"format": "prettier --list-different **/*.{ts,json,md}", | ||
"format:fix": "prettier --write **/*.{ts,json,md}", | ||
"tslint": "tslint -p ./tsconfig.json -e node_modules/**/* -e **/node_modules/**/* -e dist/**/* **/*.ts", | ||
"tslint:fix": "tslint --fix --format stylish -p ./tsconfig.json -e node_modules/**/* -e **/node_modules/**/* -e dist/**/* **/*.ts", | ||
"tsc": "tsc --noEmit", | ||
"lint": "npm run format && npm run tslint && npm run tsc", | ||
"lint:fix": "npm run format:fix && npm run tslint:fix && npm run tsc", | ||
"test": "ts-node node_modules/tape/bin/tape ./test/index.ts" | ||
}, | ||
@@ -28,12 +40,23 @@ "keywords": [ | ||
"dependencies": { | ||
"ethereumjs-util": "^5.0.0", | ||
"rlp": "^2.0.0", | ||
"ethereumjs-util": "^6.0.0", | ||
"rlp": "^2.2.1", | ||
"safe-buffer": "^5.1.1" | ||
}, | ||
"devDependencies": { | ||
"@ethereumjs/config-nyc": "^1.0.0", | ||
"@ethereumjs/config-prettier": "^1.0.1", | ||
"@ethereumjs/config-tsc": "^1.0.2", | ||
"@ethereumjs/config-tslint": "^1.0.0", | ||
"@types/bn.js": "^4.11.3", | ||
"@types/node": "^10.12.18", | ||
"@types/tape": "^4.2.33", | ||
"coveralls": "^3.0.0", | ||
"nyc": "^11.7.1", | ||
"standard": "^11.0.1", | ||
"tape": "^4.0.3" | ||
"prettier": "^1.15.3", | ||
"tape": "^4.0.3", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.12.0", | ||
"typescript": "^3.2.2", | ||
"typestrict": "^1.0.2" | ||
} | ||
} |
@@ -9,43 +9,49 @@ # SYNOPSIS | ||
This library eases the handling of Ethereum accounts, where accounts can be either external accounts | ||
or contracts (see | ||
This library eases the handling of Ethereum accounts, where accounts can be either external accounts | ||
or contracts (see | ||
[Account Types](http://ethdocs.org/en/latest/contracts-and-transactions/account-types-gas-and-transactions.html) docs). | ||
Note that the library is not meant to be used to handle your wallet accounts, use e.g. the | ||
[web3-eth-personal](http://web3js.readthedocs.io/en/1.0/web3-eth-personal.html) package from the | ||
``web3.js`` library for that. This is just a semantic wrapper to ease the use of account data and | ||
[web3-eth-personal](http://web3js.readthedocs.io/en/1.0/web3-eth-personal.html) package from the | ||
`web3.js` library for that. This is just a semantic wrapper to ease the use of account data and | ||
provide functionality for reading and writing accounts from and to the Ethereum state trie. | ||
# INSTALL | ||
`npm install ethereumjs-account` | ||
# BROWSER | ||
This module work with `browserify`. | ||
# API | ||
- [`new Account([data])`](#new-accountdata) | ||
- [`Account` Properties](#account-properties) | ||
- [`Account` Methods](#account-methods) | ||
- [`account.isEmpty()`](#accountisempty) | ||
- [`account.isContract()`](#accountiscontract) | ||
- [`account.serialize()`](#accountserialize) | ||
- [`account.toJSON()`](#accounttojson) | ||
- [`account.getCode(trie, cb)`](#accountgetcodetrie-cb) | ||
- [`account.setCode(trie, code, cb)`](#accountsetcodetrie-code-cb) | ||
- [`account.getStorage(trie, key, cb)`](#accountgetstoragetrie-key-cb) | ||
- [`account.setStorage(trie, key, val, cb)`](#accountsetstoragetrie-key-val-cb) | ||
- [`new Account([data])`](#new-accountdata) | ||
- [`Account` Properties](#account-properties) | ||
- [`Account` Methods](#account-methods) | ||
- [`account.isEmpty()`](#accountisempty) | ||
- [`account.isContract()`](#accountiscontract) | ||
- [`account.serialize()`](#accountserialize) | ||
- [`account.toJSON()`](#accounttojson) | ||
- [`account.getCode(trie, cb)`](#accountgetcodetrie-cb) | ||
- [`account.setCode(trie, code, cb)`](#accountsetcodetrie-code-cb) | ||
- [`account.getStorage(trie, key, cb)`](#accountgetstoragetrie-key-cb) | ||
- [`account.setStorage(trie, key, val, cb)`](#accountsetstoragetrie-key-val-cb) | ||
### `new Account([data])` | ||
Creates a new account object | ||
- `data` - an account can be initialized with either a `buffer` containing the RLP serialized account. | ||
Or an `Array` of buffers relating to each of the account Properties, listed in order below. For example: | ||
Or an `Array` of buffers relating to each of the account Properties, listed in order below. For example: | ||
```javascript | ||
var raw = [ | ||
var raw = [ | ||
'0x02', //nonce | ||
'0x0384', //balance | ||
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', //stateRoot | ||
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' //codeHash | ||
]; | ||
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', //codeHash | ||
] | ||
var account = new Account(raw); | ||
var account = new Account(raw) | ||
``` | ||
@@ -60,12 +66,14 @@ | ||
stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', | ||
codeHash: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' | ||
}; | ||
codeHash: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', | ||
} | ||
var account = new Account(raw); | ||
var account = new Account(raw) | ||
``` | ||
For `Object` and `Array` each of the elements can either be a `Buffer`, hex `String`, `Number`, or an object with a `toBuffer` method such as `Bignum`. | ||
### `Account` Properties | ||
- `nonce` - The account's nonce. | ||
- `balance` - The account's balance in wei. | ||
- `balance` - The account's balance in wei. | ||
- `stateRoot` - The stateRoot for the storage of the contract. | ||
@@ -77,16 +85,23 @@ - `codeHash` - The hash of the code of the contract. | ||
#### `account.isEmpty()` | ||
Returns a `Boolean` determining if the account is empty. | ||
#### `account.isContract()` | ||
Returns a `Boolean` deteremining if the account is a contract. | ||
#### `account.serialize()` | ||
Returns the RLP serialization of the account as a `Buffer`. | ||
#### `account.toJSON([object])` | ||
Returns the account as JSON. | ||
- `object` - A `Boolean` that defaults to false. If `object` is true then this will return an `Object`, else it will return an `Array`. | ||
#### `account.getCode(trie, cb)` | ||
Fetches the code from the trie. | ||
- `trie` - The [trie](https://github.com/ethereumjs/merkle-patricia-tree) storing the accounts. | ||
@@ -96,3 +111,5 @@ - `cb` - The callback. | ||
#### `account.setCode(trie, code, cb)` | ||
Stores the code in the trie. | ||
- `trie` - The [trie](https://github.com/ethereumjs/merkle-patricia-tree) storing the accounts. | ||
@@ -102,9 +119,13 @@ - `code` - A `Buffer`. | ||
Example for ``getCode`` and ``setCode``: | ||
Example for `getCode` and `setCode`: | ||
```javascript | ||
// Requires manual merkle-patricia-tree install | ||
const SecureTrie = require('merkle-patricia-tree/secure') | ||
const Account = require('./index.js') | ||
const Account = require('./index.js').default | ||
let code = Buffer.from('73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873157', 'hex') | ||
let code = Buffer.from( | ||
'73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873157', | ||
'hex', | ||
) | ||
@@ -115,3 +136,3 @@ let raw = { | ||
stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', | ||
codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4' | ||
codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4', | ||
} | ||
@@ -122,5 +143,5 @@ | ||
account.setCode(trie, code, function (err, codeHash) { | ||
account.setCode(trie, code, function(err, codeHash) { | ||
console.log(`Code with hash 0x${codeHash.toString('hex')} set to trie`) | ||
account.getCode(trie, function (err, code) { | ||
account.getCode(trie, function(err, code) { | ||
console.log(`Code ${code.toString('hex')} read from trie`) | ||
@@ -132,8 +153,10 @@ }) | ||
#### `account.getStorage(trie, key, cb)` | ||
Fetches `key` from the account's storage. | ||
#### `account.setStorage(trie, key, val, cb)` | ||
Stores a `val` at the `key` in the contract's storage. | ||
Example for ``getStorage`` and ``setStorage``: | ||
Example for `getStorage` and `setStorage`: | ||
@@ -143,3 +166,3 @@ ```javascript | ||
const SecureTrie = require('merkle-patricia-tree/secure') | ||
const Account = require('./index.js') | ||
const Account = require('./index.js').default | ||
@@ -150,3 +173,3 @@ let raw = { | ||
stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', | ||
codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4' | ||
codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4', | ||
} | ||
@@ -160,4 +183,4 @@ | ||
account.setStorage(trie, key, value, function (err, value) { | ||
account.getStorage(trie, key, function (err, value) { | ||
account.setStorage(trie, key, value, function(err, value) { | ||
account.getStorage(trie, key, function(err, value) { | ||
console.log(`Value ${value.toString('hex')} set and retrieved from trie.`) | ||
@@ -164,0 +187,0 @@ }) |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
16383
179
15
108
1
+ Added@types/bn.js@4.11.6(transitive)
+ Addedethereumjs-util@6.2.1(transitive)
- Removedethereumjs-util@5.2.1(transitive)
Updatedethereumjs-util@^6.0.0
Updatedrlp@^2.2.1