ethereum_bip44 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ac7dded1881ea89ba528ade58c9ec2b4ff743dc
4
- data.tar.gz: ba56b19aaf62a63ce38c00628d077189628b316b
3
+ metadata.gz: 9216b9ed9156d0c1255151c09468ae6c824e3c51
4
+ data.tar.gz: 19c0e5853bb81ed0a3ede0981ca93f61b5875ce6
5
5
  SHA512:
6
- metadata.gz: faa56578be1bb137faf110b61155899e719910f2ec9810f31aa703cfae114de4256068685bdd22df42670bf914cd9527d55cae7dfceb026ac2b10fe6aea30738
7
- data.tar.gz: 4c2e8a40d126c55093bf7fdd6e0b1d61a074f2c0c6dd399c8c1cd75345ec5326684b9e9eb696a6fd991086e6cdb501e3e941080390171e8cb09faed1839ac687
6
+ metadata.gz: 5a2d4105fc2b5a67a6407996b090fecdc3fdde7ae2f50c644b7e17e511a5b3bed29dc6a754d68bc772289b76f80fe799704cbeb931f31df495f8cd54701c3a92
7
+ data.tar.gz: 1ce8be2778f75e3eae991b1d65fa38748bfeedfc798f5b8217413d82a49518ae57ac34a3d2d0f99baba17a077292e1ea498d5b47bb87e04c300388bdf1848f64
data/.DS_Store ADDED
Binary file
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build ethereum_bip44-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install ethereum_bip44-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install ethereum_bip44-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push ethereum_bip44-0.1.0.gem to Rubygems" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
data/.idea/workspace.xml CHANGED
@@ -3,7 +3,6 @@
3
3
  <component name="ChangeListManager">
4
4
  <list default="true" id="6adfe41e-75d6-4c9f-94a7-6cf45e8f0229" name="Default" comment="">
5
5
  <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
6
- <change type="MODIFICATION" beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" />
7
6
  </list>
8
7
  <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
9
8
  <option name="TRACKING_ENABLED" value="true" />
@@ -20,11 +19,11 @@
20
19
  <SUITE FILE_PATH="coverage/ethereum_bip44@test_it_can_create_a_new_wallet__ethereum_bip44.coverage" NAME="test_it_can_create_a_new_wallet: ethereum_bip44 Coverage Results" MODIFIED="1509687010786" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="ethereum_bip44" />
21
20
  </component>
22
21
  <component name="FileEditorManager">
23
- <leaf>
22
+ <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
24
23
  <file leaf-file-name="ethereum_bip44.rb" pinned="false" current-in-tab="false">
25
24
  <entry file="file://$PROJECT_DIR$/lib/ethereum_bip44.rb">
26
25
  <provider selected="true" editor-type-id="text-editor">
27
- <state relative-caret-position="385">
26
+ <state relative-caret-position="1064">
28
27
  <caret line="56" column="6" lean-forward="false" selection-start-line="56" selection-start-column="6" selection-end-line="56" selection-end-column="6" />
29
28
  <folding />
30
29
  </state>
@@ -54,36 +53,23 @@
54
53
  <file leaf-file-name="ethereum_bip44.gemspec" pinned="false" current-in-tab="false">
55
54
  <entry file="file://$PROJECT_DIR$/ethereum_bip44.gemspec">
56
55
  <provider selected="true" editor-type-id="text-editor">
57
- <state relative-caret-position="395">
58
- <caret line="21" column="30" lean-forward="true" selection-start-line="21" selection-start-column="30" selection-end-line="21" selection-end-column="30" />
56
+ <state relative-caret-position="399">
57
+ <caret line="21" column="30" lean-forward="false" selection-start-line="21" selection-start-column="30" selection-end-line="21" selection-end-column="30" />
59
58
  <folding />
60
59
  </state>
61
60
  </provider>
62
61
  </entry>
63
62
  </file>
64
- <file leaf-file-name="ethereum_bip44_test.rb" pinned="false" current-in-tab="false">
63
+ <file leaf-file-name="ethereum_bip44_test.rb" pinned="false" current-in-tab="true">
65
64
  <entry file="file://$PROJECT_DIR$/test/ethereum_bip44_test.rb">
66
65
  <provider selected="true" editor-type-id="text-editor">
67
- <state relative-caret-position="418">
68
- <caret line="22" column="29" lean-forward="false" selection-start-line="22" selection-start-column="29" selection-end-line="22" selection-end-column="29" />
66
+ <state relative-caret-position="266">
67
+ <caret line="14" column="5" lean-forward="false" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
69
68
  <folding />
70
69
  </state>
71
70
  </provider>
72
71
  </entry>
73
72
  </file>
74
- <file leaf-file-name="README.md" pinned="false" current-in-tab="true">
75
- <entry file="file://$PROJECT_DIR$/README.md">
76
- <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
77
- <state split_layout="FIRST">
78
- <first_editor relative-caret-position="349">
79
- <caret line="26" column="8" lean-forward="false" selection-start-line="26" selection-start-column="8" selection-end-line="26" selection-end-column="8" />
80
- <folding />
81
- </first_editor>
82
- <second_editor />
83
- </state>
84
- </provider>
85
- </entry>
86
- </file>
87
73
  </leaf>
88
74
  </component>
89
75
  <component name="FileTemplateManagerImpl">
@@ -350,7 +336,8 @@
350
336
  <option name="number" value="Default" />
351
337
  <option name="presentableId" value="Default" />
352
338
  <updated>1509628188086</updated>
353
- <workItem from="1509628189826" duration="7015000" />
339
+ <workItem from="1509628189826" duration="8852000" />
340
+ <workItem from="1509870563290" duration="595000" />
354
341
  </task>
355
342
  <servers />
356
343
  </component>
@@ -387,28 +374,28 @@
387
374
  </history-entry>
388
375
  </component>
389
376
  <component name="TimeTrackingManager">
390
- <option name="totallyTimeSpent" value="7015000" />
377
+ <option name="totallyTimeSpent" value="9447000" />
391
378
  </component>
392
379
  <component name="ToolWindowManager">
393
380
  <frame x="0" y="23" width="1680" height="1023" extended-state="6" />
394
381
  <layout>
395
- <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
382
+ <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25305623" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
396
383
  <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
397
- <window_info id="Cargo" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
398
- <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
399
- <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
384
+ <window_info id="Cargo" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
385
+ <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
386
+ <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
400
387
  <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3297414" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
401
- <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
388
+ <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
402
389
  <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
403
- <window_info id="Terminal" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3297414" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
390
+ <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3297414" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
404
391
  <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
405
- <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
392
+ <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
406
393
  <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
407
- <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
408
394
  <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
409
395
  <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
410
- <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
411
396
  <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
397
+ <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
398
+ <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
412
399
  <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
413
400
  </layout>
414
401
  <layout-to-restore>
@@ -443,10 +430,10 @@
443
430
  <watches-manager />
444
431
  </component>
445
432
  <component name="editorHistoryManager">
446
- <entry file="file://$PROJECT_DIR$/lib/ethereum_bip44/version.rb">
433
+ <entry file="file://$PROJECT_DIR$/lib/ethereum_bip44.rb">
447
434
  <provider selected="true" editor-type-id="text-editor">
448
- <state relative-caret-position="0">
449
- <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
435
+ <state relative-caret-position="1064">
436
+ <caret line="56" column="6" lean-forward="false" selection-start-line="56" selection-start-column="6" selection-end-line="56" selection-end-column="6" />
450
437
  <folding />
451
438
  </state>
452
439
  </provider>
@@ -459,17 +446,49 @@
459
446
  </state>
460
447
  </provider>
461
448
  </entry>
449
+ <entry file="file://$PROJECT_DIR$/lib/ethereum_bip44/version.rb">
450
+ <provider selected="true" editor-type-id="text-editor">
451
+ <state relative-caret-position="0">
452
+ <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
453
+ <folding />
454
+ </state>
455
+ </provider>
456
+ </entry>
457
+ <entry file="file://$PROJECT_DIR$/ethereum_bip44.gemspec">
458
+ <provider selected="true" editor-type-id="text-editor">
459
+ <state relative-caret-position="399">
460
+ <caret line="21" column="30" lean-forward="true" selection-start-line="21" selection-start-column="30" selection-end-line="21" selection-end-column="30" />
461
+ <folding />
462
+ </state>
463
+ </provider>
464
+ </entry>
462
465
  <entry file="file://$PROJECT_DIR$/test/ethereum_bip44_test.rb">
463
466
  <provider selected="true" editor-type-id="text-editor">
464
- <state relative-caret-position="418">
465
- <caret line="22" column="29" lean-forward="false" selection-start-line="22" selection-start-column="29" selection-end-line="22" selection-end-column="29" />
467
+ <state relative-caret-position="266">
468
+ <caret line="14" column="5" lean-forward="true" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
469
+ <folding />
470
+ </state>
471
+ </provider>
472
+ </entry>
473
+ <entry file="file://$PROJECT_DIR$/lib/ethereum_bip44/version.rb">
474
+ <provider selected="true" editor-type-id="text-editor">
475
+ <state relative-caret-position="0">
476
+ <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
477
+ <folding />
478
+ </state>
479
+ </provider>
480
+ </entry>
481
+ <entry file="file://$PROJECT_DIR$/lib/ethereum_bip44/utils.rb">
482
+ <provider selected="true" editor-type-id="text-editor">
483
+ <state relative-caret-position="19">
484
+ <caret line="1" column="14" lean-forward="false" selection-start-line="1" selection-start-column="9" selection-end-line="1" selection-end-column="14" />
466
485
  <folding />
467
486
  </state>
468
487
  </provider>
469
488
  </entry>
470
489
  <entry file="file://$PROJECT_DIR$/lib/ethereum_bip44.rb">
471
490
  <provider selected="true" editor-type-id="text-editor">
472
- <state relative-caret-position="385">
491
+ <state relative-caret-position="1064">
473
492
  <caret line="56" column="6" lean-forward="false" selection-start-line="56" selection-start-column="6" selection-end-line="56" selection-end-column="6" />
474
493
  <folding />
475
494
  </state>
@@ -477,8 +496,8 @@
477
496
  </entry>
478
497
  <entry file="file://$PROJECT_DIR$/ethereum_bip44.gemspec">
479
498
  <provider selected="true" editor-type-id="text-editor">
480
- <state relative-caret-position="395">
481
- <caret line="21" column="30" lean-forward="true" selection-start-line="21" selection-start-column="30" selection-end-line="21" selection-end-column="30" />
499
+ <state relative-caret-position="399">
500
+ <caret line="21" column="30" lean-forward="false" selection-start-line="21" selection-start-column="30" selection-end-line="21" selection-end-column="30" />
482
501
  <folding />
483
502
  </state>
484
503
  </provider>
@@ -486,13 +505,20 @@
486
505
  <entry file="file://$PROJECT_DIR$/README.md">
487
506
  <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
488
507
  <state split_layout="FIRST">
489
- <first_editor relative-caret-position="349">
490
- <caret line="26" column="8" lean-forward="false" selection-start-line="26" selection-start-column="8" selection-end-line="26" selection-end-column="8" />
491
- <folding />
508
+ <first_editor relative-caret-position="171">
509
+ <caret line="9" column="0" lean-forward="true" selection-start-line="9" selection-start-column="0" selection-end-line="9" selection-end-column="0" />
492
510
  </first_editor>
493
511
  <second_editor />
494
512
  </state>
495
513
  </provider>
496
514
  </entry>
515
+ <entry file="file://$PROJECT_DIR$/test/ethereum_bip44_test.rb">
516
+ <provider selected="true" editor-type-id="text-editor">
517
+ <state relative-caret-position="266">
518
+ <caret line="14" column="5" lean-forward="false" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
519
+ <folding />
520
+ </state>
521
+ </provider>
522
+ </entry>
497
523
  </component>
498
524
  </project>
data/README.md CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  A ruby library to generate Ethereum addresses from a hierarchical deterministic wallet according to the [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) standard.
4
4
 
5
- Internally it uses [btcruby](https://github.com/oleganza/btcruby) for the deterministic private and public keys which allows to use many additional features like deriving Ethereum address from mnemonic backups (BIP32).
6
-
7
- This library is inspired by the js library [coinme/ethereum-bip44](https://github.com/coinme/ethereum-bip44), I followed its design.
5
+ Internally it uses [money-tree](https://github.com/GemHQ/money-tree) for the deterministic private and public keys which allows to use many additional features like deriving Ethereum address from mnemonic backups (BIP32).
8
6
 
7
+ Compatible with most hd wallet client like: imToken,MetaMask,Jaxx,MyEtherWallet,TREZOR,Exodus...
9
8
  ## Installation
10
9
 
11
10
  Add this line to your application's Gemfile:
@@ -24,7 +23,7 @@ Or install it yourself as:
24
23
 
25
24
  ## Usage
26
25
 
27
- See test
26
+ See test_get_addresses_from_wallet
28
27
 
29
28
  TODO: Write usage instructions here
30
29
 
@@ -25,8 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "minitest", "~> 5.0"
27
27
 
28
- spec.add_dependency "btcruby", "~> 1.7"
28
+ spec.add_dependency "money-tree"
29
29
  spec.add_dependency "ecdsa", "~> 1.2.0"
30
30
  spec.add_dependency "digest-sha3", "~> 1.1.0"
31
31
  spec.add_dependency "rlp", "~> 0.7.3"
32
+ spec.add_dependency "bip_mnemonic"
32
33
  end
@@ -1,60 +1,45 @@
1
1
  require "ethereum_bip44/version"
2
- require 'btcruby'
3
2
  require 'ecdsa'
4
3
  require 'digest/sha3'
5
4
  require 'rlp'
5
+ require 'money-tree'
6
+ require 'bip_mnemonic'
6
7
  require 'ethereum_bip44/utils'
7
8
 
8
9
  module EthereumBip44
9
- class Wallet
10
- def self.from_public_seed(seed)
11
- EthereumBip44::Wallet.new(BTC::Keychain.new(xpub: seed))
12
- end
13
10
 
14
- def self.from_private_seed(seed)
15
- EthereumBip44::Wallet.new(BTC::Keychain.new(xprv: seed))
16
- end
11
+ # "44'", # bip 44
12
+ # "60'", # coin
13
+ # "0'", # wallet
14
+ # "0" # 0 - public, 1 = private
15
+ # "0" # index
16
+ class Wallet
17
17
 
18
- def initialize(keychain)
19
- @parts = [
20
- "44'", # bip 44
21
- "60'", # coin
22
- "0'", # wallet
23
- "0" # 0 - public, 1 = private
24
- # index
25
- ]
26
- @keychain = keychain
18
+ def self.create_from_mnemonic(mnemonic, wallet_index)
19
+ seed = BipMnemonic.to_seed(mnemonic: mnemonic) # 2. 该助记词使用 PBKDF2 转化为种子(参见 BIP39)
20
+ EthereumBip44::Wallet.new(seed, wallet_index)
27
21
  end
28
-
29
- def derive(path)
30
- @keychain.derived_keychain(path)
22
+
23
+ def initialize(seed, wallet_index)
24
+ master = MoneyTree::Master.new(seed_hex: seed) # 3. 种子用于使用 HMAC-SHA512 生成根私钥(参见 BIP32)
25
+ @wallet_node = master.node_for_path("m/44'/60'/#{wallet_index}'") # 4. 从该根私钥,导出子私钥(参见 BIP32),其中节点布局由BIP44设置
31
26
  end
32
27
 
33
-
34
28
  def get_address(index)
35
- # get the public key of index
36
- parts = @parts[@keychain.depth..-1]
37
- path = 'm/' + (!parts.empty? ? parts.join('/') + '/' : '') + index.to_s
38
- derived = @keychain.derived_keychain(path)
39
- public_key_string = derived.key.public_key
29
+ node = @wallet_node.node_for_path("M/0/#{index}")
40
30
 
41
- # translate the public key to ethereum public key
31
+ # from bitcoin public key to ethereum public key
42
32
  group = ECDSA::Group::Secp256k1
43
- public_key = ECDSA::Format::PointOctetString.decode(public_key_string, group) # a point
33
+ public_key = ECDSA::Format::PointOctetString.decode(node.public_key.to_bytes, group) # a point
44
34
  ethereum_public = public_key.x.to_s(16) + public_key.y.to_s(16)
45
35
 
46
- # get the address from the ethereum public key
47
- bytes = Utils.hex_to_bin(ethereum_public)
36
+ # from ethereum public key to ethereum address
37
+ bytes = EthereumBip44::Utils.hex_to_bin(ethereum_public)
48
38
  address_bytes = Digest::SHA3.new(256).digest(bytes)[-20..-1]
49
- address = Utils.bin_to_hex(address_bytes)
50
- Utils.prefix_hex(address)
39
+ address = EthereumBip44::Utils.bin_to_hex(address_bytes)
40
+ EthereumBip44::Utils.prefix_hex(address)
51
41
  end
52
42
 
53
- def get_private_key(index)
54
- parts = @parts[@keychain.depth..-1]
55
- path = 'm/' + (!parts.empty? ? parts.join('/') + '/' : '') + index.to_s
56
- derived = @keychain.derived_keychain(path)
57
- Utils.bin_to_hex(derived.key.private_key)
58
- end
59
43
  end
44
+
60
45
  end
@@ -1,3 +1,3 @@
1
1
  module EthereumBip44
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethereum_bip44
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - wuminzhe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2018-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: btcruby
56
+ name: money-tree
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.7'
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.7'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ecdsa
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.7.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: bip_mnemonic
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: A ruby library to generate Ethereum addresses from a hierarchical deterministic
112
126
  wallet according to the BIP44 standard.
113
127
  email:
@@ -116,7 +130,9 @@ executables: []
116
130
  extensions: []
117
131
  extra_rdoc_files: []
118
132
  files:
133
+ - ".DS_Store"
119
134
  - ".gitignore"
135
+ - ".idea/.rakeTasks"
120
136
  - ".idea/ethereum_bip44.iml"
121
137
  - ".idea/misc.xml"
122
138
  - ".idea/modules.xml"
@@ -154,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
170
  version: '0'
155
171
  requirements: []
156
172
  rubyforge_project:
157
- rubygems_version: 2.6.13
173
+ rubygems_version: 2.6.14
158
174
  signing_key:
159
175
  specification_version: 4
160
176
  summary: A ruby library to generate Ethereum addresses from a hierarchical deterministic