ts-mls
Version:
[](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [](https://badge.fury.io/js/ts-mls) [) {
test(`Reject incoming message ${cs}`, async () => {
await rejectIncomingMessagesTest(cs, true);
await rejectIncomingMessagesTest(cs, false);
});
}
async function rejectIncomingMessagesTest(cipherSuite, publicMessage) {
const impl = await getCiphersuiteImpl(getCiphersuiteFromName(cipherSuite));
const aliceCredential = { credentialType: "basic", identity: new TextEncoder().encode("alice") };
const alice = await generateKeyPackage(aliceCredential, defaultCapabilities(), defaultLifetime, [], impl);
const groupId = new TextEncoder().encode("group1");
const preferredWireformat = publicMessage ? "mls_public_message" : "mls_private_message";
let aliceGroup = await createGroup(groupId, alice.publicPackage, alice.privatePackage, [], impl);
const bobCredential = { credentialType: "basic", identity: new TextEncoder().encode("bob") };
const bob = await generateKeyPackage(bobCredential, defaultCapabilities(), defaultLifetime, [], impl);
const addBobProposal = {
proposalType: "add",
add: {
keyPackage: bob.publicPackage,
},
};
const addBobCommitResult = await createCommit(aliceGroup, emptyPskIndex, publicMessage, [addBobProposal], impl);
aliceGroup = addBobCommitResult.newState;
let bobGroup = await joinGroup(addBobCommitResult.welcome, bob.publicPackage, bob.privatePackage, emptyPskIndex, impl, aliceGroup.ratchetTree);
const bobProposeExtensions = {
proposalType: "group_context_extensions",
groupContextExtensions: {
extensions: [
{
extensionType: "external_senders",
extensionData: encodeExternalSender({
credential: { credentialType: "basic", identity: new Uint8Array() },
signaturePublicKey: new Uint8Array(),
}),
},
],
},
};
const createExtensionsProposalResults = await createProposal(bobGroup, publicMessage, bobProposeExtensions, impl);
bobGroup = createExtensionsProposalResults.newState;
if (createExtensionsProposalResults.message.wireformat !== preferredWireformat)
throw new Error(`Expected ${preferredWireformat} message`);
//alice rejects the proposal
const aliceRejectsProposalResult = await processMessage(createExtensionsProposalResults.message, aliceGroup, emptyPskIndex, () => "reject", impl);
aliceGroup = aliceRejectsProposalResult.newState;
expect(aliceGroup.unappliedProposals).toStrictEqual({});
// alice commits without the proposal
const aliceCommitResult = await createCommit(aliceGroup, emptyPskIndex, publicMessage, [], impl);
aliceGroup = aliceCommitResult.newState;
if (aliceCommitResult.commit.wireformat !== preferredWireformat)
throw new Error(`Expected ${preferredWireformat} message`);
const bobRejectsAliceCommitResult = await processMessage(aliceCommitResult.commit, bobGroup, emptyPskIndex, () => "reject", impl);
// group context and keySchedule haven't changed since bob rejected the commit
expect(bobRejectsAliceCommitResult.newState.groupContext).toStrictEqual(bobGroup.groupContext);
expect(bobRejectsAliceCommitResult.newState.keySchedule).toStrictEqual(bobGroup.keySchedule);
}
//# sourceMappingURL=rejectIncomingMessage.test.js.map