diff --git a/.changeset/breezy-glasses-grow.md b/.changeset/breezy-glasses-grow.md new file mode 100644 index 0000000000..a74c75b156 --- /dev/null +++ b/.changeset/breezy-glasses-grow.md @@ -0,0 +1,5 @@ +--- +'livekit-client': patch +--- + +Actually allow E2EE keyring size of 256 diff --git a/src/e2ee/worker/ParticipantKeyHandler.test.ts b/src/e2ee/worker/ParticipantKeyHandler.test.ts new file mode 100644 index 0000000000..85a35e0388 --- /dev/null +++ b/src/e2ee/worker/ParticipantKeyHandler.test.ts @@ -0,0 +1,37 @@ +import { describe, expect, it } from 'vitest'; +import { KEY_PROVIDER_DEFAULTS } from '../constants'; +import { createKeyMaterialFromString } from '../utils'; +import { ParticipantKeyHandler } from './ParticipantKeyHandler'; + +describe('ParticipantKeyHandler', () => { + const participantIdentity = 'testParticipant'; + + it('keyringSize must be greater than 0', () => { + expect(() => { + new ParticipantKeyHandler(participantIdentity, { ...KEY_PROVIDER_DEFAULTS, keyringSize: 0 }); + }).toThrowError(TypeError); + }); + + it('keyringSize must be max 256', () => { + expect(() => { + new ParticipantKeyHandler(participantIdentity, { + ...KEY_PROVIDER_DEFAULTS, + keyringSize: 257, + }); + }).toThrowError(TypeError); + }); + + it('get and sets keys at an index', async () => { + const keyHandler = new ParticipantKeyHandler(participantIdentity, { + ...KEY_PROVIDER_DEFAULTS, + keyringSize: 128, + }); + const materialA = await createKeyMaterialFromString('passwordA'); + const materialB = await createKeyMaterialFromString('passwordB'); + await keyHandler.setKey(materialA, 0); + expect(keyHandler.getKeySet(0)).toBeDefined(); + expect(keyHandler.getKeySet(0)?.material).toEqual(materialA); + await keyHandler.setKey(materialB, 0); + expect(keyHandler.getKeySet(0)?.material).toEqual(materialB); + }); +}); diff --git a/src/e2ee/worker/ParticipantKeyHandler.ts b/src/e2ee/worker/ParticipantKeyHandler.ts index 4b715ec7dd..6f24b4b558 100644 --- a/src/e2ee/worker/ParticipantKeyHandler.ts +++ b/src/e2ee/worker/ParticipantKeyHandler.ts @@ -38,7 +38,7 @@ export class ParticipantKeyHandler extends (EventEmitter as new () => TypedEvent constructor(participantIdentity: string, keyProviderOptions: KeyProviderOptions) { super(); this.currentKeyIndex = 0; - if (keyProviderOptions.keyringSize < 1 || keyProviderOptions.keyringSize > 255) { + if (keyProviderOptions.keyringSize < 1 || keyProviderOptions.keyringSize > 256) { throw new TypeError('Keyring size needs to be between 1 and 256'); } this.cryptoKeyRing = new Array(keyProviderOptions.keyringSize).fill(undefined);