Skip to main content

samp-core

Python implementation of SAMP (Substrate Account Messaging Protocol). Crypto operations use a native Rust extension via PyO3.

Install

pip install samp-core

Usage

import os

from samp import (
    EncryptedRemark, Seed, decode_remark,
    nonce_from_bytes, plaintext_from_bytes, pubkey_from_bytes, sr25519_signing_scalar,
)
from samp.encryption import compute_view_tag, decrypt, encrypt
from samp.wire import ContentType, encode_encrypted, encode_public

sender_seed = Seed.from_bytes(bytes.fromhex("e5be9a5092b81bca" + "00" * 24))
recipient_pub = pubkey_from_bytes(bytes.fromhex("8eaf04151687736" + "0" + "00" * 24))

# Public message
remark = encode_public(recipient_pub, "Hello from Python")

# Encrypted message
nonce = nonce_from_bytes(os.urandom(12))
plaintext = plaintext_from_bytes(b"Private message")
ciphertext = encrypt(plaintext, recipient_pub, nonce, sender_seed)
tag = compute_view_tag(sender_seed, recipient_pub, nonce)
enc_remark = encode_encrypted(ContentType.ENCRYPTED, tag, nonce, ciphertext)

# Decrypt
recipient_seed = Seed.from_bytes(bytes(32))
scalar = sr25519_signing_scalar(recipient_seed)
parsed = decode_remark(enc_remark)
assert isinstance(parsed, EncryptedRemark)
clear = decrypt(parsed.ciphertext, parsed.nonce, scalar)

API

Wire

Function Description
encode_public Public message (0x10)
encode_encrypted Encrypted or thread message (0x11/0x12)
encode_channel_create Channel creation (0x13)
encode_channel_msg Channel message (0x14)
encode_group Group message (0x15)
decode_remark Parse any SAMP remark → Remark dataclass
encode_thread_content / decode_thread_content Thread plaintext (refs + body)
encode_channel_content / decode_channel_content Channel plaintext (refs + body)
decode_group_content Group plaintext (refs + body)
encode_group_members / decode_group_members Group member list
channel_ref_from_recipient Extract channel ref from recipient field

Crypto

Function Description
encrypt / decrypt 1:1 ECDH + ChaCha20-Poly1305
decrypt_as_sender Sender self-decryption via sealed_to
encrypt_for_group / decrypt_from_group Multi-recipient encryption
sr25519_signing_scalar Derive signing scalar from sr25519 seed
public_from_seed Derive public key from seed
compute_view_tag / check_view_tag 1-byte recipient filter
unseal_recipient Recover recipient from sealed_to field
build_capsules / scan_capsules Group capsule construction and scanning

Types

Remark (dataclass), SampError (exception)

Test

pytest tests/ -v

Metadata

Release files for samp-core 1.2.1

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

Source distribution (sdist)

Source distribution for samp-core 1.2.1
File Size Uploaded
samp_core-1.2.1.tar.gz 26.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for samp-core 1.2.1
File Interpreter ABI Platform
samp_core-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 43.6 kB

Release files / samp_core-1.2.1.tar.gz

Download URL samp_core-1.2.1.tar.gz
Size 26.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4aa78b64c7ac5ae655e060a391a24425f956568375bf90060b5def558cfca331
BLAKE2b-256 checksum
How to use checksums
d499ed5d867b97b95edea129541423994e07a8ea69691322e6330d23f067a3b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 20, 2026.

Transparency log

Release files / samp_core-1.2.1-py3-none-any.whl

Download URL samp_core-1.2.1-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f958fe25906b06bf95711f56e6d4dd0bbbf590e4231d10aa11ed6e519d54ae1
BLAKE2b-256 checksum
How to use checksums
864b59cc95a63509de88dd9ae3f282f2f46bf8247a0e35179103da80cfd4335c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

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