Skip to content

Commit

Permalink
fix: adding back the encryption key requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jul 10, 2024
1 parent 4d872aa commit 8fca333
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.14.6"
implementation "org.xmtp:android:0.14.7"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
36 changes: 25 additions & 11 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ export class Client<
ContentCodecs extends DefaultContentTypes = DefaultContentTypes,
>(
wallet: Signer | WalletClient | null,
opts?: Partial<ClientOptions> & { codecs?: ContentCodecs }
options: ClientOptions & { codecs?: ContentCodecs }
): Promise<Client<ContentCodecs>> {
const options = defaultOptions(opts)

if (
options.dbEncryptionKey === undefined ||
options.dbEncryptionKey.length !== 32
) {
throw new Error('Must pass an encryption key that is exactly 32 bytes.')
}
const { enableSubscription, createSubscription } =
this.setupSubscriptions(options)
const signer = getSigner(wallet)
Expand Down Expand Up @@ -109,7 +113,7 @@ export class Client<
message.address,
message.inboxId as InboxId,
message.installationId,
opts?.codecs || []
options.codecs || []
)
)
}
Expand Down Expand Up @@ -152,9 +156,14 @@ export class Client<
* @returns {Promise<Client>} A Promise that resolves to a new Client instance with a random address.
*/
static async createRandom<ContentTypes extends DefaultContentTypes>(
opts?: Partial<ClientOptions> & { codecs?: ContentTypes }
options: ClientOptions & { codecs?: ContentTypes }
): Promise<Client<ContentTypes>> {
const options = defaultOptions(opts)
if (
options.dbEncryptionKey === undefined ||
options.dbEncryptionKey.length !== 32
) {
throw new Error('Must pass an encryption key that is exactly 32 bytes.')
}
const { enableSubscription, createSubscription } =
this.setupSubscriptions(options)
const client = await XMTPModule.createRandom(
Expand All @@ -174,7 +183,7 @@ export class Client<
client['address'],
client['inboxId'],
client['installationId'],
opts?.codecs || []
options?.codecs || []
)
}

Expand All @@ -192,9 +201,14 @@ export class Client<
ContentCodecs extends DefaultContentTypes = [],
>(
keyBundle: string,
opts?: Partial<ClientOptions> & { codecs?: ContentCodecs }
options: ClientOptions & { codecs?: ContentCodecs }
): Promise<Client<ContentCodecs>> {
const options = defaultOptions(opts)
if (
options.dbEncryptionKey === undefined ||
options.dbEncryptionKey.length !== 32
) {
throw new Error('Must pass an encryption key that is exactly 32 bytes.')
}
const client = await XMTPModule.createFromKeyBundle(
keyBundle,
options.env,
Expand All @@ -209,7 +223,7 @@ export class Client<
client['address'],
client['inboxId'],
client['installationId'],
opts?.codecs || []
options.codecs || []
)
}

Expand Down Expand Up @@ -507,7 +521,7 @@ export type ClientOptions = {
*/
enableV3?: boolean
/**
* OPTIONAL specify the encryption key for the database. The encryption key must be exactly 32 bytes.
* REQUIRED specify the encryption key for the database. The encryption key must be exactly 32 bytes.
*/
dbEncryptionKey?: Uint8Array
/**
Expand Down

0 comments on commit 8fca333

Please sign in to comment.