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

123 lines (122 loc) 5.7 kB
import { AuthenticatedContent } from "./authenticatedContent"; import { CiphersuiteImpl } from "./crypto/ciphersuite"; import { Hash } from "./crypto/hash"; import { Extension } from "./extension"; import { FramedContentCommit } from "./framedContent"; import { GroupContext } from "./groupContext"; import { KeyPackage, PrivateKeyPackage } from "./keyPackage"; import { KeySchedule } from "./keySchedule"; import { PreSharedKeyID } from "./presharedkey"; import { RatchetTree } from "./ratchetTree"; import { SecretTree } from "./secretTree"; import { Welcome } from "./welcome"; import { WireformatName } from "./wireformat"; import { ProposalOrRef } from "./proposalOrRefType"; import { Proposal, ProposalAdd, ProposalExternalInit, ProposalGroupContextExtensions, ProposalPSK, ProposalReinit, ProposalRemove, ProposalUpdate, Reinit } from "./proposal"; import { PrivateKeyPath } from "./privateKeyPath"; import { UnappliedProposals, ProposalWithSender } from "./unappliedProposals"; import { PskIndex } from "./pskIndex"; import { MlsError } from "./mlsError"; import { Signature } from "./crypto/signature"; import { LeafNodeCommit, LeafNodeUpdate } from "./leafNode"; import { AuthenticationService } from "./authenticationService"; import { LifetimeConfig } from "./lifetimeConfig"; import { ClientConfig } from "./clientConfig"; export type ClientState = { groupContext: GroupContext; keySchedule: KeySchedule; secretTree: SecretTree; ratchetTree: RatchetTree; privatePath: PrivateKeyPath; signaturePrivateKey: Uint8Array; unappliedProposals: UnappliedProposals; confirmationTag: Uint8Array; historicalReceiverData: Map<bigint, EpochReceiverData>; groupActiveState: GroupActiveState; clientConfig: ClientConfig; }; export type GroupActiveState = { kind: "active"; } | { kind: "suspendedPendingReinit"; reinit: Reinit; } | { kind: "removedFromGroup"; }; /** * This type contains everything necessary to receieve application messages for an earlier epoch */ export type EpochReceiverData = { resumptionPsk: Uint8Array; secretTree: SecretTree; ratchetTree: RatchetTree; senderDataSecret: Uint8Array; groupContext: GroupContext; }; export declare function checkCanSendApplicationMessages(state: ClientState): void; export declare function checkCanSendHandshakeMessages(state: ClientState): void; export type Proposals = { add: { senderLeafIndex: number | undefined; proposal: ProposalAdd; }[]; update: { senderLeafIndex: number | undefined; proposal: ProposalUpdate; }[]; remove: { senderLeafIndex: number | undefined; proposal: ProposalRemove; }[]; psk: { senderLeafIndex: number | undefined; proposal: ProposalPSK; }[]; reinit: { senderLeafIndex: number | undefined; proposal: ProposalReinit; }[]; external_init: { senderLeafIndex: number | undefined; proposal: ProposalExternalInit; }[]; group_context_extensions: { senderLeafIndex: number | undefined; proposal: ProposalGroupContextExtensions; }[]; }; export declare function validateRatchetTree(tree: RatchetTree, groupContext: GroupContext, config: LifetimeConfig, authService: AuthenticationService, treeHash: Uint8Array, cs: CiphersuiteImpl): Promise<MlsError | undefined>; export declare function validateLeafNodeUpdateOrCommit(leafNode: LeafNodeCommit | LeafNodeUpdate, leafIndex: number, groupContext: GroupContext, tree: RatchetTree, authService: AuthenticationService, s: Signature): Promise<MlsError | undefined>; export declare function throwIfDefined(err: MlsError | undefined): void; export type ApplyProposalsResult = { tree: RatchetTree; pskSecret: Uint8Array; pskIds: PreSharedKeyID[]; needsUpdatePath: boolean; additionalResult: ApplyProposalsData; selfRemoved: boolean; allProposals: ProposalWithSender[]; }; export type ApplyProposalsData = { kind: "memberCommit"; addedLeafNodes: [number, KeyPackage][]; extensions: Extension[]; } | { kind: "externalCommit"; externalInitSecret: Uint8Array; newMemberLeafIndex: number; } | { kind: "reinit"; reinit: Reinit; }; export declare function applyProposals(state: ClientState, proposals: ProposalOrRef[], committerLeafIndex: number | undefined, pskSearch: PskIndex, sentByClient: boolean, cs: CiphersuiteImpl): Promise<ApplyProposalsResult>; export declare function makePskIndex(state: ClientState | undefined, externalPsks: Record<string, Uint8Array>): PskIndex; export declare function nextEpochContext(groupContext: GroupContext, wireformat: WireformatName, content: FramedContentCommit, signature: Uint8Array, updatedTreeHash: Uint8Array, confirmationTag: Uint8Array, h: Hash): Promise<GroupContext>; export declare function joinGroup(welcome: Welcome, keyPackage: KeyPackage, privateKeys: PrivateKeyPackage, pskSearch: PskIndex, cs: CiphersuiteImpl, ratchetTree?: RatchetTree, resumingFromState?: ClientState, clientConfig?: ClientConfig): Promise<ClientState>; export declare function createGroup(groupId: Uint8Array, keyPackage: KeyPackage, privateKeyPackage: PrivateKeyPackage, extensions: Extension[], cs: CiphersuiteImpl, clientConfig?: ClientConfig): Promise<ClientState>; export declare function exportSecret(publicKey: Uint8Array, cs: CiphersuiteImpl): Promise<{ enc: Uint8Array; secret: Uint8Array; }>; export declare function processProposal(state: ClientState, content: AuthenticatedContent, proposal: Proposal, h: Hash): Promise<ClientState>; export declare function addHistoricalReceiverData(state: ClientState): Map<bigint, EpochReceiverData>;