ton_sdk_client 1.7.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 +7 -0
- data/CHANGELOG.md +46 -0
- data/LICENSE +201 -0
- data/README.md +235 -0
- data/lib/ton_sdk_client.rb +6 -0
- data/lib/ton_sdk_client/abi.rb +956 -0
- data/lib/ton_sdk_client/boc.rb +344 -0
- data/lib/ton_sdk_client/client.rb +208 -0
- data/lib/ton_sdk_client/client_context.rb +51 -0
- data/lib/ton_sdk_client/config.rb +108 -0
- data/lib/ton_sdk_client/crypto.rb +1325 -0
- data/lib/ton_sdk_client/debot.rb +466 -0
- data/lib/ton_sdk_client/helper.rb +20 -0
- data/lib/ton_sdk_client/interop.rb +230 -0
- data/lib/ton_sdk_client/net.rb +452 -0
- data/lib/ton_sdk_client/processing.rb +257 -0
- data/lib/ton_sdk_client/tvm.rb +264 -0
- data/lib/ton_sdk_client/types.rb +44 -0
- data/lib/ton_sdk_client/utils.rb +76 -0
- data/lib/ton_sdk_client/version.rb +5 -0
- metadata +134 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'json'
|
2
|
+
require_relative './interop.rb'
|
3
|
+
require_relative './types.rb'
|
4
|
+
require_relative './helper.rb'
|
5
|
+
|
6
|
+
require_relative './config.rb'
|
7
|
+
require_relative './client.rb'
|
8
|
+
require_relative './utils.rb'
|
9
|
+
require_relative './crypto.rb'
|
10
|
+
require_relative './abi.rb'
|
11
|
+
require_relative './boc.rb'
|
12
|
+
require_relative './net.rb'
|
13
|
+
require_relative './tvm.rb'
|
14
|
+
require_relative './processing.rb'
|
15
|
+
require_relative './debot.rb'
|
16
|
+
|
17
|
+
module TonSdk
|
18
|
+
class ClientContext
|
19
|
+
attr_reader :context
|
20
|
+
|
21
|
+
def initialize(cfg_json)
|
22
|
+
cfg_json_tc_str = Interop::TcStringData::from_string(cfg_json)
|
23
|
+
ptr = Interop::tc_create_context(cfg_json_tc_str)
|
24
|
+
ctx_tc_str = Interop::tc_read_string(ptr)
|
25
|
+
if (ctx_tc_str != nil) && (ctx_tc_str[:len] > 0)
|
26
|
+
cont_str = ctx_tc_str[:content].read_string(ctx_tc_str[:len])
|
27
|
+
ctx_json = JSON.parse(cont_str)
|
28
|
+
ctx_val = ctx_json["result"]
|
29
|
+
if ctx_val != nil
|
30
|
+
@context = ctx_val
|
31
|
+
@requests = Concurrent::Hash.new()
|
32
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(@context))
|
33
|
+
else
|
34
|
+
raise SdkError.new(message: "unable to create context: #{ctx_json}")
|
35
|
+
end
|
36
|
+
|
37
|
+
Interop::tc_destroy_string(ptr)
|
38
|
+
else
|
39
|
+
raise SdkError.new("unable to create context")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.finalize(ctx)
|
44
|
+
Proc.new do
|
45
|
+
if (ctx != nil) && (ctx > 0)
|
46
|
+
Interop::tc_destroy_context(ctx)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module TonSdk
|
2
|
+
class ClientConfig
|
3
|
+
attr_reader :network, :crypto, :abi
|
4
|
+
|
5
|
+
def initialize(network: nil, crypto: nil, abi: nil)
|
6
|
+
if network.nil? && crypto.nil? && abi.nil?
|
7
|
+
raise ArgumentError.new("all 3 arguments may not be nil")
|
8
|
+
end
|
9
|
+
|
10
|
+
@network = network
|
11
|
+
@crypto = crypto
|
12
|
+
@abi = abi
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
{
|
17
|
+
network: @network.nil? ? nil : @network.to_h,
|
18
|
+
crypto: @crypto.nil? ? nil : @crypto.to_h,
|
19
|
+
abi: @abi.nil? ? nil : @abi.to_h
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class NetworkConfig
|
25
|
+
DEFAULT_RETRIES_COUNT = 5
|
26
|
+
DEFAULT_PROCESSING_TIMEOUT = 40000
|
27
|
+
DEFAULT_WAIT_TIMEOUT = 40000
|
28
|
+
DEFAULT_OUT_OF_SYNC_THRESHOLD = 15000
|
29
|
+
DEFAULT_NETWORK_RETRIES_COUNT = 5
|
30
|
+
DEFAULT_MAX_RECONNECT_TIMEOUT = 2
|
31
|
+
|
32
|
+
attr_reader :server_address, :endpoints, :network_retries_count,
|
33
|
+
:message_retries_count, :message_processing_timeout,
|
34
|
+
:wait_for_timeout, :out_of_sync_threshold, :reconnect_timeout,
|
35
|
+
:access_key, :max_reconnect_timeout
|
36
|
+
|
37
|
+
def initialize(
|
38
|
+
server_address: "",
|
39
|
+
endpoints: [],
|
40
|
+
network_retries_count: DEFAULT_NETWORK_RETRIES_COUNT,
|
41
|
+
message_retries_count: DEFAULT_RETRIES_COUNT,
|
42
|
+
message_processing_timeout: DEFAULT_PROCESSING_TIMEOUT,
|
43
|
+
wait_for_timeout: DEFAULT_WAIT_TIMEOUT,
|
44
|
+
out_of_sync_threshold: DEFAULT_OUT_OF_SYNC_THRESHOLD,
|
45
|
+
reconnect_timeout: 0,
|
46
|
+
access_key: nil,
|
47
|
+
max_reconnect_timeout: DEFAULT_MAX_RECONNECT_TIMEOUT
|
48
|
+
)
|
49
|
+
@server_address = server_address
|
50
|
+
@endpoints = endpoints
|
51
|
+
@network_retries_count = network_retries_count
|
52
|
+
@message_retries_count = message_retries_count
|
53
|
+
@message_processing_timeout = message_processing_timeout
|
54
|
+
@wait_for_timeout = wait_for_timeout
|
55
|
+
@out_of_sync_threshold = out_of_sync_threshold
|
56
|
+
@reconnect_timeout = reconnect_timeout
|
57
|
+
@access_key = access_key
|
58
|
+
@max_reconnect_timeout = max_reconnect_timeout
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_h
|
62
|
+
{
|
63
|
+
server_address: @server_address,
|
64
|
+
endpoints: @endpoints,
|
65
|
+
network_retries_count: @network_retries_count,
|
66
|
+
message_retries_count: @message_retries_count,
|
67
|
+
message_processing_timeout: @message_processing_timeout,
|
68
|
+
wait_for_timeout: @wait_for_timeout,
|
69
|
+
out_of_sync_threshold: @out_of_sync_threshold,
|
70
|
+
reconnect_timeout: @reconnect_timeout,
|
71
|
+
access_key: @access_key,
|
72
|
+
max_reconnect_timeout: @max_reconnect_timeout
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class CryptoConfig
|
78
|
+
attr_reader :fish_param
|
79
|
+
|
80
|
+
def initialize(a)
|
81
|
+
@fish_param = a
|
82
|
+
end
|
83
|
+
|
84
|
+
def to_h = { fish_param: @fish_param }
|
85
|
+
end
|
86
|
+
|
87
|
+
class AbiConfig
|
88
|
+
DEFAULT_EXPIRATION_TIMEOUT = 40000
|
89
|
+
DEFAULT_TIMEOUT_GROW_FACTOR = 1.5
|
90
|
+
|
91
|
+
attr_reader :message_expiration_timeout, :message_expiration_timeout_grow_factor
|
92
|
+
|
93
|
+
def initialize(
|
94
|
+
message_expiration_timeout: DEFAULT_EXPIRATION_TIMEOUT,
|
95
|
+
message_expiration_timeout_grow_factor: DEFAULT_TIMEOUT_GROW_FACTOR
|
96
|
+
)
|
97
|
+
@message_expiration_timeout = message_expiration_timeout
|
98
|
+
@message_expiration_timeout_grow_factor = message_expiration_timeout_grow_factor
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_h
|
102
|
+
{
|
103
|
+
message_expiration_timeout: @message_expiration_timeout,
|
104
|
+
message_expiration_timeout_grow_factor: @message_expiration_timeout_grow_factor
|
105
|
+
}
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,1325 @@
|
|
1
|
+
module TonSdk
|
2
|
+
module Crypto
|
3
|
+
|
4
|
+
#
|
5
|
+
# types
|
6
|
+
#
|
7
|
+
module ErrorCode
|
8
|
+
INVALID_PUBLICKEY = 100
|
9
|
+
INVALID_SECRETKEY = 101
|
10
|
+
INVALID_KEY = 102
|
11
|
+
INVALID_FACTORIZE_CHALLENGE = 106
|
12
|
+
INVALID_BIGINT = 107
|
13
|
+
SCRYPT_FAILED = 108,
|
14
|
+
INVALID_KEYSIZE = 109
|
15
|
+
NACL_SECRET_BOX_FAILED = 110,
|
16
|
+
NACL_BOX_FAILED = 111,
|
17
|
+
NACL_SIGN_FAILED = 112,
|
18
|
+
BIP39_INVALID_ENTROPY = 113
|
19
|
+
BIP39_INVALID_PHRASE = 114
|
20
|
+
BIP32_INVALID_KEY = 115
|
21
|
+
BIP32_INVALID_DERIVEPATH = 116
|
22
|
+
BIP39_INVALID_DICTIONARY = 117
|
23
|
+
BIP39_INVALID_WORDCOUNT = 118
|
24
|
+
MNEMONIC_GENERATION_FAILED = 119
|
25
|
+
MNEMONICFROMENTROPY_FAILED = 120
|
26
|
+
SIGNING_BOX_NOT_REGISTERED = 121
|
27
|
+
INVALID_SIGNATURE = 122
|
28
|
+
end
|
29
|
+
|
30
|
+
class ParamsOfFactorize
|
31
|
+
attr_reader :composite
|
32
|
+
|
33
|
+
def initialize(a)
|
34
|
+
@composite = a
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_h = { composite: @composite }
|
38
|
+
end
|
39
|
+
|
40
|
+
class ResultOfFactorize
|
41
|
+
attr_reader :factors
|
42
|
+
|
43
|
+
def initialize(a)
|
44
|
+
@factors = a
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class ParamsOfModularPower
|
49
|
+
attr_reader :base, :exponent, :modulus
|
50
|
+
|
51
|
+
def initialize(base:, exponent:, modulus:)
|
52
|
+
@base = base
|
53
|
+
@exponent = exponent
|
54
|
+
@modulus = modulus
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_h
|
58
|
+
{
|
59
|
+
base: @base,
|
60
|
+
exponent: @exponent,
|
61
|
+
modulus: @modulus
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class ResultOfModularPower
|
67
|
+
attr_reader :modular_power
|
68
|
+
|
69
|
+
def initialize(a)
|
70
|
+
@modular_power = a
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class ParamsOfTonCrc16
|
75
|
+
attr_reader :data
|
76
|
+
|
77
|
+
def initialize(a)
|
78
|
+
@data = a
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_h = { data: @data }
|
82
|
+
end
|
83
|
+
|
84
|
+
class ResultOfTonCrc16
|
85
|
+
attr_reader :crc
|
86
|
+
|
87
|
+
def initialize(a)
|
88
|
+
@crc = a
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class ParamsOfGenerateRandomBytes
|
93
|
+
attr_reader :length
|
94
|
+
|
95
|
+
def initialize(a)
|
96
|
+
@length = a
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_h
|
100
|
+
{
|
101
|
+
length: @length
|
102
|
+
}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class ResultOfGenerateRandomBytes
|
107
|
+
attr_reader :bytes
|
108
|
+
|
109
|
+
def initialize(a)
|
110
|
+
@bytes = a
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class ParamsOfConvertPublicKeyToTonSafeFormat
|
115
|
+
attr_reader :public_key
|
116
|
+
|
117
|
+
def initialize(a)
|
118
|
+
@public_key = a
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_h
|
122
|
+
{
|
123
|
+
public_key: @public_key
|
124
|
+
}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class ResultOfConvertPublicKeyToTonSafeFormat
|
129
|
+
attr_reader :ton_public_key
|
130
|
+
|
131
|
+
def initialize(a)
|
132
|
+
@ton_public_key = a
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class KeyPair
|
137
|
+
attr_reader :public_, :secret
|
138
|
+
|
139
|
+
def initialize(public_: , secret:)
|
140
|
+
@public_ = public_
|
141
|
+
@secret = secret
|
142
|
+
end
|
143
|
+
|
144
|
+
def to_h
|
145
|
+
{
|
146
|
+
public: @public_,
|
147
|
+
secret: @secret
|
148
|
+
}
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class ParamsOfSign
|
153
|
+
attr_reader :unsigned, :keys
|
154
|
+
|
155
|
+
def initialize(unsigned:, keys:)
|
156
|
+
@unsigned = unsigned
|
157
|
+
@keys = keys
|
158
|
+
end
|
159
|
+
|
160
|
+
def to_h
|
161
|
+
{
|
162
|
+
unsigned: @unsigned,
|
163
|
+
keys: @keys.to_h
|
164
|
+
}
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class ResultOfSign
|
169
|
+
attr_reader :signed, :signature
|
170
|
+
|
171
|
+
def initialize(signed:, signature:)
|
172
|
+
@signed = signed
|
173
|
+
@signature = signature
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
class ParamsOfVerifySignature
|
178
|
+
attr_reader :signed, :public_
|
179
|
+
|
180
|
+
def initialize(signed:, public_:)
|
181
|
+
@signed = signed
|
182
|
+
@public_ = public_
|
183
|
+
end
|
184
|
+
|
185
|
+
def to_h
|
186
|
+
{
|
187
|
+
signed: @signed,
|
188
|
+
public: @public_
|
189
|
+
}
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
class ResultOfVerifySignature
|
194
|
+
attr_reader :unsigned
|
195
|
+
|
196
|
+
def initialize(a)
|
197
|
+
@unsigned = a
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class ParamsOfHash
|
202
|
+
attr_reader :data
|
203
|
+
|
204
|
+
def initialize(a)
|
205
|
+
@data = a
|
206
|
+
end
|
207
|
+
|
208
|
+
def to_h
|
209
|
+
{
|
210
|
+
data: @data
|
211
|
+
}
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
class ResultOfHash
|
216
|
+
attr_reader :hash
|
217
|
+
|
218
|
+
def initialize(a)
|
219
|
+
@hash = a
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
class ParamsOfScrypt
|
224
|
+
attr_reader :password, :salt, :log_n, :r, :p_, :dk_len
|
225
|
+
|
226
|
+
def initialize(password:, salt:, log_n:, r:, p_:, dk_len:)
|
227
|
+
@password = password
|
228
|
+
@salt = salt
|
229
|
+
@log_n = log_n
|
230
|
+
@r = r
|
231
|
+
@p_ = p_
|
232
|
+
@dk_len = dk_len
|
233
|
+
end
|
234
|
+
|
235
|
+
def to_h
|
236
|
+
{
|
237
|
+
password: @password,
|
238
|
+
salt: @salt,
|
239
|
+
log_n: @log_n,
|
240
|
+
r: @r,
|
241
|
+
p: @p_,
|
242
|
+
dk_len: @dk_len
|
243
|
+
}
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
class ResultOfScrypt
|
248
|
+
attr_reader :key
|
249
|
+
|
250
|
+
def initialize(a)
|
251
|
+
@key = a
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
class ParamsOfNaclSignKeyPairFromSecret
|
256
|
+
attr_reader :secret
|
257
|
+
|
258
|
+
def initialize(a)
|
259
|
+
@secret = a
|
260
|
+
end
|
261
|
+
|
262
|
+
def to_h = { secret: @secret }
|
263
|
+
end
|
264
|
+
|
265
|
+
class ParamsOfNaclSign
|
266
|
+
attr_reader :unsigned, :secret
|
267
|
+
|
268
|
+
def initialize(unsigned:, secret:)
|
269
|
+
@unsigned = unsigned
|
270
|
+
@secret = secret
|
271
|
+
end
|
272
|
+
|
273
|
+
def to_h
|
274
|
+
{
|
275
|
+
unsigned: @unsigned,
|
276
|
+
secret: @secret
|
277
|
+
}
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
class ResultOfNaclSign
|
282
|
+
attr_reader :signed
|
283
|
+
|
284
|
+
def initialize(a)
|
285
|
+
@signed = a
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
class ParamsOfNaclSignOpen
|
290
|
+
attr_reader :signed, :public_
|
291
|
+
|
292
|
+
def initialize(signed:, public_:)
|
293
|
+
@signed = signed
|
294
|
+
@public_ = public_
|
295
|
+
end
|
296
|
+
|
297
|
+
def to_h
|
298
|
+
{
|
299
|
+
signed: @signed,
|
300
|
+
public: @public_
|
301
|
+
}
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
class ResultOfNaclSignOpen
|
306
|
+
attr_reader :unsigned
|
307
|
+
|
308
|
+
def initialize(a)
|
309
|
+
@unsigned = a
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
class ResultOfNaclSignDetached
|
314
|
+
attr_reader :signature
|
315
|
+
|
316
|
+
def initialize(a)
|
317
|
+
@signature = a
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
class ParamsOfNaclBoxKeyPairFromSecret
|
322
|
+
attr_reader :secret
|
323
|
+
|
324
|
+
def initialize(a)
|
325
|
+
@secret = a
|
326
|
+
end
|
327
|
+
|
328
|
+
def to_h
|
329
|
+
{
|
330
|
+
secret: @secret
|
331
|
+
}
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
class ParamsOfNaclBox
|
336
|
+
attr_reader :decrypted, :nonce, :their_public, :secret
|
337
|
+
|
338
|
+
def initialize(decrypted:, nonce:, their_public:, secret:)
|
339
|
+
@decrypted = decrypted
|
340
|
+
@nonce = nonce
|
341
|
+
@their_public = their_public
|
342
|
+
@secret = secret
|
343
|
+
end
|
344
|
+
|
345
|
+
def to_h
|
346
|
+
{
|
347
|
+
decrypted: @decrypted,
|
348
|
+
nonce: @nonce,
|
349
|
+
their_public: @their_public,
|
350
|
+
secret: @secret
|
351
|
+
}
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
class ResultOfNaclBox
|
356
|
+
attr_reader :encrypted
|
357
|
+
|
358
|
+
def initialize(a)
|
359
|
+
@encrypted = a
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
class ParamsOfNaclBoxOpen
|
364
|
+
attr_reader :encrypted, :nonce, :their_public, :secret
|
365
|
+
|
366
|
+
def initialize(encrypted:, nonce:, their_public:, secret:)
|
367
|
+
@encrypted = encrypted
|
368
|
+
@nonce = nonce
|
369
|
+
@their_public = their_public
|
370
|
+
@secret = secret
|
371
|
+
end
|
372
|
+
|
373
|
+
def to_h
|
374
|
+
{
|
375
|
+
encrypted: @encrypted,
|
376
|
+
nonce: @nonce,
|
377
|
+
their_public: @their_public,
|
378
|
+
secret: @secret
|
379
|
+
}
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
class ResultOfNaclBoxOpen
|
384
|
+
attr_reader :decrypted
|
385
|
+
|
386
|
+
def initialize(a)
|
387
|
+
@decrypted = a
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
class ParamsOfNaclSecretBox
|
392
|
+
attr_reader :decrypted, :nonce, :key
|
393
|
+
|
394
|
+
def initialize(decrypted:, nonce:, key:)
|
395
|
+
@decrypted = decrypted
|
396
|
+
@nonce = nonce
|
397
|
+
@key = key
|
398
|
+
end
|
399
|
+
|
400
|
+
def to_h
|
401
|
+
{
|
402
|
+
decrypted: @decrypted,
|
403
|
+
nonce: @nonce,
|
404
|
+
key: @key
|
405
|
+
}
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
class ParamsOfNaclSecretBoxOpen
|
410
|
+
attr_reader :encrypted, :nonce, :key
|
411
|
+
|
412
|
+
def initialize(encrypted:, nonce:, key:)
|
413
|
+
@encrypted = encrypted
|
414
|
+
@nonce = nonce
|
415
|
+
@key = key
|
416
|
+
end
|
417
|
+
|
418
|
+
def to_h
|
419
|
+
{
|
420
|
+
encrypted: @encrypted,
|
421
|
+
nonce: @nonce,
|
422
|
+
key: @key
|
423
|
+
}
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
class ParamsOfMnemonicWords
|
428
|
+
attr_reader :dictionary
|
429
|
+
|
430
|
+
def initialize(a: nil)
|
431
|
+
@dictionary = a
|
432
|
+
end
|
433
|
+
|
434
|
+
def to_h
|
435
|
+
{
|
436
|
+
dictionary: @dictionary
|
437
|
+
}
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
class ResultOfMnemonicWords
|
442
|
+
attr_reader :words
|
443
|
+
|
444
|
+
def initialize(a)
|
445
|
+
@words = a
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
class ParamsOfMnemonicFromRandom
|
450
|
+
attr_reader :dictionary, :word_count
|
451
|
+
|
452
|
+
def initialize(dictionary: nil, word_count: nil)
|
453
|
+
@dictionary = dictionary
|
454
|
+
@word_count = word_count
|
455
|
+
end
|
456
|
+
|
457
|
+
def to_h
|
458
|
+
{
|
459
|
+
dictionary: @dictionary,
|
460
|
+
word_count: @word_count
|
461
|
+
}
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
class ResultOfMnemonicFromRandom
|
466
|
+
attr_reader :phrase
|
467
|
+
|
468
|
+
def initialize(a)
|
469
|
+
@phrase = a
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
class ParamsOfMnemonicFromEntropy
|
474
|
+
attr_reader :entropy, :dictionary, :word_count
|
475
|
+
|
476
|
+
def initialize(entropy:, dictionary: nil, word_count: nil)
|
477
|
+
@entropy = entropy
|
478
|
+
@dictionary = dictionary
|
479
|
+
@word_count = word_count
|
480
|
+
end
|
481
|
+
|
482
|
+
def to_h
|
483
|
+
{
|
484
|
+
entropy: @entropy,
|
485
|
+
dictionary: @dictionary,
|
486
|
+
word_count: @word_count
|
487
|
+
}
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
class ResultOfMnemonicFromEntropy
|
492
|
+
attr_reader :phrase
|
493
|
+
|
494
|
+
def initialize(a)
|
495
|
+
@phrase = a
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
class ParamsOfMnemonicVerify
|
500
|
+
attr_reader :phrase, :dictionary, :word_count
|
501
|
+
|
502
|
+
def initialize(phrase:, dictionary: nil, word_count: nil)
|
503
|
+
@phrase = phrase
|
504
|
+
@dictionary = dictionary
|
505
|
+
@word_count = word_count
|
506
|
+
end
|
507
|
+
|
508
|
+
def to_h
|
509
|
+
{
|
510
|
+
phrase: @phrase,
|
511
|
+
dictionary: @dictionary,
|
512
|
+
word_count: @word_count
|
513
|
+
}
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
class ResultOfMnemonicVerify
|
518
|
+
attr_reader :valid
|
519
|
+
|
520
|
+
def initialize(a)
|
521
|
+
@valid = a
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
class ParamsOfMnemonicDeriveSignKeys
|
526
|
+
attr_reader :phrase, :path, :dictionary, :word_count
|
527
|
+
|
528
|
+
def initialize(phrase:, path: nil, dictionary: nil, word_count: nil)
|
529
|
+
@phrase = phrase
|
530
|
+
@path = path
|
531
|
+
@dictionary = dictionary
|
532
|
+
@word_count = word_count
|
533
|
+
end
|
534
|
+
|
535
|
+
def to_h
|
536
|
+
{
|
537
|
+
phrase: @phrase,
|
538
|
+
path: @path,
|
539
|
+
dictionary: @dictionary,
|
540
|
+
word_count: @word_count
|
541
|
+
}
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
class ParamsOfHDKeyXPrvFromMnemonic
|
546
|
+
attr_reader :phrase, :dictionary, :word_count
|
547
|
+
|
548
|
+
def initialize(phrase:, dictionary: nil, word_count: nil)
|
549
|
+
@phrase = phrase
|
550
|
+
@dictionary = dictionary
|
551
|
+
@word_count = word_count
|
552
|
+
end
|
553
|
+
|
554
|
+
def to_h
|
555
|
+
{
|
556
|
+
phrase: @phrase,
|
557
|
+
dictionary: @dictionary,
|
558
|
+
word_count: @word_count
|
559
|
+
}
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
class ResultOfHDKeyXPrvFromMnemonic
|
564
|
+
attr_reader :xprv
|
565
|
+
|
566
|
+
def initialize(a)
|
567
|
+
@xprv = a
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
class ParamsOfHDKeyDeriveFromXPrv
|
572
|
+
attr_reader :xprv, :child_index, :hardened
|
573
|
+
|
574
|
+
def initialize(xprv:, child_index:, hardened:)
|
575
|
+
@xprv = xprv
|
576
|
+
@child_index = child_index
|
577
|
+
@hardened = hardened
|
578
|
+
end
|
579
|
+
|
580
|
+
def to_h
|
581
|
+
{
|
582
|
+
xprv: @xprv,
|
583
|
+
child_index: @child_index,
|
584
|
+
hardened: @hardened
|
585
|
+
}
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
class ResultOfHDKeyDeriveFromXPrv
|
590
|
+
attr_reader :xprv
|
591
|
+
|
592
|
+
def initialize(a)
|
593
|
+
@xprv = a
|
594
|
+
end
|
595
|
+
|
596
|
+
def to_h
|
597
|
+
{
|
598
|
+
xprv: @xprv,
|
599
|
+
path: @path
|
600
|
+
}
|
601
|
+
end
|
602
|
+
end
|
603
|
+
|
604
|
+
class ParamsOfHDKeySecretFromXPrv
|
605
|
+
attr_reader :xprv
|
606
|
+
|
607
|
+
def initialize(a)
|
608
|
+
@xprv = a
|
609
|
+
end
|
610
|
+
|
611
|
+
def to_h
|
612
|
+
{
|
613
|
+
xprv: @xprv
|
614
|
+
}
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
class ResultOfHDKeySecretFromXPrv
|
619
|
+
attr_reader :secret
|
620
|
+
|
621
|
+
def initialize(a)
|
622
|
+
@secret = a
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
626
|
+
class ParamsOfHDKeyPublicFromXPrv
|
627
|
+
attr_reader :xprv
|
628
|
+
|
629
|
+
def initialize(a)
|
630
|
+
@xprv = a
|
631
|
+
end
|
632
|
+
|
633
|
+
def to_h
|
634
|
+
{
|
635
|
+
xprv: @xprv
|
636
|
+
}
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
class ResultOfHDKeyPublicFromXPrv
|
641
|
+
attr_reader :public_
|
642
|
+
|
643
|
+
def initialize(a)
|
644
|
+
@public_ = a
|
645
|
+
end
|
646
|
+
end
|
647
|
+
|
648
|
+
class ParamsOfHDKeyDeriveFromXPrvPath
|
649
|
+
attr_reader :xprv, :path
|
650
|
+
|
651
|
+
def initialize(xprv:, path:)
|
652
|
+
@xprv = xprv
|
653
|
+
@path = path
|
654
|
+
end
|
655
|
+
|
656
|
+
def to_h
|
657
|
+
{
|
658
|
+
xprv: @xprv,
|
659
|
+
path: @path
|
660
|
+
}
|
661
|
+
end
|
662
|
+
end
|
663
|
+
|
664
|
+
class ResultOfHDKeyDeriveFromXPrvPath
|
665
|
+
attr_reader :xprv
|
666
|
+
|
667
|
+
def initialize(a)
|
668
|
+
@xprv = a
|
669
|
+
end
|
670
|
+
end
|
671
|
+
|
672
|
+
class ParamsOfChaCha20
|
673
|
+
attr_reader :data, :key, :nonce
|
674
|
+
|
675
|
+
def initialize(data:, key:, nonce:)
|
676
|
+
@data = data
|
677
|
+
@key = key
|
678
|
+
@nonce = nonce
|
679
|
+
end
|
680
|
+
|
681
|
+
def to_h
|
682
|
+
{
|
683
|
+
data: @data,
|
684
|
+
key: @key,
|
685
|
+
nonce: @nonce
|
686
|
+
}
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
class ResultOfChaCha20
|
691
|
+
attr_reader :data
|
692
|
+
|
693
|
+
def initialize(a)
|
694
|
+
@data = a
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
class ParamsOfSigningBoxSign
|
699
|
+
attr_reader :signing_box, :unsigned
|
700
|
+
|
701
|
+
def initialize(signing_box:, unsigned:)
|
702
|
+
@signing_box = signing_box
|
703
|
+
@unsigned = unsigned
|
704
|
+
end
|
705
|
+
|
706
|
+
def to_h
|
707
|
+
{
|
708
|
+
signing_box: @signing_box,
|
709
|
+
unsigned: @unsigned
|
710
|
+
}
|
711
|
+
end
|
712
|
+
end
|
713
|
+
|
714
|
+
class ResultOfSigningBoxSign
|
715
|
+
attr_reader :signature
|
716
|
+
|
717
|
+
def initialize(a)
|
718
|
+
@signature = a
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
722
|
+
class RegisteredSigningBox
|
723
|
+
attr_reader :handle
|
724
|
+
|
725
|
+
def initialize(a)
|
726
|
+
@handle = a
|
727
|
+
end
|
728
|
+
|
729
|
+
def to_h
|
730
|
+
{
|
731
|
+
handle: @handle
|
732
|
+
}
|
733
|
+
end
|
734
|
+
end
|
735
|
+
|
736
|
+
class ResultOfSigningBoxGetPublicKey
|
737
|
+
attr_reader :pubkey
|
738
|
+
|
739
|
+
def initialize(a)
|
740
|
+
@pubkey = a
|
741
|
+
end
|
742
|
+
|
743
|
+
def to_h = { pubkey: @pubkey }
|
744
|
+
end
|
745
|
+
|
746
|
+
class ParamsOfNaclSignDetachedVerify
|
747
|
+
attr_reader :unsigned, :signature, :public
|
748
|
+
|
749
|
+
def initialize(unsigned:, signature:, public_:)
|
750
|
+
@unsigned, @signature, @public_ = unsigned, signature, public_
|
751
|
+
end
|
752
|
+
|
753
|
+
def to_h
|
754
|
+
{
|
755
|
+
unsigned: @unsigned,
|
756
|
+
signature: @signature,
|
757
|
+
public: @public_
|
758
|
+
}
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
762
|
+
class ResultOfNaclSignDetachedVerify
|
763
|
+
attr_reader :succeeded
|
764
|
+
|
765
|
+
def initialize(a)
|
766
|
+
@succeeded = a
|
767
|
+
end
|
768
|
+
|
769
|
+
def to_h = { succeeded: @succeeded }
|
770
|
+
end
|
771
|
+
|
772
|
+
class ParamsOfAppSigningBox
|
773
|
+
TYPES = [
|
774
|
+
:get_public_key,
|
775
|
+
:sign
|
776
|
+
]
|
777
|
+
|
778
|
+
attr_reader :type_, :unsigned
|
779
|
+
|
780
|
+
def initialize(type_:, unsigned:)
|
781
|
+
unless TYPES.include?(type_)
|
782
|
+
raise ArgumentError.new("type #{type_} is unknown; known types: #{TYPES}")
|
783
|
+
end
|
784
|
+
@type_ = type_
|
785
|
+
@unsigned = unsigned
|
786
|
+
end
|
787
|
+
|
788
|
+
def to_h
|
789
|
+
{
|
790
|
+
type: Helper.sym_to_capitalized_case_str(@type_),
|
791
|
+
unsigned: @unsigned
|
792
|
+
}
|
793
|
+
end
|
794
|
+
end
|
795
|
+
|
796
|
+
|
797
|
+
#
|
798
|
+
# functions
|
799
|
+
#
|
800
|
+
|
801
|
+
def self.factorize(ctx, params)
|
802
|
+
pr_json = params.to_h.to_json
|
803
|
+
Interop::request_to_native_lib(ctx, "crypto.factorize", pr_json) do |resp|
|
804
|
+
if resp.success?
|
805
|
+
yield NativeLibResponsetResult.new(
|
806
|
+
result: ResultOfFactorize.new(resp.result["factors"])
|
807
|
+
)
|
808
|
+
else
|
809
|
+
yield resp
|
810
|
+
end
|
811
|
+
end
|
812
|
+
end
|
813
|
+
|
814
|
+
def self.modular_power(ctx, params)
|
815
|
+
pr_json = params.to_h.to_json
|
816
|
+
Interop::request_to_native_lib(ctx, "crypto.modular_power", pr_json) do |resp|
|
817
|
+
if resp.success?
|
818
|
+
yield NativeLibResponsetResult.new(
|
819
|
+
result: ResultOfModularPower.new(resp.result["modular_power"])
|
820
|
+
)
|
821
|
+
else
|
822
|
+
yield resp
|
823
|
+
end
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
def self.ton_crc16(ctx, params)
|
828
|
+
pr_json = params.to_h.to_json
|
829
|
+
Interop::request_to_native_lib(ctx, "crypto.ton_crc16", pr_json) do |resp|
|
830
|
+
if resp.success?
|
831
|
+
yield NativeLibResponsetResult.new(
|
832
|
+
result: ResultOfTonCrc16.new(resp.result["crc"])
|
833
|
+
)
|
834
|
+
else
|
835
|
+
yield resp
|
836
|
+
end
|
837
|
+
end
|
838
|
+
end
|
839
|
+
|
840
|
+
def self.generate_random_bytes(ctx, params)
|
841
|
+
pr_json = params.to_h.to_json
|
842
|
+
Interop::request_to_native_lib(ctx, "crypto.generate_random_bytes", pr_json) do |resp|
|
843
|
+
if resp.success?
|
844
|
+
yield NativeLibResponsetResult.new(
|
845
|
+
result: ResultOfGenerateRandomBytes.new(resp.result["bytes"])
|
846
|
+
)
|
847
|
+
else
|
848
|
+
yield resp
|
849
|
+
end
|
850
|
+
end
|
851
|
+
end
|
852
|
+
|
853
|
+
def self.convert_public_key_to_ton_safe_format(ctx, params)
|
854
|
+
pr_json = params.to_h.to_json
|
855
|
+
Interop::request_to_native_lib(ctx, "crypto.convert_public_key_to_ton_safe_format", pr_json) do |resp|
|
856
|
+
if resp.success?
|
857
|
+
yield NativeLibResponsetResult.new(
|
858
|
+
result: ResultOfConvertPublicKeyToTonSafeFormat.new(resp.result["ton_public_key"])
|
859
|
+
)
|
860
|
+
else
|
861
|
+
yield resp
|
862
|
+
end
|
863
|
+
end
|
864
|
+
end
|
865
|
+
|
866
|
+
def self.generate_random_sign_keys(ctx, is_single_thread_only: false)
|
867
|
+
Interop::request_to_native_lib(ctx, "crypto.generate_random_sign_keys", nil, is_single_thread_only: is_single_thread_only) do |resp|
|
868
|
+
if resp.success?
|
869
|
+
yield NativeLibResponsetResult.new(
|
870
|
+
result: KeyPair.new(
|
871
|
+
public_: resp.result["public"],
|
872
|
+
secret: resp.result["secret"]
|
873
|
+
)
|
874
|
+
)
|
875
|
+
else
|
876
|
+
yield resp
|
877
|
+
end
|
878
|
+
end
|
879
|
+
end
|
880
|
+
|
881
|
+
def self.sign(ctx, params)
|
882
|
+
pr_json = params.to_h.to_json
|
883
|
+
Interop::request_to_native_lib(ctx, "crypto.sign", pr_json) do |resp|
|
884
|
+
if resp.success?
|
885
|
+
yield NativeLibResponsetResult.new(
|
886
|
+
result: ResultOfSign.new(
|
887
|
+
signed: resp.result["signed"],
|
888
|
+
signature: resp.result["signature"]
|
889
|
+
)
|
890
|
+
)
|
891
|
+
else
|
892
|
+
yield resp
|
893
|
+
end
|
894
|
+
end
|
895
|
+
end
|
896
|
+
|
897
|
+
def self.verify_signature(ctx, params)
|
898
|
+
pr_json = params.to_h.to_json
|
899
|
+
Interop::request_to_native_lib(ctx, "crypto.verify_signature", pr_json) do |resp|
|
900
|
+
if resp.success?
|
901
|
+
yield NativeLibResponsetResult.new(
|
902
|
+
result: ResultOfVerifySignature.new(resp.result["unsigned"])
|
903
|
+
)
|
904
|
+
else
|
905
|
+
yield resp
|
906
|
+
end
|
907
|
+
end
|
908
|
+
end
|
909
|
+
|
910
|
+
def self.sha256(ctx, params)
|
911
|
+
pr_json = params.to_h.to_json
|
912
|
+
Interop::request_to_native_lib(ctx, "crypto.sha256", pr_json) do |resp|
|
913
|
+
if resp.success?
|
914
|
+
yield NativeLibResponsetResult.new(
|
915
|
+
result: ResultOfHash.new(resp.result["hash"])
|
916
|
+
)
|
917
|
+
else
|
918
|
+
yield resp
|
919
|
+
end
|
920
|
+
end
|
921
|
+
end
|
922
|
+
|
923
|
+
def self.sha512(ctx, params)
|
924
|
+
pr_json = params.to_h.to_json
|
925
|
+
Interop::request_to_native_lib(ctx, "crypto.sha512", pr_json) do |resp|
|
926
|
+
if resp.success?
|
927
|
+
yield NativeLibResponsetResult.new(
|
928
|
+
result: ResultOfHash.new(resp.result["hash"])
|
929
|
+
)
|
930
|
+
else
|
931
|
+
yield resp
|
932
|
+
end
|
933
|
+
end
|
934
|
+
end
|
935
|
+
|
936
|
+
def self.scrypt(ctx, params)
|
937
|
+
pr_json = params.to_h.to_json
|
938
|
+
Interop::request_to_native_lib(ctx, "crypto.scrypt", pr_json) do |resp|
|
939
|
+
if resp.success?
|
940
|
+
yield NativeLibResponsetResult.new(
|
941
|
+
result: ResultOfScrypt.new(resp.result["key"])
|
942
|
+
)
|
943
|
+
else
|
944
|
+
yield resp
|
945
|
+
end
|
946
|
+
end
|
947
|
+
end
|
948
|
+
|
949
|
+
def self.nacl_sign_keypair_from_secret_key(ctx, params)
|
950
|
+
pr_json = params.to_h.to_json
|
951
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_sign_keypair_from_secret_key", pr_json) do |resp|
|
952
|
+
if resp.success?
|
953
|
+
yield NativeLibResponsetResult.new(
|
954
|
+
result: KeyPair.new(public_: resp.result["public"], secret: resp.result["secret"])
|
955
|
+
)
|
956
|
+
else
|
957
|
+
yield resp
|
958
|
+
end
|
959
|
+
end
|
960
|
+
end
|
961
|
+
|
962
|
+
def self.nacl_sign(ctx, params)
|
963
|
+
pr_json = params.to_h.to_json
|
964
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_sign", pr_json) do |resp|
|
965
|
+
if resp.success?
|
966
|
+
yield NativeLibResponsetResult.new(
|
967
|
+
result: ResultOfNaclSign.new(resp.result["signed"])
|
968
|
+
)
|
969
|
+
else
|
970
|
+
yield resp
|
971
|
+
end
|
972
|
+
end
|
973
|
+
end
|
974
|
+
|
975
|
+
def self.nacl_sign_open(ctx, params)
|
976
|
+
pr_json = params.to_h.to_json
|
977
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_sign_open", pr_json) do |resp|
|
978
|
+
if resp.success?
|
979
|
+
yield NativeLibResponsetResult.new(
|
980
|
+
result: ResultOfNaclSignOpen.new(resp.result["unsigned"])
|
981
|
+
)
|
982
|
+
else
|
983
|
+
yield resp
|
984
|
+
end
|
985
|
+
end
|
986
|
+
end
|
987
|
+
|
988
|
+
def self.nacl_sign_detached(ctx, params)
|
989
|
+
pr_json = params.to_h.to_json
|
990
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_sign_detached", pr_json) do |resp|
|
991
|
+
if resp.success?
|
992
|
+
yield NativeLibResponsetResult.new(
|
993
|
+
result: ResultOfNaclSignDetached.new(resp.result["signature"])
|
994
|
+
)
|
995
|
+
else
|
996
|
+
yield resp
|
997
|
+
end
|
998
|
+
end
|
999
|
+
end
|
1000
|
+
|
1001
|
+
def self.nacl_box_keypair(ctx)
|
1002
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_box_keypair", "") do |resp|
|
1003
|
+
if resp.success?
|
1004
|
+
yield NativeLibResponsetResult.new(
|
1005
|
+
result: KeyPair.new(public_: resp.result["public"], secret: resp.result["secret"])
|
1006
|
+
)
|
1007
|
+
else
|
1008
|
+
yield resp
|
1009
|
+
end
|
1010
|
+
end
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
def self.nacl_box_keypair_from_secret_key(ctx, params)
|
1014
|
+
pr_json = params.to_h.to_json
|
1015
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_box_keypair_from_secret_key", pr_json) do |resp|
|
1016
|
+
if resp.success?
|
1017
|
+
yield NativeLibResponsetResult.new(
|
1018
|
+
result: KeyPair.new(public_: resp.result["public"], secret: resp.result["secret"])
|
1019
|
+
)
|
1020
|
+
else
|
1021
|
+
yield resp
|
1022
|
+
end
|
1023
|
+
end
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
def self.nacl_box(ctx, params)
|
1027
|
+
pr_json = params.to_h.to_json
|
1028
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_box", pr_json) do |resp|
|
1029
|
+
if resp.success?
|
1030
|
+
yield NativeLibResponsetResult.new(
|
1031
|
+
result: ResultOfNaclBox.new(resp.result["encrypted"])
|
1032
|
+
)
|
1033
|
+
else
|
1034
|
+
yield resp
|
1035
|
+
end
|
1036
|
+
end
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
def self.nacl_box_open(ctx, params)
|
1040
|
+
pr_json = params.to_h.to_json
|
1041
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_box_open", pr_json) do |resp|
|
1042
|
+
if resp.success?
|
1043
|
+
yield NativeLibResponsetResult.new(
|
1044
|
+
result: ResultOfNaclBoxOpen.new(resp.result["decrypted"])
|
1045
|
+
)
|
1046
|
+
else
|
1047
|
+
yield resp
|
1048
|
+
end
|
1049
|
+
end
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
def self.nacl_secret_box(ctx, params)
|
1053
|
+
pr_json = params.to_h.to_json
|
1054
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_secret_box", pr_json) do |resp|
|
1055
|
+
if resp.success?
|
1056
|
+
yield NativeLibResponsetResult.new(
|
1057
|
+
result: ResultOfNaclBox.new(resp.result["encrypted"])
|
1058
|
+
)
|
1059
|
+
else
|
1060
|
+
yield resp
|
1061
|
+
end
|
1062
|
+
end
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
def self.nacl_secret_box_open(ctx, params)
|
1066
|
+
pr_json = params.to_h.to_json
|
1067
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_secret_box_open", pr_json) do |resp|
|
1068
|
+
if resp.success?
|
1069
|
+
yield NativeLibResponsetResult.new(
|
1070
|
+
result: ResultOfNaclBoxOpen.new(resp.result["decrypted"])
|
1071
|
+
)
|
1072
|
+
else
|
1073
|
+
yield resp
|
1074
|
+
end
|
1075
|
+
end
|
1076
|
+
end
|
1077
|
+
|
1078
|
+
def self.mnemonic_words(ctx, params)
|
1079
|
+
pr_json = params.to_h.to_json
|
1080
|
+
Interop::request_to_native_lib(ctx, "crypto.mnemonic_words", pr_json) do |resp|
|
1081
|
+
if resp.success?
|
1082
|
+
yield NativeLibResponsetResult.new(
|
1083
|
+
result: ResultOfMnemonicWords.new(resp.result["words"])
|
1084
|
+
)
|
1085
|
+
else
|
1086
|
+
yield resp
|
1087
|
+
end
|
1088
|
+
end
|
1089
|
+
end
|
1090
|
+
|
1091
|
+
def self.mnemonic_from_random(ctx, params)
|
1092
|
+
pr_json = params.to_h.to_json
|
1093
|
+
Interop::request_to_native_lib(ctx, "crypto.mnemonic_from_random", pr_json) do |resp|
|
1094
|
+
if resp.success?
|
1095
|
+
yield NativeLibResponsetResult.new(
|
1096
|
+
result: ResultOfMnemonicFromRandom.new(resp.result["phrase"])
|
1097
|
+
)
|
1098
|
+
else
|
1099
|
+
yield resp
|
1100
|
+
end
|
1101
|
+
end
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
def self.mnemonic_from_entropy(ctx, params)
|
1105
|
+
pr_json = params.to_h.to_json
|
1106
|
+
Interop::request_to_native_lib(ctx, "crypto.mnemonic_from_entropy", pr_json) do |resp|
|
1107
|
+
if resp.success?
|
1108
|
+
yield NativeLibResponsetResult.new(
|
1109
|
+
result: ResultOfMnemonicFromEntropy.new(resp.result["phrase"])
|
1110
|
+
)
|
1111
|
+
else
|
1112
|
+
yield resp
|
1113
|
+
end
|
1114
|
+
end
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
def self.mnemonic_verify(ctx, params)
|
1118
|
+
pr_json = params.to_h.to_json
|
1119
|
+
Interop::request_to_native_lib(ctx, "crypto.mnemonic_verify", pr_json) do |resp|
|
1120
|
+
if resp.success?
|
1121
|
+
yield NativeLibResponsetResult.new(
|
1122
|
+
result: ResultOfMnemonicVerify.new(resp.result["valid"])
|
1123
|
+
)
|
1124
|
+
else
|
1125
|
+
yield resp
|
1126
|
+
end
|
1127
|
+
end
|
1128
|
+
end
|
1129
|
+
|
1130
|
+
def self.mnemonic_derive_sign_keys(ctx, params)
|
1131
|
+
pr_json = params.to_h.to_json
|
1132
|
+
Interop::request_to_native_lib(ctx, "crypto.mnemonic_derive_sign_keys", pr_json) do |resp|
|
1133
|
+
if resp.success?
|
1134
|
+
yield NativeLibResponsetResult.new(
|
1135
|
+
result: KeyPair.new(public_: resp.result["public"], secret: resp.result["secret"])
|
1136
|
+
)
|
1137
|
+
else
|
1138
|
+
yield resp
|
1139
|
+
end
|
1140
|
+
end
|
1141
|
+
end
|
1142
|
+
|
1143
|
+
def self.hdkey_xprv_from_mnemonic(ctx, params)
|
1144
|
+
pr_json = params.to_h.to_json
|
1145
|
+
Interop::request_to_native_lib(ctx, "crypto.hdkey_xprv_from_mnemonic", pr_json) do |resp|
|
1146
|
+
if resp.success?
|
1147
|
+
yield NativeLibResponsetResult.new(
|
1148
|
+
result: ResultOfHDKeyXPrvFromMnemonic.new(resp.result["xprv"])
|
1149
|
+
)
|
1150
|
+
else
|
1151
|
+
yield resp
|
1152
|
+
end
|
1153
|
+
end
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
def self.hdkey_derive_from_xprv(ctx, params)
|
1157
|
+
pr_json = params.to_h.to_json
|
1158
|
+
Interop::request_to_native_lib(ctx, "crypto.hdkey_derive_from_xprv", pr_json) do |resp|
|
1159
|
+
if resp.success?
|
1160
|
+
yield NativeLibResponsetResult.new(
|
1161
|
+
result: ResultOfHDKeyDeriveFromXPrv.new(resp.result["xprv"])
|
1162
|
+
)
|
1163
|
+
else
|
1164
|
+
yield resp
|
1165
|
+
end
|
1166
|
+
end
|
1167
|
+
end
|
1168
|
+
|
1169
|
+
def self.hdkey_derive_from_xprv_path(ctx, params)
|
1170
|
+
pr_json = params.to_h.to_json
|
1171
|
+
Interop::request_to_native_lib(ctx, "crypto.hdkey_derive_from_xprv_path", pr_json) do |resp|
|
1172
|
+
if resp.success?
|
1173
|
+
yield NativeLibResponsetResult.new(
|
1174
|
+
result: ResultOfHDKeyDeriveFromXPrvPath.new(resp.result["xprv"])
|
1175
|
+
)
|
1176
|
+
else
|
1177
|
+
yield resp
|
1178
|
+
end
|
1179
|
+
end
|
1180
|
+
end
|
1181
|
+
|
1182
|
+
def self.hdkey_secret_from_xprv(ctx, params)
|
1183
|
+
pr_json = params.to_h.to_json
|
1184
|
+
Interop::request_to_native_lib(ctx, "crypto.hdkey_secret_from_xprv", pr_json) do |resp|
|
1185
|
+
if resp.success?
|
1186
|
+
yield NativeLibResponsetResult.new(
|
1187
|
+
result: ResultOfHDKeySecretFromXPrv.new(resp.result["secret"])
|
1188
|
+
)
|
1189
|
+
else
|
1190
|
+
yield resp
|
1191
|
+
end
|
1192
|
+
end
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
def self.hdkey_public_from_xprv(ctx, params)
|
1196
|
+
pr_json = params.to_h.to_json
|
1197
|
+
Interop::request_to_native_lib(ctx, "crypto.hdkey_public_from_xprv", pr_json) do |resp|
|
1198
|
+
if resp.success?
|
1199
|
+
yield NativeLibResponsetResult.new(
|
1200
|
+
result: ResultOfHDKeyPublicFromXPrv.new(resp.result["public"])
|
1201
|
+
)
|
1202
|
+
else
|
1203
|
+
yield resp
|
1204
|
+
end
|
1205
|
+
end
|
1206
|
+
end
|
1207
|
+
|
1208
|
+
def self.chacha20(ctx, params)
|
1209
|
+
pr_json = params.to_h.to_json
|
1210
|
+
Interop::request_to_native_lib(ctx, "crypto.chacha20", pr_json) do |resp|
|
1211
|
+
if resp.success?
|
1212
|
+
yield NativeLibResponsetResult.new(
|
1213
|
+
result: ResultOfChaCha20.new(resp.result["data"])
|
1214
|
+
)
|
1215
|
+
else
|
1216
|
+
yield resp
|
1217
|
+
end
|
1218
|
+
end
|
1219
|
+
end
|
1220
|
+
|
1221
|
+
def self.register_signing_box(ctx, app_obj:, is_single_thread_only: false)
|
1222
|
+
client_callback = Proc.new do |type_, x|
|
1223
|
+
app_res = app_obj.request(x["request_data"])
|
1224
|
+
app_req_result = case app_res
|
1225
|
+
in [:success, result]
|
1226
|
+
TonSdk::Client::AppRequestResult.new(
|
1227
|
+
type_: :ok,
|
1228
|
+
result: result
|
1229
|
+
)
|
1230
|
+
in [:error, text]
|
1231
|
+
TonSdk::Client::AppRequestResult.new(
|
1232
|
+
type_: :error,
|
1233
|
+
text: text
|
1234
|
+
)
|
1235
|
+
end
|
1236
|
+
|
1237
|
+
params = TonSdk::Client::ParamsOfResolveAppRequest.new(
|
1238
|
+
app_request_id: x["app_request_id"],
|
1239
|
+
result: app_req_result
|
1240
|
+
)
|
1241
|
+
TonSdk::Client.resolve_app_request(ctx, params)
|
1242
|
+
end
|
1243
|
+
|
1244
|
+
Interop::request_to_native_lib(
|
1245
|
+
ctx,
|
1246
|
+
"crypto.register_signing_box",
|
1247
|
+
nil,
|
1248
|
+
is_single_thread_only: is_single_thread_only
|
1249
|
+
) do |resp|
|
1250
|
+
if resp.success?
|
1251
|
+
yield NativeLibResponsetResult.new(
|
1252
|
+
result: RegisteredSigningBox.new(resp.result["handle"])
|
1253
|
+
)
|
1254
|
+
else
|
1255
|
+
yield resp
|
1256
|
+
end
|
1257
|
+
end
|
1258
|
+
end
|
1259
|
+
|
1260
|
+
def self.get_signing_box(ctx, params)
|
1261
|
+
Interop::request_to_native_lib(ctx, "crypto.get_signing_box", params.to_h.to_json) do |resp|
|
1262
|
+
if resp.success?
|
1263
|
+
yield NativeLibResponsetResult.new(
|
1264
|
+
result: RegisteredSigningBox.new(resp.result["handle"])
|
1265
|
+
)
|
1266
|
+
else
|
1267
|
+
yield resp
|
1268
|
+
end
|
1269
|
+
end
|
1270
|
+
end
|
1271
|
+
|
1272
|
+
def self.signing_box_get_public_key(ctx, params, is_single_thread_only: false)
|
1273
|
+
Interop::request_to_native_lib(
|
1274
|
+
ctx,
|
1275
|
+
"crypto.signing_box_get_public_key",
|
1276
|
+
params.to_h.to_json,
|
1277
|
+
is_single_thread_only: is_single_thread_only
|
1278
|
+
) do |resp|
|
1279
|
+
if resp.success?
|
1280
|
+
yield NativeLibResponsetResult.new(
|
1281
|
+
result: ResultOfSigningBoxGetPublicKey.new(resp.result["pubkey"])
|
1282
|
+
)
|
1283
|
+
else
|
1284
|
+
yield resp
|
1285
|
+
end
|
1286
|
+
end
|
1287
|
+
end
|
1288
|
+
|
1289
|
+
def self.signing_box_sign(ctx, params)
|
1290
|
+
Interop::request_to_native_lib(ctx, "crypto.signing_box_sign", params.to_h.to_json) do |resp|
|
1291
|
+
if resp.success?
|
1292
|
+
yield NativeLibResponsetResult.new(
|
1293
|
+
result: ResultOfSigningBoxSign.new(resp.result["signature"])
|
1294
|
+
)
|
1295
|
+
else
|
1296
|
+
yield resp
|
1297
|
+
end
|
1298
|
+
end
|
1299
|
+
end
|
1300
|
+
|
1301
|
+
def self.remove_signing_box(ctx, params)
|
1302
|
+
Interop::request_to_native_lib(ctx, "crypto.remove_signing_box", params.to_h.to_json) do |resp|
|
1303
|
+
if resp.success?
|
1304
|
+
yield NativeLibResponsetResult.new(
|
1305
|
+
result: ResultOfSigningBoxSign.new(resp.result["signature"])
|
1306
|
+
)
|
1307
|
+
else
|
1308
|
+
yield resp
|
1309
|
+
end
|
1310
|
+
end
|
1311
|
+
end
|
1312
|
+
|
1313
|
+
def self.nacl_sign_detached_verify(ctx, params)
|
1314
|
+
Interop::request_to_native_lib(ctx, "crypto.nacl_sign_detached_verify", params.to_h.to_json) do |resp|
|
1315
|
+
if resp.success?
|
1316
|
+
yield NativeLibResponsetResult.new(
|
1317
|
+
result: ResultOfNaclSignDetachedVerify.new(resp.result["succeeded"])
|
1318
|
+
)
|
1319
|
+
else
|
1320
|
+
yield resp
|
1321
|
+
end
|
1322
|
+
end
|
1323
|
+
end
|
1324
|
+
end
|
1325
|
+
end
|