laksa 0.1.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 +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +674 -0
- data/README.md +94 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/laksa.gemspec +46 -0
- data/lib/laksa.rb +21 -0
- data/lib/laksa/account/account.rb +34 -0
- data/lib/laksa/account/transaction.rb +184 -0
- data/lib/laksa/account/transaction_factory.rb +16 -0
- data/lib/laksa/account/wallet.rb +129 -0
- data/lib/laksa/contract/contract.rb +148 -0
- data/lib/laksa/contract/contract_factory.rb +47 -0
- data/lib/laksa/crypto/key_store.rb +113 -0
- data/lib/laksa/crypto/key_tool.rb +61 -0
- data/lib/laksa/crypto/schnorr.rb +146 -0
- data/lib/laksa/jsonrpc/provider.rb +23 -0
- data/lib/laksa/proto/message.proto +44 -0
- data/lib/laksa/proto/message_pb.rb +46 -0
- data/lib/laksa/util/bech32.rb +28 -0
- data/lib/laksa/util/unit.rb +37 -0
- data/lib/laksa/util/util.rb +17 -0
- data/lib/laksa/util/validator.rb +40 -0
- data/lib/laksa/version.rb +3 -0
- metadata +201 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'jsonrpc-client'
|
2
|
+
|
3
|
+
module JSONRPC
|
4
|
+
class Base
|
5
|
+
def self.make_id
|
6
|
+
"1"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Laksa
|
12
|
+
module Jsonrpc
|
13
|
+
class Provider
|
14
|
+
def initialize(endpoint)
|
15
|
+
@client = JSONRPC::Client.new(endpoint)
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(sym, *args)
|
19
|
+
@client.invoke(sym.to_s, args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
syntax = "proto2";
|
2
|
+
|
3
|
+
package laksa.proto;
|
4
|
+
|
5
|
+
// ============================================================================
|
6
|
+
// Primitives
|
7
|
+
// ============================================================================
|
8
|
+
|
9
|
+
message ByteArray
|
10
|
+
{
|
11
|
+
required bytes data = 1;
|
12
|
+
}
|
13
|
+
|
14
|
+
message ProtoTransactionCoreInfo
|
15
|
+
{
|
16
|
+
optional uint32 version = 1;
|
17
|
+
optional uint64 nonce = 2;
|
18
|
+
optional bytes toaddr = 3;
|
19
|
+
optional ByteArray senderpubkey = 4;
|
20
|
+
optional ByteArray amount = 5;
|
21
|
+
optional ByteArray gasprice = 6;
|
22
|
+
optional uint64 gaslimit = 7;
|
23
|
+
optional bytes code = 8;
|
24
|
+
optional bytes data = 9;
|
25
|
+
}
|
26
|
+
|
27
|
+
message ProtoTransaction
|
28
|
+
{
|
29
|
+
optional bytes tranid = 1;
|
30
|
+
optional ProtoTransactionCoreInfo info = 2;
|
31
|
+
optional ByteArray signature = 3;
|
32
|
+
}
|
33
|
+
|
34
|
+
message ProtoTransactionReceipt
|
35
|
+
{
|
36
|
+
optional bytes receipt = 1;
|
37
|
+
optional uint64 cumgas = 2;
|
38
|
+
}
|
39
|
+
|
40
|
+
message ProtoTransactionWithReceipt
|
41
|
+
{
|
42
|
+
optional ProtoTransaction transaction = 1;
|
43
|
+
optional ProtoTransactionReceipt receipt = 2;
|
44
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: message.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_file("message.proto", :syntax => :proto2) do
|
8
|
+
add_message "laksa.proto.ByteArray" do
|
9
|
+
required :data, :bytes, 1
|
10
|
+
end
|
11
|
+
add_message "laksa.proto.ProtoTransactionCoreInfo" do
|
12
|
+
optional :version, :uint32, 1
|
13
|
+
optional :nonce, :uint64, 2
|
14
|
+
optional :toaddr, :bytes, 3
|
15
|
+
optional :senderpubkey, :message, 4, "laksa.proto.ByteArray"
|
16
|
+
optional :amount, :message, 5, "laksa.proto.ByteArray"
|
17
|
+
optional :gasprice, :message, 6, "laksa.proto.ByteArray"
|
18
|
+
optional :gaslimit, :uint64, 7
|
19
|
+
optional :code, :bytes, 8
|
20
|
+
optional :data, :bytes, 9
|
21
|
+
end
|
22
|
+
add_message "laksa.proto.ProtoTransaction" do
|
23
|
+
optional :tranid, :bytes, 1
|
24
|
+
optional :info, :message, 2, "laksa.proto.ProtoTransactionCoreInfo"
|
25
|
+
optional :signature, :message, 3, "laksa.proto.ByteArray"
|
26
|
+
end
|
27
|
+
add_message "laksa.proto.ProtoTransactionReceipt" do
|
28
|
+
optional :receipt, :bytes, 1
|
29
|
+
optional :cumgas, :uint64, 2
|
30
|
+
end
|
31
|
+
add_message "laksa.proto.ProtoTransactionWithReceipt" do
|
32
|
+
optional :transaction, :message, 1, "laksa.proto.ProtoTransaction"
|
33
|
+
optional :receipt, :message, 2, "laksa.proto.ProtoTransactionReceipt"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module Laksa
|
39
|
+
module Proto
|
40
|
+
ByteArray = Google::Protobuf::DescriptorPool.generated_pool.lookup("laksa.proto.ByteArray").msgclass
|
41
|
+
ProtoTransactionCoreInfo = Google::Protobuf::DescriptorPool.generated_pool.lookup("laksa.proto.ProtoTransactionCoreInfo").msgclass
|
42
|
+
ProtoTransaction = Google::Protobuf::DescriptorPool.generated_pool.lookup("laksa.proto.ProtoTransaction").msgclass
|
43
|
+
ProtoTransactionReceipt = Google::Protobuf::DescriptorPool.generated_pool.lookup("laksa.proto.ProtoTransactionReceipt").msgclass
|
44
|
+
ProtoTransactionWithReceipt = Google::Protobuf::DescriptorPool.generated_pool.lookup("laksa.proto.ProtoTransactionWithReceipt").msgclass
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bitcoin'
|
2
|
+
|
3
|
+
module Laksa
|
4
|
+
module Util
|
5
|
+
class Bech32
|
6
|
+
|
7
|
+
def self.to_bech32(address)
|
8
|
+
raise 'Invalid address format.' unless Validator.address?(address)
|
9
|
+
|
10
|
+
address = address.sub('0x','')
|
11
|
+
|
12
|
+
ret = Bitcoin::Bech32.convert_bits(Util.decode_hex(address).bytes, from_bits: 8, to_bits: 5, pad: false)
|
13
|
+
|
14
|
+
Bitcoin::Bech32.encode('zil', ret);
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_bech32(address)
|
18
|
+
data = Bitcoin::Bech32.decode(address)
|
19
|
+
|
20
|
+
raise 'Expected hrp to be zil' unless data[0] == 'zil'
|
21
|
+
|
22
|
+
ret = Bitcoin::Bech32.convert_bits(data[1], from_bits: 5, to_bits: 8, pad: false)
|
23
|
+
|
24
|
+
Laksa::Account::Wallet.to_checksum_address(Util.encode_hex(ret.pack('c*'))).sub('0x', '')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Laksa
|
2
|
+
module Util
|
3
|
+
class Unit
|
4
|
+
ZIL = 'zil'
|
5
|
+
LI = 'li'
|
6
|
+
QA = 'qa'
|
7
|
+
|
8
|
+
def self.from_qa(qa, unit, is_pack = false)
|
9
|
+
ret = case unit
|
10
|
+
when ZIL
|
11
|
+
qa / 1000000000000.0
|
12
|
+
when LI
|
13
|
+
qa / 1000000.0
|
14
|
+
when QA
|
15
|
+
qa
|
16
|
+
end
|
17
|
+
|
18
|
+
if is_pack
|
19
|
+
ret.round
|
20
|
+
else
|
21
|
+
ret
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.to_qa(qa, unit)
|
26
|
+
case unit
|
27
|
+
when ZIL
|
28
|
+
qa * 1000000000000
|
29
|
+
when LI
|
30
|
+
qa * 1000000
|
31
|
+
when QA
|
32
|
+
qa
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Laksa
|
2
|
+
module Util
|
3
|
+
class Validator
|
4
|
+
def self.public_key?(public_key)
|
5
|
+
m = /(0x)?\h{66}/ =~ public_key
|
6
|
+
m != nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.private_key?(private_key)
|
10
|
+
m = /(0x)?\h{64}/ =~ private_key
|
11
|
+
m != nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.address?(address)
|
15
|
+
m = /(0x)?\h{40}/ =~ address
|
16
|
+
m != nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.signature?(signature)
|
20
|
+
m = /(0x)?\h{128}/ =~ signature
|
21
|
+
m != nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# checksum_address?
|
25
|
+
#
|
26
|
+
# takes hex-encoded string and returns boolean if address is checksumed
|
27
|
+
#
|
28
|
+
# @param {string} address
|
29
|
+
# @returns {boolean}
|
30
|
+
def self.checksum_address?(address)
|
31
|
+
self.address?(address) && Laksa::Account::Wallet::to_checksum_address(address) == address
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.bech32?(address)
|
35
|
+
m = /^zil1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38}/ =~ address
|
36
|
+
m != nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: laksa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cenyongh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-24 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bitcoin-secp256k1
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: scrypt
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pbkdf2-ruby
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: jsonrpc-client
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: google-protobuf
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: bitcoin-ruby
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: LaksaRuby -- Zilliqa Blockchain Library
|
140
|
+
email:
|
141
|
+
- cenyongh@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".travis.yml"
|
148
|
+
- Gemfile
|
149
|
+
- Gemfile.lock
|
150
|
+
- LICENSE.txt
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- bin/console
|
154
|
+
- bin/setup
|
155
|
+
- laksa.gemspec
|
156
|
+
- lib/laksa.rb
|
157
|
+
- lib/laksa/account/account.rb
|
158
|
+
- lib/laksa/account/transaction.rb
|
159
|
+
- lib/laksa/account/transaction_factory.rb
|
160
|
+
- lib/laksa/account/wallet.rb
|
161
|
+
- lib/laksa/contract/contract.rb
|
162
|
+
- lib/laksa/contract/contract_factory.rb
|
163
|
+
- lib/laksa/crypto/key_store.rb
|
164
|
+
- lib/laksa/crypto/key_tool.rb
|
165
|
+
- lib/laksa/crypto/schnorr.rb
|
166
|
+
- lib/laksa/jsonrpc/provider.rb
|
167
|
+
- lib/laksa/proto/message.proto
|
168
|
+
- lib/laksa/proto/message_pb.rb
|
169
|
+
- lib/laksa/util/bech32.rb
|
170
|
+
- lib/laksa/util/unit.rb
|
171
|
+
- lib/laksa/util/util.rb
|
172
|
+
- lib/laksa/util/validator.rb
|
173
|
+
- lib/laksa/version.rb
|
174
|
+
homepage: https://github.com/FireStack-Lab/LaksaRuby
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata:
|
178
|
+
homepage_uri: https://github.com/FireStack-Lab/LaksaRuby
|
179
|
+
source_code_uri: https://github.com/FireStack-Lab/LaksaRuby
|
180
|
+
changelog_uri: https://github.com/FireStack-Lab/LaksaRuby
|
181
|
+
post_install_message:
|
182
|
+
rdoc_options: []
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
requirements: []
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 2.7.8
|
198
|
+
signing_key:
|
199
|
+
specification_version: 4
|
200
|
+
summary: LaksaRuby -- Zilliqa Blockchain Library
|
201
|
+
test_files: []
|