Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit de3a92e

Browse files
authored
Merge pull request #93 from the-jackalope/typescript-rewrite
Typescript rewrite
2 parents c04b80e + 807b980 commit de3a92e

25 files changed

+1423
-1074
lines changed

.babelrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

.gitignore

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ lib-cov
1313

1414
# Coverage directory used by tools like istanbul
1515
coverage
16+
.nyc_output
1617

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

37-
# Build folder
38-
# Update 2018-08-07: currently build is done to / (before: dist/) due to
39-
# backwards compatibility reasons, JS files from root and root test/ folder
40-
# are excluded
41-
/*.js
42-
/test
38+
39+
# IDE and text editor config files
40+
.idea
41+
.vscode
42+
43+
# build output
44+
dist

.nycrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@ethereumjs/config-nyc"
3+
}

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.vscode
3+
package.json
4+
dist
5+
.nyc_output

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ node_js:
33
- "6"
44
- "8"
55
- "10"
6-
env:
7-
- CXX=g++-4.8
86
addons:
97
apt:
108
sources:

CHANGELOG.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

4-
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5-
(modification: no type change headlines) and this project adheres to
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6+
(modification: no type change headlines) and this project adheres to
67
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
78

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

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

1819
## [0.6.2] - 2018-08-08
19-
- [PLEASE UPDATE!] Fixes a critical import bug introduced in ``v0.6.1`` accidentally
20+
21+
- [PLEASE UPDATE!] Fixes a critical import bug introduced in `v0.6.1` accidentally
2022
changing the import path for the different submodules, see PR [#65](https://github.com/ethereumjs/ethereumjs-wallet/pull/65)
2123

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

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

3437
## [0.6.0] - 2016-04-27
38+
3539
- Added provider-engine integration, PR [#7](https://github.com/ethereumjs/ethereumjs-wallet/pull/7)
3640

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

3943
## [0.5.2] - 2016-04-25
44+
4045
- Dependency updates
4146

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

4449
## [0.5.1] - 2016-03-26
45-
- Bugfix for ``EthereumHDKey.privateExtendedKey()``
50+
51+
- Bugfix for `EthereumHDKey.privateExtendedKey()`
4652
- Added travis and coveralls support
4753
- Documentation and test improvements
4854

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

5157
## [0.5.0] - 2016-03-23
52-
- Support HD keys using ``cryptocoinjs/hdkey``
58+
59+
- Support HD keys using `cryptocoinjs/hdkey`
5360
- Ensure private keys are valid according to the curve
5461
- Support instantation with public keys
5562
- Support importing BIP32 xpub/xpriv

README.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,50 @@
88
A lightweight wallet implementation. At the moment it supports key creation and conversion between various formats.
99

1010
It is complemented by the following packages:
11+
1112
- [ethereumjs-tx](https://github.com/ethereumjs/ethereumjs-tx) to sign transactions
1213
- [ethereumjs-icap](https://github.com/ethereumjs/ethereumjs-icap) to manipulate ICAP addresses
1314
- [store.js](https://github.com/marcuswestin/store.js) to use browser storage
1415

1516
Motivations are:
17+
1618
- be lightweight
1719
- work in a browser
1820
- use a single, maintained version of crypto library (and that should be in line with `ethereumjs-util` and `ethereumjs-tx`)
1921
- support import/export between various wallet formats
2022
- support BIP32 HD keys
2123

2224
Features not supported:
25+
2326
- signing transactions
2427
- managing storage (neither in node.js or the browser)
2528

2629
## Wallet API
2730

2831
Constructors:
2932

30-
* `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`)
31-
* `generateVanityAddress(pattern)` - create an instance where the address is valid against the supplied pattern (**this will be very slow**)
32-
* `fromPrivateKey(input)` - create an instance based on a raw private key
33-
* `fromExtendedPrivateKey(input)` - create an instance based on a BIP32 extended private key (xprv)
34-
* `fromPublicKey(input, [nonStrict])` - create an instance based on a public key (certain methods will not be available)
35-
* `fromExtendedPublicKey(input)` - create an instance based on a BIP32 extended public key (xpub)
36-
* `fromV1(input, password)` - import a wallet (Version 1 of the Ethereum wallet format)
37-
* `fromV3(input, password, [nonStrict])` - import a wallet (Version 3 of the Ethereum wallet format). Set `nonStrict` true to accept files with mixed-caps.
38-
* `fromEthSale(input, password)` - import an Ethereum Pre Sale wallet
33+
- `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`)
34+
- `generateVanityAddress(pattern)` - create an instance where the address is valid against the supplied pattern (**this will be very slow**)
35+
- `fromPrivateKey(input)` - create an instance based on a raw private key
36+
- `fromExtendedPrivateKey(input)` - create an instance based on a BIP32 extended private key (xprv)
37+
- `fromPublicKey(input, [nonStrict])` - create an instance based on a public key (certain methods will not be available)
38+
- `fromExtendedPublicKey(input)` - create an instance based on a BIP32 extended public key (xpub)
39+
- `fromV1(input, password)` - import a wallet (Version 1 of the Ethereum wallet format)
40+
- `fromV3(input, password, [nonStrict])` - import a wallet (Version 3 of the Ethereum wallet format). Set `nonStrict` true to accept files with mixed-caps.
41+
- `fromEthSale(input, password)` - import an Ethereum Pre Sale wallet
3942

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

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

4447
Instance methods:
4548

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

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

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

6366
Constructors:
6467

65-
* `fromEtherCamp(passphrase)` - import a brain wallet used by Ether.Camp
66-
* `fromEtherWallet(input, password)` - import a wallet generated by EtherWallet
67-
* `fromKryptoKit(seed)` - import a wallet from a KryptoKit seed
68-
* `fromQuorumWallet(passphrase, userid)` - import a brain wallet used by Quorum Wallet
68+
- `fromEtherCamp(passphrase)` - import a brain wallet used by Ether.Camp
69+
- `fromEtherWallet(input, password)` - import a wallet generated by EtherWallet
70+
- `fromKryptoKit(seed)` - import a wallet from a KryptoKit seed
71+
- `fromQuorumWallet(passphrase, userid)` - import a brain wallet used by Quorum Wallet
6972

7073
## HD Wallet API
7174

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

7679
Constructors:
7780

78-
* `fromMasterSeed(seed)` - create an instance based on a seed
79-
* `fromExtendedKey(key)` - create an instance based on a BIP32 extended private or public key
81+
- `fromMasterSeed(seed)` - create an instance based on a seed
82+
- `fromExtendedKey(key)` - create an instance based on a BIP32 extended private or public key
8083

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

8386
Instance methods:
8487

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

9194
## Provider Engine
9295

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

105108
The `options` is an optional object hash, where all the serialization parameters can be fine tuned:
109+
106110
- uuid - UUID. One is randomly generated.
107111
- 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.
108112
- iv - Initialization vector for the `cipher`. Size must match the requirements of the cipher. Random number generated via `crypto.getRandomBytes` if nothing is supplied.
@@ -113,15 +117,18 @@ The `options` is an optional object hash, where all the serialization parameters
113117
Depending on the `kdf` selected, the following options are available too.
114118

115119
For `pbkdf2`:
120+
116121
- `c` - Number of iterations. Defaults to 262144.
117122
- `prf` - The only supported (and default) value is `hmac-sha256`. So no point changing it.
118123

119124
For `scrypt`:
125+
120126
- `n` - Iteration count. Defaults to 262144.
121127
- `r` - Block size for the underlying hash. Defaults to 8.
122128
- `p` - Parallelization factor. Defaults to 1.
123129

124130
The following settings are favoured by the Go Ethereum implementation and we default to the same:
131+
125132
- `kdf`: `scrypt`
126133
- `dklen`: `32`
127134
- `n`: `262144`

package.json

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
"name": "ethereumjs-wallet",
33
"version": "0.6.3",
44
"description": "Utilities for handling Ethereum keys",
5-
"main": "index.js",
5+
"main": "dist/index.js",
6+
"types": "./dist/index.d.ts",
67
"files": [
7-
"*.js",
8-
"test/"
8+
"dist"
99
],
1010
"scripts": {
11-
"coverage": "istanbul cover _mocha",
12-
"coveralls": "npm run build:dist && npm run coverage && coveralls <coverage/lcov.info",
13-
"lint": "standard",
14-
"prepublishOnly": "npm run lint && npm run test:build",
15-
"test": "mocha ./src/test/*.js",
16-
"test:build": "npm run build:dist && mocha ./test/*.js",
17-
"build:dist": "babel src/ -d ."
11+
"build": "ethereumjs-config-build",
12+
"prepublishOnly": "npm run format && npm run tslint && npm run test",
13+
"coverage": "ethereumjs-config-coverage",
14+
"coveralls": "ethereumjs-config-coveralls",
15+
"format": "ethereumjs-config-format",
16+
"format-fix": "ethereumjs-config-format-fix",
17+
"lint": "ethereumjs-config-lint",
18+
"lint-fix": "ethereumjs-config-lint-fix",
19+
"pretest": "npm run build",
20+
"test": "nyc mocha ./test/**/*.ts",
21+
"tsc": "ethereumjs-config-tsc",
22+
"tslint": "ethereumjs-config-tslint",
23+
"tslint:fix": "ethereumjs-config-tslint-fix"
1824
},
1925
"husky": {
2026
"hooks": {
@@ -42,27 +48,27 @@
4248
"ethereumjs-util": "^6.0.0",
4349
"hdkey": "^1.1.1",
4450
"randombytes": "^2.0.6",
45-
"safe-buffer": "^5.1.2",
4651
"scrypt.js": "^0.3.0",
4752
"utf8": "^3.0.0",
4853
"uuid": "^3.3.2"
4954
},
5055
"devDependencies": {
51-
"babel-cli": "^6.26.0",
52-
"babel-preset-env": "^1.7.0",
56+
"@ethereumjs/config-nyc": "^1.1.1",
57+
"@ethereumjs/config-prettier": "^1.1.1",
58+
"@ethereumjs/config-tsc": "^1.1.1",
59+
"@ethereumjs/config-tslint": "^1.1.1",
60+
"@types/bn.js": "^4.11.5",
61+
"@types/mocha": "^5.2.7",
62+
"@types/node": "^12.0.10",
5363
"coveralls": "^3.0.0",
5464
"husky": "^2.1.0",
55-
"istanbul": "^0.4.5",
5665
"mocha": "^5.2.0",
57-
"standard": "^12.0.0"
58-
},
59-
"standard": {
60-
"globals": [
61-
"describe",
62-
"it"
63-
],
64-
"ignore": [
65-
"./*.js"
66-
]
66+
"nyc": "^14.1.1",
67+
"prettier": "^1.15.3",
68+
"source-map-support": "^0.5.12",
69+
"ts-node": "^8.3.0",
70+
"tslint": "^5.12.0",
71+
"typescript": "^3.2.2",
72+
"typestrict": "^1.0.2"
6773
}
6874
}

prettier.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@ethereumjs/config-prettier')

src/hdkey.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)