Skip to content

Commit

Permalink
remove the ability to set a dbPath
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed May 29, 2024
1 parent a6ec504 commit 80e7739
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class XMTPModule : Module() {
//
// Auth functions
//
AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>?, dbPath: String? ->
AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>? ->
logV("auth")
requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment)
val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address)
Expand All @@ -217,7 +217,6 @@ class XMTPModule : Module() {
enableAlphaMls = enableAlphaMls == true,
appContext = context,
dbEncryptionKey = encryptionKeyBytes,
dbPath = dbPath
)
clients[address] = Client().create(account = reactSigner, options = options)
ContentJson.Companion
Expand All @@ -231,7 +230,7 @@ class XMTPModule : Module() {
}

// Generate a random wallet and set the client to that
AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>?, dbPath: String? ->
AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>? ->
logV("createRandom")
requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment)
val privateKey = PrivateKeyBuilder()
Expand All @@ -257,15 +256,14 @@ class XMTPModule : Module() {
enableAlphaMls = enableAlphaMls == true,
appContext = context,
dbEncryptionKey = encryptionKeyBytes,
dbPath = dbPath
)
val randomClient = Client().create(account = privateKey, options = options)
ContentJson.Companion
clients[randomClient.address] = randomClient
randomClient.address
}

AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>?, dbPath: String? ->
AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean?, dbEncryptionKey: List<Int>? ->
logV("createFromKeyBundle")
requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment)

Expand All @@ -280,7 +278,6 @@ class XMTPModule : Module() {
enableAlphaMls = enableAlphaMls == true,
appContext = context,
dbEncryptionKey = encryptionKeyBytes,
dbPath = dbPath
)
val bundle =
PrivateKeyOuterClass.PrivateKeyBundle.parseFrom(
Expand Down
61 changes: 0 additions & 61 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import RNFS from 'react-native-fs'
import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage'

import {
Expand Down Expand Up @@ -68,66 +67,6 @@ test('can delete a local database', async () => {
return true
})

test('can make a MLS V3 client with encryption key and database path', async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const dbDirPath = `${RNFS.DocumentDirectoryPath}/xmtp_db`
const directoryExists = await RNFS.exists(dbDirPath)
if (!directoryExists) {
await RNFS.mkdir(dbDirPath)
}
const timestamp = Date.now().toString()
const dbPath = `${dbDirPath}/myCoolApp${timestamp}.db3`

const key = new Uint8Array([
233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64,
166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145,
])
const client = await Client.createRandom({
env: 'local',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true,
dbEncryptionKey: key,
dbPath,
})

const anotherClient = await Client.createRandom({
env: 'local',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true,
dbEncryptionKey: key,
})

await client.conversations.newGroup([anotherClient.address])
assert(
(await client.conversations.listGroups()).length === 1,
`should have a group size of 1 but was ${
(await client.conversations.listGroups()).length
}`
)

const bundle = await client.exportKeyBundle()
const clientFromBundle = await Client.createFromKeyBundle(bundle, {
env: 'local',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true,
dbEncryptionKey: key,
dbPath,
})

assert(
clientFromBundle.address === client.address,
`clients dont match ${client.address} and ${clientFromBundle.address}`
)

assert(
(await clientFromBundle.conversations.listGroups()).length === 1,
`should have a group size of 1 but was ${
(await clientFromBundle.conversations.listGroups()).length
}`
)
return true
})

test('can make a MLS V3 client from bundle', async () => {
const key = new Uint8Array([
233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64,
Expand Down
20 changes: 10 additions & 10 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class XMTPModule: Module {
//
// Auth functions
//
AsyncFunction("auth") { (address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?, dbPath: String?) in
AsyncFunction("auth") { (address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?) in
try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment)

let signer = ReactNativeSigner(module: self, address: address)
Expand All @@ -116,7 +116,7 @@ public class XMTPModule: Module {
let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil
let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!)

let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData, dbPath: dbPath)
let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData)
try await clientsManager.updateClient(key: address, client: await XMTP.Client.create(account: signer, options: options))
self.signer = nil
sendEvent("authed")
Expand All @@ -127,7 +127,7 @@ public class XMTPModule: Module {
}

// Generate a random wallet and set the client to that
AsyncFunction("createRandom") { (environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?, dbPath: String?) -> String in
AsyncFunction("createRandom") { (environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?) -> String in
try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment)

let privateKey = try PrivateKey.generate()
Expand All @@ -141,15 +141,15 @@ public class XMTPModule: Module {
let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil
let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!)

let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData, dbPath: dbPath)
let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData)
let client = try await Client.create(account: privateKey, options: options)

await clientsManager.updateClient(key: client.address, client: client)
return client.address
}

// Create a client using its serialized key bundle.
AsyncFunction("createFromKeyBundle") { (keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?, dbPath: String?) -> String in
AsyncFunction("createFromKeyBundle") { (keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?) -> String in
try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment)

do {
Expand All @@ -159,7 +159,7 @@ public class XMTPModule: Module {
throw Error.invalidKeyBundle
}
let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!)
let options = createClientConfig(env: environment, appVersion: appVersion, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData, dbPath: dbPath)
let options = createClientConfig(env: environment, appVersion: appVersion, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData)
let client = try await Client.from(bundle: bundle, options: options)
await clientsManager.updateClient(key: client.address, client: client)
return client.address
Expand Down Expand Up @@ -1023,27 +1023,27 @@ public class XMTPModule: Module {
// Helpers
//

func createClientConfig(env: String, appVersion: String?, preEnableIdentityCallback: PreEventCallback? = nil, preCreateIdentityCallback: PreEventCallback? = nil, mlsAlpha: Bool = false, encryptionKey: Data? = nil, dbPath: String? = nil) -> XMTP.ClientOptions {
func createClientConfig(env: String, appVersion: String?, preEnableIdentityCallback: PreEventCallback? = nil, preCreateIdentityCallback: PreEventCallback? = nil, mlsAlpha: Bool = false, encryptionKey: Data? = nil) -> XMTP.ClientOptions {
// Ensure that all codecs have been registered.
switch env {
case "local":
return XMTP.ClientOptions(api: XMTP.ClientOptions.Api(
env: XMTP.XMTPEnvironment.local,
isSecure: false,
appVersion: appVersion
), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey, mlsDbPath: dbPath)
), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey)
case "production":
return XMTP.ClientOptions(api: XMTP.ClientOptions.Api(
env: XMTP.XMTPEnvironment.production,
isSecure: true,
appVersion: appVersion
), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: false, mlsEncryptionKey: encryptionKey, mlsDbPath: dbPath)
), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: false, mlsEncryptionKey: encryptionKey)
default:
return XMTP.ClientOptions(api: XMTP.ClientOptions.Api(
env: XMTP.XMTPEnvironment.dev,
isSecure: true,
appVersion: appVersion
), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey, mlsDbPath: dbPath)
), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey)
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export async function auth(
hasEnableIdentityCallback?: boolean | undefined,
enableAlphaMls?: boolean | undefined,
dbEncryptionKey?: Uint8Array | undefined,

Check warning on line 54 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
dbPath?: string | undefined
) {
return await XMTPModule.auth(
address,
Expand All @@ -62,7 +61,6 @@ export async function auth(
hasEnableIdentityCallback,
enableAlphaMls,
dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined,

Check warning on line 63 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
dbPath
)
}

Expand All @@ -77,7 +75,6 @@ export async function createRandom(
hasEnableIdentityCallback?: boolean | undefined,
enableAlphaMls?: boolean | undefined,
dbEncryptionKey?: Uint8Array | undefined,

Check warning on line 77 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
dbPath?: string | undefined
): Promise<string> {
return await XMTPModule.createRandom(
environment,
Expand All @@ -86,7 +83,6 @@ export async function createRandom(
hasEnableIdentityCallback,
enableAlphaMls,
dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined,

Check warning on line 85 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
dbPath
)
}

Expand All @@ -96,15 +92,13 @@ export async function createFromKeyBundle(
appVersion?: string | undefined,
enableAlphaMls?: boolean | undefined,
dbEncryptionKey?: Uint8Array | undefined,

Check warning on line 94 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
dbPath?: string | undefined
): Promise<string> {
return await XMTPModule.createFromKeyBundle(
keyBundle,
environment,
appVersion,
enableAlphaMls,
dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined,

Check warning on line 101 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
dbPath
)
}

Expand Down
8 changes: 0 additions & 8 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export class Client<
Boolean(enableSubscription),
Boolean(options.enableAlphaMls),
options.dbEncryptionKey,

Check warning on line 110 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
options.dbPath
)
})().catch((error) => {
console.error('ERROR in create: ', error)
Expand Down Expand Up @@ -149,7 +148,6 @@ export class Client<
Boolean(enableSubscription),
Boolean(options.enableAlphaMls),
options.dbEncryptionKey,

Check warning on line 150 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
options.dbPath
)
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)
Expand Down Expand Up @@ -180,7 +178,6 @@ export class Client<
options.appVersion,
Boolean(options.enableAlphaMls),
options.dbEncryptionKey,

Check warning on line 180 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
options.dbPath
)
return new Client(address, opts?.codecs || [])
}
Expand Down Expand Up @@ -445,10 +442,6 @@ export type ClientOptions = {
* OPTIONAL specify the encryption key for the database. The encryption key must be exactly 32 bytes.
*/
dbEncryptionKey?: Uint8Array
/**
* OPTIONAL specify the XMTP managed database path
*/
dbPath?: string
}

export type KeyType = {
Expand All @@ -466,7 +459,6 @@ export function defaultOptions(opts?: Partial<ClientOptions>): ClientOptions {
env: 'dev',
enableAlphaMls: false,
dbEncryptionKey: undefined,
dbPath: undefined,
}

return { ..._defaultOptions, ...opts } as ClientOptions
Expand Down

0 comments on commit 80e7739

Please sign in to comment.