Skip to content

Commit 4706fb3

Browse files
committed
Add td_api::authenticationCodeTypeSmsWord and td_api::authenticationCodeTypeSmsPhrase.
1 parent 5ffc05a commit 4706fb3

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

td/generate/scheme/td_api.tl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@ ok = Ok;
2424

2525
//@class AuthenticationCodeType @description Provides information about the method by which an authentication code is delivered to the user
2626

27-
//@description An authentication code is delivered via a private Telegram message, which can be viewed from another active session
27+
//@description A digit-only authentication code is delivered via a private Telegram message, which can be viewed from another active session
2828
//@length Length of the code
2929
authenticationCodeTypeTelegramMessage length:int32 = AuthenticationCodeType;
3030

31-
//@description An authentication code is delivered via an SMS message to the specified phone number; applications may not receive this type of code
31+
//@description A digit-only authentication code is delivered via an SMS message to the specified phone number; non-official applications may not receive this type of code
3232
//@length Length of the code
3333
authenticationCodeTypeSms length:int32 = AuthenticationCodeType;
3434

35-
//@description An authentication code is delivered via a phone call to the specified phone number
35+
//@description An authentication code is a word delivered via an SMS message to the specified phone number; non-official applications may not receive this type of code
36+
//@first_letter The first letters of the word if known
37+
authenticationCodeTypeSmsWord first_letter:string = AuthenticationCodeType;
38+
39+
//@description An authentication code is a phrase from multiple words delivered via an SMS message to the specified phone number; non-official applications may not receive this type of code
40+
//@first_word The first word of the phrase if known
41+
authenticationCodeTypeSmsPhrase first_word:string = AuthenticationCodeType;
42+
43+
//@description A digit-only authentication code is delivered via a phone call to the specified phone number
3644
//@length Length of the code
3745
authenticationCodeTypeCall length:int32 = AuthenticationCodeType;
3846

@@ -45,17 +53,17 @@ authenticationCodeTypeFlashCall pattern:string = AuthenticationCodeType;
4553
//@length Number of digits in the code, excluding the prefix
4654
authenticationCodeTypeMissedCall phone_number_prefix:string length:int32 = AuthenticationCodeType;
4755

48-
//@description An authentication code is delivered to https://fragment.com. The user must be logged in there via a wallet owning the phone number's NFT
56+
//@description A digit-only authentication code is delivered to https://fragment.com. The user must be logged in there via a wallet owning the phone number's NFT
4957
//@url URL to open to receive the code
5058
//@length Length of the code
5159
authenticationCodeTypeFragment url:string length:int32 = AuthenticationCodeType;
5260

53-
//@description An authentication code is delivered via Firebase Authentication to the official Android application
61+
//@description A digit-only authentication code is delivered via Firebase Authentication to the official Android application
5462
//@nonce Nonce to pass to the SafetyNet Attestation API
5563
//@length Length of the code
5664
authenticationCodeTypeFirebaseAndroid nonce:bytes length:int32 = AuthenticationCodeType;
5765

58-
//@description An authentication code is delivered via Firebase Authentication to the official iOS application
66+
//@description A digit-only authentication code is delivered via Firebase Authentication to the official iOS application
5967
//@receipt Receipt of successful application token validation to compare with receipt from push notification
6068
//@push_timeout Time after the next authentication method is supposed to be used if verification push notification isn't received, in seconds
6169
//@length Length of the code

td/telegram/SendCodeHelper.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "td/utils/base64.h"
1010
#include "td/utils/buffer.h"
1111
#include "td/utils/Time.h"
12+
#include "td/utils/utf8.h"
1213

1314
namespace td {
1415

@@ -206,10 +207,18 @@ SendCodeHelper::AuthenticationCodeInfo SendCodeHelper::get_sent_authentication_c
206207
}
207208
return AuthenticationCodeInfo{AuthenticationCodeInfo::Type::Sms, code_type->length_, ""};
208209
}
209-
case telegram_api::auth_sentCodeTypeSmsWord::ID:
210-
return AuthenticationCodeInfo{AuthenticationCodeInfo::Type::Sms, 0, ""};
211-
case telegram_api::auth_sentCodeTypeSmsPhrase::ID:
212-
return AuthenticationCodeInfo{AuthenticationCodeInfo::Type::Sms, 0, ""};
210+
case telegram_api::auth_sentCodeTypeSmsWord::ID: {
211+
auto code_type = move_tl_object_as<telegram_api::auth_sentCodeTypeSmsWord>(sent_code_type_ptr);
212+
if (utf8_length(code_type->beginning_) > 1u) {
213+
LOG(ERROR) << "Receive \"" << code_type->beginning_ << "\" as word first letter";
214+
code_type->beginning_ = string();
215+
}
216+
return AuthenticationCodeInfo{AuthenticationCodeInfo::Type::SmsWord, 0, code_type->beginning_};
217+
}
218+
case telegram_api::auth_sentCodeTypeSmsPhrase::ID: {
219+
auto code_type = move_tl_object_as<telegram_api::auth_sentCodeTypeSmsPhrase>(sent_code_type_ptr);
220+
return AuthenticationCodeInfo{AuthenticationCodeInfo::Type::SmsPhrase, 0, code_type->beginning_};
221+
}
213222
case telegram_api::auth_sentCodeTypeEmailCode::ID:
214223
case telegram_api::auth_sentCodeTypeSetUpEmailRequired::ID:
215224
default:
@@ -243,6 +252,10 @@ td_api::object_ptr<td_api::AuthenticationCodeType> SendCodeHelper::get_authentic
243252
case AuthenticationCodeInfo::Type::FirebaseIos:
244253
return td_api::make_object<td_api::authenticationCodeTypeFirebaseIos>(
245254
authentication_code_info.pattern, authentication_code_info.push_timeout, authentication_code_info.length);
255+
case AuthenticationCodeInfo::Type::SmsWord:
256+
return td_api::make_object<td_api::authenticationCodeTypeSmsWord>(authentication_code_info.pattern);
257+
case AuthenticationCodeInfo::Type::SmsPhrase:
258+
return td_api::make_object<td_api::authenticationCodeTypeSmsPhrase>(authentication_code_info.pattern);
246259
default:
247260
UNREACHABLE();
248261
return nullptr;

td/telegram/SendCodeHelper.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,19 @@ class SendCodeHelper {
5959

6060
private:
6161
struct AuthenticationCodeInfo {
62-
enum class Type : int32 { None, Message, Sms, Call, FlashCall, MissedCall, Fragment, FirebaseAndroid, FirebaseIos };
62+
enum class Type : int32 {
63+
None,
64+
Message,
65+
Sms,
66+
Call,
67+
FlashCall,
68+
MissedCall,
69+
Fragment,
70+
FirebaseAndroid,
71+
FirebaseIos,
72+
SmsWord,
73+
SmsPhrase
74+
};
6375
Type type = Type::None;
6476
int32 length = 0;
6577
int32 push_timeout = 0;

0 commit comments

Comments
 (0)