ts-mls
Version:
[](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [](https://badge.fury.io/js/ts-mls) [) {
test(`External PSK ${cs}`, async () => {
await externalPsk(cs);
});
}
async function externalPsk(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 pskSecret1 = impl.rng.randomBytes(impl.kdf.size);
const pskSecret2 = impl.rng.randomBytes(impl.kdf.size);
const pskNonce1 = impl.rng.randomBytes(impl.kdf.size);
const pskNonce2 = impl.rng.randomBytes(impl.kdf.size);
const pskId1 = new TextEncoder().encode("psk-1");
const pskId2 = new TextEncoder().encode("psk-1");
const pskProposal1 = {
proposalType: "psk",
psk: {
preSharedKeyId: {
psktype: "external",
pskId: pskId1,
pskNonce: pskNonce1,
},
},
};
const pskProposal2 = {
proposalType: "psk",
psk: {
preSharedKeyId: {
psktype: "external",
pskId: pskId2,
pskNonce: pskNonce2,
},
},
};
const base64PskId1 = bytesToBase64(pskId1);
const base64PskId2 = bytesToBase64(pskId2);
const sharedPsks = { [base64PskId1]: pskSecret1, [base64PskId2]: pskSecret2 };
const pskCommitResult = await createCommit(aliceGroup, makePskIndex(aliceGroup, sharedPsks), false, [pskProposal1, pskProposal2], impl);
aliceGroup = pskCommitResult.newState;
if (pskCommitResult.commit.wireformat !== "mls_private_message")
throw new Error("Expected private message");
const processPskResult = await processPrivateMessage(bobGroup, pskCommitResult.commit.privateMessage, makePskIndex(bobGroup, sharedPsks), impl);
bobGroup = processPskResult.newState;
await testEveryoneCanMessageEveryone([aliceGroup, bobGroup], impl);
await checkHpkeKeysMatch(aliceGroup, impl);
await checkHpkeKeysMatch(bobGroup, impl);
}
//# sourceMappingURL=externalPsk.test.js.map