npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

samp-core

v1.2.0

Published

Substrate Account Messaging Protocol -- TypeScript SDK

Readme

samp-core

TypeScript implementation of SAMP (Substrate Account Messaging Protocol).

Install

npm install samp-core

Usage

import {
  ContentType, Nonce, Plaintext, Pubkey, Seed,
  computeViewTag, decodeRemark, decrypt, encodeEncrypted, encodePublic,
  encrypt, sr25519SigningScalar,
} from "samp-core";

const senderSeed = Seed.fromBytes(new Uint8Array(32));   // your sr25519 seed
const recipientPub = Pubkey.fromBytes(new Uint8Array(32)); // recipient's sr25519 public key

// Public message
const remark = encodePublic(recipientPub, "Hello from TypeScript");

// Encrypted message
const nonce = Nonce.fromBytes(crypto.getRandomValues(new Uint8Array(12)));
const plaintext = Plaintext.fromBytes(new TextEncoder().encode("Private message"));
const ciphertext = encrypt(plaintext, recipientPub, nonce, senderSeed);
const tag = computeViewTag(senderSeed, recipientPub, nonce);
const encRemark = encodeEncrypted(ContentType.Encrypted, tag, nonce, ciphertext);

// Decrypt
const recipientSeed = Seed.fromBytes(new Uint8Array(32));
const scalar = sr25519SigningScalar(recipientSeed);
const parsed = decodeRemark(encRemark);
if (parsed.type !== ContentType.Encrypted) throw new Error("expected Encrypted");
const clear = decrypt(parsed.ciphertext, parsed.nonce, scalar);

API

Wire

| Function | Description | |----------|-------------| | encodePublic | Public message (0x10) | | encodeEncrypted | Encrypted or thread message (0x11/0x12) | | encodeChannelCreate | Channel creation (0x13) | | encodeChannelMsg | Channel message (0x14) | | encodeGroup | Group message (0x15) | | decodeRemark | Parse any SAMP remark → Remark | | encodeThreadContent / decodeThreadContent | Thread plaintext (refs + body) | | encodeChannelContent / decodeChannelContent | Channel plaintext (refs + body) | | decodeGroupContent | Group plaintext (refs + body) | | encodeGroupMembers / decodeGroupMembers | Group member list | | channelRefFromRecipient | Extract channel BlockRef from recipient field |

Crypto

| Function | Description | |----------|-------------| | encrypt / decrypt | 1:1 ECDH + ChaCha20-Poly1305 | | decryptAsSender | Sender self-decryption via sealed_to | | encryptForGroup / decryptFromGroup | Multi-recipient encryption | | sr25519SigningScalar | Derive signing scalar from sr25519 seed | | publicFromSeed | Derive public key from seed | | computeViewTag / checkViewTag | 1-byte recipient filter | | unsealRecipient | Recover recipient from sealed_to field | | buildCapsules / scanCapsules | Group capsule construction and scanning |

Types

BlockRef, Remark, SampError

Constants

SAMP_VERSION, ContentType (enum), CAPSULE_SIZE, CHANNEL_NAME_MAX, CHANNEL_DESC_MAX

Test

npm test