UNPKG

ts-mls

Version:

[![CI](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml/badge.svg)](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [![npm version](https://badge.fury.io/js/ts-mls.svg)](https://badge.fury.io/js/ts-mls) [![Coverage Status](https://co

43 lines 2.81 kB
import { createGroup, joinGroup } from "../../src/clientState"; import { createCommit } from "../../src/createCommit"; import { emptyPskIndex } from "../../src/pskIndex"; import { branchGroup, joinGroupFromBranch } from "../../src/resumption"; import { ciphersuites, getCiphersuiteFromName, getCiphersuiteImpl } from "../../src/crypto/ciphersuite"; import { generateKeyPackage } from "../../src/keyPackage"; import { checkHpkeKeysMatch } from "../crypto/keyMatch"; import { testEveryoneCanMessageEveryone } from "./common"; import { defaultLifetime } from "../../src/lifetime"; import { defaultCapabilities } from "../../src/defaultCapabilities"; for (const cs of Object.keys(ciphersuites)) { test(`Resumption ${cs}`, async () => { await resumption(cs); }); } async function resumption(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 bobNewKeyPackage = await generateKeyPackage(bobCredential, defaultCapabilities(), defaultLifetime, [], impl); const aliceNewKeyPackage = await generateKeyPackage(aliceCredential, defaultCapabilities(), defaultLifetime, [], impl); const newGroupId = new TextEncoder().encode("new-group1"); const branchCommitResult = await branchGroup(aliceGroup, aliceNewKeyPackage.publicPackage, aliceNewKeyPackage.privatePackage, [bobNewKeyPackage.publicPackage], newGroupId, impl); aliceGroup = branchCommitResult.newState; bobGroup = await joinGroupFromBranch(bobGroup, branchCommitResult.welcome, bobNewKeyPackage.publicPackage, bobNewKeyPackage.privatePackage, aliceGroup.ratchetTree, impl); await testEveryoneCanMessageEveryone([aliceGroup, bobGroup], impl); await checkHpkeKeysMatch(aliceGroup, impl); await checkHpkeKeysMatch(bobGroup, impl); } //# sourceMappingURL=resumption.test.js.map