Skip to content

Commit

Permalink
fix: topic non-determinism
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas committed Aug 31, 2023
1 parent 0bcb160 commit 9fbb995
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/keystore/InMemoryKeystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,16 @@ export default class InMemoryKeystore implements Keystore {
}
const created = nsToDate(req.createdNs)
const recipient = toSignedPublicKeyBundle(req.recipient)
const myAddress = await this.getAccountAddress()
const theirAddress = await recipient.walletSignatureAddress()

const secret = await this.v2Keys.sharedSecret(
recipient,
this.v2Keys.getCurrentPreKey().publicKey,
false
myAddress > theirAddress
)

const sortedAddresses = [
this.accountAddress,
await recipient.walletSignatureAddress(),
].sort()
const sortedAddresses = [myAddress, theirAddress].sort()

const msgString =
(req.context?.conversationId || '') + sortedAddresses.join()
Expand Down
34 changes: 33 additions & 1 deletion test/keystore/InMemoryKeystore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,39 @@ describe('InMemoryKeystore', () => {
).toHaveLength(25)
})

it('works with persistence', async () => {})
it('creates deterministic topics bidirectionally', async () => {
const aliceInvite = await aliceKeystore.createInvite({
recipient: SignedPublicKeyBundle.fromLegacyBundle(
bobKeys.getPublicKeyBundle()
),
createdNs: dateToNs(new Date()),
context: undefined,
})
const bobInvite = await bobKeystore.createInvite({
recipient: SignedPublicKeyBundle.fromLegacyBundle(
aliceKeys.getPublicKeyBundle()
),
createdNs: dateToNs(new Date()),
context: undefined,
})
expect(
await aliceKeys.sharedSecret(
bobKeys.getPublicKeyBundle(),
aliceKeys.getCurrentPreKey().publicKey,
false
)
).toEqual(
await bobKeys.sharedSecret(
aliceKeys.getPublicKeyBundle(),
bobKeys.getCurrentPreKey().publicKey,
true
)
)

expect(aliceInvite.conversation!.topic).toEqual(
bobInvite.conversation!.topic
)
})
})

describe('createAuthToken', () => {
Expand Down

0 comments on commit 9fbb995

Please sign in to comment.