test_sdk1 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +1 -0
  3. data/LICENSE +201 -0
  4. data/README.md +147 -0
  5. data/SECURITY.md +12 -0
  6. data/lib/crypto/00_asymmetric_key.rb +95 -0
  7. data/lib/crypto/01_ed25519.rb +67 -0
  8. data/lib/crypto/asymmetric_key.rb +87 -0
  9. data/lib/crypto/ed25519_key.rb +44 -0
  10. data/lib/crypto/key_pair.rb +40 -0
  11. data/lib/crypto/keys.rb +7 -0
  12. data/lib/crypto/secp256k1_key.rb +0 -0
  13. data/lib/crypto/test_ed25519_key.rb +44 -0
  14. data/lib/entity/account.rb +45 -0
  15. data/lib/entity/action_thresholds.rb +25 -0
  16. data/lib/entity/associated_key.rb +24 -0
  17. data/lib/entity/auction_state.rb +36 -0
  18. data/lib/entity/bid.rb +24 -0
  19. data/lib/entity/bid_info.rb +51 -0
  20. data/lib/entity/contract.rb +47 -0
  21. data/lib/entity/contract_package.rb +41 -0
  22. data/lib/entity/contract_version.rb +33 -0
  23. data/lib/entity/delegator.rb +37 -0
  24. data/lib/entity/deploy.rb +44 -0
  25. data/lib/entity/deploy_approval.rb +24 -0
  26. data/lib/entity/deploy_executable.rb +162 -0
  27. data/lib/entity/deploy_executable_item_internal.rb +26 -0
  28. data/lib/entity/deploy_executable_transfer.rb +50 -0
  29. data/lib/entity/deploy_hash.rb +16 -0
  30. data/lib/entity/deploy_header.rb +60 -0
  31. data/lib/entity/deploy_info.rb +44 -0
  32. data/lib/entity/deploy_named_argument.rb +19 -0
  33. data/lib/entity/deploy_transfer.rb +10 -0
  34. data/lib/entity/disabled_version.rb +26 -0
  35. data/lib/entity/era_info.rb +18 -0
  36. data/lib/entity/era_summary.rb +44 -0
  37. data/lib/entity/era_validator.rb +23 -0
  38. data/lib/entity/executable_deploy_item.rb +11 -0
  39. data/lib/entity/group.rb +25 -0
  40. data/lib/entity/module_bytes.rb +50 -0
  41. data/lib/entity/peer.rb +25 -0
  42. data/lib/entity/seigniorage_allocation.rb +18 -0
  43. data/lib/entity/stored_contract_by_hash.rb +50 -0
  44. data/lib/entity/stored_contract_by_name.rb +50 -0
  45. data/lib/entity/stored_value.rb +57 -0
  46. data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
  47. data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
  48. data/lib/entity/transfer.rb +65 -0
  49. data/lib/entity/validator_weight.rb +23 -0
  50. data/lib/entity/vesting_schedule.rb +22 -0
  51. data/lib/include.rb +18 -0
  52. data/lib/rpc/rpc.rb +227 -0
  53. data/lib/rpc/rpc_client.rb +233 -0
  54. data/lib/rpc/rpc_error.rb +79 -0
  55. data/lib/serialization/cl_type_serializer.rb +76 -0
  56. data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
  57. data/lib/serialization/cl_value_serializer.rb +259 -0
  58. data/lib/serialization/deploy_approval_serializer.rb +15 -0
  59. data/lib/serialization/deploy_executable_serializer.rb +27 -0
  60. data/lib/serialization/deploy_header_serializer.rb +49 -0
  61. data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
  62. data/lib/serialization/deploy_serializer.rb +268 -0
  63. data/lib/serialization/test.rb +431 -0
  64. data/lib/test_sdk1.rb +289 -0
  65. data/lib/types/cl_account_hash.rb +24 -0
  66. data/lib/types/cl_account_hash_type.rb +22 -0
  67. data/lib/types/cl_any.rb +25 -0
  68. data/lib/types/cl_any_type.rb +22 -0
  69. data/lib/types/cl_bool.rb +32 -0
  70. data/lib/types/cl_bool_type.rb +35 -0
  71. data/lib/types/cl_byte_array.rb +25 -0
  72. data/lib/types/cl_byte_array_type.rb +27 -0
  73. data/lib/types/cl_i32.rb +26 -0
  74. data/lib/types/cl_i32_type.rb +26 -0
  75. data/lib/types/cl_i64.rb +26 -0
  76. data/lib/types/cl_i64_type.rb +27 -0
  77. data/lib/types/cl_key.rb +39 -0
  78. data/lib/types/cl_key_type.rb +27 -0
  79. data/lib/types/cl_list.rb +25 -0
  80. data/lib/types/cl_list_type.rb +26 -0
  81. data/lib/types/cl_map.rb +25 -0
  82. data/lib/types/cl_map_type.rb +26 -0
  83. data/lib/types/cl_option.rb +33 -0
  84. data/lib/types/cl_option_type.rb +52 -0
  85. data/lib/types/cl_public_key.rb +152 -0
  86. data/lib/types/cl_public_key_type.rb +26 -0
  87. data/lib/types/cl_result.rb +25 -0
  88. data/lib/types/cl_result_type.rb +26 -0
  89. data/lib/types/cl_string.rb +39 -0
  90. data/lib/types/cl_string_type.rb +32 -0
  91. data/lib/types/cl_tuple.rb +151 -0
  92. data/lib/types/cl_tuple_type.rb +108 -0
  93. data/lib/types/cl_type.rb +94 -0
  94. data/lib/types/cl_type_tag.rb +51 -0
  95. data/lib/types/cl_u128.rb +26 -0
  96. data/lib/types/cl_u128_type.rb +26 -0
  97. data/lib/types/cl_u256.rb +26 -0
  98. data/lib/types/cl_u256_type.rb +26 -0
  99. data/lib/types/cl_u32.rb +26 -0
  100. data/lib/types/cl_u32_type.rb +26 -0
  101. data/lib/types/cl_u512.rb +26 -0
  102. data/lib/types/cl_u512_type.rb +26 -0
  103. data/lib/types/cl_u64.rb +26 -0
  104. data/lib/types/cl_u64_type.rb +27 -0
  105. data/lib/types/cl_u8.rb +26 -0
  106. data/lib/types/cl_u8_type.rb +26 -0
  107. data/lib/types/cl_unit.rb +38 -0
  108. data/lib/types/cl_unit_type.rb +22 -0
  109. data/lib/types/cl_uref.rb +120 -0
  110. data/lib/types/cl_uref_type.rb +46 -0
  111. data/lib/types/cl_value.rb +10 -0
  112. data/lib/types/constants.rb +50 -0
  113. data/lib/types/error.rb +7 -0
  114. data/lib/utils/base_16.rb +18 -0
  115. data/lib/utils/byte_utils.rb +107 -0
  116. data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
  117. data/lib/utils/hash_utils.rb +19 -0
  118. data/lib/utils/hex_utils.rb +12 -0
  119. data/lib/utils/time_utils.rb +85 -0
  120. data/lib/utils/utils.rb +2 -0
  121. data/lib/version.rb +3 -0
  122. data/spec/a_spec.rb +697 -0
  123. data/spec/byte_utils_spec.rb +72 -0
  124. data/spec/cl_public_spec.rb +169 -0
  125. data/spec/cl_types_spec.rb +715 -0
  126. data/spec/cl_value_serializer_spec.rb +140 -0
  127. data/spec/client_spec.rb +25 -0
  128. data/spec/crypto_spec.rb +42 -0
  129. data/spec/deploy_approval_serializer_spec.rb +26 -0
  130. data/spec/deploy_executable_serializer_spec.rb +0 -0
  131. data/spec/deploy_header_serializer_spec.rb +21 -0
  132. data/spec/deploy_named_arg_serializer_spec.rb +49 -0
  133. data/spec/deploy_serializer_spec.rb +77 -0
  134. data/spec/deploy_serializer_test_spec.rb +225 -0
  135. data/spec/mainnet_spec.rb +452 -0
  136. data/spec/spec_helper.rb +100 -0
  137. data/spec/string_spec.rb +68 -0
  138. data/spec/testnet_spec.rb +498 -0
  139. data/spec/time_utils_spec.rb +87 -0
  140. metadata +198 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9712f691a560569a3121f7c5ad9d89a0e0a745b40cc5c1f9344ce73d9e09af84
4
+ data.tar.gz: 653cde3e0bf5aeb8dc87abe17f5e8eaac2b3fb9d64eb816cf4def1fcab120d18
5
+ SHA512:
6
+ metadata.gz: 2670f2470ae0afbe934af510a4b06c9b96ae74ef6b9df665f9af8a0ac411b227cc3cc4927a25cc539a32c2fb33717d69bc4d7dcfaf1b593001cc134898c212e2
7
+ data.tar.gz: f28a9700ee6dc7be50a03d77388d570251cb0194e3918fdb327e07e3787764cafa314c4cebd8ee6c7e424e06e62b8bbc67d7ce9b420c4b6f9dbd82860cb1b68b
data/CONTRIBUTING.md ADDED
@@ -0,0 +1 @@
1
+ # Contributing to Casper Ruby SDK
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # Casper Ruby SDK
2
+ The Ruby SDK enables developers to interact with the Casper Network.
3
+
4
+ ## Requirements
5
+ Click [rbenv](https://github.com/rbenv/rbenv) or [here (Steps: 1, 2, 3)](https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-20-04) to install dependencies.
6
+ ```bash
7
+ ruby -v
8
+ # ruby 3.0.2
9
+ ```
10
+ ```bash
11
+ # Install bundler
12
+ gem install bundler
13
+ ```
14
+ ## How to install
15
+
16
+ ```bash
17
+ # There are two options to install casper_network
18
+
19
+ # Option 1:
20
+ # Install casper_network that is available in the https://guides.rubygems.org/
21
+ gem install casper_network
22
+
23
+ # Option 2:
24
+ git clone git@github.com:saitgulmez/casper-ruby-sdk.git
25
+ cd casper-ruby-sdk
26
+ # It automatically installs all the required gems located in the Gemfile
27
+ bundle install
28
+ # Install casper_network gem from repository
29
+ # casper_network-X.Y.Z.gem will be generated after running below command
30
+ gem build casper_network.gemspec
31
+ # (X, Y, Z depends on s.version described in the casper_network.gemspec)
32
+ gem install casper_network-X.Y.Z.gem
33
+ ```
34
+
35
+ ## How to build
36
+ ```bash
37
+ gem build casper_network.gemspec
38
+ ```
39
+
40
+ ## How to run tests
41
+ ```bash
42
+ # Install RSpec
43
+ gem install rspec
44
+ # Run the test
45
+ bundle exec rspec
46
+ # To see the test results in detail
47
+ bundle exec rspec -fd
48
+ ```
49
+
50
+ ## How to generate docs
51
+ ```bash
52
+ gem install yard
53
+ # Generate documentation from source code
54
+ yardoc lib/**/*.rb lib/*.rb - README.md LICENSE CONTRIBUTING.md SECURITY.md
55
+ # To see the options
56
+ yardoc --help
57
+ ```
58
+
59
+ ## Usage examples
60
+ ### Get 5 peer IP addresses randomly
61
+ ```ruby
62
+ require 'casper_network'
63
+
64
+ # In order to interact with casper network we should give a valid ip address to the constructor
65
+
66
+ # if it does not work, please choose another node ip address from the Testnet
67
+ # IP is taken from "Testnet"
68
+ node_ip_address = "85.114.132.129"
69
+ # block_Hash taken from Testnet
70
+ block_hash = "71e19e2e9629c716dc9578066cfeceace559d32fe51b08245ddd4d218f8c18da"
71
+ # deploy_Hash taken from Testnet
72
+ deploy_hash = "d3e0a1bd85ee74916e096cf4b18df391ada414d0915aeb865eff0ba75f04c3d8"
73
+ state_root_hash = "2a62440a1e1e57bff71344aac8a7de169f6dd08d29cffe83b2fb5d6648971855"
74
+ item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
75
+ uref = "uref-9199d08ff4ca4d52cd7a05ba0d2694204b7ebff963fec1c216f81bf654e0e59f-007"
76
+ switch_block_hash = "9e30104581a492f5c6faad4cdfb098311e3bf0e93897ebbfb47c3df62f5e6375"
77
+
78
+
79
+ # Uncomment following lines to test on Mainnet
80
+ # if it does not work, please choose another node ip address from the Mainnet
81
+ # IP is taken from "Mainnet"
82
+ # node_ip_address = "65.108.78.12"
83
+ # block_Hash taken from MainNet
84
+ # block_hash = "5fdbdf3fa70d37821aa2d1752743e9653befc15e65e40c2655e1ce93a807260f"
85
+ # # deploy_Hash taken from MainNet
86
+ # deploy_hash = "52a40996a88523c475c12e5370ff90b0ae4ec051cfaa57cd048c136b1a83319d"
87
+ # state_root_hash = "7b605ad991c949832fd966495afc3f97a2b8122a1a6afc2610b545a8c07e3456"
88
+ # item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
89
+ # uref = "uref-0d689e987db7ee5be246282c3a7badf0411e34baeeab8e9d73c1223ae4ad02e5-007"
90
+ # switch_block_hash = "4696285db1ca6572f425cada612257f85a58a6a4034c09846afe360ba40e5df0"
91
+
92
+ if (IPAddress.valid? node_ip_address)
93
+ client = Casper::CasperClient.new(node_ip_address)
94
+ peers = client.info_get_peers.sample(5)
95
+ puts "node_id and address of five randomly selected 5 peers:"
96
+ puts peers
97
+
98
+ # Store ip addresses of these peers into an array
99
+ ips = []
100
+ peers.select do |item|
101
+ ip = item["address"]
102
+ ips << ip[0, ip.index(':')]
103
+ end
104
+
105
+ clients = []
106
+ puts "Randomly selected 5 peers ip addresses:"
107
+ ips.each do |ip_address|
108
+ # Create a client object for each iteration
109
+ puts ip_address
110
+ client = CasperClient.new(ip_address)
111
+ clients.push(client)
112
+ end
113
+
114
+
115
+ clients.each do |client|
116
+ puts client.info_get_peers
117
+ puts client.chain_get_StateRootHash(block_hash)
118
+ puts client.chain_get_StateRootHash
119
+ puts client.info_get_deploy(deploy_hash)
120
+ puts client.info_get_status
121
+ puts client.chain_get_block_transfers(block_hash)
122
+ puts client.chain_get_block_transfers
123
+ puts client.chain_get_block(block_hash)
124
+ puts client.chain_get_eraInfo_by_SwitchBlock(switch_block_hash)
125
+ puts client.state_get_item("647C28545316E913969B032Cf506d5D242e0F857061E70Fb3DF55980611ace86", "bid-24b6D5Aabb8F0AC17D272763A405E9CECa9166B75B745Cf200695E172857c2dD", [])
126
+ puts client.state_get_dictionary_item(state_root_hash, item_key, uref)
127
+ state_root_hash = "610e932aef10d3e1fa04940c79a4a2789ee79c17046f1a9b45a2919f3600f3d5"
128
+ uref = "uref-7de5e973b7d70bc2b328814411f2009aafd8dba901cfc2c588ba65088dcd22bb-007"
129
+ puts client.state_get_balance(state_root_hash, uref)
130
+ puts client.state_get_AuctionInfo
131
+
132
+ end
133
+ else
134
+ puts "Invalid IP address"
135
+ end
136
+ ```
137
+ - [Testnet](https://testnet.cspr.live/tools/peers), [Mainnet](https://cspr.live/tools/peers)
138
+ - [doc](https://www.rubydoc.info/gems/casper_network/0.2.1)
139
+
140
+
141
+ ## TODO
142
+ - [x] Ruby version of CLType primitives
143
+ - [x] Ruby version for Casper domain-specific objects
144
+ - [x] Serialization of Casper domain-specific objects
145
+ - [ ] ED25519/SECP256K1 key pairs Wrappers implemented
146
+ - [ ] PutDeploy call implemented and tested
147
+ - [x] SDK calls will return Casper domain-specific objects
data/SECURITY.md ADDED
@@ -0,0 +1,12 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 0.2.0 | :white_check_mark: |
8
+
9
+
10
+ ## Reporting a Vulnerability
11
+
12
+ If you find a security vulnerability in Casper Ruby SDK, please send an email to cenggulmez.65@gmail.com.
@@ -0,0 +1,95 @@
1
+ require_relative '../utils/base_16.rb'
2
+ require_relative '../types/cl_public_key.rb'
3
+ require_relative '../utils/hex_utils.rb'
4
+ require_relative '../utils/hash_utils.rb'
5
+
6
+ CLPublicKeyTag = {
7
+ ED25519: 1,
8
+ SECP256K1: 2
9
+ }
10
+
11
+ SignatureAlgorithm = {
12
+ Ed25519: 'ed25519',
13
+ Secp256K1: 'secp256k1'
14
+ }
15
+
16
+ class AsymmetricKey
17
+ attr_reader :public_key, :private_key, :signature_algorithm
18
+ include Utils::HashUtils
19
+ # @param [CLPublicKey] public_key
20
+ # @param [Array] private_key
21
+ # @param [SignatureAlgorithm] signature_algorithm
22
+ def initialize(public_key, private_key, signature_algorithm)
23
+ @public_key = public_key
24
+ @private_key = private_key
25
+ @signature_algorithm = signature_algorithm
26
+ @tag = @public_key.get_cl_public_key_tag
27
+ end
28
+
29
+ # @return [CLPublicKey]
30
+ def get_public_key
31
+ @public_key
32
+ end
33
+
34
+ def get_signature_algorithm
35
+ @signature_algorithm
36
+ end
37
+
38
+ # Get public hex-encoded string
39
+ #
40
+ # @return [String]
41
+ def get_public_key_hex
42
+ "0#{@tag}" + Utils::Base16.encode16(@public_key.get_value)
43
+ end
44
+
45
+ # @param [CLPublicKey] public_key
46
+ # @return [String] account_hex
47
+ def account_hex(public_key)
48
+ account_hex = @public_key.to_hex
49
+ end
50
+
51
+ # @return [Array<Integer>]
52
+ def account_hash
53
+ @tag = @public_key.get_cl_public_key_tag
54
+ key_name = CLPublicKeyTag.key(@tag).to_s
55
+ prefix = key_name.downcase.unpack("C*") + [0]
56
+ bytes = prefix + @public_key.get_value
57
+ result_array = Utils::HashUtils.byte_hash(bytes)
58
+ @public_key.get_value.length == 0 ? [] : result_array
59
+ #** @public_key.to_account_hash_byte_array
60
+ end
61
+
62
+ # @param [String] path_to_private_key
63
+ def create_from_private_key_file(path_to_private_key)
64
+ puts "AsymmetricKey::create_from_private_key_file is called!"
65
+ end
66
+
67
+ # Get public key which is stored in pem
68
+ def export_public_key_in_pem
69
+ puts "AsymmetricKey::export_public_key_in_pem is called!"
70
+ end
71
+
72
+ # @param [String] message
73
+ # @return [String]
74
+ def sign(message)
75
+ puts "AsymmetricKey:sign is called!"
76
+ end
77
+
78
+
79
+ # @param [String] signature
80
+ # @param [String] message
81
+ # @return [Boolean]
82
+ def verify(signature, message)
83
+ puts "AsymmetricKey::verify is called!"
84
+ end
85
+
86
+ protected
87
+ attr_accessor :private_key
88
+
89
+ def to_pem(tag, content)
90
+ line1 = "-----BEGIN #{tag}-----\n"
91
+ line2 = "#{content}"
92
+ line3 = "-----END #{tag}-----\n"
93
+ line1 + line2 + line3
94
+ end
95
+ end
@@ -0,0 +1,67 @@
1
+ require 'openssl'
2
+ require 'ed25519'
3
+ require_relative './asymmetric_key.rb'
4
+
5
+
6
+
7
+ class Ed25519Key < AsymmetricKey
8
+
9
+ def initialize(public_key, private_key)
10
+ super(public_key, private_key, SignatureAlgorithm[:Ed25519])
11
+ end
12
+
13
+ # @param [Array] public_key
14
+ # @return [String]
15
+ # def self.account_hex(public_key)
16
+ # '01' + Utils::Base16.encode16(public_key)
17
+ # end
18
+
19
+
20
+ def create_from_private_key_file(path_to_private_key)
21
+
22
+ end
23
+
24
+
25
+ def parse_private_key_file(path)
26
+ end
27
+
28
+ def parse_public_key_file(path)
29
+ end
30
+
31
+ def parse_private_key(bytes)
32
+ end
33
+
34
+ def parse_public_key(bytes)
35
+ end
36
+
37
+ def read_base_64_with_pem(content)
38
+ end
39
+
40
+ # private method
41
+ def read_base_64_file(path)
42
+ end
43
+
44
+ # private
45
+ def parse_key(bytes, from, to)
46
+ end
47
+
48
+ def export_private_key_in_pem
49
+ end
50
+
51
+ def export_public_key_in_pem
52
+ end
53
+
54
+ def sign(msg)
55
+ end
56
+
57
+ def verify(signature, msg)
58
+ end
59
+
60
+ def private_to_public(private_key)
61
+ end
62
+
63
+ def load_keypair_from_private_file(private_key_path)
64
+ end
65
+
66
+ end
67
+
@@ -0,0 +1,87 @@
1
+ require_relative '../utils/base_16.rb'
2
+ require_relative '../types/cl_public_key.rb'
3
+ require_relative '../utils/hex_utils.rb'
4
+ require_relative '../utils/hash_utils.rb'
5
+
6
+ CLPublicKeyTag = {
7
+ ED25519: 1,
8
+ SECP256K1: 2
9
+ }
10
+
11
+ SignatureAlgorithm = {
12
+ Ed25519: 'ed25519',
13
+ Secp256K1: 'secp256k1'
14
+ }
15
+
16
+ class AsymmetricKey
17
+ attr_reader :public_key, :private_key, :signature_algorithm
18
+ include Utils::HashUtils
19
+ # @param [CLPublicKey] public_key
20
+ # @param [Array] private_key
21
+ # @param [SignatureAlgorithm] signature_algorithm
22
+ def initialize(public_key, private_key, signature_algorithm)
23
+ @public_key = public_key
24
+ @private_key = private_key
25
+ @signature_algorithm = signature_algorithm
26
+ @tag = @public_key.get_cl_public_key_tag
27
+ end
28
+
29
+ # @return [CLPublicKey]
30
+ def get_public_key
31
+ @public_key
32
+ end
33
+
34
+ def get_signature_algorithm
35
+ @signature_algorithm
36
+ end
37
+
38
+ # Get public hex-encoded string
39
+ #
40
+ # @return [String]
41
+ def get_public_key_hex
42
+ "0#{@tag}" + Utils::Base16.encode16(@public_key.get_value)
43
+ end
44
+
45
+ # @param [CLPublicKey] public_key
46
+ # @return [String] account_hex
47
+ def account_hex(public_key)
48
+ account_hex = @public_key.to_hex
49
+ end
50
+
51
+ # @return [Array<Integer>]
52
+ def account_hash
53
+ @tag = @public_key.get_cl_public_key_tag
54
+ key_name = CLPublicKeyTag.key(@tag).to_s
55
+ prefix = key_name.downcase.unpack("C*") + [0]
56
+ bytes = prefix + @public_key.get_value
57
+ result_array = Utils::HashUtils.byte_hash(bytes)
58
+ @public_key.get_value.length == 0 ? [] : result_array
59
+ #*** @public_key.to_account_hash_byte_array
60
+ end
61
+
62
+ # @param [String] path_to_private_key
63
+ def create_from_private_key_file(path_to_private_key)
64
+ end
65
+
66
+ # Get public key which is stored in pem
67
+ def export_public_key_in_pem
68
+ end
69
+
70
+ # @param [String] message
71
+ # @return [String]
72
+ def sign(message)
73
+ end
74
+
75
+
76
+ # @param [String] signature
77
+ # @param [String] message
78
+ # @return [Boolean]
79
+ def verify(signature, message)
80
+ end
81
+
82
+ protected
83
+ attr_accessor :private_key
84
+
85
+ def to_pem(tag, content)
86
+ end
87
+ end
@@ -0,0 +1,44 @@
1
+ require 'openssl'
2
+ require 'ed25519'
3
+ require_relative './asymmetric_key.rb'
4
+
5
+ # ED25519 private key length in bytes
6
+ PRIVATE_KEY_LENGTH = 32
7
+
8
+ class Ed25519Key < AsymmetricKey
9
+
10
+ def initialize(public_key, private_key)
11
+ super(public_key, private_key, SignatureAlgorithm[:Ed25519])
12
+ end
13
+
14
+ # @param [Array] public_key
15
+ # @return [String]
16
+ # def self.account_hex(public_key)
17
+ # '01' + Utils::Base16.encode16(public_key)
18
+ # end
19
+
20
+
21
+ def create_from_private_key_file(private_key_path)
22
+
23
+ end
24
+
25
+ def export_public_key_in_pem
26
+ end
27
+
28
+ def export_private_key_in_pem
29
+ end
30
+
31
+ def sign(msg)
32
+ end
33
+
34
+ def verify(signature, msg)
35
+ end
36
+
37
+ def private_to_public_key(private_key)
38
+ end
39
+
40
+ def parse_private_key(private_key)
41
+ end
42
+
43
+ end
44
+