From 3fa77a36959d2a57739fb921505b6ce5c21e658c Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Mon, 22 Jan 2024 10:09:56 -0800 Subject: [PATCH] Update for latest uniffi (#219) --- Package.resolved | 4 ++-- Package.swift | 2 +- Sources/XMTPiOS/Contacts.swift | 10 +++++----- Sources/XMTPiOS/Extensions/Ffi.swift | 4 ++-- Sources/XMTPiOS/KeyUtil.swift | 6 +++--- Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift | 2 +- Sources/XMTPiOS/Messages/Signature.swift | 6 +++--- Tests/XMTPTests/IntegrationTests.swift | 8 ++++---- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Package.resolved b/Package.resolved index f24dcde4..13f2700c 100644 --- a/Package.resolved +++ b/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift", "state" : { - "branch" : "60b99d0", - "revision" : "60b99d04f642a7e2b15156d818dabc4aab65b1c0" + "branch" : "ccbf6ac", + "revision" : "ccbf6ac71b8c5a89c3078d8dc4057123bea8a291" } }, { diff --git a/Package.swift b/Package.swift index be7444d8..de004935 100644 --- a/Package.swift +++ b/Package.swift @@ -26,7 +26,7 @@ let package = Package( .package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", exact: "0.3.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), - .package(url: "https://github.com/xmtp/libxmtp-swift", revision: "60b99d0"), + .package(url: "https://github.com/xmtp/libxmtp-swift", revision: "ccbf6ac"), // .package(path: "../libxmtp-swift") ], targets: [ diff --git a/Sources/XMTPiOS/Contacts.swift b/Sources/XMTPiOS/Contacts.swift index 662333ba..2252eb2f 100644 --- a/Sources/XMTPiOS/Contacts.swift +++ b/Sources/XMTPiOS/Contacts.swift @@ -49,7 +49,7 @@ public class ConsentList { privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes publicKey = client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes // swiftlint:disable no_optional_try - identifier = try? LibXMTP.generatePrivatePreferencesTopicIdentifier(privateKey: privateKey.bytes) + identifier = try? LibXMTP.generatePrivatePreferencesTopicIdentifier(privateKey: privateKey) // swiftlint:enable no_optional_try } @@ -65,7 +65,7 @@ public class ConsentList { var preferences: [PrivatePreferencesAction] = [] for envelope in envelopes { - let payload = try LibXMTP.userPreferencesDecrypt(publicKey: publicKey.bytes, privateKey: privateKey.bytes, message: envelope.message.bytes) + let payload = try LibXMTP.userPreferencesDecrypt(publicKey: publicKey, privateKey: privateKey, message: envelope.message) try preferences.append(PrivatePreferencesAction(serializedData: Data(payload))) } @@ -99,9 +99,9 @@ public class ConsentList { } let message = try LibXMTP.userPreferencesEncrypt( - publicKey: publicKey.bytes, - privateKey: privateKey.bytes, - message: payload.serializedData().bytes + publicKey: publicKey, + privateKey: privateKey, + message: payload.serializedData() ) let envelope = Envelope( diff --git a/Sources/XMTPiOS/Extensions/Ffi.swift b/Sources/XMTPiOS/Extensions/Ffi.swift index ba7b7b52..af948793 100644 --- a/Sources/XMTPiOS/Extensions/Ffi.swift +++ b/Sources/XMTPiOS/Extensions/Ffi.swift @@ -32,7 +32,7 @@ extension FfiPagingInfo { extension Cursor { var toFFI: FfiCursor { - FfiCursor(digest: [UInt8](self.index.digest), senderTimeNs: self.index.senderTimeNs) + FfiCursor(digest: self.index.digest, senderTimeNs: self.index.senderTimeNs) } } @@ -148,7 +148,7 @@ extension FfiV2BatchQueryResponse { extension Envelope { var toFFI: FfiEnvelope { - FfiEnvelope(contentTopic: contentTopic, timestampNs: timestampNs, message: [UInt8](message)) + FfiEnvelope(contentTopic: contentTopic, timestampNs: timestampNs, message: message) } } diff --git a/Sources/XMTPiOS/KeyUtil.swift b/Sources/XMTPiOS/KeyUtil.swift index 83ae7219..a9acaeca 100644 --- a/Sources/XMTPiOS/KeyUtil.swift +++ b/Sources/XMTPiOS/KeyUtil.swift @@ -21,16 +21,16 @@ enum KeyUtilError: Error { // Copied from web3.swift since its version is `internal` enum KeyUtilx { static func generatePublicKey(from data: Data) throws -> Data { - let vec = try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: data.bytes) + let vec = try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: data) return Data(vec) } static func recoverPublicKeySHA256(from data: Data, message: Data) throws -> Data { - return try Data(LibXMTP.recoverPublicKeyK256Sha256(message: message.bytes, signature: data.bytes)) + return try Data(LibXMTP.recoverPublicKeyK256Sha256(message: message, signature: data)) } static func recoverPublicKeyKeccak256(from data: Data, message: Data) throws -> Data { - return Data(try LibXMTP.recoverPublicKeyK256Keccak256(message: message.bytes, signature: data.bytes)) + return Data(try LibXMTP.recoverPublicKeyK256Keccak256(message: message, signature: data)) } static func sign(message: Data, with privateKey: Data, hashing: Bool) throws -> Data { diff --git a/Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift b/Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift index 8eae75bc..bb7b04cb 100644 --- a/Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift +++ b/Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift @@ -34,7 +34,7 @@ extension PrivateKeyBundleV2 { } func sharedSecret(private privateData: Data, public publicData: Data) throws -> Data { - return Data(try LibXMTP.diffieHellmanK256(privateKeyBytes: [UInt8](privateData), publicKeyBytes: [UInt8](publicData))) + return Data(try LibXMTP.diffieHellmanK256(privateKeyBytes: privateData, publicKeyBytes: publicData)) } func findPreKey(_ myPreKey: SignedPublicKey) throws -> SignedPrivateKey { diff --git a/Sources/XMTPiOS/Messages/Signature.swift b/Sources/XMTPiOS/Messages/Signature.swift index 791c753f..01bf381f 100644 --- a/Sources/XMTPiOS/Messages/Signature.swift +++ b/Sources/XMTPiOS/Messages/Signature.swift @@ -104,9 +104,9 @@ extension Signature { func verify(signedBy: PublicKey, digest: Data) throws -> Bool { do { _ = try LibXMTP.verifyK256Sha256( - signedBy: signedBy.secp256K1Uncompressed.bytes.bytes, - message: digest.bytes, - signature: ecdsaCompact.bytes.bytes, + signedBy: signedBy.secp256K1Uncompressed.bytes, + message: digest, + signature: ecdsaCompact.bytes, recoveryId: UInt8(ecdsaCompact.recovery) ) } catch { diff --git a/Tests/XMTPTests/IntegrationTests.swift b/Tests/XMTPTests/IntegrationTests.swift index 4e33ad45..37833a77 100644 --- a/Tests/XMTPTests/IntegrationTests.swift +++ b/Tests/XMTPTests/IntegrationTests.swift @@ -494,7 +494,7 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes.bytes)) + key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes)) let client = try await XMTPiOS.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -564,7 +564,7 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes.bytes)) + key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes)) let client = try await XMTPiOS.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -587,7 +587,7 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes.bytes)) + key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes)) let client = try await XMTPiOS.Client.create(account: key) XCTAssertEqual(client.apiClient.environment, .dev) @@ -616,7 +616,7 @@ final class IntegrationTests: XCTestCase { var key = PrivateKey() key.secp256K1.bytes = Data(keyBytes) - key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes.bytes)) + key.publicKey.secp256K1Uncompressed.bytes = Data(try LibXMTP.publicKeyFromPrivateKeyK256(privateKeyBytes: keyBytes)) let client = try await XMTPiOS.Client.create(account: key)