casper_network 0.2.1 → 1.0.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.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -4
  3. data/lib/casper_network.rb +62 -8
  4. data/lib/crypto/00_asymmetric_key.rb +95 -0
  5. data/lib/crypto/01_ed25519.rb +67 -0
  6. data/lib/crypto/asymmetric_key.rb +87 -0
  7. data/lib/crypto/ed25519_key.rb +44 -0
  8. data/lib/crypto/key_pair.rb +40 -0
  9. data/lib/crypto/keys.rb +7 -0
  10. data/lib/crypto/secp256k1_key.rb +0 -0
  11. data/lib/crypto/test_ed25519_key.rb +44 -0
  12. data/lib/entity/account.rb +45 -0
  13. data/lib/entity/action_thresholds.rb +25 -0
  14. data/lib/entity/associated_key.rb +24 -0
  15. data/lib/entity/auction_state.rb +1 -0
  16. data/lib/entity/bid.rb +1 -0
  17. data/lib/entity/bid_info.rb +1 -0
  18. data/lib/entity/contract.rb +47 -0
  19. data/lib/entity/contract_package.rb +41 -0
  20. data/lib/entity/contract_version.rb +33 -0
  21. data/lib/entity/delegator.rb +1 -0
  22. data/lib/entity/deploy.rb +1 -0
  23. data/lib/entity/deploy_approval.rb +8 -6
  24. data/lib/entity/deploy_executable.rb +155 -1
  25. data/lib/entity/deploy_executable_item_internal.rb +27 -0
  26. data/lib/entity/deploy_executable_transfer.rb +51 -0
  27. data/lib/entity/deploy_hash.rb +1 -0
  28. data/lib/entity/deploy_header.rb +18 -15
  29. data/lib/entity/deploy_info.rb +45 -0
  30. data/lib/entity/deploy_named_argument.rb +20 -0
  31. data/lib/entity/deploy_transfer.rb +11 -0
  32. data/lib/entity/disabled_version.rb +26 -0
  33. data/lib/entity/era_info.rb +18 -0
  34. data/lib/entity/era_summary.rb +1 -0
  35. data/lib/entity/era_validator.rb +1 -0
  36. data/lib/entity/executable_deploy_item.rb +11 -0
  37. data/lib/entity/group.rb +25 -0
  38. data/lib/entity/module_bytes.rb +51 -0
  39. data/lib/entity/peer.rb +1 -0
  40. data/lib/entity/seigniorage_allocation.rb +18 -0
  41. data/lib/entity/stored_contract_by_hash.rb +51 -0
  42. data/lib/entity/stored_contract_by_name.rb +52 -0
  43. data/lib/entity/stored_value.rb +57 -0
  44. data/lib/entity/stored_versioned_contract_by_hash.rb +63 -0
  45. data/lib/entity/stored_versioned_contract_by_name.rb +63 -0
  46. data/lib/entity/transfer.rb +66 -0
  47. data/lib/entity/validator_weight.rb +1 -0
  48. data/lib/entity/vesting_schedule.rb +22 -0
  49. data/lib/include.rb +18 -0
  50. data/lib/rpc/rpc.rb +227 -0
  51. data/lib/rpc/rpc_client.rb +45 -39
  52. data/lib/rpc/rpc_error.rb +1 -0
  53. data/lib/serialization/cl_type_serializer.rb +77 -0
  54. data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
  55. data/lib/serialization/cl_value_serializer.rb +260 -0
  56. data/lib/serialization/deploy_approval_serializer.rb +16 -0
  57. data/lib/serialization/deploy_executable_serializer.rb +27 -0
  58. data/lib/serialization/deploy_header_serializer.rb +49 -0
  59. data/lib/serialization/deploy_named_arg_serializer.rb +20 -0
  60. data/lib/serialization/deploy_serializer.rb +269 -0
  61. data/lib/serialization/test.rb +431 -0
  62. data/lib/types/cl_account_hash.rb +24 -0
  63. data/lib/types/cl_account_hash_type.rb +22 -0
  64. data/lib/types/cl_any.rb +25 -0
  65. data/lib/types/cl_any_type.rb +22 -0
  66. data/lib/types/cl_bool.rb +32 -0
  67. data/lib/types/cl_bool_type.rb +35 -0
  68. data/lib/types/cl_byte_array.rb +25 -0
  69. data/lib/types/cl_byte_array_type.rb +27 -0
  70. data/lib/types/cl_i32.rb +26 -0
  71. data/lib/types/cl_i32_type.rb +26 -0
  72. data/lib/types/cl_i64.rb +26 -0
  73. data/lib/types/cl_i64_type.rb +27 -0
  74. data/lib/types/cl_key.rb +39 -0
  75. data/lib/types/cl_key_type.rb +27 -0
  76. data/lib/types/cl_list.rb +25 -0
  77. data/lib/types/cl_list_type.rb +26 -0
  78. data/lib/types/cl_map.rb +25 -0
  79. data/lib/types/cl_map_type.rb +26 -0
  80. data/lib/types/cl_option.rb +33 -0
  81. data/lib/types/cl_option_type.rb +52 -0
  82. data/lib/types/cl_public_key.rb +152 -0
  83. data/lib/types/cl_public_key_type.rb +26 -0
  84. data/lib/types/cl_result.rb +25 -0
  85. data/lib/types/cl_result_type.rb +26 -0
  86. data/lib/types/cl_string.rb +39 -0
  87. data/lib/types/cl_string_type.rb +32 -0
  88. data/lib/types/cl_tuple.rb +151 -0
  89. data/lib/types/cl_tuple_type.rb +108 -0
  90. data/lib/types/cl_type.rb +96 -0
  91. data/lib/types/cl_type_tag.rb +51 -0
  92. data/lib/types/cl_u128.rb +26 -0
  93. data/lib/types/cl_u128_type.rb +26 -0
  94. data/lib/types/cl_u256.rb +26 -0
  95. data/lib/types/cl_u256_type.rb +26 -0
  96. data/lib/types/cl_u32.rb +26 -0
  97. data/lib/types/cl_u32_type.rb +26 -0
  98. data/lib/types/cl_u512.rb +26 -0
  99. data/lib/types/cl_u512_type.rb +26 -0
  100. data/lib/types/cl_u64.rb +26 -0
  101. data/lib/types/cl_u64_type.rb +27 -0
  102. data/lib/types/cl_u8.rb +26 -0
  103. data/lib/types/cl_u8_type.rb +26 -0
  104. data/lib/types/cl_unit.rb +38 -0
  105. data/lib/types/cl_unit_type.rb +22 -0
  106. data/lib/types/cl_uref.rb +120 -0
  107. data/lib/types/cl_uref_type.rb +46 -0
  108. data/lib/types/cl_value.rb +11 -0
  109. data/lib/types/constants.rb +50 -0
  110. data/lib/types/error.rb +7 -0
  111. data/lib/utils/base_16.rb +18 -0
  112. data/lib/utils/byte_utils.rb +107 -0
  113. data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
  114. data/lib/utils/hash_utils.rb +19 -0
  115. data/lib/utils/hex_utils.rb +12 -0
  116. data/lib/utils/time_utils.rb +85 -0
  117. data/lib/utils/utils.rb +2 -0
  118. data/lib/version.rb +3 -0
  119. data/spec/a_spec.rb +697 -0
  120. data/spec/byte_utils_spec.rb +72 -0
  121. data/spec/cl_public_spec.rb +169 -0
  122. data/spec/cl_types_spec.rb +715 -0
  123. data/spec/cl_value_serializer_spec.rb +140 -0
  124. data/spec/crypto_spec.rb +42 -0
  125. data/spec/deploy_approval_serializer_spec.rb +26 -0
  126. data/spec/deploy_executable_serializer_spec.rb +0 -0
  127. data/spec/deploy_header_serializer_spec.rb +21 -0
  128. data/spec/deploy_named_arg_serializer_spec.rb +49 -0
  129. data/spec/deploy_serializer_spec.rb +77 -0
  130. data/spec/deploy_serializer_test_spec.rb +225 -0
  131. data/spec/mainnet_spec.rb +8 -8
  132. data/spec/string_spec.rb +68 -0
  133. data/spec/testnet_spec.rb +11 -11
  134. data/spec/time_utils_spec.rb +87 -0
  135. metadata +130 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f511c7cefe099bfc5f6a67280f7826c179e9127f4dd8facf554351cdc132ab19
4
- data.tar.gz: '08057f40c2f037da844a3a4f816ca538eb7985e71a41ae0d02303fc65f9527f1'
3
+ metadata.gz: 79a82b8fd4b57919a7bfe74dcd42f79fcdcac5a89a68722ee5d9d0cc4f621f76
4
+ data.tar.gz: 4c77091a8448de28de05cf8af7b19e32bd21f6e7dc2916f8e91c1def1738db7d
5
5
  SHA512:
6
- metadata.gz: 61ca00e871d1fba6c79bf31b60dec38c5285d95675c457823843c7cb99956baadd96bf15c1953d0adbdf01caa5b31179a46ad528e9f3c48c5a203dc194194977
7
- data.tar.gz: e9eb9a792d46f97a9316914c7d0cb885a48568b2f162feb97225cb64ff2a428d47b5a8b448c9aa941fc19275ad4da6dc8751694c6a95df97fd904948079d03a7
6
+ metadata.gz: e884413451fb3e760745245319570d2a299c276c0885042c170821e535aaec7eeed65772e68c6c444f63674ba60d4d2ee2933a99dd8512b0b0975909faada95c
7
+ data.tar.gz: e01d429e70bf95b5a2e3197de1fec5a935a7507adb553bf52cf773d862a919f090c0e6654744aa5d4b7aae1f0915d3a6595f79b7951d6ab8f43236ccbd27ea94
data/README.md CHANGED
@@ -53,6 +53,8 @@ git checkout main
53
53
  rspec spec/testnet_spec.rb
54
54
  # To see the test results in detail
55
55
  rspec -fd spec/testnet_spec.rb
56
+ # Test for cltypes
57
+ rspec -fd spec/cl_types_spec.rb
56
58
  ```
57
59
 
58
60
  ## Mainnet Tests
@@ -79,7 +81,7 @@ require 'casper_network'
79
81
 
80
82
  # In order to interact with casper network we should give a valid ip address to the constructor
81
83
 
82
- # if it does not work, please choose another node ip address from the link1
84
+ # if it does not work, please choose another node ip address from the Testnet
83
85
  # IP is taken from "Testnet"
84
86
  node_ip_address = "85.114.132.129"
85
87
  # block_Hash taken from Testnet
@@ -93,7 +95,7 @@ switch_block_hash = "9e30104581a492f5c6faad4cdfb098311e3bf0e93897ebbfb47c3df62f5
93
95
 
94
96
 
95
97
  # Uncomment following lines to test on Mainnet
96
- # if it does not work, please choose another node ip address from the link2
98
+ # if it does not work, please choose another node ip address from the Mainnet
97
99
  # IP is taken from "Mainnet"
98
100
  # node_ip_address = "65.108.78.12"
99
101
  # block_Hash taken from MainNet
@@ -150,5 +152,14 @@ else
150
152
  puts "Invalid IP address"
151
153
  end
152
154
  ```
153
- - [link1](https://testnet.cspr.live/tools/peers), [link2](https://cspr.live/tools/peers)
154
- - [doc](https://htmlpreview.github.io/?https://raw.githubusercontent.com/saitgulmez/casper-ruby-sdk/main/doc/index.html)
155
+ - [Testnet](https://testnet.cspr.live/tools/peers), [Mainnet](https://cspr.live/tools/peers)
156
+ - [doc](https://www.rubydoc.info/gems/casper_network/0.2.1)
157
+
158
+
159
+ ## TODO
160
+ - [ ] Ruby version of CLType primitives
161
+ - [ ] Ruby version for Casper domain-specific objects
162
+ - [ ] Serialization of Casper domain-specific objects
163
+ - [ ] ED25519/SECP256K1 key pairs Wrappers implemented
164
+ - [ ] PutDeploy call implemented and tested
165
+ - [ ] SDK calls will return Casper domain-specific objects
@@ -9,8 +9,14 @@ require 'timeout'
9
9
  require 'net/http'
10
10
  # require "./rpc/rpc.rb"
11
11
  require_relative './rpc/rpc_error.rb'
12
- # Class for interacting with the network via RPC
12
+ require_relative './rpc/rpc_client.rb'
13
+
14
+ # Dir["./entity/*.rb"].each {|file| require file }
15
+ # Dir["./serialization/*.rb"].each {|file| require file }
16
+ # Dir["./types/*.rb"].each {|file| require file }
17
+ require_relative './include.rb'
13
18
  module Casper
19
+ # Interacting with the network
14
20
  class CasperClient
15
21
  attr_accessor :ip_address, :port, :url, :state_root_hash
16
22
 
@@ -33,18 +39,37 @@ module Casper
33
39
  @rpc_error = Casper::RpcError::ErrorHandle.new
34
40
  @err = @rpc_error.error_handling(@url)
35
41
 
42
+ @pr = []
43
+
36
44
  end
37
45
 
38
46
  def get_error
39
47
  @err
40
48
  end
41
49
 
50
+ # @return [Array<Hash>] peers array
51
+ # def info_get_peers
52
+ # begin
53
+ # client = Jimson::Client.new(@url)
54
+ # response = client.info_get_peers
55
+ # @peer_array = response["peers"]
56
+ # rescue
57
+ # @rpc_error = Casper::RpcError::ErrorHandle.new
58
+ # @error = @rpc_error.error_handling(@url)
59
+ # end
60
+ # end
61
+
42
62
  # @return [Array<Hash>] peers array
43
63
  def info_get_peers
44
64
  begin
45
65
  client = Jimson::Client.new(@url)
46
66
  response = client.info_get_peers
47
- @peer_array = response["peers"]
67
+ @peers = response["peers"]
68
+ # @peers.map! do |peer|
69
+ # peer.symbolize_keys
70
+ # end
71
+ @peers.map { |item| @pr << Casper::Entity::Peer.new(item.symbolize_keys) }
72
+ @pr
48
73
  rescue
49
74
  @rpc_error = Casper::RpcError::ErrorHandle.new
50
75
  @error = @rpc_error.error_handling(@url)
@@ -68,19 +93,40 @@ module Casper
68
93
  # Get information about a single deploy by hash.
69
94
  # @param [String] deploy_hash
70
95
  # @return [Hash] Deploy
96
+ # def info_get_deploy(deploy_hash)
97
+ # begin
98
+ # status = Timeout::timeout(10) {
99
+ # client = Jimson::Client.new(@url)
100
+ # response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
101
+ # if (deploy_hash == "" || deploy_hash == nil)
102
+ # Casper::RpcError::InvalidParameter.error
103
+ # end
104
+ # @deploy = response["deploy"]
105
+ # # @deploy.keys.each do |key|
106
+ # # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
107
+ # # end
108
+ # @deploy
109
+ # }
110
+ # rescue
111
+ # Casper::RpcError::InvalidParameter.error
112
+ # end
113
+ # end
71
114
  def info_get_deploy(deploy_hash)
115
+ @dep = nil
72
116
  begin
73
- status = Timeout::timeout(10) {
117
+ status = Timeout::timeout(60) {
74
118
  client = Jimson::Client.new(@url)
75
119
  response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
76
120
  if (deploy_hash == "" || deploy_hash == nil)
77
121
  Casper::RpcError::InvalidParameter.error
78
122
  end
79
- @deploy = response["deploy"]
80
123
  # @deploy.keys.each do |key|
81
124
  # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
82
125
  # end
83
- @deploy
126
+ temp = []
127
+ @deploy = response["deploy"]
128
+ @deploy.deep_symbolize_keys!
129
+ Casper::Entity::Deploy.new(@deploy[:hash], @deploy[:header], @deploy[:payment], @deploy[:session], @deploy[:approvals])
84
130
  }
85
131
  rescue
86
132
  Casper::RpcError::InvalidParameter.error
@@ -111,8 +157,8 @@ module Casper
111
157
  response = client.chain_get_block_transfers({
112
158
  "block_identifier" => {"Hash" => block_hash}
113
159
  })
114
- @block_transfers = response["transfers"]
115
- @block_transfers
160
+ @transfers = response["transfers"]
161
+ @transfers.map { |transfer| Casper::Entity::Transfer.new(transfer.deep_symbolize_keys!)}
116
162
  }
117
163
  rescue
118
164
  Casper::RpcError::InvalidParameter.error
@@ -230,5 +276,13 @@ module Casper
230
276
  @error = @rpc_error.error_handling(@url)
231
277
  end
232
278
  end
279
+
280
+ def put_deploy(deploy)
281
+ client = Jimson::Client.new(url)
282
+ response = client.account_put_deploy(deploy)
283
+ response['deploy_hash']
284
+ end
285
+
233
286
  end
234
- end
287
+
288
+ end
@@ -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
+
@@ -0,0 +1,40 @@
1
+ require 'ed25519'
2
+
3
+
4
+ signing_key = Ed25519::SigningKey.generate
5
+ puts "signing_key:\t #{signing_key}"
6
+
7
+ message = "hello"
8
+ signature = signing_key.sign(message)
9
+ puts "signature:\t #{signature}"
10
+
11
+ verify_key = signing_key.verify_key
12
+ puts "verify_key:\t #{verify_key}"
13
+
14
+ check_validity_of_signature = verify_key.verify(signature, message)
15
+ puts "check_validity_of_signature:\t #{check_validity_of_signature}"
16
+
17
+ # Serializing Keys
18
+ signature_key_bytes = signing_key.to_bytes
19
+ puts "signature_key_bytes:\t #{signature_key_bytes}"
20
+ verify_key_bytes = verify_key.to_bytes
21
+ puts "verify_key_bytes:\t #{verify_key_bytes}"
22
+
23
+ signing_key = Ed25519::SigningKey.new(signature_key_bytes)
24
+ puts "signing_key:\t #{signing_key}"
25
+ verify_key = Ed25519::VerifyKey.new(verify_key_bytes)
26
+ puts "verify_key:\t #{verify_key}"
27
+
28
+
29
+ require "ssh_data"
30
+
31
+ # key_data = File.read("/home/mehmet/Desktop/casper-ruby-sdk/lib/crypto/id_ed25519")
32
+ # key = SSHData::PrivateKey.parse_openssh(key_data)
33
+ #=> <SSHData::PrivateKey::ED25519>
34
+
35
+ # SSHData::PrivateKey::ED25519.generate
36
+ #=> raises SSHData::AlgorithmError
37
+
38
+
39
+ # SSHData::PrivateKey::ED25519.generate
40
+ #=> <SSHData::PrivateKey::ED25519>
@@ -0,0 +1,7 @@
1
+
2
+ SignatureAlgorithm = {
3
+ Ed25519: 'ed25519',
4
+ Secp256K1: 'secp256k1'
5
+ }
6
+
7
+
File without changes
@@ -0,0 +1,44 @@
1
+ require 'openssl'
2
+ require 'ed25519'
3
+ require_relative './asymmetric_key.rb'
4
+
5
+ # SignatureAlgorithm = {
6
+ # Ed25519: 'ed25519',
7
+ # Secp256K1: 'secp256k1'
8
+ # }
9
+ public_key = [
10
+ 72, 211, 174, 85, 36, 108, 106, 103,
11
+ 8, 124, 245, 68, 60, 206, 180, 170,
12
+ 17, 175, 158, 175, 142, 32, 64, 61,
13
+ 195, 38, 169, 191, 55, 231, 249, 39
14
+ ]
15
+
16
+ private_key = [
17
+ 236, 126, 0, 243, 8, 76, 9, 186, 180, 175, 7,
18
+ 155, 21, 92, 86, 47, 12, 70, 89, 171, 48, 87,
19
+ 37, 172, 174, 34, 140, 219, 24, 190, 42, 192, 72,
20
+ 211, 174, 85, 36, 108, 106, 103, 8, 124, 245, 68,
21
+ 60, 206, 180, 170, 17, 175, 158, 175, 142, 32, 64,
22
+ 61, 195, 38, 169, 191, 55, 231, 249, 39
23
+ ]
24
+ class Ed25519Key < AsymmetricKey
25
+
26
+ def initialize(public_key, private_key)
27
+ # super(keypair.public_key, keypair.secret_key, SignatureAlgorithm[:Ed25519])
28
+ super(public_key, private_key, SignatureAlgorithm[:Ed25519])
29
+ end
30
+
31
+ # Generate the account_hex for the Ed25519 public key
32
+ #
33
+ # @param [Array] public_key
34
+ # @return [String]
35
+ def account_hex(public_key)
36
+ '01' + Utils::Base16.encode16(public_key)
37
+ end
38
+ end
39
+
40
+ ed25519 = Ed25519Key.new(public_key, private_key)
41
+
42
+ puts ed25519.account_hash(public_key)
43
+ puts ed25519.get_signature_algorithm
44
+ puts ed25519.get_public_key
@@ -0,0 +1,45 @@
1
+ module Casper
2
+ module Entity
3
+ # An Account is a structure that represents a user on a Casper Network.
4
+ class Account
5
+
6
+ # @param [CLAccountHash] account_hash
7
+ # @param [Array] named_keys
8
+ # @param [CLUref] main_purse The account's main purse URef
9
+ # @param [Array] associated_keys
10
+ # @param [Array<ActionThresHolds>] action_thresholds
11
+ def initialize(account_hash, named_keys, main_purse, associated_keys, action_thresholds)
12
+ @account_hash = account_hash
13
+ @named_keys = named_keys
14
+ @main_purse = main_purse
15
+ @associated_keys = associated_keys
16
+ @action_thresholds = action_thresholds
17
+ end
18
+
19
+ # @return [CLAccountHash]
20
+ def get_account_hash
21
+ @account_hash
22
+ end
23
+
24
+ # @return [Array]
25
+ def get_named_keys
26
+ @named_keys
27
+ end
28
+
29
+ # @return [CLUref]
30
+ def get_main_purse
31
+ @main_purse
32
+ end
33
+
34
+ # @return [Array<AssociatedKey>]
35
+ def get_associated_keys
36
+ @associated_keys
37
+ end
38
+
39
+ # @return [ActionThresHolds]
40
+ def get_action_thresholds
41
+ @action_thresholds
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ module Casper
2
+ module Entity
3
+
4
+ # @note The minimum weight thresholds that have to be met when executing an action of a certain type.
5
+ class ActionThresholds
6
+
7
+ # @param [Integer] deployment Threshold required to perform deployment actions.
8
+ # @param [Integer] key_management Threshold required to perform key management actions.
9
+ def initialize(deployment, key_management)
10
+ @deployment = deployment
11
+ @key_management = key_management
12
+ end
13
+
14
+ # @return [Integer] deployment
15
+ def get_deployment
16
+ @deployment
17
+ end
18
+
19
+ # @return [Integer] key_management
20
+ def get_key_management
21
+ @key_management
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module Casper
2
+ module Entity
3
+ # A key granted limited permissions to an Account, for purposes such as multisig.
4
+ class AssociatedKey
5
+
6
+ # @param [CLAccountHash] account_hash
7
+ # @param [Integer] weight
8
+ def initialize(account_hash, weight)
9
+ @account_hash = account_hash
10
+ @weight = weight
11
+ end
12
+
13
+ # @return [CLAccountHash] account hash of associated key
14
+ def get_account_hash
15
+ @account_hash
16
+ end
17
+
18
+ # @return [Integer] weight of an associated key.
19
+ def get_weight
20
+ @weight
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,6 @@
1
1
  module Casper
2
2
  module Entity
3
+ # Data structure summarizing auction contract data.
3
4
  class AuctionState
4
5
  # @param [String] state_root_hash
5
6
  # @param [Integer] block_height
data/lib/entity/bid.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Casper
2
2
  module Entity
3
+ # An entry in the validator map.
3
4
  class Bid
4
5
 
5
6
  # @param [String] public_key
@@ -1,5 +1,6 @@
1
1
  module Casper
2
2
  module Entity
3
+ # BidInfo
3
4
  class BidInfo
4
5
 
5
6
  # @param [String] bonding_purse