@swiftbrowser/swift 0.1.0 → 0.3.0

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 (393) hide show
  1. package/Package.swift +200 -9
  2. package/README.md +7 -9
  3. package/Sources/AVFoundation/AVFoundation.swift +131 -0
  4. package/Sources/AVFoundation/Asset.swift +487 -0
  5. package/Sources/AVFoundation/AudioSession.swift +144 -0
  6. package/Sources/AVFoundation/CMTime.swift +303 -0
  7. package/Sources/AVFoundation/Capture.swift +688 -0
  8. package/Sources/AVFoundation/Player.swift +749 -0
  9. package/Sources/AVFoundation/PlayerView.swift +117 -0
  10. package/Sources/AVKit/AVKit.swift +132 -0
  11. package/Sources/Accelerate/Accelerate.swift +122 -0
  12. package/Sources/AppIntents/AppIntents.swift +144 -0
  13. package/Sources/AppIntents/Parameters.swift +220 -0
  14. package/Sources/AppIntents/Shortcuts.swift +159 -0
  15. package/Sources/AudioToolbox/AudioToolbox.swift +55 -0
  16. package/Sources/AuthenticationServices/AuthenticationServices.swift +257 -0
  17. package/Sources/AuthenticationServices/Authorization.swift +251 -0
  18. package/Sources/Charts/Charts.swift +0 -4
  19. package/Sources/Combine/AnyCancellable.swift +65 -0
  20. package/Sources/Combine/AnyPublisher.swift +148 -0
  21. package/Sources/Combine/AnySubscriber.swift +230 -0
  22. package/Sources/Combine/Cancellable.swift +35 -0
  23. package/Sources/Combine/Codable.swift +29 -0
  24. package/Sources/Combine/CombineIdentifier.swift +45 -0
  25. package/Sources/Combine/Concurrency/ConcurrencyHelpers.swift +24 -0
  26. package/Sources/Combine/Concurrency/Future+Concurrency.swift +136 -0
  27. package/Sources/Combine/Concurrency/GENERATED-Publisher+Concurrency.swift +397 -0
  28. package/Sources/Combine/CurrentValueSubject.swift +252 -0
  29. package/Sources/Combine/CustomCombineIdentifierConvertible.swift +28 -0
  30. package/Sources/Combine/Future.swift +228 -0
  31. package/Sources/Combine/GENERATED-RootProtocols.swift +426 -0
  32. package/Sources/Combine/Helpers/ConduitBase.swift +40 -0
  33. package/Sources/Combine/Helpers/ConduitList.swift +59 -0
  34. package/Sources/Combine/Helpers/DebugHook.swift +177 -0
  35. package/Sources/Combine/Helpers/FilterProducer.swift +174 -0
  36. package/Sources/Combine/Helpers/Locking.swift +30 -0
  37. package/Sources/Combine/Helpers/PartialCompletion.swift +26 -0
  38. package/Sources/Combine/Helpers/ReduceProducer.swift +249 -0
  39. package/Sources/Combine/Helpers/SubjectSubscriber.swift +96 -0
  40. package/Sources/Combine/Helpers/SubscriberTap.swift +69 -0
  41. package/Sources/Combine/Helpers/SubscriptionStatus.swift +33 -0
  42. package/Sources/Combine/Helpers/SubscriptionTap.swift +33 -0
  43. package/Sources/Combine/Helpers/Utils.swift +30 -0
  44. package/Sources/Combine/Helpers/Violations.swift +33 -0
  45. package/Sources/Combine/ImmediateScheduler.swift +178 -0
  46. package/Sources/Combine/LICENSE +21 -0
  47. package/Sources/Combine/NotificationPublisher.swift +48 -0
  48. package/Sources/Combine/ObjectWillChange.swift +46 -0
  49. package/Sources/Combine/PassthroughSubject.swift +222 -0
  50. package/Sources/Combine/Publisher+Subscribe.swift +53 -0
  51. package/Sources/Combine/Publishers/Deferred.swift +48 -0
  52. package/Sources/Combine/Publishers/Empty.swift +54 -0
  53. package/Sources/Combine/Publishers/Fail.swift +42 -0
  54. package/Sources/Combine/Publishers/GENERATED-Publishers.Catch.swift +673 -0
  55. package/Sources/Combine/Publishers/GENERATED-Publishers.Encode.swift +388 -0
  56. package/Sources/Combine/Publishers/GENERATED-Publishers.MapKeyPath.swift +384 -0
  57. package/Sources/Combine/Publishers/Just.swift +313 -0
  58. package/Sources/Combine/Publishers/Optional.Publisher.swift +315 -0
  59. package/Sources/Combine/Publishers/Publishers.AllSatisfy.swift +217 -0
  60. package/Sources/Combine/Publishers/Publishers.AssertNoFailure.swift +158 -0
  61. package/Sources/Combine/Publishers/Publishers.Autoconnect.swift +193 -0
  62. package/Sources/Combine/Publishers/Publishers.Breakpoint.swift +231 -0
  63. package/Sources/Combine/Publishers/Publishers.Buffer.swift +356 -0
  64. package/Sources/Combine/Publishers/Publishers.Collect.swift +102 -0
  65. package/Sources/Combine/Publishers/Publishers.CollectByCount.swift +195 -0
  66. package/Sources/Combine/Publishers/Publishers.CompactMap.swift +241 -0
  67. package/Sources/Combine/Publishers/Publishers.Comparison.swift +371 -0
  68. package/Sources/Combine/Publishers/Publishers.Concatenate.swift +474 -0
  69. package/Sources/Combine/Publishers/Publishers.Contains.swift +293 -0
  70. package/Sources/Combine/Publishers/Publishers.Count.swift +87 -0
  71. package/Sources/Combine/Publishers/Publishers.Debounce.swift +332 -0
  72. package/Sources/Combine/Publishers/Publishers.Delay.swift +269 -0
  73. package/Sources/Combine/Publishers/Publishers.Drop.swift +155 -0
  74. package/Sources/Combine/Publishers/Publishers.DropUntilOutput.swift +283 -0
  75. package/Sources/Combine/Publishers/Publishers.DropWhile.swift +378 -0
  76. package/Sources/Combine/Publishers/Publishers.Filter.swift +248 -0
  77. package/Sources/Combine/Publishers/Publishers.First.swift +261 -0
  78. package/Sources/Combine/Publishers/Publishers.FlatMap.swift +533 -0
  79. package/Sources/Combine/Publishers/Publishers.HandleEvents.swift +260 -0
  80. package/Sources/Combine/Publishers/Publishers.IgnoreOutput.swift +109 -0
  81. package/Sources/Combine/Publishers/Publishers.Last.swift +252 -0
  82. package/Sources/Combine/Publishers/Publishers.MakeConnectable.swift +82 -0
  83. package/Sources/Combine/Publishers/Publishers.Map.swift +351 -0
  84. package/Sources/Combine/Publishers/Publishers.MapError.swift +140 -0
  85. package/Sources/Combine/Publishers/Publishers.MeasureInterval.swift +187 -0
  86. package/Sources/Combine/Publishers/Publishers.Multicast.swift +284 -0
  87. package/Sources/Combine/Publishers/Publishers.Output.swift +241 -0
  88. package/Sources/Combine/Publishers/Publishers.PrefixUntilOutput.swift +197 -0
  89. package/Sources/Combine/Publishers/Publishers.PrefixWhile.swift +176 -0
  90. package/Sources/Combine/Publishers/Publishers.Print.swift +206 -0
  91. package/Sources/Combine/Publishers/Publishers.ReceiveOn.swift +227 -0
  92. package/Sources/Combine/Publishers/Publishers.Reduce.swift +204 -0
  93. package/Sources/Combine/Publishers/Publishers.RemoveDuplicates.swift +264 -0
  94. package/Sources/Combine/Publishers/Publishers.ReplaceEmpty.swift +201 -0
  95. package/Sources/Combine/Publishers/Publishers.ReplaceError.swift +211 -0
  96. package/Sources/Combine/Publishers/Publishers.Retry.swift +274 -0
  97. package/Sources/Combine/Publishers/Publishers.Scan.swift +331 -0
  98. package/Sources/Combine/Publishers/Publishers.Sequence.swift +437 -0
  99. package/Sources/Combine/Publishers/Publishers.SetFailureType.swift +120 -0
  100. package/Sources/Combine/Publishers/Publishers.Share.swift +104 -0
  101. package/Sources/Combine/Publishers/Publishers.SubscribeOn.swift +197 -0
  102. package/Sources/Combine/Publishers/Publishers.SwitchToLatest.swift +444 -0
  103. package/Sources/Combine/Publishers/Publishers.Throttle.swift +359 -0
  104. package/Sources/Combine/Publishers/Publishers.Timeout.swift +301 -0
  105. package/Sources/Combine/Publishers/Publishers.Zip.swift +720 -0
  106. package/Sources/Combine/Publishers/Publishers.swift +13 -0
  107. package/Sources/Combine/Publishers/Record.swift +237 -0
  108. package/Sources/Combine/Publishers/Result.Publisher.swift +337 -0
  109. package/Sources/Combine/Result.swift +46 -0
  110. package/Sources/Combine/Scheduler.swift +89 -0
  111. package/Sources/Combine/Schedulers.swift +211 -0
  112. package/Sources/Combine/Subject+Void.swift +17 -0
  113. package/Sources/Combine/Subscriber+Void.swift +20 -0
  114. package/Sources/Combine/Subscribers/Subscribers.Assign.swift +175 -0
  115. package/Sources/Combine/Subscribers/Subscribers.Completion.swift +90 -0
  116. package/Sources/Combine/Subscribers/Subscribers.Demand.swift +476 -0
  117. package/Sources/Combine/Subscribers/Subscribers.Sink.swift +206 -0
  118. package/Sources/Combine/Subscribers/Subscribers.swift +9 -0
  119. package/Sources/Combine/Subscription.swift +22 -0
  120. package/Sources/Combine/Subscriptions.swift +42 -0
  121. package/Sources/Combine/SwiftUIObservation.swift +10 -0
  122. package/Sources/Combine/_Introspection.swift +107 -0
  123. package/Sources/CommonCrypto/CommonCrypto.swift +80 -0
  124. package/Sources/Compression/Compression.swift +365 -0
  125. package/Sources/Compression/Deflate.swift +407 -0
  126. package/Sources/Compression/Zlib.swift +179 -0
  127. package/Sources/CoreFoundationTypes/CoreFoundationTypes.swift +101 -0
  128. package/Sources/CoreGraphics/CoreGraphics.swift +411 -0
  129. package/Sources/CoreGraphics/ProjectionTransforms.swift +28 -0
  130. package/Sources/CoreHaptics/CoreHaptics.swift +399 -0
  131. package/Sources/CoreImage/CIColor.swift +41 -0
  132. package/Sources/CoreImage/CIContext.swift +31 -0
  133. package/Sources/CoreImage/CIDetector.swift +57 -0
  134. package/Sources/CoreImage/CIFilter.swift +243 -0
  135. package/Sources/CoreImage/CIFilterBuiltins.swift +136 -0
  136. package/Sources/CoreImage/CIImage.swift +162 -0
  137. package/Sources/CoreImage/QRCode.swift +393 -0
  138. package/Sources/CoreLocation/Coordinate.swift +30 -0
  139. package/Sources/CoreLocation/Location.swift +65 -0
  140. package/Sources/CoreML/Evaluation.swift +414 -0
  141. package/Sources/CoreML/FeatureValue.swift +266 -0
  142. package/Sources/CoreML/Model.swift +269 -0
  143. package/Sources/CoreML/MultiArray.swift +92 -0
  144. package/Sources/CoreML/Specification.swift +233 -0
  145. package/Sources/CoreText/CoreText.swift +64 -0
  146. package/Sources/CoreTransferable/CoreTransferable.swift +606 -0
  147. package/Sources/CryptoKit/ChaChaPoly.swift +258 -0
  148. package/Sources/CryptoKit/CryptoKit.swift +375 -0
  149. package/Sources/CryptoKit/Curve25519.swift +317 -0
  150. package/Sources/CryptoKit/P256.swift +321 -0
  151. package/Sources/FoundationBridge/AppStorage.swift +165 -0
  152. package/Sources/FoundationBridge/AssetResources.swift +90 -0
  153. package/Sources/FoundationBridge/AsyncBytes.swift +128 -0
  154. package/Sources/FoundationBridge/AsyncImage.swift +116 -0
  155. package/Sources/FoundationBridge/AttributedStrings.swift +16 -0
  156. package/Sources/{_FoundationCommon → FoundationBridge}/Bundle.swift +41 -4
  157. package/Sources/FoundationBridge/CombineExports.swift +8 -0
  158. package/Sources/FoundationBridge/CoreFoundation.swift +77 -0
  159. package/Sources/FoundationBridge/Dispatch.swift +458 -0
  160. package/Sources/FoundationBridge/EnvironmentFoundation.swift +41 -0
  161. package/Sources/FoundationBridge/FileImporter.swift +128 -0
  162. package/Sources/FoundationBridge/FileSystem.swift +68 -0
  163. package/Sources/FoundationBridge/FoundationBridge.swift +24 -72
  164. package/Sources/FoundationBridge/HostResolution.swift +31 -0
  165. package/Sources/FoundationBridge/ItemProvider.swift +655 -0
  166. package/Sources/FoundationBridge/KeyValueObserving.swift +138 -0
  167. package/Sources/FoundationBridge/Links.swift +127 -0
  168. package/Sources/FoundationBridge/ListFormatter.swift +32 -0
  169. package/Sources/FoundationBridge/Localization.swift +149 -0
  170. package/Sources/FoundationBridge/Locks.swift +50 -0
  171. package/Sources/FoundationBridge/Markdown.swift +527 -0
  172. package/Sources/FoundationBridge/MeasurementFormat.swift +95 -0
  173. package/Sources/FoundationBridge/NotificationCenter.swift +154 -0
  174. package/Sources/FoundationBridge/OpenURLHandlers.swift +60 -0
  175. package/Sources/FoundationBridge/Operation.swift +195 -0
  176. package/Sources/FoundationBridge/ProcessInfo.swift +32 -0
  177. package/Sources/FoundationBridge/RelativeDateTimeFormatter.swift +136 -0
  178. package/Sources/FoundationBridge/SceneStorage.swift +78 -0
  179. package/Sources/FoundationBridge/SecurityExports.swift +8 -0
  180. package/Sources/FoundationBridge/Selector.swift +226 -0
  181. package/Sources/FoundationBridge/StringComparators.swift +17 -0
  182. package/Sources/FoundationBridge/Table.swift +211 -0
  183. package/Sources/FoundationBridge/TextAttributes.swift +42 -0
  184. package/Sources/FoundationBridge/Timer.swift +6 -1
  185. package/Sources/FoundationBridge/URLSession.swift +718 -0
  186. package/Sources/{_FoundationCommon → FoundationBridge}/UserDefaults.swift +17 -4
  187. package/Sources/FoundationBridge/WebAuthRedirects.swift +227 -0
  188. package/Sources/FoundationBridge/WebSocket.swift +187 -0
  189. package/Sources/FoundationModels/FoundationModels.swift +1098 -0
  190. package/Sources/ImageIO/GIF.swift +72 -0
  191. package/Sources/ImageIO/ImageIO.swift +248 -0
  192. package/Sources/ImageIO/ImageTypes.swift +28 -0
  193. package/Sources/LinkPresentation/LinkPresentation.swift +249 -0
  194. package/Sources/LocalAuthentication/LAContext.swift +86 -0
  195. package/Sources/MapKit/Geometry.swift +223 -0
  196. package/Sources/MapKit/Map.swift +638 -0
  197. package/Sources/MapKit/MapView.swift +229 -0
  198. package/Sources/MobileCoreServices/MobileCoreServices.swift +28 -0
  199. package/Sources/NaturalLanguage/LanguageIdentifier.swift +317 -0
  200. package/Sources/NaturalLanguage/NaturalLanguage.swift +135 -0
  201. package/Sources/OSLog/OSLog.swift +6 -0
  202. package/Sources/Photos/Photos.swift +572 -0
  203. package/Sources/PhotosUI/PhotosPicker.swift +248 -0
  204. package/Sources/PhotosUI/PhotosPickerItem.swift +261 -0
  205. package/Sources/QuickLook/QuickLook.swift +168 -0
  206. package/Sources/SafariServices/SafariServices.swift +106 -0
  207. package/Sources/Security/Security.swift +332 -0
  208. package/Sources/StoreKit/AppStore.swift +207 -0
  209. package/Sources/StoreKit/Products.swift +280 -0
  210. package/Sources/StoreKit/RequestReview.swift +28 -0
  211. package/Sources/StoreKit/StoreKit1.swift +486 -0
  212. package/Sources/StoreKit/StoreViews.swift +428 -0
  213. package/Sources/StoreKit/Transactions.swift +197 -0
  214. package/Sources/SwiftData/Macros.swift +58 -0
  215. package/Sources/SwiftData/ModelActor.swift +38 -0
  216. package/Sources/SwiftData/ModelContainer.swift +129 -0
  217. package/Sources/SwiftData/ModelContext.swift +451 -0
  218. package/Sources/SwiftData/PersistentModel.swift +238 -0
  219. package/Sources/SwiftData/Properties.swift +261 -0
  220. package/Sources/SwiftData/Query.swift +256 -0
  221. package/Sources/SwiftData/Schema.swift +192 -0
  222. package/Sources/SwiftData/Store.swift +146 -0
  223. package/Sources/SwiftData/StringPredicates.swift +125 -0
  224. package/Sources/SwiftDataMacros/EntryMacro.swift +82 -0
  225. package/Sources/SwiftDataMacros/GenerableMacro.swift +183 -0
  226. package/Sources/SwiftDataMacros/ModelActorMacro.swift +46 -0
  227. package/Sources/SwiftDataMacros/ModelMacro.swift +260 -0
  228. package/Sources/SwiftDataMacros/Plugin.swift +18 -0
  229. package/Sources/SwiftDataMacros/PredicateMacro.swift +1244 -0
  230. package/Sources/SwiftUI/API/Accessibility.swift +55 -6
  231. package/Sources/SwiftUI/API/AccessibilityExtras.swift +33 -0
  232. package/Sources/SwiftUI/API/AccessibilityFocus.swift +63 -0
  233. package/Sources/SwiftUI/API/Alert.swift +1 -1
  234. package/Sources/SwiftUI/API/AlignmentGuides.swift +68 -0
  235. package/Sources/SwiftUI/API/Animation.swift +37 -5
  236. package/Sources/SwiftUI/API/App.swift +31 -1
  237. package/Sources/SwiftUI/API/BindingCollections.swift +35 -0
  238. package/Sources/SwiftUI/API/BindingForEach.swift +27 -0
  239. package/Sources/SwiftUI/API/Bitmaps.swift +254 -0
  240. package/Sources/SwiftUI/API/ButtonStyles.swift +96 -0
  241. package/Sources/SwiftUI/API/Canvas.swift +337 -0
  242. package/Sources/SwiftUI/API/Color.swift +104 -28
  243. package/Sources/SwiftUI/API/ColorEffects.swift +52 -0
  244. package/Sources/SwiftUI/API/ColorPickerAndLabeledContent.swift +138 -0
  245. package/Sources/SwiftUI/API/ColorSpaces.swift +161 -0
  246. package/Sources/SwiftUI/API/Commands.swift +106 -0
  247. package/Sources/SwiftUI/API/ContainerBackground.swift +28 -0
  248. package/Sources/SwiftUI/API/ContentShape.swift +33 -0
  249. package/Sources/SwiftUI/API/ContentSizeCategory.swift +35 -0
  250. package/Sources/SwiftUI/API/ContentUnavailable.swift +101 -0
  251. package/Sources/SwiftUI/API/Controls.swift +59 -27
  252. package/Sources/SwiftUI/API/CustomLayout.swift +49 -10
  253. package/Sources/SwiftUI/API/CustomToolbarContent.swift +46 -0
  254. package/Sources/SwiftUI/API/Decorations.swift +1 -1
  255. package/Sources/SwiftUI/API/EditMode.swift +25 -82
  256. package/Sources/SwiftUI/API/Effects.swift +125 -10
  257. package/Sources/SwiftUI/API/Entry.swift +8 -0
  258. package/Sources/SwiftUI/API/Environment.swift +100 -9
  259. package/Sources/SwiftUI/API/EnvironmentSendable.swift +6 -0
  260. package/Sources/SwiftUI/API/Focus.swift +11 -3
  261. package/Sources/SwiftUI/API/Gauge.swift +26 -10
  262. package/Sources/SwiftUI/API/GeometryEffects.swift +232 -0
  263. package/Sources/SwiftUI/API/GeometryReader.swift +13 -2
  264. package/Sources/SwiftUI/API/GestureState.swift +65 -0
  265. package/Sources/SwiftUI/API/Gestures.swift +1 -1
  266. package/Sources/SwiftUI/API/Glass.swift +127 -0
  267. package/Sources/SwiftUI/API/Grid.swift +1 -1
  268. package/Sources/SwiftUI/API/GroupBoxAndControlGroup.swift +130 -0
  269. package/Sources/SwiftUI/API/KeyPress.swift +54 -0
  270. package/Sources/SwiftUI/API/LabelStyle.swift +13 -6
  271. package/Sources/SwiftUI/API/Layout.swift +71 -12
  272. package/Sources/SwiftUI/API/LazyStacks.swift +49 -0
  273. package/Sources/SwiftUI/API/LegacyAlert.swift +97 -0
  274. package/Sources/SwiftUI/API/Lists.swift +61 -6
  275. package/Sources/SwiftUI/API/Menu.swift +8 -1
  276. package/Sources/SwiftUI/API/Modifiers.swift +88 -12
  277. package/Sources/SwiftUI/API/MoreModifiers.swift +100 -0
  278. package/Sources/SwiftUI/API/Namespace.swift +44 -0
  279. package/Sources/SwiftUI/API/Navigation.swift +24 -9
  280. package/Sources/SwiftUI/API/NavigationDestinationBindings.swift +55 -0
  281. package/Sources/SwiftUI/API/ObservableObject.swift +16 -2
  282. package/Sources/SwiftUI/API/Path.swift +543 -0
  283. package/Sources/SwiftUI/API/Phase8Controls.swift +48 -31
  284. package/Sources/SwiftUI/API/PhaseAnimator.swift +130 -0
  285. package/Sources/SwiftUI/API/Picker.swift +14 -4
  286. package/Sources/SwiftUI/API/PointerAndKeyboard.swift +77 -0
  287. package/Sources/SwiftUI/API/Popover.swift +41 -0
  288. package/Sources/SwiftUI/API/Preferences.swift +262 -0
  289. package/Sources/SwiftUI/API/Presentation.swift +17 -4
  290. package/Sources/SwiftUI/API/PresentationExtras.swift +60 -0
  291. package/Sources/SwiftUI/API/Primitives.swift +168 -39
  292. package/Sources/SwiftUI/API/Publishers.swift +4 -4
  293. package/Sources/SwiftUI/API/Redaction.swift +75 -0
  294. package/Sources/SwiftUI/API/RowActions.swift +3 -2
  295. package/Sources/SwiftUI/API/Scenes.swift +131 -0
  296. package/Sources/SwiftUI/API/ScrollModifiers.swift +132 -0
  297. package/Sources/SwiftUI/API/ScrollTargets.swift +3 -3
  298. package/Sources/SwiftUI/API/ScrollViewReader.swift +144 -0
  299. package/Sources/SwiftUI/API/SectionSupplements.swift +86 -0
  300. package/Sources/SwiftUI/API/Shape.swift +214 -0
  301. package/Sources/SwiftUI/API/ShapeStyle.swift +187 -8
  302. package/Sources/SwiftUI/API/ShapeTrim.swift +78 -0
  303. package/Sources/SwiftUI/API/Sharing.swift +193 -0
  304. package/Sources/SwiftUI/API/StackLayouts.swift +199 -0
  305. package/Sources/SwiftUI/API/State.swift +18 -1
  306. package/Sources/SwiftUI/API/StatusGaps.swift +121 -0
  307. package/Sources/SwiftUI/API/SymbolEffects.swift +203 -0
  308. package/Sources/SwiftUI/API/TabContent.swift +841 -0
  309. package/Sources/SwiftUI/API/Table.swift +382 -0
  310. package/Sources/SwiftUI/API/Tabs.swift +148 -4
  311. package/Sources/SwiftUI/API/Tasks.swift +2 -2
  312. package/Sources/SwiftUI/API/Text.swift +386 -0
  313. package/Sources/SwiftUI/API/TextDates.swift +61 -0
  314. package/Sources/SwiftUI/API/TextDecorations.swift +52 -0
  315. package/Sources/SwiftUI/API/TextFieldAxis.swift +103 -0
  316. package/Sources/SwiftUI/API/TextFieldCommit.swift +52 -0
  317. package/Sources/SwiftUI/API/Toolbar.swift +52 -16
  318. package/Sources/SwiftUI/API/Transfer.swift +145 -0
  319. package/Sources/SwiftUI/API/UnevenRoundedRectangle.swift +66 -0
  320. package/Sources/SwiftUI/API/Video.swift +64 -0
  321. package/Sources/SwiftUI/API/View.swift +46 -2
  322. package/Sources/SwiftUI/API/ViewModifier.swift +4 -1
  323. package/Sources/SwiftUI/API/VisualEffect.swift +74 -1
  324. package/Sources/SwiftUI/API/Windows.swift +25 -0
  325. package/Sources/SwiftUI/Charts/Axis.swift +7 -1
  326. package/Sources/SwiftUI/Charts/AxisFormatsAndRanges.swift +68 -0
  327. package/Sources/SwiftUI/Charts/Chart.swift +17 -3
  328. package/Sources/SwiftUI/Charts/ChartProxy.swift +57 -0
  329. package/Sources/SwiftUI/Localization/Localization.swift +524 -0
  330. package/Sources/SwiftUI/Localization/PluralRules.swift +127 -0
  331. package/Sources/SwiftUI/Runtime/Executor.swift +2 -0
  332. package/Sources/SwiftUI/Runtime/Exports.swift +37 -1
  333. package/Sources/SwiftUI/Runtime/ImageSource.swift +310 -0
  334. package/Sources/SwiftUI/Runtime/JSON.swift +76 -4
  335. package/Sources/SwiftUI/Runtime/LazyRows.swift +99 -0
  336. package/Sources/SwiftUI/Runtime/Measurements.swift +140 -0
  337. package/Sources/SwiftUI/Runtime/Ops.swift +58 -12
  338. package/Sources/SwiftUI/Runtime/Reconciler.swift +10 -1
  339. package/Sources/SwiftUI/Runtime/Replay.swift +382 -0
  340. package/Sources/SwiftUI/Runtime/Runtime.swift +977 -198
  341. package/Sources/SwiftUI/Runtime/Sameness.swift +152 -0
  342. package/Sources/SwiftUI/Runtime/ViewPath.swift +89 -0
  343. package/Sources/SwiftUI/Runtime/ViewTraits.swift +175 -0
  344. package/Sources/SwiftUI/Runtime/WebAuthHeadless.swift +49 -0
  345. package/Sources/Symbols/Symbols.swift +25 -0
  346. package/Sources/Translation/Translation.swift +423 -0
  347. package/Sources/UIKit/Activity.swift +213 -0
  348. package/Sources/UIKit/Alerts.swift +69 -0
  349. package/Sources/UIKit/AppDelegate.swift +222 -0
  350. package/Sources/UIKit/Appearance.swift +84 -0
  351. package/Sources/UIKit/ColorConversions.swift +70 -0
  352. package/Sources/UIKit/Controls.swift +225 -0
  353. package/Sources/UIKit/Device.swift +200 -0
  354. package/Sources/UIKit/Feedback.swift +65 -0
  355. package/Sources/UIKit/Font.swift +307 -0
  356. package/Sources/UIKit/Graphics.swift +204 -0
  357. package/Sources/UIKit/HostingController.swift +185 -0
  358. package/Sources/UIKit/Identity.swift +24 -0
  359. package/Sources/UIKit/Introspectable.swift +510 -0
  360. package/Sources/UIKit/Pasteboard.swift +363 -0
  361. package/Sources/UIKit/PhotoAlbum.swift +81 -0
  362. package/Sources/UIKit/RemoteNotifications.swift +15 -0
  363. package/Sources/UIKit/Representable.swift +288 -0
  364. package/Sources/UIKit/SafeArea.swift +12 -0
  365. package/Sources/UIKit/SceneDelegates.swift +132 -0
  366. package/Sources/UIKit/Scenes.swift +40 -0
  367. package/Sources/UIKit/ScrollView.swift +157 -0
  368. package/Sources/UIKit/ShortcutItems.swift +67 -0
  369. package/Sources/UIKit/SymbolConfiguration.swift +124 -0
  370. package/Sources/UIKit/TargetAction.swift +123 -0
  371. package/Sources/UIKit/TextPaste.swift +161 -0
  372. package/Sources/UIKit/TextView.swift +538 -0
  373. package/Sources/UIKit/UIKit.swift +292 -0
  374. package/Sources/UIKit/UIView.swift +855 -0
  375. package/Sources/UIKit/ViewTranslation.swift +311 -0
  376. package/Sources/UniformTypeIdentifiers/UTType.swift +196 -0
  377. package/Sources/UserNotifications/Content.swift +370 -0
  378. package/Sources/UserNotifications/NotificationCenter.swift +309 -0
  379. package/Sources/WeatherKit/WeatherKit.swift +228 -0
  380. package/Sources/WebKit/WebKit.swift +245 -0
  381. package/Sources/os/os.swift +376 -0
  382. package/Sources/zlib/zlib.swift +6 -0
  383. package/index.d.ts +1 -1
  384. package/index.mjs +2 -2
  385. package/manifest.d.mts +2 -0
  386. package/manifest.mjs +41 -0
  387. package/package.json +5 -3
  388. package/sync-sources.mjs +21 -7
  389. package/Sources/FoundationLite/Common.swift +0 -3
  390. package/Sources/FoundationLite/FoundationLite.swift +0 -171
  391. package/Sources/FoundationLite/Interaction.swift +0 -146
  392. package/Sources/FoundationLite/Timer.swift +0 -48
  393. package/Sources/_FoundationCommon/_FoundationCommon.swift +0 -10
@@ -0,0 +1,317 @@
1
+ // Curve25519: Ed25519 signatures (`Curve25519.Signing`, RFC 8032) and X25519
2
+ // key agreement (`Curve25519.KeyAgreement`, RFC 7748), in plain Swift over
3
+ // the Montgomery field arithmetic of P256.swift (RevenueCat verifies its
4
+ // server's signed responses with an Ed25519 public key). Points on the
5
+ // Edwards curve use extended coordinates. As with P-256, nothing here is
6
+ // constant-time: fine for keys the page makes and checks, not for a server.
7
+ // Signatures are deterministic (RFC 8032); CryptoKit's add randomness, and
8
+ // either kind verifies with either implementation.
9
+
10
+ import struct Foundation.Data
11
+ import protocol Foundation.ContiguousBytes
12
+ import protocol Foundation.DataProtocol
13
+
14
+ public enum Curve25519 {
15
+ public enum Signing {
16
+ public struct PrivateKey: Sendable {
17
+ /// The 32-byte seed.
18
+ let seed: [UInt8]
19
+ let scalar: _U256
20
+ let prefix: [UInt8]
21
+ public let publicKey: PublicKey
22
+
23
+ /// A new random key.
24
+ public init() {
25
+ var generator = SystemRandomNumberGenerator()
26
+ self.init(seed: (0..<32).map { _ in UInt8.random(in: .min ... .max, using: &generator) })
27
+ }
28
+
29
+ /// The 32-byte seed.
30
+ public init<D: ContiguousBytes>(rawRepresentation data: D) throws {
31
+ let seed = data.withUnsafeBytes { Array($0) }
32
+ guard seed.count == 32 else { throw CryptoKitError.incorrectKeySize }
33
+ self.init(seed: seed)
34
+ }
35
+
36
+ init(seed: [UInt8]) {
37
+ self.seed = seed
38
+ let hash = Array(SHA512.hash(data: seed))
39
+ var clamped = Array(hash[0..<32])
40
+ clamped[0] &= 248
41
+ clamped[31] &= 127
42
+ clamped[31] |= 64
43
+ scalar = _U256(littleEndian: clamped)
44
+ prefix = Array(hash[32..<64])
45
+ publicKey = PublicKey(encoded: _Ed25519.encode(_Ed25519.multiply(_Ed25519.base, by: scalar)))
46
+ }
47
+
48
+ public var rawRepresentation: Data { Data(seed) }
49
+
50
+ /// The 64-byte signature `R ‖ S` of `data`.
51
+ public func signature<D: DataProtocol>(for data: D) throws -> Data {
52
+ let message = Array(data)
53
+ let r = _Ed25519.reducedHash(prefix + message)
54
+ let encodedR = _Ed25519.encode(_Ed25519.multiply(_Ed25519.base, by: r))
55
+ let k = _Ed25519.reducedHash(encodedR + publicKey.encoded + message)
56
+ let s = _Ed25519.scalars.add(r, _Ed25519.scalarProduct(k, _Ed25519.reduced(scalar)))
57
+ return Data(encodedR + s.littleEndianBytes)
58
+ }
59
+ }
60
+
61
+ public struct PublicKey: Sendable {
62
+ let encoded: [UInt8]
63
+
64
+ init(encoded: [UInt8]) { self.encoded = encoded }
65
+
66
+ /// The 32-byte encoded point.
67
+ public init<D: ContiguousBytes>(rawRepresentation data: D) throws {
68
+ let bytes = data.withUnsafeBytes { Array($0) }
69
+ guard bytes.count == 32 else { throw CryptoKitError.incorrectKeySize }
70
+ guard _Ed25519.decode(bytes) != nil else { throw CryptoKitError.invalidParameter }
71
+ encoded = bytes
72
+ }
73
+
74
+ public var rawRepresentation: Data { Data(encoded) }
75
+
76
+ /// Whether `signature` is this key's signature of `data`.
77
+ public func isValidSignature<S: DataProtocol, D: DataProtocol>(_ signature: S, for data: D) -> Bool {
78
+ let signature = Array(signature)
79
+ guard signature.count == 64, let point = _Ed25519.decode(encoded) else { return false }
80
+ let encodedR = Array(signature[0..<32])
81
+ let s = _U256(littleEndian: Array(signature[32..<64]))
82
+ guard s < _Ed25519.l else { return false }
83
+ let k = _Ed25519.reducedHash(encodedR + encoded + Array(data))
84
+ // [S]B − [k]A must be R.
85
+ let sB = _Ed25519.multiply(_Ed25519.base, by: s)
86
+ let kA = _Ed25519.multiply(point, by: k)
87
+ return _Ed25519.encode(_Ed25519.add(sB, _Ed25519.negate(kA))) == encodedR
88
+ }
89
+ }
90
+ }
91
+
92
+ public enum KeyAgreement {
93
+ public struct PrivateKey: Sendable {
94
+ let bytes: [UInt8]
95
+
96
+ /// A new random key.
97
+ public init() {
98
+ var generator = SystemRandomNumberGenerator()
99
+ bytes = (0..<32).map { _ in UInt8.random(in: .min ... .max, using: &generator) }
100
+ }
101
+
102
+ public init<D: ContiguousBytes>(rawRepresentation data: D) throws {
103
+ let bytes = data.withUnsafeBytes { Array($0) }
104
+ guard bytes.count == 32 else { throw CryptoKitError.incorrectKeySize }
105
+ self.bytes = bytes
106
+ }
107
+
108
+ public var rawRepresentation: Data { Data(bytes) }
109
+
110
+ public var publicKey: PublicKey { PublicKey(bytes: _X25519.multiply(bytes, _X25519.basePoint)) }
111
+
112
+ /// X25519 of this key and `publicKeyShare`; an all-zero result (a
113
+ /// point of small order) is refused, as CryptoKit refuses it.
114
+ public func sharedSecretFromKeyAgreement(with publicKeyShare: PublicKey) throws -> SharedSecret {
115
+ let shared = _X25519.multiply(bytes, publicKeyShare.bytes)
116
+ guard shared.contains(where: { $0 != 0 }) else { throw CryptoKitError.invalidParameter }
117
+ return SharedSecret(bytes: shared)
118
+ }
119
+ }
120
+
121
+ public struct PublicKey: Sendable {
122
+ let bytes: [UInt8]
123
+
124
+ init(bytes: [UInt8]) { self.bytes = bytes }
125
+
126
+ public init<D: ContiguousBytes>(rawRepresentation data: D) throws {
127
+ let bytes = data.withUnsafeBytes { Array($0) }
128
+ guard bytes.count == 32 else { throw CryptoKitError.incorrectKeySize }
129
+ self.bytes = bytes
130
+ }
131
+
132
+ public var rawRepresentation: Data { Data(bytes) }
133
+ }
134
+ }
135
+ }
136
+
137
+ // MARK: - Little-endian integers
138
+
139
+ extension _U256 {
140
+ init(littleEndian bytes: [UInt8]) { self.init(bigEndian: bytes.reversed()) }
141
+ var littleEndianBytes: [UInt8] { bigEndianBytes.reversed() }
142
+ }
143
+
144
+ // MARK: - The field and the Edwards curve
145
+
146
+ enum _Ed25519 {
147
+ /// 2²⁵⁵ − 19.
148
+ static let p = _U256([0xFFFF_FFFF_FFFF_FFED, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x7FFF_FFFF_FFFF_FFFF])
149
+ /// The order of the base point, 2²⁵² + 27742317777372353535851937790883648493.
150
+ static let l = _U256([0x5812_631A_5CF5_D3ED, 0x14DE_F9DE_A2F7_9CD6, 0, 0x1000_0000_0000_0000])
151
+ static let field = _MontgomeryField(modulus: p)
152
+ static let scalars = _MontgomeryField(modulus: l)
153
+
154
+ static let one = field.toMontgomery(_U256([1, 0, 0, 0]))
155
+ static let zero = _U256([0, 0, 0, 0])
156
+ /// −121665/121666, in Montgomery form.
157
+ static let d = field.multiply(field.subtract(zero, field.toMontgomery(_U256([121_665, 0, 0, 0]))),
158
+ field.inverse(field.toMontgomery(_U256([121_666, 0, 0, 0]))))
159
+ static let d2 = field.add(d, d)
160
+ /// √−1 = 2^((p−1)/4).
161
+ static let sqrtMinusOne = power(field.toMontgomery(_U256([2, 0, 0, 0])),
162
+ _U256([0xFFFF_FFFF_FFFF_FFFB, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x1FFF_FFFF_FFFF_FFFF]))
163
+ /// y = 4/5 with even x.
164
+ static let base: Point = {
165
+ let y = field.fromMontgomery(field.multiply(field.toMontgomery(_U256([4, 0, 0, 0])),
166
+ field.inverse(field.toMontgomery(_U256([5, 0, 0, 0])))))
167
+ return decode(y.littleEndianBytes)!
168
+ }()
169
+
170
+ /// A point in extended coordinates (Montgomery form): x = X/Z, y = Y/Z, xy = T/Z.
171
+ struct Point: Sendable {
172
+ var x, y, z, t: _U256
173
+ }
174
+
175
+ static let identity = Point(x: zero, y: one, z: one, t: zero)
176
+
177
+ static func power(_ base: _U256, _ exponent: _U256) -> _U256 {
178
+ var result = one
179
+ for index in (0..<256).reversed() {
180
+ result = field.multiply(result, result)
181
+ if exponent.bit(index) { result = field.multiply(result, base) }
182
+ }
183
+ return result
184
+ }
185
+
186
+ /// The point a 32-byte encoding names, or nil when it names none.
187
+ static func decode(_ bytes: [UInt8]) -> Point? {
188
+ guard bytes.count == 32 else { return nil }
189
+ var yBytes = bytes
190
+ let sign = yBytes[31] >> 7
191
+ yBytes[31] &= 0x7F
192
+ let yPlain = _U256(littleEndian: yBytes)
193
+ guard yPlain < p else { return nil }
194
+ let y = field.toMontgomery(yPlain)
195
+ let y2 = field.multiply(y, y)
196
+ let u = field.subtract(y2, one)
197
+ let v = field.add(field.multiply(d, y2), one)
198
+ // x = u·v³·(u·v⁷)^((p−5)/8)
199
+ let v3 = field.multiply(field.multiply(v, v), v)
200
+ let v7 = field.multiply(field.multiply(v3, v3), v)
201
+ let exponent = _U256([0xFFFF_FFFF_FFFF_FFFD, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0FFF_FFFF_FFFF_FFFF])
202
+ var x = field.multiply(field.multiply(u, v3), power(field.multiply(u, v7), exponent))
203
+ let vx2 = field.multiply(v, field.multiply(x, x))
204
+ if vx2 == u {
205
+ // x is a root.
206
+ } else if vx2 == field.subtract(zero, u) {
207
+ x = field.multiply(x, sqrtMinusOne)
208
+ } else {
209
+ return nil
210
+ }
211
+ let xPlain = field.fromMontgomery(x)
212
+ if xPlain.isZero && sign == 1 { return nil }
213
+ if UInt8(xPlain.limbs[0] & 1) != sign { x = field.subtract(zero, x) }
214
+ return Point(x: x, y: y, z: one, t: field.multiply(x, y))
215
+ }
216
+
217
+ static func encode(_ point: Point) -> [UInt8] {
218
+ let inverse = field.inverse(point.z)
219
+ let x = field.fromMontgomery(field.multiply(point.x, inverse))
220
+ var bytes = field.fromMontgomery(field.multiply(point.y, inverse)).littleEndianBytes
221
+ bytes[31] |= UInt8(x.limbs[0] & 1) << 7
222
+ return bytes
223
+ }
224
+
225
+ /// The sum of two points (unified: also doubles).
226
+ static func add(_ p1: Point, _ p2: Point) -> Point {
227
+ let a = field.multiply(field.subtract(p1.y, p1.x), field.subtract(p2.y, p2.x))
228
+ let b = field.multiply(field.add(p1.y, p1.x), field.add(p2.y, p2.x))
229
+ let c = field.multiply(field.multiply(p1.t, d2), p2.t)
230
+ let zz = field.multiply(p1.z, p2.z)
231
+ let dd = field.add(zz, zz)
232
+ let e = field.subtract(b, a)
233
+ let f = field.subtract(dd, c)
234
+ let g = field.add(dd, c)
235
+ let h = field.add(b, a)
236
+ return Point(x: field.multiply(e, f), y: field.multiply(g, h), z: field.multiply(f, g), t: field.multiply(e, h))
237
+ }
238
+
239
+ static func negate(_ point: Point) -> Point {
240
+ Point(x: field.subtract(zero, point.x), y: point.y, z: point.z, t: field.subtract(zero, point.t))
241
+ }
242
+
243
+ static func multiply(_ point: Point, by scalar: _U256) -> Point {
244
+ var result = identity
245
+ for index in (0..<256).reversed() {
246
+ result = add(result, result)
247
+ if scalar.bit(index) { result = add(result, point) }
248
+ }
249
+ return result
250
+ }
251
+
252
+ // MARK: Scalars modulo l
253
+
254
+ /// `x` mod l, for any 256-bit `x` (plain form in and out).
255
+ static func reduced(_ x: _U256) -> _U256 { scalars.fromMontgomery(scalars.toMontgomery(x)) }
256
+
257
+ /// SHA-512 of `bytes`, as a little-endian integer mod l.
258
+ static func reducedHash(_ bytes: [UInt8]) -> _U256 {
259
+ let hash = Array(SHA512.hash(data: bytes))
260
+ let low = _U256(littleEndian: Array(hash[0..<32]))
261
+ let high = _U256(littleEndian: Array(hash[32..<64]))
262
+ // high·2²⁵⁶ + low: toMontgomery(high) is high·2²⁵⁶ mod l.
263
+ return scalars.add(scalars.toMontgomery(high), reduced(low))
264
+ }
265
+
266
+ /// a·b mod l (plain form).
267
+ static func scalarProduct(_ a: _U256, _ b: _U256) -> _U256 {
268
+ scalars.fromMontgomery(scalars.multiply(scalars.toMontgomery(a), scalars.toMontgomery(b)))
269
+ }
270
+ }
271
+
272
+
273
+ // MARK: - X25519
274
+
275
+ enum _X25519 {
276
+ static let basePoint: [UInt8] = [9] + [UInt8](repeating: 0, count: 31)
277
+
278
+ /// The Montgomery ladder of RFC 7748: the u-coordinate of `scalar`·`u`.
279
+ static func multiply(_ scalarBytes: [UInt8], _ uBytes: [UInt8]) -> [UInt8] {
280
+ let field = _Ed25519.field
281
+ var k = scalarBytes
282
+ k[0] &= 248
283
+ k[31] &= 127
284
+ k[31] |= 64
285
+ let scalar = _U256(littleEndian: k)
286
+ var uMasked = uBytes
287
+ uMasked[31] &= 127
288
+ var uPlain = _U256(littleEndian: uMasked)
289
+ if !(uPlain < _Ed25519.p) { uPlain = uPlain.subtracting(_Ed25519.p).0 }
290
+ let x1 = field.toMontgomery(uPlain)
291
+ let a24 = field.toMontgomery(_U256([121_665, 0, 0, 0]))
292
+ var (x2, z2, x3, z3) = (_Ed25519.one, _Ed25519.zero, x1, _Ed25519.one)
293
+ var swapped = false
294
+ for index in (0..<255).reversed() {
295
+ let bit = scalar.bit(index)
296
+ if swapped != bit { swap(&x2, &x3); swap(&z2, &z3) }
297
+ swapped = bit
298
+ let a = field.add(x2, z2)
299
+ let aa = field.multiply(a, a)
300
+ let b = field.subtract(x2, z2)
301
+ let bb = field.multiply(b, b)
302
+ let e = field.subtract(aa, bb)
303
+ let c = field.add(x3, z3)
304
+ let dd = field.subtract(x3, z3)
305
+ let da = field.multiply(dd, a)
306
+ let cb = field.multiply(c, b)
307
+ let sum = field.add(da, cb)
308
+ let difference = field.subtract(da, cb)
309
+ x3 = field.multiply(sum, sum)
310
+ z3 = field.multiply(x1, field.multiply(difference, difference))
311
+ x2 = field.multiply(aa, bb)
312
+ z2 = field.multiply(e, field.add(aa, field.multiply(a24, e)))
313
+ }
314
+ if swapped { swap(&x2, &x3); swap(&z2, &z3) }
315
+ return field.fromMontgomery(field.multiply(x2, field.inverse(z2))).littleEndianBytes
316
+ }
317
+ }
@@ -0,0 +1,321 @@
1
+ // P-256 key agreement (`P256.KeyAgreement`): private keys, their public
2
+ // keys in CryptoKit's representations, and ECDH shared secrets, computed in
3
+ // plain Swift (Ice Cubes registers a P-256 public key with its push relay).
4
+ // Field elements are four 64-bit limbs in Montgomery form; points use
5
+ // Jacobian coordinates. The scalar multiplication is not constant-time:
6
+ // fine for keys the page makes and keeps for itself, not for a server.
7
+ // P-256 signing, HKDF and AES are not here (Curve25519.swift and
8
+ // ChaChaPoly.swift have the other curve and cipher).
9
+
10
+ import struct Foundation.Data
11
+ import protocol Foundation.DataProtocol
12
+
13
+ public enum CryptoKitError: Error, Equatable, Sendable {
14
+ case incorrectKeySize
15
+ case incorrectParameterSize
16
+ case invalidParameter
17
+ case underlyingCoreCryptoError(error: Int32)
18
+ case authenticationFailure
19
+ }
20
+
21
+ public enum P256 {
22
+ public enum KeyAgreement {
23
+ public struct PrivateKey: Sendable {
24
+ let scalar: _U256
25
+
26
+ /// A new random key.
27
+ public init(compactRepresentable: Bool = true) {
28
+ var generator = SystemRandomNumberGenerator()
29
+ while true {
30
+ let candidate = _U256((0..<4).map { _ in generator.next() as UInt64 })
31
+ if !candidate.isZero && candidate < _P256.n { scalar = candidate; return }
32
+ }
33
+ }
34
+
35
+ /// The 32-byte big-endian scalar.
36
+ public init<D: DataProtocol>(rawRepresentation data: D) throws {
37
+ let bytes = Array(data)
38
+ guard bytes.count == 32 else { throw CryptoKitError.incorrectKeySize }
39
+ let scalar = _U256(bigEndian: bytes)
40
+ guard !scalar.isZero, scalar < _P256.n else { throw CryptoKitError.invalidParameter }
41
+ self.scalar = scalar
42
+ }
43
+
44
+ public var rawRepresentation: Data { Data(scalar.bigEndianBytes) }
45
+
46
+ public var publicKey: PublicKey { PublicKey(point: _P256.multiply(_P256.generator, by: scalar)) }
47
+
48
+ /// The x coordinate of this key times `publicKeyShare`.
49
+ public func sharedSecretFromKeyAgreement(with publicKeyShare: PublicKey) throws -> SharedSecret {
50
+ let point = _P256.multiply(publicKeyShare.point, by: scalar)
51
+ return SharedSecret(bytes: point.x.bigEndianBytes)
52
+ }
53
+ }
54
+
55
+ public struct PublicKey: Sendable {
56
+ let point: _P256.Affine
57
+
58
+ init(point: _P256.Affine) { self.point = point }
59
+
60
+ /// `04 ‖ x ‖ y` (65 bytes).
61
+ public init<D: DataProtocol>(x963Representation data: D) throws {
62
+ let bytes = Array(data)
63
+ guard bytes.count == 65, bytes[0] == 4 else { throw CryptoKitError.incorrectParameterSize }
64
+ try self.init(x: Array(bytes[1..<33]), y: Array(bytes[33..<65]))
65
+ }
66
+
67
+ /// `x ‖ y` (64 bytes).
68
+ public init<D: DataProtocol>(rawRepresentation data: D) throws {
69
+ let bytes = Array(data)
70
+ guard bytes.count == 64 else { throw CryptoKitError.incorrectParameterSize }
71
+ try self.init(x: Array(bytes[0..<32]), y: Array(bytes[32..<64]))
72
+ }
73
+
74
+ init(x: [UInt8], y: [UInt8]) throws {
75
+ let point = _P256.Affine(x: _U256(bigEndian: x), y: _U256(bigEndian: y))
76
+ guard _P256.isOnCurve(point) else { throw CryptoKitError.invalidParameter }
77
+ self.point = point
78
+ }
79
+
80
+ public var x963Representation: Data { Data([4] + point.x.bigEndianBytes + point.y.bigEndianBytes) }
81
+ public var rawRepresentation: Data { Data(point.x.bigEndianBytes + point.y.bigEndianBytes) }
82
+ /// `02`/`03` (the parity of y) ‖ x.
83
+ public var compressedRepresentation: Data { Data([point.y.limbs[0] & 1 == 0 ? 2 : 3] + point.x.bigEndianBytes) }
84
+ }
85
+ }
86
+ }
87
+
88
+ /// The result of a key agreement: here, the shared point's x coordinate.
89
+ public struct SharedSecret: Sendable, CustomStringConvertible {
90
+ let bytes: [UInt8]
91
+
92
+ public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
93
+ try bytes.withUnsafeBytes(body)
94
+ }
95
+
96
+ public var description: String { "SharedSecret: \(bytes.map { String($0, radix: 16) }.joined())" }
97
+ }
98
+
99
+ // MARK: - 256-bit arithmetic
100
+
101
+ /// An unsigned 256-bit integer: four 64-bit limbs, least significant first.
102
+ struct _U256: Comparable, Sendable {
103
+ var limbs: [UInt64]
104
+
105
+ init(_ limbs: [UInt64]) { self.limbs = limbs }
106
+
107
+ init(bigEndian bytes: [UInt8]) {
108
+ limbs = (0..<4).map { i in
109
+ (0..<8).reduce(UInt64(0)) { $0 << 8 | UInt64(bytes[32 - 8 * (i + 1) + $1]) }
110
+ }
111
+ }
112
+
113
+ var bigEndianBytes: [UInt8] {
114
+ limbs.reversed().flatMap { limb in (0..<8).reversed().map { UInt8(truncatingIfNeeded: limb >> (8 * $0)) } }
115
+ }
116
+
117
+ var isZero: Bool { limbs.allSatisfy { $0 == 0 } }
118
+
119
+ func bit(_ index: Int) -> Bool { limbs[index / 64] >> (index % 64) & 1 == 1 }
120
+
121
+ static func < (lhs: _U256, rhs: _U256) -> Bool {
122
+ for i in (0..<4).reversed() where lhs.limbs[i] != rhs.limbs[i] { return lhs.limbs[i] < rhs.limbs[i] }
123
+ return false
124
+ }
125
+
126
+ /// `self + other`, and whether it overflowed 2²⁵⁶.
127
+ func adding(_ other: _U256) -> (_U256, Bool) {
128
+ var result = [UInt64](repeating: 0, count: 4)
129
+ var carry = false
130
+ for i in 0..<4 {
131
+ let (sum1, o1) = limbs[i].addingReportingOverflow(other.limbs[i])
132
+ let (sum2, o2) = sum1.addingReportingOverflow(carry ? 1 : 0)
133
+ result[i] = sum2
134
+ carry = o1 || o2
135
+ }
136
+ return (_U256(result), carry)
137
+ }
138
+
139
+ /// `self − other`, and whether it borrowed.
140
+ func subtracting(_ other: _U256) -> (_U256, Bool) {
141
+ var result = [UInt64](repeating: 0, count: 4)
142
+ var borrow = false
143
+ for i in 0..<4 {
144
+ let (d1, b1) = limbs[i].subtractingReportingOverflow(other.limbs[i])
145
+ let (d2, b2) = d1.subtractingReportingOverflow(borrow ? 1 : 0)
146
+ result[i] = d2
147
+ borrow = b1 || b2
148
+ }
149
+ return (_U256(result), borrow)
150
+ }
151
+ }
152
+
153
+ /// Arithmetic modulo an odd 256-bit modulus, in Montgomery form (x·2²⁵⁶ mod m).
154
+ struct _MontgomeryField: Sendable {
155
+ let modulus: _U256
156
+ let mPrime: UInt64
157
+ let r2: _U256
158
+
159
+ init(modulus: _U256) {
160
+ self.modulus = modulus
161
+ var inverse: UInt64 = 1
162
+ for _ in 0..<6 { inverse = inverse &* (2 &- modulus.limbs[0] &* inverse) }
163
+ mPrime = 0 &- inverse
164
+ // 2⁵¹² mod m, by doubling 1 that many times.
165
+ var value = _U256([1, 0, 0, 0])
166
+ for _ in 0..<512 {
167
+ let (doubled, overflow) = value.adding(value)
168
+ value = overflow || !(doubled < modulus) ? doubled.subtracting(modulus).0 : doubled
169
+ }
170
+ r2 = value
171
+ }
172
+
173
+ func add(_ a: _U256, _ b: _U256) -> _U256 {
174
+ let (sum, overflow) = a.adding(b)
175
+ return overflow || !(sum < modulus) ? sum.subtracting(modulus).0 : sum
176
+ }
177
+
178
+ func subtract(_ a: _U256, _ b: _U256) -> _U256 {
179
+ let (difference, borrow) = a.subtracting(b)
180
+ return borrow ? difference.adding(modulus).0 : difference
181
+ }
182
+
183
+ /// a·b·2⁻²⁵⁶ mod m (CIOS).
184
+ func multiply(_ a: _U256, _ b: _U256) -> _U256 {
185
+ var t = [UInt64](repeating: 0, count: 6)
186
+ let m = modulus.limbs
187
+ for i in 0..<4 {
188
+ var carry: UInt64 = 0
189
+ for j in 0..<4 { (t[j], carry) = Self.multiplyAdd(a.limbs[j], b.limbs[i], t[j], carry) }
190
+ let (sum, overflow) = t[4].addingReportingOverflow(carry)
191
+ t[4] = sum
192
+ t[5] = overflow ? 1 : 0
193
+ let factor = t[0] &* mPrime
194
+ (_, carry) = Self.multiplyAdd(factor, m[0], t[0], 0)
195
+ for j in 1..<4 { (t[j - 1], carry) = Self.multiplyAdd(factor, m[j], t[j], carry) }
196
+ let (top, overflow2) = t[4].addingReportingOverflow(carry)
197
+ t[3] = top
198
+ t[4] = t[5] + (overflow2 ? 1 : 0)
199
+ }
200
+ let result = _U256(Array(t[0..<4]))
201
+ return t[4] != 0 || !(result < modulus) ? result.subtracting(modulus).0 : result
202
+ }
203
+
204
+ /// a·b + c + d, as (low, high) limbs.
205
+ static func multiplyAdd(_ a: UInt64, _ b: UInt64, _ c: UInt64, _ d: UInt64) -> (UInt64, UInt64) {
206
+ var (high, low) = a.multipliedFullWidth(by: b)
207
+ var overflow: Bool
208
+ (low, overflow) = low.addingReportingOverflow(c)
209
+ if overflow { high &+= 1 }
210
+ (low, overflow) = low.addingReportingOverflow(d)
211
+ if overflow { high &+= 1 }
212
+ return (low, high)
213
+ }
214
+
215
+ func toMontgomery(_ a: _U256) -> _U256 { multiply(a, r2) }
216
+ func fromMontgomery(_ a: _U256) -> _U256 { multiply(a, _U256([1, 0, 0, 0])) }
217
+
218
+ /// a⁻¹ by Fermat (a^(m−2)), in Montgomery form.
219
+ func inverse(_ a: _U256) -> _U256 {
220
+ let exponent = modulus.subtracting(_U256([2, 0, 0, 0])).0
221
+ var result = toMontgomery(_U256([1, 0, 0, 0]))
222
+ for index in (0..<256).reversed() {
223
+ result = multiply(result, result)
224
+ if exponent.bit(index) { result = multiply(result, a) }
225
+ }
226
+ return result
227
+ }
228
+ }
229
+
230
+ // MARK: - The curve
231
+
232
+ enum _P256 {
233
+ static let p = _U256([0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_FFFF_FFFF, 0, 0xFFFF_FFFF_0000_0001])
234
+ static let n = _U256([0xF3B9_CAC2_FC63_2551, 0xBCE6_FAAD_A717_9E84, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_0000_0000])
235
+ static let b = _U256([0x3BCE_3C3E_27D2_604B, 0x651D_06B0_CC53_B0F6, 0xB3EB_BD55_7698_86BC, 0x5AC6_35D8_AA3A_93E7])
236
+ static let generator = Affine(
237
+ x: _U256([0xF4A1_3945_D898_C296, 0x7703_7D81_2DEB_33A0, 0xF8BC_E6E5_63A4_40F2, 0x6B17_D1F2_E12C_4247]),
238
+ y: _U256([0xCBB6_4068_37BF_51F5, 0x2BCE_3357_6B31_5ECE, 0x8EE7_EB4A_7C0F_9E16, 0x4FE3_42E2_FE1A_7F9B]))
239
+ static let field = _MontgomeryField(modulus: p)
240
+
241
+ /// A point in plain (not Montgomery) coordinates.
242
+ struct Affine: Sendable {
243
+ let x: _U256
244
+ let y: _U256
245
+ }
246
+
247
+ /// A point in Jacobian coordinates, Montgomery form; z = 0 is the point at infinity.
248
+ struct Jacobian {
249
+ var x: _U256
250
+ var y: _U256
251
+ var z: _U256
252
+ static let infinity = Jacobian(x: _U256([0, 0, 0, 0]), y: _U256([0, 0, 0, 0]), z: _U256([0, 0, 0, 0]))
253
+ }
254
+
255
+ /// y² = x³ − 3x + b, with both coordinates below p.
256
+ static func isOnCurve(_ point: Affine) -> Bool {
257
+ guard point.x < p, point.y < p else { return false }
258
+ let f = field
259
+ let x = f.toMontgomery(point.x), y = f.toMontgomery(point.y)
260
+ let x3 = f.multiply(f.multiply(x, x), x)
261
+ let threeX = f.add(f.add(x, x), x)
262
+ let right = f.add(f.subtract(x3, threeX), f.toMontgomery(b))
263
+ return f.fromMontgomery(f.multiply(y, y)).limbs == f.fromMontgomery(right).limbs
264
+ }
265
+
266
+ static func double(_ point: Jacobian) -> Jacobian {
267
+ if point.z.isZero || point.y.isZero { return .infinity }
268
+ let f = field
269
+ let delta = f.multiply(point.z, point.z)
270
+ let gamma = f.multiply(point.y, point.y)
271
+ let beta = f.multiply(point.x, gamma)
272
+ let product = f.multiply(f.subtract(point.x, delta), f.add(point.x, delta))
273
+ let alpha = f.add(f.add(product, product), product)
274
+ let fourBeta = f.add(f.add(beta, beta), f.add(beta, beta))
275
+ let x3 = f.subtract(f.multiply(alpha, alpha), f.add(fourBeta, fourBeta))
276
+ let yz = f.add(point.y, point.z)
277
+ let z3 = f.subtract(f.subtract(f.multiply(yz, yz), gamma), delta)
278
+ let gamma2 = f.multiply(gamma, gamma)
279
+ let eightGamma2 = f.add(f.add(f.add(gamma2, gamma2), f.add(gamma2, gamma2)), f.add(f.add(gamma2, gamma2), f.add(gamma2, gamma2)))
280
+ let y3 = f.subtract(f.multiply(alpha, f.subtract(fourBeta, x3)), eightGamma2)
281
+ return Jacobian(x: x3, y: y3, z: z3)
282
+ }
283
+
284
+ /// `point + other`, `other` affine in Montgomery form (madd-2007-bl).
285
+ static func add(_ point: Jacobian, _ other: (x: _U256, y: _U256)) -> Jacobian {
286
+ let f = field
287
+ if point.z.isZero { return Jacobian(x: other.x, y: other.y, z: f.toMontgomery(_U256([1, 0, 0, 0]))) }
288
+ let z1z1 = f.multiply(point.z, point.z)
289
+ let u2 = f.multiply(other.x, z1z1)
290
+ let s2 = f.multiply(f.multiply(other.y, point.z), z1z1)
291
+ let h = f.subtract(u2, point.x)
292
+ let r0 = f.subtract(s2, point.y)
293
+ if h.isZero { return r0.isZero ? double(point) : .infinity }
294
+ let hh = f.multiply(h, h)
295
+ let i = f.add(f.add(hh, hh), f.add(hh, hh))
296
+ let j = f.multiply(h, i)
297
+ let r = f.add(r0, r0)
298
+ let v = f.multiply(point.x, i)
299
+ let x3 = f.subtract(f.subtract(f.multiply(r, r), j), f.add(v, v))
300
+ let y1j = f.multiply(point.y, j)
301
+ let y3 = f.subtract(f.multiply(r, f.subtract(v, x3)), f.add(y1j, y1j))
302
+ let zh = f.add(point.z, h)
303
+ let z3 = f.subtract(f.subtract(f.multiply(zh, zh), z1z1), hh)
304
+ return Jacobian(x: x3, y: y3, z: z3)
305
+ }
306
+
307
+ /// scalar · point, by double-and-add. The scalar is in [1, n), so the result is never infinity.
308
+ static func multiply(_ point: Affine, by scalar: _U256) -> Affine {
309
+ let f = field
310
+ let base = (x: f.toMontgomery(point.x), y: f.toMontgomery(point.y))
311
+ var result = Jacobian.infinity
312
+ for index in (0..<256).reversed() {
313
+ result = double(result)
314
+ if scalar.bit(index) { result = add(result, base) }
315
+ }
316
+ let zInverse = f.inverse(result.z)
317
+ let zInverse2 = f.multiply(zInverse, zInverse)
318
+ return Affine(x: f.fromMontgomery(f.multiply(result.x, zInverse2)),
319
+ y: f.fromMontgomery(f.multiply(result.y, f.multiply(zInverse2, zInverse))))
320
+ }
321
+ }