Skip to content

Commit

Permalink
Merge pull request #384 from xmtp/np/remove-require-encryption-key
Browse files Browse the repository at this point in the history
Remove hard requirement on encryption key
  • Loading branch information
nplasterer authored May 15, 2024
2 parents 10c1c00 + 6c5ba4f commit d36fc8c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
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.10.10):
- XMTP (0.10.11):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.4.4-beta5)
Expand All @@ -458,7 +458,7 @@ PODS:
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.10.10)
- XMTP (= 0.10.11)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ 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',
enableAlphaMls: true,
dbEncryptionKey: keyBytes,
})

return true
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.10.10"
s.dependency "XMTP", "= 0.10.11"
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
51 changes: 30 additions & 21 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ export class Client<
ContentCodecs extends DefaultContentTypes = DefaultContentTypes,
>(
wallet: Signer | WalletClient | null,
options: ClientOptions & { codecs?: ContentCodecs }
opts?: Partial<ClientOptions> & { codecs?: ContentCodecs }
): Promise<Client<ContentCodecs>> {
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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -140,11 +139,9 @@ 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>(
options: ClientOptions & { codecs?: ContentTypes }
opts?: Partial<ClientOptions> & { codecs?: ContentTypes }
): Promise<Client<ContentTypes>> {
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(
Expand All @@ -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 || [])
}

/**
Expand All @@ -176,11 +173,9 @@ export class Client<
ContentCodecs extends DefaultContentTypes = [],
>(
keyBundle: string,
options: ClientOptions & { codecs?: ContentCodecs }
opts?: Partial<ClientOptions> & { codecs?: ContentCodecs }
): Promise<Client<DefaultContentTypes>> {
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,
Expand All @@ -189,7 +184,7 @@ export class Client<
options.dbEncryptionKey,
options.dbPath
)
return new Client(address, options?.codecs || [])
return new Client(address, opts?.codecs || [])
}

/**
Expand Down Expand Up @@ -237,11 +232,9 @@ export class Client<
*/
static async canMessage(
peerAddress: string,
options: ClientOptions
opts?: Partial<ClientOptions>
): Promise<boolean> {
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,
Expand Down Expand Up @@ -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
*/
Expand All @@ -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>): ClientOptions {
const _defaultOptions: ClientOptions = {
env: 'dev',
enableAlphaMls: false,
dbEncryptionKey: undefined,
dbPath: undefined,
}

return { ..._defaultOptions, ...opts } as ClientOptions
}

0 comments on commit d36fc8c

Please sign in to comment.