init: 1.0.0

This commit is contained in:
Chang lue Tsen
2025-04-25 12:08:29 +09:00
commit 8addcc584b
1031 changed files with 76472 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
package telegram
import "fmt"
type AuthData struct {
Id *int64 `json:"id,omitempty"`
FirstName *string `json:"first_name,omitempty"`
LastName *string `json:"last_name,omitempty"`
Username *string `json:"username,omitempty"`
PhotoUrl *string `json:"photo_url,omitempty"`
AuthDate *int64 `json:"auth_date,omitempty"`
Hash *string `json:"hash,omitempty"`
}
// Validate checks the hash of AuthData with computed one. To compute hash botToken is required.
// Ref: https://core.telegram.org/widgets/login#checking-authorization
func (d *AuthData) Validate(botToken []byte) error {
if d.Hash == nil {
return fmt.Errorf("auth data has no 'hash' value")
}
if len(botToken) == 0 {
return fmt.Errorf("telegram bot token is not provided")
}
hash := *d.Hash
computedHash := computeHash(d, botToken)
if hash != computedHash {
return fmt.Errorf("hash is not valid")
}
return nil
}