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

v3 (typescript included) #104

Merged
merged 33 commits into from Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
37a4d0d
install typescript
d-yokoi Mar 23, 2019
717868a
add tsconfig.json
d-yokoi Mar 23, 2019
54169e3
install prettier and add config files
d-yokoi Mar 23, 2019
52aa129
install types
d-yokoi Mar 23, 2019
4aadbec
enable resolveJsonModule
d-yokoi Mar 23, 2019
0c20add
uninstall safe-buffer to use built-in Buffer
d-yokoi Mar 23, 2019
bb82323
add typescript implementation
d-yokoi Mar 23, 2019
31fd6e8
add @types/node
d-yokoi Mar 23, 2019
b9df613
move wordlists to under ts root directory
d-yokoi Mar 23, 2019
ad5dec9
add build artifacts
d-yokoi Mar 23, 2019
4649846
fix unit test
d-yokoi Mar 23, 2019
834389c
add tslint and fix lint errors
d-yokoi Mar 23, 2019
b91260e
fix exports
d-yokoi Mar 23, 2019
a998922
replace standard with prettier and tslint
d-yokoi Mar 23, 2019
558732c
update repository url
d-yokoi Mar 23, 2019
a8393a0
anchor new dependencies
d-yokoi Mar 24, 2019
5561a45
delete old file
d-yokoi Mar 24, 2019
427eb0c
move @types/node from devDep to dep
d-yokoi Mar 24, 2019
0bc1939
prefer simpler module path
d-yokoi Mar 24, 2019
d84e282
clean output dir before build
d-yokoi Mar 24, 2019
ac0da78
change build target from es2015 to es2017
d-yokoi Mar 24, 2019
00e50b3
delete comment
d-yokoi Mar 24, 2019
c49db9f
prefer destructuring to slice
d-yokoi Mar 25, 2019
9f805df
prefer const in README examples
d-yokoi Mar 25, 2019
6dedef0
Fix util to download into ts folder
junderw Mar 26, 2019
c30b47b
Allow excluding wordlists when building for browserify
junderw Mar 26, 2019
6194c3f
Add tests and getDefaultWordlist
junderw Mar 28, 2019
cce4bd0
Add git diff check to travis
junderw Apr 1, 2019
68d0bb4
Merge pull request #105 from bitcoinjs/tsAllowExclude
junderw Apr 2, 2019
b6e8f0a
Merge branch 'master' into typescript
junderw Apr 2, 2019
91b0efd
Remove unorm dependency
junderw Apr 2, 2019
4acb712
Remove hex functions and make async default
junderw Apr 2, 2019
981b010
3.0.0
junderw Apr 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added .prettierignore
Empty file.
4 changes: 4 additions & 0 deletions .prettierrc.json
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,10 @@ node_js:
- "lts/*"
- "9"
- "10"
matrix:
include:
- node_js: "lts/*"
env: TEST_SUITE=gitdiff:ci
env:
- TEST_SUITE=test
script: npm run-script $TEST_SUITE
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,10 @@
# 3.0.0
__added__
- Added TypeScript support (#104)
- Added support for excluding wordlists from packages (#105)

__changed__
- Changed `mnemonicToSeed` to use async, sync version moved to `mnemonicToSeedSync` (#104)

__removed__
- Removed explicit hex methods (use `toString('hex')` on the Buffer) (#104)
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,12 @@
# Check the CONTRIBUTING doc on bitcoinjs-lib for info

[Contributing to BitcoinJS](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/CONTRIBUTING.md)

# TypeScript

* `npm install`
* Modify TypeScript in ts_src folder
* Run `npm run format`
* Run `npm run lint` and make any necessary changes to remove errors
* Run `npm test` and make sure the tests pass
* Run `git diff` and make sure the diff in the JS files in the src folder match the changes you made to the TS files
74 changes: 65 additions & 9 deletions README.md
Expand Up @@ -16,6 +16,62 @@ When a checksum is invalid, warn the user that the phrase is not something gener

However, there should be other checks in place, such as checking to make sure the user is inputting 12 words or more separated by a space. ie. `phrase.trim().split(/\s+/g).length >= 12`

## Removing wordlists from webpack/browserify

Browserify/Webpack bundles can get very large if you include all the wordlists, so you can now exclude wordlists to make your bundle lighter.

For example, if we want to exclude all wordlists besides chinese_simplified, you could build using the browserify command below.

```bash
$ browserify -r bip39 -s bip39 \
--exclude=./wordlists/english.json \
--exclude=./wordlists/japanese.json \
--exclude=./wordlists/spanish.json \
--exclude=./wordlists/italian.json \
--exclude=./wordlists/french.json \
--exclude=./wordlists/korean.json \
--exclude=./wordlists/chinese_traditional.json \
> bip39.browser.js
```

This will create a bundle that only contains the chinese_simplified wordlist, and it will be the default wordlist for all calls without explicit wordlists.

This is how it will look in the browser console.

```javascript
> bip39.entropyToMnemonic('00000000000000000000000000000000')
"的 的 的 的 的 的 的 的 的 的 的 在"
> bip39.wordlists.chinese_simplified
Array(2048) [ "的", "一", "是", "在", "不", "了", "有", "和", "人", "这", … ]
> bip39.wordlists.english
undefined
> bip39.wordlists.japanese
undefined
> bip39.wordlists.spanish
undefined
> bip39.wordlists.italian
undefined
> bip39.wordlists.french
undefined
> bip39.wordlists.korean
undefined
> bip39.wordlists.chinese_traditional
undefined
```

For a list of supported wordlists check the wordlists folder. The name of the json file (minus the extension) is the name of the key to access the wordlist.

You can also change the default wordlist at runtime if you dislike the wordlist you were given as default.

```javascript
> bip39.entropyToMnemonic('00000000000000000000000000000fff')
"あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あまい ろんり"
> bip39.setDefaultWordlist('italian')
undefined
> bip39.entropyToMnemonic('00000000000000000000000000000fff')
"abaco abaco abaco abaco abaco abaco abaco abaco abaco abaco aforisma zibetto"
```

## Installation
``` bash
npm install bip39
Expand All @@ -27,21 +83,21 @@ npm install bip39
const mnemonic = bip39.generateMnemonic()
// => 'seed sock milk update focus rotate barely fade car face mechanic mercy'

bip39.mnemonicToSeedHex('basket actual')
bip39.mnemonicToSeedSync('basket actual').toString('hex')
// => '5cf2d4a8b0355e90295bdfc565a022a409af063d5365bb57bf74d9528f494bfa4400f53d8349b80fdae44082d7f9541e1dba2b003bcfec9d0d53781ca676651f'

bip39.mnemonicToSeed('basket actual')
bip39.mnemonicToSeedSync('basket actual')
// => <Buffer 5c f2 d4 a8 b0 35 5e 90 29 5b df c5 65 a0 22 a4 09 af 06 3d 53 65 bb 57 bf 74 d9 52 8f 49 4b fa 44 00 f5 3d 83 49 b8 0f da e4 40 82 d7 f9 54 1e 1d ba 2b ...>

// mnemonicToSeed and mnemonicToSeedHex have async versions
// mnemonicToSeedAsync mnemonicToSeedHexAsync are more performance oriented
bip39.mnemonicToSeedAsync('basket actual').then(console.log)
// mnemonicToSeed has an synchronous version
// mnemonicToSeedSync is less performance oriented
bip39.mnemonicToSeed('basket actual').then(console.log)
// => <Buffer 5c f2 d4 a8 b0 35 5e 90 29 5b df c5 65 a0 22 a4 09 af 06 3d 53 65 bb 57 bf 74 d9 52 8f 49 4b fa 44 00 f5 3d 83 49 b8 0f da e4 40 82 d7 f9 54 1e 1d ba 2b ...>

bip39.mnemonicToSeedHexAsync('basket actual').then(console.log)
bip39.mnemonicToSeed('basket actual').then(bytes => bytes.toString('hex')).then(console.log)
// => '5cf2d4a8b0355e90295bdfc565a022a409af063d5365bb57bf74d9528f494bfa4400f53d8349b80fdae44082d7f9541e1dba2b003bcfec9d0d53781ca676651f'

bip39.mnemonicToSeed('basket actual', 'a password')
bip39.mnemonicToSeedSync('basket actual', 'a password')
// => <Buffer 46 16 a4 4f 2c 90 b9 69 02 14 b8 fd 43 5b b4 14 62 43 de 10 7b 30 87 59 0a 3b b8 d3 1b 2f 3a ef ab 1d 4b 52 6d 21 e5 0a 04 02 3d 7a d0 66 43 ea 68 3b ... >

bip39.validateMnemonic(mnemonic)
Expand All @@ -53,11 +109,11 @@ bip39.validateMnemonic('basket actual')


``` js
var bip39 = require('bip39')
const bip39 = require('bip39')

// defaults to BIP39 English word list
// uses HEX strings for entropy
var mnemonic = bip39.entropyToMnemonic('00000000000000000000000000000000')
const mnemonic = bip39.entropyToMnemonic('00000000000000000000000000000000')
// => abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about

// reversible
Expand Down
178 changes: 0 additions & 178 deletions index.js

This file was deleted.