dbchain_client 0.6.2 → 0.7.0
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/dbchain_client/key.rb +22 -4
- data/lib/dbchain_client/reader.rb +19 -2
- data/lib/dbchain_client/transaction.rb +1 -1
- data/lib/dbchain_client/writer.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bbc767c04668e2a61263dca178a4b957c754859e4319dec14048d230d639c26
|
4
|
+
data.tar.gz: 5f5eb7aed816a764524b3c50f0ae74fa54626595eefdfcf6f228bceb238c196e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eadc63b8c3a2a771bcb1845103bf86a35ae9a2af2273f89a1a680f779d95ca2732752957314874be431072c7c10dd0e7ed4f548334091c4b86fb50fd1b270ef2
|
7
|
+
data.tar.gz: 5996ecbe45d93d40a9b9beee5fdb1c3f621af2585d70dde2b9fb9bdde8b2748685f2b2b36ac4e0ffc9d20231def53cf656fef982db6543f54f4f3815acd01600
|
data/lib/dbchain_client/key.rb
CHANGED
@@ -29,8 +29,7 @@ module DbchainClient
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def verify(message, signature)
|
32
|
-
|
33
|
-
raw_sig = @public_key.ecdsa_deserialize_compact(compact_sig)
|
32
|
+
raw_sig = signature.raw
|
34
33
|
@public_key.ecdsa_verify(message, raw_sig)
|
35
34
|
end
|
36
35
|
end
|
@@ -47,8 +46,27 @@ module DbchainClient
|
|
47
46
|
|
48
47
|
def sign(message)
|
49
48
|
raw_sig = @private_key.ecdsa_sign(message)
|
50
|
-
|
51
|
-
|
49
|
+
Signature.new(raw_sig)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Signature
|
54
|
+
include Secp256k1::ECDSA
|
55
|
+
|
56
|
+
def initialize(raw_sig)
|
57
|
+
@raw_sig = raw_sig
|
58
|
+
end
|
59
|
+
|
60
|
+
def raw
|
61
|
+
@raw_sig
|
62
|
+
end
|
63
|
+
|
64
|
+
def compact
|
65
|
+
ecdsa_serialize_compact(@raw_sig)
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_hex
|
69
|
+
compact.unpack("H*")
|
52
70
|
end
|
53
71
|
end
|
54
72
|
end
|
@@ -3,6 +3,8 @@ require 'base58'
|
|
3
3
|
|
4
4
|
module DbchainClient
|
5
5
|
class Reader
|
6
|
+
QueryRoot = '/dbchain'
|
7
|
+
|
6
8
|
def initialize(base_url, private_key, address=nil)
|
7
9
|
@rest_lib = DbchainClient::RestLib.new(base_url)
|
8
10
|
|
@@ -16,12 +18,27 @@ module DbchainClient
|
|
16
18
|
@from_address = address || @public_key.address
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
21
|
+
def get_row(app_code, table_name, id)
|
22
|
+
uri = uri_builder("find", app_code, table_name, id)
|
23
|
+
response = @rest_lib.rest_get(uri)
|
24
|
+
h = JSON.parse(response.body)
|
25
|
+
return h['result']
|
26
|
+
end
|
27
|
+
|
28
|
+
def generate_access_code(time=nil)
|
20
29
|
encoded_public_key = Base58.binary_to_base58(@public_key.to_raw, :bitcoin)
|
21
30
|
time ||= (Time.now.to_f * 1000).to_i.to_s
|
22
31
|
signature = @private_key.sign(time)
|
23
|
-
encoded_signature = Base58.binary_to_base58(
|
32
|
+
encoded_signature = Base58.binary_to_base58(signature.compact, :bitcoin)
|
24
33
|
"#{encoded_public_key}:#{time}:#{encoded_signature}"
|
25
34
|
end
|
35
|
+
|
36
|
+
def uri_builder(*args)
|
37
|
+
raise "At least one parameter is needed!" if args.size < 1
|
38
|
+
access_token = generate_access_code
|
39
|
+
args.insert(1, access_token)
|
40
|
+
args.unshift(QueryRoot)
|
41
|
+
args.join('/')
|
42
|
+
end
|
26
43
|
end
|
27
44
|
end
|
@@ -25,7 +25,7 @@ module DbchainClient
|
|
25
25
|
sign_message = make_sign_message(tx, messages)
|
26
26
|
signature = @private_key.sign(sign_message)
|
27
27
|
signed_tx = {
|
28
|
-
signature: Base64.strict_encode64(
|
28
|
+
signature: Base64.strict_encode64(signature.compact),
|
29
29
|
pub_key: {
|
30
30
|
type: 'tendermint/PubKeySecp256k1',
|
31
31
|
value: Base64.strict_encode64([@private_key.public_key.public_key_hex].pack("H*"))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbchain_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Zhang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This is the ruby client of DBChain. DBChain is a blockchain based relational
|
14
14
|
database. Developers can use traditional ways to quickly develop blockchain applications
|
@@ -28,7 +28,7 @@ files:
|
|
28
28
|
- lib/dbchain_client/rest_lib.rb
|
29
29
|
- lib/dbchain_client/transaction.rb
|
30
30
|
- lib/dbchain_client/writer.rb
|
31
|
-
homepage: https://
|
31
|
+
homepage: https://github.com/dbchaincloud/ruby-client
|
32
32
|
licenses:
|
33
33
|
- MIT
|
34
34
|
metadata: {}
|