casper_network 0.2.1 → 1.0.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.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -4
  3. data/lib/casper_network.rb +62 -7
  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/contract.rb +47 -0
  16. data/lib/entity/contract_package.rb +41 -0
  17. data/lib/entity/contract_version.rb +33 -0
  18. data/lib/entity/deploy_approval.rb +7 -6
  19. data/lib/entity/deploy_executable.rb +154 -1
  20. data/lib/entity/deploy_executable_item_internal.rb +26 -0
  21. data/lib/entity/deploy_executable_transfer.rb +50 -0
  22. data/lib/entity/deploy_header.rb +17 -15
  23. data/lib/entity/deploy_info.rb +44 -0
  24. data/lib/entity/deploy_named_argument.rb +19 -0
  25. data/lib/entity/deploy_transfer.rb +10 -0
  26. data/lib/entity/disabled_version.rb +26 -0
  27. data/lib/entity/era_info.rb +18 -0
  28. data/lib/entity/executable_deploy_item.rb +11 -0
  29. data/lib/entity/group.rb +25 -0
  30. data/lib/entity/module_bytes.rb +50 -0
  31. data/lib/entity/seigniorage_allocation.rb +18 -0
  32. data/lib/entity/stored_contract_by_hash.rb +50 -0
  33. data/lib/entity/stored_contract_by_name.rb +50 -0
  34. data/lib/entity/stored_value.rb +57 -0
  35. data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
  36. data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
  37. data/lib/entity/transfer.rb +65 -0
  38. data/lib/entity/vesting_schedule.rb +22 -0
  39. data/lib/include.rb +18 -0
  40. data/lib/rpc/rpc.rb +227 -0
  41. data/lib/rpc/rpc_client.rb +45 -39
  42. data/lib/serialization/cl_type_serializer.rb +76 -0
  43. data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
  44. data/lib/serialization/cl_value_serializer.rb +259 -0
  45. data/lib/serialization/deploy_approval_serializer.rb +15 -0
  46. data/lib/serialization/deploy_executable_serializer.rb +26 -0
  47. data/lib/serialization/deploy_header_serializer.rb +49 -0
  48. data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
  49. data/lib/serialization/deploy_serializer.rb +268 -0
  50. data/lib/serialization/test.rb +431 -0
  51. data/lib/types/cl_account_hash.rb +24 -0
  52. data/lib/types/cl_account_hash_type.rb +22 -0
  53. data/lib/types/cl_any.rb +25 -0
  54. data/lib/types/cl_any_type.rb +22 -0
  55. data/lib/types/cl_bool.rb +32 -0
  56. data/lib/types/cl_bool_type.rb +35 -0
  57. data/lib/types/cl_byte_array.rb +25 -0
  58. data/lib/types/cl_byte_array_type.rb +27 -0
  59. data/lib/types/cl_i32.rb +26 -0
  60. data/lib/types/cl_i32_type.rb +26 -0
  61. data/lib/types/cl_i64.rb +26 -0
  62. data/lib/types/cl_i64_type.rb +27 -0
  63. data/lib/types/cl_key.rb +39 -0
  64. data/lib/types/cl_key_type.rb +27 -0
  65. data/lib/types/cl_list.rb +25 -0
  66. data/lib/types/cl_list_type.rb +26 -0
  67. data/lib/types/cl_map.rb +25 -0
  68. data/lib/types/cl_map_type.rb +26 -0
  69. data/lib/types/cl_option.rb +33 -0
  70. data/lib/types/cl_option_type.rb +52 -0
  71. data/lib/types/cl_public_key.rb +152 -0
  72. data/lib/types/cl_public_key_type.rb +26 -0
  73. data/lib/types/cl_result.rb +25 -0
  74. data/lib/types/cl_result_type.rb +26 -0
  75. data/lib/types/cl_string.rb +39 -0
  76. data/lib/types/cl_string_type.rb +32 -0
  77. data/lib/types/cl_tuple.rb +151 -0
  78. data/lib/types/cl_tuple_type.rb +108 -0
  79. data/lib/types/cl_type.rb +94 -0
  80. data/lib/types/cl_type_tag.rb +51 -0
  81. data/lib/types/cl_u128.rb +26 -0
  82. data/lib/types/cl_u128_type.rb +26 -0
  83. data/lib/types/cl_u256.rb +26 -0
  84. data/lib/types/cl_u256_type.rb +26 -0
  85. data/lib/types/cl_u32.rb +26 -0
  86. data/lib/types/cl_u32_type.rb +26 -0
  87. data/lib/types/cl_u512.rb +26 -0
  88. data/lib/types/cl_u512_type.rb +26 -0
  89. data/lib/types/cl_u64.rb +26 -0
  90. data/lib/types/cl_u64_type.rb +27 -0
  91. data/lib/types/cl_u8.rb +26 -0
  92. data/lib/types/cl_u8_type.rb +26 -0
  93. data/lib/types/cl_unit.rb +38 -0
  94. data/lib/types/cl_unit_type.rb +22 -0
  95. data/lib/types/cl_uref.rb +119 -0
  96. data/lib/types/cl_uref_type.rb +46 -0
  97. data/lib/types/cl_value.rb +10 -0
  98. data/lib/types/constants.rb +50 -0
  99. data/lib/types/error.rb +7 -0
  100. data/lib/utils/base_16.rb +18 -0
  101. data/lib/utils/byte_utils.rb +107 -0
  102. data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
  103. data/lib/utils/hash_utils.rb +19 -0
  104. data/lib/utils/hex_utils.rb +12 -0
  105. data/lib/utils/time_utils.rb +85 -0
  106. data/lib/utils/utils.rb +2 -0
  107. data/lib/version.rb +3 -0
  108. data/spec/a_spec.rb +697 -0
  109. data/spec/byte_utils_spec.rb +72 -0
  110. data/spec/cl_public_spec.rb +169 -0
  111. data/spec/cl_types_spec.rb +715 -0
  112. data/spec/cl_value_serializer_spec.rb +140 -0
  113. data/spec/client_spec.rb +20 -20
  114. data/spec/crypto_spec.rb +42 -0
  115. data/spec/deploy_approval_serializer_spec.rb +26 -0
  116. data/spec/deploy_executable_serializer_spec.rb +0 -0
  117. data/spec/deploy_header_serializer_spec.rb +21 -0
  118. data/spec/deploy_named_arg_serializer_spec.rb +49 -0
  119. data/spec/deploy_serializer_spec.rb +77 -0
  120. data/spec/deploy_serializer_test_spec.rb +225 -0
  121. data/spec/mainnet_spec.rb +8 -8
  122. data/spec/string_spec.rb +68 -0
  123. data/spec/testnet_spec.rb +11 -11
  124. data/spec/time_utils_spec.rb +87 -0
  125. 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: 5690859dc418eff2224b41b3001cb2c61bd3ec34df10249a4a5d13d42fba979d
4
+ data.tar.gz: d5faa5ae453065ddae80766f33332c24c4b6f3fe9a6aa530a007f5fc806d1f38
5
5
  SHA512:
6
- metadata.gz: 61ca00e871d1fba6c79bf31b60dec38c5285d95675c457823843c7cb99956baadd96bf15c1953d0adbdf01caa5b31179a46ad528e9f3c48c5a203dc194194977
7
- data.tar.gz: e9eb9a792d46f97a9316914c7d0cb885a48568b2f162feb97225cb64ff2a428d47b5a8b448c9aa941fc19275ad4da6dc8751694c6a95df97fd904948079d03a7
6
+ metadata.gz: 7c7f495af10f0ea7c22a392ac6401e57545d748b52adf8d6b987592646d42eb67b8ca2155d9ed7d43e7ac808819bcd5d754c393fb747bd12d6e53b87d6e1477c
7
+ data.tar.gz: fa704d9f40f44c1099aa2b08ea2452b8e4731fd01356a3d574bb17f9d982de494117ef50aaf7cd92dab65117c6d05ff33b1429c29607f269dc1388350f1633ef
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,7 +9,14 @@ require 'timeout'
9
9
  require 'net/http'
10
10
  # require "./rpc/rpc.rb"
11
11
  require_relative './rpc/rpc_error.rb'
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'
12
18
  # Class for interacting with the network via RPC
19
+ # puts "Hello"
13
20
  module Casper
14
21
  class CasperClient
15
22
  attr_accessor :ip_address, :port, :url, :state_root_hash
@@ -33,18 +40,37 @@ module Casper
33
40
  @rpc_error = Casper::RpcError::ErrorHandle.new
34
41
  @err = @rpc_error.error_handling(@url)
35
42
 
43
+ @pr = []
44
+
36
45
  end
37
46
 
38
47
  def get_error
39
48
  @err
40
49
  end
41
50
 
51
+ # @return [Array<Hash>] peers array
52
+ # def info_get_peers
53
+ # begin
54
+ # client = Jimson::Client.new(@url)
55
+ # response = client.info_get_peers
56
+ # @peer_array = response["peers"]
57
+ # rescue
58
+ # @rpc_error = Casper::RpcError::ErrorHandle.new
59
+ # @error = @rpc_error.error_handling(@url)
60
+ # end
61
+ # end
62
+
42
63
  # @return [Array<Hash>] peers array
43
64
  def info_get_peers
44
65
  begin
45
66
  client = Jimson::Client.new(@url)
46
67
  response = client.info_get_peers
47
- @peer_array = response["peers"]
68
+ @peers = response["peers"]
69
+ # @peers.map! do |peer|
70
+ # peer.symbolize_keys
71
+ # end
72
+ @peers.map { |item| @pr << Casper::Entity::Peer.new(item.symbolize_keys) }
73
+ @pr
48
74
  rescue
49
75
  @rpc_error = Casper::RpcError::ErrorHandle.new
50
76
  @error = @rpc_error.error_handling(@url)
@@ -68,19 +94,40 @@ module Casper
68
94
  # Get information about a single deploy by hash.
69
95
  # @param [String] deploy_hash
70
96
  # @return [Hash] Deploy
97
+ # def info_get_deploy(deploy_hash)
98
+ # begin
99
+ # status = Timeout::timeout(10) {
100
+ # client = Jimson::Client.new(@url)
101
+ # response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
102
+ # if (deploy_hash == "" || deploy_hash == nil)
103
+ # Casper::RpcError::InvalidParameter.error
104
+ # end
105
+ # @deploy = response["deploy"]
106
+ # # @deploy.keys.each do |key|
107
+ # # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
108
+ # # end
109
+ # @deploy
110
+ # }
111
+ # rescue
112
+ # Casper::RpcError::InvalidParameter.error
113
+ # end
114
+ # end
71
115
  def info_get_deploy(deploy_hash)
116
+ @dep = nil
72
117
  begin
73
- status = Timeout::timeout(10) {
118
+ status = Timeout::timeout(60) {
74
119
  client = Jimson::Client.new(@url)
75
120
  response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
76
121
  if (deploy_hash == "" || deploy_hash == nil)
77
122
  Casper::RpcError::InvalidParameter.error
78
123
  end
79
- @deploy = response["deploy"]
80
124
  # @deploy.keys.each do |key|
81
125
  # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
82
126
  # end
83
- @deploy
127
+ temp = []
128
+ @deploy = response["deploy"]
129
+ @deploy.deep_symbolize_keys!
130
+ Casper::Entity::Deploy.new(@deploy[:hash], @deploy[:header], @deploy[:payment], @deploy[:session], @deploy[:approvals])
84
131
  }
85
132
  rescue
86
133
  Casper::RpcError::InvalidParameter.error
@@ -111,8 +158,8 @@ module Casper
111
158
  response = client.chain_get_block_transfers({
112
159
  "block_identifier" => {"Hash" => block_hash}
113
160
  })
114
- @block_transfers = response["transfers"]
115
- @block_transfers
161
+ @transfers = response["transfers"]
162
+ @transfers.map { |transfer| Casper::Entity::Transfer.new(transfer.deep_symbolize_keys!)}
116
163
  }
117
164
  rescue
118
165
  Casper::RpcError::InvalidParameter.error
@@ -230,5 +277,13 @@ module Casper
230
277
  @error = @rpc_error.error_handling(@url)
231
278
  end
232
279
  end
280
+
281
+ def put_deploy(deploy)
282
+ client = Jimson::Client.new(url)
283
+ response = client.account_put_deploy(deploy)
284
+ response['deploy_hash']
285
+ end
286
+
233
287
  end
234
- end
288
+
289
+ 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
+
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