steamutils 1.5.35 → 1.5.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/_steamproto.js CHANGED
@@ -27,6 +27,10 @@ export class SteamProto {
27
27
  }
28
28
 
29
29
  protoDecode(obj) {
30
+ if (isBase64(obj)) {
31
+ obj = Buffer.from(obj, "base64");
32
+ }
33
+
30
34
  const protobuf = this.toProto();
31
35
  try {
32
36
  return protobuf.toObject(protobuf.decode(obj), { defaults: true });
@@ -37,3 +41,11 @@ export class SteamProto {
37
41
  }
38
42
  }
39
43
  }
44
+
45
+ function isBase64(str) {
46
+ if (typeof str !== "string") return false;
47
+ // remove whitespace and check
48
+ str = str.trim();
49
+ // base64 should only contain A-Z, a-z, 0-9, +, /, and possibly = at the end
50
+ return /^[A-Za-z0-9+/]+={0,2}$/.test(str) && str.length % 4 === 0;
51
+ }