Socket
Socket
Sign inDemoInstall

ethereumjs-account

Package Overview
Dependencies
44
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.4 to 2.0.5

CHANGELOG.md

9

index.js
const ethUtil = require('ethereumjs-util')
const rlp = require('rlp')
const Buffer = require('safe-buffer').Buffer

@@ -8,6 +9,6 @@ var Account = module.exports = function (data) {

name: 'nonce',
default: new Buffer([])
default: Buffer.alloc(0)
}, {
name: 'balance',
default: new Buffer([])
default: Buffer.alloc(0)
}, {

@@ -36,3 +37,3 @@ name: 'stateRoot',

if (!this.isContract()) {
cb(null, new Buffer([]))
cb(null, Buffer.alloc(0))
return

@@ -50,3 +51,3 @@ }

if (this.codeHash.toString('hex') === ethUtil.SHA3_NULL_S) {
cb(null, new Buffer([]))
cb(null, Buffer.alloc(0))
return

@@ -53,0 +54,0 @@ }

{
"name": "ethereumjs-account",
"version": "2.0.4",
"version": "2.0.5",
"description": "Encoding, decoding and validation of Ethereum's Account schema",

@@ -11,4 +11,4 @@ "main": "index.js",

"scripts": {
"coverage": "istanbul cover ./test/index.js",
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
"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",

@@ -28,11 +28,12 @@ "test": "tape ./test/index.js"

"dependencies": {
"ethereumjs-util": "^4.0.1",
"rlp": "^2.0.0"
"ethereumjs-util": "^5.0.0",
"rlp": "^2.0.0",
"safe-buffer": "^5.1.1"
},
"devDependencies": {
"coveralls": "^2.11.4",
"istanbul": "^0.4.1",
"standard": "^5.4.1",
"coveralls": "^3.0.0",
"nyc": "^11.7.1",
"standard": "^11.0.1",
"tape": "^4.0.3"
}
}
# SYNOPSIS
[![NPM Package](https://img.shields.io/npm/v/ethereumjs-account.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-account)
[![Build Status](https://img.shields.io/travis/ethereumjs/ethereumjs-account.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereumjs/ethereumjs-account)
[![Build Status](https://travis-ci.org/ethereumjs/ethereumjs-account.svg?branch=master)](https://travis-ci.org/ethereumjs/ethereumjs-account)
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-account.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-account)
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ethereum/ethereumjs-lib?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) or #ethereumjs on freenode
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).
Implements schema and functions relating to accounts stored ethereum's state Trie
NOTE: this is different from [ethereumjs-accounts](https://github.com/SilentCicero/ethereumjs-accounts) which should be used if you want to key management and web3 sugar.
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
provide functionality for reading and writing accounts from and to the Ethereum state trie.

@@ -17,3 +22,3 @@ # INSTALL

# BROWSER
This module work with `browserify`
This module work with `browserify`.

@@ -94,2 +99,28 @@ # API

Example for ``getCode`` and ``setCode``:
```javascript
// Requires manual merkle-patricia-tree install
const SecureTrie = require('merkle-patricia-tree/secure')
const Account = require('./index.js')
let code = Buffer.from('73095e7baea6a6c7c4c2dfeb977efac326af552d873173095e7baea6a6c7c4c2dfeb977efac326af552d873157', 'hex')
let raw = {
nonce: '',
balance: '0x03e7',
stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4'
}
let account = new Account(raw)
let trie = new SecureTrie()
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) {
console.log(`Code ${code.toString('hex')} read from trie`)
})
})
```
#### `account.getStorage(trie, key, cb)`

@@ -100,1 +131,28 @@ Fetches `key` from the account's storage.

Stores a `val` at the `key` in the contract's storage.
Example for ``getStorage`` and ``setStorage``:
```javascript
// Requires manual merkle-patricia-tree install
const SecureTrie = require('merkle-patricia-tree/secure')
const Account = require('./index.js')
let raw = {
nonce: '',
balance: '0x03e7',
stateRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
codeHash: '0xb30fb32201fe0486606ad451e1a61e2ae1748343cd3d411ed992ffcc0774edd4'
}
let account = new Account(raw)
let trie = new SecureTrie()
let key = Buffer.from('0000000000000000000000000000000000000000', 'hex')
let value = Buffer.from('01', 'hex')
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.`)
})
})
```

@@ -23,3 +23,3 @@ const Account = require('../index.js')

'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', // stateRoot
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' // codeHash
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' // codeHash
]

@@ -26,0 +26,0 @@ var account = new Account(raw)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc