Skip to main content

Substrate Account Messaging Protocol -- Python SDK

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

samp_core-1.2.1.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

samp_core-1.2.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file samp_core-1.2.1.tar.gz.

File metadata

  • Download URL: samp_core-1.2.1.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for samp_core-1.2.1.tar.gz
Algorithm Hash digest
SHA256 4aa78b64c7ac5ae655e060a391a24425f956568375bf90060b5def558cfca331
MD5 eec3164def3fb03464b3bcc19eb34865
BLAKE2b-256 d499ed5d867b97b95edea129541423994e07a8ea69691322e6330d23f067a3b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for samp_core-1.2.1.tar.gz:

Publisher: release-py-core.yml on samp-org/samp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file samp_core-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: samp_core-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for samp_core-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9f958fe25906b06bf95711f56e6d4dd0bbbf590e4231d10aa11ed6e519d54ae1
MD5 65ca42b44f87775ef923f529ae18cf99
BLAKE2b-256 864b59cc95a63509de88dd9ae3f282f2f46bf8247a0e35179103da80cfd4335c

See more details on using hashes here.

Provenance

The following attestation bundles were made for samp_core-1.2.1-py3-none-any.whl:

Publisher: release-py-core.yml on samp-org/samp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page