Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hard requirement on encryption key #384

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -14,7 +14,7 @@
Group,
ConversationContainer,
ConversationVersion,
syncGroup,

Check warning on line 17 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

'syncGroup' is defined but never used
MessageDeliveryStatus,
} from '../../../src/index'

Expand All @@ -26,15 +26,10 @@

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 Expand Up @@ -268,7 +263,7 @@

test('who added me to a group', async () => {
const [alixClient, boClient] = await createClients(2)
const alixGroup = await alixClient.conversations.newGroup([boClient.address])

Check warning on line 266 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

'alixGroup' is assigned a value but never used

const boGroup = (await boClient.conversations.listGroups())[0]
const addedByAddress = await boGroup.addedByAddress()
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 @@ -19,11 +19,11 @@

declare const Buffer

export type GetMessageContentTypeFromClient<C> = C extends Client<infer T>

Check warning on line 22 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `·C·extends·Client<infer·T>⏎··?·T⏎·` with `⏎··C·extends·Client<infer·T>·?·T`
? T
: never

export type ExtractDecodedType<C> = C extends XMTPModule.ContentCodec<infer T>

Check warning on line 26 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `·C·extends·XMTPModule.ContentCodec<infer·T>⏎··?·T⏎·` with `⏎··C·extends·XMTPModule.ContentCodec<infer·T>·?·T`
? T
: never

Expand All @@ -50,11 +50,10 @@
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 @@
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 @@
* @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 @@
this.removeSubscription(enableSubscription)
this.removeSubscription(createSubscription)

return new Client(address, options?.codecs || [])
return new Client(address, opts?.codecs || [])
}

/**
Expand All @@ -176,11 +173,9 @@
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 @@
options.dbEncryptionKey,
options.dbPath
)
return new Client(address, options?.codecs || [])
return new Client(address, opts?.codecs || [])
}

/**
Expand Down Expand Up @@ -237,11 +232,9 @@
*/
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 @@
*/
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 @@
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
}
Loading