From c6ea497584c08dc3027fdbd5f1ba48199e4fd418 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 15 May 2024 15:00:29 -0700 Subject: [PATCH 1/3] undo all the hard requirements on encryption key --- src/hooks/useClient.ts | 2 +- src/lib/Client.ts | 51 +++++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/hooks/useClient.ts b/src/hooks/useClient.ts index 26c0495a4..df6390773 100644 --- a/src/hooks/useClient.ts +++ b/src/hooks/useClient.ts @@ -7,7 +7,7 @@ import { DefaultContentTypes } from '../lib/types/DefaultContentType' interface InitializeClientOptions { signer: Signer | null - options: ClientOptions + options?: ClientOptions } export const useClient = < diff --git a/src/lib/Client.ts b/src/lib/Client.ts index badbe2f06..21a2052fe 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -50,11 +50,10 @@ export class Client< ContentCodecs extends DefaultContentTypes = DefaultContentTypes, >( wallet: Signer | WalletClient | null, - options: ClientOptions & { codecs?: ContentCodecs } + opts?: Partial & { codecs?: ContentCodecs } ): Promise> { - if (options.dbEncryptionKey.length !== 32) { - throw new Error('The encryption key must be exactly 32 bytes.') - } + const options = defaultOptions(opts) + const { enableSubscription, createSubscription } = this.setupSubscriptions(options) const signer = getSigner(wallet) @@ -100,7 +99,7 @@ export class Client< this.removeSignSubscription() this.removeAuthSubscription() const address = await signer.getAddress() - resolve(new Client(address, options?.codecs || [])) + resolve(new Client(address, opts?.codecs || [])) } ) await XMTPModule.auth( @@ -140,11 +139,9 @@ export class Client< * @returns {Promise} A Promise that resolves to a new Client instance with a random address. */ static async createRandom( - options: ClientOptions & { codecs?: ContentTypes } + opts?: Partial & { codecs?: ContentTypes } ): Promise> { - if (options.dbEncryptionKey.length !== 32) { - throw new Error('The encryption key must be exactly 32 bytes.') - } + const options = defaultOptions(opts) const { enableSubscription, createSubscription } = this.setupSubscriptions(options) const address = await XMTPModule.createRandom( @@ -159,7 +156,7 @@ export class Client< this.removeSubscription(enableSubscription) this.removeSubscription(createSubscription) - return new Client(address, options?.codecs || []) + return new Client(address, opts?.codecs || []) } /** @@ -176,11 +173,9 @@ export class Client< ContentCodecs extends DefaultContentTypes = [], >( keyBundle: string, - options: ClientOptions & { codecs?: ContentCodecs } + opts?: Partial & { codecs?: ContentCodecs } ): Promise> { - if (options.dbEncryptionKey.length !== 32) { - throw new Error('The encryption key must be exactly 32 bytes.') - } + const options = defaultOptions(opts) const address = await XMTPModule.createFromKeyBundle( keyBundle, options.env, @@ -189,7 +184,7 @@ export class Client< options.dbEncryptionKey, options.dbPath ) - return new Client(address, options?.codecs || []) + return new Client(address, opts?.codecs || []) } /** @@ -237,11 +232,9 @@ export class Client< */ static async canMessage( peerAddress: string, - options: ClientOptions + opts?: Partial ): Promise { - if (options.dbEncryptionKey.length !== 32) { - throw new Error('The encryption key must be exactly 32 bytes.') - } + const options = defaultOptions(opts) return await XMTPModule.staticCanMessage( peerAddress, options.env, @@ -451,9 +444,9 @@ export type ClientOptions = { */ enableAlphaMls?: boolean /** - * REQUIRED specify the encryption key for the database. The encryption key must be exactly 32 bytes. + * OPTIONAL specify the encryption key for the database. The encryption key must be exactly 32 bytes. */ - dbEncryptionKey: Uint8Array + dbEncryptionKey?: Uint8Array /** * OPTIONAL specify the XMTP managed database path */ @@ -464,3 +457,19 @@ export type KeyType = { kind: 'identity' | 'prekey' prekeyIndex?: number } + +/** + * Provide a default client configuration. These settings can be used on their own, or as a starting point for custom configurations + * + * @param opts additional options to override the default settings + */ +export function defaultOptions(opts?: Partial): ClientOptions { + const _defaultOptions: ClientOptions = { + env: 'dev', + enableAlphaMls: false, + dbEncryptionKey: undefined, + dbPath: undefined, + } + + return { ..._defaultOptions, ...opts } as ClientOptions +} From 7e5c35829fcd145ad0f6ec9e83464bae936dc703 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 15 May 2024 15:08:04 -0700 Subject: [PATCH 2/3] fix: bump the pod --- ios/XMTPReactNative.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index 44e71141d..9f1df1ff9 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.10.10" + s.dependency "XMTP", "= 0.10.11" end From 6c5ba4f6735cce27aa414cf80a0e43a4929c8a2e Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 15 May 2024 15:30:04 -0700 Subject: [PATCH 3/3] update a test to see if it can be created without a key --- example/ios/Podfile.lock | 8 ++++---- example/src/tests/groupTests.ts | 5 ----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 7d391a235..c5244f04d 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -449,7 +449,7 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.10.10): + - XMTP (0.10.11): - Connect-Swift (= 0.12.0) - GzipSwift - LibXMTP (= 0.4.4-beta5) @@ -458,7 +458,7 @@ PODS: - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.10.10) + - XMTP (= 0.10.11) - Yoga (1.14.0) DEPENDENCIES: @@ -763,8 +763,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 13907da1638c2b1a23f38ef246091c7a88c33108 - XMTPReactNative: 9ae92e4df220d4043a6583a6c05673a698390ee8 + XMTP: 1deb40ac712ba315dcfdecd590a9b924d8c2241a + XMTPReactNative: a7d7c609861e0b31ca7f624f58969dcb92c19990 Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index bf5fa7c7f..2b6b3532e 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -26,15 +26,10 @@ function test(name: string, perform: () => Promise) { test('can make a MLS V3 client', async () => { // eslint-disable-next-line @typescript-eslint/no-unused-vars - const keyBytes = 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: keyBytes, }) return true