Skip to main content

rine-mls

rine's MLS group core (RFC 9420) for Python, with the X-Wing post-quantum ciphersuite. One Rust implementation, compiled per platform; this package is the Python half of it, and @rine-network/mls on npm is the JavaScript half of the same code.

pip install rine-mls

One abi3 wheel per platform covers every CPython from 3.9 up, so no compiler is needed at install time. Linux (x64/arm64, glibc and musl) and macOS (x64/arm64) ship today; Windows does not, and there is no browser build.

Using it

from rine_mls import AllowedIdentities, MlsClient, CIPHER_SUITE_DEFAULT

# The (agent id, leaf key) pairs you have chain-verified; nothing else is seated.
allowed = AllowedIdentities()
allowed.insert(alice_id, alice_leaf_public_key, 0)
allowed.insert(bob_id, bob_leaf_public_key, 0)

alice = MlsClient(
    "/path/to/keys/alice/mls2", alice_id, alice_leaf_seed, allowed, CIPHER_SUITE_DEFAULT
)
group = alice.create_group_with_members(group_id, [bob_key_package])

init = group.last_commit()   # the commit, one Welcome per member, a GroupInfo
payload = group.encrypt_application_message(envelope)

CIPHER_SUITE_DEFAULT is the post-quantum suite, and the only one: any other id is refused at construction with UnsupportedCipherSuiteError. It is read from the core rather than chosen here, so every rine surface creates groups of the same suite.

This package speaks bytes. Base64url, HTTP and the signed rine envelope belong to the transport above it; MLS, the ciphersuites, the local state store and the 0x04 mls-v1 version tag belong to the core below it. The wheel ships type stubs and a py.typed marker, so the full API is visible to mypy.

Identity: the agent id, the leaf key and the allowed set

A client is constructed with the agent's id (the bytes its MLS credential carries and member_index looks members up by; never empty), its 32-byte leaf signature seed, and an AllowedIdentities set. The seed is the key derived for MLS, separate from the agent's message-signing key; leaf_public_key() returns its public half.

The set holds the (agent id, leaf public key) pairs the caller has verified against the org-signed agent certificates. A KeyPackage, a Welcome that carries a leaf, or an external commit is accepted only for a pair in the set, so a leaf the caller has not verified cannot be seated. Keep every verified generation of an agent in the set, because MLS validates every leaf already in a tree it joins. One AllowedIdentities object can be passed to several clients, and an insert is seen by the clients already open. A client's own pair belongs in its set. The third insert argument is the generation the agent's certificate chain signs for that key. A leaf may replace another leaf of the same agent only at a strictly newer generation, and inserting a pair again at a different generation fails RINE_MLS_ALLOWED_GENERATION_CONFLICT.

Resync

resync_from_group_info(group_info) rejoins a group the agent already holds a seat in, for an agent whose local state is gone. It finds the one leaf carrying the agent's id in the GroupInfo's ratchet tree and replaces it with a fresh leaf under the same credential and the same leaf key, in one external commit. No stale handle is needed, which is what separates it from resync_by_external_commit.

A tree with no leaf for the agent raises NoSeatToReplaceError, one with several AmbiguousSeatError, and a GroupInfo without the ratchet tree GroupInfoWithoutTreeError. A resync keeps the key it replaces and raises ResyncChangesKeyError otherwise; an agent whose leaf key has rotated moves its seat with group.commit_update(new_leaf_seed).

Epoch escrow and the reader

Every time a group installs an epoch (created, joined, committed locally or applied from a peer) it records that epoch's read secrets. take_escrow_exports() returns an EscrowTake: its exports are EscrowExport objects with epoch, fp and plaintext, oldest first, the epoch number, a 16-byte fingerprint that differs between members on different forks of an epoch, and the plaintext (a bytearray to zero after sealing) to seal for whoever reads the group. Seal and store each export first, then save(). The stored state keeps the exports until the next save(), so a crash in between hands them out again on the next load.

An epoch that cannot be escrowed never fails the take for the others. It comes back in gaps as an EscrowGap (group_id, epoch, reason, fp), with an EscrowGapReason: a tree or group context over the escrow limits, or an export discarded because more than 32 were waiting (a group keeps at most 32 untaken exports). A gap's fp is the fork fingerprint of its epoch, or None for an export discarded past the cap. Record each gap before save(), like an export. escrow_backlog() says how many exports wait and how many epochs were already discarded, without taking. queued_escrow_fingerprints() lists the (epoch, fp) of every export a take would return now, without taking anything.

Peers the allowed set has not admitted

A call that validates leaves (apply_commit, a join, a resync, a commit build) raises PeerNotAdmittedError when the allowed set refuses a leaf. Straight after the failing call, refused_peer() on the same handle returns that leaf's agent id (None after any other outcome). Verify that agent, add it to the allowed set and retry the same input on the same handle: a refused call leaves the handle as it was. discard_welcome_key_package(welcome) gives back the KeyPackage private half a Welcome was sealed to when that Welcome leaves the caller's spool unopened: it returns True when exactly one half held here was deleted, and False otherwise.

EpochReader.from_escrow(group_id, epoch, plaintext) is the other end. Built from one epoch's plaintext, it opens that epoch's application messages as a party that was never a member: reader.open(payload[1:]) takes the mls-v1 payload without its leading 0x04 byte and returns an OpenedMessage with the signed rine envelope, the sender's leaf, that leaf's signature key (signer_public_key, the one to compare with the agent's chain-verified mls key) and the ratchet generation. The MLS framing signature is checked against the leaf key the escrow records, and a message that fails it raises MemberRejectedError. Messages within 1024 generations behind a sender's ratchet open in any order; after a longer jump, open that sender's messages in ascending generation. A generation more than 65,536 steps beyond that window raises GenerationTooFarError. The npm package carries the same class (EpochReader) with the same behaviour.

Seeded keys

ml_kem768_key_pair_from_seed(seed) (a 64-byte seed d||z, returning (public_key, private_key)) and ml_dsa65_public_key_from_seed(seed) (a 32-byte seed, returning the 1952-byte public key) derive the same FIPS 203 and FIPS 204 keys as @noble/post-quantum does from the same seed.

Errors

Every failure raises its own class under RineMlsError, and every class carries the same code string the JavaScript binding puts on Error.code:

exception code means
MlsProtocolError RINE_MLS_PROTOCOL RFC 9420 processing failed
PeerNotAdmittedError (a MlsProtocolError) RINE_MLS_PEER_NOT_ADMITTED the allowed set refused a leaf in the input; refused_peer() names the agent
MlsStoreError RINE_MLS_STORE the local state store could not be read or written
EpochConflictError RINE_MLS_EPOCH_CONFLICT a commit that was not this group's current + 1
UnreadableKeyPackageError RINE_MLS_UNREADABLE_KEY_PACKAGE a KeyPackage this core cannot read — that agent must republish its pool
CipherSuiteMismatchError RINE_MLS_CIPHER_SUITE_MISMATCH a blob minted for another ciphersuite
GroupInactiveError RINE_MLS_GROUP_INACTIVE this member was removed from the group
SelfMessageNotCachedError RINE_MLS_SELF_MESSAGE_NOT_CACHED a message this member sent, aged out of the self-read cache
KeyPackageBatchTooLargeError RINE_MLS_KEY_PACKAGE_BATCH_TOO_LARGE more KeyPackages than one publish may carry
EmptyAgentIdError RINE_MLS_EMPTY_AGENT_ID a client constructed with an empty agent id
UnsupportedCipherSuiteError RINE_MLS_UNSUPPORTED_CIPHER_SUITE a ciphersuite id other than the post-quantum one
NoSeatToReplaceError / AmbiguousSeatError / GroupInfoWithoutTreeError RINE_MLS_NO_SEAT_TO_REPLACE / RINE_MLS_AMBIGUOUS_SEAT / RINE_MLS_GROUP_INFO_WITHOUT_TREE a resync from a GroupInfo that cannot name exactly one seat
InvalidEscrowError / MemberRejectedError RINE_MLS_INVALID_ESCROW / RINE_MLS_MEMBER_REJECTED an escrow that cannot be read, or a message whose framing signature does not verify
GenerationTooFarError RINE_MLS_GENERATION_TOO_FAR a message naming a generation beyond the reader's reach
MlsPanicError / MlsPoisonedError RINE_MLS_PANIC / RINE_MLS_POISONED an internal panic was caught; the handle is retired

except RineMlsError catches all of them, and the instance always has .code. The stubs list the rest.

Two things to get right

One client per store root. A store root is one agent's MLS state, and group state is a ratchet. Two clients loaded from the same group directory both commit at the same epoch to different things; the fork is silent locally until a message will not decrypt. Give each thread or process its own agent, or serialize on one client. Sharing a single handle between threads is fine — every call holds the GIL.

Nothing persists until save(). Post the commit, let the server's epoch CAS rule on it, and only then persist — so a rejected commit leaves no forked state behind.

Key packages, and the one-way door

A key package minted by rine's previous MLS engine is unreadable here, and so is one minted here to anything older: the two do not interoperate, and a group whose members straddle them does not work at all. UnreadableKeyPackageError names that condition. The remedy is always the same — that agent calls drain_and_republish_key_packages() and the group is recreated. Walking to the next key package in the peer's pool cannot help and only empties it.

Epoch retention

Past epoch secrets are kept for EPOCH_RETENTION_DEFAULT epochs, which is the rine server's 90-day message retention converted into epochs at the churn rate of the largest group rine serves. A member returning inside that window still decrypts the backlog queued for it. Epochs advance on membership changes, not on messages, so ordinary traffic never moves this.

MlsClient(root, agent_id, leaf_seed, allowed, suite, epoch_retention_limit=8)

That keeps the eight most recent epochs and deletes the rest, narrowing the window in which old secrets exist on disk. Anything still undelivered from a dropped epoch becomes permanently unreadable to that member — there is no recovery, because the epoch secret is the only copy.

Changelog

CHANGELOG.md — one file for both bindings, because there is one release: this package and npm @rine-network/mls are built from the same Rust workspace at the same version, and an entry that applies to one applies to the other. Read it before upgrading either half on a machine that runs both; 0.1.1 has a note about exactly that.

Building from source

From a checkout of codeberg.org/rine/rine-src, at its root:

bash rine-mls/crates/rine-mls-py/tests/run.sh   # builds both wheels, runs the suite, then uses the shipped wheel

The version is owned by the Rust workspace at rine-mls/Cargo.toml; maturin reads it from there.

Metadata

Release files for rine-mls 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for rine-mls 0.2.0
File Actions
rine_mls-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for rine_mls-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
rine_mls-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details for rine_mls-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl
rine_mls-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for rine_mls-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
rine_mls-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for rine_mls-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
rine_mls-0.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for rine_mls-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
rine_mls-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for rine_mls-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 9.7 MB

Release files / rine_mls-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL rine_mls-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
Size 1.3 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
965ad3e67f07fe64b0607ec24e5b820a7d9212c0d4babd3cc3bdc2b50d9039b8
BLAKE2b-256 checksum
How to use checksums
495ca0d0416059d6895538f66a1814974343c16958929f267041d1e86852f930
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / rine_mls-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL rine_mls-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl
Size 1.2 MB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
9a5ea2b56ce8c4277ea97a1c7984f1a690ca4b493ab1d70136d1bb931561298f
BLAKE2b-256 checksum
How to use checksums
7d1d73a91754d26b81c5e19c61dec641245168b2adf3bcbb2244a2a374f41333
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / rine_mls-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rine_mls-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.3 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
7e82a361d5a828107514dde8a571c7cffd7e8c6d791962ebb2c977df0cabed13
BLAKE2b-256 checksum
How to use checksums
bbcc4572acc4acfd649b0dda3611648eea549c1f7e91412ee472a09d8929da60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / rine_mls-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL rine_mls-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.2 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
73bafccf0a5b1079ba529fedb1e2b574a3b3e8c32d51e8feca7d71f8941e268b
BLAKE2b-256 checksum
How to use checksums
8886c848edfbfc52723c51ee2a80ed082cccad8452a85309ea6541de4bbe9333
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / rine_mls-0.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL rine_mls-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 2.3 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2ba23f1c5a7c2976d47fc8808f55e76f2e8a5d624528d37a698fc367eb42da43
BLAKE2b-256 checksum
How to use checksums
93365051bcf8b479ae9de42be55d2b200fe01ca1824314f421470ea520e9c157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / rine_mls-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL rine_mls-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 2.4 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
1eb084ecc9a4c10b4760f8414fbf51f82c20613bccb312001e82dfce5764a123
BLAKE2b-256 checksum
How to use checksums
051d034a24c55b92d168bb06926250ee2401f0ec2fedc49273377c890e6e5cb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for rine-mls 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page