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

Fix: Create from key bundle #247

Merged
merged 3 commits into from
Feb 9, 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
53 changes: 52 additions & 1 deletion example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,51 +99,102 @@
})

test('can make a MLS V3 client', async () => {
const client = await Client.createRandom({

Check warning on line 102 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'client' is assigned a value but never used
env: 'local',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true
enableAlphaMls: true,
})

return true
})

test('can make a MLS V3 client from bundle', async () => {
const client = await Client.createRandom({
env: 'local',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true,
})

const anotherClient = await Client.createRandom({
env: 'local',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true,
})

const group1 = await client.conversations.newGroup([anotherClient.address])

if (group1.clientAddress !== client.address) {
throw new Error(
`clients dont match ${client.address} and ${group1.clientAddress}`
)
}
const bundle = await client.exportKeyBundle()

const client2 = await Client.createFromKeyBundle(bundle, {
env: 'local',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true,
})

if (client.address !== client2.address) {
throw new Error(
`clients dont match ${client2.address} and ${client.address}`
)
}

const randomClient = await Client.createRandom({
env: 'local',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true,
})

const group = await client2.conversations.newGroup([randomClient.address])

if (group.clientAddress !== client2.address) {
throw new Error(
`clients dont match ${client2.address} and ${group.clientAddress}`
)
}

return true
})

test('production MLS V3 client creation throws error', async () => {
try {
const client = await Client.createRandom({

Check warning on line 164 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'client' is assigned a value but never used
env: 'production',
appVersion: 'Testing/0.0.0',
enableAlphaMls: true

Check warning on line 167 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
})
} catch (error: any) {
return error.message.endsWith("Environment must be \"local\" or \"dev\" to enable alpha MLS")

Check warning on line 170 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"Environment·must·be·\"local\"·or·\"dev\"·to·enable·alpha·MLS"` with `⏎······'Environment·must·be·"local"·or·"dev"·to·enable·alpha·MLS'⏎····`
}
throw new Error('should throw error on MLS V3 client create when environment is not local')

Check warning on line 172 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'should·throw·error·on·MLS·V3·client·create·when·environment·is·not·local'` with `⏎····'should·throw·error·on·MLS·V3·client·create·when·environment·is·not·local'⏎··`
})

test('can message in a group', async () => {
// Create three MLS enabled Clients
const aliceClient = await Client.createRandom({
env: 'local',
enableAlphaMls: true

Check warning on line 179 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
})
const bobClient = await Client.createRandom({
env: 'local',
enableAlphaMls: true

Check warning on line 183 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
})
const camClient = await Client.createRandom({
env: 'local',
enableAlphaMls: true

Check warning on line 187 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
})

// Alice's num groups start at 0
let aliceGroups = await aliceClient.conversations.listGroups()
if (aliceGroups.length != 0) {

Check warning on line 192 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Expected '!==' and instead saw '!='
throw new Error('num groups should be 0')
}

// Alice creates a group
const aliceGroup = await aliceClient.conversations.newGroup(

Check warning on line 197 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `[`
[bobClient.address, camClient.address]
)

Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ export async function createRandom(
export async function createFromKeyBundle(
keyBundle: string,
environment: 'local' | 'dev' | 'production',
appVersion?: string | undefined
appVersion?: string | undefined,
enableAlphaMls?: boolean | undefined
): Promise<string> {
return await XMTPModule.createFromKeyBundle(
keyBundle,
environment,
appVersion
appVersion,
enableAlphaMls
)
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export class Client<ContentTypes> {
const address = await XMTPModule.createFromKeyBundle(
keyBundle,
options.env,
options.appVersion
options.appVersion,
Boolean(options.enableAlphaMls)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also needed for client.create :)

)
return new Client(address, opts?.codecs || [])
}
Expand Down
Loading