From 36a4c05dd490d4827e15fceb7c00fa74a3cd3ab4 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Fri, 21 Aug 2026 19:52:08 -0400 Subject: [PATCH] refactor(http): use standard uuid package --- go.mod | 1 - go.sum | 2 -- internal/http/properties.go | 13 +++++++------ internal/http/properties_test.go | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index cce93b1..e268287 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,6 @@ require ( github.com/bogdanfinn/tls-client v1.15.1 github.com/gdamore/tcell/v3 v3.4.2 github.com/google/go-cmp v0.6.0 - github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.5.3 github.com/klauspost/compress v1.19.2 github.com/ncruces/zenity v0.10.15 diff --git a/go.sum b/go.sum index a423e74..1994ce8 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,6 @@ github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ= github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E= github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= diff --git a/internal/http/properties.go b/internal/http/properties.go index c462198..7762657 100644 --- a/internal/http/properties.go +++ b/internal/http/properties.go @@ -1,10 +1,11 @@ package http import ( + "uuid" + "github.com/ayn2op/arikawa/v3/discord" "github.com/ayn2op/arikawa/v3/gateway" "github.com/ayn2op/discordo/internal/tls" - "github.com/google/uuid" ) //go:generate go run generator.go @@ -37,7 +38,7 @@ func CommonProperties() gateway.IdentifyProperties { "client_build_number": ClientBuildNumber, "client_event_source": nil, - "client_launch_id": uuid.NewString(), + "client_launch_id": uuid.NewV4().String(), "system_locale": Locale, "release_channel": "stable", @@ -59,7 +60,7 @@ func IdentifyProperties() gateway.IdentifyProperties { func XSuperProperties() gateway.IdentifyProperties { props := CommonProperties() props["client_app_state"] = "focused" - props["client_heartbeat_session_id"] = uuid.NewString() + props["client_heartbeat_session_id"] = uuid.NewV4().String() props["launch_signature"] = generateLaunchSignature() return props } @@ -69,15 +70,15 @@ func generateLaunchSignature() string { // This mask clears detection bits to avoid identification. // Reference: https://docs.discord.food/reference#launch-signature // - // Required version and variant bits for UUIDv4 validity are set by google/uuid. - // Reference: https://github.com/google/uuid/blob/master/version4.go#L54 + // Required version and variant bits for UUIDv4 validity are set by uuid.NewV4. + // Reference: https://pkg.go.dev/uuid#NewV4 mask := [16]byte{ 0b11111111, 0b01111111, 0b11101111, 0b11101111, 0b11110111, 0b11101111, 0b11110111, 0b11111111, 0b11011111, 0b01111110, 0b11111111, 0b10111111, 0b11111110, 0b11111111, 0b11110111, 0b11111111, } - id := uuid.New() + id := uuid.NewV4() for i := range mask { id[i] &= mask[i] } diff --git a/internal/http/properties_test.go b/internal/http/properties_test.go index d1d91ca..f00d2c2 100644 --- a/internal/http/properties_test.go +++ b/internal/http/properties_test.go @@ -3,6 +3,7 @@ package http import ( "strings" "testing" + "uuid" "github.com/ayn2op/arikawa/v3/gateway" "github.com/ayn2op/discordo/internal/tls" @@ -53,3 +54,22 @@ func TestBrowserClientHints(t *testing.T) { }) } } + +func TestPropertyUUIDs(t *testing.T) { + properties := XSuperProperties() + for _, key := range []gateway.IdentifyPropertyKey{"client_launch_id", "client_heartbeat_session_id", "launch_signature"} { + t.Run(string(key), func(t *testing.T) { + value, ok := properties[key].(string) + if !ok { + t.Fatalf("got %T, want string", properties[key]) + } + id, err := uuid.Parse(value) + if err != nil { + t.Fatal(err) + } + if id[6]>>4 != 4 || id[8]>>6 != 2 { + t.Errorf("got non-v4 UUID %q", id) + } + }) + } +}