@hiroosy/baileys-lite 0.0.1

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.
Files changed (63) hide show
  1. package/README.md +25 -0
  2. package/WAProto/index.d.ts +15932 -0
  3. package/WAProto/index.js +115856 -0
  4. package/engine-requirements.js +11 -0
  5. package/package.json +27 -0
  6. package/src/binary/wa-binary-constants.js +1300 -0
  7. package/src/binary/wa-binary.js +649 -0
  8. package/src/constants.js +143 -0
  9. package/src/defaults.js +102 -0
  10. package/src/foundation/audio-duration.js +530 -0
  11. package/src/foundation/audio-samples.js +268 -0
  12. package/src/foundation/boom.js +46 -0
  13. package/src/foundation/cache.js +142 -0
  14. package/src/foundation/concurrency.js +87 -0
  15. package/src/foundation/curve25519.js +221 -0
  16. package/src/foundation/link-preview.js +320 -0
  17. package/src/foundation/logger.js +69 -0
  18. package/src/foundation/long.js +140 -0
  19. package/src/foundation/protobuf-minimal.js +619 -0
  20. package/src/foundation/wa-crypto.js +76 -0
  21. package/src/foundation/zip.js +124 -0
  22. package/src/index.js +48 -0
  23. package/src/signal/libsignal.js +1051 -0
  24. package/src/signal/signal-group.js +487 -0
  25. package/src/signal/signal-repository.js +646 -0
  26. package/src/socket/business-communities.js +830 -0
  27. package/src/socket/chats.js +674 -0
  28. package/src/socket/groups-newsletter.js +342 -0
  29. package/src/socket/messages-recv.js +1835 -0
  30. package/src/socket/messages-send.js +1202 -0
  31. package/src/socket/socket-core.js +833 -0
  32. package/src/socket/usync.js +291 -0
  33. package/src/socket-client/websocket-client.js +124 -0
  34. package/src/utils/auth-state-core.js +764 -0
  35. package/src/utils/auth-state-storage.js +316 -0
  36. package/src/utils/chat-sync.js +1045 -0
  37. package/src/utils/media.js +841 -0
  38. package/src/utils/message-compose.js +1609 -0
  39. package/src/utils/message-processing.js +958 -0
  40. package/src/utils/wa-protocol-core.js +1283 -0
  41. package/src/vendor/jpeg-js/LICENSE +25 -0
  42. package/src/vendor/jpeg-js/decoder.js +1152 -0
  43. package/src/vendor/jpeg-js/encoder.js +824 -0
  44. package/src/vendor/pngjs/LICENSE +20 -0
  45. package/src/vendor/pngjs/bitmapper.js +273 -0
  46. package/src/vendor/pngjs/bitpacker.js +167 -0
  47. package/src/vendor/pngjs/constants.js +38 -0
  48. package/src/vendor/pngjs/crc.js +47 -0
  49. package/src/vendor/pngjs/filter-pack.js +179 -0
  50. package/src/vendor/pngjs/filter-parse-sync.js +27 -0
  51. package/src/vendor/pngjs/filter-parse.js +185 -0
  52. package/src/vendor/pngjs/format-normaliser.js +101 -0
  53. package/src/vendor/pngjs/interlace.js +101 -0
  54. package/src/vendor/pngjs/packer-sync.js +65 -0
  55. package/src/vendor/pngjs/packer.js +138 -0
  56. package/src/vendor/pngjs/paeth-predictor.js +22 -0
  57. package/src/vendor/pngjs/parser-sync.js +121 -0
  58. package/src/vendor/pngjs/parser.js +299 -0
  59. package/src/vendor/pngjs/png-sync.js +19 -0
  60. package/src/vendor/pngjs/sync-inflate.js +174 -0
  61. package/src/vendor/pngjs/sync-reader.js +54 -0
  62. package/src/wam/wam-constants.js +22853 -0
  63. package/src/wam/wam.js +151 -0
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Minimal 64-bit integer, API-compatible with the subset of `long` (long.js 5.x)
3
+ * that protobufjs and WAProto actually use. Replaces the `long` package.
4
+ *
5
+ * Shape is intentionally the same as long.js so consumers keep working:
6
+ * { low, high, unsigned } (low/high are signed 32-bit ints)
7
+ * toNumber(), toString(), toJSON-free, isLong via __isLong__
8
+ * Arithmetic is done with BigInt instead of long.js's emulated 32-bit math.
9
+ */
10
+ const TWO_64 = 1n << 64n
11
+ const MASK64 = TWO_64 - 1n
12
+
13
+ const isLong = obj => (obj && obj.__isLong__) === true
14
+
15
+ export class Long {
16
+ constructor(low, high, unsigned) {
17
+ this.low = low | 0
18
+ this.high = high | 0
19
+ this.unsigned = !!unsigned
20
+ }
21
+
22
+ /** Underlying 64 bits as an unsigned BigInt. */
23
+ _bits() {
24
+ return (BigInt(this.high >>> 0) << 32n) | BigInt(this.low >>> 0)
25
+ }
26
+ /** Value as BigInt honoring signedness. */
27
+ toBigInt() {
28
+ const b = this._bits()
29
+ return this.unsigned ? b : BigInt.asIntN(64, b)
30
+ }
31
+ toNumber() {
32
+ if (this.unsigned) return (this.high >>> 0) * 4294967296 + (this.low >>> 0)
33
+ return this.high * 4294967296 + (this.low >>> 0)
34
+ }
35
+ toInt() {
36
+ return this.unsigned ? this.low >>> 0 : this.low
37
+ }
38
+ toString(radix) {
39
+ return this.toBigInt().toString(radix || 10)
40
+ }
41
+ isZero() {
42
+ return this.high === 0 && this.low === 0
43
+ }
44
+ isNegative() {
45
+ return !this.unsigned && this.high < 0
46
+ }
47
+ equals(other) {
48
+ if (!isLong(other)) other = Long.fromValue(other)
49
+ if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1) return false
50
+ return this.high === other.high && this.low === other.low
51
+ }
52
+ eq(other) {
53
+ return this.equals(other)
54
+ }
55
+ getHighBits() {
56
+ return this.high
57
+ }
58
+ getHighBitsUnsigned() {
59
+ return this.high >>> 0
60
+ }
61
+ getLowBits() {
62
+ return this.low
63
+ }
64
+ getLowBitsUnsigned() {
65
+ return this.low >>> 0
66
+ }
67
+ toSigned() {
68
+ return this.unsigned ? new Long(this.low, this.high, false) : this
69
+ }
70
+ toUnsigned() {
71
+ return this.unsigned ? this : new Long(this.low, this.high, true)
72
+ }
73
+
74
+ static fromBits(low, high, unsigned) {
75
+ return new Long(low, high, unsigned)
76
+ }
77
+
78
+ static fromBigInt(value, unsigned) {
79
+ const b = BigInt.asUintN(64, value)
80
+ return new Long(Number(BigInt.asIntN(32, b)), Number(BigInt.asIntN(32, b >> 32n)), unsigned)
81
+ }
82
+
83
+ static fromNumber(value, unsigned) {
84
+ if (Number.isNaN(value)) return new Long(0, 0, unsigned)
85
+ if (unsigned) {
86
+ if (value < 0) return new Long(0, 0, true)
87
+ if (value >= 18446744073709551616) return new Long(-1, -1, true) // saturate, like long.js
88
+ } else {
89
+ if (value <= -9223372036854775808) return new Long(0, -2147483648, false)
90
+ if (value + 1 >= 9223372036854775808) return new Long(-1, 2147483647, false)
91
+ }
92
+ return Long.fromBigInt(BigInt(Math.trunc(value)), unsigned)
93
+ }
94
+
95
+ static fromString(str, unsigned, radix) {
96
+ if (str.length === 0) throw Error('empty string')
97
+ if (typeof unsigned === 'number') {
98
+ radix = unsigned
99
+ unsigned = false
100
+ } else {
101
+ unsigned = !!unsigned
102
+ }
103
+ if (str === 'NaN' || str === 'Infinity' || str === '+Infinity' || str === '-Infinity') return new Long(0, 0, unsigned)
104
+ radix = radix || 10
105
+ if (radix < 2 || radix > 36) throw RangeError('radix')
106
+ const p = str.indexOf('-')
107
+ if (p > 0) throw Error('interior hyphen')
108
+ const neg = p === 0
109
+ const digits = neg ? str.substring(1) : str
110
+ // same parse as long.js: parseInt per 8-digit block, so garbage digits become NaN -> 0 rather than throwing
111
+ let result = 0n
112
+ const R = BigInt(radix)
113
+ for (let i = 0; i < digits.length; i += 8) {
114
+ const size = Math.min(8, digits.length - i)
115
+ const value = parseInt(digits.substring(i, i + size), radix)
116
+ result = result * R ** BigInt(size) + BigInt(Number.isNaN(value) ? 0 : value)
117
+ }
118
+ if (neg) result = -result
119
+ return Long.fromBigInt(result, unsigned)
120
+ }
121
+
122
+ static fromValue(val, unsigned) {
123
+ if (typeof val === 'number') return Long.fromNumber(val, unsigned)
124
+ if (typeof val === 'string') return Long.fromString(val, unsigned)
125
+ if (typeof val === 'bigint') return Long.fromBigInt(val, unsigned)
126
+ // throws for non-objects, converts non-instanceof Long (same as long.js)
127
+ return new Long(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned)
128
+ }
129
+
130
+ static isLong(obj) {
131
+ return isLong(obj)
132
+ }
133
+ }
134
+
135
+ Object.defineProperty(Long.prototype, '__isLong__', { value: true })
136
+
137
+ export const ZERO = new Long(0, 0, false)
138
+ export const UZERO = new Long(0, 0, true)
139
+ export { MASK64 }
140
+ export default Long