Skip to content

Commit

Permalink
add the swift side
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Feb 2, 2024
1 parent dee03d0 commit 3a7d925
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.xmtp.android.library.messages.Pagination
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.Signature
import org.xmtp.android.library.messages.toPublicKeyBundle
import org.xmtp.android.library.messages.toV2
import org.xmtp.android.library.push.XMTPPush
import org.xmtp.proto.keystore.api.v1.Keystore.TopicMap.TopicData
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
Expand Down Expand Up @@ -238,7 +239,7 @@ class XMTPModule : Module() {
)
}
}
val privateKeyBundle = client.privateKeyBundleV1
val privateKeyBundle = client.privateKeyBundle.v2
val key = if (keyType == "prekey") {
privateKeyBundle.preKeysList[preKeyIndex]
} else {
Expand All @@ -253,7 +254,7 @@ class XMTPModule : Module() {
AsyncFunction("exportPublicKeyBundle") { clientAddress: String ->
logV("exportPublicKeyBundle")
val client = clients[clientAddress] ?: throw XMTPException("No client")
client.privateKeyBundleV1.toPublicKeyBundle().toByteArray().map { it.toInt() and 0xFF }
client.privateKeyBundle.toV2().toPublicKeyBundle().toByteArray().map { it.toInt() and 0xFF }
}

AsyncFunction("exportKeyBundle") { clientAddress: String ->
Expand Down
25 changes: 24 additions & 1 deletion ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,32 @@ public class XMTPModule: Module {
throw error
}
}

AsyncFunction("sign") { (clientAddress: String, digest: [UInt8], keyType: String, preKeyIndex: Int) -> [UInt8] in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}

let privateKeyBundle = client.privateKeyBundle
let key = if (keyType == "prekey") {
privateKeyBundle.v2.preKeys[preKeyIndex]
} else {
privateKeyBundle.v2.identityKey
}
let signature = await PrivateKey(key).sign(Data(digest))
return Array(Data(signature))
}

AsyncFunction("exportKeyBundle") { (clientAddress: String) -> [UInt8] in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
let bundle = try client.publicKeyBundle.serializedData()
return Array(bundle)
}

// Export the client's serialized key bundle.
AsyncFunction("exportKeyBundle") { (clientAddress: String) -> String in
AsyncFunction("exportPublicKeyBundle") { (clientAddress: String) -> String in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
}
Expand Down

0 comments on commit 3a7d925

Please sign in to comment.