From 9b346b907841ca861182da11d118bfdc94ff8ec6 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 20 Feb 2024 23:16:29 -0800 Subject: [PATCH 01/11] add the ability to create with an encryption key --- src/index.ts | 18 ++++++++++++------ src/lib/Client.ts | 12 +++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0f31ff4ff..cbbe351fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,7 +45,8 @@ export async function auth( appVersion?: string | undefined, hasCreateIdentityCallback?: boolean | undefined, hasEnableIdentityCallback?: boolean | undefined, - enableAlphaMls?: boolean | undefined + enableAlphaMls?: boolean | undefined, + encryptionKey?: Uint8Array | undefined ) { return await XMTPModule.auth( address, @@ -53,7 +54,8 @@ export async function auth( appVersion, hasCreateIdentityCallback, hasEnableIdentityCallback, - enableAlphaMls + enableAlphaMls, + encryptionKey ? Array.from(encryptionKey) : undefined ) } @@ -66,14 +68,16 @@ export async function createRandom( appVersion?: string | undefined, hasCreateIdentityCallback?: boolean | undefined, hasEnableIdentityCallback?: boolean | undefined, - enableAlphaMls?: boolean | undefined + enableAlphaMls?: boolean | undefined, + encryptionKey?: Uint8Array | undefined ): Promise { return await XMTPModule.createRandom( environment, appVersion, hasCreateIdentityCallback, hasEnableIdentityCallback, - enableAlphaMls + enableAlphaMls, + encryptionKey ? Array.from(encryptionKey) : undefined ) } @@ -81,13 +85,15 @@ export async function createFromKeyBundle( keyBundle: string, environment: 'local' | 'dev' | 'production', appVersion?: string | undefined, - enableAlphaMls?: boolean | undefined + enableAlphaMls?: boolean | undefined, + encryptionKey?: Uint8Array | undefined ): Promise { return await XMTPModule.createFromKeyBundle( keyBundle, environment, appVersion, - enableAlphaMls + enableAlphaMls, + encryptionKey ? Array.from(encryptionKey) : undefined ) } diff --git a/src/lib/Client.ts b/src/lib/Client.ts index c3d1b9b77..72a0f1ac6 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -107,7 +107,8 @@ export class Client< options.appVersion, Boolean(createSubscription), Boolean(enableSubscription), - Boolean(options.enableAlphaMls) + Boolean(options.enableAlphaMls), + options.encryptionKey ) })() }) @@ -144,7 +145,8 @@ export class Client< options.appVersion, Boolean(createSubscription), Boolean(enableSubscription), - Boolean(options.enableAlphaMls) + Boolean(options.enableAlphaMls), + options.encryptionKey ) this.removeSubscription(enableSubscription) this.removeSubscription(createSubscription) @@ -173,7 +175,8 @@ export class Client< keyBundle, options.env, options.appVersion, - Boolean(options.enableAlphaMls) + Boolean(options.enableAlphaMls), + options.encryptionKey ) return new Client(address, opts?.codecs || []) } @@ -427,6 +430,8 @@ export type ClientOptions = { * Specify whether to enable Alpha version of MLS (Group Chat) */ enableAlphaMls?: boolean + + encryptionKey?: Uint8Array } export type KeyType = { @@ -443,6 +448,7 @@ export function defaultOptions(opts?: Partial): ClientOptions { const _defaultOptions: ClientOptions = { env: 'dev', enableAlphaMls: false, + encryptionKey: undefined, } return { ..._defaultOptions, ...opts } as ClientOptions From 3a01116527b66fc79b1408e3ce5e44cfbd7b7d57 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 20 Feb 2024 23:27:57 -0800 Subject: [PATCH 02/11] fix: allow passing of encryption key in iOS --- ios/XMTPModule.swift | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 3f1dd4172..6be44bc27 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -78,7 +78,7 @@ public class XMTPModule: Module { // // Auth functions // - AsyncFunction("auth") { (address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?) in + AsyncFunction("auth") { (address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, encryptionKey: [UInt8]?) in try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment) let signer = ReactNativeSigner(module: self, address: address) @@ -91,7 +91,9 @@ public class XMTPModule: Module { } let preCreateIdentityCallback: PreEventCallback? = hasCreateIdentityCallback ?? false ? self.preCreateIdentityCallback : nil let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil - let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true) + let encryptionKeyData = encryptionKey == nil ? nil : Data(encryptionKey!) + + 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") @@ -102,7 +104,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?) -> String in + AsyncFunction("createRandom") { (environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, encryptionKey: [UInt8]?) -> String in try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment) let privateKey = try PrivateKey.generate() @@ -114,8 +116,9 @@ public class XMTPModule: Module { } let preCreateIdentityCallback: PreEventCallback? = hasCreateIdentityCallback ?? false ? self.preCreateIdentityCallback : nil let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil + let encryptionKeyData = encryptionKey == nil ? nil : Data(encryptionKey!) - let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true) + 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) @@ -123,7 +126,7 @@ public class XMTPModule: Module { } // Create a client using its serialized key bundle. - AsyncFunction("createFromKeyBundle") { (keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Bool?) -> String in + AsyncFunction("createFromKeyBundle") { (keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Bool?, encryptionKey: [UInt8]?) -> String in try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment) do { @@ -132,8 +135,8 @@ public class XMTPModule: Module { else { throw Error.invalidKeyBundle } - - let options = createClientConfig(env: environment, appVersion: appVersion, mlsAlpha: enableAlphaMls == true) + let encryptionKeyData = encryptionKey == nil ? nil : Data(encryptionKey!) + 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 @@ -838,7 +841,7 @@ public class XMTPModule: Module { // Helpers // - func createClientConfig(env: String, appVersion: String?, preEnableIdentityCallback: PreEventCallback? = nil, preCreateIdentityCallback: PreEventCallback? = nil, mlsAlpha: Bool = false) -> 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": @@ -846,19 +849,19 @@ public class XMTPModule: Module { env: XMTP.XMTPEnvironment.local, isSecure: false, appVersion: appVersion - ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha) + ), 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) + ), 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) + ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey) } } From 0f7dc1b05b65b16c628033d9653f5b1e33e1c12b Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 20 Feb 2024 23:35:50 -0800 Subject: [PATCH 03/11] do it on android as well --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index efd8582b6..8c0e005b8 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -170,7 +170,7 @@ class XMTPModule : Module() { // // Auth functions // - AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean? -> + AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, encryptionKey: List? -> logV("auth") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address) @@ -185,13 +185,18 @@ class XMTPModule : Module() { val preEnableIdentityCallback: PreEventCallback? = preEnableIdentityCallback.takeIf { hasEnableIdentityCallback == true } val context = if (enableAlphaMls == true) context else null + val encryptionKeyBytes = + encryptionKey?.foldIndexed(ByteArray(encryptionKey.size)) { i, a, v -> + a.apply { set(i, v.toByte()) } + } val options = ClientOptions( api = apiEnvironments(environment, appVersion), preCreateIdentityCallback = preCreateIdentityCallback, preEnableIdentityCallback = preEnableIdentityCallback, enableAlphaMls = enableAlphaMls == true, - appContext = context + appContext = context, + dbEncryptionKey = encryptionKeyBytes ) clients[address] = Client().create(account = reactSigner, options = options) ContentJson.Companion @@ -205,7 +210,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? -> + AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, encryptionKey: List? -> logV("createRandom") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) val privateKey = PrivateKeyBuilder() @@ -219,13 +224,18 @@ class XMTPModule : Module() { val preEnableIdentityCallback: PreEventCallback? = preEnableIdentityCallback.takeIf { hasEnableIdentityCallback == true } val context = if (enableAlphaMls == true) context else null + val encryptionKeyBytes = + encryptionKey?.foldIndexed(ByteArray(encryptionKey.size)) { i, a, v -> + a.apply { set(i, v.toByte()) } + } val options = ClientOptions( api = apiEnvironments(environment, appVersion), preCreateIdentityCallback = preCreateIdentityCallback, preEnableIdentityCallback = preEnableIdentityCallback, enableAlphaMls = enableAlphaMls == true, - appContext = context + appContext = context, + dbEncryptionKey = encryptionKeyBytes ) val randomClient = Client().create(account = privateKey, options = options) ContentJson.Companion @@ -233,15 +243,21 @@ class XMTPModule : Module() { randomClient.address } - AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean? -> + AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean?, encryptionKey: List? -> logV("createFromKeyBundle") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) + try { val context = if (enableAlphaMls == true) context else null + val encryptionKeyBytes = + encryptionKey?.foldIndexed(ByteArray(encryptionKey.size)) { i, a, v -> + a.apply { set(i, v.toByte()) } + } val options = ClientOptions( api = apiEnvironments(environment, appVersion), enableAlphaMls = enableAlphaMls == true, - appContext = context + appContext = context, + dbEncryptionKey = encryptionKeyBytes ) val bundle = PrivateKeyOuterClass.PrivateKeyBundle.parseFrom( From f9b20f57697353d22247a34fac72ce17fa952e1b Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 21 Feb 2024 06:46:30 -0800 Subject: [PATCH 04/11] add dbPath and rename encryption key --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 21 ++++++++------- ios/XMTPModule.swift | 26 +++++++++---------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 8c0e005b8..f3a8e7449 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -170,7 +170,7 @@ class XMTPModule : Module() { // // Auth functions // - AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, encryptionKey: List? -> + AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List?, dbPath: String? -> logV("auth") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address) @@ -186,7 +186,7 @@ class XMTPModule : Module() { preEnableIdentityCallback.takeIf { hasEnableIdentityCallback == true } val context = if (enableAlphaMls == true) context else null val encryptionKeyBytes = - encryptionKey?.foldIndexed(ByteArray(encryptionKey.size)) { i, a, v -> + dbEncryptionKey?.foldIndexed(ByteArray(dbEncryptionKey.size)) { i, a, v -> a.apply { set(i, v.toByte()) } } @@ -196,7 +196,8 @@ class XMTPModule : Module() { preEnableIdentityCallback = preEnableIdentityCallback, enableAlphaMls = enableAlphaMls == true, appContext = context, - dbEncryptionKey = encryptionKeyBytes + dbEncryptionKey = encryptionKeyBytes, + dbPath = dbPath ) clients[address] = Client().create(account = reactSigner, options = options) ContentJson.Companion @@ -210,7 +211,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?, encryptionKey: List? -> + AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean?, enableAlphaMls: Boolean?, dbEncryptionKey: List?, dbPath: String? -> logV("createRandom") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) val privateKey = PrivateKeyBuilder() @@ -225,7 +226,7 @@ class XMTPModule : Module() { preEnableIdentityCallback.takeIf { hasEnableIdentityCallback == true } val context = if (enableAlphaMls == true) context else null val encryptionKeyBytes = - encryptionKey?.foldIndexed(ByteArray(encryptionKey.size)) { i, a, v -> + dbEncryptionKey?.foldIndexed(ByteArray(dbEncryptionKey.size)) { i, a, v -> a.apply { set(i, v.toByte()) } } @@ -235,7 +236,8 @@ class XMTPModule : Module() { preEnableIdentityCallback = preEnableIdentityCallback, enableAlphaMls = enableAlphaMls == true, appContext = context, - dbEncryptionKey = encryptionKeyBytes + dbEncryptionKey = encryptionKeyBytes, + dbPath = dbPath ) val randomClient = Client().create(account = privateKey, options = options) ContentJson.Companion @@ -243,21 +245,22 @@ class XMTPModule : Module() { randomClient.address } - AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean?, encryptionKey: List? -> + AsyncFunction("createFromKeyBundle") { keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Boolean?, dbEncryptionKey: List?, dbPath: String? -> logV("createFromKeyBundle") requireNotProductionEnvForAlphaMLS(enableAlphaMls, environment) try { val context = if (enableAlphaMls == true) context else null val encryptionKeyBytes = - encryptionKey?.foldIndexed(ByteArray(encryptionKey.size)) { i, a, v -> + dbEncryptionKey?.foldIndexed(ByteArray(dbEncryptionKey.size)) { i, a, v -> a.apply { set(i, v.toByte()) } } val options = ClientOptions( api = apiEnvironments(environment, appVersion), enableAlphaMls = enableAlphaMls == true, appContext = context, - dbEncryptionKey = encryptionKeyBytes + dbEncryptionKey = encryptionKeyBytes, + dbPath = dbPath ) val bundle = PrivateKeyOuterClass.PrivateKeyBundle.parseFrom( diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 6be44bc27..a534e4992 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -78,7 +78,7 @@ public class XMTPModule: Module { // // Auth functions // - AsyncFunction("auth") { (address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, encryptionKey: [UInt8]?) in + AsyncFunction("auth") { (address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?, dbPath: String?) in try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment) let signer = ReactNativeSigner(module: self, address: address) @@ -91,9 +91,9 @@ public class XMTPModule: Module { } let preCreateIdentityCallback: PreEventCallback? = hasCreateIdentityCallback ?? false ? self.preCreateIdentityCallback : nil let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil - let encryptionKeyData = encryptionKey == nil ? nil : Data(encryptionKey!) + let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!) - let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData) + let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData, dbPath: dbPath) try await clientsManager.updateClient(key: address, client: await XMTP.Client.create(account: signer, options: options)) self.signer = nil sendEvent("authed") @@ -104,7 +104,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?, encryptionKey: [UInt8]?) -> String in + AsyncFunction("createRandom") { (environment: String, appVersion: String?, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?, dbPath: String?) -> String in try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment) let privateKey = try PrivateKey.generate() @@ -116,9 +116,9 @@ public class XMTPModule: Module { } let preCreateIdentityCallback: PreEventCallback? = hasCreateIdentityCallback ?? false ? self.preCreateIdentityCallback : nil let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil - let encryptionKeyData = encryptionKey == nil ? nil : Data(encryptionKey!) + let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!) - let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData) + let options = createClientConfig(env: environment, appVersion: appVersion, preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData, dbPath: dbPath) let client = try await Client.create(account: privateKey, options: options) await clientsManager.updateClient(key: client.address, client: client) @@ -126,7 +126,7 @@ public class XMTPModule: Module { } // Create a client using its serialized key bundle. - AsyncFunction("createFromKeyBundle") { (keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Bool?, encryptionKey: [UInt8]?) -> String in + AsyncFunction("createFromKeyBundle") { (keyBundle: String, environment: String, appVersion: String?, enableAlphaMls: Bool?, dbEncryptionKey: [UInt8]?, dbPath: String?) -> String in try requireNotProductionEnvForAlphaMLS(enableAlphaMls: enableAlphaMls, environment: environment) do { @@ -135,8 +135,8 @@ public class XMTPModule: Module { else { throw Error.invalidKeyBundle } - let encryptionKeyData = encryptionKey == nil ? nil : Data(encryptionKey!) - let options = createClientConfig(env: environment, appVersion: appVersion, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData) + let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!) + let options = createClientConfig(env: environment, appVersion: appVersion, mlsAlpha: enableAlphaMls == true, encryptionKey: encryptionKeyData, dbPath: dbPath) let client = try await Client.from(bundle: bundle, options: options) await clientsManager.updateClient(key: client.address, client: client) return client.address @@ -841,7 +841,7 @@ public class XMTPModule: Module { // Helpers // - func createClientConfig(env: String, appVersion: String?, preEnableIdentityCallback: PreEventCallback? = nil, preCreateIdentityCallback: PreEventCallback? = nil, mlsAlpha: Bool = false, encryptionKey: Data? = nil) -> XMTP.ClientOptions { + func createClientConfig(env: String, appVersion: String?, preEnableIdentityCallback: PreEventCallback? = nil, preCreateIdentityCallback: PreEventCallback? = nil, mlsAlpha: Bool = false, encryptionKey: Data? = nil, dbPath: String? = nil) -> XMTP.ClientOptions { // Ensure that all codecs have been registered. switch env { case "local": @@ -849,19 +849,19 @@ public class XMTPModule: Module { env: XMTP.XMTPEnvironment.local, isSecure: false, appVersion: appVersion - ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey) + ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey, dbPath: dbPath) 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) + ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: false, mlsEncryptionKey: encryptionKey, dbPath: dbPath) default: return XMTP.ClientOptions(api: XMTP.ClientOptions.Api( env: XMTP.XMTPEnvironment.dev, isSecure: true, appVersion: appVersion - ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey) + ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey, dbPath: dbPath) } } From 0bfd9d430186ae87c6b69494295dd1ec78e2ba08 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 21 Feb 2024 06:50:28 -0800 Subject: [PATCH 05/11] update the RN with the dbPath --- src/index.ts | 18 ++++++++++++------ src/lib/Client.ts | 22 ++++++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index cbbe351fc..8dae60e35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,7 +46,8 @@ export async function auth( hasCreateIdentityCallback?: boolean | undefined, hasEnableIdentityCallback?: boolean | undefined, enableAlphaMls?: boolean | undefined, - encryptionKey?: Uint8Array | undefined + dbEncryptionKey?: Uint8Array | undefined, + dbPath?: string | undefined ) { return await XMTPModule.auth( address, @@ -55,7 +56,8 @@ export async function auth( hasCreateIdentityCallback, hasEnableIdentityCallback, enableAlphaMls, - encryptionKey ? Array.from(encryptionKey) : undefined + dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined, + dbPath ) } @@ -69,7 +71,8 @@ export async function createRandom( hasCreateIdentityCallback?: boolean | undefined, hasEnableIdentityCallback?: boolean | undefined, enableAlphaMls?: boolean | undefined, - encryptionKey?: Uint8Array | undefined + dbEncryptionKey?: Uint8Array | undefined, + dbPath?: string | undefined ): Promise { return await XMTPModule.createRandom( environment, @@ -77,7 +80,8 @@ export async function createRandom( hasCreateIdentityCallback, hasEnableIdentityCallback, enableAlphaMls, - encryptionKey ? Array.from(encryptionKey) : undefined + dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined, + dbPath ) } @@ -86,14 +90,16 @@ export async function createFromKeyBundle( environment: 'local' | 'dev' | 'production', appVersion?: string | undefined, enableAlphaMls?: boolean | undefined, - encryptionKey?: Uint8Array | undefined + dbEncryptionKey?: Uint8Array | undefined, + dbPath?: string | undefined ): Promise { return await XMTPModule.createFromKeyBundle( keyBundle, environment, appVersion, enableAlphaMls, - encryptionKey ? Array.from(encryptionKey) : undefined + dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined, + dbPath ) } diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 72a0f1ac6..048a58fd2 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.encryptionKey + options.dbEncryptionKey, + options.dbPath ) })() }) @@ -146,7 +147,8 @@ export class Client< Boolean(createSubscription), Boolean(enableSubscription), Boolean(options.enableAlphaMls), - options.encryptionKey + options.dbEncryptionKey, + options.dbPath ) this.removeSubscription(enableSubscription) this.removeSubscription(createSubscription) @@ -176,7 +178,8 @@ export class Client< options.env, options.appVersion, Boolean(options.enableAlphaMls), - options.encryptionKey + options.dbEncryptionKey, + options.dbPath ) return new Client(address, opts?.codecs || []) } @@ -430,8 +433,14 @@ export type ClientOptions = { * Specify whether to enable Alpha version of MLS (Group Chat) */ enableAlphaMls?: boolean - - encryptionKey?: Uint8Array + /** + * OPTIONAL specify the encryption key for the database + */ + dbEncryptionKey?: Uint8Array + /** + * OPTIONAL specify the XMTP managed database path + */ + dbPath?: string } export type KeyType = { @@ -448,7 +457,8 @@ export function defaultOptions(opts?: Partial): ClientOptions { const _defaultOptions: ClientOptions = { env: 'dev', enableAlphaMls: false, - encryptionKey: undefined, + dbEncryptionKey: undefined, + dbPath: undefined, } return { ..._defaultOptions, ...opts } as ClientOptions From eec3f7350cf1c237e9249dfa59255b3adc66df32 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 21 Feb 2024 07:55:23 -0800 Subject: [PATCH 06/11] add tests for setting db path --- example/ios/Podfile.lock | 12 +++++++ example/package.json | 2 ++ example/src/tests/groupTests.ts | 55 +++++++++++++++++++++++++++++++++ example/yarn.lock | 17 ++++++++-- ios/XMTPModule.swift | 6 ++-- 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 867c88bcf..8057daad9 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -344,6 +344,8 @@ PODS: - RCTTypeSafety - React-Core - ReactCommon/turbomodule/core + - react-native-sqlite-storage (6.0.1): + - React-Core - React-perflogger (0.71.14) - React-RCTActionSheet (0.71.14): - React-Core/RCTActionSheetHeaders (= 0.71.14) @@ -430,6 +432,8 @@ PODS: - React-perflogger (= 0.71.14) - RNCAsyncStorage (1.21.0): - React-Core + - RNFS (2.20.0): + - React-Core - RNScreens (3.20.0): - React-Core - React-RCTImage @@ -502,6 +506,7 @@ DEPENDENCIES: - react-native-quick-crypto (from `../node_modules/react-native-quick-crypto`) - react-native-randombytes (from `../node_modules/react-native-randombytes`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) + - react-native-sqlite-storage (from `../node_modules/react-native-sqlite-storage`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) - React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`) - React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`) @@ -516,6 +521,7 @@ DEPENDENCIES: - React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`) - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) - "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)" + - RNFS (from `../node_modules/react-native-fs`) - RNScreens (from `../node_modules/react-native-screens`) - RNSVG (from `../node_modules/react-native-svg`) - XMTPReactNative (from `../../ios`) @@ -630,6 +636,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native-randombytes" react-native-safe-area-context: :path: "../node_modules/react-native-safe-area-context" + react-native-sqlite-storage: + :path: "../node_modules/react-native-sqlite-storage" React-perflogger: :path: "../node_modules/react-native/ReactCommon/reactperflogger" React-RCTActionSheet: @@ -658,6 +666,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon" RNCAsyncStorage: :path: "../node_modules/@react-native-async-storage/async-storage" + RNFS: + :path: "../node_modules/react-native-fs" RNScreens: :path: "../node_modules/react-native-screens" RNSVG: @@ -725,6 +735,7 @@ SPEC CHECKSUMS: react-native-quick-crypto: 455c1b411db006dba1026a30681ececb19180187 react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846 react-native-safe-area-context: 39c2d8be3328df5d437ac1700f4f3a4f75716acc + react-native-sqlite-storage: f6d515e1c446d1e6d026aa5352908a25d4de3261 React-perflogger: 4987ad83731c23d11813c84263963b0d3028c966 React-RCTActionSheet: 5ad952b2a9740d87a5bd77280c4bc23f6f89ea0c React-RCTAnimation: d2de22af3f536cc80bb5b3918e1a455114d1b985 @@ -739,6 +750,7 @@ SPEC CHECKSUMS: React-runtimeexecutor: ffe826b7b1cfbc32a35ed5b64d5886c0ff75f501 ReactCommon: 7f3dd5e98a9ec627c6b03d26c062bf37ea9fc888 RNCAsyncStorage: 618d03a5f52fbccb3d7010076bc54712844c18ef + RNFS: 4ac0f0ea233904cb798630b3c077808c06931688 RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f RNSVG: d00c8f91c3cbf6d476451313a18f04d220d4f396 secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 diff --git a/example/package.json b/example/package.json index f2c12fab1..43266045a 100644 --- a/example/package.json +++ b/example/package.json @@ -30,6 +30,7 @@ "react-native-config": "^1.5.1", "react-native-crypto": "^2.2.0", "react-native-encrypted-storage": "^4.0.3", + "react-native-fs": "^2.20.0", "react-native-get-random-values": "^1.10.0", "react-native-mmkv": "^2.8.0", "react-native-modal-selector": "^2.1.2", @@ -38,6 +39,7 @@ "react-native-randombytes": "^3.6.1", "react-native-safe-area-context": "4.5.0", "react-native-screens": "~3.20.0", + "react-native-sqlite-storage": "^6.0.1", "react-native-svg": "^13.9.0", "react-native-url-polyfill": "^2.0.0", "react-query": "^3.39.3", diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index ffc059535..3a271b8a8 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -1,4 +1,5 @@ import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage' +import RNFS from 'react-native-fs' import { Test, assert, delayToPropogate, isIos } from './tests' import { @@ -26,6 +27,60 @@ test('can make a MLS V3 client', 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 dbPath = `${dbDirPath}/myCoolApp.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, + }) + + 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 client = await Client.createRandom({ env: 'local', diff --git a/example/yarn.lock b/example/yarn.lock index 94a1c57ee..e2a9579bf 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -7325,7 +7325,7 @@ balanced-match@^1.0.0: resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== -base-64@0.1.0: +base-64@0.1.0, base-64@^0.1.0: version "0.1.0" resolved "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz" integrity sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA== @@ -13432,6 +13432,14 @@ react-native-encrypted-storage@^4.0.3: resolved "https://registry.npmjs.org/react-native-encrypted-storage/-/react-native-encrypted-storage-4.0.3.tgz" integrity sha512-0pJA4Aj2S1PIJEbU7pN/Qvf7JIJx3hFywx+i+bLHtgK0/6Zryf1V2xVsWcrD50dfiu3jY1eN2gesQ5osGxE7jA== +react-native-fs@^2.20.0: + version "2.20.0" + resolved "https://registry.yarnpkg.com/react-native-fs/-/react-native-fs-2.20.0.tgz#05a9362b473bfc0910772c0acbb73a78dbc810f6" + integrity sha512-VkTBzs7fIDUiy/XajOSNk0XazFE9l+QlMAce7lGuebZcag5CnjszB+u4BdqzwaQOdcYb5wsJIsqq4kxInIRpJQ== + dependencies: + base-64 "^0.1.0" + utf8 "^3.0.0" + react-native-get-random-values@^1.10.0, react-native-get-random-values@^1.4.0: version "1.10.0" resolved "https://registry.npmjs.org/react-native-get-random-values/-/react-native-get-random-values-1.10.0.tgz" @@ -13531,6 +13539,11 @@ react-native-screens@~3.20.0: react-freeze "^1.0.0" warn-once "^0.1.0" +react-native-sqlite-storage@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/react-native-sqlite-storage/-/react-native-sqlite-storage-6.0.1.tgz#ce6a6b852f07abbea68658d5363818c8bef45dfb" + integrity sha512-1tDFjrint6X6qSYKf3gDyz+XB+X79jfiL6xTugKHPRtF0WvqMtVgdLuNqZunIXjNEvNtNVEbXaeZ6MsguFu00A== + react-native-svg@^13.9.0: version "13.14.0" resolved "https://registry.npmjs.org/react-native-svg/-/react-native-svg-13.14.0.tgz" @@ -15273,7 +15286,7 @@ utf-8-validate@^5.0.2: dependencies: node-gyp-build "^4.3.0" -utf8@3.0.0: +utf8@3.0.0, utf8@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz" integrity sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ== diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index a534e4992..0e9c845da 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -849,19 +849,19 @@ public class XMTPModule: Module { env: XMTP.XMTPEnvironment.local, isSecure: false, appVersion: appVersion - ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey, dbPath: dbPath) + ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey, mlsDbPath: dbPath) 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, dbPath: dbPath) + ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: false, mlsEncryptionKey: encryptionKey, mlsDbPath: dbPath) default: return XMTP.ClientOptions(api: XMTP.ClientOptions.Api( env: XMTP.XMTPEnvironment.dev, isSecure: true, appVersion: appVersion - ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey, dbPath: dbPath) + ), preEnableIdentityCallback: preEnableIdentityCallback, preCreateIdentityCallback: preCreateIdentityCallback, mlsAlpha: mlsAlpha, mlsEncryptionKey: encryptionKey, mlsDbPath: dbPath) } } From 8396d96ddb2fe9af7c1c7315f8a9dd7c3c33ada8 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 21 Feb 2024 11:51:40 -0800 Subject: [PATCH 07/11] bump pod --- example/ios/Podfile.lock | 8 ++++---- ios/XMTPReactNative.podspec | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 8057daad9..00cc4ee30 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -446,7 +446,7 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.8.9): + - XMTP (0.8.11): - Connect-Swift (= 0.3.0) - GzipSwift - LibXMTP (= 0.4.2-beta3) @@ -455,7 +455,7 @@ PODS: - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.8.9) + - XMTP (= 0.8.11) - Yoga (1.14.0) DEPENDENCIES: @@ -756,8 +756,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 4bc651602abefdb119a7ac2e8a12e9bf67aa3447 - XMTPReactNative: 4c0ae41719aa36ca90c3f65ff998977c3011bca8 + XMTP: 8a2dd650bffa972ad1429fc194e405c9fa3a768b + XMTPReactNative: 744edc40cb1f7728a338d130e906fcb6827458b2 Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index bcd8f30d1..76fbe615d 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,5 +26,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency 'secp256k1.swift' s.dependency "MessagePacker" - s.dependency "XMTP", "= 0.8.9" + s.dependency "XMTP", "= 0.8.11" end From c6298f4ca9ee713368f4319d576edafb31431610 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 22 Feb 2024 07:26:31 -0800 Subject: [PATCH 08/11] bump to get pagination fixes --- ios/XMTPReactNative.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index 76fbe615d..ebf48b9bb 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,5 +26,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency 'secp256k1.swift' s.dependency "MessagePacker" - s.dependency "XMTP", "= 0.8.11" + s.dependency "XMTP", "= 0.8.12" end From 386ae096641b995931ceed6ba3717927faa7d0b8 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 22 Feb 2024 07:41:59 -0800 Subject: [PATCH 09/11] update the pod file --- example/ios/Podfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 00cc4ee30..61a5309f8 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -446,7 +446,7 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.8.11): + - XMTP (0.8.12): - Connect-Swift (= 0.3.0) - GzipSwift - LibXMTP (= 0.4.2-beta3) @@ -455,7 +455,7 @@ PODS: - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.8.11) + - XMTP (= 0.8.12) - Yoga (1.14.0) DEPENDENCIES: @@ -756,8 +756,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 8a2dd650bffa972ad1429fc194e405c9fa3a768b - XMTPReactNative: 744edc40cb1f7728a338d130e906fcb6827458b2 + XMTP: 44904e5214d3cf9b31883ed95e74acc4b620a943 + XMTPReactNative: bf207f0b9f34db0735dd78b0b5ddc49269e4dc2e Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 From 185e1f26c5236ca9670a1a19c39fbe89a78c41c3 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 22 Feb 2024 08:59:26 -0800 Subject: [PATCH 10/11] delete the database --- example/src/tests/groupTests.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 22bf44465..3abdadf27 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -1,5 +1,5 @@ -import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage' import RNFS from 'react-native-fs' +import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage' import { Test, assert, delayToPropogate, isIos } from './tests' import { @@ -78,6 +78,7 @@ test('can make a MLS V3 client with encryption key and database path', async () (await clientFromBundle.conversations.listGroups()).length === 1, `should have a group size of 1 but was ${(await clientFromBundle.conversations.listGroups()).length}` ) + RNFS.unlink(dbDirPath) return true }) From 8afe5e81372b3a031e09250796e9edde6c65de2e Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Thu, 22 Feb 2024 09:59:03 -0800 Subject: [PATCH 11/11] Add timestamp to db filename to avoid collisions --- example/src/tests/groupTests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 3abdadf27..7a3b0b58a 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -34,7 +34,8 @@ test('can make a MLS V3 client with encryption key and database path', async () if (!directoryExists) { await RNFS.mkdir(dbDirPath) } - const dbPath = `${dbDirPath}/myCoolApp.db3` + 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, @@ -78,7 +79,6 @@ test('can make a MLS V3 client with encryption key and database path', async () (await clientFromBundle.conversations.listGroups()).length === 1, `should have a group size of 1 but was ${(await clientFromBundle.conversations.listGroups()).length}` ) - RNFS.unlink(dbDirPath) return true })