ever_sdk_client 1.36.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.
@@ -0,0 +1,1047 @@
1
+ module EverSdk
2
+ module Crypto
3
+
4
+ #
5
+ # types
6
+ #
7
+ module ErrorCode
8
+ INVALID_PUBLIC_KEY = 100
9
+ INVALID_SECRET_KEY = 101
10
+ INVALID_KEY = 102
11
+ INVALID_FACTORIZE_CHALLENGE = 106
12
+ INVALID_BIG_INT = 107
13
+ SCRYPT_FAILED = 108
14
+ INVALID_KEY_SIZE = 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_DERIVE_PATH = 116
22
+ BIP39_INVALID_DICTIONARY = 117
23
+ BIP39_INVALID_WORD_COUNT = 118
24
+ MNEMONIC_GENERATION_FAILED = 119
25
+ MNEMONIC_FROM_ENTROPY_FAILED = 120
26
+ SIGNING_BOX_NOT_REGISTERED = 121
27
+ INVALID_SIGNATURE = 122
28
+ ENCRYPTION_BOX_NOT_REGISTERED = 123
29
+ INVALID_IV_SIZE = 124
30
+ UNSUPPORTED_CIPHER_MODE = 125
31
+ CANNOT_CREATE_CIPHER = 126
32
+ ENCRYPT_DATA_ERROR = 127
33
+ DECRYPT_DATA_ERROR = 128
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
40
+ end
41
+
42
+ ParamsOfFactorize = KwStruct.new(:composite)
43
+ ResultOfFactorize = KwStruct.new(:factors)
44
+ ParamsOfModularPower = KwStruct.new(:base, :exponent, :modulus)
45
+ ResultOfModularPower = KwStruct.new(:modular_power)
46
+ ParamsOfTonCrc16 = KwStruct.new(:data)
47
+
48
+ ResultOfTonCrc16 = KwStruct.new(:crc)
49
+ ParamsOfGenerateRandomBytes = KwStruct.new(:length)
50
+ ResultOfGenerateRandomBytes = KwStruct.new(:bytes)
51
+ ParamsOfConvertPublicKeyToTonSafeFormat = KwStruct.new(:public_key)
52
+ ResultOfConvertPublicKeyToTonSafeFormat = KwStruct.new(:ton_public_key)
53
+
54
+ KeyPair = KwStruct.new(:public_, :secret) do
55
+ def to_h
56
+ {
57
+ public: public_,
58
+ secret: secret
59
+ }
60
+ end
61
+ end
62
+ ParamsOfSign = KwStruct.new(:unsigned, :keys) do
63
+ def to_h
64
+ {
65
+ unsigned: unsigned,
66
+ keys: keys&.to_h
67
+ }
68
+ end
69
+ end
70
+ ResultOfSign = KwStruct.new(:signed, :signature)
71
+ ParamsOfVerifySignature = KwStruct.new(:signed, :public_) do
72
+ def to_h
73
+ {
74
+ signed: signed,
75
+ public: public_
76
+ }
77
+ end
78
+ end
79
+ ResultOfVerifySignature = KwStruct.new(:unsigned)
80
+
81
+ ParamsOfHash = KwStruct.new(:data)
82
+ ResultOfHash = KwStruct.new(:hash)
83
+ ParamsOfScrypt = KwStruct.new(:password, :salt, :log_n, :r, :p, :dk_len)
84
+ ResultOfScrypt = KwStruct.new(:key)
85
+ ParamsOfNaclSignKeyPairFromSecret = KwStruct.new(:secret)
86
+
87
+ ParamsOfNaclSign = KwStruct.new(:unsigned, :secret)
88
+ ResultOfNaclSign = KwStruct.new(:signed)
89
+ ParamsOfNaclSignOpen = KwStruct.new(:signed, :public_) do
90
+ def to_h
91
+ {
92
+ signed: signed,
93
+ public: public_
94
+ }
95
+ end
96
+ end
97
+
98
+ ResultOfNaclSignOpen = KwStruct.new(:unsigned)
99
+
100
+ ParamsOfNaclSignDetached = KwStruct.new(:unsigned, :secret)
101
+
102
+ ResultOfNaclSignDetached = KwStruct.new(:signature)
103
+
104
+ ParamsOfNaclBoxKeyPairFromSecret = KwStruct.new(:secret)
105
+
106
+ ParamsOfNaclBox = KwStruct.new(:decrypted, :nonce, :their_public, :secret)
107
+
108
+ ResultOfNaclBox = KwStruct.new(:encrypted)
109
+ ParamsOfNaclBoxOpen = KwStruct.new(:encrypted, :nonce, :their_public, :secret)
110
+
111
+ ResultOfNaclBoxOpen = KwStruct.new(:decrypted)
112
+ ParamsOfNaclSecretBox = KwStruct.new(:decrypted, :nonce, :key)
113
+
114
+ ParamsOfNaclSecretBoxOpen = KwStruct.new(:encrypted, :nonce, :key)
115
+
116
+ ParamsOfMnemonicWords = KwStruct.new(:dictionary)
117
+ ResultOfMnemonicWords = KwStruct.new(:words)
118
+ ParamsOfMnemonicFromRandom = KwStruct.new(:dictionary, :word_count)
119
+ ResultOfMnemonicFromRandom = KwStruct.new(:phrase)
120
+
121
+ ParamsOfMnemonicFromEntropy = KwStruct.new(:entropy, :dictionary, :word_count)
122
+
123
+ ResultOfMnemonicFromEntropy = KwStruct.new(:phrase)
124
+
125
+ ParamsOfMnemonicVerify = KwStruct.new(:phrase, :dictionary, :word_count)
126
+
127
+ ResultOfMnemonicVerify = KwStruct.new(:valid)
128
+
129
+ ParamsOfMnemonicDeriveSignKeys = KwStruct.new(:phrase, :path, :dictionary, :word_count)
130
+
131
+ class ParamsOfHDKeyXPrvFromMnemonic
132
+ attr_reader :phrase, :dictionary, :word_count
133
+
134
+ def initialize(phrase:, dictionary: nil, word_count: nil)
135
+ @phrase = phrase
136
+ @dictionary = dictionary
137
+ @word_count = word_count
138
+ end
139
+
140
+ def to_h
141
+ {
142
+ phrase: @phrase,
143
+ dictionary: @dictionary,
144
+ word_count: @word_count
145
+ }
146
+ end
147
+ end
148
+
149
+ ResultOfHDKeyXPrvFromMnemonic = KwStruct.new(:xprv)
150
+
151
+ class ParamsOfHDKeyDeriveFromXPrv
152
+ attr_reader :xprv, :child_index, :hardened
153
+
154
+ def initialize(xprv:, child_index:, hardened:)
155
+ @xprv = xprv
156
+ @child_index = child_index
157
+ @hardened = hardened
158
+ end
159
+
160
+ def to_h
161
+ {
162
+ xprv: @xprv,
163
+ child_index: @child_index,
164
+ hardened: @hardened
165
+ }
166
+ end
167
+ end
168
+
169
+ ResultOfHDKeyDeriveFromXPrv = KwStruct.new(:xprv)
170
+ ParamsOfHDKeySecretFromXPrv = KwStruct.new(:xprv)
171
+ ResultOfHDKeySecretFromXPrv = KwStruct.new(:secret)
172
+ ParamsOfHDKeyPublicFromXPrv = KwStruct.new(:xprv)
173
+ ResultOfHDKeyPublicFromXPrv = KwStruct.new(:public_)
174
+
175
+ ParamsOfHDKeyDeriveFromXPrvPath = KwStruct.new(:xprv, :path)
176
+
177
+ ResultOfHDKeyDeriveFromXPrvPath = KwStruct.new(:xprv)
178
+
179
+ ParamsOfChaCha20 = KwStruct.new(:data, :key, :nonce)
180
+
181
+ ResultOfChaCha20 = KwStruct.new(:data)
182
+
183
+ ParamsOfSigningBoxSign = KwStruct.new(:signing_box, :unsigned)
184
+
185
+ ResultOfSigningBoxSign = KwStruct.new(:signature)
186
+
187
+ RegisteredSigningBox = KwStruct.new(:handle)
188
+
189
+ ResultOfSigningBoxGetPublicKey = KwStruct.new(:pubkey)
190
+
191
+ ParamsOfNaclSignDetachedVerify = KwStruct.new(:unsigned, :signature, :public_) do
192
+ def to_h
193
+ {
194
+ unsigned: unsigned,
195
+ signature: signature,
196
+ public: public_
197
+ }
198
+ end
199
+ end
200
+
201
+ ResultOfNaclSignDetachedVerify = KwStruct.new(:succeeded)
202
+
203
+ class ParamsOfAppSigningBox
204
+ TYPES = [:get_public_key, :sign]
205
+
206
+ attr_reader :type_, :unsigned
207
+
208
+ def initialize(type_:, unsigned:)
209
+ unless TYPES.include?(type_)
210
+ raise ArgumentError.new("type #{type_} is unknown; known types: #{TYPES}")
211
+ end
212
+ @type_ = type_
213
+ @unsigned = unsigned
214
+ end
215
+
216
+ def to_h
217
+ {
218
+ type: Helper.sym_to_capitalized_case_str(@type_),
219
+ unsigned: @unsigned
220
+ }
221
+ end
222
+ end
223
+
224
+ EncryptionBoxInfo = KwStruct.new(:hdpath, :algorithm, :options, :public)
225
+
226
+ ParamsOfEncryptionBoxGetInfo = KwStruct.new(:encryption_box)
227
+
228
+ ResultOfEncryptionBoxGetInfo = KwStruct.new(:info)
229
+
230
+ ParamsOfEncryptionBoxEncrypt = KwStruct.new(:encryption_box, :data)
231
+
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
+
240
+ ParamsOfCreateEncryptionBox = KwStruct.new(:algorithm)
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
+
369
+ class EncryptionAlgorithm
370
+ private_class_method :new
371
+
372
+ attr_reader :type_, :aes_params
373
+
374
+ def self.new_with_type_aes(aes_params:)
375
+ @type_ = :aes
376
+ @aes_params = aes_params
377
+ end
378
+ end
379
+
380
+ #
381
+ # functions
382
+ #
383
+
384
+ def self.factorize(ctx, params)
385
+ Interop::request_to_native_lib(ctx, "crypto.factorize", params) do |resp|
386
+ if resp.success?
387
+ yield NativeLibResponseResult.new(
388
+ result: ResultOfFactorize.new(factors: resp.result["factors"])
389
+ )
390
+ else
391
+ yield resp
392
+ end
393
+ end
394
+ end
395
+
396
+ def self.modular_power(ctx, params)
397
+ Interop::request_to_native_lib(ctx, "crypto.modular_power", params) do |resp|
398
+ if resp.success?
399
+ yield NativeLibResponseResult.new(
400
+ result: ResultOfModularPower.new(modular_power: resp.result["modular_power"])
401
+ )
402
+ else
403
+ yield resp
404
+ end
405
+ end
406
+ end
407
+
408
+ def self.ton_crc16(ctx, params)
409
+ Interop::request_to_native_lib(ctx, "crypto.ton_crc16", params) do |resp|
410
+ if resp.success?
411
+ yield NativeLibResponseResult.new(
412
+ result: ResultOfTonCrc16.new(crc: resp.result["crc"])
413
+ )
414
+ else
415
+ yield resp
416
+ end
417
+ end
418
+ end
419
+
420
+ def self.generate_random_bytes(ctx, params)
421
+ Interop::request_to_native_lib(ctx, "crypto.generate_random_bytes", params) do |resp|
422
+ if resp.success?
423
+ yield NativeLibResponseResult.new(
424
+ result: ResultOfGenerateRandomBytes.new(bytes: resp.result["bytes"])
425
+ )
426
+ else
427
+ yield resp
428
+ end
429
+ end
430
+ end
431
+
432
+ def self.convert_public_key_to_ton_safe_format(ctx, params)
433
+ Interop::request_to_native_lib(ctx, "crypto.convert_public_key_to_ton_safe_format", params) do |resp|
434
+ if resp.success?
435
+ yield NativeLibResponseResult.new(
436
+ result: ResultOfConvertPublicKeyToTonSafeFormat.new(ton_public_key: resp.result["ton_public_key"])
437
+ )
438
+ else
439
+ yield resp
440
+ end
441
+ end
442
+ end
443
+
444
+ def self.generate_random_sign_keys(ctx, is_single_thread_only: false)
445
+ Interop::request_to_native_lib(ctx, "crypto.generate_random_sign_keys", nil, is_single_thread_only: is_single_thread_only) do |resp|
446
+ if resp.success?
447
+ yield NativeLibResponseResult.new(
448
+ result: KeyPair.new(
449
+ public_: resp.result["public"],
450
+ secret: resp.result["secret"]
451
+ )
452
+ )
453
+ else
454
+ yield resp
455
+ end
456
+ end
457
+ end
458
+
459
+ def self.sign(ctx, params)
460
+ Interop::request_to_native_lib(ctx, "crypto.sign", params) do |resp|
461
+ if resp.success?
462
+ yield NativeLibResponseResult.new(
463
+ result: ResultOfSign.new(
464
+ signed: resp.result["signed"],
465
+ signature: resp.result["signature"]
466
+ )
467
+ )
468
+ else
469
+ yield resp
470
+ end
471
+ end
472
+ end
473
+
474
+ def self.verify_signature(ctx, params)
475
+ Interop::request_to_native_lib(ctx, "crypto.verify_signature", params) do |resp|
476
+ if resp.success?
477
+ yield NativeLibResponseResult.new(
478
+ result: ResultOfVerifySignature.new(unsigned: resp.result["unsigned"])
479
+ )
480
+ else
481
+ yield resp
482
+ end
483
+ end
484
+ end
485
+
486
+ def self.sha256(ctx, params)
487
+ Interop::request_to_native_lib(ctx, "crypto.sha256", params) do |resp|
488
+ if resp.success?
489
+ yield NativeLibResponseResult.new(
490
+ result: ResultOfHash.new(hash: resp.result["hash"])
491
+ )
492
+ else
493
+ yield resp
494
+ end
495
+ end
496
+ end
497
+
498
+ def self.sha512(ctx, params)
499
+ Interop::request_to_native_lib(ctx, "crypto.sha512", params) do |resp|
500
+ if resp.success?
501
+ yield NativeLibResponseResult.new(
502
+ result: ResultOfHash.new(hash: resp.result["hash"])
503
+ )
504
+ else
505
+ yield resp
506
+ end
507
+ end
508
+ end
509
+
510
+ def self.scrypt(ctx, params)
511
+ Interop::request_to_native_lib(ctx, "crypto.scrypt", params) do |resp|
512
+ if resp.success?
513
+ yield NativeLibResponseResult.new(
514
+ result: ResultOfScrypt.new(key: resp.result["key"])
515
+ )
516
+ else
517
+ yield resp
518
+ end
519
+ end
520
+ end
521
+
522
+ def self.nacl_sign_keypair_from_secret_key(ctx, params)
523
+ Interop::request_to_native_lib(ctx, "crypto.nacl_sign_keypair_from_secret_key", params) do |resp|
524
+ if resp.success?
525
+ yield NativeLibResponseResult.new(
526
+ result: KeyPair.new(
527
+ public_: resp.result["public"],
528
+ secret: resp.result["secret"]
529
+ )
530
+ )
531
+ else
532
+ yield resp
533
+ end
534
+ end
535
+ end
536
+
537
+ def self.nacl_sign(ctx, params)
538
+ Interop::request_to_native_lib(ctx, "crypto.nacl_sign", params) do |resp|
539
+ if resp.success?
540
+ yield NativeLibResponseResult.new(
541
+ result: ResultOfNaclSign.new(signed: resp.result["signed"])
542
+ )
543
+ else
544
+ yield resp
545
+ end
546
+ end
547
+ end
548
+
549
+ def self.nacl_sign_open(ctx, params)
550
+ Interop::request_to_native_lib(ctx, "crypto.nacl_sign_open", params) do |resp|
551
+ if resp.success?
552
+ yield NativeLibResponseResult.new(
553
+ result: ResultOfNaclSignOpen.new(unsigned: resp.result["unsigned"])
554
+ )
555
+ else
556
+ yield resp
557
+ end
558
+ end
559
+ end
560
+
561
+ def self.nacl_sign_detached(ctx, params)
562
+ Interop::request_to_native_lib(ctx, "crypto.nacl_sign_detached", params) do |resp|
563
+ if resp.success?
564
+ yield NativeLibResponseResult.new(
565
+ result: ResultOfNaclSignDetached.new(signature: resp.result["signature"])
566
+ )
567
+ else
568
+ yield resp
569
+ end
570
+ end
571
+ end
572
+
573
+ def self.nacl_sign_detached_verify(ctx, params)
574
+ Interop::request_to_native_lib(ctx, "crypto.nacl_sign_detached_verify", params) do |resp|
575
+ if resp.success?
576
+ yield NativeLibResponseResult.new(
577
+ result: ResultOfNaclSignDetachedVerify.new(succeeded: resp.result["succeeded"])
578
+ )
579
+ else
580
+ yield resp
581
+ end
582
+ end
583
+ end
584
+
585
+ def self.nacl_box_keypair(ctx)
586
+ Interop::request_to_native_lib(ctx, "crypto.nacl_box_keypair") do |resp|
587
+ if resp.success?
588
+ yield NativeLibResponseResult.new(
589
+ result: KeyPair.new(
590
+ public_: resp.result["public"],
591
+ secret: resp.result["secret"]
592
+ )
593
+ )
594
+ else
595
+ yield resp
596
+ end
597
+ end
598
+ end
599
+
600
+ def self.nacl_box_keypair_from_secret_key(ctx, params)
601
+ Interop::request_to_native_lib(ctx, "crypto.nacl_box_keypair_from_secret_key", params) do |resp|
602
+ if resp.success?
603
+ yield NativeLibResponseResult.new(
604
+ result: KeyPair.new(
605
+ public_: resp.result["public"],
606
+ secret: resp.result["secret"]
607
+ )
608
+ )
609
+ else
610
+ yield resp
611
+ end
612
+ end
613
+ end
614
+
615
+ def self.nacl_box(ctx, params)
616
+ Interop::request_to_native_lib(ctx, "crypto.nacl_box", params) do |resp|
617
+ if resp.success?
618
+ yield NativeLibResponseResult.new(
619
+ result: ResultOfNaclBox.new(encrypted: resp.result["encrypted"])
620
+ )
621
+ else
622
+ yield resp
623
+ end
624
+ end
625
+ end
626
+
627
+ def self.nacl_box_open(ctx, params)
628
+ Interop::request_to_native_lib(ctx, "crypto.nacl_box_open", params) do |resp|
629
+ if resp.success?
630
+ yield NativeLibResponseResult.new(
631
+ result: ResultOfNaclBoxOpen.new(decrypted: resp.result["decrypted"])
632
+ )
633
+ else
634
+ yield resp
635
+ end
636
+ end
637
+ end
638
+
639
+ def self.nacl_secret_box(ctx, params)
640
+ Interop::request_to_native_lib(ctx, "crypto.nacl_secret_box", params) do |resp|
641
+ if resp.success?
642
+ yield NativeLibResponseResult.new(
643
+ result: ResultOfNaclBox.new(encrypted: resp.result["encrypted"])
644
+ )
645
+ else
646
+ yield resp
647
+ end
648
+ end
649
+ end
650
+
651
+ def self.nacl_secret_box_open(ctx, params)
652
+ Interop::request_to_native_lib(ctx, "crypto.nacl_secret_box_open", params) do |resp|
653
+ if resp.success?
654
+ yield NativeLibResponseResult.new(
655
+ result: ResultOfNaclBoxOpen.new(decrypted: resp.result["decrypted"])
656
+ )
657
+ else
658
+ yield resp
659
+ end
660
+ end
661
+ end
662
+
663
+ def self.mnemonic_words(ctx, params)
664
+ Interop::request_to_native_lib(ctx, "crypto.mnemonic_words", params) do |resp|
665
+ if resp.success?
666
+ yield NativeLibResponseResult.new(
667
+ result: ResultOfMnemonicWords.new(words: resp.result["words"])
668
+ )
669
+ else
670
+ yield resp
671
+ end
672
+ end
673
+ end
674
+
675
+ def self.mnemonic_from_random(ctx, params)
676
+ Interop::request_to_native_lib(ctx, "crypto.mnemonic_from_random", params) do |resp|
677
+ if resp.success?
678
+ yield NativeLibResponseResult.new(
679
+ result: ResultOfMnemonicFromRandom.new(phrase: resp.result["phrase"])
680
+ )
681
+ else
682
+ yield resp
683
+ end
684
+ end
685
+ end
686
+
687
+ def self.mnemonic_from_entropy(ctx, params)
688
+ Interop::request_to_native_lib(ctx, "crypto.mnemonic_from_entropy", params) do |resp|
689
+ if resp.success?
690
+ yield NativeLibResponseResult.new(
691
+ result: ResultOfMnemonicFromEntropy.new(phrase: resp.result["phrase"])
692
+ )
693
+ else
694
+ yield resp
695
+ end
696
+ end
697
+ end
698
+
699
+ def self.mnemonic_verify(ctx, params)
700
+ Interop::request_to_native_lib(ctx, "crypto.mnemonic_verify", params) do |resp|
701
+ if resp.success?
702
+ yield NativeLibResponseResult.new(
703
+ result: ResultOfMnemonicVerify.new(valid: resp.result["valid"])
704
+ )
705
+ else
706
+ yield resp
707
+ end
708
+ end
709
+ end
710
+
711
+ def self.mnemonic_derive_sign_keys(ctx, params)
712
+ Interop::request_to_native_lib(ctx, "crypto.mnemonic_derive_sign_keys", params) do |resp|
713
+ if resp.success?
714
+ yield NativeLibResponseResult.new(
715
+ result: KeyPair.new(
716
+ public_: resp.result["public"],
717
+ secret: resp.result["secret"]
718
+ )
719
+ )
720
+ else
721
+ yield resp
722
+ end
723
+ end
724
+ end
725
+
726
+ def self.hdkey_xprv_from_mnemonic(ctx, params)
727
+ Interop::request_to_native_lib(ctx, "crypto.hdkey_xprv_from_mnemonic", params) do |resp|
728
+ if resp.success?
729
+ yield NativeLibResponseResult.new(
730
+ result: ResultOfHDKeyXPrvFromMnemonic.new(xprv: resp.result["xprv"])
731
+ )
732
+ else
733
+ yield resp
734
+ end
735
+ end
736
+ end
737
+
738
+ def self.hdkey_derive_from_xprv(ctx, params)
739
+ Interop::request_to_native_lib(ctx, "crypto.hdkey_derive_from_xprv", params) do |resp|
740
+ if resp.success?
741
+ yield NativeLibResponseResult.new(
742
+ result: ResultOfHDKeyDeriveFromXPrv.new(xprv: resp.result["xprv"])
743
+ )
744
+ else
745
+ yield resp
746
+ end
747
+ end
748
+ end
749
+
750
+ def self.hdkey_derive_from_xprv_path(ctx, params)
751
+ Interop::request_to_native_lib(ctx, "crypto.hdkey_derive_from_xprv_path", params) do |resp|
752
+ if resp.success?
753
+ yield NativeLibResponseResult.new(
754
+ result: ResultOfHDKeyDeriveFromXPrvPath.new(xprv: resp.result["xprv"])
755
+ )
756
+ else
757
+ yield resp
758
+ end
759
+ end
760
+ end
761
+
762
+ def self.hdkey_secret_from_xprv(ctx, params)
763
+ Interop::request_to_native_lib(ctx, "crypto.hdkey_secret_from_xprv", params) do |resp|
764
+ if resp.success?
765
+ yield NativeLibResponseResult.new(
766
+ result: ResultOfHDKeySecretFromXPrv.new(secret: resp.result["secret"])
767
+ )
768
+ else
769
+ yield resp
770
+ end
771
+ end
772
+ end
773
+
774
+ def self.hdkey_public_from_xprv(ctx, params)
775
+ Interop::request_to_native_lib(ctx, "crypto.hdkey_public_from_xprv", params) do |resp|
776
+ if resp.success?
777
+ yield NativeLibResponseResult.new(
778
+ result: ResultOfHDKeyPublicFromXPrv.new(public_: resp.result["public"])
779
+ )
780
+ else
781
+ yield resp
782
+ end
783
+ end
784
+ end
785
+
786
+ def self.chacha20(ctx, params)
787
+ Interop::request_to_native_lib(ctx, "crypto.chacha20", params) do |resp|
788
+ if resp.success?
789
+ yield NativeLibResponseResult.new(
790
+ result: ResultOfChaCha20.new(data: resp.result["data"])
791
+ )
792
+ else
793
+ yield resp
794
+ end
795
+ end
796
+ end
797
+
798
+ def self.register_signing_box(ctx, callback:)
799
+ Interop::request_to_native_lib(
800
+ ctx,
801
+ "crypto.register_signing_box",
802
+ nil,
803
+ client_callback: callback,
804
+ is_single_thread_only: false
805
+ ) do |resp|
806
+ if resp.success?
807
+ yield NativeLibResponseResult.new(
808
+ result: RegisteredSigningBox.new(handle: resp.result["handle"])
809
+ )
810
+ else
811
+ yield resp
812
+ end
813
+ end
814
+ end
815
+
816
+ def self.get_signing_box(ctx, params)
817
+ Interop::request_to_native_lib(ctx, "crypto.get_signing_box", params) do |resp|
818
+ if resp.success?
819
+ yield NativeLibResponseResult.new(
820
+ result: RegisteredSigningBox.new(handle: resp.result["handle"])
821
+ )
822
+ else
823
+ yield resp
824
+ end
825
+ end
826
+ end
827
+
828
+ def self.signing_box_get_public_key(ctx, params, is_single_thread_only: false)
829
+ Interop::request_to_native_lib(
830
+ ctx,
831
+ "crypto.signing_box_get_public_key",
832
+ params,
833
+ is_single_thread_only: is_single_thread_only
834
+ ) do |resp|
835
+ if resp.success?
836
+ yield NativeLibResponseResult.new(
837
+ result: ResultOfSigningBoxGetPublicKey.new(pubkey: resp.result["pubkey"])
838
+ )
839
+ else
840
+ yield resp
841
+ end
842
+ end
843
+ end
844
+
845
+ def self.signing_box_sign(ctx, params)
846
+ Interop::request_to_native_lib(ctx, "crypto.signing_box_sign", params) do |resp|
847
+ if resp.success?
848
+ yield NativeLibResponseResult.new(
849
+ result: ResultOfSigningBoxSign.new(signature: resp.result["signature"])
850
+ )
851
+ else
852
+ yield resp
853
+ end
854
+ end
855
+ end
856
+
857
+ def self.remove_signing_box(ctx, params)
858
+ Interop::request_to_native_lib(ctx, "crypto.remove_signing_box", params) do |resp|
859
+ if resp.success?
860
+ yield NativeLibResponseResult.new(
861
+ result: nil
862
+ )
863
+ else
864
+ yield resp
865
+ end
866
+ end
867
+ end
868
+
869
+ def self.register_encryption_box(ctx, callback:)
870
+ Interop::request_to_native_lib(
871
+ ctx,
872
+ "crypto.register_encryption_box",
873
+ nil,
874
+ client_callback: callback,
875
+ is_single_thread_only: false
876
+ ) do |resp|
877
+ if resp.success?
878
+ yield NativeLibResponseResult.new(
879
+ result: RegisteredEncryptionBox.new(handle: resp.result["handle"])
880
+ )
881
+ else
882
+ yield resp
883
+ end
884
+ end
885
+ end
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
+
899
+ def self.encryption_box_get_info(ctx, params)
900
+ Interop::request_to_native_lib(ctx, "crypto.encryption_box_get_info", params) do |resp|
901
+ if resp.success?
902
+ yield NativeLibResponseResult.new(
903
+ result: ResultOfEncryptionBoxGetInfo.new(info: resp.result["info"])
904
+ )
905
+ else
906
+ yield resp
907
+ end
908
+ end
909
+ end
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
+
935
+ def self.create_encryption_box(ctx, params)
936
+ Interop::request_to_native_lib(ctx, "crypto.create_encryption_box", params) do |resp|
937
+ if resp.success?
938
+ yield NativeLibResponseResult.new(
939
+ result: RegisteredEncryptionBox.new(handle: resp.result["handle"])
940
+ )
941
+ else
942
+ yield resp
943
+ end
944
+ end
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
1046
+ end
1047
+ end