Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for latest uniffi #219

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/xmtp/libxmtp-swift",
"state" : {
"branch" : "60b99d0",
"revision" : "60b99d04f642a7e2b15156d818dabc4aab65b1c0"
"branch" : "ccbf6ac",
"revision" : "ccbf6ac71b8c5a89c3078d8dc4057123bea8a291"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
10 changes: 5 additions & 5 deletions Sources/XMTPiOS/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)))
}
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions Sources/XMTPiOS/Extensions/Ffi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/XMTPiOS/KeyUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Messages/PrivateKeyBundleV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions Sources/XMTPiOS/Messages/Signature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions Tests/XMTPTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down