block_io 2.0.0 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{.appveyor.yml → .appveyor.yml-disabled} +2 -2
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/LICENSE +1 -1
- data/README.md +18 -14
- data/block_io.gemspec +7 -7
- data/examples/basic.rb +29 -5
- data/examples/dtrust.rb +43 -24
- data/examples/sweeper.rb +21 -16
- data/lib/block_io/api_exception.rb +11 -0
- data/lib/block_io/chainparams/BTC.yml +8 -0
- data/lib/block_io/chainparams/BTCTEST.yml +8 -0
- data/lib/block_io/chainparams/DOGE.yml +8 -0
- data/lib/block_io/chainparams/DOGETEST.yml +8 -0
- data/lib/block_io/chainparams/LTC.yml +8 -0
- data/lib/block_io/chainparams/LTCTEST.yml +8 -0
- data/lib/block_io/client.rb +145 -80
- data/lib/block_io/extended_bitcoinrb.rb +132 -0
- data/lib/block_io/helper.rb +211 -53
- data/lib/block_io/key.rb +11 -124
- data/lib/block_io/version.rb +1 -1
- data/lib/block_io.rb +3 -2
- data/spec/client_misc_spec.rb +76 -0
- data/spec/client_spec.rb +23 -178
- data/spec/dtrust_spec.rb +167 -0
- data/spec/helper_spec.rb +117 -7
- data/spec/key_spec.rb +50 -19
- data/spec/larger_transaction_spec.rb +371 -0
- data/spec/sweep_spec.rb +115 -0
- data/spec/test-cases/.gitignore +2 -0
- data/spec/test-cases/LICENSE +21 -0
- data/spec/test-cases/README.md +2 -0
- data/spec/test-cases/json/create_and_sign_transaction_response.json +61 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_P2WSH-over-P2SH_1of2_251inputs.json +1261 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_P2WSH-over-P2SH_1of2_252inputs.json +1266 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_P2WSH-over-P2SH_1of2_253inputs.json +1271 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_P2WSH-over-P2SH_1of2_762inputs.json +3816 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2SH_3of5_195inputs.json +2931 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2SH_4of5_195inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_3of5_251inputs.json +3771 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_3of5_252inputs.json +3786 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_3of5_253inputs.json +3801 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_4of5_251inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_4of5_252inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_P2WSH-over-P2SH_4of5_253inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_3of5_251inputs.json +3771 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_3of5_252inputs.json +3786 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_3of5_253inputs.json +3801 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_4of5_251inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_4of5_252inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_WITNESS_V0_4of5_253inputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2sh_3_of_5_keys.json +21 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2sh_4_of_5_keys.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_3_of_5_keys.json +21 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_4_of_5_keys.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3_of_5_keys.json +36 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3of5_251outputs.json +591 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3of5_252outputs.json +576 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3of5_253outputs.json +531 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4_of_5_keys.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4of5_251outputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4of5_252outputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4of5_253outputs.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_sweep_p2pkh.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_sweep_p2wpkh.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_sweep_p2wpkh_over_p2sh.json +5 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json +21 -0
- data/spec/test-cases/json/create_and_sign_transaction_response_witness_v1_output.json +11 -0
- data/spec/test-cases/json/get_balance_response.json +8 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2SH_3of5_195inputs.json +1397 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2SH_4of5_195inputs.json +1397 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_3of5_251inputs.json +1795 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_3of5_252inputs.json +1802 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_3of5_253inputs.json +1809 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_4of5_251inputs.json +1789 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_4of5_252inputs.json +1802 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_P2WSH-over-P2SH_4of5_253inputs.json +1809 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_3of5_251inputs.json +1795 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_3of5_252inputs.json +1802 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_3of5_253inputs.json +1809 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_4of5_251inputs.json +1795 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_4of5_252inputs.json +1802 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_WITNESS_V0_4of5_253inputs.json +1809 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_p2sh.json +45 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_p2wsh_over_p2sh.json +45 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0.json +52 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_3of5_251outputs.json +1805 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_3of5_252outputs.json +1804 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_3of5_253outputs.json +1789 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_4of5_251outputs.json +1805 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_4of5_252outputs.json +1804 -0
- data/spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0_4of5_253outputs.json +1789 -0
- data/spec/test-cases/json/prepare_sweep_transaction_response_p2pkh.json +35 -0
- data/spec/test-cases/json/prepare_sweep_transaction_response_p2wpkh.json +35 -0
- data/spec/test-cases/json/prepare_sweep_transaction_response_p2wpkh_over_p2sh.json +35 -0
- data/spec/test-cases/json/prepare_transaction_response.json +164 -0
- data/spec/test-cases/json/prepare_transaction_response_P2WSH-over-P2SH_1of2_251inputs.json +1796 -0
- data/spec/test-cases/json/prepare_transaction_response_P2WSH-over-P2SH_1of2_252inputs.json +1803 -0
- data/spec/test-cases/json/prepare_transaction_response_P2WSH-over-P2SH_1of2_253inputs.json +1810 -0
- data/spec/test-cases/json/prepare_transaction_response_P2WSH-over-P2SH_1of2_762inputs.json +5367 -0
- data/spec/test-cases/json/prepare_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json +76 -0
- data/spec/test-cases/json/prepare_transaction_response_witness_v1_output.json +64 -0
- data/spec/test-cases/json/summarize_prepared_transaction_response_with_blockio_fee_and_expected_unsigned_txid.json +6 -0
- metadata +203 -57
- data/examples/max_withdrawal.rb +0 -29
- data/lib/block_io/constants.rb +0 -10
- data/spec/data/sign_and_finalize_dtrust_withdrawal_request.json +0 -1
- data/spec/data/sign_and_finalize_sweep_request.json +0 -1
- data/spec/data/sign_and_finalize_withdrawal_request.json +0 -4
- data/spec/data/sweep_from_address_response.json +0 -1
- data/spec/data/withdraw_from_dtrust_address_response.json +0 -1
- data/spec/data/withdraw_response.json +0 -1227
- data/spec/rfc6979_spec.rb +0 -59
- data/spec/withdraw_spec.rb +0 -90
data/spec/client_spec.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
|
2
|
-
describe "Client.withdraw" do
|
1
|
+
describe "Client.prepare_transaction" do
|
3
2
|
|
4
3
|
before(:each) do
|
5
|
-
|
6
4
|
@api_key = "0000-0000-0000-0000"
|
7
|
-
@req_params = {:
|
5
|
+
@req_params = {:to_address => "QTLcyTFrH7T6kqUsi1VV2mJVXmX3AmwUNH", :amounts => "0.248"}
|
8
6
|
@headers = {
|
9
7
|
'Accept' => 'application/json',
|
10
8
|
'Connection' => 'Keep-Alive',
|
@@ -13,211 +11,58 @@ describe "Client.withdraw" do
|
|
13
11
|
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
14
12
|
}
|
15
13
|
|
16
|
-
@
|
17
|
-
@stub1 = stub_request(:post, "https://block.io/api/v2/
|
14
|
+
@prepare_transaction_response = File.new("spec/test-cases/json/prepare_transaction_response.json").read
|
15
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_transaction").
|
18
16
|
with(
|
19
17
|
body: @req_params.merge({:api_key => @api_key}).to_json,
|
20
|
-
headers: @headers
|
21
|
-
)
|
22
|
-
to_return(status: 200, body: @withdraw_response, headers: {})
|
23
|
-
|
24
|
-
@sign_and_finalize_withdrawal_request = Oj.dump(Oj.load_file("spec/data/sign_and_finalize_withdrawal_request.json"))
|
25
|
-
@success_response = Oj.dump({"status" => "success", "data" => {"network" => "random", "txid" => "random"}})
|
26
|
-
@stub2 = stub_request(:post, "https://block.io/api/v2/sign_and_finalize_withdrawal").
|
27
|
-
with(
|
28
|
-
body: @sign_and_finalize_withdrawal_request,
|
29
|
-
headers: @headers
|
30
|
-
).to_return(status: 200, body: @success_response, headers: {})
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context "pin" do
|
18
|
+
headers: @headers).
|
19
|
+
to_return(status: 200, body: @prepare_transaction_response, headers: {})
|
35
20
|
|
36
|
-
|
37
|
-
|
38
|
-
@blockio = BlockIo::Client.new(:api_key => @api_key, :pin => "blockiotestpininsecure", :version => 2, :use_low_r => false)
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
it "success" do
|
43
|
-
|
44
|
-
@blockio.withdraw(@req_params)
|
45
|
-
|
46
|
-
expect(@stub1).to have_been_requested.times(1)
|
47
|
-
expect(@stub2).to have_been_requested.times(1)
|
48
|
-
|
49
|
-
end
|
21
|
+
@create_and_sign_transaction_response = File.new("spec/test-cases/json/create_and_sign_transaction_response.json").read
|
50
22
|
|
23
|
+
@insecure_pin_valid = "d1650160bd8d2bb32bebd139d0063eb6063ffa2f9e4501ad" # still insecure, don't use this!
|
24
|
+
@insecure_pin_invalid = "blockiotestpininsecure"
|
51
25
|
end
|
52
|
-
|
53
|
-
context "key" do
|
54
|
-
|
55
|
-
before(:each) do
|
56
26
|
|
57
|
-
|
58
|
-
@key = BlockIo::Helper.extractKey(Oj.load(@withdraw_response)["data"]["encrypted_passphrase"]["passphrase"], @encryption_key, false)
|
27
|
+
context "pin_valid" do
|
59
28
|
|
60
|
-
|
29
|
+
before(:each) do
|
61
30
|
|
31
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key, :pin => @insecure_pin_valid)
|
32
|
+
|
62
33
|
end
|
63
34
|
|
64
35
|
it "success" do
|
65
36
|
|
66
|
-
@blockio.
|
37
|
+
@blockio.prepare_transaction(@req_params)
|
67
38
|
|
68
39
|
expect(@stub1).to have_been_requested.times(1)
|
69
|
-
expect(@stub2).to have_been_requested.times(1)
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
40
|
|
77
|
-
|
78
|
-
|
79
|
-
before(:each) do
|
80
|
-
|
81
|
-
@api_key = "0000-0000-0000-0000"
|
82
|
-
@wif = "cTYLVcC17cYYoRjaBu15rEcD5WuDyowAw562q2F1ihcaomRJENu5"
|
83
|
-
@key = BlockIo::Key.from_wif(@wif)
|
84
|
-
@req_params = {:to_address => "QhSWVppS12Fqv6dh3rAyoB18jXh5mB1hoC", :from_address => "tltc1qpygwklc39wl9p0wvlm0p6x42sh9259xdjl059s", :public_key => @key.public_key}
|
85
|
-
@headers = {
|
86
|
-
'Accept' => 'application/json',
|
87
|
-
'Connection' => 'Keep-Alive',
|
88
|
-
'Content-Type' => 'application/json; charset=UTF-8',
|
89
|
-
'Host' => 'block.io',
|
90
|
-
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
91
|
-
}
|
41
|
+
expect(@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_transaction_response))).to eq(Oj.safe_load(@create_and_sign_transaction_response))
|
92
42
|
|
93
|
-
|
94
|
-
@stub1 = stub_request(:post, "https://block.io/api/v2/sweep_from_address").
|
95
|
-
with(
|
96
|
-
body: @req_params.merge({:api_key => @api_key}).to_json,
|
97
|
-
headers: @headers
|
98
|
-
).
|
99
|
-
to_return(status: 200, body: @sweep_from_address_response, headers:{})
|
100
|
-
|
101
|
-
@sign_and_finalize_sweep_request = Oj.dump(Oj.load_file("spec/data/sign_and_finalize_sweep_request.json"))
|
102
|
-
@success_response = Oj.dump({"status" => "success", "data" => {"network" => "random", "txid" => "random"}})
|
103
|
-
@stub2 = stub_request(:post, "https://block.io/api/v2/sign_and_finalize_sweep").
|
104
|
-
with(
|
105
|
-
body: @sign_and_finalize_sweep_request,
|
106
|
-
headers: @headers
|
107
|
-
).to_return(status: 200, body: @success_response, headers: {})
|
43
|
+
end
|
108
44
|
|
109
45
|
end
|
110
46
|
|
111
|
-
context "
|
47
|
+
context "pin_invalid" do
|
112
48
|
|
113
49
|
before(:each) do
|
114
50
|
|
115
|
-
@blockio = BlockIo::Client.new(:api_key => @api_key, :
|
116
|
-
|
51
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key, :pin => @insecure_pin_invalid)
|
52
|
+
|
117
53
|
end
|
118
54
|
|
119
|
-
it "
|
55
|
+
it "fails" do
|
120
56
|
|
121
|
-
@blockio.
|
57
|
+
@blockio.prepare_transaction(@req_params)
|
122
58
|
|
123
59
|
expect(@stub1).to have_been_requested.times(1)
|
124
|
-
expect(@stub2).to have_been_requested.times(1)
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
60
|
|
132
|
-
|
133
|
-
|
134
|
-
before(:each) do
|
135
|
-
|
136
|
-
@api_key = "0000-0000-0000-0000"
|
137
|
-
@req_params = {:from_address => "tltc1q8y9naxlsw7xay4jesqshnpeuc0ap8fg9ejm2j2memwq4ng87dk3s88nr5j", :to_addresses => "QhSWVppS12Fqv6dh3rAyoB18jXh5mB1hoC", :amounts => "0.09"}
|
138
|
-
@headers = {
|
139
|
-
'Accept' => 'application/json',
|
140
|
-
'Connection' => 'Keep-Alive',
|
141
|
-
'Content-Type' => 'application/json; charset=UTF-8',
|
142
|
-
'Host' => 'block.io',
|
143
|
-
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
144
|
-
}
|
145
|
-
|
146
|
-
@keys = [
|
147
|
-
BlockIo::Key.new("b515fd806a662e061b488e78e5d0c2ff46df80083a79818e166300666385c0a2", false), # alpha1alpha2alpha3alpha4
|
148
|
-
BlockIo::Key.new("1584b821c62ecdc554e185222591720d6fe651ed1b820d83f92cdc45c5e21f", false), # alpha2alpha3alpha4alpha1
|
149
|
-
BlockIo::Key.new("2f9090b8aa4ddb32c3b0b8371db1b50e19084c720c30db1d6bb9fcd3a0f78e61", false), # alpha3alpha4alpha1alpha2
|
150
|
-
BlockIo::Key.new("6c1cefdfd9187b36b36c3698c1362642083dcc1941dc76d751481d3aa29ca65", false) # alpha4alpha1alpha2alpha3
|
151
|
-
].freeze
|
152
|
-
|
153
|
-
@withdraw_from_dtrust_address_response = File.new("spec/data/withdraw_from_dtrust_address_response.json", "r").read
|
154
|
-
@stub1 = stub_request(:post, "https://block.io/api/v2/withdraw_from_dtrust_address").
|
155
|
-
with(
|
156
|
-
body: @req_params.merge({:api_key => @api_key}).to_json,
|
157
|
-
headers: @headers
|
158
|
-
).
|
159
|
-
to_return(status: 200, body: @withdraw_from_dtrust_address_response, headers: {})
|
160
|
-
|
161
|
-
@sign_and_finalize_dtrust_withdrawal_request = Oj.dump(Oj.load_file("spec/data/sign_and_finalize_dtrust_withdrawal_request.json"))
|
162
|
-
@success_response = Oj.dump({"status" => "success", "data" => {"network" => "random", "txid" => "random"}})
|
163
|
-
@stub2 = stub_request(:post, "https://block.io/api/v2/sign_and_finalize_withdrawal").
|
164
|
-
with(
|
165
|
-
body: @sign_and_finalize_dtrust_withdrawal_request,
|
166
|
-
headers: @headers
|
167
|
-
).to_return(status: 200, body: @success_response, headers: {})
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
context "without_keys_at_init" do
|
172
|
-
|
173
|
-
before(:each) do
|
174
|
-
|
175
|
-
@blockio = BlockIo::Client.new(:api_key => @api_key, :version => 2, :use_low_r => false)
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
it "only_required_signatures" do
|
180
|
-
|
181
|
-
@response = @blockio.withdraw_from_dtrust_address(@req_params)
|
182
|
-
|
183
|
-
BlockIo::Helper.signData(@response["data"]["inputs"], @keys)
|
184
|
-
only_required_signatures = @response["data"]["inputs"].map{|input| input["signers"].map{|s| (s["signed_data"].nil? ? 0 : 1)}.inject(:+) == input["signatures_needed"]}.all?{|x| x}
|
185
|
-
|
186
|
-
expect(@stub1).to have_been_requested.times(1)
|
187
|
-
expect(only_required_signatures).to eq(true)
|
61
|
+
expect { @blockio.create_and_sign_transaction(Oj.safe_load(@prepare_transaction_response)) }.to raise_error(Exception, "Invalid Secret PIN provided.")
|
188
62
|
|
189
63
|
end
|
190
64
|
|
191
|
-
it "success" do
|
192
|
-
|
193
|
-
@response = @blockio.withdraw_from_dtrust_address(@req_params)
|
194
|
-
|
195
|
-
BlockIo::Helper.signData(@response["data"]["inputs"], @keys)
|
196
|
-
|
197
|
-
@blockio.sign_and_finalize_withdrawal({:signature_data => @response["data"]})
|
198
|
-
|
199
|
-
expect(@stub1).to have_been_requested.times(1)
|
200
|
-
expect(@stub2).to have_been_requested.times(1)
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
65
|
end
|
205
66
|
|
206
|
-
context "with_keys_at_init" do
|
207
|
-
|
208
|
-
before(:each) do
|
209
|
-
@blockio = BlockIo::Client.new(:api_key => @api_key, :keys => @keys, :version => 2, :use_low_r => false)
|
210
|
-
end
|
211
|
-
|
212
|
-
it "success" do
|
213
|
-
|
214
|
-
@blockio.withdraw_from_dtrust_address(@req_params)
|
215
|
-
|
216
|
-
expect(@stub1).to have_been_requested.times(1)
|
217
|
-
expect(@stub2).to have_been_requested.times(1)
|
218
|
-
|
219
|
-
end
|
220
|
-
|
221
|
-
end
|
222
|
-
|
223
67
|
end
|
68
|
+
|
data/spec/dtrust_spec.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
describe "Client.prepare_dtrust_transaction" do
|
2
|
+
|
3
|
+
before(:each) do
|
4
|
+
@api_key = "0000-0000-0000-0000"
|
5
|
+
@private_keys = ["b515fd806a662e061b488e78e5d0c2ff46df80083a79818e166300666385c0a2",
|
6
|
+
"1584b821c62ecdc554e185222591720d6fe651ed1b820d83f92cdc45c5e21f",
|
7
|
+
"2f9090b8aa4ddb32c3b0b8371db1b50e19084c720c30db1d6bb9fcd3a0f78e61",
|
8
|
+
"6c1cefdfd9187b36b36c3698c1362642083dcc1941dc76d751481d3aa29ca65"]
|
9
|
+
@to_address = "QcnYiN3t3foHxHv7CnqXrmRoiMkADhapZw"
|
10
|
+
@amount = "0.00020000"
|
11
|
+
@headers = {
|
12
|
+
'Accept' => 'application/json',
|
13
|
+
'Connection' => 'Keep-Alive',
|
14
|
+
'Content-Type' => 'application/json; charset=UTF-8',
|
15
|
+
'Host' => 'block.io',
|
16
|
+
'User-Agent' => "gem:block_io:#{BlockIo::VERSION}"
|
17
|
+
}
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "p2sh" do
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
|
25
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key)
|
26
|
+
@from_address = "QZVSzPeaEJxB9bYuDEL7iWrHSdGbAP3pXV"
|
27
|
+
@prepare_dtrust_transaction_response_p2sh = File.new("spec/test-cases/json/prepare_dtrust_transaction_response_p2sh.json").read
|
28
|
+
@req_params = {:from_address => @from_address, :amount => @amount, :to_address => @to_address}
|
29
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_dtrust_transaction").
|
30
|
+
with(
|
31
|
+
body: @req_params.merge({:api_key => @api_key}).to_json,
|
32
|
+
headers: @headers).
|
33
|
+
to_return(status: 200, body: @prepare_dtrust_transaction_response_p2sh, headers: {})
|
34
|
+
|
35
|
+
@create_and_sign_transaction_response_dtrust_p2sh_3_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2sh_3_of_5_keys.json").read
|
36
|
+
@create_and_sign_transaction_response_dtrust_p2sh_4_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2sh_4_of_5_keys.json").read
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "3_of_5_keys" do
|
41
|
+
it "success" do
|
42
|
+
|
43
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
44
|
+
|
45
|
+
expect(@stub1).to have_been_requested.times(1)
|
46
|
+
|
47
|
+
expect(
|
48
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_p2sh), @private_keys.first(3))
|
49
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_p2sh_3_of_5_keys))
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "4_of_5_keys" do
|
55
|
+
it "success" do
|
56
|
+
|
57
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
58
|
+
|
59
|
+
expect(@stub1).to have_been_requested.times(1)
|
60
|
+
|
61
|
+
expect(@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_p2sh), @private_keys)).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_p2sh_4_of_5_keys))
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
context "p2wsh_over_p2sh" do
|
69
|
+
|
70
|
+
before(:each) do
|
71
|
+
|
72
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key)
|
73
|
+
@from_address = "Qg1QzgjUDkwaHeT7Yznuyu2V1keJieDVAF"
|
74
|
+
@prepare_dtrust_transaction_response_p2wsh_over_p2sh = File.new("spec/test-cases/json/prepare_dtrust_transaction_response_p2wsh_over_p2sh.json").read
|
75
|
+
@req_params = {:from_address => @from_address, :amount => @amount, :to_address => @to_address}
|
76
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_dtrust_transaction").
|
77
|
+
with(
|
78
|
+
body: @req_params.merge({:api_key => @api_key}).to_json,
|
79
|
+
headers: @headers).
|
80
|
+
to_return(status: 200, body: @prepare_dtrust_transaction_response_p2wsh_over_p2sh, headers: {})
|
81
|
+
|
82
|
+
@create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_3_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_3_of_5_keys.json").read
|
83
|
+
@create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_4_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_4_of_5_keys.json").read
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
context "3_of_5_keys" do
|
88
|
+
it "success" do
|
89
|
+
|
90
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
91
|
+
|
92
|
+
expect(@stub1).to have_been_requested.times(1)
|
93
|
+
|
94
|
+
expect(
|
95
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_p2wsh_over_p2sh), @private_keys.first(3))
|
96
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_3_of_5_keys))
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "4_of_5_keys" do
|
102
|
+
it "success" do
|
103
|
+
|
104
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
105
|
+
|
106
|
+
expect(@stub1).to have_been_requested.times(1)
|
107
|
+
|
108
|
+
expect(
|
109
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_p2wsh_over_p2sh), @private_keys)
|
110
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_p2wsh_over_p2sh_4_of_5_keys))
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
context "witness_v0" do
|
118
|
+
|
119
|
+
before(:each) do
|
120
|
+
|
121
|
+
@blockio = BlockIo::Client.new(:api_key => @api_key)
|
122
|
+
@from_address = "tltc1qtvscupcwnlsykujp98y0jhf8s4x48mzrr3v8v822ytg6vmprvzaqj8jd0h"
|
123
|
+
@prepare_dtrust_transaction_response_witness_v0 = File.new("spec/test-cases/json/prepare_dtrust_transaction_response_witness_v0.json").read
|
124
|
+
@req_params = {:from_address => @from_address, :amount => @amount, :to_address => @to_address}
|
125
|
+
@stub1 = stub_request(:post, "https://block.io/api/v2/prepare_dtrust_transaction").
|
126
|
+
with(
|
127
|
+
body: @req_params.merge({:api_key => @api_key}).to_json,
|
128
|
+
headers: @headers).
|
129
|
+
to_return(status: 200, body: @prepare_dtrust_transaction_response_witness_v0, headers: {})
|
130
|
+
|
131
|
+
@create_and_sign_transaction_response_dtrust_witness_v0_3_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_3_of_5_keys.json").read
|
132
|
+
@create_and_sign_transaction_response_dtrust_witness_v0_4_of_5_keys = File.new("spec/test-cases/json/create_and_sign_transaction_response_dtrust_witness_v0_4_of_5_keys.json").read
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
context "3_of_5_keys" do
|
137
|
+
it "success" do
|
138
|
+
|
139
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
140
|
+
|
141
|
+
expect(@stub1).to have_been_requested.times(1)
|
142
|
+
|
143
|
+
expect(
|
144
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_witness_v0), @private_keys.first(3))
|
145
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_witness_v0_3_of_5_keys))
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "4_of_5_keys" do
|
151
|
+
it "success" do
|
152
|
+
|
153
|
+
@blockio.prepare_dtrust_transaction(@req_params)
|
154
|
+
|
155
|
+
expect(@stub1).to have_been_requested.times(1)
|
156
|
+
|
157
|
+
expect(
|
158
|
+
@blockio.create_and_sign_transaction(Oj.safe_load(@prepare_dtrust_transaction_response_witness_v0), @private_keys)
|
159
|
+
).to eq(Oj.safe_load(@create_and_sign_transaction_response_dtrust_witness_v0_4_of_5_keys))
|
160
|
+
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
data/spec/helper_spec.rb
CHANGED
@@ -6,32 +6,39 @@ describe "Helper.sha256" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "Helper.pinToAesKey" do
|
9
|
-
|
10
|
-
|
9
|
+
describe "no_salt" do
|
10
|
+
it "deadbeef" do
|
11
|
+
expect(BlockIo::Helper.pinToAesKey("deadbeef")).to eq([["b87ddac3d84865782a0edbc21b5786d56795dd52bab0fe49270b3726372a83fe"].pack("H*")].pack("m0"))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe "salt" do
|
15
|
+
it "922445847c173e90667a19d90729e1fb" do
|
16
|
+
expect(BlockIo::Helper.pinToAesKey("deadbeef", 500000, "922445847c173e90667a19d90729e1fb")).to eq([["f206403c6bad20e1c8cb1f3318e17cec5b2da0560ed6c7b26826867452534172"].pack("H*")].pack("m0"))
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
13
20
|
|
14
|
-
describe "Helper.
|
21
|
+
describe "Helper.encrypt_aes256ecb" do
|
15
22
|
before(:each) do
|
16
23
|
@encryption_key = BlockIo::Helper.pinToAesKey("deadbeef")
|
17
24
|
@encrypted_data = BlockIo::Helper.encrypt("beadbeef", @encryption_key)
|
18
25
|
end
|
19
26
|
|
20
27
|
it "beadbeef" do
|
21
|
-
expect(@encrypted_data).to eq("3wIJtPoC8KO6S7x6LtrN0g==")
|
28
|
+
expect(@encrypted_data[:aes_cipher_text]).to eq("3wIJtPoC8KO6S7x6LtrN0g==")
|
22
29
|
end
|
23
30
|
|
24
31
|
end
|
25
32
|
|
26
|
-
describe "Helper.
|
33
|
+
describe "Helper.decrypt_aes256ecb" do
|
27
34
|
before(:each) do
|
28
35
|
@encryption_key = BlockIo::Helper.pinToAesKey("deadbeef")
|
29
|
-
@bad_encryption_key = BlockIo::Helper.pinToAesKey(SecureRandom.hex(
|
36
|
+
@bad_encryption_key = BlockIo::Helper.pinToAesKey(SecureRandom.hex(8))
|
30
37
|
@encrypted_data = BlockIo::Helper.encrypt("beadbeef", @encryption_key)
|
31
38
|
end
|
32
39
|
|
33
40
|
it "encryption_key" do
|
34
|
-
@decrypted_data = BlockIo::Helper.decrypt(@encrypted_data, @encryption_key)
|
41
|
+
@decrypted_data = BlockIo::Helper.decrypt(@encrypted_data[:aes_cipher_text], @encryption_key)
|
35
42
|
expect(@decrypted_data).to eq("beadbeef")
|
36
43
|
end
|
37
44
|
|
@@ -42,3 +49,106 @@ describe "Helper.decrypt" do
|
|
42
49
|
end
|
43
50
|
|
44
51
|
end
|
52
|
+
|
53
|
+
describe "Helper.encrypt_aes256cbc" do
|
54
|
+
before(:each) do
|
55
|
+
@encryption_key = BlockIo::Helper.pinToAesKey("deadbeef", 500000, "922445847c173e90667a19d90729e1fb")
|
56
|
+
@encrypted_data = BlockIo::Helper.encrypt("beadbeef", @encryption_key, "11bc22166c8cf8560e5fa7e5c622bb0f", "AES-256-CBC")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "beadbeef" do
|
60
|
+
expect(@encrypted_data[:aes_cipher_text]).to eq("LExu1rUAtIBOekslc328Lw==")
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "Helper.decrypt_aes256cbc" do
|
66
|
+
before(:each) do
|
67
|
+
@encryption_key = BlockIo::Helper.pinToAesKey("deadbeef", 500000, "922445847c173e90667a19d90729e1fb")
|
68
|
+
@bad_encryption_key = BlockIo::Helper.pinToAesKey(SecureRandom.hex(8))
|
69
|
+
@encrypted_data = BlockIo::Helper.encrypt("beadbeef", @encryption_key, "11bc22166c8cf8560e5fa7e5c622bb0f", "AES-256-CBC")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "encryption_key" do
|
73
|
+
@decrypted_data = BlockIo::Helper.decrypt(@encrypted_data[:aes_cipher_text], @encryption_key, @encrypted_data[:aes_iv], @encrypted_data[:aes_cipher])
|
74
|
+
expect(@decrypted_data).to eq("beadbeef")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "bad_encryption_key" do
|
78
|
+
expect{
|
79
|
+
BlockIo::Helper.decrypt(@encrypted_data[:aes_cipher_text], @bad_encryption_key, @encrypted_data[:aes_iv], @encrypted_data[:aes_cipher])
|
80
|
+
}.to raise_error(Exception, "Invalid Secret PIN provided.")
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Helper.decrypt_aes256gcm" do
|
86
|
+
before(:each) do
|
87
|
+
@encryption_key = BlockIo::Helper.pinToAesKey("deadbeef", 500000, "922445847c173e90667a19d90729e1fb")
|
88
|
+
@bad_encryption_key = BlockIo::Helper.pinToAesKey(SecureRandom.hex(8))
|
89
|
+
@encrypted_data = BlockIo::Helper.encrypt("beadbeef", @encryption_key, "a57414b88b67f977829cbdca", "AES-256-GCM", "")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "encryption_key" do
|
93
|
+
@decrypted_data = BlockIo::Helper.decrypt(@encrypted_data[:aes_cipher_text],
|
94
|
+
@encryption_key, @encrypted_data[:aes_iv],
|
95
|
+
@encrypted_data[:aes_cipher],
|
96
|
+
@encrypted_data[:aes_auth_tag],
|
97
|
+
@encrypted_data[:aes_auth_data])
|
98
|
+
expect(@decrypted_data).to eq("beadbeef")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "encryption_key_bad_auth_tag" do
|
102
|
+
expect{
|
103
|
+
BlockIo::Helper.decrypt(@encrypted_data[:aes_cipher_text],
|
104
|
+
@encryption_key, @encrypted_data[:aes_iv],
|
105
|
+
@encrypted_data[:aes_cipher],
|
106
|
+
@encrypted_data[:aes_auth_tag][0..30],
|
107
|
+
@encrypted_data[:aes_auth_data])
|
108
|
+
}.to raise_error(Exception, "Auth tag must be 16 bytes exactly.")
|
109
|
+
end
|
110
|
+
|
111
|
+
it "bad_encryption_key" do
|
112
|
+
expect{
|
113
|
+
BlockIo::Helper.decrypt(@encrypted_data[:aes_cipher_text], @bad_encryption_key, @encrypted_data[:aes_iv], @encrypted_data[:aes_cipher], @encrypted_data[:aes_auth_tag],
|
114
|
+
@encrypted_data[:aes_auth_data])
|
115
|
+
}.to raise_error(Exception, "Invalid Secret PIN provided.")
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "Helper.encrypt_aes256gcm" do
|
121
|
+
before(:each) do
|
122
|
+
@encryption_key = BlockIo::Helper.pinToAesKey("deadbeef", 500000, "922445847c173e90667a19d90729e1fb")
|
123
|
+
@encrypted_data = BlockIo::Helper.encrypt("beadbeef", @encryption_key, "a57414b88b67f977829cbdca", "AES-256-GCM", "")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "beadbeef" do
|
127
|
+
expect(@encrypted_data[:aes_cipher_text]).to eq("ELV56Z57KoA=")
|
128
|
+
expect(@encrypted_data[:aes_auth_tag]).to eq("adeb7dfe53027bdda5824dc524d5e55a")
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "Helper.dynamicExtractKey" do
|
134
|
+
|
135
|
+
before(:each) do
|
136
|
+
@aes256cbc_user_key = Oj.safe_load('{"encrypted_passphrase":"LExu1rUAtIBOekslc328Lw==","public_key":"02f87f787bffb30396984cb6b3a9d6830f32d5b656b3e39b0abe4f3b3c35d99323","algorithm":{"pbkdf2_salt":"922445847c173e90667a19d90729e1fb","pbkdf2_iterations":500000,"pbkdf2_hash_function":"SHA256","pbkdf2_phase1_key_length":16,"pbkdf2_phase2_key_length":32,"aes_iv":"11bc22166c8cf8560e5fa7e5c622bb0f","aes_cipher":"AES-256-CBC","aes_auth_tag":null,"aes_auth_data":null}}')
|
137
|
+
@aes256gcm_user_key = Oj.safe_load('{"encrypted_passphrase":"ELV56Z57KoA=","public_key":"02f87f787bffb30396984cb6b3a9d6830f32d5b656b3e39b0abe4f3b3c35d99323","algorithm":{"pbkdf2_salt":"922445847c173e90667a19d90729e1fb","pbkdf2_iterations":500000,"pbkdf2_hash_function":"SHA256","pbkdf2_phase1_key_length":16,"pbkdf2_phase2_key_length":32,"aes_iv":"a57414b88b67f977829cbdca","aes_cipher":"AES-256-GCM","aes_auth_tag":"adeb7dfe53027bdda5824dc524d5e55a","aes_auth_data":""}}')
|
138
|
+
@aes256ecb_user_key = Oj.safe_load('{"encrypted_passphrase":"3wIJtPoC8KO6S7x6LtrN0g==","public_key":"02f87f787bffb30396984cb6b3a9d6830f32d5b656b3e39b0abe4f3b3c35d99323","algorithm":{"pbkdf2_salt":"","pbkdf2_iterations":2048,"pbkdf2_hash_function":"SHA256","pbkdf2_phase1_key_length":16,"pbkdf2_phase2_key_length":32,"aes_iv":null,"aes_cipher":"AES-256-ECB","aes_auth_tag":null,"aes_auth_data":null}}')
|
139
|
+
@pin = "deadbeef"
|
140
|
+
end
|
141
|
+
|
142
|
+
it "aes256ecb_success" do
|
143
|
+
expect(BlockIo::Helper.dynamicExtractKey(@aes256ecb_user_key, @pin).public_key_hex).to eq(BlockIo::Key.from_passphrase("beadbeef").public_key_hex)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "aes256cbc_success" do
|
147
|
+
expect(BlockIo::Helper.dynamicExtractKey(@aes256cbc_user_key, @pin).public_key_hex).to eq(BlockIo::Key.from_passphrase("beadbeef").public_key_hex)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "aes256gcm_success" do
|
151
|
+
expect(BlockIo::Helper.dynamicExtractKey(@aes256gcm_user_key, @pin).public_key_hex).to eq(BlockIo::Key.from_passphrase("beadbeef").public_key_hex)
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
data/spec/key_spec.rb
CHANGED
@@ -1,29 +1,42 @@
|
|
1
|
+
describe "Key.from_private_key_hex" do
|
2
|
+
# generates faulty signature with Native Ruby bitcoinrb 0.7.0 unless the private key is padded to be 64 char hex (below is 63 chars)
|
3
|
+
|
4
|
+
context "6c1cefdfd9187b36b36c3698c1362642083dcc1941dc76d751481d3aa29ca65" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@key = BlockIo::Key.from_private_key_hex("6c1cefdfd9187b36b36c3698c1362642083dcc1941dc76d751481d3aa29ca65")
|
8
|
+
@data_to_sign = "c290b6e7e43ae83124499a06d1c0f8d385cc86f28aad77260599654061847547"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "succeeds" do
|
12
|
+
@signature = @key.sign([@data_to_sign].pack("H*"))
|
13
|
+
expect(@signature.unpack("H*")[0]).to eq("304402204ad00b8fd0918e5a0e9ec353a32139265ab3e633748dc85494561f1cee748551022073b229aad08f7bf62020300a34df587336a30784b29439abb405435413c961f4")
|
14
|
+
expect(@key.verify(@signature, [@data_to_sign].pack("H*"))).to eq(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
1
20
|
|
2
21
|
describe "Key.from_wif" do
|
3
22
|
|
4
23
|
context "L1cq4uDmSKMiViT4DuR8jqJv8AiiSZ9VeJr82yau5nfVQYaAgDdr" do
|
5
24
|
|
6
25
|
before(:each) do
|
7
|
-
|
8
|
-
@key_low_r =
|
26
|
+
Bitcoin.chain_params = "BTC"
|
27
|
+
@key_low_r = Bitcoin::Key.from_wif("L1cq4uDmSKMiViT4DuR8jqJv8AiiSZ9VeJr82yau5nfVQYaAgDdr")
|
9
28
|
end
|
10
29
|
|
11
30
|
it "match(public_key)" do
|
12
|
-
expect(@
|
13
|
-
expect(@key_low_r.public_key).to eq("024988bae7e0ade83cb1b6eb0fd81e6161f6657ad5dd91d216fbeab22aea3b61a0")
|
31
|
+
expect(@key_low_r.public_key_hex).to eq("024988bae7e0ade83cb1b6eb0fd81e6161f6657ad5dd91d216fbeab22aea3b61a0")
|
14
32
|
end
|
15
33
|
|
16
34
|
it "match(private_key)" do
|
17
|
-
expect(@
|
18
|
-
expect(@key_low_r.private_key).to eq("833e2256c42b4a41ee0a6ee284c39cf8e1978bc8e878eb7ae87803e22d48caa9")
|
35
|
+
expect(@key_low_r.private_key_hex).to eq("833e2256c42b4a41ee0a6ee284c39cf8e1978bc8e878eb7ae87803e22d48caa9")
|
19
36
|
end
|
20
37
|
|
21
|
-
it "sign_without_low_r" do
|
22
|
-
expect(@key_any_r.sign("e76f0f78b7e7474f04cc14ad1343e4cc28f450399a79457d1240511a054afd63")).to eq("3045022100aec97f7ad7a9831d583ca157284a68706a6ac4e76d6c9ee33adce6227a40e675022008894fb35020792c01443d399d33ffceb72ac1d410b6dcb9e31dcc71e6c49e92")
|
23
|
-
end
|
24
|
-
|
25
38
|
it "sign_with_low_r" do
|
26
|
-
expect(@key_low_r.sign("e76f0f78b7e7474f04cc14ad1343e4cc28f450399a79457d1240511a054afd63")).to eq("3044022061753424b6936ca4cfcc81b883dab55f16d84d3eaf9d5da77c1e25f54fda963802200d3db78e8f5aac62909c2a89ab1b2b413c00c0860926e824f37a19fa140c79f4")
|
39
|
+
expect(@key_low_r.sign(["e76f0f78b7e7474f04cc14ad1343e4cc28f450399a79457d1240511a054afd63"].pack("H*")).unpack("H*")[0]).to eq("3044022061753424b6936ca4cfcc81b883dab55f16d84d3eaf9d5da77c1e25f54fda963802200d3db78e8f5aac62909c2a89ab1b2b413c00c0860926e824f37a19fa140c79f4")
|
27
40
|
end
|
28
41
|
end
|
29
42
|
|
@@ -34,28 +47,46 @@ describe "Key.from_passphrase" do
|
|
34
47
|
context "deadbeef" do
|
35
48
|
|
36
49
|
before(:each) do
|
37
|
-
@key_any_r = BlockIo::Key.from_passphrase("deadbeef", false)
|
38
50
|
@key_low_r = BlockIo::Key.from_passphrase("deadbeef")
|
39
51
|
@data = "e76f0f78b7e7474f04cc14ad1343e4cc28f450399a79457d1240511a054afd63"
|
40
52
|
end
|
41
53
|
|
42
54
|
it "match(public_key)" do
|
43
|
-
expect(@key_low_r.
|
55
|
+
expect(@key_low_r.public_key_hex).to eq("02953b9dfcec241eec348c12b1db813d3cd5ec9d93923c04d2fa3832208b8c0f84")
|
44
56
|
end
|
45
57
|
|
46
58
|
it "match(private_key)" do
|
47
|
-
expect(@key_low_r.
|
48
|
-
end
|
49
|
-
|
50
|
-
it "sign_without_low_r" do
|
51
|
-
expect(@key_any_r.sign(@data)).to eq("30450221009a68321e071c94e25484e26435639f00d23ef3fbe9c529c3347dc061f562530c0220134d3159098950b81b678f9e3b15e100f5478bb45345d3243df41ae616e70032")
|
59
|
+
expect(@key_low_r.private_key_hex).to eq("5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953")
|
52
60
|
end
|
53
61
|
|
54
62
|
it "sign_with_low_r" do
|
55
|
-
expect(@key_low_r.sign(@data)).to eq("304402204ac97a4cdad5f842e745e27c3ffbe08b3704900baafab602277a5a196c3a4a3202202bacdf06afaf58032383447a9f3e9a42bfaeabf6dbcf9ab275d8f24171d272cf")
|
63
|
+
expect(@key_low_r.sign([@data].pack("H*")).unpack("H*")[0]).to eq("304402204ac97a4cdad5f842e745e27c3ffbe08b3704900baafab602277a5a196c3a4a3202202bacdf06afaf58032383447a9f3e9a42bfaeabf6dbcf9ab275d8f24171d272cf")
|
56
64
|
end
|
57
65
|
|
58
66
|
end
|
59
67
|
|
60
68
|
end
|
61
69
|
|
70
|
+
describe "Key.generate" do
|
71
|
+
|
72
|
+
context "compressed" do
|
73
|
+
|
74
|
+
before(:each) do
|
75
|
+
Bitcoin.chain_params = "BTC"
|
76
|
+
@key = Bitcoin::Key.generate
|
77
|
+
end
|
78
|
+
|
79
|
+
it "compressed?" do
|
80
|
+
expect(@key.compressed?).to eq(true)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
context "uncompressed" do
|
86
|
+
Bitcoin.chain_params = "BTC"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "raises_exception" do
|
90
|
+
expect {Bitcoin::Key.generate(0x00)}.to raise_error(RuntimeError, "key_type must always be Bitcoin::KEY::TYPES[:compressed]")
|
91
|
+
end
|
92
|
+
end
|