bcoin-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6876db8d74297101f7ef5390d33e5cc767f3a08
4
+ data.tar.gz: 2685d89a4404151f62da43c10a6122eb6c0cd726
5
+ SHA512:
6
+ metadata.gz: 88ade4d1a2930e92983f15d2a298f8cd6afce79fa2becfcfd97cf54222e01f2d4845d309534d4653e9132be32451d2a73aeec4bf970afbcec6fab006075bca07
7
+ data.tar.gz: a051953e56260071fed081575398c0ff6b01831373bbfade5ed9fa13050240e1d23bb428ab8e35650b0c1d78ac84227be91466744e41ebb5769d47ed45696c05
data/.env ADDED
@@ -0,0 +1,2 @@
1
+ BCOIN_API_KEY=bcoin-ruby
2
+ BCOIN_NETWORK=testnet
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /config/containers/bcoin/node_modules/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dknox@threedotloft.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bcoin-client.gemspec
6
+ gemspec
@@ -0,0 +1 @@
1
+ ./config/Guardfile
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dan Knox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,292 @@
1
+ # Bcoin::Client
2
+
3
+ [![Build Status](https://travis-ci.org/DanKnox-BitFS/bcoin-client.svg?branch=master)](https://travis-ci.org/DanKnox-BitFS/bcoin-client)
4
+
5
+ Ruby client for the [bcoin.io](http://bcoin.io) bitcoin node. This
6
+ client implements the HTTP wallet API methods. Perhaps one day I will
7
+ add a consumer for the WebSocket wallet events API.
8
+
9
+ This gem is developed and maintained by Dan Knox <dk@bitfs.us>.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'bcoin-client'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install bcoin-client
26
+
27
+ ## Usage
28
+
29
+ ```bash
30
+ $ console
31
+ ```
32
+
33
+ Initialize the client with your API key:
34
+
35
+ ```ruby
36
+ pry> client = Bcoin::Client.new password: 'bcoin-ruby'
37
+ => #<Bcoin::Client:0x007f85161b74c8 @options={:password=>"bcoin-ruby"}>
38
+ ```
39
+
40
+ Retrieve the full list of wallets or skip to ahead to learn how to find a
41
+ single wallet.
42
+ Refreshing the full list performs a GET for each individual
43
+ wallet so don't do this if you have a ton of wallets.
44
+
45
+ ```ruby
46
+ pry> client.wallets.refresh!
47
+ => #<Bcoin::Client::Wallets @collection=[...]>
48
+ ```
49
+
50
+ Lets find a wallet by id.
51
+
52
+ ```ruby
53
+ # You can also pass the :token parameter if wallet auth is on.
54
+ pry> wallet = client.wallets.find id: 'primary'
55
+ => #<Bcoin::Client::Wallet @attributes={
56
+ :network=>"main",
57
+ :wid=>1,
58
+ :id=>"primary",
59
+ :initialized=>true,
60
+ :watchOnly=>false,
61
+ :accountDepth=>1,
62
+ :token=>"87499ed1df632246b3a3b98222668b030d5b9ed3617833f9ec08683af20c0dfb",
63
+ :tokenDepth=>0,
64
+ :state=>{
65
+ "tx"=>0,
66
+ "coin"=>0,
67
+ "unconfirmed"=>0,
68
+ "confirmed"=>0
69
+ },
70
+ :master=>{
71
+ "encrypted"=>false
72
+ },
73
+ :account=>{
74
+ "name"=>"default",
75
+ "initialized"=>true,
76
+ "witness"=>false,
77
+ "watchOnly"=>false,
78
+ "type"=>"pubkeyhash",
79
+ "m"=>1, "n"=>1,
80
+ "accountIndex"=>0,
81
+ "receiveDepth"=>1,
82
+ "changeDepth"=>1,
83
+ "nestedDepth"=>0,
84
+ "lookahead"=>10,
85
+ "receiveAddress"=>"14Uk3qcs8RNxeprNunzNbunFXn6AbWHJBF",
86
+ "nestedAddress"=>nil,
87
+ "changeAddress"=>"1n5KTQbqcwcpuLfw47YFQwmyyM5Lgmbcd",
88
+ "accountKey"=>"xpub6CuW3mzkvLHFZtNPGs3xN8tJCF8AighD7RjtPqTS6dwQay8iMqFguQuYC6cHXKYeBTM5qEofMDJ3CsgXwr59Se2HeBS3PoYYtRVySbaMvVX",
89
+ "keys"=>[]
90
+ }
91
+ }>
92
+ ```
93
+
94
+ Now we can retrieve this wallet's master key.
95
+
96
+ ```ruby
97
+ pry> wallet.master
98
+ => #<Bcoin::Client::Master @attributes={
99
+ :encrypted=>false,
100
+ :key=>{
101
+ "xprivkey"=>"xprv9s21ZrQH143K3VfDtnoq7BMDhh8JGwytkEfztoXfgoJUgLsWAisFTtZssbhh41JEN7BWtuLQeWdRyn4tQo4Wcc5xQYkoZNZ42RLCHUErCrN"},
102
+ :mnemonic=>{
103
+ "bits"=>128,
104
+ "language"=>"english",
105
+ "entropy"=>"46df98f5245d73bd707694d8b3b666d8",
106
+ "phrase"=>"egg wolf diary emerge strong team scrub spoon suffer oval often ramp",
107
+ "passphrase"=>""
108
+ }
109
+ }
110
+ }>
111
+ ```
112
+
113
+ Create a new wallet:
114
+
115
+ ```ruby
116
+ pry> wallet = client.wallets.create id: 'dan', type: :pubkeyhash
117
+ => #<Bcoin::Client::Wallet @attributes={
118
+ :network=>"main",
119
+ :wid=>2,
120
+ :id=>"dan",
121
+ :initialized=>true, :watchOnly=>false, :accountDepth=>1,
122
+ :token=>"1b7e6fb0a94e3432cafe6fbe58c057ac2d6c0048650769c45ecd551eb39ba003",
123
+ :tokenDepth=>0,
124
+ :state=>{
125
+ "tx"=>0, "coin"=>0,
126
+ "unconfirmed"=>0,
127
+ "confirmed"=>0
128
+ },
129
+ :master=>{"encrypted"=>false},
130
+ :account=>{
131
+ "name"=>"default",
132
+ "initialized"=>true,
133
+ "witness"=>false,
134
+ "watchOnly"=>false,
135
+ "type"=>"pubkeyhash",
136
+ "m"=>1, "n"=>1,
137
+ "accountIndex"=>0, "receiveDepth"=>1, "changeDepth"=>1,
138
+ "nestedDepth"=>0, "lookahead"=>10,
139
+ "receiveAddress"=>"1LYEVNtioaiVkkhpJgPA4m5hAitpXFSeNc",
140
+ "nestedAddress"=>nil,
141
+ "changeAddress"=>"1N17f1HExuPvcyB4cUZcRPGmHHCSN7J9Uf",
142
+ "accountKey"=>"xpub6DPi9Arcao3wG8oBBuGH4okiCQhifqwgZ86jnJJioqjeShe7MMhqE4Ykfe2YmBzD3Kto7vrszH9scYxGGShTJWjkCQfPWYH5rCDtaLJvqRv",
143
+ "keys"=>[]
144
+ }
145
+ }>
146
+ ```
147
+
148
+ When the wallet is created without a passphrase, it's master key should be
149
+ unencrypted when retrieved.
150
+
151
+ ```ruby
152
+ pry> wallet.master
153
+ => #<Bcoin::Client::Master @attributes={
154
+ :encrypted=>false,
155
+ :key=>{
156
+ "xprivkey"=>"xprv9s21ZrQH143K4VDn4ZZH9b1u3vbDGFesKy6g8uLqjsmwUiLwcsNusyHDzeVjQgdBfwNPfL5Fjgk13WNkuFL68LskGbDGn29nwcgYhZwviWc"},
157
+ :mnemonic=>{
158
+ "bits"=>128,
159
+ "language"=>"english",
160
+ "entropy"=>"09f479f97e705138b78233880985b4da",
161
+ "phrase"=>"antique phrase layer woman agree ordinary task edit marine equip honey relax",
162
+ "passphrase"=>""
163
+ }
164
+ }
165
+ }>
166
+ ```
167
+
168
+ Lets go ahead and set a passphrase on this wallet.
169
+
170
+ ```ruby
171
+ pry> wallet.passphrase new: 'testpass'
172
+ => true
173
+ ```
174
+
175
+ Now lets lock the wallet master key.
176
+
177
+ ```ruby
178
+ pry> wallet.lock
179
+ => true
180
+ ```
181
+
182
+ With the wallet locked, the master key will now be returned encrypted.
183
+
184
+ ```ruby
185
+ pry> wallet.master.refresh!
186
+ #<Bcoin::Client::Master @attributes={
187
+ :encrypted=>true,
188
+ :until=>0,
189
+ :iv=>"ac51c8e4c2251ca0e3a8d32f282fa829",
190
+ :ciphertext=>"4ce1c061359564c1e0e47e500cf44cb7271880129e86c03adec0986b85b714dbd5983afc4a77b93dd068f275bacc5b8493b454aee3ffbf2ccd40b527bd8176fa9ce5ae1d41e153d15ed18081478610d55e1470cc8d2267c88a82e5eb5af5af6e94178fd7f9efeb2aa334e7893c7e1094342d471c157873a80a99a0831b417847ccbafa16aa59d75cf79f487508687092002f2c15a682163cb6173d907ff4a6036958e3fb3604a035527ea4c5b4d2c6965dd275e42d3e2f7406c1f7621bcf4619",
191
+ :algorithm=>"pbkdf2",
192
+ :N=>50000,
193
+ :r=>0,
194
+ :p=>0
195
+ }>
196
+ ```
197
+
198
+ We can unlock the wallet for a number of seconds to perform sensitive operations.
199
+
200
+ ```ruby
201
+ pry> wallet.unlock passphrase: 'testpass', timeout: 60
202
+ => true
203
+ ```
204
+
205
+ With the wallet unlocked, we can now retrieve the private key and plain text mnemonic.
206
+
207
+ ```ruby
208
+ pry> wallet.master.refresh!
209
+ => #<Bcoin::Client::Master @attributes={
210
+ :encrypted=>false,
211
+ :key=>{
212
+ "xprivkey"=>"xprv9s21ZrQH143K4VDn4ZZH9b1u3vbDGFesKy6g8uLqjsmwUiLwcsNusyHDzeVjQgdBfwNPfL5Fjgk13WNkuFL68LskGbDGn29nwcgYhZwviWc"},
213
+ :mnemonic=>{
214
+ "bits"=>128,
215
+ "language"=>"english",
216
+ "entropy"=>"09f479f97e705138b78233880985b4da",
217
+ "phrase"=>"antique phrase layer woman agree ordinary task edit marine equip honey relax",
218
+ "passphrase"=>""
219
+ }
220
+ }>
221
+ ```
222
+
223
+ Finally, lets go ahead and send a transaction.
224
+
225
+ ```ruby
226
+ pry> wallet.send rate: 0.0003, outputs: [{value: 1.5, address: '1LYEVNtioaiVkkhpJgPA4m5hAitpXFSeNc'}]
227
+ => {
228
+ {
229
+ "wid": 2,
230
+ "id": "dan",
231
+ "hash": "d9c7526b00f6d563200f685e6e229f0b41982153502467497153f7f466bd46d2",
232
+ "height": -1,
233
+ "block": null,
234
+ "ts": 0,
235
+ "ps": 1502837803,
236
+ "date": "2017-08-15T22:56:43Z",
237
+ "index": -1,
238
+ "size": 225,
239
+ "virtualSize": 225,
240
+ "fee": 4540,
241
+ "rate": 20177,
242
+ "confirmations": 0,
243
+ "inputs": [
244
+ {
245
+ "value": 5000000000,
246
+ "address": "RMKoN2RDoNMCvGKx2xigLezsDHBVV2WQ77",
247
+ "path": {
248
+ "name": "default",
249
+ "account": 0,
250
+ "change": false,
251
+ "derivation": "m/0'/0/0"
252
+ }
253
+ }
254
+ ],
255
+ "outputs": [
256
+ {
257
+ "value": 500000000,
258
+ "address": "RW6vfe34Qz3d6SmS3cnnQ2VyhQr6whWxpa",
259
+ "path": null
260
+ },
261
+ {
262
+ "value": 4499995460,
263
+ "address": "RWFa7WXvhnc6GWeFhDUHAR38CYarWaMw9S",
264
+ "path": {
265
+ "name": "default",
266
+ "account": 0,
267
+ "change": true,
268
+ "derivation": "m/0'/1/0"
269
+ }
270
+ }
271
+ ],
272
+ "tx": "0100000001659a478b1eb89bc5df48cd3a641d7996a644e2b05138a5e85c6483b9add9d4b0000000006a4730440220787987deb06a23e03b969abe8a95489aea604c1f5ff38657c40ced41b80b166102204d84297cf720344fa4f2119b8bd43b206b811a0fd535c24dcc80140eab0d0788012102354eb584896a4a2aea9729d0eff420f73193b8de6c55bdf6e6857cfede22ffbcffffffff020065cd1d000000001976a914e4699de8892b8623e1f87700fabc53470f698adc88ac447b380c010000001976a914e60c33f1d0c47fe550c33de373f0af79a58e788988ac00000000"
273
+ }>
274
+ ```
275
+
276
+ ## Development
277
+
278
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
279
+
280
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
281
+
282
+ ## Contributing
283
+
284
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DanKnox/bcoin-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
285
+
286
+ ## License
287
+
288
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
289
+
290
+ ## Code of Conduct
291
+
292
+ Everyone interacting in the Bcoin::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/DanKnox/bcoin-client/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bcoin/client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bcoin-client"
8
+ spec.version = Bcoin::Client::VERSION
9
+ spec.authors = ["Dan Knox"]
10
+ spec.email = ["dknox@threedotloft.com"]
11
+
12
+ spec.summary = %q{Client for the bcoin.io bitcoin node.}
13
+ spec.description = %q{Client for the bcoin.io bitcoin node including their wallet API.}
14
+ spec.homepage = "http://github.com/DanKnox-BitFS/bcoin-ruby"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
37
+ spec.add_development_dependency "pry", "~> 0.10"
38
+ spec.add_development_dependency "pry-doc", "~> 0.11"
39
+ spec.add_dependency "httparty", "~> 0.15"
40
+ end