From b913665de413c421eca7d4b934619f2caaa6f0e8 Mon Sep 17 00:00:00 2001 From: fengshanshan Date: Fri, 3 Mar 2023 11:57:23 +0800 Subject: [PATCH 1/4] add telegram --- go.mod | 36 +++---- go.sum | 38 +++++++ validator/main.go | 2 + validator/telegram/telegram.go | 182 +++++++++++++++++---------------- 4 files changed, 151 insertions(+), 107 deletions(-) diff --git a/go.mod b/go.mod index da27db7..a9c9c24 100644 --- a/go.mod +++ b/go.mod @@ -13,8 +13,8 @@ require ( github.com/gagliardetto/solana-go v1.4.0 github.com/gin-gonic/gin v1.7.7 github.com/go-resty/resty/v2 v2.7.0 - github.com/go-rod/rod v0.112.0 - github.com/gotd/td v0.71.0 + github.com/go-rod/rod v0.112.5 + github.com/gotd/td v0.76.0 github.com/mr-tron/base58 v1.2.0 github.com/sirupsen/logrus v1.9.0 github.com/spf13/viper v1.11.0 @@ -39,7 +39,7 @@ require ( github.com/blendle/zapdriver v1.3.1 // indirect github.com/btcsuite/btcd v0.22.0-beta // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect - github.com/cenkalti/backoff/v4 v4.1.3 // indirect + github.com/cenkalti/backoff/v4 v4.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set v1.8.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect @@ -53,7 +53,7 @@ require ( github.com/gagliardetto/treeout v0.1.4 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-faster/errors v0.6.1 // indirect - github.com/go-faster/jx v0.40.0 // indirect + github.com/go-faster/jx v0.41.0 // indirect github.com/go-faster/xor v0.3.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-playground/locales v0.14.0 // indirect @@ -82,7 +82,7 @@ require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/compress v1.15.12 // indirect + github.com/klauspost/compress v1.15.15 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/logrusorgru/aurora v2.0.3+incompatible // indirect @@ -123,20 +123,20 @@ require ( github.com/ugorji/go/codec v1.2.7 // indirect github.com/wealdtech/go-multicodec v1.4.0 // indirect github.com/ysmood/goob v0.4.0 // indirect - github.com/ysmood/gson v0.7.2 // indirect + github.com/ysmood/gson v0.7.3 // indirect github.com/ysmood/leakless v0.8.0 // indirect go.opencensus.io v0.23.0 // indirect - go.opentelemetry.io/otel v1.11.1 // indirect - go.opentelemetry.io/otel/trace v1.11.1 // indirect + go.opentelemetry.io/otel v1.12.0 // indirect + go.opentelemetry.io/otel/trace v1.12.0 // indirect go.uber.org/atomic v1.10.0 // indirect - go.uber.org/multierr v1.8.0 // indirect - go.uber.org/zap v1.23.0 // indirect - golang.org/x/crypto v0.1.0 // indirect - golang.org/x/exp v0.0.0-20221002003631-540bb7301a08 // indirect - golang.org/x/net v0.1.0 // indirect - golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect - golang.org/x/term v0.1.0 // indirect - golang.org/x/text v0.4.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + go.uber.org/zap v1.24.0 // indirect + golang.org/x/crypto v0.5.0 // indirect + golang.org/x/exp v0.0.0-20230116083435-1de6713980de // indirect + golang.org/x/net v0.5.0 // indirect + golang.org/x/sync v0.1.0 // indirect + golang.org/x/term v0.4.0 // indirect + golang.org/x/text v0.6.0 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/ini.v1 v1.66.4 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect @@ -156,9 +156,9 @@ require ( github.com/gin-contrib/cors v1.3.1 github.com/google/go-github/v41 v41.0.0 github.com/google/uuid v1.3.0 - github.com/samber/lo v1.28.2 + github.com/samber/lo v1.37.0 github.com/stretchr/testify v1.8.1 - golang.org/x/sys v0.1.0 // indirect + golang.org/x/sys v0.4.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 gorm.io/datatypes v1.0.6 gorm.io/driver/postgres v1.3.5 diff --git a/go.sum b/go.sum index 70cda13..053247b 100644 --- a/go.sum +++ b/go.sum @@ -132,6 +132,8 @@ github.com/bwmarrin/discordgo v0.25.0 h1:NXhdfHRNxtwso6FPdzW2i3uBvvU7UIQTghmV2T4 github.com/bwmarrin/discordgo v0.25.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= +github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= +github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= @@ -225,6 +227,8 @@ github.com/go-faster/errors v0.6.1 h1:nNIPOBkprlKzkThvS/0YaX8Zs9KewLCOSFQS5BU06F github.com/go-faster/errors v0.6.1/go.mod h1:5MGV2/2T9yvlrbhe9pD9LO5Z/2zCSq2T8j+Jpi2LAyY= github.com/go-faster/jx v0.40.0 h1:Y9cDVPguBRX4WbZFJlEVHwA1/YDmWWOyHtzyfxaByk0= github.com/go-faster/jx v0.40.0/go.mod h1:ALDOh8oc4TjEID/ytTY0Yqlf1ZnNAZ0GJF3SCNo2c8s= +github.com/go-faster/jx v0.41.0 h1:eWv2Tu8EYDBBpVI5pHpQJAJGITA8nGwAdlU5MwhXdKQ= +github.com/go-faster/jx v0.41.0/go.mod h1:fTSMeBYBKUmGFJaA6EkF658Rrco40FHenmq9fOBpYuM= github.com/go-faster/xor v0.3.0 h1:tc0bdVe31Wj999e5rEj7K3DhHyQNp2VydYyLFj3YSN8= github.com/go-faster/xor v0.3.0/go.mod h1:x5CaDY9UKErKzqfRfFZdfu+OSTfoZny3w5Ak7UxcipQ= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -255,6 +259,8 @@ github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPr github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= github.com/go-rod/rod v0.112.0 h1:U9Yc+quw4hxZ6GrdbWFBeylvaYElEKM9ijFW2LYkGlA= github.com/go-rod/rod v0.112.0/go.mod h1:GZDtmEs6RpF6kBRYpGCZXxXlKNneKVPiKOjaMbmVVjE= +github.com/go-rod/rod v0.112.5 h1:2mH97UK8We4D2MfX388WqPjG1lDbxx8lLi5MzfvnEo0= +github.com/go-rod/rod v0.112.5/go.mod h1:ElViL9ABbcshNQw93+11FrYRH92RRhMKleuILo6+5V0= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -363,6 +369,8 @@ github.com/gotd/neo v0.1.5 h1:oj0iQfMbGClP8xI59x7fE/uHoTJD7NZH9oV1WNuPukQ= github.com/gotd/neo v0.1.5/go.mod h1:9A2a4bn9zL6FADufBdt7tZt+WMhvZoc5gWXihOPoiBQ= github.com/gotd/td v0.71.0 h1:Mx8IQqoyxcw1Yn5VmfnBongXKgtwFnqjZokFMN/ejeI= github.com/gotd/td v0.71.0/go.mod h1:UowV9JjlcUaBiEL7dyrQ/2uWEUV/WFCJIRDQ/wV9Glw= +github.com/gotd/td v0.76.0 h1:JBgylUNNYbETCZ2Hv7A6GssF84dpzMflZS3nI9a/GqM= +github.com/gotd/td v0.76.0/go.mod h1:lL9rDh82uF97DTTbLchEFDnjtLWaq2ullKVXj6796Uw= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= @@ -489,6 +497,8 @@ github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYs github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= +github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= @@ -635,6 +645,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samber/lo v1.28.2 h1:f1gctelJ5YQk336wCN+Elr90FyhZ6ArhelD5kjhNTz4= github.com/samber/lo v1.28.2/go.mod h1:it33p9UtPMS7z72fP4gw/EIfQB2eI8ke7GR2wc6+Rhg= +github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= +github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= @@ -732,11 +744,15 @@ github.com/ysmood/goob v0.4.0 h1:HsxXhyLBeGzWXnqVKtmT9qM7EuVs/XOgkX7T6r1o1AQ= github.com/ysmood/goob v0.4.0/go.mod h1:u6yx7ZhS4Exf2MwciFr6nIM8knHQIE22lFpWHnfql18= github.com/ysmood/got v0.31.3 h1:UvvF+TDVsZLO7MSzm/Bd/H4HVp+7S5YwsxgdwaKq8uA= github.com/ysmood/got v0.31.3/go.mod h1:pE1l4LOwOBhQg6A/8IAatkGp7uZjnalzrZolnlhhMgY= +github.com/ysmood/got v0.32.0 h1:aAHdQgfgMb/lo4v+OekM+SSqEJYFI035h5YYvLXsVyU= +github.com/ysmood/got v0.32.0/go.mod h1:pE1l4LOwOBhQg6A/8IAatkGp7uZjnalzrZolnlhhMgY= github.com/ysmood/gotrace v0.6.0 h1:SyI1d4jclswLhg7SWTL6os3L1WOKeNn/ZtzVQF8QmdY= github.com/ysmood/gotrace v0.6.0/go.mod h1:TzhIG7nHDry5//eYZDYcTzuJLYQIkykJzCRIo4/dzQM= github.com/ysmood/gson v0.7.1/go.mod h1:3Kzs5zDl21g5F/BlLTNcuAGAYLKt2lV5G8D1zF3RNmg= github.com/ysmood/gson v0.7.2 h1:1iWUvpi5DPvd2j59W7ifRPR9DiAZ3Ga+fmMl1mJrRbM= github.com/ysmood/gson v0.7.2/go.mod h1:3Kzs5zDl21g5F/BlLTNcuAGAYLKt2lV5G8D1zF3RNmg= +github.com/ysmood/gson v0.7.3 h1:QFkWbTH8MxyUTKPkVWAENJhxqdBa4lYTQWqZCiLG6kE= +github.com/ysmood/gson v0.7.3/go.mod h1:3Kzs5zDl21g5F/BlLTNcuAGAYLKt2lV5G8D1zF3RNmg= github.com/ysmood/leakless v0.8.0 h1:BzLrVoiwxikpgEQR0Lk8NyBN5Cit2b1z+u0mgL4ZJak= github.com/ysmood/leakless v0.8.0/go.mod h1:R8iAXPRaG97QJwqxs74RdwzcRHT1SWCGTNqY8q0JvMQ= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -756,8 +772,12 @@ go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4= go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE= +go.opentelemetry.io/otel v1.12.0 h1:IgfC7kqQrRccIKuB7Cl+SRUmsKbEwSGPr0Eu+/ht1SQ= +go.opentelemetry.io/otel v1.12.0/go.mod h1:geaoz0L0r1BEOR81k7/n9W4TCXYCJ7bPO7K374jQHG0= go.opentelemetry.io/otel/trace v1.11.1 h1:ofxdnzsNrGBYXbP7t7zpUK281+go5rF7dvdIZXF8gdQ= go.opentelemetry.io/otel/trace v1.11.1/go.mod h1:f/Q9G7vzk5u91PhbmKbg1Qn0rzH1LJ4vbPHFGkTPtOk= +go.opentelemetry.io/otel/trace v1.12.0 h1:p28in++7Kd0r2d8gSt931O57fdjUyWxkVbESuILAeUc= +go.opentelemetry.io/otel/trace v1.12.0/go.mod h1:pHlgBynn6s25qJ2szD+Bv+iwKJttjHSI3lUAyf0GNuQ= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= @@ -772,6 +792,8 @@ go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKY go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= @@ -781,6 +803,8 @@ go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY= go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY= +go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= +go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -806,6 +830,8 @@ golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= +golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -818,6 +844,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20221002003631-540bb7301a08 h1:LtBIgSqNhkuC9gA3BFjGy5obHQT1lnmNsMDFSqWzQ5w= golang.org/x/exp v0.0.0-20221002003631-540bb7301a08/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/exp v0.0.0-20230116083435-1de6713980de h1:DBWn//IJw30uYCgERoxCg84hWtA97F4wMiKOIh00Uf0= +golang.org/x/exp v0.0.0-20230116083435-1de6713980de/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -888,6 +916,8 @@ golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -909,6 +939,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -968,11 +1000,15 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg= +golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -983,6 +1019,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/validator/main.go b/validator/main.go index cf1b5f8..5650f96 100644 --- a/validator/main.go +++ b/validator/main.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/ecdsa" "encoding/json" + "fmt" "net/http" "time" @@ -81,6 +82,7 @@ func GetPostWithHeadlessBrowser(url string, regexp string) (post string, err err } // POST request body to entrypoint headless server requestBody, err := json.Marshal(request) + fmt.Println(string(requestBody)) if err != nil { return "", err } diff --git a/validator/telegram/telegram.go b/validator/telegram/telegram.go index e9dcb6e..ec08c97 100644 --- a/validator/telegram/telegram.go +++ b/validator/telegram/telegram.go @@ -5,9 +5,7 @@ import ( "context" "encoding/json" "fmt" - "net/url" "regexp" - "strconv" "strings" "github.com/nextdotid/proof_server/config" @@ -112,97 +110,103 @@ func (telegram *Telegram) GenerateSignPayload() (payload string) { } func (telegram *Telegram) Validate() (err error) { - initClient() + //initClient() telegram.Identity = strings.ToLower(telegram.Identity) telegram.SignaturePayload = telegram.GenerateSignPayload() - // Deletion. No need to fetch the telegram message. - if telegram.Action == types.Actions.Delete { - return mycrypto.ValidatePersonalSignature(telegram.SignaturePayload, telegram.Signature, telegram.Pubkey) - } - // Message link of the public channel message, e.g. https://t.me/some_public_channel/CHAT_ID_DIGITS - u, err := url.Parse(telegram.ProofLocation) + post, err := validator.GetPostWithHeadlessBrowser(telegram.ProofLocation, telegram.Identity) if err != nil { - return xerrors.Errorf("Error when parsing telegram proof location: %v", err) - - } - msgPath := strings.Trim(u.Path, "/") - parts := strings.Split(msgPath, "/") - if len(parts) != 2 { - return xerrors.Errorf("Error: malformatted telegram proof location: %v", telegram.ProofLocation) - } - channelName := parts[0] - messageId, err := strconv.ParseInt(parts[1], 10, 64) - if err != nil { - return xerrors.Errorf("Error when parsing telegram message ID %s: %s", telegram.ProofLocation, err.Error()) - } - - // Optional, could be removed - if channelName != config.C.Platform.Telegram.PublicChannelName { - return xerrors.New("Unknown channel") - } - - if err := client.Run(context.Background(), func(ctx context.Context) error { - - if _, err := client.Auth().Bot(ctx, config.C.Platform.Telegram.BotToken); err != nil { - return xerrors.Errorf("Error when authenticating the telegram bot: %v,", err) - } - - resolved, err := client.API().ContactsResolveUsername(ctx, channelName) - if err != nil { - return xerrors.Errorf("Error while resolving the public channel name: %v,", err) - } - - if len(resolved.Chats) != 1 { - return xerrors.New("The resulting telegram public channel is empty") - } - - channel, ok := resolved.Chats[0].(*tg.Channel) - if !ok { - return xerrors.New("The resulting telegram public channel is empty") - } - - msgsClass, err := client.API().ChannelsGetMessages(ctx, &tg.ChannelsGetMessagesRequest{ - Channel: &tg.InputChannel{ - ChannelID: channel.ID, - AccessHash: channel.AccessHash, - }, - ID: []tg.InputMessageClass{ - &tg.InputMessageID{ID: int(messageId)}, - }, - }) - - if err != nil { - return xerrors.Errorf("Error while fetching the public channel message: %v,", err) - } - - msgList, ok := msgsClass.(*tg.MessagesChannelMessages) - if !ok || len(msgList.Messages) != 1 || len(msgList.Messages) != 2 { - return xerrors.New("Please try again sending an original message") - } - user, userOk := msgList.Users[0].(*tg.User) - if !userOk { - return xerrors.New("Please try again sending an original message") - } - if user.Bot { - user, userOk = msgList.Users[1].(*tg.User) - } - msg, msgOk := msgList.Messages[0].(*tg.Message) - if !msgOk || !userOk { - return xerrors.New("Please try again sending an original message") - } - userId := strconv.FormatInt(user.ID, 10) - if strings.EqualFold(userId, telegram.Identity) { - return xerrors.Errorf("Telegram username mismatch: expect %s - actual %s", telegram.Identity, user.Username) - } - - telegram.Text = msg.Message - telegram.AltID = user.Username - telegram.Identity = userId - return telegram.validateText() - }); err != nil { - return xerrors.Errorf("Error inside the telegram client context: %v", err) - } + return xerrors.Errorf("fetching tweet with headless browser: %w", err) + } + telegram.Text = post + //// Deletion. No need to fetch the telegram message. + //if telegram.Action == types.Actions.Delete { + // return mycrypto.ValidatePersonalSignature(telegram.SignaturePayload, telegram.Signature, telegram.Pubkey) + //} + // + //// Message link of the public channel message, e.g. https://t.me/some_public_channel/CHAT_ID_DIGITS + //u, err := url.Parse(telegram.ProofLocation) + //if err != nil { + // return xerrors.Errorf("Error when parsing telegram proof location: %v", err) + // + //} + //msgPath := strings.Trim(u.Path, "/") + //parts := strings.Split(msgPath, "/") + //if len(parts) != 2 { + // return xerrors.Errorf("Error: malformatted telegram proof location: %v", telegram.ProofLocation) + //} + //channelName := parts[0] + //messageId, err := strconv.ParseInt(parts[1], 10, 64) + //if err != nil { + // return xerrors.Errorf("Error when parsing telegram message ID %s: %s", telegram.ProofLocation, err.Error()) + //} + // + //// Optional, could be removed + //if channelName != config.C.Platform.Telegram.PublicChannelName { + // return xerrors.New("Unknown channel") + //} + // + //if err := client.Run(context.Background(), func(ctx context.Context) error { + // + // if _, err := client.Auth().Bot(ctx, config.C.Platform.Telegram.BotToken); err != nil { + // return xerrors.Errorf("Error when authenticating the telegram bot: %v,", err) + // } + // + // resolved, err := client.API().ContactsResolveUsername(ctx, channelName) + // if err != nil { + // return xerrors.Errorf("Error while resolving the public channel name: %v,", err) + // } + // + // if len(resolved.Chats) != 1 { + // return xerrors.New("The resulting telegram public channel is empty") + // } + // + // channel, ok := resolved.Chats[0].(*tg.Channel) + // if !ok { + // return xerrors.New("The resulting telegram public channel is empty") + // } + // + // msgsClass, err := client.API().ChannelsGetMessages(ctx, &tg.ChannelsGetMessagesRequest{ + // Channel: &tg.InputChannel{ + // ChannelID: channel.ID, + // AccessHash: channel.AccessHash, + // }, + // ID: []tg.InputMessageClass{ + // &tg.InputMessageID{ID: int(messageId)}, + // }, + // }) + // + // if err != nil { + // return xerrors.Errorf("Error while fetching the public channel message: %v,", err) + // } + // + // msgList, ok := msgsClass.(*tg.MessagesChannelMessages) + // if !ok || len(msgList.Messages) != 1 || len(msgList.Messages) != 2 { + // return xerrors.New("Please try again sending an original message") + // } + // user, userOk := msgList.Users[0].(*tg.User) + // if !userOk { + // return xerrors.New("Please try again sending an original message") + // } + // if user.Bot { + // user, userOk = msgList.Users[1].(*tg.User) + // } + // msg, msgOk := msgList.Messages[0].(*tg.Message) + // if !msgOk || !userOk { + // return xerrors.New("Please try again sending an original message") + // } + // userId := strconv.FormatInt(user.ID, 10) + // if strings.EqualFold(userId, telegram.Identity) { + // return xerrors.Errorf("Telegram username mismatch: expect %s - actual %s", telegram.Identity, user.Username) + // } + // + // telegram.Text = msg.Message + // telegram.AltID = user.Username + // telegram.Identity = userId + // return telegram.validateText() + //}); err != nil { + // return xerrors.Errorf("Error inside the telegram client context: %v", err) + //} return xerrors.New("Unknown error") } From 0ee496e9c12a9da4fdac4d15cb6270d6d584d2af Mon Sep 17 00:00:00 2001 From: fengshanshan Date: Wed, 8 Mar 2023 17:21:25 +0800 Subject: [PATCH 2/4] use headless browser instead of telegram client --- cmd/server/main.go | 3 +- validator/main.go | 6 +- validator/telegram/telegram.go | 160 +++------------------------------ validator/twitter/twitter.go | 1 + 4 files changed, 17 insertions(+), 153 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 5865c53..d31eda8 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "github.com/nextdotid/proof_server/common" "github.com/nextdotid/proof_server/config" "github.com/nextdotid/proof_server/controller" @@ -18,6 +17,7 @@ import ( "github.com/nextdotid/proof_server/validator/minds" "github.com/nextdotid/proof_server/validator/solana" "github.com/nextdotid/proof_server/validator/steam" + "github.com/nextdotid/proof_server/validator/telegram" "github.com/nextdotid/proof_server/validator/twitter" "github.com/sirupsen/logrus" ) @@ -39,6 +39,7 @@ func init_validators() { dns.Init() steam.Init() activitypub.Init() + telegram.Init() } func main() { diff --git a/validator/main.go b/validator/main.go index 5650f96..378467f 100644 --- a/validator/main.go +++ b/validator/main.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/ecdsa" "encoding/json" - "fmt" "net/http" "time" @@ -64,7 +63,7 @@ func BaseToInterface(v *Base) IValidator { return performer_factory(v) } -func GetPostWithHeadlessBrowser(url string, regexp string) (post string, err error) { +func GetPostWithHeadlessBrowser(url string, selector string, regexp string) (post string, err error) { headlessEntrypoint := lo.Sample(config.C.Headless.Urls) headlessEntrypoint += "/v1/find" request := headless.FindRequest{ @@ -73,7 +72,7 @@ func GetPostWithHeadlessBrowser(url string, regexp string) (post string, err err Match: headless.Match{ Type: "regexp", MatchRegExp: &headless.MatchRegExp{ - Selector: "*", + Selector: selector, Value: regexp, }, MatchXPath: nil, @@ -82,7 +81,6 @@ func GetPostWithHeadlessBrowser(url string, regexp string) (post string, err err } // POST request body to entrypoint headless server requestBody, err := json.Marshal(request) - fmt.Println(string(requestBody)) if err != nil { return "", err } diff --git a/validator/telegram/telegram.go b/validator/telegram/telegram.go index ec08c97..a158ce7 100644 --- a/validator/telegram/telegram.go +++ b/validator/telegram/telegram.go @@ -2,21 +2,17 @@ package telegram import ( "bufio" - "context" "encoding/json" "fmt" "regexp" "strings" - "github.com/nextdotid/proof_server/config" "github.com/nextdotid/proof_server/types" "github.com/nextdotid/proof_server/util" mycrypto "github.com/nextdotid/proof_server/util/crypto" "github.com/sirupsen/logrus" "golang.org/x/xerrors" - "github.com/gotd/td/telegram" - "github.com/gotd/td/tg" "github.com/nextdotid/proof_server/validator" ) @@ -29,7 +25,6 @@ const ( ) var ( - client *telegram.Client l = logrus.WithFields(logrus.Fields{"module": "validator", "validator": "telegram"}) re = regexp.MustCompile(MATCH_TEMPLATE) POST_STRUCT = map[string]string{ @@ -40,14 +35,13 @@ var ( ) func Init() { - initClient() if validator.PlatformFactories == nil { validator.PlatformFactories = make(map[types.Platform]func(*validator.Base) validator.IValidator) } validator.PlatformFactories[types.Platforms.Telegram] = func(base *validator.Base) validator.IValidator { - telg := Telegram{base} - return &telg + twi := Telegram{base} + return &twi } } @@ -61,36 +55,9 @@ func (telegram *Telegram) GeneratePostPayload() (post map[string]string) { } func (telegram *Telegram) GenerateSignPayload() (payload string) { - initClient() - var userId string - if err := client.Run(context.Background(), func(ctx context.Context) error { - if _, err := client.Auth().Bot(ctx, config.C.Platform.Telegram.BotToken); err != nil { - return xerrors.Errorf("Error when authenticating the telegram bot: %v,", err) - } - - resolved, err := client.API().ContactsResolveUsername(ctx, telegram.Identity) - if err != nil { - return xerrors.Errorf("Error while resolving the telegram username: %v,", err) - } - - if len(resolved.Users) != 1 { - return xerrors.New("The resulting telegram user is empty") - } - - user, ok := resolved.Users[0].(*tg.User) - if !ok { - return xerrors.New("The resulting telegram user is empty") - } - userId = fmt.Sprintf("%d", user.ID) - return nil - }); err != nil { - l.Warnf("Error inside the telegram client context: %v", err) - return "" - } - payloadStruct := validator.H{ "action": string(telegram.Action), - "identity": userId, + "identity": telegram.Identity, "platform": "telegram", "prev": nil, "created_at": util.TimeToTimestampString(telegram.CreatedAt), @@ -110,104 +77,21 @@ func (telegram *Telegram) GenerateSignPayload() (payload string) { } func (telegram *Telegram) Validate() (err error) { - //initClient() telegram.Identity = strings.ToLower(telegram.Identity) telegram.SignaturePayload = telegram.GenerateSignPayload() - post, err := validator.GetPostWithHeadlessBrowser(telegram.ProofLocation, telegram.Identity) + //// Deletion. No need to fetch the telegram message. + if telegram.Action == types.Actions.Delete { + return mycrypto.ValidatePersonalSignature(telegram.SignaturePayload, telegram.Signature, telegram.Pubkey) + } + + post, err := validator.GetPostWithHeadlessBrowser(fmt.Sprintf("%s%s", telegram.ProofLocation, "?embed=1&mode=tme"), "div.tgme_widget_message_text.js-message_text", "Sig:") if err != nil { - return xerrors.Errorf("fetching tweet with headless browser: %w", err) + return xerrors.Errorf("fetching post message with headless browser: %w", err) } + telegram.Text = post - //// Deletion. No need to fetch the telegram message. - //if telegram.Action == types.Actions.Delete { - // return mycrypto.ValidatePersonalSignature(telegram.SignaturePayload, telegram.Signature, telegram.Pubkey) - //} - // - //// Message link of the public channel message, e.g. https://t.me/some_public_channel/CHAT_ID_DIGITS - //u, err := url.Parse(telegram.ProofLocation) - //if err != nil { - // return xerrors.Errorf("Error when parsing telegram proof location: %v", err) - // - //} - //msgPath := strings.Trim(u.Path, "/") - //parts := strings.Split(msgPath, "/") - //if len(parts) != 2 { - // return xerrors.Errorf("Error: malformatted telegram proof location: %v", telegram.ProofLocation) - //} - //channelName := parts[0] - //messageId, err := strconv.ParseInt(parts[1], 10, 64) - //if err != nil { - // return xerrors.Errorf("Error when parsing telegram message ID %s: %s", telegram.ProofLocation, err.Error()) - //} - // - //// Optional, could be removed - //if channelName != config.C.Platform.Telegram.PublicChannelName { - // return xerrors.New("Unknown channel") - //} - // - //if err := client.Run(context.Background(), func(ctx context.Context) error { - // - // if _, err := client.Auth().Bot(ctx, config.C.Platform.Telegram.BotToken); err != nil { - // return xerrors.Errorf("Error when authenticating the telegram bot: %v,", err) - // } - // - // resolved, err := client.API().ContactsResolveUsername(ctx, channelName) - // if err != nil { - // return xerrors.Errorf("Error while resolving the public channel name: %v,", err) - // } - // - // if len(resolved.Chats) != 1 { - // return xerrors.New("The resulting telegram public channel is empty") - // } - // - // channel, ok := resolved.Chats[0].(*tg.Channel) - // if !ok { - // return xerrors.New("The resulting telegram public channel is empty") - // } - // - // msgsClass, err := client.API().ChannelsGetMessages(ctx, &tg.ChannelsGetMessagesRequest{ - // Channel: &tg.InputChannel{ - // ChannelID: channel.ID, - // AccessHash: channel.AccessHash, - // }, - // ID: []tg.InputMessageClass{ - // &tg.InputMessageID{ID: int(messageId)}, - // }, - // }) - // - // if err != nil { - // return xerrors.Errorf("Error while fetching the public channel message: %v,", err) - // } - // - // msgList, ok := msgsClass.(*tg.MessagesChannelMessages) - // if !ok || len(msgList.Messages) != 1 || len(msgList.Messages) != 2 { - // return xerrors.New("Please try again sending an original message") - // } - // user, userOk := msgList.Users[0].(*tg.User) - // if !userOk { - // return xerrors.New("Please try again sending an original message") - // } - // if user.Bot { - // user, userOk = msgList.Users[1].(*tg.User) - // } - // msg, msgOk := msgList.Messages[0].(*tg.Message) - // if !msgOk || !userOk { - // return xerrors.New("Please try again sending an original message") - // } - // userId := strconv.FormatInt(user.ID, 10) - // if strings.EqualFold(userId, telegram.Identity) { - // return xerrors.Errorf("Telegram username mismatch: expect %s - actual %s", telegram.Identity, user.Username) - // } - // - // telegram.Text = msg.Message - // telegram.AltID = user.Username - // telegram.Identity = userId - // return telegram.validateText() - //}); err != nil { - // return xerrors.Errorf("Error inside the telegram client context: %v", err) - //} - return xerrors.New("Unknown error") + return telegram.validateText() } func (telegram *Telegram) validateText() (err error) { @@ -228,23 +112,3 @@ func (telegram *Telegram) validateText() (err error) { } return xerrors.Errorf("Signature not found in the telegram message.") } - -func initClient() { - if client != nil { - return - } - // https://core.telegram.org/api/obtaining_api_id - client = telegram.NewClient(config.C.Platform.Telegram.ApiID, config.C.Platform.Telegram.ApiHash, telegram.Options{}) - - // Exit if the we can't authenticate the telegram client - // using the provided configs. - if err := client.Run(context.Background(), func(ctx context.Context) error { - if _, err := client.Auth().Bot(ctx, config.C.Platform.Telegram.BotToken); err != nil { - return xerrors.Errorf("Error when authenticating the telegram bot: %v,", err) - } - return nil - }); err != nil { - panic(err) - } - -} diff --git a/validator/twitter/twitter.go b/validator/twitter/twitter.go index f7b50d2..bf117e8 100644 --- a/validator/twitter/twitter.go +++ b/validator/twitter/twitter.go @@ -93,6 +93,7 @@ func (twitter *Twitter) Validate() (err error) { post, err := validator.GetPostWithHeadlessBrowser( fmt.Sprintf("https://twitter.com/%s/status/%d", twitter.Identity, tweetID), + "*", "Sig:", ) if err != nil { From 499db4de32b06934dd4c6cf28db88d4d0206b43a Mon Sep 17 00:00:00 2001 From: fengshanshan Date: Thu, 9 Mar 2023 14:19:30 +0800 Subject: [PATCH 3/4] bug fix --- validator/telegram/telegram.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/validator/telegram/telegram.go b/validator/telegram/telegram.go index a158ce7..671e11e 100644 --- a/validator/telegram/telegram.go +++ b/validator/telegram/telegram.go @@ -40,8 +40,8 @@ func Init() { } validator.PlatformFactories[types.Platforms.Telegram] = func(base *validator.Base) validator.IValidator { - twi := Telegram{base} - return &twi + telg := Telegram{base} + return &telg } } @@ -58,7 +58,7 @@ func (telegram *Telegram) GenerateSignPayload() (payload string) { payloadStruct := validator.H{ "action": string(telegram.Action), "identity": telegram.Identity, - "platform": "telegram", + "platform": string(types.Platforms.Telegram), "prev": nil, "created_at": util.TimeToTimestampString(telegram.CreatedAt), "uuid": telegram.Uuid.String(), @@ -89,6 +89,7 @@ func (telegram *Telegram) Validate() (err error) { if err != nil { return xerrors.Errorf("fetching post message with headless browser: %w", err) } + // TODO validate user telegram.Text = post return telegram.validateText() @@ -101,7 +102,6 @@ func (telegram *Telegram) validateText() (err error) { if len(matched) < 2 { continue // Search for next line } - sigBase64 := matched[1] sigBytes, err := util.DecodeString(sigBase64) if err != nil { From 0fbf0de3b8fc84882998ef8125be582ade372f6d Mon Sep 17 00:00:00 2001 From: fengshanshan Date: Thu, 9 Mar 2023 16:45:31 +0800 Subject: [PATCH 4/4] username validation in validate() --- headless/find.go | 17 ++++++++++++----- validator/main.go | 3 ++- validator/telegram/telegram.go | 13 +++++++++++-- validator/twitter/twitter.go | 1 + 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/headless/find.go b/headless/find.go index 02b12ff..42d757d 100644 --- a/headless/find.go +++ b/headless/find.go @@ -51,6 +51,7 @@ type Match struct { MatchRegExp *MatchRegExp `json:"regexp"` MatchXPath *MatchXPath `json:"xpath"` MatchJS *MatchJS `json:"js"` + Property string `json:"property"` } type FindRequest struct { @@ -189,12 +190,18 @@ func find(match Match, page *rod.Page) (content string, err error) { return "", xerrors.Errorf("%s", "invalid payload") } - text, err := element.Text() - if err != nil { - return "", xerrors.Errorf("%w", err) - } + switch match.Property { + case "href": + link := element.MustElement("a").MustProperty("href") + return link.String(), nil + default: + text, err := element.Text() + if err != nil { + return "", xerrors.Errorf("%w", err) + } + return text, nil - return text, nil + } } func checkValidateRequest(req *FindRequest) error { diff --git a/validator/main.go b/validator/main.go index 378467f..156b6e4 100644 --- a/validator/main.go +++ b/validator/main.go @@ -63,7 +63,7 @@ func BaseToInterface(v *Base) IValidator { return performer_factory(v) } -func GetPostWithHeadlessBrowser(url string, selector string, regexp string) (post string, err error) { +func GetPostWithHeadlessBrowser(url string, selector string, regexp string, property string) (post string, err error) { headlessEntrypoint := lo.Sample(config.C.Headless.Urls) headlessEntrypoint += "/v1/find" request := headless.FindRequest{ @@ -77,6 +77,7 @@ func GetPostWithHeadlessBrowser(url string, selector string, regexp string) (pos }, MatchXPath: nil, MatchJS: nil, + Property: property, }, } // POST request body to entrypoint headless server diff --git a/validator/telegram/telegram.go b/validator/telegram/telegram.go index 671e11e..d3b9c7d 100644 --- a/validator/telegram/telegram.go +++ b/validator/telegram/telegram.go @@ -85,11 +85,20 @@ func (telegram *Telegram) Validate() (err error) { return mycrypto.ValidatePersonalSignature(telegram.SignaturePayload, telegram.Signature, telegram.Pubkey) } - post, err := validator.GetPostWithHeadlessBrowser(fmt.Sprintf("%s%s", telegram.ProofLocation, "?embed=1&mode=tme"), "div.tgme_widget_message_text.js-message_text", "Sig:") + userLink, err := validator.GetPostWithHeadlessBrowser(fmt.Sprintf("%s%s", telegram.ProofLocation, "?embed=1&mode=tme"), "div.tgme_widget_message_user", "^$", "href") + if err != nil { + return xerrors.Errorf("fetching post message with headless browser: %w", err) + } + + username := userLink[strings.LastIndex(userLink, "/")+1 : len(userLink)] + if username != telegram.Identity { + return xerrors.Errorf("User name mismatch: expect %s - actual %s", telegram.Identity, username) + } + + post, err := validator.GetPostWithHeadlessBrowser(fmt.Sprintf("%s%s", telegram.ProofLocation, "?embed=1&mode=tme"), "div.tgme_widget_message_text.js-message_text", "Sig:", "text") if err != nil { return xerrors.Errorf("fetching post message with headless browser: %w", err) } - // TODO validate user telegram.Text = post return telegram.validateText() diff --git a/validator/twitter/twitter.go b/validator/twitter/twitter.go index bf117e8..ecec7e9 100644 --- a/validator/twitter/twitter.go +++ b/validator/twitter/twitter.go @@ -95,6 +95,7 @@ func (twitter *Twitter) Validate() (err error) { fmt.Sprintf("https://twitter.com/%s/status/%d", twitter.Identity, tweetID), "*", "Sig:", + "text", ) if err != nil { return xerrors.Errorf("fetching tweet with headless browser: %w", err)