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

51 lines 2.27 kB
import { validateRatchetTree } from "../../src/clientState"; import { generateKeyPackage } from "../../src/keyPackage"; import { getCiphersuiteImpl, getCiphersuiteFromName, ciphersuites } from "../../src/crypto/ciphersuite"; import { defaultLifetime } from "../../src/lifetime"; import { ValidationError } from "../../src/mlsError"; import { defaultLifetimeConfig } from "../../src/lifetimeConfig"; import { defaultAuthenticationService } from "../../src/authenticationService"; for (const cs of Object.keys(ciphersuites)) { test("should reject structurally unsound ratchet tree", async () => { await testStructuralIntegrity(cs); }); } async function testStructuralIntegrity(cipherSuite) { const impl = await getCiphersuiteImpl(getCiphersuiteFromName(cipherSuite)); const aliceCredential = { credentialType: "basic", identity: new TextEncoder().encode("alice") }; const aliceCapabilities = { extensions: [], credentials: ["basic"], proposals: [], versions: ["mls10"], ciphersuites: [cipherSuite], }; const alice = await generateKeyPackage(aliceCredential, aliceCapabilities, defaultLifetime, [], impl); const validLeafNode = alice.publicPackage.leafNode; // Make the first node a parent node, which is invalid for a leaf position const invalidTree = [ { nodeType: "parent", parent: { unmergedLeaves: [], parentHash: new Uint8Array(), hpkePublicKey: new Uint8Array(), }, }, { nodeType: "leaf", leaf: validLeafNode }, { nodeType: "leaf", leaf: validLeafNode }, ]; const groupContext = { version: "mls10", cipherSuite: cipherSuite, epoch: 0n, treeHash: new Uint8Array(), groupId: new Uint8Array(), extensions: [], confirmedTranscriptHash: new Uint8Array(), }; const error = await validateRatchetTree(invalidTree, groupContext, defaultLifetimeConfig, defaultAuthenticationService, new Uint8Array(), impl); expect(error).toBeInstanceOf(ValidationError); expect(error?.message).toBe("Received Ratchet Tree is not structurally sound"); } //# sourceMappingURL=ratchetTreeValidation.test.js.map