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.
- checksums.yaml +4 -4
- data/README.md +15 -4
- data/lib/casper_network.rb +62 -7
- data/lib/crypto/00_asymmetric_key.rb +95 -0
- data/lib/crypto/01_ed25519.rb +67 -0
- data/lib/crypto/asymmetric_key.rb +87 -0
- data/lib/crypto/ed25519_key.rb +44 -0
- data/lib/crypto/key_pair.rb +40 -0
- data/lib/crypto/keys.rb +7 -0
- data/lib/crypto/secp256k1_key.rb +0 -0
- data/lib/crypto/test_ed25519_key.rb +44 -0
- data/lib/entity/account.rb +45 -0
- data/lib/entity/action_thresholds.rb +25 -0
- data/lib/entity/associated_key.rb +24 -0
- data/lib/entity/contract.rb +47 -0
- data/lib/entity/contract_package.rb +41 -0
- data/lib/entity/contract_version.rb +33 -0
- data/lib/entity/deploy_approval.rb +7 -6
- data/lib/entity/deploy_executable.rb +154 -1
- data/lib/entity/deploy_executable_item_internal.rb +26 -0
- data/lib/entity/deploy_executable_transfer.rb +50 -0
- data/lib/entity/deploy_header.rb +17 -15
- data/lib/entity/deploy_info.rb +44 -0
- data/lib/entity/deploy_named_argument.rb +19 -0
- data/lib/entity/deploy_transfer.rb +10 -0
- data/lib/entity/disabled_version.rb +26 -0
- data/lib/entity/era_info.rb +18 -0
- data/lib/entity/executable_deploy_item.rb +11 -0
- data/lib/entity/group.rb +25 -0
- data/lib/entity/module_bytes.rb +50 -0
- data/lib/entity/seigniorage_allocation.rb +18 -0
- data/lib/entity/stored_contract_by_hash.rb +50 -0
- data/lib/entity/stored_contract_by_name.rb +50 -0
- data/lib/entity/stored_value.rb +57 -0
- data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
- data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
- data/lib/entity/transfer.rb +65 -0
- data/lib/entity/vesting_schedule.rb +22 -0
- data/lib/include.rb +18 -0
- data/lib/rpc/rpc.rb +227 -0
- data/lib/rpc/rpc_client.rb +45 -39
- data/lib/serialization/cl_type_serializer.rb +76 -0
- data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
- data/lib/serialization/cl_value_serializer.rb +259 -0
- data/lib/serialization/deploy_approval_serializer.rb +15 -0
- data/lib/serialization/deploy_executable_serializer.rb +26 -0
- data/lib/serialization/deploy_header_serializer.rb +49 -0
- data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
- data/lib/serialization/deploy_serializer.rb +268 -0
- data/lib/serialization/test.rb +431 -0
- data/lib/types/cl_account_hash.rb +24 -0
- data/lib/types/cl_account_hash_type.rb +22 -0
- data/lib/types/cl_any.rb +25 -0
- data/lib/types/cl_any_type.rb +22 -0
- data/lib/types/cl_bool.rb +32 -0
- data/lib/types/cl_bool_type.rb +35 -0
- data/lib/types/cl_byte_array.rb +25 -0
- data/lib/types/cl_byte_array_type.rb +27 -0
- data/lib/types/cl_i32.rb +26 -0
- data/lib/types/cl_i32_type.rb +26 -0
- data/lib/types/cl_i64.rb +26 -0
- data/lib/types/cl_i64_type.rb +27 -0
- data/lib/types/cl_key.rb +39 -0
- data/lib/types/cl_key_type.rb +27 -0
- data/lib/types/cl_list.rb +25 -0
- data/lib/types/cl_list_type.rb +26 -0
- data/lib/types/cl_map.rb +25 -0
- data/lib/types/cl_map_type.rb +26 -0
- data/lib/types/cl_option.rb +33 -0
- data/lib/types/cl_option_type.rb +52 -0
- data/lib/types/cl_public_key.rb +152 -0
- data/lib/types/cl_public_key_type.rb +26 -0
- data/lib/types/cl_result.rb +25 -0
- data/lib/types/cl_result_type.rb +26 -0
- data/lib/types/cl_string.rb +39 -0
- data/lib/types/cl_string_type.rb +32 -0
- data/lib/types/cl_tuple.rb +151 -0
- data/lib/types/cl_tuple_type.rb +108 -0
- data/lib/types/cl_type.rb +94 -0
- data/lib/types/cl_type_tag.rb +51 -0
- data/lib/types/cl_u128.rb +26 -0
- data/lib/types/cl_u128_type.rb +26 -0
- data/lib/types/cl_u256.rb +26 -0
- data/lib/types/cl_u256_type.rb +26 -0
- data/lib/types/cl_u32.rb +26 -0
- data/lib/types/cl_u32_type.rb +26 -0
- data/lib/types/cl_u512.rb +26 -0
- data/lib/types/cl_u512_type.rb +26 -0
- data/lib/types/cl_u64.rb +26 -0
- data/lib/types/cl_u64_type.rb +27 -0
- data/lib/types/cl_u8.rb +26 -0
- data/lib/types/cl_u8_type.rb +26 -0
- data/lib/types/cl_unit.rb +38 -0
- data/lib/types/cl_unit_type.rb +22 -0
- data/lib/types/cl_uref.rb +119 -0
- data/lib/types/cl_uref_type.rb +46 -0
- data/lib/types/cl_value.rb +10 -0
- data/lib/types/constants.rb +50 -0
- data/lib/types/error.rb +7 -0
- data/lib/utils/base_16.rb +18 -0
- data/lib/utils/byte_utils.rb +107 -0
- data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
- data/lib/utils/hash_utils.rb +19 -0
- data/lib/utils/hex_utils.rb +12 -0
- data/lib/utils/time_utils.rb +85 -0
- data/lib/utils/utils.rb +2 -0
- data/lib/version.rb +3 -0
- data/spec/a_spec.rb +697 -0
- data/spec/byte_utils_spec.rb +72 -0
- data/spec/cl_public_spec.rb +169 -0
- data/spec/cl_types_spec.rb +715 -0
- data/spec/cl_value_serializer_spec.rb +140 -0
- data/spec/client_spec.rb +20 -20
- data/spec/crypto_spec.rb +42 -0
- data/spec/deploy_approval_serializer_spec.rb +26 -0
- data/spec/deploy_executable_serializer_spec.rb +0 -0
- data/spec/deploy_header_serializer_spec.rb +21 -0
- data/spec/deploy_named_arg_serializer_spec.rb +49 -0
- data/spec/deploy_serializer_spec.rb +77 -0
- data/spec/deploy_serializer_test_spec.rb +225 -0
- data/spec/mainnet_spec.rb +8 -8
- data/spec/string_spec.rb +68 -0
- data/spec/testnet_spec.rb +11 -11
- data/spec/time_utils_spec.rb +87 -0
- metadata +130 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5690859dc418eff2224b41b3001cb2c61bd3ec34df10249a4a5d13d42fba979d
|
4
|
+
data.tar.gz: d5faa5ae453065ddae80766f33332c24c4b6f3fe9a6aa530a007f5fc806d1f38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
-
- [
|
154
|
-
- [doc](https://
|
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
|
data/lib/casper_network.rb
CHANGED
@@ -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
|
-
@
|
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(
|
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
|
-
|
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
|
-
@
|
115
|
-
@
|
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
|
-
|
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>
|
data/lib/crypto/keys.rb
ADDED
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
|