Skip to content

Commit

Permalink
Merge pull request #439 from xmtp/np/add-back-encryption-key
Browse files Browse the repository at this point in the history
Add back encryption key requirement
  • Loading branch information
nplasterer authored Jul 10, 2024
2 parents 90828ef + eaea00e commit 691a70c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 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
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.13.5):
- XMTP (0.13.6):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.5.4-beta4)
Expand All @@ -458,7 +458,7 @@ PODS:
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.13.5)
- XMTP (= 0.13.6)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 476b406c10c2c19183794b670790912545cc7699
XMTPReactNative: d172e052907d373f40348ed091cdbf7c6da4a331
XMTP: aeeff5ecac80f7ec9a2ba4f732d439ab600545ed
XMTPReactNative: 7a5fb82f5e8392ea53b5231edceb87ed07761e0b
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2
Expand Down
7 changes: 7 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ function test(name: string, perform: () => Promise<boolean>) {

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',
enableV3: true,
dbEncryptionKey: keyBytes,
})

return true
Expand Down Expand Up @@ -591,6 +596,8 @@ test('unpublished messages handling', async () => {
if (preparedMessageId !== messages[0].id) {
throw new Error(`Message ID should match the prepared message ID`)
}

return true
})

test('can add members to a group', async () => {
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.13.5"
s.dependency "XMTP", "= 0.13.6"
end
2 changes: 1 addition & 1 deletion src/hooks/useClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DefaultContentTypes } from '../lib/types/DefaultContentType'

interface InitializeClientOptions {
signer: Signer | null
options?: ClientOptions
options: ClientOptions
}

export const useClient = <
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 691a70c

Please sign in to comment.