From ec1abb046de8b5be73f61c1c15d877a1e37b8150 Mon Sep 17 00:00:00 2001 From: "teach.gamil.com" Date: Mon, 15 Jan 2024 20:32:53 +0545 Subject: [PATCH] private group scaling v0 --- .../PushIosDemo.xcodeproj/project.pbxproj | 398 ------------------ .../contents.xcworkspacedata | 7 - .../xcshareddata/IDEWorkspaceChecks.plist | 8 - .../xcshareddata/WorkspaceSettings.xcsettings | 5 - .../xcshareddata/swiftpm/Package.resolved | 140 ------ .../AccentColor.colorset/Contents.json | 11 - .../AppIcon.appiconset/Contents.json | 13 - .../PushIosDemo/Assets.xcassets/Contents.json | 6 - PushIosDemo/PushIosDemo/ContentView.swift | 52 --- .../Preview Assets.xcassets/Contents.json | 6 - PushIosDemo/PushIosDemo/PushIosDemoApp.swift | 17 - Sources/Chat/Conversation.swift | 39 +- Sources/Chat/Group/CreateGroup.swift | 138 ++++-- Sources/Chat/Group/GetGroup.swift | 49 +++ Sources/Chat/Group/Group.swift | 15 + Sources/Chat/Send.swift | 172 +++++++- Sources/Endpoints/ChatEndpoint.swift | 19 +- Sources/Helpers/Chat/GetInboxList.swift | 4 +- Sources/Helpers/Crypto/Pgp.swift | 2 +- Sources/Helpers/Ipfs/Cid.swift | 3 +- Sources/Helpers/JsonUtils.swift | 5 +- Tests/Chat/Group/CreateGroupTests.swift | 76 ++-- Tests/Chat/Group/SendGroupMsgTests.swift | 2 +- Tests/Chat/P2P/SendTests.swift | 2 +- Tests/Helper/IpfsTests.swift | 4 +- Tests/e2e/GroupConversation.swift | 11 +- Tests/e2e/PrivateGroupDecrypt.swift | 107 +++++ 27 files changed, 558 insertions(+), 753 deletions(-) delete mode 100644 PushIosDemo/PushIosDemo.xcodeproj/project.pbxproj delete mode 100644 PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings delete mode 100644 PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved delete mode 100644 PushIosDemo/PushIosDemo/Assets.xcassets/AccentColor.colorset/Contents.json delete mode 100644 PushIosDemo/PushIosDemo/Assets.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 PushIosDemo/PushIosDemo/Assets.xcassets/Contents.json delete mode 100644 PushIosDemo/PushIosDemo/ContentView.swift delete mode 100644 PushIosDemo/PushIosDemo/Preview Content/Preview Assets.xcassets/Contents.json delete mode 100644 PushIosDemo/PushIosDemo/PushIosDemoApp.swift create mode 100644 Tests/e2e/PrivateGroupDecrypt.swift diff --git a/PushIosDemo/PushIosDemo.xcodeproj/project.pbxproj b/PushIosDemo/PushIosDemo.xcodeproj/project.pbxproj deleted file mode 100644 index 88e6107..0000000 --- a/PushIosDemo/PushIosDemo.xcodeproj/project.pbxproj +++ /dev/null @@ -1,398 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 56; - objects = { - -/* Begin PBXBuildFile section */ - E700DAB52A18ADE8009EF921 /* PushIosDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = E700DAB42A18ADE8009EF921 /* PushIosDemoApp.swift */; }; - E700DAB72A18ADE8009EF921 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E700DAB62A18ADE8009EF921 /* ContentView.swift */; }; - E700DAB92A18ADEB009EF921 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E700DAB82A18ADEB009EF921 /* Assets.xcassets */; }; - E700DABC2A18ADEB009EF921 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E700DABB2A18ADEB009EF921 /* Preview Assets.xcassets */; }; - E700DAC42A18D3C3009EF921 /* WalletConnect in Frameworks */ = {isa = PBXBuildFile; productRef = E700DAC32A18D3C3009EF921 /* WalletConnect */; }; - E7FBD19C2A24718D0080F660 /* Push in Frameworks */ = {isa = PBXBuildFile; productRef = E7FBD19B2A24718D0080F660 /* Push */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - E700DAB12A18ADE8009EF921 /* PushIosDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PushIosDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; - E700DAB42A18ADE8009EF921 /* PushIosDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushIosDemoApp.swift; sourceTree = ""; }; - E700DAB62A18ADE8009EF921 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; - E700DAB82A18ADEB009EF921 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - E700DABB2A18ADEB009EF921 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; - E7FBD19A2A2471740080F660 /* push-swift-sdk */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "push-swift-sdk"; path = ..; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - E700DAAE2A18ADE8009EF921 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - E7FBD19C2A24718D0080F660 /* Push in Frameworks */, - E700DAC42A18D3C3009EF921 /* WalletConnect in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 555B9A912A1DE62100F96CB7 /* Frameworks */ = { - isa = PBXGroup; - children = ( - ); - name = Frameworks; - sourceTree = ""; - }; - 555B9A932A1DE66F00F96CB7 /* Packages */ = { - isa = PBXGroup; - children = ( - E7FBD19A2A2471740080F660 /* push-swift-sdk */, - ); - name = Packages; - sourceTree = ""; - }; - E700DAA82A18ADE8009EF921 = { - isa = PBXGroup; - children = ( - 555B9A932A1DE66F00F96CB7 /* Packages */, - E700DAB32A18ADE8009EF921 /* PushIosDemo */, - E700DAB22A18ADE8009EF921 /* Products */, - 555B9A912A1DE62100F96CB7 /* Frameworks */, - ); - sourceTree = ""; - }; - E700DAB22A18ADE8009EF921 /* Products */ = { - isa = PBXGroup; - children = ( - E700DAB12A18ADE8009EF921 /* PushIosDemo.app */, - ); - name = Products; - sourceTree = ""; - }; - E700DAB32A18ADE8009EF921 /* PushIosDemo */ = { - isa = PBXGroup; - children = ( - E700DAB42A18ADE8009EF921 /* PushIosDemoApp.swift */, - E700DAB62A18ADE8009EF921 /* ContentView.swift */, - E700DAB82A18ADEB009EF921 /* Assets.xcassets */, - E700DABA2A18ADEB009EF921 /* Preview Content */, - ); - path = PushIosDemo; - sourceTree = ""; - }; - E700DABA2A18ADEB009EF921 /* Preview Content */ = { - isa = PBXGroup; - children = ( - E700DABB2A18ADEB009EF921 /* Preview Assets.xcassets */, - ); - path = "Preview Content"; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - E700DAB02A18ADE8009EF921 /* PushIosDemo */ = { - isa = PBXNativeTarget; - buildConfigurationList = E700DABF2A18ADEB009EF921 /* Build configuration list for PBXNativeTarget "PushIosDemo" */; - buildPhases = ( - E700DAAD2A18ADE8009EF921 /* Sources */, - E700DAAE2A18ADE8009EF921 /* Frameworks */, - E700DAAF2A18ADE8009EF921 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = PushIosDemo; - packageProductDependencies = ( - E700DAC32A18D3C3009EF921 /* WalletConnect */, - E7FBD19B2A24718D0080F660 /* Push */, - ); - productName = PushIosDemo; - productReference = E700DAB12A18ADE8009EF921 /* PushIosDemo.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - E700DAA92A18ADE8009EF921 /* Project object */ = { - isa = PBXProject; - attributes = { - BuildIndependentTargetsInParallel = 1; - LastSwiftUpdateCheck = 1430; - LastUpgradeCheck = 1430; - TargetAttributes = { - E700DAB02A18ADE8009EF921 = { - CreatedOnToolsVersion = 14.3; - }; - }; - }; - buildConfigurationList = E700DAAC2A18ADE8009EF921 /* Build configuration list for PBXProject "PushIosDemo" */; - compatibilityVersion = "Xcode 14.0"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = E700DAA82A18ADE8009EF921; - packageReferences = ( - E700DAC22A18D3C3009EF921 /* XCRemoteSwiftPackageReference "WalletConnectSwiftV2" */, - ); - productRefGroup = E700DAB22A18ADE8009EF921 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - E700DAB02A18ADE8009EF921 /* PushIosDemo */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - E700DAAF2A18ADE8009EF921 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - E700DABC2A18ADEB009EF921 /* Preview Assets.xcassets in Resources */, - E700DAB92A18ADEB009EF921 /* Assets.xcassets in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - E700DAAD2A18ADE8009EF921 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - E700DAB72A18ADE8009EF921 /* ContentView.swift in Sources */, - E700DAB52A18ADE8009EF921 /* PushIosDemoApp.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - E700DABD2A18ADEB009EF921 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.4; - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - }; - name = Debug; - }; - E700DABE2A18ADEB009EF921 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 16.4; - MTL_ENABLE_DEBUG_INFO = NO; - MTL_FAST_MATH = YES; - SDKROOT = iphoneos; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - E700DAC02A18ADEB009EF921 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_ASSET_PATHS = "\"PushIosDemo/Preview Content\""; - DEVELOPMENT_TEAM = 62B7287GF5; - ENABLE_PREVIEWS = YES; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; - INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; - INFOPLIST_KEY_UILaunchScreen_Generation = YES; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 14.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = io.pushsdk.PushIosDemo; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - E700DAC12A18ADEB009EF921 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_ASSET_PATHS = "\"PushIosDemo/Preview Content\""; - DEVELOPMENT_TEAM = 62B7287GF5; - ENABLE_PREVIEWS = YES; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; - INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; - INFOPLIST_KEY_UILaunchScreen_Generation = YES; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - IPHONEOS_DEPLOYMENT_TARGET = 14.0; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); - MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = io.pushsdk.PushIosDemo; - PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - E700DAAC2A18ADE8009EF921 /* Build configuration list for PBXProject "PushIosDemo" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - E700DABD2A18ADEB009EF921 /* Debug */, - E700DABE2A18ADEB009EF921 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - E700DABF2A18ADEB009EF921 /* Build configuration list for PBXNativeTarget "PushIosDemo" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - E700DAC02A18ADEB009EF921 /* Debug */, - E700DAC12A18ADEB009EF921 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - -/* Begin XCRemoteSwiftPackageReference section */ - E700DAC22A18D3C3009EF921 /* XCRemoteSwiftPackageReference "WalletConnectSwiftV2" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/WalletConnect/WalletConnectSwiftV2"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 1.0.0; - }; - }; -/* End XCRemoteSwiftPackageReference section */ - -/* Begin XCSwiftPackageProductDependency section */ - E700DAC32A18D3C3009EF921 /* WalletConnect */ = { - isa = XCSwiftPackageProductDependency; - package = E700DAC22A18D3C3009EF921 /* XCRemoteSwiftPackageReference "WalletConnectSwiftV2" */; - productName = WalletConnect; - }; - E7FBD19B2A24718D0080F660 /* Push */ = { - isa = XCSwiftPackageProductDependency; - productName = Push; - }; -/* End XCSwiftPackageProductDependency section */ - }; - rootObject = E700DAA92A18ADE8009EF921 /* Project object */; -} diff --git a/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a..0000000 --- a/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings deleted file mode 100644 index 0c67376..0000000 --- a/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index a63e172..0000000 --- a/PushIosDemo/PushIosDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,140 +0,0 @@ -{ - "pins" : [ - { - "identity" : "bigint", - "kind" : "remoteSourceControl", - "location" : "https://github.com/attaswift/BigInt", - "state" : { - "revision" : "0ed110f7555c34ff468e72e1686e59721f2b0da6", - "version" : "5.3.0" - } - }, - { - "identity" : "cryptoswift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", - "state" : { - "revision" : "eee9ad754926c40a0f7e73f152357d37b119b7fa", - "version" : "1.7.1" - } - }, - { - "identity" : "generic-json-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/iwill/generic-json-swift", - "state" : { - "revision" : "0a06575f4038b504e78ac330913d920f1630f510", - "version" : "2.0.2" - } - }, - { - "identity" : "objectivepgp", - "kind" : "remoteSourceControl", - "location" : "https://github.com/krzyzanowskim/ObjectivePGP.git", - "state" : { - "revision" : "5629d849ec6c8f8ec733dffa9949c507468ec0b4", - "version" : "0.99.4" - } - }, - { - "identity" : "secp256k1.swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/GigaBitcoin/secp256k1.swift.git", - "state" : { - "revision" : "48fb20fce4ca3aad89180448a127d5bc16f0e44c", - "version" : "0.10.0" - } - }, - { - "identity" : "swift-atomics", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-atomics.git", - "state" : { - "revision" : "6c89474e62719ddcc1e9614989fff2f68208fe10", - "version" : "1.1.0" - } - }, - { - "identity" : "swift-collections", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-collections.git", - "state" : { - "revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", - "version" : "1.0.4" - } - }, - { - "identity" : "swift-log", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-log.git", - "state" : { - "revision" : "32e8d724467f8fe623624570367e3d50c5638e46", - "version" : "1.5.2" - } - }, - { - "identity" : "swift-nio", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio.git", - "state" : { - "revision" : "2d8e6ca36fe3e8ed74b0883f593757a45463c34d", - "version" : "2.53.0" - } - }, - { - "identity" : "swift-nio-extras", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-extras.git", - "state" : { - "revision" : "0e0d0aab665ff1a0659ce75ac003081f2b1c8997", - "version" : "1.19.0" - } - }, - { - "identity" : "swift-nio-ssl", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-ssl.git", - "state" : { - "revision" : "e866a626e105042a6a72a870c88b4c531ba05f83", - "version" : "2.24.0" - } - }, - { - "identity" : "swift-nio-transport-services", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-nio-transport-services.git", - "state" : { - "revision" : "41f4098903878418537020075a4d8a6e20a0b182", - "version" : "1.17.0" - } - }, - { - "identity" : "walletconnectswiftv2", - "kind" : "remoteSourceControl", - "location" : "https://github.com/WalletConnect/WalletConnectSwiftV2", - "state" : { - "revision" : "742a501a87101801389e35e427b0a3695812423d", - "version" : "1.6.0" - } - }, - { - "identity" : "web3.swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/argentlabs/web3.swift", - "state" : { - "revision" : "8ca33e700ed8de6137a0e1471017aa3b3c8de0db", - "version" : "1.6.0" - } - }, - { - "identity" : "websocket-kit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/vapor/websocket-kit.git", - "state" : { - "revision" : "17c0afbf24f4e288e183bc34317dc97b5cd084bd", - "version" : "2.9.0" - } - } - ], - "version" : 2 -} diff --git a/PushIosDemo/PushIosDemo/Assets.xcassets/AccentColor.colorset/Contents.json b/PushIosDemo/PushIosDemo/Assets.xcassets/AccentColor.colorset/Contents.json deleted file mode 100644 index eb87897..0000000 --- a/PushIosDemo/PushIosDemo/Assets.xcassets/AccentColor.colorset/Contents.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "colors" : [ - { - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/PushIosDemo/PushIosDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/PushIosDemo/PushIosDemo/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 13613e3..0000000 --- a/PushIosDemo/PushIosDemo/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "platform" : "ios", - "size" : "1024x1024" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/PushIosDemo/PushIosDemo/Assets.xcassets/Contents.json b/PushIosDemo/PushIosDemo/Assets.xcassets/Contents.json deleted file mode 100644 index 73c0059..0000000 --- a/PushIosDemo/PushIosDemo/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/PushIosDemo/PushIosDemo/ContentView.swift b/PushIosDemo/PushIosDemo/ContentView.swift deleted file mode 100644 index ec7357d..0000000 --- a/PushIosDemo/PushIosDemo/ContentView.swift +++ /dev/null @@ -1,52 +0,0 @@ -import Push -import SwiftUI -import WalletConnectSign - -struct ContentView: View { - @State private var showAlert = false - - var body: some View { - VStack { - Text("Push Sdk Demo") - .font(.title) - .padding() - - Button(action: { - showAlert = false - // connect() - Task { - await connect() - } - }) { - Text("Conect Wallet Connect") - .font(.headline) - .padding() - .background(Color.blue) - .foregroundColor(.white) - .cornerRadius(10) - } - .padding(.horizontal, 40.0) - .alert(isPresented: $showAlert) { - Alert( - title: Text("Alert"), message: Text("Button clicked!"), - dismissButton: .default(Text("OK"))) - } - } - } -} - -func connect() async { - do { - let user = try await PushUser.get( - account: "0xD26A7BF7fa0f8F1f3f73B056c9A67565A6aFE63c", env: .STAGING)! - print(user) - } catch { - print(error) - } -} - -struct ContentView_Previews: PreviewProvider { - static var previews: some View { - ContentView() - } -} diff --git a/PushIosDemo/PushIosDemo/Preview Content/Preview Assets.xcassets/Contents.json b/PushIosDemo/PushIosDemo/Preview Content/Preview Assets.xcassets/Contents.json deleted file mode 100644 index 73c0059..0000000 --- a/PushIosDemo/PushIosDemo/Preview Content/Preview Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/PushIosDemo/PushIosDemo/PushIosDemoApp.swift b/PushIosDemo/PushIosDemo/PushIosDemoApp.swift deleted file mode 100644 index 698418b..0000000 --- a/PushIosDemo/PushIosDemo/PushIosDemoApp.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// PushIosDemoApp.swift -// PushIosDemo -// -// Created by Abishek Bashyal on 20/05/2023. -// - -import SwiftUI - -@main -struct PushIosDemoApp: App { - var body: some Scene { - WindowGroup { - ContentView() - } - } -} diff --git a/Sources/Chat/Conversation.swift b/Sources/Chat/Conversation.swift index fbb8018..20fed81 100644 --- a/Sources/Chat/Conversation.swift +++ b/Sources/Chat/Conversation.swift @@ -29,6 +29,7 @@ extension PushChat { async throws -> Message { + return try await History( threadHash: threadHash, limit: 1, pgpPrivateKey: pgpPrivateKey, toDecrypt: toDecrypt, env: env ).first! @@ -44,8 +45,8 @@ extension PushChat { if toDecrypt { for i in 0.. String { + privateKeyArmored: String, + env: ENV = ENV.STAGING + ) async throws -> String { do { + + if message.encType == "pgpv1:group" { + return try await decryptPrivateGroupMessage( + message, privateKeyArmored: privateKeyArmored, env: env) + } if message.encType != "pgp" { return message.messageContent } return try decryptMessage( - message.messageContent, encryptedSecret: message.encryptedSecret, + message.messageContent, encryptedSecret: message.encryptedSecret!, privateKeyArmored: privateKeyArmored) } catch { if isGroupChatId(message.toCAIP10) { @@ -94,6 +101,28 @@ extension PushChat { } } + public static func decryptPrivateGroupMessage( + _ message: Message, + privateKeyArmored: String, + env: ENV + ) async throws -> String { + do { + + let encryptedSecret = try await PushChat.getGroupSessionKey( + sessionKey: message.sessionKey!, env: env) + + print("got enc sec \(encryptedSecret)") + + return try decryptMessage( + message.messageContent, + encryptedSecret: encryptedSecret, + privateKeyArmored: privateKeyArmored + ) + } catch { + throw PushChat.ChatError.dectyptionFalied + } + } + public static func decryptMessage( _ message: String, encryptedSecret: String, diff --git a/Sources/Chat/Group/CreateGroup.swift b/Sources/Chat/Group/CreateGroup.swift index 92b8506..eb0a543 100644 --- a/Sources/Chat/Group/CreateGroup.swift +++ b/Sources/Chat/Group/CreateGroup.swift @@ -2,17 +2,10 @@ import Foundation extension PushChat { - public static func createGroup(options: CreateGroupOptions) async throws -> PushGroup { + public static func createGroup(options: CreateGroupOptions) async throws -> PushGroupInfoDTO { do { - - let createGroupInfoHash = try getCreateGroupHash(options: options) - let signature = try Pgp.sign( - message: createGroupInfoHash, privateKey: options.creatorPgpPrivateKey) - - let sigType = "pgp" - let verificationProof = "\(sigType):\(signature)" - - let payload = CreateGroupPlayload(options: options, verificationProof: verificationProof) + let payload = try CreateGroupPlayload(options: options) + print("got payload") return try await createGroupService(payload: payload, env: options.env) } catch { throw GroupChatError.RUNTIME_ERROR( @@ -66,8 +59,9 @@ extension PushChat { } static func createGroupService(payload: CreateGroupPlayload, env: ENV) async throws - -> PushChat.PushGroup + -> PushChat.PushGroupInfoDTO { + let url = try PushEndpoint.createChatGroup(env: env).url var request = URLRequest(url: url) request.httpMethod = "POST" @@ -81,11 +75,10 @@ extension PushChat { } guard (200...299).contains(httpResponse.statusCode) else { - print(String(data: data, encoding: .utf8)!) throw URLError(.badServerResponse) } - let groupData = try JSONDecoder().decode(PushGroup.self, from: data) + let groupData = try JSONDecoder().decode(PushGroupInfoDTO.self, from: data) return groupData } @@ -94,29 +87,122 @@ extension PushChat { struct CreateGroupPlayload: Encodable { var groupName: String var groupDescription: String - var members: [String] var groupImage: String + + var rules: [String: String] var isPublic: Bool + var groupType: String = "default" + var profileVerificationProof: String + + var config: Config + + var members: [String] var admins: [String] = [] - var contractAddressNFT: String? - var numberOfNFTs: Int? - var contractAddressERC20: String? - var numberOfERC20: Int? - var groupCreator: String - var verificationProof: String - var meta: String? - - public init(options: PushChat.CreateGroupOptions, verificationProof: String) { + var idempotentVerificationProof: String + + struct Config: Encodable { + var meta: String? + var scheduleAt: String? + var scheduleEnd: String? + var status: String? + var configVerificationProof: String + + private enum CodingKeys: String, CodingKey { + case meta, scheduleAt, scheduleEnd, status, configVerificationProof + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(meta, forKey: .meta) + try container.encode(scheduleAt, forKey: .scheduleAt) + try container.encode(scheduleEnd, forKey: .scheduleEnd) + try container.encode(status, forKey: .status) + try container.encode(configVerificationProof, forKey: .configVerificationProof) + } + } + + public init(options: PushChat.CreateGroupOptions) throws { groupName = options.name groupDescription = options.description - members = options.members groupImage = options.image + + rules = [String: String]() isPublic = options.isPublic - groupCreator = options.creatorAddress - self.verificationProof = verificationProof + + members = options.members + + idempotentVerificationProof = try getIdempotentVerificationProof(options: options) + profileVerificationProof = try getProfileVerificationProof(options: options) + + config = Config(configVerificationProof: try getConfigVerificationProof(options: options)) + } } +func getProfileVerificationProof(options: PushChat.CreateGroupOptions) throws -> String { + let profileHash = try getCreateGroupProfileVerificationHash(options: options) + let signature = try Pgp.sign( + message: profileHash, privateKey: options.creatorPgpPrivateKey) + + let connectedUserDID = walletToPCAIP10(account: options.creatorAddress) + let sigType = "pgpv2" + let verificationProof = + "\(sigType):\(signature):\(connectedUserDID)" + return verificationProof +} + +func getCreateGroupProfileVerificationHash(options: PushChat.CreateGroupOptions) throws -> String { + let jsonString = + "{\"groupName\":\"\(options.name)\",\"groupDescription\":\"\(options.description)\",\"groupImage\":\"\(options.image)\",\"rules\":{},\"isPublic\":\(options.isPublic),\"groupType\":\"default\"}" + + let hash = generateSHA256Hash(msg: jsonString) + + return hash +} + +func getConfigVerificationProof(options: PushChat.CreateGroupOptions) throws -> String { + let profileHash = try getCreateGroupConfigVerificationHash(options: options) + let signature = try Pgp.sign( + message: profileHash, privateKey: options.creatorPgpPrivateKey) + + let connectedUserDID = walletToPCAIP10(account: options.creatorAddress) + let sigType = "pgpv2" + let verificationProof = + "\(sigType):\(signature):\(connectedUserDID)" + return verificationProof +} + +func getCreateGroupConfigVerificationHash(options: PushChat.CreateGroupOptions) throws -> String { + let jsonString = + "{\"meta\":null,\"scheduleAt\":null,\"scheduleEnd\":null,\"status\":null}" + + let hash = generateSHA256Hash(msg: jsonString) + + return hash +} + +func getIdempotentVerificationProof(options: PushChat.CreateGroupOptions) throws -> String { + let profileHash = try getCreateGroupIdempotentHash(options: options) + let signature = try Pgp.sign( + message: profileHash, privateKey: options.creatorPgpPrivateKey) + + let connectedUserDID = walletToPCAIP10(account: options.creatorAddress) + let sigType = "pgpv2" + let verificationProof = + "\(sigType):\(signature):\(connectedUserDID)" + return verificationProof +} + +func getCreateGroupIdempotentHash(options: PushChat.CreateGroupOptions) throws -> String { + let jsonString = + "{\"members\":\(options.members),\"admins\":[]}" + + let hash = generateSHA256Hash(msg: jsonString) + + return hash +} + func getCreateGroupHash(options: PushChat.CreateGroupOptions) throws -> String { struct CreateGroupStruct: Codable { let groupName: String diff --git a/Sources/Chat/Group/GetGroup.swift b/Sources/Chat/Group/GetGroup.swift index 593ddf5..f979e8b 100644 --- a/Sources/Chat/Group/GetGroup.swift +++ b/Sources/Chat/Group/GetGroup.swift @@ -24,4 +24,53 @@ extension PushChat { return groupData } + public static func getGroupInfoDTO(chatId: String, env: ENV) async throws -> PushChat + .PushGroupInfoDTO? + { + let url = try PushEndpoint.getGroup(chatId: chatId, apiVersion: "v2", env: env).url + var request = URLRequest(url: url) + request.httpMethod = "GET" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + + let (data, res) = try await URLSession.shared.data(for: request) + guard let httpResponse = res as? HTTPURLResponse else { + throw URLError(.badServerResponse) + } + + if httpResponse.statusCode == 400 { + return nil + } + + guard (200...299).contains(httpResponse.statusCode) else { + throw URLError(.badServerResponse) + } + + let groupData = try JSONDecoder().decode(PushGroupInfoDTO.self, from: data) + return groupData + } + + public static func getGroupSessionKey(sessionKey: String, env: ENV) async throws -> String { + let url = try PushEndpoint.getGroupSession(chatId: sessionKey, apiVersion: "v1", env: env).url + var request = URLRequest(url: url) + request.httpMethod = "GET" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + + let (data, res) = try await URLSession.shared.data(for: request) + guard let httpResponse = res as? HTTPURLResponse else { + throw URLError(.badServerResponse) + } + + guard (200...299).contains(httpResponse.statusCode) else { + throw URLError(.badServerResponse) + } + + struct SecretSessionRes: Codable { + var encryptedSecret: String + } + + let groupData = try JSONDecoder().decode(SecretSessionRes.self, from: data) + + return groupData.encryptedSecret + } + } diff --git a/Sources/Chat/Group/Group.swift b/Sources/Chat/Group/Group.swift index 76adec1..b86c713 100644 --- a/Sources/Chat/Group/Group.swift +++ b/Sources/Chat/Group/Group.swift @@ -40,4 +40,19 @@ extension PushChat { } } } + + public struct PushGroupInfoDTO: Codable { + public var groupName: String + public var groupDescription: String + public var groupImage: String? + public var isPublic: Bool + public var groupCreator: String + public var chatId: String + public var groupType: String? + public var meta: String? + public var sessionKey: String? + public var encryptedSecret: String? + + } + } diff --git a/Sources/Chat/Send.swift b/Sources/Chat/Send.swift index 50b6c85..21466e7 100644 --- a/Sources/Chat/Send.swift +++ b/Sources/Chat/Send.swift @@ -11,12 +11,40 @@ extension PushChat { var fromCAIP10: String var toCAIP10: String var messageContent: String + var messageObj: String? var messageType: String var signature: String var encType: String - var encryptedSecret: String + var encryptedSecret: String? var sigType: String var verificationProof: String? + var sessionKey: String? + + private enum CodingKeys: String, CodingKey { + case fromDID, toDID, fromCAIP10, toCAIP10, messageContent, messageObj, messageType, signature, + encType, + encryptedSecret, sigType, verificationProof, sessionKey + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(fromDID, forKey: .fromDID) + try container.encode(toDID, forKey: .toDID) + try container.encode(fromCAIP10, forKey: .fromCAIP10) + try container.encode(toCAIP10, forKey: .toCAIP10) + try container.encode(messageContent, forKey: .messageContent) + try container.encode(messageObj, forKey: .messageObj) + + try container.encode(messageType, forKey: .messageType) + try container.encode(signature, forKey: .signature) + try container.encode(encType, forKey: .encType) + try container.encode(encryptedSecret, forKey: .encryptedSecret) + + try container.encode(sigType, forKey: .sigType) + try container.encode(verificationProof, forKey: .verificationProof) + try container.encode(sessionKey, forKey: .sessionKey) + } } public struct SendOptions { @@ -56,7 +84,6 @@ extension PushChat { } guard (200...299).contains(httpResponse.statusCode) else { - print(try data.toString()) throw URLError(.badServerResponse) } @@ -118,6 +145,58 @@ extension PushChat { return try Pgp.sign(message: messageContent, privateKey: senderPgpPrivateKey) } + static func getPrivateGroupSendMessagePayload( + _ options: SendOptions, + groupInfo: PushChat + .PushGroupInfoDTO + ) async throws + -> SendMessagePayload + { + + var encType = "PlainText" + var (signature, messageConent) = ("", options.messageContent) + + let secretKey = try Pgp.pgpDecrypt( + cipherText: groupInfo.encryptedSecret!, toPrivateKeyArmored: options.pgpPrivateKey) + + if groupInfo.encryptedSecret != nil { + encType = "pgpv1:group" + + messageConent = try AESCBCHelper.encrypt(messageText: messageConent, secretKey: secretKey) + signature = try Pgp.sign(message: messageConent, privateKey: options.pgpPrivateKey) + + } else { + signature = try signMessage( + messageContent: messageConent, senderPgpPrivateKey: options.pgpPrivateKey) + } + + let dataToHash = try getJsonStringFromKV([ + ("fromDID", options.account), + ("toDID", options.account), + ("fromCAIP10", options.account), + ("toCAIP10", options.receiverAddress), + ("messageObj", messageConent), + ("messageType", "Text"), + ("encType", encType), + ("sessionKey", groupInfo.sessionKey!), + ("encryptedSecret", "null"), + ]) + + let hash = generateSHA256Hash(msg: dataToHash) + let verificationProof = try Pgp.sign(message: hash, privateKey: options.pgpPrivateKey) + + return SendMessagePayload( + fromDID: options.account, toDID: options.receiverAddress, + fromCAIP10: options.account, toCAIP10: options.receiverAddress, + messageContent: messageConent, + messageObj: messageConent, + messageType: options.messageType, + signature: signature, encType: encType, encryptedSecret: nil, sigType: "pgpv3", + verificationProof: "pgpv3:\(verificationProof)", + sessionKey: groupInfo.sessionKey) + + } + static func getSendMessagePayload( _ options: SendOptions, publicKeys: [String], shouldEncrypt: Bool = true ) async throws @@ -183,7 +262,16 @@ extension PushChat { } else { return [] } + } + static func getAllGroupMembersPublicKeys(_ groupId: String, _ env: ENV) async throws -> [String] { + if let group = try await PushChat.getGroup(chatId: groupId, env: env) { + let _publicKeys = group.members.compactMap { $0.publicKey } + + return _publicKeys + } else { + return [] + } } public static func send(_ chatOptions: SendOptions) async throws -> Message { @@ -216,7 +304,15 @@ extension PushChat { if shouldEncrypt { if isGroupChatId(receiverAddress) { - publicKeys = try await getGroupChatPublicKeys(sendOptions) + let groupInfo = try await PushChat.getGroupInfoDTO( + chatId: receiverAddress, env: sendOptions.env)! + if groupInfo.isPublic { + publicKeys = try await getGroupChatPublicKeys(sendOptions) + } else { + let payload = try await getPrivateGroupSendMessagePayload( + sendOptions, groupInfo: groupInfo) + return try await sendMessageService(payload: payload, env: sendOptions.env) + } } else { publicKeys = try await getP2PChatPublicKeys(sendOptions) } @@ -251,10 +347,27 @@ extension PushChat { return try await sendIntentService(payload: sendMessagePayload, env: sendOptions.env) } - public static func approve(_ approveOptions: ApproveOptions) async throws -> String { + static func getApprovePayloadCore(_ approveOptions: ApproveOptions) async throws + -> ApproveRequestPayload + { + if approveOptions.isGroupChat { + // TODO: remove unwrap + let groupInfo = try await PushChat.getGroupInfoDTO( + chatId: approveOptions.toDID, env: approveOptions.env)! + if !groupInfo.isPublic { + return try await getApprovePayloadPrivateGroup(approveOptions, groupInfo) + } + } + let acceptIntentPayload = try await getApprovePayload(approveOptions) + return acceptIntentPayload + } + public static func approve(_ approveOptions: ApproveOptions) async throws -> String { + + let acceptIntentPayload = try await getApprovePayloadCore(approveOptions) let url = try PushEndpoint.acceptChatRequest(env: approveOptions.env).url + var request = URLRequest(url: url) request.httpMethod = "PUT" request.setValue("application/json", forHTTPHeaderField: "Content-Type") @@ -285,8 +398,9 @@ extension PushChat { let apiData = AcceptHashData( fromDID: approveOptions.fromDID, toDID: approveOptions.toDID, status: "Approved") - - let jsonString = "{\"fromDID\":\"\(apiData.fromDID)\",\"toDID\":\"\(apiData.toDID)\",\"status\":\"\(apiData.status)\"}" + + let jsonString = + "{\"fromDID\":\"\(apiData.fromDID)\",\"toDID\":\"\(apiData.toDID)\",\"status\":\"\(apiData.status)\"}" let hash = generateSHA256Hash( msg: jsonString ) @@ -298,11 +412,54 @@ extension PushChat { status: "Approved", sigType: "pgp", verificationProof: "pgp:\(sig)") } + static func getApprovePayloadPrivateGroup( + _ approveOptions: ApproveOptions, _ groupInfo: PushChat.PushGroupInfoDTO + ) async throws -> ApproveRequestPayload { + let secretKey = getRandomHexString(length: 15) + let senderPublicKey = try await PushUser.get( + account: approveOptions.fromDID, env: approveOptions.env)!.getPGPPublickey() + + var groupMembersPublicKeys = try await getAllGroupMembersPublicKeys( + groupInfo.chatId, approveOptions.env) + groupMembersPublicKeys.append(senderPublicKey) + + let encryptedSecret = try Pgp.pgpEncryptV2( + message: secretKey, pgpPublicKeys: groupMembersPublicKeys) + + // let publicKeys = grou + let sigType = "pgpv2" + + let bodyToBeHashed = try getJsonStringFromKV([ + ("fromDID", approveOptions.fromDID), + ("toDID", approveOptions.toDID), + ("status", "Approved"), + ("encryptedSecret", encryptedSecret), + ]) + + let hash = generateSHA256Hash(msg: bodyToBeHashed) + + let signature = try Pgp.sign(message: hash, privateKey: approveOptions.privateKey) + let verificationProof = "\(sigType):\(signature)" + + let approvePayload = ApproveRequestPayload( + fromDID: approveOptions.fromDID, + toDID: approveOptions.toDID, + signature: signature, + // status: "Approved", + status: "Approved", + sigType: sigType, + verificationProof: verificationProof, encryptedSecret: encryptedSecret + ) + + return approvePayload + } + public struct ApproveOptions { var fromDID: String var toDID: String var privateKey: String var env: ENV + var isGroupChat: Bool public init(requesterAddress: String, approverAddress: String, privateKey: String, env: ENV) { self.fromDID = walletToPCAIP10(account: requesterAddress) @@ -310,6 +467,8 @@ extension PushChat { self.privateKey = privateKey self.env = env + self.isGroupChat = isGroupChatId(requesterAddress) + if isGroupChatId(requesterAddress) { self.toDID = walletToPCAIP10(account: requesterAddress) self.fromDID = walletToPCAIP10(account: approverAddress) @@ -324,6 +483,7 @@ extension PushChat { var status: String = "Approved" var sigType: String var verificationProof: String + var encryptedSecret: String? } } diff --git a/Sources/Endpoints/ChatEndpoint.swift b/Sources/Endpoints/ChatEndpoint.swift index 8ef3021..bc71ade 100644 --- a/Sources/Endpoints/ChatEndpoint.swift +++ b/Sources/Endpoints/ChatEndpoint.swift @@ -83,7 +83,8 @@ extension PushEndpoint { ) throws -> Self { return PushEndpoint( env: env, - path: "chat/groups" + path: "chat/groups", + apiVersion: "v2" ) } @@ -99,11 +100,25 @@ extension PushEndpoint { static func getGroup( chatId: String, + apiVersion: String = "v1", env: ENV ) throws -> Self { return PushEndpoint( env: env, - path: "chat/groups/\(chatId)" + path: "chat/groups/\(chatId)", + apiVersion: apiVersion + ) + } + + static func getGroupSession( + chatId: String, + apiVersion: String = "v1", + env: ENV + ) throws -> Self { + return PushEndpoint( + env: env, + path: "chat/encryptedsecret/sessionKey/\(chatId)", + apiVersion: apiVersion ) } diff --git a/Sources/Helpers/Chat/GetInboxList.swift b/Sources/Helpers/Chat/GetInboxList.swift index 0f06bac..188cb74 100644 --- a/Sources/Helpers/Chat/GetInboxList.swift +++ b/Sources/Helpers/Chat/GetInboxList.swift @@ -57,8 +57,8 @@ private func decryptFeeds( throw PushChat.ChatError.decryptedPrivateKeyNecessary } - let decryptedMsg = try PushChat.decryptMessage( - message: currentFeed.msg!, privateKeyArmored: pgpPrivateKey!) + let decryptedMsg = try await PushChat.decryptMessage( + message: currentFeed.msg!, privateKeyArmored: pgpPrivateKey!, env: env) currentFeed.msg?.messageContent = decryptedMsg } updatedFeeds.append(currentFeed) diff --git a/Sources/Helpers/Crypto/Pgp.swift b/Sources/Helpers/Crypto/Pgp.swift index f4c3a41..cca32b0 100644 --- a/Sources/Helpers/Crypto/Pgp.swift +++ b/Sources/Helpers/Crypto/Pgp.swift @@ -222,6 +222,6 @@ public struct Pgp { let messsageData = message.data(using: .utf8)! let encrypted = try ObjectivePGP.encrypt( messsageData, addSignature: false, using: publicKeys) - return Armor.armored(encrypted, as: .message) + return filterPgpInfo(Armor.armored(encrypted, as: .message)) } } diff --git a/Sources/Helpers/Ipfs/Cid.swift b/Sources/Helpers/Ipfs/Cid.swift index 8dad790..aa2f1b4 100644 --- a/Sources/Helpers/Ipfs/Cid.swift +++ b/Sources/Helpers/Ipfs/Cid.swift @@ -11,9 +11,10 @@ public struct Message: Codable { public var sigType: String public var timestamp: Int? public var encType: String - public var encryptedSecret: String + public var encryptedSecret: String? public var link: String? public var cid: String? + public var sessionKey: String? } public func getCID(env: ENV, cid: String) async throws -> Message { diff --git a/Sources/Helpers/JsonUtils.swift b/Sources/Helpers/JsonUtils.swift index fd068cf..aad78dd 100644 --- a/Sources/Helpers/JsonUtils.swift +++ b/Sources/Helpers/JsonUtils.swift @@ -1,6 +1,6 @@ import Foundation -func getJsonStringFromKV(_ tuples: [(String, String)]) throws -> String { +public func getJsonStringFromKV(_ tuples: [(String, String)]) throws -> String { func removeOccurrences(substring: String, text: String, with: String) -> String { return text.replacingOccurrences(of: substring, with: with) } @@ -18,5 +18,8 @@ func getJsonStringFromKV(_ tuples: [(String, String)]) throws -> String { jsonString = removeOccurrences(substring: "},{", text: jsonString, with: ",") jsonString = removeOccurrences(substring: "}]", text: jsonString, with: "}") jsonString = removeOccurrences(substring: "[{", text: jsonString, with: "{") + jsonString = removeOccurrences(substring: "\"null\"", text: jsonString, with: "null") + jsonString = removeOccurrences(substring: "\\/", text: jsonString, with: "/") + // jsonString = removeOccurrences(substring: "/", text: jsonString, with: "\\n") return jsonString } diff --git a/Tests/Chat/Group/CreateGroupTests.swift b/Tests/Chat/Group/CreateGroupTests.swift index 5c5e769..ef6b8b3 100644 --- a/Tests/Chat/Group/CreateGroupTests.swift +++ b/Tests/Chat/Group/CreateGroupTests.swift @@ -3,45 +3,45 @@ import Push import XCTest class CreateGroupTest: XCTestCase { - func testCreatePublicGroupChat() async throws { - let anotherUser = generateRandomEthereumAddress() + // func testCreatePublicGroupChat() async throws { + // let anotherUser = generateRandomEthereumAddress() - let userPk = getRandomAccount() - let signer = try SignerPrivateKey( - privateKey: userPk - ) - let addrs = try await signer.getAddress() + // let userPk = getRandomAccount() + // let signer = try SignerPrivateKey( + // privateKey: userPk + // ) + // let addrs = try await signer.getAddress() - let user = try await PushUser.create( - options: PushUser.CreateUserOptions( - env: ENV.STAGING, - signer: SignerPrivateKey( - privateKey: userPk - ), - progressHook: nil - )) + // let user = try await PushUser.create( + // options: PushUser.CreateUserOptions( + // env: ENV.STAGING, + // signer: SignerPrivateKey( + // privateKey: userPk + // ), + // progressHook: nil + // )) - let pgpPK = try await Push.PushUser.DecryptPGPKey( - encryptedPrivateKey: user.encryptedPrivateKey, signer: signer) + // let pgpPK = try await Push.PushUser.DecryptPGPKey( + // encryptedPrivateKey: user.encryptedPrivateKey, signer: signer) - let createGroupOptions = try PushChat.CreateGroupOptions( - name: "Group \(anotherUser)", - description: "Group with \(anotherUser) & others", - image: - "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADMElEQVR4nOzVwQnAIBQFQYXff81RUkQCOyDj1YOPnbXWPmeTRef+/3O/OyBjzh3CD95BfqICMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMO0TAAD//2Anhf4QtqobAAAAAElFTkSuQmCC", - members: [anotherUser], - isPublic: true, - creatorAddress: addrs, - creatorPgpPrivateKey: pgpPK, - env: ENV.STAGING - ) + // let createGroupOptions = try PushChat.CreateGroupOptions( + // name: "Group \(anotherUser)", + // description: "Group with \(anotherUser) & others", + // image: + // "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADMElEQVR4nOzVwQnAIBQFQYXff81RUkQCOyDj1YOPnbXWPmeTRef+/3O/OyBjzh3CD95BfqICMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMO0TAAD//2Anhf4QtqobAAAAAElFTkSuQmCC", + // members: [anotherUser], + // isPublic: true, + // creatorAddress: addrs, + // creatorPgpPrivateKey: pgpPK, + // env: ENV.STAGING + // ) - let createdGroup = try await PushChat.createGroup(options: createGroupOptions) - XCTAssertEqual(createdGroup.groupName, createGroupOptions.name) - XCTAssertEqual(createdGroup.isPublic, true) - XCTAssertEqual(createdGroup.groupCreator, walletToPCAIP10(account: addrs)) - XCTAssertEqual(createdGroup.pendingMembers[0].wallet, walletToPCAIP10(account: anotherUser)) - } + // let createdGroup = try await PushChat.createGroup(options: createGroupOptions) + // XCTAssertEqual(createdGroup.groupName, createGroupOptions.name) + // XCTAssertEqual(createdGroup.isPublic, true) + // XCTAssertEqual(createdGroup.groupCreator, walletToPCAIP10(account: addrs)) + // XCTAssertEqual(createdGroup.pendingMembers[0].wallet, walletToPCAIP10(account: anotherUser)) + // } func testCreatePrivateGroupChat() async throws { let anotherUser = generateRandomEthereumAddress() @@ -70,16 +70,18 @@ class CreateGroupTest: XCTestCase { image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADMElEQVR4nOzVwQnAIBQFQYXff81RUkQCOyDj1YOPnbXWPmeTRef+/3O/OyBjzh3CD95BfqICMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMO0TAAD//2Anhf4QtqobAAAAAElFTkSuQmCC", members: [anotherUser], - isPublic: true, + isPublic: false, creatorAddress: addrs, creatorPgpPrivateKey: pgpPK, env: ENV.STAGING ) let createdGroup = try await PushChat.createGroup(options: createGroupOptions) + XCTAssertEqual(createdGroup.groupName, createGroupOptions.name) - XCTAssertEqual(createdGroup.isPublic, true) + XCTAssertEqual(createdGroup.isPublic, false) XCTAssertEqual(createdGroup.groupCreator, walletToPCAIP10(account: addrs)) - XCTAssertEqual(createdGroup.pendingMembers[0].wallet, walletToPCAIP10(account: anotherUser)) + + print("created group ", createdGroup) } } diff --git a/Tests/Chat/Group/SendGroupMsgTests.swift b/Tests/Chat/Group/SendGroupMsgTests.swift index d5dded9..071c833 100644 --- a/Tests/Chat/Group/SendGroupMsgTests.swift +++ b/Tests/Chat/Group/SendGroupMsgTests.swift @@ -34,7 +34,7 @@ class GroupChatSendMsgTests: XCTestCase { pgpPrivateKey: UserPrivateKey )) - let decrytedMessage = try PushChat.decryptMessage( + let decrytedMessage = try await PushChat.decryptMessage( message: msgRes, privateKeyArmored: UserPrivateKey) XCTAssertEqual(msgRes.encType, "pgp") diff --git a/Tests/Chat/P2P/SendTests.swift b/Tests/Chat/P2P/SendTests.swift index cbc2c9b..51eece5 100644 --- a/Tests/Chat/P2P/SendTests.swift +++ b/Tests/Chat/P2P/SendTests.swift @@ -201,7 +201,7 @@ class SendChatsTests: XCTestCase { pgpPrivateKey: UserPrivateKey )) - let res = try PushChat.decryptMessage(message: msg, privateKeyArmored: UserPrivateKey) + let res = try await PushChat.decryptMessage(message: msg, privateKeyArmored: UserPrivateKey) XCTAssertEqual(res, messageToSen2) } diff --git a/Tests/Helper/IpfsTests.swift b/Tests/Helper/IpfsTests.swift index bdfb0af..5e12cd9 100644 --- a/Tests/Helper/IpfsTests.swift +++ b/Tests/Helper/IpfsTests.swift @@ -23,10 +23,10 @@ class IpfsTests: XCTestCase { message.signature.hasSuffix("-----END PGP SIGNATURE-----\n"), "signature should end with appropriate suffix") XCTAssertTrue( - message.encryptedSecret.hasPrefix("-----BEGIN PGP MESSAGE-----"), + message.encryptedSecret!.hasPrefix("-----BEGIN PGP MESSAGE-----"), "encryptedSecret should begin with appropriate prefix") XCTAssertTrue( - message.encryptedSecret.hasSuffix("-----END PGP MESSAGE-----\n"), + message.encryptedSecret!.hasSuffix("-----END PGP MESSAGE-----\n"), "encryptedSecret should end with appropriate suffix") } diff --git a/Tests/e2e/GroupConversation.swift b/Tests/e2e/GroupConversation.swift index 14236cc..756fa20 100644 --- a/Tests/e2e/GroupConversation.swift +++ b/Tests/e2e/GroupConversation.swift @@ -37,14 +37,13 @@ class GroupFullConversation: XCTestCase { let user2PpgpPk = try await PushUser.DecryptPGPKey( encryptedPrivateKey: user2.encryptedPrivateKey, signer: signer2) - let createGroupOptions = try PushChat.CreateGroupOptions( name: "Group \(address1)", description: "Group with \(address1) & others", image: - "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAADMElEQVR4nOzVwQnAIBQFQYXff81RUkQCOyDj1YOPnbXWPmeTRef+/3O/OyBjzh3CD95BfqICMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0CMK0C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UhEUgAAAQAAAAEACAIAAADTED8xAAADMElEQVR4nOzVwQnAIBQFQYXff81RUkQCOyDj1YOPnbXWPmeTRef+/3O///2Anhf4QtqobAAAAAElFTkSuQmCC", members: [address2], - isPublic: true, + isPublic: false, creatorAddress: address1, creatorPgpPrivateKey: user1PpgpPk, env: ENV.STAGING @@ -52,15 +51,17 @@ class GroupFullConversation: XCTestCase { let createdGroup = try await PushChat.createGroup(options: createGroupOptions) - // user 2 joins the group let res = try await Push.PushChat.approve( PushChat.ApproveOptions( requesterAddress: createdGroup.chatId, approverAddress: address2, privateKey: user2PpgpPk, env: .STAGING)) + let newGroup = try await PushChat.getGroupInfoDTO( + chatId: createdGroup.chatId, env: ENV.STAGING)! + + XCTAssert(newGroup.sessionKey!.count > 0) XCTAssert(res.contains(address1)) XCTAssert(res.contains(address2)) } } - diff --git a/Tests/e2e/PrivateGroupDecrypt.swift b/Tests/e2e/PrivateGroupDecrypt.swift new file mode 100644 index 0000000..3434bdc --- /dev/null +++ b/Tests/e2e/PrivateGroupDecrypt.swift @@ -0,0 +1,107 @@ +import Push +import XCTest + +class PrivateGroupSendRead: XCTestCase { + let env = ENV.STAGING + + func testPrivateGroupFetchConvesation() async throws { + + // conversation hash are also called link inside chat messages + let converationHash = try await PushChat.ConversationHash( + conversationId: PG_GROUP_ID, + account: PG_USER, + env: env + )! + + let _ = try await PushChat.Latest( + threadHash: converationHash, + pgpPrivateKey: PG_PGP_KEY, + toDecrypt: true, + env: env + ) + + // print("got message \(message.messageContent)") + // print(message) + + } + + func testPrivateGroupSendPrivateMessage() async throws { + + let _ = try await PushChat.send( + PushChat.SendOptions( + messageContent: "This is the test message", + messageType: "Text", + receiverAddress: PG_GROUP_ID, + account: PG_USER, + pgpPrivateKey: PG_PGP_KEY + )) + + } + +} + +let PG_USER = "0xc95fE6BC0eC97aFA7adF2e98628caC6ec28Bb04c" +let PG_GROUP_ID = "ed3046965676e2118f452aa21318e527bec662dece05f63003e934c116b13e7d" +let PG_PGP_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AkayV8tuzhOtoyUN8upcRRlDmF5QnDLYqr + mJESouIq1QM7adTv0POb8PcVJhZEq0tOezgWEttLVTK13c0ObV1kTFnjvb4U + kEDJnHnHBmPPzxGVeSZ387sVlM3bThJJwkfK9z4PIk1YQzDMzDwbg2sKmdv7 + QdNy/dq7bCBplsE0k/pBwxs/AQ== + =svYB + -----END PGP PRIVATE KEY BLOCK----- + + """