Skip to content

Commit

Permalink
Merge pull request #247 from xmtp/np/fix-from-bundle
Browse files Browse the repository at this point in the history
Fix: Create from key bundle
  • Loading branch information
nplasterer authored Feb 9, 2024
2 parents 2e532b4 + f5bf1db commit bdd1ffe
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
53 changes: 52 additions & 1 deletion example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,60 @@ test('can make a MLS V3 client', async () => {
const client = await Client.createRandom({
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
})

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)
)
return new Client(address, opts?.codecs || [])
}
Expand Down

0 comments on commit bdd1ffe

Please sign in to comment.