hexsafe 0.0.0 → 0.0.1
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/lib/hexsafe/api.rb +108 -110
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ec8ce1e707e3567efe4143851d16fb4493633a0a797eed4141f30ff0b4dbb75
|
4
|
+
data.tar.gz: 5aab011d9c06c0c0cea2c8e834c5f8e2f3add402e0e8ae6e78b66d807992da1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf1cb87f60b179ad143c68fd0b36662854baffcb73dfe403ecc5e335c4d8b85a082f336b8d40cc5f0b8a376739fc493ee0b15e9af76c6e84cd6f7d93f7017c55
|
7
|
+
data.tar.gz: f48ec28c83e7e62d5630927e11388ee6ac52147963f6c53a5386f06bf1cc1bb849f819eff13d8303770b0fe113863e6c74528ce8a693202523d32489d2b55b89
|
data/lib/hexsafe/api.rb
CHANGED
@@ -1,116 +1,112 @@
|
|
1
1
|
module Hexsafe
|
2
2
|
class Api
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
response = rest_api("GET", "deposit/#{request_id}", {})
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_withdraw body
|
45
|
-
response = rest_api("post", "withdraw", body)
|
46
|
-
end
|
47
|
-
|
48
|
-
def cancel_withdraw request_id
|
49
|
-
response = rest_api("DELETE", "withdraw/#{request_id}", {})
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_withdraw request_id
|
53
|
-
response = rest_api("GET", "withdraw/#{request_id}", {})
|
54
|
-
end
|
55
|
-
|
56
|
-
def subscribe_webhook
|
57
|
-
response = rest_api("post", "webhook", body)
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_subscriptions account_id
|
61
|
-
response = rest_api("GET", "webhook/#{account_id}", {})
|
62
|
-
end
|
63
|
-
|
64
|
-
def delete_subscription uuid
|
65
|
-
response = rest_api("DELETE", "webhook/#{uuid}", {})
|
66
|
-
end
|
67
|
-
|
68
|
-
protected
|
69
|
-
|
70
|
-
def rest_api(verb, path, body = nil)
|
71
|
-
verb = verb.upcase
|
72
|
-
body_digest = nil
|
73
|
-
puts "\n\n\n#{new_timestamp}\n\n"
|
74
|
-
timestamp = new_timestamp.to_s + "0000"
|
75
|
-
request_line = verb + ' ' + base_url+path + ' HTTP/1.1'
|
76
|
-
if body
|
77
|
-
if non_get_verb? verb
|
78
|
-
body_digest = Base64.strict_encode64(digest(JSON.generate(body)))
|
79
|
-
end
|
3
|
+
class Error < RuntimeError; end
|
4
|
+
|
5
|
+
def initialize options = {}
|
6
|
+
@mode = options[:env].upcase rescue nil
|
7
|
+
@key = options[:key] rescue nil
|
8
|
+
@secret = options[:secret] rescue nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_accounts
|
12
|
+
response = rest_api("GET", "account", {})
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_account account_id
|
16
|
+
response = rest_api("GET", "account/#{account_id}", {})
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_balance account_id
|
20
|
+
response = rest_api("GET", "balance/#{account_id}", {})
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_txn ticker, tx_hash
|
24
|
+
response = rest_api("GET", "transaction/asset_ticker/#{ticker.upcase}/hash/#{tx_hash}", {})
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_txn_ac account_id, start_time, end_time
|
28
|
+
response = rest_api("GET", "transaction/account_id/#{account_id}/start_time/#{start_time}/end_time/#{end_time}", {})
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_deposit body
|
32
|
+
response = rest_api("post", "deposit", body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def cancel_deposit request_id
|
36
|
+
response = rest_api("DELETE", "deposit/#{request_id}", {})
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_deposit request_id
|
40
|
+
response = rest_api("GET", "deposit/#{request_id}", {})
|
80
41
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
42
|
+
|
43
|
+
def create_withdraw body
|
44
|
+
response = rest_api("post", "withdraw", body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def cancel_withdraw request_id
|
48
|
+
response = rest_api("DELETE", "withdraw/#{request_id}", {})
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_withdraw request_id
|
52
|
+
response = rest_api("GET", "withdraw/#{request_id}", {})
|
53
|
+
end
|
54
|
+
|
55
|
+
def subscribe_webhook
|
56
|
+
response = rest_api("post", "webhook", body)
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_subscriptions account_id
|
60
|
+
response = rest_api("GET", "webhook/#{account_id}", {})
|
61
|
+
end
|
62
|
+
|
63
|
+
def delete_subscription uuid
|
64
|
+
response = rest_api("DELETE", "webhook/#{uuid}", {})
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def rest_api(verb, path, body = nil)
|
70
|
+
verb = verb.upcase
|
71
|
+
body_digest = nil
|
72
|
+
timestamp = new_timestamp.to_s + "0000"
|
73
|
+
request_line = verb + ' ' + base_url+path + ' HTTP/1.1'
|
74
|
+
if body
|
75
|
+
if non_get_verb? verb
|
76
|
+
body_digest = Base64.strict_encode64(digest(JSON.generate(body)))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
signature = encode_hmac_512(timestamp, host, request_line, body_digest)
|
80
|
+
url = host+base_url+path
|
81
|
+
|
82
|
+
if ['POST', 'PUT', 'PATCH', 'DELETE'].include?(verb)
|
83
|
+
authorization = "hmac username=\"" + key + "\", algorithm=\"hmac-sha512\", headers=\"nonce host digest request-line\", signature=\"" + signature + "\""
|
84
|
+
else
|
85
|
+
authorization = "hmac username=\"" + key + "\", algorithm=\"hmac-sha512\", headers=\"nonce host request-line\", signature=\"" + signature + "\"";
|
96
86
|
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
87
|
+
if is_get? verb
|
88
|
+
response = Faraday.get(url) do |req|
|
89
|
+
req.headers['nonce'] = timestamp.to_s
|
90
|
+
req.headers['authorization'] = authorization
|
91
|
+
req.headers['Date'] = http_format_date
|
92
|
+
req.headers['Content-Type'] = 'application/json'
|
93
|
+
req.headers['Accept'] = 'application/json'
|
94
|
+
end
|
95
|
+
elsif non_get_verb? verb
|
96
|
+
response = Faraday.post(url) do |req|
|
97
|
+
req.body = body.compact.to_json
|
98
|
+
req.headers['nonce'] = timestamp.to_s
|
99
|
+
req.headers['digest'] = "SHA-256="+body_digest
|
100
|
+
req.headers['authorization'] = authorization
|
101
|
+
req.headers['Date'] = http_format_date
|
102
|
+
req.headers['Content-Type'] = 'application/json'
|
103
|
+
end
|
105
104
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
private
|
113
|
-
|
105
|
+
JSON.parse(response.body)
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
114
110
|
def base_url
|
115
111
|
return "/hexsafe/api/v4/"
|
116
112
|
end
|
@@ -121,10 +117,12 @@ module Hexsafe
|
|
121
117
|
end
|
122
118
|
|
123
119
|
def key
|
120
|
+
return "Empty key" if @key.nil?
|
124
121
|
@key ||= @key
|
125
122
|
end
|
126
123
|
|
127
124
|
def secret
|
125
|
+
return "Empty secret" if @secret.nil?
|
128
126
|
@secret ||= @secret
|
129
127
|
end
|
130
128
|
|
@@ -133,7 +131,7 @@ module Hexsafe
|
|
133
131
|
sha256.digest(data.encode('utf-8'))
|
134
132
|
end
|
135
133
|
|
136
|
-
def hmac_512
|
134
|
+
def hmac_512(secret, data)
|
137
135
|
OpenSSL::HMAC.digest('sha512',secret, data)
|
138
136
|
end
|
139
137
|
|
@@ -163,5 +161,5 @@ module Hexsafe
|
|
163
161
|
def non_get_verb? verb
|
164
162
|
return ['POST', 'PUT', 'PATCH', 'DELETE'].include?(verb)
|
165
163
|
end
|
166
|
-
end
|
164
|
+
end
|
167
165
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexsafe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- imrahulprajapat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.6'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: rake
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|