Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript rewrite #93

Merged
merged 7 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .babelrc

This file was deleted.

14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand All @@ -34,9 +35,10 @@ package-lock.json
# Optional REPL history
.node_repl_history

# Build folder
# Update 2018-08-07: currently build is done to / (before: dist/) due to
# backwards compatibility reasons, JS files from root and root test/ folder
# are excluded
/*.js
/test

# IDE and text editor config files
.idea
.vscode

# build output
dist
3 changes: 3 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@ethereumjs/config-nyc"
}
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.vscode
package.json
dist
.nyc_output
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ node_js:
- "6"
- "8"
- "10"
env:
- CXX=g++-4.8
addons:
apt:
sources:
Expand Down
27 changes: 17 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# 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).


## [0.6.3] - 2018-12-19

- Fixed installation errors for certain packaging tools, PR [#67](https://github.com/ethereumjs/ethereumjs-wallet/pull/67)
- Remove dependency on ``crypto.randomBytes`` and use ``randombytes`` package instead, PR [#63](https://github.com/ethereumjs/ethereumjs-wallet/pull/63)
- Add comprehensive test coverage for ``fromV3``, PR [#62](https://github.com/ethereumjs/ethereumjs-wallet/pull/62)
- Remove excess parameter from ``decipherBuffer`` usage, PR [#77](https://github.com/ethereumjs/ethereumjs-wallet/pull/77)
- Update dependencies, including a fixed ``scrypt.js``, which should resolve more installation issues, PR [#78](https://github.com/ethereumjs/ethereumjs-wallet/pull/78)
- Remove dependency on `crypto.randomBytes` and use `randombytes` package instead, PR [#63](https://github.com/ethereumjs/ethereumjs-wallet/pull/63)
- Add comprehensive test coverage for `fromV3`, PR [#62](https://github.com/ethereumjs/ethereumjs-wallet/pull/62)
- Remove excess parameter from `decipherBuffer` usage, PR [#77](https://github.com/ethereumjs/ethereumjs-wallet/pull/77)
- Update dependencies, including a fixed `scrypt.js`, which should resolve more installation issues, PR [#78](https://github.com/ethereumjs/ethereumjs-wallet/pull/78)

[0.6.3]: https://github.com/ethereumjs/ethereumjs-wallet/compare/v0.6.2...v0.6.3

## [0.6.2] - 2018-08-08
- [PLEASE UPDATE!] Fixes a critical import bug introduced in ``v0.6.1`` accidentally

- [PLEASE UPDATE!] Fixes a critical import bug introduced in `v0.6.1` accidentally
changing the import path for the different submodules, see PR [#65](https://github.com/ethereumjs/ethereumjs-wallet/pull/65)

[0.6.2]: https://github.com/ethereumjs/ethereumjs-wallet/compare/v0.6.1...v0.6.2

## [0.6.1] - 2018-07-28 [DEPRECATED]

- Added support for vanity address generation, PR [#5](https://github.com/ethereumjs/ethereumjs-wallet/pull/5)
- Fixed typo in provider-engine, PR [#16](https://github.com/ethereumjs/ethereumjs-wallet/pull/16)
- Accept the true range of addresses for ICAP direct, PR [#6](https://github.com/ethereumjs/ethereumjs-wallet/pull/6)
Expand All @@ -32,24 +35,28 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
[0.6.1]: https://github.com/ethereumjs/ethereumjs-wallet/compare/v0.6.0...v0.6.1

## [0.6.0] - 2016-04-27

- Added provider-engine integration, PR [#7](https://github.com/ethereumjs/ethereumjs-wallet/pull/7)

[0.6.0]: https://github.com/ethereumjs/ethereumjs-wallet/compare/v0.5.2...v0.6.0

## [0.5.2] - 2016-04-25

- Dependency updates

[0.5.2]: https://github.com/ethereumjs/ethereumjs-wallet/compare/v0.5.1...v0.5.2

## [0.5.1] - 2016-03-26
- Bugfix for ``EthereumHDKey.privateExtendedKey()``

- Bugfix for `EthereumHDKey.privateExtendedKey()`
- Added travis and coveralls support
- Documentation and test improvements

[0.5.1]: https://github.com/ethereumjs/ethereumjs-wallet/compare/v0.5.0...v0.5.1

## [0.5.0] - 2016-03-23
- Support HD keys using ``cryptocoinjs/hdkey``

- Support HD keys using `cryptocoinjs/hdkey`
- Ensure private keys are valid according to the curve
- Support instantation with public keys
- Support importing BIP32 xpub/xpriv
Expand Down
61 changes: 34 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,50 @@
A lightweight wallet implementation. At the moment it supports key creation and conversion between various formats.

It is complemented by the following packages:

- [ethereumjs-tx](https://github.com/ethereumjs/ethereumjs-tx) to sign transactions
- [ethereumjs-icap](https://github.com/ethereumjs/ethereumjs-icap) to manipulate ICAP addresses
- [store.js](https://github.com/marcuswestin/store.js) to use browser storage

Motivations are:

- be lightweight
- work in a browser
- use a single, maintained version of crypto library (and that should be in line with `ethereumjs-util` and `ethereumjs-tx`)
- support import/export between various wallet formats
- support BIP32 HD keys

Features not supported:

- signing transactions
- managing storage (neither in node.js or the browser)

## Wallet API

Constructors:

* `generate([icap])` - create an instance based on a new random key (setting `icap` to true will generate an address suitable for the `ICAP Direct mode`)
* `generateVanityAddress(pattern)` - create an instance where the address is valid against the supplied pattern (**this will be very slow**)
* `fromPrivateKey(input)` - create an instance based on a raw private key
* `fromExtendedPrivateKey(input)` - create an instance based on a BIP32 extended private key (xprv)
* `fromPublicKey(input, [nonStrict])` - create an instance based on a public key (certain methods will not be available)
* `fromExtendedPublicKey(input)` - create an instance based on a BIP32 extended public key (xpub)
* `fromV1(input, password)` - import a wallet (Version 1 of the Ethereum wallet format)
* `fromV3(input, password, [nonStrict])` - import a wallet (Version 3 of the Ethereum wallet format). Set `nonStrict` true to accept files with mixed-caps.
* `fromEthSale(input, password)` - import an Ethereum Pre Sale wallet
- `generate([icap])` - create an instance based on a new random key (setting `icap` to true will generate an address suitable for the `ICAP Direct mode`)
- `generateVanityAddress(pattern)` - create an instance where the address is valid against the supplied pattern (**this will be very slow**)
- `fromPrivateKey(input)` - create an instance based on a raw private key
- `fromExtendedPrivateKey(input)` - create an instance based on a BIP32 extended private key (xprv)
- `fromPublicKey(input, [nonStrict])` - create an instance based on a public key (certain methods will not be available)
- `fromExtendedPublicKey(input)` - create an instance based on a BIP32 extended public key (xpub)
- `fromV1(input, password)` - import a wallet (Version 1 of the Ethereum wallet format)
- `fromV3(input, password, [nonStrict])` - import a wallet (Version 3 of the Ethereum wallet format). Set `nonStrict` true to accept files with mixed-caps.
- `fromEthSale(input, password)` - import an Ethereum Pre Sale wallet

For the V1, V3 and EthSale formats the input is a JSON serialized string. All these formats require a password.

Note: `fromPublicKey()` only accepts uncompressed Ethereum-style public keys, unless the `nonStrict` flag is set to true.

Instance methods:

* `getPrivateKey()` - return the private key
* `getPublicKey()` - return the public key
* `getAddress()` - return the address
* `getChecksumAddressString()` - return the [address with checksum](https://github.com/ethereum/EIPs/issues/55)
* `getV3Filename([timestamp])` - return the suggested filename for V3 keystores
* `toV3(password, [options])` - return the wallet as a JSON string (Version 3 of the Ethereum wallet format)
- `getPrivateKey()` - return the private key
- `getPublicKey()` - return the public key
- `getAddress()` - return the address
- `getChecksumAddressString()` - return the [address with checksum](https://github.com/ethereum/EIPs/issues/55)
- `getV3Filename([timestamp])` - return the suggested filename for V3 keystores
- `toV3(password, [options])` - return the wallet as a JSON string (Version 3 of the Ethereum wallet format)

All of the above instance methods return a Buffer or JSON. Use the `String` suffixed versions for a string output, such as `getPrivateKeyString()`.

Expand All @@ -62,10 +65,10 @@ Importing various third party wallets is possible through the `thirdparty` submo

Constructors:

* `fromEtherCamp(passphrase)` - import a brain wallet used by Ether.Camp
* `fromEtherWallet(input, password)` - import a wallet generated by EtherWallet
* `fromKryptoKit(seed)` - import a wallet from a KryptoKit seed
* `fromQuorumWallet(passphrase, userid)` - import a brain wallet used by Quorum Wallet
- `fromEtherCamp(passphrase)` - import a brain wallet used by Ether.Camp
- `fromEtherWallet(input, password)` - import a wallet generated by EtherWallet
- `fromKryptoKit(seed)` - import a wallet from a KryptoKit seed
- `fromQuorumWallet(passphrase, userid)` - import a brain wallet used by Quorum Wallet

## HD Wallet API

Expand All @@ -75,18 +78,18 @@ To use BIP32 HD wallets, first include the `hdkey` submodule:

Constructors:

* `fromMasterSeed(seed)` - create an instance based on a seed
* `fromExtendedKey(key)` - create an instance based on a BIP32 extended private or public key
- `fromMasterSeed(seed)` - create an instance based on a seed
- `fromExtendedKey(key)` - create an instance based on a BIP32 extended private or public key

For the seed we suggest to use [bip39](https://npmjs.org/package/bip39) to create one from a BIP39 mnemonic.
For the seed we suggest to use [bip39](https://npmjs.org/package/bip39) to create one from a BIP39 mnemonic.

Instance methods:

* `privateExtendedKey()` - return a BIP32 extended private key (xprv)
* `publicExtendedKey()` - return a BIP32 extended public key (xpub)
* `derivePath(path)` - derive a node based on a path (e.g. m/44'/0'/0/1)
* `deriveChild(index)` - derive a node based on a child index
* `getWallet()` - return a `Wallet` instance as seen above
- `privateExtendedKey()` - return a BIP32 extended private key (xprv)
- `publicExtendedKey()` - return a BIP32 extended public key (xpub)
- `derivePath(path)` - derive a node based on a path (e.g. m/44'/0'/0/1)
- `deriveChild(index)` - derive a node based on a child index
- `getWallet()` - return a `Wallet` instance as seen above

## Provider Engine

Expand All @@ -103,6 +106,7 @@ Note it only supports the basic wallet. With a HD Wallet, call `getWallet()` fir
### Remarks about `toV3`

The `options` is an optional object hash, where all the serialization parameters can be fine tuned:

- uuid - UUID. One is randomly generated.
- salt - Random salt for the `kdf`. Size must match the requirements of the KDF (key derivation function). Random number generated via `crypto.getRandomBytes` if nothing is supplied.
- iv - Initialization vector for the `cipher`. Size must match the requirements of the cipher. Random number generated via `crypto.getRandomBytes` if nothing is supplied.
Expand All @@ -113,15 +117,18 @@ The `options` is an optional object hash, where all the serialization parameters
Depending on the `kdf` selected, the following options are available too.

For `pbkdf2`:

- `c` - Number of iterations. Defaults to 262144.
- `prf` - The only supported (and default) value is `hmac-sha256`. So no point changing it.

For `scrypt`:

- `n` - Iteration count. Defaults to 262144.
- `r` - Block size for the underlying hash. Defaults to 8.
- `p` - Parallelization factor. Defaults to 1.

The following settings are favoured by the Go Ethereum implementation and we default to the same:

- `kdf`: `scrypt`
- `dklen`: `32`
- `n`: `262144`
Expand Down
54 changes: 30 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
"name": "ethereumjs-wallet",
"version": "0.6.3",
"description": "Utilities for handling Ethereum keys",
"main": "index.js",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"*.js",
"test/"
"dist"
],
"scripts": {
"coverage": "istanbul cover _mocha",
"coveralls": "npm run build:dist && npm run coverage && coveralls <coverage/lcov.info",
"lint": "standard",
"prepublishOnly": "npm run lint && npm run test:build",
"test": "mocha ./src/test/*.js",
"test:build": "npm run build:dist && mocha ./test/*.js",
"build:dist": "babel src/ -d ."
"build": "ethereumjs-config-build",
"prepublishOnly": "npm run format && npm run tslint && npm run test",
"coverage": "ethereumjs-config-coverage",
"coveralls": "ethereumjs-config-coveralls",
"format": "ethereumjs-config-format",
"format-fix": "ethereumjs-config-format-fix",
"lint": "ethereumjs-config-lint",
"lint-fix": "ethereumjs-config-lint-fix",
"pretest": "npm run build",
"test": "nyc mocha ./test/**/*.ts",
"tsc": "ethereumjs-config-tsc",
"tslint": "ethereumjs-config-tslint",
"tslint:fix": "ethereumjs-config-tslint-fix"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -42,27 +48,27 @@
"ethereumjs-util": "^6.0.0",
"hdkey": "^1.1.1",
"randombytes": "^2.0.6",
"safe-buffer": "^5.1.2",
"scrypt.js": "^0.3.0",
"utf8": "^3.0.0",
"uuid": "^3.3.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"@ethereumjs/config-nyc": "^1.1.1",
"@ethereumjs/config-prettier": "^1.1.1",
"@ethereumjs/config-tsc": "^1.1.1",
"@ethereumjs/config-tslint": "^1.1.1",
"@types/bn.js": "^4.11.5",
"@types/mocha": "^5.2.7",
"@types/node": "^12.0.10",
"coveralls": "^3.0.0",
"husky": "^2.1.0",
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"standard": "^12.0.0"
},
"standard": {
"globals": [
"describe",
"it"
],
"ignore": [
"./*.js"
]
"nyc": "^14.1.1",
"prettier": "^1.15.3",
"source-map-support": "^0.5.12",
"ts-node": "^8.3.0",
"tslint": "^5.12.0",
"typescript": "^3.2.2",
"typestrict": "^1.0.2"
}
}
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@ethereumjs/config-prettier')
51 changes: 0 additions & 51 deletions src/hdkey.js

This file was deleted.

Loading