klay 0.0.1 → 0.0.4
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/AUTHORS.txt +1 -5
- data/LICENSE.txt +0 -1
- data/README.md +28 -84
- data/bin/setup +1 -1
- data/klay.gemspec +1 -1
- data/lib/klay/abi/type.rb +8 -8
- data/lib/klay/abi.rb +7 -7
- data/lib/klay/address.rb +5 -5
- data/lib/klay/api.rb +4 -4
- data/lib/klay/chain.rb +2 -2
- data/lib/klay/client/http.rb +2 -2
- data/lib/klay/client/ipc.rb +2 -2
- data/lib/klay/client.rb +17 -17
- data/lib/klay/constant.rb +2 -2
- data/lib/klay/eip712.rb +2 -2
- data/lib/klay/key/decrypter.rb +9 -9
- data/lib/klay/key/encrypter.rb +8 -8
- data/lib/klay/key.rb +12 -12
- data/lib/klay/rlp/decoder.rb +3 -3
- data/lib/klay/rlp/encoder.rb +4 -4
- data/lib/klay/rlp/sedes/big_endian_int.rb +2 -2
- data/lib/klay/rlp/sedes/binary.rb +3 -3
- data/lib/klay/rlp/sedes/list.rb +2 -2
- data/lib/klay/rlp/sedes.rb +6 -6
- data/lib/klay/rlp.rb +4 -4
- data/lib/klay/signature.rb +10 -9
- data/lib/klay/tx/eip1559.rb +9 -9
- data/lib/klay/tx/eip2930.rb +9 -9
- data/lib/klay/tx/legacy.rb +9 -9
- data/lib/klay/tx.rb +7 -7
- data/lib/klay/unit.rb +9 -21
- data/lib/klay/util.rb +5 -5
- data/lib/klay/version.rb +4 -4
- data/lib/klay.rb +3 -3
- metadata +1 -3
- data/.github/workflows/codeql.yml +0 -48
- data/.github/workflows/docs.yml +0 -26
data/lib/klay/key/decrypter.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
15
|
+
# Provides the {Klay} module.
|
16
16
|
module Klay
|
17
17
|
|
18
|
-
# The {
|
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 {
|
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 [
|
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 {
|
35
|
-
# decryption. Should not be used; use {
|
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 [
|
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
|
-
|
53
|
+
Klay::Key.new priv: private_key
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
data/lib/klay/key/encrypter.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
15
|
+
# Provides the {Klay} module.
|
16
16
|
module Klay
|
17
17
|
|
18
|
-
# The {
|
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 {
|
24
|
+
# Class method {Klay::Key::Encrypter.perform} to performa an key-store
|
25
25
|
# encryption.
|
26
26
|
#
|
27
|
-
# @param key [
|
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 {
|
42
|
-
# encryption. Should not be used; use {
|
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 [
|
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-
|
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 {
|
21
|
+
# Provides the {Klay} module.
|
22
22
|
module Klay
|
23
23
|
|
24
|
-
# The {
|
24
|
+
# The {Klay::Key} class to handle Secp256k1 private/public key-pairs.
|
25
25
|
class Key
|
26
26
|
|
27
|
-
# The {
|
27
|
+
# The {Klay::Key::Decrypter} class to handle PBKDF2-SHA-256 decryption.
|
28
28
|
autoload :Decrypter, "eth/key/decrypter"
|
29
29
|
|
30
|
-
# The {
|
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 {
|
33
|
+
# The `Secp256k1::PrivateKey` of the {Klay::Key} pair.
|
34
34
|
attr_reader :private_key
|
35
35
|
|
36
|
-
# The `Secp256k1::PublicKey` of the {
|
36
|
+
# The `Secp256k1::PublicKey` of the {Klay::Key} pair.
|
37
37
|
attr_reader :public_key
|
38
38
|
|
39
|
-
# Constructor of the {
|
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 `\
|
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 {
|
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 {
|
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 [
|
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
|
data/lib/klay/rlp/decoder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
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 [
|
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
|
data/lib/klay/rlp/encoder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
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 [
|
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 [
|
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-
|
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 {
|
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-
|
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 {
|
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 [
|
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
|
data/lib/klay/rlp/sedes/list.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
17
|
+
# Provides the {Klay} module.
|
18
18
|
module Klay
|
19
19
|
|
20
20
|
# Provides an recursive-length prefix (RLP) encoder and decoder.
|
data/lib/klay/rlp/sedes.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
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 {
|
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 {
|
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 [
|
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 [
|
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-
|
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 {
|
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 {
|
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 {
|
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.
|
data/lib/klay/signature.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
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
|
-
"
|
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,11 +50,11 @@ 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
|
53
|
+
if signature.size != 130
|
54
54
|
raise SignatureError, "Unknown signature length #{signature.size}!"
|
55
55
|
end
|
56
|
-
r = signature[0
|
57
|
-
s = signature[64
|
56
|
+
r = signature[0...64]
|
57
|
+
s = signature[64...128]
|
58
58
|
v = signature[128..]
|
59
59
|
return r, s, v
|
60
60
|
end
|
@@ -70,7 +70,8 @@ module Klay
|
|
70
70
|
context = Secp256k1::Context.new
|
71
71
|
r, s, v = dissect signature
|
72
72
|
v = v.to_i(16)
|
73
|
-
|
73
|
+
p v
|
74
|
+
# raise SignatureError, "Invalid signature v byte #{v} for chain ID #{chain_id}!" if v != 130
|
74
75
|
recovery_id = Chain.to_recovery_id v, chain_id
|
75
76
|
signature_rs = Util.hex_to_bin "#{r}#{s}"
|
76
77
|
recoverable_signature = context.recoverable_signature_from_compact signature_rs, recovery_id
|
@@ -109,7 +110,7 @@ module Klay
|
|
109
110
|
#
|
110
111
|
# @param blob [String] that arbitrary data to be verified.
|
111
112
|
# @param signature [String] the hex string containing the signature.
|
112
|
-
# @param public_key [String] either a public key or an
|
113
|
+
# @param public_key [String] either a public key or an Klaytn address.
|
113
114
|
# @param chain_id [Integer] the chain ID used to sign.
|
114
115
|
# @return [Boolean] true if signature matches provided public key.
|
115
116
|
# @raise [SignatureError] if it cannot determine the type of data or public key.
|
@@ -134,7 +135,7 @@ module Klay
|
|
134
135
|
|
135
136
|
if public_key.instance_of? Address
|
136
137
|
|
137
|
-
# recovering using an
|
138
|
+
# recovering using an Klay::Address
|
138
139
|
address = public_key.to_s
|
139
140
|
recovered_address = Util.public_key_to_address(recovered_key).to_s
|
140
141
|
return address == recovered_address
|
data/lib/klay/tx/eip1559.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
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 [
|
81
|
-
# @option params [
|
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 {
|
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 [
|
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 [
|
198
|
-
# @return [
|
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 [
|
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.
|
data/lib/klay/tx/eip2930.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
15
|
+
# Provides the {Klay} module.
|
16
16
|
module Klay
|
17
17
|
|
18
18
|
# Provides the `Tx` module supporting various transaction types.
|
@@ -75,8 +75,8 @@ module Klay
|
|
75
75
|
# @option params [Integer] :nonce the signer nonce.
|
76
76
|
# @option params [Integer] :gas_price the gas price.
|
77
77
|
# @option params [Integer] :gas_limit the gas limit.
|
78
|
-
# @option params [
|
79
|
-
# @option params [
|
78
|
+
# @option params [Klay::Address] :from the sender address.
|
79
|
+
# @option params [Klay::Address] :to the reciever address.
|
80
80
|
# @option params [Integer] :value the transaction value.
|
81
81
|
# @option params [String] :data the transaction data payload.
|
82
82
|
# @option params [Array] :access_list an optional access list.
|
@@ -124,11 +124,11 @@ module Klay
|
|
124
124
|
# Overloads the constructor for decoding raw transactions and creating unsigned copies.
|
125
125
|
konstructor :decode, :unsigned_copy
|
126
126
|
|
127
|
-
# Decodes a raw transaction hex into an {
|
127
|
+
# Decodes a raw transaction hex into an {Klay::Tx::Eip2930}
|
128
128
|
# transaction object.
|
129
129
|
#
|
130
130
|
# @param hex [String] the raw transaction hex-string.
|
131
|
-
# @return [
|
131
|
+
# @return [Klay::Tx::Eip2930] transaction payload.
|
132
132
|
# @raise [TransactionTypeError] if transaction type is invalid.
|
133
133
|
# @raise [ParameterError] if transaction is missing fields.
|
134
134
|
# @raise [DecoderError] if transaction decoding fails.
|
@@ -189,8 +189,8 @@ module Klay
|
|
189
189
|
|
190
190
|
# Creates an unsigned copy of a transaction payload.
|
191
191
|
#
|
192
|
-
# @param tx [
|
193
|
-
# @return [
|
192
|
+
# @param tx [Klay::Tx::Eip2930] an EIP-2930 transaction payload.
|
193
|
+
# @return [Klay::Tx::Eip2930] an unsigned EIP-2930 transaction payload.
|
194
194
|
# @raise [TransactionTypeError] if transaction type does not match.
|
195
195
|
def unsigned_copy(tx)
|
196
196
|
|
@@ -219,7 +219,7 @@ module Klay
|
|
219
219
|
|
220
220
|
# Sign the transaction with a given key.
|
221
221
|
#
|
222
|
-
# @param key [
|
222
|
+
# @param key [Klay::Key] the key-pair to use for signing.
|
223
223
|
# @return [String] a transaction hash.
|
224
224
|
# @raise [Signature::SignatureError] if transaction is already signed.
|
225
225
|
# @raise [Signature::SignatureError] if sender address does not match signing key.
|
data/lib/klay/tx/legacy.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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 {
|
15
|
+
# Provides the {Klay} module.
|
16
16
|
module Klay
|
17
17
|
|
18
18
|
# Provides the `Tx` module supporting various transaction types.
|
@@ -67,8 +67,8 @@ module Klay
|
|
67
67
|
# @option params [Integer] :nonce the signer nonce.
|
68
68
|
# @option params [Integer] :gas_price the gas price.
|
69
69
|
# @option params [Integer] :gas_limit the gas limit.
|
70
|
-
# @option params [
|
71
|
-
# @option params [
|
70
|
+
# @option params [Klay::Address] :from the sender address.
|
71
|
+
# @option params [Klay::Address] :to the reciever address.
|
72
72
|
# @option params [Integer] :value the transaction value.
|
73
73
|
# @option params [String] :data the transaction data payload.
|
74
74
|
# @param chain_id [Integer] the EIP-155 Chain ID.
|
@@ -113,11 +113,11 @@ module Klay
|
|
113
113
|
# overloads the constructor for decoding raw transactions and creating unsigned copies
|
114
114
|
konstructor :decode, :unsigned_copy
|
115
115
|
|
116
|
-
# Decodes a raw transaction hex into an {
|
116
|
+
# Decodes a raw transaction hex into an {Klay::Tx::Legacy}
|
117
117
|
# transaction object.
|
118
118
|
#
|
119
119
|
# @param hex [String] the raw transaction hex-string.
|
120
|
-
# @return [
|
120
|
+
# @return [Klay::Tx::Legacy] transaction object.
|
121
121
|
# @raise [ParameterError] if transaction misses fields.
|
122
122
|
def decode(hex)
|
123
123
|
bin = Util.hex_to_bin hex
|
@@ -170,8 +170,8 @@ module Klay
|
|
170
170
|
|
171
171
|
# Creates an unsigned copy of a transaction.
|
172
172
|
#
|
173
|
-
# @param tx [
|
174
|
-
# @return [
|
173
|
+
# @param tx [Klay::Tx::Legacy] an legacy transaction object.
|
174
|
+
# @return [Klay::Tx::Legacy] an unsigned transaction object.
|
175
175
|
# @raise [TransactionTypeError] if transaction type does not match.
|
176
176
|
def unsigned_copy(tx)
|
177
177
|
|
@@ -199,7 +199,7 @@ module Klay
|
|
199
199
|
|
200
200
|
# Sign the transaction with a given key.
|
201
201
|
#
|
202
|
-
# @param key [
|
202
|
+
# @param key [Klay::Key] the key-pair to use for signing.
|
203
203
|
# @return [String] a transaction hash.
|
204
204
|
# @raise [Signature::SignatureError] if transaction is already signed.
|
205
205
|
# @raise [Signature::SignatureError] if sender address does not match signing key.
|
data/lib/klay/tx.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2016-2022 The Ruby-
|
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.
|
@@ -20,7 +20,7 @@ require "klay/tx/eip2930"
|
|
20
20
|
require "klay/tx/legacy"
|
21
21
|
require "klay/unit"
|
22
22
|
|
23
|
-
# Provides the {
|
23
|
+
# Provides the {Klay} module.
|
24
24
|
module Klay
|
25
25
|
|
26
26
|
# Provides the `Tx` module supporting various transaction types.
|
@@ -39,8 +39,8 @@ module Klay
|
|
39
39
|
# The minimum transaction gas limit required for a value transfer.
|
40
40
|
DEFAULT_GAS_LIMIT = 21_000.freeze
|
41
41
|
|
42
|
-
# The "default" transaction gas price of
|
43
|
-
DEFAULT_GAS_PRICE = (
|
42
|
+
# The "default" transaction gas price of 25 GPeb.
|
43
|
+
DEFAULT_GAS_PRICE = (25 * Unit::GPEB).freeze
|
44
44
|
|
45
45
|
# The calldata gas cost of a non-zero byte as per EIP-2028.
|
46
46
|
COST_NON_ZERO_BYTE = 16.freeze
|
@@ -101,7 +101,7 @@ module Klay
|
|
101
101
|
# Decodes a transaction hex of any known type (2, 1, or legacy).
|
102
102
|
#
|
103
103
|
# @param hex [String] the raw transaction hex-string.
|
104
|
-
# @return [
|
104
|
+
# @return [Klay::Tx] transaction payload.
|
105
105
|
# @raise [TransactionTypeError] if the transaction type is unknown.
|
106
106
|
def decode(hex)
|
107
107
|
hex = Util.remove_hex_prefix hex
|
@@ -128,8 +128,8 @@ module Klay
|
|
128
128
|
|
129
129
|
# Creates an unsigned copy of any transaction object.
|
130
130
|
#
|
131
|
-
# @param tx [
|
132
|
-
# @return [
|
131
|
+
# @param tx [Klay::Tx] any transaction payload.
|
132
|
+
# @return [Klay::Tx] an unsigned transaction payload of the same type.
|
133
133
|
# @raise [TransactionTypeError] if the transaction type is unknown.
|
134
134
|
def unsigned_copy(tx)
|
135
135
|
case tx.type
|