Skip to content

Commit

Permalink
Merge pull request #58 from xmtp/daniel-create-export-keybundle
Browse files Browse the repository at this point in the history
feat: permit creating client from exported key bundle
  • Loading branch information
dmccartney authored Jun 21, 2023
2 parents f126118 + 7ebfec8 commit 2bafc64
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.Signature
import org.xmtp.android.library.push.XMTPPush
import org.xmtp.proto.message.contents.SignatureOuterClass
import org.xmtp.proto.message.contents.PrivateKeyOuterClass
import java.util.Date
import java.util.UUID
import kotlin.coroutines.Continuation
Expand Down Expand Up @@ -132,6 +133,22 @@ class XMTPModule : Module() {
randomClient.address
}

AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String ->
logV("createFromKeyBundle")
val options =
ClientOptions(api = apiEnvironments[environment] ?: apiEnvironments["dev"]!!)
val bundle = PrivateKeyOuterClass.PrivateKeyBundle.parseFrom(Base64.decode(keyBundle, NO_WRAP))
val client = Client().buildFromBundle(bundle = bundle, options = options)
clients[client.address] = client
client.address
}

AsyncFunction("exportKeyBundle") { clientAddress: String ->
logV("exportKeyBundle")
val client = clients[clientAddress] ?: throw XMTPException("No client")
Base64.encodeToString(client.privateKeyBundle.toByteArray(), NO_WRAP)
}

//
// Client API
AsyncFunction("canMessage") { clientAddress: String, peerAddress: String ->
Expand Down
Loading

0 comments on commit 2bafc64

Please sign in to comment.