pochette_web 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/javascripts/pochette_web/application.js +16 -0
  5. data/app/assets/javascripts/pochette_web/bootstrap.js +4 -0
  6. data/app/assets/javascripts/pochette_web/home.js.coffee +172 -0
  7. data/app/assets/javascripts/pochette_web/lib/bitcoinjs.js +5140 -0
  8. data/app/assets/javascripts/pochette_web/lib/trezor.js +7267 -0
  9. data/app/assets/javascripts/pochette_web/lib/trezor_utils.js.coffee +47 -0
  10. data/app/assets/javascripts/pochette_web/lib/underscore.js +1548 -0
  11. data/app/assets/stylesheets/pochette_web/application.css +15 -0
  12. data/app/assets/stylesheets/pochette_web/bootstrap_and_overrides.css +7 -0
  13. data/app/assets/stylesheets/pochette_web/home.css +4 -0
  14. data/app/controllers/pochette_web/application_controller.rb +4 -0
  15. data/app/controllers/pochette_web/home_controller.rb +34 -0
  16. data/app/helpers/pochette_web/application_helper.rb +4 -0
  17. data/app/helpers/pochette_web/home_helper.rb +4 -0
  18. data/app/views/layouts/pochette_web/application.html.erb +14 -0
  19. data/app/views/pochette_web/home/index.html.haml +186 -0
  20. data/config/routes.rb +5 -0
  21. data/lib/pochette_web.rb +9 -0
  22. data/lib/pochette_web/engine.rb +5 -0
  23. data/lib/pochette_web/version.rb +3 -0
  24. data/lib/tasks/pochette_web_tasks.rake +4 -0
  25. data/test/controllers/pochette_web/home_controller_test.rb +13 -0
  26. data/test/dummy/README.rdoc +28 -0
  27. data/test/dummy/Rakefile +6 -0
  28. data/test/dummy/app/assets/javascripts/application.js +13 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  30. data/test/dummy/app/controllers/application_controller.rb +5 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/bin/bundle +3 -0
  33. data/test/dummy/bin/rails +4 -0
  34. data/test/dummy/bin/rake +4 -0
  35. data/test/dummy/bin/setup +29 -0
  36. data/test/dummy/config.ru +4 -0
  37. data/test/dummy/config/application.rb +27 -0
  38. data/test/dummy/config/boot.rb +5 -0
  39. data/test/dummy/config/database.yml +25 -0
  40. data/test/dummy/config/environment.rb +5 -0
  41. data/test/dummy/config/environments/development.rb +41 -0
  42. data/test/dummy/config/environments/production.rb +79 -0
  43. data/test/dummy/config/environments/test.rb +42 -0
  44. data/test/dummy/config/initializers/assets.rb +11 -0
  45. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  47. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/test/dummy/config/initializers/inflections.rb +16 -0
  49. data/test/dummy/config/initializers/mime_types.rb +4 -0
  50. data/test/dummy/config/initializers/pochette.rb +7 -0
  51. data/test/dummy/config/initializers/rack_attack.rb +5 -0
  52. data/test/dummy/config/initializers/session_store.rb +3 -0
  53. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/test/dummy/config/locales/en.yml +23 -0
  55. data/test/dummy/config/routes.rb +4 -0
  56. data/test/dummy/config/secrets.yml +22 -0
  57. data/test/dummy/db/development.sqlite3 +0 -0
  58. data/test/dummy/public/404.html +67 -0
  59. data/test/dummy/public/422.html +67 -0
  60. data/test/dummy/public/500.html +66 -0
  61. data/test/dummy/public/favicon.ico +0 -0
  62. data/test/dummy/public/trezor_config_signed.bin +1 -0
  63. data/test/integration/navigation_test.rb +8 -0
  64. data/test/pochette_web_test.rb +7 -0
  65. data/test/test_helper.rb +21 -0
  66. metadata +262 -0
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,7 @@
1
+ /*
2
+ =require twitter-bootstrap-static/bootstrap
3
+
4
+ Use Font Awesome icons (default)
5
+ To use Glyphicons sprites instead of Font Awesome, replace with "require twitter-bootstrap-static/sprites"
6
+ =require twitter-bootstrap-static/fontawesome
7
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ module PochetteWeb
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,34 @@
1
+ require_dependency "pochette_web/application_controller"
2
+
3
+ module PochetteWeb
4
+ class HomeController < ApplicationController
5
+ rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
6
+ error = {parameter_missing_exception.param => ['parameter is required']}
7
+ render json: { errors: [error] }, status: 422
8
+ end
9
+
10
+ def index
11
+ end
12
+
13
+ def trezor_transaction_builder
14
+ t = Pochette::TrezorTransactionBuilder.new(
15
+ bip32_addresses: params.require(:bip32_addresses),
16
+ outputs: params.require(:outputs),
17
+ utxo_blacklist: params[:utxo_blacklist],
18
+ change_address: params[:change_address].presence,
19
+ fee_per_kb: params[:fee_per_kb].presence && params[:fee_per_kb].to_i,
20
+ spend_all: params[:spend_all]
21
+ )
22
+
23
+ render json: ( t.valid? ? t.as_hash : t.errors )
24
+ end
25
+
26
+ def make_multisig
27
+ public_keys = params[:xpubs].collect do |x|
28
+ MoneyTree::Node.from_bip32(x).node_for_path(params[:path]).public_key.key
29
+ end
30
+ address, _ = Bitcoin.pubkeys_to_p2sh_multisig_address(params[:signers].to_i, *public_keys)
31
+ render json: address
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module PochetteWeb
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PochetteWeb
2
+ module HomeHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>PochetteWeb</title>
5
+ <%= stylesheet_link_tag "pochette_web/application", media: "all" %>
6
+ <%= javascript_include_tag "pochette_web/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,186 @@
1
+ .container
2
+ %h1
3
+ Pochette Trezor Sandbox
4
+ %p
5
+ Play with your trezor and Pochette, create multisig addresses,
6
+ spend their unspent outputs, have fun!
7
+ %p
8
+ Source available on GitHub
9
+ %a(href="https://github.com/bitex-la/pochette-web") bitex-la/pochette-web
10
+ .alert.alert-warning
11
+ Running on
12
+ %strong Testnet3.
13
+ You're limited to prepare no more than 5 transactions per minute because our testnet node is very modest.
14
+
15
+ %ul.nav.nav-tabs(role="tablist")
16
+ %li.active(role="presentation")
17
+ %a(data-toggle="tab" href="#trezor_transaction_builder")
18
+ TrezorTransactionBuilder
19
+ %li(role="presentation")
20
+ %a(data-toggle="tab" href="#multisig_address")
21
+ Make Multisig Address
22
+
23
+ .tab-content
24
+ #trezor_transaction_builder.tab-pane.active(role="tabpanel")
25
+ %form
26
+ %h2 Parameters
27
+ %p
28
+ Start by setting all the parameters to create a transaction to be signed
29
+ with your trezor.
30
+ .form-group
31
+ %h3 bip32_addresses
32
+ %p
33
+ List of addresses in wallet. We will be spending their unspent outputs.
34
+ Each address is represented as a pair, with the public address string
35
+ and the BIP32 path as a list of integers.
36
+ %p
37
+ Multisig addresses are represented as a list of root XPUBs,
38
+ and the BIP32 derivation path as an array of integers.
39
+ %textarea#bip32_addresses.form-control(rows=10)
40
+ %span#add_address.btn.btn-default Add Address
41
+ %span#add_multisig_address.btn.btn-default Add Multisig Address
42
+ .form-group
43
+ %h3 outputs
44
+ %p
45
+ List of pairs [recipient_address, amount_in_satoshis] This will not be all the final
46
+ outputs in the transaction, as a 'change' output may be added if needed.
47
+ %textarea#outputs.form-control(rows=10)
48
+ %span#add_output.btn.btn-default Add Output
49
+ .form-group
50
+ %h3 utxo_blacklist
51
+ %p
52
+ Optional. List of utxos to ignore, a list of pairs [transaction hash, position]
53
+ %textarea#utxo_blacklist.form-control(rows=10)
54
+ %span#add_utxo_blacklist.btn.btn-default Add UTXO to blacklist
55
+ .form-group
56
+ %h3 change_address
57
+ %p
58
+ Optional. Change address to use. Will default to the first source address.
59
+ %input#change_address.form-control(type="text")
60
+ .form-group
61
+ %h3 fee_per_kb
62
+ %p
63
+ Optional. Defaults to 10000 satoshis
64
+ %input#fee_per_kb.form-control(type="text")
65
+ %h3 spend all
66
+ %p
67
+ Optional. Wether to spend all available utxos or just select enough to cover the given outputs.
68
+ .checkbox
69
+ %label
70
+ %input#spend_all(type="checkbox")
71
+ yes
72
+ %br
73
+ %p
74
+ #prepare_transaction.btn.btn-primary.btn-lg Prepare Transaction
75
+
76
+ %hr
77
+ %h2 Prepared Transaction
78
+ %p
79
+ This is the prepared transaction as returned by Pochette::TrezorTransactionBuilder#as_hash
80
+ .form-group
81
+ %textarea#as_hash.form-control(rows=30)
82
+
83
+ #pending_multisig_signatures.alert.alert-warning.hidden
84
+ This transaction has multi-signature inputs, connect another trezor and
85
+ keep on signing.
86
+
87
+ %span#sign_transaction.btn.btn-primary.btn-lg Sign Transaction
88
+
89
+ %hr
90
+ %h2 Signed Transaction
91
+ %p
92
+ Copy and paste your raw transaction hex representation and push it however you want,
93
+ Here are some transaction pushing services:
94
+ %br
95
+ %a(href="https://tbtc.blockr.io/tx/push") https://tbtc.blockr.io/tx/push
96
+ %br
97
+ %a(href="https://live.blockcypher.com/btc-testnet/pushtx/") https://live.blockcypher.com/btc-testnet/pushtx/
98
+
99
+ .form-group
100
+ %textarea#signed_transaction.form-control(rows=25)
101
+
102
+ #multisig_address.tab-pane(role="tabpanel")
103
+ %form
104
+ .form-group
105
+ %h3 Collect xpub's
106
+ %p
107
+ Connect your Trezors, one at a time, and fetch their root xpubs
108
+ from which the multisig address will be derived.
109
+ Unplugging your device then plugging it again but using a different
110
+ passphrase is also interpreted as a different device.
111
+ %textarea#xpubs.form-control(rows=6)
112
+ %span#read_xpub.btn.btn-default Read Current Trezor xpub
113
+ .form-group
114
+ %h3 Required signatures
115
+ %p
116
+ How many signatures are required to redeem funds received to this address?
117
+ %input#signers.form-control(value="2")
118
+ .form-group
119
+ %h3 Path
120
+ %p
121
+ BIP32 derivation path (ex: 44/0/0/1). Your address will be created from
122
+ all the public keys at this path in each device.
123
+ %input#path.form-control(value="0/0")
124
+
125
+ %br
126
+ %p
127
+ #make_multisig_address.btn.btn-primary.btn-lg Make Multisig Address
128
+ %hr
129
+ .form-group
130
+ %h3 Your address
131
+ %input#view_multisig_address.form-control
132
+
133
+
134
+ .pin_dialog.modal.fade(role="dialog")
135
+ .modal-dialog
136
+ .modal-content
137
+ .modal-body
138
+ %h3 Enter PIN
139
+ %p Look at the device for number positions
140
+
141
+ .grid
142
+ .row
143
+ .col-xs-4
144
+ %button.btn-block.btn-primary.btn(type="button" data-value="7") &#8226;
145
+ .col-xs-4
146
+ %button.btn-block.btn-primary.btn(type="button" data-value="8") &#8226;
147
+ .col-xs-4
148
+ %button.btn-block.btn-primary.btn(type="button" data-value="9") &#8226;
149
+ %br
150
+ .row
151
+ .col-xs-4
152
+ %button.btn-block.btn-primary.btn(type="button" data-value="4") &#8226;
153
+ .col-xs-4
154
+ %button.btn-block.btn-primary.btn(type="button" data-value="5") &#8226;
155
+ .col-xs-4
156
+ %button.btn-block.btn-primary.btn(type="button" data-value="6") &#8226;
157
+ %br
158
+ .row
159
+ .col-xs-4
160
+ %button.btn-block.btn-primary.btn(type="button" data-value="1") &#8226;
161
+ .col-xs-4
162
+ %button.btn-block.btn-primary.btn(type="button" data-value="2") &#8226;
163
+ .col-xs-4
164
+ %button.btn-block.btn-primary.btn(type="button" data-value="3") &#8226;
165
+
166
+ %br
167
+ .preview.row
168
+ .col-xs-9
169
+ %input.form-control(type="password" disabled="disabled")
170
+ .col-xs-3
171
+ %button.btn-block.btn-primary.btn.pin-del(type="button") &lt;
172
+
173
+ .modal-footer
174
+ %button.btn-block.btn.btn-success.done.pin-enter(type="button") Enter
175
+
176
+ .passphrase_dialog.modal.fade(role="dialog")
177
+ .modal-dialog
178
+ .modal-content
179
+ .modal-body
180
+ %h3 Enter Passphrase
181
+ %input#passphrase.form-control(type="password" placeholder="Password")
182
+ %br
183
+ %input#passphrase_confirmation.form-control(type="password" placeholder="Password confirmation")
184
+
185
+ .modal-footer
186
+ %button.btn-block.btn.btn-success.done.passphrase-enter(type="button") Enter
@@ -0,0 +1,5 @@
1
+ PochetteWeb::Engine.routes.draw do
2
+ get '/' => 'home#index'
3
+ post '/trezor_transaction_builder' => 'home#trezor_transaction_builder'
4
+ get '/make_multisig' => 'home#make_multisig'
5
+ end
@@ -0,0 +1,9 @@
1
+ require "pochette_web/engine"
2
+ require "haml"
3
+ require "twitter/bootstrap/rails/bootstrap"
4
+ require "jquery-rails"
5
+ require "pochette"
6
+ require "pochette_toshi"
7
+
8
+ module PochetteWeb
9
+ end
@@ -0,0 +1,5 @@
1
+ module PochetteWeb
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace PochetteWeb
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module PochetteWeb
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :pochette_web do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ module PochetteWeb
4
+ class HomeControllerTest < ActionController::TestCase
5
+ setup do
6
+ @routes = Engine.routes
7
+ end
8
+
9
+ # test "the truth" do
10
+ # assert true
11
+ # end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end