RecordsKeeperRubyLib 0.1.0 → 0.1.1
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 +5 -5
- data/.gitignore +2 -1
- data/CODE_OF_CONDUCT.md +0 -8
- data/Gemfile +0 -1
- data/Gemfile.lock +4 -62
- data/LICENSE.txt +2 -2
- data/README.md +92 -1
- data/{RecordsKeeperRuby.gemspec → RecordsKeeperRubyLib.gemspec} +4 -5
- data/bin/console +1 -1
- data/config.yaml +8 -0
- data/docs/{addressdoc.rb → address_doc.rb} +105 -116
- data/docs/{assetsdoc.rb → asset_doc.rb} +54 -65
- data/docs/block_doc.rb +63 -0
- data/docs/blockchain_doc.rb +77 -0
- data/docs/{permissionsdoc.rb → permissions_doc.rb} +54 -65
- data/docs/{streamdoc.rb → stream_doc.rb} +79 -84
- data/docs/{transactiondoc.rb → transaction_doc.rb} +110 -121
- data/docs/{walletdoc.rb → wallet_doc.rb} +122 -133
- data/lib/RecordsKeeperRubyLib.rb +9 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/address.rb +198 -186
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/assets.rb +99 -87
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/block.rb +94 -89
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/blockchain.rb +148 -135
- data/lib/RecordsKeeperRubyLib/config.yaml +8 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/permissions.rb +77 -77
- data/lib/RecordsKeeperRubyLib/stream.rb +220 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/transaction.rb +213 -182
- data/lib/RecordsKeeperRubyLib/version.rb +3 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/wallet.rb +263 -252
- data/lib/config.yaml +8 -0
- metadata +27 -41
- data/docs/blockchaindoc.rb +0 -77
- data/docs/blockdoc.rb +0 -76
- data/lib/RecordsKeeperRuby.rb +0 -9
- data/lib/RecordsKeeperRuby/sample_config.yaml +0 -60
- data/lib/RecordsKeeperRuby/stream.rb +0 -169
- data/lib/RecordsKeeperRuby/version.rb +0 -3
- data/lib/sample_config.yaml +0 -60
- data/sample_config.yaml +0 -60
@@ -1,252 +1,263 @@
|
|
1
|
-
# Library to work with RecordsKeeper wallet.
|
2
|
-
|
3
|
-
# You can create wallet, create multisignature wallet, retrieve wallet's information, retrieve private key of a particular
|
4
|
-
# wallet address, sign message verify message, dump wallet file, backup wallet file, import wallet file, encrypt wallet by
|
5
|
-
# using wallet class. You just have to pass parameters to invoke the pre-defined functions.
|
6
|
-
|
7
|
-
require 'rubygems'
|
8
|
-
require 'httparty'
|
9
|
-
require 'json'
|
10
|
-
require 'binary_parser'
|
11
|
-
require 'yaml'
|
12
|
-
require 'hex_string'
|
13
|
-
|
14
|
-
module
|
15
|
-
class Wallet
|
16
|
-
|
17
|
-
# Entry point for accessing
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@url = cfg['
|
23
|
-
@user = cfg['
|
24
|
-
@password = cfg['
|
25
|
-
@chain = cfg['
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
:
|
93
|
-
:
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
:
|
110
|
-
:
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
:
|
129
|
-
:
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
:
|
148
|
-
:
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
:
|
167
|
-
:
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
:
|
186
|
-
:
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
:
|
205
|
-
:
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
:
|
224
|
-
:
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
1
|
+
# Library to work with RecordsKeeper wallet.
|
2
|
+
|
3
|
+
# You can create wallet, create multisignature wallet, retrieve wallet's information, retrieve private key of a particular
|
4
|
+
# wallet address, sign message verify message, dump wallet file, backup wallet file, import wallet file, encrypt wallet by
|
5
|
+
# using wallet class. You just have to pass parameters to invoke the pre-defined functions.
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'httparty'
|
9
|
+
require 'json'
|
10
|
+
require 'binary_parser'
|
11
|
+
require 'yaml'
|
12
|
+
require 'hex_string'
|
13
|
+
|
14
|
+
module RecordsKeeperRubyLib
|
15
|
+
class Wallet
|
16
|
+
|
17
|
+
# # Entry point for accessing Wallet class functions
|
18
|
+
if File.exist?('config.yaml')
|
19
|
+
# Import values from configuration file.
|
20
|
+
cfg = YAML::load(File.open('config.yaml','r'))
|
21
|
+
|
22
|
+
@url = cfg['url']
|
23
|
+
@user = cfg['rkuser']
|
24
|
+
@password = cfg['passwd']
|
25
|
+
@chain = cfg['chain']
|
26
|
+
|
27
|
+
else
|
28
|
+
#Import using ENV variables
|
29
|
+
|
30
|
+
@url = ENV['url']
|
31
|
+
@user = ENV['rkuser']
|
32
|
+
@password = ENV['passwd']
|
33
|
+
@chain = ENV['chain']
|
34
|
+
end
|
35
|
+
|
36
|
+
# Function to create wallet on RecordsKeeper Blockchain
|
37
|
+
def self.createWallet
|
38
|
+
auth = {:username => @user, :password => @password}
|
39
|
+
options = {
|
40
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
41
|
+
:basic_auth => auth,
|
42
|
+
:body => [ {"method":"createkeypairs","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
43
|
+
}
|
44
|
+
response = HTTParty.get(@url, options)
|
45
|
+
out = response.parsed_response
|
46
|
+
public_address = out[0]['result'][0]['address'] # returns public address of the wallet
|
47
|
+
private_key = out[0]['result'][0]['privkey'] # returns private key of the wallet
|
48
|
+
public_key = out[0]['result'][0]['pubkey'] # returns public key of the wallet
|
49
|
+
|
50
|
+
def self.importAddress public_address
|
51
|
+
auth = {:username => @user, :password => @password}
|
52
|
+
options = {
|
53
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
54
|
+
:basic_auth => auth,
|
55
|
+
:body => [ {"method":"importaddress","params":[public_address, " ", false],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
56
|
+
}
|
57
|
+
response = HTTParty.get(@url, options)
|
58
|
+
out = response.parsed_response
|
59
|
+
result = out[0]['result']
|
60
|
+
return result;
|
61
|
+
end
|
62
|
+
import_address = importAddress public_address
|
63
|
+
retrieve = {:public_address => public_address,:private_key => private_key,:public_key => public_key}
|
64
|
+
retrievedinfo = JSON.generate retrieve
|
65
|
+
return retrievedinfo
|
66
|
+
end
|
67
|
+
|
68
|
+
# Function to retrieve private key of a wallet address on RecordsKeeper Blockchain
|
69
|
+
def self.getPrivateKey public_address
|
70
|
+
auth = {:username => @user, :password => @password}
|
71
|
+
options = {
|
72
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
73
|
+
:basic_auth => auth,
|
74
|
+
:body => [ {"method":"dumpprivkey","params":[public_address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
75
|
+
}
|
76
|
+
response = HTTParty.get(@url, options)
|
77
|
+
out = response.parsed_response
|
78
|
+
result = out[0]['result']
|
79
|
+
if result.nil?
|
80
|
+
private_key = out[0]['error']['message']
|
81
|
+
else
|
82
|
+
private_key = out[0]['result']
|
83
|
+
end
|
84
|
+
return private_key; #returns private key
|
85
|
+
end
|
86
|
+
|
87
|
+
# Function to retrieve wallet's information on RecordsKeeper Blockchain
|
88
|
+
def self.retrieveWalletinfo
|
89
|
+
auth = {:username => @user, :password => @password}
|
90
|
+
options = {
|
91
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
92
|
+
:basic_auth => auth,
|
93
|
+
:body => [ {"method":"getwalletinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
94
|
+
}
|
95
|
+
response = HTTParty.get(@url, options)
|
96
|
+
out = response.parsed_response
|
97
|
+
balance = out[0]['result']['balance']
|
98
|
+
tx_count = out[0]['result']['txcount']
|
99
|
+
unspent_tx = out[0]['result']['utxocount']
|
100
|
+
retrieve = {:balance => balance,:tx_count => tx_count,:unspent_tx => unspent_tx}
|
101
|
+
retrievedinfo = JSON.generate retrieve
|
102
|
+
return retrievedinfo
|
103
|
+
end
|
104
|
+
|
105
|
+
# Function to create wallet's backup on RecordsKeeper Blockchain
|
106
|
+
def self.backupWallet filename
|
107
|
+
auth = {:username => @user, :password => @password}
|
108
|
+
options = {
|
109
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
110
|
+
:basic_auth => auth,
|
111
|
+
:body => [ {"method":"backupwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
112
|
+
}
|
113
|
+
response = HTTParty.get(@url, options)
|
114
|
+
out = response.parsed_response
|
115
|
+
result = out[0]['result']
|
116
|
+
if result.nil?
|
117
|
+
res = "Backup successful!"
|
118
|
+
else
|
119
|
+
res = out[0]['error']['message']
|
120
|
+
end
|
121
|
+
return res; #returns result
|
122
|
+
end
|
123
|
+
|
124
|
+
# Function to import wallet's backup on RecordsKeeper Blockchain
|
125
|
+
def self.importWallet filename
|
126
|
+
auth = {:username => @user, :password => @password}
|
127
|
+
options = {
|
128
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
129
|
+
:basic_auth => auth,
|
130
|
+
:body => [ {"method":"importwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
131
|
+
}
|
132
|
+
response = HTTParty.get(@url, options)
|
133
|
+
out = response.parsed_response
|
134
|
+
result = out[0]['result']
|
135
|
+
if result.nil?
|
136
|
+
res = "Wallet is successfully imported"
|
137
|
+
else
|
138
|
+
res = out[0]['error']['message']
|
139
|
+
end
|
140
|
+
return res; #returns result
|
141
|
+
end
|
142
|
+
|
143
|
+
# Function to dump wallet on RecordsKeeper Blockchain
|
144
|
+
def self.dumpWallet filename
|
145
|
+
auth = {:username => @user, :password => @password}
|
146
|
+
options = {
|
147
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
148
|
+
:basic_auth => auth,
|
149
|
+
:body => [ {"method":"dumpwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
150
|
+
}
|
151
|
+
response = HTTParty.get(@url, options)
|
152
|
+
out = response.parsed_response
|
153
|
+
result = out[0]['result']
|
154
|
+
if result.nil?
|
155
|
+
res = "Wallet is successfully dumped"
|
156
|
+
else
|
157
|
+
res = out[0]['error']['message']
|
158
|
+
end
|
159
|
+
return res; #returns result
|
160
|
+
end
|
161
|
+
|
162
|
+
# Function to lock wallet on RecordsKeeper Blockchain
|
163
|
+
def self.lockWallet password
|
164
|
+
auth = {:username => @user, :password => @password}
|
165
|
+
options = {
|
166
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
167
|
+
:basic_auth => auth,
|
168
|
+
:body => [ {"method":"encryptwallet","params":[password],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
169
|
+
}
|
170
|
+
response = HTTParty.get(@url, options)
|
171
|
+
out = response.parsed_response
|
172
|
+
result = out[0]['result']
|
173
|
+
if result.nil?
|
174
|
+
res = "Wallet is successfully encrypted."
|
175
|
+
else
|
176
|
+
res = out[0]['error']['message']
|
177
|
+
end
|
178
|
+
return res; #returns result
|
179
|
+
end
|
180
|
+
|
181
|
+
# Function to unlock wallet on RecordsKeeper Blockchain
|
182
|
+
def self.unlockWallet password, unlocktime
|
183
|
+
auth = {:username => @user, :password => @password}
|
184
|
+
options = {
|
185
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
186
|
+
:basic_auth => auth,
|
187
|
+
:body => [ {"method":"walletpassphrase","params":[password, unlocktime],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
188
|
+
}
|
189
|
+
response = HTTParty.get(@url, options)
|
190
|
+
out = response.parsed_response
|
191
|
+
result = out[0]['result']
|
192
|
+
if result.nil?
|
193
|
+
res = "Wallet is successfully unlocked."
|
194
|
+
else
|
195
|
+
res = out[0]['error']['message']
|
196
|
+
end
|
197
|
+
return res; #returns result
|
198
|
+
end
|
199
|
+
|
200
|
+
# Function to change password for wallet on RecordsKeeper Blockchain
|
201
|
+
def self.changeWalletPassword old_password, new_password
|
202
|
+
auth = {:username => @user, :password => @password}
|
203
|
+
options = {
|
204
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
205
|
+
:basic_auth => auth,
|
206
|
+
:body => [ {"method":"walletpassphrasechange","params":[old_password, new_password],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
207
|
+
}
|
208
|
+
response = HTTParty.get(@url, options)
|
209
|
+
out = response.parsed_response
|
210
|
+
result = out[0]['result']
|
211
|
+
if result.nil?
|
212
|
+
res = "Password successfully changed!"
|
213
|
+
else
|
214
|
+
res = out[0]['error']['message']
|
215
|
+
end
|
216
|
+
return res; #returns result
|
217
|
+
end
|
218
|
+
|
219
|
+
# Function to sign message on RecordsKeeper Blockchain
|
220
|
+
def self.signMessage private_key, message
|
221
|
+
auth = {:username => @user, :password => @password}
|
222
|
+
options = {
|
223
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
224
|
+
:basic_auth => auth,
|
225
|
+
:body => [ {"method":"signmessage","params":[private_key, message],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
226
|
+
}
|
227
|
+
response = HTTParty.get(@url, options)
|
228
|
+
out = response.parsed_response
|
229
|
+
check = out[0]['result']
|
230
|
+
|
231
|
+
if check.nil?
|
232
|
+
signedMessage = out[0]['error']['message']
|
233
|
+
else
|
234
|
+
signedMessage = out[0]['result']
|
235
|
+
end
|
236
|
+
return signedMessage; #returns private key
|
237
|
+
end
|
238
|
+
|
239
|
+
# Function to verify message on RecordsKeeper Blockchain
|
240
|
+
def self.verifyMessage address, signedMessage, message
|
241
|
+
auth = {:username => @user, :password => @password}
|
242
|
+
options = {
|
243
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
244
|
+
:basic_auth => auth,
|
245
|
+
:body => [ {"method":"verifymessage","params":[address, signedMessage, message],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
246
|
+
}
|
247
|
+
response = HTTParty.get(@url, options)
|
248
|
+
out = response.parsed_response
|
249
|
+
verifiedMessage = out[0]['result']
|
250
|
+
error = out[0]['error']
|
251
|
+
if verifiedMessage
|
252
|
+
validity = "Yes, message is verified"
|
253
|
+
elsif error.nil?
|
254
|
+
validity = "No, signedMessage is not correct"
|
255
|
+
else
|
256
|
+
validity = error['message']
|
257
|
+
end
|
258
|
+
return validity; #returns validity
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|