// mautrix-discord - A Matrix-Discord puppeting bridge. // Copyright (C) 2026 The mautrix-discord contributors // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . package meowcord import ( "encoding" "fmt" "github.com/google/uuid" ) const uuidv4ByteSize = 16 // A LaunchSignature is a valid version 4 UUID that doubles as a bitfield denoting the presence // of certain properties on the JavaScript window object. // // In the first-party client, launch signatures are generated by libdiscore. type LaunchSignature uuid.UUID // A bitmask that, when ANDed with the bytes of a version 4 UUID, produces a launch signature reflecting // no detected properties. // // Note that this incidentally includes the bits that must be zeroed in a valid version 4 UUID. var vanillaBitmask = [uuidv4ByteSize]byte{0xff, 0x7f, 0xef, 0xef, 0xf7, 0xef, 0x47, 0xff, 0x9f, 0x7e, 0xff, 0xbf, 0xfe, 0xff, 0xf7, 0xff} // NewVanillaSignature randomly generates a valid launch signature corresponding to a completely unmodified // client, i.e. a browser environment that does not trip any of the property checks. func NewVanillaSignature() (LaunchSignature, error) { uuid := uuid.New() for i := 0; i < uuidv4ByteSize; i++ { uuid[i] &= vanillaBitmask[i] } return LaunchSignature(uuid), nil } var _ encoding.TextMarshaler = (*LaunchSignature)(nil) var _ fmt.Stringer = (*LaunchSignature)(nil) func (l LaunchSignature) MarshalText() (text []byte, err error) { return uuid.UUID(l).MarshalText() } func (l LaunchSignature) String() string { return uuid.UUID(l).String() }