bip70 0.0.1

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: fff03405f55e878ae6263fa0f97cc1723ddc4716
4
+ data.tar.gz: 0a3d567209f5752cf8b71864f118330aefd78663
5
+ SHA512:
6
+ metadata.gz: cd32fef5974169c5542c06d0ef32c797ff7c4d6e4d6a07c6fc9fd86f6c9b6e34c785619eeb61572d572c7537cc009f3e9ff6a4adcc099ad266ab6ea5053bfcc3
7
+ data.tar.gz: dd87511605a193ebca47dfc85e557985136806dedea5d53b5180b90085a9de0212d2ee80f7b3c1210609f0d33a8ea77a65cbad4d4de8e7a7dd60b9949fd12464
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bip70.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Justin Litchfield
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Bip70
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bip70'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bip70
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/bip70/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'bip70'
7
+ ARGV.clear
8
+ IRB.start
9
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bip70/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bip70"
8
+ spec.version = Bip70::VERSION
9
+ spec.authors = ["Justin Litchfield"]
10
+ spec.email = ["j@obsidianexchange.com"]
11
+ spec.summary = %q{Ruby library for working with the BIP-0070 protocol}
12
+ spec.description = %q{Create bitcoin payment requests easily}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+
26
+ spec.add_dependency "ruby-protocol-buffers"
27
+ end
@@ -0,0 +1,5 @@
1
+ require "bip70/version"
2
+ require "bip70/payment_request"
3
+
4
+ module Bip70
5
+ end
@@ -0,0 +1,32 @@
1
+ require 'resources/paymentrequest.pb'
2
+
3
+ module Bip70
4
+ class PaymentRequestCreator
5
+ def self.run(outputs, merchant_data = '')
6
+ outputs = outputs.map{ |output|
7
+ Payments::Output.new(script: "#{output.fetch(:address)} OP_CHECKSIG", amount: output.fetch(:amount) { 0 })
8
+ }
9
+ payment_details = Payments::PaymentDetails.new(merchant_data: merchant_data, time: Time.now.to_i)
10
+
11
+ data = Payments::PaymentRequest.new(serialized_payment_details: payment_details.serialize_to_string)
12
+
13
+ wrap_in_headers(data)
14
+ end
15
+
16
+ private
17
+
18
+ def self.wrap_in_headers(data)
19
+ filename = "req-#{Time.now.to_f}.bitcoinpaymenetrequest"
20
+ output = <<-EOS
21
+ Content-Type: application/bitcoin-paymentrequest
22
+ Content-Disposition: inline; filename=#{filename}
23
+ Content-Transfer-Encoding: binary
24
+ Expires: 0
25
+ Cache-Control: must-revalidate, post-check=0, pre-check=0
26
+ Content-Length: #{data.serialize_to_string.length}
27
+ #{data.serialize_to_string}
28
+ EOS
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Bip70
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+
4
+ require 'protocol_buffers'
5
+
6
+ module Payments
7
+ # forward declarations
8
+ class Output < ::ProtocolBuffers::Message; end
9
+ class PaymentDetails < ::ProtocolBuffers::Message; end
10
+ class PaymentRequest < ::ProtocolBuffers::Message; end
11
+ class X509Certificates < ::ProtocolBuffers::Message; end
12
+ class Payment < ::ProtocolBuffers::Message; end
13
+ class PaymentACK < ::ProtocolBuffers::Message; end
14
+
15
+ class Output < ::ProtocolBuffers::Message
16
+ set_fully_qualified_name "payments.Output"
17
+
18
+ optional :uint64, :amount, 1, :default => 0
19
+ required :bytes, :script, 2
20
+ end
21
+
22
+ class PaymentDetails < ::ProtocolBuffers::Message
23
+ set_fully_qualified_name "payments.PaymentDetails"
24
+
25
+ optional :string, :network, 1, :default => "main"
26
+ repeated ::Payments::Output, :outputs, 2
27
+ required :uint64, :time, 3
28
+ optional :uint64, :expires, 4
29
+ optional :string, :memo, 5
30
+ optional :string, :payment_url, 6
31
+ optional :bytes, :merchant_data, 7
32
+ end
33
+
34
+ class PaymentRequest < ::ProtocolBuffers::Message
35
+ set_fully_qualified_name "payments.PaymentRequest"
36
+
37
+ optional :uint32, :payment_details_version, 1, :default => 1
38
+ optional :string, :pki_type, 2, :default => "none"
39
+ optional :bytes, :pki_data, 3
40
+ required :bytes, :serialized_payment_details, 4
41
+ optional :bytes, :signature, 5
42
+ end
43
+
44
+ class X509Certificates < ::ProtocolBuffers::Message
45
+ set_fully_qualified_name "payments.X509Certificates"
46
+
47
+ repeated :bytes, :certificate, 1
48
+ end
49
+
50
+ class Payment < ::ProtocolBuffers::Message
51
+ set_fully_qualified_name "payments.Payment"
52
+
53
+ optional :bytes, :merchant_data, 1
54
+ repeated :bytes, :transactions, 2
55
+ repeated ::Payments::Output, :refund_to, 3
56
+ optional :string, :memo, 4
57
+ end
58
+
59
+ class PaymentACK < ::ProtocolBuffers::Message
60
+ set_fully_qualified_name "payments.PaymentACK"
61
+
62
+ required ::Payments::Payment, :payment, 1
63
+ optional :string, :memo, 2
64
+ end
65
+
66
+ end
@@ -0,0 +1,46 @@
1
+ //
2
+ // Simple Bitcoin Payment Protocol messages
3
+ //
4
+ // Use fields 1000+ for extensions;
5
+ // to avoid conflicts, register extensions via pull-req at
6
+ // https://github.com/bitcoin/bips/bip-0070/extensions.mediawiki
7
+ //
8
+
9
+ package payments;
10
+ option java_package = "org.bitcoin.protocols.payments";
11
+ option java_outer_classname = "Protos";
12
+
13
+ // Generalized form of "send payment to this/these bitcoin addresses"
14
+ message Output {
15
+ optional uint64 amount = 1 [default = 0]; // amount is integer-number-of-satoshis
16
+ required bytes script = 2; // usually one of the standard Script forms
17
+ }
18
+ message PaymentDetails {
19
+ optional string network = 1 [default = "main"]; // "main" or "test"
20
+ repeated Output outputs = 2; // Where payment should be sent
21
+ required uint64 time = 3; // Timestamp; when payment request created
22
+ optional uint64 expires = 4; // Timestamp; when this request should be considered invalid
23
+ optional string memo = 5; // Human-readable description of request for the customer
24
+ optional string payment_url = 6; // URL to send Payment and get PaymentACK
25
+ optional bytes merchant_data = 7; // Arbitrary data to include in the Payment message
26
+ }
27
+ message PaymentRequest {
28
+ optional uint32 payment_details_version = 1 [default = 1];
29
+ optional string pki_type = 2 [default = "none"]; // none / x509+sha256 / x509+sha1
30
+ optional bytes pki_data = 3; // depends on pki_type
31
+ required bytes serialized_payment_details = 4; // PaymentDetails
32
+ optional bytes signature = 5; // pki-dependent signature
33
+ }
34
+ message X509Certificates {
35
+ repeated bytes certificate = 1; // DER-encoded X.509 certificate chain
36
+ }
37
+ message Payment {
38
+ optional bytes merchant_data = 1; // From PaymentDetails.merchant_data
39
+ repeated bytes transactions = 2; // Signed transactions that satisfy PaymentDetails.outputs
40
+ repeated Output refund_to = 3; // Where to send refunds, if a refund is necessary
41
+ optional string memo = 4; // Human-readable message for the merchant
42
+ }
43
+ message PaymentACK {
44
+ required Payment payment = 1; // Payment message that triggered this ACK
45
+ optional string memo = 2; // human-readable message for customer
46
+ }
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bip70::PaymentRequestCreator do
4
+ let(:outputs) { [{address: 'aoeusnth', amount: 100}] }
5
+
6
+ it "can create a paymentrequest" do
7
+ expect{ Bip70::PaymentRequestCreator.run(outputs) }.to_not raise_error
8
+ end
9
+
10
+ it "appends headers" do
11
+ request = Bip70::PaymentRequestCreator.run(outputs)
12
+ expect(request).to include("application/bitcoin-paymentrequest")
13
+ p request
14
+ end
15
+
16
+ end
@@ -0,0 +1,64 @@
1
+ require 'bip70'
2
+
3
+ #
4
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
5
+ RSpec.configure do |config|
6
+ # The settings below are suggested to provide a good initial experience
7
+ # with RSpec, but feel free to customize to your heart's content.
8
+ # These two settings work together to allow you to limit a spec run
9
+ # to individual examples or groups you care about by tagging them with
10
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
11
+ # get run.
12
+ config.filter_run :focus
13
+ config.run_all_when_everything_filtered = true
14
+
15
+ # Many RSpec users commonly either run the entire suite or an individual
16
+ # file, and it's useful to allow more verbose output when running an
17
+ # individual spec file.
18
+ if config.files_to_run.one?
19
+ # Use the documentation formatter for detailed output,
20
+ # unless a formatter has already been configured
21
+ # (e.g. via a command-line flag).
22
+ config.default_formatter = 'progress'
23
+ end
24
+
25
+ # Print the 10 slowest examples and example groups at the
26
+ # end of the spec run, to help surface which specs are running
27
+ # particularly slow.
28
+ # config.profile_examples = 10
29
+
30
+ # Run specs in random order to surface order dependencies. If you find an
31
+ # order dependency and want to debug it, you can fix the order by providing
32
+ # the seed, which is printed after each run.
33
+ # --seed 1234
34
+ config.order = :random
35
+
36
+ # Seed global randomization in this process using the `--seed` CLI option.
37
+ # Setting this allows you to use `--seed` to deterministically reproduce
38
+ # test failures related to randomization by passing the same `--seed` value
39
+ # as the one that triggered the failure.
40
+ Kernel.srand config.seed
41
+
42
+ # rspec-expectations config goes here. You can use an alternate
43
+ # assertion/expectation library such as wrong or the stdlib/minitest
44
+ # assertions if you prefer.
45
+ config.expect_with :rspec do |expectations|
46
+ # Enable only the newer, non-monkey-patching expect syntax.
47
+ # For more details, see:
48
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
49
+ expectations.syntax = :expect
50
+ end
51
+
52
+ # rspec-mocks config goes here. You can use an alternate test double
53
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
54
+ config.mock_with :rspec do |mocks|
55
+ # Enable only the newer, non-monkey-patching expect syntax.
56
+ # For more details, see:
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ mocks.syntax = :expect
59
+
60
+ # Prevents you from mocking or stubbing a method that does not exist on
61
+ # a real object. This is generally recommended.
62
+ mocks.verify_partial_doubles = true
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bip70
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Litchfield
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-protocol-buffers
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Create bitcoin payment requests easily
84
+ email:
85
+ - j@obsidianexchange.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bip70.gemspec
97
+ - lib/bip70.rb
98
+ - lib/bip70/payment_request.rb
99
+ - lib/bip70/version.rb
100
+ - lib/resources/paymentrequest.pb.rb
101
+ - lib/resources/paymentrequest.proto
102
+ - spec/payment_request_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.0
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Ruby library for working with the BIP-0070 protocol
128
+ test_files:
129
+ - spec/payment_request_spec.rb
130
+ - spec/spec_helper.rb
131
+ has_rdoc: