ton_sdk_client 1.26.0 → 1.34.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,24 +5,24 @@ module TonSdk
5
5
  # types
6
6
  #
7
7
  module ErrorCode
8
- INVALID_PUBLICKEY = 100
9
- INVALID_SECRETKEY = 101
8
+ INVALID_PUBLIC_KEY = 100
9
+ INVALID_SECRET_KEY = 101
10
10
  INVALID_KEY = 102
11
11
  INVALID_FACTORIZE_CHALLENGE = 106
12
- INVALID_BIGINT = 107
12
+ INVALID_BIG_INT = 107
13
13
  SCRYPT_FAILED = 108
14
- INVALID_KEYSIZE = 109
14
+ INVALID_KEY_SIZE = 109
15
15
  NACL_SECRET_BOX_FAILED = 110
16
16
  NACL_BOX_FAILED = 111
17
17
  NACL_SIGN_FAILED = 112
18
18
  BIP39_INVALID_ENTROPY = 113
19
19
  BIP39_INVALID_PHRASE = 114
20
20
  BIP32_INVALID_KEY = 115
21
- BIP32_INVALID_DERIVEPATH = 116
21
+ BIP32_INVALID_DERIVE_PATH = 116
22
22
  BIP39_INVALID_DICTIONARY = 117
23
- BIP39_INVALID_WORDCOUNT = 118
23
+ BIP39_INVALID_WORD_COUNT = 118
24
24
  MNEMONIC_GENERATION_FAILED = 119
25
- MNEMONICFROMENTROPY_FAILED = 120
25
+ MNEMONIC_FROM_ENTROPY_FAILED = 120
26
26
  SIGNING_BOX_NOT_REGISTERED = 121
27
27
  INVALID_SIGNATURE = 122
28
28
  ENCRYPTION_BOX_NOT_REGISTERED = 123
@@ -32,6 +32,11 @@ module TonSdk
32
32
  ENCRYPT_DATA_ERROR = 127
33
33
  DECRYPT_DATA_ERROR = 128
34
34
  IV_REQUIRED = 129
35
+ CRYPTO_BOX_NOT_REGISTERED = 130
36
+ INVALID_CRYPTO_BOX_TYPE = 131
37
+ CRYPTO_BOX_SECRET_SERIALIZATION_ERROR = 132
38
+ CRYPTO_BOX_SECRET_DESERIALIZATION_ERROR = 133
39
+ INVALID_NONCE_SIZE = 134
35
40
  end
36
41
 
37
42
  ParamsOfFactorize = KwStruct.new(:composite)
@@ -178,7 +183,9 @@ module TonSdk
178
183
  ParamsOfSigningBoxSign = KwStruct.new(:signing_box, :unsigned)
179
184
 
180
185
  ResultOfSigningBoxSign = KwStruct.new(:signature)
186
+
181
187
  RegisteredSigningBox = KwStruct.new(:handle)
188
+
182
189
  ResultOfSigningBoxGetPublicKey = KwStruct.new(:pubkey)
183
190
 
184
191
  ParamsOfNaclSignDetachedVerify = KwStruct.new(:unsigned, :signature, :public_) do
@@ -194,10 +201,7 @@ module TonSdk
194
201
  ResultOfNaclSignDetachedVerify = KwStruct.new(:succeeded)
195
202
 
196
203
  class ParamsOfAppSigningBox
197
- TYPES = [
198
- :get_public_key,
199
- :sign
200
- ]
204
+ TYPES = [:get_public_key, :sign]
201
205
 
202
206
  attr_reader :type_, :unsigned
203
207
 
@@ -218,11 +222,150 @@ module TonSdk
218
222
  end
219
223
 
220
224
  EncryptionBoxInfo = KwStruct.new(:hdpath, :algorithm, :options, :public)
225
+
221
226
  ParamsOfEncryptionBoxGetInfo = KwStruct.new(:encryption_box)
227
+
222
228
  ResultOfEncryptionBoxGetInfo = KwStruct.new(:info)
229
+
230
+ ParamsOfEncryptionBoxEncrypt = KwStruct.new(:encryption_box, :data)
231
+
223
232
  RegisteredEncryptionBox = KwStruct.new(:handle)
233
+
234
+ ResultOfEncryptionBoxEncrypt = KwStruct.new(:data)
235
+
236
+ ParamsOfEncryptionBoxDecrypt = KwStruct.new(:encryption_box, :data)
237
+
238
+ ResultOfEncryptionBoxDecrypt = KwStruct.new(:data)
239
+
224
240
  ParamsOfCreateEncryptionBox = KwStruct.new(:algorithm)
225
241
 
242
+ class CryptoBoxSecret
243
+ TYPES = %i[random_seed_phrase predefined_seed_phrase encrypted_secret]
244
+ attr_reader :type, :args
245
+
246
+ def initialize(type:, **args)
247
+ unless TYPES.include?(type)
248
+ raise ArgumentError.new("type #{type} is unknown; known types: #{TYPES}")
249
+ end
250
+ @type = type
251
+ @args = args
252
+ end
253
+
254
+ def to_h
255
+ hash = case type
256
+ when :random_seed_phrase
257
+ {
258
+ dictionary: args[:dictionary],
259
+ wordcount: args[:wordcount]
260
+ }
261
+ when :predefined_seed_phrase
262
+ {
263
+ phrase: args[:phrase],
264
+ dictionary: args[:dictionary],
265
+ wordcount: args[:wordcount]
266
+ }
267
+ when :encrypted_secret
268
+ {
269
+ encrypted_secret: args[:encrypted_secret]
270
+ }
271
+ end
272
+ {
273
+ type: Helper.sym_to_capitalized_case_str(type)
274
+ }.merge(hash)
275
+ end
276
+ end
277
+
278
+ class BoxEncryptionAlgorithm
279
+ TYPES = %i[cha_cha20 nacl_box nacl_secret_box]
280
+ attr_reader :type, :args
281
+
282
+ def initialize(type:, **args)
283
+ unless TYPES.include?(type)
284
+ raise ArgumentError.new("type #{type} is unknown; known types: #{TYPES}")
285
+ end
286
+ @type = type
287
+ @args = args
288
+ end
289
+
290
+ def to_h
291
+ hash = case type
292
+ when :cha_cha20
293
+ {
294
+ nonce: args[:nonce]
295
+ }
296
+ when :nacl_box
297
+ {
298
+ their_public: args[:their_public],
299
+ nonce: args[:nonce]
300
+ }
301
+ when :nacl_secret_box
302
+ {
303
+ nonce: args[:nonce]
304
+ }
305
+ end
306
+ {
307
+ type: Helper.sym_to_capitalized_case_str(type)
308
+ }.merge(hash)
309
+ end
310
+ end
311
+
312
+ class ParamsOfAppEncryptionBox
313
+ TYPES = %i[get_info encrypt decrypt]
314
+ attr_reader :type, :args
315
+
316
+ def initialize(type:, **args)
317
+ unless TYPES.include?(type)
318
+ raise ArgumentError.new("type #{type} is unknown; known types: #{TYPES}")
319
+ end
320
+ @type = type
321
+ @args = args
322
+ end
323
+
324
+ def to_h
325
+ hash = case type
326
+ when :get_info
327
+ {}
328
+ when :encrypt, :decrypt
329
+ {
330
+ data: args[:data]
331
+ }
332
+ end
333
+ {
334
+ type: Helper.sym_to_capitalized_case_str(type)
335
+ }.merge(hash)
336
+ end
337
+ end
338
+
339
+ ParamsOfCreateCryptoBox = KwStruct.new(:secret_encryption_salt, :secret)
340
+
341
+ RegisteredCryptoBox = KwStruct.new(:handle)
342
+
343
+ ParamsOfAppPasswordProvider = KwStruct.new(:encryption_public_key) do
344
+ attr_reader :type, :encryption_public_key
345
+
346
+ def initialize(encryption_public_key:)
347
+ @type = "GetPassword"
348
+ @encryption_public_key = encryption_public_key
349
+ end
350
+
351
+ def to_h
352
+ {
353
+ type: type,
354
+ encryption_public_key: encryption_public_key
355
+ }
356
+ end
357
+ end
358
+
359
+ ResultOfAppPasswordProvider = KwStruct.new(:type, :encrypted_password, :app_encryption_pubkey)
360
+
361
+ ResultOfGetCryptoBoxInfo = KwStruct.new(:encrypted_secret)
362
+
363
+ ResultOfGetCryptoBoxSeedPhrase = KwStruct.new(:phrase, :dictionary, :wordcount)
364
+
365
+ ParamsOfGetSigningBoxFromCryptoBox = KwStruct.new(:handle, :hdpath, :secret_lifetime)
366
+
367
+ ParamsOfGetEncryptionBoxFromCryptoBox = KwStruct.new(:handle, :hdpath, :algorithm, :secret_lifetime)
368
+
226
369
  class EncryptionAlgorithm
227
370
  private_class_method :new
228
371
 
@@ -234,8 +377,6 @@ module TonSdk
234
377
  end
235
378
  end
236
379
 
237
-
238
-
239
380
  #
240
381
  # functions
241
382
  #
@@ -654,34 +795,13 @@ module TonSdk
654
795
  end
655
796
  end
656
797
 
657
- def self.register_signing_box(ctx, app_obj:, is_single_thread_only: false)
658
- client_callback = Proc.new do |type_, x|
659
- app_res = app_obj.request(x["request_data"])
660
- app_req_result = case app_res
661
- in [:success, result]
662
- TonSdk::Client::AppRequestResult.new(
663
- type_: :ok,
664
- result: result
665
- )
666
- in [:error, text]
667
- TonSdk::Client::AppRequestResult.new(
668
- type_: :error,
669
- text: text
670
- )
671
- end
672
-
673
- params = TonSdk::Client::ParamsOfResolveAppRequest.new(
674
- app_request_id: x["app_request_id"],
675
- result: app_req_result
676
- )
677
- TonSdk::Client.resolve_app_request(ctx, params)
678
- end
679
-
798
+ def self.register_signing_box(ctx, callback:)
680
799
  Interop::request_to_native_lib(
681
800
  ctx,
682
801
  "crypto.register_signing_box",
683
802
  nil,
684
- is_single_thread_only: is_single_thread_only
803
+ client_callback: callback,
804
+ is_single_thread_only: false
685
805
  ) do |resp|
686
806
  if resp.success?
687
807
  yield NativeLibResponseResult.new(
@@ -746,34 +866,12 @@ module TonSdk
746
866
  end
747
867
  end
748
868
 
749
- def self.register_encryption_box(ctx, app_obj:)
750
- client_callback = Proc.new do |type_, x|
751
- app_res = app_obj.request(x["request_data"])
752
- app_req_result = case app_res
753
- in [:success, result]
754
- TonSdk::Client::AppRequestResult.new(
755
- type_: :ok,
756
- result: result
757
- )
758
- in [:error, text]
759
- TonSdk::Client::AppRequestResult.new(
760
- type_: :error,
761
- text: text
762
- )
763
- end
764
-
765
- params = TonSdk::Client::ParamsOfResolveAppRequest.new(
766
- app_request_id: x["app_request_id"],
767
- result: app_req_result
768
- )
769
- TonSdk::Client.resolve_app_request(ctx, params)
770
- end
771
-
869
+ def self.register_encryption_box(ctx, callback:)
772
870
  Interop::request_to_native_lib(
773
871
  ctx,
774
872
  "crypto.register_encryption_box",
775
873
  nil,
776
- client_callback: client_callback,
874
+ client_callback: callback,
777
875
  is_single_thread_only: false
778
876
  ) do |resp|
779
877
  if resp.success?
@@ -786,6 +884,18 @@ module TonSdk
786
884
  end
787
885
  end
788
886
 
887
+ def self.remove_encryption_box(ctx, params)
888
+ Interop::request_to_native_lib(ctx, "crypto.remove_encryption_box", params) do |resp|
889
+ if resp.success?
890
+ yield NativeLibResponseResult.new(
891
+ result: nil
892
+ )
893
+ else
894
+ yield resp
895
+ end
896
+ end
897
+ end
898
+
789
899
  def self.encryption_box_get_info(ctx, params)
790
900
  Interop::request_to_native_lib(ctx, "crypto.encryption_box_get_info", params) do |resp|
791
901
  if resp.success?
@@ -798,6 +908,30 @@ module TonSdk
798
908
  end
799
909
  end
800
910
 
911
+ def self.encryption_box_encrypt(ctx, params)
912
+ Interop::request_to_native_lib(ctx, "crypto.encryption_box_encrypt", params) do |resp|
913
+ if resp.success?
914
+ yield NativeLibResponseResult.new(
915
+ result: ResultOfEncryptionBoxEncrypt.new(data: resp.result["data"])
916
+ )
917
+ else
918
+ yield resp
919
+ end
920
+ end
921
+ end
922
+
923
+ def self.encryption_box_decrypt(ctx, params)
924
+ Interop::request_to_native_lib(ctx, "crypto.encryption_box_decrypt", params) do |resp|
925
+ if resp.success?
926
+ yield NativeLibResponseResult.new(
927
+ result: ResultOfEncryptionBoxDecrypt.new(data: resp.result["data"])
928
+ )
929
+ else
930
+ yield resp
931
+ end
932
+ end
933
+ end
934
+
801
935
  def self.create_encryption_box(ctx, params)
802
936
  Interop::request_to_native_lib(ctx, "crypto.create_encryption_box", params) do |resp|
803
937
  if resp.success?
@@ -809,5 +943,105 @@ module TonSdk
809
943
  end
810
944
  end
811
945
  end
946
+
947
+ def self.create_crypto_box(ctx, params, callback:)
948
+ Interop::request_to_native_lib(
949
+ ctx,
950
+ "crypto.create_crypto_box",
951
+ params,
952
+ client_callback: callback,
953
+ is_single_thread_only: false
954
+ ) do |resp|
955
+ if resp.success?
956
+ yield NativeLibResponseResult.new(
957
+ result: RegisteredCryptoBox.new(handle: resp.result["handle"])
958
+ )
959
+ else
960
+ yield resp
961
+ end
962
+ end
963
+ end
964
+
965
+ def self.remove_crypto_box(ctx, params)
966
+ Interop::request_to_native_lib(ctx, "crypto.remove_crypto_box", params) do |resp|
967
+ if resp.success?
968
+ yield NativeLibResponseResult.new(
969
+ result: nil
970
+ )
971
+ else
972
+ yield resp
973
+ end
974
+ end
975
+ end
976
+
977
+ def self.get_crypto_box_info(ctx, params)
978
+ Interop::request_to_native_lib(ctx, "crypto.get_crypto_box_info", params) do |resp|
979
+ if resp.success?
980
+ yield NativeLibResponseResult.new(
981
+ result: ResultOfGetCryptoBoxInfo.new(
982
+ encrypted_secret: resp.result["encrypted_secret"]
983
+ )
984
+ )
985
+ else
986
+ yield resp
987
+ end
988
+ end
989
+ end
990
+
991
+ def self.get_crypto_box_seed_phrase(ctx, params)
992
+ Interop::request_to_native_lib(ctx, "crypto.get_crypto_box_seed_phrase", params) do |resp|
993
+ if resp.success?
994
+ yield NativeLibResponseResult.new(
995
+ result: ResultOfGetCryptoBoxSeedPhrase.new(
996
+ phrase: resp.result["phrase"],
997
+ dictionary: resp.result["dictionary"],
998
+ wordcount: resp.result["wordcount"]
999
+ )
1000
+ )
1001
+ else
1002
+ yield resp
1003
+ end
1004
+ end
1005
+ end
1006
+
1007
+ def self.get_signing_box_from_crypto_box(ctx, params)
1008
+ Interop::request_to_native_lib(ctx, "crypto.get_signing_box_from_crypto_box", params) do |resp|
1009
+ if resp.success?
1010
+ yield NativeLibResponseResult.new(
1011
+ result: RegisteredSigningBox.new(handle: resp.result["handle"])
1012
+ )
1013
+ else
1014
+ yield resp
1015
+ end
1016
+ end
1017
+ end
1018
+
1019
+ def self.get_encryption_box_from_crypto_box(ctx, params)
1020
+ Interop::request_to_native_lib(ctx, "crypto.get_encryption_box_from_crypto_box", params) do |resp|
1021
+ if resp.success?
1022
+ yield NativeLibResponseResult.new(
1023
+ result: RegisteredEncryptionBox.new(handle: resp.result["handle"])
1024
+ )
1025
+ else
1026
+ yield resp
1027
+ end
1028
+ end
1029
+ end
1030
+
1031
+ def self.clear_crypto_box_secret_cache(ctx, params)
1032
+ Interop::request_to_native_lib(
1033
+ ctx,
1034
+ "crypto.clear_crypto_box_secret_cache",
1035
+ params
1036
+ ) do |resp|
1037
+ if resp.success?
1038
+ yield NativeLibResponseResult.new(
1039
+ result: nil
1040
+ )
1041
+ else
1042
+ yield resp
1043
+ end
1044
+ end
1045
+ end
812
1046
  end
813
1047
  end