ts-mls
Version:
[](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [](https://badge.fury.io/js/ts-mls) [) {
test(`Reinit ${cs}`, async () => {
await reinit(cs);
});
}
async function reinit(cipherSuite) {
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");
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 commitResult = await createCommit(aliceGroup, emptyPskIndex, false, [addBobProposal], impl);
aliceGroup = commitResult.newState;
let bobGroup = await joinGroup(commitResult.welcome, bob.publicPackage, bob.privatePackage, emptyPskIndex, impl, aliceGroup.ratchetTree);
const newCiphersuite = getRandomElement(Object.keys(ciphersuites));
const newGroupId = new TextEncoder().encode("new-group1");
const reinitCommitResult = await reinitGroup(aliceGroup, newGroupId, "mls10", newCiphersuite, [], impl);
aliceGroup = reinitCommitResult.newState;
if (reinitCommitResult.commit.wireformat !== "mls_private_message")
throw new Error("Expected private message");
const processReinitResult = await processPrivateMessage(bobGroup, reinitCommitResult.commit.privateMessage, makePskIndex(bobGroup, {}), impl);
bobGroup = processReinitResult.newState;
expect(bobGroup.groupActiveState.kind).toBe("suspendedPendingReinit");
expect(aliceGroup.groupActiveState.kind).toBe("suspendedPendingReinit");
//creating a message will fail now
await expect(createCommit(aliceGroup, emptyPskIndex, false, [], impl)).rejects.toThrow(UsageError);
const newImpl = await getCiphersuiteImpl(getCiphersuiteFromName(newCiphersuite));
const bobNewKeyPackage = await generateKeyPackage(bobCredential, defaultCapabilities(), defaultLifetime, [], newImpl);
const aliceNewKeyPackage = await generateKeyPackage(aliceCredential, defaultCapabilities(), defaultLifetime, [], newImpl);
const resumeGroupResult = await reinitCreateNewGroup(aliceGroup, aliceNewKeyPackage.publicPackage, aliceNewKeyPackage.privatePackage, [bobNewKeyPackage.publicPackage], newGroupId, newCiphersuite, []);
aliceGroup = resumeGroupResult.newState;
bobGroup = await joinGroupFromReinit(bobGroup, resumeGroupResult.welcome, bobNewKeyPackage.publicPackage, bobNewKeyPackage.privatePackage, aliceGroup.ratchetTree);
await testEveryoneCanMessageEveryone([aliceGroup, bobGroup], newImpl);
await checkHpkeKeysMatch(aliceGroup, newImpl);
await checkHpkeKeysMatch(bobGroup, newImpl);
}
//# sourceMappingURL=reinit.test.js.map