mtproto 0.0.7 → 0.0.9

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.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +4 -0
  3. data/ext/aes_ige/extconf.rb +3 -9
  4. data/ext/factorization/extconf.rb +2 -0
  5. data/lib/mtproto/auth_key_generator.rb +66 -103
  6. data/lib/mtproto/binary.rb +21 -0
  7. data/lib/mtproto/client/api/check_password.rb +41 -0
  8. data/lib/mtproto/client/api/export_login_token.rb +27 -0
  9. data/lib/mtproto/client/api/get_updates_difference.rb +21 -0
  10. data/lib/mtproto/client/api/get_updates_state.rb +14 -0
  11. data/lib/mtproto/client/api/get_users.rb +14 -0
  12. data/lib/mtproto/client/api/import_login_token.rb +23 -0
  13. data/lib/mtproto/client/api/send_code.rb +21 -0
  14. data/lib/mtproto/client/api/sign_in.rb +27 -0
  15. data/lib/mtproto/client/api.rb +28 -0
  16. data/lib/mtproto/client/rpc/response.rb +63 -0
  17. data/lib/mtproto/client/rpc.rb +67 -107
  18. data/lib/mtproto/client.rb +176 -31
  19. data/lib/mtproto/crypto/dh_key_exchange.rb +1 -2
  20. data/lib/mtproto/crypto/dh_validator.rb +17 -19
  21. data/lib/mtproto/crypto/factorization.rb +1 -1
  22. data/lib/mtproto/crypto/rsa_key.rb +2 -2
  23. data/lib/mtproto/crypto/srp.rb +117 -0
  24. data/lib/mtproto/delegate_methods.rb +11 -0
  25. data/lib/mtproto/message/message.rb +85 -0
  26. data/lib/mtproto/session.rb +1 -1
  27. data/lib/mtproto/tl/constructors.rb +2269 -0
  28. data/lib/mtproto/tl/object.rb +25 -0
  29. data/lib/mtproto/tl/objects/account_password.rb +72 -0
  30. data/lib/mtproto/tl/objects/authorization.rb +73 -0
  31. data/lib/mtproto/tl/objects/check_password.rb +46 -0
  32. data/lib/mtproto/tl/objects/client_dh_inner_data.rb +47 -0
  33. data/lib/mtproto/tl/objects/dh_gen_response.rb +50 -0
  34. data/lib/mtproto/tl/objects/export_login_token.rb +51 -0
  35. data/lib/mtproto/tl/objects/get_config.rb +15 -0
  36. data/lib/mtproto/tl/objects/get_difference.rb +36 -0
  37. data/lib/mtproto/tl/objects/get_password.rb +15 -0
  38. data/lib/mtproto/tl/objects/get_state.rb +15 -0
  39. data/lib/mtproto/tl/objects/get_users.rb +20 -0
  40. data/lib/mtproto/tl/objects/help_config.rb +77 -0
  41. data/lib/mtproto/tl/objects/import_login_token.rb +39 -0
  42. data/lib/mtproto/tl/objects/init_connection.rb +59 -0
  43. data/lib/mtproto/tl/objects/invoke_with_layer.rb +22 -0
  44. data/lib/mtproto/tl/objects/login_token.rb +82 -0
  45. data/lib/mtproto/tl/objects/pq_inner_data.rb +69 -0
  46. data/lib/mtproto/tl/objects/req_dh_params.rb +65 -0
  47. data/lib/mtproto/tl/objects/req_pq_multi.rb +23 -0
  48. data/lib/mtproto/tl/objects/res_pq.rb +75 -0
  49. data/lib/mtproto/tl/objects/send_code.rb +50 -0
  50. data/lib/mtproto/tl/objects/sent_code.rb +79 -0
  51. data/lib/mtproto/tl/objects/server_dh_inner_data.rb +74 -0
  52. data/lib/mtproto/tl/objects/server_dh_params.rb +53 -0
  53. data/lib/mtproto/tl/objects/set_client_dh_params.rb +48 -0
  54. data/lib/mtproto/tl/objects/sign_in.rb +47 -0
  55. data/lib/mtproto/tl/objects/update.rb +80 -0
  56. data/lib/mtproto/tl/objects/update_short.rb +22 -0
  57. data/lib/mtproto/tl/objects/update_short_message.rb +67 -0
  58. data/lib/mtproto/tl/objects/updates_difference.rb +157 -0
  59. data/lib/mtproto/tl/objects/updates_state.rb +37 -0
  60. data/lib/mtproto/tl/objects/users.rb +86 -0
  61. data/lib/mtproto/transport/abridged_packet_codec.rb +35 -12
  62. data/lib/mtproto/transport/connection.rb +23 -0
  63. data/lib/mtproto/transport/errors.rb +11 -0
  64. data/lib/mtproto/transport/packet.rb +19 -0
  65. data/lib/mtproto/transport/tcp_connection.rb +57 -46
  66. data/lib/mtproto/{tl → type}/bad_msg_notification.rb +11 -11
  67. data/lib/mtproto/{tl → type}/client_dh_inner_data.rb +1 -1
  68. data/lib/mtproto/{tl → type}/gzip_packed.rb +6 -4
  69. data/lib/mtproto/{tl → type}/message.rb +3 -3
  70. data/lib/mtproto/{tl → type}/msg_container.rb +1 -1
  71. data/lib/mtproto/{tl → type}/new_session_created.rb +1 -1
  72. data/lib/mtproto/{tl/p_q_inner_data.rb → type/pq_inner_data.rb} +1 -1
  73. data/lib/mtproto/{tl → type}/rpc_error.rb +1 -2
  74. data/lib/mtproto/{tl → type}/serializer.rb +1 -1
  75. data/lib/mtproto/{tl → type}/server_dh_inner_data.rb +1 -1
  76. data/lib/mtproto/updates_poller.rb +37 -33
  77. data/lib/mtproto/version.rb +1 -1
  78. data/lib/mtproto.rb +21 -22
  79. data/scripts/generate_constructors.rb +65 -0
  80. metadata +80 -49
  81. data/lib/mtproto/rpc/get_config.rb +0 -37
  82. data/lib/mtproto/rpc/get_contacts.rb +0 -22
  83. data/lib/mtproto/rpc/get_updates_difference.rb +0 -33
  84. data/lib/mtproto/rpc/get_updates_state.rb +0 -22
  85. data/lib/mtproto/rpc/get_users.rb +0 -22
  86. data/lib/mtproto/rpc/ping.rb +0 -26
  87. data/lib/mtproto/rpc/send_code.rb +0 -44
  88. data/lib/mtproto/rpc/send_message.rb +0 -31
  89. data/lib/mtproto/rpc/sign_in.rb +0 -52
  90. data/lib/mtproto/tl/auth_key/dh_gen_response.rb +0 -37
  91. data/lib/mtproto/tl/auth_key/req_dh_params.rb +0 -31
  92. data/lib/mtproto/tl/auth_key/req_pq_multi.rb +0 -18
  93. data/lib/mtproto/tl/auth_key/res_pq.rb +0 -62
  94. data/lib/mtproto/tl/auth_key/server_dh_params.rb +0 -43
  95. data/lib/mtproto/tl/auth_key/set_client_dh_params.rb +0 -25
  96. data/lib/mtproto/tl/code_settings.rb +0 -25
  97. data/lib/mtproto/tl/config.rb +0 -124
  98. data/lib/mtproto/tl/method_builder.rb +0 -29
  99. data/lib/mtproto/tl/rpc/auth/authorization.rb +0 -107
  100. data/lib/mtproto/tl/rpc/auth/send_code.rb +0 -28
  101. data/lib/mtproto/tl/rpc/auth/sent_code.rb +0 -36
  102. data/lib/mtproto/tl/rpc/auth/sign_in.rb +0 -32
  103. data/lib/mtproto/tl/rpc/contacts/contacts.rb +0 -155
  104. data/lib/mtproto/tl/rpc/contacts/get_contacts.rb +0 -18
  105. data/lib/mtproto/tl/rpc/help/config.rb +0 -35
  106. data/lib/mtproto/tl/rpc/help/get_config.rb +0 -17
  107. data/lib/mtproto/tl/rpc/messages/send_message.rb +0 -43
  108. data/lib/mtproto/tl/rpc/messages/updates.rb +0 -87
  109. data/lib/mtproto/tl/rpc/ping.rb +0 -18
  110. data/lib/mtproto/tl/rpc/pong.rb +0 -46
  111. data/lib/mtproto/tl/rpc/updates/difference.rb +0 -332
  112. data/lib/mtproto/tl/rpc/updates/get_difference.rb +0 -42
  113. data/lib/mtproto/tl/rpc/updates/get_state.rb +0 -17
  114. data/lib/mtproto/tl/rpc/updates/state.rb +0 -59
  115. data/lib/mtproto/tl/rpc/users/get_users.rb +0 -25
  116. data/lib/mtproto/tl/rpc/users/users.rb +0 -99
  117. data/lib/mtproto/tl/sent_code.rb +0 -128
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtproto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Levenkov
@@ -9,6 +9,20 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: async
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: base64
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -28,7 +42,9 @@ description: A Ruby library for Telegram MTProto protocol with TCP abridged tran
28
42
  email:
29
43
  - me@alev.pro
30
44
  executables: []
31
- extensions: []
45
+ extensions:
46
+ - ext/aes_ige/extconf.rb
47
+ - ext/factorization/extconf.rb
32
48
  extra_rdoc_files: []
33
49
  files:
34
50
  - ".env.example"
@@ -40,8 +56,19 @@ files:
40
56
  - ext/factorization/factorization.c
41
57
  - lib/mtproto.rb
42
58
  - lib/mtproto/auth_key_generator.rb
59
+ - lib/mtproto/binary.rb
43
60
  - lib/mtproto/client.rb
61
+ - lib/mtproto/client/api.rb
62
+ - lib/mtproto/client/api/check_password.rb
63
+ - lib/mtproto/client/api/export_login_token.rb
64
+ - lib/mtproto/client/api/get_updates_difference.rb
65
+ - lib/mtproto/client/api/get_updates_state.rb
66
+ - lib/mtproto/client/api/get_users.rb
67
+ - lib/mtproto/client/api/import_login_token.rb
68
+ - lib/mtproto/client/api/send_code.rb
69
+ - lib/mtproto/client/api/sign_in.rb
44
70
  - lib/mtproto/client/rpc.rb
71
+ - lib/mtproto/client/rpc/response.rb
45
72
  - lib/mtproto/crypto/aes_ige.rb
46
73
  - lib/mtproto/crypto/auth_key_helper.rb
47
74
  - lib/mtproto/crypto/dh_key_exchange.rb
@@ -50,61 +77,65 @@ files:
50
77
  - lib/mtproto/crypto/message_key.rb
51
78
  - lib/mtproto/crypto/rsa_key.rb
52
79
  - lib/mtproto/crypto/rsa_pad.rb
80
+ - lib/mtproto/crypto/srp.rb
81
+ - lib/mtproto/delegate_methods.rb
53
82
  - lib/mtproto/encrypted_message.rb
54
83
  - lib/mtproto/errors.rb
84
+ - lib/mtproto/message/message.rb
55
85
  - lib/mtproto/message_id.rb
56
- - lib/mtproto/rpc/get_config.rb
57
- - lib/mtproto/rpc/get_contacts.rb
58
- - lib/mtproto/rpc/get_updates_difference.rb
59
- - lib/mtproto/rpc/get_updates_state.rb
60
- - lib/mtproto/rpc/get_users.rb
61
- - lib/mtproto/rpc/ping.rb
62
- - lib/mtproto/rpc/send_code.rb
63
- - lib/mtproto/rpc/send_message.rb
64
- - lib/mtproto/rpc/sign_in.rb
65
86
  - lib/mtproto/session.rb
66
- - lib/mtproto/tl/auth_key/dh_gen_response.rb
67
- - lib/mtproto/tl/auth_key/req_dh_params.rb
68
- - lib/mtproto/tl/auth_key/req_pq_multi.rb
69
- - lib/mtproto/tl/auth_key/res_pq.rb
70
- - lib/mtproto/tl/auth_key/server_dh_params.rb
71
- - lib/mtproto/tl/auth_key/set_client_dh_params.rb
72
- - lib/mtproto/tl/bad_msg_notification.rb
73
- - lib/mtproto/tl/client_dh_inner_data.rb
74
- - lib/mtproto/tl/code_settings.rb
75
- - lib/mtproto/tl/config.rb
76
- - lib/mtproto/tl/gzip_packed.rb
77
- - lib/mtproto/tl/message.rb
78
- - lib/mtproto/tl/method_builder.rb
79
- - lib/mtproto/tl/msg_container.rb
80
- - lib/mtproto/tl/new_session_created.rb
81
- - lib/mtproto/tl/p_q_inner_data.rb
82
- - lib/mtproto/tl/rpc/auth/authorization.rb
83
- - lib/mtproto/tl/rpc/auth/send_code.rb
84
- - lib/mtproto/tl/rpc/auth/sent_code.rb
85
- - lib/mtproto/tl/rpc/auth/sign_in.rb
86
- - lib/mtproto/tl/rpc/contacts/contacts.rb
87
- - lib/mtproto/tl/rpc/contacts/get_contacts.rb
88
- - lib/mtproto/tl/rpc/help/config.rb
89
- - lib/mtproto/tl/rpc/help/get_config.rb
90
- - lib/mtproto/tl/rpc/messages/send_message.rb
91
- - lib/mtproto/tl/rpc/messages/updates.rb
92
- - lib/mtproto/tl/rpc/ping.rb
93
- - lib/mtproto/tl/rpc/pong.rb
94
- - lib/mtproto/tl/rpc/updates/difference.rb
95
- - lib/mtproto/tl/rpc/updates/get_difference.rb
96
- - lib/mtproto/tl/rpc/updates/get_state.rb
97
- - lib/mtproto/tl/rpc/updates/state.rb
98
- - lib/mtproto/tl/rpc/users/get_users.rb
99
- - lib/mtproto/tl/rpc/users/users.rb
100
- - lib/mtproto/tl/rpc_error.rb
101
- - lib/mtproto/tl/sent_code.rb
102
- - lib/mtproto/tl/serializer.rb
103
- - lib/mtproto/tl/server_dh_inner_data.rb
87
+ - lib/mtproto/tl/constructors.rb
88
+ - lib/mtproto/tl/object.rb
89
+ - lib/mtproto/tl/objects/account_password.rb
90
+ - lib/mtproto/tl/objects/authorization.rb
91
+ - lib/mtproto/tl/objects/check_password.rb
92
+ - lib/mtproto/tl/objects/client_dh_inner_data.rb
93
+ - lib/mtproto/tl/objects/dh_gen_response.rb
94
+ - lib/mtproto/tl/objects/export_login_token.rb
95
+ - lib/mtproto/tl/objects/get_config.rb
96
+ - lib/mtproto/tl/objects/get_difference.rb
97
+ - lib/mtproto/tl/objects/get_password.rb
98
+ - lib/mtproto/tl/objects/get_state.rb
99
+ - lib/mtproto/tl/objects/get_users.rb
100
+ - lib/mtproto/tl/objects/help_config.rb
101
+ - lib/mtproto/tl/objects/import_login_token.rb
102
+ - lib/mtproto/tl/objects/init_connection.rb
103
+ - lib/mtproto/tl/objects/invoke_with_layer.rb
104
+ - lib/mtproto/tl/objects/login_token.rb
105
+ - lib/mtproto/tl/objects/pq_inner_data.rb
106
+ - lib/mtproto/tl/objects/req_dh_params.rb
107
+ - lib/mtproto/tl/objects/req_pq_multi.rb
108
+ - lib/mtproto/tl/objects/res_pq.rb
109
+ - lib/mtproto/tl/objects/send_code.rb
110
+ - lib/mtproto/tl/objects/sent_code.rb
111
+ - lib/mtproto/tl/objects/server_dh_inner_data.rb
112
+ - lib/mtproto/tl/objects/server_dh_params.rb
113
+ - lib/mtproto/tl/objects/set_client_dh_params.rb
114
+ - lib/mtproto/tl/objects/sign_in.rb
115
+ - lib/mtproto/tl/objects/update.rb
116
+ - lib/mtproto/tl/objects/update_short.rb
117
+ - lib/mtproto/tl/objects/update_short_message.rb
118
+ - lib/mtproto/tl/objects/updates_difference.rb
119
+ - lib/mtproto/tl/objects/updates_state.rb
120
+ - lib/mtproto/tl/objects/users.rb
104
121
  - lib/mtproto/transport/abridged_packet_codec.rb
122
+ - lib/mtproto/transport/connection.rb
123
+ - lib/mtproto/transport/errors.rb
124
+ - lib/mtproto/transport/packet.rb
105
125
  - lib/mtproto/transport/tcp_connection.rb
126
+ - lib/mtproto/type/bad_msg_notification.rb
127
+ - lib/mtproto/type/client_dh_inner_data.rb
128
+ - lib/mtproto/type/gzip_packed.rb
129
+ - lib/mtproto/type/message.rb
130
+ - lib/mtproto/type/msg_container.rb
131
+ - lib/mtproto/type/new_session_created.rb
132
+ - lib/mtproto/type/pq_inner_data.rb
133
+ - lib/mtproto/type/rpc_error.rb
134
+ - lib/mtproto/type/serializer.rb
135
+ - lib/mtproto/type/server_dh_inner_data.rb
106
136
  - lib/mtproto/updates_poller.rb
107
137
  - lib/mtproto/version.rb
138
+ - scripts/generate_constructors.rb
108
139
  - tmp/.keep
109
140
  homepage: https://github.com/alev-pro/mtproto-ruby
110
141
  licenses:
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/help/get_config'
4
- require_relative '../tl/rpc/help/config'
5
-
6
- module MTProto
7
- module RPC
8
- class GetConfig
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call
14
- query = TL::RPC::Help::GetConfig.build
15
-
16
- unless @client.instance_variable_get(:@connection_initialized)
17
- query = @client.init_connection(
18
- api_id: @client.api_id,
19
- device_model: @client.device_model,
20
- system_version: @client.system_version,
21
- app_version: @client.app_version,
22
- system_lang_code: @client.system_lang_code,
23
- lang_pack: @client.lang_pack,
24
- lang_code: @client.lang_code,
25
- query: query
26
- )
27
- query = @client.invoke_with_layer(214, query)
28
- @client.instance_variable_set(:@connection_initialized, true)
29
- end
30
-
31
- response = @client.rpc.call(query)
32
-
33
- TL::RPC::Help::Config.parse(response)
34
- end
35
- end
36
- end
37
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/contacts/get_contacts'
4
- require_relative '../tl/rpc/contacts/contacts'
5
-
6
- module MTProto
7
- module RPC
8
- class GetContacts
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call(hash: 0)
14
- raise 'Auth key not generated' unless @client.auth_key
15
-
16
- query = TL::RPC::Contacts::GetContacts.build(hash: hash)
17
- response = @client.rpc.call(query)
18
- TL::RPC::Contacts::Contacts.parse(response)
19
- end
20
- end
21
- end
22
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/updates/get_difference'
4
- require_relative '../tl/rpc/updates/difference'
5
-
6
- module MTProto
7
- module RPC
8
- class GetUpdatesDifference
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call(pts:, date:, qts:, pts_limit: 100, qts_limit: 100, pts_total_limit: nil)
14
- raise 'Auth key not generated' unless @client.auth_key
15
- raise ArgumentError, 'pts is required' if pts.nil?
16
- raise ArgumentError, 'date is required' if date.nil?
17
- raise ArgumentError, 'qts is required' if qts.nil?
18
-
19
- query = TL::RPC::Updates::GetDifference.build(
20
- pts: pts,
21
- pts_limit: pts_limit,
22
- pts_total_limit: pts_total_limit,
23
- date: date,
24
- qts: qts,
25
- qts_limit: qts_limit
26
- )
27
-
28
- response = @client.rpc.call(query)
29
- TL::RPC::Updates::Difference.parse(response)
30
- end
31
- end
32
- end
33
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/updates/get_state'
4
- require_relative '../tl/rpc/updates/state'
5
-
6
- module MTProto
7
- module RPC
8
- class GetUpdatesState
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call
14
- raise 'Auth key not generated' unless @client.auth_key
15
-
16
- query = TL::RPC::Updates::GetState.build
17
- response = @client.rpc.call(query)
18
- TL::RPC::Updates::State.parse(response)
19
- end
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/users/get_users'
4
- require_relative '../tl/rpc/users/users'
5
-
6
- module MTProto
7
- module RPC
8
- class GetUsers
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call
14
- raise 'Auth key not generated' unless @client.auth_key
15
-
16
- query = TL::RPC::Users::GetUsers.build
17
- response = @client.rpc.call(query)
18
- TL::RPC::Users::Users.parse(response)
19
- end
20
- end
21
- end
22
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/ping'
4
- require_relative '../tl/rpc/pong'
5
-
6
- module MTProto
7
- module RPC
8
- class Ping
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call(ping_id = nil)
14
- ping_id ||= rand(2**63)
15
- body = TL::RPC::Ping.build(ping_id)
16
-
17
- response_body = @client.rpc.call(body)
18
- pong = TL::RPC::Pong.parse(response_body)
19
-
20
- raise PingMismatchError unless pong[:ping_id] == ping_id
21
-
22
- true
23
- end
24
- end
25
- end
26
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/auth/send_code'
4
- require_relative '../tl/rpc/auth/sent_code'
5
-
6
- module MTProto
7
- module RPC
8
- class SendCode
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call(phone_number, code_settings: {})
14
- raise ArgumentError, 'phone_number is required' if phone_number.nil? || phone_number.empty?
15
-
16
- query = TL::RPC::Auth::SendCode.build(
17
- phone_number: phone_number,
18
- api_id: @client.api_id,
19
- api_hash: @client.api_hash,
20
- code_settings: code_settings
21
- )
22
-
23
- unless @client.instance_variable_get(:@connection_initialized)
24
- query = @client.init_connection(
25
- api_id: @client.api_id,
26
- device_model: @client.device_model,
27
- system_version: @client.system_version,
28
- app_version: @client.app_version,
29
- system_lang_code: @client.system_lang_code,
30
- lang_pack: @client.lang_pack,
31
- lang_code: @client.lang_code,
32
- query: query
33
- )
34
- query = @client.invoke_with_layer(214, query)
35
- @client.instance_variable_set(:@connection_initialized, true)
36
- end
37
-
38
- response = @client.rpc.call(query)
39
-
40
- TL::RPC::Auth::SentCode.parse(response)
41
- end
42
- end
43
- end
44
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/messages/send_message'
4
- require_relative '../tl/rpc/messages/updates'
5
-
6
- module MTProto
7
- module RPC
8
- class SendMessage
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call(user_id:, access_hash:, message:, random_id: nil)
14
- raise 'Auth key not generated' unless @client.auth_key
15
- raise ArgumentError, 'user_id is required' if user_id.nil?
16
- raise ArgumentError, 'access_hash is required' if access_hash.nil?
17
- raise ArgumentError, 'message is required and cannot be empty' if message.nil? || message.empty?
18
-
19
- query = TL::RPC::Messages::SendMessage.build(
20
- user_id: user_id,
21
- access_hash: access_hash,
22
- message: message,
23
- random_id: random_id
24
- )
25
-
26
- response = @client.rpc.call(query)
27
- TL::RPC::Messages::Updates.parse(response)
28
- end
29
- end
30
- end
31
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tl/rpc/auth/sign_in'
4
- require_relative '../tl/rpc/auth/authorization'
5
-
6
- module MTProto
7
- module RPC
8
- class SignIn
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def call(phone_number:, phone_code_hash:, phone_code:)
14
- raise ArgumentError, 'phone_number is required' if phone_number.nil? || phone_number.empty?
15
- raise ArgumentError, 'phone_code_hash is required' if phone_code_hash.nil? || phone_code_hash.empty?
16
- raise ArgumentError, 'phone_code is required' if phone_code.nil? || phone_code.empty?
17
-
18
- query = TL::RPC::Auth::SignIn.build(
19
- phone_number: phone_number,
20
- phone_code_hash: phone_code_hash,
21
- phone_code: phone_code
22
- )
23
-
24
- unless @client.instance_variable_get(:@connection_initialized)
25
- query = @client.init_connection(
26
- api_id: @client.api_id,
27
- device_model: @client.device_model,
28
- system_version: @client.system_version,
29
- app_version: @client.app_version,
30
- system_lang_code: @client.system_lang_code,
31
- lang_pack: @client.lang_pack,
32
- lang_code: @client.lang_code,
33
- query: query
34
- )
35
- query = @client.invoke_with_layer(214, query)
36
- @client.instance_variable_set(:@connection_initialized, true)
37
- end
38
-
39
- response = @client.rpc.call(query)
40
-
41
- result = TL::RPC::Auth::Authorization.parse(response)
42
-
43
- # Update client with user data if authorization was successful
44
- if result[:authorization] && result[:user_id]
45
- @client.update_user(user_id: result[:user_id], access_hash: result[:access_hash])
46
- end
47
-
48
- result
49
- end
50
- end
51
- end
52
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MTProto
4
- module TL
5
- module AuthKey
6
- class DHGenResponse
7
- CONSTRUCTOR_DH_GEN_OK = 0x3bcbf734
8
- CONSTRUCTOR_DH_GEN_RETRY = 0x46dc1fb9
9
- CONSTRUCTOR_DH_GEN_FAIL = 0xa69dae02
10
-
11
- def self.parse(body)
12
- constructor = body[0, 4].unpack1('L<')
13
-
14
- offset = 4
15
- nonce = body[offset, 16]
16
- offset += 16
17
-
18
- server_nonce = body[offset, 16]
19
- offset += 16
20
-
21
- new_nonce_hash = body[offset, 16]
22
-
23
- case constructor
24
- when CONSTRUCTOR_DH_GEN_OK
25
- { status: :ok, nonce: nonce, server_nonce: server_nonce, new_nonce_hash: new_nonce_hash }
26
- when CONSTRUCTOR_DH_GEN_RETRY
27
- { status: :retry, nonce: nonce, server_nonce: server_nonce, new_nonce_hash: new_nonce_hash }
28
- when CONSTRUCTOR_DH_GEN_FAIL
29
- { status: :fail, nonce: nonce, server_nonce: server_nonce, new_nonce_hash: new_nonce_hash }
30
- else
31
- raise "Unexpected constructor: 0x#{constructor.to_s(16)}"
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../serializer'
4
-
5
- module MTProto
6
- module TL
7
- module AuthKey
8
- class ReqDHParams
9
- CONSTRUCTOR = 0xd712e4be
10
-
11
- def self.build(nonce:, server_nonce:, p:, q:, public_key_fingerprint:, encrypted_data:)
12
- raise ArgumentError, 'Nonce must be 16 bytes' unless nonce.bytesize == 16
13
- raise ArgumentError, 'Server nonce must be 16 bytes' unless server_nonce.bytesize == 16
14
-
15
- p_bytes = Serializer.integer_to_bytes(p)
16
- q_bytes = Serializer.integer_to_bytes(q)
17
-
18
- body = Serializer.serialize_int(CONSTRUCTOR)
19
- body += nonce
20
- body += server_nonce
21
- body += Serializer.serialize_bytes(p_bytes)
22
- body += Serializer.serialize_bytes(q_bytes)
23
- body += Serializer.serialize_long(public_key_fingerprint)
24
- body += Serializer.serialize_bytes(encrypted_data)
25
-
26
- body
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MTProto
4
- module TL
5
- module AuthKey
6
- class ReqPqMulti
7
- CONSTRUCTOR = 0xbe7e8ef1
8
-
9
- def self.build(nonce)
10
- raise ArgumentError, 'Nonce must be 16 bytes' unless nonce.bytesize == 16
11
-
12
- constructor = [CONSTRUCTOR].pack('L<')
13
- constructor + nonce
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MTProto
4
- module TL
5
- module AuthKey
6
- class ResPq
7
- CONSTRUCTOR = 0x05162463
8
-
9
- def self.parse(body)
10
- constructor = body[0, 4].unpack1('L<')
11
- raise "Unexpected constructor: 0x#{constructor.to_s(16)}" unless constructor == CONSTRUCTOR
12
-
13
- offset = 4
14
-
15
- nonce = body[offset, 16]
16
- offset += 16
17
-
18
- server_nonce = body[offset, 16]
19
- offset += 16
20
-
21
- pq_length_byte = body[offset].unpack1('C')
22
- offset += 1
23
-
24
- pq_length = if pq_length_byte == 254
25
- body[offset, 3].unpack1('L<') & 0xffffff
26
- offset += 3
27
- else
28
- pq_length_byte
29
- end
30
-
31
- pq = body[offset, pq_length]
32
- offset += pq_length
33
- offset += padding_length(pq_length + 1)
34
-
35
- vector_constructor = body[offset, 4].unpack1('L<')
36
- offset += 4
37
- raise 'Expected vector constructor' unless vector_constructor == 0x1cb5c415
38
-
39
- fingerprints_count = body[offset, 4].unpack1('L<')
40
- offset += 4
41
-
42
- fingerprints = []
43
- fingerprints_count.times do
44
- fingerprints << body[offset, 8].unpack1('Q<')
45
- offset += 8
46
- end
47
-
48
- {
49
- nonce: nonce,
50
- server_nonce: server_nonce,
51
- pq: pq,
52
- fingerprints: fingerprints
53
- }
54
- end
55
-
56
- def self.padding_length(length)
57
- (4 - (length % 4)) % 4
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MTProto
4
- module TL
5
- module AuthKey
6
- class ServerDHParams
7
- CONSTRUCTOR = 0xd0e8075c
8
-
9
- def self.parse(body)
10
- constructor = body[0, 4].unpack1('L<')
11
- raise "Unexpected constructor: 0x#{constructor.to_s(16)}" unless constructor == CONSTRUCTOR
12
-
13
- offset = 4
14
-
15
- nonce = body[offset, 16]
16
- offset += 16
17
-
18
- server_nonce = body[offset, 16]
19
- offset += 16
20
-
21
- length_byte = body[offset].ord
22
- offset += 1
23
-
24
- if length_byte == 254
25
- length_bytes = body[offset, 3].bytes
26
- encrypted_answer_length = length_bytes[0] | (length_bytes[1] << 8) | (length_bytes[2] << 16)
27
- offset += 3
28
- else
29
- encrypted_answer_length = length_byte
30
- end
31
-
32
- encrypted_answer = body[offset, encrypted_answer_length]
33
-
34
- {
35
- nonce: nonce,
36
- server_nonce: server_nonce,
37
- encrypted_answer: encrypted_answer
38
- }
39
- end
40
- end
41
- end
42
- end
43
- end