vchain_client 1.0.15 → 1.0.16
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.
- checksums.yaml +4 -4
- data/lib/vchain_client.rb +804 -737
- data/lib/vchain_client/bitcoind_blockchain_adapter.rb +16 -2
- data/lib/vchain_client/blockstack_client.rb +4 -0
- data/lib/vchain_client/signatures.rb +73 -51
- metadata +1 -1
@@ -9,6 +9,8 @@ module VChainClient
|
|
9
9
|
@rpc_username = nil
|
10
10
|
@rpc_password = nil
|
11
11
|
|
12
|
+
@@tx_cache = {}
|
13
|
+
|
12
14
|
def initialize(server, port, rpc_username, rpc_password)
|
13
15
|
@server = server
|
14
16
|
@port = port
|
@@ -24,6 +26,14 @@ module VChainClient
|
|
24
26
|
|
25
27
|
def getTx(txid)
|
26
28
|
|
29
|
+
if @@tx_cache.key?(txid)
|
30
|
+
if @log.debug?
|
31
|
+
@log.debug("[Bitcoind.getTx] '#{txid}' is in a cache")
|
32
|
+
end
|
33
|
+
|
34
|
+
return @@tx_cache[txid]
|
35
|
+
end
|
36
|
+
|
27
37
|
if @log.debug?
|
28
38
|
@log.debug("[Bitcoind.getTx] input:")
|
29
39
|
@log.debug("-> txid: #{txid}")
|
@@ -84,14 +94,18 @@ module VChainClient
|
|
84
94
|
|
85
95
|
if prefix == "VCH"
|
86
96
|
|
87
|
-
op_return = op_return[
|
97
|
+
op_return = op_return[5..op_return.length]
|
88
98
|
|
89
|
-
|
99
|
+
out = {
|
90
100
|
"size" => raw_tx["size"],
|
91
101
|
"block_hash" => raw_tx["blockhash"],
|
92
102
|
"block_timestamp" => raw_tx["blocktime"],
|
93
103
|
"op_return" => op_return
|
94
104
|
}
|
105
|
+
|
106
|
+
@@tx_cache[txid] = out
|
107
|
+
|
108
|
+
return out
|
95
109
|
|
96
110
|
else
|
97
111
|
if @log.error?
|
@@ -413,6 +413,8 @@ module VChainClient
|
|
413
413
|
|
414
414
|
blockstack_path = @config["blockstack"]["path"]
|
415
415
|
|
416
|
+
cmd_init = blockstack_path +" set_advanced_mode on"
|
417
|
+
|
416
418
|
cmd = blockstack_path +" get_name_zonefile "+ blockstack_id
|
417
419
|
|
418
420
|
if @log.debug?
|
@@ -424,6 +426,8 @@ module VChainClient
|
|
424
426
|
|
425
427
|
begin
|
426
428
|
|
429
|
+
`#{cmd_init}`
|
430
|
+
|
427
431
|
ret = `#{cmd}`
|
428
432
|
|
429
433
|
rescue => e
|
@@ -11,13 +11,15 @@ module VChainClient
|
|
11
11
|
@log = Log4r::Logger["vchain_client"]
|
12
12
|
end
|
13
13
|
|
14
|
-
def signRequest(document, timestamp)
|
14
|
+
def signRequest(document, point_type, weight, timestamp)
|
15
15
|
OpenSSL::PKey::EC.send(:alias_method, :private?, :private_key?)
|
16
16
|
|
17
17
|
priv_key_path = @config["private_key_location"]
|
18
18
|
|
19
19
|
if @log.debug?
|
20
20
|
@log.debug("[Signatures.signRequest] input:")
|
21
|
+
@log.debug("-> point_type: "+ point_type)
|
22
|
+
@log.debug("-> weight: "+ weight.to_s)
|
21
23
|
@log.debug("-> timestamp: "+ timestamp.to_s)
|
22
24
|
@log.debug("-> key path: #{priv_key_path}")
|
23
25
|
@log.debug("-> input:")
|
@@ -34,6 +36,8 @@ module VChainClient
|
|
34
36
|
if @log.error?
|
35
37
|
@log.error("[Signatures.signRequest] File.read raised exception:")
|
36
38
|
@log.error("#{e.class}, #{e.message}")
|
39
|
+
@log.error("-> point_type: "+ point_type)
|
40
|
+
@log.error("-> weight: "+ weight.to_s)
|
37
41
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
38
42
|
@log.error("-> input:")
|
39
43
|
@log.error(document)
|
@@ -46,6 +50,8 @@ module VChainClient
|
|
46
50
|
if priv_key == nil
|
47
51
|
if @log.error?
|
48
52
|
@log.error("[Signatures.signRequest] failed to load private key")
|
53
|
+
@log.error("-> point_type: "+ point_type)
|
54
|
+
@log.error("-> weight: "+ weight.to_s)
|
49
55
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
50
56
|
@log.error("-> input:")
|
51
57
|
@log.error(document)
|
@@ -69,6 +75,8 @@ module VChainClient
|
|
69
75
|
if @log.error?
|
70
76
|
@log.error("[Signatures.signRequest] OpenSSL::PKey::EC.new raised exception:")
|
71
77
|
@log.error("#{e.class}, #{e.message}")
|
78
|
+
@log.error("-> point_type: "+ point_type)
|
79
|
+
@log.error("-> weight: "+ weight.to_s)
|
72
80
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
73
81
|
@log.error("-> input:")
|
74
82
|
@log.error(document)
|
@@ -81,6 +89,8 @@ module VChainClient
|
|
81
89
|
if ec == nil
|
82
90
|
if @log.error?
|
83
91
|
@log.error("[Signatures.signRequest] failed init EC key")
|
92
|
+
@log.error("-> point_type: "+ point_type)
|
93
|
+
@log.error("-> weight: "+ weight.to_s)
|
84
94
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
85
95
|
@log.error("-> input:")
|
86
96
|
@log.error(document)
|
@@ -96,7 +106,7 @@ module VChainClient
|
|
96
106
|
|
97
107
|
digest = OpenSSL::Digest::SHA256.new
|
98
108
|
|
99
|
-
whole_sign = document.to_json + timestamp.to_s
|
109
|
+
whole_sign = document.to_json + point_type + weight.to_s + timestamp.to_s
|
100
110
|
|
101
111
|
if @log.debug?
|
102
112
|
@log.debug("[Signatures.signRequest] whole_to_sign: "+ whole_sign)
|
@@ -112,6 +122,8 @@ module VChainClient
|
|
112
122
|
if @log.error?
|
113
123
|
@log.error("[Signatures.signRequest] ec.sign raised exception:")
|
114
124
|
@log.error("#{e.class}, #{e.message}")
|
125
|
+
@log.error("-> point_type: "+ point_type)
|
126
|
+
@log.error("-> weight: "+ weight.to_s)
|
115
127
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
116
128
|
@log.error("-> input:")
|
117
129
|
@log.error(document)
|
@@ -125,6 +137,8 @@ module VChainClient
|
|
125
137
|
if whole_signature == nil
|
126
138
|
if @log.error?
|
127
139
|
@log.error("[Signatures.signRequest] failed to sign")
|
140
|
+
@log.error("-> point_type: "+ point_type)
|
141
|
+
@log.error("-> weight: "+ weight.to_s)
|
128
142
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
129
143
|
@log.error("-> input:")
|
130
144
|
@log.error(document)
|
@@ -147,13 +161,6 @@ module VChainClient
|
|
147
161
|
pub_key += public_key
|
148
162
|
pub_key += "\n-----END PUBLIC KEY-----"
|
149
163
|
|
150
|
-
if @log.debug?
|
151
|
-
@log.debug("[Signatures.verifySignature] input:")
|
152
|
-
@log.debug("-> what_to_check: #{what_to_check}")
|
153
|
-
@log.debug("-> signature: "+ Base64.encode64(signature))
|
154
|
-
@log.debug("-> public_key: "+ pub_key)
|
155
|
-
end
|
156
|
-
|
157
164
|
ec = nil
|
158
165
|
|
159
166
|
begin
|
@@ -164,9 +171,9 @@ module VChainClient
|
|
164
171
|
if @log.error?
|
165
172
|
@log.error("[Signatures.verifySignature] OpenSSL::PKey::EC.new raised exception:")
|
166
173
|
@log.error("#{e.class}, #{e.message}")
|
167
|
-
@log.
|
168
|
-
@log.
|
169
|
-
@log.
|
174
|
+
@log.error("-> what_to_check: #{what_to_check}")
|
175
|
+
@log.error("-> signature: "+ Base64.encode64(signature))
|
176
|
+
@log.error("-> public_key: "+ pub_key)
|
170
177
|
@log.error(document)
|
171
178
|
@log.error("--> pub_key: #{pub_key}")
|
172
179
|
end
|
@@ -177,19 +184,15 @@ module VChainClient
|
|
177
184
|
if ec == nil
|
178
185
|
if @log.error?
|
179
186
|
@log.error("[Signatures.verifySignature] failed init EC key")
|
180
|
-
@log.
|
181
|
-
@log.
|
182
|
-
@log.
|
187
|
+
@log.error("-> what_to_check: #{what_to_check}")
|
188
|
+
@log.error("-> signature: "+ Base64.encode64(signature))
|
189
|
+
@log.error("-> public_key: "+ pub_key)
|
183
190
|
@log.error("--> pub_key: #{pub_key}")
|
184
191
|
end
|
185
192
|
|
186
193
|
return false
|
187
194
|
end
|
188
195
|
|
189
|
-
if @log.debug?
|
190
|
-
@log.debug("[Signatures.verifySignature] key created")
|
191
|
-
end
|
192
|
-
|
193
196
|
digest = OpenSSL::Digest::SHA256.new
|
194
197
|
|
195
198
|
begin
|
@@ -200,9 +203,9 @@ module VChainClient
|
|
200
203
|
if @log.error?
|
201
204
|
@log.error("[Signatures.verifySignature] ec.verify raised exception:")
|
202
205
|
@log.error("#{e.class}, #{e.message}")
|
203
|
-
@log.
|
204
|
-
@log.
|
205
|
-
@log.
|
206
|
+
@log.error("-> what_to_check: #{what_to_check}")
|
207
|
+
@log.error("-> signature: "+ Base64.encode64(signature))
|
208
|
+
@log.error("-> public_key: "+ pub_key)
|
206
209
|
@log.error(document)
|
207
210
|
@log.error("--> signature: "+ Base64.encode64(signature))
|
208
211
|
@log.error("--> what_to_check: #{what_to_check}")
|
@@ -212,7 +215,7 @@ module VChainClient
|
|
212
215
|
end
|
213
216
|
end
|
214
217
|
|
215
|
-
def
|
218
|
+
def signDataPoint(point_type, data, doc_hash, weight, timestamp)
|
216
219
|
|
217
220
|
OpenSSL::PKey::EC.send(:alias_method, :private?, :private_key?)
|
218
221
|
|
@@ -220,10 +223,12 @@ module VChainClient
|
|
220
223
|
priv_key_path = @config["private_key_location"]
|
221
224
|
|
222
225
|
if @log.debug?
|
223
|
-
@log.debug("[Signatures.
|
226
|
+
@log.debug("[Signatures.signDataPoint] input:")
|
224
227
|
@log.debug("-> this_client_id: #{this_client_id}")
|
228
|
+
@log.debug("-> doc_hash: #{doc_hash}")
|
229
|
+
@log.debug("-> weight: "+ weight.to_s)
|
225
230
|
@log.debug("-> timestamp: "+ timestamp.to_s)
|
226
|
-
@log.debug("->
|
231
|
+
@log.debug("-> point_type: #{point_type}")
|
227
232
|
@log.debug("-> key path: #{priv_key_path}")
|
228
233
|
@log.debug("-> data:")
|
229
234
|
@log.debug(data)
|
@@ -237,11 +242,13 @@ module VChainClient
|
|
237
242
|
|
238
243
|
rescue => e
|
239
244
|
if @log.error?
|
240
|
-
@log.error("[Signatures.
|
245
|
+
@log.error("[Signatures.signDataPoint] File.read raised exception:")
|
241
246
|
@log.error("#{e.class}, #{e.message}")
|
242
247
|
@log.error("-> this_client_id: #{this_client_id}")
|
248
|
+
@log.error("-> doc_hash: #{doc_hash}")
|
249
|
+
@log.error("-> weight: "+ weight.to_s)
|
243
250
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
244
|
-
@log.error("->
|
251
|
+
@log.error("-> point_type: #{point_type}")
|
245
252
|
@log.error("-> key path: #{priv_key_path}")
|
246
253
|
@log.error("-> data:")
|
247
254
|
@log.error(data)
|
@@ -253,10 +260,12 @@ module VChainClient
|
|
253
260
|
|
254
261
|
if priv_key == nil
|
255
262
|
if @log.error?
|
256
|
-
@log.error("[Signatures.
|
263
|
+
@log.error("[Signatures.signDataPoint] failed to load private key")
|
257
264
|
@log.error("-> this_client_id: #{this_client_id}")
|
265
|
+
@log.error("-> doc_hash: #{doc_hash}")
|
266
|
+
@log.error("-> weight: "+ weight.to_s)
|
258
267
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
259
|
-
@log.error("->
|
268
|
+
@log.error("-> point_type: #{point_type}")
|
260
269
|
@log.error("-> key path: #{priv_key_path}")
|
261
270
|
@log.error("-> data:")
|
262
271
|
@log.error(data)
|
@@ -267,7 +276,7 @@ module VChainClient
|
|
267
276
|
end
|
268
277
|
|
269
278
|
if @log.debug?
|
270
|
-
@log.debug("[Signatures.
|
279
|
+
@log.debug("[Signatures.signDataPoint] priv key loaded")
|
271
280
|
end
|
272
281
|
|
273
282
|
output = {}
|
@@ -277,10 +286,10 @@ module VChainClient
|
|
277
286
|
value = rec[1]
|
278
287
|
|
279
288
|
if @log.debug?
|
280
|
-
@log.debug("[Signatures.
|
289
|
+
@log.debug("[Signatures.signDataPoint] field: #{field}, value: #{value}")
|
281
290
|
end
|
282
291
|
|
283
|
-
if field != '
|
292
|
+
if field != 'client_id'
|
284
293
|
|
285
294
|
field_hash = Digest::SHA512.hexdigest(field)
|
286
295
|
|
@@ -288,13 +297,15 @@ module VChainClient
|
|
288
297
|
|
289
298
|
what_to_sign = field_hash
|
290
299
|
what_to_sign += value_hash
|
291
|
-
what_to_sign +=
|
300
|
+
what_to_sign += Digest::SHA512.hexdigest(doc_hash)
|
301
|
+
what_to_sign += point_type
|
302
|
+
what_to_sign += weight.to_s
|
292
303
|
what_to_sign += timestamp.to_s
|
293
304
|
what_to_sign += this_client_id
|
294
305
|
|
295
306
|
if @log.debug?
|
296
|
-
@log.debug("[Signatures.
|
297
|
-
@log.debug("[Signatures.
|
307
|
+
@log.debug("[Signatures.signDataPoint] field_hash: #{field_hash}")
|
308
|
+
@log.debug("[Signatures.signDataPoint] value_hash: #{value_hash}")
|
298
309
|
end
|
299
310
|
|
300
311
|
ec = nil
|
@@ -305,11 +316,13 @@ module VChainClient
|
|
305
316
|
|
306
317
|
rescue => e
|
307
318
|
if @log.error?
|
308
|
-
@log.error("[Signatures.
|
319
|
+
@log.error("[Signatures.signDataPoint] OpenSSL::PKey::EC.new raised exception:")
|
309
320
|
@log.error("#{e.class}, #{e.message}")
|
310
321
|
@log.error("-> this_client_id: #{this_client_id}")
|
322
|
+
@log.error("-> doc_hash: #{doc_hash}")
|
323
|
+
@log.error("-> weight: "+ weight.to_s)
|
311
324
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
312
|
-
@log.error("->
|
325
|
+
@log.error("-> point_type: #{point_type}")
|
313
326
|
@log.error("-> key path: #{priv_key_path}")
|
314
327
|
@log.error("-> data:")
|
315
328
|
@log.error(data)
|
@@ -321,10 +334,12 @@ module VChainClient
|
|
321
334
|
|
322
335
|
if ec == nil
|
323
336
|
if @log.error?
|
324
|
-
@log.error("[Signatures.
|
337
|
+
@log.error("[Signatures.signDataPoint] failed init EC key")
|
325
338
|
@log.error("-> this_client_id: #{this_client_id}")
|
339
|
+
@log.error("-> doc_hash: #{doc_hash}")
|
340
|
+
@log.error("-> weight: "+ weight.to_s)
|
326
341
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
327
|
-
@log.error("->
|
342
|
+
@log.error("-> point_type: #{point_type}")
|
328
343
|
@log.error("-> key path: #{priv_key_path}")
|
329
344
|
@log.error("-> data:")
|
330
345
|
@log.error(data)
|
@@ -335,7 +350,7 @@ module VChainClient
|
|
335
350
|
end
|
336
351
|
|
337
352
|
if @log.debug?
|
338
|
-
@log.debug("[Signatures.
|
353
|
+
@log.debug("[Signatures.signDataPoint] key created")
|
339
354
|
end
|
340
355
|
|
341
356
|
digest = OpenSSL::Digest::SHA256.new
|
@@ -348,11 +363,13 @@ module VChainClient
|
|
348
363
|
|
349
364
|
rescue => e
|
350
365
|
if @log.error?
|
351
|
-
@log.error("[Signatures.
|
366
|
+
@log.error("[Signatures.signDataPoint] ec.sign raised exception:")
|
352
367
|
@log.error("#{e.class}, #{e.message}")
|
353
368
|
@log.error("-> this_client_id: #{this_client_id}")
|
369
|
+
@log.error("-> doc_hash: #{doc_hash}")
|
370
|
+
@log.error("-> weight: "+ weight.to_s)
|
354
371
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
355
|
-
@log.error("->
|
372
|
+
@log.error("-> point_type: #{point_type}")
|
356
373
|
@log.error("-> key path: #{priv_key_path}")
|
357
374
|
@log.error("-> data:")
|
358
375
|
@log.error(data)
|
@@ -365,10 +382,12 @@ module VChainClient
|
|
365
382
|
|
366
383
|
if signature == nil
|
367
384
|
if @log.error?
|
368
|
-
@log.error("[Signatures.
|
385
|
+
@log.error("[Signatures.signDataPoint] failed to sign")
|
369
386
|
@log.error("-> this_client_id: #{this_client_id}")
|
387
|
+
@log.error("-> doc_hash: #{doc_hash}")
|
388
|
+
@log.error("-> weight: "+ weight.to_s)
|
370
389
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
371
|
-
@log.error("->
|
390
|
+
@log.error("-> point_type: #{point_type}")
|
372
391
|
@log.error("-> key path: #{priv_key_path}")
|
373
392
|
@log.error("-> data:")
|
374
393
|
@log.error(data)
|
@@ -380,7 +399,7 @@ module VChainClient
|
|
380
399
|
end
|
381
400
|
|
382
401
|
if @log.debug?
|
383
|
-
@log.debug("[Signatures.
|
402
|
+
@log.debug("[Signatures.signDataPoint] signature raw: "+ Base64.encode64(signature))
|
384
403
|
end
|
385
404
|
|
386
405
|
output[field] = Base64.encode64(signature).gsub(/\n/, "")
|
@@ -389,7 +408,7 @@ module VChainClient
|
|
389
408
|
}
|
390
409
|
|
391
410
|
if @log.debug?
|
392
|
-
@log.debug("[Signatures.
|
411
|
+
@log.debug("[Signatures.signDataPoint] output:")
|
393
412
|
@log.debug(output)
|
394
413
|
end
|
395
414
|
|
@@ -442,13 +461,15 @@ module VChainClient
|
|
442
461
|
end
|
443
462
|
end
|
444
463
|
|
445
|
-
def checkVerificationSignature(field_hash, data_hash, verification_type, timestamp, blockstack_client_id, pubkey, signature)
|
464
|
+
def checkVerificationSignature(field_hash, data_hash, doc_hash, verification_type, weight, timestamp, blockstack_client_id, pubkey, signature)
|
446
465
|
|
447
466
|
if @log.debug?
|
448
467
|
@log.debug("[Signatures.checkVerificationSignature] input:")
|
449
468
|
@log.debug("-> field_hash: #{field_hash}")
|
450
469
|
@log.debug("-> data_hash: #{data_hash}")
|
451
|
-
@log.debug("->
|
470
|
+
@log.debug("-> doc_hash: #{doc_hash}")
|
471
|
+
@log.debug("-> type: #{verification_type}")
|
472
|
+
@log.debug("-> weight: "+ weight.to_s)
|
452
473
|
@log.debug("-> timestamp: "+ timestamp.to_s)
|
453
474
|
@log.debug("-> blockstack_client_id: #{blockstack_client_id}")
|
454
475
|
@log.debug("-> signature: "+ Base64.encode64(signature))
|
@@ -457,7 +478,9 @@ module VChainClient
|
|
457
478
|
|
458
479
|
what_to_check = field_hash
|
459
480
|
what_to_check += data_hash
|
481
|
+
what_to_check += doc_hash
|
460
482
|
what_to_check += verification_type
|
483
|
+
what_to_check += weight.to_s
|
461
484
|
what_to_check += timestamp.to_s
|
462
485
|
what_to_check += blockstack_client_id
|
463
486
|
|
@@ -471,14 +494,13 @@ module VChainClient
|
|
471
494
|
@log.error("#{e.class}, #{e.message}")
|
472
495
|
@log.error("-> field_hash: #{field_hash}")
|
473
496
|
@log.error("-> data_hash: #{data_hash}")
|
497
|
+
@log.error("-> doc_hash: #{doc_hash}")
|
474
498
|
@log.error("-> verification_type: #{verification_type}")
|
475
499
|
@log.error("-> timestamp: "+ timestamp.to_s)
|
500
|
+
@log.error("-> weight: "+ weight.to_s)
|
476
501
|
@log.error("-> blockstack_client_id: #{blockstack_client_id}")
|
477
502
|
@log.error("-> signature: "+ Base64.encode64(signature))
|
478
503
|
@log.error("-> pubkey: #{pubkey}")
|
479
|
-
@log.error("--> what_to_check: #{what_to_check}")
|
480
|
-
@log.error("--> signature: "+ Base64.encode64(signature))
|
481
|
-
@log.error("--> pubkey: #{pubkey}")
|
482
504
|
end
|
483
505
|
|
484
506
|
raise e
|