gasfree_sdk 0.1.0 → 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/.rubocop.yml +28 -3
- data/CHANGELOG.md +58 -3
- data/LICENSE.txt +119 -21
- data/README.md +211 -56
- data/examples/basic_usage.rb +26 -10
- data/examples/demo.rb +12 -10
- data/examples/simple_usage_example.rb +107 -0
- data/examples/test_tron_signer.rb +122 -0
- data/lib/gasfree_sdk/base58.rb +65 -0
- data/lib/gasfree_sdk/client.rb +184 -14
- data/lib/gasfree_sdk/crypto.rb +111 -0
- data/lib/gasfree_sdk/models/token.rb +4 -4
- data/lib/gasfree_sdk/models/transfer_response.rb +19 -19
- data/lib/gasfree_sdk/tron_eip712_signer.rb +260 -0
- data/lib/gasfree_sdk/types.rb +25 -2
- data/lib/gasfree_sdk/version.rb +1 -1
- data/lib/gasfree_sdk.rb +3 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8aeb4c75e0cd23ef92ce14e8bb3eff5a603b3548adb107e2972ca405f6c5d1f
|
4
|
+
data.tar.gz: 5ae0d2003914b2213836d436f0f4e3d33a7863e2575ff7b6055a00ba6b8f3c33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c62cbe4781d62f6b4a448f9e7e9dc56bd2fc5ebd5db255f4629fac1b090e6ef47e13a087adc0c3abe678912e1ced805e8e4482c32649e158c2cf7465c0f78ee
|
7
|
+
data.tar.gz: 17051e90d09f6fdcba77eece0baae5a7e62867a3d208552001e2a40641b459e43e521becd62cd766c26df19e2cc10c20f365e85c46c35df1a1233c114d782a2f
|
data/.rubocop.yml
CHANGED
@@ -1,49 +1,74 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 3.3
|
3
|
+
NewCops: enable
|
3
4
|
SuggestExtensions: false
|
4
5
|
Exclude:
|
5
6
|
- 'vendor/**/*'
|
6
7
|
- 'bin/**/*'
|
8
|
+
- 'examples/**/*'
|
7
9
|
|
8
10
|
require:
|
9
11
|
- rubocop-rake
|
10
12
|
- rubocop-rspec
|
11
13
|
|
14
|
+
# Disable problematic cops that cause errors
|
15
|
+
Capybara/RSpec/PredicateMatcher:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
# Layout rules
|
12
19
|
Layout/LineLength:
|
13
20
|
Max: 120
|
14
21
|
Exclude:
|
15
22
|
- 'gasfree_sdk.gemspec'
|
16
23
|
- 'examples/**/*'
|
17
24
|
|
25
|
+
# Metrics rules
|
18
26
|
Metrics/BlockLength:
|
19
27
|
Exclude:
|
20
28
|
- 'spec/**/*'
|
21
29
|
- 'examples/**/*'
|
22
30
|
|
23
31
|
Metrics/MethodLength:
|
24
|
-
Max:
|
32
|
+
Max: 17
|
25
33
|
Exclude:
|
26
34
|
- 'spec/**/*'
|
27
35
|
|
36
|
+
Metrics/ClassLength:
|
37
|
+
Max: 200
|
38
|
+
|
28
39
|
Metrics/CyclomaticComplexity:
|
29
40
|
Max: 10
|
30
41
|
Exclude:
|
31
42
|
- 'spec/**/*'
|
32
43
|
|
44
|
+
# Documentation rules
|
33
45
|
Style/Documentation:
|
34
46
|
Exclude:
|
35
47
|
- 'spec/**/*'
|
36
48
|
- 'examples/**/*'
|
37
49
|
- 'lib/gasfree_sdk/errors.rb'
|
38
50
|
|
51
|
+
# RSpec rules
|
39
52
|
RSpec/ExampleLength:
|
40
|
-
Max:
|
53
|
+
Max: 50
|
41
54
|
|
42
55
|
RSpec/MultipleExpectations:
|
43
|
-
Max:
|
56
|
+
Max: 15
|
44
57
|
|
58
|
+
# String literal rules
|
45
59
|
Style/StringLiterals:
|
46
60
|
EnforcedStyle: double_quotes
|
47
61
|
|
48
62
|
Style/StringLiteralsInInterpolation:
|
49
63
|
EnforcedStyle: double_quotes
|
64
|
+
|
65
|
+
# Disable some overly strict cops for this project
|
66
|
+
Style/FrozenStringLiteralComment:
|
67
|
+
Enabled: true
|
68
|
+
|
69
|
+
# Gemspec rules - be more lenient for development gems
|
70
|
+
Gemspec/RequireMFA:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Gemspec/DevelopmentDependencies:
|
74
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,60 @@
|
|
1
|
-
|
1
|
+
# Changelog
|
2
2
|
|
3
|
-
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [1.0.0] - 2025-06-08
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- **TronEIP712Signer Module**: Complete EIP-712 signature implementation for TRON GasFree transfers
|
12
|
+
- Full EIP-712 structured data signing according to TIP-712 specifications
|
13
|
+
- Support for both TRON Mainnet and Testnet (Nile) networks
|
14
|
+
- Built-in Keccak256 cryptographic hashing implementation
|
15
|
+
- Base58 encoding/decoding utilities for TRON addresses
|
16
|
+
- Flexible data key handling (camelCase, snake_case conversion)
|
17
|
+
- Pre-configured domain constants for GasFree contracts
|
18
|
+
- Comprehensive test coverage with RSpec
|
19
|
+
|
20
|
+
- **Core GasFree SDK functionality**
|
21
|
+
- API client for GasFree.io with support for different endpoints (mainnet, testnet, custom)
|
22
|
+
- Support for tokens, providers, and transfer operations
|
23
|
+
- Comprehensive error handling and validation
|
24
|
+
- Ethereum and TRON address support
|
25
|
+
- RSpec test suite with comprehensive coverage
|
26
|
+
- Dry-rb validation and type checking
|
27
|
+
|
28
|
+
### Features
|
29
|
+
- `GasfreeSdk::TronEIP712Signer.sign_typed_data_testnet()` - Sign for TRON Testnet
|
30
|
+
- `GasfreeSdk::TronEIP712Signer.sign_typed_data_mainnet()` - Sign for TRON Mainnet
|
31
|
+
- `GasfreeSdk::TronEIP712Signer.sign_typed_data()` - Generic signing with custom domains
|
32
|
+
- `GasfreeSdk::Crypto::Keccak256` - Pure Ruby Keccak256 implementation
|
33
|
+
- `GasfreeSdk::Base58` - TRON address encoding/decoding utilities
|
34
|
+
- Token, Provider, and Transfer management APIs
|
35
|
+
- Service Providers API with proper data mapping from camelCase to snake_case
|
36
|
+
- Improved URL path handling for API requests
|
37
|
+
|
38
|
+
### Dependencies
|
39
|
+
- Added `rbsecp256k1` (~> 6.0) for secp256k1 cryptographic operations
|
40
|
+
|
41
|
+
### Examples
|
42
|
+
- `examples/simple_usage_example.rb` - Basic TronEIP712Signer usage demonstration
|
43
|
+
- `examples/test_tron_signer.rb` - Comprehensive module testing script
|
44
|
+
- Updated `examples/test_with_real_data_prod.rb` to use the new module
|
45
|
+
|
46
|
+
### Documentation
|
47
|
+
- Updated README.md with comprehensive TronEIP712Signer documentation
|
48
|
+
- Added usage examples and API reference
|
49
|
+
- Documented all cryptographic operations and utilities
|
50
|
+
- Improved documentation for Service Providers with detailed configuration constraints
|
51
|
+
|
52
|
+
### Fixed
|
53
|
+
- Fixed Service Providers API data mapping from camelCase to snake_case
|
54
|
+
- Added proper transformation for provider configuration fields (maxPendingTransfer -> max_pending_transfer, etc.)
|
55
|
+
- Updated tests to use correct API response format for providers
|
56
|
+
|
57
|
+
### Enhanced
|
58
|
+
- Comprehensive test coverage for provider field mapping
|
59
|
+
- RSpec testing framework integration
|
60
|
+
- Improved error handling and validation throughout the SDK
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,119 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2025 Eugene Leontev (madmatvey)
|
5
|
+
Project: gasfree_sdk (https://github.com/madmatvey/gasfree_sdk)
|
6
|
+
|
7
|
+
Everyone is permitted to copy and distribute verbatim copies
|
8
|
+
of this license document, but changing it is not allowed.
|
9
|
+
|
10
|
+
This version of the GNU Lesser General Public License incorporates
|
11
|
+
the terms and conditions of version 3 of the GNU General Public License,
|
12
|
+
supplemented by the additional permissions listed below.
|
13
|
+
|
14
|
+
0. Additional Definitions.
|
15
|
+
|
16
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser General Public License,
|
17
|
+
and the "GNU GPL" refers to version 3 of the GNU General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
|
20
|
+
|
21
|
+
An "Application" is any work that makes use of an interface provided by the Library,
|
22
|
+
but which is not otherwise based on the Library.
|
23
|
+
Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
|
24
|
+
|
25
|
+
A "Combined Work" is a work produced by combining or linking an Application with the Library.
|
26
|
+
The particular version of the Library with which the Combined Work was made is also called the "Linked Version".
|
27
|
+
|
28
|
+
The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work,
|
29
|
+
excluding any source code for portions of the Combined Work that are based on the Application,
|
30
|
+
and not on the Linked Version.
|
31
|
+
|
32
|
+
The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application,
|
33
|
+
including any data and utility programs needed for reproducing the Combined Work from the Application,
|
34
|
+
but excluding the System Libraries of the Combined Work.
|
35
|
+
|
36
|
+
1. Exception to Section 3 of the GNU GPL.
|
37
|
+
|
38
|
+
You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
|
39
|
+
|
40
|
+
2. Conveying Modified Versions.
|
41
|
+
|
42
|
+
If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked),
|
43
|
+
then you may convey a copy of the modified version:
|
44
|
+
|
45
|
+
a) under this License, provided that you make a good faith effort to ensure that,
|
46
|
+
in the event an Application does not supply the function or data,
|
47
|
+
the facility still operates, and performs whatever part of its purpose remains meaningful, or
|
48
|
+
|
49
|
+
b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
|
50
|
+
|
51
|
+
3. Object Code Incorporating Material from Library Header Files.
|
52
|
+
|
53
|
+
The object code form of an Application may incorporate material from a header file that is part of the Library.
|
54
|
+
You may convey such object code under terms of your choice, provided that,
|
55
|
+
if the incorporated material is not limited to numerical parameters, data structure layouts and accessors,
|
56
|
+
or small macros, inline functions and templates (ten or fewer lines in length),
|
57
|
+
you do both of the following:
|
58
|
+
|
59
|
+
a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
|
60
|
+
|
61
|
+
b) Accompany the object code with a copy of the GNU GPL and this license document.
|
62
|
+
|
63
|
+
4. Combined Works.
|
64
|
+
|
65
|
+
You may convey a Combined Work under terms of your choice that, taken together,
|
66
|
+
effectively do not restrict modification of the portions of the Library contained in the Combined Work
|
67
|
+
and reverse engineering for debugging such modifications,
|
68
|
+
if you also do each of the following:
|
69
|
+
|
70
|
+
a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
|
71
|
+
|
72
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
|
73
|
+
|
74
|
+
c) For a Combined Work that displays copyright notices during execution,
|
75
|
+
include the copyright notice for the Library among these notices,
|
76
|
+
as well as a reference directing the user to the copies of the GNU GPL and this license document.
|
77
|
+
|
78
|
+
d) Do one of the following:
|
79
|
+
|
80
|
+
0) Convey the Minimal Corresponding Source under the terms of this License,
|
81
|
+
and the Corresponding Application Code in a form suitable for,
|
82
|
+
and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work,
|
83
|
+
in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
|
84
|
+
|
85
|
+
1) Use a suitable shared library mechanism for linking with the Library.
|
86
|
+
A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system,
|
87
|
+
and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
|
88
|
+
|
89
|
+
e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL,
|
90
|
+
and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version.
|
91
|
+
(If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code.
|
92
|
+
If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
|
93
|
+
|
94
|
+
5. Combined Libraries.
|
95
|
+
|
96
|
+
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities not covered by this License,
|
97
|
+
and distribute such a combined library,
|
98
|
+
provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted,
|
99
|
+
and provided that you do these two things:
|
100
|
+
|
101
|
+
a) Accompany the combined library with a copy of the same work based on the Library,
|
102
|
+
uncombined with any other library facilities, conveyed under the terms of this License.
|
103
|
+
|
104
|
+
b) Give prominent notice with the combined library that part of it is a work based on the Library,
|
105
|
+
and explaining where to find the accompanying uncombined form of the same work.
|
106
|
+
|
107
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
108
|
+
|
109
|
+
The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time.
|
110
|
+
Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
111
|
+
|
112
|
+
Each version is given a distinguishing version number.
|
113
|
+
If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it,
|
114
|
+
you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation.
|
115
|
+
If the Library as you received it does not specify a version number of the GNU Lesser General Public License,
|
116
|
+
you may choose any version ever published by the Free Software Foundation.
|
117
|
+
|
118
|
+
If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply,
|
119
|
+
that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
|
data/README.md
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# GasFree SDK
|
2
2
|
|
3
|
-
Ruby SDK for
|
3
|
+
Ruby SDK for GasFree.io - TRC-20 gasless transfer solution.
|
4
4
|
|
5
|
-
##
|
5
|
+
## 💬 Support & Consulting
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
- Thread-safe configuration
|
7
|
+
If you encounter any issues, feel free to open a discussion or report a bug via the [GitHub Issues](https://github.com/madmatvey/gasfree_sdk/issues) page.
|
8
|
+
|
9
|
+
You can also [hire me as an external consultant](https://madmatvey.github.io/about/#cv) if you need help integrating or customizing the gem for your project.
|
10
|
+
|
11
|
+
If you find this gem useful and want to support further development, you're welcome to [donate here](https://madmatvey.github.io/about/#donate-me).
|
13
12
|
|
14
13
|
## Installation
|
15
14
|
|
15
|
+
This gem is published on [RubyGems.org](https://rubygems.org/gems/gasfree_sdk).
|
16
|
+
|
16
17
|
Add this line to your application's Gemfile:
|
17
18
|
|
18
19
|
```ruby
|
@@ -21,30 +22,25 @@ gem 'gasfree_sdk'
|
|
21
22
|
|
22
23
|
And then execute:
|
23
24
|
|
24
|
-
|
25
|
-
bundle install
|
26
|
-
```
|
25
|
+
$ bundle install
|
27
26
|
|
28
27
|
Or install it yourself as:
|
29
28
|
|
30
|
-
|
31
|
-
gem install gasfree_sdk
|
32
|
-
```
|
29
|
+
$ gem install gasfree_sdk
|
33
30
|
|
34
31
|
## Configuration
|
35
32
|
|
36
|
-
Configure the SDK with your API credentials:
|
37
|
-
|
38
33
|
```ruby
|
34
|
+
require 'gasfree_sdk'
|
35
|
+
|
39
36
|
GasfreeSdk.configure do |config|
|
40
37
|
config.api_key = "your-api-key"
|
41
38
|
config.api_secret = "your-api-secret"
|
42
|
-
config.api_endpoint = "https://open.gasfree.io/tron/"
|
43
|
-
config.default_chain_id = 1 # Optional, defaults to Ethereum mainnet
|
39
|
+
config.api_endpoint = "https://open.gasfree.io/tron/" # TRON endpoint
|
44
40
|
end
|
45
41
|
```
|
46
42
|
|
47
|
-
## Usage
|
43
|
+
## Basic Usage
|
48
44
|
|
49
45
|
### Initialize Client
|
50
46
|
|
@@ -57,10 +53,9 @@ client = GasfreeSdk.client
|
|
57
53
|
```ruby
|
58
54
|
tokens = client.tokens
|
59
55
|
tokens.each do |token|
|
60
|
-
puts "
|
61
|
-
puts "
|
62
|
-
puts "
|
63
|
-
puts "Transfer Fee: #{token.transfer_fee}"
|
56
|
+
puts "#{token.symbol} (#{token.token_address})"
|
57
|
+
puts " Activation Fee: #{token.activate_fee}"
|
58
|
+
puts " Transfer Fee: #{token.transfer_fee}"
|
64
59
|
end
|
65
60
|
```
|
66
61
|
|
@@ -69,76 +64,236 @@ end
|
|
69
64
|
```ruby
|
70
65
|
providers = client.providers
|
71
66
|
providers.each do |provider|
|
72
|
-
puts "
|
73
|
-
puts "
|
74
|
-
puts "
|
67
|
+
puts "#{provider.name} (#{provider.address})"
|
68
|
+
puts " Max Pending Transfers: #{provider.config.max_pending_transfer}"
|
69
|
+
puts " Default Deadline: #{provider.config.default_deadline_duration}s"
|
75
70
|
end
|
76
71
|
```
|
77
72
|
|
78
|
-
###
|
73
|
+
### Check Account Information
|
79
74
|
|
80
75
|
```ruby
|
81
|
-
account = client.address("
|
76
|
+
account = client.address("TYourTronAddress")
|
82
77
|
puts "GasFree Address: #{account.gas_free_address}"
|
83
78
|
puts "Active: #{account.active}"
|
84
79
|
puts "Nonce: #{account.nonce}"
|
85
80
|
|
86
81
|
account.assets.each do |asset|
|
87
|
-
puts "
|
88
|
-
puts "Frozen Amount: #{asset.frozen}"
|
82
|
+
puts "#{asset.token_symbol}: #{asset.frozen} frozen"
|
89
83
|
end
|
90
84
|
```
|
91
85
|
|
92
|
-
|
86
|
+
## TRON EIP-712 Signature Module
|
87
|
+
|
88
|
+
The SDK includes a comprehensive EIP-712 signature implementation specifically designed for TRON GasFree transfers. This module handles the complex cryptographic operations required for signing structured data according to the EIP-712 standard as implemented by TRON (TIP-712).
|
89
|
+
|
90
|
+
### Features
|
91
|
+
|
92
|
+
- **Complete EIP-712 Implementation**: Full support for EIP-712 structured data signing
|
93
|
+
- **TRON-Specific Adaptations**: Handles TRON address encoding and TIP-712 specifications
|
94
|
+
- **Dual Network Support**: Separate configurations for TRON Mainnet and Testnet (Nile)
|
95
|
+
- **Flexible Key Handling**: Support for multiple data key formats (camelCase, snake_case)
|
96
|
+
- **Built-in Cryptography**: Includes Keccak256 hashing and Base58 encoding for TRON addresses
|
97
|
+
|
98
|
+
### Basic Signature Usage
|
93
99
|
|
94
100
|
```ruby
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
# Example message data
|
102
|
+
message_data = {
|
103
|
+
token: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", # USDT TRC-20
|
104
|
+
serviceProvider: "TGzz8gjYiYRqpfmDwnLxfgPuLVNmpCswVp",
|
105
|
+
user: "TYRhsi1fkke2tjdVW9XGYLjf8TgbbutEgY",
|
106
|
+
receiver: "TW1dWXfta5ygVN298JBN2UPhaSAUzo2owZ",
|
107
|
+
value: "3000000", # 3 USDT (6 decimals)
|
108
|
+
maxFee: "2000000", # 2 USDT max fee
|
109
|
+
deadline: (Time.now.to_i + 300).to_s, # 5 minutes from now
|
103
110
|
version: 1,
|
104
|
-
nonce: 0
|
105
|
-
|
111
|
+
nonce: 0
|
112
|
+
}
|
113
|
+
|
114
|
+
private_key = "your_private_key_hex"
|
115
|
+
|
116
|
+
# Sign for TRON Testnet (Nile)
|
117
|
+
testnet_signature = GasfreeSdk::TronEIP712Signer.sign_typed_data_testnet(private_key, message_data)
|
118
|
+
|
119
|
+
# Sign for TRON Mainnet
|
120
|
+
mainnet_signature = GasfreeSdk::TronEIP712Signer.sign_typed_data_mainnet(private_key, message_data)
|
121
|
+
|
122
|
+
# Generic signing with custom domain
|
123
|
+
signature = GasfreeSdk::TronEIP712Signer.sign_typed_data(
|
124
|
+
private_key,
|
125
|
+
message_data,
|
126
|
+
domain: GasfreeSdk::TronEIP712Signer::DOMAIN_TESTNET
|
106
127
|
)
|
128
|
+
```
|
129
|
+
|
130
|
+
### Advanced Usage
|
131
|
+
|
132
|
+
#### Custom Domain Configuration
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
custom_domain = {
|
136
|
+
name: "GasFreeController",
|
137
|
+
version: "V1.0.0",
|
138
|
+
chainId: 728_126_428,
|
139
|
+
verifyingContract: "THQGuFzL87ZqhxkgqYEryRAd7gqFqL5rdc"
|
140
|
+
}
|
141
|
+
|
142
|
+
signature = GasfreeSdk::TronEIP712Signer.sign_typed_data(
|
143
|
+
private_key,
|
144
|
+
message_data,
|
145
|
+
domain: custom_domain,
|
146
|
+
use_ethereum_v: true
|
147
|
+
)
|
148
|
+
```
|
149
|
+
|
150
|
+
#### Individual Cryptographic Operations
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
# Keccak256 hashing
|
154
|
+
hash = GasfreeSdk::TronEIP712Signer.keccac256("data to hash")
|
155
|
+
hex_hash = GasfreeSdk::TronEIP712Signer.keccac256_hex("data to hash")
|
156
|
+
|
157
|
+
# EIP-712 type encoding
|
158
|
+
encoded_type = GasfreeSdk::TronEIP712Signer.encode_type(:PermitTransfer)
|
107
159
|
|
160
|
+
# Structured data hashing
|
161
|
+
message_hash = GasfreeSdk::TronEIP712Signer.hash_struct(:PermitTransfer, message_data)
|
162
|
+
domain_hash = GasfreeSdk::TronEIP712Signer.hash_domain
|
163
|
+
```
|
164
|
+
|
165
|
+
#### TRON Address Utilities
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
# Base58 encoding/decoding for TRON addresses
|
169
|
+
binary_data = GasfreeSdk::Base58.base58_to_binary("TYRhsi1fkke2tjdVW9XGYLjf8TgbbutEgY")
|
170
|
+
base58_string = GasfreeSdk::Base58.binary_to_base58(binary_data)
|
171
|
+
```
|
172
|
+
|
173
|
+
### Domain Constants
|
174
|
+
|
175
|
+
The module provides pre-configured domain constants for both networks:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
# TRON Testnet (Nile)
|
179
|
+
GasfreeSdk::TronEIP712Signer::DOMAIN_TESTNET
|
180
|
+
# => {
|
181
|
+
# name: "GasFreeController",
|
182
|
+
# version: "V1.0.0",
|
183
|
+
# chainId: 728_126_428,
|
184
|
+
# verifyingContract: "THQGuFzL87ZqhxkgqYEryRAd7gqFqL5rdc"
|
185
|
+
# }
|
186
|
+
|
187
|
+
# TRON Mainnet
|
188
|
+
GasfreeSdk::TronEIP712Signer::DOMAIN_MAINNET
|
189
|
+
# => {
|
190
|
+
# name: "GasFreeController",
|
191
|
+
# version: "V1.0.0",
|
192
|
+
# chainId: 3_448_148_188,
|
193
|
+
# verifyingContract: "TFFAMQLZybALaLb4uxHA9RBE7pxhUAjF3U"
|
194
|
+
# }
|
195
|
+
```
|
196
|
+
|
197
|
+
### Submit Transfer with Signature
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
# Create and submit a transfer request
|
201
|
+
token = client.tokens.first
|
202
|
+
provider = client.providers.first
|
203
|
+
|
204
|
+
message_data = {
|
205
|
+
token: token.token_address,
|
206
|
+
serviceProvider: provider.address,
|
207
|
+
user: "TYourTronAddress",
|
208
|
+
receiver: "TReceiverAddress",
|
209
|
+
value: "1000000", # 1 USDT
|
210
|
+
maxFee: "500000", # 0.5 USDT max fee
|
211
|
+
deadline: (Time.now.to_i + provider.config.default_deadline_duration).to_s,
|
212
|
+
version: 1,
|
213
|
+
nonce: account.nonce
|
214
|
+
}
|
215
|
+
|
216
|
+
# Sign the message
|
217
|
+
signature = GasfreeSdk::TronEIP712Signer.sign_typed_data_testnet(private_key, message_data)
|
218
|
+
|
219
|
+
# Create transfer request
|
220
|
+
request = GasfreeSdk::Models::TransferRequest.new(
|
221
|
+
token: message_data[:token],
|
222
|
+
service_provider: message_data[:serviceProvider],
|
223
|
+
user: message_data[:user],
|
224
|
+
receiver: message_data[:receiver],
|
225
|
+
value: message_data[:value],
|
226
|
+
max_fee: message_data[:maxFee],
|
227
|
+
deadline: message_data[:deadline].to_i,
|
228
|
+
version: message_data[:version],
|
229
|
+
nonce: message_data[:nonce],
|
230
|
+
sig: signature
|
231
|
+
)
|
232
|
+
|
233
|
+
# Submit the transfer
|
108
234
|
response = client.submit_transfer(request)
|
109
235
|
puts "Transfer ID: #{response.id}"
|
110
236
|
puts "State: #{response.state}"
|
111
237
|
```
|
112
238
|
|
113
|
-
###
|
239
|
+
### Monitor Transfer Status
|
114
240
|
|
115
241
|
```ruby
|
116
|
-
|
117
|
-
|
118
|
-
|
242
|
+
transfer_id = response.id
|
243
|
+
|
244
|
+
loop do
|
245
|
+
status = client.transfer_status(transfer_id)
|
246
|
+
puts "State: #{status.state}"
|
247
|
+
puts "Transaction Hash: #{status.txn_hash}" if status.txn_hash
|
248
|
+
|
249
|
+
break if %w[SUCCEED FAILED].include?(status.state)
|
250
|
+
sleep 2
|
251
|
+
end
|
119
252
|
```
|
120
253
|
|
121
254
|
## Error Handling
|
122
255
|
|
123
|
-
The SDK provides detailed error classes for different types of errors:
|
124
|
-
|
125
256
|
```ruby
|
126
257
|
begin
|
127
|
-
client.submit_transfer(request)
|
128
|
-
rescue GasfreeSdk::InsufficientBalanceError => e
|
129
|
-
puts "Insufficient balance: #{e.message}"
|
130
|
-
rescue GasfreeSdk::DeadlineExceededError => e
|
131
|
-
puts "Deadline exceeded: #{e.message}"
|
258
|
+
response = client.submit_transfer(request)
|
132
259
|
rescue GasfreeSdk::APIError => e
|
133
|
-
puts "API
|
260
|
+
puts "API Error (#{e.code}): #{e.message}"
|
261
|
+
|
262
|
+
case e.message
|
263
|
+
when /insufficient balance/
|
264
|
+
puts "Solution: Get test tokens or transfer tokens to GasFree address"
|
265
|
+
when /max fee exceeded/
|
266
|
+
puts "Solution: Increase maxFee parameter"
|
267
|
+
when /Invalid signature/
|
268
|
+
puts "Solution: Check private key and address correspondence"
|
269
|
+
end
|
270
|
+
rescue StandardError => e
|
271
|
+
puts "Error: #{e.message}"
|
134
272
|
end
|
135
273
|
```
|
136
274
|
|
275
|
+
## Examples
|
276
|
+
|
277
|
+
See the `examples/` directory for complete working examples:
|
278
|
+
|
279
|
+
- `examples/simple_usage_example.rb` - Basic TronEIP712Signer usage
|
280
|
+
|
281
|
+
## Dependencies
|
282
|
+
|
283
|
+
- `dry-configurable` - Configuration management
|
284
|
+
- `dry-struct` - Data structures
|
285
|
+
- `dry-types` - Type system
|
286
|
+
- `dry-validation` - Data validation
|
287
|
+
- `faraday` - HTTP client
|
288
|
+
- `faraday-retry` - HTTP retry logic
|
289
|
+
- `eth` - Ethereum utilities
|
290
|
+
- `rbsecp256k1` - Cryptographic operations for EIP-712 signatures
|
291
|
+
|
137
292
|
## Development
|
138
293
|
|
139
294
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
140
295
|
|
141
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
296
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
142
297
|
|
143
298
|
## Contributing
|
144
299
|
|
@@ -146,4 +301,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/madmat
|
|
146
301
|
|
147
302
|
## License
|
148
303
|
|
149
|
-
The gem is available as open source under the terms of the [
|
304
|
+
The gem is available as open source under the terms of the [LGPL v3.0](https://www.gnu.org/licenses/lgpl-3.0.html) © 2025 Eugene Leontev (https://github.com/madmatvey)
|