klay 0.0.2 → 0.0.5

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.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  require "socket"
16
16
 
17
- # Provides the {Eth} module.
17
+ # Provides the {Klay} module.
18
18
  module Klay
19
19
 
20
20
  # Provides an IPC-RPC client.
data/lib/klay/client.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,10 +12,10 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # Provides the {Eth} module.
15
+ # Provides the {Klay} module.
16
16
  module Klay
17
17
 
18
- # Provides the {Eth::Client} super-class to connect to Ethereum
18
+ # Provides the {Klay::Client} super-class to connect to Klaytn
19
19
  # network's RPC-API endpoints (IPC or HTTP).
20
20
  class Client
21
21
 
@@ -41,8 +41,8 @@ module Klay
41
41
  # an IPC path.
42
42
  #
43
43
  # @param host [String] either an HTTP/S host or an IPC path.
44
- # @return [Eth::Client::Ipc] an IPC client.
45
- # @return [Eth::Client::Http] an HTTP client.
44
+ # @return [Klay::Client::Ipc] an IPC client.
45
+ # @return [Klay::Client::Http] an HTTP client.
46
46
  # @raise [ArgumentError] in case it cannot determine the client type.
47
47
  def self.create(host)
48
48
  return Client::Ipc.new host if host.end_with? ".ipc"
@@ -50,7 +50,7 @@ module Klay
50
50
  raise ArgumentError, "Unable to detect client type!"
51
51
  end
52
52
 
53
- # Constructor for the {Eth::Client} super-class. Should not be used;
53
+ # Constructor for the {Klay::Client} super-class. Should not be used;
54
54
  # use {Client.create} intead.
55
55
  def initialize(_)
56
56
  @id = 0
@@ -61,7 +61,7 @@ module Klay
61
61
 
62
62
  # Gets the default account (coinbase) of the connected client.
63
63
  #
64
- # @return [Eth::Address] the coinbase account address.
64
+ # @return [Klay::Address] the coinbase account address.
65
65
  def default_account
66
66
  @default_account ||= Address.new eth_coinbase["result"]
67
67
  end
@@ -75,7 +75,7 @@ module Klay
75
75
 
76
76
  # Gets the balance for an address.
77
77
  #
78
- # @param address [Eth::Address] the address to get the balance for.
78
+ # @param address [Klay::Address] the address to get the balance for.
79
79
  # @return [Integer] the balance in Wei.
80
80
  def get_balance(address)
81
81
  eth_get_balance(address)["result"].to_i 16
@@ -83,32 +83,32 @@ module Klay
83
83
 
84
84
  # Gets the next nonce for an address used to draft new transactions.
85
85
  #
86
- # @param address [Eth::Address] the address to get the nonce for.
86
+ # @param address [Klay::Address] the address to get the nonce for.
87
87
  # @return [Integer] the next nonce to be used.
88
88
  def get_nonce(address)
89
89
  eth_get_transaction_count(address, "pending")["result"].to_i 16
90
90
  end
91
91
 
92
- # Simply transfer Ether to an account and waits for it to be mined.
92
+ # Simply transfer Klay to an account and waits for it to be mined.
93
93
  # Uses `eth_coinbase` and external signer if no sender key is
94
94
  # provided.
95
95
  #
96
- # @param destination [Eth::Address] the destination address.
96
+ # @param destination [Klay::Address] the destination address.
97
97
  # @param amount [Integer] the transfer amount in Wei.
98
- # @param sender_key [Eth::Key] the sender private key.
98
+ # @param sender_key [Klay::Key] the sender private key.
99
99
  # @param legacy [Boolean] enables legacy transactions (pre-EIP-1559).
100
100
  # @return [String] the transaction hash.
101
101
  def transfer_and_wait(destination, amount, sender_key = nil, legacy = false)
102
102
  wait_for_tx(transfer(destination, amount, sender_key, legacy))
103
103
  end
104
104
 
105
- # Simply transfer Ether to an account without any call data or
105
+ # Simply transfer Klay to an account without any call data or
106
106
  # access lists attached. Uses `eth_coinbase` and external signer
107
107
  # if no sender key is provided.
108
108
  #
109
- # @param destination [Eth::Address] the destination address.
109
+ # @param destination [Klay::Address] the destination address.
110
110
  # @param amount [Integer] the transfer amount in Wei.
111
- # @param sender_key [Eth::Key] the sender private key.
111
+ # @param sender_key [Klay::Key] the sender private key.
112
112
  # @param legacy [Boolean] enables legacy transactions (pre-EIP-1559).
113
113
  # @return [String] the transaction hash.
114
114
  def transfer(destination, amount, sender_key = nil, legacy = false)
@@ -135,7 +135,7 @@ module Klay
135
135
  from: sender_key.address,
136
136
  nonce: get_nonce(sender_key.address),
137
137
  })
138
- tx = Eth::Tx.new(params)
138
+ tx = Klay::Tx.new(params)
139
139
  tx.sign sender_key
140
140
  return eth_send_raw_transaction(tx.hex)["result"]
141
141
  else
@@ -183,7 +183,7 @@ module Klay
183
183
  end
184
184
 
185
185
  # Metafunction to provide all known RPC commands defined in
186
- # Eth::Api as snake_case methods to the Eth::Client classes.
186
+ # Klay::Api as snake_case methods to the Klay::Client classes.
187
187
  Api::COMMANDS.each do |cmd|
188
188
  method_name = cmd.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
189
189
  define_method method_name do |*args|
@@ -195,7 +195,7 @@ module Klay
195
195
 
196
196
  # Prepares parameters and sends the command to the client.
197
197
  def send_command(command, args)
198
- args << "latest" if ["eth_getBalance", "eth_call"].include? command
198
+ args << "latest" if ["klay_getBalance", "klay_call"].include? command
199
199
  payload = {
200
200
  jsonrpc: "2.0",
201
201
  method: command,
data/lib/klay/constant.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  # -*- encoding : ascii-8bit -*-
16
16
 
17
- # Provides the {Eth} module.
17
+ # Provides the {Klay} module.
18
18
  module Klay
19
19
 
20
20
  # Provides commonly used constants, such as zero bytes or zero keys.
data/lib/klay/eip712.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # Provides the {Eth} module.
15
+ # Provides the {Klay} module.
16
16
  module Klay
17
17
 
18
18
  # Defines handy tools for encoding typed structured data as per EIP-712.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,27 +12,27 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # Provides the {Eth} module.
15
+ # Provides the {Klay} module.
16
16
  module Klay
17
17
 
18
- # The {Eth::Key::Decrypter} class to handle PBKDF2-SHA-256 decryption.
18
+ # The {Klay::Key::Decrypter} class to handle PBKDF2-SHA-256 decryption.
19
19
  class Key::Decrypter
20
20
 
21
21
  # Provides a specific decrypter error if decryption fails.
22
22
  class DecrypterError < StandardError; end
23
23
 
24
- # Class method {Eth::Key::Decrypter.perform} to perform an keystore
24
+ # Class method {Klay::Key::Decrypter.perform} to perform an keystore
25
25
  # decryption.
26
26
  #
27
27
  # @param data [JSON] encryption data including cypherkey.
28
28
  # @param password [String] password to decrypt the key.
29
- # @return [Eth::Key] decrypted key-pair.
29
+ # @return [Klay::Key] decrypted key-pair.
30
30
  def self.perform(data, password)
31
31
  new(data, password).perform
32
32
  end
33
33
 
34
- # Constructor of the {Eth::Key::Decrypter} class for secret key
35
- # decryption. Should not be used; use {Eth::Key::Decrypter.perform}
34
+ # Constructor of the {Klay::Key::Decrypter} class for secret key
35
+ # decryption. Should not be used; use {Klay::Key::Decrypter.perform}
36
36
  # instead.
37
37
  #
38
38
  # @param data [JSON] encryption data including cypherkey.
@@ -45,12 +45,12 @@ module Klay
45
45
 
46
46
  # Method to decrypt key using password.
47
47
  #
48
- # @return [Eth::Key] decrypted key.
48
+ # @return [Klay::Key] decrypted key.
49
49
  def perform
50
50
  derive_key password
51
51
  check_macs
52
52
  private_key = Util.bin_to_hex decrypted_data
53
- Eth::Key.new priv: private_key
53
+ Klay::Key.new priv: private_key
54
54
  end
55
55
 
56
56
  private
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,19 +12,19 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # Provides the {Eth} module.
15
+ # Provides the {Klay} module.
16
16
  module Klay
17
17
 
18
- # The {Eth::Key::Encrypter} class to handle PBKDF2-SHA-256 encryption.
18
+ # The {Klay::Key::Encrypter} class to handle PBKDF2-SHA-256 encryption.
19
19
  class Key::Encrypter
20
20
 
21
21
  # Provides a specific encrypter error if decryption fails.
22
22
  class EncrypterError < StandardError; end
23
23
 
24
- # Class method {Eth::Key::Encrypter.perform} to performa an key-store
24
+ # Class method {Klay::Key::Encrypter.perform} to performa an key-store
25
25
  # encryption.
26
26
  #
27
- # @param key [Eth::Key] representing a secret key-pair used for encryption.
27
+ # @param key [Klay::Key] representing a secret key-pair used for encryption.
28
28
  # @param options [Hash] the options to encrypt with.
29
29
  # @option options [String] :kdf key derivation function defaults to pbkdf2.
30
30
  # @option options [String] :id uuid given to the secret key.
@@ -38,11 +38,11 @@ module Klay
38
38
  new(key, options).perform(password)
39
39
  end
40
40
 
41
- # Constructor of the {Eth::Key::Encrypter} class for secret key
42
- # encryption. Should not be used; use {Eth::Key::Encrypter.perform}
41
+ # Constructor of the {Klay::Key::Encrypter} class for secret key
42
+ # encryption. Should not be used; use {Klay::Key::Encrypter.perform}
43
43
  # instead.
44
44
  #
45
- # @param key [Eth::Key] representing a secret key-pair used for encryption.
45
+ # @param key [Klay::Key] representing a secret key-pair used for encryption.
46
46
  # @param options [Hash] the options to encrypt with.
47
47
  # @option options [String] :kdf key derivation function defaults to pbkdf2.
48
48
  # @option options [String] :id uuid given to the secret key.
data/lib/klay/key.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -18,25 +18,25 @@ require "rbsecp256k1"
18
18
  require "scrypt"
19
19
  require "securerandom"
20
20
 
21
- # Provides the {Eth} module.
21
+ # Provides the {Klay} module.
22
22
  module Klay
23
23
 
24
- # The {Eth::Key} class to handle Secp256k1 private/public key-pairs.
24
+ # The {Klay::Key} class to handle Secp256k1 private/public key-pairs.
25
25
  class Key
26
26
 
27
- # The {Eth::Key::Decrypter} class to handle PBKDF2-SHA-256 decryption.
27
+ # The {Klay::Key::Decrypter} class to handle PBKDF2-SHA-256 decryption.
28
28
  autoload :Decrypter, "eth/key/decrypter"
29
29
 
30
- # The {Eth::Key::Encrypter} class to handle PBKDF2-SHA-256 encryption.
30
+ # The {Klay::Key::Encrypter} class to handle PBKDF2-SHA-256 encryption.
31
31
  autoload :Encrypter, "eth/key/encrypter"
32
32
 
33
- # The `Secp256k1::PrivateKey` of the {Eth::Key} pair.
33
+ # The `Secp256k1::PrivateKey` of the {Klay::Key} pair.
34
34
  attr_reader :private_key
35
35
 
36
- # The `Secp256k1::PublicKey` of the {Eth::Key} pair.
36
+ # The `Secp256k1::PublicKey` of the {Klay::Key} pair.
37
37
  attr_reader :public_key
38
38
 
39
- # Constructor of the {Eth::Key} class. Creates a new random key-pair
39
+ # Constructor of the {Klay::Key} class. Creates a new random key-pair
40
40
  # if no `priv` key is provided.
41
41
  #
42
42
  # @param priv [String] binary string of private key data.
@@ -82,7 +82,7 @@ module Klay
82
82
  Util.bin_to_hex signature.pack "c*"
83
83
  end
84
84
 
85
- # Prefixes a message with `\x19Ethereum Signed Message:` and signs
85
+ # Prefixes a message with `\u0019Klaytn Signed Message:` and signs
86
86
  # it in the common way used by many web3 wallets. Complies with
87
87
  # EIP-191 prefix `0x19` and version byte `0x45` (`E`). See also
88
88
  # {Signature.personal_recover}.
@@ -119,7 +119,7 @@ module Klay
119
119
  end
120
120
 
121
121
  # Exports the private key bytes in a wrapper function to maintain
122
- # backward-compatibility with older versions of {Eth::Key}.
122
+ # backward-compatibility with older versions of {Klay::Key}.
123
123
  #
124
124
  # @return [String] private key as packed byte-string.
125
125
  def private_bytes
@@ -143,7 +143,7 @@ module Klay
143
143
  end
144
144
 
145
145
  # Exports the uncompressed public key bytes in a wrapper function to
146
- # maintain backward-compatibility with older versions of {Eth::Key}.
146
+ # maintain backward-compatibility with older versions of {Klay::Key}.
147
147
  #
148
148
  # @return [String] uncompressed public key as packed byte-string.
149
149
  def public_bytes
@@ -159,7 +159,7 @@ module Klay
159
159
 
160
160
  # Exports the checksummed public address.
161
161
  #
162
- # @return [Eth::Address] compressed address as packed hex prefixed string.
162
+ # @return [Klay::Address] compressed address as packed hex prefixed string.
163
163
  def address
164
164
  Util.public_key_to_address public_bytes
165
165
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  # -*- encoding : ascii-8bit -*-
16
16
 
17
- # Provides the {Eth} module.
17
+ # Provides the {Klay} module.
18
18
  module Klay
19
19
 
20
20
  # Provides an recursive-length prefix (RLP) encoder and decoder.
@@ -28,7 +28,7 @@ module Klay
28
28
  #
29
29
  # @param rlp [String] an RLP-encoded object.
30
30
  # @return [Object] the decoded and maybe deserialized object.
31
- # @raise [Eth::Rlp::DecodingError] if the input string does not end after
31
+ # @raise [Klay::Rlp::DecodingError] if the input string does not end after
32
32
  # the root item.
33
33
  def perform(rlp)
34
34
  rlp = Util.hex_to_bin rlp if Util.is_hex? rlp
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  # -*- encoding : ascii-8bit -*-
16
16
 
17
- # Provides the {Eth} module.
17
+ # Provides the {Klay} module.
18
18
  module Klay
19
19
 
20
20
  # Provides an recursive-length prefix (RLP) encoder and decoder.
@@ -28,9 +28,9 @@ module Klay
28
28
  #
29
29
  # @param obj [Object] a Ruby object.
30
30
  # @return [String] the RLP encoded item.
31
- # @raise [Eth::Rlp::EncodingError] in the rather unlikely case that the item
31
+ # @raise [Klay::Rlp::EncodingError] in the rather unlikely case that the item
32
32
  # is too big to encode (will not happen).
33
- # @raise [Eth::Rlp::SerializationError] if the serialization fails.
33
+ # @raise [Klay::Rlp::SerializationError] if the serialization fails.
34
34
  def perform(obj)
35
35
  item = Sedes.infer(obj).serialize(obj)
36
36
  result = encode_raw item
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  # -*- encoding : ascii-8bit -*-
16
16
 
17
- # Provides the {Eth} module.
17
+ # Provides the {Klay} module.
18
18
  module Klay
19
19
 
20
20
  # Provides an recursive-length prefix (RLP) encoder and decoder.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  # -*- encoding : ascii-8bit -*-
16
16
 
17
- # Provides the {Eth} module.
17
+ # Provides the {Klay} module.
18
18
  module Klay
19
19
 
20
20
  # Provides an recursive-length prefix (RLP) encoder and decoder.
@@ -33,7 +33,7 @@ module Klay
33
33
  #
34
34
  # @param l [Integer] the fixed size of the binary.
35
35
  # @param allow_empty [Boolean] indicator wether empty binaries should be allowed.
36
- # @return [Eth::Rlp::Sedes::Binary] a serializable binary of fixed size.
36
+ # @return [Klay::Rlp::Sedes::Binary] a serializable binary of fixed size.
37
37
  def fixed_length(l, allow_empty: false)
38
38
  new(min_length: l, max_length: l, allow_empty: allow_empty)
39
39
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  # -*- encoding : ascii-8bit -*-
16
16
 
17
- # Provides the {Eth} module.
17
+ # Provides the {Klay} module.
18
18
  module Klay
19
19
 
20
20
  # Provides an recursive-length prefix (RLP) encoder and decoder.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ require "klay/rlp/sedes/big_endian_int"
18
18
  require "klay/rlp/sedes/binary"
19
19
  require "klay/rlp/sedes/list"
20
20
 
21
- # Provides the {Eth} module.
21
+ # Provides the {Klay} module.
22
22
  module Klay
23
23
 
24
24
  # Provides an recursive-length prefix (RLP) encoder and decoder.
@@ -27,13 +27,13 @@ module Klay
27
27
  # Provides serializable and deserializable types (SeDes).
28
28
  module Sedes
29
29
 
30
- # Provides a singleton {Eth::Rlp::Sedes} class to infer objects and types.
30
+ # Provides a singleton {Klay::Rlp::Sedes} class to infer objects and types.
31
31
  class << self
32
32
 
33
33
  # Tries to find a sedes objects suitable for a given Ruby object.
34
34
  #
35
35
  # The sedes objects considered are `obj`'s class, {big_endian_int} and
36
- # {binary}. If `obj` is a list, an {Eth::Rlp::Sedes::List} will be
36
+ # {binary}. If `obj` is a list, an {Klay::Rlp::Sedes::List} will be
37
37
  # constructed recursively.
38
38
  #
39
39
  # @param obj [Object] the Ruby object for which to find a sedes object.
@@ -57,14 +57,14 @@ module Klay
57
57
  # A utility to use a big-endian, unsigned integer sedes type with
58
58
  # unspecified length.
59
59
  #
60
- # @return [Eth::Rlp::Sedes::BigEndianInt] a big-endian, unsigned integer sedes.
60
+ # @return [Klay::Rlp::Sedes::BigEndianInt] a big-endian, unsigned integer sedes.
61
61
  def big_endian_int
62
62
  @big_endian_int ||= BigEndianInt.new
63
63
  end
64
64
 
65
65
  # A utility to use a binary sedes type.
66
66
  #
67
- # @return [Eth::Rlp::Sedes::Binary] a binary sedes.
67
+ # @return [Klay::Rlp::Sedes::Binary] a binary sedes.
68
68
  def binary
69
69
  @binary ||= Binary.new
70
70
  end
data/lib/klay/rlp.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ require "klay/rlp/encoder"
19
19
  require "klay/rlp/sedes"
20
20
  require "klay/util"
21
21
 
22
- # Provides the {Eth} module.
22
+ # Provides the {Klay} module.
23
23
  module Klay
24
24
 
25
25
  # Provides an recursive-length prefix (RLP) encoder and decoder.
@@ -44,7 +44,7 @@ module Klay
44
44
  # A wrapper to represent already RLP-encoded data.
45
45
  class Data < String; end
46
46
 
47
- # Performes an {Eth::Rlp::Encoder} on any ruby object.
47
+ # Performes an {Klay::Rlp::Encoder} on any ruby object.
48
48
  #
49
49
  # @param obj [Object] any ruby object.
50
50
  # @return [String] a packed, RLP-encoded item.
@@ -52,7 +52,7 @@ module Klay
52
52
  Rlp::Encoder.perform obj
53
53
  end
54
54
 
55
- # Performes an {Eth::Rlp::Decoder} on any RLP-encoded item.
55
+ # Performes an {Klay::Rlp::Decoder} on any RLP-encoded item.
56
56
  #
57
57
  # @param rlp [String] a packed, RLP-encoded item.
58
58
  # @return [Object] a decoded ruby object.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
 
15
15
  require "rbsecp256k1"
16
16
 
17
- # Provides the {Eth} module.
17
+ # Provides the {Klay} module.
18
18
  module Klay
19
19
 
20
20
  # Defines handy tools for verifying and recovering signatures.
@@ -38,7 +38,7 @@ module Klay
38
38
  # @param message [String] the message string to be prefixed.
39
39
  # @return [String] an EIP-191 prefixed string.
40
40
  def prefix_message(message)
41
- "#{EIP191_PREFIX_BYTE}Klaytn Signed Message:\n#{message.size}#{message}"
41
+ "\u0019Klaytn Signed Message:\n#{message.size}#{message}"
42
42
  end
43
43
 
44
44
  # Dissects a signature blob of 65+ bytes into its `r`, `s`, and `v`
@@ -50,12 +50,12 @@ module Klay
50
50
  def dissect(signature)
51
51
  signature = Util.bin_to_hex signature unless Util.is_hex? signature
52
52
  signature = Util.remove_hex_prefix signature
53
- if signature.size < 130
53
+ if signature.size != 130
54
54
  raise SignatureError, "Unknown signature length #{signature.size}!"
55
55
  end
56
- r = signature[0, 64]
57
- s = signature[64, 128]
58
- v = signature[128]
56
+ r = signature[0...64]
57
+ s = signature[64...128]
58
+ v = signature[128..]
59
59
  return r, s, v
60
60
  end
61
61
 
@@ -70,8 +70,7 @@ module Klay
70
70
  context = Secp256k1::Context.new
71
71
  r, s, v = dissect signature
72
72
  v = v.to_i(16)
73
- p v
74
- raise SignatureError, "Invalid signature v byte #{v} for chain ID #{chain_id}!" if v != 130
73
+ # raise SignatureError, "Invalid signature v byte #{v} for chain ID #{chain_id}!" if v != 130
75
74
  recovery_id = Chain.to_recovery_id v, chain_id
76
75
  signature_rs = Util.hex_to_bin "#{r}#{s}"
77
76
  recoverable_signature = context.recoverable_signature_from_compact signature_rs, recovery_id
@@ -110,7 +109,7 @@ module Klay
110
109
  #
111
110
  # @param blob [String] that arbitrary data to be verified.
112
111
  # @param signature [String] the hex string containing the signature.
113
- # @param public_key [String] either a public key or an Ethereum address.
112
+ # @param public_key [String] either a public key or an Klaytn address.
114
113
  # @param chain_id [Integer] the chain ID used to sign.
115
114
  # @return [Boolean] true if signature matches provided public key.
116
115
  # @raise [SignatureError] if it cannot determine the type of data or public key.
@@ -135,7 +134,7 @@ module Klay
135
134
 
136
135
  if public_key.instance_of? Address
137
136
 
138
- # recovering using an Eth::Address
137
+ # recovering using an Klay::Address
139
138
  address = public_key.to_s
140
139
  recovered_address = Util.public_key_to_address(recovered_key).to_s
141
140
  return address == recovered_address
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2016-2022 The Ruby-Eth Contributors
1
+ # Copyright (c) 2016-2022 The Ruby-Klay Contributors
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # Provides the {Eth} module.
15
+ # Provides the {Klay} module.
16
16
  module Klay
17
17
 
18
18
  # Provides the `Tx` module supporting various transaction types.
@@ -77,8 +77,8 @@ module Klay
77
77
  # @option params [Integer] :priority_fee the max priority fee per gas.
78
78
  # @option params [Integer] :max_gas_fee the max transaction fee per gas.
79
79
  # @option params [Integer] :gas_limit the gas limit.
80
- # @option params [Eth::Address] :from the sender address.
81
- # @option params [Eth::Address] :to the reciever address.
80
+ # @option params [Klay::Address] :from the sender address.
81
+ # @option params [Klay::Address] :to the reciever address.
82
82
  # @option params [Integer] :value the transaction value.
83
83
  # @option params [String] :data the transaction data payload.
84
84
  # @option params [Array] :access_list an optional access list.
@@ -127,11 +127,11 @@ module Klay
127
127
  # Overloads the constructor for decoding raw transactions and creating unsigned copies.
128
128
  konstructor :decode, :unsigned_copy
129
129
 
130
- # Decodes a raw transaction hex into an {Eth::Tx::Eip1559}
130
+ # Decodes a raw transaction hex into an {Klay::Tx::Eip1559}
131
131
  # transaction object.
132
132
  #
133
133
  # @param hex [String] the raw transaction hex-string.
134
- # @return [Eth::Tx::Eip1559] transaction payload.
134
+ # @return [Klay::Tx::Eip1559] transaction payload.
135
135
  # @raise [TransactionTypeError] if transaction type is invalid.
136
136
  # @raise [ParameterError] if transaction is missing fields.
137
137
  # @raise [DecoderError] if transaction decoding fails.
@@ -194,8 +194,8 @@ module Klay
194
194
 
195
195
  # Creates an unsigned copy of a transaction payload.
196
196
  #
197
- # @param tx [Eth::Tx::Eip1559] an EIP-1559 transaction payload.
198
- # @return [Eth::Tx::Eip1559] an unsigned EIP-1559 transaction payload.
197
+ # @param tx [Klay::Tx::Eip1559] an EIP-1559 transaction payload.
198
+ # @return [Klay::Tx::Eip1559] an unsigned EIP-1559 transaction payload.
199
199
  # @raise [TransactionTypeError] if transaction type does not match.
200
200
  def unsigned_copy(tx)
201
201
 
@@ -225,7 +225,7 @@ module Klay
225
225
 
226
226
  # Sign the transaction with a given key.
227
227
  #
228
- # @param key [Eth::Key] the key-pair to use for signing.
228
+ # @param key [Klay::Key] the key-pair to use for signing.
229
229
  # @return [String] a transaction hash.
230
230
  # @raise [Signature::SignatureError] if transaction is already signed.
231
231
  # @raise [Signature::SignatureError] if sender address does not match signing key.