diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 4d133dbf0..b79f4ad52 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -209,7 +209,7 @@ class XMTPModule : Module() { // // Auth functions // - AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List? -> + AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List?, dbDirectory: String? -> logV("auth") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address) @@ -236,6 +236,7 @@ class XMTPModule : Module() { enableAlphaMls = enableAlphaMls == true, appContext = context, dbEncryptionKey = encryptionKeyBytes, + dbDirectory = dbDirectory ) val client = Client().create(account = reactSigner, options = options) clients[address] = client @@ -250,7 +251,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? -> + AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List?, dbDirectory: String? -> logV("createRandom") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) val privateKey = PrivateKeyBuilder() @@ -276,6 +277,7 @@ class XMTPModule : Module() { enableAlphaMls = enableAlphaMls == true, appContext = context, dbEncryptionKey = encryptionKeyBytes, + dbDirectory = dbDirectory ) val randomClient = Client().create(account = privateKey, options = options) ContentJson.Companion @@ -286,7 +288,7 @@ class XMTPModule : Module() { ) } - AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean?, dbEncryptionKey: List? -> + AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean?, dbEncryptionKey: List?, dbDirectory: String? -> logV("createFromKeyBundle") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) @@ -301,6 +303,7 @@ class XMTPModule : Module() { enableAlphaMls = enableAlphaMls == true, appContext = context, dbEncryptionKey = encryptionKeyBytes, + dbDirectory = dbDirectory ) val bundle = PrivateKeyOuterClass.PrivateKeyBundle.parseFrom( diff --git a/src/index.ts b/src/index.ts index b0b6d10d2..734909119 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,7 +64,8 @@ export async function auth( hasCreateIdentityCallback?: boolean | undefined, hasEnableIdentityCallback?: boolean | undefined, enableAlphaMls?: boolean | undefined, - dbEncryptionKey?: Uint8Array | undefined + dbEncryptionKey?: Uint8Array | undefined, + dbDirectory?: string | undefined ) { return await XMTPModule.auth( address, @@ -73,7 +74,8 @@ export async function auth( hasCreateIdentityCallback, hasEnableIdentityCallback, enableAlphaMls, - dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined + dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined, + dbDirectory ) } @@ -87,7 +89,8 @@ export async function createRandom( hasCreateIdentityCallback?: boolean | undefined, hasEnableIdentityCallback?: boolean | undefined, enableAlphaMls?: boolean | undefined, - dbEncryptionKey?: Uint8Array | undefined + dbEncryptionKey?: Uint8Array | undefined, + dbDirectory?: string | undefined ): Promise { return await XMTPModule.createRandom( environment, @@ -95,7 +98,8 @@ export async function createRandom( hasCreateIdentityCallback, hasEnableIdentityCallback, enableAlphaMls, - dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined + dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined, + dbDirectory ) } @@ -104,14 +108,16 @@ export async function createFromKeyBundle( environment: 'local' | 'dev' | 'production', appVersion?: string | undefined, enableAlphaMls?: boolean | undefined, - dbEncryptionKey?: Uint8Array | undefined + dbEncryptionKey?: Uint8Array | undefined, + dbDirectory?: string | undefined ): Promise { return await XMTPModule.createFromKeyBundle( keyBundle, environment, appVersion, enableAlphaMls, - dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined + dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined, + dbDirectory ) } diff --git a/src/lib/Client.ts b/src/lib/Client.ts index e2675d6c2..5a2859fb3 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -108,7 +108,8 @@ export class Client< Boolean(createSubscription), Boolean(enableSubscription), Boolean(options.enableAlphaMls), - options.dbEncryptionKey + options.dbEncryptionKey, + options.dbDirectory ) })().catch((error) => { console.error('ERROR in create: ', error) @@ -148,7 +149,8 @@ export class Client< Boolean(createSubscription), Boolean(enableSubscription), Boolean(options.enableAlphaMls), - options.dbEncryptionKey + options.dbEncryptionKey, + options.dbDirectory ) this.removeSubscription(enableSubscription) this.removeSubscription(createSubscription) @@ -183,6 +185,7 @@ export class Client< options.appVersion, Boolean(options.enableAlphaMls), options.dbEncryptionKey + options.dbDirectory ) return new Client( @@ -468,6 +471,10 @@ 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 directory + */ + dbDirectory?: string } export type KeyType = { @@ -485,6 +492,7 @@ export function defaultOptions(opts?: Partial): ClientOptions { env: 'dev', enableAlphaMls: false, dbEncryptionKey: undefined, + dbDirectory: undefined, } return { ..._defaultOptions, ...opts } as ClientOptions