@bugsee/react-native 0.0.0-stage → 7.0.0-beta2

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 (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +557 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +962 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,148 @@
1
+ /**
2
+ * A minimal, dependency-free SHA-1 (FIPS 180-4). React Native has no built-in
3
+ * crypto module, and pulling one in is not worth it for a single, non-secret
4
+ * digest used only to compute the exception `signature` (R2).
5
+ */
6
+
7
+ function utf8Bytes(text: string): number[] {
8
+ const bytes: number[] = [];
9
+
10
+ for (let i = 0; i < text.length; i += 1) {
11
+ let code = text.charCodeAt(i);
12
+
13
+ if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {
14
+ const low = text.charCodeAt(i + 1);
15
+ if (low >= 0xdc00 && low <= 0xdfff) {
16
+ code = 0x10000 + ((code - 0xd800) << 10) + (low - 0xdc00);
17
+ i += 1;
18
+ }
19
+ }
20
+
21
+ if (code <= 0x7f) {
22
+ bytes.push(code);
23
+ } else if (code <= 0x7ff) {
24
+ bytes.push(0xc0 | (code >> 6), 0x80 | (code & 0x3f));
25
+ } else if (code <= 0xffff) {
26
+ bytes.push(
27
+ 0xe0 | (code >> 12),
28
+ 0x80 | ((code >> 6) & 0x3f),
29
+ 0x80 | (code & 0x3f),
30
+ );
31
+ } else {
32
+ bytes.push(
33
+ 0xf0 | (code >> 18),
34
+ 0x80 | ((code >> 12) & 0x3f),
35
+ 0x80 | ((code >> 6) & 0x3f),
36
+ 0x80 | (code & 0x3f),
37
+ );
38
+ }
39
+ }
40
+
41
+ return bytes;
42
+ }
43
+
44
+ function rotl(x: number, n: number): number {
45
+ return (x << n) | (x >>> (32 - n));
46
+ }
47
+
48
+ /** `arr[i]`, defaulting to 0 -- every index used below is in bounds by construction. */
49
+ function at(arr: number[], i: number): number {
50
+ return arr[i] ?? 0;
51
+ }
52
+
53
+ function pad(bytes: number[]): number[] {
54
+ const bitLength = bytes.length * 8;
55
+ const padded = bytes.slice();
56
+
57
+ padded.push(0x80);
58
+ while (padded.length % 64 !== 56) {
59
+ padded.push(0);
60
+ }
61
+
62
+ const high = Math.floor(bitLength / 0x100000000);
63
+ const low = bitLength >>> 0;
64
+ for (const part of [high, low]) {
65
+ padded.push((part >>> 24) & 0xff, (part >>> 16) & 0xff, (part >>> 8) & 0xff, part & 0xff);
66
+ }
67
+
68
+ return padded;
69
+ }
70
+
71
+ function digest(bytes: number[]): number[] {
72
+ const padded = pad(bytes);
73
+
74
+ let h0 = 0x67452301;
75
+ let h1 = 0xefcdab89;
76
+ let h2 = 0x98badcfe;
77
+ let h3 = 0x10325476;
78
+ let h4 = 0xc3d2e1f0;
79
+
80
+ const w = new Array<number>(80);
81
+
82
+ for (let block = 0; block < padded.length; block += 64) {
83
+ for (let t = 0; t < 16; t += 1) {
84
+ const offset = block + t * 4;
85
+ w[t] =
86
+ (at(padded, offset) << 24) |
87
+ (at(padded, offset + 1) << 16) |
88
+ (at(padded, offset + 2) << 8) |
89
+ at(padded, offset + 3);
90
+ }
91
+ for (let t = 16; t < 80; t += 1) {
92
+ w[t] = rotl(at(w, t - 3) ^ at(w, t - 8) ^ at(w, t - 14) ^ at(w, t - 16), 1);
93
+ }
94
+
95
+ let a = h0;
96
+ let b = h1;
97
+ let c = h2;
98
+ let d = h3;
99
+ let e = h4;
100
+
101
+ for (let t = 0; t < 80; t += 1) {
102
+ let f: number;
103
+ let k: number;
104
+
105
+ if (t < 20) {
106
+ f = (b & c) | (~b & d);
107
+ k = 0x5a827999;
108
+ } else if (t < 40) {
109
+ f = b ^ c ^ d;
110
+ k = 0x6ed9eba1;
111
+ } else if (t < 60) {
112
+ f = (b & c) | (b & d) | (c & d);
113
+ k = 0x8f1bbcdc;
114
+ } else {
115
+ f = b ^ c ^ d;
116
+ k = 0xca62c1d6;
117
+ }
118
+
119
+ const temp = (rotl(a, 5) + f + e + k + at(w, t)) | 0;
120
+ e = d;
121
+ d = c;
122
+ c = rotl(b, 30);
123
+ b = a;
124
+ a = temp;
125
+ }
126
+
127
+ h0 = (h0 + a) | 0;
128
+ h1 = (h1 + b) | 0;
129
+ h2 = (h2 + c) | 0;
130
+ h3 = (h3 + d) | 0;
131
+ h4 = (h4 + e) | 0;
132
+ }
133
+
134
+ return [h0, h1, h2, h3, h4];
135
+ }
136
+
137
+ function toHex(words: number[]): string {
138
+ let hex = '';
139
+ for (const word of words) {
140
+ hex += (word >>> 0).toString(16).padStart(8, '0');
141
+ }
142
+ return hex;
143
+ }
144
+
145
+ /** SHA-1 of `text`'s UTF-8 bytes (never its UTF-16 code units), lowercase hex. */
146
+ export function sha1Hex(text: string): string {
147
+ return toHex(digest(utf8Bytes(text)));
148
+ }
@@ -0,0 +1,355 @@
1
+ /**
2
+ * Adapted from stacktrace-parser (https://github.com/errwischt/stacktrace-parser),
3
+ * which 6.x's `stack-trace-parse.ts` was itself based on. The MIT notice below
4
+ * is carried over verbatim, unmodified.
5
+ *
6
+ * MIT License
7
+ *
8
+ * Copyright (c) 2014-2019 Georg Tavonius
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ * SOFTWARE.
27
+ */
28
+
29
+ /**
30
+ * One parsed line of a JS stack (or a React `componentStack`). A line this
31
+ * SDK's parser does not recognise produces no frame at all -- there is no
32
+ * "unparsed" shape to fall back to.
33
+ */
34
+ export interface ParsedFrame {
35
+ raw: string;
36
+ file: string | null;
37
+ methodName: string | null;
38
+ lineNumber: number | null;
39
+ column: number | null;
40
+ }
41
+
42
+ /**
43
+ * `error.stack` carries the error's own **message**, which is arbitrary,
44
+ * attacker-reachable data (a server body, user input, a pretty-printed
45
+ * dump). `buildExceptionPayload` runs synchronously on the fatal path,
46
+ * before React Native's own handler (Phase 7 R11), so a slow parse there
47
+ * freezes the app instead of reporting the crash. Two bounds keep every
48
+ * regex below fed a small, fixed-size string regardless of how large the
49
+ * real input is:
50
+ *
51
+ * - `STACK_MAX_INPUT_LENGTH` bounds the whole stack before it is even split
52
+ * into lines -- a stack with an enormous number of lines is cut here.
53
+ * - `STACK_MAX_LINE_LENGTH` bounds each individual line before any pattern
54
+ * runs on it -- a single enormous line is cut here.
55
+ *
56
+ * A cap alone is not the guarantee it first looks like: a genuinely
57
+ * quadratic pattern at `STACK_MAX_LINE_LENGTH` (2 KiB) still costs a few
58
+ * milliseconds, and that cost multiplies by every line in a 64 KiB stack,
59
+ * and again by every node in the cause chain (review N1 -- the first
60
+ * version of this comment claimed "low single-digit milliseconds" as a
61
+ * consequence of the cap alone, which a 64 KiB stack and a full cause
62
+ * chain both disproved). Every pattern below is therefore also written,
63
+ * and directly timed against multi-megabyte adversarial input (see
64
+ * `stack.test.ts`'s "bounded against a hostile stack" cases and this
65
+ * file's own history) to be linear in the line's length on its own, not
66
+ * merely fast because it is short -- so the caps below bound the *total*
67
+ * work by their product, not by one pattern's worst case surviving
68
+ * unnoticed at small sizes. `EXCEPTION_MAX_TOTAL_STACK_LENGTH` in
69
+ * `payload.ts` bounds the sum across every node in a cause chain plus
70
+ * `componentStack`, for the same reason: bounding each node alone still
71
+ * lets the total multiply by the chain's depth.
72
+ */
73
+ export const STACK_MAX_INPUT_LENGTH = 64 * 1024;
74
+ export const STACK_MAX_LINE_LENGTH = 2 * 1024;
75
+
76
+ // Every pattern below is matched against an already-`trim()`-ed line (see
77
+ // `parseStack`), so none of them need their own leading `^\s*`/trailing
78
+ // `\s*$`. That removal is not just tidying: a `\s*` at one end, retried at
79
+ // every position a *different* flexible quantifier backtracks to, is
80
+ // exactly what made the previous versions of these patterns super-linear on
81
+ // a padded-with-spaces line. A single upfront `trim()` handles every
82
+ // leading/trailing-whitespace case once, for all four patterns, in O(line
83
+ // length).
84
+
85
+ // Chrome/V8 (and a Hermes frame served from a Metro dev-server URL, which has
86
+ // the same "at name (url:line:col)" shape): the file must start with one of
87
+ // these recognised schemes/paths, which is what lets a native/no-location
88
+ // frame ("at forEach (native)") and a real file both match one pattern. The
89
+ // name group excludes `(`: a lazy `(.*?)` there let `(` (or ` (`) followed
90
+ // by a whitelisted scheme act as a fresh candidate split, anywhere in the
91
+ // line, each needing its own O(line length) scan by the file group to fail
92
+ // -- quadratic overall (review N1; measured 4-5 ms on a crafted 2 KiB line,
93
+ // which a 64 KiB stack or a chain then multiplies well past budget). A
94
+ // frame's own method name is never expected to contain `(` (a real one,
95
+ // `eval at foo (bar.js:1:2)`, has its `(` only in the *file* half, which
96
+ // this group never touches); the fix is exact, not a lossy workaround.
97
+ const CHROME_RE =
98
+ /^at ([^(]*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?$/i;
99
+
100
+ // A Hermes release frame whose file contains parentheses -- an iOS app
101
+ // bundle such as "My App (Beta).app" -- or an empty name ("at (address
102
+ // at ...)", the literal shape a Hermes anonymous release frame has: an
103
+ // empty name still leaves the format string's own separating space, so
104
+ // there are two spaces before the parenthesis). NODE_PAREN_RE below
105
+ // excludes parens from its file group specifically to avoid competing
106
+ // with its name group over the same characters (review N1); once the
107
+ // literal "address at " marker matches, there is no other flexible
108
+ // quantifier left for the file group to compete with, so it can safely
109
+ // allow parens here (measured linear: 0-5 ms even at 1 MiB of adversarial
110
+ // parens/colons with no valid ending). Tried before the general
111
+ // NODE_PAREN_RE, as the more specific shape (review N3; round 1's removal
112
+ // of the original, dedicated `HERMES_ADDRESS_RE` lost this case along with
113
+ // the then-redundant rest of it).
114
+ const HERMES_ADDRESS_PAREN_RE = /^at ([^\s(][^(]*?)? \((address at .*?):(\d+)(?::(\d+))?\)$/i;
115
+
116
+ // A V8/Hermes frame with no recognised scheme: "at name (file:line:col)"
117
+ // where the file is a relative bundle-internal path such as
118
+ // `index.android.bundle` or `InternalBytecode.js` (CHROME_RE's scheme
119
+ // whitelist rejects these) -- which also covers a Hermes release frame,
120
+ // "at name (address at file:line:col)", identically, when neither the name
121
+ // nor the file contain parentheses (see `HERMES_ADDRESS_PAREN_RE` above
122
+ // for when they do): the file group here is unrestricted (but for the
123
+ // parens `HERMES_ADDRESS_PAREN_RE` already tries first), so it captures
124
+ // "address at file" as one string exactly as a dedicated Hermes pattern
125
+ // would (`fileKey`/`cleanSource` then strip the "address at " prefix the
126
+ // same way). Or "at file:line:col" with no name and no parentheses at all
127
+ // (an anonymous top-level V8 frame). 6.x's `nodeRe`, split into two
128
+ // patterns rather than one with an optional " (" -- an optional
129
+ // single-character separator, tried at every position a same-shaped inner
130
+ // group could also stop at, reintroduces the same super-linear search C1
131
+ // fixes elsewhere (measured: the combined form hung past 3 s on a 1 MB
132
+ // adversarial "at /x" + spaces + "x" line with no trailing digits; each
133
+ // split half returns in under 5 ms on the same input). Tried after
134
+ // Chrome/V8 and Hermes-address-with-parens, and before JSC.
135
+ const NODE_PAREN_RE = /^at ([^\s(][^(]*?)? \(([^()]*?):(\d+)(?::(\d+))?\)$/i;
136
+ const NODE_BARE_RE = /^at ([^()]*?):(\d+)(?::(\d+))?$/i;
137
+
138
+ // JavaScriptCore: "name@file:line:col" (a name may itself contain spaces,
139
+ // as JSC's own "global code" frame does), "@file:line:col" (an anonymous
140
+ // frame -- an empty name, not one starting with whitespace), or just
141
+ // "file:line:col". Real captured JSC output has all three (review M2). The
142
+ // name, when non-empty, must start with a non-space, non-`@` character so
143
+ // it cannot start mid-run of the padding a hostile message might contain.
144
+ const JSC_RE = /^(?:([^@\s][^@]*)?@)?(\S.*?):(\d+)(?::(\d+))?$/i;
145
+
146
+ // A React `componentStack` line: "in ComponentName (at File.js:10)". Unlike
147
+ // the file-then-line-then-column groups above, whose separators are single
148
+ // literal characters, the name and the parenthesised part are separated by
149
+ // arbitrary whitespace in real output -- but that separator is `\s*`
150
+ // (matched inside the component-name group itself, then trimmed off in
151
+ // `parseComponentStack`) rather than its own quantifier between two other
152
+ // flexible groups: measured, a *separate* `\s*` there hung past 3 s on a
153
+ // 1 MB "in " + spaces + "x" line (the review's own C1 example), because it
154
+ // and the leading `in\s+` could both keep retrying the same run of spaces
155
+ // against each other. The file group has the same guard for the same
156
+ // reason: `\(at\s+` is followed by a file group whose first character must
157
+ // be non-space, so `\s+` and the file group cannot both keep re-trying the
158
+ // same run of spaces between "at" and the file either (review N1; the
159
+ // version without this guard measured 2 ms on a crafted 2 KiB line, which
160
+ // a chain of them then multiplies past budget). Both forms return in low
161
+ // single-digit milliseconds even at 1 MiB.
162
+ const COMPONENT_STACK_RE = /^in\s+([^\s(][^(]*?)?\(at\s+([^\s()][^()]*?):(\d+)(?::(\d+))?\)$/i;
163
+
164
+ const UNKNOWN = '<unknown>';
165
+
166
+ function parseChrome(line: string): ParsedFrame | null {
167
+ const parts = CHROME_RE.exec(line);
168
+ if (!parts) {
169
+ return null;
170
+ }
171
+
172
+ // Group 2 is mandatory in CHROME_RE, so it is always captured on a match.
173
+ const file = parts[2] as string;
174
+ const isNative = file.indexOf('native') === 0;
175
+
176
+ return {
177
+ raw: line,
178
+ file: isNative ? null : file,
179
+ methodName: parts[1] || null,
180
+ lineNumber: parts[3] ? Number(parts[3]) : null,
181
+ column: parts[4] ? Number(parts[4]) : null,
182
+ };
183
+ }
184
+
185
+ function parseNode(line: string): ParsedFrame | null {
186
+ const addressParen = HERMES_ADDRESS_PAREN_RE.exec(line);
187
+ if (addressParen) {
188
+ return {
189
+ raw: line,
190
+ // Group 2 is mandatory in HERMES_ADDRESS_PAREN_RE, so it is always captured on a match.
191
+ file: addressParen[2] as string,
192
+ methodName: addressParen[1] || null,
193
+ lineNumber: Number(addressParen[3]),
194
+ column: addressParen[4] ? Number(addressParen[4]) : null,
195
+ };
196
+ }
197
+
198
+ const paren = NODE_PAREN_RE.exec(line);
199
+ if (paren) {
200
+ return {
201
+ raw: line,
202
+ // Group 2 is mandatory in NODE_PAREN_RE, so it is always captured on a match.
203
+ file: paren[2] as string,
204
+ methodName: paren[1] || null,
205
+ lineNumber: Number(paren[3]),
206
+ column: paren[4] ? Number(paren[4]) : null,
207
+ };
208
+ }
209
+
210
+ const bare = NODE_BARE_RE.exec(line);
211
+ if (!bare) {
212
+ return null;
213
+ }
214
+
215
+ return {
216
+ raw: line,
217
+ // Group 1 is mandatory in NODE_BARE_RE, so it is always captured on a match.
218
+ file: bare[1] as string,
219
+ methodName: null,
220
+ lineNumber: Number(bare[2]),
221
+ column: bare[3] ? Number(bare[3]) : null,
222
+ };
223
+ }
224
+
225
+ function parseJsc(line: string): ParsedFrame | null {
226
+ const parts = JSC_RE.exec(line);
227
+ if (!parts) {
228
+ return null;
229
+ }
230
+
231
+ // Group 2 is mandatory in JSC_RE, so it is always captured on a match.
232
+ const file = parts[2] as string;
233
+
234
+ // A bare match (no "@" anywhere in the line -- not even an empty name
235
+ // before one) whose "file" contains ": " is a "Name: message" header
236
+ // line that stripKnownHeader could not identify (its name/message no
237
+ // longer match the stack, e.g. `message` was reassigned after the stack
238
+ // was captured), not a real file: a real path never contains ": '
239
+ // (review N2). `line.includes('@')` -- not `parts[1]` -- is the right
240
+ // check: an explicit empty name ("@file:1:2", a genuine JSC anonymous
241
+ // frame) also leaves `parts[1]` undefined, but must still be kept.
242
+ if (!line.includes('@') && file.includes(': ')) {
243
+ return null;
244
+ }
245
+
246
+ return {
247
+ raw: line,
248
+ file,
249
+ methodName: parts[1] || null,
250
+ lineNumber: Number(parts[3]),
251
+ column: parts[4] ? Number(parts[4]) : null,
252
+ };
253
+ }
254
+
255
+ function parseComponentStack(line: string): ParsedFrame | null {
256
+ const parts = COMPONENT_STACK_RE.exec(line);
257
+ if (!parts) {
258
+ return null;
259
+ }
260
+
261
+ // The component-name group has no separator of its own before "(at" (see
262
+ // COMPONENT_STACK_RE's comment), so it absorbs any whitespace before the
263
+ // parenthesis as part of its own match; trim that off here instead.
264
+ const name = parts[1]?.trimEnd();
265
+
266
+ return {
267
+ raw: line,
268
+ // Group 2 is mandatory in COMPONENT_STACK_RE, so it is always captured on a match.
269
+ file: parts[2] as string,
270
+ methodName: name || UNKNOWN,
271
+ lineNumber: Number(parts[3]),
272
+ column: parts[4] ? Number(parts[4]) : null,
273
+ };
274
+ }
275
+
276
+ /**
277
+ * Parses a JS stack (or a React `componentStack`) into frames, top first.
278
+ * Chrome/V8, a V8/Hermes frame with no recognised scheme (which also covers
279
+ * a Hermes release "address at" frame and a Metro-URL frame identically),
280
+ * JSC and "in X (at f:l)" lines are recognised; anything else -- the
281
+ * "Name: message" header (stripped by the caller before this runs, not
282
+ * here), a blank line, a line no pattern matches -- produces no frame and
283
+ * is skipped.
284
+ *
285
+ * Bounded against a hostile `stack` on every axis that matters: the input
286
+ * length, each line's length (`STACK_MAX_INPUT_LENGTH`/`STACK_MAX_LINE_LENGTH`),
287
+ * and the number of frames produced (`maxFrames`, stopped as soon as it is
288
+ * reached, so a stack with millions of matching lines does not keep going
289
+ * past the caller's own cap).
290
+ */
291
+ export function parseStack(
292
+ stack: string,
293
+ maxFrames: number = Number.POSITIVE_INFINITY,
294
+ ): ParsedFrame[] {
295
+ const frames: ParsedFrame[] = [];
296
+ const bounded = stack.length > STACK_MAX_INPUT_LENGTH ? stack.slice(0, STACK_MAX_INPUT_LENGTH) : stack;
297
+
298
+ for (const originalLine of bounded.split('\n')) {
299
+ if (frames.length >= maxFrames) {
300
+ break;
301
+ }
302
+
303
+ const raw =
304
+ originalLine.length > STACK_MAX_LINE_LENGTH
305
+ ? originalLine.slice(0, STACK_MAX_LINE_LENGTH)
306
+ : originalLine;
307
+ const trimmed = raw.trim();
308
+ if (trimmed.length === 0) {
309
+ continue;
310
+ }
311
+
312
+ const frame =
313
+ parseChrome(trimmed) ?? parseNode(trimmed) ?? parseJsc(trimmed) ?? parseComponentStack(trimmed);
314
+
315
+ if (frame) {
316
+ frames.push({ ...frame, raw });
317
+ }
318
+ }
319
+
320
+ return frames;
321
+ }
322
+
323
+ const FILE_SCHEME_RE = /^file:\/\//;
324
+ const ADDRESS_AT_RE = /^address at /;
325
+
326
+ /**
327
+ * Steps 1-2 of "The payload (exact)": strips a leading `file://` and then a
328
+ * leading `address at `. This is the join key between a registration stack's
329
+ * top frame and a crash frame's file (Task 7.3, R5) -- it is deliberately
330
+ * less aggressive than `cleanSource`, since steps 3-5 there would not agree
331
+ * between the two.
332
+ */
333
+ export function fileKey(file: string): string {
334
+ return file.replace(FILE_SCHEME_RE, '').replace(ADDRESS_AT_RE, '');
335
+ }
336
+
337
+ const IOS_APP_BUNDLE_RE = /^.*\/[^/]+\.app\//;
338
+ const IOS_DATA_CONTAINER_RE = /^\/var\/mobile\/Containers\/Data\/Application\/[^/]+\//;
339
+ const ANDROID_DATA_DIR_RE = /^\/data\/(?:data|user\/\d+)\/[^/]+\//;
340
+
341
+ /**
342
+ * Steps 1-5 of "The payload (exact)": `fileKey`, then strips an iOS app
343
+ * bundle path, the iOS data container and the Android data directory (where
344
+ * CodePush keeps bundles). `null` (no file) becomes `''`.
345
+ */
346
+ export function cleanSource(file: string | null): string {
347
+ if (file === null) {
348
+ return '';
349
+ }
350
+
351
+ return fileKey(file)
352
+ .replace(IOS_APP_BUNDLE_RE, '')
353
+ .replace(IOS_DATA_CONTAINER_RE, '')
354
+ .replace(ANDROID_DATA_DIR_RE, '');
355
+ }